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