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

Base class for MAC modules. More...

#include <MACBase.h>

Inheritance diagram for inet::MACBase:
inet::ILifecycle inet::EtherMACBase inet::ExtInterface inet::Loopback inet::PPP inet::TunInterface inet::EtherMAC inet::EtherMACFullDuplex

Public Member Functions

 MACBase ()
 
virtual ~MACBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
void registerInterface ()
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void updateOperationalFlag (bool isNodeUp)
 
virtual bool isNodeUp ()
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual InterfaceEntrycreateInterfaceEntry ()=0
 should create InterfaceEntry More...
 
virtual void flushQueue ()=0
 should clear queue and emit signal "dropPkFromHLIfaceDown" with entire packets More...
 
virtual void clearQueue ()=0
 should clear queue silently More...
 
virtual bool isUpperMsg (cMessage *msg)=0
 should return true if the msg arrived from upper layer, else return false More...
 

Protected Attributes

cModule * hostModule = nullptr
 
bool isOperational = false
 
InterfaceEntryinterfaceEntry = nullptr
 

Detailed Description

Base class for MAC modules.

Constructor & Destructor Documentation

inet::MACBase::MACBase ( )
inline
41 {}
inet::MACBase::~MACBase ( )
virtual
34 {
35 }

Member Function Documentation

virtual void inet::MACBase::clearQueue ( )
protectedpure virtual

should clear queue silently

Implemented in inet::EtherMACBase, inet::PPP, inet::ExtInterface, inet::Loopback, and inet::TunInterface.

Referenced by handleOperationStage().

virtual InterfaceEntry* inet::MACBase::createInterfaceEntry ( )
protectedpure virtual
virtual void inet::MACBase::flushQueue ( )
protectedpure virtual

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

Implemented in inet::EtherMACBase, inet::PPP, inet::ExtInterface, inet::Loopback, and inet::TunInterface.

Referenced by handleOperationStage().

void inet::MACBase::handleMessageWhenDown ( cMessage *  msg)
protectedvirtual

Referenced by inet::EtherMACFullDuplex::handleMessage(), inet::EtherMAC::handleMessage(), inet::Loopback::handleMessage(), inet::ExtInterface::handleMessage(), and inet::PPP::handleMessage().

109 {
110  if (isUpperMsg(msg) || msg->isSelfMessage()) { //FIXME remove 1st part -- it is not possible to ensure that no msg is sent by upper layer (race condition!!!)
111  throw cRuntimeError("Message received from higher layer while interface is off");
112  }
113  else {
114  EV << "Interface is turned off, dropping packet\n";
115  delete msg;
116  }
117 }
virtual bool isUpperMsg(cMessage *msg)=0
should return true if the msg arrived from upper layer, else return false
bool inet::MACBase::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overrideprotectedvirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

Reimplemented in inet::EtherMACBase.

Referenced by inet::EtherMACBase::handleOperationStage().

52 {
53  Enter_Method_Silent();
54 
55  if (dynamic_cast<NodeStartOperation *>(operation)) {
58  }
59  }
60  else if (dynamic_cast<NodeShutdownOperation *>(operation)) {
62  updateOperationalFlag(false);
63  flushQueue();
64  }
65  }
66  else if (dynamic_cast<NodeCrashOperation *>(operation)) {
68  updateOperationalFlag(false);
69  clearQueue();
70  }
71  }
72  else {
73  throw cRuntimeError("Unsupported operation '%s'", operation->getClassName());
74  }
75 
76  return true;
77 }
Definition: NodeOperations.h:49
Stage
Definition: NodeOperations.h:71
Stage
Definition: NodeOperations.h:126
Stage
Definition: NodeOperations.h:46
virtual void clearQueue()=0
should clear queue silently
virtual void updateOperationalFlag(bool isNodeUp)
Definition: MACBase.cc:93
virtual void flushQueue()=0
should clear queue and emit signal "dropPkFromHLIfaceDown" with entire packets
Definition: NodeOperations.h:127
Definition: NodeOperations.h:77
void inet::MACBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented in inet::EtherMACBase, inet::PPP, inet::ExtInterface, inet::Loopback, inet::TunInterface, inet::EtherMAC, and inet::EtherMACFullDuplex.

Referenced by inet::TunInterface::initialize(), inet::Loopback::initialize(), inet::ExtInterface::initialize(), inet::PPP::initialize(), and inet::EtherMACBase::initialize().

38 {
39  cSimpleModule::initialize(stage);
40 
41  if (stage == INITSTAGE_LOCAL) {
43  if (hostModule)
44  hostModule->subscribe(NF_INTERFACE_DELETED, this);
45  }
46  else if (stage == INITSTAGE_LINK_LAYER) {
47  updateOperationalFlag(isNodeUp()); // needs to be done when interface is already registered (=last stage)
48  }
49 }
cModule * hostModule
Definition: MACBase.h:36
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
Initialization of link-layer protocols.
Definition: InitStages.h:59
simsignal_t NF_INTERFACE_DELETED
Definition: NotifierConsts.cc:49
virtual bool isNodeUp()
Definition: MACBase.cc:87
virtual void updateOperationalFlag(bool isNodeUp)
Definition: MACBase.cc:93
bool inet::MACBase::isNodeUp ( )
protectedvirtual

Referenced by initialize(), and updateOperationalFlag().

88 {
89  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(hostModule->getSubmodule("status"));
90  return !nodeStatus || nodeStatus->getState() == NodeStatus::UP;
91 }
cModule * hostModule
Definition: MACBase.h:36
Definition: NodeStatus.h:40
virtual bool inet::MACBase::isUpperMsg ( cMessage *  msg)
protectedpure virtual

should return true if the msg arrived from upper layer, else return false

Implemented in inet::EtherMACBase, inet::PPP, inet::ExtInterface, inet::Loopback, and inet::TunInterface.

Referenced by handleMessageWhenDown().

virtual int inet::MACBase::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented in inet::EtherMACBase, inet::PPP, inet::ExtInterface, inet::Loopback, inet::TunInterface, inet::EtherMAC, and inet::EtherMACFullDuplex.

47 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::MACBase::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
overrideprotectedvirtual

Reimplemented in inet::EtherMACBase, and inet::PPP.

Referenced by inet::PPP::receiveSignal(), and inet::EtherMACBase::receiveSignal().

80 {
81  if (signalID == NF_INTERFACE_DELETED) {
82  if (interfaceEntry == check_and_cast<const InterfaceEntry *>(obj))
83  interfaceEntry = nullptr;
84  }
85 }
InterfaceEntry * interfaceEntry
Definition: MACBase.h:38
simsignal_t NF_INTERFACE_DELETED
Definition: NotifierConsts.cc:49
void inet::MACBase::registerInterface ( )
protected

Referenced by inet::TunInterface::initialize(), inet::Loopback::initialize(), inet::ExtInterface::initialize(), inet::PPP::initialize(), and inet::EtherMACBase::initialize().

99 {
100  ASSERT(interfaceEntry == nullptr);
101  IInterfaceTable *ift = findModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
102  if (ift) {
104  ift->addInterface(interfaceEntry);
105  }
106 }
InterfaceEntry * interfaceEntry
Definition: MACBase.h:38
virtual InterfaceEntry * createInterfaceEntry()=0
should create InterfaceEntry
void inet::MACBase::updateOperationalFlag ( bool  isNodeUp)
protectedvirtual

Referenced by handleOperationStage(), and initialize().

94 {
95  isOperational = isNodeUp; // TODO and interface is up, too
96 }
bool isOperational
Definition: MACBase.h:37
virtual bool isNodeUp()
Definition: MACBase.cc:87

Member Data Documentation

cModule* inet::MACBase::hostModule = nullptr
protected

Referenced by initialize(), and isNodeUp().


The documentation for this class was generated from the following files: