A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dsr-passive-buff.h
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_PASSIVEBUFF_H
33 #define DSR_PASSIVEBUFF_H
34 
35 #include <vector>
36 #include "ns3/ipv4-routing-protocol.h"
37 #include "ns3/simulator.h"
38 
39 namespace ns3 {
40 namespace dsr {
46 {
47 public:
48  // / c-tor
50  Ipv4Address n = Ipv4Address (), uint16_t i = 0, uint16_t f = 0, uint8_t seg = 0, Time exp = Simulator::Now (),
51  uint8_t p = 0)
52  : m_packet (pa),
53  m_dst (d),
54  m_source (s),
55  m_nextHop (n),
56  m_identification (i),
57  m_fragmentOffset (f),
58  m_segsLeft (seg),
59  m_expire (exp + Simulator::Now ()),
60  m_protocol (p)
61  {
62  }
67  bool operator== (PassiveBuffEntry const & o) const
68  {
69  return ((m_packet == o.m_packet) && (m_source == o.m_source) && (m_nextHop == o.m_nextHop) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
70  }
71  // /\name Fields
72  // \{
73  Ptr<const Packet> GetPacket () const
74  {
75  return m_packet;
76  }
77  void SetPacket (Ptr<const Packet> p)
78  {
79  m_packet = p;
80  }
81  Ipv4Address GetDestination () const
82  {
83  return m_dst;
84  }
85  void SetDestination (Ipv4Address d)
86  {
87  m_dst = d;
88  }
89  Ipv4Address GetSource () const
90  {
91  return m_source;
92  }
93  void SetSource (Ipv4Address s)
94  {
95  m_source = s;
96  }
97  Ipv4Address GetNextHop () const
98  {
99  return m_nextHop;
100  }
101  void SetNextHop (Ipv4Address n)
102  {
103  m_nextHop = n;
104  }
105  uint16_t GetIdentification () const
106  {
107  return m_identification;
108  }
109  void SetIdentification (uint16_t i)
110  {
111  m_identification = i;
112  }
113  uint16_t GetFragmentOffset () const
114  {
115  return m_fragmentOffset;
116  }
117  void SetFragmentOffset (uint16_t f)
118  {
119  m_fragmentOffset = f;
120  }
121  uint8_t GetSegsLeft () const
122  {
123  return m_segsLeft;
124  }
125  void SetSegsLeft (uint8_t seg)
126  {
127  m_segsLeft = seg;
128  }
129  void SetExpireTime (Time exp)
130  {
131  m_expire = exp + Simulator::Now ();
132  }
133  Time GetExpireTime () const
134  {
135  return m_expire - Simulator::Now ();
136  }
137  void SetProtocol (uint8_t p)
138  {
139  m_protocol = p;
140  }
141  uint8_t GetProtocol () const
142  {
143  return m_protocol;
144  }
145  // \}
146 private:
147  // / Data packet
148  Ptr<const Packet> m_packet;
149  // / Destination address
150  Ipv4Address m_dst;
151  // / Source address
152  Ipv4Address m_source;
153  // / Nexthop address
154  Ipv4Address m_nextHop;
155  // /
156  uint16_t m_identification;
157  uint16_t m_fragmentOffset;
158  uint8_t m_segsLeft;
159  // / Expire time for queue entry
160  Time m_expire;
161  // / The protocol number
162  uint8_t m_protocol;
163 };
164 
169 /************************************************************************************************************************/
170 class PassiveBuffer : public Object
171 {
172 public:
173  // / c-tor
178  static TypeId GetTypeId ();
182  PassiveBuffer ();
186  virtual ~PassiveBuffer ();
187  // / Push entry in queue, if there is no entry with the same packet and destination address in queue.
188  bool Enqueue (PassiveBuffEntry & entry);
189  // / Return first found (the earliest) entry for given destination
190  bool Dequeue (Ipv4Address dst, PassiveBuffEntry & entry);
191  // / Finds whether a packet with destination dst exists in the queue
192  bool Find (Ipv4Address dst);
193  // / Check if all the entries in passive buffer entry is all equal or not
194  bool AllEqual (PassiveBuffEntry & entry);
195  // / Number of entries
196  uint32_t GetSize ();
197  // /\name Fields
198  // \{
199  uint32_t GetMaxQueueLen () const
200  {
201  return m_maxLen;
202  }
203  void SetMaxQueueLen (uint32_t len)
204  {
205  m_maxLen = len;
206  }
207  Time GetPassiveBufferTimeout () const
208  {
209  return m_passiveBufferTimeout;
210  }
211  void SetPassiveBufferTimeout (Time t)
212  {
213  m_passiveBufferTimeout = t;
214  }
215  // \}
216 
217 private:
218  // / The send buffer to cache unsent packet
219  std::vector<PassiveBuffEntry> m_passiveBuffer;
220  // / Remove all expired entries
221  void Purge ();
222  // / Notify that packet is dropped from queue by timeout
223  void Drop (PassiveBuffEntry en, std::string reason);
224  // / Notify that packet is dropped from queue by timeout
225  void DropLink (PassiveBuffEntry en, std::string reason);
226  // / The maximum number of packets that we allow a routing protocol to buffer.
227  uint32_t m_maxLen;
228  // / The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
229  Time m_passiveBufferTimeout;
230  // / Check if the send buffer entry is the same or not
231  static bool LinkEqual (PassiveBuffEntry en, const std::vector<Ipv4Address> link)
232  {
233  return ((en.GetSource () == link[0]) && (en.GetNextHop () == link[1]));
234  }
235 };
236 /*******************************************************************************************************************************/
237 } // namespace dsr
238 } // namespace ns3
239 
240 #endif /* DSR_PASSIVEBUFF_H */
keep track of time unit.
Definition: nstime.h:149
DSR Passive Buffer Entry.
DSR passive buffer.
bool operator==(PassiveBuffEntry const &o) const
static TypeId GetTypeId()
Get the type identificator.
virtual ~PassiveBuffer()
Destructor.
static Time Now(void)
Definition: simulator.cc:179
PassiveBuffer()
Constructor.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
a base class which provides memory management and object aggregation
Definition: object.h:63
a unique identifier for an interface.
Definition: type-id.h:44