A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-errorbuff.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_ERRORBUFF_H
32#define DSR_ERRORBUFF_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:
64 Time exp = Simulator::Now(),
65 uint8_t p = 0)
66 : m_packet(pa),
67 m_dst(d),
68 m_source(s),
69 m_nextHop(n),
70 m_expire(exp + Simulator::Now()),
71 m_protocol(p)
72 {
73 }
74
80 bool operator==(const DsrErrorBuffEntry& o) const
81 {
82 return ((m_packet == o.m_packet) && (m_source == o.m_source) &&
83 (m_nextHop == o.m_nextHop) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
84 }
85
86 // Fields
92 {
93 return m_packet;
94 }
95
101 {
102 m_packet = p;
103 }
104
110 {
111 return m_dst;
112 }
113
119 {
120 m_dst = d;
121 }
122
128 {
129 return m_source;
130 }
131
137 {
138 m_source = s;
139 }
140
146 {
147 return m_nextHop;
148 }
149
155 {
156 m_nextHop = n;
157 }
158
164 {
165 m_expire = exp + Simulator::Now();
166 }
167
173 {
174 return m_expire - Simulator::Now();
175 }
176
181 void SetProtocol(uint8_t p)
182 {
183 m_protocol = p;
184 }
185
190 uint8_t GetProtocol() const
191 {
192 return m_protocol;
193 }
194
195 private:
207 uint8_t m_protocol;
208};
209
214/************************************************************************************************************************/
216{
217 public:
222 {
223 }
224
232 bool Enqueue(DsrErrorBuffEntry& entry);
239 bool Dequeue(Ipv4Address dst, DsrErrorBuffEntry& entry);
245 void DropPacketForErrLink(Ipv4Address source, Ipv4Address nextHop);
251 bool Find(Ipv4Address dst);
257
258 // Fields
264 {
265 return m_maxLen;
266 }
267
273 {
274 m_maxLen = len;
275 }
276
282 {
284 }
285
291 {
293 }
294
299 std::vector<DsrErrorBuffEntry>& GetBuffer()
300 {
301 return m_errorBuffer;
302 }
303
304 private:
306 std::vector<DsrErrorBuffEntry> m_errorBuffer;
308 void Purge();
315 void Drop(DsrErrorBuffEntry en, std::string reason);
321 void DropLink(DsrErrorBuffEntry en, std::string reason);
327};
328
329/*******************************************************************************************************************************/
330} // namespace dsr
331} // namespace ns3
332
333#endif /* DSR_ERRORBUFF_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:77
Control the scheduling of simulation events.
Definition: simulator.h:68
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
DSR Error Buffer Entry.
Definition: dsr-errorbuff.h:48
DsrErrorBuffEntry(Ptr< const Packet > pa=nullptr, Ipv4Address d=Ipv4Address(), Ipv4Address s=Ipv4Address(), Ipv4Address n=Ipv4Address(), Time exp=Simulator::Now(), uint8_t p=0)
Create an DsrErrorBuffEntry with the given parameters.
Definition: dsr-errorbuff.h:60
Ptr< const Packet > GetPacket() const
Get packet from entry.
Definition: dsr-errorbuff.h:91
void SetDestination(Ipv4Address d)
Set destination address.
Ipv4Address m_nextHop
Nexthop address.
void SetNextHop(Ipv4Address n)
Set next hop.
Ptr< const Packet > m_packet
Data packet.
void SetSource(Ipv4Address s)
Set source address.
void SetProtocol(uint8_t p)
Set protocol number.
void SetExpireTime(Time exp)
Set expire time.
Ipv4Address m_source
Source address.
Ipv4Address m_dst
Destination address.
Ipv4Address GetNextHop() const
Get next hop.
Ipv4Address GetSource() const
Get source address.
Time GetExpireTime() const
Get expire time.
void SetPacket(Ptr< const Packet > p)
Set packet for entry.
uint8_t m_protocol
The protocol number.
Time m_expire
Expire time for queue entry.
Ipv4Address GetDestination() const
Get destination address.
uint8_t GetProtocol() const
Get protocol number.
bool operator==(const DsrErrorBuffEntry &o) const
Compare send buffer entries.
Definition: dsr-errorbuff.h:80
DSR error buffer.
Time m_errorBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
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.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
std::vector< DsrErrorBuffEntry > & GetBuffer()
Get error buffer entry.
Time GetErrorBufferTimeout() const
Get error buffer timeout.
bool Enqueue(DsrErrorBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
void DropLink(DsrErrorBuffEntry en, std::string reason)
Notify that packet is dropped from queue by link error.
bool Dequeue(Ipv4Address dst, DsrErrorBuffEntry &entry)
Return first found (the earliest) entry for given destination.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
DsrErrorBuffer()
Default constructor.
void DropPacketForErrLink(Ipv4Address source, Ipv4Address nextHop)
Remove all packets with the error link.
void SetErrorBufferTimeout(Time t)
Set error buffer timeout.
uint32_t GetSize()
Returns the number of entries in the queue.
std::vector< DsrErrorBuffEntry > m_errorBuffer
The send buffer to cache unsent packet.
void Drop(DsrErrorBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
void Purge()
Remove all expired entries.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:305
Every class exported by the ns3 library is enclosed in the ns3 namespace.