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

Base class for Ethernet MAC implementations. More...

#include <EtherMACBase.h>

Inheritance diagram for inet::EtherMACBase:
inet::MACBase inet::ILifecycle inet::EtherMAC inet::EtherMACFullDuplex

Classes

struct  EtherDescr
 
class  InnerQueue
 
class  MacQueue
 

Public Types

enum  MACTransmitState {
  TX_IDLE_STATE = 1, WAIT_IFG_STATE, SEND_IFG_STATE, TRANSMITTING_STATE,
  JAMMING_STATE, BACKOFF_STATE, PAUSE_STATE
}
 
enum  MACReceiveState { RX_IDLE_STATE = 1, RECEIVING_STATE, RX_COLLISION_STATE, RX_RECONNECT_STATE }
 

Public Member Functions

 EtherMACBase ()
 
virtual ~EtherMACBase ()
 
virtual MACAddress getMACAddress ()
 
double getTxRate ()
 
bool isActive ()
 
MACTransmitState getTransmitState ()
 
MACReceiveState getReceiveState ()
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
- Public Member Functions inherited from inet::MACBase
 MACBase ()
 
virtual ~MACBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Static Public Attributes

static const double SPEED_OF_LIGHT_IN_CABLE = 200000000.0
 
static simsignal_t dropPkIfaceDownSignal = registerSignal("dropPkIfaceDown")
 
static simsignal_t dropPkFromHLIfaceDownSignal = registerSignal("dropPkFromHLIfaceDown")
 

Protected Types

enum  SelfMsgKindValues {
  ENDIFG = 100, ENDRECEPTION, ENDBACKOFF, ENDTRANSMISSION,
  ENDJAMMING, ENDPAUSE
}
 
enum  { NUM_OF_ETHERDESCRS = 6 }
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void initializeFlags ()
 
virtual void initializeMACAddress ()
 
virtual void initializeQueueModule ()
 
virtual void initializeStatistics ()
 
virtual void finish () override
 
virtual bool dropFrameNotForUs (EtherFrame *frame)
 Checks destination address and drops the frame when frame is not for us; returns true if frame is dropped. More...
 
virtual void readChannelParameters (bool errorWhenAsymmetric)
 Calculates datarates, etc. More...
 
virtual void printParameters ()
 
virtual void getNextFrameFromQueue ()
 
virtual void requestNextFrameFromExtQueue ()
 
virtual void processConnectDisconnect ()
 
virtual EtherPhyFrameencapsulate (EtherFrame *phyFrame)
 
virtual EtherFramedecapsulate (EtherPhyFrame *phyFrame)
 
virtual InterfaceEntrycreateInterfaceEntry () override
 should create InterfaceEntry More...
 
virtual void flushQueue () override
 should clear queue and emit signal "dropPkFromHLIfaceDown" with entire packets More...
 
virtual void clearQueue () override
 should clear queue silently More...
 
virtual bool isUpperMsg (cMessage *msg) override
 should return true if the msg arrived from upper layer, else return false More...
 
virtual void refreshDisplay () const override
 
virtual void receiveSignal (cComponent *src, simsignal_t signalId, cObject *obj, cObject *details) override
 
virtual void refreshConnection ()
 
- Protected Member Functions inherited from inet::MACBase
void registerInterface ()
 
virtual void updateOperationalFlag (bool isNodeUp)
 
virtual bool isNodeUp ()
 
virtual void handleMessageWhenDown (cMessage *msg)
 

Protected Attributes

const EtherDescrcurEtherDescr = nullptr
 
MACAddress address
 
bool connected = false
 
bool disabled = false
 
bool promiscuous = false
 
bool duplexMode = false
 
bool frameBursting = false
 
MacQueue txQueue
 
cChannel * transmissionChannel = nullptr
 
cGate * physInGate = nullptr
 
cGate * physOutGate = nullptr
 
cGate * upperLayerInGate = nullptr
 
bool channelsDiffer = false
 
MACTransmitState transmitState = (MACTransmitState)-1
 
MACReceiveState receiveState = (MACReceiveState)-1
 
simtime_t lastTxFinishTime
 
int pauseUnitsRequested = 0
 
EtherFramecurTxFrame = nullptr
 
cMessage * endTxMsg = nullptr
 
cMessage * endIFGMsg = nullptr
 
cMessage * endPauseMsg = nullptr
 
unsigned long numFramesSent = 0
 
unsigned long numFramesReceivedOK = 0
 
unsigned long numBytesSent = 0
 
unsigned long numBytesReceivedOK = 0
 
unsigned long numFramesFromHL = 0
 
unsigned long numDroppedPkFromHLIfaceDown = 0
 
unsigned long numDroppedIfaceDown = 0
 
unsigned long numDroppedBitError = 0
 
unsigned long numDroppedNotForUs = 0
 
unsigned long numFramesPassedToHL = 0
 
unsigned long numPauseFramesRcvd = 0
 
unsigned long numPauseFramesSent = 0
 
- Protected Attributes inherited from inet::MACBase
cModule * hostModule = nullptr
 
bool isOperational = false
 
InterfaceEntryinterfaceEntry = nullptr
 

Static Protected Attributes

static const EtherDescr etherDescrs [NUM_OF_ETHERDESCRS]
 
static const EtherDescr nullEtherDescr
 
static simsignal_t txPkSignal = registerSignal("txPk")
 
static simsignal_t rxPkOkSignal = registerSignal("rxPkOk")
 
static simsignal_t txPausePkUnitsSignal = registerSignal("txPausePkUnits")
 
static simsignal_t rxPausePkUnitsSignal = registerSignal("rxPausePkUnits")
 
static simsignal_t rxPkFromHLSignal = registerSignal("rxPkFromHL")
 
static simsignal_t dropPkNotForUsSignal = registerSignal("dropPkNotForUs")
 
static simsignal_t dropPkBitErrorSignal = registerSignal("dropPkBitError")
 
static simsignal_t packetSentToLowerSignal = registerSignal("packetSentToLower")
 
static simsignal_t packetReceivedFromLowerSignal = registerSignal("packetReceivedFromLower")
 
static simsignal_t packetSentToUpperSignal = registerSignal("packetSentToUpper")
 
static simsignal_t packetReceivedFromUpperSignal = registerSignal("packetReceivedFromUpper")
 
static simsignal_t transmitStateSignal = registerSignal("transmitState")
 
static simsignal_t receiveStateSignal = registerSignal("receiveState")
 

Detailed Description

Base class for Ethernet MAC implementations.

Member Enumeration Documentation

anonymous enum
protected
Enumerator
NUM_OF_ETHERDESCRS 
74  {
76  };
Definition: EtherMACBase.h:75
Enumerator
RX_IDLE_STATE 
RECEIVING_STATE 
RX_COLLISION_STATE 
RX_RECONNECT_STATE 
56  {
57  RX_IDLE_STATE = 1,
61  };
Definition: EtherMACBase.h:58
Definition: EtherMACBase.h:59
Definition: EtherMACBase.h:57
Definition: EtherMACBase.h:60
Enumerator
TX_IDLE_STATE 
WAIT_IFG_STATE 
SEND_IFG_STATE 
TRANSMITTING_STATE 
JAMMING_STATE 
BACKOFF_STATE 
PAUSE_STATE 
46  {
47  TX_IDLE_STATE = 1,
54  };
Definition: EtherMACBase.h:49
Definition: EtherMACBase.h:52
Definition: EtherMACBase.h:47
Definition: EtherMACBase.h:53
Definition: EtherMACBase.h:50
Definition: EtherMACBase.h:51
Definition: EtherMACBase.h:48
Enumerator
ENDIFG 
ENDRECEPTION 
ENDBACKOFF 
ENDTRANSMISSION 
ENDJAMMING 
ENDPAUSE 
65  {
66  ENDIFG = 100,
68  ENDBACKOFF,
70  ENDJAMMING,
71  ENDPAUSE
72  };
Definition: EtherMACBase.h:70
Definition: EtherMACBase.h:67
Definition: EtherMACBase.h:66
Definition: EtherMACBase.h:68
Definition: EtherMACBase.h:69
Definition: EtherMACBase.h:71

Constructor & Destructor Documentation

inet::EtherMACBase::EtherMACBase ( )
138 {
139  lastTxFinishTime = -1.0; // never equals to current simtime
141 }
simtime_t lastTxFinishTime
Definition: EtherMACBase.h:151
static const EtherDescr nullEtherDescr
Definition: EtherMACBase.h:129
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
inet::EtherMACBase::~EtherMACBase ( )
virtual
144 {
145  delete curTxFrame;
146 
147  cancelAndDelete(endTxMsg);
148  cancelAndDelete(endIFGMsg);
149  cancelAndDelete(endPauseMsg);
150 }
cMessage * endIFGMsg
Definition: EtherMACBase.h:156
cMessage * endTxMsg
Definition: EtherMACBase.h:156
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
cMessage * endPauseMsg
Definition: EtherMACBase.h:156

Member Function Documentation

void inet::EtherMACBase::clearQueue ( )
overrideprotectedvirtual

should clear queue silently

Implements inet::MACBase.

440 {
441  if (txQueue.innerQueue)
443  else
444  txQueue.extQueue->clear(); // clear request count
445 }
virtual void clear()=0
Clear all queued packets and stored requests.
MacQueue txQueue
Definition: EtherMACBase.h:141
InnerQueue * innerQueue
Definition: EtherMACBase.h:115
IPassiveQueue * extQueue
Definition: EtherMACBase.h:116
void clear()
Definition: EtherMACBase.h:109
InterfaceEntry * inet::EtherMACBase::createInterfaceEntry ( )
overrideprotectedvirtual

should create InterfaceEntry

Implements inet::MACBase.

282 {
283  InterfaceEntry *interfaceEntry = new InterfaceEntry(this);
284 
285  // generate a link-layer address to be used as interface token for IPv6
286  interfaceEntry->setMACAddress(address);
287  interfaceEntry->setInterfaceToken(address.formInterfaceIdentifier());
288  //InterfaceToken token(0, getSimulation()->getUniqueNumber(), 64);
289  //interfaceEntry->setInterfaceToken(token);
290 
291  // MTU: typical values are 576 (Internet de facto), 1500 (Ethernet-friendly),
292  // 4000 (on some point-to-point links), 4470 (Cisco routers default, FDDI compatible)
293  interfaceEntry->setMtu(par("mtu").longValue());
294 
295  // capabilities
296  interfaceEntry->setMulticast(true);
297  interfaceEntry->setBroadcast(true);
298 
299  return interfaceEntry;
300 }
InterfaceEntry * interfaceEntry
Definition: MACBase.h:38
MACAddress address
Definition: EtherMACBase.h:133
InterfaceToken formInterfaceIdentifier() const
Create interface identifier (IEEE EUI-64) which can be used by IPv6 stateless address autoconfigurati...
Definition: MACAddress.cc:136
EtherFrame * inet::EtherMACBase::decapsulate ( EtherPhyFrame phyFrame)
protectedvirtual

Referenced by inet::EtherMAC::frameReceptionComplete(), inet::EtherMACFullDuplex::processMsgFromNetwork(), and inet::EtherMAC::processMsgFromNetwork().

400 {
401  if (phyFrame->getSrcMacFullDuplex() != duplexMode)
402  throw cRuntimeError("Ethernet misconfiguration: MACs on the same link must be all in full duplex mode, or all in half-duplex mode");
403 
404  cPacket *frame = phyFrame->decapsulate();
405  delete phyFrame;
406 
407  if (RawPacket *rawPacket = dynamic_cast<RawPacket *>(frame)) {
408  using namespace serializer;
409  Buffer b(rawPacket->getByteArray().getDataPtr(), rawPacket->getByteArray().getDataArraySize());
410  Context c;
412  if (!frame)
413  throw cRuntimeError("Could not deserialize RawPacket '%s' as Ethernet frame", rawPacket->getName());
414  delete rawPacket;
415  }
416  return check_and_cast<EtherFrame *>(frame);
417 }
bool duplexMode
Definition: EtherMACBase.h:137
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
static cPacket * lookupAndDeserialize(const Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
Definition: SerializerBase.cc:99
value< double, units::m > b
Definition: Units.h:1054
Definition: SerializerBase.h:45
Definition: SerializerBase.h:40
bool inet::EtherMACBase::dropFrameNotForUs ( EtherFrame frame)
protectedvirtual

Checks destination address and drops the frame when frame is not for us; returns true if frame is dropped.

Referenced by inet::EtherMAC::frameReceptionComplete(), and inet::EtherMACFullDuplex::processMsgFromNetwork().

459 {
460  // Current ethernet mac implementation does not support the configuration of multicast
461  // ethernet address groups. We rather accept all multicast frames (just like they were
462  // broadcasts) and pass it up to the higher layer where they will be dropped
463  // if not needed.
464  //
465  // PAUSE frames must be handled a bit differently because they are processed at
466  // this level. Multicast PAUSE frames should not be processed unless they have a
467  // destination of MULTICAST_PAUSE_ADDRESS. We drop all PAUSE frames that have a
468  // different muticast destination. (Note: Would the multicast ethernet addressing
469  // implemented, we could also process the PAUSE frames destined to any of our
470  // multicast adresses)
471  // All NON-PAUSE frames must be passed to the upper layer if the interface is
472  // in promiscuous mode.
473 
474  if (frame->getDest().equals(address))
475  return false;
476 
477  if (frame->getDest().isBroadcast())
478  return false;
479 
480  bool isPause = (dynamic_cast<EtherPauseFrame *>(frame) != nullptr);
481 
482  if (!isPause && (promiscuous || frame->getDest().isMulticast()))
483  return false;
484 
485  if (isPause && frame->getDest().equals(MACAddress::MULTICAST_PAUSE_ADDRESS))
486  return false;
487 
488  EV_WARN << "Frame `" << frame->getName() << "' not destined to us, discarding\n";
490  emit(dropPkNotForUsSignal, frame);
491  delete frame;
492  return true;
493 }
static simsignal_t dropPkNotForUsSignal
Definition: EtherMACBase.h:177
static const MACAddress MULTICAST_PAUSE_ADDRESS
The special multicast PAUSE MAC address, 01:80:C2:00:00:01.
Definition: MACAddress.h:63
bool promiscuous
Definition: EtherMACBase.h:136
MACAddress address
Definition: EtherMACBase.h:133
unsigned long numDroppedNotForUs
Definition: EtherMACBase.h:167
EtherPhyFrame * inet::EtherMACBase::encapsulate ( EtherFrame phyFrame)
protectedvirtual

Referenced by inet::EtherMACFullDuplex::startFrameTransmission(), and inet::EtherMAC::startFrameTransmission().

392 {
393  EtherPhyFrame *phyFrame = new EtherPhyFrame(frame->getName());
394  phyFrame->encapsulate(frame);
395  phyFrame->setSrcMacFullDuplex(duplexMode);
396  return phyFrame;
397 }
bool duplexMode
Definition: EtherMACBase.h:137
void inet::EtherMACBase::finish ( )
overrideprotectedvirtual

Reimplemented in inet::EtherMAC, and inet::EtherMACFullDuplex.

Referenced by inet::EtherMACFullDuplex::finish(), and inet::EtherMAC::finish().

601 {
602  if (!disabled) {
603  simtime_t t = simTime();
604  recordScalar("simulated time", t);
605  recordScalar("full-duplex", duplexMode);
606 
607  if (t > 0) {
608  recordScalar("frames/sec sent", numFramesSent / t);
609  recordScalar("frames/sec rcvd", numFramesReceivedOK / t);
610  recordScalar("bits/sec sent", (8.0 * numBytesSent) / t);
611  recordScalar("bits/sec rcvd", (8.0 * numBytesReceivedOK) / t);
612  }
613  }
614 }
unsigned long numFramesSent
Definition: EtherMACBase.h:159
unsigned long numFramesReceivedOK
Definition: EtherMACBase.h:160
bool disabled
Definition: EtherMACBase.h:135
bool duplexMode
Definition: EtherMACBase.h:137
unsigned long numBytesSent
Definition: EtherMACBase.h:161
unsigned long numBytesReceivedOK
Definition: EtherMACBase.h:162
void inet::EtherMACBase::flushQueue ( )
overrideprotectedvirtual

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

Implements inet::MACBase.

420 {
421  // code would look slightly nicer with a pop() function that returns nullptr if empty
422  if (txQueue.innerQueue) {
423  while (!txQueue.innerQueue->isEmpty()) {
424  cMessage *msg = (cMessage *)txQueue.innerQueue->pop();
425  emit(dropPkFromHLIfaceDownSignal, msg);
426  delete msg;
427  }
428  }
429  else {
430  while (!txQueue.extQueue->isEmpty()) {
431  cMessage *msg = txQueue.extQueue->pop();
432  emit(dropPkFromHLIfaceDownSignal, msg);
433  delete msg;
434  }
435  txQueue.extQueue->clear(); // clear request count
436  }
437 }
virtual void clear()=0
Clear all queued packets and stored requests.
MacQueue txQueue
Definition: EtherMACBase.h:141
InnerQueue * innerQueue
Definition: EtherMACBase.h:115
cObject * pop()
Definition: EtherMACBase.h:104
static simsignal_t dropPkFromHLIfaceDownSignal
Definition: EtherMACBase.h:192
IPassiveQueue * extQueue
Definition: EtherMACBase.h:116
virtual bool isEmpty()=0
Return true when queue is empty, otherwise return false.
bool isEmpty() const
Definition: EtherMACBase.h:105
virtual cMessage * pop()=0
Returns a packet directly from the queue, bypassing the primary, send-on-request mechanism.
virtual MACAddress inet::EtherMACBase::getMACAddress ( )
inlinevirtual
198 { return address; }
MACAddress address
Definition: EtherMACBase.h:133
void inet::EtherMACBase::getNextFrameFromQueue ( )
protectedvirtual

Referenced by inet::EtherMACFullDuplex::handleEndIFGPeriod(), inet::EtherMACFullDuplex::handleEndPausePeriod(), inet::EtherMAC::handleEndTxPeriod(), and inet::EtherMAC::handleRetransmission().

579 {
580  ASSERT(nullptr == curTxFrame);
581  if (txQueue.extQueue) {
584  }
585  else {
586  if (!txQueue.innerQueue->isEmpty())
587  curTxFrame = (EtherFrame *)txQueue.innerQueue->pop();
588  }
589 }
virtual void requestPacket()=0
The queue should send a packet whenever this method is invoked.
MacQueue txQueue
Definition: EtherMACBase.h:141
InnerQueue * innerQueue
Definition: EtherMACBase.h:115
cObject * pop()
Definition: EtherMACBase.h:104
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
IPassiveQueue * extQueue
Definition: EtherMACBase.h:116
virtual int getNumPendingRequests()=0
Returns number of pending requests.
bool isEmpty() const
Definition: EtherMACBase.h:105
MACReceiveState inet::EtherMACBase::getReceiveState ( )
inline
204 { return receiveState; }
MACReceiveState receiveState
Definition: EtherMACBase.h:150
MACTransmitState inet::EtherMACBase::getTransmitState ( )
inline
203 { return transmitState; }
MACTransmitState transmitState
Definition: EtherMACBase.h:149
double inet::EtherMACBase::getTxRate ( )
inline
200 { return curEtherDescr->txrate; }
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
double txrate
Definition: EtherMACBase.h:80
bool inet::EtherMACBase::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overridevirtual

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"

Reimplemented from inet::MACBase.

303 {
304  Enter_Method_Silent();
305  if (dynamic_cast<NodeStartOperation *>(operation)) {
307  initializeFlags();
310  }
311  }
312  else if (dynamic_cast<NodeShutdownOperation *>(operation)) {
314  connected = false;
316  }
317  }
318  else if (dynamic_cast<NodeCrashOperation *>(operation)) {
320  connected = false;
322  }
323  }
324  return MACBase::handleOperationStage(operation, stage, doneCallback);
325 }
bool connected
Definition: EtherMACBase.h:134
virtual bool handleOperationStage(LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
Perform one stage of a lifecycle operation.
Definition: MACBase.cc:51
virtual void initializeMACAddress()
Definition: EtherMACBase.cc:217
virtual void initializeFlags()
Definition: EtherMACBase.cc:233
Definition: NodeOperations.h:49
Stage
Definition: NodeOperations.h:71
Stage
Definition: NodeOperations.h:126
Stage
Definition: NodeOperations.h:46
virtual void initializeQueueModule()
Definition: EtherMACBase.cc:194
virtual void processConnectDisconnect()
Definition: EtherMACBase.cc:355
Definition: NodeOperations.h:127
Definition: NodeOperations.h:77
void inet::EtherMACBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::MACBase.

Reimplemented in inet::EtherMAC, and inet::EtherMACFullDuplex.

Referenced by inet::EtherMACFullDuplex::initialize(), and inet::EtherMAC::initialize().

153 {
154  MACBase::initialize(stage);
155 
156  if (stage == INITSTAGE_LOCAL) {
157  physInGate = gate("phys$i");
158  physOutGate = gate("phys$o");
159  upperLayerInGate = gate("upperLayerIn");
160  transmissionChannel = nullptr;
161  curTxFrame = nullptr;
162 
163  initializeFlags();
164 
167 
168  lastTxFinishTime = -1.0; // not equals with current simtime.
169 
170  // initialize self messages
171  endTxMsg = new cMessage("EndTransmission", ENDTRANSMISSION);
172  endIFGMsg = new cMessage("EndIFG", ENDIFG);
173  endPauseMsg = new cMessage("EndPause", ENDPAUSE);
174 
175  // initialize states
178  WATCH(transmitState);
179  WATCH(receiveState);
180 
181  // initialize pause
183  WATCH(pauseUnitsRequested);
184 
185  subscribe(POST_MODEL_CHANGE, this);
186  }
187  else if (stage == INITSTAGE_LINK_LAYER) {
188  registerInterface(); // needs MAC address //FIXME why not called in MACBase::initialize()?
190  readChannelParameters(true);
191  }
192 }
simtime_t lastTxFinishTime
Definition: EtherMACBase.h:151
cMessage * endIFGMsg
Definition: EtherMACBase.h:156
virtual void initializeStatistics()
Definition: EtherMACBase.cc:260
MACReceiveState receiveState
Definition: EtherMACBase.h:150
Definition: EtherMACBase.h:57
virtual void initializeMACAddress()
Definition: EtherMACBase.cc:217
cGate * physInGate
Definition: EtherMACBase.h:143
virtual void initializeFlags()
Definition: EtherMACBase.cc:233
Definition: EtherMACBase.h:66
cChannel * transmissionChannel
Definition: EtherMACBase.h:142
cMessage * endTxMsg
Definition: EtherMACBase.h:156
virtual void initialize(int stage) override
Definition: MACBase.cc:37
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
Definition: EtherMACBase.h:69
cMessage * endPauseMsg
Definition: EtherMACBase.h:156
Local initializations.
Definition: InitStages.h:35
Initialization of link-layer protocols.
Definition: InitStages.h:59
int pauseUnitsRequested
Definition: EtherMACBase.h:152
Definition: EtherMACBase.h:47
virtual void readChannelParameters(bool errorWhenAsymmetric)
Calculates datarates, etc.
Definition: EtherMACBase.cc:495
Definition: EtherMACBase.h:71
cGate * upperLayerInGate
Definition: EtherMACBase.h:145
virtual void initializeQueueModule()
Definition: EtherMACBase.cc:194
MACTransmitState transmitState
Definition: EtherMACBase.h:149
void registerInterface()
Definition: MACBase.cc:98
cGate * physOutGate
Definition: EtherMACBase.h:144
void inet::EtherMACBase::initializeFlags ( )
protectedvirtual

Reimplemented in inet::EtherMAC, and inet::EtherMACFullDuplex.

Referenced by handleOperationStage(), initialize(), inet::EtherMACFullDuplex::initializeFlags(), and inet::EtherMAC::initializeFlags().

234 {
235  duplexMode = true;
236 
237  // initialize connected flag
238  connected = physOutGate->getPathEndGate()->isConnected() && physInGate->getPathStartGate()->isConnected();
239 
240  if (!connected)
241  EV_WARN << "MAC not connected to a network.\n";
242 
243  WATCH(connected);
244 
245  // TODO: this should be set from the GUI
246  // initialize disabled flag
247  // Note: it is currently not supported to enable a disabled MAC at runtime.
248  // Difficulties: (1) autoconfig (2) how to pick up channel state (free, tx, collision etc)
249  disabled = false;
250  WATCH(disabled);
251 
252  // initialize promiscuous flag
253  promiscuous = par("promiscuous");
254  WATCH(promiscuous);
255 
256  frameBursting = false;
257  WATCH(frameBursting);
258 }
bool connected
Definition: EtherMACBase.h:134
bool disabled
Definition: EtherMACBase.h:135
bool frameBursting
Definition: EtherMACBase.h:138
bool duplexMode
Definition: EtherMACBase.h:137
cGate * physInGate
Definition: EtherMACBase.h:143
bool promiscuous
Definition: EtherMACBase.h:136
cGate * physOutGate
Definition: EtherMACBase.h:144
void inet::EtherMACBase::initializeMACAddress ( )
protectedvirtual

Referenced by handleOperationStage(), and initialize().

218 {
219  const char *addrstr = par("address");
220 
221  if (!strcmp(addrstr, "auto")) {
222  // assign automatic address
224 
225  // change module parameter from "auto" to concrete address
226  par("address").setStringValue(address.str().c_str());
227  }
228  else {
229  address.setAddress(addrstr);
230  }
231 }
MACAddress address
Definition: EtherMACBase.h:133
std::string str() const
Converts address to a hex string.
Definition: MACAddress.cc:121
void setAddress(const char *hexstr)
Converts address value from hex string (12 hex digits, may also contain spaces, hyphens and colons) ...
Definition: MACAddress.cc:102
static MACAddress generateAutoAddress()
Generates a unique address which begins with 0a:aa and ends in a unique suffix.
Definition: MACAddress.cc:143
void inet::EtherMACBase::initializeQueueModule ( )
protectedvirtual

Referenced by handleOperationStage(), and initialize().

195 {
196  if (par("queueModule").stringValue()[0]) {
197  cModule *module = getModuleFromPar<cModule>(par("queueModule"), this);
198  IPassiveQueue *queueModule;
199  if (module->isSimple())
200  queueModule = check_and_cast<IPassiveQueue *>(module);
201  else {
202  cGate *queueOut = module->gate("out")->getPathStartGate();
203  queueModule = check_and_cast<IPassiveQueue *>(queueOut->getOwnerModule());
204  }
205 
206  EV_DETAIL << "Requesting first frame from queue module\n";
207  txQueue.setExternalQueue(queueModule);
208 
211  }
212  else {
213  txQueue.setInternalQueue("txQueue", par("txQueueLimit").longValue());
214  }
215 }
void setInternalQueue(const char *name=nullptr, int limit=0)
Definition: EtherMACBase.h:123
virtual void requestPacket()=0
The queue should send a packet whenever this method is invoked.
MacQueue txQueue
Definition: EtherMACBase.h:141
IPassiveQueue * extQueue
Definition: EtherMACBase.h:116
#define stringValue()
Definition: NedFunctions.cc:24
void setExternalQueue(IPassiveQueue *_extQueue)
Definition: EtherMACBase.h:121
virtual int getNumPendingRequests()=0
Returns number of pending requests.
void inet::EtherMACBase::initializeStatistics ( )
protectedvirtual

Reimplemented in inet::EtherMAC, and inet::EtherMACFullDuplex.

Referenced by initialize(), inet::EtherMACFullDuplex::initializeStatistics(), and inet::EtherMAC::initializeStatistics().

261 {
266 
267  WATCH(numFramesSent);
268  WATCH(numFramesReceivedOK);
269  WATCH(numBytesSent);
270  WATCH(numBytesReceivedOK);
271  WATCH(numFramesFromHL);
273  WATCH(numDroppedIfaceDown);
274  WATCH(numDroppedBitError);
275  WATCH(numDroppedNotForUs);
276  WATCH(numFramesPassedToHL);
277  WATCH(numPauseFramesRcvd);
278  WATCH(numPauseFramesSent);
279 }
unsigned long numPauseFramesSent
Definition: EtherMACBase.h:170
unsigned long numFramesSent
Definition: EtherMACBase.h:159
unsigned long numFramesReceivedOK
Definition: EtherMACBase.h:160
unsigned long numDroppedIfaceDown
Definition: EtherMACBase.h:165
unsigned long numFramesFromHL
Definition: EtherMACBase.h:163
unsigned long numPauseFramesRcvd
Definition: EtherMACBase.h:169
unsigned long numDroppedPkFromHLIfaceDown
Definition: EtherMACBase.h:164
unsigned long numDroppedNotForUs
Definition: EtherMACBase.h:167
unsigned long numBytesSent
Definition: EtherMACBase.h:161
unsigned long numBytesReceivedOK
Definition: EtherMACBase.h:162
unsigned long numDroppedBitError
Definition: EtherMACBase.h:166
unsigned long numFramesPassedToHL
Definition: EtherMACBase.h:168
bool inet::EtherMACBase::isActive ( )
inline
201 { return connected && !disabled; }
bool connected
Definition: EtherMACBase.h:134
bool disabled
Definition: EtherMACBase.h:135
virtual bool inet::EtherMACBase::isUpperMsg ( cMessage *  msg)
inlineoverrideprotectedvirtual

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

Implements inet::MACBase.

241 { return msg->getArrivalGate() == upperLayerInGate; }
cGate * upperLayerInGate
Definition: EtherMACBase.h:145
virtual int inet::EtherMACBase::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::MACBase.

Reimplemented in inet::EtherMAC, and inet::EtherMACFullDuplex.

211 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::EtherMACBase::printParameters ( )
protectedvirtual
564 {
565  // Dump parameters
566  EV_DETAIL << "MAC address: " << address << (promiscuous ? ", promiscuous mode" : "") << endl
567  << "txrate: " << curEtherDescr->txrate << ", "
568  << (duplexMode ? "full-duplex" : "half-duplex") << endl;
569 #if 1
570  EV_DETAIL << "bitTime: " << 1.0 / curEtherDescr->txrate << endl;
571  EV_DETAIL << "frameBursting: " << frameBursting << endl;
572  EV_DETAIL << "slotTime: " << curEtherDescr->slotTime << endl;
573  EV_DETAIL << "interFrameGap: " << INTERFRAME_GAP_BITS / curEtherDescr->txrate << endl;
574  EV_DETAIL << endl;
575 #endif // if 1
576 }
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
bool frameBursting
Definition: EtherMACBase.h:138
bool duplexMode
Definition: EtherMACBase.h:137
bool promiscuous
Definition: EtherMACBase.h:136
MACAddress address
Definition: EtherMACBase.h:133
double txrate
Definition: EtherMACBase.h:80
double slotTime
Definition: EtherMACBase.h:88
#define INTERFRAME_GAP_BITS
Definition: Ethernet.h:33
void inet::EtherMACBase::processConnectDisconnect ( )
protectedvirtual

Reimplemented in inet::EtherMAC.

Referenced by handleOperationStage(), inet::EtherMAC::processConnectDisconnect(), and refreshConnection().

356 {
357  if (!connected) {
358  cancelEvent(endTxMsg);
359  cancelEvent(endIFGMsg);
360  cancelEvent(endPauseMsg);
361 
362  if (curTxFrame) {
363  delete curTxFrame;
364  curTxFrame = nullptr;
365  lastTxFinishTime = -1.0; // so that it never equals to the current simtime, used for Burst mode detection.
366  }
367 
368  if (txQueue.extQueue) {
369  // Clear external queue: send a request, and received packet will be deleted in handleMessage()
372  }
373  else {
374  // Clear inner queue
375  while (!txQueue.innerQueue->isEmpty()) {
376  cMessage *msg = check_and_cast<cMessage *>(txQueue.innerQueue->pop());
377  EV_DETAIL << "Interface is not connected, dropping packet " << msg << endl;
379  emit(dropPkIfaceDownSignal, msg);
380  delete msg;
381  }
382  }
383 
388  }
389 }
simtime_t lastTxFinishTime
Definition: EtherMACBase.h:151
virtual void requestPacket()=0
The queue should send a packet whenever this method is invoked.
cMessage * endIFGMsg
Definition: EtherMACBase.h:156
bool connected
Definition: EtherMACBase.h:134
MACReceiveState receiveState
Definition: EtherMACBase.h:150
Definition: EtherMACBase.h:57
MacQueue txQueue
Definition: EtherMACBase.h:141
static simsignal_t receiveStateSignal
Definition: EtherMACBase.h:187
cMessage * endTxMsg
Definition: EtherMACBase.h:156
InnerQueue * innerQueue
Definition: EtherMACBase.h:115
cObject * pop()
Definition: EtherMACBase.h:104
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
cMessage * endPauseMsg
Definition: EtherMACBase.h:156
static simsignal_t transmitStateSignal
Definition: EtherMACBase.h:186
unsigned long numDroppedPkFromHLIfaceDown
Definition: EtherMACBase.h:164
IPassiveQueue * extQueue
Definition: EtherMACBase.h:116
Definition: EtherMACBase.h:47
MACTransmitState transmitState
Definition: EtherMACBase.h:149
static simsignal_t dropPkIfaceDownSignal
Definition: EtherMACBase.h:191
virtual int getNumPendingRequests()=0
Returns number of pending requests.
bool isEmpty() const
Definition: EtherMACBase.h:105
void inet::EtherMACBase::readChannelParameters ( bool  errorWhenAsymmetric)
protectedvirtual

Calculates datarates, etc.

Verifies the datarates on the incoming/outgoing channels, and throws error when they differ and the parameter errorWhenAsymmetric is true.

Reimplemented in inet::EtherMAC.

Referenced by inet::EtherMACFullDuplex::handleMessage(), initialize(), inet::EtherMAC::readChannelParameters(), and refreshConnection().

496 {
497  // When the connected channels change at runtime, we'll receive
498  // two separate notifications (one for the rx channel and one for the tx one),
499  // so we cannot immediately raise an error when they differ. Rather, we'll need
500  // to verify at the next opportunity (event) that the two channels have eventually
501  // been set to the same value.
502 
503  cDatarateChannel *outTrChannel = check_and_cast_nullable<cDatarateChannel *>(physOutGate->findTransmissionChannel());
504  cDatarateChannel *inTrChannel = check_and_cast_nullable<cDatarateChannel *>(physInGate->findIncomingTransmissionChannel());
505 
506  connected = physOutGate->getPathEndGate()->isConnected() && physInGate->getPathStartGate()->isConnected();
507 
508  if (connected && ((!outTrChannel) || (!inTrChannel)))
509  throw cRuntimeError("Ethernet phys gate must be connected using a transmission channel");
510 
511  double txRate = outTrChannel ? outTrChannel->getNominalDatarate() : 0.0;
512  double rxRate = inTrChannel ? inTrChannel->getNominalDatarate() : 0.0;
513 
514  bool rxDisabled = !inTrChannel || inTrChannel->isDisabled();
515  bool txDisabled = !outTrChannel || outTrChannel->isDisabled();
516 
517  if (errorWhenAsymmetric && (rxDisabled != txDisabled))
518  throw cRuntimeError("The enablements of the input/output channels differ (rx=%s vs tx=%s)", rxDisabled ? "off" : "on", txDisabled ? "off" : "on");
519 
520  if (txDisabled)
521  connected = false;
522 
523  bool dataratesDiffer;
524  if (!connected) {
526  dataratesDiffer = false;
527  if (!outTrChannel)
528  transmissionChannel = nullptr;
529  if (interfaceEntry) {
530  interfaceEntry->setCarrier(false);
532  }
533  }
534  else {
535  if (outTrChannel && !transmissionChannel)
536  outTrChannel->subscribe(POST_MODEL_CHANGE, this);
537  transmissionChannel = outTrChannel;
538  dataratesDiffer = (txRate != rxRate);
539  }
540 
541  channelsDiffer = dataratesDiffer || (rxDisabled != txDisabled);
542 
543  if (errorWhenAsymmetric && dataratesDiffer)
544  throw cRuntimeError("The input/output datarates differ (rx=%g bps vs tx=%g bps)", rxRate, txRate);
545 
546  if (connected) {
547  // Check valid speeds
548  for (auto & etherDescr : etherDescrs) {
549  if (txRate == etherDescr.txrate) {
550  curEtherDescr = &(etherDescr);
551  if (interfaceEntry) {
552  interfaceEntry->setCarrier(true);
553  interfaceEntry->setDatarate(txRate);
554  }
555  return;
556  }
557  }
558  throw cRuntimeError("Invalid transmission rate %g bps on channel %s at module %s",
559  txRate, transmissionChannel->getFullPath().c_str(), getFullPath().c_str());
560  }
561 }
static const EtherDescr nullEtherDescr
Definition: EtherMACBase.h:129
bool channelsDiffer
Definition: EtherMACBase.h:148
virtual void setDatarate(double d)
Definition: InterfaceEntry.h:214
bool connected
Definition: EtherMACBase.h:134
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
InterfaceEntry * interfaceEntry
Definition: MACBase.h:38
cGate * physInGate
Definition: EtherMACBase.h:143
virtual void setCarrier(bool b)
Definition: InterfaceEntry.h:209
cChannel * transmissionChannel
Definition: EtherMACBase.h:142
static const EtherDescr etherDescrs[NUM_OF_ETHERDESCRS]
Definition: EtherMACBase.h:128
cGate * physOutGate
Definition: EtherMACBase.h:144
void inet::EtherMACBase::receiveSignal ( cComponent *  src,
simsignal_t  signalId,
cObject *  obj,
cObject *  details 
)
overrideprotectedvirtual

Reimplemented from inet::MACBase.

328 {
329  Enter_Method_Silent();
330 
331  MACBase::receiveSignal(source, signalID, obj, details);
332 
333  if (signalID != POST_MODEL_CHANGE)
334  return;
335 
336  if (dynamic_cast<cPostPathCreateNotification *>(obj)) {
337  cPostPathCreateNotification *gcobj = (cPostPathCreateNotification *)obj;
338 
339  if ((physOutGate == gcobj->pathStartGate) || (physInGate == gcobj->pathEndGate))
341  }
342  else if (dynamic_cast<cPostPathCutNotification *>(obj)) {
343  cPostPathCutNotification *gcobj = (cPostPathCutNotification *)obj;
344 
345  if ((physOutGate == gcobj->pathStartGate) || (physInGate == gcobj->pathEndGate))
347  }
348  else if (transmissionChannel && dynamic_cast<cPostParameterChangeNotification *>(obj)) { // note: we are subscribed to the channel object too
349  cPostParameterChangeNotification *gcobj = (cPostParameterChangeNotification *)obj;
350  if (transmissionChannel == gcobj->par->getOwner())
352  }
353 }
cGate * physInGate
Definition: EtherMACBase.h:143
cChannel * transmissionChannel
Definition: EtherMACBase.h:142
virtual void refreshConnection()
Definition: EtherMACBase.cc:447
virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
Definition: MACBase.cc:79
cGate * physOutGate
Definition: EtherMACBase.h:144
void inet::EtherMACBase::refreshConnection ( )
protectedvirtual

Referenced by receiveSignal().

448 {
449  Enter_Method_Silent();
450 
451  bool oldConn = connected;
452  readChannelParameters(false);
453 
454  if (oldConn != connected)
456 }
bool connected
Definition: EtherMACBase.h:134
virtual void readChannelParameters(bool errorWhenAsymmetric)
Calculates datarates, etc.
Definition: EtherMACBase.cc:495
virtual void processConnectDisconnect()
Definition: EtherMACBase.cc:355
void inet::EtherMACBase::refreshDisplay ( ) const
overrideprotectedvirtual
617 {
618  // icon coloring
619  const char *color;
620 
622  color = "red";
623  else if (transmitState == TRANSMITTING_STATE)
624  color = "yellow";
625  else if (transmitState == JAMMING_STATE)
626  color = "red";
627  else if (receiveState == RECEIVING_STATE)
628  color = "#4040ff";
629  else if (transmitState == BACKOFF_STATE)
630  color = "white";
631  else if (transmitState == PAUSE_STATE)
632  color = "gray";
633  else
634  color = "";
635 
636  getDisplayString().setTagArg("i", 1, color);
637 
638  if (!strcmp(getParentModule()->getNedTypeName(), "inet.linklayer.ethernet.EthernetInterface"))
639  getParentModule()->getDisplayString().setTagArg("i", 1, color);
640 
641 #if 0
642  // this code works but didn't turn out to be very useful
643  const char *txStateName;
644 
645  switch (transmitState) {
646  case TX_IDLE_STATE:
647  txStateName = "IDLE";
648  break;
649 
650  case WAIT_IFG_STATE:
651  txStateName = "WAIT_IFG";
652  break;
653 
654  case SEND_IFG_STATE:
655  txStateName = "SEND_IFG";
656  break;
657 
658  case TRANSMITTING_STATE:
659  txStateName = "TX";
660  break;
661 
662  case JAMMING_STATE:
663  txStateName = "JAM";
664  break;
665 
666  case BACKOFF_STATE:
667  txStateName = "BACKOFF";
668  break;
669 
670  case PAUSE_STATE:
671  txStateName = "PAUSE";
672  break;
673 
674  default:
675  throw cRuntimeError("wrong tx state");
676  }
677 
678  const char *rxStateName;
679 
680  switch (receiveState) {
681  case RX_IDLE_STATE:
682  rxStateName = "IDLE";
683  break;
684 
685  case RECEIVING_STATE:
686  rxStateName = "RX";
687  break;
688 
689  case RX_COLLISION_STATE:
690  rxStateName = "COLL";
691  break;
692 
693  default:
694  throw cRuntimeError("wrong rx state");
695  }
696 
697  char buf[80];
698  sprintf(buf, "tx:%s rx: %s\n#boff:%d #cTx:%d",
699  txStateName, rxStateName, backoffs, numConcurrentTransmissions);
700  getDisplayString().setTagArg("t", 0, buf);
701 #endif // if 0
702 }
Definition: EtherMACBase.h:58
Definition: EtherMACBase.h:59
MACReceiveState receiveState
Definition: EtherMACBase.h:150
Definition: EtherMACBase.h:57
Definition: EtherMACBase.h:49
Definition: EtherMACBase.h:52
Definition: EtherMACBase.h:47
Definition: EtherMACBase.h:53
MACTransmitState transmitState
Definition: EtherMACBase.h:149
Definition: EtherMACBase.h:50
Definition: EtherMACBase.h:51
Definition: EtherMACBase.h:48
void inet::EtherMACBase::requestNextFrameFromExtQueue ( )
protectedvirtual

Referenced by inet::EtherMACFullDuplex::processFrameFromUpperLayer(), and inet::EtherMAC::processFrameFromUpperLayer().

592 {
593  ASSERT(nullptr == curTxFrame);
594  if (txQueue.extQueue) {
597  }
598 }
virtual void requestPacket()=0
The queue should send a packet whenever this method is invoked.
MacQueue txQueue
Definition: EtherMACBase.h:141
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
IPassiveQueue * extQueue
Definition: EtherMACBase.h:116
virtual int getNumPendingRequests()=0
Returns number of pending requests.

Member Data Documentation

bool inet::EtherMACBase::channelsDiffer = false
protected
simsignal_t inet::EtherMACBase::dropPkBitErrorSignal = registerSignal("dropPkBitError")
staticprotected
simsignal_t inet::EtherMACBase::dropPkNotForUsSignal = registerSignal("dropPkNotForUs")
staticprotected

Referenced by dropFrameNotForUs().

const EtherMACBase::EtherDescr inet::EtherMACBase::etherDescrs
staticprotected

Referenced by readChannelParameters().

const EtherMACBase::EtherDescr inet::EtherMACBase::nullEtherDescr
staticprotected
Initial value:
= {
0.0,
0.0,
0,
0,
0,
0,
0,
0.0,
0.0
}

Referenced by EtherMACBase(), and readChannelParameters().

unsigned long inet::EtherMACBase::numBytesReceivedOK = 0
protected
unsigned long inet::EtherMACBase::numBytesSent = 0
protected
unsigned long inet::EtherMACBase::numDroppedBitError = 0
protected
unsigned long inet::EtherMACBase::numDroppedIfaceDown = 0
protected
unsigned long inet::EtherMACBase::numDroppedNotForUs = 0
protected
unsigned long inet::EtherMACBase::numDroppedPkFromHLIfaceDown = 0
protected
unsigned long inet::EtherMACBase::numFramesFromHL = 0
protected
unsigned long inet::EtherMACBase::numFramesPassedToHL = 0
protected
unsigned long inet::EtherMACBase::numFramesReceivedOK = 0
protected
unsigned long inet::EtherMACBase::numFramesSent = 0
protected
unsigned long inet::EtherMACBase::numPauseFramesRcvd = 0
protected
unsigned long inet::EtherMACBase::numPauseFramesSent = 0
protected
simsignal_t inet::EtherMACBase::packetReceivedFromLowerSignal = registerSignal("packetReceivedFromLower")
staticprotected
simsignal_t inet::EtherMACBase::packetReceivedFromUpperSignal = registerSignal("packetReceivedFromUpper")
staticprotected
simsignal_t inet::EtherMACBase::packetSentToLowerSignal = registerSignal("packetSentToLower")
staticprotected
simsignal_t inet::EtherMACBase::packetSentToUpperSignal = registerSignal("packetSentToUpper")
staticprotected
bool inet::EtherMACBase::promiscuous = false
protected
simsignal_t inet::EtherMACBase::rxPausePkUnitsSignal = registerSignal("rxPausePkUnits")
staticprotected
simsignal_t inet::EtherMACBase::rxPkFromHLSignal = registerSignal("rxPkFromHL")
staticprotected
simsignal_t inet::EtherMACBase::rxPkOkSignal = registerSignal("rxPkOk")
staticprotected
const double inet::EtherMACBase::SPEED_OF_LIGHT_IN_CABLE = 200000000.0
static
simsignal_t inet::EtherMACBase::txPausePkUnitsSignal = registerSignal("txPausePkUnits")
staticprotected
simsignal_t inet::EtherMACBase::txPkSignal = registerSignal("txPk")
staticprotected
cGate* inet::EtherMACBase::upperLayerInGate = nullptr
protected

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