EMANE  1.2.1
ieee80211abgmacheadermessage.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013,2016 - Adjacent Link LLC, Bridgewater, New Jersey
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Adjacent Link LLC nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
34 #include "ieee80211abgmacheader.pb.h"
35 #include "msgtypes.h"
36 #include "utils.h"
37 
38 namespace {
39 
40  inline EMANEMessage::IEEE80211ABGMACHeader_MessageType convertMessageType(std::uint8_t type)
41  {
42  switch(type)
43  {
45  return EMANEMessage::IEEE80211ABGMACHeader_MessageType::IEEE80211ABGMACHeader_MessageType_NONE;
46 
48  return EMANEMessage::IEEE80211ABGMACHeader_MessageType::IEEE80211ABGMACHeader_MessageType_BROADCAST_DATA;
49 
51  return EMANEMessage::IEEE80211ABGMACHeader_MessageType::IEEE80211ABGMACHeader_MessageType_UNICAST_DATA;
52 
54  return EMANEMessage::IEEE80211ABGMACHeader_MessageType::IEEE80211ABGMACHeader_MessageType_UNICAST_RTS_CTS_DATA;
55 
57  return EMANEMessage::IEEE80211ABGMACHeader_MessageType::IEEE80211ABGMACHeader_MessageType_UNICAST_CTS_CTRL;
58 
59  default:
60  return EMANEMessage::IEEE80211ABGMACHeader_MessageType::IEEE80211ABGMACHeader_MessageType_NONE;
61  }
62  }
63 
64  inline std::uint8_t convertMessageType(EMANEMessage::IEEE80211ABGMACHeader_MessageType type)
65  {
66  switch(type)
67  {
68  case EMANEMessage::IEEE80211ABGMACHeader_MessageType::IEEE80211ABGMACHeader_MessageType_NONE:
70 
71  case EMANEMessage::IEEE80211ABGMACHeader_MessageType::IEEE80211ABGMACHeader_MessageType_BROADCAST_DATA:
73 
74  case EMANEMessage::IEEE80211ABGMACHeader_MessageType::IEEE80211ABGMACHeader_MessageType_UNICAST_DATA:
76 
77  case EMANEMessage::IEEE80211ABGMACHeader_MessageType::IEEE80211ABGMACHeader_MessageType_UNICAST_RTS_CTS_DATA:
79 
80  case EMANEMessage::IEEE80211ABGMACHeader_MessageType::IEEE80211ABGMACHeader_MessageType_UNICAST_CTS_CTRL:
82 
83  default:
85  }
86  }
87 }
88 
89 class EMANE::Models::IEEE80211ABG::MACHeaderMessage::Implementation
90 {
91 public:
92  Implementation(std::uint8_t u8MessageType,
93  std::uint8_t u8NumRetries,
94  std::uint16_t u16DataRateIndex,
95  std::uint16_t u16SequenceNumber,
96  std::uint16_t u16SrcNEM,
97  std::uint16_t u16DstNEM,
98  const Microseconds &durationMicroseconds) :
99  u8MessageType_{u8MessageType},
100  u8NumRetries_{u8NumRetries},
101  u16DataRateIndex_{u16DataRateIndex},
102  u16SequenceNumber_{u16SequenceNumber},
103  u16SrcNEM_{u16SrcNEM},
104  u16DstNEM_{u16DstNEM},
105  durationMicroseconds_{durationMicroseconds}
106  { }
107 
108  std::uint8_t getMessageType() const
109  {
110  return u8MessageType_;
111  }
112 
113  std::uint8_t getNumRetries() const
114  {
115  return u8NumRetries_;
116  }
117 
118  std::uint16_t getDataRateIndex() const
119  {
120  return u16DataRateIndex_;
121  }
122 
123  std::uint16_t getSequenceNumber() const
124  {
125  return u16SequenceNumber_;
126  }
127 
128  std::uint16_t getSrcNEM() const
129  {
130  return u16SrcNEM_;
131  }
132 
133  std::uint16_t getDstNEM() const
134  {
135  return u16DstNEM_;
136  }
137 
139  {
140  return durationMicroseconds_;
141  }
142 
143 private:
144  const std::uint8_t u8MessageType_;
145  const std::uint8_t u8NumRetries_;
146  const std::uint16_t u16DataRateIndex_;
147  const std::uint16_t u16SequenceNumber_;
148  const std::uint16_t u16SrcNEM_;
149  const std::uint16_t u16DstNEM_;
150  EMANE::Microseconds durationMicroseconds_;
151 };
152 
153 
155  std::uint8_t u8NumRetries,
156  std::uint16_t u16DataRateIndex,
157  std::uint16_t u16SequenceNumber,
158  std::uint16_t u16SrcNEM,
159  std::uint16_t u16DstNEM,
160  const Microseconds &durationMicroseconds) :
161 
162  pImpl_{new Implementation{u8MessageType,
163  u8NumRetries,
164  u16DataRateIndex,
165  u16SequenceNumber,
166  u16SrcNEM,
167  u16DstNEM,
168  durationMicroseconds}}
169 
170 { }
171 
172 
174 {
175  EMANEMessage::IEEE80211ABGMACHeader message;
176 
177  if(!message.ParseFromArray(p, len))
178  {
179  throw SerializationException("unable to deserialize MACHeaderMessage");
180  }
181 
182  pImpl_.reset(new Implementation{convertMessageType(message.messagetype()),
183  static_cast<std::uint8_t>(message.numretries()),
184  static_cast<std::uint16_t>(message.datarateindex()),
185  static_cast<std::uint16_t>(message.sequencenumber()),
186  static_cast<std::uint16_t>(message.srcnem()),
187  static_cast<std::uint16_t>(message.dstnem()),
188  Microseconds{message.durationmicroseconds()}});
189 }
190 
191 
193 { }
194 
195 
197 {
198  return pImpl_->getMessageType();
199 }
200 
201 
203 {
204  return pImpl_->getNumRetries();
205 
206 }
207 
209 {
210  return pImpl_->getDataRateIndex();
211 }
212 
214 {
215  return pImpl_->getSequenceNumber();
216 }
217 
219 {
220  return pImpl_->getSrcNEM();
221 }
222 
224 {
225  return pImpl_->getDstNEM();
226 }
227 
229 {
230  return pImpl_->getDurationMicroseconds();
231 }
232 
233 
234 
236 {
237  Serialization serialization;
238 
239  EMANEMessage::IEEE80211ABGMACHeader message;
240 
241  message.set_messagetype(convertMessageType(pImpl_->getMessageType()));
242 
243  message.set_numretries(pImpl_->getNumRetries());
244 
245  message.set_datarateindex(pImpl_->getDataRateIndex());
246 
247  message.set_sequencenumber(pImpl_->getSequenceNumber());
248 
249  message.set_srcnem(pImpl_->getSrcNEM());
250 
251  message.set_dstnem(pImpl_->getDstNEM());
252 
253  message.set_durationmicroseconds(pImpl_->getDurationMicroseconds().count());
254 
255  if(!message.SerializeToString(&serialization))
256  {
257  throw SerializationException("unable to serialize MACHeaderMessage");
258  }
259 
260  return serialization;
261 }
std::string Serialization
Definition: serializable.h:42
const std::uint8_t MSG_TYPE_UNICAST_CTS_CTRL
Definition: msgtypes.h:48
const std::uint8_t MSG_TYPE_NONE
Definition: msgtypes.h:44
SerializationException is thrown when an exception occurs during serialization or deserialization of ...
const std::uint8_t MSG_TYPE_BROADCAST_DATA
Definition: msgtypes.h:45
std::chrono::microseconds Microseconds
Definition: types.h:45
MACHeaderMessage(std::uint8_t u8MessageType, std::uint8_t u8NumRetries, std::uint16_t u16DataRateIndex, std::uint16_t u16SequenceNumber, std::uint16_t u16SrcNEM, std::uint16_t u16DstNEM, const Microseconds &duration)
const std::uint8_t MSG_TYPE_UNICAST_DATA
Definition: msgtypes.h:46
const std::uint8_t MSG_TYPE_UNICAST_RTS_CTS_DATA
Definition: msgtypes.h:47