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

#include <BasicReassembly.h>

Inheritance diagram for inet::ieee80211::BasicReassembly:
inet::ieee80211::IReassembly

Classes

struct  Key
 
struct  Value
 

Public Member Functions

virtual ~BasicReassembly ()
 
virtual Ieee80211DataOrMgmtFrameaddFragment (Ieee80211DataOrMgmtFrame *frame) override
 Add a fragment to the reassembly buffer. More...
 
virtual void purge (const MACAddress &address, int tid, int startSeqNumber, int endSeqNumber) override
 Discard fragments from the reassembly buffer. More...
 
- Public Member Functions inherited from inet::ieee80211::IReassembly
virtual ~IReassembly ()
 

Protected Types

typedef std::map< Key, ValueFragmentsMap
 

Protected Attributes

FragmentsMap fragmentsMap
 

Member Typedef Documentation

Constructor & Destructor Documentation

inet::ieee80211::BasicReassembly::~BasicReassembly ( )
virtual
100 {
101  for (auto it = fragmentsMap.begin(); it != fragmentsMap.end(); ++it)
102  delete it->second.frame;
103 }
FragmentsMap fragmentsMap
Definition: BasicReassembly.h:43

Member Function Documentation

Ieee80211DataOrMgmtFrame * inet::ieee80211::BasicReassembly::addFragment ( Ieee80211DataOrMgmtFrame frame)
overridevirtual

Add a fragment to the reassembly buffer.

If the new fragment completes a frame, then the reassembled frame is returned (and fragments are removed from the buffer), otherwise the function returns nullptr.

Implements inet::ieee80211::IReassembly.

Referenced by inet::ieee80211::RecipientMacDataService::defragment(), and inet::ieee80211::RecipientQoSMacDataService::defragment().

30 {
31  // Frame is not fragmented
32  if (!frame->getMoreFragments() && frame->getFragmentNumber() == 0)
33  return frame;
34  // FIXME: temporary fix for mgmt frames
35  if (dynamic_cast<Ieee80211ManagementFrame*>(frame))
36  return frame;
37  // find entry for this frame
38  Key key;
39  key.macAddress = frame->getTransmitterAddress();
40  key.tid = -1;
41  if (frame->getType() == ST_DATA_WITH_QOS)
42  if (Ieee80211DataFrame *qosDataFrame = dynamic_cast<Ieee80211DataFrame *>(frame))
43  key.tid = qosDataFrame->getTid();
44  key.seqNum = frame->getSequenceNumber();
45  short fragNum = frame->getFragmentNumber();
46  ASSERT(fragNum >= 0 && fragNum < MAX_NUM_FRAGMENTS);
47  auto& value = fragmentsMap[key];
48 
49  // update entry
50  uint16_t fragmentBit = 1 << fragNum;
51  value.receivedFragments |= fragmentBit;
52  if (!frame->getMoreFragments())
53  value.allFragments = (fragmentBit << 1) - 1;
54  if (!value.frame) {
55  frame->setByteLength(0); // needed for decapsulation of larger packet
56  value.frame = check_and_cast_nullable<Ieee80211DataOrMgmtFrame *>(frame->decapsulate());
57  }
58  MACAddress txAddress = frame->getTransmitterAddress();
59  delete frame;
60 
61  // if all fragments arrived, return assembled frame
62  if (value.allFragments != 0 && value.allFragments == value.receivedFragments) {
63  Ieee80211DataOrMgmtFrame *result = value.frame;
64  // We need to restore some data from the carrying frame's header like TX address
65  // TODO: Maybe we need to restore the fromDs, toDs fields as well when traveling through multiple APs
66  // TODO: Are there any other fields that we need to restore?
67  // TODO: SET TX ADDR WHEN THE FRAME ARRIVES FROM UPPER LAYER
68  result->setTransmitterAddress(txAddress);
69  fragmentsMap.erase(key);
70  return result;
71  }
72  else
73  return nullptr;
74 }
FragmentsMap fragmentsMap
Definition: BasicReassembly.h:43
Definition: Ieee80211Frame_m.h:117
const short int MAX_NUM_FRAGMENTS
Definition: Ieee80211Frame_m.h:50
void * Key
Definition: Macho.h:325
void inet::ieee80211::BasicReassembly::purge ( const MACAddress address,
int  tid,
int  startSeqNumber,
int  endSeqNumber 
)
overridevirtual

Discard fragments from the reassembly buffer.

Frames are identified by the transmitter address, the TID, and the sequence number range [startSeqNumber, endSeqNumber[. Set tid=-1 for non-QoS frames.

Implements inet::ieee80211::IReassembly.

77 {
78  Key key;
79  key.macAddress = address;
80  key.tid = tid;
81  key.seqNum = startSeqNumber;
82  auto itStart = fragmentsMap.lower_bound(key);
83  key.seqNum = endSeqNumber;
84  auto itEnd = fragmentsMap.upper_bound(key);
85 
86  if (endSeqNumber < startSeqNumber) {
87  for (auto it = itStart; it != fragmentsMap.end(); ) {
88  delete it->second.frame;
89  it = fragmentsMap.erase(it);
90  }
91  itStart = fragmentsMap.begin();
92  }
93  for (auto it = itStart; it != itEnd; ) {
94  delete it->second.frame;
95  it = fragmentsMap.erase(it);
96  }
97 }
FragmentsMap fragmentsMap
Definition: BasicReassembly.h:43
void * Key
Definition: Macho.h:325

Member Data Documentation

FragmentsMap inet::ieee80211::BasicReassembly::fragmentsMap
protected

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