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