INET Framework for OMNeT++/OMNEST
inet::ieee80211::Contention Class Reference

The default implementation of IContention. More...

#include <Contention.h>

Inheritance diagram for inet::ieee80211::Contention:
inet::ieee80211::IContention

Public Types

enum  State { IDLE, DEFER, IFS_AND_BACKOFF }
 
enum  EventType { START, MEDIUM_STATE_CHANGED, CORRUPTED_FRAME_RECEIVED, CHANNEL_ACCESS_GRANTED }
 

Public Member Functions

 Contention ()
 
 ~Contention ()
 
virtual void startContention (int cw, simtime_t ifs, simtime_t eifs, simtime_t slotTime, ICallback *callback) override
 
virtual void mediumStateChanged (bool mediumFree) override
 
virtual void corruptedFrameReceived () override
 
virtual bool isContentionInProgress () override
 
- Public Member Functions inherited from inet::ieee80211::IContention
virtual ~IContention ()
 
virtual void startContention (int cw, simtime_t ifs, simtime_t eifs, simtime_t slotTime, ICallback *callback)=0
 

Static Public Attributes

static simsignal_t stateChangedSignal = registerSignal("stateChanged")
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void handleWithFSM (EventType event)
 
virtual void scheduleTransmissionRequest ()
 
virtual void scheduleTransmissionRequestFor (simtime_t txStartTime)
 
virtual void cancelTransmissionRequest ()
 
virtual void switchToEifs ()
 
virtual void computeRemainingBackoffSlots ()
 
virtual void revokeBackoffOptimization ()
 
virtual void updateDisplayString (simtime_t expectedChannelAccess)
 
const char * getEventName (EventType event)
 

Protected Attributes

Ieee80211Macmac = nullptr
 
ICallbackcallback = nullptr
 
cMessage * startTxEvent = nullptr
 
cMessage * channelGrantedEvent = nullptr
 
simtime_t ifs = SIMTIME_ZERO
 
simtime_t eifs = SIMTIME_ZERO
 
simtime_t slotTime = SIMTIME_ZERO
 
cFSM fsm
 
simtime_t endEifsTime = SIMTIME_ZERO
 
int backoffSlots = 0
 
simtime_t scheduledTransmissionTime = SIMTIME_ZERO
 
simtime_t lastChannelBusyTime = SIMTIME_ZERO
 
simtime_t lastIdleStartTime = SIMTIME_ZERO
 
simtime_t backoffOptimizationDelta = SIMTIME_ZERO
 
bool mediumFree = true
 
bool backoffOptimization = true
 
simtime_t startTime = SIMTIME_ZERO
 

Detailed Description

The default implementation of IContention.

Member Enumeration Documentation

Enumerator
START 
MEDIUM_STATE_CHANGED 
CORRUPTED_FRAME_RECEIVED 
CHANNEL_ACCESS_GRANTED 
Enumerator
IDLE 
DEFER 
IFS_AND_BACKOFF 
Definition: Contention.h:37
Definition: Contention.h:37

Constructor & Destructor Documentation

inet::ieee80211::Contention::Contention ( )
inline
79 {}
inet::ieee80211::Contention::~Contention ( )
73 {
74  cancelAndDelete(channelGrantedEvent);
75  cancelAndDelete(startTxEvent);
76 }
cMessage * startTxEvent
Definition: Contention.h:44
cMessage * channelGrantedEvent
Definition: Contention.h:45

Member Function Documentation

void inet::ieee80211::Contention::cancelTransmissionRequest ( )
protectedvirtual

Referenced by handleWithFSM(), revokeBackoffOptimization(), and switchToEifs().

199 {
200  cancelEvent(startTxEvent);
202  if (hasGUI())
204 }
cMessage * startTxEvent
Definition: Contention.h:44
ICallback * callback
Definition: Contention.h:43
virtual void updateDisplayString(simtime_t expectedChannelAccess)
Definition: Contention.cc:265
virtual void expectedChannelAccess(simtime_t time)=0
void inet::ieee80211::Contention::computeRemainingBackoffSlots ( )
protectedvirtual

Referenced by handleWithFSM(), and revokeBackoffOptimization().

235 {
236  simtime_t remainingTime = scheduledTransmissionTime - simTime();
237  int remainingSlots = (remainingTime.raw() + slotTime.raw() - 1) / slotTime.raw();
238  if (remainingSlots < backoffSlots) // don't count IFS
239  backoffSlots = remainingSlots;
240 }
int backoffSlots
Definition: Contention.h:54
simtime_t scheduledTransmissionTime
Definition: Contention.h:55
simtime_t slotTime
Definition: Contention.h:50
void inet::ieee80211::Contention::corruptedFrameReceived ( )
overridevirtual

Implements inet::ieee80211::IContention.

185 {
186  Enter_Method("corruptedFrameReceived()");
188 }
virtual void handleWithFSM(EventType event)
Definition: Contention.cc:94
const char * inet::ieee80211::Contention::getEventName ( EventType  event)
protected

Referenced by handleWithFSM().

253 {
254 #define CASE(x) case x: return #x;
255  switch (event) {
256  CASE(START);
260  default: ASSERT(false); return "";
261  }
262 #undef CASE
263 }
#define CASE(x)
Definition: Contention.h:38
void inet::ieee80211::Contention::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
172 {
173  if (msg == startTxEvent)
175  else if (msg == channelGrantedEvent) {
176  EV_INFO << "Channel granted: contention started at " << startTime << std::endl;
178  callback = nullptr;
179  }
180  else
181  throw cRuntimeError("Unknown msg");
182 }
virtual void handleWithFSM(EventType event)
Definition: Contention.cc:94
cMessage * startTxEvent
Definition: Contention.h:44
simtime_t startTime
Definition: Contention.h:61
cMessage * channelGrantedEvent
Definition: Contention.h:45
ICallback * callback
Definition: Contention.h:43
void inet::ieee80211::Contention::handleWithFSM ( EventType  event)
protectedvirtual

Referenced by corruptedFrameReceived(), handleMessage(), mediumStateChanged(), and startContention().

95 {
96  emit(stateChangedSignal, fsm.getState());
97  EV_DEBUG << "handleWithFSM: processing event " << getEventName(event) << "\n";
98  bool finallyReportChannelAccessGranted = false;
99  FSMA_Switch(fsm) {
100  FSMA_State(IDLE) {
102  FSMA_Event_Transition(Starting-IFS-and-Backoff,
103  event == START && mediumFree,
106  );
108  event == START && !mediumFree,
109  DEFER,
110  ;
111  );
115  }
116  FSMA_State(DEFER) {
118  FSMA_Event_Transition(Restarting-IFS-and-Backoff,
119  event == MEDIUM_STATE_CHANGED && mediumFree,
122  );
123  FSMA_Event_Transition(Use-EIFS,
124  event == CORRUPTED_FRAME_RECEIVED,
125  DEFER,
126  endEifsTime = simTime() + eifs;
127  );
129  }
131  FSMA_Enter();
132  FSMA_Event_Transition(Backoff-expired,
133  event == CHANNEL_ACCESS_GRANTED,
134  IDLE,
135  lastIdleStartTime = simTime();
136  finallyReportChannelAccessGranted = true;
137  );
138  FSMA_Event_Transition(Defer-on-channel-busy,
139  event == MEDIUM_STATE_CHANGED && !mediumFree,
140  DEFER,
143  );
144  FSMA_Event_Transition(Use-EIFS,
145  event == CORRUPTED_FRAME_RECEIVED,
147  switchToEifs();
148  );
150  }
151  }
152  emit(stateChangedSignal, fsm.getState());
153  if (finallyReportChannelAccessGranted)
154  scheduleAt(simTime(), channelGrantedEvent);
155  if (hasGUI()) {
156  if (startTxEvent->isScheduled())
157  updateDisplayString(startTxEvent->getArrivalTime());
158  else
160  }
161 }
virtual void sendDownPendingRadioConfigMsg()
Definition: Ieee80211Mac.cc:223
cMessage * startTxEvent
Definition: Contention.h:44
virtual void computeRemainingBackoffSlots()
Definition: Contention.cc:234
simtime_t endEifsTime
Definition: Contention.h:53
#define FSMA_State(s)
Definition: FSMA.h:117
virtual void scheduleTransmissionRequest()
Definition: Contention.cc:206
cMessage * channelGrantedEvent
Definition: Contention.h:45
simtime_t lastIdleStartTime
Definition: Contention.h:57
Ieee80211Mac * mac
Definition: Contention.h:42
Definition: Contention.h:38
#define FSMA_Switch(fsm)
Definition: FSMA.h:101
#define FSMA_Fail_On_Unhandled_Event()
Definition: FSMA.h:156
#define FSMA_Event_Transition(transition, condition, target, action)
Definition: FSMA.h:127
virtual void updateDisplayString(simtime_t expectedChannelAccess)
Definition: Contention.cc:265
cFSM fsm
Definition: Contention.h:52
virtual void switchToEifs()
Definition: Contention.cc:227
virtual void cancelTransmissionRequest()
Definition: Contention.cc:198
simtime_t eifs
Definition: Contention.h:49
Definition: Contention.h:37
#define FSMA_Enter(action)
Definition: FSMA.h:119
#define FSMA_Ignore_Event(condition)
Definition: FSMA.h:149
const char * getEventName(EventType event)
Definition: Contention.cc:252
bool mediumFree
Definition: Contention.h:59
Definition: Contention.h:37
static simsignal_t stateChangedSignal
Definition: Contention.h:39
void inet::ieee80211::Contention::initialize ( int  stage)
overrideprotectedvirtual
37 {
38  if (stage == INITSTAGE_LOCAL) {
39  backoffOptimization = par("backoffOptimization");
40  lastIdleStartTime = simTime() - SimTime::getMaxTime() / 2;
41  mac = check_and_cast<Ieee80211Mac *>(getContainingNicModule(this)->getSubmodule("mac"));
42  startTxEvent = new cMessage("startTx");
43  startTxEvent->setSchedulingPriority(1000); // low priority, i.e. processed later than most events for the same time
44  // FIXME: kludge
45  // The callback->channelAccessGranted() call should be the last
46  // event at a simulation time in order to handle internal collisions
47  // properly.
48  channelGrantedEvent = new cMessage("channelGranted");
49  channelGrantedEvent->setSchedulingPriority(1000);
50  fsm.setName("Backoff procedure");
51  fsm.setState(IDLE, "IDLE");
52 
53  WATCH(ifs);
54  WATCH(eifs);
55  WATCH(slotTime);
56  WATCH(endEifsTime);
57  WATCH(backoffSlots);
59  WATCH(lastChannelBusyTime);
60  WATCH(lastIdleStartTime);
62  WATCH(mediumFree);
63  WATCH(backoffOptimization);
65  }
66  else if (stage == INITSTAGE_LAST) {
67  if (!par("initialChannelBusy") && simTime() == 0)
68  lastChannelBusyTime = simTime() - SimTime().getMaxTime() / 2;
69  }
70 }
simtime_t ifs
Definition: Contention.h:48
cMessage * startTxEvent
Definition: Contention.h:44
int backoffSlots
Definition: Contention.h:54
simtime_t endEifsTime
Definition: Contention.h:53
simtime_t lastChannelBusyTime
Definition: Contention.h:56
cMessage * channelGrantedEvent
Definition: Contention.h:45
simtime_t lastIdleStartTime
Definition: Contention.h:57
Operations that no other initializations can depend on, e.g.
Definition: InitStages.h:111
Ieee80211Mac * mac
Definition: Contention.h:42
Implements the IEEE 802.11 MAC.
Definition: Ieee80211Mac.h:47
Local initializations.
Definition: InitStages.h:35
cModule * getContainingNicModule(cModule *from)
Find the nic module (inside the networkNode) containing the given module.
Definition: ModuleAccess.cc:96
virtual void updateDisplayString(simtime_t expectedChannelAccess)
Definition: Contention.cc:265
cFSM fsm
Definition: Contention.h:52
simtime_t scheduledTransmissionTime
Definition: Contention.h:55
simtime_t backoffOptimizationDelta
Definition: Contention.h:58
simtime_t slotTime
Definition: Contention.h:50
simtime_t eifs
Definition: Contention.h:49
bool backoffOptimization
Definition: Contention.h:60
bool mediumFree
Definition: Contention.h:59
Definition: Contention.h:37
virtual bool inet::ieee80211::Contention::isContentionInProgress ( )
inlineoverridevirtual

Implements inet::ieee80211::IContention.

87 { return fsm.getState() != IDLE; }
cFSM fsm
Definition: Contention.h:52
Definition: Contention.h:37
void inet::ieee80211::Contention::mediumStateChanged ( bool  mediumFree)
overridevirtual

Implements inet::ieee80211::IContention.

164 {
165  Enter_Method_Silent(mediumFree ? "medium FREE" : "medium BUSY");
166  this->mediumFree = mediumFree;
167  lastChannelBusyTime = simTime();
169 }
virtual void handleWithFSM(EventType event)
Definition: Contention.cc:94
simtime_t lastChannelBusyTime
Definition: Contention.h:56
bool mediumFree
Definition: Contention.h:59
virtual int inet::ieee80211::Contention::numInitStages ( ) const
inlineoverrideprotectedvirtual
64 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::ieee80211::Contention::revokeBackoffOptimization ( )
protectedvirtual
244 {
246  backoffOptimizationDelta = SIMTIME_ZERO;
250 }
virtual void computeRemainingBackoffSlots()
Definition: Contention.cc:234
virtual void scheduleTransmissionRequest()
Definition: Contention.cc:206
simtime_t scheduledTransmissionTime
Definition: Contention.h:55
simtime_t backoffOptimizationDelta
Definition: Contention.h:58
virtual void cancelTransmissionRequest()
Definition: Contention.cc:198
void inet::ieee80211::Contention::scheduleTransmissionRequest ( )
protectedvirtual

Referenced by handleWithFSM(), revokeBackoffOptimization(), and switchToEifs().

207 {
208  ASSERT(mediumFree);
209  simtime_t now = simTime();
210  bool useEifs = endEifsTime > now + ifs;
211  simtime_t waitInterval = (useEifs ? eifs : ifs) + backoffSlots * slotTime;
212  EV_INFO << "backoffslots = " << backoffSlots << " slotTime = " << slotTime << std::endl;
213  if (backoffOptimization && fsm.getState() == IDLE) {
214  // we can pretend the frame has arrived into the queue a little bit earlier, and may be able to start transmitting immediately
215  simtime_t elapsedFreeChannelTime = now - lastChannelBusyTime;
216  simtime_t elapsedIdleTime = now - lastIdleStartTime;
217  EV_INFO << "lastBusyTime = " << lastChannelBusyTime << " lastIdle = " << lastIdleStartTime << std::endl;
218  backoffOptimizationDelta = std::min(waitInterval, std::min(elapsedFreeChannelTime, elapsedIdleTime));
219  if (backoffOptimizationDelta > SIMTIME_ZERO)
220  waitInterval -= backoffOptimizationDelta;
221  }
222  scheduledTransmissionTime = now + waitInterval;
223  EV_INFO << "waitInterval = " << waitInterval << std::endl;
225 }
simtime_t ifs
Definition: Contention.h:48
int backoffSlots
Definition: Contention.h:54
simtime_t endEifsTime
Definition: Contention.h:53
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SCTPAssociation.h:270
simtime_t lastChannelBusyTime
Definition: Contention.h:56
simtime_t lastIdleStartTime
Definition: Contention.h:57
virtual void scheduleTransmissionRequestFor(simtime_t txStartTime)
Definition: Contention.cc:190
cFSM fsm
Definition: Contention.h:52
simtime_t scheduledTransmissionTime
Definition: Contention.h:55
simtime_t backoffOptimizationDelta
Definition: Contention.h:58
simtime_t slotTime
Definition: Contention.h:50
simtime_t eifs
Definition: Contention.h:49
bool backoffOptimization
Definition: Contention.h:60
bool mediumFree
Definition: Contention.h:59
Definition: Contention.h:37
void inet::ieee80211::Contention::scheduleTransmissionRequestFor ( simtime_t  txStartTime)
protectedvirtual

Referenced by scheduleTransmissionRequest().

191 {
192  scheduleAt(txStartTime, startTxEvent);
193  callback->expectedChannelAccess(txStartTime);
194  if (hasGUI())
195  updateDisplayString(txStartTime);
196 }
cMessage * startTxEvent
Definition: Contention.h:44
ICallback * callback
Definition: Contention.h:43
virtual void updateDisplayString(simtime_t expectedChannelAccess)
Definition: Contention.cc:265
virtual void expectedChannelAccess(simtime_t time)=0
void inet::ieee80211::Contention::startContention ( int  cw,
simtime_t  ifs,
simtime_t  eifs,
simtime_t  slotTime,
ICallback callback 
)
overridevirtual
79 {
80  startTime = simTime();
81  ASSERT(ifs >= 0 && eifs >= 0 && slotTime >= 0 && cw >= 0);
82  Enter_Method("startContention()");
83  cancelEvent(channelGrantedEvent);
84  ASSERT(fsm.getState() == IDLE);
85  this->ifs = ifs;
86  this->eifs = eifs;
87  this->slotTime = slotTime;
88  this->callback = callback;
89  backoffSlots = intrand(cw + 1);
90  EV_DETAIL << "Starting contention: cw = " << cw << ", slots = " << backoffSlots << endl;
92 }
virtual void handleWithFSM(EventType event)
Definition: Contention.cc:94
simtime_t ifs
Definition: Contention.h:48
int backoffSlots
Definition: Contention.h:54
simtime_t startTime
Definition: Contention.h:61
cMessage * channelGrantedEvent
Definition: Contention.h:45
Definition: Contention.h:38
ICallback * callback
Definition: Contention.h:43
cFSM fsm
Definition: Contention.h:52
simtime_t slotTime
Definition: Contention.h:50
simtime_t eifs
Definition: Contention.h:49
Definition: Contention.h:37
void inet::ieee80211::Contention::switchToEifs ( )
protectedvirtual

Referenced by handleWithFSM().

228 {
229  endEifsTime = simTime() + eifs;
232 }
simtime_t endEifsTime
Definition: Contention.h:53
virtual void scheduleTransmissionRequest()
Definition: Contention.cc:206
virtual void cancelTransmissionRequest()
Definition: Contention.cc:198
simtime_t eifs
Definition: Contention.h:49
void inet::ieee80211::Contention::updateDisplayString ( simtime_t  expectedChannelAccess)
protectedvirtual

Referenced by cancelTransmissionRequest(), handleWithFSM(), initialize(), and scheduleTransmissionRequestFor().

266 {
267  std::string displayString(fsm.getStateName());
268  if (expectedChannelAccess != -1) {
269  std::ostringstream strs;
270  strs << expectedChannelAccess;
271  displayString += ("\nExp. access: " + strs.str());
272  }
273  getDisplayString().setTagArg("t", 0, displayString.c_str());
274 }
cFSM fsm
Definition: Contention.h:52

Member Data Documentation

bool inet::ieee80211::Contention::backoffOptimization = true
protected
simtime_t inet::ieee80211::Contention::backoffOptimizationDelta = SIMTIME_ZERO
protected
int inet::ieee80211::Contention::backoffSlots = 0
protected
ICallback* inet::ieee80211::Contention::callback = nullptr
protected
cMessage* inet::ieee80211::Contention::channelGrantedEvent = nullptr
protected
simtime_t inet::ieee80211::Contention::eifs = SIMTIME_ZERO
protected
simtime_t inet::ieee80211::Contention::endEifsTime = SIMTIME_ZERO
protected
cFSM inet::ieee80211::Contention::fsm
protected
simtime_t inet::ieee80211::Contention::ifs = SIMTIME_ZERO
protected
simtime_t inet::ieee80211::Contention::lastChannelBusyTime = SIMTIME_ZERO
protected
simtime_t inet::ieee80211::Contention::lastIdleStartTime = SIMTIME_ZERO
protected
Ieee80211Mac* inet::ieee80211::Contention::mac = nullptr
protected

Referenced by handleWithFSM(), and initialize().

bool inet::ieee80211::Contention::mediumFree = true
protected
simtime_t inet::ieee80211::Contention::scheduledTransmissionTime = SIMTIME_ZERO
protected
simtime_t inet::ieee80211::Contention::slotTime = SIMTIME_ZERO
protected
simtime_t inet::ieee80211::Contention::startTime = SIMTIME_ZERO
protected

Referenced by handleMessage(), and startContention().

cMessage* inet::ieee80211::Contention::startTxEvent = nullptr
protected
simsignal_t inet::ieee80211::Contention::stateChangedSignal = registerSignal("stateChanged")
static

Referenced by handleWithFSM().


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