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 (MaintainBuffEntry & entry);
262  bool Dequeue (Ipv4Address dst, MaintainBuffEntry & 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 (MaintainBuffEntry & entry);
290  bool LinkEqual (MaintainBuffEntry & entry);
292  bool NetworkEqual (MaintainBuffEntry & entry);
294  bool PromiscEqual (MaintainBuffEntry & entry);
295 
296 private:
298  std::vector<MaintainBuffEntry> m_maintainBuffer;
299  std::vector<NetworkKey> m_allNetworkKey;
301  void Purge ();
303  uint32_t m_maxLen;
307  static bool IsEqual (MaintainBuffEntry 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 */
void SetExpireTime(Time exp)
bool NetworkEqual(MaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for network ack.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
void SetDst(Ipv4Address n)
Ipv4Address m_src
The source address.
Control the scheduling of simulation events.
Definition: simulator.h:70
uint16_t m_ackId
The data ack id.
static bool IsEqual(MaintainBuffEntry en, const Ipv4Address nextHop)
Verify if the maintain buffer is equal or not.
void SetOurAdd(Ipv4Address us)
Time GetExpireTime() const
std::vector< NetworkKey > m_allNetworkKey
void SetSrc(Ipv4Address s)
bool AllEqual(MaintainBuffEntry &entry)
Verify if all the elements in the maintainence buffer entry is the same.
bool operator<(const NetworkKey &o) const
Compare maintain Buffer entries.
void DropPacketWithNextHop(Ipv4Address nextHop)
Remove all packets with destination IP address dst.
Ipv4Address GetOurAdd() const
bool LinkEqual(MaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for link ack.
Ipv4Address m_ourAdd
Our own ip address.
Ptr< SampleEmitter > s
DSR maintain buffer.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
bool Find(Ipv4Address nextHop)
Finds whether a packet with destination dst exists in the queue.
bool PromiscEqual(MaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for promiscuous ack.
Ipv4Address m_nextHop
Next hop Ip address.
void SetPacket(Ptr< const Packet > p)
Ipv4Address GetSrc() const
uint16_t GetAckId() const
Time m_maintainBufferTimeout
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 GetDst() const
Ipv4Address m_dst
The destination address.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
MaintainBuffer()
Default constructor.
DSR Maintain Buffer Entry.
void SetMaintainBufferTimeout(Time t)
uint8_t m_segsLeft
The segments left field.
uint32_t GetSize()
Number of entries.
bool Enqueue(MaintainBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
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
void SetSegsLeft(uint8_t segs)
Time m_expire
Expire time for queue entry.
void Purge()
Remove all expired entries.
Ptr< const Packet > GetPacket() const
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:330
Time GetMaintainBufferTimeout() const
bool Dequeue(Ipv4Address dst, MaintainBuffEntry &entry)
Return first found (the earliest) entry for given destination.
Ptr< const Packet > m_packet
Data packet.
void SetNextHop(Ipv4Address n)
uint32_t GetMaxQueueLen() const
MaintainBuffEntry(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 MaintainBuffEntry with the given parameters.
void SetMaxQueueLen(uint32_t len)
uint8_t GetSegsLeft() const
void SetAckId(uint16_t ackId)
std::vector< MaintainBuffEntry > m_maintainBuffer
The vector of maintain buffer entries.
Ipv4Address GetNextHop() const