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

#include <FrameSequenceHandler.h>

Inheritance diagram for inet::ieee80211::FrameSequenceHandler:
inet::ieee80211::IFrameSequenceHandler

Public Member Functions

virtual void startFrameSequence (IFrameSequence *frameSequence, FrameSequenceContext *context, IFrameSequenceHandler::ICallback *callback) override
 
virtual void processResponse (Ieee80211Frame *frame) override
 
virtual void transmissionComplete () override
 
virtual void handleStartRxTimeout () override
 
virtual bool isSequenceRunning () override
 
virtual ~FrameSequenceHandler ()
 
- Public Member Functions inherited from inet::ieee80211::IFrameSequenceHandler
virtual ~IFrameSequenceHandler ()
 

Protected Member Functions

virtual void startFrameSequenceStep ()
 
virtual void finishFrameSequenceStep ()
 
virtual void finishFrameSequence ()
 
virtual void abortFrameSequence ()
 

Protected Attributes

IFrameSequenceHandler::ICallbackcallback = nullptr
 
IFrameSequenceframeSequence = nullptr
 
FrameSequenceContextcontext = nullptr
 

Constructor & Destructor Documentation

inet::ieee80211::FrameSequenceHandler::~FrameSequenceHandler ( )
virtual
175 {
176  delete frameSequence;
177  delete context;
178 }
FrameSequenceContext * context
Definition: FrameSequenceHandler.h:33
IFrameSequence * frameSequence
Definition: FrameSequenceHandler.h:32

Member Function Documentation

void inet::ieee80211::FrameSequenceHandler::abortFrameSequence ( )
protectedvirtual

Referenced by finishFrameSequenceStep(), and handleStartRxTimeout().

157 {
158  EV_INFO << "Frame sequence aborted\n";
159  auto step = context->getLastStep();
160  auto failedTxStep = check_and_cast<ITransmitStep*>(dynamic_cast<IReceiveStep*>(step) ? context->getStepBeforeLast() : step);
161  auto frameToTransmit = failedTxStep->getFrameToTransmit();
162  if (auto dataOrMgmtFrame = dynamic_cast<Ieee80211DataOrMgmtFrame *>(frameToTransmit))
163  callback->originatorProcessFailedFrame(dataOrMgmtFrame);
164  else if (auto rtsTxStep = dynamic_cast<RtsTransmitStep *>(failedTxStep))
165  callback->originatorProcessRtsProtectionFailed(rtsTxStep->getProtectedFrame());
166  delete context;
167  delete frameSequence;
168  context = nullptr;
169  frameSequence = nullptr;
171  callback = nullptr;
172 }
virtual IFrameSequenceStep * getLastStep() const
Definition: FrameSequenceContext.h:84
Definition: IFrameSequence.h:59
Definition: IFrameSequence.h:50
virtual void originatorProcessFailedFrame(Ieee80211DataOrMgmtFrame *failedFrame)=0
virtual Ieee80211Frame * getFrameToTransmit()=0
virtual IFrameSequenceStep * getStepBeforeLast() const
Definition: FrameSequenceContext.h:85
IFrameSequenceHandler::ICallback * callback
Definition: FrameSequenceHandler.h:31
FrameSequenceContext * context
Definition: FrameSequenceHandler.h:33
virtual void originatorProcessRtsProtectionFailed(Ieee80211DataOrMgmtFrame *protectedFrame)=0
IFrameSequence * frameSequence
Definition: FrameSequenceHandler.h:32
void inet::ieee80211::FrameSequenceHandler::finishFrameSequence ( )
protectedvirtual

Referenced by startFrameSequenceStep().

146 {
147  EV_INFO << "Frame sequence finished\n";
148  delete context;
149  delete frameSequence;
150  context = nullptr;
151  frameSequence = nullptr;
153  callback = nullptr;
154 }
IFrameSequenceHandler::ICallback * callback
Definition: FrameSequenceHandler.h:31
FrameSequenceContext * context
Definition: FrameSequenceHandler.h:33
IFrameSequence * frameSequence
Definition: FrameSequenceHandler.h:32
void inet::ieee80211::FrameSequenceHandler::finishFrameSequenceStep ( )
protectedvirtual

Referenced by processResponse(), and transmissionComplete().

116 {
117  ASSERT(isSequenceRunning());
118  auto lastStep = context->getLastStep();
119  auto stepResult = frameSequence->completeStep(context);
120  // EV_INFO << "Frame sequence history:" << frameSequence->getHistory() << endl;
121  if (!stepResult) {
122  lastStep->setCompletion(IFrameSequenceStep::Completion::REJECTED);
124  }
125  else {
126  lastStep->setCompletion(IFrameSequenceStep::Completion::ACCEPTED);
127  switch (lastStep->getType()) {
129  auto transmitStep = static_cast<ITransmitStep *>(lastStep);
130  callback->originatorProcessTransmittedFrame(transmitStep->getFrameToTransmit());
131  break;
132  }
134  auto receiveStep = static_cast<IReceiveStep *>(lastStep);
135  auto transmitStep = check_and_cast<ITransmitStep *>(context->getStepBeforeLast());
136  callback->originatorProcessReceivedFrame(receiveStep->getReceivedFrame(), transmitStep->getFrameToTransmit());
137  break;
138  }
139  default:
140  throw cRuntimeError("Unknown frame sequence step type");
141  }
142  }
143 }
virtual IFrameSequenceStep * getLastStep() const
Definition: FrameSequenceContext.h:84
Definition: IFrameSequence.h:59
Definition: IFrameSequence.h:50
virtual bool isSequenceRunning() override
Definition: FrameSequenceHandler.h:46
virtual void originatorProcessReceivedFrame(Ieee80211Frame *frame, Ieee80211Frame *lastTransmittedFrame)=0
virtual IFrameSequenceStep * getStepBeforeLast() const
Definition: FrameSequenceContext.h:85
IFrameSequenceHandler::ICallback * callback
Definition: FrameSequenceHandler.h:31
FrameSequenceContext * context
Definition: FrameSequenceHandler.h:33
virtual bool completeStep(FrameSequenceContext *context)=0
virtual void abortFrameSequence()
Definition: FrameSequenceHandler.cc:156
IFrameSequence * frameSequence
Definition: FrameSequenceHandler.h:32
virtual void originatorProcessTransmittedFrame(Ieee80211Frame *transmittedFrame)=0
void inet::ieee80211::FrameSequenceHandler::handleStartRxTimeout ( )
overridevirtual

Implements inet::ieee80211::IFrameSequenceHandler.

27 {
28  auto lastStep = context->getLastStep();
29  switch (lastStep->getType()) {
32  break;
34  throw cRuntimeError("Received timeout while in transmit step");
35  default:
36  throw cRuntimeError("Unknown step type");
37  }
38 }
virtual IFrameSequenceStep * getLastStep() const
Definition: FrameSequenceContext.h:84
FrameSequenceContext * context
Definition: FrameSequenceHandler.h:33
virtual void abortFrameSequence()
Definition: FrameSequenceHandler.cc:156
virtual bool inet::ieee80211::FrameSequenceHandler::isSequenceRunning ( )
inlineoverridevirtual
void inet::ieee80211::FrameSequenceHandler::processResponse ( Ieee80211Frame frame)
overridevirtual

Implements inet::ieee80211::IFrameSequenceHandler.

41 {
42  ASSERT(callback != nullptr);
43  auto lastStep = context->getLastStep();
44  switch (lastStep->getType()) {
46  // TODO: check if not for us and abort
47  auto receiveStep = check_and_cast<IReceiveStep *>(context->getLastStep());
48  receiveStep->setFrameToReceive(frame);
50  if (isSequenceRunning())
52  break;
53  }
55  throw cRuntimeError("Received frame while current step is transmit");
56  default:
57  throw cRuntimeError("Unknown step type");
58  }
59 }
virtual IFrameSequenceStep * getLastStep() const
Definition: FrameSequenceContext.h:84
virtual void startFrameSequenceStep()
Definition: FrameSequenceHandler.cc:84
Definition: IFrameSequence.h:59
virtual bool isSequenceRunning() override
Definition: FrameSequenceHandler.h:46
virtual void setFrameToReceive(Ieee80211Frame *frame)=0
IFrameSequenceHandler::ICallback * callback
Definition: FrameSequenceHandler.h:31
FrameSequenceContext * context
Definition: FrameSequenceHandler.h:33
virtual void finishFrameSequenceStep()
Definition: FrameSequenceHandler.cc:115
void inet::ieee80211::FrameSequenceHandler::startFrameSequence ( IFrameSequence frameSequence,
FrameSequenceContext context,
IFrameSequenceHandler::ICallback callback 
)
overridevirtual

Implements inet::ieee80211::IFrameSequenceHandler.

71 {
72  this->callback = callback;
73  if (!isSequenceRunning()) {
74  this->frameSequence = frameSequence;
75  this->context = context;
76  frameSequence->startSequence(context, 0);
78  }
79  else
80  throw cRuntimeError("Channel access granted while a frame sequence is running");
81 }
virtual void startFrameSequenceStep()
Definition: FrameSequenceHandler.cc:84
virtual bool isSequenceRunning() override
Definition: FrameSequenceHandler.h:46
IFrameSequenceHandler::ICallback * callback
Definition: FrameSequenceHandler.h:31
FrameSequenceContext * context
Definition: FrameSequenceHandler.h:33
virtual void startSequence(FrameSequenceContext *context, int step)=0
IFrameSequence * frameSequence
Definition: FrameSequenceHandler.h:32
void inet::ieee80211::FrameSequenceHandler::startFrameSequenceStep ( )
protectedvirtual

Referenced by processResponse(), startFrameSequence(), and transmissionComplete().

85 {
86  ASSERT(isSequenceRunning());
87  auto nextStep = frameSequence->prepareStep(context);
88  // EV_INFO << "Frame sequence history:" << frameSequence->getHistory() << endl;
89  if (nextStep == nullptr)
91  else {
92  context->addStep(nextStep);
93  switch (nextStep->getType()) {
95  auto transmitStep = static_cast<TransmitStep *>(nextStep);
96  EV_INFO << "Transmitting, frame = " << transmitStep->getFrameToTransmit() << "\n";
97  callback->transmitFrame(transmitStep->getFrameToTransmit(), transmitStep->getIfs());
98  // TODO: lifetime
99  // if (auto dataFrame = dynamic_cast<Ieee80211DataFrame *>(transmitStep->getFrameToTransmit()))
100  // transmitLifetimeHandler->frameTransmitted(dataFrame);
101  break;
102  }
104  // start reception timer, break loop if timer expires before reception is over
105  auto receiveStep = static_cast<IReceiveStep *>(nextStep);
106  callback->scheduleStartRxTimer(receiveStep->getTimeout());
107  break;
108  }
109  default:
110  throw cRuntimeError("Unknown frame sequence step type");
111  }
112  }
113 }
Definition: IFrameSequence.h:59
virtual void finishFrameSequence()
Definition: FrameSequenceHandler.cc:145
virtual IFrameSequenceStep * prepareStep(FrameSequenceContext *context)=0
virtual bool isSequenceRunning() override
Definition: FrameSequenceHandler.h:46
virtual void transmitFrame(Ieee80211Frame *frame, simtime_t ifs)=0
IFrameSequenceHandler::ICallback * callback
Definition: FrameSequenceHandler.h:31
FrameSequenceContext * context
Definition: FrameSequenceHandler.h:33
virtual void addStep(IFrameSequenceStep *step)
Definition: FrameSequenceContext.h:81
IFrameSequence * frameSequence
Definition: FrameSequenceHandler.h:32
Definition: FrameSequenceStep.h:26
virtual Ieee80211Frame * getFrameToTransmit() override
Definition: FrameSequenceStep.h:42
virtual void scheduleStartRxTimer(simtime_t timeout)=0
void inet::ieee80211::FrameSequenceHandler::transmissionComplete ( )
overridevirtual

Implements inet::ieee80211::IFrameSequenceHandler.

62 {
63  if (isSequenceRunning()) {
65  if (isSequenceRunning())
67  }
68 }
virtual void startFrameSequenceStep()
Definition: FrameSequenceHandler.cc:84
virtual bool isSequenceRunning() override
Definition: FrameSequenceHandler.h:46
virtual void finishFrameSequenceStep()
Definition: FrameSequenceHandler.cc:115

Member Data Documentation

IFrameSequence* inet::ieee80211::FrameSequenceHandler::frameSequence = nullptr
protected

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