INET Framework for OMNeT++/OMNEST
inet::RelayInterfaceSelector Class Reference

#include <RelayInterfaceSelector.h>

Inheritance diagram for inet::RelayInterfaceSelector:
inet::queueing::PacketPusherBase inet::TransparentProtocolRegistrationListener inet::queueing::PacketProcessorBase inet::queueing::IPacketPusher inet::IProtocolRegistrationListener inet::queueing::IPacketProcessor inet::StringFormat::IDirectiveResolver inet::queueing::IPassivePacketSink inet::queueing::IActivePacketSource

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void pushPacket (Packet *packet, cGate *gate) override
 Pushes the packet into the packet sink at the given gate. More...
 
virtual bool isForwardingInterface (NetworkInterface *networkInterface) const
 
virtual void broadcastPacket (Packet *packet, const MacAddress &destinationAddress, NetworkInterface *incomingInterface)
 
virtual void sendPacket (Packet *packet, const MacAddress &destinationAddress, NetworkInterface *outgoingInterface)
 
virtual bool isForwardingService (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) const override
 
virtual bool isForwardingServiceGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) const override
 
virtual bool isForwardingAnyService (cGate *gate, ServicePrimitive servicePrimitive) const override
 
virtual bool isForwardingProtocol (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) const override
 
virtual bool isForwardingProtocolGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) const override
 
virtual bool isForwardingAnyProtocol (cGate *gate, ServicePrimitive servicePrimitive) const override
 
virtual cGate * getRegistrationForwardingGate (cGate *gate) override
 
- Protected Member Functions inherited from inet::queueing::PacketPusherBase
virtual void handleMessage (cMessage *message) override
 
- Protected Member Functions inherited from inet::queueing::PacketProcessorBase
virtual int numInitStages () const override
 
virtual void refreshDisplay () const override
 
virtual void handlePacketProcessed (Packet *packet)
 
virtual void checkPacketOperationSupport (cGate *gate) const
 
virtual void checkPacketOperationSupport (cGate *startGate, cGate *endGate) const
 
virtual void animate (Packet *packet, cGate *gate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacket (Packet *packet, cGate *gate, Action action) const
 
virtual void animatePacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId, Action action) const
 
virtual void animatePacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacketEnd (Packet *packet, cGate *gate, long transmissionId, Action action) const
 
virtual void animatePacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId, Action action) const
 
virtual void animatePacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions, Action action) const
 
virtual void pushOrSendPacket (Packet *packet, cGate *gate, IPassivePacketSink *consumer)
 
virtual void pushOrSendPacketStart (Packet *packet, cGate *gate, IPassivePacketSink *consumer, bps datarate, int transmissionId)
 
virtual void pushOrSendPacketEnd (Packet *packet, cGate *gate, IPassivePacketSink *consumer, int transmissionId)
 
virtual void pushOrSendPacketProgress (Packet *packet, cGate *gate, IPassivePacketSink *consumer, bps datarate, b position, b extraProcessableLength, int transmissionId)
 
virtual void animatePush (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePushPacket (Packet *packet, cGate *gate) const
 
virtual void animatePushPacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId) const
 
virtual void animatePushPacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions) const
 
virtual void animatePushPacketEnd (Packet *packet, cGate *gate, long transmissionId) const
 
virtual void animatePushPacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId) const
 
virtual void animatePushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions) const
 
virtual void animatePull (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePullPacket (Packet *packet, cGate *gate) const
 
virtual void animatePullPacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId) const
 
virtual void animatePullPacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions) const
 
virtual void animatePullPacketEnd (Packet *packet, cGate *gate, long transmissionId) const
 
virtual void animatePullPacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePullPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId) const
 
virtual void animatePullPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions) const
 
virtual void dropPacket (Packet *packet, PacketDropReason reason, int limit=-1)
 
virtual void updateDisplayString () const
 

Protected Attributes

ModuleRefByPar< IInterfaceTableinterfaceTable
 
ModuleRefByPar< IMacForwardingTablemacForwardingTable
 
long numProcessedFrames = 0
 
long numDroppedFrames = 0
 
- Protected Attributes inherited from inet::queueing::PacketPusherBase
cGate * inputGate = nullptr
 
IActivePacketSourceproducer = nullptr
 
cGate * outputGate = nullptr
 
IPassivePacketSinkconsumer = nullptr
 
- Protected Attributes inherited from inet::queueing::PacketProcessorBase
const char * displayStringTextFormat = nullptr
 
int numProcessedPackets = -1
 
b processedTotalLength = b(-1)
 

Additional Inherited Members

- Public Member Functions inherited from inet::queueing::PacketPusherBase
virtual IPassivePacketSinkgetConsumer (cGate *gate) override
 Returns the passive packet sink where packets are pushed or nullptr if the connected module doesn't implement the interface. More...
 
virtual bool supportsPacketPushing (cGate *gate) const override
 Returns true if the processor supports pushing packets at the given gate. More...
 
virtual bool supportsPacketPulling (cGate *gate) const override
 Returns true if the processor supports pulling packets at the given gate. More...
 
virtual bool canPushSomePacket (cGate *gate) const override
 Returns false if the packet sink is full at the given gate and no more packets can be pushed into it without raising an error. More...
 
virtual bool canPushPacket (Packet *packet, cGate *gate) const override
 Returns true if the given packet can be pushed at the given gate into the packet sink without raising an error. More...
 
virtual void pushPacketStart (Packet *packet, cGate *gate, bps datarate) override
 Starts pushing the packet into the packet sink at the given gate. More...
 
virtual void pushPacketEnd (Packet *packet, cGate *gate) override
 Ends pushing the packet into the packet sink at the given gate. More...
 
virtual void pushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength=b(0)) override
 Progresses pushing the packet into the packet sink at the given gate. More...
 
virtual void handleCanPushPacketChanged (cGate *gate) override
 Notifies about a change in the possibility of pushing some packet into the passive packet sink at the given gate. More...
 
virtual void handlePushPacketProcessed (Packet *packet, cGate *gate, bool successful) override
 Notifies about the completion of the packet processing for a packet that was pushed earlier independently whether the packet is passed or streamed. More...
 
- Public Member Functions inherited from inet::queueing::PacketProcessorBase
virtual bool supportsPacketSending (cGate *gate) const override
 Returns true if the processor supports sending packets at the given gate. More...
 
virtual bool supportsPacketPassing (cGate *gate) const override
 Returns true if the processor supports passing packets as a whole at the given gate. More...
 
virtual bool supportsPacketStreaming (cGate *gate) const override
 Returns true if the processor supports streaming packets at the given gate. More...
 
virtual const char * resolveDirective (char directive) const override
 
- Public Member Functions inherited from inet::queueing::IPacketProcessor
virtual ~IPacketProcessor ()
 
- Public Member Functions inherited from inet::queueing::IPassivePacketSink
virtual ~IPassivePacketSink ()
 
- Public Member Functions inherited from inet::queueing::IActivePacketSource
virtual ~IActivePacketSource ()
 
- Public Member Functions inherited from inet::TransparentProtocolRegistrationListener
virtual void mapRegistrationForwardingGates (cGate *gate, std::function< void(cGate *)> f)
 
virtual bool isForwardingProtocol (cGate *gate, ServicePrimitive servicePrimitive) const
 
virtual bool isForwardingService (cGate *gate, ServicePrimitive servicePrimitive) const
 
virtual void handleRegisterService (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterProtocol (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterServiceGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterProtocolGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterAnyService (cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterAnyProtocol (cGate *gate, ServicePrimitive servicePrimitive) override
 
- Protected Types inherited from inet::queueing::PacketProcessorBase
enum  Action { PUSH, PULL }
 

Member Function Documentation

◆ broadcastPacket()

void inet::RelayInterfaceSelector::broadcastPacket ( Packet packet,
const MacAddress destinationAddress,
NetworkInterface incomingInterface 
)
protectedvirtual
103 {
104  if (incomingInterface == nullptr)
105  EV_INFO << "Broadcasting packet to all interfaces" << EV_FIELD(destinationAddress) << EV_FIELD(outgoingPacket) << EV_ENDL;
106  else
107  EV_INFO << "Broadcasting packet to all interfaces except incoming interface" << EV_FIELD(destinationAddress) << EV_FIELD(incomingInterface) << EV_FIELD(outgoingPacket) << EV_ENDL;
108  for (int i = 0; i < interfaceTable->getNumInterfaces(); i++) {
109  auto outgoingInterface = interfaceTable->getInterface(i);
110  if (incomingInterface != outgoingInterface && isForwardingInterface(outgoingInterface))
111  sendPacket(outgoingPacket->dup(), destinationAddress, outgoingInterface);
112  }
113  delete outgoingPacket;
114 }

Referenced by pushPacket().

◆ getRegistrationForwardingGate()

cGate * inet::RelayInterfaceSelector::getRegistrationForwardingGate ( cGate *  gate)
overrideprotectedvirtual

Reimplemented from inet::TransparentProtocolRegistrationListener.

33 {
34  if (gate == outputGate)
35  return inputGate;
36  else if (gate == inputGate)
37  return outputGate;
38  else
39  throw cRuntimeError("Unknown gate");
40 }

◆ initialize()

void inet::RelayInterfaceSelector::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::queueing::PacketPusherBase.

22 {
24  if (stage == INITSTAGE_LOCAL) {
25  macForwardingTable.reference(this, "macTableModule", true);
26  interfaceTable.reference(this, "interfaceTableModule", true);
27  WATCH(numProcessedFrames);
28  WATCH(numDroppedFrames);
29  }
30 }

◆ isForwardingAnyProtocol()

virtual bool inet::RelayInterfaceSelector::isForwardingAnyProtocol ( cGate *  gate,
ServicePrimitive  servicePrimitive 
) const
inlineoverrideprotectedvirtual

Reimplemented from inet::TransparentProtocolRegistrationListener.

45 { return false; }

◆ isForwardingAnyService()

virtual bool inet::RelayInterfaceSelector::isForwardingAnyService ( cGate *  gate,
ServicePrimitive  servicePrimitive 
) const
inlineoverrideprotectedvirtual

Reimplemented from inet::TransparentProtocolRegistrationListener.

41 { return servicePrimitive == SP_REQUEST; }

◆ isForwardingInterface()

virtual bool inet::RelayInterfaceSelector::isForwardingInterface ( NetworkInterface networkInterface) const
inlineprotectedvirtual
35 { return !networkInterface->isLoopback() && networkInterface->isBroadcast(); }

Referenced by broadcastPacket().

◆ isForwardingProtocol()

virtual bool inet::RelayInterfaceSelector::isForwardingProtocol ( const Protocol protocol,
cGate *  gate,
ServicePrimitive  servicePrimitive 
) const
inlineoverrideprotectedvirtual

Reimplemented from inet::TransparentProtocolRegistrationListener.

43 { return false; }

◆ isForwardingProtocolGroup()

virtual bool inet::RelayInterfaceSelector::isForwardingProtocolGroup ( const ProtocolGroup protocolGroup,
cGate *  gate,
ServicePrimitive  servicePrimitive 
) const
inlineoverrideprotectedvirtual

Reimplemented from inet::TransparentProtocolRegistrationListener.

44 { return false; }

◆ isForwardingService()

virtual bool inet::RelayInterfaceSelector::isForwardingService ( const Protocol protocol,
cGate *  gate,
ServicePrimitive  servicePrimitive 
) const
inlineoverrideprotectedvirtual

Reimplemented from inet::TransparentProtocolRegistrationListener.

39 { return servicePrimitive == SP_REQUEST; }

◆ isForwardingServiceGroup()

virtual bool inet::RelayInterfaceSelector::isForwardingServiceGroup ( const ProtocolGroup protocolGroup,
cGate *  gate,
ServicePrimitive  servicePrimitive 
) const
inlineoverrideprotectedvirtual

Reimplemented from inet::TransparentProtocolRegistrationListener.

40 { return servicePrimitive == SP_REQUEST; }

◆ pushPacket()

void inet::RelayInterfaceSelector::pushPacket ( Packet packet,
cGate *  gate 
)
overrideprotectedvirtual

Pushes the packet into the packet sink at the given gate.

This operation pushes the packet as a whole. The onwership of the packet is transferred to the sink.

This method is called, for example, when a packet source module pushes a packet into a queue module.

The sink must not be full at the gate. The packet must not be nullptr. The gate must be a valid gate of this module and it must support pushing and passing packets.

Reimplemented from inet::queueing::PacketPusherBase.

43 {
44  Enter_Method("pushPacket");
45  take(packet);
46  auto interfaceReq = packet->findTag<InterfaceReq>();
47  auto macAddressReq = packet->getTag<MacAddressReq>();
48  auto destinationAddress = macAddressReq->getDestAddress();
49  if (interfaceReq != nullptr) {
50  auto networkInterface = interfaceTable->getInterfaceById(interfaceReq->getInterfaceId());
51  sendPacket(packet, destinationAddress, networkInterface);
52  }
53  else {
54  auto interfaceInd = packet->findTag<InterfaceInd>();
55  auto incomingInterface = interfaceInd != nullptr ? interfaceTable->getInterfaceById(interfaceInd->getInterfaceId()) : nullptr;
56  auto vlanReq = packet->findTag<VlanReq>();
57  int vlanId = vlanReq != nullptr ? vlanReq->getVlanId() : 0;
58  if (destinationAddress.isBroadcast())
59  broadcastPacket(packet, destinationAddress, incomingInterface);
60  else if (destinationAddress.isMulticast()) {
61  auto outgoingInterfaceIds = macForwardingTable->getMulticastAddressForwardingInterfaces(destinationAddress, vlanId);
62  if (outgoingInterfaceIds.size() == 0)
63  broadcastPacket(packet, destinationAddress, incomingInterface);
64  else {
65  for (auto outgoingInterfaceId : outgoingInterfaceIds) {
66  if (interfaceInd != nullptr && outgoingInterfaceId == interfaceInd->getInterfaceId())
67  EV_WARN << "Ignoring outgoing interface because it is the same as incoming interface" << EV_FIELD(destinationAddress) << EV_FIELD(incomingInterface) << EV_FIELD(packet) << EV_ENDL;
68  else {
69  auto outgoingInterface = interfaceTable->getInterfaceById(outgoingInterfaceId);
70  sendPacket(packet->dup(), destinationAddress, outgoingInterface);
71  }
72  }
73  delete packet;
74  }
75  }
76  else {
77  // Find output interface of destination address and send packet to output interface
78  // if not found then broadcasts to all other interfaces instead
79  int outgoingInterfaceId = macForwardingTable->getUnicastAddressForwardingInterface(destinationAddress, vlanId);
80  // should not send out the same packet on the same interface
81  // (although wireless interfaces are ok to receive the same message)
82  if (interfaceInd != nullptr && outgoingInterfaceId == interfaceInd->getInterfaceId()) {
83  EV_WARN << "Discarding packet because outgoing interface is the same as incoming interface" << EV_FIELD(destinationAddress) << EV_FIELD(incomingInterface) << EV_FIELD(packet) << EV_ENDL;
85  PacketDropDetails details;
86  details.setReason(NO_INTERFACE_FOUND);
87  emit(packetDroppedSignal, packet, &details);
88  delete packet;
89  }
90  else if (outgoingInterfaceId != -1) {
91  auto outgoingInterface = interfaceTable->getInterfaceById(outgoingInterfaceId);
92  sendPacket(packet, destinationAddress, outgoingInterface);
93  }
94  else
95  broadcastPacket(packet, destinationAddress, incomingInterface);
96  }
97  }
100 }

◆ sendPacket()

void inet::RelayInterfaceSelector::sendPacket ( Packet packet,
const MacAddress destinationAddress,
NetworkInterface outgoingInterface 
)
protectedvirtual
117 {
118  EV_INFO << "Sending packet to peer" << EV_FIELD(destinationAddress) << EV_FIELD(outgoingInterface) << EV_FIELD(packet) << EV_ENDL;
119  packet->addTagIfAbsent<DirectionTag>()->setDirection(DIRECTION_OUTBOUND);
120  packet->addTagIfAbsent<InterfaceReq>()->setInterfaceId(outgoingInterface->getInterfaceId());
121  auto protocol = outgoingInterface->getProtocol();
122  if (protocol != nullptr) {
123  if (auto dispatchProtocolReq = packet->findTag<DispatchProtocolReq>()) {
124  auto encapsulationProtocolReq = packet->addTagIfAbsent<EncapsulationProtocolReq>();
125  encapsulationProtocolReq->appendProtocol(protocol);
126  }
127  else
128  packet->addTag<DispatchProtocolReq>()->setProtocol(protocol);
129  }
131 }

Referenced by broadcastPacket(), and pushPacket().

Member Data Documentation

◆ interfaceTable

ModuleRefByPar<IInterfaceTable> inet::RelayInterfaceSelector::interfaceTable
protected

◆ macForwardingTable

ModuleRefByPar<IMacForwardingTable> inet::RelayInterfaceSelector::macForwardingTable
protected

Referenced by initialize(), and pushPacket().

◆ numDroppedFrames

long inet::RelayInterfaceSelector::numDroppedFrames = 0
protected

Referenced by initialize(), and pushPacket().

◆ numProcessedFrames

long inet::RelayInterfaceSelector::numProcessedFrames = 0
protected

Referenced by initialize(), and pushPacket().


The documentation for this class was generated from the following files:
inet::queueing::PacketPusherBase::inputGate
cGate * inputGate
Definition: PacketPusherBase.h:22
inet::DIRECTION_OUTBOUND
@ DIRECTION_OUTBOUND
Definition: DirectionTag_m.h:58
inet::RelayInterfaceSelector::broadcastPacket
virtual void broadcastPacket(Packet *packet, const MacAddress &destinationAddress, NetworkInterface *incomingInterface)
Definition: RelayInterfaceSelector.cc:102
inet::queueing::PacketProcessorBase::pushOrSendPacket
virtual void pushOrSendPacket(Packet *packet, cGate *gate, IPassivePacketSink *consumer)
Definition: PacketProcessorBase.cc:126
protocol
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down protocol
Definition: IUdp-gates.txt:25
inet::RelayInterfaceSelector::interfaceTable
ModuleRefByPar< IInterfaceTable > interfaceTable
Definition: RelayInterfaceSelector.h:25
inet::NO_INTERFACE_FOUND
@ NO_INTERFACE_FOUND
Definition: Simsignals_m.h:74
inet::RelayInterfaceSelector::sendPacket
virtual void sendPacket(Packet *packet, const MacAddress &destinationAddress, NetworkInterface *outgoingInterface)
Definition: RelayInterfaceSelector.cc:116
inet::RelayInterfaceSelector::isForwardingInterface
virtual bool isForwardingInterface(NetworkInterface *networkInterface) const
Definition: RelayInterfaceSelector.h:35
InterfaceReq
removed InterfaceReq
Definition: IUdp-gates.txt:11
DispatchProtocolReq
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
inet::packetDroppedSignal
simsignal_t packetDroppedSignal
Definition: Simsignals.cc:85
inet::queueing::PacketPusherBase::outputGate
cGate * outputGate
Definition: PacketPusherBase.h:25
EV_FIELD
#define EV_FIELD(...)
Definition: INETDefs.h:112
inet::queueing::PacketPusherBase::initialize
virtual void initialize(int stage) override
Definition: PacketPusherBase.cc:16
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::queueing::PacketProcessorBase::updateDisplayString
virtual void updateDisplayString() const
Definition: PacketProcessorBase.cc:399
inet::RelayInterfaceSelector::macForwardingTable
ModuleRefByPar< IMacForwardingTable > macForwardingTable
Definition: RelayInterfaceSelector.h:26
inet::queueing::PacketPusherBase::consumer
IPassivePacketSink * consumer
Definition: PacketPusherBase.h:26
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::RelayInterfaceSelector::numProcessedFrames
long numProcessedFrames
Definition: RelayInterfaceSelector.h:28
EV_ENDL
#define EV_ENDL
Definition: INETDefs.h:114
inet::SP_REQUEST
@ SP_REQUEST
Definition: ProtocolTag_m.h:174
inet::RelayInterfaceSelector::numDroppedFrames
long numDroppedFrames
Definition: RelayInterfaceSelector.h:29