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  }
79  bool operator== (DsrPassiveBuffEntry const & o) const
80  {
81  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));
82  }
83 
84  // Fields
86  {
87  return m_packet;
88  }
90  {
91  m_packet = p;
92  }
94  {
95  return m_dst;
96  }
98  {
99  m_dst = d;
100  }
102  {
103  return m_source;
104  }
106  {
107  m_source = s;
108  }
110  {
111  return m_nextHop;
112  }
114  {
115  m_nextHop = n;
116  }
117  uint16_t GetIdentification () const
118  {
119  return m_identification;
120  }
121  void SetIdentification (uint16_t i)
122  {
123  m_identification = i;
124  }
125  uint16_t GetFragmentOffset () const
126  {
127  return m_fragmentOffset;
128  }
129  void SetFragmentOffset (uint16_t f)
130  {
132  }
133  uint8_t GetSegsLeft () const
134  {
135  return m_segsLeft;
136  }
137  void SetSegsLeft (uint8_t seg)
138  {
139  m_segsLeft = seg;
140  }
141  void SetExpireTime (Time exp)
142  {
143  m_expire = exp + Simulator::Now ();
144  }
146  {
147  return m_expire - Simulator::Now ();
148  }
149  void SetProtocol (uint8_t p)
150  {
151  m_protocol = p;
152  }
153  uint8_t GetProtocol () const
154  {
155  return m_protocol;
156  }
157 
158 private:
170  uint8_t m_segsLeft;
174  uint8_t m_protocol;
175 };
176 
181 /************************************************************************************************************************/
182 class DsrPassiveBuffer : public Object
183 {
184 public:
185 
186  static TypeId GetTypeId ();
187 
188  DsrPassiveBuffer ();
189  virtual ~DsrPassiveBuffer ();
190 
192  bool Enqueue (DsrPassiveBuffEntry & entry);
194  bool Dequeue (Ipv4Address dst, DsrPassiveBuffEntry & entry);
196  bool Find (Ipv4Address dst);
198  bool AllEqual (DsrPassiveBuffEntry & entry);
200  uint32_t GetSize ();
201 
202  // Fields
203  uint32_t GetMaxQueueLen () const
204  {
205  return m_maxLen;
206  }
207  void SetMaxQueueLen (uint32_t len)
208  {
209  m_maxLen = len;
210  }
212  {
213  return m_passiveBufferTimeout;
214  }
216  {
218  }
219 
220 private:
222  std::vector<DsrPassiveBuffEntry> m_passiveBuffer;
224  void Purge ();
226  void Drop (DsrPassiveBuffEntry en, std::string reason);
228  void DropLink (DsrPassiveBuffEntry en, std::string reason);
230  uint32_t m_maxLen;
234  static bool LinkEqual (DsrPassiveBuffEntry en, const std::vector<Ipv4Address> link)
235  {
236  return ((en.GetSource () == link[0]) && (en.GetNextHop () == link[1]));
237  }
238 };
239 /*******************************************************************************************************************************/
240 } // namespace dsr
241 } // namespace ns3
242 
243 #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)
bool operator==(DsrPassiveBuffEntry const &o) const
Compare send buffer entries.
void DropLink(DsrPassiveBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
DSR passive buffer.
uint32_t GetSize()
Number of entries.
uint16_t m_fragmentOffset
uint8_t GetSegsLeft() const
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
uint16_t GetFragmentOffset() const
void SetExpireTime(Time exp)
static bool LinkEqual(DsrPassiveBuffEntry en, const std::vector< Ipv4Address > link)
Check if the send buffer entry is the same or not.
Ipv4Address GetSource() const
std::vector< DsrPassiveBuffEntry > m_passiveBuffer
The send buffer to cache unsent packet.
uint8_t GetProtocol() const
void SetDestination(Ipv4Address d)
void SetProtocol(uint8_t p)
uint16_t m_identification
void Purge()
Remove all expired entries.
void SetFragmentOffset(uint16_t f)
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:60
Ipv4Address GetDestination() const
void SetMaxQueueLen(uint32_t len)
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.
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 GetPassiveBufferTimeout() const
Time m_expire
Expire time for queue entry.
uint8_t m_segsLeft
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
void SetSegsLeft(uint8_t seg)
uint16_t GetIdentification() const
void SetSource(Ipv4Address s)
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
Ipv4Address GetNextHop() const
void SetPacket(Ptr< const Packet > p)
Ipv4Address m_source
Source address.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:340
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
Time GetExpireTime() const
void SetIdentification(uint16_t i)
uint8_t m_protocol
The protocol number.
uint32_t GetMaxQueueLen() const
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
Ptr< const Packet > GetPacket() const