A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
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  // \{
74  {
75  return m_packet;
76  }
78  {
79  m_packet = p;
80  }
82  {
83  return m_dst;
84  }
86  {
87  m_dst = d;
88  }
90  {
91  return m_source;
92  }
94  {
95  m_source = s;
96  }
98  {
99  return m_nextHop;
100  }
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  }
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
149  // / Destination address
151  // / Source address
153  // / Nexthop address
155  // /
158  uint8_t m_segsLeft;
159  // / Expire time for queue entry
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  }
208  {
209  return m_passiveBufferTimeout;
210  }
212  {
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.
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 */
void SetExpireTime(Time exp)
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
Ptr< const Packet > m_packet
void SetPassiveBufferTimeout(Time t)
void SetDestination(Ipv4Address d)
Control the scheduling of simulation events.
Definition: simulator.h:62
DSR Passive Buffer Entry.
Time GetPassiveBufferTimeout() const
Time m_expire
DSR passive buffer.
uint16_t m_fragmentOffset
uint16_t GetFragmentOffset() const
void SetNextHop(Ipv4Address n)
void SetPacket(Ptr< const Packet > p)
bool Enqueue(PassiveBuffEntry &entry)
uint16_t m_identification
bool Dequeue(Ipv4Address dst, PassiveBuffEntry &entry)
void SetMaxQueueLen(uint32_t len)
void SetSource(Ipv4Address s)
bool operator==(PassiveBuffEntry const &o) const
static TypeId GetTypeId()
Get the type identificator.
Ipv4Address GetSource() const
bool AllEqual(PassiveBuffEntry &entry)
Ptr< SampleEmitter > s
Ipv4Address m_source
uint8_t GetSegsLeft() const
uint16_t GetIdentification() const
uint32_t GetMaxQueueLen() const
uint8_t m_protocol
void DropLink(PassiveBuffEntry en, std::string reason)
virtual ~PassiveBuffer()
Destructor.
void SetProtocol(uint8_t p)
static Time Now(void)
Definition: simulator.cc:180
std::vector< PassiveBuffEntry > m_passiveBuffer
void Drop(PassiveBuffEntry en, std::string reason)
Ipv4Address m_dst
PassiveBuffEntry(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)
Time GetExpireTime() const
PassiveBuffer()
Constructor.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
uint8_t GetProtocol() const
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Ipv4Address m_nextHop
Ptr< const Packet > GetPacket() const
void SetSegsLeft(uint8_t seg)
uint8_t m_segsLeft
void SetIdentification(uint16_t i)
a base class which provides memory management and object aggregation
Definition: object.h:63
Ipv4Address GetDestination() const
Ipv4Address GetNextHop() const
bool Find(Ipv4Address dst)
void SetFragmentOffset(uint16_t f)
static bool LinkEqual(PassiveBuffEntry en, const std::vector< Ipv4Address > link)
a unique identifier for an interface.
Definition: type-id.h:49