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);
189  void RemoveDuplicates (std::vector<Ipv4Address>& vec);
197  void ScheduleReply (Ptr<Packet> &packet, std::vector<Ipv4Address> &nodeList, Ipv4Address &source, Ipv4Address &destination);
204  uint32_t GetIDfromIP (Ipv4Address address);
226  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;
227 
228 protected:
256  std::vector<Ipv4Address> m_ipv4Address;
260  std::vector<Ipv4Address> m_finalRoute;
269 
270 private:
272 };
273 
278 class DsrOptionPad1 : public DsrOptions
279 {
280 public:
284  static const uint8_t OPT_NUMBER = 224;
285 
290  static TypeId GetTypeId ();
291 
292  DsrOptionPad1 ();
293  virtual ~DsrOptionPad1 ();
294 
295  virtual uint8_t GetOptionNumber () const;
296  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
297 };
298 
303 class DsrOptionPadn : public DsrOptions
304 {
305 public:
309  static const uint8_t OPT_NUMBER = 0;
310 
315  static TypeId GetTypeId ();
316 
317  DsrOptionPadn ();
318  virtual ~DsrOptionPadn ();
319 
320  virtual uint8_t GetOptionNumber () const;
321  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
322 };
323 
328 class DsrOptionRreq : public DsrOptions
329 {
330 public:
334  static const uint8_t OPT_NUMBER = 1;
335 
340  static TypeId GetTypeId ();
345  virtual TypeId GetInstanceTypeId () const;
349  DsrOptionRreq ();
353  virtual ~DsrOptionRreq ();
354 
355  virtual uint8_t GetOptionNumber () const;
356  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
357 
358 private:
367 };
368 
373 class DsrOptionRrep : public DsrOptions
374 {
375 public:
379  static const uint8_t OPT_NUMBER = 2;
380 
385  static TypeId GetTypeId ();
390  virtual TypeId GetInstanceTypeId () const;
391 
392  DsrOptionRrep ();
393  virtual ~DsrOptionRrep ();
394 
395  virtual uint8_t GetOptionNumber () const;
396  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
397 
398 private:
407 };
408 
413 class DsrOptionSR : public DsrOptions
414 {
415 public:
419  static const uint8_t OPT_NUMBER = 96;
420 
425  static TypeId GetTypeId ();
430  virtual TypeId GetInstanceTypeId () const;
431 
432  DsrOptionSR ();
433  virtual ~DsrOptionSR ();
434 
435  virtual uint8_t GetOptionNumber () const;
436  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
437 
438 private:
443 };
444 
449 class DsrOptionRerr : public DsrOptions
450 {
451 public:
455  static const uint8_t OPT_NUMBER = 3;
456 
461  static TypeId GetTypeId ();
466  virtual TypeId GetInstanceTypeId () const;
467 
468  DsrOptionRerr ();
469  virtual ~DsrOptionRerr ();
470 
471  virtual uint8_t GetOptionNumber () const;
472  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
483  uint8_t DoSendError (Ptr<Packet> p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol);
484 
485 private:
494 };
495 
501 {
502 public:
506  static const uint8_t OPT_NUMBER = 160;
507 
512  static TypeId GetTypeId ();
517  virtual TypeId GetInstanceTypeId () const;
518 
519  DsrOptionAckReq ();
520  virtual ~DsrOptionAckReq ();
521 
522  virtual uint8_t GetOptionNumber () const;
523  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
524 
525 private:
534 };
535 
540 class DsrOptionAck : public DsrOptions
541 {
542 public:
546  static const uint8_t OPT_NUMBER = 32;
547 
552  static TypeId GetTypeId ();
557  virtual TypeId GetInstanceTypeId () const;
558 
559  DsrOptionAck ();
560  virtual ~DsrOptionAck ();
561 
562  virtual uint8_t GetOptionNumber () const;
563  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc, Ipv4Address promiscSource);
564 
565 private:
574 };
575 } // namespace dsr
576 } // Namespace ns3
577 
578 #endif
Ptr< dsr::DsrRreqTable > m_rreqTable
The route request table.
Definition: dsr-options.h:240
static const uint8_t OPT_NUMBER
Dsr Route Error option number.
Definition: dsr-options.h:455
Ptr< Ipv4 > m_ipv4
The ip layer 3.
Definition: dsr-options.h:406
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:334
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:506
Ptr< Ipv4 > m_ipv4
The ipv4 layer 3.
Definition: dsr-options.h:493
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:802
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:449
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:284
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:533
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:373
static TypeId GetTypeId()
Get the type ID.
Definition: dsr-options.cc:963
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:489
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:232
static const uint8_t OPT_NUMBER
Router alert option number.
Definition: dsr-options.h:379
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:309
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:569
Ipv4Address Broadcast
The broadcast IP address.
Definition: dsr-options.h:236
virtual ~DsrOptionRreq()
Destructor.
Definition: dsr-options.cc:483
std::vector< Ipv4Address > m_finalRoute
The vector of final Ipv4 address.
Definition: dsr-options.h:260
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache table.
Definition: dsr-options.h:244
void RemoveDuplicates(std::vector< Ipv4Address > &vec)
Remove the duplicates from the route.
Definition: dsr-options.cc:301
Time ActiveRouteTimeout
The active route timeout value.
Definition: dsr-options.h:264
void PrintVector(std::vector< Ipv4Address > &vec)
Print out the elements in the route vector.
Definition: dsr-options.cc:244
virtual uint8_t GetOptionNumber() const
Get the option number.
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:362
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:546
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:413
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:268
static TypeId GetTypeId()
Get the type ID.
Ptr< Ipv4 > m_ipv4
The ip layer 3.
Definition: dsr-options.h:442
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:573
Ptr< Node > m_node
the node
Definition: dsr-options.h:271
static TypeId GetTypeId()
Get the type ID.
Definition: dsr-options.cc:381
Dsr Option Rreq.
Definition: dsr-options.h:328
IPv4 Option Padn.
Definition: dsr-options.h:303
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:248
Ptr< Ipv4 > m_ipv4
The ipv4.
Definition: dsr-options.h:252
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:540
Ptr< Ipv4 > m_ipv4
The ipv4.
Definition: dsr-options.h:366
static const uint8_t OPT_NUMBER
Source Route option number.
Definition: dsr-options.h:419
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:402
std::vector< Ipv4Address > m_ipv4Address
The vector of Ipv4 address.
Definition: dsr-options.h:256
A base class which provides memory management and object aggregation.
Definition: object.h:87
Dsr Option Pad1.
Definition: dsr-options.h:278
Ptr< dsr::DsrRouteCache > m_routeCache
The route cache.
Definition: dsr-options.h:529
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