LEFT | RIGHT |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2008,2009 IITP RAS | 3 * Copyright (c) 2008,2009 IITP RAS |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Kirill Andreev <andreev@iitp.ru> | 18 * Author: Kirill Andreev <andreev@iitp.ru> |
19 */ | 19 */ |
20 | 20 |
21 | |
22 #include "ns3/object.h" | 21 #include "ns3/object.h" |
23 #include "ns3/assert.h" | 22 #include "ns3/assert.h" |
24 #include "ns3/simulator.h" | 23 #include "ns3/simulator.h" |
25 #include "ns3/test.h" | 24 #include "ns3/test.h" |
26 #include "ns3/log.h" | 25 #include "ns3/log.h" |
27 | 26 |
28 #include "hwmp-rtable.h" | 27 #include "hwmp-rtable.h" |
29 | 28 |
30 namespace ns3 { | 29 namespace ns3 { |
31 namespace dot11s { | 30 namespace dot11s { |
32 | 31 |
33 NS_LOG_COMPONENT_DEFINE ("HwmpRtable"); | 32 NS_LOG_COMPONENT_DEFINE ("HwmpRtable"); |
34 | 33 |
35 NS_OBJECT_ENSURE_REGISTERED (HwmpRtable); | 34 NS_OBJECT_ENSURE_REGISTERED (HwmpRtable); |
36 | 35 |
37 TypeId | 36 TypeId |
38 HwmpRtable::GetTypeId () | 37 HwmpRtable::GetTypeId () |
39 { | 38 { |
40 static TypeId tid = TypeId ("ns3::dot11s::HwmpRtable") | 39 static TypeId tid = TypeId ("ns3::dot11s::HwmpRtable") |
41 .SetParent<Object> () | 40 .SetParent<Object> () |
42 .AddConstructor<HwmpRtable> (); | 41 .AddConstructor<HwmpRtable> (); |
43 return tid; | 42 return tid; |
44 } | 43 } |
45 HwmpRtable::HwmpRtable () | 44 HwmpRtable::HwmpRtable () |
46 { | 45 { |
47 DeleteProactivePath (); | 46 DeleteProactivePath (); |
48 } | 47 } |
49 HwmpRtable::~HwmpRtable () | 48 HwmpRtable::~HwmpRtable () |
50 { | 49 { |
51 } | 50 } |
52 void | 51 void |
53 HwmpRtable::DoDispose () | 52 HwmpRtable::DoDispose () |
54 { | 53 { |
55 m_routes.clear (); | 54 m_routes.clear (); |
56 } | 55 } |
57 void | 56 void |
58 HwmpRtable::AddReactivePath ( | 57 HwmpRtable::AddReactivePath (Mac48Address destination, Mac48Address retransmitte
r, uint32_t interface, |
59 Mac48Address destination, | 58 uint32_t metric, Time lifetime, uint32_t seqnum) |
60 Mac48Address retransmitter, | |
61 uint32_t interface, | |
62 uint32_t metric, | |
63 Time lifetime, | |
64 uint32_t seqnum | |
65 ) | |
66 { | 59 { |
67 std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination
); | 60 std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination
); |
68 if (i == m_routes.end ()) | 61 if (i == m_routes.end ()) |
69 { | 62 { |
70 ReactiveRoute newroute; | 63 ReactiveRoute newroute; |
71 m_routes[destination] = newroute; | 64 m_routes[destination] = newroute; |
72 } | 65 } |
73 i = m_routes.find (destination); | 66 i = m_routes.find (destination); |
74 NS_ASSERT (i != m_routes.end()); | 67 NS_ASSERT (i != m_routes.end ()); |
75 i->second.retransmitter = retransmitter; | 68 i->second.retransmitter = retransmitter; |
76 i->second.interface = interface; | 69 i->second.interface = interface; |
77 i->second.metric = metric; | 70 i->second.metric = metric; |
78 i->second.whenExpire = Simulator::Now() + lifetime; | 71 i->second.whenExpire = Simulator::Now () + lifetime; |
79 i->second.seqnum = seqnum; | 72 i->second.seqnum = seqnum; |
80 } | 73 } |
81 void | 74 void |
82 HwmpRtable::AddProactivePath ( | 75 HwmpRtable::AddProactivePath (uint32_t metric, Mac48Address root, Mac48Address r
etransmitter, |
83 uint32_t metric, | 76 uint32_t interface, Time lifetime, uint32_t seqnum) |
84 Mac48Address root, | |
85 Mac48Address retransmitter, | |
86 uint32_t interface, | |
87 Time lifetime, | |
88 uint32_t seqnum | |
89 ) | |
90 { | 77 { |
91 m_root.root = root; | 78 m_root.root = root; |
92 m_root.retransmitter = retransmitter; | 79 m_root.retransmitter = retransmitter; |
93 m_root.metric = metric; | 80 m_root.metric = metric; |
94 m_root.whenExpire = Simulator::Now() + lifetime; | 81 m_root.whenExpire = Simulator::Now () + lifetime; |
95 m_root.seqnum = seqnum; | 82 m_root.seqnum = seqnum; |
96 m_root.interface = interface; | 83 m_root.interface = interface; |
97 } | 84 } |
98 void | 85 void |
99 HwmpRtable::AddPrecursor (Mac48Address destination, uint32_t precursorInterface,
Mac48Address precursorAddress) | 86 HwmpRtable::AddPrecursor (Mac48Address destination, uint32_t precursorInterface, |
| 87 Mac48Address precursorAddress) |
100 { | 88 { |
101 std::pair<uint32_t, Mac48Address> precursor; | 89 std::pair<uint32_t, Mac48Address> precursor; |
102 precursor.first = precursorInterface; | 90 precursor.first = precursorInterface; |
103 precursor.second = precursorAddress; | 91 precursor.second = precursorAddress; |
104 std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination
); | 92 std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination
); |
105 if (i != m_routes.end ()) | 93 if (i != m_routes.end ()) |
106 { | 94 { |
107 bool should_add = true; | 95 bool should_add = true; |
108 for (unsigned int j = 0 ; j < i->second.precursors.size (); j ++) | 96 for (unsigned int j = 0; j < i->second.precursors.size (); j++) |
109 //NB: Only one active route may exist, so do not check | 97 { |
110 //interface ID, just address | 98 //NB: Only one active route may exist, so do not check |
111 if (i->second.precursors[j].second == precursorAddress) | 99 //interface ID, just address |
112 { | 100 if (i->second.precursors[j].second == precursorAddress) |
113 should_add = false; | 101 { |
114 break; | 102 should_add = false; |
115 } | 103 break; |
| 104 } |
| 105 } |
116 if (should_add) | 106 if (should_add) |
117 i->second.precursors.push_back (precursor); | 107 { |
118 } | 108 i->second.precursors.push_back (precursor); |
119 if(m_root.root == destination) | 109 } |
120 for (unsigned int j = 0 ; j < m_root.precursors.size (); j ++) | 110 } |
121 if (m_root.precursors[j].second == precursorAddress) | 111 if (m_root.root == destination) |
122 return; | 112 { |
123 m_root.precursors.push_back(precursor); | 113 for (unsigned int j = 0; j < m_root.precursors.size (); j++) |
| 114 { |
| 115 if (m_root.precursors[j].second == precursorAddress) |
| 116 { |
| 117 return; |
| 118 } |
| 119 } |
| 120 } |
| 121 m_root.precursors.push_back (precursor); |
124 } | 122 } |
125 void | 123 void |
126 HwmpRtable::DeleteProactivePath () | 124 HwmpRtable::DeleteProactivePath () |
127 { | 125 { |
128 m_root.precursors.clear (); | 126 m_root.precursors.clear (); |
129 m_root.interface = INTERFACE_ANY; | 127 m_root.interface = INTERFACE_ANY; |
130 m_root.metric = MAX_METRIC; | 128 m_root.metric = MAX_METRIC; |
131 m_root.retransmitter = Mac48Address::GetBroadcast (); | 129 m_root.retransmitter = Mac48Address::GetBroadcast (); |
132 m_root.seqnum = 0; | 130 m_root.seqnum = 0; |
133 m_root.whenExpire = Simulator::Now (); | 131 m_root.whenExpire = Simulator::Now (); |
134 } | 132 } |
135 void | 133 void |
136 HwmpRtable::DeleteProactivePath (Mac48Address root) | 134 HwmpRtable::DeleteProactivePath (Mac48Address root) |
137 { | 135 { |
138 if(m_root.root == root) | 136 if (m_root.root == root) |
139 DeleteProactivePath (); | 137 { |
| 138 DeleteProactivePath (); |
| 139 } |
140 } | 140 } |
141 void | 141 void |
142 HwmpRtable::DeleteReactivePath (Mac48Address destination) | 142 HwmpRtable::DeleteReactivePath (Mac48Address destination) |
143 { | 143 { |
144 std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination
); | 144 std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination
); |
145 if (i != m_routes.end ()) | 145 if (i != m_routes.end ()) |
146 m_routes.erase (i); | 146 { |
| 147 m_routes.erase (i); |
| 148 } |
147 } | 149 } |
148 HwmpRtable::LookupResult | 150 HwmpRtable::LookupResult |
149 HwmpRtable::LookupReactive (Mac48Address destination) | 151 HwmpRtable::LookupReactive (Mac48Address destination) |
150 { | 152 { |
151 std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination
); | 153 std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination
); |
152 if (i == m_routes.end ()) | 154 if (i == m_routes.end ()) |
153 return LookupResult (); | 155 { |
| 156 return LookupResult (); |
| 157 } |
154 if ((i->second.whenExpire < Simulator::Now ()) && (i->second.whenExpire != Sec
onds (0))) | 158 if ((i->second.whenExpire < Simulator::Now ()) && (i->second.whenExpire != Sec
onds (0))) |
155 { | 159 { |
156 NS_LOG_DEBUG ("Reactive route has expired, sorry."); | 160 NS_LOG_DEBUG ("Reactive route has expired, sorry."); |
157 return LookupResult(); | 161 return LookupResult (); |
158 } | 162 } |
159 return LookupReactiveExpired (destination); | 163 return LookupReactiveExpired (destination); |
160 } | 164 } |
161 HwmpRtable::LookupResult | 165 HwmpRtable::LookupResult |
162 HwmpRtable::LookupReactiveExpired (Mac48Address destination) | 166 HwmpRtable::LookupReactiveExpired (Mac48Address destination) |
163 { | 167 { |
164 std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination
); | 168 std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.find (destination
); |
165 if (i == m_routes.end ()) | 169 if (i == m_routes.end ()) |
166 return LookupResult (); | 170 { |
167 return LookupResult ( | 171 return LookupResult (); |
168 i->second.retransmitter, | 172 } |
169 i->second.interface, | 173 return LookupResult (i->second.retransmitter, i->second.interface, i->second.m
etric, i->second.seqnum, |
170 i->second.metric, i->second.seqnum, | 174 i->second.whenExpire - Simulator::Now ()); |
171 i->second.whenExpire - Simulator::Now () | |
172 ); | |
173 } | 175 } |
174 HwmpRtable::LookupResult | 176 HwmpRtable::LookupResult |
175 HwmpRtable::LookupProactive () | 177 HwmpRtable::LookupProactive () |
176 { | 178 { |
177 if (m_root.whenExpire < Simulator::Now ()) | 179 if (m_root.whenExpire < Simulator::Now ()) |
178 { | 180 { |
179 NS_LOG_DEBUG ("Proactive route has expired and will be deleted, sorry."); | 181 NS_LOG_DEBUG ("Proactive route has expired and will be deleted, sorry."); |
180 DeleteProactivePath (); | 182 DeleteProactivePath (); |
181 } | 183 } |
182 return LookupProactiveExpired (); | 184 return LookupProactiveExpired (); |
183 } | 185 } |
184 HwmpRtable::LookupResult | 186 HwmpRtable::LookupResult |
185 HwmpRtable::LookupProactiveExpired () | 187 HwmpRtable::LookupProactiveExpired () |
186 { | 188 { |
187 return LookupResult(m_root.retransmitter, m_root.interface, m_root.metric, m_r
oot.seqnum, m_root.whenExpire - Simulator::Now ()); | 189 return LookupResult (m_root.retransmitter, m_root.interface, m_root.metric, m_
root.seqnum, |
188 } | 190 m_root.whenExpire - Simulator::Now ()); |
189 std::vector<IePerr::FailedDestination> | 191 } |
| 192 std::vector<HwmpProtocol::FailedDestination> |
190 HwmpRtable::GetUnreachableDestinations (Mac48Address peerAddress) | 193 HwmpRtable::GetUnreachableDestinations (Mac48Address peerAddress) |
191 { | 194 { |
192 IePerr::FailedDestination dst; | 195 HwmpProtocol::FailedDestination dst; |
193 std::vector<IePerr::FailedDestination> retval; | 196 std::vector<HwmpProtocol::FailedDestination> retval; |
194 for (std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.begin (); i
!= m_routes.end(); i++) | 197 for (std::map<Mac48Address, ReactiveRoute>::iterator i = m_routes.begin (); i
!= m_routes.end (); i++) |
195 if (i->second.retransmitter == peerAddress) | 198 { |
196 { | 199 if (i->second.retransmitter == peerAddress) |
197 dst.destination = i->first; | 200 { |
198 i->second.seqnum ++; | 201 dst.destination = i->first; |
199 dst.seqnum = i->second.seqnum; | 202 i->second.seqnum++; |
200 retval.push_back (dst); | 203 dst.seqnum = i->second.seqnum; |
201 } | 204 retval.push_back (dst); |
| 205 } |
| 206 } |
202 //Lookup a path to root | 207 //Lookup a path to root |
203 if (m_root.retransmitter == peerAddress) | 208 if (m_root.retransmitter == peerAddress) |
204 { | 209 { |
205 dst.destination = m_root.root; | 210 dst.destination = m_root.root; |
206 dst.seqnum = m_root.seqnum; | 211 dst.seqnum = m_root.seqnum; |
207 retval.push_back (dst); | 212 retval.push_back (dst); |
208 } | 213 } |
209 return retval; | 214 return retval; |
210 } | 215 } |
211 HwmpRtable::PrecursorList | 216 HwmpRtable::PrecursorList |
212 HwmpRtable::GetPrecursors (Mac48Address destination) | 217 HwmpRtable::GetPrecursors (Mac48Address destination) |
213 { | 218 { |
214 //We suppose that no duplicates here can be | 219 //We suppose that no duplicates here can be |
215 PrecursorList retval; | 220 PrecursorList retval; |
216 std::map<Mac48Address, ReactiveRoute>::iterator route = m_routes.find (destina
tion); | 221 std::map<Mac48Address, ReactiveRoute>::iterator route = m_routes.find (destina
tion); |
217 if (route != m_routes.end ()) | 222 if (route != m_routes.end ()) |
218 for (unsigned int i = 0; i < route->second.precursors.size (); i ++) | 223 { |
219 retval.push_back(route->second.precursors[i]); | 224 for (unsigned int i = 0; i < route->second.precursors.size (); i++) |
| 225 { |
| 226 retval.push_back (route->second.precursors[i]); |
| 227 } |
| 228 } |
220 if (m_root.root == destination) | 229 if (m_root.root == destination) |
221 for (unsigned int i = 0; i < m_root.precursors.size (); i ++) | 230 { |
222 { | 231 for (unsigned int i = 0; i < m_root.precursors.size (); i++) |
223 bool should_add = true; | 232 { |
224 for(unsigned int j = 0; j < retval.size(); j ++) | 233 bool should_add = true; |
225 if(retval[j].second == m_root.precursors[i].second) | 234 for (unsigned int j = 0; j < retval.size (); j++) |
226 { | 235 { |
227 should_add = false; | 236 if (retval[j].second == m_root.precursors[i].second) |
228 break; | 237 { |
229 } | 238 should_add = false; |
230 if(should_add) | 239 break; |
231 retval.push_back(m_root.precursors[i]); | 240 } |
| 241 } |
| 242 if (should_add) |
| 243 { |
| 244 retval.push_back (m_root.precursors[i]); |
| 245 } |
| 246 } |
232 } | 247 } |
233 return retval; | 248 return retval; |
234 } | 249 } |
235 bool HwmpRtable::LookupResult::operator==(const HwmpRtable::LookupResult & o) co
nst | 250 bool |
236 { | 251 HwmpRtable::LookupResult::operator== (const HwmpRtable::LookupResult & o) const |
237 return (retransmitter == o.retransmitter | 252 { |
238 && ifIndex == o.ifIndex· | 253 return (retransmitter == o.retransmitter && ifIndex == o.ifIndex && metric ==
o.metric && seqnum |
239 && metric == o.metric | 254 == o.seqnum); |
240 && seqnum == o.seqnum | 255 } |
241 ); | 256 HwmpRtable::LookupResult::LookupResult (Mac48Address r, uint32_t i, uint32_t m,
uint32_t s, Time l) : |
242 } | 257 retransmitter (r), ifIndex (i), metric (m), seqnum (s), lifetime (l) |
243 bool HwmpRtable::LookupResult::IsValid() const | 258 { |
244 { | 259 } |
245 return !( retransmitter == Mac48Address::GetBroadcast () | 260 bool |
246 && ifIndex == INTERFACE_ANY | 261 HwmpRtable::LookupResult::IsValid () const |
247 && metric == MAX_METRIC | 262 { |
248 && seqnum == 0 | 263 return !(retransmitter == Mac48Address::GetBroadcast () && ifIndex == INTERFAC
E_ANY && metric == MAX_METRIC |
249 ); | 264 && seqnum == 0); |
250 } | 265 } |
251 #ifdef RUN_SELF_TESTS | 266 #ifdef RUN_SELF_TESTS |
252 /// Unit test for HwmpRtable | 267 /// Unit test for HwmpRtable |
253 class HwmpRtableTest : public Test | 268 class HwmpRtableTest : public Test |
254 { | 269 { |
255 public: | 270 public: |
256 HwmpRtableTest (); | 271 HwmpRtableTest (); |
257 virtual bool RunTests(); | 272 virtual bool |
258 | 273 RunTests (); |
| 274 |
259 private: | 275 private: |
260 /// Test Add apth and lookup path; | 276 /// Test Add apth and lookup path; |
261 void TestLookup (); | 277 void |
| 278 TestLookup (); |
262 /** | 279 /** |
263 * \name Test add path and try to lookup after entry has expired | 280 * \name Test add path and try to lookup after entry has expired |
264 * \{ | 281 * \{ |
265 */ | 282 */ |
266 void TestAddPath (); | 283 void |
267 void TestExpire (); | 284 TestAddPath (); |
| 285 void |
| 286 TestExpire (); |
268 ///\} | 287 ///\} |
269 /** | 288 /** |
270 * \name Test add precursors and find precursor list in rtable | 289 * \name Test add precursors and find precursor list in rtable |
271 * \{ | 290 * \{ |
272 */ | 291 */ |
273 void TestPrecursorAdd (); | 292 void |
274 void TestPrecursorFind (); | 293 TestPrecursorAdd (); |
| 294 void |
| 295 TestPrecursorFind (); |
275 ///\} | 296 ///\} |
276 private: | 297 private: |
277 bool result; | 298 bool result; |
278 | 299 |
279 Mac48Address dst; | 300 Mac48Address dst; |
280 Mac48Address hop; | 301 Mac48Address hop; |
281 uint32_t iface; | 302 uint32_t iface; |
282 uint32_t metric; | 303 uint32_t metric; |
283 uint32_t seqnum; | 304 uint32_t seqnum; |
284 Time expire; | 305 Time expire; |
285 Ptr<HwmpRtable> table; | 306 Ptr<HwmpRtable> table; |
286 std::vector<Mac48Address> precursors; | 307 std::vector<Mac48Address> precursors; |
287 }; | 308 }; |
288 /// Test instance | 309 /// Test instance |
289 static HwmpRtableTest g_HwmpRtableTest; | 310 static HwmpRtableTest g_HwmpRtableTest; |
290 | 311 |
291 HwmpRtableTest::HwmpRtableTest () : Test ("Mesh/802.11s/HwmpRtable"), | 312 HwmpRtableTest::HwmpRtableTest () : |
292 result(true), | 313 Test ("Mesh/802.11s/HwmpRtable"), result (true), dst ("01:00:00:01:00:01"), ho
p ("01:00:00:01:00:03"), |
293 dst ("01:00:00:01:00:01"), | 314 iface (8010), metric (10), seqnum (1), expire (Seconds (10)) |
294 hop ("01:00:00:01:00:03"), | |
295 iface (8010), | |
296 metric (10), | |
297 seqnum (1), | |
298 expire (Seconds (10)) | |
299 { | 315 { |
300 precursors.push_back (Mac48Address ("00:10:20:30:40:50")); | 316 precursors.push_back (Mac48Address ("00:10:20:30:40:50")); |
301 precursors.push_back (Mac48Address ("00:11:22:33:44:55")); | 317 precursors.push_back (Mac48Address ("00:11:22:33:44:55")); |
302 precursors.push_back (Mac48Address ("00:01:02:03:04:05")); | 318 precursors.push_back (Mac48Address ("00:01:02:03:04:05")); |
303 } | 319 } |
304 void HwmpRtableTest::TestLookup () | 320 void |
| 321 HwmpRtableTest::TestLookup () |
305 { | 322 { |
306 HwmpRtable::LookupResult correct (hop, iface, metric, seqnum); | 323 HwmpRtable::LookupResult correct (hop, iface, metric, seqnum); |
307 | 324 |
308 // Reactive path | 325 // Reactive path |
309 table->AddReactivePath (dst, hop, iface, metric, expire, seqnum); | 326 table->AddReactivePath (dst, hop, iface, metric, expire, seqnum); |
310 NS_TEST_ASSERT (table->LookupReactive (dst) == correct); | 327 NS_TEST_ASSERT (table->LookupReactive (dst) == correct); |
311 table->DeleteReactivePath (dst); | 328 table->DeleteReactivePath (dst); |
312 NS_TEST_ASSERT (! table->LookupReactive (dst).IsValid ()); | 329 NS_TEST_ASSERT (!table->LookupReactive (dst).IsValid ()); |
313 | 330 |
314 // Proactive | 331 // Proactive |
315 table->AddProactivePath (metric, dst, hop, iface, expire, seqnum); | 332 table->AddProactivePath (metric, dst, hop, iface, expire, seqnum); |
316 NS_TEST_ASSERT (table->LookupProactive () == correct); | 333 NS_TEST_ASSERT (table->LookupProactive () == correct); |
317 table->DeleteProactivePath (dst); | 334 table->DeleteProactivePath (dst); |
318 NS_TEST_ASSERT (! table->LookupProactive ().IsValid ()); | 335 NS_TEST_ASSERT (!table->LookupProactive ().IsValid ()); |
319 } | 336 } |
320 void HwmpRtableTest::TestAddPath () | 337 void |
| 338 HwmpRtableTest::TestAddPath () |
321 { | 339 { |
322 table->AddReactivePath (dst, hop, iface, metric, expire, seqnum); | 340 table->AddReactivePath (dst, hop, iface, metric, expire, seqnum); |
323 table->AddProactivePath (metric, dst, hop, iface, expire, seqnum); | 341 table->AddProactivePath (metric, dst, hop, iface, expire, seqnum); |
324 } | 342 } |
325 void HwmpRtableTest::TestExpire () | 343 void |
| 344 HwmpRtableTest::TestExpire () |
326 { | 345 { |
327 // this is assumed to be called when path records are already expired | 346 // this is assumed to be called when path records are already expired |
328 HwmpRtable::LookupResult correct (hop, iface, metric, seqnum); | 347 HwmpRtable::LookupResult correct (hop, iface, metric, seqnum); |
329 NS_TEST_ASSERT (table->LookupReactiveExpired (dst) == correct); | 348 NS_TEST_ASSERT (table->LookupReactiveExpired (dst) == correct); |
330 NS_TEST_ASSERT (table->LookupProactiveExpired () == correct); | 349 NS_TEST_ASSERT (table->LookupProactiveExpired () == correct); |
331 | 350 |
332 NS_TEST_ASSERT (! table->LookupReactive (dst).IsValid ()); | 351 NS_TEST_ASSERT (!table->LookupReactive (dst).IsValid ()); |
333 NS_TEST_ASSERT (! table->LookupProactive ().IsValid ()); | 352 NS_TEST_ASSERT (!table->LookupProactive ().IsValid ()); |
334 } | 353 } |
335 void HwmpRtableTest::TestPrecursorAdd () | 354 void |
336 { | 355 HwmpRtableTest::TestPrecursorAdd () |
337 for (std::vector<Mac48Address>::const_iterator i = precursors.begin (); i != p
recursors.end (); i ++) | 356 { |
338 { | 357 for (std::vector<Mac48Address>::const_iterator i = precursors.begin (); i != p
recursors.end (); i++) |
339 table->AddPrecursor (dst, iface, *i); | 358 { |
340 // Check that duplicates are filtered | 359 table->AddPrecursor (dst, iface, *i); |
341 table->AddPrecursor (dst, iface, *i); | 360 // Check that duplicates are filtered |
342 } | 361 table->AddPrecursor (dst, iface, *i); |
343 } | 362 } |
344 void HwmpRtableTest::TestPrecursorFind () | 363 } |
| 364 void |
| 365 HwmpRtableTest::TestPrecursorFind () |
345 { | 366 { |
346 HwmpRtable::PrecursorList precursorList = table->GetPrecursors (dst); | 367 HwmpRtable::PrecursorList precursorList = table->GetPrecursors (dst); |
347 NS_TEST_ASSERT(precursors.size () == precursorList.size ()); | 368 NS_TEST_ASSERT (precursors.size () == precursorList.size ()); |
348 for(unsigned int i = 0; i < precursors.size (); i ++) | 369 for (unsigned int i = 0; i < precursors.size (); i++) |
349 { | 370 { |
350 NS_TEST_ASSERT(precursorList[i].first == iface); | 371 NS_TEST_ASSERT (precursorList[i].first == iface); |
351 NS_TEST_ASSERT(precursorList[i].second == precursors[i]); | 372 NS_TEST_ASSERT (precursorList[i].second == precursors[i]); |
352 } | 373 } |
353 } | 374 } |
354 bool HwmpRtableTest::RunTests () | 375 bool |
| 376 HwmpRtableTest::RunTests () |
355 { | 377 { |
356 table = CreateObject<HwmpRtable> (); | 378 table = CreateObject<HwmpRtable> (); |
357 | 379 |
358 Simulator::Schedule (Seconds (0), & HwmpRtableTest::TestLookup, this); | 380 Simulator::Schedule (Seconds (0), &HwmpRtableTest::TestLookup, this); |
359 Simulator::Schedule (Seconds (1), & HwmpRtableTest::TestAddPath, this); | 381 Simulator::Schedule (Seconds (1), &HwmpRtableTest::TestAddPath, this); |
360 Simulator::Schedule (Seconds (2), & HwmpRtableTest::TestPrecursorAdd, this); | 382 Simulator::Schedule (Seconds (2), &HwmpRtableTest::TestPrecursorAdd, this); |
361 Simulator::Schedule (expire + Seconds (2), & HwmpRtableTest::TestExpire, this)
; | 383 Simulator::Schedule (expire + Seconds (2), &HwmpRtableTest::TestExpire, this); |
362 Simulator::Schedule (expire + Seconds (3), & HwmpRtableTest::TestPrecursorFind
, this); | 384 Simulator::Schedule (expire + Seconds (3), &HwmpRtableTest::TestPrecursorFind,
this); |
363 | 385 |
364 Simulator::Run (); | 386 Simulator::Run (); |
365 Simulator::Destroy (); | 387 Simulator::Destroy (); |
366 | 388 |
367 return result; | 389 return result; |
368 } | 390 } |
369 #endif // RUN_SELF_TESTS | 391 #endif // RUN_SELF_TESTS |
370 } //namespace dot11s | 392 } //namespace dot11s |
371 } //namespace ns3 | 393 } //namespace ns3 |
LEFT | RIGHT |