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.
194 EV_DETAIL <<
"Scheduling the first wakeup at : " <<
slotDuration << endl;
198 for (
int i = 0; i <
numSlots; i++) {
214 EV_DETAIL <<
"Old state: INIT, New state: SLEEP" << endl;
218 EV <<
"Unknown packet" << msg->getKind() <<
"in state" <<
macState << endl;
226 EV_DETAIL <<
"New slot starting - No. " <<
currSlot <<
", my slot is " <<
mySlot << endl;
229 EV_DETAIL <<
"Waking up in my slot. Switch to RECV first to check the channel.\n";
232 EV_DETAIL <<
"Old state: SLEEP, New state: CCA" << endl;
236 EV_DETAIL <<
"Checking for channel for " << small_delay <<
" time.\n";
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;
254 EV_DETAIL <<
"Setup phase end. Start normal work at the next slot.\n";
255 if (
wakeup->isScheduled())
263 EV <<
"Unknown packet" << msg->getKind() <<
"in state" <<
macState << endl;
270 EV <<
"Channel is free, so let's prepare for sending.\n";
274 EV_DETAIL <<
"Old state: CCA, New state: SEND_CONTROL" << endl;
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;
289 EV_DETAIL <<
"Occupied slot " <<
s <<
": " <<
occSlotsAway[
s] << endl;
290 EV_DETAIL <<
"Occupied direct slot " <<
s <<
": " <<
occSlotsDirect[
s] << endl;
293 if (mac->getMySlot() > -1) {
295 for (
int i = 0; i <
numSlots; i++) {
304 collision = collision || (mac->getMySlot() ==
mySlot);
306 EV_DETAIL <<
"My slot is taken by " << mac->getOccupiedSlots(
mySlot) <<
". I need to change it.\n";
308 EV_DETAIL <<
"My new slot is " <<
mySlot << endl;
311 EV_DETAIL <<
"I don;t have a slot - try to find one.\n";
316 EV_DETAIL <<
"I need to stay awake.\n";
320 EV_DETAIL <<
"Old state: CCA, New state: WAIT_DATA" << endl;
323 EV_DETAIL <<
"Incoming data packet not for me. Going back to sleep.\n";
325 EV_DETAIL <<
"Old state: CCA, New state: SLEEP" << endl;
334 LMacFrame *
const mac =
static_cast<LMacFrame *
>(msg);
335 const MACAddress& dest = mac->getDestAddr();
342 EV_DETAIL <<
" I have received a data packet.\n";
344 EV_DETAIL <<
"sending pkt to upper...\n";
348 EV_DETAIL <<
"packet not for me, deleting...\n";
353 EV_DETAIL <<
"Old state: CCA, New state: SLEEP" << endl;
357 EV_DETAIL <<
"Setup phase end. Start normal work at the next slot.\n";
358 if (
wakeup->isScheduled())
366 EV <<
"Unknown packet" << msg->getKind() <<
"in state" <<
macState << endl;
372 EV_DETAIL <<
"Control timeout. Go back to sleep.\n";
374 EV_DETAIL <<
"Old state: WAIT_CONTROL, New state: SLEEP" << endl;
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";
382 bool collision =
false;
389 EV_DETAIL <<
"Occupied slot " <<
s <<
": " <<
occSlotsAway[
s] << endl;
390 EV_DETAIL <<
"Occupied direct slot " <<
s <<
": " <<
occSlotsDirect[
s] << endl;
393 if (mac->getMySlot() > -1) {
395 for (
int i = 0; i <
numSlots; i++) {
405 collision = collision || (mac->getMySlot() ==
mySlot);
407 EV_DETAIL <<
"My slot is taken by " << mac->getOccupiedSlots(
mySlot) <<
". I need to change it.\n";
409 EV_DETAIL <<
"My new slot is " <<
mySlot << endl;
412 EV_DETAIL <<
"I don;t have a slot - try to find one.\n";
417 EV_DETAIL <<
"I need to stay awake.\n";
419 EV_DETAIL <<
"Old state: WAIT_CONTROL, New state: WAIT_DATA" << endl;
424 EV_DETAIL <<
"Incoming data packet not for me. Going back to sleep.\n";
426 EV_DETAIL <<
"Old state: WAIT_CONTROL, New state: SLEEP" << endl;
435 EV_DETAIL <<
"End of setup-phase slot" << endl;
437 EV_DETAIL <<
"Very unlikely transition";
440 EV_DETAIL <<
"Old state: WAIT_DATA, New state: SLEEP" << endl;
441 scheduleAt(simTime(),
wakeup);
444 EV_DETAIL <<
"Setup phase end. Start normal work at the next slot.\n";
445 if (
wakeup->isScheduled())
453 EV <<
"Unknown packet" << msg->getKind() <<
"in state" <<
macState << endl;
462 EV <<
"Sending a control packet.\n";
463 LMacFrame *control =
new LMacFrame();
466 control->setDestAddr((
macQueue.front())->getDestAddr());
471 control->setMySlot(
mySlot);
473 control->setOccupiedSlotsArraySize(numSlots);
484 EV_DETAIL <<
"ERROR: Send data message received, but we are not in our slot!!! Repair.\n";
490 LMacFrame *data =
macQueue.front()->dup();
493 data->setOccupiedSlotsArraySize(numSlots);
497 EV <<
"Sending down data packet\n";
502 EV_DETAIL <<
"Old state: SEND_CONTROL, New state: SEND_DATA" << endl;
505 EV_DETAIL <<
"Setup phase end. Start normal work at the next slot.\n";
506 if (
wakeup->isScheduled())
514 EV <<
"Unknown packet" << msg->getKind() <<
"in state" <<
macState << endl;
520 throw cRuntimeError(
"I am still sending a message, while a new slot is starting!\n");
523 EV <<
"Unknown packet" << msg->getKind() <<
"in state" <<
macState << endl;
529 LMacFrame *
const mac =
static_cast<LMacFrame *
>(msg);
530 const MACAddress& dest = mac->getDestAddr();
532 EV_DETAIL <<
" I have received a data packet.\n";
534 EV_DETAIL <<
"sending pkt to upper...\n";
538 EV_DETAIL <<
"packet not for me, deleting...\n";
543 EV_DETAIL <<
"Old state: WAIT_DATA, New state: SLEEP" << endl;
550 EV_DETAIL <<
"Unlikely transition. Old state: WAIT_DATA, New state: SLEEP" << endl;
551 scheduleAt(simTime(),
wakeup);
554 EV <<
"Unknown packet" << msg->getKind() <<
"in state" <<
macState << endl;
559 throw cRuntimeError(
"Unknown mac state: %d",
macState);
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
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