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

#include <ShortcutMac.h>

Inheritance diagram for inet::ShortcutMac:
inet::MacProtocolBase inet::LayeredProtocolBase inet::OperationalBase inet::OperationalMixin< cSimpleModule > inet::ILifecycle

Public Member Functions

 ~ShortcutMac ()
 
- Public Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual ~OperationalMixin ()
 }@ More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void configureNetworkInterface () override
 
virtual void handleMessageWhenUp (cMessage *message) override
 
virtual void handleUpperPacket (Packet *packet) override
 
virtual void handleLowerPacket (Packet *packet) override
 
virtual ShortcutMacfindPeer (MacAddress address)
 
virtual void sendToPeer (Packet *packet, ShortcutMac *peer)
 
virtual void receiveFromPeer (Packet *packet)
 
- Protected Member Functions inherited from inet::MacProtocolBase
 MacProtocolBase ()
 
virtual ~MacProtocolBase ()
 
virtual void registerInterface ()
 
virtual MacAddress parseMacAddressParameter (const char *addrstr)
 
virtual void deleteCurrentTxFrame ()
 
virtual void dropCurrentTxFrame (PacketDropDetails &details)
 
virtual void handleMessageWhenDown (cMessage *msg) override
 
virtual void sendUp (cMessage *message)
 
virtual void sendDown (cMessage *message)
 
virtual bool isUpperMessage (cMessage *message) const override
 
virtual bool isLowerMessage (cMessage *message) const override
 
virtual bool isInitializeStage (int stage) const override
 
virtual bool isModuleStartStage (int stage) const override
 
virtual bool isModuleStopStage (int stage) const override
 
virtual void flushQueue (PacketDropDetails &details)
 should clear queue and emit signal "packetDropped" with entire packets More...
 
virtual void clearQueue ()
 should clear queue silently More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 
virtual void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
queueing::IPacketQueuegetQueue (cGate *gate) const
 
virtual bool canDequeuePacket () const
 
virtual PacketdequeuePacket ()
 
- Protected Member Functions inherited from inet::LayeredProtocolBase
virtual void handleSelfMessage (cMessage *message)
 
virtual void handleUpperMessage (cMessage *message)
 
virtual void handleLowerMessage (cMessage *message)
 
virtual void handleUpperCommand (cMessage *message)
 
virtual void handleLowerCommand (cMessage *message)
 
- Protected Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual int numInitStages () const override
 
virtual void refreshDisplay () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual State getInitialOperationalState () const
 Returns initial operational state: OPERATING or NOT_OPERATING. More...
 
virtual void handleActiveOperationTimeout (cMessage *message)
 
virtual bool isUp () const
 utility functions More...
 
virtual bool isDown () const
 
virtual void setOperationalState (State newState)
 
virtual void scheduleOperationTimeout (simtime_t timeout)
 
virtual void setupActiveOperation (LifecycleOperation *operation, IDoneCallback *doneCallback, State)
 
virtual void delayActiveOperationFinish (simtime_t timeout)
 
virtual void startActiveOperationExtraTime (simtime_t delay=SIMTIME_ZERO)
 
virtual void startActiveOperationExtraTimeOrFinish (simtime_t extraTime)
 
virtual void finishActiveOperation ()
 

Protected Attributes

double bitrate = NaN
 
cPar * propagationDelay = nullptr
 
cPar * lengthOverhead = nullptr
 
cPar * durationOverhead = nullptr
 
cPar * packetLoss = nullptr
 
- Protected Attributes inherited from inet::MacProtocolBase
int upperLayerInGateId = -1
 Gate ids. More...
 
int upperLayerOutGateId = -1
 
int lowerLayerInGateId = -1
 
int lowerLayerOutGateId = -1
 
opp_component_ptr< NetworkInterfacenetworkInterface
 
opp_component_ptr< cModule > hostModule
 
PacketcurrentTxFrame = nullptr
 Currently transmitted frame if any. More...
 
opp_component_ptr< queueing::IPacketQueuetxQueue
 Messages received from upper layer and to be transmitted later. More...
 
- Protected Attributes inherited from inet::OperationalMixin< cSimpleModule >
State operationalState
 
simtime_t lastChange
 
Operation activeOperation
 
cMessage * activeOperationTimeout
 
cMessage * activeOperationExtraTimer
 

Static Protected Attributes

static std::map< MacAddress, ShortcutMac * > shortcutMacs
 

Additional Inherited Members

- Protected Types inherited from inet::OperationalMixin< cSimpleModule >
enum  State
 

Constructor & Destructor Documentation

◆ ~ShortcutMac()

inet::ShortcutMac::~ShortcutMac ( )
24 {
25  auto it = shortcutMacs.begin();
26  while (it != shortcutMacs.end()) {
27  if (it->second == this)
28  it = shortcutMacs.erase(it);
29  else
30  ++it;
31  }
32 }

Member Function Documentation

◆ configureNetworkInterface()

void inet::ShortcutMac::configureNetworkInterface ( )
overrideprotectedvirtual

Implements inet::MacProtocolBase.

49 {
50  MacAddress address = parseMacAddressParameter(par("address"));
51  shortcutMacs[address] = this;
52  networkInterface->setDatarate(bitrate);
53  networkInterface->setMacAddress(address);
54  networkInterface->setInterfaceToken(address.formInterfaceIdentifier());
55  networkInterface->setMtu(par("mtu"));
56  networkInterface->setMulticast(false);
57  networkInterface->setBroadcast(true);
58 }

◆ findPeer()

ShortcutMac * inet::ShortcutMac::findPeer ( MacAddress  address)
protectedvirtual
92 {
93  auto it = shortcutMacs.find(address);
94  return (it == shortcutMacs.end()) ? nullptr : it->second;
95 }

Referenced by handleUpperPacket().

◆ handleLowerPacket()

void inet::ShortcutMac::handleLowerPacket ( Packet packet)
overrideprotectedvirtual

Reimplemented from inet::LayeredProtocolBase.

87 {
88  throw cRuntimeError("Received lower packet is unexpected");
89 }

◆ handleMessageWhenUp()

void inet::ShortcutMac::handleMessageWhenUp ( cMessage *  message)
overrideprotectedvirtual

Reimplemented from inet::LayeredProtocolBase.

61 {
62  if (message->getArrivalGate() == gate("peerIn"))
63  receiveFromPeer(check_and_cast<Packet *>(message));
64  else
66 }

◆ handleUpperPacket()

void inet::ShortcutMac::handleUpperPacket ( Packet packet)
overrideprotectedvirtual

Reimplemented from inet::LayeredProtocolBase.

69 {
70  auto destination = packet->getTag<MacAddressReq>()->getDestAddress();
71  if (destination.isBroadcast()) {
72  for (auto it : shortcutMacs)
73  if (it.second != this)
74  sendToPeer(packet->dup(), it.second);
75  delete packet;
76  }
77  else {
78  auto peer = findPeer(destination);
79  if (peer != nullptr)
80  sendToPeer(packet, peer);
81  else
82  throw cRuntimeError("ShortcutMac not found");
83  }
84 }

◆ initialize()

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

Reimplemented from inet::MacProtocolBase.

37 {
39  if (stage == INITSTAGE_LOCAL) {
40  bitrate = par("bitrate");
41  propagationDelay = &par("propagationDelay");
42  lengthOverhead = &par("lengthOverhead");
43  durationOverhead = &par("durationOverhead");
44  packetLoss = &par("packetLoss");
45  }
46 }

◆ receiveFromPeer()

void inet::ShortcutMac::receiveFromPeer ( Packet packet)
protectedvirtual
123 {
124  auto& packetProtocolTag = packet->getTagForUpdate<PacketProtocolTag>();
125  auto packetProtocol = packetProtocolTag->getProtocol();
126  if (packetProtocol == &Protocol::shortcutMac) {
127  const auto& header = packet->popAtFront<ShortcutMacHeader>();
128  packetProtocol = header->getPayloadProtocol();
129  packetProtocolTag->setProtocol(packetProtocol);
130  }
131  packet->addTag<DispatchProtocolReq>()->setProtocol(packetProtocol);
132  packet->addTag<InterfaceInd>()->setInterfaceId(networkInterface->getInterfaceId());
133  sendUp(packet);
134 }

Referenced by handleMessageWhenUp().

◆ sendToPeer()

void inet::ShortcutMac::sendToPeer ( Packet packet,
ShortcutMac peer 
)
protectedvirtual
98 {
99  if (dblrand() < packetLoss->doubleValue()) {
100  EV_WARN << "Packet " << packet << " lost.";
101  delete packet;
102  }
103  else {
104  auto length = b(lengthOverhead->intValue());
105  auto packetProtocol = packet->getTag<PacketProtocolTag>()->getProtocol();
106  packet->clearTags();
107  if (length != b(0)) {
108  auto header = makeShared<ShortcutMacHeader>();
109  header->setChunkLength(length);
110  header->setPayloadProtocol(packetProtocol);
111  packet->insertAtFront(header);
112  packet->addTag<PacketProtocolTag>()->setProtocol(&Protocol::shortcutMac);
113  }
114  else
115  packet->addTag<PacketProtocolTag>()->setProtocol(packetProtocol);
116  simtime_t transmissionDuration = packet->getBitLength() / bitrate + durationOverhead->doubleValue();
117  packet->setDuration(transmissionDuration);
118  sendDirect(packet, propagationDelay->doubleValue(), transmissionDuration, peer->gate("peerIn"));
119  }
120 }

Referenced by handleUpperPacket().

Member Data Documentation

◆ bitrate

double inet::ShortcutMac::bitrate = NaN
protected

◆ durationOverhead

cPar* inet::ShortcutMac::durationOverhead = nullptr
protected

Referenced by initialize(), and sendToPeer().

◆ lengthOverhead

cPar* inet::ShortcutMac::lengthOverhead = nullptr
protected

Referenced by initialize(), and sendToPeer().

◆ packetLoss

cPar* inet::ShortcutMac::packetLoss = nullptr
protected

Referenced by initialize(), and sendToPeer().

◆ propagationDelay

cPar* inet::ShortcutMac::propagationDelay = nullptr
protected

Referenced by initialize(), and sendToPeer().

◆ shortcutMacs

std::map< MacAddress, ShortcutMac * > inet::ShortcutMac::shortcutMacs
staticprotected

The documentation for this class was generated from the following files:
inet::MacProtocolBase::networkInterface
opp_component_ptr< NetworkInterface > networkInterface
Definition: MacProtocolBase.h:30
inet::LayeredProtocolBase::handleMessageWhenUp
virtual void handleMessageWhenUp(cMessage *message) override
Definition: LayeredProtocolBase.cc:14
inet::ShortcutMac::packetLoss
cPar * packetLoss
Definition: ShortcutMac.h:26
inet::MacProtocolBase::sendUp
virtual void sendUp(cMessage *message)
Definition: MacProtocolBase.cc:59
inet::ShortcutMac::sendToPeer
virtual void sendToPeer(Packet *packet, ShortcutMac *peer)
Definition: ShortcutMac.cc:97
DispatchProtocolReq
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
PacketProtocolTag
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
inet::ShortcutMac::lengthOverhead
cPar * lengthOverhead
Definition: ShortcutMac.h:24
inet::ShortcutMac::durationOverhead
cPar * durationOverhead
Definition: ShortcutMac.h:25
inet::ShortcutMac::propagationDelay
cPar * propagationDelay
Definition: ShortcutMac.h:23
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::MacProtocolBase::initialize
virtual void initialize(int stage) override
Definition: MacProtocolBase.cc:37
inet::ShortcutMac::bitrate
double bitrate
Definition: ShortcutMac.h:22
inet::Protocol::shortcutMac
static const Protocol shortcutMac
Definition: Protocol.h:130
inet::MacProtocolBase::parseMacAddressParameter
virtual MacAddress parseMacAddressParameter(const char *addrstr)
Definition: MacProtocolBase.cc:24
inet::ShortcutMac::receiveFromPeer
virtual void receiveFromPeer(Packet *packet)
Definition: ShortcutMac.cc:122
inet::ShortcutMac::findPeer
virtual ShortcutMac * findPeer(MacAddress address)
Definition: ShortcutMac.cc:91
inet::ShortcutMac::shortcutMacs
static std::map< MacAddress, ShortcutMac * > shortcutMacs
Definition: ShortcutMac.h:19