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)
62  {
63  return true;
64  }
65  if (o.m_source < m_source)
66  {
67  return false;
68  }
70  {
71  return true;
72  }
74  {
75  return false;
76  }
77  if (m_ourAdd < o.m_ourAdd)
78  {
79  return true;
80  }
81  if (o.m_ourAdd < m_ourAdd)
82  {
83  return false;
84  }
85  if (m_nextHop < o.m_nextHop)
86  {
87  return true;
88  }
89  if (o.m_nextHop < m_nextHop)
90  {
91  return false;
92  }
93  return false;
94  }
95 };
96 
98 struct NetworkKey
99 {
100  uint16_t m_ackId;
105 
111  bool operator < (const NetworkKey & o) const
112  {
113  if (m_ackId < o.m_ackId)
114  {
115  return true;
116  }
117  if (o.m_ackId < m_ackId)
118  {
119  return false;
120  }
121  if (m_source < o.m_source)
122  {
123  return true;
124  }
125  if (o.m_source < m_source)
126  {
127  return false;
128  }
130  {
131  return true;
132  }
134  {
135  return false;
136  }
137  if (m_ourAdd < o.m_ourAdd)
138  {
139  return true;
140  }
141  if (o.m_ourAdd < m_ourAdd)
142  {
143  return false;
144  }
145  if (m_nextHop < o.m_nextHop)
146  {
147  return true;
148  }
149  if (o.m_nextHop < m_nextHop)
150  {
151  return false;
152  }
153  return false;
154  }
155 };
156 
159 {
160  uint16_t m_ackId;
163  uint8_t m_segsLeft;
164 
170  bool operator < (const PassiveKey & o) const
171  {
172  if (m_ackId < o.m_ackId)
173  {
174  return true;
175  }
176  if (o.m_ackId < m_ackId)
177  {
178  return false;
179  }
180  if (m_source < o.m_source)
181  {
182  return true;
183  }
184  if (o.m_source < m_source)
185  {
186  return false;
187  }
189  {
190  return true;
191  }
193  {
194  return false;
195  }
196  if (m_segsLeft < o.m_segsLeft)
197  {
198  return true;
199  }
200  if (o.m_segsLeft < m_segsLeft)
201  {
202  return false;
203  }
204  return false;
205  }
206 };
207 
213 {
214 public:
229  uint16_t ackId = 0, uint8_t segs = 0, Time exp = Simulator::Now ())
230  : m_packet (pa),
231  m_ourAdd (us),
232  m_nextHop (n),
233  m_src (s),
234  m_dst (dst),
235  m_ackId (ackId),
236  m_segsLeft (segs),
237  m_expire (exp + Simulator::Now ())
238  {
239  }
240 
241  // Fields
247  {
248  return m_packet;
249  }
255  {
256  m_packet = p;
257  }
263  {
264  return m_ourAdd;
265  }
271  {
272  m_ourAdd = us;
273  }
279  {
280  return m_nextHop;
281  }
287  {
288  m_nextHop = n;
289  }
295  {
296  return m_dst;
297  }
303  {
304  m_dst = n;
305  }
311  {
312  return m_src;
313  }
319  {
320  m_src = s;
321  }
326  uint16_t GetAckId () const
327  {
328  return m_ackId;
329  }
334  void SetAckId (uint16_t ackId)
335  {
336  m_ackId = ackId;
337  }
342  uint8_t GetSegsLeft () const
343  {
344  return m_segsLeft;
345  }
350  void SetSegsLeft (uint8_t segs)
351  {
352  m_segsLeft = segs;
353  }
358  void SetExpireTime (Time exp)
359  {
360  m_expire = exp + Simulator::Now ();
361  }
367  {
368  return m_expire - Simulator::Now ();
369  }
370 
371 private:
383  uint16_t m_ackId;
385  uint8_t m_segsLeft;
388 };
393 /************************************************************************************************************************/
395 {
396 public:
401  {
402  }
406  bool Enqueue (DsrMaintainBuffEntry & entry);
411  bool Dequeue (Ipv4Address dst, DsrMaintainBuffEntry & entry);
414  void DropPacketWithNextHop (Ipv4Address nextHop);
418  bool Find (Ipv4Address nextHop);
421  uint32_t GetSize ();
422 
423  // Fields
428  uint32_t GetMaxQueueLen () const
429  {
430  return m_maxLen;
431  }
436  void SetMaxQueueLen (uint32_t len)
437  {
438  m_maxLen = len;
439  }
445  {
447  }
453  {
455  }
461  bool AllEqual (DsrMaintainBuffEntry & entry);
465  bool LinkEqual (DsrMaintainBuffEntry & entry);
469  bool NetworkEqual (DsrMaintainBuffEntry & entry);
473  bool PromiscEqual (DsrMaintainBuffEntry & entry);
474 
475 private:
477  std::vector<DsrMaintainBuffEntry> m_maintainBuffer;
479  std::vector<NetworkKey> m_allNetworkKey;
481  void Purge ();
483  uint32_t m_maxLen;
490  static bool IsEqual (DsrMaintainBuffEntry en, const Ipv4Address nextHop)
491  {
492  return (en.GetNextHop () == nextHop);
493  }
494 };
495 /*******************************************************************************************************************************/
496 } // namespace dsr
497 } // namespace ns3
498 #endif /* DSR_MAINTAIN_BUFF_H */
DsrMaintainBuffer()
Default constructor.
uint8_t GetSegsLeft() const
Get segments left.
Time GetMaintainBufferTimeout() const
Get maintain buffer timeout.
Ipv4Address m_ourAdd
local address
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Control the scheduling of simulation events.
Definition: simulator.h:68
uint16_t m_ackId
acknowledge ID
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
Ipv4Address m_source
source address
bool NetworkEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for network ack.
DSR Maintain Buffer Entry.
Ipv4Address m_destination
destination address
void SetDst(Ipv4Address n)
Set destination address.
void DropPacketWithNextHop(Ipv4Address nextHop)
Remove all packets with next hop IP address dst.
Ipv4Address GetDst() const
Get destination address.
bool AllEqual(DsrMaintainBuffEntry &entry)
Verify if all the elements in the maintenance buffer entry is the same.
void SetNextHop(Ipv4Address n)
Set next hop of entry.
void SetSegsLeft(uint8_t segs)
Set segments left.
bool operator<(const NetworkKey &o) const
Compare maintain Buffer entries.
Ipv4Address m_nextHop
next hop
Ipv4Address m_destination
destination address
uint16_t m_ackId
The data ack id.
uint32_t GetSize()
Number of entries.
uint8_t m_segsLeft
segments left
bool Find(Ipv4Address nextHop)
Finds whether a packet with next hop dst exists in the queue.
uint8_t m_segsLeft
The segments left field.
Ipv4Address m_ourAdd
Our own ip address.
std::vector< NetworkKey > m_allNetworkKey
The vector of network keys.
Ptr< const Packet > GetPacket() const
Get packet.
Ipv4Address GetSrc() const
Get source address.
bool PromiscEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for promiscuous ack.
PassiveKey structure.
void SetExpireTime(Time exp)
Set expiration time.
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 SetMaintainBufferTimeout(Time t)
Set maintain buffer timeout.
void SetAckId(uint16_t ackId)
Set acknowledge ID.
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.
Ipv4Address m_source
source address
Time GetExpireTime() const
Get expiration time.
void Purge()
Remove all expired entries.
void SetOurAdd(Ipv4Address us)
Set local address of entry.
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:249
Ipv4Address GetOurAdd() const
Get local address of entry.
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)
Set packet.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
NetworkKey structure.
Ipv4Address GetNextHop() const
Get next hop of entry.
Time m_expire
Expire time for queue entry.
bool operator<(const PassiveKey &o) const
Compare maintain Buffer entries.
bool Enqueue(DsrMaintainBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
uint16_t m_ackId
acknowledge ID
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:365
Ptr< const Packet > m_packet
Data packet.
Ipv4Address m_dst
The destination address.
void SetSrc(Ipv4Address s)
Set source address.
uint16_t GetAckId() const
Get acknowledge ID.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
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.