A Discrete-Event Network Simulator
API
dsr-passive-buff.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_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:
62  Ipv4Address n = Ipv4Address (), uint16_t i = 0, uint16_t f = 0, uint8_t seg = 0, Time exp = Simulator::Now (),
63  uint8_t p = 0)
64  : m_packet (pa),
65  m_dst (d),
66  m_source (s),
67  m_nextHop (n),
68  m_identification (i),
70  m_segsLeft (seg),
71  m_expire (exp + Simulator::Now ()),
72  m_protocol (p)
73  {
74  }
80  bool operator== (DsrPassiveBuffEntry const & o) const
81  {
82  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));
83  }
84 
85  // Fields
91  {
92  return m_packet;
93  }
99  {
100  m_packet = p;
101  }
107  {
108  return m_dst;
109  }
115  {
116  m_dst = d;
117  }
123  {
124  return m_source;
125  }
131  {
132  m_source = s;
133  }
139  {
140  return m_nextHop;
141  }
147  {
148  m_nextHop = n;
149  }
154  uint16_t GetIdentification () const
155  {
156  return m_identification;
157  }
162  void SetIdentification (uint16_t i)
163  {
164  m_identification = i;
165  }
170  uint16_t GetFragmentOffset () const
171  {
172  return m_fragmentOffset;
173  }
178  void SetFragmentOffset (uint16_t f)
179  {
181  }
186  uint8_t GetSegsLeft () const
187  {
188  return m_segsLeft;
189  }
194  void SetSegsLeft (uint8_t seg)
195  {
196  m_segsLeft = seg;
197  }
202  void SetExpireTime (Time exp)
203  {
204  m_expire = exp + Simulator::Now ();
205  }
211  {
212  return m_expire - Simulator::Now ();
213  }
218  void SetProtocol (uint8_t p)
219  {
220  m_protocol = p;
221  }
226  uint8_t GetProtocol () const
227  {
228  return m_protocol;
229  }
230 
231 private:
245  uint8_t m_segsLeft;
249  uint8_t m_protocol;
250 };
251 
257 /************************************************************************************************************************/
258 class DsrPassiveBuffer : public Object
259 {
260 public:
265  static TypeId GetTypeId ();
266 
267  DsrPassiveBuffer ();
268  virtual ~DsrPassiveBuffer ();
269 
273  bool Enqueue (DsrPassiveBuffEntry & entry);
278  bool Dequeue (Ipv4Address dst, DsrPassiveBuffEntry & entry);
282  bool Find (Ipv4Address dst);
288  bool AllEqual (DsrPassiveBuffEntry & entry);
291  uint32_t GetSize ();
292 
293  // Fields
298  uint32_t GetMaxQueueLen () const
299  {
300  return m_maxLen;
301  }
306  void SetMaxQueueLen (uint32_t len)
307  {
308  m_maxLen = len;
309  }
315  {
316  return m_passiveBufferTimeout;
317  }
323  {
325  }
326 
327 private:
329  std::vector<DsrPassiveBuffEntry> m_passiveBuffer;
331  void Purge ();
335  void Drop (DsrPassiveBuffEntry en, std::string reason);
339  void DropLink (DsrPassiveBuffEntry en, std::string reason);
341  uint32_t m_maxLen;
348  static bool LinkEqual (DsrPassiveBuffEntry en, const std::vector<Ipv4Address> link)
349  {
350  return ((en.GetSource () == link[0]) && (en.GetNextHop () == link[1]));
351  }
352 };
353 /*******************************************************************************************************************************/
354 } // namespace dsr
355 } // namespace ns3
356 
357 #endif /* DSR_PASSIVEBUFF_H */
Ipv4Address m_dst
Destination address.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Control the scheduling of simulation events.
Definition: simulator.h:68
void SetNextHop(Ipv4Address n)
Set next hop address function.
void DropLink(DsrPassiveBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
Time GetExpireTime() const
Get expire time.
uint32_t GetSize()
Number of entries.
Time GetPassiveBufferTimeout() const
Get passive buffer timeout.
uint16_t m_fragmentOffset
Fragment offset.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
void SetExpireTime(Time exp)
Set expire time.
static bool LinkEqual(DsrPassiveBuffEntry en, const std::vector< Ipv4Address > link)
Check if the send buffer entry is the same or not.
uint16_t GetFragmentOffset() const
Get fragment offset function.
std::vector< DsrPassiveBuffEntry > m_passiveBuffer
The send buffer to cache unsent packet.
void SetDestination(Ipv4Address d)
Set destination address function.
void SetProtocol(uint8_t p)
Set protocol function.
uint8_t GetProtocol() const
Get protocol.
void SetPassiveBufferTimeout(Time t)
Set passive buffer timeout.
uint16_t m_identification
Identification.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
bool operator==(DsrPassiveBuffEntry const &o) const
Compare send buffer entries.
void Purge()
Remove all expired entries.
void SetFragmentOffset(uint16_t f)
Set fragment offset function.
DSR Passive Buffer Entry.
bool Dequeue(Ipv4Address dst, DsrPassiveBuffEntry &entry)
Return first found (the earliest) entry for given destination.
bool AllEqual(DsrPassiveBuffEntry &entry)
Check if all the entries in passive buffer entry is all equal or not.
double f(double x, void *params)
Definition: 80211b.c:70
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
bool Enqueue(DsrPassiveBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
Time m_passiveBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ipv4Address GetSource() const
Get source address function.
Ptr< const Packet > m_packet
Data packet.
Ipv4Address m_nextHop
Nexthop address.
DsrPassiveBuffEntry(Ptr< const Packet > pa=0, Ipv4Address d=Ipv4Address(), Ipv4Address s=Ipv4Address(), Ipv4Address n=Ipv4Address(), uint16_t i=0, uint16_t f=0, uint8_t seg=0, Time exp=Simulator::Now(), uint8_t p=0)
Construct a DsrPassiveBuffEntry with the given parameters.
Time m_expire
Expire time for queue entry.
uint16_t GetIdentification() const
Get identification function.
uint8_t m_segsLeft
Segments left.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
void SetSegsLeft(uint8_t seg)
Set segments left.
Ipv4Address GetNextHop() const
Get next hop address function.
void SetSource(Ipv4Address s)
Set surce address function.
uint8_t GetSegsLeft() const
Get segments left function.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
void SetPacket(Ptr< const Packet > p)
Set packet function.
Ipv4Address m_source
Source address.
Ptr< const Packet > GetPacket() const
Get packet function.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:365
void Drop(DsrPassiveBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
A base class which provides memory management and object aggregation.
Definition: object.h:87
void SetIdentification(uint16_t i)
Set identification function.
uint8_t m_protocol
The protocol number.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
a unique identifier for an interface.
Definition: type-id.h:58
static TypeId GetTypeId()
Get the type ID.
Ipv4Address GetDestination() const
Get destination address function.