A Discrete-Event Network Simulator
API
dsr-maintain-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_MAINTAIN_BUFF_H
33 #define DSR_MAINTAIN_BUFF_H
34 
35 #include <vector>
36 #include "ns3/ipv4-routing-protocol.h"
37 #include "ns3/simulator.h"
38 #include "ns3/ipv4-header.h"
39 #include "dsr-option-header.h"
40 
41 namespace ns3 {
42 namespace dsr {
47 struct LinkKey
48 {
53 
59  bool operator < (const LinkKey & o) const
60  {
61  if (m_source < o.m_source) return true;
62  if (o.m_source < m_source) return false;
63  if (m_destination < o.m_destination) return true;
64  if (o.m_destination < m_destination) return false;
65  if (m_ourAdd < o.m_ourAdd) return true;
66  if (o.m_ourAdd < m_ourAdd) return false;
67  if (m_nextHop < o.m_nextHop) return true;
68  if (o.m_nextHop < m_nextHop) return false;
69  return false;
70  }
71 };
72 
73 struct NetworkKey
74 {
75  uint16_t m_ackId;
80 
86  bool operator < (const NetworkKey & o) const
87  {
88  if (m_ackId < o.m_ackId) return true;
89  if (o.m_ackId < m_ackId) return false;
90  if (m_source < o.m_source) return true;
91  if (o.m_source < m_source) return false;
92  if (m_destination < o.m_destination) return true;
93  if (o.m_destination < m_destination) return false;
94  if (m_ourAdd < o.m_ourAdd) return true;
95  if (o.m_ourAdd < m_ourAdd) return false;
96  if (m_nextHop < o.m_nextHop) return true;
97  if (o.m_nextHop < m_nextHop) return false;
98  return false;
99  }
100 };
101 
103 {
104  uint16_t m_ackId;
107  uint8_t m_segsLeft;
108 
114  bool operator < (const PassiveKey & o) const
115  {
116  if (m_ackId < o.m_ackId) return true;
117  if (o.m_ackId < m_ackId) return false;
118  if (m_source < o.m_source) return true;
119  if (o.m_source < m_source) return false;
120  if (m_destination < o.m_destination) return true;
121  if (o.m_destination < m_destination) return false;
122  if (m_segsLeft < o.m_segsLeft) return true;
123  if (o.m_segsLeft < m_segsLeft) return false;
124  return false;
125  }
126 };
127 
133 {
134 public:
149  uint16_t ackId = 0, uint8_t segs = 0, Time exp = Simulator::Now ())
150  : m_packet (pa),
151  m_ourAdd (us),
152  m_nextHop (n),
153  m_src (s),
154  m_dst (dst),
155  m_ackId (ackId),
156  m_segsLeft (segs),
157  m_expire (exp + Simulator::Now ())
158  {
159  }
160 
161  // Fields
163  {
164  return m_packet;
165  }
167  {
168  m_packet = p;
169  }
171  {
172  return m_ourAdd;
173  }
175  {
176  m_ourAdd = us;
177  }
179  {
180  return m_nextHop;
181  }
183  {
184  m_nextHop = n;
185  }
187  {
188  return m_dst;
189  }
191  {
192  m_dst = n;
193  }
195  {
196  return m_src;
197  }
199  {
200  m_src = s;
201  }
202  uint16_t GetAckId () const
203  {
204  return m_ackId;
205  }
206  void SetAckId (uint16_t ackId)
207  {
208  m_ackId = ackId;
209  }
210  uint8_t GetSegsLeft () const
211  {
212  return m_segsLeft;
213  }
214  void SetSegsLeft (uint8_t segs)
215  {
216  m_segsLeft = segs;
217  }
218  void SetExpireTime (Time exp)
219  {
220  m_expire = exp + Simulator::Now ();
221  }
223  {
224  return m_expire - Simulator::Now ();
225  }
226 
227 private:
239  uint16_t m_ackId;
241  uint8_t m_segsLeft;
244 };
249 /************************************************************************************************************************/
251 {
252 public:
257  {
258  }
260  bool Enqueue (DsrMaintainBuffEntry & entry);
262  bool Dequeue (Ipv4Address dst, DsrMaintainBuffEntry & entry);
264  void DropPacketWithNextHop (Ipv4Address nextHop);
266  bool Find (Ipv4Address nextHop);
268  uint32_t GetSize ();
269 
270  // Fields
271  uint32_t GetMaxQueueLen () const
272  {
273  return m_maxLen;
274  }
275  void SetMaxQueueLen (uint32_t len)
276  {
277  m_maxLen = len;
278  }
280  {
282  }
284  {
286  }
288  bool AllEqual (DsrMaintainBuffEntry & entry);
290  bool LinkEqual (DsrMaintainBuffEntry & entry);
292  bool NetworkEqual (DsrMaintainBuffEntry & entry);
294  bool PromiscEqual (DsrMaintainBuffEntry & entry);
295 
296 private:
298  std::vector<DsrMaintainBuffEntry> m_maintainBuffer;
299  std::vector<NetworkKey> m_allNetworkKey;
301  void Purge ();
303  uint32_t m_maxLen;
307  static bool IsEqual (DsrMaintainBuffEntry en, const Ipv4Address nextHop)
308  {
309  return (en.GetNextHop () == nextHop);
310  }
311 };
312 /*******************************************************************************************************************************/
313 } // namespace dsr
314 } // namespace ns3
315 #endif /* DSR_MAINTAIN_BUFF_H */
DsrMaintainBuffer()
Default constructor.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Ipv4Address GetDst() const
Control the scheduling of simulation events.
Definition: simulator.h:68
uint8_t GetSegsLeft() const
Ipv4Address GetOurAdd() const
void SetMaxQueueLen(uint32_t len)
bool NetworkEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for network ack.
DSR Maintain Buffer Entry.
Ipv4Address GetSrc() const
void SetDst(Ipv4Address n)
void DropPacketWithNextHop(Ipv4Address nextHop)
Remove all packets with destination IP address dst.
bool AllEqual(DsrMaintainBuffEntry &entry)
Verify if all the elements in the maintainence buffer entry is the same.
uint16_t GetAckId() const
void SetNextHop(Ipv4Address n)
Ipv4Address GetNextHop() const
void SetSegsLeft(uint8_t segs)
bool operator<(const NetworkKey &o) const
Compare maintain Buffer entries.
uint16_t m_ackId
The data ack id.
uint32_t GetSize()
Number of entries.
bool Find(Ipv4Address nextHop)
Finds whether a packet with destination dst exists in the queue.
uint8_t m_segsLeft
The segments left field.
Ptr< const Packet > GetPacket() const
Ipv4Address m_ourAdd
Our own ip address.
std::vector< NetworkKey > m_allNetworkKey
bool PromiscEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for promiscuous ack.
void SetExpireTime(Time exp)
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetAckId(uint16_t ackId)
Time m_maintainBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
static bool IsEqual(DsrMaintainBuffEntry en, const Ipv4Address nextHop)
Verify if the maintain buffer is equal or not.
void Purge()
Remove all expired entries.
void SetOurAdd(Ipv4Address us)
std::vector< DsrMaintainBuffEntry > m_maintainBuffer
The vector of maintain buffer entries.
Ipv4Address m_src
The source address.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
Ipv4Address m_nextHop
Next hop Ip address.
bool Dequeue(Ipv4Address dst, DsrMaintainBuffEntry &entry)
Return first found (the earliest) entry for given destination.
void SetPacket(Ptr< const Packet > p)
bool operator<(const PassiveKey &o) const
Compare maintain Buffer entries.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
Time m_expire
Expire time for queue entry.
bool Enqueue(DsrMaintainBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
bool LinkEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for link ack.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:340
Ptr< const Packet > m_packet
Data packet.
Ipv4Address m_dst
The destination address.
uint32_t GetMaxQueueLen() const
Time GetExpireTime() const
void SetSrc(Ipv4Address s)
DsrMaintainBuffEntry(Ptr< const Packet > pa=0, Ipv4Address us=Ipv4Address(), Ipv4Address n=Ipv4Address(), Ipv4Address s=Ipv4Address(), Ipv4Address dst=Ipv4Address(), uint16_t ackId=0, uint8_t segs=0, Time exp=Simulator::Now())
Construct a DsrMaintainBuffEntry with the given parameters.