A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-rsendbuff.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Yufei Cheng
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
7 *
8 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
9 * ResiliNets Research Group https://resilinets.org/
10 * Information and Telecommunication Technology Center (ITTC)
11 * and Department of Electrical Engineering and Computer Science
12 * The University of Kansas Lawrence, KS USA.
13 *
14 * Work supported in part by NSF FIND (Future Internet Design) Program
15 * under grant CNS-0626918 (Postmodern Internet Architecture),
16 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
17 * US Department of Defense (DoD), and ITTC at The University of Kansas.
18 */
19
20#ifndef DSR_SENDBUFF_H
21#define DSR_SENDBUFF_H
22
23#include "ns3/ipv4-routing-protocol.h"
24#include "ns3/simulator.h"
25
26#include <vector>
27
28namespace ns3
29{
30namespace dsr
31{
32/**
33 * @ingroup dsr
34 * @brief DSR Send Buffer Entry
35 */
37{
38 public:
39 /**
40 * Construct DsrSendBuffEntry with the given parameters.
41 *
42 * @param pa packet
43 * @param d destination address
44 * @param exp expiration time
45 * @param p protocol number
46 */
49 Time exp = Simulator::Now(),
50 uint8_t p = 0)
51 : m_packet(pa),
52 m_dst(d),
53 m_expire(exp + Simulator::Now()),
54 m_protocol(p)
55 {
56 }
57
58 /**
59 * Compare send buffer entries
60 * @param o another DsrSendBuffEntry
61 * @return true if equal
62 */
63 bool operator==(const DsrSendBuffEntry& o) const
64 {
65 return ((m_packet == o.m_packet) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
66 }
67
68 // Fields
69 /**
70 * Get pointer to entry's packet
71 * @returns the current packet
72 */
74 {
75 return m_packet;
76 }
77
78 /**
79 * Set pointer to entry's packet
80 * @param p the current packet
81 */
83 {
84 m_packet = p;
85 }
86
87 /**
88 * Get destination address of entry
89 * @returns the destination IPv4 address
90 */
92 {
93 return m_dst;
94 }
95
96 /**
97 * Set destination address of entry
98 * @param d the destination IP address
99 */
101 {
102 m_dst = d;
103 }
104
105 /**
106 * Set expire time for entry
107 * @param exp the expire time
108 */
110 {
111 m_expire = exp + Simulator::Now();
112 }
113
114 /**
115 * Get expire time for entry
116 * @returns the expire time
117 */
119 {
120 return m_expire - Simulator::Now();
121 }
122
123 /**
124 * Set protocol value
125 * @param p the protocol
126 */
127 void SetProtocol(uint8_t p)
128 {
129 m_protocol = p;
130 }
131
132 /**
133 * Get protocol value
134 * @returns the protocol
135 */
136 uint8_t GetProtocol() const
137 {
138 return m_protocol;
139 }
140
141 private:
142 /// Data packet
144 /// Destination address
146 /// Expire time for queue entry
148 /// The protocol number
149 uint8_t m_protocol;
150};
151
152/**
153 * @ingroup dsr
154 * @brief DSR send buffer
155 */
156/************************************************************************************************************************/
158{
159 public:
160 /**
161 * Default constructor
162 */
164 {
165 }
166
167 /**
168 * Push entry in queue, if there is no entry with
169 * the same packet and destination address in queue.
170 *
171 * @param entry DsrSendBuffEntry to put in the queue
172 * @return true if successfully enqueued,
173 * false otherwise
174 */
175 bool Enqueue(DsrSendBuffEntry& entry);
176 /**
177 * Return first found (the earliest) entry for
178 * the given destination.
179 *
180 * @param dst IPv4 address of the destination
181 * @param entry pointer to entry to return
182 * @return true if successfully dequeued,
183 * false otherwise
184 */
185 bool Dequeue(Ipv4Address dst, DsrSendBuffEntry& entry);
186 /**
187 * Remove all packets with destination IP address dst
188 *
189 * @param dst IPv4 address of the destination
190 */
192 /**
193 * Check if a packet with destination dst exists in the queue
194 *
195 * @param dst IPv4 address of the destination
196 * @return true if found, false otherwise
197 */
198 bool Find(Ipv4Address dst);
199 /**
200 * Number of entries
201 *
202 * @return the number of entries in the queue
203 */
205
206 /**
207 * Return the maximum queue length
208 *
209 * @return the maximum queue length
210 */
212 {
213 return m_maxLen;
214 }
215
216 /**
217 * Set the maximum queue length
218 *
219 * @param len the maximum queue length
220 */
222 {
223 m_maxLen = len;
224 }
225
226 /**
227 * Return the entry lifetime in the queue
228 *
229 * @return the entry lifetime in the queue
230 */
232 {
233 return m_sendBufferTimeout;
234 }
235
236 /**
237 * Set the entry lifetime in the queue
238 *
239 * @param t the entry lifetime in the queue
240 */
242 {
244 }
245
246 // \}
247
248 /**
249 * Return a pointer to the internal queue
250 *
251 * @return a pointer to the internal queue
252 */
253 std::vector<DsrSendBuffEntry>& GetBuffer()
254 {
255 return m_sendBuffer;
256 }
257
258 private:
259 std::vector<DsrSendBuffEntry> m_sendBuffer; ///< The send buffer to cache unsent packet
260 void Purge(); ///< Remove all expired entries
261
262 /// Notify that packet is dropped from queue by timeout
263 /// @param en BuffEntry Buffer entry
264 /// @param reason Drop reason
265 void Drop(DsrSendBuffEntry en, std::string reason);
266
268 m_maxLen; ///< The maximum number of packets that we allow a routing protocol to buffer.
269 Time m_sendBufferTimeout; ///< The maximum period of time that a routing protocol is allowed to
270 ///< buffer a packet for, seconds.
271};
272
273/*******************************************************************************************************************************/
274} // namespace dsr
275} // namespace ns3
276
277#endif /* DSR_SENDBUFF_H */
Ipv4 addresses are stored in host order in this class.
Smart pointer class similar to boost::intrusive_ptr.
Control the scheduling of simulation events.
Definition simulator.h:57
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
DSR Send Buffer Entry.
Ipv4Address m_dst
Destination address.
Ptr< const Packet > m_packet
Data packet.
DsrSendBuffEntry(Ptr< const Packet > pa=nullptr, Ipv4Address d=Ipv4Address(), Time exp=Simulator::Now(), uint8_t p=0)
Construct DsrSendBuffEntry with the given parameters.
uint8_t m_protocol
The protocol number.
void SetDestination(Ipv4Address d)
Set destination address of entry.
void SetPacket(Ptr< const Packet > p)
Set pointer to entry's packet.
Time GetExpireTime() const
Get expire time for entry.
void SetProtocol(uint8_t p)
Set protocol value.
Ipv4Address GetDestination() const
Get destination address of entry.
Time m_expire
Expire time for queue entry.
uint8_t GetProtocol() const
Get protocol value.
void SetExpireTime(Time exp)
Set expire time for entry.
Ptr< const Packet > GetPacket() const
Get pointer to entry's packet.
bool operator==(const DsrSendBuffEntry &o) const
Compare send buffer entries.
void SetMaxQueueLen(uint32_t len)
Set the maximum queue length.
Time GetSendBufferTimeout() const
Return the entry lifetime in the queue.
uint32_t GetSize()
Number of entries.
bool Dequeue(Ipv4Address dst, DsrSendBuffEntry &entry)
Return first found (the earliest) entry for the given destination.
uint32_t GetMaxQueueLen() const
Return the maximum queue length.
void SetSendBufferTimeout(Time t)
Set the entry lifetime in the queue.
void Purge()
Remove all expired entries.
Time m_sendBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
std::vector< DsrSendBuffEntry > m_sendBuffer
The send buffer to cache unsent packet.
std::vector< DsrSendBuffEntry > & GetBuffer()
Return a pointer to the internal queue.
bool Enqueue(DsrSendBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
bool Find(Ipv4Address dst)
Check if a packet with destination dst exists in the queue.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
void Drop(DsrSendBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
DsrSendBuffer()
Default constructor.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Every class exported by the ns3 library is enclosed in the ns3 namespace.