|
INET Framework for OMNeT++/OMNEST
|
Implementation of X-MAC.
More...
#include <XMac.h>
Implementation of X-MAC.
This implementation was created for the MiXiM framework by Joaquim Oller. It was ported to the INET framework by Jan Peter Drees.
A paper describing the X-MAC protocol can be found at: http://www.cs.cmu.edu/~andersoe/papers/xmac-sensys.pdf
A paper analyzing this MiXiM implementation can be found at: http://ieeexplore.ieee.org/document/7024195/
- Author
- Joaquim Oller and Jan Peter Drees
◆ States
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 | |
◆ XMAC_COLORS
Possible colors of the node for animation.
| Enumerator |
|---|
| GREEN | |
| BLUE | |
| RED | |
| BLACK | |
| YELLOW | |
◆ XMac() [1/2]
| inet::XMac::XMac |
( |
const XMac & |
| ) |
|
|
private |
Copy constructor is not allowed.
◆ XMac() [2/2]
◆ ~XMac()
◆ attachSignal()
| void inet::XMac::attachSignal |
( |
Packet * |
packet, |
|
|
simtime_t_cref |
startTime |
|
) |
| |
|
protected |
Internal function to attach a signal to the packet.
564 simtime_t duration = packet->getBitLength() /
bitrate;
565 packet->setDuration(duration);
◆ changeDisplayColor()
| void inet::XMac::changeDisplayColor |
( |
XMAC_COLORS |
color | ) |
|
|
protected |
Internal function to change the color of the node.
Change the color of the node for animation purposes.
578 dispStr.setTagArg(
"t", 0,
"INIT");
582 dispStr.setTagArg(
"t", 0,
"SLEEP");
586 dispStr.setTagArg(
"t", 0,
"CCA");
592 dispStr.setTagArg(
"t", 0,
"SEND");
599 dispStr.setTagArg(
"t", 0,
"WAIT");
603 dispStr.setTagArg(
"t", 0,
"");
◆ configureNetworkInterface()
| void inet::XMac::configureNetworkInterface |
( |
| ) |
|
|
overrideprotectedvirtual |
◆ decapsulate()
| void inet::XMac::decapsulate |
( |
Packet * |
packet | ) |
|
|
protected |
610 const auto& xmacHeader = packet->popAtFront<XMacDataFrameHeader>();
611 packet->addTagIfAbsent<MacAddressInd>()->setSrcAddress(xmacHeader->getSrcAddr());
612 packet->addTagIfAbsent<InterfaceInd>()->setInterfaceId(
networkInterface->getInterfaceId());
617 EV_DETAIL <<
" message decapsulated " << endl;
◆ encapsulate()
| void inet::XMac::encapsulate |
( |
Packet * |
packet | ) |
|
|
protected |
622 auto pkt = makeShared<XMacDataFrameHeader>();
627 auto dest = packet->getTag<MacAddressReq>()->getDestAddress();
628 EV_DETAIL <<
"CInfo removed, mac addr=" << dest << endl;
630 pkt->setDestAddr(dest);
633 delete packet->removeControlInfo();
642 packet->insertAtFront(pkt);
644 EV_DETAIL <<
"pkt encapsulated\n";
◆ finish()
| void inet::XMac::finish |
( |
| ) |
|
|
overridevirtual |
Delete all dynamically allocated objects of the module.
◆ getProvider()
Returns the passive packet source from where packets are pulled or nullptr if the connected module doesn't implement the interface.
The gate parameter must be a valid gate of this module.
Implements inet::queueing::IActivePacketSink.
◆ handleCanPullPacketChanged()
| void inet::XMac::handleCanPullPacketChanged |
( |
cGate * |
gate | ) |
|
|
overridevirtual |
Notifies about a change in the possibility of pulling some packet from the passive packet source at the given gate.
This method is called, for example, when a new packet is inserted into a queue. It allows the sink to pull a new packet from the queue.
The gate parameter must be a valid gate of this module.
Implements inet::queueing::IActivePacketSink.
659 rescheduleAfter(dblrand() * 0.01f,
wakeup);
◆ handleLowerPacket()
| void inet::XMac::handleLowerPacket |
( |
Packet * |
msg | ) |
|
|
overridevirtual |
Handle messages from lower layer.
Handle XMAC preambles and received data packets.
Reimplemented from inet::LayeredProtocolBase.
500 if (msg->hasBitError()) {
501 EV <<
"Received " << msg <<
" contains bit errors or collision, dropping it\n";
507 const auto& hdr = msg->peekAtFront<XMacHeaderBase>();
508 msg->setKind(hdr->getType());
◆ handlePullPacketProcessed()
| void inet::XMac::handlePullPacketProcessed |
( |
Packet * |
packet, |
|
|
cGate * |
gate, |
|
|
bool |
successful |
|
) |
| |
|
overridevirtual |
Notifies about the completion of the packet processing for a packet that was pulled earlier independently whether the packet is passed or streamed.
This method is called, for example, when a previously pulled packet is failed to be processed successfully. It allows the sink to retry the operation.
The gate parameter must be a valid gate of this module. The packet must not be nullptr.
Implements inet::queueing::IActivePacketSink.
666 throw cRuntimeError(
"Not supported callback");
◆ handleSelfMessage()
| void inet::XMac::handleSelfMessage |
( |
cMessage * |
msg | ) |
|
|
overridevirtual |
Handle self messages such as timers.
Handle own messages:
Reimplemented from inet::LayeredProtocolBase.
202 EV_DEBUG <<
"State INIT, message XMAC_START, new state SLEEP" << endl;
212 EV_DEBUG <<
"node " << address <<
" : State SLEEP, message XMAC_WAKEUP, new state CCA, simTime "
213 << simTime() <<
" to " << simTime() + 1.7f *
checkInterval << endl;
223 else if (msg->getKind() ==
XMAC_ACK) {
258 auto incoming_preamble = check_and_cast<Packet *>(msg)->peekAtFront<XMacControlFrame>();
261 if (incoming_preamble->getDestAddr() == address || incoming_preamble->getDestAddr().isBroadcast() || incoming_preamble->getDestAddr().isMulticast()) {
264 EV <<
"node " << address <<
" : State CCA, message XMAC_PREAMBLE received, new state SEND_ACK" << endl;
272 EV <<
"node " << address <<
" : State CCA, message XMAC_PREAMBLE not for me." << endl;
287 EV_DEBUG <<
"State CCA, message XMAC_ACK, new state CCA" << endl;
295 auto incoming_data = check_and_cast<Packet *>(msg)->peekAtFront<XMacDataFrameHeader>();
298 if (incoming_data->getDestAddr() == address) {
299 EV <<
"node " << address <<
" : State CCA, received XMAC_DATA, accepting it." << endl;
304 scheduleAfter(SIMTIME_ZERO, msg);
317 EV_DEBUG <<
"node " << address <<
" : preamble_phase tx, simTime = " << simTime() << endl;
324 EV_DEBUG <<
"node " << address <<
" : preamble_phase rx, simTime = " << simTime() << endl;
346 EV <<
"node " << address <<
" : State SEND_PREAMBLE, message XMAC_ACK, new state SEND_DATA" << endl;
349 EV <<
"node " << address <<
" : State SEND_PREAMBLE, message XMAC_STOP_PREAMBLES" << endl;
369 EV <<
"**node " << address <<
" : State SEND_PREAMBLE, received message " << msg->getKind() << endl;
376 EV <<
"node " << address <<
" : State SEND_DATA, message XMAC_STOP_PREAMBLES" << endl;
383 EV <<
"node " << address <<
" : State SEND_DATA, message RADIO_SWITCHING OVER, sending packet..." << endl;
396 EV_DEBUG <<
"node " << address <<
" : State WAIT_TX_DATA_OVER, message XMAC_DATA_TX_OVER, new state SLEEP" << endl;
426 auto packet = check_and_cast<Packet *>(msg);
427 auto mac = packet->peekAtFront<XMacDataFrameHeader>();
428 const MacAddress& dest = mac->getDestAddr();
430 if ((dest == address) || dest.isBroadcast() || dest.isMulticast()) {
452 EV <<
"node " << address <<
" : State WAIT_DATA, message XMAC_DATA, new state SLEEP" << endl;
457 EV <<
"node " << address <<
" : State WAIT_DATA, message XMAC_DATA_TIMEOUT, new state SLEEP" << endl;
472 EV_DEBUG <<
"node " << address <<
" : State SEND_ACK, message XMAC_SEND_ACK, new state WAIT_ACK_TX" << endl;
481 EV_DEBUG <<
"node " << address <<
" : State WAIT_ACK_TX, message XMAC_ACK_TX_OVER, new state WAIT_DATA" << endl;
491 throw cRuntimeError(
"Undefined event of type %d in state %d (Radio state %d)!",
◆ handleUpperPacket()
| void inet::XMac::handleUpperPacket |
( |
Packet * |
packet | ) |
|
|
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.
Reimplemented from inet::LayeredProtocolBase.
153 throw cRuntimeError(
"Model error: this module should pull packet from upper queue, direct incoming packet not accepted");
◆ initialize()
| void inet::XMac::initialize |
( |
int |
stage | ) |
|
|
overridevirtual |
Initialization of the module and some variables.
Initialize method of XMac.
Init all parameters, schedule timers.
Reimplemented from inet::MacProtocolBase.
63 radio.reference(
this,
"radioModule",
true);
64 cModule *radioModule = check_and_cast<cModule *>(
radio.get());
◆ operator=()
| XMac& inet::XMac::operator= |
( |
const XMac & |
| ) |
|
|
private |
Assignment operator is not allowed.
◆ receiveSignal()
| void inet::XMac::receiveSignal |
( |
cComponent * |
source, |
|
|
simsignal_t |
signalID, |
|
|
intval_t |
value, |
|
|
cObject * |
details |
|
) |
| |
|
override |
Handle transmission over messages: either send another preambles or the data packet itself.
533 Enter_Method(
"%s", cComponent::getSignalName(signalID));
◆ sendDataPacket()
| void inet::XMac::sendDataPacket |
( |
| ) |
|
|
protected |
Internal function to send the first packet in the queue.
520 const auto& hdr = packet->
peekAtFront<XMacHeaderBase>();
◆ sendMacAck()
| void inet::XMac::sendMacAck |
( |
| ) |
|
|
protected |
Internal function to send an ACK.
Send one short preamble packet immediately.
179 auto ack = makeShared<XMacControlFrame>();
185 auto packet =
new Packet(
"XMacAck", ack);
◆ sendPreamble()
| void inet::XMac::sendPreamble |
( |
MacAddress |
destination | ) |
|
|
protected |
Internal function to send one preamble.
Send one short preamble packet immediately.
162 auto preamble = makeShared<XMacControlFrame>();
164 preamble->setDestAddr(preamble_address);
167 auto packet =
new Packet(
"Preamble", preamble);
◆ ack_timeout
| cMessage* inet::XMac::ack_timeout |
|
protected |
◆ ack_tx_over
| cMessage* inet::XMac::ack_tx_over |
|
protected |
◆ animation
| bool inet::XMac::animation |
|
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
◆ bitrate
| double inet::XMac::bitrate |
|
protected |
The bitrate of transmission.
◆ cca_timeout
| cMessage* inet::XMac::cca_timeout |
|
protected |
◆ checkInterval
| double inet::XMac::checkInterval |
|
protected |
◆ ctrlFrameLength
| b inet::XMac::ctrlFrameLength = b(0) |
|
protected |
◆ data_timeout
| cMessage* inet::XMac::data_timeout |
|
protected |
◆ data_tx_over
| cMessage* inet::XMac::data_tx_over |
|
protected |
◆ delay_for_ack_within_remote_rx
| cMessage* inet::XMac::delay_for_ack_within_remote_rx |
|
protected |
◆ headerLength
| b inet::XMac::headerLength = b(0) |
|
protected |
◆ lastDataPktDestAddr
◆ lastDataPktSrcAddr
◆ lastPreamblePktSrcAddr
◆ macState
The current state of the protocol.
◆ maxTxAttempts
| int inet::XMac::maxTxAttempts |
|
protected |
Maximum transmission attempts per data packet, when ACKs are used.
◆ nbDroppedDataPackets
| long inet::XMac::nbDroppedDataPackets |
|
protected |
◆ nbMissedAcks
| long inet::XMac::nbMissedAcks |
|
protected |
◆ nbRecvdAcks
| long inet::XMac::nbRecvdAcks |
|
protected |
◆ nbRxBrokenDataPackets
| long inet::XMac::nbRxBrokenDataPackets |
|
protected |
◆ nbRxDataPackets
| long inet::XMac::nbRxDataPackets |
|
protected |
◆ nbRxPreambles
| long inet::XMac::nbRxPreambles |
|
protected |
◆ nbTxAcks
| long inet::XMac::nbTxAcks |
|
protected |
◆ nbTxDataPackets
| long inet::XMac::nbTxDataPackets |
|
protected |
◆ nbTxPreambles
| long inet::XMac::nbTxPreambles |
|
protected |
◆ radio
◆ resend_data
| cMessage* inet::XMac::resend_data |
|
protected |
◆ send_ack
| cMessage* inet::XMac::send_ack |
|
protected |
◆ send_preamble
| cMessage* inet::XMac::send_preamble |
|
protected |
◆ slotDuration
| double inet::XMac::slotDuration |
|
protected |
The duration of the slot in secs.
◆ start_xmac
| cMessage* inet::XMac::start_xmac |
|
protected |
◆ stats
Gather stats at the end of the simulation.
◆ stop_preambles
| cMessage* inet::XMac::stop_preambles |
|
protected |
◆ switch_preamble_phase
| cMessage* inet::XMac::switch_preamble_phase |
|
protected |
◆ switching_done
| cMessage* inet::XMac::switching_done |
|
protected |
◆ transmissionState
◆ txAttempts
| int inet::XMac::txAttempts |
|
protected |
◆ txPower
| double inet::XMac::txPower |
|
protected |
Transmission power of the node.
◆ useMacAcks
| bool inet::XMac::useMacAcks |
|
protected |
Use MAC level acks or not.
◆ wakeup
| cMessage* inet::XMac::wakeup |
|
protected |
The documentation for this class was generated from the following files:
opp_component_ptr< NetworkInterface > networkInterface
Definition: MacProtocolBase.h:30
@ SEND_DATA
Definition: XMac.h:143
cMessage * data_tx_over
Definition: XMac.h:164
double slotDuration
The duration of the slot in secs.
Definition: XMac.h:192
@ BLACK
Definition: XMac.h:212
b headerLength
Definition: XMac.h:173
bool useMacAcks
Use MAC level acks or not.
Definition: XMac.h:200
@ XMAC_START_XMAC
Definition: XMacHeader_m.h:82
cMessage * wakeup
Definition: XMac.h:156
long nbRxDataPackets
Definition: XMac.h:108
@ XMAC_RESEND_DATA
Definition: XMacHeader_m.h:80
virtual void sendUp(cMessage *message)
Definition: MacProtocolBase.cc:59
cMessage * stop_preambles
Definition: XMac.h:163
MacAddress lastDataPktDestAddr
Definition: XMac.h:171
MacAddress lastDataPktSrcAddr
Definition: XMac.h:170
@ BLUE
Definition: XMac.h:210
@ SEND_PREAMBLE
Definition: XMac.h:141
@ XMAC_SWITCHING_FINISHED
Definition: XMacHeader_m.h:93
cMessage * switching_done
Definition: XMac.h:166
cMessage * ack_tx_over
Definition: XMac.h:159
@ XMAC_PREAMBLE
Definition: XMacHeader_m.h:77
const Ptr< const Chunk > peekAtFront(b length=b(-1), int flags=0) const
Returns the designated part from the beginning of the data part of the packet as an immutable chunk i...
Definition: Packet.h:245
@ DELAY_FOR_ACK_WITHIN_REMOTE_RX
Definition: XMacHeader_m.h:92
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
@ RADIO_MODE_SLEEP
The radio is sleeping, frame reception or transmission is not possible, power consumption is minimal,...
Definition: IRadio.h:90
long nbRecvdAcks
Definition: XMac.h:111
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
@ SWITCH_PREAMBLE_PHASE
Definition: XMacHeader_m.h:91
long nbTxDataPackets
Definition: XMac.h:106
static simsignal_t transmissionStateChangedSignal
This signal is emitted when the radio transmission state of the radio is changed.
Definition: IRadio.h:60
@ SLEEP
Definition: XMac.h:139
void sendMacAck()
Internal function to send an ACK.
Definition: XMac.cc:177
@ XMAC_DATA_TIMEOUT
Definition: XMacHeader_m.h:90
void sendDataPacket()
Internal function to send the first packet in the queue.
Definition: XMac.cc:512
@ RADIO_MODE_TRANSMITTER
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:104
@ XMAC_SEND_PREAMBLE
Definition: XMacHeader_m.h:87
void changeDisplayColor(XMAC_COLORS color)
Internal function to change the color of the node.
Definition: XMac.cc:571
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
long nbRxPreambles
Definition: XMac.h:109
@ XMAC_ACK_TX_OVER
Definition: XMacHeader_m.h:86
double checkInterval
The duration of CCA.
Definition: XMac.h:196
MacProtocolBase()
Definition: MacProtocolBase.cc:15
cMessage * send_ack
Definition: XMac.h:157
States macState
The current state of the protocol.
Definition: XMac.h:150
long nbTxPreambles
Definition: XMac.h:107
int maxTxAttempts
Maximum transmission attempts per data packet, when ACKs are used.
Definition: XMac.h:203
double bitrate
The bitrate of transmission.
Definition: XMac.h:194
physicallayer::IRadio::TransmissionState transmissionState
Definition: XMac.h:178
virtual Packet * dup() const override
Definition: Packet.h:171
@ RADIO_MODE_RECEIVER
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:97
cMessage * ack_timeout
Definition: XMac.h:154
virtual void handleSelfMessage(cMessage *) override
Handle self messages such as timers.
Definition: XMac.cc:195
@ SEND_ACK
Definition: XMac.h:146
Packet * currentTxFrame
Currently transmitted frame if any.
Definition: MacProtocolBase.h:35
cMessage * resend_data
Definition: XMac.h:153
cMessage * delay_for_ack_within_remote_rx
Definition: XMac.h:162
cMessage * data_timeout
Definition: XMac.h:165
virtual void sendDown(cMessage *message)
Definition: MacProtocolBase.cc:66
b ctrlFrameLength
Definition: XMac.h:174
@ XMAC_CCA_TIMEOUT
Definition: XMacHeader_m.h:85
int upperLayerInGateId
Gate ids.
Definition: MacProtocolBase.h:24
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
@ TRANSMISSION_STATE_TRANSMITTING
The radio medium is busy, the radio is currently transmitting a signal.
Definition: IRadio.h:171
value< int64_t, units::b > b
Definition: Units.h:1241
bool stats
Gather stats at the end of the simulation.
Definition: XMac.h:205
cMessage * switch_preamble_phase
Definition: XMac.h:161
static const Protocol xmac
Definition: Protocol.h:118
void decapsulate(Packet *packet)
Definition: XMac.cc:608
bool animation
Animate (colorize) the nodes.
Definition: XMac.h:190
long nbRxBrokenDataPackets
Definition: XMac.h:114
virtual void deleteCurrentTxFrame()
Definition: MacProtocolBase.cc:93
@ XMAC_ACK
Definition: XMacHeader_m.h:79
virtual void initialize(int stage) override
Definition: MacProtocolBase.cc:37
void encapsulate(Packet *packet)
Definition: XMac.cc:620
@ WAIT_ACK
Definition: XMac.h:145
@ RED
Definition: XMac.h:211
@ XMAC_STOP_PREAMBLES
Definition: XMacHeader_m.h:88
@ YELLOW
Definition: XMac.h:213
void sendPreamble(MacAddress destination)
Internal function to send one preamble.
Definition: XMac.cc:159
cMessage * start_xmac
Definition: XMac.h:155
queueing::IPacketQueue * getQueue(cGate *gate) const
Definition: MacProtocolBase.cc:157
MacAddress lastPreamblePktSrcAddr
Definition: XMac.h:172
@ GREEN
Definition: XMac.h:209
@ XMAC_WAKE_UP
Definition: XMacHeader_m.h:83
@ WAIT_ACK_TX
Definition: XMac.h:147
#define Enter_Method(...)
Definition: SelfDoc.h:71
TransmissionState
This enumeration specifies the transmission state of the radio.
Definition: IRadio.h:155
void attachSignal(Packet *packet, simtime_t_cref startTime)
Internal function to attach a signal to the packet.
Definition: XMac.cc:562
ModuleRefByPar< physicallayer::IRadio > radio
The radio.
Definition: XMac.h:177
virtual Packet * dequeuePacket()
Definition: MacProtocolBase.cc:175
@ XMAC_DATA_TX_OVER
Definition: XMacHeader_m.h:89
static const MacAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MacAddress.h:34
long nbDroppedDataPackets
Definition: XMac.h:112
@ INIT
Definition: XMac.h:138
virtual MacAddress parseMacAddressParameter(const char *addrstr)
Definition: MacProtocolBase.cc:24
cMessage * send_preamble
Definition: XMac.h:160
@ XMAC_SEND_ACK
Definition: XMacHeader_m.h:84
@ XMAC_ACK_TIMEOUT
Definition: XMacHeader_m.h:81
const Protocol * getProtocol(int protocolNumber) const
Definition: ProtocolGroup.cc:31
opp_component_ptr< queueing::IPacketQueue > txQueue
Messages received from upper layer and to be transmitted later.
Definition: MacProtocolBase.h:38
@ TRANSMISSION_STATE_IDLE
The radio is not transmitting a signal on the radio medium.
Definition: IRadio.h:166
double txPower
Transmission power of the node.
Definition: XMac.h:198
@ WAIT_TX_DATA_OVER
Definition: XMac.h:144
@ XMAC_DATA
Definition: XMacHeader_m.h:78
long nbMissedAcks
Definition: XMac.h:110
@ CCA
Definition: XMac.h:140
virtual bool canDequeuePacket() const
Definition: MacProtocolBase.cc:170
@ WAIT_DATA
Definition: XMac.h:142
long nbTxAcks
Definition: XMac.h:113
int txAttempts
Definition: XMac.h:180
INET_API InitStage INITSTAGE_LINK_LAYER
Initialization of link-layer protocols.
static ProtocolGroup ethertype
Definition: ProtocolGroup.h:40
static simsignal_t radioModeChangedSignal
This signal is emitted when the radio mode of the radio is changed.
Definition: IRadio.h:42
cMessage * cca_timeout
Definition: XMac.h:158