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:
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),
69  m_fragmentOffset (f),
70  m_segsLeft (seg),
71  m_expire (exp + Simulator::Now ()),
72  m_protocol (p)
73  {
74  }
79  bool operator== (PassiveBuffEntry 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  }
84  // \{
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  {
131  m_fragmentOffset = f;
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 PassiveBuffer : public Object
183 {
184 public:
185 
186  static TypeId GetTypeId ();
187 
188  PassiveBuffer ();
189  virtual ~PassiveBuffer ();
190 
192  bool Enqueue (PassiveBuffEntry & entry);
194  bool Dequeue (Ipv4Address dst, PassiveBuffEntry & entry);
196  bool Find (Ipv4Address dst);
198  bool AllEqual (PassiveBuffEntry & entry);
200  uint32_t GetSize ();
202  // \{
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 
221 private:
223  std::vector<PassiveBuffEntry> m_passiveBuffer;
225  void Purge ();
227  void Drop (PassiveBuffEntry en, std::string reason);
229  void DropLink (PassiveBuffEntry en, std::string reason);
231  uint32_t m_maxLen;
235  static bool LinkEqual (PassiveBuffEntry en, const std::vector<Ipv4Address> link)
236  {
237  return ((en.GetSource () == link[0]) && (en.GetNextHop () == link[1]));
238  }
239 };
240 /*******************************************************************************************************************************/
241 } // namespace dsr
242 } // namespace ns3
243 
244 #endif /* DSR_PASSIVEBUFF_H */
void SetExpireTime(Time exp)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
Ptr< const Packet > m_packet
Data packet.
void SetPassiveBufferTimeout(Time t)
void SetDestination(Ipv4Address d)
Control the scheduling of simulation events.
Definition: simulator.h:63
DSR Passive Buffer Entry.
Time GetPassiveBufferTimeout() const
void Purge()
Remove all expired entries.
Time m_expire
Expire time for queue entry.
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)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
uint16_t m_identification
bool Dequeue(Ipv4Address dst, PassiveBuffEntry &entry)
Return first found (the earliest) entry for given destination.
void SetMaxQueueLen(uint32_t len)
void SetSource(Ipv4Address s)
bool operator==(PassiveBuffEntry const &o) const
Compare send buffer entries.
uint32_t GetSize()
Number of entries.
Ipv4Address GetSource() const
bool AllEqual(PassiveBuffEntry &entry)
Check if all the entries in passive buffer entry is all equal or not.
Ptr< SampleEmitter > s
Ipv4Address m_source
Source address.
Time m_passiveBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
uint8_t GetSegsLeft() const
uint16_t GetIdentification() const
uint32_t GetMaxQueueLen() const
uint8_t m_protocol
The protocol number.
void DropLink(PassiveBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
void SetProtocol(uint8_t p)
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
std::vector< PassiveBuffEntry > m_passiveBuffer
The send buffer to cache unsent packet.
void Drop(PassiveBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
Ipv4Address m_dst
Destination address.
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)
Construct a PassiveBuffEntry with the given parameters.
Time GetExpireTime() const
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
Nexthop address.
Ptr< const Packet > GetPacket() const
void SetSegsLeft(uint8_t seg)
uint8_t m_segsLeft
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
void SetIdentification(uint16_t i)
a base class which provides memory management and object aggregation
Definition: object.h:64
Ipv4Address GetDestination() const
Ipv4Address GetNextHop() const
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
void SetFragmentOffset(uint16_t f)
static bool LinkEqual(PassiveBuffEntry en, const std::vector< Ipv4Address > link)
Check if the send buffer entry is the same or not.
a unique identifier for an interface.
Definition: type-id.h:49