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

Implementation of B-MAC (called also Berkeley MAC, Low Power Listening or LPL). More...

#include <BMacLayer.h>

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

Public Member Functions

 BMacLayer ()
 
virtual ~BMacLayer ()
 
virtual int numInitStages () const override
 Initialization of the module and some variables. More...
 
virtual void initialize (int) override
 
virtual void refreshDisplay () const override
 Change the color of the node for animation purposes. 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  States {
  INIT, SLEEP, CCA, SEND_PREAMBLE,
  WAIT_DATA, SEND_DATA, WAIT_TX_DATA_OVER, WAIT_ACK,
  SEND_ACK, WAIT_ACK_TX
}
 MAC states. More...
 
enum  TYPES {
  BMAC_PREAMBLE = 191, BMAC_DATA, BMAC_ACK, BMAC_RESEND_DATA,
  BMAC_ACK_TIMEOUT, BMAC_START_BMAC, BMAC_WAKE_UP, BMAC_SEND_ACK,
  BMAC_CCA_TIMEOUT, BMAC_ACK_TX_OVER, BMAC_SEND_PREAMBLE, BMAC_STOP_PREAMBLES,
  BMAC_DATA_TX_OVER, BMAC_DATA_TIMEOUT
}
 Types of messages (self messages and packets) the node can process. More...
 
typedef std::list< BMacFrame * > MacQueue
 

Protected Member Functions

virtual void initializeMACAddress ()
 Generate new interface address. More...
 
virtual InterfaceEntrycreateInterfaceEntry () override
 
virtual void handleCommand (cMessage *msg)
 
void sendDataPacket ()
 Internal function to send the first packet in the queue. More...
 
void sendMacAck ()
 Internal function to send an ACK. More...
 
void sendPreamble ()
 Internal function to send one preamble. More...
 
void attachSignal (BMacFrame *macPkt)
 Internal function to attach a signal to the packet. More...
 
bool addToQueue (cMessage *msg)
 Internal function to add a new packet from upper to the queue. More...
 
virtual void flushQueue ()
 
virtual void clearQueue ()
 
cPacket * decapsMsg (BMacFrame *msg)
 
BMacFrameencapsMsg (cPacket *netwPkt)
 
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 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

MACAddress address
 The MAC address of the interface. More...
 
MacQueue macQueue
 A queue to store packets from upper layer in case another packet is still waiting for transmission. More...
 
IRadioradio = nullptr
 The radio. More...
 
IRadio::TransmissionState transmissionState = IRadio::TRANSMISSION_STATE_UNDEFINED
 
States macState = (States)-1
 The current state of the protocol. More...
 
cMessage * resend_data = nullptr
 
cMessage * ack_timeout = nullptr
 
cMessage * start_bmac = nullptr
 
cMessage * wakeup = nullptr
 
cMessage * send_ack = nullptr
 
cMessage * cca_timeout = nullptr
 
cMessage * ack_tx_over = nullptr
 
cMessage * send_preamble = nullptr
 
cMessage * stop_preambles = nullptr
 
cMessage * data_tx_over = nullptr
 
cMessage * data_timeout = nullptr
 
unsigned int queueLength = 0
 The maximum length of the queue. More...
 
bool animation = false
 Animate (colorize) the nodes. More...
 
double slotDuration = 0
 The duration of the slot in secs. More...
 
int headerLength = 0
 Length of the header. More...
 
double bitrate = 0
 The bitrate of transmission. More...
 
double checkInterval = 0
 The duration of CCA. More...
 
bool useMacAcks = false
 Use MAC level acks or not. More...
 
int maxTxAttempts = 0
 Maximum transmission attempts per data packet, when ACKs are used. More...
 
bool stats = false
 Gather stats at the end of the simulation. More...
 
Different tracked statistics.
long nbTxDataPackets = 0
 
long nbTxPreambles = 0
 
long nbRxDataPackets = 0
 
long nbRxPreambles = 0
 
long nbMissedAcks = 0
 
long nbRecvdAcks = 0
 
long nbDroppedDataPackets = 0
 
long nbTxAcks = 0
 
Help variables for the acknowledgment process.
MACAddress lastDataPktSrcAddr
 
MACAddress lastDataPktDestAddr
 
int txAttempts = 0
 
- Protected Attributes inherited from inet::OperationalBase
bool isOperational
 
simtime_t lastChange
 

Private Member Functions

 BMacLayer (const BMacLayer &)
 Copy constructor is not allowed. More...
 
BMacLayeroperator= (const BMacLayer &)
 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

Implementation of B-MAC (called also Berkeley MAC, Low Power Listening or LPL).

The protocol works as follows: each node is allowed to sleep for slotDuration. After waking up, it first checks the channel for ongoing transmissions. If a transmission is catched (a preamble is received), the node stays awake for at most slotDuration and waits for the actual data packet. If a node wants to send a packet, it first sends preambles for at least slotDuration, thus waking up all nodes in its transmission radius and then sends out the data packet. If a mac-level ack is required, then the receiver sends the ack immediately after receiving the packet (no preambles) and the sender waits for some time more before going back to sleep.

B-MAC is designed for low traffic, low power communication in WSN and is one of the most widely used protocols (e.g. it is part of TinyOS). The finite state machine of the protocol is given in the below figure:

BMACFSM.png
B-MAC Layer - finite state machine

A paper describing this implementation can be found at: http://www.omnet-workshop.org/2011/uploads/slides/OMNeT_WS2011_S5_C1_Foerster.pdf

Author
Anna Foerster

Member Typedef Documentation

typedef std::list<BMacFrame *> inet::BMacLayer::MacQueue
protected

Member Enumeration Documentation

enum inet::BMacLayer::States
protected

MAC states.

The MAC states help to keep track what the MAC is actually trying to do. INIT – node has just started and its status is unclear SLEEP – node sleeps, but accepts packets from the network layer CCA – Clear Channel Assessment - MAC checks whether medium is busy SEND_PREAMBLE – node sends preambles to wake up all nodes WAIT_DATA – node has received at least one preamble from another node and wiats for the actual data packet SEND_DATA – node has sent enough preambles and sends the actual data packet WAIT_TX_DATA_OVER – node waits until the data packet sending is ready WAIT_ACK – node has sent the data packet and waits for ack from the receiving node SEND_ACK – node send an ACK back to the sender WAIT_ACK_TX – node waits until the transmission of the ack packet is over

Enumerator
INIT 
SLEEP 
CCA 
SEND_PREAMBLE 
WAIT_DATA 
SEND_DATA 
WAIT_TX_DATA_OVER 
WAIT_ACK 
SEND_ACK 
WAIT_ACK_TX 
138  {
139  INIT, //0
140  SLEEP, //1
141  CCA, //2
142  SEND_PREAMBLE, //3
143  WAIT_DATA, //4
144  SEND_DATA, //5
145  WAIT_TX_DATA_OVER, //6
146  WAIT_ACK, //7
147  SEND_ACK, //8
148  WAIT_ACK_TX //9
149  };
Definition: BMacLayer.h:142
Definition: BMacLayer.h:139
Definition: BMacLayer.h:141
Definition: BMacLayer.h:143
Definition: BMacLayer.h:146
Definition: BMacLayer.h:140
Definition: BMacLayer.h:144
Definition: BMacLayer.h:145
Definition: BMacLayer.h:148
Definition: BMacLayer.h:147
enum inet::BMacLayer::TYPES
protected

Types of messages (self messages and packets) the node can process.

Enumerator
BMAC_PREAMBLE 
BMAC_DATA 
BMAC_ACK 
BMAC_RESEND_DATA 
BMAC_ACK_TIMEOUT 
BMAC_START_BMAC 
BMAC_WAKE_UP 
BMAC_SEND_ACK 
BMAC_CCA_TIMEOUT 
BMAC_ACK_TX_OVER 
BMAC_SEND_PREAMBLE 
BMAC_STOP_PREAMBLES 
BMAC_DATA_TX_OVER 
BMAC_DATA_TIMEOUT 
155  {
156  // packet types
157  BMAC_PREAMBLE = 191,
158  BMAC_DATA,
159  BMAC_ACK,
160  // self message types
164  BMAC_WAKE_UP,
172  };
Definition: BMacLayer.h:163
Definition: BMacLayer.h:165
Definition: BMacLayer.h:171
Definition: BMacLayer.h:167
Definition: BMacLayer.h:169
Definition: BMacLayer.h:166
Definition: BMacLayer.h:168
Definition: BMacLayer.h:164
Definition: BMacLayer.h:170
Definition: BMacLayer.h:159
Definition: BMacLayer.h:158
Definition: BMacLayer.h:162
Definition: BMacLayer.h:161
Definition: BMacLayer.h:157

Constructor & Destructor Documentation

inet::BMacLayer::BMacLayer ( const BMacLayer )
private

Copy constructor is not allowed.

inet::BMacLayer::BMacLayer ( )
inline
69 {}
inet::BMacLayer::~BMacLayer ( )
virtual
110 {
111  cancelAndDelete(wakeup);
112  cancelAndDelete(data_timeout);
113  cancelAndDelete(data_tx_over);
114  cancelAndDelete(stop_preambles);
115  cancelAndDelete(send_preamble);
116  cancelAndDelete(ack_tx_over);
117  cancelAndDelete(cca_timeout);
118  cancelAndDelete(send_ack);
119  cancelAndDelete(start_bmac);
120  cancelAndDelete(ack_timeout);
121  cancelAndDelete(resend_data);
122 
123  for (auto & elem : macQueue) {
124  delete (elem);
125  }
126  macQueue.clear();
127 }
cMessage * send_preamble
Definition: BMacLayer.h:182
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: BMacLayer.h:100
cMessage * ack_timeout
Definition: BMacLayer.h:176
cMessage * send_ack
Definition: BMacLayer.h:179
cMessage * wakeup
Definition: BMacLayer.h:178
cMessage * stop_preambles
Definition: BMacLayer.h:183
cMessage * resend_data
Definition: BMacLayer.h:175
cMessage * data_tx_over
Definition: BMacLayer.h:184
cMessage * ack_tx_over
Definition: BMacLayer.h:181
cMessage * cca_timeout
Definition: BMacLayer.h:180
cMessage * data_timeout
Definition: BMacLayer.h:185
cMessage * start_bmac
Definition: BMacLayer.h:177

Member Function Documentation

bool inet::BMacLayer::addToQueue ( cMessage *  msg)
protected

Internal function to add a new packet from upper to the queue.

Encapsulates the received network-layer packet into a BMacFrame and set all needed header fields.

Referenced by handleUpperPacket().

606 {
607  if (macQueue.size() >= queueLength) {
608  // queue is full, message has to be deleted
609  EV_DETAIL << "New packet arrived, but queue is FULL, so new packet is"
610  " deleted\n";
611  emit(packetFromUpperDroppedSignal, msg);
613  return false;
614  }
615 
616  BMacFrame *macPkt = encapsMsg((cPacket *)msg);
617  macQueue.push_back(macPkt);
618  EV_DETAIL << "Max queue length: " << queueLength << ", packet put in queue"
619  "\n queue size: " << macQueue.size() << " macState: "
620  << macState << endl;
621  return true;
622 }
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: BMacLayer.h:100
States macState
The current state of the protocol.
Definition: BMacLayer.h:151
static simsignal_t packetFromUpperDroppedSignal
Definition: LayeredProtocolBase.h:30
long nbDroppedDataPackets
Definition: BMacLayer.h:114
unsigned int queueLength
The maximum length of the queue.
Definition: BMacLayer.h:195
BMacFrame * encapsMsg(cPacket *netwPkt)
Definition: BMacLayer.cc:728
void inet::BMacLayer::attachSignal ( BMacFrame macPkt)
protected

Internal function to attach a signal to the packet.

Referenced by sendDataPacket(), sendMacAck(), and sendPreamble().

636 {
637  //calc signal duration
638  simtime_t duration = macPkt->getBitLength() / bitrate;
639  //create and initialize control info with new signal
640  macPkt->setDuration(duration);
641 }
double bitrate
The bitrate of transmission.
Definition: BMacLayer.h:209
void inet::BMacLayer::clearQueue ( )
protectedvirtual
631 {
632  macQueue.clear();
633 }
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: BMacLayer.h:100
InterfaceEntry * inet::BMacLayer::createInterfaceEntry ( )
overrideprotectedvirtual

Implements inet::MACProtocolBase.

161 {
162  InterfaceEntry *e = new InterfaceEntry(this);
163 
164  // data rate
165  e->setDatarate(bitrate);
166 
167  // generate a link-layer address to be used as interface token for IPv6
168  e->setMACAddress(address);
169  e->setInterfaceToken(address.formInterfaceIdentifier());
170 
171  // capabilities
172  e->setMtu(par("mtu").longValue());
173  e->setMulticast(false);
174  e->setBroadcast(true);
175 
176  return e;
177 }
double bitrate
The bitrate of transmission.
Definition: BMacLayer.h:209
MACAddress address
The MAC address of the interface.
Definition: BMacLayer.h:96
const value< double, units::C > e(1.602176487e-19)
InterfaceToken formInterfaceIdentifier() const
Create interface identifier (IEEE EUI-64) which can be used by IPv6 stateless address autoconfigurati...
Definition: MACAddress.cc:136
cPacket * inet::BMacLayer::decapsMsg ( BMacFrame msg)
protected

Referenced by handleSelfMessage().

719 {
720  cPacket *m = msg->decapsulate();
721  setUpControlInfo(m, msg->getSrcAddr());
722  // delete the macPkt
723  delete msg;
724  EV_DETAIL << " message decapsulated " << endl;
725  return m;
726 }
cObject * setUpControlInfo(cMessage *const pMsg, const MACAddress &pSrcAddr)
Attaches a "control info" (MacToNetw) structure (object) to the message pMsg.
Definition: BMacLayer.cc:755
value< double, units::m > m
Definition: Units.h:1047
BMacFrame * inet::BMacLayer::encapsMsg ( cPacket *  netwPkt)
protected

Referenced by addToQueue().

729 {
730  BMacFrame *pkt = new BMacFrame(netwPkt->getName(), netwPkt->getKind());
731  pkt->setBitLength(headerLength);
732 
733  // copy dest address from the Control Info attached to the network
734  // message by the network layer
735  IMACProtocolControlInfo *cInfo = check_and_cast<IMACProtocolControlInfo *>(netwPkt->removeControlInfo());
736  EV_DETAIL << "CInfo removed, mac addr=" << cInfo->getDestinationAddress() << endl;
737  pkt->setDestAddr(cInfo->getDestinationAddress());
738 
739  //delete the control info
740  delete cInfo;
741 
742  //set the src address to own mac address (nic module getId())
743  pkt->setSrcAddr(address);
744 
745  //encapsulate the network packet
746  pkt->encapsulate(netwPkt);
747  EV_DETAIL << "pkt encapsulated\n";
748 
749  return pkt;
750 }
MACAddress address
The MAC address of the interface.
Definition: BMacLayer.h:96
int headerLength
Length of the header.
Definition: BMacLayer.h:207
void inet::BMacLayer::finish ( )
overridevirtual

Delete all dynamically allocated objects of the module.

130 {
131  recordScalar("nbTxDataPackets", nbTxDataPackets);
132  recordScalar("nbTxPreambles", nbTxPreambles);
133  recordScalar("nbRxDataPackets", nbRxDataPackets);
134  recordScalar("nbRxPreambles", nbRxPreambles);
135  recordScalar("nbMissedAcks", nbMissedAcks);
136  recordScalar("nbRecvdAcks", nbRecvdAcks);
137  recordScalar("nbTxAcks", nbTxAcks);
138  recordScalar("nbDroppedDataPackets", nbDroppedDataPackets);
139  //recordScalar("timeSleep", timeSleep);
140  //recordScalar("timeRX", timeRX);
141  //recordScalar("timeTX", timeTX);
142 }
long nbRxPreambles
Definition: BMacLayer.h:111
long nbRxDataPackets
Definition: BMacLayer.h:110
long nbTxPreambles
Definition: BMacLayer.h:109
long nbDroppedDataPackets
Definition: BMacLayer.h:114
long nbMissedAcks
Definition: BMacLayer.h:112
long nbTxAcks
Definition: BMacLayer.h:115
long nbRecvdAcks
Definition: BMacLayer.h:113
long nbTxDataPackets
Definition: BMacLayer.h:108
void inet::BMacLayer::flushQueue ( )
protectedvirtual
625 {
626  // TODO:
627  macQueue.clear();
628 }
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: BMacLayer.h:100
virtual void inet::BMacLayer::handleCommand ( cMessage *  msg)
inlineprotectedvirtual
223 {}
void inet::BMacLayer::handleLowerPacket ( cPacket *  msg)
overridevirtual

Handle messages from lower layer.

Handle BMAC preambles and received data packets.

Implements inet::LayeredProtocolBase.

549 {
550  if (msg->hasBitError()) {
551  EV << "Received " << msg << " contains bit errors or collision, dropping it\n";
552  delete msg;
553  return;
554  }
555  else
556  // simply pass the massage as self message, to be processed by the FSM.
557  handleSelfMessage(msg);
558 }
virtual void handleSelfMessage(cMessage *) override
Handle self messages such as timers.
Definition: BMacLayer.cc:243
void inet::BMacLayer::handleSelfMessage ( cMessage *  msg)
overridevirtual

Handle self messages such as timers.

Handle own messages: BMAC_WAKEUP: wake up the node, check the channel for some time.

BMAC_CHECK_CHANNEL: if the channel is free, check whether there is something in the queue and switch the radio to TX. When switched to TX, the node will start sending preambles for a full slot duration. If the channel is busy, stay awake to receive message. Schedule a timeout to handle false alarms. BMAC_SEND_PREAMBLES: sending of preambles over. Next time the data packet will be send out (single one). BMAC_TIMEOUT_DATA: timeout the node after a false busy channel alarm. Go back to sleep.

Reimplemented from inet::LayeredProtocolBase.

Referenced by handleLowerPacket().

244 {
245  switch (macState) {
246  case INIT:
247  if (msg->getKind() == BMAC_START_BMAC) {
248  EV_DETAIL << "State INIT, message BMAC_START, new state SLEEP" << endl;
250  macState = SLEEP;
251  scheduleAt(simTime() + dblrand() * slotDuration, wakeup);
252  return;
253  }
254  break;
255 
256  case SLEEP:
257  if (msg->getKind() == BMAC_WAKE_UP) {
258  EV_DETAIL << "State SLEEP, message BMAC_WAKEUP, new state CCA" << endl;
259  scheduleAt(simTime() + checkInterval, cca_timeout);
261  macState = CCA;
262  return;
263  }
264  break;
265 
266  case CCA:
267  if (msg->getKind() == BMAC_CCA_TIMEOUT) {
268  // channel is clear
269  // something waiting in eth queue?
270  if (macQueue.size() > 0) {
271  EV_DETAIL << "State CCA, message CCA_TIMEOUT, new state"
272  " SEND_PREAMBLE" << endl;
275  scheduleAt(simTime() + slotDuration, stop_preambles);
276  return;
277  }
278  // if not, go back to sleep and wake up after a full period
279  else {
280  EV_DETAIL << "State CCA, message CCA_TIMEOUT, new state SLEEP"
281  << endl;
282  scheduleAt(simTime() + slotDuration, wakeup);
283  macState = SLEEP;
285  return;
286  }
287  }
288  // during CCA, we received a preamble. Go to state WAIT_DATA and
289  // schedule the timeout.
290  if (msg->getKind() == BMAC_PREAMBLE) {
291  nbRxPreambles++;
292  EV_DETAIL << "State CCA, message BMAC_PREAMBLE received, new state"
293  " WAIT_DATA" << endl;
295  cancelEvent(cca_timeout);
296  scheduleAt(simTime() + slotDuration + checkInterval, data_timeout);
297  delete msg;
298  return;
299  }
300  // this case is very, very, very improbable, but let's do it.
301  // if in CCA and the node receives directly the data packet, switch to
302  // state WAIT_DATA and re-send the message
303  if (msg->getKind() == BMAC_DATA) {
304  nbRxDataPackets++;
305  EV_DETAIL << "State CCA, message BMAC_DATA, new state WAIT_DATA"
306  << endl;
308  cancelEvent(cca_timeout);
309  scheduleAt(simTime() + slotDuration + checkInterval, data_timeout);
310  scheduleAt(simTime(), msg);
311  return;
312  }
313  //in case we get an ACK, we simply dicard it, because it means the end
314  //of another communication
315  if (msg->getKind() == BMAC_ACK) {
316  EV_DETAIL << "State CCA, message BMAC_ACK, new state CCA" << endl;
317  delete msg;
318  return;
319  }
320  break;
321 
322  case SEND_PREAMBLE:
323  if (msg->getKind() == BMAC_SEND_PREAMBLE) {
324  EV_DETAIL << "State SEND_PREAMBLE, message BMAC_SEND_PREAMBLE, new"
325  " state SEND_PREAMBLE" << endl;
326  sendPreamble();
327  scheduleAt(simTime() + 0.5f * checkInterval, send_preamble);
329  return;
330  }
331  // simply change the state to SEND_DATA
332  if (msg->getKind() == BMAC_STOP_PREAMBLES) {
333  EV_DETAIL << "State SEND_PREAMBLE, message BMAC_STOP_PREAMBLES, new"
334  " state SEND_DATA" << endl;
336  txAttempts = 1;
337  return;
338  }
339  break;
340 
341  case SEND_DATA:
342  if ((msg->getKind() == BMAC_SEND_PREAMBLE)
343  || (msg->getKind() == BMAC_RESEND_DATA))
344  {
345  EV_DETAIL << "State SEND_DATA, message BMAC_SEND_PREAMBLE or"
346  " BMAC_RESEND_DATA, new state WAIT_TX_DATA_OVER" << endl;
347  // send the data packet
348  sendDataPacket();
350  return;
351  }
352  break;
353 
354  case WAIT_TX_DATA_OVER:
355  if (msg->getKind() == BMAC_DATA_TX_OVER) {
357  EV_DETAIL << "State WAIT_TX_DATA_OVER, message BMAC_DATA_TX_OVER,"
358  " new state WAIT_ACK" << endl;
359  macState = WAIT_ACK;
361  scheduleAt(simTime() + checkInterval, ack_timeout);
362  }
363  else {
364  EV_DETAIL << "State WAIT_TX_DATA_OVER, message BMAC_DATA_TX_OVER,"
365  " new state SLEEP" << endl;
366  delete macQueue.front();
367  macQueue.pop_front();
368  // if something in the queue, wakeup soon.
369  if (macQueue.size() > 0)
370  scheduleAt(simTime() + dblrand() * checkInterval, wakeup);
371  else
372  scheduleAt(simTime() + slotDuration, wakeup);
373  macState = SLEEP;
375  }
376  return;
377  }
378  break;
379 
380  case WAIT_ACK:
381  if (msg->getKind() == BMAC_ACK_TIMEOUT) {
382  // No ACK received. try again or drop.
383  if (txAttempts < maxTxAttempts) {
384  EV_DETAIL << "State WAIT_ACK, message BMAC_ACK_TIMEOUT, new state"
385  " SEND_DATA" << endl;
386  txAttempts++;
388  scheduleAt(simTime() + slotDuration, stop_preambles);
390  }
391  else {
392  EV_DETAIL << "State WAIT_ACK, message BMAC_ACK_TIMEOUT, new state"
393  " SLEEP" << endl;
394  //drop the packet
395  cMessage *mac = macQueue.front();
396  macQueue.pop_front();
397  emit(NF_LINK_BREAK, mac);
398  delete mac;
399 
400  // if something in the queue, wakeup soon.
401  if (macQueue.size() > 0)
402  scheduleAt(simTime() + dblrand() * checkInterval, wakeup);
403  else
404  scheduleAt(simTime() + slotDuration, wakeup);
405  macState = SLEEP;
407  nbMissedAcks++;
408  }
409  return;
410  }
411  //ignore and other packets
412  if ((msg->getKind() == BMAC_DATA) || (msg->getKind() == BMAC_PREAMBLE)) {
413  EV_DETAIL << "State WAIT_ACK, message BMAC_DATA or BMAC_PREMABLE, new"
414  " state WAIT_ACK" << endl;
415  delete msg;
416  return;
417  }
418  if (msg->getKind() == BMAC_ACK) {
419  EV_DETAIL << "State WAIT_ACK, message BMAC_ACK" << endl;
420  BMacFrame *mac = static_cast<BMacFrame *>(msg);
421  const MACAddress src = mac->getSrcAddr();
422  // the right ACK is received..
423  EV_DETAIL << "We are waiting for ACK from : " << lastDataPktDestAddr
424  << ", and ACK came from : " << src << endl;
425  if (src == lastDataPktDestAddr) {
426  EV_DETAIL << "New state SLEEP" << endl;
427  nbRecvdAcks++;
429  cancelEvent(ack_timeout);
430  delete macQueue.front();
431  macQueue.pop_front();
432  // if something in the queue, wakeup soon.
433  if (macQueue.size() > 0)
434  scheduleAt(simTime() + dblrand() * checkInterval, wakeup);
435  else
436  scheduleAt(simTime() + slotDuration, wakeup);
437  macState = SLEEP;
440  }
441  delete msg;
442  return;
443  }
444  break;
445 
446  case WAIT_DATA:
447  if (msg->getKind() == BMAC_PREAMBLE) {
448  //nothing happens
449  EV_DETAIL << "State WAIT_DATA, message BMAC_PREAMBLE, new state"
450  " WAIT_DATA" << endl;
451  nbRxPreambles++;
452  delete msg;
453  return;
454  }
455  if (msg->getKind() == BMAC_ACK) {
456  //nothing happens
457  EV_DETAIL << "State WAIT_DATA, message BMAC_ACK, new state WAIT_DATA"
458  << endl;
459  delete msg;
460  return;
461  }
462  if (msg->getKind() == BMAC_DATA) {
463  nbRxDataPackets++;
464  BMacFrame *mac = static_cast<BMacFrame *>(msg);
465  const MACAddress& dest = mac->getDestAddr();
466  const MACAddress& src = mac->getSrcAddr();
467  if ((dest == address) || dest.isBroadcast()) {
468  EV_DETAIL << "Local delivery " << mac << endl;
469  sendUp(decapsMsg(mac));
470  }
471  else {
472  EV_DETAIL << "Received " << mac << " is not for us, dropping frame." << endl;
473  delete msg;
474  msg = nullptr;
475  mac = nullptr;
476  }
477 
478  cancelEvent(data_timeout);
479  if ((useMacAcks) && (dest == address)) {
480  EV_DETAIL << "State WAIT_DATA, message BMAC_DATA, new state"
481  " SEND_ACK" << endl;
482  macState = SEND_ACK;
483  lastDataPktSrcAddr = src;
485  }
486  else {
487  EV_DETAIL << "State WAIT_DATA, message BMAC_DATA, new state SLEEP"
488  << endl;
489  // if something in the queue, wakeup soon.
490  if (macQueue.size() > 0)
491  scheduleAt(simTime() + dblrand() * checkInterval, wakeup);
492  else
493  scheduleAt(simTime() + slotDuration, wakeup);
494  macState = SLEEP;
496  }
497  return;
498  }
499  if (msg->getKind() == BMAC_DATA_TIMEOUT) {
500  EV_DETAIL << "State WAIT_DATA, message BMAC_DATA_TIMEOUT, new state"
501  " SLEEP" << endl;
502  // if something in the queue, wakeup soon.
503  if (macQueue.size() > 0)
504  scheduleAt(simTime() + dblrand() * checkInterval, wakeup);
505  else
506  scheduleAt(simTime() + slotDuration, wakeup);
507  macState = SLEEP;
509  return;
510  }
511  break;
512 
513  case SEND_ACK:
514  if (msg->getKind() == BMAC_SEND_ACK) {
515  EV_DETAIL << "State SEND_ACK, message BMAC_SEND_ACK, new state"
516  " WAIT_ACK_TX" << endl;
517  // send now the ack packet
518  sendMacAck();
520  return;
521  }
522  break;
523 
524  case WAIT_ACK_TX:
525  if (msg->getKind() == BMAC_ACK_TX_OVER) {
526  EV_DETAIL << "State WAIT_ACK_TX, message BMAC_ACK_TX_OVER, new state"
527  " SLEEP" << endl;
528  // ack sent, go to sleep now.
529  // if something in the queue, wakeup soon.
530  if (macQueue.size() > 0)
531  scheduleAt(simTime() + dblrand() * checkInterval, wakeup);
532  else
533  scheduleAt(simTime() + slotDuration, wakeup);
534  macState = SLEEP;
537  return;
538  }
539  break;
540  }
541  throw cRuntimeError("Undefined event of type %d in state %d (radio mode %d, radio reception state %d, radio transmission state %d)!",
543 }
bool isBroadcast() const
Returns true if this is the broadcast address (hex ff:ff:ff:ff:ff:ff).
Definition: MACAddress.h:141
Definition: BMacLayer.h:142
simsignal_t NF_LINK_BREAK
Definition: NotifierConsts.cc:43
double slotDuration
The duration of the slot in secs.
Definition: BMacLayer.h:205
Definition: BMacLayer.h:163
void sendPreamble()
Internal function to send one preamble.
Definition: BMacLayer.cc:199
Definition: BMacLayer.h:139
Definition: BMacLayer.h:165
Definition: BMacLayer.h:171
Definition: BMacLayer.h:167
cMessage * send_preamble
Definition: BMacLayer.h:182
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: BMacLayer.h:100
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
int txAttempts
Definition: BMacLayer.h:191
States macState
The current state of the protocol.
Definition: BMacLayer.h:151
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:116
Definition: BMacLayer.h:141
cMessage * ack_timeout
Definition: BMacLayer.h:176
long nbRxPreambles
Definition: BMacLayer.h:111
bool useMacAcks
Use MAC level acks or not.
Definition: BMacLayer.h:213
Definition: BMacLayer.h:169
void sendMacAck()
Internal function to send an ACK.
Definition: BMacLayer.cc:216
Definition: BMacLayer.h:143
The radio is sleeping, frame reception or transmission is not possible, power consumption is minimal...
Definition: IRadio.h:102
Definition: BMacLayer.h:166
virtual RadioMode getRadioMode() const =0
Returns the current radio mode, This is the same mode as the one emitted with the last radioModeChang...
Definition: BMacLayer.h:168
Definition: BMacLayer.h:146
IRadio * radio
The radio.
Definition: BMacLayer.h:103
cMessage * wakeup
Definition: BMacLayer.h:178
virtual void sendUp(cMessage *message)
Definition: MACProtocolBase.cc:52
Definition: BMacLayer.h:140
cMessage * stop_preambles
Definition: BMacLayer.h:183
MACAddress address
The MAC address of the interface.
Definition: BMacLayer.h:96
Definition: BMacLayer.h:144
Definition: BMacLayer.h:164
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:109
long nbRxDataPackets
Definition: BMacLayer.h:110
Definition: BMacLayer.h:170
Definition: BMacLayer.h:145
Definition: BMacLayer.h:148
Definition: BMacLayer.h:159
double checkInterval
The duration of CCA.
Definition: BMacLayer.h:211
virtual ReceptionState getReceptionState() const =0
Returns the current radio reception state.
long nbMissedAcks
Definition: BMacLayer.h:112
MACAddress lastDataPktDestAddr
Definition: BMacLayer.h:190
MACAddress lastDataPktSrcAddr
Definition: BMacLayer.h:189
Definition: BMacLayer.h:158
int maxTxAttempts
Maximum transmission attempts per data packet, when ACKs are used.
Definition: BMacLayer.h:216
Definition: BMacLayer.h:147
cMessage * cca_timeout
Definition: BMacLayer.h:180
cMessage * data_timeout
Definition: BMacLayer.h:185
Definition: BMacLayer.h:162
void sendDataPacket()
Internal function to send the first packet in the queue.
Definition: BMacLayer.cc:560
virtual TransmissionState getTransmissionState() const =0
Returns the current radio transmission state.
Definition: BMacLayer.h:161
long nbRecvdAcks
Definition: BMacLayer.h:113
Definition: BMacLayer.h:157
static const MACAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MACAddress.h:60
cPacket * decapsMsg(BMacFrame *msg)
Definition: BMacLayer.cc:718
void inet::BMacLayer::handleUpperPacket ( cPacket *  msg)
overridevirtual

Handle messages from upper layer.

Check whether the queue is not full: if yes, print a warning and drop the packet.

Then initiate sending of the packet, if the node is sleeping. Do nothing, if node is working.

Implements inet::LayeredProtocolBase.

185 {
186  bool pktAdded = addToQueue(msg);
187  if (!pktAdded)
188  return;
189  // force wakeup now
190  if (wakeup->isScheduled() && (macState == SLEEP)) {
191  cancelEvent(wakeup);
192  scheduleAt(simTime() + dblrand() * 0.1f, wakeup);
193  }
194 }
States macState
The current state of the protocol.
Definition: BMacLayer.h:151
bool addToQueue(cMessage *msg)
Internal function to add a new packet from upper to the queue.
Definition: BMacLayer.cc:605
cMessage * wakeup
Definition: BMacLayer.h:178
Definition: BMacLayer.h:140
void inet::BMacLayer::initialize ( int  stage)
overridevirtual

Reimplemented from inet::MACProtocolBase.

29 {
31  if (stage == INITSTAGE_LOCAL) {
32  queueLength = par("queueLength");
33  animation = par("animation");
34  slotDuration = par("slotDuration");
35  bitrate = par("bitrate");
36  headerLength = par("headerLength");
37  checkInterval = par("checkInterval");
38  useMacAcks = par("useMACAcks");
39  maxTxAttempts = par("maxTxAttempts");
40  EV_DETAIL << "headerLength: " << headerLength << ", bitrate: " << bitrate << endl;
41 
42  nbTxDataPackets = 0;
43  nbTxPreambles = 0;
44  nbRxDataPackets = 0;
45  nbRxPreambles = 0;
46  nbMissedAcks = 0;
47  nbRecvdAcks = 0;
49  nbTxAcks = 0;
50 
51  txAttempts = 0;
54 
55  macState = INIT;
56 
59 
60  cModule *radioModule = getModuleFromPar<cModule>(par("radioModule"), this);
61  radioModule->subscribe(IRadio::radioModeChangedSignal, this);
62  radioModule->subscribe(IRadio::transmissionStateChangedSignal, this);
63  radio = check_and_cast<IRadio *>(radioModule);
64 
65  // init the dropped packet info
66  WATCH(macState);
67  }
68  else if (stage == INITSTAGE_LINK_LAYER) {
69  wakeup = new cMessage("wakeup");
70  wakeup->setKind(BMAC_WAKE_UP);
71 
72  data_timeout = new cMessage("data_timeout");
74  data_timeout->setSchedulingPriority(100);
75 
76  data_tx_over = new cMessage("data_tx_over");
78 
79  stop_preambles = new cMessage("stop_preambles");
81 
82  send_preamble = new cMessage("send_preamble");
84 
85  ack_tx_over = new cMessage("ack_tx_over");
86  ack_tx_over->setKind(BMAC_ACK_TX_OVER);
87 
88  cca_timeout = new cMessage("cca_timeout");
89  cca_timeout->setKind(BMAC_CCA_TIMEOUT);
90  cca_timeout->setSchedulingPriority(100);
91 
92  send_ack = new cMessage("send_ack");
93  send_ack->setKind(BMAC_SEND_ACK);
94 
95  start_bmac = new cMessage("start_bmac");
96  start_bmac->setKind(BMAC_START_BMAC);
97 
98  ack_timeout = new cMessage("ack_timeout");
99  ack_timeout->setKind(BMAC_ACK_TIMEOUT);
100 
101  resend_data = new cMessage("resend_data");
102  resend_data->setKind(BMAC_RESEND_DATA);
103  resend_data->setSchedulingPriority(100);
104 
105  scheduleAt(0.0, start_bmac);
106  }
107 }
double slotDuration
The duration of the slot in secs.
Definition: BMacLayer.h:205
Definition: BMacLayer.h:163
double bitrate
The bitrate of transmission.
Definition: BMacLayer.h:209
Definition: BMacLayer.h:139
Definition: BMacLayer.h:165
Definition: BMacLayer.h:171
Definition: BMacLayer.h:167
cMessage * send_preamble
Definition: BMacLayer.h:182
int txAttempts
Definition: BMacLayer.h:191
States macState
The current state of the protocol.
Definition: BMacLayer.h:151
virtual void initialize(int stage) override
Definition: MACProtocolBase.cc:31
virtual void initializeMACAddress()
Generate new interface address.
Definition: BMacLayer.cc:144
cMessage * ack_timeout
Definition: BMacLayer.h:176
long nbRxPreambles
Definition: BMacLayer.h:111
bool useMacAcks
Use MAC level acks or not.
Definition: BMacLayer.h:213
Definition: BMacLayer.h:169
cMessage * send_ack
Definition: BMacLayer.h:179
Definition: BMacLayer.h:166
Definition: BMacLayer.h:168
IRadio * radio
The radio.
Definition: BMacLayer.h:103
cMessage * wakeup
Definition: BMacLayer.h:178
Local initializations.
Definition: InitStages.h:35
bool animation
Animate (colorize) the nodes.
Definition: BMacLayer.h:203
Initialization of link-layer protocols.
Definition: InitStages.h:59
cMessage * stop_preambles
Definition: BMacLayer.h:183
Definition: BMacLayer.h:164
int headerLength
Length of the header.
Definition: BMacLayer.h:207
long nbRxDataPackets
Definition: BMacLayer.h:110
long nbTxPreambles
Definition: BMacLayer.h:109
Definition: BMacLayer.h:170
long nbDroppedDataPackets
Definition: BMacLayer.h:114
virtual void registerInterface()
Definition: MACProtocolBase.cc:42
cMessage * resend_data
Definition: BMacLayer.h:175
cMessage * data_tx_over
Definition: BMacLayer.h:184
double checkInterval
The duration of CCA.
Definition: BMacLayer.h:211
cMessage * ack_tx_over
Definition: BMacLayer.h:181
long nbMissedAcks
Definition: BMacLayer.h:112
MACAddress lastDataPktDestAddr
Definition: BMacLayer.h:190
unsigned int queueLength
The maximum length of the queue.
Definition: BMacLayer.h:195
MACAddress lastDataPktSrcAddr
Definition: BMacLayer.h:189
long nbTxAcks
Definition: BMacLayer.h:115
int maxTxAttempts
Maximum transmission attempts per data packet, when ACKs are used.
Definition: BMacLayer.h:216
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
cMessage * cca_timeout
Definition: BMacLayer.h:180
cMessage * data_timeout
Definition: BMacLayer.h:185
Definition: BMacLayer.h:162
cMessage * start_bmac
Definition: BMacLayer.h:177
Definition: BMacLayer.h:161
static simsignal_t radioModeChangedSignal
This signal is emitted every time the radio mode changes.
Definition: IRadio.h:54
long nbRecvdAcks
Definition: BMacLayer.h:113
long nbTxDataPackets
Definition: BMacLayer.h:108
static const MACAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MACAddress.h:60
void inet::BMacLayer::initializeMACAddress ( )
protectedvirtual

Generate new interface address.

Referenced by initialize().

145 {
146  const char *addrstr = par("address");
147 
148  if (!strcmp(addrstr, "auto")) {
149  // assign automatic address
151 
152  // change module parameter from "auto" to concrete address
153  par("address").setStringValue(address.str().c_str());
154  }
155  else {
156  address.setAddress(addrstr);
157  }
158 }
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
MACAddress address
The MAC address of the interface.
Definition: BMacLayer.h:96
static MACAddress generateAutoAddress()
Generates a unique address which begins with 0a:aa and ends in a unique suffix.
Definition: MACAddress.cc:143
virtual int inet::BMacLayer::numInitStages ( ) const
inlineoverridevirtual

Initialization of the module and some variables.

Reimplemented from inet::OperationalBase.

73 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
BMacLayer& inet::BMacLayer::operator= ( const BMacLayer )
private

Assignment operator is not allowed.

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

Handle control messages from lower layer.

571 {
572  Enter_Method_Silent();
573  if (signalID == IRadio::radioModeChangedSignal) {
574  IRadio::RadioMode radioMode = (IRadio::RadioMode)value;
575  if (radioMode == IRadio::RADIO_MODE_TRANSMITTER) {
576  // we just switched to TX after CCA, so simply send the first
577  // sendPremable self message
578  if (macState == SEND_PREAMBLE)
579  scheduleAt(simTime(), send_preamble);
580  else if (macState == SEND_ACK)
581  scheduleAt(simTime(), send_ack);
582  // we were waiting for acks, but none came. we switched to TX and now
583  // need to resend data
584  else if (macState == SEND_DATA)
585  scheduleAt(simTime(), resend_data);
586  }
587  }
588  // Transmission of one packet is over
589  else if (signalID == IRadio::transmissionStateChangedSignal) {
590  IRadio::TransmissionState newRadioTransmissionState = (IRadio::TransmissionState)value;
593  scheduleAt(simTime(), data_tx_over);
594  else if (macState == WAIT_ACK_TX)
595  scheduleAt(simTime(), ack_tx_over);
596  }
597  transmissionState = newRadioTransmissionState;
598  }
599 }
Definition: BMacLayer.h:142
IRadio::TransmissionState transmissionState
Definition: BMacLayer.h:104
TransmissionState
This enumeration specifies the transmission state of the radio.
Definition: IRadio.h:167
cMessage * send_preamble
Definition: BMacLayer.h:182
The radio is not transmitting a signal on the radio medium.
Definition: IRadio.h:178
States macState
The current state of the protocol.
Definition: BMacLayer.h:151
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:116
cMessage * send_ack
Definition: BMacLayer.h:179
RadioMode
This enumeration specifies the requested operational mode of the radio.
Definition: IRadio.h:91
The radio medium is busy, the radio is currently transmitting a signal.
Definition: IRadio.h:183
Definition: BMacLayer.h:144
Definition: BMacLayer.h:145
Definition: BMacLayer.h:148
cMessage * resend_data
Definition: BMacLayer.h:175
cMessage * data_tx_over
Definition: BMacLayer.h:184
cMessage * ack_tx_over
Definition: BMacLayer.h:181
Definition: BMacLayer.h:147
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
static simsignal_t radioModeChangedSignal
This signal is emitted every time the radio mode changes.
Definition: IRadio.h:54
void inet::BMacLayer::refreshDisplay ( ) const
overridevirtual

Change the color of the node for animation purposes.

647 {
648  if (!animation)
649  return;
650  cDisplayString& dispStr = findContainingNode(this)->getDisplayString();
651 
652  switch (macState) {
653  case INIT:
654  case SLEEP:
655  dispStr.setTagArg("b", 3, "black");
656  break;
657 
658  case CCA:
659  dispStr.setTagArg("b", 3, "green");
660  break;
661 
662  case SEND_ACK:
663  case SEND_PREAMBLE:
664  case SEND_DATA:
665  dispStr.setTagArg("b", 3, "blue");
666  break;
667 
668  case WAIT_ACK:
669  case WAIT_DATA:
670  case WAIT_TX_DATA_OVER:
671  case WAIT_ACK_TX:
672  dispStr.setTagArg("b", 3, "yellow");
673  break;
674 
675  default:
676  dispStr.setTagArg("b", 3, "");
677  break;
678  }
679 }
Definition: BMacLayer.h:142
Definition: BMacLayer.h:139
States macState
The current state of the protocol.
Definition: BMacLayer.h:151
Definition: BMacLayer.h:141
Definition: BMacLayer.h:143
Definition: BMacLayer.h:146
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
bool animation
Animate (colorize) the nodes.
Definition: BMacLayer.h:203
Definition: BMacLayer.h:140
Definition: BMacLayer.h:144
Definition: BMacLayer.h:145
Definition: BMacLayer.h:148
Definition: BMacLayer.h:147
void inet::BMacLayer::sendDataPacket ( )
protected

Internal function to send the first packet in the queue.

Referenced by handleSelfMessage().

561 {
562  nbTxDataPackets++;
563  BMacFrame *pkt = macQueue.front()->dup();
564  attachSignal(pkt);
565  lastDataPktDestAddr = pkt->getDestAddr();
566  pkt->setKind(BMAC_DATA);
567  sendDown(pkt);
568 }
void attachSignal(BMacFrame *macPkt)
Internal function to attach a signal to the packet.
Definition: BMacLayer.cc:635
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: BMacLayer.h:100
MACAddress lastDataPktDestAddr
Definition: BMacLayer.h:190
Definition: BMacLayer.h:158
virtual void sendDown(cMessage *message)
Definition: MACProtocolBase.cc:59
long nbTxDataPackets
Definition: BMacLayer.h:108
void inet::BMacLayer::sendMacAck ( )
protected

Internal function to send an ACK.

Send one short preamble packet immediately.

Referenced by handleSelfMessage().

217 {
218  BMacFrame *ack = new BMacFrame();
219  ack->setSrcAddr(address);
220  ack->setDestAddr(lastDataPktSrcAddr);
221  ack->setKind(BMAC_ACK);
222  ack->setBitLength(headerLength);
223 
224  //attach signal and send down
225  attachSignal(ack);
226  sendDown(ack);
227  nbTxAcks++;
228  //endSimulation();
229 }
void attachSignal(BMacFrame *macPkt)
Internal function to attach a signal to the packet.
Definition: BMacLayer.cc:635
MACAddress address
The MAC address of the interface.
Definition: BMacLayer.h:96
int headerLength
Length of the header.
Definition: BMacLayer.h:207
Definition: BMacLayer.h:159
MACAddress lastDataPktSrcAddr
Definition: BMacLayer.h:189
long nbTxAcks
Definition: BMacLayer.h:115
virtual void sendDown(cMessage *message)
Definition: MACProtocolBase.cc:59
void inet::BMacLayer::sendPreamble ( )
protected

Internal function to send one preamble.

Send one short preamble packet immediately.

Referenced by handleSelfMessage().

200 {
201  BMacFrame *preamble = new BMacFrame();
202  preamble->setSrcAddr(address);
203  preamble->setDestAddr(MACAddress::BROADCAST_ADDRESS);
204  preamble->setKind(BMAC_PREAMBLE);
205  preamble->setBitLength(headerLength);
206 
207  //attach signal and send down
208  attachSignal(preamble);
209  sendDown(preamble);
210  nbTxPreambles++;
211 }
void attachSignal(BMacFrame *macPkt)
Internal function to attach a signal to the packet.
Definition: BMacLayer.cc:635
MACAddress address
The MAC address of the interface.
Definition: BMacLayer.h:96
int headerLength
Length of the header.
Definition: BMacLayer.h:207
long nbTxPreambles
Definition: BMacLayer.h:109
virtual void sendDown(cMessage *message)
Definition: MACProtocolBase.cc:59
Definition: BMacLayer.h:157
static const MACAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MACAddress.h:60
cObject * inet::BMacLayer::setUpControlInfo ( cMessage *const  pMsg,
const MACAddress pSrcAddr 
)
protected

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

Referenced by decapsMsg().

756 {
757  SimpleLinkLayerControlInfo *const cCtrlInfo = new SimpleLinkLayerControlInfo();
758  cCtrlInfo->setSrc(pSrcAddr);
759  cCtrlInfo->setInterfaceId(interfaceEntry->getInterfaceId());
760  pMsg->setControlInfo(cCtrlInfo);
761  return cCtrlInfo;
762 }
int getInterfaceId() const
Definition: InterfaceEntry.h:185
InterfaceEntry * interfaceEntry
Definition: MACProtocolBase.h:38

Member Data Documentation

cMessage* inet::BMacLayer::ack_timeout = nullptr
protected
cMessage* inet::BMacLayer::ack_tx_over = nullptr
protected
MACAddress inet::BMacLayer::address
protected
bool inet::BMacLayer::animation = false
protected

Animate (colorize) the nodes.

The color of the node reflects its basic status (not the exact state!) BLACK - node is sleeping GREEN - node is receiving YELLOW - node is sending

Referenced by initialize(), and refreshDisplay().

double inet::BMacLayer::bitrate = 0
protected

The bitrate of transmission.

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

cMessage* inet::BMacLayer::cca_timeout = nullptr
protected
double inet::BMacLayer::checkInterval = 0
protected

The duration of CCA.

Referenced by handleSelfMessage(), and initialize().

cMessage* inet::BMacLayer::data_timeout = nullptr
protected
cMessage* inet::BMacLayer::data_tx_over = nullptr
protected
int inet::BMacLayer::headerLength = 0
protected

Length of the header.

Referenced by encapsMsg(), initialize(), sendMacAck(), and sendPreamble().

MACAddress inet::BMacLayer::lastDataPktDestAddr
protected
MACAddress inet::BMacLayer::lastDataPktSrcAddr
protected
MacQueue inet::BMacLayer::macQueue
protected

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

Referenced by addToQueue(), clearQueue(), flushQueue(), handleSelfMessage(), sendDataPacket(), and ~BMacLayer().

States inet::BMacLayer::macState = (States)-1
protected

The current state of the protocol.

Referenced by addToQueue(), handleSelfMessage(), handleUpperPacket(), initialize(), receiveSignal(), and refreshDisplay().

int inet::BMacLayer::maxTxAttempts = 0
protected

Maximum transmission attempts per data packet, when ACKs are used.

Referenced by handleSelfMessage(), and initialize().

long inet::BMacLayer::nbDroppedDataPackets = 0
protected

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

long inet::BMacLayer::nbMissedAcks = 0
protected
long inet::BMacLayer::nbRecvdAcks = 0
protected
long inet::BMacLayer::nbRxDataPackets = 0
protected
long inet::BMacLayer::nbRxPreambles = 0
protected
long inet::BMacLayer::nbTxAcks = 0
protected

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

long inet::BMacLayer::nbTxDataPackets = 0
protected

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

long inet::BMacLayer::nbTxPreambles = 0
protected

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

unsigned int inet::BMacLayer::queueLength = 0
protected

The maximum length of the queue.

Referenced by addToQueue(), and initialize().

IRadio* inet::BMacLayer::radio = nullptr
protected

The radio.

Referenced by handleSelfMessage(), and initialize().

cMessage* inet::BMacLayer::resend_data = nullptr
protected
cMessage* inet::BMacLayer::send_ack = nullptr
protected
cMessage* inet::BMacLayer::send_preamble = nullptr
protected
double inet::BMacLayer::slotDuration = 0
protected

The duration of the slot in secs.

Referenced by handleSelfMessage(), and initialize().

cMessage* inet::BMacLayer::start_bmac = nullptr
protected

Referenced by initialize(), and ~BMacLayer().

bool inet::BMacLayer::stats = false
protected

Gather stats at the end of the simulation.

cMessage* inet::BMacLayer::stop_preambles = nullptr
protected
IRadio::TransmissionState inet::BMacLayer::transmissionState = IRadio::TRANSMISSION_STATE_UNDEFINED
protected

Referenced by receiveSignal().

int inet::BMacLayer::txAttempts = 0
protected

Referenced by handleSelfMessage(), and initialize().

bool inet::BMacLayer::useMacAcks = false
protected

Use MAC level acks or not.

Referenced by handleSelfMessage(), and initialize().

cMessage* inet::BMacLayer::wakeup = nullptr
protected

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