A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
109  bool ContainAddressAfter (Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector<Ipv4Address> &nodeList);
114  std::vector<Ipv4Address> CutRoute (Ipv4Address ipv4Address, std::vector<Ipv4Address> &nodeList);
115  /*
116  * \brief Set the route to use for data packets
117  * \return the route
118  * \used by the option headers when sending data/control packets
119  */
120  virtual Ptr<Ipv4Route> SetRoute (Ipv4Address nextHop, Ipv4Address srcAddress);
125  bool ReverseRoutes (std::vector<Ipv4Address>& vec);
126  /*
127  * \brief Search for the next hop in the route
128  * \return the next hop address if found
129  */
130  Ipv4Address SearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
131  /*
132  * \brief Reverse search for the next hop in the route
133  * \return the next hop address if found
134  */
135  Ipv4Address ReverseSearchNextHop (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
136  /*
137  * \brief Print out the elements in the route vector
138  */
139  void PrintVector (std::vector<Ipv4Address>& vec);
140  /*
141  * \brief Check if the two vectors contain duplicate or not
142  * \return true if contains duplicate
143  */
144  bool IfDuplicates (std::vector<Ipv4Address>& vec, std::vector<Ipv4Address>& vec2);
145  /*
146  * \brief Check if the route already contains the node ip address
147  * \return true if it already exists
148  */
149  bool CheckDuplicates (Ipv4Address ipv4Address, std::vector<Ipv4Address>& vec);
150  /*
151  * \brief Remove the duplicates from the route
152  * \return the route after route shorten
153  */
154  void RemoveDuplicates (std::vector<Ipv4Address>& vec);
155  /*
156  * \brief Schedule the intermediate node route request broadcast
157  * \param the original packet
158  * \param rrepHeader The rrep header
159  * \param source address
160  * \param destination address
161  */
162  void ScheduleReply (Ptr<Packet> &packet, std::vector<Ipv4Address> &nodeList, Ipv4Address &source, Ipv4Address &destination);
163  /*
164  * \brief Get the node id with Ipv4Address
165  * \return the id of the node
166  */
167  uint32_t GetIDfromIP (Ipv4Address address);
168  /*
169  * \brief Get the node object with Ipv4Address
170  * \return the object of the node
171  */
184  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc) = 0;
185 
186 protected:
214  std::vector<Ipv4Address> m_ipv4Address;
218  std::vector<Ipv4Address> m_finalRoute;
223  /*
224  * The receive trace back, only triggered when final destination receive data packet
225  */
227 
228 private:
230 };
231 
236 class DsrOptionPad1 : public DsrOptions
237 {
238 public:
242  static const uint8_t OPT_NUMBER = 224;
247  static TypeId GetTypeId ();
251  DsrOptionPad1 ();
255  virtual ~DsrOptionPad1 ();
260  virtual uint8_t GetOptionNumber () const;
272  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
273 };
274 
279 class DsrOptionPadn : public DsrOptions
280 {
281 public:
285  static const uint8_t OPT_NUMBER = 0;
290  static TypeId GetTypeId ();
294  DsrOptionPadn ();
298  virtual ~DsrOptionPadn ();
303  virtual uint8_t GetOptionNumber () const;
315  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
316 };
317 
322 class DsrOptionRreq : public DsrOptions
323 {
324 public:
328  static const uint8_t OPT_NUMBER = 1;
333  static TypeId GetTypeId ();
338  virtual TypeId GetInstanceTypeId () const;
342  DsrOptionRreq ();
346  virtual ~DsrOptionRreq ();
351  virtual uint8_t GetOptionNumber () const;
363  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
364 
365 private:
374 };
375 
380 class DsrOptionRrep : public DsrOptions
381 {
382 public:
386  static const uint8_t OPT_NUMBER = 2;
391  static TypeId GetTypeId ();
396  virtual TypeId GetInstanceTypeId () const;
400  DsrOptionRrep ();
404  virtual ~DsrOptionRrep ();
409  virtual uint8_t GetOptionNumber () const;
421  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
422 
423 private:
431  uint32_t m_length;
436 };
437 
442 class DsrOptionSR : public DsrOptions
443 {
444 public:
448  static const uint8_t OPT_NUMBER = 96;
453  static TypeId GetTypeId ();
458  virtual TypeId GetInstanceTypeId () const;
462  DsrOptionSR ();
466  virtual ~DsrOptionSR ();
471  virtual uint8_t GetOptionNumber () const;
483  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
484 
485 private:
489  uint32_t m_length;
494 };
495 
500 class DsrOptionRerr : public DsrOptions
501 {
502 public:
506  static const uint8_t OPT_NUMBER = 3;
511  static TypeId GetTypeId ();
516  virtual TypeId GetInstanceTypeId () const;
520  DsrOptionRerr ();
524  virtual ~DsrOptionRerr ();
529  virtual uint8_t GetOptionNumber () const;
541  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
552  uint8_t DoSendError (Ptr<Packet> p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol);
553 
554 private:
562  uint32_t m_length;
567 };
568 
574 {
575 public:
579  static const uint8_t OPT_NUMBER = 160;
584  static TypeId GetTypeId ();
589  virtual TypeId GetInstanceTypeId () const;
593  DsrOptionAckReq ();
597  virtual ~DsrOptionAckReq ();
602  virtual uint8_t GetOptionNumber () const;
614  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
615 
616 private:
624  uint32_t m_length;
629 };
630 
635 class DsrOptionAck : public DsrOptions
636 {
637 public:
641  static const uint8_t OPT_NUMBER = 32;
646  static TypeId GetTypeId ();
651  virtual TypeId GetInstanceTypeId () const;
655  DsrOptionAck ();
659  virtual ~DsrOptionAck ();
664  virtual uint8_t GetOptionNumber () const;
676  virtual uint8_t Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address ipv4Address, Ipv4Address source, Ipv4Header const& ipv4Header, uint8_t protocol, bool& isPromisc);
677 
678 private:
686  uint32_t m_length;
691 };
692 } // namespace dsr
693 } // Namespace ns3
694 
695 #endif