author | Peter D. Barnes, Jr. <barnes26@llnl.gov> |
Wed, 15 May 2013 14:45:28 -0400 | |
changeset 9782 | ed82eb2702d0 |
parent 9293 | 854e085e1a01 |
child 9802 | 5dea58a3b261 |
permissions | -rw-r--r-- |
8751 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2011 Yufei Cheng |
|
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: Yufei Cheng <yfcheng@ittc.ku.edu> |
|
19 |
* |
|
20 |
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director |
|
21 |
* ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets |
|
22 |
* Information and Telecommunication Technology Center (ITTC) |
|
23 |
* and Department of Electrical Engineering and Computer Science |
|
24 |
* The University of Kansas Lawrence, KS USA. |
|
25 |
* |
|
26 |
* Work supported in part by NSF FIND (Future Internet Design) Program |
|
27 |
* under grant CNS-0626918 (Postmodern Internet Architecture), |
|
28 |
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI), |
|
29 |
* US Department of Defense (DoD), and ITTC at The University of Kansas. |
|
30 |
*/ |
|
31 |
||
32 |
#define NS_LOG_APPEND_CONTEXT \ |
|
33 |
if (GetObject<Node> ()) { std::clog << "[node " << GetObject<Node> ()->GetId () << "] "; } |
|
34 |
||
35 |
#include <list> |
|
36 |
#include <ctime> |
|
37 |
#include <map> |
|
38 |
||
39 |
#include "ns3/ptr.h" |
|
40 |
#include "ns3/log.h" |
|
41 |
#include "ns3/assert.h" |
|
42 |
#include "ns3/fatal-error.h" |
|
43 |
#include "ns3/node.h" |
|
44 |
#include "ns3/uinteger.h" |
|
45 |
#include "ns3/trace-source-accessor.h" |
|
46 |
#include "ns3/udp-header.h" |
|
47 |
#include "ns3/pointer.h" |
|
48 |
#include "ns3/node-list.h" |
|
49 |
#include "ns3/uinteger.h" |
|
50 |
#include "ns3/object-vector.h" |
|
51 |
#include "ns3/ipv4-l3-protocol.h" |
|
52 |
#include "ns3/ipv4-interface.h" |
|
53 |
#include "ns3/ipv4-header.h" |
|
54 |
#include "ns3/ipv4-address.h" |
|
55 |
#include "ns3/ipv4-route.h" |
|
56 |
#include "ns3/icmpv4-l4-protocol.h" |
|
8753 | 57 |
#include "ns3/ip-l4-protocol.h" |
8751 | 58 |
|
59 |
#include "dsr-option-header.h" |
|
60 |
#include "dsr-options.h" |
|
61 |
#include "dsr-rcache.h" |
|
62 |
||
63 |
NS_LOG_COMPONENT_DEFINE ("DsrOptions"); |
|
64 |
||
65 |
namespace ns3 { |
|
66 |
namespace dsr { |
|
67 |
||
68 |
NS_OBJECT_ENSURE_REGISTERED (DsrOptions); |
|
69 |
||
70 |
TypeId DsrOptions::GetTypeId () |
|
71 |
{ |
|
72 |
static TypeId tid = TypeId ("ns3::dsr::DsrOptions") |
|
73 |
.SetParent<Object> () |
|
74 |
.AddAttribute ("OptionNumber", "The Dsr option number.", |
|
75 |
UintegerValue (0), |
|
76 |
MakeUintegerAccessor (&DsrOptions::GetOptionNumber), |
|
77 |
MakeUintegerChecker<uint8_t> ()) |
|
78 |
.AddTraceSource ("Rx", "Receive DSR packet.", |
|
79 |
MakeTraceSourceAccessor (&DsrOptions::m_rxPacketTrace)) |
|
80 |
; |
|
81 |
return tid; |
|
82 |
} |
|
83 |
||
84 |
DsrOptions::DsrOptions () |
|
85 |
{ |
|
86 |
NS_LOG_FUNCTION_NOARGS (); |
|
87 |
} |
|
88 |
||
89 |
DsrOptions::~DsrOptions () |
|
90 |
{ |
|
91 |
NS_LOG_FUNCTION_NOARGS (); |
|
92 |
} |
|
93 |
||
94 |
void DsrOptions::SetNode (Ptr<Node> node) |
|
95 |
{ |
|
96 |
NS_LOG_FUNCTION (this << node); |
|
97 |
m_node = node; |
|
98 |
} |
|
99 |
||
100 |
Ptr<Node> DsrOptions::GetNode () const |
|
101 |
{ |
|
102 |
NS_LOG_FUNCTION_NOARGS (); |
|
103 |
return m_node; |
|
104 |
} |
|
105 |
||
106 |
bool DsrOptions::ContainAddressAfter (Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector<Ipv4Address> &nodeList) |
|
107 |
{ |
|
8752 | 108 |
NS_LOG_FUNCTION (this << ipv4Address << destAddress); |
8751 | 109 |
std::vector<Ipv4Address>::iterator it = find (nodeList.begin (), nodeList.end (), destAddress); |
110 |
||
111 |
for (std::vector<Ipv4Address>::iterator i = it; i != nodeList.end (); ++i) |
|
112 |
{ |
|
113 |
if ((ipv4Address == (*i)) && ((*i) != nodeList.back ())) |
|
114 |
{ |
|
115 |
return true; |
|
116 |
} |
|
117 |
} |
|
118 |
return false; |
|
119 |
} |
|
120 |
||
121 |
std::vector<Ipv4Address> |
|
122 |
DsrOptions::CutRoute (Ipv4Address ipv4Address, std::vector<Ipv4Address> &nodeList) |
|
123 |
{ |
|
8752 | 124 |
NS_LOG_FUNCTION (this << ipv4Address); |
8751 | 125 |
std::vector<Ipv4Address>::iterator it = find (nodeList.begin (), nodeList.end (), ipv4Address); |
126 |
std::vector<Ipv4Address> cutRoute; |
|
127 |
for (std::vector<Ipv4Address>::iterator i = it; i != nodeList.end (); ++i) |
|
128 |
{ |
|
129 |
cutRoute.push_back (*i); |
|
130 |
} |
|
131 |
return cutRoute; |
|
132 |
} |
|
133 |
||
134 |
Ptr<Ipv4Route> DsrOptions::SetRoute (Ipv4Address nextHop, Ipv4Address srcAddress) |
|
135 |
{ |
|
136 |
NS_LOG_FUNCTION (this << nextHop << srcAddress); |
|
137 |
m_ipv4Route = Create<Ipv4Route> (); |
|
138 |
m_ipv4Route->SetDestination (nextHop); |
|
139 |
m_ipv4Route->SetGateway (nextHop); |
|
140 |
m_ipv4Route->SetSource (srcAddress); |
|
141 |
return m_ipv4Route; |
|
142 |
} |
|
143 |
||
144 |
bool DsrOptions::ReverseRoutes (std::vector<Ipv4Address> & vec) |
|
145 |
{ |
|
8752 | 146 |
NS_LOG_FUNCTION (this); |
8751 | 147 |
std::vector<Ipv4Address> vec2 (vec); |
148 |
vec.clear (); // To ensure vec is empty before start |
|
149 |
for (std::vector<Ipv4Address>::reverse_iterator ri = vec2.rbegin (); ri |
|
150 |
!= vec2.rend (); ++ri) |
|
151 |
{ |
|
152 |
vec.push_back (*ri); |
|
153 |
} |
|
154 |
||
155 |
if ((vec.size () == vec2.size ()) && (vec.front () == vec2.back ())) |
|
156 |
{ |
|
157 |
return true; |
|
158 |
} |
|
159 |
return false; |
|
160 |
} |
|
161 |
||
162 |
Ipv4Address DsrOptions::SearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec) |
|
163 |
{ |
|
8752 | 164 |
NS_LOG_FUNCTION (this << ipv4Address); |
8751 | 165 |
Ipv4Address nextHop; |
8752 | 166 |
NS_LOG_DEBUG ("the vector size " << vec.size ()); |
8751 | 167 |
if (vec.size () == 2) |
168 |
{ |
|
169 |
NS_LOG_DEBUG ("The two nodes are neighbors"); |
|
170 |
nextHop = vec[1]; |
|
171 |
return nextHop; |
|
172 |
} |
|
173 |
else |
|
174 |
{ |
|
175 |
if (ipv4Address == vec.back ()) |
|
176 |
{ |
|
177 |
NS_LOG_DEBUG ("We have reached to the final destination " << ipv4Address << " " << vec.back ()); |
|
178 |
return ipv4Address; |
|
179 |
} |
|
8752 | 180 |
for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i) |
8751 | 181 |
{ |
182 |
if (ipv4Address == (*i)) |
|
183 |
{ |
|
184 |
nextHop = *(++i); |
|
185 |
return nextHop; |
|
186 |
} |
|
187 |
} |
|
188 |
} |
|
189 |
NS_LOG_DEBUG ("next hop address not found, route corrupted"); |
|
190 |
Ipv4Address none = "0.0.0.0"; |
|
191 |
return none; |
|
192 |
} |
|
193 |
||
194 |
Ipv4Address DsrOptions::ReverseSearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec) |
|
195 |
{ |
|
8752 | 196 |
NS_LOG_FUNCTION (this << ipv4Address); |
8751 | 197 |
Ipv4Address nextHop; |
198 |
if (vec.size () == 2) |
|
199 |
{ |
|
200 |
NS_LOG_DEBUG ("The two nodes are neighbors"); |
|
201 |
nextHop = vec[0]; |
|
202 |
return nextHop; |
|
203 |
} |
|
204 |
else |
|
205 |
{ |
|
206 |
for (std::vector<Ipv4Address>::reverse_iterator ri = vec.rbegin (); ri != vec.rend (); ++ri) |
|
207 |
{ |
|
208 |
if (ipv4Address == (*ri)) |
|
209 |
{ |
|
210 |
nextHop = *(++ri); |
|
211 |
return nextHop; |
|
212 |
} |
|
213 |
} |
|
214 |
} |
|
215 |
NS_LOG_DEBUG ("next hop address not found, route corrupted"); |
|
216 |
Ipv4Address none = "0.0.0.0"; |
|
217 |
return none; |
|
218 |
} |
|
219 |
||
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
220 |
Ipv4Address DsrOptions::ReverseSearchNextTwoHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec) |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
221 |
{ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
222 |
NS_LOG_FUNCTION (this << ipv4Address); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
223 |
Ipv4Address nextTwoHop; |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
224 |
NS_LOG_DEBUG ("The vector size " << vec.size ()); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
225 |
NS_ASSERT (vec.size () > 2); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
226 |
for (std::vector<Ipv4Address>::reverse_iterator ri = vec.rbegin (); ri != vec.rend (); ++ri) |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
227 |
{ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
228 |
if (ipv4Address == (*ri)) |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
229 |
{ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
230 |
nextTwoHop = *(ri + 2); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
231 |
return nextTwoHop; |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
232 |
} |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
233 |
} |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
234 |
NS_FATAL_ERROR ("next hop address not found, route corrupted"); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
235 |
Ipv4Address none = "0.0.0.0"; |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
236 |
return none; |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
237 |
} |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
238 |
|
8751 | 239 |
void DsrOptions::PrintVector (std::vector<Ipv4Address>& vec) |
240 |
{ |
|
8752 | 241 |
NS_LOG_FUNCTION (this); |
8751 | 242 |
/* |
243 |
* Check elements in a route vector |
|
244 |
*/ |
|
245 |
if (!vec.size ()) |
|
246 |
{ |
|
247 |
NS_LOG_DEBUG ("The vector is empty"); |
|
248 |
} |
|
249 |
else |
|
250 |
{ |
|
251 |
NS_LOG_DEBUG ("Print all the elements in a vector"); |
|
252 |
for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i) |
|
253 |
{ |
|
254 |
NS_LOG_DEBUG ("The ip address " << *i); |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
bool DsrOptions::IfDuplicates (std::vector<Ipv4Address>& vec, std::vector<Ipv4Address>& vec2) |
|
260 |
{ |
|
8752 | 261 |
NS_LOG_FUNCTION (this); |
8751 | 262 |
for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i) |
263 |
{ |
|
264 |
for (std::vector<Ipv4Address>::const_iterator j = vec2.begin (); j != vec2.end (); ++j) |
|
265 |
{ |
|
266 |
if ((*i) == (*j)) |
|
267 |
{ |
|
268 |
return true; |
|
269 |
} |
|
270 |
else |
|
271 |
{ |
|
272 |
continue; |
|
273 |
} |
|
274 |
} |
|
275 |
} |
|
276 |
return false; |
|
277 |
} |
|
278 |
||
279 |
bool DsrOptions::CheckDuplicates (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec) |
|
280 |
{ |
|
8752 | 281 |
NS_LOG_FUNCTION (this << ipv4Address); |
8751 | 282 |
for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.end (); ++i) |
283 |
{ |
|
284 |
if ((*i) == ipv4Address) |
|
285 |
{ |
|
286 |
return true; |
|
287 |
} |
|
288 |
else |
|
289 |
{ |
|
290 |
continue; |
|
291 |
} |
|
292 |
} |
|
293 |
return false; |
|
294 |
} |
|
295 |
||
296 |
void DsrOptions::RemoveDuplicates (std::vector<Ipv4Address>& vec) |
|
297 |
{ |
|
8752 | 298 |
NS_LOG_FUNCTION (this); |
8751 | 299 |
//Remove duplicate ip address from the route if any, should not happen with normal behavior nodes |
300 |
std::vector<Ipv4Address> vec2 (vec); // declare vec2 as a copy of the vec |
|
301 |
PrintVector (vec2); // Print all the ip address in the route |
|
302 |
vec.clear (); // clear vec |
|
303 |
for (std::vector<Ipv4Address>::const_iterator i = vec2.begin (); i != vec2.end (); ++i) |
|
304 |
{ |
|
305 |
if (vec.empty ()) |
|
306 |
{ |
|
307 |
vec.push_back (*i); |
|
308 |
continue; |
|
309 |
} |
|
310 |
else |
|
311 |
{ |
|
312 |
for (std::vector<Ipv4Address>::iterator j = vec.begin (); j != vec.end (); ++j) |
|
313 |
{ |
|
314 |
if ((*i) == (*j)) |
|
315 |
{ |
|
316 |
if ((j + 1) != vec.end ()) |
|
317 |
{ |
|
318 |
vec.erase (j + 1, vec.end ()); // Automatic shorten the route |
|
319 |
break; |
|
320 |
} |
|
321 |
else |
|
322 |
{ |
|
323 |
break; |
|
324 |
} |
|
325 |
} |
|
326 |
else if (j == (vec.end () - 1)) |
|
327 |
{ |
|
328 |
vec.push_back (*i); |
|
329 |
break; |
|
330 |
} |
|
331 |
else |
|
332 |
{ |
|
333 |
continue; |
|
334 |
} |
|
335 |
} |
|
336 |
} |
|
337 |
} |
|
338 |
} |
|
339 |
||
340 |
uint32_t |
|
341 |
DsrOptions::GetIDfromIP (Ipv4Address address) |
|
342 |
{ |
|
8752 | 343 |
NS_LOG_FUNCTION (this << address); |
8751 | 344 |
int32_t nNodes = NodeList::GetNNodes (); |
345 |
for (int32_t i = 0; i < nNodes; ++i) |
|
346 |
{ |
|
347 |
Ptr<Node> node = NodeList::GetNode (i); |
|
348 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
|
349 |
if (ipv4->GetAddress (1, 0).GetLocal () == address) |
|
350 |
{ |
|
351 |
return i; |
|
352 |
} |
|
353 |
} |
|
354 |
return 255; |
|
355 |
} |
|
356 |
||
357 |
Ptr<Node> DsrOptions::GetNodeWithAddress (Ipv4Address ipv4Address) |
|
358 |
{ |
|
8752 | 359 |
NS_LOG_FUNCTION (this << ipv4Address); |
8751 | 360 |
int32_t nNodes = NodeList::GetNNodes (); |
361 |
for (int32_t i = 0; i < nNodes; ++i) |
|
362 |
{ |
|
363 |
Ptr<Node> node = NodeList::GetNode (i); |
|
364 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
|
365 |
int32_t ifIndex = ipv4->GetInterfaceForAddress (ipv4Address); |
|
366 |
if (ifIndex != -1) |
|
367 |
{ |
|
368 |
return node; |
|
369 |
} |
|
370 |
} |
|
371 |
return 0; |
|
372 |
} |
|
373 |
||
374 |
NS_OBJECT_ENSURE_REGISTERED (DsrOptionPad1); |
|
375 |
||
376 |
TypeId DsrOptionPad1::GetTypeId () |
|
377 |
{ |
|
378 |
static TypeId tid = TypeId ("ns3::dsr::DsrOptionPad1") |
|
379 |
.SetParent<DsrOptions> () |
|
380 |
.AddConstructor<DsrOptionPad1> () |
|
381 |
; |
|
382 |
return tid; |
|
383 |
} |
|
384 |
||
385 |
DsrOptionPad1::DsrOptionPad1 () |
|
386 |
{ |
|
387 |
NS_LOG_FUNCTION_NOARGS (); |
|
388 |
} |
|
389 |
||
390 |
DsrOptionPad1::~DsrOptionPad1 () |
|
391 |
{ |
|
392 |
NS_LOG_FUNCTION_NOARGS (); |
|
393 |
} |
|
394 |
||
395 |
uint8_t DsrOptionPad1::GetOptionNumber () const |
|
396 |
{ |
|
397 |
NS_LOG_FUNCTION_NOARGS (); |
|
398 |
||
399 |
return OPT_NUMBER; |
|
400 |
} |
|
401 |
||
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
402 |
uint8_t DsrOptionPad1::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource) |
8751 | 403 |
{ |
404 |
NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc); |
|
405 |
Ptr<Packet> p = packet->Copy (); |
|
406 |
DsrOptionPad1Header pad1Header; |
|
407 |
p->RemoveHeader (pad1Header); |
|
408 |
||
409 |
isPromisc = false; |
|
410 |
||
411 |
return pad1Header.GetSerializedSize (); |
|
412 |
} |
|
413 |
||
414 |
NS_OBJECT_ENSURE_REGISTERED (DsrOptionPadn); |
|
415 |
||
416 |
TypeId DsrOptionPadn::GetTypeId () |
|
417 |
{ |
|
418 |
static TypeId tid = TypeId ("ns3::dsr::DsrOptionPadn") |
|
419 |
.SetParent<DsrOptions> () |
|
420 |
.AddConstructor<DsrOptionPadn> () |
|
421 |
; |
|
422 |
return tid; |
|
423 |
} |
|
424 |
||
425 |
DsrOptionPadn::DsrOptionPadn () |
|
426 |
{ |
|
427 |
NS_LOG_FUNCTION_NOARGS (); |
|
428 |
} |
|
429 |
||
430 |
DsrOptionPadn::~DsrOptionPadn () |
|
431 |
{ |
|
432 |
NS_LOG_FUNCTION_NOARGS (); |
|
433 |
} |
|
434 |
||
435 |
uint8_t DsrOptionPadn::GetOptionNumber () const |
|
436 |
{ |
|
437 |
NS_LOG_FUNCTION_NOARGS (); |
|
438 |
return OPT_NUMBER; |
|
439 |
} |
|
440 |
||
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
441 |
uint8_t DsrOptionPadn::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource) |
8751 | 442 |
{ |
443 |
NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc); |
|
444 |
||
445 |
Ptr<Packet> p = packet->Copy (); |
|
446 |
DsrOptionPadnHeader padnHeader; |
|
447 |
p->RemoveHeader (padnHeader); |
|
448 |
||
449 |
isPromisc = false; |
|
450 |
||
451 |
return padnHeader.GetSerializedSize (); |
|
452 |
} |
|
453 |
||
454 |
NS_OBJECT_ENSURE_REGISTERED (DsrOptionRreq); |
|
455 |
||
456 |
TypeId DsrOptionRreq::GetTypeId () |
|
457 |
{ |
|
458 |
static TypeId tid = TypeId ("ns3::dsr::DsrOptionRreq") |
|
459 |
.SetParent<DsrOptions> () |
|
460 |
.AddConstructor<DsrOptionRreq> () |
|
461 |
; |
|
462 |
return tid; |
|
463 |
} |
|
464 |
||
465 |
TypeId DsrOptionRreq::GetInstanceTypeId () const |
|
466 |
{ |
|
467 |
return GetTypeId (); |
|
468 |
} |
|
469 |
||
470 |
DsrOptionRreq::DsrOptionRreq () |
|
471 |
{ |
|
472 |
NS_LOG_FUNCTION_NOARGS (); |
|
473 |
} |
|
474 |
||
475 |
DsrOptionRreq::~DsrOptionRreq () |
|
476 |
{ |
|
477 |
NS_LOG_FUNCTION_NOARGS (); |
|
478 |
} |
|
479 |
||
480 |
uint8_t DsrOptionRreq::GetOptionNumber () const |
|
481 |
{ |
|
482 |
NS_LOG_FUNCTION_NOARGS (); |
|
483 |
||
484 |
return OPT_NUMBER; |
|
485 |
} |
|
486 |
||
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
487 |
uint8_t DsrOptionRreq::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource) |
8751 | 488 |
{ |
489 |
NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc); |
|
8752 | 490 |
// Fields from IP header |
491 |
Ipv4Address srcAddress = ipv4Header.GetSource (); |
|
492 |
/* |
|
493 |
* \ when the ip source address is equal to the address of our own, this is request packet originated |
|
494 |
* \ by the node itself, discard it |
|
495 |
*/ |
|
496 |
if (srcAddress == ipv4Address) |
|
497 |
{ |
|
498 |
NS_LOG_DEBUG ("Discard the packet"); |
|
499 |
m_dropTrace (packet); // call the drop trace to show in the tracing |
|
500 |
return 0; |
|
501 |
} |
|
8751 | 502 |
/* |
503 |
* Get the node associated with the ipv4 address and get several objects from the node and leave for further use |
|
504 |
*/ |
|
505 |
Ptr<Node> node = GetNodeWithAddress (ipv4Address); |
|
506 |
Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> (); |
|
507 |
||
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
508 |
Ptr<Packet> p = packet->Copy (); // Note: The packet here doesn't contain the fixed size dsr header |
8751 | 509 |
/* |
510 |
* \brief Get the number of routers' address field before removing the header |
|
511 |
* \peek the packet and get the value |
|
512 |
*/ |
|
513 |
uint8_t buf[2]; |
|
514 |
p->CopyData (buf, sizeof(buf)); |
|
515 |
uint8_t numberAddress = (buf[1] - 6) / 4; |
|
8752 | 516 |
NS_LOG_DEBUG ("The number of Ip addresses " << (uint32_t)numberAddress); |
8751 | 517 |
if (numberAddress >= 255) |
518 |
{ |
|
519 |
NS_LOG_DEBUG ("Discard the packet, malformed header since two many ip addresses in route"); |
|
520 |
m_dropTrace (packet); // call the drop trace to show in the tracing |
|
521 |
return 0; |
|
522 |
} |
|
523 |
||
524 |
/* |
|
525 |
* Create the dsr rreq header |
|
526 |
*/ |
|
527 |
DsrOptionRreqHeader rreq; |
|
528 |
/* |
|
529 |
* Set the number of addresses with the value from peek data and remove the rreq header |
|
530 |
*/ |
|
531 |
rreq.SetNumberAddress (numberAddress); |
|
8752 | 532 |
// Remove the route request header |
533 |
p->RemoveHeader (rreq); |
|
534 |
// Verify the option length |
|
535 |
uint8_t length = rreq.GetLength (); |
|
536 |
if (length % 2 != 0) |
|
8751 | 537 |
{ |
8752 | 538 |
NS_LOG_LOGIC ("Malformed header. Drop!"); |
539 |
m_dropTrace (packet); // call drop trace |
|
8751 | 540 |
return 0; |
541 |
} |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
542 |
// Check the rreq id for verifying the request id |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
543 |
uint16_t requestId = rreq.GetId (); |
8751 | 544 |
// The target address is where we want to send the data packets |
545 |
Ipv4Address targetAddress = rreq.GetTarget (); |
|
546 |
// Get the node list and source address from the route request header |
|
8752 | 547 |
std::vector<Ipv4Address> mainVector = rreq.GetNodesAddresses (); |
548 |
std::vector<Ipv4Address> nodeList (mainVector); |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
549 |
// Get the real source address of this request, it will be used when checking if we have received the save |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
550 |
// route request before or not |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
551 |
Ipv4Address sourceAddress = nodeList.front (); |
8751 | 552 |
PrintVector (nodeList); |
553 |
/* |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
554 |
* Construct the dsr routing header for later use |
8751 | 555 |
*/ |
8752 | 556 |
DsrRoutingHeader dsrRoutingHeader; |
557 |
dsrRoutingHeader.SetNextHeader (protocol); |
|
558 |
dsrRoutingHeader.SetMessageType (1); |
|
559 |
dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); |
|
560 |
dsrRoutingHeader.SetDestId (255); |
|
8751 | 561 |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
562 |
// check whether we have received this request or not, if not, it will save the request in the table for |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
563 |
// later use, if not found, return false, and push the newly received source request entry in the cache |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
564 |
|
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
565 |
bool dupRequest = dsr->FindSourceEntry (sourceAddress, targetAddress, requestId); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
566 |
/* |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
567 |
* Before processing the route request, we need to check two things |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
568 |
* 1. if this is the exact same request we have just received, ignore it |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
569 |
* 2. if our address is already in the path list, ignore it |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
570 |
* 3. otherwise process further |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
571 |
*/ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
572 |
if (dupRequest) |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
573 |
{ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
574 |
NS_LOG_DEBUG ("We have received duplicate request"); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
575 |
// We have received this same route reqeust before, not forwarding it now |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
576 |
NS_LOG_LOGIC ("Duplicate request. Drop!"); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
577 |
m_dropTrace (packet); // call drop trace |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
578 |
return 0; |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
579 |
} |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
580 |
|
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
581 |
else if (CheckDuplicates (ipv4Address, nodeList)) |
8751 | 582 |
{ |
583 |
/* |
|
584 |
* if the route contains the node address already, drop the request packet |
|
585 |
*/ |
|
586 |
m_dropTrace (packet); // call drop trace |
|
587 |
NS_LOG_DEBUG ("Our node address is already seen in the route, drop the request"); |
|
588 |
return 0; |
|
589 |
} |
|
590 |
else |
|
591 |
{ |
|
592 |
// A node ignores all RREQs received from any node in its blacklist |
|
593 |
RouteCacheEntry toPrev; |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
594 |
|
8751 | 595 |
/* |
596 |
* When the reverse route is created or updated, the following actions on the route are also carried out: |
|
597 |
* 3. the next hop in the routing table becomes the node from which the RREQ was received |
|
598 |
* 4. the hop count is copied from the Hop Count in the RREQ message; |
|
599 |
*/ |
|
600 |
||
601 |
// A node generates a RREP if either: |
|
602 |
// (i) it is itself the destination, |
|
603 |
/* |
|
604 |
* The target address equal to our own ip address |
|
605 |
*/ |
|
8752 | 606 |
NS_LOG_DEBUG ("The target address over here " << targetAddress << " and the ip address " << ipv4Address << " and the source address " << mainVector[0]); |
8751 | 607 |
if (targetAddress == ipv4Address) |
608 |
{ |
|
609 |
Ipv4Address nextHop; // Declare the next hop address to use |
|
610 |
if (nodeList.size () == 1) |
|
611 |
{ |
|
612 |
NS_LOG_DEBUG ("These two nodes are neighbors"); |
|
613 |
m_finalRoute.clear (); |
|
614 |
m_finalRoute.push_back (srcAddress); // push back the request originator's address |
|
615 |
m_finalRoute.push_back (ipv4Address); // push back our own address |
|
616 |
nextHop = srcAddress; |
|
617 |
} |
|
618 |
else |
|
619 |
{ |
|
8752 | 620 |
std::vector<Ipv4Address> changeRoute (nodeList); |
621 |
changeRoute.push_back (ipv4Address); // push back our own address |
|
8751 | 622 |
m_finalRoute.clear (); // get a clear route vector |
8752 | 623 |
for (std::vector<Ipv4Address>::iterator i = changeRoute.begin (); i != changeRoute.end (); ++i) |
8751 | 624 |
{ |
625 |
m_finalRoute.push_back (*i); // Get the full route from source to destination |
|
626 |
} |
|
627 |
PrintVector (m_finalRoute); |
|
628 |
nextHop = ReverseSearchNextHop (ipv4Address, m_finalRoute); // get the next hop |
|
629 |
} |
|
630 |
||
631 |
DsrOptionRrepHeader rrep; |
|
632 |
rrep.SetNodesAddress (m_finalRoute); // Set the node addresses in the route reply header |
|
633 |
NS_LOG_DEBUG ("The nextHop address " << nextHop); |
|
634 |
Ipv4Address replyDst = m_finalRoute.front (); |
|
635 |
/* |
|
8752 | 636 |
* This part add dsr header to the packet and send route reply packet |
8751 | 637 |
*/ |
638 |
DsrRoutingHeader dsrRoutingHeader; |
|
639 |
dsrRoutingHeader.SetNextHeader (protocol); |
|
640 |
dsrRoutingHeader.SetMessageType (1); |
|
641 |
dsrRoutingHeader.SetSourceId (GetIDfromIP (ipv4Address)); |
|
642 |
dsrRoutingHeader.SetDestId (GetIDfromIP (replyDst)); |
|
643 |
// Set the route for route reply |
|
644 |
SetRoute (nextHop, ipv4Address); |
|
645 |
||
646 |
uint8_t length = rrep.GetLength (); // Get the length of the rrep header excluding the type header |
|
647 |
dsrRoutingHeader.SetPayloadLength (length + 2); |
|
648 |
dsrRoutingHeader.AddDsrOption (rrep); |
|
649 |
Ptr<Packet> newPacket = Create<Packet> (); |
|
650 |
newPacket->AddHeader (dsrRoutingHeader); |
|
651 |
dsr->ScheduleInitialReply (newPacket, ipv4Address, nextHop, m_ipv4Route); |
|
652 |
/* |
|
653 |
* Create the route entry to the rreq originator and save it to route cache, also need to reverse the route |
|
654 |
*/ |
|
655 |
PrintVector (m_finalRoute); |
|
656 |
if (ReverseRoutes (m_finalRoute)) |
|
657 |
{ |
|
658 |
PrintVector (m_finalRoute); |
|
659 |
Ipv4Address dst = m_finalRoute.back (); |
|
660 |
bool addRoute = false; |
|
661 |
if (numberAddress > 0) |
|
662 |
{ |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8753
diff
changeset
|
663 |
RouteCacheEntry toSource (/*IP_VECTOR=*/ m_finalRoute, /*dst=*/ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8753
diff
changeset
|
664 |
dst, /*expire time=*/ ActiveRouteTimeout); |
8752 | 665 |
if (dsr->IsLinkCache ()) |
8751 | 666 |
{ |
8752 | 667 |
addRoute = dsr->AddRoute_Link (m_finalRoute, ipv4Address); |
8751 | 668 |
} |
669 |
else |
|
670 |
{ |
|
8752 | 671 |
addRoute = dsr->AddRoute (toSource); |
8751 | 672 |
} |
673 |
} |
|
674 |
else |
|
675 |
{ |
|
676 |
NS_LOG_DEBUG ("Abnormal RouteRequest"); |
|
677 |
return 0; |
|
678 |
} |
|
679 |
||
680 |
if (addRoute) |
|
681 |
{ |
|
682 |
/* |
|
683 |
* Found a route to the dst, construct the source route option header |
|
684 |
*/ |
|
685 |
DsrOptionSRHeader sourceRoute; |
|
686 |
NS_LOG_DEBUG ("The route length " << m_finalRoute.size ()); |
|
687 |
sourceRoute.SetNodesAddress (m_finalRoute); |
|
8752 | 688 |
if (dsr->IsLinkCache ()) |
8751 | 689 |
{ |
8752 | 690 |
dsr->UseExtends (m_finalRoute); |
8751 | 691 |
} |
692 |
sourceRoute.SetSegmentsLeft ((m_finalRoute.size () - 2)); |
|
8752 | 693 |
// The salvage value here is 0 |
694 |
sourceRoute.SetSalvage (0); |
|
8751 | 695 |
Ipv4Address nextHop = SearchNextHop (ipv4Address, m_finalRoute); // Get the next hop address |
696 |
NS_LOG_DEBUG ("The nextHop address " << nextHop); |
|
697 |
||
698 |
if (nextHop == "0.0.0.0") |
|
699 |
{ |
|
700 |
dsr->PacketNewRoute (dsrP, ipv4Address, dst, protocol); |
|
701 |
return 0; |
|
702 |
} |
|
703 |
SetRoute (nextHop, ipv4Address); |
|
704 |
/* |
|
8752 | 705 |
* Send the data packet from the send buffer |
8751 | 706 |
*/ |
8752 | 707 |
dsr->SendPacketFromBuffer (sourceRoute, nextHop, protocol); |
708 |
// Cancel the route request timer for destination after sending the data packet |
|
709 |
dsr->CancelRreqTimer (dst, true); |
|
710 |
} |
|
711 |
else |
|
712 |
{ |
|
713 |
NS_LOG_DEBUG ("The route is failed to add in cache"); |
|
714 |
return 0; |
|
8751 | 715 |
} |
716 |
} |
|
717 |
else |
|
718 |
{ |
|
719 |
NS_LOG_DEBUG ("Unable to reverse route"); |
|
720 |
return 0; |
|
721 |
} |
|
722 |
isPromisc = false; |
|
723 |
return rreq.GetSerializedSize (); |
|
724 |
} |
|
725 |
||
726 |
/* |
|
727 |
* (ii) or it has an active route to the destination, send reply based on request header and route cache, |
|
728 |
* need to delay based on a random value from d = H * (h - 1 + r), which can avoid possible route |
|
729 |
* reply storm. |
|
730 |
*/ |
|
8752 | 731 |
else if (dsr->LookupRoute (targetAddress, toPrev)) |
8751 | 732 |
{ |
733 |
RouteCacheEntry::IP_VECTOR ip = toPrev.GetVector (); // The route from our own route cache to dst |
|
734 |
PrintVector (ip); |
|
735 |
std::vector<Ipv4Address> saveRoute (nodeList); |
|
736 |
PrintVector (saveRoute); |
|
737 |
// Verify if the two vector contains duplicates, if so, do not use |
|
738 |
// the route found and forward the route request |
|
8752 | 739 |
if (!(IfDuplicates (ip, saveRoute))) |
8751 | 740 |
{ |
8752 | 741 |
m_finalRoute.clear (); // Clear the final route vector |
8751 | 742 |
/** |
743 |
* push back the intermediate node address from the source to this node |
|
744 |
*/ |
|
8752 | 745 |
for (std::vector<Ipv4Address>::iterator i = saveRoute.begin (); i != saveRoute.end (); ++i) |
8751 | 746 |
{ |
747 |
m_finalRoute.push_back (*i); |
|
748 |
} |
|
749 |
/** |
|
750 |
* push back the route vector we found in our route cache to destination, including this node's address |
|
751 |
*/ |
|
752 |
for (std::vector<Ipv4Address>::iterator j = ip.begin (); j != ip.end (); ++j) |
|
753 |
{ |
|
754 |
m_finalRoute.push_back (*j); |
|
755 |
} |
|
756 |
/* |
|
757 |
* Create the route entry to the rreq originator and save it to route cache, also need to reverse the route |
|
758 |
*/ |
|
759 |
bool addRoute = false; |
|
760 |
std::vector<Ipv4Address> reverseRoute (m_finalRoute); |
|
761 |
||
762 |
if (ReverseRoutes (reverseRoute)) |
|
763 |
{ |
|
764 |
saveRoute.push_back (ipv4Address); |
|
765 |
ReverseRoutes (saveRoute); |
|
8752 | 766 |
Ipv4Address dst = saveRoute.back (); |
767 |
NS_LOG_DEBUG ("This is the route save in route cache"); |
|
8751 | 768 |
PrintVector (saveRoute); |
8752 | 769 |
|
8751 | 770 |
RouteCacheEntry toSource (/*IP_VECTOR=*/ saveRoute, /*dst=*/ dst, /*expire time=*/ ActiveRouteTimeout); |
771 |
NS_ASSERT (saveRoute.front () == ipv4Address); |
|
772 |
// Add the route entry in the route cache |
|
8752 | 773 |
if (dsr->IsLinkCache ()) |
8751 | 774 |
{ |
8752 | 775 |
addRoute = dsr->AddRoute_Link (saveRoute, ipv4Address); |
8751 | 776 |
} |
777 |
else |
|
778 |
{ |
|
8752 | 779 |
addRoute = dsr->AddRoute (toSource); |
8751 | 780 |
} |
8752 | 781 |
|
8751 | 782 |
if (addRoute) |
783 |
{ |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
784 |
NS_LOG_LOGIC ("We have added the route and search send buffer for packet with destination " << dst); |
8751 | 785 |
/* |
786 |
* Found a route the dst, construct the source route option header |
|
787 |
*/ |
|
788 |
DsrOptionSRHeader sourceRoute; |
|
8752 | 789 |
PrintVector (saveRoute); |
790 |
||
791 |
sourceRoute.SetNodesAddress (saveRoute); |
|
792 |
if (dsr->IsLinkCache ()) |
|
8751 | 793 |
{ |
8752 | 794 |
dsr->UseExtends (saveRoute); |
8751 | 795 |
} |
796 |
sourceRoute.SetSegmentsLeft ((saveRoute.size () - 2)); |
|
797 |
uint8_t salvage = 0; |
|
798 |
sourceRoute.SetSalvage (salvage); |
|
8752 | 799 |
Ipv4Address nextHop = SearchNextHop (ipv4Address, saveRoute); // Get the next hop address |
8751 | 800 |
NS_LOG_DEBUG ("The nextHop address " << nextHop); |
801 |
||
802 |
if (nextHop == "0.0.0.0") |
|
803 |
{ |
|
804 |
dsr->PacketNewRoute (dsrP, ipv4Address, dst, protocol); |
|
805 |
return 0; |
|
806 |
} |
|
807 |
SetRoute (nextHop, ipv4Address); |
|
808 |
/* |
|
809 |
* Schedule the packet retry |
|
810 |
*/ |
|
8752 | 811 |
dsr->SendPacketFromBuffer (sourceRoute, nextHop, protocol); |
8751 | 812 |
// Cancel the route request timer for destination |
8752 | 813 |
dsr->CancelRreqTimer (dst, true); |
814 |
} |
|
815 |
else |
|
816 |
{ |
|
817 |
NS_LOG_DEBUG ("The route is failed to add in cache"); |
|
818 |
return 0; |
|
8751 | 819 |
} |
820 |
} |
|
821 |
else |
|
822 |
{ |
|
823 |
NS_LOG_DEBUG ("Unable to reverse the route"); |
|
8752 | 824 |
return 0; |
8751 | 825 |
} |
826 |
||
827 |
/* |
|
828 |
* Need to first pin down the next hop address before removing duplicates |
|
829 |
*/ |
|
830 |
Ipv4Address nextHop = ReverseSearchNextHop (ipv4Address, m_finalRoute); |
|
8752 | 831 |
NS_LOG_DEBUG ("The nextHop address " << nextHop); |
8751 | 832 |
/* |
833 |
* First remove the duplicate ip address to automatically shorten the route, and then reversely |
|
834 |
* search the next hop address |
|
835 |
*/ |
|
836 |
// Set the route |
|
837 |
SetRoute (nextHop, ipv4Address); |
|
838 |
||
839 |
uint16_t hops = m_finalRoute.size (); |
|
840 |
DsrOptionRrepHeader rrep; |
|
841 |
rrep.SetNodesAddress (m_finalRoute); // Set the node addresses in the route reply header |
|
842 |
// Get the real source of the reply |
|
843 |
Ipv4Address realSource = m_finalRoute.back (); |
|
8752 | 844 |
PrintVector (m_finalRoute); |
8792
8f15de62d18e
fix some logging code for optimized builds
Tom Henderson <tomh@tomh.org>
parents:
8756
diff
changeset
|
845 |
NS_LOG_DEBUG ("This is the full route from " << realSource << " to " << m_finalRoute.front ()); |
8751 | 846 |
/* |
8752 | 847 |
* This part add dsr header to the packet and send route reply packet |
8751 | 848 |
*/ |
849 |
DsrRoutingHeader dsrRoutingHeader; |
|
850 |
dsrRoutingHeader.SetNextHeader (protocol); |
|
851 |
dsrRoutingHeader.SetMessageType (1); |
|
852 |
dsrRoutingHeader.SetSourceId (GetIDfromIP (realSource)); |
|
853 |
dsrRoutingHeader.SetDestId (255); |
|
854 |
||
855 |
uint8_t length = rrep.GetLength (); // Get the length of the rrep header excluding the type header |
|
856 |
dsrRoutingHeader.SetPayloadLength (length + 2); |
|
857 |
dsrRoutingHeader.AddDsrOption (rrep); |
|
858 |
Ptr<Packet> newPacket = Create<Packet> (); |
|
859 |
newPacket->AddHeader (dsrRoutingHeader); |
|
860 |
dsr->ScheduleCachedReply (newPacket, ipv4Address, nextHop, m_ipv4Route, hops); |
|
861 |
isPromisc = false; |
|
862 |
} |
|
8752 | 863 |
else |
864 |
{ |
|
865 |
NS_LOG_DEBUG ("There is duplicate ip addresses in the two route parts"); |
|
866 |
} |
|
867 |
return rreq.GetSerializedSize (); |
|
8751 | 868 |
} |
869 |
/* |
|
870 |
* (iii) no route in any type has been found |
|
871 |
*/ |
|
872 |
else |
|
873 |
{ |
|
8752 | 874 |
mainVector.push_back (ipv4Address); |
875 |
NS_ASSERT (mainVector.front () == source); |
|
876 |
NS_LOG_DEBUG ("Print out the main vector"); |
|
877 |
PrintVector (mainVector); |
|
878 |
rreq.SetNodesAddress (mainVector); |
|
879 |
||
880 |
Ptr<Packet> errP = p->Copy (); |
|
881 |
if (errP->GetSize ()) |
|
882 |
{ |
|
883 |
NS_LOG_DEBUG ("Error header included"); |
|
884 |
DsrOptionRerrUnreachHeader rerr; |
|
885 |
p->RemoveHeader (rerr); |
|
886 |
Ipv4Address errorSrc = rerr.GetErrorSrc (); |
|
887 |
Ipv4Address unreachNode = rerr.GetUnreachNode (); |
|
888 |
Ipv4Address errorDst = rerr.GetErrorDst (); |
|
889 |
||
890 |
if ((errorSrc == srcAddress) && (unreachNode == ipv4Address)) |
|
891 |
{ |
|
892 |
NS_LOG_DEBUG ("The error link back to work again"); |
|
893 |
uint16_t length = rreq.GetLength (); |
|
894 |
NS_LOG_DEBUG ("The RREQ header length " << length); |
|
895 |
dsrRoutingHeader.AddDsrOption (rreq); |
|
896 |
dsrRoutingHeader.SetPayloadLength (length + 2); |
|
897 |
} |
|
898 |
else |
|
899 |
{ |
|
900 |
dsr->DeleteAllRoutesIncludeLink (errorSrc, unreachNode, ipv4Address); |
|
901 |
||
902 |
DsrOptionRerrUnreachHeader newUnreach; |
|
903 |
newUnreach.SetErrorType (1); |
|
904 |
newUnreach.SetErrorSrc (errorSrc); |
|
905 |
newUnreach.SetUnreachNode (unreachNode); |
|
906 |
newUnreach.SetErrorDst (errorDst); |
|
907 |
newUnreach.SetSalvage (rerr.GetSalvage ()); // Set the value about whether to salvage a packet or not |
|
908 |
uint16_t length = rreq.GetLength () + newUnreach.GetLength (); |
|
909 |
NS_LOG_DEBUG ("The RREQ and newUnreach header length " << length); |
|
910 |
dsrRoutingHeader.SetPayloadLength (length + 4); |
|
911 |
dsrRoutingHeader.AddDsrOption (rreq); |
|
912 |
dsrRoutingHeader.AddDsrOption (newUnreach); |
|
913 |
} |
|
914 |
} |
|
915 |
else |
|
916 |
{ |
|
917 |
uint16_t length = rreq.GetLength (); |
|
918 |
NS_LOG_DEBUG ("The RREQ header length " << length); |
|
919 |
dsrRoutingHeader.AddDsrOption (rreq); |
|
920 |
dsrRoutingHeader.SetPayloadLength (length + 2); |
|
921 |
} |
|
922 |
// Get the TTL value |
|
923 |
uint8_t ttl = ipv4Header.GetTtl (); |
|
8751 | 924 |
/* |
925 |
* Decrease the TTL value in the packet tag by one, this tag will go to ip layer 3 send function |
|
926 |
* and drop packet when TTL value equals to 0 |
|
927 |
*/ |
|
8752 | 928 |
NS_LOG_DEBUG ("The ttl value here " << (uint32_t)ttl); |
8751 | 929 |
if (ttl) |
930 |
{ |
|
931 |
Ptr<Packet> interP = Create<Packet> (); |
|
932 |
SocketIpTtlTag tag; |
|
933 |
tag.SetTtl (ttl - 1); |
|
934 |
interP->AddPacketTag (tag); |
|
8752 | 935 |
interP->AddHeader (dsrRoutingHeader); |
8751 | 936 |
dsr->ScheduleInterRequest (interP); |
937 |
isPromisc = false; |
|
938 |
} |
|
8752 | 939 |
return rreq.GetSerializedSize (); |
8751 | 940 |
} |
941 |
} |
|
9782
ed82eb2702d0
[Coverity] Structurally dead code (UNREACHABLE)
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
9293
diff
changeset
|
942 |
//unreachable: return rreq.GetSerializedSize (); |
8751 | 943 |
} |
944 |
||
945 |
NS_OBJECT_ENSURE_REGISTERED (DsrOptionRrep); |
|
946 |
||
947 |
TypeId DsrOptionRrep::GetTypeId () |
|
948 |
{ |
|
949 |
static TypeId tid = TypeId ("ns3::dsr::DsrOptionRrep") |
|
950 |
.SetParent<DsrOptions> () |
|
951 |
.AddConstructor<DsrOptionRrep> () |
|
952 |
; |
|
953 |
return tid; |
|
954 |
} |
|
955 |
||
956 |
DsrOptionRrep::DsrOptionRrep () |
|
957 |
{ |
|
958 |
NS_LOG_FUNCTION_NOARGS (); |
|
959 |
} |
|
960 |
||
961 |
DsrOptionRrep::~DsrOptionRrep () |
|
962 |
{ |
|
963 |
NS_LOG_FUNCTION_NOARGS (); |
|
964 |
} |
|
965 |
||
966 |
TypeId DsrOptionRrep::GetInstanceTypeId () const |
|
967 |
{ |
|
968 |
return GetTypeId (); |
|
969 |
} |
|
970 |
||
971 |
uint8_t DsrOptionRrep::GetOptionNumber () const |
|
972 |
{ |
|
973 |
NS_LOG_FUNCTION_NOARGS (); |
|
974 |
||
975 |
return OPT_NUMBER; |
|
976 |
} |
|
977 |
||
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
978 |
uint8_t DsrOptionRrep::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource) |
8751 | 979 |
{ |
980 |
NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc); |
|
981 |
||
982 |
Ptr<Packet> p = packet->Copy (); |
|
983 |
||
984 |
// Get the number of routers' address field |
|
985 |
uint8_t buf[2]; |
|
986 |
p->CopyData (buf, sizeof(buf)); |
|
987 |
uint8_t numberAddress = (buf[1] - 2) / 4; |
|
988 |
||
989 |
DsrOptionRrepHeader rrep; |
|
990 |
rrep.SetNumberAddress (numberAddress); // Set the number of ip address in the header to reserver space for deserialize header |
|
991 |
p->RemoveHeader (rrep); |
|
992 |
||
993 |
Ptr<Node> node = GetNodeWithAddress (ipv4Address); |
|
994 |
Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> (); |
|
995 |
||
996 |
NS_LOG_DEBUG ("The next header value " << (uint32_t)protocol); |
|
997 |
||
998 |
std::vector<Ipv4Address> nodeList = rrep.GetNodesAddress (); |
|
8752 | 999 |
/** |
8751 | 1000 |
* Get the destination address, which is the last element in the nodeList |
1001 |
*/ |
|
1002 |
Ipv4Address targetAddress = nodeList.front (); |
|
1003 |
// If the RREP option has reached to the destination |
|
1004 |
if (targetAddress == ipv4Address) |
|
1005 |
{ |
|
1006 |
RemoveDuplicates (nodeList); // This is for the route reply from intermediate node since we didn't remove |
|
1007 |
// duplicate there |
|
1008 |
if (nodeList.size () == 0) |
|
1009 |
{ |
|
1010 |
NS_LOG_DEBUG ("The route we have contains 0 entries"); |
|
1011 |
return 0; |
|
1012 |
} |
|
8752 | 1013 |
/** |
8751 | 1014 |
* Get the destination address for the data packet, which is the last element in the nodeList |
1015 |
*/ |
|
1016 |
Ipv4Address dst = nodeList.back (); |
|
8752 | 1017 |
/** |
8751 | 1018 |
* Add the newly found route to the route cache |
1019 |
* The route looks like: |
|
1020 |
* \\ "srcAddress" + "intermediate node address" + "targetAddress" |
|
1021 |
*/ |
|
1022 |
RouteCacheEntry toDestination (/*IP_VECTOR=*/ nodeList, /*dst=*/ dst, /*expire time=*/ ActiveRouteTimeout); |
|
1023 |
NS_ASSERT (nodeList.front () == ipv4Address); |
|
1024 |
bool addRoute = false; |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8753
diff
changeset
|
1025 |
if (dsr->IsLinkCache ()) |
8751 | 1026 |
{ |
8752 | 1027 |
addRoute = dsr->AddRoute_Link (nodeList, ipv4Address); |
8751 | 1028 |
} |
1029 |
else |
|
1030 |
{ |
|
8752 | 1031 |
addRoute = dsr->AddRoute (toDestination); |
8751 | 1032 |
} |
8752 | 1033 |
|
8751 | 1034 |
if (addRoute) |
1035 |
{ |
|
1036 |
NS_LOG_DEBUG ("We have added the route and search send buffer for packet with destination " << dst); |
|
8752 | 1037 |
/** |
8751 | 1038 |
* Found a route the dst, construct the source route option header |
1039 |
*/ |
|
1040 |
DsrOptionSRHeader sourceRoute; |
|
1041 |
NS_LOG_DEBUG ("The route length " << nodeList.size ()); |
|
1042 |
sourceRoute.SetNodesAddress (nodeList); |
|
1043 |
sourceRoute.SetSegmentsLeft ((nodeList.size () - 2)); |
|
8752 | 1044 |
sourceRoute.SetSalvage (0); |
8751 | 1045 |
Ipv4Address nextHop = SearchNextHop (ipv4Address, nodeList); // Get the next hop address |
1046 |
NS_LOG_DEBUG ("The nextHop address " << nextHop); |
|
1047 |
if (nextHop == "0.0.0.0") |
|
1048 |
{ |
|
1049 |
dsr->PacketNewRoute (dsrP, ipv4Address, dst, protocol); |
|
1050 |
return 0; |
|
1051 |
} |
|
1052 |
PrintVector (nodeList); |
|
1053 |
SetRoute (nextHop, ipv4Address); |
|
8752 | 1054 |
// Cancel the route request timer for destination |
1055 |
dsr->CancelRreqTimer (dst, true); |
|
1056 |
/** |
|
8751 | 1057 |
* Schedule the packet retry |
1058 |
*/ |
|
8752 | 1059 |
dsr->SendPacketFromBuffer (sourceRoute, nextHop, protocol); |
1060 |
} |
|
1061 |
else |
|
1062 |
{ |
|
1063 |
NS_LOG_DEBUG ("Failed to add the route"); |
|
1064 |
return 0; |
|
8751 | 1065 |
} |
1066 |
} |
|
1067 |
else |
|
1068 |
{ |
|
1069 |
uint8_t length = rrep.GetLength () - 2; // The get length - 2 is to get aligned for the malformed header check |
|
1070 |
NS_LOG_DEBUG ("The length of rrep option " << (uint32_t)length); |
|
1071 |
||
1072 |
if (length % 2 != 0) |
|
1073 |
{ |
|
1074 |
NS_LOG_LOGIC ("Malformed header. Drop!"); |
|
1075 |
m_dropTrace (packet); |
|
1076 |
return 0; |
|
1077 |
} |
|
1078 |
PrintVector (nodeList); |
|
1079 |
/* |
|
1080 |
* This node is only an intermediate node, but it needs to save the possible route to the destination when cutting the route |
|
1081 |
*/ |
|
1082 |
std::vector<Ipv4Address> routeCopy = nodeList; |
|
1083 |
std::vector<Ipv4Address> cutRoute = CutRoute (ipv4Address, nodeList); |
|
1084 |
PrintVector (cutRoute); |
|
1085 |
if (cutRoute.size () >= 2) |
|
1086 |
{ |
|
1087 |
Ipv4Address dst = cutRoute.back (); |
|
1088 |
NS_LOG_DEBUG ("The route destination after cut " << dst); |
|
1089 |
RouteCacheEntry toDestination (/*IP_VECTOR=*/ cutRoute, /*dst=*/ dst, /*expire time=*/ ActiveRouteTimeout); |
|
1090 |
NS_ASSERT (cutRoute.front () == ipv4Address); |
|
1091 |
bool addRoute = false; |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8753
diff
changeset
|
1092 |
if (dsr->IsLinkCache ()) |
8751 | 1093 |
{ |
8752 | 1094 |
addRoute = dsr->AddRoute_Link (nodeList, ipv4Address); |
8751 | 1095 |
} |
1096 |
else |
|
1097 |
{ |
|
8752 | 1098 |
addRoute = dsr->AddRoute (toDestination); |
8751 | 1099 |
} |
1100 |
if (addRoute) |
|
1101 |
{ |
|
8752 | 1102 |
dsr->CancelRreqTimer (dst, true); |
8751 | 1103 |
} |
1104 |
else |
|
1105 |
{ |
|
1106 |
NS_LOG_DEBUG ("The route not added"); |
|
1107 |
} |
|
1108 |
} |
|
1109 |
else |
|
1110 |
{ |
|
1111 |
NS_LOG_DEBUG ("The route is corrupted"); |
|
1112 |
} |
|
1113 |
/* |
|
1114 |
* Reverse search the vector for next hop address |
|
1115 |
*/ |
|
1116 |
Ipv4Address nextHop = ReverseSearchNextHop (ipv4Address, routeCopy); |
|
1117 |
NS_ASSERT (routeCopy.back () == source); |
|
1118 |
PrintVector (routeCopy); |
|
1119 |
NS_LOG_DEBUG ("The nextHop address " << nextHop << " and the source in the route reply " << source); |
|
1120 |
/* |
|
1121 |
* Set the route entry we will use to send reply |
|
1122 |
*/ |
|
1123 |
SetRoute (nextHop, ipv4Address); |
|
1124 |
/* |
|
1125 |
* This part add dsr routing header to the packet and send reply |
|
1126 |
*/ |
|
1127 |
DsrRoutingHeader dsrRoutingHeader; |
|
1128 |
dsrRoutingHeader.SetNextHeader (protocol); |
|
1129 |
||
1130 |
length = rrep.GetLength (); // Get the length of the rrep header excluding the type header |
|
1131 |
NS_LOG_DEBUG ("The reply header length " << (uint32_t)length); |
|
1132 |
dsrRoutingHeader.SetPayloadLength (length + 2); |
|
1133 |
dsrRoutingHeader.SetMessageType (1); |
|
1134 |
dsrRoutingHeader.SetSourceId (GetIDfromIP (source)); |
|
1135 |
dsrRoutingHeader.SetDestId (GetIDfromIP (targetAddress)); |
|
1136 |
dsrRoutingHeader.AddDsrOption (rrep); |
|
1137 |
Ptr<Packet> newPacket = Create<Packet> (); |
|
1138 |
newPacket->AddHeader (dsrRoutingHeader); |
|
1139 |
dsr->SendReply (newPacket, ipv4Address, nextHop, m_ipv4Route); |
|
1140 |
isPromisc = false; |
|
1141 |
} |
|
1142 |
return rrep.GetSerializedSize (); |
|
1143 |
} |
|
1144 |
||
1145 |
NS_OBJECT_ENSURE_REGISTERED (DsrOptionSR); |
|
1146 |
||
1147 |
TypeId DsrOptionSR::GetTypeId () |
|
1148 |
{ |
|
1149 |
static TypeId tid = TypeId ("ns3::dsr::DsrOptionSR") |
|
1150 |
.SetParent<DsrOptions> () |
|
1151 |
.AddConstructor<DsrOptionSR> () |
|
1152 |
; |
|
1153 |
return tid; |
|
1154 |
} |
|
1155 |
||
1156 |
DsrOptionSR::DsrOptionSR () |
|
1157 |
{ |
|
1158 |
NS_LOG_FUNCTION_NOARGS (); |
|
1159 |
} |
|
1160 |
||
1161 |
DsrOptionSR::~DsrOptionSR () |
|
1162 |
{ |
|
1163 |
NS_LOG_FUNCTION_NOARGS (); |
|
1164 |
} |
|
1165 |
||
1166 |
TypeId DsrOptionSR::GetInstanceTypeId () const |
|
1167 |
{ |
|
1168 |
return GetTypeId (); |
|
1169 |
} |
|
1170 |
||
1171 |
uint8_t DsrOptionSR::GetOptionNumber () const |
|
1172 |
{ |
|
1173 |
NS_LOG_FUNCTION_NOARGS (); |
|
1174 |
return OPT_NUMBER; |
|
1175 |
} |
|
1176 |
||
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1177 |
uint8_t DsrOptionSR::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource) |
8751 | 1178 |
{ |
1179 |
NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Address << ipv4Header << (uint32_t)protocol << isPromisc); |
|
1180 |
Ptr<Packet> p = packet->Copy (); |
|
1181 |
// Get the number of routers' address field |
|
1182 |
uint8_t buf[2]; |
|
1183 |
p->CopyData (buf, sizeof(buf)); |
|
1184 |
uint8_t numberAddress = (buf[1] - 2) / 4; |
|
1185 |
DsrOptionSRHeader sourceRoute; |
|
1186 |
sourceRoute.SetNumberAddress (numberAddress); |
|
1187 |
p->RemoveHeader (sourceRoute); |
|
1188 |
||
1189 |
// The route size saved in the source route |
|
1190 |
std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress (); |
|
1191 |
uint8_t segsLeft = sourceRoute.GetSegmentsLeft (); |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1192 |
/// TODO remove this one later |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1193 |
NS_LOG_DEBUG ("The segment left here " << (uint32_t) segsLeft); |
8751 | 1194 |
uint8_t salvage = sourceRoute.GetSalvage (); |
1195 |
/* |
|
1196 |
* Get the node from IP address and get the DSR extension object |
|
1197 |
*/ |
|
1198 |
Ptr<Node> node = GetNodeWithAddress (ipv4Address); |
|
1199 |
Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> (); |
|
1200 |
/* |
|
1201 |
* Get the source and destination address from ipv4 header |
|
1202 |
*/ |
|
1203 |
Ipv4Address srcAddress = ipv4Header.GetSource (); |
|
1204 |
Ipv4Address destAddress = ipv4Header.GetDestination (); |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1205 |
|
8751 | 1206 |
// Get the node list destination |
1207 |
Ipv4Address destination = nodeList.back (); |
|
1208 |
/* |
|
1209 |
* If it's a promiscuous receive data packet, |
|
1210 |
* 1. see if automatic route shortening possible or not |
|
1211 |
* 2. see if it is a passive acknowledgment |
|
1212 |
*/ |
|
1213 |
if (isPromisc) |
|
1214 |
{ |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1215 |
NS_LOG_LOGIC ("We process promiscuous receipt data packet"); |
8751 | 1216 |
if (ContainAddressAfter (ipv4Address, destAddress, nodeList)) |
1217 |
{ |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1218 |
NS_LOG_LOGIC ("Send back the gratuitous reply"); |
8751 | 1219 |
dsr->SendGratuitousReply (source, srcAddress, nodeList, protocol); |
1220 |
} |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1221 |
|
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1222 |
uint16_t fragmentOffset = ipv4Header.GetFragmentOffset (); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1223 |
uint16_t identification = ipv4Header.GetIdentification (); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1224 |
|
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1225 |
/// TODO add the link ack over here |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1226 |
|
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1227 |
if (destAddress != destination) |
8751 | 1228 |
{ |
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1229 |
NS_LOG_DEBUG ("Process the promiscuously received packet"); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1230 |
bool findPassive = false; |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1231 |
int32_t nNodes = NodeList::GetNNodes (); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1232 |
for (int32_t i = 0; i < nNodes; ++i) |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1233 |
{ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1234 |
NS_LOG_DEBUG ("Working with node " << i); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1235 |
|
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1236 |
Ptr<Node> node = NodeList::GetNode (i); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1237 |
Ptr<dsr::DsrRouting> dsrNode = node->GetObject<dsr::DsrRouting> (); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1238 |
// The source and destination addresses here are the real source and destination for the packet |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1239 |
findPassive = dsrNode->PassiveEntryCheck (packet, source, destination, segsLeft, fragmentOffset, identification, false); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1240 |
if (findPassive) |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1241 |
{ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1242 |
break; |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1243 |
} |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1244 |
} |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1245 |
|
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1246 |
if (findPassive) |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1247 |
{ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1248 |
NS_LOG_DEBUG ("We find one previously received passive entry"); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1249 |
/* |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1250 |
* Get the node from IP address and get the DSR extension object |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1251 |
* the srcAddress would be the source address from ip header |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1252 |
*/ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1253 |
PrintVector (nodeList); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1254 |
|
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1255 |
NS_LOG_DEBUG ("promisc source " << promiscSource); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1256 |
Ptr<Node> node = GetNodeWithAddress (promiscSource); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1257 |
Ptr<dsr::DsrRouting> dsrSrc = node->GetObject<dsr::DsrRouting> (); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1258 |
|
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1259 |
/// TODO need to think about this part |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1260 |
/// TODO this is temporarily disabled to enable other |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1261 |
dsrSrc->CancelPassiveTimer (packet, source, destination, segsLeft); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1262 |
} |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1263 |
else |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1264 |
{ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1265 |
NS_LOG_DEBUG ("Saved the entry for further use"); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1266 |
dsr->PassiveEntryCheck (packet, source, destination, segsLeft, fragmentOffset, identification, true); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1267 |
} |
8751 | 1268 |
} |
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1269 |
/// Safely terminate promiscuously received packet |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1270 |
return 0; |
8751 | 1271 |
} |
1272 |
else |
|
1273 |
{ |
|
1274 |
/* |
|
1275 |
* Get the number of address from the source route header |
|
1276 |
*/ |
|
1277 |
uint8_t length = sourceRoute.GetLength (); |
|
1278 |
uint8_t nextAddressIndex; |
|
1279 |
Ipv4Address nextAddress; |
|
8752 | 1280 |
|
1281 |
// Get the option type value |
|
1282 |
uint32_t size = p->GetSize (); |
|
1283 |
uint8_t *data = new uint8_t[size]; |
|
1284 |
p->CopyData (data, size); |
|
1285 |
uint8_t optionType = 0; |
|
1286 |
optionType = *(data); |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1287 |
/// When the option type is 160, means there is ACK request header after the source route, we need |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1288 |
/// to send back acknowledgment |
8752 | 1289 |
if (optionType == 160) |
1290 |
{ |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1291 |
NS_LOG_LOGIC ("Remove the ack request header and add ack header to the packet"); |
8752 | 1292 |
// Here we remove the ack packet to the previous hop |
1293 |
DsrOptionAckReqHeader ackReq; |
|
1294 |
p->RemoveHeader (ackReq); |
|
1295 |
uint16_t ackId = ackReq.GetAckId (); |
|
1296 |
/* |
|
1297 |
* Send back acknowledgment packet to the earlier hop |
|
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1298 |
* If the node list is not empty, find the previous hop from the node list, |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1299 |
* otherwise, use srcAddress |
8752 | 1300 |
*/ |
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1301 |
Ipv4Address ackAddress = srcAddress; |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1302 |
if (!nodeList.empty ()) |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1303 |
{ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1304 |
if (segsLeft > numberAddress) // The segmentsLeft field should not be larger than the total number of ip addresses |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1305 |
{ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1306 |
NS_LOG_LOGIC ("Malformed header. Drop!"); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1307 |
m_dropTrace (packet); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1308 |
return 0; |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1309 |
} |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1310 |
if (numberAddress - segsLeft - 2 < 0) // The index is invalid |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1311 |
{ |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1312 |
NS_LOG_LOGIC ("Malformed header. Drop!"); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1313 |
m_dropTrace (packet); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1314 |
return 0; |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1315 |
} |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1316 |
ackAddress = nodeList[numberAddress - segsLeft - 2]; |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1317 |
} |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1318 |
m_ipv4Route = SetRoute (ackAddress, ipv4Address); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1319 |
NS_LOG_DEBUG ("Send back ACK to the earlier hop " << ackAddress << " from us " << ipv4Address); |
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1320 |
dsr->SendAck (ackId, ackAddress, source, destination, protocol, m_ipv4Route); |
8752 | 1321 |
} |
8751 | 1322 |
/* |
1323 |
* After send back ACK, check if the segments left value has turned to 0 or not, if yes, update the route entry |
|
1324 |
* and return header length |
|
1325 |
*/ |
|
1326 |
if (segsLeft == 0) |
|
1327 |
{ |
|
8752 | 1328 |
NS_LOG_DEBUG ("This is the final destination"); |
8751 | 1329 |
isPromisc = false; |
1330 |
return sourceRoute.GetSerializedSize (); |
|
1331 |
} |
|
1332 |
||
1333 |
if (length % 2 != 0) |
|
1334 |
{ |
|
1335 |
NS_LOG_LOGIC ("Malformed header. Drop!"); |
|
1336 |
m_dropTrace (packet); |
|
1337 |
return 0; |
|
1338 |
} |
|
1339 |
||
1340 |
if (segsLeft > numberAddress) // The segmentsLeft field should not be larger than the total number of ip addresses |
|
1341 |
{ |
|
1342 |
NS_LOG_LOGIC ("Malformed header. Drop!"); |
|
1343 |
m_dropTrace (packet); |
|
1344 |
return 0; |
|
1345 |
} |
|
1346 |
||
1347 |
DsrOptionSRHeader newSourceRoute; |
|
1348 |
newSourceRoute.SetSegmentsLeft (segsLeft - 1); |
|
1349 |
newSourceRoute.SetSalvage (salvage); |
|
1350 |
newSourceRoute.SetNodesAddress (nodeList); |
|
1351 |
nextAddressIndex = numberAddress - segsLeft; |
|
1352 |
nextAddress = newSourceRoute.GetNodeAddress (nextAddressIndex); |
|
1353 |
NS_LOG_DEBUG ("The next address of source route option " << nextAddress << " and the nextAddressIndex: " << (uint32_t)nextAddressIndex << " and the segments left : " << (uint32_t)segsLeft); |
|
1354 |
/* |
|
1355 |
* Get the target Address in the node list |
|
1356 |
*/ |
|
1357 |
Ipv4Address targetAddress = nodeList.back (); |
|
1358 |
Ipv4Address realSource = nodeList.front (); |
|
1359 |
/* |
|
1360 |
* Search the vector for next hop address |
|
1361 |
*/ |
|
1362 |
Ipv4Address nextHop = SearchNextHop (ipv4Address, nodeList); |
|
1363 |
PrintVector (nodeList); |
|
1364 |
||
1365 |
if (nextHop == "0.0.0.0") |
|
1366 |
{ |
|
1367 |
NS_LOG_DEBUG ("Before new packet " << *dsrP); |
|
1368 |
dsr->PacketNewRoute (dsrP, realSource, targetAddress, protocol); |
|
1369 |
return 0; |
|
1370 |
} |
|
1371 |
||
1372 |
if (ipv4Address == nextHop) |
|
1373 |
{ |
|
1374 |
NS_LOG_DEBUG ("We have reached the destination"); |
|
1375 |
newSourceRoute.SetSegmentsLeft (0); |
|
1376 |
return newSourceRoute.GetSerializedSize (); |
|
1377 |
} |
|
1378 |
// Verify the multicast address, leave it here for now |
|
1379 |
if (nextAddress.IsMulticast () || destAddress.IsMulticast ()) |
|
1380 |
{ |
|
1381 |
m_dropTrace (packet); |
|
1382 |
return 0; |
|
1383 |
} |
|
1384 |
// Set the route and forward the data packet |
|
1385 |
SetRoute (nextAddress, ipv4Address); |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8753
diff
changeset
|
1386 |
NS_LOG_DEBUG ("dsr packet size " << dsrP->GetSize ()); |
8751 | 1387 |
dsr->ForwardPacket (dsrP, newSourceRoute, ipv4Header, realSource, nextAddress, targetAddress, protocol, m_ipv4Route); |
1388 |
} |
|
1389 |
return sourceRoute.GetSerializedSize (); |
|
1390 |
} |
|
1391 |
||
1392 |
NS_OBJECT_ENSURE_REGISTERED (DsrOptionRerr); |
|
1393 |
||
1394 |
TypeId DsrOptionRerr::GetTypeId () |
|
1395 |
{ |
|
1396 |
static TypeId tid = TypeId ("ns3::dsr::DsrOptionRerr") |
|
1397 |
.SetParent<DsrOptions> () |
|
1398 |
.AddConstructor<DsrOptionRerr> () |
|
1399 |
; |
|
1400 |
return tid; |
|
1401 |
} |
|
1402 |
||
1403 |
DsrOptionRerr::DsrOptionRerr () |
|
1404 |
{ |
|
1405 |
NS_LOG_FUNCTION_NOARGS (); |
|
1406 |
} |
|
1407 |
||
1408 |
DsrOptionRerr::~DsrOptionRerr () |
|
1409 |
{ |
|
1410 |
NS_LOG_FUNCTION_NOARGS (); |
|
1411 |
} |
|
1412 |
||
1413 |
TypeId DsrOptionRerr::GetInstanceTypeId () const |
|
1414 |
{ |
|
1415 |
return GetTypeId (); |
|
1416 |
} |
|
1417 |
||
1418 |
uint8_t DsrOptionRerr::GetOptionNumber () const |
|
1419 |
{ |
|
1420 |
NS_LOG_FUNCTION_NOARGS (); |
|
1421 |
return OPT_NUMBER; |
|
1422 |
} |
|
1423 |
||
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1424 |
uint8_t DsrOptionRerr::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource) |
8751 | 1425 |
{ |
1426 |
NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc); |
|
1427 |
Ptr<Packet> p = packet->Copy (); |
|
1428 |
uint32_t size = p->GetSize (); |
|
1429 |
uint8_t *data = new uint8_t[size]; |
|
1430 |
p->CopyData (data, size); |
|
1431 |
uint8_t errorType = *(data + 2); |
|
1432 |
/* |
|
1433 |
* Get the node from Ip address and get the dsr extension object |
|
1434 |
*/ |
|
1435 |
Ptr<Node> node = GetNodeWithAddress (ipv4Address); |
|
1436 |
Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> (); |
|
1437 |
/* |
|
1438 |
* The error serialized size |
|
1439 |
*/ |
|
1440 |
uint32_t rerrSize; |
|
8752 | 1441 |
NS_LOG_DEBUG ("The error type value here " << (uint32_t)errorType); |
8751 | 1442 |
if (errorType == 1) // unreachable ip address |
1443 |
{ |
|
1444 |
/* |
|
1445 |
* Remove the route error header from the packet, and get the error type |
|
1446 |
*/ |
|
1447 |
DsrOptionRerrUnreachHeader rerrUnreach; |
|
1448 |
p->RemoveHeader (rerrUnreach); |
|
1449 |
/* |
|
1450 |
* Get the error destination address |
|
1451 |
*/ |
|
1452 |
Ipv4Address unreachAddress = rerrUnreach.GetUnreachNode (); |
|
1453 |
Ipv4Address errorSource = rerrUnreach.GetErrorSrc (); |
|
1454 |
||
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1455 |
NS_LOG_DEBUG ("The error source is " << rerrUnreach.GetErrorDst () << "and the unreachable node is " << unreachAddress); |
8751 | 1456 |
/* |
1457 |
* Get the serialized size of the rerr header |
|
1458 |
*/ |
|
1459 |
rerrSize = rerrUnreach.GetSerializedSize (); |
|
1460 |
/* |
|
1461 |
* Delete all the routes including the unreachable node address from the route cache |
|
1462 |
*/ |
|
1463 |
Ptr<Node> node = GetNodeWithAddress (ipv4Address); |
|
8752 | 1464 |
dsr->DeleteAllRoutesIncludeLink (errorSource, unreachAddress, ipv4Address); |
8751 | 1465 |
|
1466 |
Ptr<Packet> newP = p->Copy (); |
|
1467 |
uint32_t serialized = DoSendError (newP, rerrUnreach, rerrSize, ipv4Address, protocol); |
|
1468 |
return serialized; |
|
1469 |
} |
|
1470 |
else |
|
1471 |
{ |
|
1472 |
/* |
|
1473 |
* Two other type of error headers: |
|
1474 |
* 1. flow state not supported type-specific information |
|
1475 |
* 2. unsupported option with option number |
|
1476 |
*/ |
|
1477 |
/* |
|
1478 |
* Remove the route error header from the packet, and get the error type |
|
1479 |
*/ |
|
1480 |
DsrOptionRerrUnsupportHeader rerrUnsupport; |
|
1481 |
p->RemoveHeader (rerrUnsupport); |
|
1482 |
rerrSize = rerrUnsupport.GetSerializedSize (); |
|
1483 |
||
8752 | 1484 |
// This is for the other two error options, not supporting for now TODO |
8751 | 1485 |
// uint32_t serialized = DoSendError (p, rerrUnsupport, rerrSize, ipv4Address, protocol); |
1486 |
uint32_t serialized = 0; |
|
1487 |
return serialized; |
|
1488 |
} |
|
1489 |
} |
|
1490 |
||
1491 |
uint8_t DsrOptionRerr::DoSendError (Ptr<Packet> p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol) |
|
1492 |
{ |
|
1493 |
// Get the number of routers' address field |
|
1494 |
uint8_t buf[2]; |
|
1495 |
p->CopyData (buf, sizeof(buf)); |
|
1496 |
uint8_t numberAddress = (buf[1] - 2) / 4; |
|
1497 |
||
1498 |
// Here remove the source route header and schedule next hop error transmission |
|
1499 |
NS_LOG_DEBUG ("The number of addresses " << (uint32_t)numberAddress); |
|
1500 |
DsrOptionSRHeader sourceRoute; |
|
1501 |
sourceRoute.SetNumberAddress (numberAddress); |
|
1502 |
p->RemoveHeader (sourceRoute); |
|
1503 |
NS_ASSERT (p->GetSize () == 0); |
|
1504 |
/* |
|
1505 |
* Get the node from ip address and the dsr extension object |
|
1506 |
*/ |
|
1507 |
Ptr<Node> node = GetNodeWithAddress (ipv4Address); |
|
1508 |
Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> (); |
|
1509 |
/* |
|
1510 |
* Get the segments left field and the next address |
|
1511 |
*/ |
|
1512 |
uint8_t segmentsLeft = sourceRoute.GetSegmentsLeft (); |
|
1513 |
uint8_t length = sourceRoute.GetLength (); |
|
1514 |
uint8_t nextAddressIndex; |
|
1515 |
Ipv4Address nextAddress; |
|
1516 |
/* |
|
1517 |
* Get the route size and the error target address |
|
1518 |
*/ |
|
1519 |
std::vector<Ipv4Address> nodeList = sourceRoute.GetNodesAddress (); |
|
1520 |
Ipv4Address targetAddress = nodeList.back (); |
|
1521 |
/* |
|
1522 |
* The total serialized size for both the rerr and source route headers |
|
1523 |
*/ |
|
1524 |
uint32_t serializedSize = rerrSize + sourceRoute.GetSerializedSize (); |
|
1525 |
||
1526 |
if (length % 2 != 0) |
|
1527 |
{ |
|
1528 |
NS_LOG_LOGIC ("Malformed header. Drop!"); |
|
1529 |
m_dropTrace (p); |
|
1530 |
return 0; |
|
1531 |
} |
|
1532 |
||
1533 |
if (segmentsLeft > numberAddress) |
|
1534 |
{ |
|
1535 |
NS_LOG_LOGIC ("Malformed header. Drop!"); |
|
1536 |
m_dropTrace (p); |
|
1537 |
return 0; |
|
1538 |
} |
|
1539 |
/* |
|
1540 |
* When the error packet has reached to the destination |
|
1541 |
*/ |
|
1542 |
if (segmentsLeft == 0 && targetAddress == ipv4Address) |
|
1543 |
{ |
|
8752 | 1544 |
NS_LOG_INFO ("This is the destination of the error, send error request"); |
8751 | 1545 |
dsr->SendErrorRequest (rerr, protocol); |
1546 |
return serializedSize; |
|
1547 |
} |
|
1548 |
||
1549 |
// Get the next Router Address |
|
1550 |
DsrOptionSRHeader newSourceRoute; |
|
1551 |
newSourceRoute.SetSegmentsLeft (segmentsLeft - 1); |
|
1552 |
nextAddressIndex = numberAddress - segmentsLeft; |
|
1553 |
nextAddress = sourceRoute.GetNodeAddress (nextAddressIndex); |
|
1554 |
newSourceRoute.SetSalvage (sourceRoute.GetSalvage ()); |
|
1555 |
newSourceRoute.SetNodesAddress (nodeList); |
|
1556 |
nextAddress = newSourceRoute.GetNodeAddress (nextAddressIndex); |
|
1557 |
||
1558 |
// / to test if the next address is multicast or not |
|
1559 |
if (nextAddress.IsMulticast () || targetAddress.IsMulticast ()) |
|
1560 |
{ |
|
1561 |
m_dropTrace (p); |
|
1562 |
return serializedSize; |
|
1563 |
} |
|
1564 |
||
1565 |
// Set the route entry |
|
1566 |
SetRoute (nextAddress, ipv4Address); |
|
8752 | 1567 |
dsr->ForwardErrPacket (rerr, newSourceRoute, nextAddress, protocol, m_ipv4Route); |
8751 | 1568 |
return serializedSize; |
1569 |
} |
|
1570 |
||
1571 |
NS_OBJECT_ENSURE_REGISTERED (DsrOptionAckReq); |
|
1572 |
||
1573 |
TypeId DsrOptionAckReq::GetTypeId () |
|
1574 |
{ |
|
1575 |
static TypeId tid = TypeId ("ns3::dsr::DsrOptionAckReq") |
|
1576 |
.SetParent<DsrOptions> () |
|
1577 |
.AddConstructor<DsrOptionAckReq> () |
|
1578 |
; |
|
1579 |
return tid; |
|
1580 |
} |
|
1581 |
||
1582 |
DsrOptionAckReq::DsrOptionAckReq () |
|
1583 |
{ |
|
1584 |
NS_LOG_FUNCTION_NOARGS (); |
|
1585 |
} |
|
1586 |
||
1587 |
DsrOptionAckReq::~DsrOptionAckReq () |
|
1588 |
{ |
|
1589 |
NS_LOG_FUNCTION_NOARGS (); |
|
1590 |
} |
|
1591 |
||
1592 |
TypeId DsrOptionAckReq::GetInstanceTypeId () const |
|
1593 |
{ |
|
1594 |
return GetTypeId (); |
|
1595 |
} |
|
1596 |
||
1597 |
uint8_t DsrOptionAckReq::GetOptionNumber () const |
|
1598 |
{ |
|
1599 |
NS_LOG_FUNCTION_NOARGS (); |
|
1600 |
return OPT_NUMBER; |
|
1601 |
} |
|
1602 |
||
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1603 |
uint8_t DsrOptionAckReq::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource) |
8751 | 1604 |
{ |
1605 |
NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc); |
|
1606 |
/* |
|
1607 |
* Current implementation of the ack request header processing is coded in source route header processing |
|
1608 |
*/ |
|
1609 |
/* |
|
1610 |
* Remove the ack request header |
|
1611 |
*/ |
|
1612 |
Ptr<Packet> p = packet->Copy (); |
|
1613 |
DsrOptionAckReqHeader ackReq; |
|
1614 |
p->RemoveHeader (ackReq); |
|
1615 |
/* |
|
1616 |
* Get the node with ip address and get the dsr extension and reoute cache objects |
|
1617 |
*/ |
|
1618 |
Ptr<Node> node = GetNodeWithAddress (ipv4Address); |
|
1619 |
Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> (); |
|
1620 |
||
1621 |
NS_LOG_DEBUG ("The next header value " << (uint32_t)protocol); |
|
1622 |
||
1623 |
return ackReq.GetSerializedSize (); |
|
1624 |
} |
|
1625 |
||
1626 |
NS_OBJECT_ENSURE_REGISTERED (DsrOptionAck); |
|
1627 |
||
1628 |
TypeId DsrOptionAck::GetTypeId () |
|
1629 |
{ |
|
1630 |
static TypeId tid = TypeId ("ns3::dsr::DsrOptionAck") |
|
1631 |
.SetParent<DsrOptions> () |
|
1632 |
.AddConstructor<DsrOptionAck> () |
|
1633 |
; |
|
1634 |
return tid; |
|
1635 |
} |
|
1636 |
||
1637 |
DsrOptionAck::DsrOptionAck () |
|
1638 |
{ |
|
1639 |
NS_LOG_FUNCTION_NOARGS (); |
|
1640 |
} |
|
1641 |
||
1642 |
DsrOptionAck::~DsrOptionAck () |
|
1643 |
{ |
|
1644 |
NS_LOG_FUNCTION_NOARGS (); |
|
1645 |
} |
|
1646 |
||
1647 |
TypeId DsrOptionAck::GetInstanceTypeId () const |
|
1648 |
{ |
|
1649 |
return GetTypeId (); |
|
1650 |
} |
|
1651 |
||
1652 |
uint8_t DsrOptionAck::GetOptionNumber () const |
|
1653 |
{ |
|
1654 |
NS_LOG_FUNCTION_NOARGS (); |
|
1655 |
return OPT_NUMBER; |
|
1656 |
} |
|
1657 |
||
9293
854e085e1a01
bug 1608: DSR network ack and bug 1609: DSR route request table
Yufei Cheng <yfcheng@ittc.ku.edu>
parents:
8976
diff
changeset
|
1658 |
uint8_t DsrOptionAck::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource) |
8751 | 1659 |
{ |
1660 |
NS_LOG_FUNCTION (this << packet << dsrP << ipv4Address << source << ipv4Header << (uint32_t)protocol << isPromisc); |
|
1661 |
/* |
|
1662 |
* Remove the ACK header |
|
1663 |
*/ |
|
1664 |
Ptr<Packet> p = packet->Copy (); |
|
1665 |
DsrOptionAckHeader ack; |
|
1666 |
p->RemoveHeader (ack); |
|
1667 |
/* |
|
1668 |
* Get the ACK source and destination address |
|
1669 |
*/ |
|
1670 |
Ipv4Address realSrc = ack.GetRealSrc (); |
|
1671 |
Ipv4Address realDst = ack.GetRealDst (); |
|
1672 |
uint16_t ackId = ack.GetAckId (); |
|
1673 |
/* |
|
1674 |
* Get the node with ip address and get the dsr extension and route cache objects |
|
1675 |
*/ |
|
1676 |
Ptr<Node> node = GetNodeWithAddress (ipv4Address); |
|
1677 |
Ptr<dsr::DsrRouting> dsr = node->GetObject<dsr::DsrRouting> (); |
|
8752 | 1678 |
dsr->UpdateRouteEntry (realDst); |
8751 | 1679 |
/* |
1680 |
* Cancel the packet retransmit timer when receiving the ack packet |
|
1681 |
*/ |
|
1682 |
dsr->CallCancelPacketTimer (ackId, ipv4Header, realSrc, realDst); |
|
1683 |
return ack.GetSerializedSize (); |
|
1684 |
} |
|
1685 |
||
1686 |
} // namespace dsr |
|
1687 |
} // namespace ns3 |