A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-passive-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_PASSIVEBUFF_H
32#define DSR_PASSIVEBUFF_H
33
34#include "ns3/ipv4-routing-protocol.h"
35#include "ns3/simulator.h"
36
37#include <vector>
38
39namespace ns3
40{
41namespace dsr
42{
48{
49 public:
67 uint16_t i = 0,
68 uint16_t f = 0,
69 uint8_t seg = 0,
70 Time exp = Simulator::Now(),
71 uint8_t p = 0)
72 : m_packet(pa),
73 m_dst(d),
74 m_source(s),
75 m_nextHop(n),
78 m_segsLeft(seg),
79 m_expire(exp + Simulator::Now()),
80 m_protocol(p)
81 {
82 }
83
89 bool operator==(const DsrPassiveBuffEntry& o) const
90 {
91 return ((m_packet == o.m_packet) && (m_source == o.m_source) &&
92 (m_nextHop == o.m_nextHop) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
93 }
94
95 // Fields
101 {
102 return m_packet;
103 }
104
110 {
111 m_packet = p;
112 }
113
119 {
120 return m_dst;
121 }
122
128 {
129 m_dst = d;
130 }
131
137 {
138 return m_source;
139 }
140
146 {
147 m_source = s;
148 }
149
155 {
156 return m_nextHop;
157 }
158
164 {
165 m_nextHop = n;
166 }
167
172 uint16_t GetIdentification() const
173 {
174 return m_identification;
175 }
176
181 void SetIdentification(uint16_t i)
182 {
184 }
185
190 uint16_t GetFragmentOffset() const
191 {
192 return m_fragmentOffset;
193 }
194
199 void SetFragmentOffset(uint16_t f)
200 {
202 }
203
208 uint8_t GetSegsLeft() const
209 {
210 return m_segsLeft;
211 }
212
217 void SetSegsLeft(uint8_t seg)
218 {
219 m_segsLeft = seg;
220 }
221
227 {
228 m_expire = exp + Simulator::Now();
229 }
230
236 {
237 return m_expire - Simulator::Now();
238 }
239
244 void SetProtocol(uint8_t p)
245 {
246 m_protocol = p;
247 }
248
253 uint8_t GetProtocol() const
254 {
255 return m_protocol;
256 }
257
258 private:
272 uint8_t m_segsLeft;
276 uint8_t m_protocol;
277};
278
284/************************************************************************************************************************/
286{
287 public:
292 static TypeId GetTypeId();
293
295 ~DsrPassiveBuffer() override;
296
301 bool Enqueue(DsrPassiveBuffEntry& entry);
306 bool Dequeue(Ipv4Address dst, DsrPassiveBuffEntry& entry);
310 bool Find(Ipv4Address dst);
316 bool AllEqual(DsrPassiveBuffEntry& entry);
320
321 // Fields
327 {
328 return m_maxLen;
329 }
330
336 {
337 m_maxLen = len;
338 }
339
345 {
347 }
348
354 {
356 }
357
358 private:
360 std::vector<DsrPassiveBuffEntry> m_passiveBuffer;
362 void Purge();
366 void Drop(DsrPassiveBuffEntry en, std::string reason);
370 void DropLink(DsrPassiveBuffEntry en, std::string reason);
376
381 static bool LinkEqual(DsrPassiveBuffEntry en, const std::vector<Ipv4Address> link)
382 {
383 return ((en.GetSource() == link[0]) && (en.GetNextHop() == link[1]));
384 }
385};
386
387/*******************************************************************************************************************************/
388} // namespace dsr
389} // namespace ns3
390
391#endif /* DSR_PASSIVEBUFF_H */
double f(double x, void *params)
Definition: 80211b.c:70
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
A base class which provides memory management and object aggregation.
Definition: object.h:89
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
a unique identifier for an interface.
Definition: type-id.h:59
DSR Passive Buffer Entry.
bool operator==(const DsrPassiveBuffEntry &o) const
Compare send buffer entries.
uint8_t m_protocol
The protocol number.
void SetExpireTime(Time exp)
Set expire time.
uint16_t m_fragmentOffset
Fragment offset.
Ipv4Address GetDestination() const
Get destination address function.
void SetIdentification(uint16_t i)
Set identification function.
void SetDestination(Ipv4Address d)
Set destination address function.
uint8_t m_segsLeft
Segments left.
uint8_t GetProtocol() const
Get protocol.
Ipv4Address m_dst
Destination address.
void SetNextHop(Ipv4Address n)
Set next hop address function.
Ptr< const Packet > GetPacket() const
Get packet function.
Ipv4Address GetNextHop() const
Get next hop address function.
void SetSegsLeft(uint8_t seg)
Set segments left.
uint16_t m_identification
Identification.
Ipv4Address GetSource() const
Get source address function.
void SetSource(Ipv4Address s)
Set surce address function.
Ipv4Address m_nextHop
Nexthop address.
Ptr< const Packet > m_packet
Data packet.
void SetProtocol(uint8_t p)
Set protocol function.
Time GetExpireTime() const
Get expire time.
DsrPassiveBuffEntry(Ptr< const Packet > pa=nullptr, Ipv4Address d=Ipv4Address(), Ipv4Address s=Ipv4Address(), Ipv4Address n=Ipv4Address(), uint16_t i=0, uint16_t f=0, uint8_t seg=0, Time exp=Simulator::Now(), uint8_t p=0)
Construct a DsrPassiveBuffEntry with the given parameters.
uint8_t GetSegsLeft() const
Get segments left function.
void SetPacket(Ptr< const Packet > p)
Set packet function.
uint16_t GetIdentification() const
Get identification function.
uint16_t GetFragmentOffset() const
Get fragment offset function.
Ipv4Address m_source
Source address.
Time m_expire
Expire time for queue entry.
void SetFragmentOffset(uint16_t f)
Set fragment offset function.
Time GetPassiveBufferTimeout() const
Get passive buffer timeout.
bool Enqueue(DsrPassiveBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
void SetPassiveBufferTimeout(Time t)
Set passive buffer timeout.
uint32_t GetSize()
Number of entries.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
bool Dequeue(Ipv4Address dst, DsrPassiveBuffEntry &entry)
Return first found (the earliest) entry for given destination.
void DropLink(DsrPassiveBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
Time m_passiveBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
void Purge()
Remove all expired entries.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
static bool LinkEqual(DsrPassiveBuffEntry en, const std::vector< Ipv4Address > link)
Check if the send buffer entry is the same or not.
std::vector< DsrPassiveBuffEntry > m_passiveBuffer
The send buffer to cache unsent packet.
void Drop(DsrPassiveBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
static TypeId GetTypeId()
Get the type ID.
bool AllEqual(DsrPassiveBuffEntry &entry)
Check if all the entries in passive buffer entry is all equal or not.
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.