A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-network-queue.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_NETWORK_QUEUE_H
21#define DSR_NETWORK_QUEUE_H
22
23#include "dsr-option-header.h"
24
25#include "ns3/ipv4-header.h"
26#include "ns3/ipv4-routing-protocol.h"
27#include "ns3/simulator.h"
28
29#include <vector>
30
31namespace ns3
32{
33namespace dsr
34{
35
36/** Flag used to prioritize packets */
42
43/**
44 * @ingroup dsr
45 * @brief DSR Network Queue Entry
46 */
48{
49 public:
50 /**
51 * Construct a DsrNetworkQueueEntry with the given parameters
52 *
53 * @param pa packet
54 * @param s IPv4 address of the source
55 * @param n IPv4 address of the next hop node
56 * @param exp expiration time
57 * @param r Route
58 */
62 Time exp = Simulator::Now(),
63 Ptr<Ipv4Route> r = nullptr)
64 : m_packet(pa),
65 m_srcAddr(s),
67 tstamp(exp),
69 {
70 }
71
72 /**
73 * Compare send buffer entries
74 * @param o entry to compare
75 * @return true if equal
76 */
77 bool operator==(const DsrNetworkQueueEntry& o) const
78 {
79 return ((m_packet == o.m_packet) && (m_srcAddr == o.m_srcAddr) &&
80 (m_nextHopAddr == o.m_nextHopAddr) && (tstamp == o.tstamp) &&
82 }
83
84 // Fields
85 /**
86 * Get packet function
87 * @returns the current packet
88 */
90 {
91 return m_packet;
92 }
93
94 /**
95 * Set packet function
96 * @param p the current packet
97 */
99 {
100 m_packet = p;
101 }
102
103 /**
104 * Get IP route function
105 * @returns the IP route
106 */
108 {
109 return m_ipv4Route;
110 }
111
112 /**
113 * Set IP route function
114 * @param route
115 */
117 {
118 m_ipv4Route = route;
119 }
120
121 /**
122 * Get source address function
123 * @returns the source IP address
124 */
126 {
127 return m_srcAddr;
128 }
129
130 /**
131 * Set source address function
132 * @param addr the source IP address
133 */
135 {
136 m_srcAddr = addr;
137 }
138
139 /**
140 * Get next hop address function
141 * @returns the next hop IP address
142 */
144 {
145 return m_nextHopAddr;
146 }
147
148 /**
149 * Set next hop address function
150 * @param addr the next hop IP address
151 */
153 {
154 m_nextHopAddr = addr;
155 }
156
157 /**
158 * Get inserted time stamp function
159 * @returns the inserted time stamp
160 */
162 {
163 return tstamp;
164 }
165
166 /**
167 * Set inserted time stamp function
168 * @param time the inserted timestamp
169 */
171 {
172 tstamp = time;
173 }
174
175 private:
176 /// Data packet
178 Ipv4Address m_srcAddr; ///< source address
179 Ipv4Address m_nextHopAddr; ///< next hop address
180 Time tstamp; ///< timestamp
181 /// Ipv4Route
183};
184
186{
187 public:
188 /**
189 * @brief Get the type ID.
190 * @return the object TypeId
191 */
192 static TypeId GetTypeId();
193
195 /**
196 * Construct a DsrNetworkQueue with the given
197 * maximum length and maximum delay.
198 *
199 * @param maxLen Maximum queue size
200 * @param maxDelay Maximum entry lifetime in the queue
201 */
202 DsrNetworkQueue(uint32_t maxLen, Time maxDelay);
203 ~DsrNetworkQueue() override;
204
205 /**
206 * Find the packet entry with a given next hop
207 * @param nextHop the IP address of the next hop
208 * @param entry the DSR queue entry
209 * @returns true if found
210 */
212 /**
213 * Try to find an entry with a particular next hop, and return true if found
214 * @param nextHop the next hop IP address
215 * @returns true if found
216 */
217 bool Find(Ipv4Address nextHop);
218 /**
219 * Push entry in queue, if there is no entry with the same
220 * packet and destination address in queue.
221 *
222 * @param entry packet entry
223 * @return true if the given entry was put in the queue,
224 * false otherwise
225 */
226 bool Enqueue(DsrNetworkQueueEntry& entry);
227 /**
228 * Return first found (the earliest) entry for given destination
229 *
230 * @param entry pointer to the return entry
231 * @return true if an entry is returned,
232 * false otherwise
233 */
234 bool Dequeue(DsrNetworkQueueEntry& entry);
235 /**
236 * Number of entries
237 *
238 * @return the current queue size/length
239 */
241
242 /**
243 * Set the maximum queue size
244 *
245 * @param maxSize the maximum queue size
246 */
247 void SetMaxNetworkSize(uint32_t maxSize);
248 /**
249 * Set the maximum entry lifetime in the queue
250 *
251 * @param delay the maximum entry lifetime
252 */
253 void SetMaxNetworkDelay(Time delay);
254 /**
255 * Return the maximum queue size
256 *
257 * @return the maximum queue size
258 */
260 /**
261 * Return the maximum entry lifetime for this queue
262 *
263 * @return the maximum entry lifetime for this queue
264 */
265 Time GetMaxNetworkDelay() const;
266 /**
267 * Clear the queue
268 */
269 void Flush();
270
271 /**
272 * Return the current queue entry
273 *
274 * @return the current queue entry
275 */
276 std::vector<DsrNetworkQueueEntry>& GetQueue()
277 {
278 return m_dsrNetworkQueue;
279 }
280
281 private:
282 /**
283 * Clean the queue by removing entries that exceeded lifetime.
284 */
285 void Cleanup();
286 std::vector<DsrNetworkQueueEntry> m_dsrNetworkQueue; //!< Queue (vector) of entries
287 uint32_t m_size; //!< Current queue size
288 uint32_t m_maxSize; //!< Maximum queue size
289 Time m_maxDelay; //!< Maximum entry lifetime
290};
291
292} // namespace dsr
293} // namespace ns3
294
295#endif /* DSR_NETWORK_QUEUE_H */
uint32_t r
Ipv4 addresses are stored in host order in this class.
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
Simulation virtual time values and global simulation resolution.
Definition nstime.h:96
a unique identifier for an interface.
Definition type-id.h:49
DSR Network Queue Entry.
Ptr< Ipv4Route > GetIpv4Route() const
Get IP route function.
Ptr< Ipv4Route > m_ipv4Route
Ipv4Route.
bool operator==(const DsrNetworkQueueEntry &o) const
Compare send buffer entries.
Ipv4Address m_srcAddr
source address
Ptr< const Packet > GetPacket() const
Get packet function.
Ipv4Address GetSourceAddress() const
Get source address function.
void SetIpv4Route(Ptr< Ipv4Route > route)
Set IP route function.
void SetNextHopAddress(Ipv4Address addr)
Set next hop address function.
DsrNetworkQueueEntry(Ptr< const Packet > pa=nullptr, Ipv4Address s=Ipv4Address(), Ipv4Address n=Ipv4Address(), Time exp=Simulator::Now(), Ptr< Ipv4Route > r=nullptr)
Construct a DsrNetworkQueueEntry with the given parameters.
void SetInsertedTimeStamp(Time time)
Set inserted time stamp function.
void SetSourceAddress(Ipv4Address addr)
Set source address function.
Ipv4Address m_nextHopAddr
next hop address
Ipv4Address GetNextHopAddress() const
Get next hop address function.
void SetPacket(Ptr< const Packet > p)
Set packet function.
Time GetInsertedTimeStamp() const
Get inserted time stamp function.
Ptr< const Packet > m_packet
Data packet.
Time tstamp
timestamp
void Flush()
Clear the queue.
uint32_t m_maxSize
Maximum queue size.
uint32_t GetMaxNetworkSize() const
Return the maximum queue size.
bool FindPacketWithNexthop(Ipv4Address nextHop, DsrNetworkQueueEntry &entry)
Find the packet entry with a given next hop.
uint32_t GetSize()
Number of entries.
void SetMaxNetworkDelay(Time delay)
Set the maximum entry lifetime in the queue.
bool Enqueue(DsrNetworkQueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
static TypeId GetTypeId()
Get the type ID.
std::vector< DsrNetworkQueueEntry > m_dsrNetworkQueue
Queue (vector) of entries.
Time m_maxDelay
Maximum entry lifetime.
std::vector< DsrNetworkQueueEntry > & GetQueue()
Return the current queue entry.
void Cleanup()
Clean the queue by removing entries that exceeded lifetime.
void SetMaxNetworkSize(uint32_t maxSize)
Set the maximum queue size.
uint32_t m_size
Current queue size.
bool Find(Ipv4Address nextHop)
Try to find an entry with a particular next hop, and return true if found.
Time GetMaxNetworkDelay() const
Return the maximum entry lifetime for this queue.
bool Dequeue(DsrNetworkQueueEntry &entry)
Return first found (the earliest) entry for given destination.
DsrMessageType
Flag used to prioritize packets.
Every class exported by the ns3 library is enclosed in the ns3 namespace.