INET Framework for OMNeT++/OMNEST
inet::physicallayer::Radio Class Reference

This class is the default implementation of the IRadio interface. More...

#include <Radio.h>

Inheritance diagram for inet::physicallayer::Radio:
inet::PhysicalLayerBase inet::physicallayer::IRadio inet::OperationalBase inet::IPhysicalLayer inet::IPhysicalLayer inet::physicallayer::IPrintableObject inet::ILifecycle inet::physicallayer::NarrowbandRadioBase inet::physicallayer::FlatRadioBase inet::physicallayer::APSKRadio inet::physicallayer::Ieee80211Radio

Public Member Functions

 Radio ()
 
virtual ~Radio ()
 
virtual int getId () const override
 Returns an identifier for this radio which is globally unique for the whole lifetime of the simulation among all radios. More...
 
virtual std::ostream & printToStream (std::ostream &stream, int level) const override
 Prints this object to the provided output stream. More...
 
virtual const IAntennagetAntenna () const override
 Returns the antenna used by the transceiver of this radio. More...
 
virtual const ITransmittergetTransmitter () const override
 Returns the transmitter part of this radio. More...
 
virtual const IReceivergetReceiver () const override
 Returns the receiver part of this radio. More...
 
virtual const IRadioMediumgetMedium () const override
 Returns the radio medium where this radio is transmitting and receiving radio signals. More...
 
virtual const cGate * getRadioGate () const override
 Returns the gate of the radio that receives incoming radio frames. More...
 
virtual RadioMode getRadioMode () const override
 Returns the current radio mode, This is the same mode as the one emitted with the last radioModeChangedSignal. More...
 
virtual void setRadioMode (RadioMode newRadioMode) override
 Changes the current radio mode. More...
 
virtual ReceptionState getReceptionState () const override
 Returns the current radio reception state. More...
 
virtual TransmissionState getTransmissionState () const override
 Returns the current radio transmission state. More...
 
virtual const ITransmissiongetTransmissionInProgress () const override
 Returns the ongoing transmission that the transmitter is currently transmitting or nullptr. More...
 
virtual const ITransmissiongetReceptionInProgress () const override
 Returns the ongoing reception that the receiver is currently receiving or nullptr. More...
 
virtual IRadioSignal::SignalPart getTransmittedSignalPart () const override
 Returns the signal part of the ongoing transmission that the transmitter is currently transmitting or -1 if no transmission is in progress. More...
 
virtual IRadioSignal::SignalPart getReceivedSignalPart () const override
 Returns the signal part of the ongoing reception that the receiver is currently receiving or -1 if no reception is in progress. More...
 
- Public Member Functions inherited from inet::PhysicalLayerBase
 PhysicalLayerBase ()
 
- Public Member Functions inherited from inet::OperationalBase
 OperationalBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- Public Member Functions inherited from inet::IPhysicalLayer
virtual ~IPhysicalLayer ()
 
- Public Member Functions inherited from inet::physicallayer::IPrintableObject
virtual ~IPrintableObject ()
 
virtual std::string getInfoStringRepresentation () const
 
virtual std::string getDetailStringRepresentation () const
 
virtual std::string getDebugStringRepresentation () const
 
virtual std::string getTraceStringRepresentation () const
 
virtual std::string getCompleteStringRepresentation () const
 

Static Public Attributes

static simsignal_t minSNIRSignal = cComponent::registerSignal("minSNIR")
 
static simsignal_t packetErrorRateSignal = cComponent::registerSignal("packetErrorRate")
 
static simsignal_t bitErrorRateSignal = cComponent::registerSignal("bitErrorRate")
 
static simsignal_t symbolErrorRateSignal = cComponent::registerSignal("symbolErrorRate")
 
- Static Public Attributes inherited from inet::physicallayer::IRadio
static simsignal_t radioModeChangedSignal = cComponent::registerSignal("radioModeChanged")
 This signal is emitted every time the radio mode changes. More...
 
static simsignal_t listeningChangedSignal = cComponent::registerSignal("listeningChanged")
 This signal is emitted every time the radio listening changes. More...
 
static simsignal_t receptionStateChangedSignal = cComponent::registerSignal("receptionStateChanged")
 This signal is emitted every time the radio reception state changes. More...
 
static simsignal_t transmissionStateChangedSignal = cComponent::registerSignal("transmissionStateChanged")
 This signal is emitted every time the radio transmission state changes. More...
 
static simsignal_t receivedSignalPartChangedSignal = cComponent::registerSignal("receivedSignalPartChanged")
 This signal is emitted every time the received part changes. More...
 
static simsignal_t transmittedSignalPartChangedSignal = cComponent::registerSignal("transmittedSignalPartChanged")
 This signal is emitted every time the transmitted part changes. More...
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleMessageWhenDown (cMessage *message) override
 
virtual void handleMessageWhenUp (cMessage *message) override
 
virtual void handleSelfMessage (cMessage *message)
 
virtual void handleSwitchTimer (cMessage *message)
 
virtual void handleTransmissionTimer (cMessage *message)
 
virtual void handleReceptionTimer (cMessage *message)
 
virtual void handleUpperCommand (cMessage *command)
 
virtual void handleLowerCommand (cMessage *command)
 
virtual void handleUpperPacket (cPacket *packet)
 
virtual void handleLowerPacket (RadioFrame *packet)
 
virtual bool handleNodeStart (IDoneCallback *doneCallback) override
 
virtual bool handleNodeShutdown (IDoneCallback *doneCallback) override
 
virtual void handleNodeCrash () override
 
virtual void startTransmission (cPacket *macFrame, IRadioSignal::SignalPart part)
 
virtual void continueTransmission ()
 
virtual void endTransmission ()
 
virtual void abortTransmission ()
 
virtual RadioFramecreateRadioFrame (cPacket *packet) const
 
virtual void startReception (cMessage *timer, IRadioSignal::SignalPart part)
 
virtual void continueReception (cMessage *timer)
 
virtual void endReception (cMessage *timer)
 
virtual void abortReception (cMessage *timer)
 
virtual void captureReception (cMessage *timer)
 
virtual void sendUp (cPacket *macFrame)
 
virtual cMessage * createReceptionTimer (RadioFrame *radioFrame) const
 
virtual bool isReceptionTimer (const cMessage *message) const
 
virtual bool isReceiverMode (IRadio::RadioMode radioMode) const
 
virtual bool isTransmitterMode (IRadio::RadioMode radioMode) const
 
virtual bool isListeningPossible () const
 
virtual void updateTransceiverState ()
 
virtual void updateTransceiverPart ()
 
- Protected Member Functions inherited from inet::PhysicalLayerBase
virtual bool isInitializeStage (int stage) override
 
virtual bool isNodeStartStage (int stage) override
 
virtual bool isNodeShutdownStage (int stage) override
 
- Protected Member Functions inherited from inet::OperationalBase
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void setOperational (bool isOperational)
 

Protected Attributes

const int id = nextId++
 An identifier which is globally unique for the whole lifetime of the simulation among all radios. More...
 
Parameters that determine the behavior of the radio.
const IAntennaantenna = nullptr
 The radio antenna model is never nullptr. More...
 
const ITransmittertransmitter = nullptr
 The transmitter model is never nullptr. More...
 
const IReceiverreceiver = nullptr
 The receiver model is never nullptr. More...
 
IRadioMediummedium = nullptr
 The radio medium model is never nullptr. More...
 
int mediumModuleId = -1
 The module id of the medim model. More...
 
simtime_t switchingTimes [RADIO_MODE_SWITCHING][RADIO_MODE_SWITCHING]
 Simulation time required to switch from one radio mode to another. More...
 
bool separateTransmissionParts = false
 Determines whether the transmission of the preamble, header and data part are simulated separately or not. More...
 
bool separateReceptionParts = false
 Determines whether the reception of the preamble, header and data part are simulated separately or not. More...
 
cGate * upperLayerOut = nullptr
 Gates. More...
 
cGate * upperLayerIn = nullptr
 
cGate * radioIn = nullptr
 
RadioMode radioMode = RADIO_MODE_OFF
 State. More...
 
RadioMode nextRadioMode = RADIO_MODE_OFF
 The radio is switching to this radio radio mode if a switch is in progress, otherwise this is the same as the current radio mode. More...
 
RadioMode previousRadioMode = RADIO_MODE_OFF
 The radio is switching from this radio mode to another if a switch is in progress, otherwise this is the same as the current radio mode. More...
 
ReceptionState receptionState = RECEPTION_STATE_UNDEFINED
 The current reception state. More...
 
TransmissionState transmissionState = TRANSMISSION_STATE_UNDEFINED
 The current transmission state. More...
 
IRadioSignal::SignalPart receivedSignalPart = IRadioSignal::SIGNAL_PART_NONE
 The current received signal part. More...
 
IRadioSignal::SignalPart transmittedSignalPart = IRadioSignal::SIGNAL_PART_NONE
 The current transmitted signal part. More...
 
Timer
cMessage * transmissionTimer = nullptr
 The timer that is scheduled to the end of the current transmission. More...
 
cMessage * receptionTimer = nullptr
 The timer that is scheduled to the end of the current reception. More...
 
cMessage * switchTimer = nullptr
 The timer that is scheduled to the end of the radio mode switch. More...
 
- Protected Attributes inherited from inet::OperationalBase
bool isOperational
 
simtime_t lastChange
 

Private Member Functions

void parseRadioModeSwitchingTimes ()
 
void startRadioModeSwitch (RadioMode newRadioMode, simtime_t switchingTime)
 
void completeRadioModeSwitch (RadioMode newRadioMode)
 

Additional Inherited Members

- Public Types inherited from inet::physicallayer::IRadio
enum  RadioMode {
  RADIO_MODE_OFF, RADIO_MODE_SLEEP, RADIO_MODE_RECEIVER, RADIO_MODE_TRANSMITTER,
  RADIO_MODE_TRANSCEIVER, RADIO_MODE_SWITCHING
}
 This enumeration specifies the requested operational mode of the radio. More...
 
enum  ReceptionState { RECEPTION_STATE_UNDEFINED, RECEPTION_STATE_IDLE, RECEPTION_STATE_BUSY, RECEPTION_STATE_RECEIVING }
 This enumeration specifies the reception state of the radio. More...
 
enum  TransmissionState { TRANSMISSION_STATE_UNDEFINED, TRANSMISSION_STATE_IDLE, TRANSMISSION_STATE_TRANSMITTING }
 This enumeration specifies the transmission state of the radio. More...
 
- Public Types inherited from inet::physicallayer::IPrintableObject
enum  PrintLevel {
  PRINT_LEVEL_TRACE, PRINT_LEVEL_DEBUG, PRINT_LEVEL_DETAIL, PRINT_LEVEL_INFO,
  PRINT_LEVEL_COMPLETE = INT_MIN
}
 
- Static Public Member Functions inherited from inet::physicallayer::IRadio
static const char * getRadioModeName (RadioMode radioMode)
 Returns the name of the provided radio mode. More...
 
static const char * getRadioReceptionStateName (ReceptionState receptionState)
 Returns the name of the provided radio reception state. More...
 
static const char * getRadioTransmissionStateName (TransmissionState transmissionState)
 Returns the name of the provided radio transmission state. More...
 
- Static Protected Attributes inherited from inet::physicallayer::IRadio
static int nextId = 0
 
static cEnum * radioModeEnum = nullptr
 The enumeration registered for radio mode. More...
 
static cEnum * receptionStateEnum = nullptr
 The enumeration registered for radio reception state. More...
 
static cEnum * transmissionStateEnum = nullptr
 The enumeration registered for radio transmission state. More...
 

Detailed Description

This class is the default implementation of the IRadio interface.

The transmission process starts when the radio module receives a packet from the higher layer. The received packet can have a TransmissionRequest attached as a control info object. The radio must be in transmitter or transceiver mode before receiving a packet, otherwise it throws an exception. The radio changes its transmitter state to transmitting, and emits a transmitter state changed signal. Finally, it schedules a timer to the end of the transmission.

The transmission process ends when the above timer expires. The radio changes its transmitter state back to idle, and emits a transmitter state changed signal.

The reception process starts when the radio module receives a radio frame. The radio must be in receiver or transceiver mode before the message arrives, otherwise it just ignores the message. The radio changes its receiver state to the appropriate value, and emits a receiver state changed signal. Finally, it schedules a timer to the end of the reception.

The reception process ends when one of the above timer expires. If the timer corresponds to an attempted reception, then the radio determines the reception decision. Independently of whether the reception is successful or not, the encapsulated packet is sent up to the higher layer. The radio also attaches a ReceptionIndication as a control info object. Finally, the radio changes its receiver state to the appropriate value, and emits a receiver state changed signal.

Constructor & Destructor Documentation

inet::physicallayer::Radio::Radio ( )
inline
221 { }
inet::physicallayer::Radio::~Radio ( )
virtual
40 {
41  // NOTE: can't use the medium module here, because it may have been already deleted
42  cModule *medium = getSimulation()->getModule(mediumModuleId);
43  if (medium != nullptr)
44  check_and_cast<IRadioMedium *>(medium)->removeRadio(this);
45  cancelAndDelete(transmissionTimer);
46  cancelAndDelete(switchTimer);
47 }
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
cMessage * switchTimer
The timer that is scheduled to the end of the radio mode switch.
Definition: Radio.h:171
int mediumModuleId
The module id of the medim model.
Definition: Radio.h:97
IRadioMedium * medium
The radio medium model is never nullptr.
Definition: Radio.h:93

Member Function Documentation

void inet::physicallayer::Radio::abortReception ( cMessage *  timer)
protectedvirtual

Referenced by completeRadioModeSwitch().

489 {
490  auto radioFrame = static_cast<RadioFrame *>(timer->getControlInfo());
491  auto part = (IRadioSignal::SignalPart)timer->getKind();
492  auto reception = radioFrame->getReception();
493  EV_INFO << "Reception aborted: for " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(part) << " as " << reception << endl;
494  if (timer == receptionTimer)
495  receptionTimer = nullptr;
498 }
static const char * getSignalPartName(SignalPart signalPart)
Returns the name of the provided signal part.
Definition: IRadioSignal.cc:33
virtual void updateTransceiverPart()
Definition: Radio.cc:587
SignalPart
This enumeration specifies a part of a radio signal.
Definition: IRadioSignal.h:36
virtual void updateTransceiverState()
Definition: Radio.cc:555
cMessage * receptionTimer
The timer that is scheduled to the end of the current reception.
Definition: Radio.h:167
void inet::physicallayer::Radio::abortTransmission ( )
protectedvirtual

Referenced by completeRadioModeSwitch(), handleNodeCrash(), and handleNodeShutdown().

395 {
396  auto part = (IRadioSignal::SignalPart)transmissionTimer->getKind();
397  auto radioFrame = static_cast<RadioFrame *>(transmissionTimer->getContextPointer());
398  auto transmission = radioFrame->getTransmission();
399  transmissionTimer->setContextPointer(nullptr);
400  EV_INFO << "Transmission aborted: " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(part) << " as " << transmission << endl;
401  EV_WARN << "Aborting ongoing transmissions is not supported" << endl;
402  cancelEvent(transmissionTimer);
405 }
static const char * getSignalPartName(SignalPart signalPart)
Returns the name of the provided signal part.
Definition: IRadioSignal.cc:33
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
virtual void updateTransceiverPart()
Definition: Radio.cc:587
SignalPart
This enumeration specifies a part of a radio signal.
Definition: IRadioSignal.h:36
virtual void updateTransceiverState()
Definition: Radio.cc:555
void inet::physicallayer::Radio::captureReception ( cMessage *  timer)
protectedvirtual
501 {
502  // TODO: this would be called when the receiver switches to a stronger signal while receiving a weaker one
503  throw cRuntimeError("Not yet implemented");
504 }
void inet::physicallayer::Radio::completeRadioModeSwitch ( RadioMode  newRadioMode)
private

Referenced by handleNodeCrash(), handleNodeShutdown(), handleNodeStart(), handleSwitchTimer(), and setRadioMode().

151 {
152  EV_INFO << "Radio mode changed from " << getRadioModeName(previousRadioMode) << " to " << getRadioModeName(newRadioMode) << endl;
153  if (!isReceiverMode(newRadioMode) && receptionTimer != nullptr)
155  if (!isTransmitterMode(newRadioMode) && transmissionTimer->isScheduled())
157  radioMode = previousRadioMode = nextRadioMode = newRadioMode;
158  emit(radioModeChangedSignal, newRadioMode);
161 }
virtual void abortTransmission()
Definition: Radio.cc:394
virtual bool isTransmitterMode(IRadio::RadioMode radioMode) const
Definition: Radio.cc:537
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
static const char * getRadioModeName(RadioMode radioMode)
Returns the name of the provided radio mode.
Definition: IRadio.cc:56
virtual bool isReceiverMode(IRadio::RadioMode radioMode) const
Definition: Radio.cc:532
virtual void updateTransceiverPart()
Definition: Radio.cc:587
virtual void abortReception(cMessage *timer)
Definition: Radio.cc:488
virtual void updateTransceiverState()
Definition: Radio.cc:555
RadioMode radioMode
State.
Definition: Radio.h:126
cMessage * receptionTimer
The timer that is scheduled to the end of the current reception.
Definition: Radio.h:167
RadioMode nextRadioMode
The radio is switching to this radio radio mode if a switch is in progress, otherwise this is the sam...
Definition: Radio.h:131
RadioMode previousRadioMode
The radio is switching from this radio mode to another if a switch is in progress, otherwise this is the same as the current radio mode.
Definition: Radio.h:136
static simsignal_t radioModeChangedSignal
This signal is emitted every time the radio mode changes.
Definition: IRadio.h:54
void inet::physicallayer::Radio::continueReception ( cMessage *  timer)
protectedvirtual

Referenced by handleReceptionTimer().

437 {
438  auto previousPart = (IRadioSignal::SignalPart)timer->getKind();
439  auto nextPart = (IRadioSignal::SignalPart)(previousPart + 1);
440  auto radioFrame = static_cast<RadioFrame *>(timer->getControlInfo());
441  auto arrival = radioFrame->getArrival();
442  auto reception = radioFrame->getReception();
443  if (timer == receptionTimer && isReceiverMode(radioMode) && arrival->getEndTime(previousPart) == simTime()) {
444  auto transmission = radioFrame->getTransmission();
445  bool isReceptionSuccessful = medium->isReceptionSuccessful(this, transmission, previousPart);
446  EV_INFO << "Reception ended: " << (isReceptionSuccessful ? "successfully" : "unsuccessfully") << " for " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(previousPart) << " as " << reception << endl;
447  if (!isReceptionSuccessful)
448  receptionTimer = nullptr;
449  auto isReceptionAttempted = medium->isReceptionAttempted(this, transmission, nextPart);
450  EV_INFO << "Reception started: " << (isReceptionAttempted ? "attempting" : "not attempting") << " " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(nextPart) << " as " << reception << endl;
451  if (!isReceptionAttempted)
452  receptionTimer = nullptr;
453  }
454  else {
455  EV_INFO << "Reception ended: ignoring " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(previousPart) << " as " << reception << endl;
456  EV_INFO << "Reception started: ignoring " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(nextPart) << " as " << reception << endl;
457  }
458  timer->setKind(nextPart);
459  scheduleAt(arrival->getEndTime(nextPart), timer);
462 }
static const char * getSignalPartName(SignalPart signalPart)
Returns the name of the provided signal part.
Definition: IRadioSignal.cc:33
virtual bool isReceptionSuccessful(const IRadio *receiver, const ITransmission *transmission, IRadioSignal::SignalPart part) const =0
Returns true when the reception is successful of the transmission part.
virtual bool isReceiverMode(IRadio::RadioMode radioMode) const
Definition: Radio.cc:532
virtual void updateTransceiverPart()
Definition: Radio.cc:587
SignalPart
This enumeration specifies a part of a radio signal.
Definition: IRadioSignal.h:36
virtual void updateTransceiverState()
Definition: Radio.cc:555
RadioMode radioMode
State.
Definition: Radio.h:126
cMessage * receptionTimer
The timer that is scheduled to the end of the current reception.
Definition: Radio.h:167
if(!(yy_init))
Definition: lexer.cc:1644
IRadioMedium * medium
The radio medium model is never nullptr.
Definition: Radio.h:93
void inet::physicallayer::Radio::continueTransmission ( )
protectedvirtual

Referenced by handleTransmissionTimer().

369 {
370  auto previousPart = (IRadioSignal::SignalPart)transmissionTimer->getKind();
371  auto nextPart = (IRadioSignal::SignalPart)(previousPart + 1);
372  auto radioFrame = static_cast<RadioFrame *>(transmissionTimer->getContextPointer());
373  auto transmission = radioFrame->getTransmission();
374  EV_INFO << "Transmission ended: " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(previousPart) << " as " << radioFrame->getTransmission() << endl;
375  transmissionTimer->setKind(nextPart);
376  scheduleAt(transmission->getEndTime(nextPart), transmissionTimer);
377  EV_INFO << "Transmission started: " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(nextPart) << " as " << transmission << endl;
380 }
static const char * getSignalPartName(SignalPart signalPart)
Returns the name of the provided signal part.
Definition: IRadioSignal.cc:33
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
virtual void updateTransceiverPart()
Definition: Radio.cc:587
SignalPart
This enumeration specifies a part of a radio signal.
Definition: IRadioSignal.h:36
virtual void updateTransceiverState()
Definition: Radio.cc:555
RadioFrame * inet::physicallayer::Radio::createRadioFrame ( cPacket *  packet) const
protectedvirtual

Referenced by startTransmission().

408 {
409  RadioFrame *radioFrame = check_and_cast<RadioFrame *>(medium->transmitPacket(this, packet));
410  ASSERT(radioFrame->getDuration() != 0);
411  return radioFrame;
412 }
virtual IRadioFrame * transmitPacket(const IRadio *transmitter, cPacket *macFrame)=0
Returns a new radio frame containing the radio signal transmission that represents the provided MAC f...
IRadioMedium * medium
The radio medium model is never nullptr.
Definition: Radio.h:93
cMessage * inet::physicallayer::Radio::createReceptionTimer ( RadioFrame radioFrame) const
protectedvirtual

Referenced by handleLowerPacket().

521 {
522  cMessage *timer = new cMessage("receptionTimer");
523  timer->setControlInfo(radioFrame);
524  return timer;
525 }
void inet::physicallayer::Radio::endReception ( cMessage *  timer)
protectedvirtual

Referenced by handleReceptionTimer().

465 {
466  auto part = (IRadioSignal::SignalPart)timer->getKind();
467  auto radioFrame = static_cast<RadioFrame *>(timer->getControlInfo());
468  auto arrival = radioFrame->getArrival();
469  auto reception = radioFrame->getReception();
470  if (timer == receptionTimer && isReceiverMode(radioMode) && arrival->getEndTime() == simTime()) {
471  auto transmission = radioFrame->getTransmission();
472 // TODO: this would draw twice from the random number generator in isReceptionSuccessful: auto isReceptionSuccessful = medium->isReceptionSuccessful(this, transmission, part);
473  auto isReceptionSuccessful = medium->getReceptionDecision(this, radioFrame->getListening(), transmission, part)->isReceptionSuccessful();
474  EV_INFO << "Reception ended: " << (isReceptionSuccessful ? "successfully" : "unsuccessfully") << " for " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(part) << " as " << reception << endl;
475  auto macFrame = medium->receivePacket(this, radioFrame);
476  emit(LayeredProtocolBase::packetSentToUpperSignal, macFrame);
477  sendUp(macFrame);
478  receptionTimer = nullptr;
479  }
480  else
481  EV_INFO << "Reception ended: ignoring " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(part) << " as " << reception << endl;
484  check_and_cast<RadioMedium *>(medium)->emit(IRadioMedium::receptionEndedSignal, check_and_cast<const cObject *>(reception));
485  delete timer;
486 }
virtual void sendUp(cPacket *macFrame)
Definition: Radio.cc:506
virtual const IReceptionDecision * getReceptionDecision(const IRadio *receiver, const IListening *listening, const ITransmission *transmission, IRadioSignal::SignalPart part) const =0
Returns the reception decision for the transmission part that specifies whether the reception is poss...
virtual bool isReceiverMode(IRadio::RadioMode radioMode) const
Definition: Radio.cc:532
virtual void updateTransceiverPart()
Definition: Radio.cc:587
SignalPart
This enumeration specifies a part of a radio signal.
Definition: IRadioSignal.h:36
virtual void updateTransceiverState()
Definition: Radio.cc:555
RadioMode radioMode
State.
Definition: Radio.h:126
cMessage * receptionTimer
The timer that is scheduled to the end of the current reception.
Definition: Radio.h:167
IRadioMedium * medium
The radio medium model is never nullptr.
Definition: Radio.h:93
void inet::physicallayer::Radio::endTransmission ( )
protectedvirtual

Referenced by handleTransmissionTimer().

383 {
384  auto part = (IRadioSignal::SignalPart)transmissionTimer->getKind();
385  auto radioFrame = static_cast<RadioFrame *>(transmissionTimer->getContextPointer());
386  auto transmission = radioFrame->getTransmission();
387  transmissionTimer->setContextPointer(nullptr);
388  EV_INFO << "Transmission ended: " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(part) << " as " << transmission << endl;
391  check_and_cast<RadioMedium *>(medium)->emit(IRadioMedium::transmissionEndedSignal, check_and_cast<const cObject *>(transmission));
392 }
static const char * getSignalPartName(SignalPart signalPart)
Returns the name of the provided signal part.
Definition: IRadioSignal.cc:33
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
virtual void updateTransceiverPart()
Definition: Radio.cc:587
SignalPart
This enumeration specifies a part of a radio signal.
Definition: IRadioSignal.h:36
virtual void updateTransceiverState()
Definition: Radio.cc:555
static simsignal_t transmissionEndedSignal
Definition: IRadioMedium.h:61
IRadioMedium * medium
The radio medium model is never nullptr.
Definition: Radio.h:93
virtual const IAntenna* inet::physicallayer::Radio::getAntenna ( ) const
inlineoverridevirtual

Returns the antenna used by the transceiver of this radio.

This function never returns nullptr.

Implements inet::physicallayer::IRadio.

228 { return antenna; }
const IAntenna * antenna
The radio antenna model is never nullptr.
Definition: Radio.h:81
virtual int inet::physicallayer::Radio::getId ( ) const
inlineoverridevirtual

Returns an identifier for this radio which is globally unique for the whole lifetime of the simulation among all radios.

Implements inet::physicallayer::IRadio.

Referenced by initialize(), startTransmission(), and inet::physicallayer::CommunicationLog::writeTransmission().

224 { return id; }
const int id
An identifier which is globally unique for the whole lifetime of the simulation among all radios...
Definition: Radio.h:74
virtual const IRadioMedium* inet::physicallayer::Radio::getMedium ( ) const
inlineoverridevirtual

Returns the radio medium where this radio is transmitting and receiving radio signals.

This function never returns nullptr.

Implements inet::physicallayer::IRadio.

231 { return medium; }
IRadioMedium * medium
The radio medium model is never nullptr.
Definition: Radio.h:93
virtual const cGate* inet::physicallayer::Radio::getRadioGate ( ) const
inlineoverridevirtual

Returns the gate of the radio that receives incoming radio frames.

Implements inet::physicallayer::IRadio.

Referenced by inet::physicallayer::RadioMedium::receiveSignal().

233 { return radioIn; }
cGate * radioIn
Definition: Radio.h:118
virtual RadioMode inet::physicallayer::Radio::getRadioMode ( ) const
inlineoverridevirtual

Returns the current radio mode, This is the same mode as the one emitted with the last radioModeChangedSignal.

Implements inet::physicallayer::IRadio.

Referenced by inet::physicallayer::RadioMedium::isPotentialReceiver().

235 { return radioMode; }
RadioMode radioMode
State.
Definition: Radio.h:126
IRadioSignal::SignalPart inet::physicallayer::Radio::getReceivedSignalPart ( ) const
overridevirtual

Returns the signal part of the ongoing reception that the receiver is currently receiving or -1 if no reception is in progress.

This is the same part as the one emitted with the last receivedPartChangedSignal.

Implements inet::physicallayer::IRadio.

185 {
186  return receivedSignalPart;
187 }
IRadioSignal::SignalPart receivedSignalPart
The current received signal part.
Definition: Radio.h:148
virtual const IReceiver* inet::physicallayer::Radio::getReceiver ( ) const
inlineoverridevirtual

Returns the receiver part of this radio.

This function never returns nullptr.

Implements inet::physicallayer::IRadio.

Referenced by inet::physicallayer::RadioMedium::receiveSignal().

230 { return receiver; }
const IReceiver * receiver
The receiver model is never nullptr.
Definition: Radio.h:89
const ITransmission * inet::physicallayer::Radio::getReceptionInProgress ( ) const
overridevirtual

Returns the ongoing reception that the receiver is currently receiving or nullptr.

Implements inet::physicallayer::IRadio.

172 {
173  if (receptionTimer == nullptr)
174  return nullptr;
175  else
176  return static_cast<RadioFrame *>(receptionTimer->getControlInfo())->getTransmission();
177 }
cMessage * receptionTimer
The timer that is scheduled to the end of the current reception.
Definition: Radio.h:167
virtual ReceptionState inet::physicallayer::Radio::getReceptionState ( ) const
inlineoverridevirtual

Returns the current radio reception state.

This is the same state as the one emitted with the last receptionStateChangedSignal.

Implements inet::physicallayer::IRadio.

238 { return receptionState; }
ReceptionState receptionState
The current reception state.
Definition: Radio.h:140
const ITransmission * inet::physicallayer::Radio::getTransmissionInProgress ( ) const
overridevirtual

Returns the ongoing transmission that the transmitter is currently transmitting or nullptr.

Implements inet::physicallayer::IRadio.

164 {
165  if (!transmissionTimer->isScheduled())
166  return nullptr;
167  else
168  return static_cast<RadioFrame *>(transmissionTimer->getContextPointer())->getTransmission();
169 }
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
virtual TransmissionState inet::physicallayer::Radio::getTransmissionState ( ) const
inlineoverridevirtual

Returns the current radio transmission state.

This is the same state as the one emitted with the last transmissionStateChangedSignal.

Implements inet::physicallayer::IRadio.

239 { return transmissionState; }
TransmissionState transmissionState
The current transmission state.
Definition: Radio.h:144
IRadioSignal::SignalPart inet::physicallayer::Radio::getTransmittedSignalPart ( ) const
overridevirtual

Returns the signal part of the ongoing transmission that the transmitter is currently transmitting or -1 if no transmission is in progress.

This is the same part as the one emitted with the last transmittedPartChangedSignal.

Implements inet::physicallayer::IRadio.

180 {
181  return transmittedSignalPart;
182 }
IRadioSignal::SignalPart transmittedSignalPart
The current transmitted signal part.
Definition: Radio.h:152
virtual const ITransmitter* inet::physicallayer::Radio::getTransmitter ( ) const
inlineoverridevirtual

Returns the transmitter part of this radio.

This function never returns nullptr.

Implements inet::physicallayer::IRadio.

229 { return transmitter; }
const ITransmitter * transmitter
The transmitter model is never nullptr.
Definition: Radio.h:85
void inet::physicallayer::Radio::handleLowerCommand ( cMessage *  command)
protectedvirtual

Referenced by handleMessageWhenUp().

278 {
279  throw cRuntimeError("Unsupported command");
280 }
void inet::physicallayer::Radio::handleLowerPacket ( RadioFrame packet)
protectedvirtual

Referenced by handleMessageWhenUp().

300 {
301  auto receptionTimer = createReceptionTimer(radioFrame);
304  else
306 }
virtual void startReception(cMessage *timer, IRadioSignal::SignalPart part)
Definition: Radio.cc:414
virtual cMessage * createReceptionTimer(RadioFrame *radioFrame) const
Definition: Radio.cc:520
bool separateReceptionParts
Determines whether the reception of the preamble, header and data part are simulated separately or no...
Definition: Radio.h:111
cMessage * receptionTimer
The timer that is scheduled to the end of the current reception.
Definition: Radio.h:167
void inet::physicallayer::Radio::handleMessageWhenDown ( cMessage *  message)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

190 {
191  if (message->getArrivalGate() == radioIn || isReceptionTimer(message))
192  delete message;
193  else
195 }
cGate * radioIn
Definition: Radio.h:118
virtual bool isReceptionTimer(const cMessage *message) const
Definition: Radio.cc:527
virtual void handleMessageWhenDown(cMessage *msg)
Definition: OperationalBase.cc:50
void inet::physicallayer::Radio::handleMessageWhenUp ( cMessage *  message)
overrideprotectedvirtual

Implements inet::OperationalBase.

198 {
199  if (message->isSelfMessage())
200  handleSelfMessage(message);
201  else if (message->getArrivalGate() == upperLayerIn) {
202  if (!message->isPacket()) {
203  handleUpperCommand(message);
204  delete message;
205  }
206  else
207  handleUpperPacket(check_and_cast<cPacket *>(message));
208  }
209  else if (message->getArrivalGate() == radioIn) {
210  if (!message->isPacket()) {
211  handleLowerCommand(message);
212  delete message;
213  }
214  else
215  handleLowerPacket(check_and_cast<RadioFrame *>(message));
216  }
217  else
218  throw cRuntimeError("Unknown arrival gate '%s'.", message->getArrivalGate()->getFullName());
219 }
cGate * upperLayerIn
Definition: Radio.h:117
virtual void handleLowerCommand(cMessage *command)
Definition: Radio.cc:277
virtual void handleLowerPacket(RadioFrame *packet)
Definition: Radio.cc:299
virtual void handleUpperPacket(cPacket *packet)
Definition: Radio.cc:282
cGate * radioIn
Definition: Radio.h:118
virtual void handleUpperCommand(cMessage *command)
Definition: Radio.cc:266
virtual void handleSelfMessage(cMessage *message)
Definition: Radio.cc:221
void inet::physicallayer::Radio::handleNodeCrash ( )
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

326 {
327  cancelEvent(switchTimer);
328  if (transmissionTimer->isScheduled())
332 }
virtual void abortTransmission()
Definition: Radio.cc:394
virtual void handleNodeCrash()
Definition: OperationalBase.cc:97
void completeRadioModeSwitch(RadioMode newRadioMode)
Definition: Radio.cc:150
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
cMessage * switchTimer
The timer that is scheduled to the end of the radio mode switch.
Definition: Radio.h:171
The radio is turned off, frame reception or transmission is not possible, power consumption is zero...
Definition: IRadio.h:96
bool inet::physicallayer::Radio::handleNodeShutdown ( IDoneCallback doneCallback)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

316 {
317  // NOTE: we ignore radio mode switching and ongoing transmission during shutdown
318  cancelEvent(switchTimer);
319  if (transmissionTimer->isScheduled())
322  return PhysicalLayerBase::handleNodeShutdown(doneCallback);
323 }
virtual void abortTransmission()
Definition: Radio.cc:394
void completeRadioModeSwitch(RadioMode newRadioMode)
Definition: Radio.cc:150
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
virtual bool handleNodeShutdown(IDoneCallback *doneCallback)
Definition: OperationalBase.cc:92
cMessage * switchTimer
The timer that is scheduled to the end of the radio mode switch.
Definition: Radio.h:171
The radio is turned off, frame reception or transmission is not possible, power consumption is zero...
Definition: IRadio.h:96
bool inet::physicallayer::Radio::handleNodeStart ( IDoneCallback doneCallback)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

309 {
310  // NOTE: we ignore radio mode switching during start
312  return PhysicalLayerBase::handleNodeStart(doneCallback);
313 }
void completeRadioModeSwitch(RadioMode newRadioMode)
Definition: Radio.cc:150
virtual bool handleNodeStart(IDoneCallback *doneCallback)
Definition: OperationalBase.cc:87
The radio is turned off, frame reception or transmission is not possible, power consumption is zero...
Definition: IRadio.h:96
void inet::physicallayer::Radio::handleReceptionTimer ( cMessage *  message)
protectedvirtual

Referenced by handleSelfMessage().

253 {
254  if (message->getKind() == IRadioSignal::SIGNAL_PART_WHOLE)
255  endReception(message);
256  else if (message->getKind() == IRadioSignal::SIGNAL_PART_PREAMBLE)
257  continueReception(message);
258  else if (message->getKind() == IRadioSignal::SIGNAL_PART_HEADER)
259  continueReception(message);
260  else if (message->getKind() == IRadioSignal::SIGNAL_PART_DATA)
261  endReception(message);
262  else
263  throw cRuntimeError("Unknown self message");
264 }
virtual void continueReception(cMessage *timer)
Definition: Radio.cc:436
virtual void endReception(cMessage *timer)
Definition: Radio.cc:464
void inet::physicallayer::Radio::handleSelfMessage ( cMessage *  message)
protectedvirtual

Referenced by handleMessageWhenUp().

222 {
223  if (message == switchTimer)
224  handleSwitchTimer(message);
225  else if (message == transmissionTimer)
226  handleTransmissionTimer(message);
227  else if (isReceptionTimer(message))
228  handleReceptionTimer(message);
229  else
230  throw cRuntimeError("Unknown self message");
231 }
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
virtual void handleTransmissionTimer(cMessage *message)
Definition: Radio.cc:238
virtual void handleReceptionTimer(cMessage *message)
Definition: Radio.cc:252
cMessage * switchTimer
The timer that is scheduled to the end of the radio mode switch.
Definition: Radio.h:171
virtual void handleSwitchTimer(cMessage *message)
Definition: Radio.cc:233
virtual bool isReceptionTimer(const cMessage *message) const
Definition: Radio.cc:527
void inet::physicallayer::Radio::handleSwitchTimer ( cMessage *  message)
protectedvirtual

Referenced by handleSelfMessage().

234 {
236 }
void completeRadioModeSwitch(RadioMode newRadioMode)
Definition: Radio.cc:150
RadioMode nextRadioMode
The radio is switching to this radio radio mode if a switch is in progress, otherwise this is the sam...
Definition: Radio.h:131
void inet::physicallayer::Radio::handleTransmissionTimer ( cMessage *  message)
protectedvirtual

Referenced by handleSelfMessage().

239 {
240  if (message->getKind() == IRadioSignal::SIGNAL_PART_WHOLE)
241  endTransmission();
242  else if (message->getKind() == IRadioSignal::SIGNAL_PART_PREAMBLE)
244  else if (message->getKind() == IRadioSignal::SIGNAL_PART_HEADER)
246  else if (message->getKind() == IRadioSignal::SIGNAL_PART_DATA)
247  endTransmission();
248  else
249  throw cRuntimeError("Unknown self message");
250 }
virtual void endTransmission()
Definition: Radio.cc:382
virtual void continueTransmission()
Definition: Radio.cc:368
void inet::physicallayer::Radio::handleUpperCommand ( cMessage *  command)
protectedvirtual

Reimplemented in inet::physicallayer::Ieee80211Radio, inet::physicallayer::NarrowbandRadioBase, and inet::physicallayer::FlatRadioBase.

Referenced by handleMessageWhenUp(), and inet::physicallayer::NarrowbandRadioBase::handleUpperCommand().

267 {
268  if (message->getKind() == RADIO_C_CONFIGURE) {
269  ConfigureRadioCommand *configureCommand = check_and_cast<ConfigureRadioCommand *>(message->getControlInfo());
270  if (configureCommand->getRadioMode() != -1)
271  setRadioMode((RadioMode)configureCommand->getRadioMode());
272  }
273  else
274  throw cRuntimeError("Unsupported command");
275 }
RadioMode
This enumeration specifies the requested operational mode of the radio.
Definition: IRadio.h:91
virtual void setRadioMode(RadioMode newRadioMode) override
Changes the current radio mode.
Definition: Radio.cc:91
Definition: RadioControlInfo_m.h:56
void inet::physicallayer::Radio::handleUpperPacket ( cPacket *  packet)
protectedvirtual

Referenced by handleMessageWhenUp().

283 {
286  if (transmissionTimer->isScheduled())
287  throw cRuntimeError("Received frame from upper layer while already transmitting.");
290  else
292  }
293  else {
294  EV_ERROR << "Radio is not in transmitter or transceiver mode, dropping frame." << endl;
295  delete packet;
296  }
297 }
virtual bool isTransmitterMode(IRadio::RadioMode radioMode) const
Definition: Radio.cc:537
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
static simsignal_t packetReceivedFromUpperSignal
Definition: LayeredProtocolBase.h:29
RadioMode radioMode
State.
Definition: Radio.h:126
bool separateTransmissionParts
Determines whether the transmission of the preamble, header and data part are simulated separately or...
Definition: Radio.h:106
virtual void startTransmission(cPacket *macFrame, IRadioSignal::SignalPart part)
Definition: Radio.cc:334
void inet::physicallayer::Radio::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

Reimplemented in inet::physicallayer::Ieee80211Radio.

Referenced by inet::physicallayer::Ieee80211Radio::initialize().

50 {
52  if (stage == INITSTAGE_LOCAL) {
53  transmissionTimer = new cMessage("transmissionTimer");
54  antenna = check_and_cast<IAntenna *>(getSubmodule("antenna"));
55  transmitter = check_and_cast<ITransmitter *>(getSubmodule("transmitter"));
56  receiver = check_and_cast<IReceiver *>(getSubmodule("receiver"));
57  medium = getModuleFromPar<IRadioMedium>(par("radioMediumModule"), this);
58  mediumModuleId = check_and_cast<cModule *>(medium)->getId();
59  upperLayerIn = gate("upperLayerIn");
60  upperLayerOut = gate("upperLayerOut");
61  radioIn = gate("radioIn");
62  radioIn->setDeliverOnReceptionStart(true);
63  separateTransmissionParts = par("separateTransmissionParts");
64  separateReceptionParts = par("separateReceptionParts");
65  WATCH(radioMode);
66  WATCH(receptionState);
67  WATCH(transmissionState);
68  WATCH(receivedSignalPart);
69  WATCH(transmittedSignalPart);
70  }
71  else if (stage == INITSTAGE_PHYSICAL_LAYER) {
72  medium->addRadio(this);
73  switchTimer = new cMessage("switchTimer");
75  }
76  else if (stage == INITSTAGE_LAST) {
77  EV_INFO << "Initialized " << getCompleteStringRepresentation() << endl;
78  }
79 }
virtual int getId() const override
Returns an identifier for this radio which is globally unique for the whole lifetime of the simulatio...
Definition: Radio.h:224
const IAntenna * antenna
The radio antenna model is never nullptr.
Definition: Radio.h:81
cGate * upperLayerIn
Definition: Radio.h:117
Initialization of the physical layer of protocol stacks.
Definition: InitStages.h:53
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
const IReceiver * receiver
The receiver model is never nullptr.
Definition: Radio.h:89
virtual std::string getCompleteStringRepresentation() const
Definition: IPrintableObject.h:60
cMessage * switchTimer
The timer that is scheduled to the end of the radio mode switch.
Definition: Radio.h:171
Operations that no other initializations can depend on, e.g.
Definition: InitStages.h:111
cGate * radioIn
Definition: Radio.h:118
const ITransmitter * transmitter
The transmitter model is never nullptr.
Definition: Radio.h:85
ReceptionState receptionState
The current reception state.
Definition: Radio.h:140
Local initializations.
Definition: InitStages.h:35
cGate * upperLayerOut
Gates.
Definition: Radio.h:116
IRadioSignal::SignalPart transmittedSignalPart
The current transmitted signal part.
Definition: Radio.h:152
virtual void initialize(int stage) override
Definition: OperationalBase.cc:32
int mediumModuleId
The module id of the medim model.
Definition: Radio.h:97
bool separateReceptionParts
Determines whether the reception of the preamble, header and data part are simulated separately or no...
Definition: Radio.h:111
TransmissionState transmissionState
The current transmission state.
Definition: Radio.h:144
RadioMode radioMode
State.
Definition: Radio.h:126
IRadioSignal::SignalPart receivedSignalPart
The current received signal part.
Definition: Radio.h:148
bool separateTransmissionParts
Determines whether the transmission of the preamble, header and data part are simulated separately or...
Definition: Radio.h:106
void parseRadioModeSwitchingTimes()
Definition: Radio.cc:109
IRadioMedium * medium
The radio medium model is never nullptr.
Definition: Radio.h:93
bool inet::physicallayer::Radio::isListeningPossible ( ) const
protectedvirtual

Referenced by updateTransceiverState().

543 {
544  const simtime_t now = simTime();
545  const Coord position = antenna->getMobility()->getCurrentPosition();
546  // TODO: use 2 * minInterferenceTime for lookahead? or maybe simply use 0 duration listening?
547  const IListening *listening = receiver->createListening(this, now, now + 1E-12, position, position);
548  const IListeningDecision *listeningDecision = medium->listenOnMedium(this, listening);
549  bool isListeningPossible = listeningDecision->isListeningPossible();
550  delete listening;
551  delete listeningDecision;
552  return isListeningPossible;
553 }
const IAntenna * antenna
The radio antenna model is never nullptr.
Definition: Radio.h:81
const IReceiver * receiver
The receiver model is never nullptr.
Definition: Radio.h:89
virtual const IListening * createListening(const IRadio *radio, const simtime_t startTime, const simtime_t endTime, const Coord startPosition, const Coord endPosition) const =0
Returns a description of how the receiver is listening on the medium.
virtual const IListeningDecision * listenOnMedium(const IRadio *receiver, const IListening *listening) const =0
Returns the listening decision that describes what the receiver detects on the radio medium...
virtual bool isListeningPossible() const
Definition: Radio.cc:542
virtual IMobility * getMobility() const =0
Returns the mobility of this antenna that describes its position and orientation over time...
virtual Coord getCurrentPosition()=0
Returns the current position at the current simulation time.
IRadioMedium * medium
The radio medium model is never nullptr.
Definition: Radio.h:93
bool inet::physicallayer::Radio::isReceiverMode ( IRadio::RadioMode  radioMode) const
protectedvirtual

Referenced by completeRadioModeSwitch(), continueReception(), endReception(), and startReception().

533 {
535 }
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
RadioMode radioMode
State.
Definition: Radio.h:126
bool inet::physicallayer::Radio::isReceptionTimer ( const cMessage *  message) const
protectedvirtual

Referenced by handleMessageWhenDown(), and handleSelfMessage().

528 {
529  return !strcmp(message->getName(), "receptionTimer");
530 }
bool inet::physicallayer::Radio::isTransmitterMode ( IRadio::RadioMode  radioMode) const
protectedvirtual

Referenced by completeRadioModeSwitch(), and handleUpperPacket().

538 {
540 }
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:116
The radio is prepared for simultaneous frame reception and transmission, power consumption is low whe...
Definition: IRadio.h:123
RadioMode radioMode
State.
Definition: Radio.h:126
void inet::physicallayer::Radio::parseRadioModeSwitchingTimes ( )
private

Referenced by initialize().

110 {
111  const char *times = par("switchingTimes");
112 
113  char prefix[3];
114  unsigned int count = sscanf(times, "%s", prefix);
115 
116  if (count > 2)
117  throw cRuntimeError("Metric prefix should be no more than two characters long");
118 
119  double metric = 1;
120 
121  if (strcmp("s", prefix) == 0)
122  metric = 1;
123  else if (strcmp("ms", prefix) == 0)
124  metric = 0.001;
125  else if (strcmp("ns", prefix) == 0)
126  metric = 0.000000001;
127  else
128  throw cRuntimeError("Undefined or missed metric prefix for switchingTimes parameter");
129 
130  cStringTokenizer tok(times + count + 1);
131  unsigned int idx = 0;
132  while (tok.hasMoreTokens()) {
133  switchingTimes[idx / RADIO_MODE_SWITCHING][idx % RADIO_MODE_SWITCHING] = atof(tok.nextToken()) * metric;
134  idx++;
135  }
137  throw cRuntimeError("Check your switchingTimes parameter! Some parameters may be missed");
138 }
int count(const std::vector< T > &v, const T &a)
Definition: stlutils.h:58
simtime_t switchingTimes[RADIO_MODE_SWITCHING][RADIO_MODE_SWITCHING]
Simulation time required to switch from one radio mode to another.
Definition: Radio.h:101
The radio is switching from one mode to another, frame reception or transmission is not possible...
Definition: IRadio.h:129
std::ostream & inet::physicallayer::Radio::printToStream ( std::ostream &  stream,
int  level 
) const
overridevirtual

Prints this object to the provided output stream.

Function calls to operator<< with pointers or references either const or not are all forwarded to this function.

Reimplemented from inet::physicallayer::IPrintableObject.

82 {
83  stream << static_cast<const cSimpleModule *>(this);
84  if (level <= PRINT_LEVEL_TRACE)
85  stream << ", antenna = " << printObjectToString(antenna, level + 1)
86  << ", transmitter = " << printObjectToString(transmitter, level + 1)
87  << ", receiver = " << printObjectToString(receiver, level + 1);
88  return stream;
89 }
const IAntenna * antenna
The radio antenna model is never nullptr.
Definition: Radio.h:81
std::string printObjectToString(const IPrintableObject *object, int level)
Definition: IPrintableObject.h:73
const IReceiver * receiver
The receiver model is never nullptr.
Definition: Radio.h:89
const ITransmitter * transmitter
The transmitter model is never nullptr.
Definition: Radio.h:85
void inet::physicallayer::Radio::sendUp ( cPacket *  macFrame)
protectedvirtual

Referenced by endReception().

507 {
508  auto indication = check_and_cast<const ReceptionIndication *>(macFrame->getControlInfo());
509  emit(minSNIRSignal, indication->getMinSNIR());
510  if (!std::isnan(indication->getPacketErrorRate()))
511  emit(packetErrorRateSignal, indication->getPacketErrorRate());
512  if (!std::isnan(indication->getBitErrorRate()))
513  emit(bitErrorRateSignal, indication->getBitErrorRate());
514  if (!std::isnan(indication->getSymbolErrorRate()))
515  emit(symbolErrorRateSignal, indication->getSymbolErrorRate());
516  EV_INFO << "Sending up " << macFrame << endl;
517  send(macFrame, upperLayerOut);
518 }
cGate * upperLayerOut
Gates.
Definition: Radio.h:116
static simsignal_t symbolErrorRateSignal
Definition: Radio.h:67
static simsignal_t bitErrorRateSignal
Definition: Radio.h:66
static simsignal_t minSNIRSignal
Definition: Radio.h:64
static simsignal_t packetErrorRateSignal
Definition: Radio.h:65
void inet::physicallayer::Radio::setRadioMode ( RadioMode  radioMode)
overridevirtual

Changes the current radio mode.

The actual change may take zero or more time. The new radio mode will be emitted with a radioModeChangedSignal.

Implements inet::physicallayer::IRadio.

Referenced by handleUpperCommand().

92 {
93  Enter_Method_Silent();
94  if (newRadioMode < RADIO_MODE_OFF || newRadioMode > RADIO_MODE_SWITCHING)
95  throw cRuntimeError("Unknown radio mode: %d", newRadioMode);
96  else if (newRadioMode == RADIO_MODE_SWITCHING)
97  throw cRuntimeError("Cannot switch manually to RADIO_MODE_SWITCHING");
98  else if (radioMode == RADIO_MODE_SWITCHING || switchTimer->isScheduled())
99  throw cRuntimeError("Cannot switch to a new radio mode while another switch is in progress");
100  else if (newRadioMode != radioMode && newRadioMode != nextRadioMode) {
101  simtime_t switchingTime = switchingTimes[radioMode][newRadioMode];
102  if (switchingTime != 0)
103  startRadioModeSwitch(newRadioMode, switchingTime);
104  else
105  completeRadioModeSwitch(newRadioMode);
106  }
107 }
void completeRadioModeSwitch(RadioMode newRadioMode)
Definition: Radio.cc:150
cMessage * switchTimer
The timer that is scheduled to the end of the radio mode switch.
Definition: Radio.h:171
simtime_t switchingTimes[RADIO_MODE_SWITCHING][RADIO_MODE_SWITCHING]
Simulation time required to switch from one radio mode to another.
Definition: Radio.h:101
void startRadioModeSwitch(RadioMode newRadioMode, simtime_t switchingTime)
Definition: Radio.cc:140
RadioMode radioMode
State.
Definition: Radio.h:126
The radio is switching from one mode to another, frame reception or transmission is not possible...
Definition: IRadio.h:129
RadioMode nextRadioMode
The radio is switching to this radio radio mode if a switch is in progress, otherwise this is the sam...
Definition: Radio.h:131
void inet::physicallayer::Radio::startRadioModeSwitch ( RadioMode  newRadioMode,
simtime_t  switchingTime 
)
private

Referenced by setRadioMode().

141 {
142  EV_DETAIL << "Starting to change radio mode from " << getRadioModeName(radioMode) << " to " << getRadioModeName(newRadioMode) << endl;
145  nextRadioMode = newRadioMode;
147  scheduleAt(simTime() + switchingTime, switchTimer);
148 }
cMessage * switchTimer
The timer that is scheduled to the end of the radio mode switch.
Definition: Radio.h:171
static const char * getRadioModeName(RadioMode radioMode)
Returns the name of the provided radio mode.
Definition: IRadio.cc:56
RadioMode radioMode
State.
Definition: Radio.h:126
The radio is switching from one mode to another, frame reception or transmission is not possible...
Definition: IRadio.h:129
RadioMode nextRadioMode
The radio is switching to this radio radio mode if a switch is in progress, otherwise this is the sam...
Definition: Radio.h:131
RadioMode previousRadioMode
The radio is switching from this radio mode to another if a switch is in progress, otherwise this is the same as the current radio mode.
Definition: Radio.h:136
static simsignal_t radioModeChangedSignal
This signal is emitted every time the radio mode changes.
Definition: IRadio.h:54
void inet::physicallayer::Radio::startReception ( cMessage *  timer,
IRadioSignal::SignalPart  part 
)
protectedvirtual

Referenced by handleLowerPacket().

415 {
416  auto radioFrame = static_cast<RadioFrame *>(timer->getControlInfo());
417  auto arrival = radioFrame->getArrival();
418  auto reception = radioFrame->getReception();
419 // TODO: should be this, but it breaks fingerprints: if (receptionTimer == nullptr && isReceiverMode(radioMode) && arrival->getStartTime(part) == simTime()) {
420  if (isReceiverMode(radioMode) && arrival->getStartTime(part) == simTime()) {
421  auto transmission = radioFrame->getTransmission();
422  auto isReceptionAttempted = medium->isReceptionAttempted(this, transmission, part);
423  EV_INFO << "Reception started: " << (isReceptionAttempted ? "attempting" : "not attempting") << " " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(part) << " as " << reception << endl;
424  if (isReceptionAttempted)
425  receptionTimer = timer;
426  }
427  else
428  EV_INFO << "Reception started: ignoring " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(part) << " as " << reception << endl;
429  timer->setKind(part);
430  scheduleAt(arrival->getEndTime(part), timer);
433  check_and_cast<RadioMedium *>(medium)->emit(IRadioMedium::receptionStartedSignal, check_and_cast<const cObject *>(reception));
434 }
virtual bool isReceiverMode(IRadio::RadioMode radioMode) const
Definition: Radio.cc:532
virtual void updateTransceiverPart()
Definition: Radio.cc:587
virtual void updateTransceiverState()
Definition: Radio.cc:555
RadioMode radioMode
State.
Definition: Radio.h:126
cMessage * receptionTimer
The timer that is scheduled to the end of the current reception.
Definition: Radio.h:167
virtual bool isReceptionAttempted(const IRadio *receiver, const ITransmission *transmission, IRadioSignal::SignalPart part) const =0
Returns true when the reception is attempted of the transmission part.
if(!(yy_init))
Definition: lexer.cc:1644
IRadioMedium * medium
The radio medium model is never nullptr.
Definition: Radio.h:93
void inet::physicallayer::Radio::startTransmission ( cPacket *  macFrame,
IRadioSignal::SignalPart  part 
)
protectedvirtual

Referenced by handleUpperPacket().

335 {
336  auto radioFrame = createRadioFrame(macFrame);
337  auto transmission = radioFrame->getTransmission();
338  transmissionTimer->setKind(part);
339  transmissionTimer->setContextPointer(const_cast<RadioFrame *>(radioFrame));
340 
341 #ifdef NS3_VALIDATION
342  auto *df = dynamic_cast<inet::ieee80211::Ieee80211DataFrame *>(macFrame);
343  const char *ac = "NA";
344  if (df != nullptr && df->getType() == inet::ieee80211::ST_DATA_WITH_QOS) {
345  switch (df->getTid()) {
346  case 1: case 2: ac = "AC_BK"; break;
347  case 0: case 3: ac = "AC_BE"; break;
348  case 4: case 5: ac = "AC_VI"; break;
349  case 6: case 7: ac = "AC_VO"; break;
350  default: ac = "???"; break;
351  }
352  }
353  const char *lastSeq = strchr(macFrame->getName(), '-');
354  if (lastSeq == nullptr)
355  lastSeq = "-1";
356  else
357  lastSeq++;
358  std::cout << "TX: node = " << getId() << ", ac = " << ac << ", seq = " << lastSeq << ", start = " << simTime().inUnit(SIMTIME_PS) << ", duration = " << radioFrame->getDuration().inUnit(SIMTIME_PS) << std::endl;
359 #endif
360 
361  scheduleAt(transmission->getEndTime(part), transmissionTimer);
362  EV_INFO << "Transmission started: " << (IRadioFrame *)radioFrame << " " << IRadioSignal::getSignalPartName(part) << " as " << transmission << endl;
365  check_and_cast<RadioMedium *>(medium)->emit(IRadioMedium::transmissionStartedSignal, check_and_cast<const cObject *>(transmission));
366 }
virtual int getId() const override
Returns an identifier for this radio which is globally unique for the whole lifetime of the simulatio...
Definition: Radio.h:224
static const char * getSignalPartName(SignalPart signalPart)
Returns the name of the provided signal part.
Definition: IRadioSignal.cc:33
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
virtual RadioFrame * createRadioFrame(cPacket *packet) const
Definition: Radio.cc:407
Definition: Ieee80211Frame_m.h:117
static simsignal_t transmissionStartedSignal
Definition: IRadioMedium.h:60
Class generated from inet/linklayer/ieee80211/mac/Ieee80211Frame.msg:177 by nedtool.
Definition: Ieee80211Frame_m.h:509
virtual void updateTransceiverPart()
Definition: Radio.cc:587
virtual void updateTransceiverState()
Definition: Radio.cc:555
IRadioMedium * medium
The radio medium model is never nullptr.
Definition: Radio.h:93
void inet::physicallayer::Radio::updateTransceiverPart ( )
protectedvirtual

Referenced by abortReception(), abortTransmission(), completeRadioModeSwitch(), continueReception(), continueTransmission(), endReception(), endTransmission(), startReception(), and startTransmission().

588 {
590  if (receivedSignalPart != newReceivedPart) {
591  EV_INFO << "Changing radio received signal part from " << IRadioSignal::getSignalPartName(receivedSignalPart) << " to " << IRadioSignal::getSignalPartName(newReceivedPart) << "." << endl;
592  receivedSignalPart = newReceivedPart;
594  }
596  if (transmittedSignalPart != newTransmittedPart) {
597  EV_INFO << "Changing radio transmitted signal part from " << IRadioSignal::getSignalPartName(transmittedSignalPart) << " to " << IRadioSignal::getSignalPartName(newTransmittedPart) << "." << endl;
598  transmittedSignalPart = newTransmittedPart;
600  }
601 }
static const char * getSignalPartName(SignalPart signalPart)
Returns the name of the provided signal part.
Definition: IRadioSignal.cc:33
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
IRadioSignal::SignalPart transmittedSignalPart
The current transmitted signal part.
Definition: Radio.h:152
static simsignal_t receivedSignalPartChangedSignal
This signal is emitted every time the received part changes.
Definition: IRadio.h:78
static simsignal_t transmittedSignalPartChangedSignal
This signal is emitted every time the transmitted part changes.
Definition: IRadio.h:84
SignalPart
This enumeration specifies a part of a radio signal.
Definition: IRadioSignal.h:36
IRadioSignal::SignalPart receivedSignalPart
The current received signal part.
Definition: Radio.h:148
cMessage * receptionTimer
The timer that is scheduled to the end of the current reception.
Definition: Radio.h:167
void inet::physicallayer::Radio::updateTransceiverState ( )
protectedvirtual

Referenced by abortReception(), abortTransmission(), completeRadioModeSwitch(), continueReception(), continueTransmission(), endReception(), endTransmission(), startReception(), and startTransmission().

556 {
557  // reception state
558  ReceptionState newRadioReceptionState;
560  newRadioReceptionState = RECEPTION_STATE_UNDEFINED;
561  else if (receptionTimer && receptionTimer->isScheduled())
562  newRadioReceptionState = RECEPTION_STATE_RECEIVING;
563  else if (isListeningPossible())
564  newRadioReceptionState = RECEPTION_STATE_BUSY;
565  else
566  newRadioReceptionState = RECEPTION_STATE_IDLE;
567  if (receptionState != newRadioReceptionState) {
568  EV_INFO << "Changing radio reception state from " << getRadioReceptionStateName(receptionState) << " to " << getRadioReceptionStateName(newRadioReceptionState) << "." << endl;
569  receptionState = newRadioReceptionState;
570  emit(receptionStateChangedSignal, newRadioReceptionState);
571  }
572  // transmission state
573  TransmissionState newRadioTransmissionState;
575  newRadioTransmissionState = TRANSMISSION_STATE_UNDEFINED;
576  else if (transmissionTimer->isScheduled())
577  newRadioTransmissionState = TRANSMISSION_STATE_TRANSMITTING;
578  else
579  newRadioTransmissionState = TRANSMISSION_STATE_IDLE;
580  if (transmissionState != newRadioTransmissionState) {
581  EV_INFO << "Changing radio transmission state from " << getRadioTransmissionStateName(transmissionState) << " to " << getRadioTransmissionStateName(newRadioTransmissionState) << "." << endl;
582  transmissionState = newRadioTransmissionState;
583  emit(transmissionStateChangedSignal, newRadioTransmissionState);
584  }
585 }
The radio medium is busy, a signal strong enough to receive is detected.
Definition: IRadio.h:161
static const char * getRadioTransmissionStateName(TransmissionState transmissionState)
Returns the name of the provided radio transmission state.
Definition: IRadio.cc:70
The radio medium state is unknown, reception state is meaningless, signal detection is not possible...
Definition: IRadio.h:142
TransmissionState
This enumeration specifies the transmission state of the radio.
Definition: IRadio.h:167
ReceptionState
This enumeration specifies the reception state of the radio.
Definition: IRadio.h:136
cMessage * transmissionTimer
The timer that is scheduled to the end of the current transmission.
Definition: Radio.h:161
static const char * getRadioReceptionStateName(ReceptionState receptionState)
Returns the name of the provided radio reception state.
Definition: IRadio.cc:63
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
The radio is sleeping, frame reception or transmission is not possible, power consumption is minimal...
Definition: IRadio.h:102
The radio medium is busy, a signal is detected but it is not strong enough to receive.
Definition: IRadio.h:155
ReceptionState receptionState
The current reception state.
Definition: Radio.h:140
The radio medium is busy, the radio is currently transmitting a signal.
Definition: IRadio.h:183
The radio medium is free, no signal is detected.
Definition: IRadio.h:148
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:109
static simsignal_t receptionStateChangedSignal
This signal is emitted every time the radio reception state changes.
Definition: IRadio.h:66
virtual bool isListeningPossible() const
Definition: Radio.cc:542
TransmissionState transmissionState
The current transmission state.
Definition: Radio.h:144
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
RadioMode radioMode
State.
Definition: Radio.h:126
The radio is turned off, frame reception or transmission is not possible, power consumption is zero...
Definition: IRadio.h:96
cMessage * receptionTimer
The timer that is scheduled to the end of the current reception.
Definition: Radio.h:167

Member Data Documentation

const IAntenna* inet::physicallayer::Radio::antenna = nullptr
protected

The radio antenna model is never nullptr.

Referenced by initialize(), isListeningPossible(), and printToStream().

simsignal_t inet::physicallayer::Radio::bitErrorRateSignal = cComponent::registerSignal("bitErrorRate")
static

Referenced by sendUp().

const int inet::physicallayer::Radio::id = nextId++
protected

An identifier which is globally unique for the whole lifetime of the simulation among all radios.

IRadioMedium* inet::physicallayer::Radio::medium = nullptr
protected
int inet::physicallayer::Radio::mediumModuleId = -1
protected

The module id of the medim model.

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

simsignal_t inet::physicallayer::Radio::minSNIRSignal = cComponent::registerSignal("minSNIR")
static

Referenced by sendUp().

RadioMode inet::physicallayer::Radio::nextRadioMode = RADIO_MODE_OFF
protected

The radio is switching to this radio radio mode if a switch is in progress, otherwise this is the same as the current radio mode.

Referenced by completeRadioModeSwitch(), handleSwitchTimer(), setRadioMode(), and startRadioModeSwitch().

simsignal_t inet::physicallayer::Radio::packetErrorRateSignal = cComponent::registerSignal("packetErrorRate")
static

Referenced by sendUp().

RadioMode inet::physicallayer::Radio::previousRadioMode = RADIO_MODE_OFF
protected

The radio is switching from this radio mode to another if a switch is in progress, otherwise this is the same as the current radio mode.

Referenced by completeRadioModeSwitch(), and startRadioModeSwitch().

cGate* inet::physicallayer::Radio::radioIn = nullptr
protected
IRadioSignal::SignalPart inet::physicallayer::Radio::receivedSignalPart = IRadioSignal::SIGNAL_PART_NONE
protected

The current received signal part.

Referenced by getReceivedSignalPart(), initialize(), and updateTransceiverPart().

ReceptionState inet::physicallayer::Radio::receptionState = RECEPTION_STATE_UNDEFINED
protected

The current reception state.

Referenced by initialize(), and updateTransceiverState().

bool inet::physicallayer::Radio::separateReceptionParts = false
protected

Determines whether the reception of the preamble, header and data part are simulated separately or not.

Referenced by handleLowerPacket(), and initialize().

bool inet::physicallayer::Radio::separateTransmissionParts = false
protected

Determines whether the transmission of the preamble, header and data part are simulated separately or not.

Referenced by handleUpperPacket(), and initialize().

simtime_t inet::physicallayer::Radio::switchingTimes[RADIO_MODE_SWITCHING][RADIO_MODE_SWITCHING]
protected

Simulation time required to switch from one radio mode to another.

Referenced by parseRadioModeSwitchingTimes(), and setRadioMode().

cMessage* inet::physicallayer::Radio::switchTimer = nullptr
protected

The timer that is scheduled to the end of the radio mode switch.

Referenced by handleNodeCrash(), handleNodeShutdown(), handleSelfMessage(), initialize(), setRadioMode(), startRadioModeSwitch(), and ~Radio().

simsignal_t inet::physicallayer::Radio::symbolErrorRateSignal = cComponent::registerSignal("symbolErrorRate")
static

Referenced by sendUp().

TransmissionState inet::physicallayer::Radio::transmissionState = TRANSMISSION_STATE_UNDEFINED
protected

The current transmission state.

Referenced by initialize(), and updateTransceiverState().

cMessage* inet::physicallayer::Radio::transmissionTimer = nullptr
protected

The timer that is scheduled to the end of the current transmission.

If this timer is not scheduled then no transmission is in progress.

Referenced by abortTransmission(), completeRadioModeSwitch(), continueTransmission(), endTransmission(), getTransmissionInProgress(), handleNodeCrash(), handleNodeShutdown(), handleSelfMessage(), handleUpperPacket(), initialize(), startTransmission(), updateTransceiverPart(), updateTransceiverState(), and ~Radio().

IRadioSignal::SignalPart inet::physicallayer::Radio::transmittedSignalPart = IRadioSignal::SIGNAL_PART_NONE
protected

The current transmitted signal part.

Referenced by getTransmittedSignalPart(), initialize(), and updateTransceiverPart().

cGate* inet::physicallayer::Radio::upperLayerIn = nullptr
protected

Referenced by handleMessageWhenUp(), and initialize().

cGate* inet::physicallayer::Radio::upperLayerOut = nullptr
protected

Gates.

Referenced by initialize(), and sendUp().


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