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

Implementation of L-MAC (Lightweight Medium Access Protocol for Wireless Sensor Networks [van Hoesel 04] ). More...

#include <LMacLayer.h>

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

Public Member Functions

 LMacLayer ()
 
virtual ~LMacLayer ()
 Clean up messges. More...
 
virtual void initialize (int) override
 Initialization of the module and some variables. 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...
 
virtual LMacFrameencapsMsg (cPacket *)
 Encapsulate the NetwPkt into an MacPkt. More...
 
virtual cPacket * decapsMsg (LMacFrame *)
 
cObject * setUpControlInfo (cMessage *const pMsg, const MACAddress &pSrcAddr)
 Attaches a "control info" (MacToNetw) structure (object) to the message pMsg. 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, WAIT_CONTROL,
  WAIT_DATA, SEND_CONTROL, SEND_DATA
}
 MAC states. More...
 
enum  TYPES {
  LMAC_CONTROL = 167, LMAC_TIMEOUT = 168, LMAC_WAKEUP = 169, LMAC_SEND_DATA = 170,
  LMAC_SETUP_PHASE_END = 171, LMAC_CHECK_CHANNEL = 172, LMAC_SOMEBODY = 173, LMAC_DATA = 174,
  LMAC_START_LMAC = 175, LMAC_SEND_CONTROL = 176
}
 
typedef std::list< LMacFrame * > MacQueue
 

Protected Member Functions

virtual void initializeMACAddress ()
 Generate new interface address. More...
 
virtual InterfaceEntrycreateInterfaceEntry () override
 
virtual void handleCommand (cMessage *msg)
 
void findNewSlot ()
 find a new slot More...
 
void attachSignal (LMacFrame *macPkt)
 Internal function to attach a signal to the packet. More...
 
virtual void flushQueue ()
 
virtual void clearQueue ()
 
- 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

bool SETUP_PHASE
 the setup phase is the beginning of the simulation, where only control packets at very small slot durations are exchanged. More...
 
cOutVector * slotChange
 indicate how often the node needs to change its slot because of collisions More...
 
States macState
 keep track of MAC state More...
 
double slotDuration
 Duration of a slot. More...
 
int headerLength
 Length of the header. More...
 
double controlDuration
 Duration of teh control time in each slot. More...
 
int mySlot
 my slot ID More...
 
int numSlots
 how many slots are there More...
 
int currSlot
 The current slot of the simulation. More...
 
MACAddress occSlotsDirect [64]
 Occupied slots from nodes, from which I hear directly. More...
 
MACAddress occSlotsAway [64]
 Occupied slots of two-hop neighbors. More...
 
int reservedMobileSlots
 The first couple of slots are reserved for nodes with special needs to avoid changing slots for them (mobile nodes) More...
 
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
 The radio. More...
 
IRadio::TransmissionState transmissionState
 
unsigned queueLength
 length of the queue More...
 
cMessage * wakeup
 
cMessage * timeout
 
cMessage * sendData
 
cMessage * initChecker
 
cMessage * checkChannel
 
cMessage * start_lmac
 
cMessage * send_control
 
double bitrate
 the bit rate at which we transmit More...
 
- Protected Attributes inherited from inet::OperationalBase
bool isOperational
 
simtime_t lastChange
 

Static Protected Attributes

static const MACAddress LMAC_NO_RECEIVER
 dummy receiver address to indicate no pending packets in the control packet More...
 
static const MACAddress LMAC_FREE_SLOT
 

Private Member Functions

 LMacLayer (const LMacLayer &)
 Copy constructor is not allowed. More...
 
LMacLayeroperator= (const LMacLayer &)
 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 L-MAC (Lightweight Medium Access Protocol for Wireless Sensor Networks [van Hoesel 04] ).

Each node has its own unique timeslot. Nodes can use their timeslots to transfer data without having to contend for the medium or having to deal with energy wasting collisions or retransmissions.

During the first 5 full frames nodes will be waking up every controlDuration to setup the network first by assigning a different timeslot to each node. Normal packets will be queued, but will be send only after the setup phase.

During its timeslot a node wakes up, checks the channel for a short random period (CCA) to check for possible collision in the slot and, if the channel is free, sends a control packet. If there is a collision it tries to change its timeslot to an empty one. After the transmission of the control packet it checks its packet queue and if its non-empty it sends a data packet.

During a foreign timeslot a node wakes up, checks the channel for 2*controlDuration period for an incoming control packet and if there in nothing it goes back to sleep and conserves energy for the rest of the timeslot. If it receives a control packet addressed for itself it stays awake for the rest of the timeslot to receive the incoming data packet.

The finite state machine of the protocol is given in the below figure:

LMACFSM.jpg
State chart for LMAC layer

A paper describing the protocol is:

L. van Hoesel and P. Havinga. A lightweight medium access protocol (LMAC) for wireless sensor networks. In Proceedings of the 3rd International Symposium on Information Processing in Sensor Networks (IPSN), pages 55-60, Berkeley, CA, February 2004. April.

Member Typedef Documentation

typedef std::list<LMacFrame *> inet::LMacLayer::MacQueue
protected

Member Enumeration Documentation

enum inet::LMacLayer::States
protected

MAC states.

The MAC states help to keep track what the MAC is actually trying to do – this is esp. useful when radio switching takes some time. SLEEP – the node sleeps but accepts packets from the network layer RX – MAC accepts packets from PHY layer TX – MAC transmits a packet CCA – Clear Channel Assessment - MAC checks whether medium is busy

Enumerator
INIT 
SLEEP 
CCA 
WAIT_CONTROL 
WAIT_DATA 
SEND_CONTROL 
SEND_DATA 
142  {
144  };
Definition: LMacLayer.h:143
Definition: LMacLayer.h:143
Definition: LMacLayer.h:143
Definition: LMacLayer.h:143
Definition: LMacLayer.h:143
Definition: LMacLayer.h:143
Definition: LMacLayer.h:143
enum inet::LMacLayer::TYPES
protected
Enumerator
LMAC_CONTROL 
LMAC_TIMEOUT 
LMAC_WAKEUP 
LMAC_SEND_DATA 
LMAC_SETUP_PHASE_END 
LMAC_CHECK_CHANNEL 
LMAC_SOMEBODY 
LMAC_DATA 
LMAC_START_LMAC 
LMAC_SEND_CONTROL 
146  {
147  LMAC_CONTROL = 167,
148  LMAC_TIMEOUT = 168,
149  LMAC_WAKEUP = 169,
150  LMAC_SEND_DATA = 170,
151  LMAC_SETUP_PHASE_END = 171,
152  LMAC_CHECK_CHANNEL = 172,
153  LMAC_SOMEBODY = 173,
154  LMAC_DATA = 174,
155  LMAC_START_LMAC = 175,
156  LMAC_SEND_CONTROL = 176
157  };
Definition: LMacLayer.h:147
Definition: LMacLayer.h:152
Definition: LMacLayer.h:151
Definition: LMacLayer.h:154
Definition: LMacLayer.h:156
Definition: LMacLayer.h:149
Definition: LMacLayer.h:150
Definition: LMacLayer.h:153
Definition: LMacLayer.h:155
Definition: LMacLayer.h:148

Constructor & Destructor Documentation

inet::LMacLayer::LMacLayer ( const LMacLayer )
private

Copy constructor is not allowed.

inet::LMacLayer::LMacLayer ( )
inline
75  : MACProtocolBase()
76  , SETUP_PHASE(true)
77  , slotChange()
78  , macState()
79  , slotDuration(0)
80  , headerLength(0)
81  , controlDuration(0)
82  , mySlot(0)
83  , numSlots(0)
84  , currSlot()
86  , macQueue()
87  , radio(nullptr)
89  , queueLength(0)
90  , wakeup(nullptr)
91  , timeout(nullptr)
92  , sendData(nullptr)
93  , initChecker(nullptr)
94  , checkChannel(nullptr)
95  , start_lmac(nullptr)
96  , send_control(nullptr)
97  , bitrate(0)
98  {}
int reservedMobileSlots
The first couple of slots are reserved for nodes with special needs to avoid changing slots for them ...
Definition: LMacLayer.h:189
bool SETUP_PHASE
the setup phase is the beginning of the simulation, where only control packets at very small slot dur...
Definition: LMacLayer.h:164
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: LMacLayer.h:196
cMessage * checkChannel
Definition: LMacLayer.h:209
int headerLength
Length of the header.
Definition: LMacLayer.h:175
MACProtocolBase()
Definition: MACProtocolBase.cc:22
cMessage * timeout
Definition: LMacLayer.h:206
double slotDuration
Duration of a slot.
Definition: LMacLayer.h:173
int currSlot
The current slot of the simulation.
Definition: LMacLayer.h:183
unsigned queueLength
length of the queue
Definition: LMacLayer.h:203
cMessage * initChecker
Definition: LMacLayer.h:208
int mySlot
my slot ID
Definition: LMacLayer.h:179
IRadio * radio
The radio.
Definition: LMacLayer.h:199
cMessage * send_control
Definition: LMacLayer.h:211
States macState
keep track of MAC state
Definition: LMacLayer.h:170
IRadio::TransmissionState transmissionState
Definition: LMacLayer.h:200
double bitrate
the bit rate at which we transmit
Definition: LMacLayer.h:214
cMessage * wakeup
Definition: LMacLayer.h:205
int numSlots
how many slots are there
Definition: LMacLayer.h:181
The transmission state is undefined or meaningless.
Definition: IRadio.h:172
cOutVector * slotChange
indicate how often the node needs to change its slot because of collisions
Definition: LMacLayer.h:167
double controlDuration
Duration of teh control time in each slot.
Definition: LMacLayer.h:177
cMessage * start_lmac
Definition: LMacLayer.h:210
cMessage * sendData
Definition: LMacLayer.h:207
inet::LMacLayer::~LMacLayer ( )
virtual

Clean up messges.

100 {
101  delete slotChange;
102  cancelAndDelete(timeout);
103  cancelAndDelete(wakeup);
104  cancelAndDelete(checkChannel);
105  cancelAndDelete(sendData);
106  cancelAndDelete(initChecker);
107  cancelAndDelete(start_lmac);
108  cancelAndDelete(send_control);
109 
110  for (auto & elem : macQueue) {
111  delete (elem);
112  }
113  macQueue.clear();
114 }
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: LMacLayer.h:196
cMessage * checkChannel
Definition: LMacLayer.h:209
cMessage * timeout
Definition: LMacLayer.h:206
cMessage * initChecker
Definition: LMacLayer.h:208
cMessage * send_control
Definition: LMacLayer.h:211
cMessage * wakeup
Definition: LMacLayer.h:205
cOutVector * slotChange
indicate how often the node needs to change its slot because of collisions
Definition: LMacLayer.h:167
cMessage * start_lmac
Definition: LMacLayer.h:210
cMessage * sendData
Definition: LMacLayer.h:207

Member Function Documentation

void inet::LMacLayer::attachSignal ( LMacFrame macPkt)
protected

Internal function to attach a signal to the packet.

688 {
689  //calc signal duration
690  simtime_t duration = macPkt->getBitLength() / bitrate;
691  //create and initialize control info with new signal
692  macPkt->setDuration(duration);
693 }
double bitrate
the bit rate at which we transmit
Definition: LMacLayer.h:214
void inet::LMacLayer::clearQueue ( )
protectedvirtual
683 {
684  macQueue.clear();
685 }
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: LMacLayer.h:196
InterfaceEntry * inet::LMacLayer::createInterfaceEntry ( )
overrideprotectedvirtual

Implements inet::MACProtocolBase.

133 {
134  InterfaceEntry *e = new InterfaceEntry(this);
135 
136  // data rate
137  e->setDatarate(bitrate);
138 
139  // generate a link-layer address to be used as interface token for IPv6
140  e->setMACAddress(address);
141  e->setInterfaceToken(address.formInterfaceIdentifier());
142 
143  // capabilities
144  e->setMtu(par("mtu").longValue());
145  e->setMulticast(false);
146  e->setBroadcast(true);
147 
148  return e;
149 }
MACAddress address
The MAC address of the interface.
Definition: LMacLayer.h:192
double bitrate
the bit rate at which we transmit
Definition: LMacLayer.h:214
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::LMacLayer::decapsMsg ( LMacFrame msg)
virtual

Referenced by handleSelfMessage().

638 {
639  cPacket *m = msg->decapsulate();
640  setUpControlInfo(m, msg->getSrcAddr());
641  // delete the macPkt
642  delete msg;
643  EV_DETAIL << " message decapsulated " << endl;
644  return m;
645 }
value< double, units::m > m
Definition: Units.h:1047
cObject * setUpControlInfo(cMessage *const pMsg, const MACAddress &pSrcAddr)
Attaches a "control info" (MacToNetw) structure (object) to the message pMsg.
Definition: LMacLayer.cc:698
LMacFrame * inet::LMacLayer::encapsMsg ( cPacket *  netwPkt)
virtual

Encapsulate the NetwPkt into an MacPkt.

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

Referenced by handleUpperPacket().

653 {
654  LMacFrame *pkt = new LMacFrame(netwPkt->getName(), netwPkt->getKind());
655  pkt->setBitLength(headerLength);
656 
657  // copy dest address from the Control Info attached to the network
658  // message by the network layer
659  IMACProtocolControlInfo *cInfo = check_and_cast<IMACProtocolControlInfo *>(netwPkt->removeControlInfo());
660  EV_DETAIL << "CInfo removed, mac addr=" << cInfo->getDestinationAddress() << endl;
661  pkt->setDestAddr(cInfo->getDestinationAddress());
662 
663  //delete the control info
664  delete cInfo;
665 
666  //set the src address to own mac address (nic module getId())
667  pkt->setSrcAddr(address);
668 
669  //encapsulate the network packet
670  pkt->encapsulate(netwPkt);
671  EV_DETAIL << "pkt encapsulated\n";
672 
673  return pkt;
674 }
int headerLength
Length of the header.
Definition: LMacLayer.h:175
MACAddress address
The MAC address of the interface.
Definition: LMacLayer.h:192
void inet::LMacLayer::findNewSlot ( )
protected

find a new slot

Try to find a new slot after collision.

If not possible, set own slot to -1 (not able to send anything)

Referenced by handleSelfMessage().

614 {
615  // pick a random slot at the beginning and schedule the next wakeup
616  // free the old one first
617  int counter = 0;
618 
619  mySlot = intrand((numSlots - reservedMobileSlots));
620  while ((occSlotsAway[mySlot] != LMAC_FREE_SLOT) && (counter < (numSlots - reservedMobileSlots))) {
621  counter++;
622  mySlot--;
623  if (mySlot < 0)
625  }
627  EV << "ERROR: I cannot find a free slot. Cannot send data.\n";
628  mySlot = -1;
629  }
630  else {
631  EV << "ERROR: My new slot is : " << mySlot << endl;
632  }
633  EV << "ERROR: I needed to find new slot\n";
634  slotChange->recordWithTimestamp(simTime(), FindModule<>::findHost(this)->getId() - 4);
635 }
int reservedMobileSlots
The first couple of slots are reserved for nodes with special needs to avoid changing slots for them ...
Definition: LMacLayer.h:189
MACAddress occSlotsAway[64]
Occupied slots of two-hop neighbors.
Definition: LMacLayer.h:187
static cModule * findHost(cModule *m)
Returns a pointer to the host module of the passed module.
Definition: FindModule.h:57
int mySlot
my slot ID
Definition: LMacLayer.h:179
int numSlots
how many slots are there
Definition: LMacLayer.h:181
cOutVector * slotChange
indicate how often the node needs to change its slot because of collisions
Definition: LMacLayer.h:167
static const MACAddress LMAC_FREE_SLOT
Definition: LMacLayer.h:161
void inet::LMacLayer::flushQueue ( )
protectedvirtual
677 {
678  // TODO:
679  macQueue.clear();
680 }
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: LMacLayer.h:196
virtual void inet::LMacLayer::handleCommand ( cMessage *  msg)
inlineprotectedvirtual
126 {}
void inet::LMacLayer::handleLowerPacket ( cPacket *  msg)
overridevirtual

Handle messages from lower layer.

Handle LMAC control packets and data packets.

Recognize collisions, change own slot if necessary and remember who is using which slot.

Implements inet::LayeredProtocolBase.

568 {
569  if (msg->hasBitError()) {
570  EV << "Received " << msg << " contains bit errors or collision, dropping it\n";
571  delete msg;
572  return;
573  }
574  // simply pass the massage as self message, to be processed by the FSM.
575  handleSelfMessage(msg);
576 }
virtual void handleSelfMessage(cMessage *) override
Handle self messages such as timers.
Definition: LMacLayer.cc:184
void inet::LMacLayer::handleSelfMessage ( cMessage *  msg)
overridevirtual

Handle self messages such as timers.

Handle self messages: LMAC_SETUP_PHASE_END: end of setup phase.

Change slot duration to normal and start sending data packets. The slots of the nodes should be stable now. LMAC_SEND_DATA: send the data packet. LMAC_CHECK_CHANNEL: check the channel in own slot. If busy, change the slot. If not, send a control packet. LMAC_WAKEUP: wake up the node and either check the channel before sending a control packet or wait for control packets. LMAC_TIMEOUT: go back to sleep after nothing happened.

Reimplemented from inet::LayeredProtocolBase.

Referenced by handleLowerPacket().

185 {
186  switch (macState) {
187  case INIT:
188  if (msg->getKind() == LMAC_START_LMAC) {
189  // the first 5 full slots we will be waking up every controlDuration to setup the network first
190  // normal packets will be queued, but will be send only after the setup phase
191  scheduleAt(slotDuration * 5 * numSlots, initChecker);
192  EV << "Startup time =" << slotDuration * 5 * numSlots << endl;
193 
194  EV_DETAIL << "Scheduling the first wakeup at : " << slotDuration << endl;
195 
196  scheduleAt(slotDuration, wakeup);
197 
198  for (int i = 0; i < numSlots; i++) {
201  }
202 
203  if (myId >= reservedMobileSlots)
204  mySlot = ((int)FindModule<>::findHost(this)->getId()) % (numSlots - reservedMobileSlots);
205  else
206  mySlot = myId;
207  //occSlotsDirect[mySlot] = address;
208  //occSlotsAway[mySlot] = address;
209  currSlot = 0;
210 
211  EV_DETAIL << "ID: " << FindModule<>::findHost(this)->getId() << ". Picked random slot: " << mySlot << endl;
212 
213  macState = SLEEP;
214  EV_DETAIL << "Old state: INIT, New state: SLEEP" << endl;
215  SETUP_PHASE = true;
216  }
217  else {
218  EV << "Unknown packet" << msg->getKind() << "in state" << macState << endl;
219  }
220  break;
221 
222  case SLEEP:
223  if (msg->getKind() == LMAC_WAKEUP) {
224  currSlot++;
225  currSlot %= numSlots;
226  EV_DETAIL << "New slot starting - No. " << currSlot << ", my slot is " << mySlot << endl;
227 
228  if (mySlot == currSlot) {
229  EV_DETAIL << "Waking up in my slot. Switch to RECV first to check the channel.\n";
230  macState = CCA;
232  EV_DETAIL << "Old state: SLEEP, New state: CCA" << endl;
233 
234  double small_delay = controlDuration * dblrand();
235  scheduleAt(simTime() + small_delay, checkChannel);
236  EV_DETAIL << "Checking for channel for " << small_delay << " time.\n";
237  }
238  else {
239  EV_DETAIL << "Waking up in a foreign slot. Ready to receive control packet.\n";
242  EV_DETAIL << "Old state: SLEEP, New state: WAIT_CONTROL" << endl;
243  if (!SETUP_PHASE) //in setup phase do not sleep
244  scheduleAt(simTime() + 2.f * controlDuration, timeout);
245  }
246  if (SETUP_PHASE) {
247  scheduleAt(simTime() + 2.f * controlDuration, wakeup);
248  EV_DETAIL << "setup phase slot duration:" << 2.f * controlDuration << "while controlduration is" << controlDuration << endl;
249  }
250  else
251  scheduleAt(simTime() + slotDuration, wakeup);
252  }
253  else if (msg->getKind() == LMAC_SETUP_PHASE_END) {
254  EV_DETAIL << "Setup phase end. Start normal work at the next slot.\n";
255  if (wakeup->isScheduled())
256  cancelEvent(wakeup);
257 
258  scheduleAt(simTime() + slotDuration, wakeup);
259 
260  SETUP_PHASE = false;
261  }
262  else {
263  EV << "Unknown packet" << msg->getKind() << "in state" << macState << endl;
264  }
265  break;
266 
267  case CCA:
268  if (msg->getKind() == LMAC_CHECK_CHANNEL) {
269  // if the channel is clear, get ready for sending the control packet
270  EV << "Channel is free, so let's prepare for sending.\n";
271 
274  EV_DETAIL << "Old state: CCA, New state: SEND_CONTROL" << endl;
275  }
276  else if (msg->getKind() == LMAC_CONTROL) {
277  LMacFrame *const mac = static_cast<LMacFrame *>(msg);
278  const MACAddress& dest = mac->getDestAddr();
279  EV_DETAIL << " I have received a control packet from src " << mac->getSrcAddr() << " and dest " << dest << ".\n";
280  bool collision = false;
281  // if we are listening to the channel and receive anything, there is a collision in the slot.
282  if (checkChannel->isScheduled()) {
283  cancelEvent(checkChannel);
284  collision = true;
285  }
286 
287  for (int s = 0; s < numSlots; s++) {
288  occSlotsAway[s] = mac->getOccupiedSlots(s);
289  EV_DETAIL << "Occupied slot " << s << ": " << occSlotsAway[s] << endl;
290  EV_DETAIL << "Occupied direct slot " << s << ": " << occSlotsDirect[s] << endl;
291  }
292 
293  if (mac->getMySlot() > -1) {
294  // check first whether this address didn't have another occupied slot and free it again
295  for (int i = 0; i < numSlots; i++) {
296  if (occSlotsDirect[i] == mac->getSrcAddr())
298  if (occSlotsAway[i] == mac->getSrcAddr())
300  }
301  occSlotsAway[mac->getMySlot()] = mac->getSrcAddr();
302  occSlotsDirect[mac->getMySlot()] = mac->getSrcAddr();
303  }
304  collision = collision || (mac->getMySlot() == mySlot);
305  if (((mySlot > -1) && (mac->getOccupiedSlots(mySlot) > LMAC_FREE_SLOT) && (mac->getOccupiedSlots(mySlot) != address)) || collision) {
306  EV_DETAIL << "My slot is taken by " << mac->getOccupiedSlots(mySlot) << ". I need to change it.\n";
307  findNewSlot();
308  EV_DETAIL << "My new slot is " << mySlot << endl;
309  }
310  if (mySlot < 0) {
311  EV_DETAIL << "I don;t have a slot - try to find one.\n";
312  findNewSlot();
313  }
314 
315  if (dest == address || dest.isBroadcast()) {
316  EV_DETAIL << "I need to stay awake.\n";
317  if (timeout->isScheduled())
318  cancelEvent(timeout);
320  EV_DETAIL << "Old state: CCA, New state: WAIT_DATA" << endl;
321  }
322  else {
323  EV_DETAIL << "Incoming data packet not for me. Going back to sleep.\n";
324  macState = SLEEP;
325  EV_DETAIL << "Old state: CCA, New state: SLEEP" << endl;
327  if (timeout->isScheduled())
328  cancelEvent(timeout);
329  }
330  delete mac;
331  }
332  //probably it never happens
333  else if (msg->getKind() == LMAC_DATA) {
334  LMacFrame *const mac = static_cast<LMacFrame *>(msg);
335  const MACAddress& dest = mac->getDestAddr();
336  //bool collision = false;
337  // if we are listening to the channel and receive anything, there is a collision in the slot.
338  if (checkChannel->isScheduled()) {
339  cancelEvent(checkChannel);
340  //collision = true;
341  }
342  EV_DETAIL << " I have received a data packet.\n";
343  if (dest == address || dest.isBroadcast()) {
344  EV_DETAIL << "sending pkt to upper...\n";
345  sendUp(decapsMsg(mac));
346  }
347  else {
348  EV_DETAIL << "packet not for me, deleting...\n";
349  delete mac;
350  }
351  // in any case, go back to sleep
352  macState = SLEEP;
353  EV_DETAIL << "Old state: CCA, New state: SLEEP" << endl;
355  }
356  else if (msg->getKind() == LMAC_SETUP_PHASE_END) {
357  EV_DETAIL << "Setup phase end. Start normal work at the next slot.\n";
358  if (wakeup->isScheduled())
359  cancelEvent(wakeup);
360 
361  scheduleAt(simTime() + slotDuration, wakeup);
362 
363  SETUP_PHASE = false;
364  }
365  else {
366  EV << "Unknown packet" << msg->getKind() << "in state" << macState << endl;
367  }
368  break;
369 
370  case WAIT_CONTROL:
371  if (msg->getKind() == LMAC_TIMEOUT) {
372  EV_DETAIL << "Control timeout. Go back to sleep.\n";
373  macState = SLEEP;
374  EV_DETAIL << "Old state: WAIT_CONTROL, New state: SLEEP" << endl;
376  }
377  else if (msg->getKind() == LMAC_CONTROL) {
378  LMacFrame *const mac = static_cast<LMacFrame *>(msg);
379  const MACAddress& dest = mac->getDestAddr();
380  EV_DETAIL << " I have received a control packet from src " << mac->getSrcAddr() << " and dest " << dest << ".\n";
381 
382  bool collision = false;
383 
384  // check first the slot assignment
385  // copy the current slot assignment
386 
387  for (int s = 0; s < numSlots; s++) {
388  occSlotsAway[s] = mac->getOccupiedSlots(s);
389  EV_DETAIL << "Occupied slot " << s << ": " << occSlotsAway[s] << endl;
390  EV_DETAIL << "Occupied direct slot " << s << ": " << occSlotsDirect[s] << endl;
391  }
392 
393  if (mac->getMySlot() > -1) {
394  // check first whether this address didn't have another occupied slot and free it again
395  for (int i = 0; i < numSlots; i++) {
396  if (occSlotsDirect[i] == mac->getSrcAddr())
398  if (occSlotsAway[i] == mac->getSrcAddr())
400  }
401  occSlotsAway[mac->getMySlot()] = mac->getSrcAddr();
402  occSlotsDirect[mac->getMySlot()] = mac->getSrcAddr();
403  }
404 
405  collision = collision || (mac->getMySlot() == mySlot);
406  if (((mySlot > -1) && (mac->getOccupiedSlots(mySlot) > LMAC_FREE_SLOT) && (mac->getOccupiedSlots(mySlot) != address)) || collision) {
407  EV_DETAIL << "My slot is taken by " << mac->getOccupiedSlots(mySlot) << ". I need to change it.\n";
408  findNewSlot();
409  EV_DETAIL << "My new slot is " << mySlot << endl;
410  }
411  if (mySlot < 0) {
412  EV_DETAIL << "I don;t have a slot - try to find one.\n";
413  findNewSlot();
414  }
415 
416  if (dest == address || dest.isBroadcast()) {
417  EV_DETAIL << "I need to stay awake.\n";
419  EV_DETAIL << "Old state: WAIT_CONTROL, New state: WAIT_DATA" << endl;
420  if (timeout->isScheduled())
421  cancelEvent(timeout);
422  }
423  else {
424  EV_DETAIL << "Incoming data packet not for me. Going back to sleep.\n";
425  macState = SLEEP;
426  EV_DETAIL << "Old state: WAIT_CONTROL, New state: SLEEP" << endl;
428  if (timeout->isScheduled())
429  cancelEvent(timeout);
430  }
431  delete mac;
432  }
433  else if ((msg->getKind() == LMAC_WAKEUP)) {
434  if (SETUP_PHASE == true)
435  EV_DETAIL << "End of setup-phase slot" << endl;
436  else
437  EV_DETAIL << "Very unlikely transition";
438 
439  macState = SLEEP;
440  EV_DETAIL << "Old state: WAIT_DATA, New state: SLEEP" << endl;
441  scheduleAt(simTime(), wakeup);
442  }
443  else if (msg->getKind() == LMAC_SETUP_PHASE_END) {
444  EV_DETAIL << "Setup phase end. Start normal work at the next slot.\n";
445  if (wakeup->isScheduled())
446  cancelEvent(wakeup);
447 
448  scheduleAt(simTime() + slotDuration, wakeup);
449 
450  SETUP_PHASE = false;
451  }
452  else {
453  EV << "Unknown packet" << msg->getKind() << "in state" << macState << endl;
454  }
455 
456  break;
457 
458  case SEND_CONTROL:
459 
460  if (msg->getKind() == LMAC_SEND_CONTROL) {
461  // send first a control message, so that non-receiving nodes can switch off.
462  EV << "Sending a control packet.\n";
463  LMacFrame *control = new LMacFrame();
464  control->setKind(LMAC_CONTROL);
465  if ((macQueue.size() > 0) && !SETUP_PHASE)
466  control->setDestAddr((macQueue.front())->getDestAddr());
467  else
468  control->setDestAddr(LMAC_NO_RECEIVER);
469 
470  control->setSrcAddr(address);
471  control->setMySlot(mySlot);
472  control->setBitLength(headerLength + numSlots);
473  control->setOccupiedSlotsArraySize(numSlots);
474  for (int i = 0; i < numSlots; i++)
475  control->setOccupiedSlots(i, occSlotsDirect[i]);
476 
477  sendDown(control);
478  if ((macQueue.size() > 0) && (!SETUP_PHASE))
479  scheduleAt(simTime() + controlDuration, sendData);
480  }
481  else if (msg->getKind() == LMAC_SEND_DATA) {
482  // we should be in our own slot and the control packet should be already sent. receiving neighbors should wait for the data now.
483  if (currSlot != mySlot) {
484  EV_DETAIL << "ERROR: Send data message received, but we are not in our slot!!! Repair.\n";
486  if (timeout->isScheduled())
487  cancelEvent(timeout);
488  return;
489  }
490  LMacFrame *data = macQueue.front()->dup();
491  data->setKind(LMAC_DATA);
492  data->setMySlot(mySlot);
493  data->setOccupiedSlotsArraySize(numSlots);
494  for (int i = 0; i < numSlots; i++)
495  data->setOccupiedSlots(i, occSlotsDirect[i]);
496 
497  EV << "Sending down data packet\n";
498  sendDown(data);
499  delete macQueue.front();
500  macQueue.pop_front();
502  EV_DETAIL << "Old state: SEND_CONTROL, New state: SEND_DATA" << endl;
503  }
504  else if (msg->getKind() == LMAC_SETUP_PHASE_END) {
505  EV_DETAIL << "Setup phase end. Start normal work at the next slot.\n";
506  if (wakeup->isScheduled())
507  cancelEvent(wakeup);
508 
509  scheduleAt(simTime() + slotDuration, wakeup);
510 
511  SETUP_PHASE = false;
512  }
513  else {
514  EV << "Unknown packet" << msg->getKind() << "in state" << macState << endl;
515  }
516  break;
517 
518  case SEND_DATA:
519  if (msg->getKind() == LMAC_WAKEUP) {
520  throw cRuntimeError("I am still sending a message, while a new slot is starting!\n");
521  }
522  else {
523  EV << "Unknown packet" << msg->getKind() << "in state" << macState << endl;
524  }
525  break;
526 
527  case WAIT_DATA:
528  if (msg->getKind() == LMAC_DATA) {
529  LMacFrame *const mac = static_cast<LMacFrame *>(msg);
530  const MACAddress& dest = mac->getDestAddr();
531 
532  EV_DETAIL << " I have received a data packet.\n";
533  if (dest == address || dest.isBroadcast()) {
534  EV_DETAIL << "sending pkt to upper...\n";
535  sendUp(decapsMsg(mac));
536  }
537  else {
538  EV_DETAIL << "packet not for me, deleting...\n";
539  delete mac;
540  }
541  // in any case, go back to sleep
542  macState = SLEEP;
543  EV_DETAIL << "Old state: WAIT_DATA, New state: SLEEP" << endl;
545  if (timeout->isScheduled())
546  cancelEvent(timeout);
547  }
548  else if (msg->getKind() == LMAC_WAKEUP) {
549  macState = SLEEP;
550  EV_DETAIL << "Unlikely transition. Old state: WAIT_DATA, New state: SLEEP" << endl;
551  scheduleAt(simTime(), wakeup);
552  }
553  else {
554  EV << "Unknown packet" << msg->getKind() << "in state" << macState << endl;
555  }
556  break;
557 
558  default:
559  throw cRuntimeError("Unknown mac state: %d", macState);
560  break;
561  }
562 }
bool isBroadcast() const
Returns true if this is the broadcast address (hex ff:ff:ff:ff:ff:ff).
Definition: MACAddress.h:141
Definition: LMacLayer.h:143
int reservedMobileSlots
The first couple of slots are reserved for nodes with special needs to avoid changing slots for them ...
Definition: LMacLayer.h:189
bool SETUP_PHASE
the setup phase is the beginning of the simulation, where only control packets at very small slot dur...
Definition: LMacLayer.h:164
Definition: LMacLayer.h:143
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: LMacLayer.h:196
Definition: LMacLayer.h:143
cMessage * checkChannel
Definition: LMacLayer.h:209
virtual cPacket * decapsMsg(LMacFrame *)
Definition: LMacLayer.cc:637
MACAddress occSlotsAway[64]
Occupied slots of two-hop neighbors.
Definition: LMacLayer.h:187
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
int headerLength
Length of the header.
Definition: LMacLayer.h:175
Definition: LMacLayer.h:147
static cModule * findHost(cModule *m)
Returns a pointer to the host module of the passed module.
Definition: FindModule.h:57
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:116
cMessage * timeout
Definition: LMacLayer.h:206
double slotDuration
Duration of a slot.
Definition: LMacLayer.h:173
int currSlot
The current slot of the simulation.
Definition: LMacLayer.h:183
MACAddress address
The MAC address of the interface.
Definition: LMacLayer.h:192
Definition: LMacLayer.h:143
The radio is sleeping, frame reception or transmission is not possible, power consumption is minimal...
Definition: IRadio.h:102
cMessage * initChecker
Definition: LMacLayer.h:208
int mySlot
my slot ID
Definition: LMacLayer.h:179
static const MACAddress LMAC_NO_RECEIVER
dummy receiver address to indicate no pending packets in the control packet
Definition: LMacLayer.h:160
#define myId
IRadio * radio
The radio.
Definition: LMacLayer.h:199
virtual void sendUp(cMessage *message)
Definition: MACProtocolBase.cc:52
States macState
keep track of MAC state
Definition: LMacLayer.h:170
Definition: LMacLayer.h:152
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:109
cMessage * wakeup
Definition: LMacLayer.h:205
Definition: LMacLayer.h:151
Definition: LMacLayer.h:154
int numSlots
how many slots are there
Definition: LMacLayer.h:181
Definition: LMacLayer.h:143
Definition: LMacLayer.h:156
value< double, units::s > s
Definition: Units.h:1049
virtual void sendDown(cMessage *message)
Definition: MACProtocolBase.cc:59
MACAddress occSlotsDirect[64]
Occupied slots from nodes, from which I hear directly.
Definition: LMacLayer.h:185
double controlDuration
Duration of teh control time in each slot.
Definition: LMacLayer.h:177
Definition: LMacLayer.h:149
cMessage * sendData
Definition: LMacLayer.h:207
Definition: LMacLayer.h:150
static const MACAddress LMAC_FREE_SLOT
Definition: LMacLayer.h:161
Definition: LMacLayer.h:155
Definition: LMacLayer.h:143
Definition: LMacLayer.h:148
Definition: LMacLayer.h:143
void findNewSlot()
find a new slot
Definition: LMacLayer.cc:613
void inet::LMacLayer::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.

Sending of messages is automatic.

Implements inet::LayeredProtocolBase.

156 {
157  LMacFrame *mac = static_cast<LMacFrame *>(encapsMsg(static_cast<cPacket *>(msg)));
158 
159  // message has to be queued if another message is waiting to be send
160  // or if we are already trying to send another message
161 
162  if (macQueue.size() <= queueLength) {
163  macQueue.push_back(mac);
164  EV_DETAIL << "packet put in queue\n queue size: " << macQueue.size() << " macState: " << macState
165  << "; mySlot is " << mySlot << "; current slot is " << currSlot << endl;
166  ;
167  }
168  else {
169  // queue is full, message has to be deleted
170  EV_DETAIL << "New packet arrived, but queue is FULL, so new packet is deleted\n";
171  delete mac;
172  EV_DETAIL << "ERROR: Queue is full, forced to delete.\n";
173  }
174 }
virtual LMacFrame * encapsMsg(cPacket *)
Encapsulate the NetwPkt into an MacPkt.
Definition: LMacLayer.cc:652
MacQueue macQueue
A queue to store packets from upper layer in case another packet is still waiting for transmission...
Definition: LMacLayer.h:196
int currSlot
The current slot of the simulation.
Definition: LMacLayer.h:183
unsigned queueLength
length of the queue
Definition: LMacLayer.h:203
int mySlot
my slot ID
Definition: LMacLayer.h:179
States macState
keep track of MAC state
Definition: LMacLayer.h:170
void inet::LMacLayer::initialize ( int  stage)
overridevirtual

Initialization of the module and some variables.

Reimplemented from inet::MACProtocolBase.

32 {
34  if (stage == INITSTAGE_LOCAL) {
35  queueLength = par("queueLength");
36  slotDuration = par("slotDuration");
37  bitrate = par("bitrate");
38  headerLength = par("headerLength");
39  EV << "headerLength is: " << headerLength << endl;
40  numSlots = par("numSlots");
41  // the first N slots are reserved for mobile nodes to be able to function normally
42  reservedMobileSlots = par("reservedMobileSlots");
43 
44  EV_DETAIL << "My Mac address is" << address << " and my Id is " << myId << endl;
45 
46  macState = INIT;
47 
48  slotChange = new cOutVector("slotChange");
49 
50  // how long does it take to send/receive a control packet
51  controlDuration = ((double)headerLength + (double)numSlots + 16) / (double)bitrate;
52  EV << "Control packets take : " << controlDuration << " seconds to transmit\n";
53 
56 
57  cModule *radioModule = getModuleFromPar<cModule>(par("radioModule"), this);
58  radioModule->subscribe(IRadio::radioModeChangedSignal, this);
59  radioModule->subscribe(IRadio::transmissionStateChangedSignal, this);
60  radio = check_and_cast<IRadio *>(radioModule);
61 
62  WATCH(macState);
63  }
64  else if (stage == INITSTAGE_LINK_LAYER) {
65  //int channel;
66  //channel = hasPar("defaultChannel") ? par("defaultChannel") : 0;
67 
68  EV_DETAIL << "queueLength = " << queueLength
69  << " slotDuration = " << slotDuration
70  << " controlDuration = " << controlDuration
71  << " numSlots = " << numSlots
72  << " bitrate = " << bitrate << endl;
73 
74  timeout = new cMessage("timeout");
75  timeout->setKind(LMAC_TIMEOUT);
76 
77  sendData = new cMessage("sendData");
78  sendData->setKind(LMAC_SEND_DATA);
79 
80  wakeup = new cMessage("wakeup");
81  wakeup->setKind(LMAC_WAKEUP);
82 
83  initChecker = new cMessage("setup phase");
85 
86  checkChannel = new cMessage("checkchannel");
88 
89  start_lmac = new cMessage("start_lmac");
90  start_lmac->setKind(LMAC_START_LMAC);
91 
92  send_control = new cMessage("send_control");
94 
95  scheduleAt(0.0, start_lmac);
96  }
97 }
int reservedMobileSlots
The first couple of slots are reserved for nodes with special needs to avoid changing slots for them ...
Definition: LMacLayer.h:189
Definition: LMacLayer.h:143
cMessage * checkChannel
Definition: LMacLayer.h:209
int headerLength
Length of the header.
Definition: LMacLayer.h:175
virtual void initialize(int stage) override
Definition: MACProtocolBase.cc:31
cMessage * timeout
Definition: LMacLayer.h:206
double slotDuration
Duration of a slot.
Definition: LMacLayer.h:173
unsigned queueLength
length of the queue
Definition: LMacLayer.h:203
MACAddress address
The MAC address of the interface.
Definition: LMacLayer.h:192
cMessage * initChecker
Definition: LMacLayer.h:208
#define myId
IRadio * radio
The radio.
Definition: LMacLayer.h:199
cMessage * send_control
Definition: LMacLayer.h:211
States macState
keep track of MAC state
Definition: LMacLayer.h:170
Local initializations.
Definition: InitStages.h:35
Initialization of link-layer protocols.
Definition: InitStages.h:59
Definition: LMacLayer.h:152
double bitrate
the bit rate at which we transmit
Definition: LMacLayer.h:214
cMessage * wakeup
Definition: LMacLayer.h:205
Definition: LMacLayer.h:151
virtual void registerInterface()
Definition: MACProtocolBase.cc:42
int numSlots
how many slots are there
Definition: LMacLayer.h:181
Definition: LMacLayer.h:156
virtual void initializeMACAddress()
Generate new interface address.
Definition: LMacLayer.cc:116
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
cOutVector * slotChange
indicate how often the node needs to change its slot because of collisions
Definition: LMacLayer.h:167
double controlDuration
Duration of teh control time in each slot.
Definition: LMacLayer.h:177
cMessage * start_lmac
Definition: LMacLayer.h:210
Definition: LMacLayer.h:149
cMessage * sendData
Definition: LMacLayer.h:207
Definition: LMacLayer.h:150
static simsignal_t radioModeChangedSignal
This signal is emitted every time the radio mode changes.
Definition: IRadio.h:54
Definition: LMacLayer.h:155
Definition: LMacLayer.h:148
void inet::LMacLayer::initializeMACAddress ( )
protectedvirtual

Generate new interface address.

Referenced by initialize().

117 {
118  const char *addrstr = par("address");
119 
120  if (!strcmp(addrstr, "auto")) {
121  // assign automatic address
123 
124  // change module parameter from "auto" to concrete address
125  par("address").setStringValue(address.str().c_str());
126  }
127  else {
128  address.setAddress(addrstr);
129  }
130 }
MACAddress address
The MAC address of the interface.
Definition: LMacLayer.h:192
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
LMacLayer& inet::LMacLayer::operator= ( const LMacLayer )
private

Assignment operator is not allowed.

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

Handle control messages from lower layer.

Handle transmission over messages: send the data packet or don;t do anyhting.

582 {
583  if (signalID == IRadio::transmissionStateChangedSignal) {
584  IRadio::TransmissionState newRadioTransmissionState = (IRadio::TransmissionState)value;
586  // if data is scheduled for transfer, don;t do anything.
587  if (sendData->isScheduled()) {
588  EV_DETAIL << " transmission of control packet over. data transfer will start soon." << endl;
589  }
590  else {
591  EV_DETAIL << " transmission over. nothing else is scheduled, get back to sleep." << endl;
592  macState = SLEEP;
593  EV_DETAIL << "Old state: ?, New state: SLEEP" << endl;
595  if (timeout->isScheduled())
596  cancelEvent(timeout);
597  }
598  }
599  transmissionState = newRadioTransmissionState;
600  }
601  else if (signalID == IRadio::radioModeChangedSignal) {
602  IRadio::RadioMode radioMode = (IRadio::RadioMode)value;
603  if (macState == SEND_CONTROL && radioMode == IRadio::RADIO_MODE_TRANSMITTER) {
604  // we just switched to TX after CCA, so simply send the first sendPremable self message
605  scheduleAt(simTime(), send_control);
606  }
607  }
608 }
TransmissionState
This enumeration specifies the transmission state of the radio.
Definition: IRadio.h:167
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
The radio is not transmitting a signal on the radio medium.
Definition: IRadio.h:178
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:116
cMessage * timeout
Definition: LMacLayer.h:206
The radio is sleeping, frame reception or transmission is not possible, power consumption is minimal...
Definition: IRadio.h:102
RadioMode
This enumeration specifies the requested operational mode of the radio.
Definition: IRadio.h:91
IRadio * radio
The radio.
Definition: LMacLayer.h:199
cMessage * send_control
Definition: LMacLayer.h:211
The radio medium is busy, the radio is currently transmitting a signal.
Definition: IRadio.h:183
States macState
keep track of MAC state
Definition: LMacLayer.h:170
IRadio::TransmissionState transmissionState
Definition: LMacLayer.h:200
Definition: LMacLayer.h:143
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
cMessage * sendData
Definition: LMacLayer.h:207
static simsignal_t radioModeChangedSignal
This signal is emitted every time the radio mode changes.
Definition: IRadio.h:54
Definition: LMacLayer.h:143
cObject * inet::LMacLayer::setUpControlInfo ( cMessage *const  pMsg,
const MACAddress pSrcAddr 
)

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

Referenced by decapsMsg().

699 {
700  SimpleLinkLayerControlInfo *const cCtrlInfo = new SimpleLinkLayerControlInfo();
701  cCtrlInfo->setSrc(pSrcAddr);
702  cCtrlInfo->setInterfaceId(interfaceEntry->getInterfaceId());
703  pMsg->setControlInfo(cCtrlInfo);
704  return cCtrlInfo;
705 }
int getInterfaceId() const
Definition: InterfaceEntry.h:185
InterfaceEntry * interfaceEntry
Definition: MACProtocolBase.h:38

Member Data Documentation

MACAddress inet::LMacLayer::address
protected

The MAC address of the interface.

Referenced by createInterfaceEntry(), encapsMsg(), handleSelfMessage(), initialize(), and initializeMACAddress().

double inet::LMacLayer::bitrate
protected

the bit rate at which we transmit

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

cMessage* inet::LMacLayer::checkChannel
protected
double inet::LMacLayer::controlDuration
protected

Duration of teh control time in each slot.

Referenced by handleSelfMessage(), and initialize().

int inet::LMacLayer::currSlot
protected

The current slot of the simulation.

Referenced by handleSelfMessage(), and handleUpperPacket().

int inet::LMacLayer::headerLength
protected

Length of the header.

Referenced by encapsMsg(), handleSelfMessage(), and initialize().

cMessage* inet::LMacLayer::initChecker
protected
const MACAddress inet::LMacLayer::LMAC_FREE_SLOT
staticprotected

Referenced by findNewSlot(), and handleSelfMessage().

const MACAddress inet::LMacLayer::LMAC_NO_RECEIVER
staticprotected

dummy receiver address to indicate no pending packets in the control packet

Referenced by handleSelfMessage().

MacQueue inet::LMacLayer::macQueue
protected

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

Referenced by clearQueue(), flushQueue(), handleSelfMessage(), handleUpperPacket(), and ~LMacLayer().

States inet::LMacLayer::macState
protected

keep track of MAC state

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

int inet::LMacLayer::mySlot
protected

my slot ID

Referenced by findNewSlot(), handleSelfMessage(), and handleUpperPacket().

int inet::LMacLayer::numSlots
protected

how many slots are there

Referenced by findNewSlot(), handleSelfMessage(), and initialize().

MACAddress inet::LMacLayer::occSlotsAway[64]
protected

Occupied slots of two-hop neighbors.

Referenced by findNewSlot(), and handleSelfMessage().

MACAddress inet::LMacLayer::occSlotsDirect[64]
protected

Occupied slots from nodes, from which I hear directly.

Referenced by handleSelfMessage().

unsigned inet::LMacLayer::queueLength
protected

length of the queue

Referenced by handleUpperPacket(), and initialize().

IRadio* inet::LMacLayer::radio
protected

The radio.

Referenced by handleSelfMessage(), initialize(), and receiveSignal().

int inet::LMacLayer::reservedMobileSlots
protected

The first couple of slots are reserved for nodes with special needs to avoid changing slots for them (mobile nodes)

Referenced by findNewSlot(), handleSelfMessage(), and initialize().

cMessage* inet::LMacLayer::send_control
protected
cMessage* inet::LMacLayer::sendData
protected
bool inet::LMacLayer::SETUP_PHASE
protected

the setup phase is the beginning of the simulation, where only control packets at very small slot durations are exchanged.

Referenced by handleSelfMessage().

cOutVector* inet::LMacLayer::slotChange
protected

indicate how often the node needs to change its slot because of collisions

Referenced by findNewSlot(), initialize(), and ~LMacLayer().

double inet::LMacLayer::slotDuration
protected

Duration of a slot.

Referenced by handleSelfMessage(), and initialize().

cMessage* inet::LMacLayer::start_lmac
protected

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

cMessage* inet::LMacLayer::timeout
protected
IRadio::TransmissionState inet::LMacLayer::transmissionState
protected

Referenced by receiveSignal().

cMessage* inet::LMacLayer::wakeup
protected

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