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

Implements a simplified ideal MAC. More...

#include <IdealMac.h>

Inheritance diagram for inet::IdealMac:
inet::MACProtocolBase inet::LayeredProtocolBase inet::OperationalBase inet::ILifecycle

Public Member Functions

 IdealMac ()
 
virtual ~IdealMac ()
 
- Public Member Functions inherited from inet::OperationalBase
 OperationalBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual void startTransmitting (cPacket *msg)
 
virtual bool dropFrameNotForUs (IdealMacFrame *frame)
 
virtual IdealMacFrameencapsulate (cPacket *msg)
 
virtual cPacket * decapsulate (IdealMacFrame *frame)
 
virtual void initializeMACAddress ()
 
virtual void acked (IdealMacFrame *frame)
 
virtual void getNextMsgFromHL ()
 
virtual void receiveSignal (cComponent *src, simsignal_t id, long value, cObject *details) override
 
virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void flushQueue ()
 implements MacBase functions More...
 
virtual void clearQueue ()
 
virtual InterfaceEntrycreateInterfaceEntry () override
 
virtual void handleUpperPacket (cPacket *msg) override
 implements MACProtocolBase functions More...
 
virtual void handleLowerPacket (cPacket *msg) override
 
virtual void handleSelfMessage (cMessage *message) override
 
- 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

int headerLength = 0
 
double bitrate = 0
 
bool promiscuous = false
 
MACAddress address
 
bool fullDuplex = false
 
bool useAck = true
 
IRadioradio = nullptr
 
IRadio::TransmissionState transmissionState = IRadio::TRANSMISSION_STATE_UNDEFINED
 
IPassiveQueuequeueModule = nullptr
 
int outStandingRequests = 0
 
cPacket * lastSentPk = nullptr
 
simtime_t ackTimeout
 
cMessage * ackTimeoutMsg = nullptr
 
- Protected Attributes inherited from inet::OperationalBase
bool isOperational
 
simtime_t lastChange
 

Static Protected Attributes

static simsignal_t dropPkNotForUsSignal = registerSignal("dropPkNotForUs")
 

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

Implements a simplified ideal MAC.

See the NED file for details.

Constructor & Destructor Documentation

inet::IdealMac::IdealMac ( )
38 {
39 }
inet::IdealMac::~IdealMac ( )
virtual
42 {
43  delete lastSentPk;
44  cancelAndDelete(ackTimeoutMsg);
45 }
cPacket * lastSentPk
Definition: IdealMac.h:59
cMessage * ackTimeoutMsg
Definition: IdealMac.h:61

Member Function Documentation

void inet::IdealMac::acked ( IdealMacFrame frame)
protectedvirtual

Referenced by handleLowerPacket().

238 {
239  Enter_Method_Silent();
240  ASSERT(useAck);
241 
242  EV_DEBUG << "IdealMac::acked(" << frame->getFullName() << ") is ";
243 
244  if (lastSentPk && lastSentPk->getTreeId() == frame->getTreeId()) {
245  EV_DEBUG << "accepted\n";
246  cancelEvent(ackTimeoutMsg);
247  delete lastSentPk;
248  lastSentPk = nullptr;
250  }
251  else
252  EV_DEBUG << "unaccepted\n";
253 }
cPacket * lastSentPk
Definition: IdealMac.h:59
virtual void getNextMsgFromHL()
Definition: IdealMac.cc:175
cMessage * ackTimeoutMsg
Definition: IdealMac.h:61
bool useAck
Definition: IdealMac.h:52
void inet::IdealMac::clearQueue ( )
protectedvirtual
59 {
60  ASSERT(queueModule);
61  queueModule->clear();
62 }
virtual void clear()=0
Clear all queued packets and stored requests.
IPassiveQueue * queueModule
Definition: IdealMac.h:56
InterfaceEntry * inet::IdealMac::createInterfaceEntry ( )
overrideprotectedvirtual

Implements inet::MACProtocolBase.

116 {
117  InterfaceEntry *e = new InterfaceEntry(this);
118 
119  // data rate
120  e->setDatarate(bitrate);
121 
122  // generate a link-layer address to be used as interface token for IPv6
123  e->setMACAddress(address);
124  e->setInterfaceToken(address.formInterfaceIdentifier());
125 
126  // MTU: typical values are 576 (Internet de facto), 1500 (Ethernet-friendly),
127  // 4000 (on some point-to-point links), 4470 (Cisco routers default, FDDI compatible)
128  e->setMtu(par("mtu").longValue());
129 
130  // capabilities
131  e->setMulticast(true);
132  e->setBroadcast(true);
133 
134  return e;
135 }
double bitrate
Definition: IdealMac.h:48
MACAddress address
Definition: IdealMac.h:50
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::IdealMac::decapsulate ( IdealMacFrame frame)
protectedvirtual

Referenced by handleLowerPacket().

293 {
294  // decapsulate and attach control info
295  cPacket *packet = frame->decapsulate();
296  Ieee802Ctrl *etherctrl = new Ieee802Ctrl();
297  etherctrl->setSrc(frame->getSrc());
298  etherctrl->setDest(frame->getDest());
299  packet->setControlInfo(etherctrl);
300 
301  delete frame;
302  return packet;
303 }
bool inet::IdealMac::dropFrameNotForUs ( IdealMacFrame frame)
protectedvirtual

Referenced by handleLowerPacket().

269 {
270  // Current implementation does not support the configuration of multicast
271  // MAC address groups. We rather accept all multicast frames (just like they were
272  // broadcasts) and pass it up to the higher layer where they will be dropped
273  // if not needed.
274  // All frames must be passed to the upper layer if the interface is
275  // in promiscuous mode.
276 
277  if (frame->getDest().equals(address))
278  return false;
279 
280  if (frame->getDest().isBroadcast())
281  return false;
282 
283  if (promiscuous || frame->getDest().isMulticast())
284  return false;
285 
286  EV << "Frame `" << frame->getName() << "' not destined to us, discarding\n";
287  emit(dropPkNotForUsSignal, frame);
288  delete frame;
289  return true;
290 }
static simsignal_t dropPkNotForUsSignal
Definition: IdealMac.h:44
bool promiscuous
Definition: IdealMac.h:49
MACAddress address
Definition: IdealMac.h:50
IdealMacFrame * inet::IdealMac::encapsulate ( cPacket *  msg)
protectedvirtual

Referenced by startTransmitting().

256 {
257  Ieee802Ctrl *ctrl = check_and_cast<Ieee802Ctrl *>(msg->removeControlInfo());
258  IdealMacFrame *frame = new IdealMacFrame(msg->getName());
259  frame->setByteLength(headerLength);
260  frame->setSrc(ctrl->getSrc());
261  frame->setDest(ctrl->getDest());
262  frame->encapsulate(msg);
263  frame->setSrcModuleId(getId());
264  delete ctrl;
265  return frame;
266 }
int headerLength
Definition: IdealMac.h:47
void inet::IdealMac::flushQueue ( )
protectedvirtual

implements MacBase functions

48 {
49  ASSERT(queueModule);
50  while (!queueModule->isEmpty()) {
51  cMessage *msg = queueModule->pop();
52  //TODO emit(dropPkIfaceDownSignal, msg); -- 'pkDropped' signals are missing in this module!
53  delete msg;
54  }
55  queueModule->clear(); // clear request count
56 }
virtual void clear()=0
Clear all queued packets and stored requests.
IPassiveQueue * queueModule
Definition: IdealMac.h:56
virtual bool isEmpty()=0
Return true when queue is empty, otherwise return false.
virtual cMessage * pop()=0
Returns a packet directly from the queue, bypassing the primary, send-on-request mechanism.
void inet::IdealMac::getNextMsgFromHL ( )
protectedvirtual

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

176 {
178  if (outStandingRequests == 0) {
181  }
182  ASSERT(outStandingRequests <= 1);
183 }
virtual void requestPacket()=0
The queue should send a packet whenever this method is invoked.
IPassiveQueue * queueModule
Definition: IdealMac.h:56
int outStandingRequests
Definition: IdealMac.h:58
virtual int getNumPendingRequests()=0
Returns number of pending requests.
void inet::IdealMac::handleLowerPacket ( cPacket *  msg)
overrideprotectedvirtual

Implements inet::LayeredProtocolBase.

200 {
201  IdealMacFrame *frame = check_and_cast<IdealMacFrame *>(msg);
202  if (frame->hasBitError()) {
203  EV << "Received " << frame << " contains bit errors or collision, dropping it\n";
204  // TODO: add reason? emit(LayeredProtocolBase::packetFromLowerDroppedSignal, frame);
205  delete frame;
206  return;
207  }
208 
209  if (!dropFrameNotForUs(frame)) {
210  int senderModuleId = frame->getSrcModuleId();
211  IdealMac *senderMac = dynamic_cast<IdealMac *>(getSimulation()->getModule(senderModuleId));
212  // TODO: this whole out of bounds ack mechanism is fishy
213  if (senderMac && senderMac->useAck)
214  senderMac->acked(frame);
215  // decapsulate and attach control info
216  cPacket *higherlayerMsg = decapsulate(frame);
217  EV << "Passing up contained packet `" << higherlayerMsg->getName() << "' to higher layer\n";
218  sendUp(higherlayerMsg);
219  }
220 }
IdealMac()
Definition: IdealMac.cc:37
virtual bool dropFrameNotForUs(IdealMacFrame *frame)
Definition: IdealMac.cc:268
virtual cPacket * decapsulate(IdealMacFrame *frame)
Definition: IdealMac.cc:292
virtual void sendUp(cMessage *message)
Definition: MACProtocolBase.cc:52
void inet::IdealMac::handleSelfMessage ( cMessage *  message)
overrideprotectedvirtual

Reimplemented from inet::LayeredProtocolBase.

223 {
224  if (message == ackTimeoutMsg) {
225  EV_DETAIL << "IdealMac: timeout: " << lastSentPk->getFullName() << " is lost\n";
226  // packet lost
227  emit(NF_LINK_BREAK, lastSentPk);
228  delete lastSentPk;
229  lastSentPk = nullptr;
231  }
232  else {
234  }
235 }
cPacket * lastSentPk
Definition: IdealMac.h:59
virtual void getNextMsgFromHL()
Definition: IdealMac.cc:175
simsignal_t NF_LINK_BREAK
Definition: NotifierConsts.cc:43
cMessage * ackTimeoutMsg
Definition: IdealMac.h:61
virtual void handleSelfMessage(cMessage *message)
Definition: LayeredProtocolBase.cc:53
void inet::IdealMac::handleUpperPacket ( cPacket *  msg)
overrideprotectedvirtual

implements MACProtocolBase functions

Implements inet::LayeredProtocolBase.

186 {
189  // Logic error: we do not request packet from the external queue when radio is transmitting
190  throw cRuntimeError("Received msg for transmission but transmitter is busy");
191  }
192  else {
193  // We are idle, so we can start transmitting right away.
194  EV << "Received " << msg << " for transmission\n";
195  startTransmitting(msg);
196  }
197 }
int outStandingRequests
Definition: IdealMac.h:58
The radio medium is busy, the radio is currently transmitting a signal.
Definition: IRadio.h:183
virtual void startTransmitting(cPacket *msg)
Definition: IdealMac.cc:151
IRadio * radio
Definition: IdealMac.h:54
virtual TransmissionState getTransmissionState() const =0
Returns the current radio transmission state.
void inet::IdealMac::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::MACProtocolBase.

65 {
67  if (stage == INITSTAGE_LOCAL) {
69 
70  bitrate = par("bitrate").doubleValue();
71  headerLength = par("headerLength").longValue();
72  promiscuous = par("promiscuous");
73  fullDuplex = par("fullDuplex");
74  useAck = par("useAck");
75  ackTimeout = par("ackTimeout");
76 
77  cModule *radioModule = gate("lowerLayerOut")->getPathEndGate()->getOwnerModule();
78  radioModule->subscribe(IRadio::transmissionStateChangedSignal, this);
79  radio = check_and_cast<IRadio *>(radioModule);
81 
82  // find queueModule
83  cGate *queueOut = gate("upperLayerIn")->getPathStartGate();
84  queueModule = dynamic_cast<IPassiveQueue *>(queueOut->getOwnerModule());
85  if (!queueModule)
86  throw cRuntimeError("Missing queueModule");
87 
89  }
90  else if (stage == INITSTAGE_LINK_LAYER) {
92  if (useAck)
93  ackTimeoutMsg = new cMessage("link-break");
96  }
97 }
int headerLength
Definition: IdealMac.h:47
virtual void getNextMsgFromHL()
Definition: IdealMac.cc:175
bool fullDuplex
Definition: IdealMac.h:51
double bitrate
Definition: IdealMac.h:48
IPassiveQueue * queueModule
Definition: IdealMac.h:56
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
virtual void initialize(int stage) override
Definition: MACProtocolBase.cc:31
int outStandingRequests
Definition: IdealMac.h:58
IRadio::TransmissionState transmissionState
Definition: IdealMac.h:55
bool promiscuous
Definition: IdealMac.h:49
Local initializations.
Definition: InitStages.h:35
Initialization of link-layer protocols.
Definition: InitStages.h:59
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:109
cMessage * ackTimeoutMsg
Definition: IdealMac.h:61
simtime_t ackTimeout
Definition: IdealMac.h:60
virtual void registerInterface()
Definition: MACProtocolBase.cc:42
The radio is prepared for simultaneous frame reception and transmission, power consumption is low whe...
Definition: IRadio.h:123
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
The transmission state is undefined or meaningless.
Definition: IRadio.h:172
bool useAck
Definition: IdealMac.h:52
IRadio * radio
Definition: IdealMac.h:54
virtual void initializeMACAddress()
Definition: IdealMac.cc:99
void inet::IdealMac::initializeMACAddress ( )
protectedvirtual

Referenced by initialize().

100 {
101  const char *addrstr = par("address");
102 
103  if (!strcmp(addrstr, "auto")) {
104  // assign automatic address
106 
107  // change module parameter from "auto" to concrete address
108  par("address").setStringValue(address.str().c_str());
109  }
110  else {
111  address.setAddress(addrstr);
112  }
113 }
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
MACAddress address
Definition: IdealMac.h:50
virtual int inet::IdealMac::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::OperationalBase.

96 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::IdealMac::receiveSignal ( cComponent *  src,
simsignal_t  id,
long  value,
cObject *  details 
)
overrideprotectedvirtual
138 {
139  Enter_Method_Silent();
140  if (signalID == IRadio::transmissionStateChangedSignal) {
141  IRadio::TransmissionState newRadioTransmissionState = (IRadio::TransmissionState)value;
144  if (!lastSentPk)
146  }
147  transmissionState = newRadioTransmissionState;
148  }
149 }
cPacket * lastSentPk
Definition: IdealMac.h:59
virtual void getNextMsgFromHL()
Definition: IdealMac.cc:175
bool fullDuplex
Definition: IdealMac.h:51
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
IRadio::TransmissionState transmissionState
Definition: IdealMac.h:55
The radio medium is busy, the radio is currently transmitting a signal.
Definition: IRadio.h:183
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:109
The radio is prepared for simultaneous frame reception and transmission, power consumption is low whe...
Definition: IRadio.h:123
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
IRadio * radio
Definition: IdealMac.h:54
void inet::IdealMac::startTransmitting ( cPacket *  msg)
protectedvirtual

Referenced by handleUpperPacket().

152 {
153  // if there's any control info, remove it; then encapsulate the packet
154  if (lastSentPk)
155  throw cRuntimeError("Model error: unacked send");
156  Ieee802Ctrl *ctrl = check_and_cast<Ieee802Ctrl *>(msg->getControlInfo());
157  MACAddress dest = ctrl->getDestinationAddress();
158  IdealMacFrame *frame = encapsulate(msg);
159 
160  if (!dest.isBroadcast() && !dest.isMulticast() && !dest.isUnspecified()) { // unicast
161  if (useAck) {
162  lastSentPk = frame->dup();
163  scheduleAt(simTime() + ackTimeout, ackTimeoutMsg);
164  }
165  }
166  else
167  frame->setSrcModuleId(-1);
168 
169  // send
170  EV << "Starting transmission of " << frame << endl;
172  sendDown(frame);
173 }
cPacket * lastSentPk
Definition: IdealMac.h:59
bool fullDuplex
Definition: IdealMac.h:51
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:116
virtual IdealMacFrame * encapsulate(cPacket *msg)
Definition: IdealMac.cc:255
cMessage * ackTimeoutMsg
Definition: IdealMac.h:61
simtime_t ackTimeout
Definition: IdealMac.h:60
The radio is prepared for simultaneous frame reception and transmission, power consumption is low whe...
Definition: IRadio.h:123
virtual void sendDown(cMessage *message)
Definition: MACProtocolBase.cc:59
bool useAck
Definition: IdealMac.h:52
IRadio * radio
Definition: IdealMac.h:54

Member Data Documentation

simtime_t inet::IdealMac::ackTimeout
protected

Referenced by initialize(), and startTransmitting().

cMessage* inet::IdealMac::ackTimeoutMsg = nullptr
protected
MACAddress inet::IdealMac::address
protected
double inet::IdealMac::bitrate = 0
protected

Referenced by createInterfaceEntry(), and initialize().

simsignal_t inet::IdealMac::dropPkNotForUsSignal = registerSignal("dropPkNotForUs")
staticprotected

Referenced by dropFrameNotForUs().

bool inet::IdealMac::fullDuplex = false
protected
int inet::IdealMac::headerLength = 0
protected

Referenced by encapsulate(), and initialize().

cPacket* inet::IdealMac::lastSentPk = nullptr
protected
int inet::IdealMac::outStandingRequests = 0
protected
bool inet::IdealMac::promiscuous = false
protected

Referenced by dropFrameNotForUs(), and initialize().

IPassiveQueue* inet::IdealMac::queueModule = nullptr
protected
IRadio* inet::IdealMac::radio = nullptr
protected
IRadio::TransmissionState inet::IdealMac::transmissionState = IRadio::TRANSMISSION_STATE_UNDEFINED
protected

Referenced by initialize(), and receiveSignal().

bool inet::IdealMac::useAck = true
protected

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