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