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 < (LinkKey const & o) const
60  {
61  return ((m_source < o.m_source) && (m_destination < o.m_destination)
62  && (m_ourAdd < o.m_nextHop) && (m_nextHop < o.m_nextHop)
63  );
64  }
65 };
66 
67 struct NetworkKey
68 {
69  uint16_t m_ackId;
74 
80  bool operator < (NetworkKey const & o) const
81  {
82  return ((m_ackId < o.m_ackId) && (m_ourAdd < o.m_ourAdd) && (m_nextHop < o.m_nextHop) && (m_source < o.m_source)
84  );
85  }
86 };
87 
88 struct PassiveKey
89 {
90  uint16_t m_ackId;
93  uint8_t m_segsLeft;
94 
100  bool operator < (PassiveKey const & o) const
101  {
102  return ((m_ackId < o.m_ackId) && (m_source < o.m_source)
104  );
105  }
106 };
107 
113 {
114 public:
129  uint16_t ackId = 0, uint8_t segs = 0, Time exp = Simulator::Now ())
130  : m_packet (pa),
131  m_ourAdd (us),
132  m_nextHop (n),
133  m_src (s),
134  m_dst (dst),
135  m_ackId (ackId),
136  m_segsLeft (segs),
137  m_expire (exp + Simulator::Now ())
138  {
139  }
140 
142  // \{
144  {
145  return m_packet;
146  }
148  {
149  m_packet = p;
150  }
152  {
153  return m_ourAdd;
154  }
156  {
157  m_ourAdd = us;
158  }
160  {
161  return m_nextHop;
162  }
164  {
165  m_nextHop = n;
166  }
168  {
169  return m_dst;
170  }
172  {
173  m_dst = n;
174  }
176  {
177  return m_src;
178  }
180  {
181  m_src = s;
182  }
183  uint16_t GetAckId () const
184  {
185  return m_ackId;
186  }
187  void SetAckId (uint16_t ackId)
188  {
189  m_ackId = ackId;
190  }
191  uint8_t GetSegsLeft () const
192  {
193  return m_segsLeft;
194  }
195  void SetSegsLeft (uint8_t segs)
196  {
197  m_segsLeft = segs;
198  }
199  void SetExpireTime (Time exp)
200  {
201  m_expire = exp + Simulator::Now ();
202  }
204  {
205  return m_expire - Simulator::Now ();
206  }
207  // \}
208 private:
220  uint16_t m_ackId;
222  uint8_t m_segsLeft;
225 };
230 /************************************************************************************************************************/
232 {
233 public:
238  {
239  }
241  bool Enqueue (MaintainBuffEntry & entry);
243  bool Dequeue (Ipv4Address dst, MaintainBuffEntry & entry);
245  void DropPacketWithNextHop (Ipv4Address nextHop);
247  bool Find (Ipv4Address nextHop);
249  uint32_t GetSize ();
251  // \{
252  uint32_t GetMaxQueueLen () const
253  {
254  return m_maxLen;
255  }
256  void SetMaxQueueLen (uint32_t len)
257  {
258  m_maxLen = len;
259  }
261  {
263  }
265  {
267  }
269  bool AllEqual (MaintainBuffEntry & entry);
271  bool LinkEqual (MaintainBuffEntry & entry);
273  bool NetworkEqual (MaintainBuffEntry & entry);
275  bool PromiscEqual (MaintainBuffEntry & entry);
276  // \}
277 
278 private:
280  std::vector<MaintainBuffEntry> m_maintainBuffer;
281  std::vector<NetworkKey> m_allNetworkKey;
283  void Purge ();
285  uint32_t m_maxLen;
289  static bool IsEqual (MaintainBuffEntry en, const Ipv4Address nextHop)
290  {
291  return (en.GetNextHop () == nextHop);
292  }
293 };
294 /*******************************************************************************************************************************/
295 } // namespace dsr
296 } // namespace ns3
297 #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.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
void SetDst(Ipv4Address n)
Ipv4Address m_src
The source address.
Control the scheduling of simulation events.
Definition: simulator.h:62
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.
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.
bool operator<(NetworkKey const &o) const
Compare maintain Buffer entries.
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...
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)
bool operator<(PassiveKey const &o) const
Compare maintain Buffer entries.
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