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 
58  bool operator < (LinkKey const & o) const
59  {
60  return ((m_source < o.m_source) && (m_destination < o.m_destination)
61  && (m_ourAdd < o.m_nextHop) && (m_nextHop < o.m_nextHop)
62  );
63  }
64 };
65 
66 struct NetworkKey
67 {
68  uint16_t m_ackId;
73 
78  bool operator < (NetworkKey const & o) const
79  {
80  return ((m_ackId < o.m_ackId) && (m_ourAdd < o.m_ourAdd) && (m_nextHop < o.m_nextHop) && (m_source < o.m_source)
82  );
83  }
84 };
85 
86 struct PassiveKey
87 {
88  uint16_t m_ackId;
91  uint8_t m_segsLeft;
92 
97  bool operator < (PassiveKey const & o) const
98  {
99  return ((m_ackId < o.m_ackId) && (m_source < o.m_source)
101  );
102  }
103 };
104 
110 {
111 public:
112  // / c-tor
115  uint16_t ackId = 0, uint8_t segs = 0, Time exp = Simulator::Now ())
116  : m_packet (pa),
117  m_ourAdd (us),
118  m_nextHop (n),
119  m_src (s),
120  m_dst (dst),
121  m_ackId (ackId),
122  m_segsLeft (segs),
123  m_expire (exp + Simulator::Now ())
124  {
125  }
126 
127  // /\name Fields
128  // \{
130  {
131  return m_packet;
132  }
134  {
135  m_packet = p;
136  }
138  {
139  return m_ourAdd;
140  }
142  {
143  m_ourAdd = us;
144  }
146  {
147  return m_nextHop;
148  }
150  {
151  m_nextHop = n;
152  }
154  {
155  return m_dst;
156  }
158  {
159  m_dst = n;
160  }
162  {
163  return m_src;
164  }
166  {
167  m_src = s;
168  }
169  uint16_t GetAckId () const
170  {
171  return m_ackId;
172  }
173  void SetAckId (uint16_t ackId)
174  {
175  m_ackId = ackId;
176  }
177  uint8_t GetSegsLeft () const
178  {
179  return m_segsLeft;
180  }
181  void SetSegsLeft (uint8_t segs)
182  {
183  m_segsLeft = segs;
184  }
185  void SetExpireTime (Time exp)
186  {
187  m_expire = exp + Simulator::Now ();
188  }
190  {
191  return m_expire - Simulator::Now ();
192  }
193  // \}
194 private:
195  // / Data packet
197  // / Our own ip address
199  // / Next hop Ip address
201  // / The source address
203  // / The destination address
205  // / The data ack id
206  uint16_t m_ackId;
207  // / The segments left field
208  uint8_t m_segsLeft;
209  // / Expire time for queue entry
211 };
216 /************************************************************************************************************************/
218 {
219 public:
220  // / Default c-tor
222  {
223  }
224  // / Push entry in queue, if there is no entry with the same packet and destination address in queue.
225  bool Enqueue (MaintainBuffEntry & entry);
226  // / Return first found (the earliest) entry for given destination
227  bool Dequeue (Ipv4Address dst, MaintainBuffEntry & entry);
228  // / Remove all packets with destination IP address dst
229  void DropPacketWithNextHop (Ipv4Address nextHop);
230  // / Finds whether a packet with destination dst exists in the queue
231  bool Find (Ipv4Address nextHop);
232  // / Number of entries
233  uint32_t GetSize ();
234  // /\name Fields
235  // \{
236  uint32_t GetMaxQueueLen () const
237  {
238  return m_maxLen;
239  }
240  void SetMaxQueueLen (uint32_t len)
241  {
242  m_maxLen = len;
243  }
245  {
247  }
249  {
251  }
252  // / Verify if all the elements in the maintainence buffer entry is the same
253  bool AllEqual (MaintainBuffEntry & entry);
254  // / Verify if the maintain buffer entry is the same in every field for link ack
255  bool LinkEqual (MaintainBuffEntry & entry);
256  // / Verify if the maintain buffer entry is the same in every field for network ack
257  bool NetworkEqual (MaintainBuffEntry & entry);
258  // / Verify if the maintain buffer entry is the same in every field for promiscuous ack
259  bool PromiscEqual (MaintainBuffEntry & entry);
260  // \}
261 
262 private:
263  // / The vector of maintain buffer entries
264  std::vector<MaintainBuffEntry> m_maintainBuffer;
265  std::vector<NetworkKey> m_allNetworkKey;
266  // / Remove all expired entries
267  void Purge ();
268  // / The maximum number of packets that we allow a routing protocol to buffer.
269  uint32_t m_maxLen;
270  // / The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
272  // / Verify if the maintain buffer is equal or not
273  static bool IsEqual (MaintainBuffEntry en, const Ipv4Address nextHop)
274  {
275  return (en.GetNextHop () == nextHop);
276  }
277 };
278 /*******************************************************************************************************************************/
279 } // namespace dsr
280 } // namespace ns3
281 #endif /* DSR_MAINTAIN_BUFF_H */
void SetExpireTime(Time exp)
bool NetworkEqual(MaintainBuffEntry &entry)
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
void SetDst(Ipv4Address n)
Ipv4Address m_src
Control the scheduling of simulation events.
Definition: simulator.h:62
uint16_t m_ackId
static bool IsEqual(MaintainBuffEntry en, const Ipv4Address nextHop)
void SetOurAdd(Ipv4Address us)
Time GetExpireTime() const
std::vector< NetworkKey > m_allNetworkKey
void SetSrc(Ipv4Address s)
bool AllEqual(MaintainBuffEntry &entry)
void DropPacketWithNextHop(Ipv4Address nextHop)
Ipv4Address GetOurAdd() const
bool LinkEqual(MaintainBuffEntry &entry)
Ipv4Address m_ourAdd
Ptr< SampleEmitter > s
DSR maintain buffer.
bool Find(Ipv4Address nextHop)
bool PromiscEqual(MaintainBuffEntry &entry)
bool operator<(NetworkKey const &o) const
Ipv4Address m_nextHop
void SetPacket(Ptr< const Packet > p)
Ipv4Address GetSrc() const
uint16_t GetAckId() const
Ipv4Address GetDst() const
Ipv4Address m_dst
static Time Now(void)
Definition: simulator.cc:180
DSR Maintain Buffer Entry.
void SetMaintainBufferTimeout(Time t)
uint8_t m_segsLeft
bool Enqueue(MaintainBuffEntry &entry)
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
Ptr< const Packet > GetPacket() const
Time GetMaintainBufferTimeout() const
bool Dequeue(Ipv4Address dst, MaintainBuffEntry &entry)
Ptr< const Packet > m_packet
void SetNextHop(Ipv4Address n)
bool operator<(PassiveKey const &o) const
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())
void SetMaxQueueLen(uint32_t len)
uint8_t GetSegsLeft() const
void SetAckId(uint16_t ackId)
std::vector< MaintainBuffEntry > m_maintainBuffer
Ipv4Address GetNextHop() const