INET Framework for OMNeT++/OMNEST
|
Implementation of B-MAC (called also Berkeley MAC, Low Power Listening or LPL). More...
#include <BMacLayer.h>
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 InterfaceEntry * | createInterfaceEntry () 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) |
BMacFrame * | encapsMsg (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... | |
IRadio * | radio = 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... | |
BMacLayer & | operator= (const BMacLayer &) |
Assignment operator is not allowed. More... | |
Additional Inherited Members | |
Public Attributes inherited from inet::MACProtocolBase | |
InterfaceEntry * | interfaceEntry |
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") |
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:
A paper describing this implementation can be found at: http://www.omnet-workshop.org/2011/uploads/slides/OMNeT_WS2011_S5_C1_Foerster.pdf
|
protected |
|
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 |
|
protected |
Types of messages (self messages and packets) the node can process.
|
private |
Copy constructor is not allowed.
|
virtual |
|
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().
|
protected |
Internal function to attach a signal to the packet.
Referenced by sendDataPacket(), sendMacAck(), and sendPreamble().
|
protectedvirtual |
|
overrideprotectedvirtual |
Implements inet::MACProtocolBase.
|
protected |
Referenced by handleSelfMessage().
|
protected |
Referenced by addToQueue().
|
overridevirtual |
Delete all dynamically allocated objects of the module.
|
protectedvirtual |
|
overridevirtual |
Handle messages from lower layer.
Handle BMAC preambles and received data packets.
Implements inet::LayeredProtocolBase.
|
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().
|
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.
|
overridevirtual |
Reimplemented from inet::MACProtocolBase.
|
protectedvirtual |
Generate new interface address.
Referenced by initialize().
|
inlineoverridevirtual |
Assignment operator is not allowed.
|
overridevirtual |
Handle control messages from lower layer.
|
overridevirtual |
Change the color of the node for animation purposes.
|
protected |
Internal function to send the first packet in the queue.
Referenced by handleSelfMessage().
|
protected |
Internal function to send an ACK.
Send one short preamble packet immediately.
Referenced by handleSelfMessage().
|
protected |
Internal function to send one preamble.
Send one short preamble packet immediately.
Referenced by handleSelfMessage().
|
protected |
Attaches a "control info" (MacToNetw) structure (object) to the message pMsg.
Referenced by decapsMsg().
|
protected |
Referenced by handleSelfMessage(), initialize(), and ~BMacLayer().
|
protected |
Referenced by initialize(), receiveSignal(), and ~BMacLayer().
|
protected |
The MAC address of the interface.
Referenced by createInterfaceEntry(), encapsMsg(), handleSelfMessage(), initializeMACAddress(), sendMacAck(), and sendPreamble().
|
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().
|
protected |
The bitrate of transmission.
Referenced by attachSignal(), createInterfaceEntry(), and initialize().
|
protected |
Referenced by handleSelfMessage(), initialize(), and ~BMacLayer().
|
protected |
The duration of CCA.
Referenced by handleSelfMessage(), and initialize().
|
protected |
Referenced by handleSelfMessage(), initialize(), and ~BMacLayer().
|
protected |
Referenced by initialize(), receiveSignal(), and ~BMacLayer().
|
protected |
Length of the header.
Referenced by encapsMsg(), initialize(), sendMacAck(), and sendPreamble().
|
protected |
Referenced by handleSelfMessage(), initialize(), and sendDataPacket().
|
protected |
Referenced by handleSelfMessage(), initialize(), and sendMacAck().
|
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().
The current state of the protocol.
Referenced by addToQueue(), handleSelfMessage(), handleUpperPacket(), initialize(), receiveSignal(), and refreshDisplay().
|
protected |
Maximum transmission attempts per data packet, when ACKs are used.
Referenced by handleSelfMessage(), and initialize().
|
protected |
Referenced by addToQueue(), finish(), and initialize().
|
protected |
Referenced by finish(), handleSelfMessage(), and initialize().
|
protected |
Referenced by finish(), handleSelfMessage(), and initialize().
|
protected |
Referenced by finish(), handleSelfMessage(), and initialize().
|
protected |
Referenced by finish(), handleSelfMessage(), and initialize().
|
protected |
Referenced by finish(), initialize(), and sendMacAck().
|
protected |
Referenced by finish(), initialize(), and sendDataPacket().
|
protected |
Referenced by finish(), initialize(), and sendPreamble().
|
protected |
The maximum length of the queue.
Referenced by addToQueue(), and initialize().
|
protected |
The radio.
Referenced by handleSelfMessage(), and initialize().
|
protected |
Referenced by initialize(), receiveSignal(), and ~BMacLayer().
|
protected |
Referenced by initialize(), receiveSignal(), and ~BMacLayer().
|
protected |
Referenced by handleSelfMessage(), initialize(), receiveSignal(), and ~BMacLayer().
|
protected |
The duration of the slot in secs.
Referenced by handleSelfMessage(), and initialize().
|
protected |
Referenced by initialize(), and ~BMacLayer().
|
protected |
Gather stats at the end of the simulation.
|
protected |
Referenced by handleSelfMessage(), initialize(), and ~BMacLayer().
|
protected |
Referenced by receiveSignal().
|
protected |
Referenced by handleSelfMessage(), and initialize().
|
protected |
Use MAC level acks or not.
Referenced by handleSelfMessage(), and initialize().
|
protected |
Referenced by handleSelfMessage(), handleUpperPacket(), initialize(), and ~BMacLayer().