A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
162  // \{
164  {
165  return m_packet;
166  }
168  {
169  m_packet = p;
170  }
172  {
173  return m_ourAdd;
174  }
176  {
177  m_ourAdd = us;
178  }
180  {
181  return m_nextHop;
182  }
184  {
185  m_nextHop = n;
186  }
188  {
189  return m_dst;
190  }
192  {
193  m_dst = n;
194  }
196  {
197  return m_src;
198  }
200  {
201  m_src = s;
202  }
203  uint16_t GetAckId () const
204  {
205  return m_ackId;
206  }
207  void SetAckId (uint16_t ackId)
208  {
209  m_ackId = ackId;
210  }
211  uint8_t GetSegsLeft () const
212  {
213  return m_segsLeft;
214  }
215  void SetSegsLeft (uint8_t segs)
216  {
217  m_segsLeft = segs;
218  }
219  void SetExpireTime (Time exp)
220  {
221  m_expire = exp + Simulator::Now ();
222  }
224  {
225  return m_expire - Simulator::Now ();
226  }
227  // \}
228 private:
240  uint16_t m_ackId;
242  uint8_t m_segsLeft;
245 };
250 /************************************************************************************************************************/
252 {
253 public:
258  {
259  }
261  bool Enqueue (MaintainBuffEntry & entry);
263  bool Dequeue (Ipv4Address dst, MaintainBuffEntry & entry);
265  void DropPacketWithNextHop (Ipv4Address nextHop);
267  bool Find (Ipv4Address nextHop);
269  uint32_t GetSize ();
271  // \{
272  uint32_t GetMaxQueueLen () const
273  {
274  return m_maxLen;
275  }
276  void SetMaxQueueLen (uint32_t len)
277  {
278  m_maxLen = len;
279  }
281  {
283  }
285  {
287  }
289  bool AllEqual (MaintainBuffEntry & entry);
291  bool LinkEqual (MaintainBuffEntry & entry);
293  bool NetworkEqual (MaintainBuffEntry & entry);
295  bool PromiscEqual (MaintainBuffEntry & entry);
296  // \}
297 
298 private:
300  std::vector<MaintainBuffEntry> m_maintainBuffer;
301  std::vector<NetworkKey> m_allNetworkKey;
303  void Purge ();
305  uint32_t m_maxLen;
309  static bool IsEqual (MaintainBuffEntry en, const Ipv4Address nextHop)
310  {
311  return (en.GetNextHop () == nextHop);
312  }
313 };
314 /*******************************************************************************************************************************/
315 } // namespace dsr
316 } // namespace ns3
317 #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:79
void SetDst(Ipv4Address n)
Ipv4Address m_src
The source address.
Control the scheduling of simulation events.
Definition: simulator.h:63
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.
Ipv4Address GetDst() const
Ipv4Address m_dst
The destination address.
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
MaintainBuffer()
Default constructor.
DSR Maintain Buffer Entry.
void SetMaintainBufferTimeout(Time t)
Verify if all the elements in the maintainence buffer entry is the same.
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:38
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
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 GetMaintainBufferTimeout() const
Verify if all the elements in the maintainence buffer entry is the same.
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
Verify if all the elements in the maintainence buffer entry is the same.
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)
Verify if all the elements in the maintainence buffer entry is the same.
uint8_t GetSegsLeft() const
void SetAckId(uint16_t ackId)
std::vector< MaintainBuffEntry > m_maintainBuffer
The vector of maintain buffer entries.
Ipv4Address GetNextHop() const