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