A Discrete-Event Network Simulator
API
dsr-options.h
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 #ifndef DSR_OPTION_H
33 #define DSR_OPTION_H
34 
35 #include <map>
36 #include <list>
37 
38 #include "ns3/buffer.h"
39 #include "ns3/packet.h"
40 #include "ns3/callback.h"
41 #include "ns3/ptr.h"
42 #include "ns3/udp-l4-protocol.h"
43 #include "ns3/ipv4.h"
44 #include "ns3/ipv4-route.h"
45 #include "ns3/object.h"
46 #include "ns3/node.h"
47 #include "ns3/ipv4-interface.h"
48 #include "ns3/ipv4-header.h"
49 #include "ns3/ipv4-address.h"
50 #include "ns3/traced-callback.h"
51 #include "ns3/output-stream-wrapper.h"
52 #include "ns3/timer.h"
53 
54 #include "dsr-rsendbuff.h"
55 #include "dsr-maintain-buff.h"
56 #include "dsr-option-header.h"
57 #include "dsr-rcache.h"
58 #include "dsr-routing.h"
60 
61 namespace ns3 {
62 
63 class Packet;
64 class NetDevice;
65 class Node;
66 class Ipv4Address;
67 class Ipv4Interface;
68 class Ipv4Route;
69 class Ipv4;
70 class Time;
71 
72 namespace dsr {
73 
74 class DsrOptions : public Object
75 {
76 public:
81  static TypeId GetTypeId (void);
85  DsrOptions ();
89  virtual ~DsrOptions ();
94  virtual uint8_t GetOptionNumber () const = 0;
99  void SetNode (Ptr<Node> node);
104  Ptr<Node> GetNode () const;
113  bool ContainAddressAfter (Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector<Ipv4Address> &nodeList);
121  std::vector<Ipv4Address> CutRoute (Ipv4Address ipv4Address, std::vector<Ipv4Address> &nodeList);
130  virtual Ptr<Ipv4Route> SetRoute (Ipv4Address nextHop, Ipv4Address srcAddress);
137  bool ReverseRoutes (std::vector<Ipv4Address>& vec);
145  Ipv4Address SearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
153  Ipv4Address ReverseSearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
161  Ipv4Address ReverseSearchNextTwoHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
166  void PrintVector (std::vector<Ipv4Address>& vec);
174  bool IfDuplicates (std::vector<Ipv4Address>& vec, std::vector<Ipv4Address>& vec2);
182  bool CheckDuplicates (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
188  void RemoveDuplicates (std::vector<Ipv4Address>& vec);
196  void ScheduleReply (Ptr<Packet> &packet, std::vector<Ipv4Address> &nodeList, Ipv4Address &source, Ipv4Address &destination);
203  uint32_t GetIDfromIP (Ipv4Address address);
225  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource) = 0;
226 
227 protected:
255  std::vector<Ipv4Address> m_ipv4Address;
259  std::vector<Ipv4Address> m_finalRoute;
268 
269 private:
271 };
272 
277 class DsrOptionPad1 : public DsrOptions
278 {
279 public:
283  static const uint8_t OPT_NUMBER = 224;
284 
289  static TypeId GetTypeId ();
290 
291  DsrOptionPad1 ();
292  virtual ~DsrOptionPad1 ();
293 
294  virtual uint8_t GetOptionNumber () const;
295  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
296 };
297 
302 class DsrOptionPadn : public DsrOptions
303 {
304 public:
308  static const uint8_t OPT_NUMBER = 0;
309 
314  static TypeId GetTypeId ();
315 
316  DsrOptionPadn ();
317  virtual ~DsrOptionPadn ();
318 
319  virtual uint8_t GetOptionNumber () const;
320  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
321 };
322 
327 class DsrOptionRreq : public DsrOptions
328 {
329 public:
333  static const uint8_t OPT_NUMBER = 1;
334 
339  static TypeId GetTypeId ();
344  virtual TypeId GetInstanceTypeId () const;
348  DsrOptionRreq ();
352  virtual ~DsrOptionRreq ();
353 
354  virtual uint8_t GetOptionNumber () const;
355  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
356 
357 private:
366 };
367 
372 class DsrOptionRrep : public DsrOptions
373 {
374 public:
378  static const uint8_t OPT_NUMBER = 2;
379 
384  static TypeId GetTypeId ();
389  virtual TypeId GetInstanceTypeId () const;
390 
391  DsrOptionRrep ();
392  virtual ~DsrOptionRrep ();
393 
394  virtual uint8_t GetOptionNumber () const;
395  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
396 
397 private:
406 };
407 
412 class DsrOptionSR : public DsrOptions
413 {
414 public:
418  static const uint8_t OPT_NUMBER = 96;
419 
424  static TypeId GetTypeId ();
429  virtual TypeId GetInstanceTypeId () const;
430 
431  DsrOptionSR ();
432  virtual ~DsrOptionSR ();
433 
434  virtual uint8_t GetOptionNumber () const;
435  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
436 
437 private:
442 };
443 
448 class DsrOptionRerr : public DsrOptions
449 {
450 public:
454  static const uint8_t OPT_NUMBER = 3;
455 
460  static TypeId GetTypeId ();
465  virtual TypeId GetInstanceTypeId () const;
466 
467  DsrOptionRerr ();
468  virtual ~DsrOptionRerr ();
469 
470  virtual uint8_t GetOptionNumber () const;
471  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
482  uint8_t DoSendError (Ptr<Packet> p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol);
483 
484 private:
493 };
494 
500 {
501 public:
505  static const uint8_t OPT_NUMBER = 160;
506 
511  static TypeId GetTypeId ();
516  virtual TypeId GetInstanceTypeId () const;
517 
518  DsrOptionAckReq ();
519  virtual ~DsrOptionAckReq ();
520 
521  virtual uint8_t GetOptionNumber () const;
522  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
523 
524 private:
533 };
534 
539 class DsrOptionAck : public DsrOptions
540 {
541 public:
545  static const uint8_t OPT_NUMBER = 32;
546 
551  static TypeId GetTypeId ();
556  virtual TypeId GetInstanceTypeId () const;
557 
558  DsrOptionAck ();
559  virtual ~DsrOptionAck ();
560 
561  virtual uint8_t GetOptionNumber () const;
562  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
563 
564 private:
573 };
574 } // namespace dsr
575 } // Namespace ns3
576 
577 #endif
Ptr< dsr::DsrRreqTable > m_rreqTable
The route request table.
Definition: dsr-options.h:239
static const uint8_t OPT_NUMBER
Dsr Route Error option number.
Definition: dsr-options.h:454
Ptr< Ipv4 > m_ipv4
The ip layer 3.
Definition: dsr-options.h:405
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 TypeId GetInstanceTypeId() const
Get the instance type ID.
Definition: dsr-options.cc:473
static const uint8_t OPT_NUMBER
Rreq option number.
Definition: dsr-options.h:333
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:442
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
static const uint8_t OPT_NUMBER
Dsr ack request option number.
Definition: dsr-options.h:505
Ptr< Ipv4 > m_ipv4
The ipv4 layer 3.
Definition: dsr-options.h:492
static TypeId GetTypeId()
Get the type ID.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:401
Introspection did not find any typical Config paths.
Definition: dsr-options.h:74
static TypeId GetTypeId()
Get the type ID.
Definition: dsr-options.cc:422
Forward calls to a chain of Callback.
virtual uint8_t GetOptionNumber() const =0
Get the option number.
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.
Definition: dsr-options.cc:488
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:813
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.
Dsr Option Route Error.
Definition: dsr-options.h:448
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)=0
Process method.
void SetNode(Ptr< Node > node)
Set the node.
Definition: dsr-options.cc:99
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.
uint32_t GetIDfromIP(Ipv4Address address)
Get the node id with Ipv4Address.
Definition: dsr-options.cc:346
virtual uint8_t GetOptionNumber() const
Get the option number.
Ptr< Ipv4 > m_ipv4
The ipv4 layer 3.
Definition: dsr-options.h:532
Packet header for IPv4.
Definition: ipv4-header.h:33
void ScheduleReply(Ptr< Packet > &packet, std::vector< Ipv4Address > &nodeList, Ipv4Address &source, Ipv4Address &destination)
Schedule the intermediate node route request broadcast.
Dsr Option Route Reply.
Definition: dsr-options.h:372
static TypeId GetTypeId()
Get the type ID.
Definition: dsr-options.cc:963
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:488
DsrOptionRreq()
Constructor.
Definition: dsr-options.cc:478
Ipv4Address ReverseSearchNextTwoHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Reverse search for the next two hop in the route.
Definition: dsr-options.cc:225
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
Definition: dsr-options.cc:995
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:378
static TypeId GetTypeId()
Get the type ID.
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
Definition: dsr-options.cc:448
static const uint8_t OPT_NUMBER
PadN option number.
Definition: dsr-options.h:308
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:568
Ipv4Address Broadcast
The broadcast IP address.
Definition: dsr-options.h:235
virtual ~DsrOptionRreq()
Destructor.
Definition: dsr-options.cc:483
std::vector< Ipv4Address > m_finalRoute
The vector of final Ipv4 address.
Definition: dsr-options.h:259
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache table.
Definition: dsr-options.h:243
void RemoveDuplicates(std::vector< Ipv4Address > &vec)
Remove the duplicates from the route.
Definition: dsr-options.cc:301
Time ActiveRouteTimeout
The active route timeout value.
Definition: dsr-options.h:263
void PrintVector(std::vector< Ipv4Address > &vec)
Print out the elements in the route vector.
Definition: dsr-options.cc:244
virtual uint8_t GetOptionNumber() const
Get the option number.
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:361
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:44
DsrOptions()
Constructor.
Definition: dsr-options.cc:89
static const uint8_t OPT_NUMBER
The Dsr Ack option number.
Definition: dsr-options.h:545
Ipv4Address SearchNextHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Search for the next hop in the route.
Definition: dsr-options.cc:167
Dsr Option Source Route.
Definition: dsr-options.h:412
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Ptr< Node > GetNode() const
Get the node.
Definition: dsr-options.cc:105
virtual uint8_t GetOptionNumber() const
Get the option number.
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: dsr-options.cc:988
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()
Get the type ID.
Ptr< Ipv4 > m_ipv4
The ip layer 3.
Definition: dsr-options.h:441
virtual ~DsrOptions()
Destructor.
Definition: dsr-options.cc:94
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
Definition: dsr-options.cc:408
Ptr< Ipv4 > m_ipv4
The ipv4 layer 3.
Definition: dsr-options.h:572
Ptr< Node > m_node
the node
Definition: dsr-options.h:270
static TypeId GetTypeId()
Get the type ID.
Definition: dsr-options.cc:381
Dsr Option Rreq.
Definition: dsr-options.h:327
IPv4 Option Padn.
Definition: dsr-options.h:302
bool CheckDuplicates(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Check if the route already contains the node ip address.
Definition: dsr-options.cc:284
virtual uint8_t GetOptionNumber() const
Get the option number.
bool ReverseRoutes(std::vector< Ipv4Address > &vec)
Reverse the routes.
Definition: dsr-options.cc:149
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
Definition: dsr-options.cc:495
Route Error (RERR) Unreachable node address option Message Format.
Ptr< Ipv4Route > m_ipv4Route
The ipv4 route.
Definition: dsr-options.h:247
Ptr< Ipv4 > m_ipv4
The ipv4.
Definition: dsr-options.h:251
Ipv4Address ReverseSearchNextHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Reverse search for the next hop in the route.
Definition: dsr-options.cc:199
static TypeId GetTypeId(void)
Get the type identificator.
Definition: dsr-options.cc:68
bool ContainAddressAfter(Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector< Ipv4Address > &nodeList)
Search for the ipv4 address in the node list.
Definition: dsr-options.cc:111
Dsr Option Ack.
Definition: dsr-options.h:539
Ptr< Ipv4 > m_ipv4
The ipv4.
Definition: dsr-options.h:365
static const uint8_t OPT_NUMBER
Source Route option number.
Definition: dsr-options.h:418
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:401
std::vector< Ipv4Address > m_ipv4Address
The vector of Ipv4 address.
Definition: dsr-options.h:255
A base class which provides memory management and object aggregation.
Definition: object.h:87
Dsr Option Pad1.
Definition: dsr-options.h:277
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:528
virtual Ptr< Ipv4Route > SetRoute(Ipv4Address nextHop, Ipv4Address srcAddress)
Set the route to use for data packets, used by the option headers when sending data/control packets...
Definition: dsr-options.cc:139
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Definition: dsr-options.cc:983
bool IfDuplicates(std::vector< Ipv4Address > &vec, std::vector< Ipv4Address > &vec2)
Check if the two vectors contain duplicate or not.
Definition: dsr-options.cc:264
Ptr< Node > GetNodeWithAddress(Ipv4Address ipv4Address)
Get the node object with Ipv4Address.
Definition: dsr-options.cc:362
static TypeId GetTypeId()
Get the type ID.
virtual uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource)
Process method.
a unique identifier for an interface.
Definition: type-id.h:58
std::vector< Ipv4Address > CutRoute(Ipv4Address ipv4Address, std::vector< Ipv4Address > &nodeList)
Cut the route from ipv4Address to the end of the route vector.
Definition: dsr-options.cc:127
static TypeId GetTypeId()
Get the type ID.
Definition: dsr-options.cc:463