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

Ethernet MAC module which supports both half-duplex (CSMA/CD) and full-duplex operation. More...

#include <EtherMAC.h>

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

Classes

struct  PkIdRxTime
 

Public Member Functions

 EtherMAC ()
 
virtual ~EtherMAC ()
 
- Public Member Functions inherited from inet::EtherMACBase
 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 ()
 

Protected Types

typedef std::list< PkIdRxTimeEndRxTimeList
 
- Protected Types inherited from inet::EtherMACBase
enum  SelfMsgKindValues {
  ENDIFG = 100, ENDRECEPTION, ENDBACKOFF, ENDTRANSMISSION,
  ENDJAMMING, ENDPAUSE
}
 
enum  { NUM_OF_ETHERDESCRS = 6 }
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void initializeFlags () override
 
virtual void initializeStatistics () override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void finish () override
 
virtual void handleSelfMessage (cMessage *msg)
 
virtual void handleEndIFGPeriod ()
 
virtual void handleEndPausePeriod ()
 
virtual void handleEndTxPeriod ()
 
virtual void handleEndRxPeriod ()
 
virtual void handleEndBackoffPeriod ()
 
virtual void handleEndJammingPeriod ()
 
virtual void handleRetransmission ()
 
virtual void readChannelParameters (bool errorWhenAsymmetric) override
 Calculates datarates, etc. More...
 
virtual void processFrameFromUpperLayer (EtherFrame *msg)
 
virtual void processMsgFromNetwork (cPacket *msg)
 
virtual void scheduleEndIFGPeriod ()
 
virtual void fillIFGIfInBurst ()
 
virtual void scheduleEndTxPeriod (int64_t sentFrameByteLength)
 
virtual void scheduleEndRxPeriod (cPacket *)
 
virtual void scheduleEndPausePeriod (int pauseUnits)
 
virtual void beginSendFrames ()
 
virtual void sendJamSignal ()
 
virtual void startFrameTransmission ()
 
virtual void frameReceptionComplete ()
 
virtual void processReceivedDataFrame (EtherFrame *frame)
 
virtual void processReceivedJam (EtherJam *jam)
 
virtual void processReceivedPauseFrame (EtherPauseFrame *frame)
 
virtual void processConnectDisconnect () override
 
virtual void addReception (simtime_t endRxTime)
 
virtual void addReceptionInReconnectState (long id, simtime_t endRxTime)
 
virtual void processDetectedCollision ()
 
virtual void printState ()
 
- Protected Member Functions inherited from inet::EtherMACBase
virtual void initializeMACAddress ()
 
virtual void initializeQueueModule ()
 
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 printParameters ()
 
virtual void getNextFrameFromQueue ()
 
virtual void requestNextFrameFromExtQueue ()
 
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

int numConcurrentTransmissions = 0
 
int backoffs = 0
 
long currentSendPkTreeID = -1
 
cPacket * frameBeingReceived = nullptr
 
cMessage * endRxMsg = nullptr
 
cMessage * endBackoffMsg = nullptr
 
cMessage * endJammingMsg = nullptr
 
EndRxTimeList endRxTimeList
 
simtime_t totalCollisionTime
 
simtime_t totalSuccessfulRxTxTime
 
simtime_t channelBusySince
 
unsigned long numCollisions = 0
 
unsigned long numBackoffs = 0
 
unsigned int framesSentInBurst = 0
 
long bytesSentInBurst = 0
 
- Protected Attributes inherited from inet::EtherMACBase
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 simsignal_t collisionSignal = registerSignal("collision")
 
static simsignal_t backoffSignal = registerSignal("backoff")
 
- Static Protected Attributes inherited from inet::EtherMACBase
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")
 

Additional Inherited Members

- Public Types inherited from inet::EtherMACBase
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 }
 
- Static Public Attributes inherited from inet::EtherMACBase
static const double SPEED_OF_LIGHT_IN_CABLE = 200000000.0
 
static simsignal_t dropPkIfaceDownSignal = registerSignal("dropPkIfaceDown")
 
static simsignal_t dropPkFromHLIfaceDownSignal = registerSignal("dropPkFromHLIfaceDown")
 

Detailed Description

Ethernet MAC module which supports both half-duplex (CSMA/CD) and full-duplex operation.

(See also EtherMACFullDuplex which has a considerably smaller code with all the CSMA/CD complexity removed.)

See NED file for more details.

Member Typedef Documentation

typedef std::list<PkIdRxTime> inet::EtherMAC::EndRxTimeList
protected

Constructor & Destructor Documentation

inet::EtherMAC::EtherMAC ( )
inline
41 {}
inet::EtherMAC::~EtherMAC ( )
virtual
48 {
49  delete frameBeingReceived;
50  cancelAndDelete(endRxMsg);
51  cancelAndDelete(endBackoffMsg);
52  cancelAndDelete(endJammingMsg);
53 }
cMessage * endBackoffMsg
Definition: EtherMAC.h:61
cMessage * endRxMsg
Definition: EtherMAC.h:60
cMessage * endJammingMsg
Definition: EtherMAC.h:62
cPacket * frameBeingReceived
Definition: EtherMAC.h:59

Member Function Documentation

void inet::EtherMAC::addReception ( simtime_t  endRxTime)
protectedvirtual

Referenced by processMsgFromNetwork(), and scheduleEndRxPeriod().

300 {
302 
303  if (endRxMsg->getArrivalTime() < endRxTime) {
304  cancelEvent(endRxMsg);
305  scheduleAt(endRxTime, endRxMsg);
306  }
307 }
int numConcurrentTransmissions
Definition: EtherMAC.h:54
cMessage * endRxMsg
Definition: EtherMAC.h:60
void inet::EtherMAC::addReceptionInReconnectState ( long  id,
simtime_t  endRxTime 
)
protectedvirtual

Referenced by processConnectDisconnect(), and processMsgFromNetwork().

267 {
268  // note: packetTreeId==-1 is legal, and represents a special entry that marks the end of the reconnect state
269 
270  // housekeeping: remove expired entries from endRxTimeList
271  simtime_t now = simTime();
272  while (!endRxTimeList.empty() && endRxTimeList.front().endTime <= now)
273  endRxTimeList.pop_front();
274 
275  // remove old entry with same packet tree ID (typically: a frame reception
276  // doesn't go through but is canceled by a jam signal)
277  auto i = endRxTimeList.begin();
278  for ( ; i != endRxTimeList.end(); i++) {
279  if (i->packetTreeId == packetTreeId) {
280  endRxTimeList.erase(i);
281  break;
282  }
283  }
284 
285  // find insertion position and insert new entry (list is ordered by endRxTime)
286  for (i = endRxTimeList.begin(); i != endRxTimeList.end() && i->endTime <= endRxTime; i++)
287  ;
288  PkIdRxTime item(packetTreeId, endRxTime);
289  endRxTimeList.insert(i, item);
290 
291  // adjust endRxMsg if needed (we'll exit reconnect mode when endRxMsg expires)
292  simtime_t maxRxTime = endRxTimeList.back().endTime;
293  if (endRxMsg->getArrivalTime() != maxRxTime) {
294  cancelEvent(endRxMsg);
295  scheduleAt(maxRxTime, endRxMsg);
296  }
297 }
EndRxTimeList endRxTimeList
Definition: EtherMAC.h:73
cMessage * endRxMsg
Definition: EtherMAC.h:60
void inet::EtherMAC::beginSendFrames ( )
protectedvirtual

Referenced by handleEndIFGPeriod(), handleEndPausePeriod(), and handleRetransmission().

893 {
894  if (curTxFrame) {
895  // Other frames are queued, therefore wait IFG period and transmit next frame
896  EV_DETAIL << "Will transmit next frame in output queue after IFG period\n";
898  }
899  else {
900  // No more frames, set transmitter to idle
903  EV_DETAIL << "No more frames to send, transmitter set to idle\n";
904  }
905 }
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
static simsignal_t transmitStateSignal
Definition: EtherMACBase.h:186
virtual void startFrameTransmission()
Definition: EtherMAC.cc:466
Definition: EtherMACBase.h:47
MACTransmitState transmitState
Definition: EtherMACBase.h:149
void inet::EtherMAC::fillIFGIfInBurst ( )
protectedvirtual

Referenced by handleEndTxPeriod(), and processFrameFromUpperLayer().

838 {
839  if (!frameBursting)
840  return;
841 
842  EV_TRACE << "fillIFGIfInBurst(): t=" << simTime() << ", framesSentInBurst=" << framesSentInBurst << ", bytesSentInBurst=" << bytesSentInBurst << endl;
843 
844  if (curTxFrame
845  && endIFGMsg->isScheduled()
847  && (simTime() == lastTxFinishTime)
848  && (simTime() == endIFGMsg->getSendingTime())
849  && (framesSentInBurst > 0)
851  && (bytesSentInBurst + (INTERFRAME_GAP_BITS / 8) + PREAMBLE_BYTES + SFD_BYTES + curTxFrame->getByteLength()
853  )
854  {
855  EtherFilledIFG *gap = new EtherFilledIFG("FilledIFG");
856  bytesSentInBurst += gap->getByteLength();
857  currentSendPkTreeID = gap->getTreeId();
858  send(gap, physOutGate);
861  cancelEvent(endIFGMsg);
862  scheduleAt(transmissionChannel->getTransmissionFinishTime(), endIFGMsg);
863  }
864  else {
865  bytesSentInBurst = 0;
866  framesSentInBurst = 0;
867  }
868 }
simtime_t lastTxFinishTime
Definition: EtherMACBase.h:151
cMessage * endIFGMsg
Definition: EtherMACBase.h:156
#define SFD_BYTES
Definition: Ethernet.h:46
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
bool frameBursting
Definition: EtherMACBase.h:138
cChannel * transmissionChannel
Definition: EtherMACBase.h:142
Definition: EtherMACBase.h:49
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
int64 maxBytesInBurst
Definition: EtherMACBase.h:85
static simsignal_t transmitStateSignal
Definition: EtherMACBase.h:186
#define PREAMBLE_BYTES
Definition: Ethernet.h:45
long currentSendPkTreeID
Definition: EtherMAC.h:56
unsigned int framesSentInBurst
Definition: EtherMAC.h:81
unsigned int maxFramesInBurst
Definition: EtherMACBase.h:84
MACTransmitState transmitState
Definition: EtherMACBase.h:149
long bytesSentInBurst
Definition: EtherMAC.h:82
#define INTERFRAME_GAP_BITS
Definition: Ethernet.h:33
Definition: EtherMACBase.h:48
cGate * physOutGate
Definition: EtherMACBase.h:144
void inet::EtherMAC::finish ( )
overrideprotectedvirtual

Reimplemented from inet::EtherMACBase.

730 {
732 
733  simtime_t t = simTime();
734  simtime_t totalChannelIdleTime = t - totalSuccessfulRxTxTime - totalCollisionTime;
735  recordScalar("rx channel idle (%)", 100 * (totalChannelIdleTime / t));
736  recordScalar("rx channel utilization (%)", 100 * (totalSuccessfulRxTxTime / t));
737  recordScalar("rx channel collision (%)", 100 * (totalCollisionTime / t));
738  recordScalar("collisions", numCollisions);
739  recordScalar("backoffs", numBackoffs);
740 }
virtual void finish() override
Definition: EtherMACBase.cc:600
simtime_t totalCollisionTime
Definition: EtherMAC.h:76
unsigned long numBackoffs
Definition: EtherMAC.h:80
unsigned long numCollisions
Definition: EtherMAC.h:79
simtime_t totalSuccessfulRxTxTime
Definition: EtherMAC.h:77
void inet::EtherMAC::frameReceptionComplete ( )
protectedvirtual

Referenced by handleEndRxPeriod(), and processMsgFromNetwork().

752 {
753  EtherTraffic *msg = check_and_cast<EtherTraffic *>(frameBeingReceived);
754  frameBeingReceived = nullptr;
755 
756  if (dynamic_cast<EtherFilledIFG *>(msg) != nullptr) {
757  delete msg;
758  return;
759  }
760 
761  bool hasBitError = msg->hasBitError();
762 
763  EtherFrame *frame = decapsulate(check_and_cast<EtherPhyFrame *>(msg));
764  emit(packetReceivedFromLowerSignal, frame);
765 
766  if (hasBitError) {
768  emit(dropPkBitErrorSignal, frame);
769  delete frame;
770  return;
771  }
772 
773  if (dropFrameNotForUs(frame))
774  return;
775 
776  if (dynamic_cast<EtherPauseFrame *>(frame) != nullptr) {
777  processReceivedPauseFrame((EtherPauseFrame *)frame);
778  }
779  else {
780  EV_INFO << "Reception of " << frame << " successfully completed.\n";
781  processReceivedDataFrame(check_and_cast<EtherFrame *>(frame));
782  }
783 }
static simsignal_t packetReceivedFromLowerSignal
Definition: EtherMACBase.h:182
virtual void processReceivedPauseFrame(EtherPauseFrame *frame)
Definition: EtherMAC.cc:800
virtual EtherFrame * decapsulate(EtherPhyFrame *phyFrame)
Definition: EtherMACBase.cc:399
virtual void processReceivedDataFrame(EtherFrame *frame)
Definition: EtherMAC.cc:785
virtual bool dropFrameNotForUs(EtherFrame *frame)
Checks destination address and drops the frame when frame is not for us; returns true if frame is dro...
Definition: EtherMACBase.cc:458
static simsignal_t dropPkBitErrorSignal
Definition: EtherMACBase.h:178
cPacket * frameBeingReceived
Definition: EtherMAC.h:59
unsigned long numDroppedBitError
Definition: EtherMACBase.h:166
void inet::EtherMAC::handleEndBackoffPeriod ( )
protectedvirtual

Referenced by handleSelfMessage().

623 {
625  throw cRuntimeError("At end of BACKOFF and not in BACKOFF_STATE");
626 
627  if (curTxFrame == nullptr)
628  throw cRuntimeError("At end of BACKOFF and no frame to transmit");
629 
630  if (receiveState == RX_IDLE_STATE) {
631  EV_DETAIL << "Backoff period ended, wait IFG\n";
633  }
634  else {
635  EV_DETAIL << "Backoff period ended but channel is not free, idling\n";
638  }
639 }
MACReceiveState receiveState
Definition: EtherMACBase.h:150
Definition: EtherMACBase.h:57
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
static simsignal_t transmitStateSignal
Definition: EtherMACBase.h:186
virtual void scheduleEndIFGPeriod()
Definition: EtherMAC.cc:829
Definition: EtherMACBase.h:52
Definition: EtherMACBase.h:47
MACTransmitState transmitState
Definition: EtherMACBase.h:149
void inet::EtherMAC::handleEndIFGPeriod ( )
protectedvirtual

Referenced by handleSelfMessage().

447 {
449  throw cRuntimeError("Not in WAIT_IFG_STATE at the end of IFG period");
450 
452 
453  EV_DETAIL << "IFG elapsed\n";
454 
456  bytesSentInBurst = 0;
457  framesSentInBurst = 0;
458  }
459 
460  // End of IFG period, okay to transmit, if Rx idle OR duplexMode ( checked in startFrameTransmission(); )
461 
462  // send frame to network
463  beginSendFrames();
464 }
bool frameBursting
Definition: EtherMACBase.h:138
Definition: EtherMACBase.h:49
virtual void beginSendFrames()
Definition: EtherMAC.cc:892
long currentSendPkTreeID
Definition: EtherMAC.h:56
unsigned int framesSentInBurst
Definition: EtherMAC.h:81
MACTransmitState transmitState
Definition: EtherMACBase.h:149
long bytesSentInBurst
Definition: EtherMAC.h:82
Definition: EtherMACBase.h:48
void inet::EtherMAC::handleEndJammingPeriod ( )
protectedvirtual

Referenced by handleSelfMessage().

660 {
662  throw cRuntimeError("At end of JAMMING but not in JAMMING_STATE");
663 
664  EV_DETAIL << "Jamming finished, executing backoff\n";
666 }
virtual void handleRetransmission()
Definition: EtherMAC.cc:668
MACTransmitState transmitState
Definition: EtherMACBase.h:149
Definition: EtherMACBase.h:51
void inet::EtherMAC::handleEndPausePeriod ( )
protectedvirtual

Referenced by handleSelfMessage().

743 {
744  if (transmitState != PAUSE_STATE)
745  throw cRuntimeError("At end of PAUSE and not in PAUSE_STATE");
746 
747  EV_DETAIL << "Pause finished, resuming transmissions\n";
748  beginSendFrames();
749 }
virtual void beginSendFrames()
Definition: EtherMAC.cc:892
Definition: EtherMACBase.h:53
MACTransmitState transmitState
Definition: EtherMACBase.h:149
void inet::EtherMAC::handleEndRxPeriod ( )
protectedvirtual

Referenced by handleSelfMessage().

591 {
592  simtime_t dt = simTime() - channelBusySince;
593 
594  switch (receiveState) {
595  case RECEIVING_STATE:
598  break;
599 
600  case RX_COLLISION_STATE:
601  EV_DETAIL << "Incoming signals finished after collision\n";
602  totalCollisionTime += dt;
603  break;
604 
605  case RX_RECONNECT_STATE:
606  EV_DETAIL << "Incoming signals finished or reconnect time elapsed after reconnect\n";
607  endRxTimeList.clear();
608  break;
609 
610  default:
611  throw cRuntimeError("model error: invalid receiveState %d", receiveState);
612  }
613 
617 
620 }
simtime_t channelBusySince
Definition: EtherMAC.h:78
Definition: EtherMACBase.h:58
Definition: EtherMACBase.h:59
virtual void frameReceptionComplete()
Definition: EtherMAC.cc:751
int numConcurrentTransmissions
Definition: EtherMAC.h:54
MACReceiveState receiveState
Definition: EtherMACBase.h:150
Definition: EtherMACBase.h:57
static simsignal_t receiveStateSignal
Definition: EtherMACBase.h:187
EndRxTimeList endRxTimeList
Definition: EtherMAC.h:73
Definition: EtherMACBase.h:60
virtual void scheduleEndIFGPeriod()
Definition: EtherMAC.cc:829
Definition: EtherMACBase.h:47
simtime_t totalCollisionTime
Definition: EtherMAC.h:76
MACTransmitState transmitState
Definition: EtherMACBase.h:149
simtime_t totalSuccessfulRxTxTime
Definition: EtherMAC.h:77
void inet::EtherMAC::handleEndTxPeriod ( )
protectedvirtual

Referenced by handleSelfMessage().

527 {
528  // we only get here if transmission has finished successfully, without collision
530  throw cRuntimeError("End of transmission, and incorrect state detected");
531 
533 
534  if (curTxFrame == nullptr)
535  throw cRuntimeError("Frame under transmission cannot be found");
536 
537  emit(packetSentToLowerSignal, curTxFrame); //consider: emit with start time of frame
538 
539  if (EtherPauseFrame *pauseFrame = dynamic_cast<EtherPauseFrame *>(curTxFrame)) {
541  emit(txPausePkUnitsSignal, pauseFrame->getPauseTime());
542  }
543  else {
544  unsigned long curBytes = curTxFrame->getByteLength();
545  numFramesSent++;
546  numBytesSent += curBytes;
547  emit(txPkSignal, curTxFrame);
548  }
549 
550  EV_INFO << "Transmission of " << curTxFrame << " successfully completed.\n";
551  delete curTxFrame;
552  curTxFrame = nullptr;
553  lastTxFinishTime = simTime();
554  getNextFrameFromQueue(); // note: cannot be moved into handleEndIFGPeriod(), because in burst mode we need to know whether to send filled IFG or not
555 
556  // only count transmissions in totalSuccessfulRxTxTime if channel is half-duplex
557  if (!duplexMode) {
558  simtime_t dt = simTime() - channelBusySince;
560  }
561 
562  backoffs = 0;
563 
564  // check for and obey received PAUSE frames after each transmission
565  if (pauseUnitsRequested > 0) {
566  // if we received a PAUSE frame recently, go into PAUSE state
567  EV_DETAIL << "Going to PAUSE mode for " << pauseUnitsRequested << " time units\n";
568  scheduleEndPausePeriod(pauseUnitsRequested);
569  pauseUnitsRequested = 0;
570  }
571  else {
572  EV_DETAIL << "Start IFG period\n";
574  if (!txQueue.extQueue)
576  }
577 }
simtime_t channelBusySince
Definition: EtherMAC.h:78
simtime_t lastTxFinishTime
Definition: EtherMACBase.h:151
unsigned long numPauseFramesSent
Definition: EtherMACBase.h:170
unsigned long numFramesSent
Definition: EtherMACBase.h:159
MACReceiveState receiveState
Definition: EtherMACBase.h:150
virtual void getNextFrameFromQueue()
Definition: EtherMACBase.cc:578
virtual void fillIFGIfInBurst()
Definition: EtherMAC.cc:837
Definition: EtherMACBase.h:57
MacQueue txQueue
Definition: EtherMACBase.h:141
static simsignal_t txPausePkUnitsSignal
Definition: EtherMACBase.h:174
bool duplexMode
Definition: EtherMACBase.h:137
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
int backoffs
Definition: EtherMAC.h:55
int pauseUnitsRequested
Definition: EtherMACBase.h:152
virtual void scheduleEndIFGPeriod()
Definition: EtherMAC.cc:829
IPassiveQueue * extQueue
Definition: EtherMACBase.h:116
static simsignal_t packetSentToLowerSignal
Definition: EtherMACBase.h:181
long currentSendPkTreeID
Definition: EtherMAC.h:56
unsigned long numBytesSent
Definition: EtherMACBase.h:161
MACTransmitState transmitState
Definition: EtherMACBase.h:149
static simsignal_t txPkSignal
Definition: EtherMACBase.h:172
simtime_t totalSuccessfulRxTxTime
Definition: EtherMAC.h:77
virtual void scheduleEndPausePeriod(int pauseUnits)
Definition: EtherMAC.cc:883
Definition: EtherMACBase.h:50
void inet::EtherMAC::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
174 {
175  if (!isOperational) {
177  return;
178  }
179 
180  if (channelsDiffer)
181  readChannelParameters(true);
182 
183  printState();
184 
185  // some consistency check
187  throw cRuntimeError("Inconsistent state -- transmitting and receiving at the same time");
188 
189  if (msg->isSelfMessage())
190  handleSelfMessage(msg);
191  else if (msg->getArrivalGate() == upperLayerInGate)
192  processFrameFromUpperLayer(check_and_cast<EtherFrame *>(msg));
193  else if (msg->getArrivalGate() == physInGate)
194  processMsgFromNetwork(check_and_cast<cPacket *>(msg));
195  else
196  throw cRuntimeError("Message received from unknown gate");
197 
198  printState();
199 }
bool channelsDiffer
Definition: EtherMACBase.h:148
MACReceiveState receiveState
Definition: EtherMACBase.h:150
virtual void processFrameFromUpperLayer(EtherFrame *msg)
Definition: EtherMAC.cc:201
Definition: EtherMACBase.h:57
bool duplexMode
Definition: EtherMACBase.h:137
cGate * physInGate
Definition: EtherMACBase.h:143
virtual void processMsgFromNetwork(cPacket *msg)
Definition: EtherMAC.cc:326
virtual void readChannelParameters(bool errorWhenAsymmetric) override
Calculates datarates, etc.
Definition: EtherMAC.cc:128
virtual void printState()
Definition: EtherMAC.cc:694
bool isOperational
Definition: MACBase.h:37
virtual void handleMessageWhenDown(cMessage *msg)
Definition: MACBase.cc:108
virtual void handleSelfMessage(cMessage *msg)
Definition: EtherMAC.cc:138
cGate * upperLayerInGate
Definition: EtherMACBase.h:145
MACTransmitState transmitState
Definition: EtherMACBase.h:149
Definition: EtherMACBase.h:50
void inet::EtherMAC::handleRetransmission ( )
protectedvirtual

Referenced by handleEndJammingPeriod().

669 {
670  if (++backoffs > MAX_ATTEMPTS) {
671  EV_DETAIL << "Number of retransmit attempts of frame exceeds maximum, cancelling transmission of frame\n";
672  delete curTxFrame;
673  curTxFrame = nullptr;
676  backoffs = 0;
678  beginSendFrames();
679  return;
680  }
681 
682  EV_DETAIL << "Executing backoff procedure\n";
683  int backoffRange = (backoffs >= BACKOFF_RANGE_LIMIT) ? 1024 : (1 << backoffs);
684  int slotNumber = intuniform(0, backoffRange - 1);
685 
686  scheduleAt(simTime() + slotNumber * curEtherDescr->slotTime, endBackoffMsg);
689 
690  numBackoffs++;
691  emit(backoffSignal, 1L);
692 }
cMessage * endBackoffMsg
Definition: EtherMAC.h:61
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
virtual void getNextFrameFromQueue()
Definition: EtherMACBase.cc:578
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
static simsignal_t backoffSignal
Definition: EtherMAC.h:85
int backoffs
Definition: EtherMAC.h:55
#define BACKOFF_RANGE_LIMIT
Definition: Ethernet.h:43
virtual void beginSendFrames()
Definition: EtherMAC.cc:892
static simsignal_t transmitStateSignal
Definition: EtherMACBase.h:186
Definition: EtherMACBase.h:52
Definition: EtherMACBase.h:47
#define MAX_ATTEMPTS
Definition: Ethernet.h:42
MACTransmitState transmitState
Definition: EtherMACBase.h:149
unsigned long numBackoffs
Definition: EtherMAC.h:80
double slotTime
Definition: EtherMACBase.h:88
void inet::EtherMAC::handleSelfMessage ( cMessage *  msg)
protectedvirtual

Referenced by handleMessage().

139 {
140  // Process different self-messages (timer signals)
141  EV_TRACE << "Self-message " << msg << " received\n";
142 
143  switch (msg->getKind()) {
144  case ENDIFG:
146  break;
147 
148  case ENDTRANSMISSION:
150  break;
151 
152  case ENDRECEPTION:
154  break;
155 
156  case ENDBACKOFF:
158  break;
159 
160  case ENDJAMMING:
162  break;
163 
164  case ENDPAUSE:
166  break;
167 
168  default:
169  throw cRuntimeError("Self-message with unexpected message kind %d", msg->getKind());
170  }
171 }
Definition: EtherMACBase.h:70
Definition: EtherMACBase.h:67
Definition: EtherMACBase.h:66
virtual void handleEndIFGPeriod()
Definition: EtherMAC.cc:446
Definition: EtherMACBase.h:68
virtual void handleEndTxPeriod()
Definition: EtherMAC.cc:526
Definition: EtherMACBase.h:69
virtual void handleEndBackoffPeriod()
Definition: EtherMAC.cc:622
virtual void handleEndRxPeriod()
Definition: EtherMAC.cc:590
virtual void handleEndJammingPeriod()
Definition: EtherMAC.cc:659
Definition: EtherMACBase.h:71
virtual void handleEndPausePeriod()
Definition: EtherMAC.cc:742
void inet::EtherMAC::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::EtherMACBase.

56 {
58 
59  if (stage == INITSTAGE_LOCAL) {
60  endRxMsg = new cMessage("EndReception", ENDRECEPTION);
61  endBackoffMsg = new cMessage("EndBackoff", ENDBACKOFF);
62  endJammingMsg = new cMessage("EndJamming", ENDJAMMING);
63 
64  // initialize state info
65  backoffs = 0;
68 
69  WATCH(backoffs);
71  }
72 }
Definition: EtherMACBase.h:70
int numConcurrentTransmissions
Definition: EtherMAC.h:54
cMessage * endBackoffMsg
Definition: EtherMAC.h:61
Definition: EtherMACBase.h:67
Definition: EtherMACBase.h:68
int backoffs
Definition: EtherMAC.h:55
cMessage * endRxMsg
Definition: EtherMAC.h:60
Local initializations.
Definition: InitStages.h:35
cMessage * endJammingMsg
Definition: EtherMAC.h:62
long currentSendPkTreeID
Definition: EtherMAC.h:56
virtual void initialize(int stage) override
Definition: EtherMACBase.cc:152
void inet::EtherMAC::initializeFlags ( )
overrideprotectedvirtual

Reimplemented from inet::EtherMACBase.

94 {
96 
97  duplexMode = par("duplexMode").boolValue();
98  frameBursting = !duplexMode && par("frameBursting").boolValue();
99  physInGate->setDeliverOnReceptionStart(true);
100 }
bool frameBursting
Definition: EtherMACBase.h:138
bool duplexMode
Definition: EtherMACBase.h:137
cGate * physInGate
Definition: EtherMACBase.h:143
virtual void initializeFlags()
Definition: EtherMACBase.cc:233
void inet::EtherMAC::initializeStatistics ( )
overrideprotectedvirtual

Reimplemented from inet::EtherMACBase.

75 {
77 
79  bytesSentInBurst = 0;
80 
81  WATCH(framesSentInBurst);
82  WATCH(bytesSentInBurst);
83 
84  // initialize statistics
85  totalCollisionTime = 0.0;
88 
89  WATCH(numCollisions);
90  WATCH(numBackoffs);
91 }
virtual void initializeStatistics()
Definition: EtherMACBase.cc:260
unsigned int framesSentInBurst
Definition: EtherMAC.h:81
simtime_t totalCollisionTime
Definition: EtherMAC.h:76
unsigned long numBackoffs
Definition: EtherMAC.h:80
unsigned long numCollisions
Definition: EtherMAC.h:79
simtime_t totalSuccessfulRxTxTime
Definition: EtherMAC.h:77
long bytesSentInBurst
Definition: EtherMAC.h:82
virtual int inet::EtherMAC::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::EtherMACBase.

45 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::EtherMAC::printState ( )
protectedvirtual

Referenced by handleMessage(), and startFrameTransmission().

695 {
696 #define CASE(x) case x: \
697  EV_DETAIL << #x; break
698 
699  EV_DETAIL << "transmitState: ";
700  switch (transmitState) {
707  CASE(PAUSE_STATE);
708  }
709 
710  EV_DETAIL << ", receiveState: ";
711  switch (receiveState) {
716  }
717 
718  EV_DETAIL << ", backoffs: " << backoffs;
719  EV_DETAIL << ", numConcurrentRxTransmissions: " << numConcurrentTransmissions;
720 
721  if (txQueue.innerQueue)
722  EV_DETAIL << ", queueLength: " << txQueue.innerQueue->getLength();
723 
724  EV_DETAIL << endl;
725 
726 #undef CASE
727 }
Definition: EtherMACBase.h:58
Definition: EtherMACBase.h:59
int numConcurrentTransmissions
Definition: EtherMAC.h:54
MACReceiveState receiveState
Definition: EtherMACBase.h:150
Definition: EtherMACBase.h:57
int getLength() const
Definition: EtherMACBase.h:108
MacQueue txQueue
Definition: EtherMACBase.h:141
Definition: EtherMACBase.h:49
InnerQueue * innerQueue
Definition: EtherMACBase.h:115
int backoffs
Definition: EtherMAC.h:55
Definition: EtherMACBase.h:60
Definition: EtherMACBase.h:52
Definition: EtherMACBase.h:47
#define CASE(x)
Definition: EtherMACBase.h:53
MACTransmitState transmitState
Definition: EtherMACBase.h:149
Definition: EtherMACBase.h:50
Definition: EtherMACBase.h:51
Definition: EtherMACBase.h:48
void inet::EtherMAC::processConnectDisconnect ( )
overrideprotectedvirtual

Reimplemented from inet::EtherMACBase.

103 {
104  if (!connected) {
105  delete frameBeingReceived;
106  frameBeingReceived = nullptr;
107  cancelEvent(endRxMsg);
108  cancelEvent(endBackoffMsg);
109  cancelEvent(endJammingMsg);
110  bytesSentInBurst = 0;
111  framesSentInBurst = 0;
112  }
113 
115 
116  if (connected) {
117  if (!duplexMode) {
118  // start RX_RECONNECT_STATE
121  simtime_t reconnectEndTime = simTime() + 8 * (MAX_ETHERNET_FRAME_BYTES + JAM_SIGNAL_BYTES) / curEtherDescr->txrate;
122  endRxTimeList.clear();
123  addReceptionInReconnectState(-1, reconnectEndTime);
124  }
125  }
126 }
cMessage * endBackoffMsg
Definition: EtherMAC.h:61
bool connected
Definition: EtherMACBase.h:134
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
MACReceiveState receiveState
Definition: EtherMACBase.h:150
bool duplexMode
Definition: EtherMACBase.h:137
#define JAM_SIGNAL_BYTES
Definition: Ethernet.h:44
static simsignal_t receiveStateSignal
Definition: EtherMACBase.h:187
EndRxTimeList endRxTimeList
Definition: EtherMAC.h:73
Definition: EtherMACBase.h:60
cMessage * endRxMsg
Definition: EtherMAC.h:60
cMessage * endJammingMsg
Definition: EtherMAC.h:62
unsigned int framesSentInBurst
Definition: EtherMAC.h:81
virtual void addReceptionInReconnectState(long id, simtime_t endRxTime)
Definition: EtherMAC.cc:266
double txrate
Definition: EtherMACBase.h:80
virtual void processConnectDisconnect()
Definition: EtherMACBase.cc:355
cPacket * frameBeingReceived
Definition: EtherMAC.h:59
long bytesSentInBurst
Definition: EtherMAC.h:82
#define MAX_ETHERNET_FRAME_BYTES
Definition: Ethernet.h:30
void inet::EtherMAC::processDetectedCollision ( )
protectedvirtual

Referenced by processMsgFromNetwork(), and processReceivedJam().

433 {
435  delete frameBeingReceived;
436  frameBeingReceived = nullptr;
437 
438  numCollisions++;
439  emit(collisionSignal, 1L);
440  // go to collision state
443  }
444 }
Definition: EtherMACBase.h:59
MACReceiveState receiveState
Definition: EtherMACBase.h:150
static simsignal_t receiveStateSignal
Definition: EtherMACBase.h:187
static simsignal_t collisionSignal
Definition: EtherMAC.h:84
cPacket * frameBeingReceived
Definition: EtherMAC.h:59
unsigned long numCollisions
Definition: EtherMAC.h:79
void inet::EtherMAC::processFrameFromUpperLayer ( EtherFrame msg)
protectedvirtual

Referenced by handleMessage().

202 {
203  ASSERT(frame->getByteLength() >= MIN_ETHERNET_FRAME_BYTES);
204 
205  EV_INFO << "Received " << frame << " from upper layer." << endl;
206 
207  emit(packetReceivedFromUpperSignal, frame);
208 
209  if (frame->getDest().equals(address)) {
210  throw cRuntimeError("Logic error: frame %s from higher layer has local MAC address as dest (%s)",
211  frame->getFullName(), frame->getDest().str().c_str());
212  }
213 
214  if (frame->getByteLength() > MAX_ETHERNET_FRAME_BYTES) {
215  throw cRuntimeError("Packet from higher layer (%d bytes) exceeds maximum Ethernet frame size (%d)",
216  (int)(frame->getByteLength()), MAX_ETHERNET_FRAME_BYTES);
217  }
218 
219  if (!connected || disabled) {
220  EV_WARN << (!connected ? "Interface is not connected" : "MAC is disabled") << " -- dropping packet " << frame << endl;
221  emit(dropPkFromHLIfaceDownSignal, frame);
223  delete frame;
224 
226  return;
227  }
228 
229  // fill in src address if not set
230  if (frame->getSrc().isUnspecified())
231  frame->setSrc(address);
232 
233  bool isPauseFrame = (dynamic_cast<EtherPauseFrame *>(frame) != nullptr);
234 
235  if (!isPauseFrame) {
236  numFramesFromHL++;
237  emit(rxPkFromHLSignal, frame);
238  }
239 
240  if (txQueue.extQueue) {
241  ASSERT(curTxFrame == nullptr);
242  curTxFrame = frame;
244  }
245  else {
246  if (txQueue.innerQueue->isFull())
247  throw cRuntimeError("txQueue length exceeds %d -- this is probably due to "
248  "a bogus app model generating excessive traffic "
249  "(or if this is normal, increase txQueueLimit!)",
251 
252  // store frame and possibly begin transmitting
253  EV_DETAIL << "Frame " << frame << " arrived from higher layer, enqueueing\n";
255 
256  if (!curTxFrame && !txQueue.innerQueue->isEmpty())
257  curTxFrame = (EtherFrame *)txQueue.innerQueue->pop();
258  }
259 
261  EV_DETAIL << "No incoming carrier signals detected, frame clear to send\n";
263  }
264 }
bool connected
Definition: EtherMACBase.h:134
MACReceiveState receiveState
Definition: EtherMACBase.h:150
bool disabled
Definition: EtherMACBase.h:135
virtual void fillIFGIfInBurst()
Definition: EtherMAC.cc:837
Definition: EtherMACBase.h:57
int getQueueLimit() const
Definition: EtherMACBase.h:106
MacQueue txQueue
Definition: EtherMACBase.h:141
bool duplexMode
Definition: EtherMACBase.h:137
InnerQueue * innerQueue
Definition: EtherMACBase.h:115
cObject * pop()
Definition: EtherMACBase.h:104
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
MACAddress address
Definition: EtherMACBase.h:133
#define MIN_ETHERNET_FRAME_BYTES
Definition: Ethernet.h:31
void insertFrame(cObject *obj)
Definition: EtherMACBase.h:103
unsigned long numFramesFromHL
Definition: EtherMACBase.h:163
static simsignal_t dropPkFromHLIfaceDownSignal
Definition: EtherMACBase.h:192
unsigned long numDroppedPkFromHLIfaceDown
Definition: EtherMACBase.h:164
virtual void startFrameTransmission()
Definition: EtherMAC.cc:466
IPassiveQueue * extQueue
Definition: EtherMACBase.h:116
static simsignal_t packetReceivedFromUpperSignal
Definition: EtherMACBase.h:184
static simsignal_t rxPkFromHLSignal
Definition: EtherMACBase.h:176
Definition: EtherMACBase.h:47
MACTransmitState transmitState
Definition: EtherMACBase.h:149
bool isFull() const
Definition: EtherMACBase.h:107
virtual void requestNextFrameFromExtQueue()
Definition: EtherMACBase.cc:591
bool isEmpty() const
Definition: EtherMACBase.h:105
#define MAX_ETHERNET_FRAME_BYTES
Definition: Ethernet.h:30
void inet::EtherMAC::processMsgFromNetwork ( cPacket *  msg)
protectedvirtual

Referenced by handleMessage().

327 {
328  EV_DETAIL << "Received " << msg << " from network.\n";
329 
330  if (!connected || disabled) {
331  EV_WARN << (!connected ? "Interface is not connected" : "MAC is disabled") << " -- dropping msg " << msg << endl;
332  if (EtherPhyFrame *phyFrame = dynamic_cast<EtherPhyFrame *>(msg)) { // do not count JAM and IFG packets
333  EtherFrame *frame = decapsulate(phyFrame);
334  emit(dropPkIfaceDownSignal, frame);
335  delete frame;
337  }
338  else
339  delete msg;
340 
341  return;
342  }
343 
344  // detect cable length violation in half-duplex mode
345  if (!duplexMode) {
346  simtime_t propagationTime = simTime() - msg->getSendingTime();
347  if (propagationTime >= curEtherDescr->maxPropagationDelay) {
348  throw cRuntimeError("Very long frame propagation time detected, maybe cable exceeds "
349  "maximum allowed length? (%lgs corresponds to an approx. %lgm cable)",
350  SIMTIME_STR(propagationTime),
351  SIMTIME_STR(propagationTime * SPEED_OF_LIGHT_IN_CABLE));
352  }
353  }
354 
355  simtime_t endRxTime = simTime() + msg->getDuration();
356  EtherJam *jamMsg = dynamic_cast<EtherJam *>(msg);
357 
358  if (duplexMode && jamMsg) {
359  throw cRuntimeError("Stray jam signal arrived in full-duplex mode");
360  }
361  else if (!duplexMode && receiveState == RX_RECONNECT_STATE) {
362  long treeId = jamMsg ? jamMsg->getAbortedPkTreeID() : msg->getTreeId();
363  addReceptionInReconnectState(treeId, endRxTime);
364  delete msg;
365  }
367  // since we're half-duplex, receiveState must be RX_IDLE_STATE (asserted at top of handleMessage)
368  if (jamMsg)
369  throw cRuntimeError("Stray jam signal arrived while transmitting (usual cause is cable length exceeding allowed maximum)");
370 
371  // set receive state and schedule end of reception
374 
375  addReception(endRxTime);
376  delete msg;
377 
378  EV_DETAIL << "Transmission interrupted by incoming frame, handling collision\n";
379  cancelEvent((transmitState == TRANSMITTING_STATE) ? endTxMsg : endIFGMsg);
380 
381  EV_DETAIL << "Transmitting jam signal\n";
382  sendJamSignal(); // backoff will be executed when jamming finished
383 
384  numCollisions++;
385  emit(collisionSignal, 1L);
386  }
387  else if (receiveState == RX_IDLE_STATE) {
388  if (jamMsg)
389  throw cRuntimeError("Stray jam signal arrived (usual cause is cable length exceeding allowed maximum)");
390 
391  channelBusySince = simTime();
392  EV_INFO << "Reception of " << msg << " started.\n";
393  scheduleEndRxPeriod(msg);
394  }
395  else if (receiveState == RECEIVING_STATE
396  && !jamMsg
397  && endRxMsg->getArrivalTime() - simTime() < curEtherDescr->halfBitTime)
398  {
399  // With the above condition we filter out "false" collisions that may occur with
400  // back-to-back frames. That is: when "beginning of frame" message (this one) occurs
401  // BEFORE "end of previous frame" event (endRxMsg) -- same simulation time,
402  // only wrong order.
403 
404  EV_DETAIL << "Back-to-back frames: completing reception of current frame, starting reception of next one\n";
405 
406  // complete reception of previous frame
407  cancelEvent(endRxMsg);
409 
410  // calculate usability
412  channelBusySince = simTime();
413 
414  // start receiving next frame
415  scheduleEndRxPeriod(msg);
416  }
417  else { // (receiveState==RECEIVING_STATE || receiveState==RX_COLLISION_STATE)
418  // handle overlapping receptions
419  if (jamMsg) {
420  processReceivedJam(jamMsg);
421  }
422  else { // EtherFrame or EtherPauseFrame
423  EV_DETAIL << "Overlapping receptions -- setting collision state\n";
424  addReception(endRxTime);
425  // delete collided frames: arrived frame as well as the one we're currently receiving
426  delete msg;
428  }
429  }
430 }
simtime_t channelBusySince
Definition: EtherMAC.h:78
Definition: EtherMACBase.h:58
Definition: EtherMACBase.h:59
cMessage * endIFGMsg
Definition: EtherMACBase.h:156
virtual void processReceivedJam(EtherJam *jam)
Definition: EtherMAC.cc:309
virtual void frameReceptionComplete()
Definition: EtherMAC.cc:751
bool connected
Definition: EtherMACBase.h:134
virtual void sendJamSignal()
Definition: EtherMAC.cc:641
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
MACReceiveState receiveState
Definition: EtherMACBase.h:150
bool disabled
Definition: EtherMACBase.h:135
Definition: EtherMACBase.h:57
double maxPropagationDelay
Definition: EtherMACBase.h:89
bool duplexMode
Definition: EtherMACBase.h:137
static const double SPEED_OF_LIGHT_IN_CABLE
Definition: EtherMACBase.h:190
double halfBitTime
Definition: EtherMACBase.h:81
static simsignal_t receiveStateSignal
Definition: EtherMACBase.h:187
static simsignal_t collisionSignal
Definition: EtherMAC.h:84
virtual void scheduleEndRxPeriod(cPacket *)
Definition: EtherMAC.cc:579
cMessage * endTxMsg
Definition: EtherMACBase.h:156
Definition: EtherMACBase.h:49
virtual EtherFrame * decapsulate(EtherPhyFrame *phyFrame)
Definition: EtherMACBase.cc:399
unsigned long numDroppedIfaceDown
Definition: EtherMACBase.h:165
Definition: EtherMACBase.h:60
cMessage * endRxMsg
Definition: EtherMAC.h:60
virtual void processDetectedCollision()
Definition: EtherMAC.cc:432
virtual void addReceptionInReconnectState(long id, simtime_t endRxTime)
Definition: EtherMAC.cc:266
MACTransmitState transmitState
Definition: EtherMACBase.h:149
unsigned long numCollisions
Definition: EtherMAC.h:79
static simsignal_t dropPkIfaceDownSignal
Definition: EtherMACBase.h:191
simtime_t totalSuccessfulRxTxTime
Definition: EtherMAC.h:77
virtual void addReception(simtime_t endRxTime)
Definition: EtherMAC.cc:299
Definition: EtherMACBase.h:50
void inet::EtherMAC::processReceivedDataFrame ( EtherFrame frame)
protectedvirtual

Referenced by frameReceptionComplete().

786 {
787  // statistics
788  unsigned long curBytes = frame->getByteLength();
790  numBytesReceivedOK += curBytes;
791  emit(rxPkOkSignal, frame);
792 
794  emit(packetSentToUpperSignal, frame);
795  // pass up to upper layer
796  EV_INFO << "Sending " << frame << " to upper layer.\n";
797  send(frame, "upperLayerOut");
798 }
static simsignal_t rxPkOkSignal
Definition: EtherMACBase.h:173
unsigned long numFramesReceivedOK
Definition: EtherMACBase.h:160
static simsignal_t packetSentToUpperSignal
Definition: EtherMACBase.h:183
unsigned long numBytesReceivedOK
Definition: EtherMACBase.h:162
unsigned long numFramesPassedToHL
Definition: EtherMACBase.h:168
void inet::EtherMAC::processReceivedJam ( EtherJam jam)
protectedvirtual

Referenced by processMsgFromNetwork().

310 {
311  simtime_t endRxTime = simTime() + jam->getDuration();
312  delete jam;
313 
316  throw cRuntimeError("Received JAM without message");
317 
318  if (numConcurrentTransmissions == 0 || endRxMsg->getArrivalTime() < endRxTime) {
319  cancelEvent(endRxMsg);
320  scheduleAt(endRxTime, endRxMsg);
321  }
322 
324 }
int numConcurrentTransmissions
Definition: EtherMAC.h:54
cMessage * endRxMsg
Definition: EtherMAC.h:60
virtual void processDetectedCollision()
Definition: EtherMAC.cc:432
void inet::EtherMAC::processReceivedPauseFrame ( EtherPauseFrame frame)
protectedvirtual

Referenced by frameReceptionComplete().

801 {
802  int pauseUnits = frame->getPauseTime();
803  delete frame;
804 
806  emit(rxPausePkUnitsSignal, pauseUnits);
807 
808  if (transmitState == TX_IDLE_STATE) {
809  EV_DETAIL << "PAUSE frame received, pausing for " << pauseUnitsRequested << " time units\n";
810  if (pauseUnits > 0)
811  scheduleEndPausePeriod(pauseUnits);
812  }
813  else if (transmitState == PAUSE_STATE) {
814  EV_DETAIL << "PAUSE frame received, pausing for " << pauseUnitsRequested
815  << " more time units from now\n";
816  cancelEvent(endPauseMsg);
817 
818  if (pauseUnits > 0)
819  scheduleEndPausePeriod(pauseUnits);
820  }
821  else {
822  // transmitter busy -- wait until it finishes with current frame (endTx)
823  // and then it'll go to PAUSE state
824  EV_DETAIL << "PAUSE frame received, storing pause request\n";
825  pauseUnitsRequested = pauseUnits;
826  }
827 }
cMessage * endPauseMsg
Definition: EtherMACBase.h:156
unsigned long numPauseFramesRcvd
Definition: EtherMACBase.h:169
int pauseUnitsRequested
Definition: EtherMACBase.h:152
Definition: EtherMACBase.h:47
Definition: EtherMACBase.h:53
MACTransmitState transmitState
Definition: EtherMACBase.h:149
static simsignal_t rxPausePkUnitsSignal
Definition: EtherMACBase.h:175
virtual void scheduleEndPausePeriod(int pauseUnits)
Definition: EtherMAC.cc:883
void inet::EtherMAC::readChannelParameters ( bool  errorWhenAsymmetric)
overrideprotectedvirtual

Calculates datarates, etc.

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

Reimplemented from inet::EtherMACBase.

Referenced by handleMessage().

129 {
130  EtherMACBase::readChannelParameters(errorWhenAsymmetric);
131 
132  if (connected && !duplexMode) {
134  throw cRuntimeError("%g bps Ethernet only supports full-duplex links", curEtherDescr->txrate);
135  }
136 }
bool connected
Definition: EtherMACBase.h:134
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
bool duplexMode
Definition: EtherMACBase.h:137
virtual void readChannelParameters(bool errorWhenAsymmetric)
Calculates datarates, etc.
Definition: EtherMACBase.cc:495
int64 halfDuplexFrameMinBytes
Definition: EtherMACBase.h:86
double txrate
Definition: EtherMACBase.h:80
void inet::EtherMAC::scheduleEndIFGPeriod ( )
protectedvirtual

Referenced by handleEndBackoffPeriod(), handleEndRxPeriod(), and handleEndTxPeriod().

830 {
833  simtime_t endIFGTime = simTime() + (INTERFRAME_GAP_BITS / curEtherDescr->txrate);
834  scheduleAt(endIFGTime, endIFGMsg);
835 }
cMessage * endIFGMsg
Definition: EtherMACBase.h:156
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
static simsignal_t transmitStateSignal
Definition: EtherMACBase.h:186
MACTransmitState transmitState
Definition: EtherMACBase.h:149
double txrate
Definition: EtherMACBase.h:80
#define INTERFRAME_GAP_BITS
Definition: Ethernet.h:33
Definition: EtherMACBase.h:48
void inet::EtherMAC::scheduleEndPausePeriod ( int  pauseUnits)
protectedvirtual

Referenced by handleEndTxPeriod(), and processReceivedPauseFrame().

884 {
885  // length is interpreted as 512-bit-time units
886  simtime_t pausePeriod = pauseUnits * PAUSE_UNIT_BITS / curEtherDescr->txrate;
887  scheduleAt(simTime() + pausePeriod, endPauseMsg);
890 }
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
#define PAUSE_UNIT_BITS
Definition: Ethernet.h:47
cMessage * endPauseMsg
Definition: EtherMACBase.h:156
static simsignal_t transmitStateSignal
Definition: EtherMACBase.h:186
Definition: EtherMACBase.h:53
MACTransmitState transmitState
Definition: EtherMACBase.h:149
double txrate
Definition: EtherMACBase.h:80
void inet::EtherMAC::scheduleEndRxPeriod ( cPacket *  frame)
protectedvirtual

Referenced by processMsgFromNetwork().

580 {
581  ASSERT(frameBeingReceived == nullptr);
582  ASSERT(!endRxMsg->isScheduled());
583 
584  frameBeingReceived = frame;
587  addReception(simTime() + frame->getDuration());
588 }
Definition: EtherMACBase.h:58
MACReceiveState receiveState
Definition: EtherMACBase.h:150
static simsignal_t receiveStateSignal
Definition: EtherMACBase.h:187
cMessage * endRxMsg
Definition: EtherMAC.h:60
cPacket * frameBeingReceived
Definition: EtherMAC.h:59
virtual void addReception(simtime_t endRxTime)
Definition: EtherMAC.cc:299
void inet::EtherMAC::scheduleEndTxPeriod ( int64_t  sentFrameByteLength)
protectedvirtual

Referenced by startFrameTransmission().

871 {
872  // update burst variables
873  if (frameBursting) {
874  bytesSentInBurst += sentFrameByteLength;
876  }
877 
878  scheduleAt(transmissionChannel->getTransmissionFinishTime(), endTxMsg);
881 }
bool frameBursting
Definition: EtherMACBase.h:138
cChannel * transmissionChannel
Definition: EtherMACBase.h:142
cMessage * endTxMsg
Definition: EtherMACBase.h:156
static simsignal_t transmitStateSignal
Definition: EtherMACBase.h:186
unsigned int framesSentInBurst
Definition: EtherMAC.h:81
MACTransmitState transmitState
Definition: EtherMACBase.h:149
long bytesSentInBurst
Definition: EtherMAC.h:82
Definition: EtherMACBase.h:50
void inet::EtherMAC::sendJamSignal ( )
protectedvirtual

Referenced by processMsgFromNetwork(), and startFrameTransmission().

642 {
643  if (currentSendPkTreeID == 0)
644  throw cRuntimeError("Model error: sending JAM while not transmitting");
645 
646  EtherJam *jam = new EtherJam("JAM_SIGNAL");
647  jam->setByteLength(JAM_SIGNAL_BYTES);
648  jam->setAbortedPkTreeID(currentSendPkTreeID);
649 
650  transmissionChannel->forceTransmissionFinishTime(SIMTIME_ZERO);
651  //emit(packetSentToLowerSignal, jam);
652  send(jam, physOutGate);
653 
654  scheduleAt(transmissionChannel->getTransmissionFinishTime(), endJammingMsg);
657 }
#define JAM_SIGNAL_BYTES
Definition: Ethernet.h:44
cChannel * transmissionChannel
Definition: EtherMACBase.h:142
static simsignal_t transmitStateSignal
Definition: EtherMACBase.h:186
cMessage * endJammingMsg
Definition: EtherMAC.h:62
long currentSendPkTreeID
Definition: EtherMAC.h:56
MACTransmitState transmitState
Definition: EtherMACBase.h:149
Definition: EtherMACBase.h:51
cGate * physOutGate
Definition: EtherMACBase.h:144
void inet::EtherMAC::startFrameTransmission ( )
protectedvirtual

Referenced by beginSendFrames(), and processFrameFromUpperLayer().

467 {
468  ASSERT(curTxFrame);
469 
470  EV_INFO << "Transmission of " << curTxFrame << " started.\n";
471 
472  EtherFrame *frame = curTxFrame->dup();
473 
474  if (frame->getSrc().isUnspecified())
475  frame->setSrc(address);
476 
477  bool inBurst = frameBursting && framesSentInBurst;
479 
480  if (frame->getByteLength() < minFrameLength)
481  frame->setByteLength(minFrameLength);
482 
483  // add preamble and SFD (Starting Frame Delimiter), then send out
484  EtherPhyFrame *phyFrame = encapsulate(frame);
485 
486  currentSendPkTreeID = phyFrame->getTreeId();
487  int64_t sentFrameByteLength = phyFrame->getByteLength();
488  send(phyFrame, physOutGate);
489 
490  // check for collisions (there might be an ongoing reception which we don't know about, see below)
492  // During the IFG period the hardware cannot listen to the channel,
493  // so it might happen that receptions have begun during the IFG,
494  // and even collisions might be in progress.
495  //
496  // But we don't know of any ongoing transmission so we blindly
497  // start transmitting, immediately collide and send a jam signal.
498  //
499  EV_DETAIL << "startFrameTransmission(): sending JAM signal.\n";
500  printState();
501 
502  sendJamSignal();
503  // numConcurrentRxTransmissions stays the same: +1 transmission, -1 jam
504 
505  if (receiveState == RECEIVING_STATE) {
506  delete frameBeingReceived;
507  frameBeingReceived = nullptr;
508 
509  numCollisions++;
510  emit(collisionSignal, 1L);
511  }
512  // go to collision state
515  }
516  else {
517  // no collision
518  scheduleEndTxPeriod(sentFrameByteLength);
519 
520  // only count transmissions in totalSuccessfulRxTxTime if channel is half-duplex
521  if (!duplexMode)
522  channelBusySince = simTime();
523  }
524 }
int64 frameMinBytes
Definition: EtherMACBase.h:82
simtime_t channelBusySince
Definition: EtherMAC.h:78
Definition: EtherMACBase.h:58
Definition: EtherMACBase.h:59
virtual void sendJamSignal()
Definition: EtherMAC.cc:641
const EtherDescr * curEtherDescr
Definition: EtherMACBase.h:132
MACReceiveState receiveState
Definition: EtherMACBase.h:150
bool frameBursting
Definition: EtherMACBase.h:138
Definition: EtherMACBase.h:57
bool duplexMode
Definition: EtherMACBase.h:137
static simsignal_t receiveStateSignal
Definition: EtherMACBase.h:187
static simsignal_t collisionSignal
Definition: EtherMAC.h:84
int64 frameInBurstMinBytes
Definition: EtherMACBase.h:87
virtual EtherPhyFrame * encapsulate(EtherFrame *phyFrame)
Definition: EtherMACBase.cc:391
virtual void printState()
Definition: EtherMAC.cc:694
EtherFrame * curTxFrame
Definition: EtherMACBase.h:153
MACAddress address
Definition: EtherMACBase.h:133
virtual void scheduleEndTxPeriod(int64_t sentFrameByteLength)
Definition: EtherMAC.cc:870
virtual EtherFrame * dup() const override
Definition: EtherFrame_m.h:267
long currentSendPkTreeID
Definition: EtherMAC.h:56
virtual void setSrc(const MACAddress &src)
unsigned int framesSentInBurst
Definition: EtherMAC.h:81
int64 halfDuplexFrameMinBytes
Definition: EtherMACBase.h:86
cPacket * frameBeingReceived
Definition: EtherMAC.h:59
unsigned long numCollisions
Definition: EtherMAC.h:79
int64_t int64
Definition: Compat.h:29
cGate * physOutGate
Definition: EtherMACBase.h:144

Member Data Documentation

int inet::EtherMAC::backoffs = 0
protected
simsignal_t inet::EtherMAC::backoffSignal = registerSignal("backoff")
staticprotected

Referenced by handleRetransmission().

long inet::EtherMAC::bytesSentInBurst = 0
protected
simtime_t inet::EtherMAC::channelBusySince
protected
simsignal_t inet::EtherMAC::collisionSignal = registerSignal("collision")
staticprotected
long inet::EtherMAC::currentSendPkTreeID = -1
protected
cMessage* inet::EtherMAC::endBackoffMsg = nullptr
protected
cMessage* inet::EtherMAC::endJammingMsg = nullptr
protected
EndRxTimeList inet::EtherMAC::endRxTimeList
protected
cPacket* inet::EtherMAC::frameBeingReceived = nullptr
protected
unsigned int inet::EtherMAC::framesSentInBurst = 0
protected
unsigned long inet::EtherMAC::numBackoffs = 0
protected
unsigned long inet::EtherMAC::numCollisions = 0
protected
int inet::EtherMAC::numConcurrentTransmissions = 0
protected
simtime_t inet::EtherMAC::totalCollisionTime
protected
simtime_t inet::EtherMAC::totalSuccessfulRxTxTime
protected

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