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
41namespace ns3 {
42namespace dsr {
47struct 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
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{
214public:
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 }
359 {
360 m_expire = exp + Simulator::Now ();
361 }
367 {
368 return m_expire - Simulator::Now ();
369 }
370
371private:
383 uint16_t m_ackId;
385 uint8_t m_segsLeft;
388};
393/************************************************************************************************************************/
395{
396public:
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
429 {
430 return m_maxLen;
431 }
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
475private:
477 std::vector<DsrMaintainBuffEntry> m_maintainBuffer;
479 std::vector<NetworkKey> m_allNetworkKey;
481 void Purge ();
486};
487/*******************************************************************************************************************************/
488} // namespace dsr
489} // namespace ns3
490#endif /* DSR_MAINTAIN_BUFF_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Control the scheduling of simulation events.
Definition: simulator.h:69
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
DSR Maintain Buffer Entry.
uint8_t GetSegsLeft() const
Get segments left.
void SetDst(Ipv4Address n)
Set destination address.
void SetExpireTime(Time exp)
Set expiration time.
void SetNextHop(Ipv4Address n)
Set next hop of entry.
Ipv4Address m_nextHop
Next hop Ip address.
Ipv4Address GetSrc() const
Get source address.
void SetSegsLeft(uint8_t segs)
Set segments left.
void SetPacket(Ptr< const Packet > p)
Set packet.
uint8_t m_segsLeft
The segments left field.
Ptr< const Packet > GetPacket() const
Get packet.
Ipv4Address m_dst
The destination address.
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.
Ptr< const Packet > m_packet
Data packet.
Ipv4Address m_ourAdd
Our own ip address.
void SetOurAdd(Ipv4Address us)
Set local address of entry.
void SetSrc(Ipv4Address s)
Set source address.
uint16_t m_ackId
The data ack id.
uint16_t GetAckId() const
Get acknowledge ID.
Ipv4Address GetOurAdd() const
Get local address of entry.
Time GetExpireTime() const
Get expiration time.
void SetAckId(uint16_t ackId)
Set acknowledge ID.
Time m_expire
Expire time for queue entry.
Ipv4Address GetNextHop() const
Get next hop of entry.
Ipv4Address m_src
The source address.
Ipv4Address GetDst() const
Get destination address.
bool Dequeue(Ipv4Address dst, DsrMaintainBuffEntry &entry)
Return first found (the earliest) entry for given destination.
Time m_maintainBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
void DropPacketWithNextHop(Ipv4Address nextHop)
Remove all packets with next hop IP address dst.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
bool AllEqual(DsrMaintainBuffEntry &entry)
Verify if all the elements in the maintenance buffer entry is the same.
bool LinkEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for link ack.
std::vector< NetworkKey > m_allNetworkKey
The vector of network keys.
bool Find(Ipv4Address nextHop)
Finds whether a packet with next hop dst exists in the queue.
void SetMaintainBufferTimeout(Time t)
Set maintain buffer timeout.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
uint32_t GetSize()
Number of entries.
bool PromiscEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for promiscuous ack.
DsrMaintainBuffer()
Default constructor.
bool NetworkEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for network ack.
bool Enqueue(DsrMaintainBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
std::vector< DsrMaintainBuffEntry > m_maintainBuffer
The vector of maintain buffer entries.
Time GetMaintainBufferTimeout() const
Get maintain buffer timeout.
void Purge()
Remove all expired entries.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Every class exported by the ns3 library is enclosed in the ns3 namespace.
NetworkKey structure.
Ipv4Address m_ourAdd
local address
bool operator<(const NetworkKey &o) const
Compare maintain Buffer entries.
Ipv4Address m_destination
destination address
uint16_t m_ackId
acknowledge ID
Ipv4Address m_source
source address
Ipv4Address m_nextHop
next hop
PassiveKey structure.
Ipv4Address m_destination
destination address
Ipv4Address m_source
source address
bool operator<(const PassiveKey &o) const
Compare maintain Buffer entries.
uint8_t m_segsLeft
segments left
uint16_t m_ackId
acknowledge ID