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

Generic CSMA Mac-Layer. More...

#include <CSMA.h>

Inheritance diagram for inet::CSMA:
inet::MACProtocolBase inet::IMACProtocol inet::LayeredProtocolBase inet::OperationalBase inet::ILifecycle

Public Member Functions

 CSMA ()
 
virtual ~CSMA ()
 
virtual void initialize (int) override
 Initialization of the module and some variables. More...
 
virtual void finish () override
 Delete all dynamically allocated objects of the module. More...
 
virtual void handleLowerPacket (cPacket *) override
 Handle messages from lower layer. More...
 
virtual void handleUpperPacket (cPacket *) override
 Handle messages from upper layer. More...
 
virtual void handleSelfMessage (cMessage *) override
 Handle self messages such as timers. More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, long value, cObject *details) override
 Handle control messages from lower layer. More...
 
- Public Member Functions inherited from inet::OperationalBase
 OperationalBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- Public Member Functions inherited from inet::IMACProtocol
virtual ~IMACProtocol ()
 

Protected Types

enum  t_mac_states {
  IDLE_1 = 1, BACKOFF_2, CCA_3, TRANSMITFRAME_4,
  WAITACK_5, WAITSIFS_6, TRANSMITACK_7
}
 MAC states see states diagram. More...
 
enum  t_mac_timer {
  TIMER_NULL = 0, TIMER_BACKOFF, TIMER_CCA, TIMER_SIFS,
  TIMER_RX_ACK
}
 Kinds for timer messages. More...
 
enum  t_mac_event {
  EV_SEND_REQUEST = 1, EV_TIMER_BACKOFF, EV_FRAME_TRANSMITTED, EV_ACK_RECEIVED,
  EV_ACK_TIMEOUT, EV_FRAME_RECEIVED, EV_DUPLICATE_RECEIVED, EV_TIMER_SIFS,
  EV_BROADCAST_RECEIVED, EV_TIMER_CCA
}
 MAC state machine events. More...
 
enum  t_csma_frame_types { DATA, ACK }
 Types for frames sent by the CSMA. More...
 
enum  t_mac_carrier_sensed { CHANNEL_BUSY = 1, CHANNEL_FREE }
 
enum  t_mac_status {
  STATUS_OK = 1, STATUS_ERROR, STATUS_RX_ERROR, STATUS_RX_TIMEOUT,
  STATUS_FRAME_TO_PROCESS, STATUS_NO_FRAME_TO_PROCESS, STATUS_FRAME_TRANSMITTED
}
 
enum  backoff_methods { CONSTANT = 0, LINEAR, EXPONENTIAL }
 The different back-off methods. More...
 
typedef std::list< CSMAFrame * > MacQueue
 

Protected Member Functions

virtual void initializeMACAddress ()
 Generate new interface address. More...
 
virtual InterfaceEntrycreateInterfaceEntry () override
 
virtual void handleCommand (cMessage *msg)
 
virtual void flushQueue ()
 
virtual void clearQueue ()
 
void fsmError (t_mac_event event, cMessage *msg)
 
void executeMac (t_mac_event event, cMessage *msg)
 Updates state machine. More...
 
void updateStatusIdle (t_mac_event event, cMessage *msg)
 
void updateStatusBackoff (t_mac_event event, cMessage *msg)
 
void updateStatusCCA (t_mac_event event, cMessage *msg)
 
void updateStatusTransmitFrame (t_mac_event event, cMessage *msg)
 
void updateStatusWaitAck (t_mac_event event, cMessage *msg)
 
void updateStatusSIFS (t_mac_event event, cMessage *msg)
 
void updateStatusTransmitAck (t_mac_event event, cMessage *msg)
 
void updateStatusNotIdle (cMessage *msg)
 
void manageQueue ()
 
void updateMacState (t_mac_states newMacState)
 
void attachSignal (CSMAFrame *mac, simtime_t_cref startTime)
 
void manageMissingAck (t_mac_event event, cMessage *msg)
 
void startTimer (t_mac_timer timer)
 
virtual simtime_t scheduleBackoff ()
 
virtual cPacket * decapsMsg (CSMAFrame *macPkt)
 
cObject * setUpControlInfo (cMessage *const pMsg, const MACAddress &pSrcAddr)
 Attaches a "control info" (MacToNetw) structure (object) to the message pMsg. More...
 
- Protected Member Functions inherited from inet::MACProtocolBase
 MACProtocolBase ()
 
virtual void registerInterface ()
 
virtual void sendUp (cMessage *message)
 
virtual void sendDown (cMessage *message)
 
virtual bool isUpperMessage (cMessage *message) override
 
virtual bool isLowerMessage (cMessage *message) override
 
virtual bool isInitializeStage (int stage) override
 
virtual bool isNodeStartStage (int stage) override
 
virtual bool isNodeShutdownStage (int stage) override
 
- Protected Member Functions inherited from inet::LayeredProtocolBase
virtual void handleMessageWhenUp (cMessage *message) override
 
virtual void handleUpperCommand (cMessage *message)
 
virtual void handleLowerCommand (cMessage *message)
 
- Protected Member Functions inherited from inet::OperationalBase
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual bool handleNodeStart (IDoneCallback *doneCallback)
 
virtual bool handleNodeShutdown (IDoneCallback *doneCallback)
 
virtual void handleNodeCrash ()
 
virtual void setOperational (bool isOperational)
 

Protected Attributes

t_mac_states macState
 keep track of MAC state More...
 
t_mac_status status
 
MACAddress address
 The MAC address of the interface. More...
 
IRadioradio
 The radio. More...
 
IRadio::TransmissionState transmissionState
 
simtime_t sifs
 Maximum time between a packet and its ACK. More...
 
simtime_t macAckWaitDuration
 The amount of time the MAC waits for the ACK of a packet. More...
 
int headerLength
 Length of the header. More...
 
bool transmissionAttemptInterruptedByRx
 
simtime_t ccaDetectionTime
 CCA detection time. More...
 
simtime_t rxSetupTime
 Time to setup radio from sleep to Rx state. More...
 
simtime_t aTurnaroundTime
 Time to switch radio from Rx to Tx state. More...
 
int macMaxCSMABackoffs
 maximum number of extra backoffs (excluding the first unconditional one) before frame drop More...
 
unsigned int macMaxFrameRetries
 maximum number of frame retransmissions without ack More...
 
simtime_t aUnitBackoffPeriod
 base time unit for calculating backoff durations More...
 
bool useMACAcks
 Stores if the MAC expects Acks for Unicast packets. More...
 
backoff_methods backoffMethod
 Defines the backoff method to be used. More...
 
int macMinBE
 Minimum backoff exponent. More...
 
int macMaxBE
 Maximum backoff exponent. More...
 
double initialCW
 initial contention window size Only used for linear and constant backoff method. More...
 
double txPower
 The power (in mW) to transmit with. More...
 
int NB
 number of backoff performed until now for current frame More...
 
MacQueue macQueue
 A queue to store packets from upper layer in case another packet is still waiting for transmission. More...
 
unsigned int queueLength
 length of the queue More...
 
unsigned int txAttempts
 count the number of tx attempts More...
 
double bitrate
 the bit rate at which we transmit More...
 
int ackLength
 The bit length of the ACK packet. More...
 
CSMAFrameackMessage
 
std::map< MACAddress, unsigned long > SeqNrParent
 
std::map< MACAddress, unsigned long > SeqNrChild
 
Different tracked statistics.
long nbTxFrames
 
long nbRxFrames
 
long nbMissedAcks
 
long nbRecvdAcks
 
long nbDroppedFrames
 
long nbTxAcks
 
long nbDuplicates
 
long nbBackoffs
 
double backoffValues
 
Pointer for timer messages.
cMessage * backoffTimer
 
cMessage * ccaTimer
 
cMessage * sifsTimer
 
cMessage * rxAckTimer
 
- Protected Attributes inherited from inet::OperationalBase
bool isOperational
 
simtime_t lastChange
 

Private Member Functions

 CSMA (const CSMA &)
 Copy constructor is not allowed. More...
 
CSMAoperator= (const CSMA &)
 Assignment operator is not allowed. More...
 

Additional Inherited Members

- Public Attributes inherited from inet::MACProtocolBase
InterfaceEntryinterfaceEntry
 
int upperLayerInGateId
 Gate ids. More...
 
int upperLayerOutGateId
 
int lowerLayerInGateId
 
int lowerLayerOutGateId
 
- Static Public Attributes inherited from inet::LayeredProtocolBase
static simsignal_t packetSentToUpperSignal = registerSignal("packetSentToUpper")
 
static simsignal_t packetReceivedFromUpperSignal = registerSignal("packetReceivedFromUpper")
 
static simsignal_t packetFromUpperDroppedSignal = registerSignal("packetFromUpperDropped")
 
static simsignal_t packetSentToLowerSignal = registerSignal("packetSentToLower")
 
static simsignal_t packetReceivedFromLowerSignal = registerSignal("packetReceivedFromLower")
 
static simsignal_t packetFromLowerDroppedSignal = registerSignal("packetFromLowerDropped")
 

Detailed Description

Generic CSMA Mac-Layer.

Supports constant, linear and exponential backoffs as well as MAC ACKs.

Author
Jerome Rousselot, Amre El-Hoiydi, Marc Loebbers, Yosia Hadisusanto, Andreas Koepke
Karl Wessel (port for MiXiM)
csmaFSM.png
CSMA Mac-Layer - finite state machine

Member Typedef Documentation

typedef std::list<CSMAFrame *> inet::CSMA::MacQueue
protected

Member Enumeration Documentation

The different back-off methods.

Enumerator
CONSTANT 

Constant back-off time.

LINEAR 

Linear increasing back-off time.

EXPONENTIAL 

Exponentially increasing back-off time.

201  {
203  CONSTANT = 0,
205  LINEAR,
207  EXPONENTIAL,
208  };
Exponentially increasing back-off time.
Definition: CSMA.h:207
Linear increasing back-off time.
Definition: CSMA.h:205
Constant back-off time.
Definition: CSMA.h:203

Types for frames sent by the CSMA.

Enumerator
DATA 
ACK 
180  {
181  DATA,
182  ACK
183  };
Definition: CSMA.h:181
Definition: CSMA.h:182
Enumerator
CHANNEL_BUSY 
CHANNEL_FREE 
185  {
186  CHANNEL_BUSY = 1,
188  };
Definition: CSMA.h:186
Definition: CSMA.h:187
enum inet::CSMA::t_mac_event
protected

MAC state machine events.

See state diagram.

Enumerator
EV_SEND_REQUEST 
EV_TIMER_BACKOFF 
EV_FRAME_TRANSMITTED 
EV_ACK_RECEIVED 
EV_ACK_TIMEOUT 
EV_FRAME_RECEIVED 
EV_DUPLICATE_RECEIVED 
EV_TIMER_SIFS 
EV_BROADCAST_RECEIVED 
EV_TIMER_CCA 
166  {
167  EV_SEND_REQUEST = 1, // 1, 11, 20, 21, 22
168  EV_TIMER_BACKOFF, // 2, 7, 14, 15
169  EV_FRAME_TRANSMITTED, // 4, 19
170  EV_ACK_RECEIVED, // 5
171  EV_ACK_TIMEOUT, // 12
172  EV_FRAME_RECEIVED, // 15, 26
174  EV_TIMER_SIFS, // 17
175  EV_BROADCAST_RECEIVED, // 23, 24
177  };
Definition: CSMA.h:169
Definition: CSMA.h:171
Definition: CSMA.h:175
Definition: CSMA.h:172
Definition: CSMA.h:167
Definition: CSMA.h:173
Definition: CSMA.h:170
Definition: CSMA.h:174
Definition: CSMA.h:168
Definition: CSMA.h:176
enum inet::CSMA::t_mac_states
protected

MAC states see states diagram.

Enumerator
IDLE_1 
BACKOFF_2 
CCA_3 
TRANSMITFRAME_4 
WAITACK_5 
WAITSIFS_6 
TRANSMITACK_7 
136  {
137  IDLE_1 = 1,
138  BACKOFF_2,
139  CCA_3,
141  WAITACK_5,
142  WAITSIFS_6,
144  };
Definition: CSMA.h:139
Definition: CSMA.h:137
Definition: CSMA.h:141
Definition: CSMA.h:143
Definition: CSMA.h:142
Definition: CSMA.h:140
Definition: CSMA.h:138
enum inet::CSMA::t_mac_status
protected
Enumerator
STATUS_OK 
STATUS_ERROR 
STATUS_RX_ERROR 
STATUS_RX_TIMEOUT 
STATUS_FRAME_TO_PROCESS 
STATUS_NO_FRAME_TO_PROCESS 
STATUS_FRAME_TRANSMITTED 
190  {
191  STATUS_OK = 1,
192  STATUS_ERROR,
198  };
Definition: CSMA.h:192
Definition: CSMA.h:191
Definition: CSMA.h:194
Definition: CSMA.h:193
enum inet::CSMA::t_mac_timer
protected

Kinds for timer messages.

Enumerator
TIMER_NULL 
TIMER_BACKOFF 
TIMER_CCA 
TIMER_SIFS 
TIMER_RX_ACK 
151  {
152  TIMER_NULL = 0,
154  TIMER_CCA,
155  TIMER_SIFS,
156  TIMER_RX_ACK,
157  };
Definition: CSMA.h:155
Definition: CSMA.h:152
Definition: CSMA.h:153
Definition: CSMA.h:154
Definition: CSMA.h:156

Constructor & Destructor Documentation

inet::CSMA::CSMA ( )
inline
55  : MACProtocolBase()
56  , nbTxFrames(0)
57  , nbRxFrames(0)
58  , nbMissedAcks(0)
59  , nbRecvdAcks(0)
60  , nbDroppedFrames(0)
61  , nbTxAcks(0)
62  , nbDuplicates(0)
63  , nbBackoffs(0)
64  , backoffValues(0)
65  , backoffTimer(nullptr), ccaTimer(nullptr), sifsTimer(nullptr), rxAckTimer(nullptr)
66  , macState(IDLE_1)
67  , status(STATUS_OK)
68  , radio(nullptr)
70  , sifs()
72  , headerLength(0)
75  , rxSetupTime()
76  , aTurnaroundTime()
80  , useMACAcks(false)
82  , macMinBE(0)
83  , macMaxBE(0)
84  , initialCW(0)
85  , txPower(0)
86  , NB(0)
87  , macQueue()
88  , queueLength(0)
89  , txAttempts(0)
90  , bitrate(0)
91  , ackLength(0)
92  , ackMessage(nullptr)
93  , SeqNrParent()
94  , SeqNrChild()
95  {}
simtime_t aUnitBackoffPeriod
base time unit for calculating backoff durations
Definition: CSMA.h:246
long nbTxAcks
Definition: CSMA.h:127
Definition: CSMA.h:137
std::map< MACAddress, unsigned long > SeqNrChild
Definition: CSMA.h:334
cMessage * rxAckTimer
Definition: CSMA.h:161
long nbMissedAcks
Definition: CSMA.h:124
int headerLength
Length of the header.
Definition: CSMA.h:232
simtime_t ccaDetectionTime
CCA detection time.
Definition: CSMA.h:236
cMessage * backoffTimer
Definition: CSMA.h:161
unsigned int txAttempts
count the number of tx attempts
Definition: CSMA.h:285
int NB
number of backoff performed until now for current frame
Definition: CSMA.h:272
MACProtocolBase()
Definition: MACProtocolBase.cc:22
long nbDroppedFrames
Definition: CSMA.h:126
IRadio::TransmissionState transmissionState
Definition: CSMA.h:219
cMessage * sifsTimer
Definition: CSMA.h:161
IRadio * radio
The radio.
Definition: CSMA.h:218
double txPower
The power (in mW) to transmit with.
Definition: CSMA.h:269
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
t_mac_status status
Definition: CSMA.h:212
backoff_methods backoffMethod
Defines the backoff method to be used.
Definition: CSMA.h:251
bool transmissionAttemptInterruptedByRx
Definition: CSMA.h:234
double backoffValues
Definition: CSMA.h:130
cMessage * ccaTimer
Definition: CSMA.h:161
long nbTxFrames
Definition: CSMA.h:122
double initialCW
initial contention window size Only used for linear and constant backoff method.
Definition: CSMA.h:266
int macMinBE
Minimum backoff exponent.
Definition: CSMA.h:257
unsigned int queueLength
length of the queue
Definition: CSMA.h:279
long nbDuplicates
Definition: CSMA.h:128
simtime_t sifs
Maximum time between a packet and its ACK.
Definition: CSMA.h:226
double bitrate
the bit rate at which we transmit
Definition: CSMA.h:288
unsigned int macMaxFrameRetries
maximum number of frame retransmissions without ack
Definition: CSMA.h:244
t_mac_states macState
keep track of MAC state
Definition: CSMA.h:211
int ackLength
The bit length of the ACK packet.
Definition: CSMA.h:291
int macMaxBE
Maximum backoff exponent.
Definition: CSMA.h:262
simtime_t macAckWaitDuration
The amount of time the MAC waits for the ACK of a packet.
Definition: CSMA.h:229
Definition: CSMA.h:191
long nbRxFrames
Definition: CSMA.h:123
CSMAFrame * ackMessage
Definition: CSMA.h:327
std::map< MACAddress, unsigned long > SeqNrParent
Definition: CSMA.h:331
Constant back-off time.
Definition: CSMA.h:203
int macMaxCSMABackoffs
maximum number of extra backoffs (excluding the first unconditional one) before frame drop ...
Definition: CSMA.h:242
The transmission state is undefined or meaningless.
Definition: IRadio.h:172
simtime_t aTurnaroundTime
Time to switch radio from Rx to Tx state.
Definition: CSMA.h:240
long nbBackoffs
Definition: CSMA.h:129
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276
long nbRecvdAcks
Definition: CSMA.h:125
simtime_t rxSetupTime
Time to setup radio from sleep to Rx state.
Definition: CSMA.h:238
inet::CSMA::~CSMA ( )
virtual
154 {
155  cancelAndDelete(backoffTimer);
156  cancelAndDelete(ccaTimer);
157  cancelAndDelete(sifsTimer);
158  cancelAndDelete(rxAckTimer);
159  if (ackMessage)
160  delete ackMessage;
161  for (auto & elem : macQueue) {
162  delete (elem);
163  }
164 }
cMessage * rxAckTimer
Definition: CSMA.h:161
cMessage * backoffTimer
Definition: CSMA.h:161
cMessage * sifsTimer
Definition: CSMA.h:161
cMessage * ccaTimer
Definition: CSMA.h:161
CSMAFrame * ackMessage
Definition: CSMA.h:327
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276
inet::CSMA::CSMA ( const CSMA )
private

Copy constructor is not allowed.

Member Function Documentation

void inet::CSMA::attachSignal ( CSMAFrame mac,
simtime_t_cref  startTime 
)
protected

Referenced by updateStatusCCA(), and updateStatusSIFS().

376 {
377  simtime_t duration = mac->getBitLength() / bitrate;
378  mac->setDuration(duration);
379 }
double bitrate
the bit rate at which we transmit
Definition: CSMA.h:288
void inet::CSMA::clearQueue ( )
protectedvirtual
371 {
372  macQueue.clear();
373 }
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276
InterfaceEntry * inet::CSMA::createInterfaceEntry ( )
overrideprotectedvirtual

Implements inet::MACProtocolBase.

183 {
184  InterfaceEntry *e = new InterfaceEntry(this);
185 
186  // data rate
187  e->setDatarate(bitrate);
188 
189  // generate a link-layer address to be used as interface token for IPv6
190  e->setMACAddress(address);
191  e->setInterfaceToken(address.formInterfaceIdentifier());
192 
193  // capabilities
194  e->setMtu(par("mtu").longValue());
195  e->setMulticast(false);
196  e->setBroadcast(true);
197 
198  return e;
199 }
double bitrate
the bit rate at which we transmit
Definition: CSMA.h:288
const value< double, units::C > e(1.602176487e-19)
MACAddress address
The MAC address of the interface.
Definition: CSMA.h:215
InterfaceToken formInterfaceIdentifier() const
Create interface identifier (IEEE EUI-64) which can be used by IPv6 stateless address autoconfigurati...
Definition: MACAddress.cc:136
cPacket * inet::CSMA::decapsMsg ( CSMAFrame macPkt)
protectedvirtual

Referenced by updateStatusBackoff(), updateStatusCCA(), updateStatusIdle(), updateStatusSIFS(), and updateStatusWaitAck().

940 {
941  cPacket *msg = macPkt->decapsulate();
942  setUpControlInfo(msg, macPkt->getSrcAddr());
943 
944  return msg;
945 }
cObject * setUpControlInfo(cMessage *const pMsg, const MACAddress &pSrcAddr)
Attaches a "control info" (MacToNetw) structure (object) to the message pMsg.
Definition: CSMA.cc:950
void inet::CSMA::executeMac ( t_mac_event  event,
cMessage *  msg 
)
protected

Updates state machine.

Referenced by handleLowerPacket(), handleSelfMessage(), handleUpperPacket(), and receiveSignal().

658 {
659  EV_DETAIL << "In executeMac" << endl;
660  if (macState != IDLE_1 && event == EV_SEND_REQUEST) {
661  updateStatusNotIdle(msg);
662  }
663  else {
664  switch (macState) {
665  case IDLE_1:
666  updateStatusIdle(event, msg);
667  break;
668 
669  case BACKOFF_2:
670  updateStatusBackoff(event, msg);
671  break;
672 
673  case CCA_3:
674  updateStatusCCA(event, msg);
675  break;
676 
677  case TRANSMITFRAME_4:
678  updateStatusTransmitFrame(event, msg);
679  break;
680 
681  case WAITACK_5:
682  updateStatusWaitAck(event, msg);
683  break;
684 
685  case WAITSIFS_6:
686  updateStatusSIFS(event, msg);
687  break;
688 
689  case TRANSMITACK_7:
690  updateStatusTransmitAck(event, msg);
691  break;
692 
693  default:
694  EV << "Error in CSMA FSM: an unknown state has been reached. macState=" << macState << endl;
695  break;
696  }
697  }
698 }
Definition: CSMA.h:139
void updateStatusTransmitFrame(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:481
Definition: CSMA.h:137
Definition: CSMA.h:141
Definition: CSMA.h:167
Definition: CSMA.h:143
Definition: CSMA.h:142
void updateStatusWaitAck(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:519
void updateStatusCCA(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:381
Definition: CSMA.h:140
t_mac_states macState
keep track of MAC state
Definition: CSMA.h:211
void updateStatusNotIdle(cMessage *msg)
Definition: CSMA.cc:635
void updateStatusBackoff(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:298
void updateStatusTransmitAck(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:619
void updateStatusSIFS(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:582
Definition: CSMA.h:138
void updateStatusIdle(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:239
void inet::CSMA::finish ( )
overridevirtual

Delete all dynamically allocated objects of the module.

135 {
136  recordScalar("nbTxFrames", nbTxFrames);
137  recordScalar("nbRxFrames", nbRxFrames);
138  recordScalar("nbDroppedFrames", nbDroppedFrames);
139  recordScalar("nbMissedAcks", nbMissedAcks);
140  recordScalar("nbRecvdAcks", nbRecvdAcks);
141  recordScalar("nbTxAcks", nbTxAcks);
142  recordScalar("nbDuplicates", nbDuplicates);
143  if (nbBackoffs > 0) {
144  recordScalar("meanBackoff", backoffValues / nbBackoffs);
145  }
146  else {
147  recordScalar("meanBackoff", 0);
148  }
149  recordScalar("nbBackoffs", nbBackoffs);
150  recordScalar("backoffDurations", backoffValues);
151 }
long nbTxAcks
Definition: CSMA.h:127
long nbMissedAcks
Definition: CSMA.h:124
long nbDroppedFrames
Definition: CSMA.h:126
double backoffValues
Definition: CSMA.h:130
long nbTxFrames
Definition: CSMA.h:122
long nbDuplicates
Definition: CSMA.h:128
long nbRxFrames
Definition: CSMA.h:123
long nbBackoffs
Definition: CSMA.h:129
long nbRecvdAcks
Definition: CSMA.h:125
void inet::CSMA::flushQueue ( )
protectedvirtual
365 {
366  // TODO:
367  macQueue.clear();
368 }
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276
void inet::CSMA::fsmError ( t_mac_event  event,
cMessage *  msg 
)
protected

Referenced by updateStatusBackoff(), updateStatusCCA(), updateStatusIdle(), updateStatusSIFS(), updateStatusTransmitAck(), updateStatusTransmitFrame(), and updateStatusWaitAck().

735 {
736  EV << "FSM Error ! In state " << macState << ", received unknown event:" << event << "." << endl;
737  if (msg != nullptr)
738  delete msg;
739 }
t_mac_states macState
keep track of MAC state
Definition: CSMA.h:211
virtual void inet::CSMA::handleCommand ( cMessage *  msg)
inlineprotectedvirtual
297 {}
void inet::CSMA::handleLowerPacket ( cPacket *  msg)
overridevirtual

Handle messages from lower layer.

Compares the address of this Host with the destination address in frame.

Generates the corresponding event.

Implements inet::LayeredProtocolBase.

835 {
836  if (msg->hasBitError()) {
837  EV << "Received " << msg << " contains bit errors or collision, dropping it\n";
838  delete msg;
839  return;
840  }
841  CSMAFrame *macPkt = static_cast<CSMAFrame *>(msg);
842  const MACAddress& src = macPkt->getSrcAddr();
843  const MACAddress& dest = macPkt->getDestAddr();
844  long ExpectedNr = 0;
845 
846  EV_DETAIL << "Received frame name= " << macPkt->getName()
847  << ", myState=" << macState << " src=" << src
848  << " dst=" << dest << " myAddr="
849  << address << endl;
850 
851  if (dest == address) {
852  if (!useMACAcks) {
853  EV_DETAIL << "Received a data packet addressed to me." << endl;
854 // nbRxFrames++;
855  executeMac(EV_FRAME_RECEIVED, macPkt);
856  }
857  else {
858  long SeqNr = macPkt->getSequenceId();
859 
860  if (strcmp(macPkt->getName(), "CSMA-Ack") != 0) {
861  // This is a data message addressed to us
862  // and we should send an ack.
863  // we build the ack packet here because we need to
864  // copy data from macPkt (src).
865  EV_DETAIL << "Received a data packet addressed to me,"
866  << " preparing an ack..." << endl;
867 
868 // nbRxFrames++;
869 
870  if (ackMessage != nullptr)
871  delete ackMessage;
872  ackMessage = new CSMAFrame("CSMA-Ack");
874  ackMessage->setDestAddr(src);
875  ackMessage->setBitLength(ackLength);
876  //Check for duplicates by checking expected seqNr of sender
877  if (SeqNrChild.find(src) == SeqNrChild.end()) {
878  //no record of current child -> add expected next number to map
879  SeqNrChild[src] = SeqNr + 1;
880  EV_DETAIL << "Adding a new child to the map of Sequence numbers:" << src << endl;
881  executeMac(EV_FRAME_RECEIVED, macPkt);
882  }
883  else {
884  ExpectedNr = SeqNrChild[src];
885  EV_DETAIL << "Expected Sequence number is " << ExpectedNr
886  << " and number of packet is " << SeqNr << endl;
887  if (SeqNr < ExpectedNr) {
888  //Duplicate Packet, count and do not send to upper layer
889  nbDuplicates++;
891  }
892  else {
893  SeqNrChild[src] = SeqNr + 1;
894  executeMac(EV_FRAME_RECEIVED, macPkt);
895  }
896  }
897  }
898  else if (macQueue.size() != 0) {
899  // message is an ack, and it is for us.
900  // Is it from the right node ?
901  CSMAFrame *firstPacket = static_cast<CSMAFrame *>(macQueue.front());
902  if (src == firstPacket->getDestAddr()) {
903  nbRecvdAcks++;
904  executeMac(EV_ACK_RECEIVED, macPkt);
905  }
906  else {
907  EV << "Error! Received an ack from an unexpected source: src=" << src << ", I was expecting from node addr=" << firstPacket->getDestAddr() << endl;
908  delete macPkt;
909  }
910  }
911  else {
912  EV << "Error! Received an Ack while my send queue was empty. src=" << src << "." << endl;
913  delete macPkt;
914  }
915  }
916  }
917  else if (dest.isBroadcast()) {
919  }
920  else {
921  EV_DETAIL << "packet not for me, deleting...\n";
922  delete macPkt;
923  }
924 }
std::map< MACAddress, unsigned long > SeqNrChild
Definition: CSMA.h:334
Definition: CSMA.h:175
Definition: CSMA.h:172
virtual void setSrcAddr(const MACAddress &srcAddr)
Definition: CSMA.h:173
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
Definition: CSMA.h:170
long nbDuplicates
Definition: CSMA.h:128
void executeMac(t_mac_event event, cMessage *msg)
Updates state machine.
Definition: CSMA.cc:657
t_mac_states macState
keep track of MAC state
Definition: CSMA.h:211
int ackLength
The bit length of the ACK packet.
Definition: CSMA.h:291
virtual void setDestAddr(const MACAddress &destAddr)
MACAddress address
The MAC address of the interface.
Definition: CSMA.h:215
CSMAFrame * ackMessage
Definition: CSMA.h:327
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276
long nbRecvdAcks
Definition: CSMA.h:125
void inet::CSMA::handleSelfMessage ( cMessage *  msg)
overridevirtual

Handle self messages such as timers.

Reimplemented from inet::LayeredProtocolBase.

814 {
815  EV_DETAIL << "timer routine." << endl;
816  if (msg == backoffTimer)
818  else if (msg == ccaTimer)
819  executeMac(EV_TIMER_CCA, msg);
820  else if (msg == sifsTimer)
822  else if (msg == rxAckTimer) {
823  nbMissedAcks++;
825  }
826  else
827  EV << "CSMA Error: unknown timer fired:" << msg << endl;
828 }
Definition: CSMA.h:171
cMessage * rxAckTimer
Definition: CSMA.h:161
long nbMissedAcks
Definition: CSMA.h:124
cMessage * backoffTimer
Definition: CSMA.h:161
cMessage * sifsTimer
Definition: CSMA.h:161
cMessage * ccaTimer
Definition: CSMA.h:161
Definition: CSMA.h:174
void executeMac(t_mac_event event, cMessage *msg)
Updates state machine.
Definition: CSMA.cc:657
Definition: CSMA.h:168
Definition: CSMA.h:176
void inet::CSMA::handleUpperPacket ( cPacket *  msg)
overridevirtual

Handle messages from upper layer.

Encapsulates the message to be transmitted and pass it on to the FSM main method for further processing.

Implements inet::LayeredProtocolBase.

206 {
207  //MacPkt*macPkt = encapsMsg(msg);
208  CSMAFrame *macPkt = new CSMAFrame(msg->getName());
209  macPkt->setBitLength(headerLength);
210  IMACProtocolControlInfo *const cInfo = check_and_cast<IMACProtocolControlInfo *>(msg->removeControlInfo());
211  EV_DETAIL << "CSMA received a message from upper layer, name is " << msg->getName() << ", CInfo removed, mac addr=" << cInfo->getDestinationAddress() << endl;
212  MACAddress dest = cInfo->getDestinationAddress();
213  macPkt->setDestAddr(dest);
214  delete cInfo;
215  macPkt->setSrcAddr(address);
216 
217  if (useMACAcks) {
218  if (SeqNrParent.find(dest) == SeqNrParent.end()) {
219  //no record of current parent -> add next sequence number to map
220  SeqNrParent[dest] = 1;
221  macPkt->setSequenceId(0);
222  EV_DETAIL << "Adding a new parent to the map of Sequence numbers:" << dest << endl;
223  }
224  else {
225  macPkt->setSequenceId(SeqNrParent[dest]);
226  EV_DETAIL << "Packet send with sequence number = " << SeqNrParent[dest] << endl;
227  SeqNrParent[dest]++;
228  }
229  }
230 
231  //RadioAccNoise3PhyControlInfo *pco = new RadioAccNoise3PhyControlInfo(bitrate);
232  //macPkt->setControlInfo(pco);
233  assert(static_cast<cPacket *>(msg));
234  macPkt->encapsulate(static_cast<cPacket *>(msg));
235  EV_DETAIL << "pkt encapsulated, length: " << macPkt->getBitLength() << "\n";
236  executeMac(EV_SEND_REQUEST, macPkt);
237 }
int headerLength
Length of the header.
Definition: CSMA.h:232
Definition: CSMA.h:167
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
void executeMac(t_mac_event event, cMessage *msg)
Updates state machine.
Definition: CSMA.cc:657
MACAddress address
The MAC address of the interface.
Definition: CSMA.h:215
std::map< MACAddress, unsigned long > SeqNrParent
Definition: CSMA.h:331
void inet::CSMA::initialize ( int  stage)
overridevirtual

Initialization of the module and some variables.

Reimplemented from inet::MACProtocolBase.

45 {
47  if (stage == INITSTAGE_LOCAL) {
48  useMACAcks = par("useMACAcks").boolValue();
49  queueLength = par("queueLength");
50  sifs = par("sifs");
52  nbTxFrames = 0;
53  nbRxFrames = 0;
54  nbMissedAcks = 0;
55  nbTxAcks = 0;
56  nbRecvdAcks = 0;
57  nbDroppedFrames = 0;
58  nbDuplicates = 0;
59  nbBackoffs = 0;
60  backoffValues = 0;
61  macMaxCSMABackoffs = par("macMaxCSMABackoffs");
62  macMaxFrameRetries = par("macMaxFrameRetries");
63  macAckWaitDuration = par("macAckWaitDuration").doubleValue();
64  aUnitBackoffPeriod = par("aUnitBackoffPeriod").doubleValue();
65  ccaDetectionTime = par("ccaDetectionTime").doubleValue();
66  rxSetupTime = par("rxSetupTime").doubleValue();
67  aTurnaroundTime = par("aTurnaroundTime").doubleValue();
68  bitrate = par("bitrate");
69  ackLength = par("ackLength");
70  ackMessage = nullptr;
71 
72  //init parameters for backoff method
73  std::string backoffMethodStr = par("backoffMethod").stdstringValue();
74  if (backoffMethodStr == "exponential") {
76  macMinBE = par("macMinBE");
77  macMaxBE = par("macMaxBE");
78  }
79  else {
80  if (backoffMethodStr == "linear") {
82  }
83  else if (backoffMethodStr == "constant") {
85  }
86  else {
87  throw cRuntimeError("Unknown backoff method \"%s\".\
88  Use \"constant\", \"linear\" or \"\
89  \"exponential\".", backoffMethodStr.c_str());
90  }
91  initialCW = par("contentionWindow");
92  }
93  NB = 0;
94 
95  // initialize the timers
96  backoffTimer = new cMessage("timer-backoff");
97  ccaTimer = new cMessage("timer-cca");
98  sifsTimer = new cMessage("timer-sifs");
99  rxAckTimer = new cMessage("timer-rxAck");
100  macState = IDLE_1;
101  txAttempts = 0;
102 
105 
106  cModule *radioModule = getModuleFromPar<cModule>(par("radioModule"), this);
107  radioModule->subscribe(IRadio::radioModeChangedSignal, this);
108  radioModule->subscribe(IRadio::transmissionStateChangedSignal, this);
109  radio = check_and_cast<IRadio *>(radioModule);
110 
111  //check parameters for consistency
112  //aTurnaroundTime should match (be equal or bigger) the RX to TX
113  //switching time of the radio
114  if (radioModule->hasPar("timeRXToTX")) {
115  simtime_t rxToTx = radioModule->par("timeRXToTX").doubleValue();
116  if (rxToTx > aTurnaroundTime) {
117  throw cRuntimeError("Parameter \"aTurnaroundTime\" (%f) does not match"
118  " the radios RX to TX switching time (%f)! It"
119  " should be equal or bigger",
120  SIMTIME_DBL(aTurnaroundTime), SIMTIME_DBL(rxToTx));
121  }
122  }
123  }
124  else if (stage == INITSTAGE_LINK_LAYER) {
126  EV_DETAIL << "queueLength = " << queueLength
127  << " bitrate = " << bitrate
128  << " backoff method = " << par("backoffMethod").stringValue() << endl;
129 
130  EV_DETAIL << "finished csma init stage 1." << endl;
131  }
132 }
simtime_t aUnitBackoffPeriod
base time unit for calculating backoff durations
Definition: CSMA.h:246
long nbTxAcks
Definition: CSMA.h:127
Definition: CSMA.h:137
cMessage * rxAckTimer
Definition: CSMA.h:161
long nbMissedAcks
Definition: CSMA.h:124
Exponentially increasing back-off time.
Definition: CSMA.h:207
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
simtime_t ccaDetectionTime
CCA detection time.
Definition: CSMA.h:236
cMessage * backoffTimer
Definition: CSMA.h:161
unsigned int txAttempts
count the number of tx attempts
Definition: CSMA.h:285
int NB
number of backoff performed until now for current frame
Definition: CSMA.h:272
virtual void initialize(int stage) override
Definition: MACProtocolBase.cc:31
long nbDroppedFrames
Definition: CSMA.h:126
cMessage * sifsTimer
Definition: CSMA.h:161
IRadio * radio
The radio.
Definition: CSMA.h:218
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
backoff_methods backoffMethod
Defines the backoff method to be used.
Definition: CSMA.h:251
bool transmissionAttemptInterruptedByRx
Definition: CSMA.h:234
double backoffValues
Definition: CSMA.h:130
cMessage * ccaTimer
Definition: CSMA.h:161
long nbTxFrames
Definition: CSMA.h:122
double initialCW
initial contention window size Only used for linear and constant backoff method.
Definition: CSMA.h:266
int macMinBE
Minimum backoff exponent.
Definition: CSMA.h:257
Local initializations.
Definition: InitStages.h:35
Initialization of link-layer protocols.
Definition: InitStages.h:59
unsigned int queueLength
length of the queue
Definition: CSMA.h:279
long nbDuplicates
Definition: CSMA.h:128
simtime_t sifs
Maximum time between a packet and its ACK.
Definition: CSMA.h:226
double bitrate
the bit rate at which we transmit
Definition: CSMA.h:288
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:109
virtual void initializeMACAddress()
Generate new interface address.
Definition: CSMA.cc:166
unsigned int macMaxFrameRetries
maximum number of frame retransmissions without ack
Definition: CSMA.h:244
t_mac_states macState
keep track of MAC state
Definition: CSMA.h:211
int ackLength
The bit length of the ACK packet.
Definition: CSMA.h:291
int macMaxBE
Maximum backoff exponent.
Definition: CSMA.h:262
virtual void registerInterface()
Definition: MACProtocolBase.cc:42
simtime_t macAckWaitDuration
The amount of time the MAC waits for the ACK of a packet.
Definition: CSMA.h:229
long nbRxFrames
Definition: CSMA.h:123
Linear increasing back-off time.
Definition: CSMA.h:205
CSMAFrame * ackMessage
Definition: CSMA.h:327
Constant back-off time.
Definition: CSMA.h:203
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
int macMaxCSMABackoffs
maximum number of extra backoffs (excluding the first unconditional one) before frame drop ...
Definition: CSMA.h:242
simtime_t aTurnaroundTime
Time to switch radio from Rx to Tx state.
Definition: CSMA.h:240
long nbBackoffs
Definition: CSMA.h:129
static simsignal_t radioModeChangedSignal
This signal is emitted every time the radio mode changes.
Definition: IRadio.h:54
long nbRecvdAcks
Definition: CSMA.h:125
simtime_t rxSetupTime
Time to setup radio from sleep to Rx state.
Definition: CSMA.h:238
void inet::CSMA::initializeMACAddress ( )
protectedvirtual

Generate new interface address.

Referenced by initialize().

167 {
168  const char *addrstr = par("address");
169 
170  if (!strcmp(addrstr, "auto")) {
171  // assign automatic address
173 
174  // change module parameter from "auto" to concrete address
175  par("address").setStringValue(address.str().c_str());
176  }
177  else {
178  address.setAddress(addrstr);
179  }
180 }
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
MACAddress address
The MAC address of the interface.
Definition: CSMA.h:215
void inet::CSMA::manageMissingAck ( t_mac_event  event,
cMessage *  msg 
)
protected

Referenced by updateStatusWaitAck().

560 {
562  // increment counter
563  txAttempts++;
564  EV_DETAIL << "I will retransmit this packet (I already tried "
565  << txAttempts << " times)." << endl;
566  }
567  else {
568  // drop packet
569  EV_DETAIL << "Packet was transmitted " << txAttempts
570  << " times and I never got an Ack. I drop the packet." << endl;
571  cMessage *mac = macQueue.front();
572  macQueue.pop_front();
573  txAttempts = 0;
574  // TODO: send dropped signal
575  // emit(packetDropped, mac);
576  emit(NF_LINK_BREAK, mac);
577  delete mac;
578  }
579  manageQueue();
580 }
simsignal_t NF_LINK_BREAK
Definition: NotifierConsts.cc:43
unsigned int txAttempts
count the number of tx attempts
Definition: CSMA.h:285
unsigned int macMaxFrameRetries
maximum number of frame retransmissions without ack
Definition: CSMA.h:244
void manageQueue()
Definition: CSMA.cc:700
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276
void inet::CSMA::manageQueue ( )
protected

Referenced by manageMissingAck(), updateStatusCCA(), updateStatusTransmitAck(), updateStatusTransmitFrame(), and updateStatusWaitAck().

701 {
702  if (macQueue.size() != 0) {
703  EV_DETAIL << "(manageQueue) there are " << macQueue.size() << " packets to send, entering backoff wait state." << endl;
705  // resume a transmission cycle which was interrupted by
706  // a frame reception during CCA check
708  }
709  else {
710  // initialize counters if we start a new transmission
711  // cycle from zero
712  NB = 0;
713  //BE = macMinBE;
714  }
715  if (!backoffTimer->isScheduled()) {
717  }
719  }
720  else {
721  EV_DETAIL << "(manageQueue) no packets to send, entering IDLE state." << endl;
723  }
724 }
Definition: CSMA.h:137
cMessage * backoffTimer
Definition: CSMA.h:161
int NB
number of backoff performed until now for current frame
Definition: CSMA.h:272
bool transmissionAttemptInterruptedByRx
Definition: CSMA.h:234
Definition: CSMA.h:153
Definition: CSMA.h:138
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276
void startTimer(t_mac_timer timer)
Definition: CSMA.cc:741
void updateMacState(t_mac_states newMacState)
Definition: CSMA.cc:726
CSMA& inet::CSMA::operator= ( const CSMA )
private

Assignment operator is not allowed.

void inet::CSMA::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
long  value,
cObject *  details 
)
overridevirtual

Handle control messages from lower layer.

927 {
928  Enter_Method_Silent();
929  if (signalID == IRadio::transmissionStateChangedSignal) {
930  IRadio::TransmissionState newRadioTransmissionState = (IRadio::TransmissionState)value;
932  // KLUDGE: we used to get a cMessage from the radio (the identity was not important)
933  executeMac(EV_FRAME_TRANSMITTED, new cMessage("Transmission over"));
934  }
935  transmissionState = newRadioTransmissionState;
936  }
937 }
Definition: CSMA.h:169
TransmissionState
This enumeration specifies the transmission state of the radio.
Definition: IRadio.h:167
The radio is not transmitting a signal on the radio medium.
Definition: IRadio.h:178
IRadio::TransmissionState transmissionState
Definition: CSMA.h:219
The radio medium is busy, the radio is currently transmitting a signal.
Definition: IRadio.h:183
void executeMac(t_mac_event event, cMessage *msg)
Updates state machine.
Definition: CSMA.cc:657
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
simtime_t inet::CSMA::scheduleBackoff ( )
protectedvirtual

Referenced by startTimer().

769 {
770  simtime_t backoffTime;
771 
772  switch (backoffMethod) {
773  case EXPONENTIAL: {
774  int BE = std::min(macMinBE + NB, macMaxBE);
775  int v = (1 << BE) - 1;
776  int r = intuniform(0, v, 0);
777  backoffTime = r * aUnitBackoffPeriod;
778 
779  EV_DETAIL << "(startTimer) backoffTimer value=" << backoffTime
780  << " (BE=" << BE << ", 2^BE-1= " << v << "r="
781  << r << ")" << endl;
782  break;
783  }
784 
785  case LINEAR: {
786  int slots = intuniform(1, initialCW + NB, 0);
787  backoffTime = slots * aUnitBackoffPeriod;
788  EV_DETAIL << "(startTimer) backoffTimer value=" << backoffTime << endl;
789  break;
790  }
791 
792  case CONSTANT: {
793  int slots = intuniform(1, initialCW, 0);
794  backoffTime = slots * aUnitBackoffPeriod;
795  EV_DETAIL << "(startTimer) backoffTimer value=" << backoffTime << endl;
796  break;
797  }
798 
799  default:
800  throw cRuntimeError("Unknown backoff method!");
801  break;
802  }
803 
804  nbBackoffs = nbBackoffs + 1;
805  backoffValues = backoffValues + SIMTIME_DBL(backoffTime);
806 
807  return backoffTime + simTime();
808 }
simtime_t aUnitBackoffPeriod
base time unit for calculating backoff durations
Definition: CSMA.h:246
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SCTPAssociation.h:270
Exponentially increasing back-off time.
Definition: CSMA.h:207
int NB
number of backoff performed until now for current frame
Definition: CSMA.h:272
backoff_methods backoffMethod
Defines the backoff method to be used.
Definition: CSMA.h:251
double backoffValues
Definition: CSMA.h:130
double initialCW
initial contention window size Only used for linear and constant backoff method.
Definition: CSMA.h:266
int macMinBE
Minimum backoff exponent.
Definition: CSMA.h:257
int macMaxBE
Maximum backoff exponent.
Definition: CSMA.h:262
Linear increasing back-off time.
Definition: CSMA.h:205
Constant back-off time.
Definition: CSMA.h:203
long nbBackoffs
Definition: CSMA.h:129
cObject * inet::CSMA::setUpControlInfo ( cMessage *const  pMsg,
const MACAddress pSrcAddr 
)
protected

Attaches a "control info" (MacToNetw) structure (object) to the message pMsg.

Referenced by decapsMsg().

951 {
952  SimpleLinkLayerControlInfo *const cCtrlInfo = new SimpleLinkLayerControlInfo();
953  cCtrlInfo->setSrc(pSrcAddr);
954  pMsg->setControlInfo(cCtrlInfo);
955  return cCtrlInfo;
956 }
void inet::CSMA::startTimer ( t_mac_timer  timer)
protected

Referenced by manageQueue(), updateStatusBackoff(), updateStatusCCA(), updateStatusIdle(), updateStatusSIFS(), and updateStatusTransmitFrame().

742 {
743  if (timer == TIMER_BACKOFF) {
744  scheduleAt(scheduleBackoff(), backoffTimer);
745  }
746  else if (timer == TIMER_CCA) {
747  simtime_t ccaTime = rxSetupTime + ccaDetectionTime;
748  EV_DETAIL << "(startTimer) ccaTimer value=" << ccaTime
749  << "(rxSetupTime,ccaDetectionTime:" << rxSetupTime
750  << "," << ccaDetectionTime << ")." << endl;
751  scheduleAt(simTime() + rxSetupTime + ccaDetectionTime, ccaTimer);
752  }
753  else if (timer == TIMER_SIFS) {
754  assert(useMACAcks);
755  EV_DETAIL << "(startTimer) sifsTimer value=" << sifs << endl;
756  scheduleAt(simTime() + sifs, sifsTimer);
757  }
758  else if (timer == TIMER_RX_ACK) {
759  assert(useMACAcks);
760  EV_DETAIL << "(startTimer) rxAckTimer value=" << macAckWaitDuration << endl;
761  scheduleAt(simTime() + macAckWaitDuration, rxAckTimer);
762  }
763  else {
764  EV << "Unknown timer requested to start:" << timer << endl;
765  }
766 }
cMessage * rxAckTimer
Definition: CSMA.h:161
Definition: CSMA.h:155
simtime_t ccaDetectionTime
CCA detection time.
Definition: CSMA.h:236
cMessage * backoffTimer
Definition: CSMA.h:161
cMessage * sifsTimer
Definition: CSMA.h:161
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
cMessage * ccaTimer
Definition: CSMA.h:161
Definition: CSMA.h:153
Definition: CSMA.h:154
simtime_t sifs
Maximum time between a packet and its ACK.
Definition: CSMA.h:226
virtual simtime_t scheduleBackoff()
Definition: CSMA.cc:768
simtime_t macAckWaitDuration
The amount of time the MAC waits for the ACK of a packet.
Definition: CSMA.h:229
Definition: CSMA.h:156
simtime_t rxSetupTime
Time to setup radio from sleep to Rx state.
Definition: CSMA.h:238
void inet::CSMA::updateMacState ( t_mac_states  newMacState)
protected

Referenced by manageQueue(), updateStatusBackoff(), updateStatusCCA(), updateStatusIdle(), updateStatusSIFS(), and updateStatusTransmitFrame().

727 {
728  macState = newMacState;
729 }
t_mac_states macState
keep track of MAC state
Definition: CSMA.h:211
void inet::CSMA::updateStatusBackoff ( t_mac_event  event,
cMessage *  msg 
)
protected

Referenced by executeMac().

299 {
300  switch (event) {
301  case EV_TIMER_BACKOFF:
302  EV_DETAIL << "(2) FSM State BACKOFF, EV_TIMER_BACKOFF:"
303  << " starting CCA timer." << endl;
307  break;
308 
310  // suspend current transmission attempt,
311  // transmit ack,
312  // and resume transmission when entering manageQueue()
313  EV_DETAIL << "(28) FSM State BACKOFF, EV_DUPLICATE_RECEIVED:";
314  if (useMACAcks) {
315  EV_DETAIL << "suspending current transmit tentative and transmitting ack";
317  cancelEvent(backoffTimer);
321  }
322  else {
323  EV_DETAIL << "Nothing to do.";
324  }
325  //sendUp(decapsMsg(static_cast<MacSeqPkt *>(msg)));
326  delete msg;
327 
328  break;
329 
330  case EV_FRAME_RECEIVED:
331  // suspend current transmission attempt,
332  // transmit ack,
333  // and resume transmission when entering manageQueue()
334  EV_DETAIL << "(28) FSM State BACKOFF, EV_FRAME_RECEIVED:";
335  if (useMACAcks) {
336  EV_DETAIL << "suspending current transmit tentative and transmitting ack";
338  cancelEvent(backoffTimer);
339 
343  }
344  else {
345  EV_DETAIL << "sending frame up and resuming normal operation.";
346  }
347  sendUp(decapsMsg(static_cast<CSMAFrame *>(msg)));
348  delete msg;
349  break;
350 
352  EV_DETAIL << "(29) FSM State BACKOFF, EV_BROADCAST_RECEIVED:"
353  << "sending frame up and resuming normal operation." << endl;
354  sendUp(decapsMsg(static_cast<CSMAFrame *>(msg)));
355  delete msg;
356  break;
357 
358  default:
359  fsmError(event, msg);
360  break;
361  }
362 }
Definition: CSMA.h:139
Definition: CSMA.h:175
Definition: CSMA.h:155
Definition: CSMA.h:172
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
cMessage * backoffTimer
Definition: CSMA.h:161
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:116
Definition: CSMA.h:142
Definition: CSMA.h:173
virtual cPacket * decapsMsg(CSMAFrame *macPkt)
Definition: CSMA.cc:939
IRadio * radio
The radio.
Definition: CSMA.h:218
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
bool transmissionAttemptInterruptedByRx
Definition: CSMA.h:234
virtual void sendUp(cMessage *message)
Definition: MACProtocolBase.cc:52
Definition: CSMA.h:154
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:109
void fsmError(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:734
Definition: CSMA.h:168
void startTimer(t_mac_timer timer)
Definition: CSMA.cc:741
void updateMacState(t_mac_states newMacState)
Definition: CSMA.cc:726
void inet::CSMA::updateStatusCCA ( t_mac_event  event,
cMessage *  msg 
)
protected

Referenced by executeMac().

382 {
383  switch (event) {
384  case EV_TIMER_CCA: {
385  EV_DETAIL << "(25) FSM State CCA_3, EV_TIMER_CCA" << endl;
387  if (isIdle) {
388  EV_DETAIL << "(3) FSM State CCA_3, EV_TIMER_CCA, [Channel Idle]: -> TRANSMITFRAME_4." << endl;
391  CSMAFrame *mac = check_and_cast<CSMAFrame *>(macQueue.front()->dup());
392  attachSignal(mac, simTime() + aTurnaroundTime);
393  //sendDown(msg);
394  // give time for the radio to be in Tx state before transmitting
395  sendDelayed(mac, aTurnaroundTime, lowerLayerOutGateId);
396  nbTxFrames++;
397  }
398  else {
399  // Channel was busy, increment 802.15.4 backoff timers as specified.
400  EV_DETAIL << "(7) FSM State CCA_3, EV_TIMER_CCA, [Channel Busy]: "
401  << " increment counters." << endl;
402  NB = NB + 1;
403  //BE = std::min(BE+1, macMaxBE);
404 
405  // decide if we go for another backoff or if we drop the frame.
406  if (NB > macMaxCSMABackoffs) {
407  // drop the frame
408  EV_DETAIL << "Tried " << NB << " backoffs, all reported a busy "
409  << "channel. Dropping the packet." << endl;
410  cMessage *mac = macQueue.front();
411  macQueue.pop_front();
412  txAttempts = 0;
413  nbDroppedFrames++;
414  emit(packetFromUpperDroppedSignal, mac);
415  delete mac;
416  manageQueue();
417  }
418  else {
419  // redo backoff
422  }
423  }
424  break;
425  }
426 
428  EV_DETAIL << "(26) FSM State CCA_3, EV_DUPLICATE_RECEIVED:";
429  if (useMACAcks) {
430  EV_DETAIL << " setting up radio tx -> WAITSIFS." << endl;
431  // suspend current transmission attempt,
432  // transmit ack,
433  // and resume transmission when entering manageQueue()
435  cancelEvent(ccaTimer);
436 
440  }
441  else {
442  EV_DETAIL << " Nothing to do." << endl;
443  }
444  //sendUp(decapsMsg(static_cast<MacPkt*>(msg)));
445  delete msg;
446  break;
447 
448  case EV_FRAME_RECEIVED:
449  EV_DETAIL << "(26) FSM State CCA_3, EV_FRAME_RECEIVED:";
450  if (useMACAcks) {
451  EV_DETAIL << " setting up radio tx -> WAITSIFS." << endl;
452  // suspend current transmission attempt,
453  // transmit ack,
454  // and resume transmission when entering manageQueue()
456  cancelEvent(ccaTimer);
460  }
461  else {
462  EV_DETAIL << " Nothing to do." << endl;
463  }
464  sendUp(decapsMsg(static_cast<CSMAFrame *>(msg)));
465  delete msg;
466  break;
467 
469  EV_DETAIL << "(24) FSM State BACKOFF, EV_BROADCAST_RECEIVED:"
470  << " Nothing to do." << endl;
471  sendUp(decapsMsg(static_cast<CSMAFrame *>(msg)));
472  delete msg;
473  break;
474 
475  default:
476  fsmError(event, msg);
477  break;
478  }
479 }
int lowerLayerOutGateId
Definition: MACProtocolBase.h:35
Definition: CSMA.h:175
Definition: CSMA.h:155
Definition: CSMA.h:172
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
unsigned int txAttempts
count the number of tx attempts
Definition: CSMA.h:285
int NB
number of backoff performed until now for current frame
Definition: CSMA.h:272
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:116
long nbDroppedFrames
Definition: CSMA.h:126
Definition: CSMA.h:142
Definition: CSMA.h:173
virtual cPacket * decapsMsg(CSMAFrame *macPkt)
Definition: CSMA.cc:939
IRadio * radio
The radio.
Definition: CSMA.h:218
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
bool transmissionAttemptInterruptedByRx
Definition: CSMA.h:234
cMessage * ccaTimer
Definition: CSMA.h:161
long nbTxFrames
Definition: CSMA.h:122
Definition: CSMA.h:153
virtual void sendUp(cMessage *message)
Definition: MACProtocolBase.cc:52
Definition: CSMA.h:140
The radio medium is free, no signal is detected.
Definition: IRadio.h:148
void attachSignal(CSMAFrame *mac, simtime_t_cref startTime)
Definition: CSMA.cc:375
static simsignal_t packetFromUpperDroppedSignal
Definition: LayeredProtocolBase.h:30
void manageQueue()
Definition: CSMA.cc:700
void fsmError(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:734
virtual ReceptionState getReceptionState() const =0
Returns the current radio reception state.
int macMaxCSMABackoffs
maximum number of extra backoffs (excluding the first unconditional one) before frame drop ...
Definition: CSMA.h:242
Definition: CSMA.h:138
simtime_t aTurnaroundTime
Time to switch radio from Rx to Tx state.
Definition: CSMA.h:240
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276
void startTimer(t_mac_timer timer)
Definition: CSMA.cc:741
Definition: CSMA.h:176
void updateMacState(t_mac_states newMacState)
Definition: CSMA.cc:726
void inet::CSMA::updateStatusIdle ( t_mac_event  event,
cMessage *  msg 
)
protected

Referenced by executeMac().

240 {
241  switch (event) {
242  case EV_SEND_REQUEST:
243  if (macQueue.size() <= queueLength) {
244  macQueue.push_back(static_cast<CSMAFrame *>(msg));
245  EV_DETAIL << "(1) FSM State IDLE_1, EV_SEND_REQUEST and [TxBuff avail]: startTimerBackOff -> BACKOFF." << endl;
247  NB = 0;
248  //BE = macMinBE;
250  }
251  else {
252  // queue is full, message has to be deleted
253  EV_DETAIL << "(12) FSM State IDLE_1, EV_SEND_REQUEST and [TxBuff not avail]: dropping packet -> IDLE." << endl;
254  emit(packetFromUpperDroppedSignal, msg);
255  delete msg;
257  }
258  break;
259 
261  EV_DETAIL << "(15) FSM State IDLE_1, EV_DUPLICATE_RECEIVED: setting up radio tx -> WAITSIFS." << endl;
262  //sendUp(decapsMsg(static_cast<MacSeqPkt *>(msg)));
263  delete msg;
264 
265  if (useMACAcks) {
269  }
270  break;
271 
272  case EV_FRAME_RECEIVED:
273  EV_DETAIL << "(15) FSM State IDLE_1, EV_FRAME_RECEIVED: setting up radio tx -> WAITSIFS." << endl;
274  sendUp(decapsMsg(static_cast<CSMAFrame *>(msg)));
275  nbRxFrames++;
276  delete msg;
277 
278  if (useMACAcks) {
282  }
283  break;
284 
286  EV_DETAIL << "(23) FSM State IDLE_1, EV_BROADCAST_RECEIVED: Nothing to do." << endl;
287  nbRxFrames++;
288  sendUp(decapsMsg(static_cast<CSMAFrame *>(msg)));
289  delete msg;
290  break;
291 
292  default:
293  fsmError(event, msg);
294  break;
295  }
296 }
Definition: CSMA.h:137
Definition: CSMA.h:175
Definition: CSMA.h:155
Definition: CSMA.h:172
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
Definition: CSMA.h:167
int NB
number of backoff performed until now for current frame
Definition: CSMA.h:272
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:116
Definition: CSMA.h:142
Definition: CSMA.h:173
virtual cPacket * decapsMsg(CSMAFrame *macPkt)
Definition: CSMA.cc:939
IRadio * radio
The radio.
Definition: CSMA.h:218
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
Definition: CSMA.h:153
virtual void sendUp(cMessage *message)
Definition: MACProtocolBase.cc:52
unsigned int queueLength
length of the queue
Definition: CSMA.h:279
static simsignal_t packetFromUpperDroppedSignal
Definition: LayeredProtocolBase.h:30
void fsmError(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:734
long nbRxFrames
Definition: CSMA.h:123
Definition: CSMA.h:138
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276
void startTimer(t_mac_timer timer)
Definition: CSMA.cc:741
void updateMacState(t_mac_states newMacState)
Definition: CSMA.cc:726
void inet::CSMA::updateStatusNotIdle ( cMessage *  msg)
protected

Referenced by executeMac().

636 {
637  EV_DETAIL << "(20) FSM State NOT IDLE, EV_SEND_REQUEST. Is a TxBuffer available ?" << endl;
638  if (macQueue.size() <= queueLength) {
639  macQueue.push_back(static_cast<CSMAFrame *>(msg));
640  EV_DETAIL << "(21) FSM State NOT IDLE, EV_SEND_REQUEST"
641  << " and [TxBuff avail]: enqueue packet and don't move." << endl;
642  }
643  else {
644  // queue is full, message has to be deleted
645  EV_DETAIL << "(22) FSM State NOT IDLE, EV_SEND_REQUEST"
646  << " and [TxBuff not avail]: dropping packet and don't move."
647  << endl;
648  // TODO: send dropped signal
649  // emit(packetDropped, msg);
650  delete msg;
651  }
652 }
unsigned int queueLength
length of the queue
Definition: CSMA.h:279
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276
void inet::CSMA::updateStatusSIFS ( t_mac_event  event,
cMessage *  msg 
)
protected

Referenced by executeMac().

583 {
584  assert(useMACAcks);
585 
586  switch (event) {
587  case EV_TIMER_SIFS:
588  EV_DETAIL << "(17) FSM State WAITSIFS_6, EV_TIMER_SIFS:"
589  << " sendAck -> TRANSMITACK." << endl;
591  attachSignal(ackMessage, simTime());
593  nbTxAcks++;
594  // sendDelayed(ackMessage, aTurnaroundTime, lowerLayerOut);
595  ackMessage = nullptr;
596  break;
597 
598  case EV_TIMER_BACKOFF:
599  // Backoff timer has expired while receiving a frame. Restart it
600  // and stay here.
601  EV_DETAIL << "(16) FSM State WAITSIFS_6, EV_TIMER_BACKOFF. "
602  << "Restart backoff timer and don't move." << endl;
604  break;
605 
607  case EV_FRAME_RECEIVED:
608  EV << "Error ! Received a frame during SIFS !" << endl;
609  sendUp(decapsMsg(static_cast<CSMAFrame *>(msg)));
610  delete msg;
611  break;
612 
613  default:
614  fsmError(event, msg);
615  break;
616  }
617 }
long nbTxAcks
Definition: CSMA.h:127
Definition: CSMA.h:175
Definition: CSMA.h:172
Definition: CSMA.h:143
virtual cPacket * decapsMsg(CSMAFrame *macPkt)
Definition: CSMA.cc:939
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
Definition: CSMA.h:153
virtual void sendUp(cMessage *message)
Definition: MACProtocolBase.cc:52
Definition: CSMA.h:174
void attachSignal(CSMAFrame *mac, simtime_t_cref startTime)
Definition: CSMA.cc:375
void fsmError(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:734
CSMAFrame * ackMessage
Definition: CSMA.h:327
Definition: CSMA.h:168
virtual void sendDown(cMessage *message)
Definition: MACProtocolBase.cc:59
void startTimer(t_mac_timer timer)
Definition: CSMA.cc:741
void updateMacState(t_mac_states newMacState)
Definition: CSMA.cc:726
void inet::CSMA::updateStatusTransmitAck ( t_mac_event  event,
cMessage *  msg 
)
protected

Referenced by executeMac().

620 {
621  assert(useMACAcks);
622 
623  if (event == EV_FRAME_TRANSMITTED) {
624  EV_DETAIL << "(19) FSM State TRANSMITACK_7, EV_FRAME_TRANSMITTED:"
625  << " ->manageQueue." << endl;
627  delete msg;
628  manageQueue();
629  }
630  else {
631  fsmError(event, msg);
632  }
633 }
Definition: CSMA.h:169
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
IRadio * radio
The radio.
Definition: CSMA.h:218
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:109
void manageQueue()
Definition: CSMA.cc:700
void fsmError(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:734
void inet::CSMA::updateStatusTransmitFrame ( t_mac_event  event,
cMessage *  msg 
)
protected

Referenced by executeMac().

482 {
483  if (event == EV_FRAME_TRANSMITTED) {
484  // delete msg;
485  CSMAFrame *packet = macQueue.front();
487 
488  bool expectAck = useMACAcks;
489  if (!packet->getDestAddr().isBroadcast()) {
490  //unicast
491  EV_DETAIL << "(4) FSM State TRANSMITFRAME_4, "
492  << "EV_FRAME_TRANSMITTED [Unicast]: ";
493  }
494  else {
495  //broadcast
496  EV_DETAIL << "(27) FSM State TRANSMITFRAME_4, EV_FRAME_TRANSMITTED "
497  << " [Broadcast]";
498  expectAck = false;
499  }
500 
501  if (expectAck) {
502  EV_DETAIL << "RadioSetupRx -> WAITACK." << endl;
505  }
506  else {
507  EV_DETAIL << ": RadioSetupRx, manageQueue..." << endl;
508  macQueue.pop_front();
509  delete packet;
510  manageQueue();
511  }
512  delete msg;
513  }
514  else {
515  fsmError(event, msg);
516  }
517 }
Definition: CSMA.h:169
Definition: CSMA.h:141
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
IRadio * radio
The radio.
Definition: CSMA.h:218
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:109
void manageQueue()
Definition: CSMA.cc:700
void fsmError(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:734
Definition: CSMA.h:156
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276
void startTimer(t_mac_timer timer)
Definition: CSMA.cc:741
void updateMacState(t_mac_states newMacState)
Definition: CSMA.cc:726
void inet::CSMA::updateStatusWaitAck ( t_mac_event  event,
cMessage *  msg 
)
protected

Referenced by executeMac().

520 {
521  assert(useMACAcks);
522 
523  switch (event) {
524  case EV_ACK_RECEIVED: {
525  EV_DETAIL << "(5) FSM State WAITACK_5, EV_ACK_RECEIVED: "
526  << " ProcessAck, manageQueue..." << endl;
527  if (rxAckTimer->isScheduled())
528  cancelEvent(rxAckTimer);
529  cMessage *mac = macQueue.front();
530  macQueue.pop_front();
531  txAttempts = 0;
532  delete mac;
533  delete msg;
534  manageQueue();
535  break;
536  }
537  case EV_ACK_TIMEOUT:
538  EV_DETAIL << "(12) FSM State WAITACK_5, EV_ACK_TIMEOUT:"
539  << " incrementCounter/dropPacket, manageQueue..." << endl;
540  manageMissingAck(event, msg);
541  break;
542 
544  case EV_FRAME_RECEIVED:
545  sendUp(decapsMsg(static_cast<CSMAFrame *>(msg)));
546  break;
547 
549  EV_DETAIL << "Error ! Received a frame during SIFS !" << endl;
550  delete msg;
551  break;
552 
553  default:
554  fsmError(event, msg);
555  break;
556  }
557 }
Definition: CSMA.h:171
void manageMissingAck(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:559
cMessage * rxAckTimer
Definition: CSMA.h:161
Definition: CSMA.h:175
Definition: CSMA.h:172
unsigned int txAttempts
count the number of tx attempts
Definition: CSMA.h:285
Definition: CSMA.h:173
virtual cPacket * decapsMsg(CSMAFrame *macPkt)
Definition: CSMA.cc:939
bool useMACAcks
Stores if the MAC expects Acks for Unicast packets.
Definition: CSMA.h:248
virtual void sendUp(cMessage *message)
Definition: MACProtocolBase.cc:52
Definition: CSMA.h:170
void manageQueue()
Definition: CSMA.cc:700
void fsmError(t_mac_event event, cMessage *msg)
Definition: CSMA.cc:734
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: CSMA.h:276

Member Data Documentation

int inet::CSMA::ackLength
protected

The bit length of the ACK packet.

Referenced by handleLowerPacket(), and initialize().

CSMAFrame* inet::CSMA::ackMessage
protected
MACAddress inet::CSMA::address
protected

The MAC address of the interface.

Referenced by createInterfaceEntry(), handleLowerPacket(), handleUpperPacket(), and initializeMACAddress().

simtime_t inet::CSMA::aTurnaroundTime
protected

Time to switch radio from Rx to Tx state.

Referenced by initialize(), and updateStatusCCA().

simtime_t inet::CSMA::aUnitBackoffPeriod
protected

base time unit for calculating backoff durations

Referenced by initialize(), and scheduleBackoff().

backoff_methods inet::CSMA::backoffMethod
protected

Defines the backoff method to be used.

Referenced by initialize(), and scheduleBackoff().

cMessage* inet::CSMA::backoffTimer
protected
double inet::CSMA::backoffValues
protected

Referenced by finish(), initialize(), and scheduleBackoff().

double inet::CSMA::bitrate
protected

the bit rate at which we transmit

Referenced by attachSignal(), createInterfaceEntry(), and initialize().

simtime_t inet::CSMA::ccaDetectionTime
protected

CCA detection time.

Referenced by initialize(), and startTimer().

cMessage * inet::CSMA::ccaTimer
protected
int inet::CSMA::headerLength
protected

Length of the header.

Referenced by handleUpperPacket().

double inet::CSMA::initialCW
protected

initial contention window size Only used for linear and constant backoff method.

Referenced by initialize(), and scheduleBackoff().

simtime_t inet::CSMA::macAckWaitDuration
protected

The amount of time the MAC waits for the ACK of a packet.

Referenced by initialize(), and startTimer().

int inet::CSMA::macMaxBE
protected

Maximum backoff exponent.

Only used for exponential backoff method.

Referenced by initialize(), and scheduleBackoff().

int inet::CSMA::macMaxCSMABackoffs
protected

maximum number of extra backoffs (excluding the first unconditional one) before frame drop

Referenced by initialize(), and updateStatusCCA().

unsigned int inet::CSMA::macMaxFrameRetries
protected

maximum number of frame retransmissions without ack

Referenced by initialize(), and manageMissingAck().

int inet::CSMA::macMinBE
protected

Minimum backoff exponent.

Only used for exponential backoff method.

Referenced by initialize(), and scheduleBackoff().

MacQueue inet::CSMA::macQueue
protected

A queue to store packets from upper layer in case another packet is still waiting for transmission.

Referenced by clearQueue(), flushQueue(), handleLowerPacket(), manageMissingAck(), manageQueue(), updateStatusCCA(), updateStatusIdle(), updateStatusNotIdle(), updateStatusTransmitFrame(), updateStatusWaitAck(), and ~CSMA().

t_mac_states inet::CSMA::macState
protected

keep track of MAC state

Referenced by executeMac(), fsmError(), handleLowerPacket(), initialize(), and updateMacState().

int inet::CSMA::NB
protected

number of backoff performed until now for current frame

Referenced by initialize(), manageQueue(), scheduleBackoff(), updateStatusCCA(), and updateStatusIdle().

long inet::CSMA::nbBackoffs
protected

Referenced by finish(), initialize(), and scheduleBackoff().

long inet::CSMA::nbDroppedFrames
protected

Referenced by finish(), initialize(), and updateStatusCCA().

long inet::CSMA::nbDuplicates
protected
long inet::CSMA::nbMissedAcks
protected
long inet::CSMA::nbRecvdAcks
protected
long inet::CSMA::nbRxFrames
protected
long inet::CSMA::nbTxAcks
protected
long inet::CSMA::nbTxFrames
protected

Referenced by finish(), initialize(), and updateStatusCCA().

unsigned int inet::CSMA::queueLength
protected

length of the queue

Referenced by initialize(), updateStatusIdle(), and updateStatusNotIdle().

cMessage * inet::CSMA::rxAckTimer
protected
simtime_t inet::CSMA::rxSetupTime
protected

Time to setup radio from sleep to Rx state.

Referenced by initialize(), and startTimer().

std::map<MACAddress, unsigned long> inet::CSMA::SeqNrChild
protected

Referenced by handleLowerPacket().

std::map<MACAddress, unsigned long> inet::CSMA::SeqNrParent
protected

Referenced by handleUpperPacket().

simtime_t inet::CSMA::sifs
protected

Maximum time between a packet and its ACK.

Usually this is slightly more then the tx-rx turnaround time The channel should stay clear within this period of time.

Referenced by initialize(), and startTimer().

cMessage * inet::CSMA::sifsTimer
protected
t_mac_status inet::CSMA::status
protected
bool inet::CSMA::transmissionAttemptInterruptedByRx
protected
IRadio::TransmissionState inet::CSMA::transmissionState
protected

Referenced by receiveSignal().

unsigned int inet::CSMA::txAttempts
protected

count the number of tx attempts

This holds the number of transmission attempts for the current frame.

Referenced by initialize(), manageMissingAck(), updateStatusCCA(), and updateStatusWaitAck().

double inet::CSMA::txPower
protected

The power (in mW) to transmit with.


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