A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-maintain-buff.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Yufei Cheng
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
18 *
19 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
20 * ResiliNets Research Group https://resilinets.org/
21 * Information and Telecommunication Technology Center (ITTC)
22 * and Department of Electrical Engineering and Computer Science
23 * The University of Kansas Lawrence, KS USA.
24 *
25 * Work supported in part by NSF FIND (Future Internet Design) Program
26 * under grant CNS-0626918 (Postmodern Internet Architecture),
27 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
28 * US Department of Defense (DoD), and ITTC at The University of Kansas.
29 */
30
31#ifndef DSR_MAINTAIN_BUFF_H
32#define DSR_MAINTAIN_BUFF_H
33
34#include "dsr-option-header.h"
35
36#include "ns3/ipv4-header.h"
37#include "ns3/ipv4-routing-protocol.h"
38#include "ns3/simulator.h"
39
40#include <vector>
41
42namespace ns3
43{
44namespace dsr
45{
51struct LinkKey
52{
57
63 bool operator<(const LinkKey& o) const
64 {
65 if (m_source < o.m_source)
66 {
67 return true;
68 }
69 if (o.m_source < m_source)
70 {
71 return false;
72 }
74 {
75 return true;
76 }
78 {
79 return false;
80 }
81 if (m_ourAdd < o.m_ourAdd)
82 {
83 return true;
84 }
85 if (o.m_ourAdd < m_ourAdd)
86 {
87 return false;
88 }
89 if (m_nextHop < o.m_nextHop)
90 {
91 return true;
92 }
93 if (o.m_nextHop < m_nextHop)
94 {
95 return false;
96 }
97 return false;
98 }
99};
100
103{
104 uint16_t m_ackId;
109
115 bool operator<(const NetworkKey& o) const
116 {
117 if (m_ackId < o.m_ackId)
118 {
119 return true;
120 }
121 if (o.m_ackId < m_ackId)
122 {
123 return false;
124 }
125 if (m_source < o.m_source)
126 {
127 return true;
128 }
129 if (o.m_source < m_source)
130 {
131 return false;
132 }
134 {
135 return true;
136 }
138 {
139 return false;
140 }
141 if (m_ourAdd < o.m_ourAdd)
142 {
143 return true;
144 }
145 if (o.m_ourAdd < m_ourAdd)
146 {
147 return false;
148 }
149 if (m_nextHop < o.m_nextHop)
150 {
151 return true;
152 }
153 if (o.m_nextHop < m_nextHop)
154 {
155 return false;
156 }
157 return false;
158 }
159};
160
163{
164 uint16_t m_ackId;
167 uint8_t m_segsLeft;
168
174 bool operator<(const PassiveKey& o) const
175 {
176 if (m_ackId < o.m_ackId)
177 {
178 return true;
179 }
180 if (o.m_ackId < m_ackId)
181 {
182 return false;
183 }
184 if (m_source < o.m_source)
185 {
186 return true;
187 }
188 if (o.m_source < m_source)
189 {
190 return false;
191 }
193 {
194 return true;
195 }
197 {
198 return false;
199 }
200 if (m_segsLeft < o.m_segsLeft)
201 {
202 return true;
203 }
204 if (o.m_segsLeft < m_segsLeft)
205 {
206 return false;
207 }
208 return false;
209 }
210};
211
217{
218 public:
232 Ipv4Address ourAddress = Ipv4Address(),
233 Ipv4Address nextHop = Ipv4Address(),
234 Ipv4Address src = Ipv4Address(),
235 Ipv4Address dst = Ipv4Address(),
236 uint16_t ackId = 0,
237 uint8_t segsLeft = 0,
238 Time expire = Simulator::Now())
239 : m_packet(packet),
240 m_ourAdd(ourAddress),
241 m_nextHop(nextHop),
242 m_src(src),
243 m_dst(dst),
244 m_ackId(ackId),
245 m_segsLeft(segsLeft),
246 m_expire(expire + Simulator::Now())
247 {
248 }
249
250 // Fields
256 {
257 return m_packet;
258 }
259
265 {
266 m_packet = p;
267 }
268
274 {
275 return m_ourAdd;
276 }
277
283 {
284 m_ourAdd = us;
285 }
286
292 {
293 return m_nextHop;
294 }
295
301 {
302 m_nextHop = n;
303 }
304
310 {
311 return m_dst;
312 }
313
319 {
320 m_dst = n;
321 }
322
328 {
329 return m_src;
330 }
331
337 {
338 m_src = s;
339 }
340
345 uint16_t GetAckId() const
346 {
347 return m_ackId;
348 }
349
354 void SetAckId(uint16_t ackId)
355 {
356 m_ackId = ackId;
357 }
358
363 uint8_t GetSegsLeft() const
364 {
365 return m_segsLeft;
366 }
367
372 void SetSegsLeft(uint8_t segs)
373 {
374 m_segsLeft = segs;
375 }
376
382 {
383 m_expire = exp + Simulator::Now();
384 }
385
391 {
392 return m_expire - Simulator::Now();
393 }
394
395 private:
407 uint16_t m_ackId;
409 uint8_t m_segsLeft;
412};
413
418/************************************************************************************************************************/
420{
421 public:
426 {
427 }
428
433 bool Enqueue(DsrMaintainBuffEntry& entry);
438 bool Dequeue(Ipv4Address dst, DsrMaintainBuffEntry& entry);
445 bool Find(Ipv4Address nextHop);
449
450 // Fields
456 {
457 return m_maxLen;
458 }
459
465 {
466 m_maxLen = len;
467 }
468
474 {
476 }
477
483 {
485 }
486
492 bool AllEqual(DsrMaintainBuffEntry& entry);
496 bool LinkEqual(DsrMaintainBuffEntry& entry);
505
506 private:
508 std::vector<DsrMaintainBuffEntry> m_maintainBuffer;
510 std::vector<NetworkKey> m_allNetworkKey;
512 void Purge();
518};
519
520/*******************************************************************************************************************************/
521} // namespace dsr
522} // namespace ns3
523#endif /* DSR_MAINTAIN_BUFF_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Control the scheduling of simulation events.
Definition: simulator.h:68
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
DSR Maintain Buffer Entry.
uint8_t GetSegsLeft() const
Get segments left.
void SetDst(Ipv4Address n)
Set destination address.
DsrMaintainBuffEntry(Ptr< const Packet > packet=nullptr, Ipv4Address ourAddress=Ipv4Address(), Ipv4Address nextHop=Ipv4Address(), Ipv4Address src=Ipv4Address(), Ipv4Address dst=Ipv4Address(), uint16_t ackId=0, uint8_t segsLeft=0, Time expire=Simulator::Now())
Construct a DsrMaintainBuffEntry with the given parameters.
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.
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()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
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