author | Kirill Andreev <andreev@iitp.ru> |
Thu, 26 Mar 2009 20:17:41 +0300 | |
changeset 4890 | 8ee0a72c0ae0 |
parent 4889 | 279b07de3327 |
permissions | -rw-r--r-- |
4883 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2009 IITP RAS |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License version 2 as |
|
7 |
* published by the Free Software Foundation; |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 |
* |
|
18 |
* Author: Kirill Andreev <andreev@iitp.ru> |
|
19 |
*/ |
|
20 |
||
21 |
||
22 |
#include "ns3/assert.h" |
|
23 |
#include "ns3/address-utils.h" |
|
24 |
#include "ns3/mesh-wifi-mac-header.h" |
|
25 |
||
26 |
namespace ns3 { |
|
27 |
||
28 |
/*********************************************************** |
|
29 |
* Here Mesh Mac Header functionality is defined. |
|
30 |
***********************************************************/ |
|
31 |
TypeId |
|
32 |
WifiMeshHeader::GetTypeId () |
|
33 |
{ |
|
34 |
static TypeId tid = TypeId ("ns3::WifiMeshHeader") |
|
4890 | 35 |
.SetParent<Header> () |
36 |
.AddConstructor<WifiMeshHeader> () |
|
37 |
; |
|
4883 | 38 |
return tid; |
39 |
} |
|
40 |
||
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
41 |
WifiMeshHeader::WifiMeshHeader (): |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
42 |
m_meshFlags (0), |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
43 |
m_meshTtl (0), |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
44 |
m_meshSeqno (0), |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
45 |
m_addr4 (Mac48Address ()), |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
46 |
m_addr5 (Mac48Address ()), |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
47 |
m_addr6 (Mac48Address ()) |
4883 | 48 |
{ |
49 |
} |
|
50 |
||
51 |
WifiMeshHeader::~WifiMeshHeader () |
|
52 |
{ |
|
53 |
} |
|
54 |
||
55 |
TypeId |
|
56 |
WifiMeshHeader::GetInstanceTypeId () const |
|
57 |
{ |
|
58 |
return GetTypeId (); |
|
59 |
} |
|
60 |
||
61 |
void |
|
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
62 |
WifiMeshHeader::SetAddr4 (Mac48Address address) |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
63 |
{ |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
64 |
m_addr4 = address; |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
65 |
} |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
66 |
|
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
67 |
void |
4883 | 68 |
WifiMeshHeader::SetAddr5 (Mac48Address address) |
69 |
{ |
|
70 |
m_addr5 = address; |
|
71 |
} |
|
72 |
||
73 |
void |
|
74 |
WifiMeshHeader::SetAddr6 (Mac48Address address) |
|
75 |
{ |
|
76 |
m_addr6 = address; |
|
77 |
} |
|
78 |
||
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
79 |
Mac48Address |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
80 |
WifiMeshHeader::GetAddr4 () const |
4883 | 81 |
{ |
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
82 |
return m_addr4; |
4883 | 83 |
} |
84 |
||
85 |
Mac48Address |
|
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
86 |
WifiMeshHeader::GetAddr5 () const |
4883 | 87 |
{ |
88 |
return m_addr5; |
|
89 |
} |
|
90 |
||
91 |
Mac48Address |
|
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
92 |
WifiMeshHeader::GetAddr6 () const |
4883 | 93 |
{ |
94 |
return m_addr6; |
|
95 |
} |
|
96 |
||
97 |
void |
|
98 |
WifiMeshHeader::SetMeshSeqno (uint32_t seqno) |
|
99 |
{ |
|
100 |
m_meshSeqno = seqno; |
|
101 |
} |
|
102 |
||
103 |
uint32_t |
|
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
104 |
WifiMeshHeader::GetMeshSeqno () const |
4883 | 105 |
{ |
106 |
return m_meshSeqno; |
|
107 |
} |
|
108 |
||
109 |
void |
|
110 |
WifiMeshHeader::SetMeshTtl (uint8_t TTL) |
|
111 |
{ |
|
112 |
m_meshTtl = TTL; |
|
113 |
} |
|
114 |
||
115 |
uint8_t |
|
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
116 |
WifiMeshHeader::GetMeshTtl () const |
4883 | 117 |
{ |
118 |
return m_meshTtl; |
|
119 |
} |
|
120 |
||
121 |
void |
|
122 |
WifiMeshHeader::SetAddressExt (uint8_t num_of_addresses) |
|
123 |
{ |
|
124 |
if (num_of_addresses > 3) |
|
125 |
return; |
|
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
126 |
m_meshFlags |= 0xc0 & (num_of_addresses << 6); |
4883 | 127 |
} |
128 |
||
129 |
uint8_t |
|
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
130 |
WifiMeshHeader::GetAddressExt () const |
4883 | 131 |
{ |
132 |
return ((0xc0 & m_meshFlags) >> 6); |
|
133 |
} |
|
134 |
||
135 |
||
136 |
uint32_t |
|
137 |
WifiMeshHeader::GetSerializedSize () const |
|
138 |
{ |
|
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
139 |
return 6 + GetAddressExt () * 6; |
4883 | 140 |
} |
141 |
||
142 |
void |
|
143 |
WifiMeshHeader::Serialize (Buffer::Iterator start) const |
|
144 |
{ |
|
145 |
Buffer::Iterator i = start; |
|
146 |
i.WriteU8 (m_meshFlags); |
|
147 |
i.WriteU8 (m_meshTtl); |
|
148 |
i.WriteU32 (m_meshSeqno); |
|
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
149 |
uint8_t addresses_to_add = GetAddressExt (); |
4883 | 150 |
//Writing Address extensions: |
151 |
if (addresses_to_add > 0) |
|
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
152 |
WriteTo (i, m_addr4); |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
153 |
if (addresses_to_add > 1) |
4883 | 154 |
WriteTo (i, m_addr5); |
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
155 |
if (addresses_to_add > 2) |
4883 | 156 |
WriteTo (i, m_addr6); |
157 |
} |
|
158 |
||
159 |
uint32_t |
|
160 |
WifiMeshHeader::Deserialize (Buffer::Iterator start) |
|
161 |
{ |
|
162 |
Buffer::Iterator i = start; |
|
163 |
uint8_t addresses_to_read = 0; |
|
164 |
m_meshFlags = i.ReadU8 (); |
|
165 |
m_meshTtl = i.ReadU8 (); |
|
166 |
m_meshSeqno = i.ReadU32 (); |
|
167 |
addresses_to_read = (m_meshFlags & 0xc0) >> 6; |
|
168 |
if (addresses_to_read > 0) |
|
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
169 |
ReadFrom (i, m_addr4); |
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
170 |
if (addresses_to_read > 1) |
4883 | 171 |
ReadFrom (i, m_addr5); |
4889
279b07de3327
Fixrd bugs with address extensions, broadcast frames can go through L2Routing
Kirill Andreev <andreev@iitp.ru>
parents:
4883
diff
changeset
|
172 |
if (addresses_to_read > 2) |
4883 | 173 |
ReadFrom (i, m_addr6); |
174 |
return i.GetDistanceFrom (start); |
|
175 |
} |
|
176 |
void |
|
177 |
WifiMeshHeader::Print (std::ostream &os) const |
|
178 |
{ |
|
179 |
os << "flags" << m_meshFlags |
|
180 |
<< "ttl" << m_meshTtl |
|
181 |
<< "seqno" << m_meshSeqno; |
|
182 |
} |
|
183 |
/********************************************************** |
|
184 |
* MultihopActionFrame |
|
185 |
**********************************************************/ |
|
186 |
WifiMeshMultihopActionHeader::WifiMeshMultihopActionHeader () |
|
187 |
{ |
|
188 |
} |
|
189 |
||
190 |
WifiMeshMultihopActionHeader::~WifiMeshMultihopActionHeader () |
|
191 |
{ |
|
192 |
} |
|
193 |
||
194 |
void |
|
195 |
WifiMeshMultihopActionHeader::SetAction ( |
|
196 |
enum WifiMeshMultihopActionHeader::CategoryValue type, |
|
197 |
WifiMeshMultihopActionHeader::ACTION_VALUE action) |
|
198 |
{ |
|
199 |
switch (type) |
|
200 |
{ |
|
201 |
case MESH_PEER_LINK_MGT: |
|
202 |
m_category = 4; |
|
203 |
switch (action.peerLink) |
|
204 |
{ |
|
205 |
case PEER_LINK_OPEN: |
|
206 |
m_actionValue = 0; |
|
207 |
break; |
|
208 |
case PEER_LINK_CONFIRM: |
|
209 |
m_actionValue = 1; |
|
210 |
break; |
|
211 |
case PEER_LINK_CLOSE: |
|
212 |
m_actionValue = 2; |
|
213 |
break; |
|
214 |
}; |
|
215 |
break; |
|
216 |
case MESH_LINK_METRIC: |
|
217 |
m_category = 5; |
|
218 |
break; |
|
219 |
case MESH_PATH_SELECTION: |
|
220 |
m_category = 6; |
|
221 |
switch (action.pathSelection) |
|
222 |
{ |
|
223 |
case PATH_REQUEST: |
|
224 |
m_actionValue = 0; |
|
225 |
break; |
|
226 |
case PATH_REPLY: |
|
227 |
m_actionValue = 1; |
|
228 |
break; |
|
229 |
case PATH_ERROR: |
|
230 |
m_actionValue = 2; |
|
231 |
break; |
|
232 |
case ROOT_ANNOUNCEMENT: |
|
233 |
m_actionValue = 3; |
|
234 |
break; |
|
235 |
}; |
|
236 |
break; |
|
237 |
case MESH_INTERWORK_ACTION: |
|
238 |
m_category = 7; |
|
239 |
break; |
|
240 |
case MESH_RESOURCE_COORDINATION: |
|
241 |
m_category = 8; |
|
242 |
break; |
|
243 |
}; |
|
244 |
} |
|
245 |
||
246 |
enum WifiMeshMultihopActionHeader::CategoryValue |
|
247 |
WifiMeshMultihopActionHeader::GetCategory () |
|
248 |
{ |
|
249 |
switch (m_category) |
|
250 |
{ |
|
251 |
case 4: |
|
252 |
return MESH_PEER_LINK_MGT; |
|
253 |
case 5: |
|
254 |
return MESH_LINK_METRIC; |
|
255 |
case 6: |
|
256 |
return MESH_PATH_SELECTION; |
|
257 |
case 7: |
|
258 |
return MESH_INTERWORK_ACTION; |
|
259 |
case 8: |
|
260 |
return MESH_RESOURCE_COORDINATION; |
|
261 |
default: |
|
262 |
NS_ASSERT (false); |
|
263 |
return MESH_PEER_LINK_MGT; |
|
264 |
} |
|
265 |
} |
|
266 |
||
267 |
WifiMeshMultihopActionHeader::ACTION_VALUE |
|
268 |
WifiMeshMultihopActionHeader::GetAction () |
|
269 |
{ |
|
270 |
ACTION_VALUE retval; |
|
271 |
switch (m_category) |
|
272 |
{ |
|
273 |
case 4: |
|
274 |
//MESH_PEER_LINK_MGT; |
|
275 |
switch (m_actionValue) |
|
276 |
{ |
|
277 |
case 0: |
|
278 |
retval.peerLink = PEER_LINK_OPEN; |
|
279 |
return retval; |
|
280 |
case 1: |
|
281 |
retval.peerLink = PEER_LINK_CONFIRM; |
|
282 |
return retval; |
|
283 |
case 2: |
|
284 |
retval.peerLink = PEER_LINK_CLOSE; |
|
285 |
return retval; |
|
286 |
default: |
|
287 |
NS_ASSERT (false); |
|
288 |
return retval; |
|
289 |
||
290 |
} |
|
291 |
case 5: |
|
292 |
//MESH_LINK_METRIC; |
|
293 |
case 6: |
|
294 |
//MESH_PATH_SELECTION; |
|
295 |
switch (m_actionValue) |
|
296 |
{ |
|
297 |
case 0: |
|
298 |
retval.pathSelection = PATH_REQUEST; |
|
299 |
return retval; |
|
300 |
case 1: |
|
301 |
retval.pathSelection = PATH_REPLY; |
|
302 |
return retval; |
|
303 |
case 2: |
|
304 |
retval.pathSelection = PATH_ERROR; |
|
305 |
return retval; |
|
306 |
case 3: |
|
307 |
retval.pathSelection = ROOT_ANNOUNCEMENT; |
|
308 |
return retval; |
|
309 |
default: |
|
310 |
NS_ASSERT (false); |
|
311 |
return retval; |
|
312 |
} |
|
313 |
||
314 |
case 7: |
|
315 |
//MESH_INTERWORK_ACTION; |
|
316 |
case 8: |
|
317 |
//MESH_RESOURCE_COORDINATION; |
|
318 |
default: |
|
319 |
NS_ASSERT (false); |
|
320 |
return retval; |
|
321 |
} |
|
322 |
} |
|
323 |
||
324 |
TypeId |
|
325 |
WifiMeshMultihopActionHeader::GetTypeId () |
|
326 |
{ |
|
327 |
static TypeId tid = TypeId ("ns3::WifiMeshMultihopActionHeader") |
|
328 |
.SetParent<Header> () |
|
329 |
.AddConstructor<WifiMeshMultihopActionHeader> () |
|
330 |
; |
|
331 |
return tid; |
|
332 |
} |
|
333 |
||
334 |
TypeId |
|
335 |
WifiMeshMultihopActionHeader::GetInstanceTypeId () const |
|
336 |
{ |
|
337 |
return GetTypeId (); |
|
338 |
} |
|
339 |
||
340 |
void |
|
341 |
WifiMeshMultihopActionHeader::Print (std::ostream &os) const |
|
342 |
{ |
|
343 |
} |
|
344 |
||
345 |
uint32_t |
|
346 |
WifiMeshMultihopActionHeader::GetSerializedSize () const |
|
347 |
{ |
|
348 |
return 2; |
|
349 |
} |
|
350 |
||
351 |
void |
|
352 |
WifiMeshMultihopActionHeader::Serialize (Buffer::Iterator start) const |
|
353 |
{ |
|
354 |
start.WriteU8 (m_category); |
|
355 |
start.WriteU8 (m_actionValue); |
|
356 |
} |
|
357 |
||
358 |
uint32_t |
|
359 |
WifiMeshMultihopActionHeader::Deserialize (Buffer::Iterator start) |
|
360 |
{ |
|
361 |
Buffer::Iterator i = start; |
|
362 |
m_category = i.ReadU8 (); |
|
363 |
m_actionValue = i.ReadU8 (); |
|
364 |
return i.GetDistanceFrom (start); |
|
365 |
} |
|
366 |
||
367 |
} // namespace ns3 |