INET Framework for OMNeT++/OMNEST
inet::MacProtocolBase Class Referenceabstract

#include <MacProtocolBase.h>

Inheritance diagram for inet::MacProtocolBase:
inet::LayeredProtocolBase inet::OperationalBase inet::OperationalMixin< cSimpleModule > inet::ILifecycle inet::AckingMac inet::BMac inet::CsmaCaMac inet::EthernetMacBase inet::ieee80211::Ieee80211Mac inet::Ieee802154Mac inet::LMac inet::Loopback inet::Ppp inet::ShortcutMac inet::Tun inet::XMac

Protected Member Functions

 MacProtocolBase ()
 
virtual ~MacProtocolBase ()
 
virtual void initialize (int stage) override
 
virtual void registerInterface ()
 
virtual void configureNetworkInterface ()=0
 
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 handleMessageWhenUp (cMessage *message) override
 
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)
 
virtual void handleUpperPacket (Packet *packet)
 
virtual void handleLowerPacket (Packet *packet)
 
- 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

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
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ MacProtocolBase()

inet::MacProtocolBase::MacProtocolBase ( )
protected
16 {
17 }

◆ ~MacProtocolBase()

inet::MacProtocolBase::~MacProtocolBase ( )
protectedvirtual
20 {
21  delete currentTxFrame;
22 }

Member Function Documentation

◆ canDequeuePacket()

◆ clearQueue()

void inet::MacProtocolBase::clearQueue ( )
protectedvirtual

should clear queue silently

118 {
119  if (txQueue)
120  while (canDequeuePacket())
121  delete dequeuePacket();
122 }

Referenced by handleCrashOperation().

◆ configureNetworkInterface()

virtual void inet::MacProtocolBase::configureNetworkInterface ( )
protectedpure virtual

◆ deleteCurrentTxFrame()

void inet::MacProtocolBase::deleteCurrentTxFrame ( )
protectedvirtual

◆ dequeuePacket()

◆ dropCurrentTxFrame()

void inet::MacProtocolBase::dropCurrentTxFrame ( PacketDropDetails details)
protectedvirtual

◆ flushQueue()

void inet::MacProtocolBase::flushQueue ( PacketDropDetails details)
protectedvirtual

should clear queue and emit signal "packetDropped" with entire packets

107 {
108  // code would look slightly nicer with a pop() function that returns nullptr if empty
109  if (txQueue)
110  while (canDequeuePacket()) {
111  auto packet = dequeuePacket();
112  emit(packetDroppedSignal, packet, &details); // FIXME this signal lumps together packets from the network and packets from higher layers! separate them
113  delete packet;
114  }
115 }

Referenced by handleStopOperation(), and inet::Ppp::refreshOutGateConnection().

◆ getQueue()

queueing::IPacketQueue * inet::MacProtocolBase::getQueue ( cGate *  gate) const
protected
158 {
159  // TODO use findConnectedModule() when the function is updated
160  for (auto g = gate->getPreviousGate(); g != nullptr; g = g->getPreviousGate()) {
161  if (g->getType() == cGate::OUTPUT) {
162  auto m = dynamic_cast<queueing::IPacketQueue *>(g->getOwnerModule());
163  if (m)
164  return m;
165  }
166  }
167  throw cRuntimeError("Gate %s is not connected to a module of type queueing::IPacketQueue", gate->getFullPath().c_str());
168 }

Referenced by inet::Ppp::initialize(), and inet::EthernetMacBase::initialize().

◆ handleCrashOperation()

void inet::MacProtocolBase::handleCrashOperation ( LifecycleOperation operation)
overrideprotectedvirtual

◆ handleMessageWhenDown()

void inet::MacProtocolBase::handleMessageWhenDown ( cMessage *  msg)
overrideprotectedvirtual

Reimplemented from inet::OperationalMixin< cSimpleModule >.

84 {
85  if (!msg->isSelfMessage() && msg->getArrivalGateId() == lowerLayerInGateId) {
86  EV << "Interface is turned off, dropping packet\n";
87  delete msg;
88  }
89  else
91 }

◆ handleStartOperation()

void inet::MacProtocolBase::handleStartOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

Reimplemented in inet::Ieee802154Mac, inet::EthernetMacBase, inet::ieee80211::Ieee80211Mac, and inet::AckingMac.

125 {
126  networkInterface->setState(NetworkInterface::State::UP);
127  networkInterface->setCarrier(true);
128 }

Referenced by inet::Ieee802154Mac::handleStartOperation().

◆ handleStopOperation()

void inet::MacProtocolBase::handleStopOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

Reimplemented in inet::Ieee802154Mac, inet::CsmaCaMac, inet::EthernetMacBase, inet::ieee80211::Ieee80211Mac, inet::Ppp, and inet::AckingMac.

131 {
132  PacketDropDetails details;
133  details.setReason(INTERFACE_DOWN);
134  if (currentTxFrame)
135  dropCurrentTxFrame(details);
136  flushQueue(details);
137 
138  networkInterface->setCarrier(false);
139  networkInterface->setState(NetworkInterface::State::DOWN);
140 }

Referenced by inet::AckingMac::handleStopOperation(), inet::CsmaCaMac::handleStopOperation(), and inet::Ieee802154Mac::handleStopOperation().

◆ initialize()

◆ isInitializeStage()

virtual bool inet::MacProtocolBase::isInitializeStage ( int  stage) const
inlineoverrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

62 { return stage == INITSTAGE_LINK_LAYER; }

◆ isLowerMessage()

bool inet::MacProtocolBase::isLowerMessage ( cMessage *  message) const
overrideprotectedvirtual

Implements inet::LayeredProtocolBase.

79 {
80  return message->getArrivalGateId() == lowerLayerInGateId;
81 }

◆ isModuleStartStage()

virtual bool inet::MacProtocolBase::isModuleStartStage ( int  stage) const
inlineoverrideprotectedvirtual

◆ isModuleStopStage()

virtual bool inet::MacProtocolBase::isModuleStopStage ( int  stage) const
inlineoverrideprotectedvirtual

◆ isUpperMessage()

bool inet::MacProtocolBase::isUpperMessage ( cMessage *  message) const
overrideprotectedvirtual

Implements inet::LayeredProtocolBase.

74 {
75  return message->getArrivalGateId() == upperLayerInGateId;
76 }

◆ parseMacAddressParameter()

MacAddress inet::MacProtocolBase::parseMacAddressParameter ( const char *  addrstr)
protectedvirtual
25 {
26  MacAddress address;
27 
28  if (!strcmp(addrstr, "auto"))
29  // assign automatic address
31  else
32  address.setAddress(addrstr);
33 
34  return address;
35 }

Referenced by inet::ShortcutMac::configureNetworkInterface().

◆ receiveSignal()

void inet::MacProtocolBase::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
overrideprotectedvirtual

Reimplemented in inet::EthernetMacBase, and inet::Ppp.

152 {
153  Enter_Method("%s", cComponent::getSignalName(signalID));
154 }

Referenced by inet::Ppp::receiveSignal(), and inet::EthernetMacBase::receiveSignal().

◆ registerInterface()

void inet::MacProtocolBase::registerInterface ( )
protectedvirtual
53 {
54  ASSERT(networkInterface == nullptr);
57 }

Referenced by initialize().

◆ sendDown()

void inet::MacProtocolBase::sendDown ( cMessage *  message)
protectedvirtual
67 {
68  if (message->isPacket())
69  emit(packetSentToLowerSignal, message);
70  send(message, lowerLayerOutGateId);
71 }

◆ sendUp()

void inet::MacProtocolBase::sendUp ( cMessage *  message)
protectedvirtual

Reimplemented in inet::ieee80211::Ieee80211Mac.

60 {
61  if (message->isPacket())
62  emit(packetSentToUpperSignal, message);
63  send(message, upperLayerOutGateId);
64 }

Referenced by inet::ShortcutMac::receiveFromPeer(), and inet::ieee80211::Ieee80211Mac::sendUp().

Member Data Documentation

◆ currentTxFrame

◆ hostModule

opp_component_ptr<cModule> inet::MacProtocolBase::hostModule
protected

Referenced by initialize().

◆ lowerLayerInGateId

◆ lowerLayerOutGateId

int inet::MacProtocolBase::lowerLayerOutGateId = -1
protected

◆ networkInterface

◆ txQueue

◆ upperLayerInGateId

◆ upperLayerOutGateId

int inet::MacProtocolBase::upperLayerOutGateId = -1
protected

The documentation for this class was generated from the following files:
inet::MacProtocolBase::networkInterface
opp_component_ptr< NetworkInterface > networkInterface
Definition: MacProtocolBase.h:30
inet::findContainingNode
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:31
inet::MacProtocolBase::flushQueue
virtual void flushQueue(PacketDropDetails &details)
should clear queue and emit signal "packetDropped" with entire packets
Definition: MacProtocolBase.cc:106
inet::MacProtocolBase::upperLayerOutGateId
int upperLayerOutGateId
Definition: MacProtocolBase.h:25
inet::MacProtocolBase::registerInterface
virtual void registerInterface()
Definition: MacProtocolBase.cc:52
inet::OperationalMixin< cSimpleModule >::initialize
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
inet::getContainingNicModule
NetworkInterface * getContainingNicModule(const cModule *from)
Find the nic module (inside the networkNode) containing the given module.
Definition: NetworkInterface.cc:691
inet::MacProtocolBase::dropCurrentTxFrame
virtual void dropCurrentTxFrame(PacketDropDetails &details)
Definition: MacProtocolBase.cc:99
inet::packetDroppedSignal
simsignal_t packetDroppedSignal
Definition: Simsignals.cc:85
inet::MacProtocolBase::lowerLayerInGateId
int lowerLayerInGateId
Definition: MacProtocolBase.h:26
inet::units::units::g
milli< kg >::type g
Definition: Units.h:1071
inet::INITSTAGE_NETWORK_INTERFACE_CONFIGURATION
INET_API InitStage INITSTAGE_NETWORK_INTERFACE_CONFIGURATION
Initialization of network interfaces includes:
inet::MacAddress::generateAutoAddress
static MacAddress generateAutoAddress()
Generates a unique address which begins with 0a:aa and ends in a unique suffix.
Definition: MacAddress.cc:133
inet::MacProtocolBase::currentTxFrame
Packet * currentTxFrame
Currently transmitted frame if any.
Definition: MacProtocolBase.h:35
inet::ModuleStopOperation::STAGE_LINK_LAYER
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:54
inet::MacProtocolBase::upperLayerInGateId
int upperLayerInGateId
Gate ids.
Definition: MacProtocolBase.h:24
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::MacProtocolBase::deleteCurrentTxFrame
virtual void deleteCurrentTxFrame()
Definition: MacProtocolBase.cc:93
inet::MacProtocolBase::hostModule
opp_component_ptr< cModule > hostModule
Definition: MacProtocolBase.h:32
inet::MacProtocolBase::configureNetworkInterface
virtual void configureNetworkInterface()=0
inet::INTERFACE_DOWN
@ INTERFACE_DOWN
Definition: Simsignals_m.h:72
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::MacProtocolBase::lowerLayerOutGateId
int lowerLayerOutGateId
Definition: MacProtocolBase.h:27
inet::MacProtocolBase::dequeuePacket
virtual Packet * dequeuePacket()
Definition: MacProtocolBase.cc:175
inet::MacProtocolBase::clearQueue
virtual void clearQueue()
should clear queue silently
Definition: MacProtocolBase.cc:117
inet::packetSentToUpperSignal
simsignal_t packetSentToUpperSignal
Definition: Simsignals.cc:87
inet::MacProtocolBase::txQueue
opp_component_ptr< queueing::IPacketQueue > txQueue
Messages received from upper layer and to be transmitted later.
Definition: MacProtocolBase.h:38
inet::units::values::m
value< double, units::m > m
Definition: Units.h:1233
inet::ModuleStartOperation::STAGE_LINK_LAYER
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:28
inet::OperationalMixin< cSimpleModule >::handleMessageWhenDown
virtual void handleMessageWhenDown(cMessage *msg)
Definition: OperationalMixinImpl.h:71
inet::MacProtocolBase::canDequeuePacket
virtual bool canDequeuePacket() const
Definition: MacProtocolBase.cc:170
inet::INITSTAGE_LINK_LAYER
INET_API InitStage INITSTAGE_LINK_LAYER
Initialization of link-layer protocols.
inet::packetSentToLowerSignal
simsignal_t packetSentToLowerSignal
Definition: Simsignals.cc:90