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
41
42/**
43 * @ingroup dsr
44 * @brief DSR Network Queue Entry
45 */
47{
48 public:
49 /**
50 * Construct a DsrNetworkQueueEntry with the given parameters
51 *
52 * @param pa packet
53 * @param s IPv4 address of the source
54 * @param n IPv4 address of the next hop node
55 * @param exp expiration time
56 * @param r Route
57 */
61 Time exp = Simulator::Now(),
62 Ptr<Ipv4Route> r = nullptr)
63 : m_packet(pa),
64 m_srcAddr(s),
66 tstamp(exp),
68 {
69 }
70
71 /**
72 * Compare send buffer entries
73 * @param o entry to compare
74 * @return true if equal
75 */
76 bool operator==(const DsrNetworkQueueEntry& o) const
77 {
78 return ((m_packet == o.m_packet) && (m_srcAddr == o.m_srcAddr) &&
79 (m_nextHopAddr == o.m_nextHopAddr) && (tstamp == o.tstamp) &&
81 }
82
83 // Fields
84 /**
85 * Get packet function
86 * @returns the current packet
87 */
89 {
90 return m_packet;
91 }
92
93 /**
94 * Set packet function
95 * @param p the current packet
96 */
98 {
99 m_packet = p;
100 }
101
102 /**
103 * Get IP route function
104 * @returns the IP route
105 */
107 {
108 return m_ipv4Route;
109 }
110
111 /**
112 * Set IP route function
113 * @param route
114 */
116 {
117 m_ipv4Route = route;
118 }
119
120 /**
121 * Get source address function
122 * @returns the source IP address
123 */
125 {
126 return m_srcAddr;
127 }
128
129 /**
130 * Set source address function
131 * @param addr the source IP address
132 */
134 {
135 m_srcAddr = addr;
136 }
137
138 /**
139 * Get next hop address function
140 * @returns the next hop IP address
141 */
143 {
144 return m_nextHopAddr;
145 }
146
147 /**
148 * Set next hop address function
149 * @param addr the next hop IP address
150 */
152 {
153 m_nextHopAddr = addr;
154 }
155
156 /**
157 * Get inserted time stamp function
158 * @returns the inserted time stamp
159 */
161 {
162 return tstamp;
163 }
164
165 /**
166 * Set inserted time stamp function
167 * @param time the inserted timestamp
168 */
170 {
171 tstamp = time;
172 }
173
174 private:
175 /// Data packet
177 Ipv4Address m_srcAddr; ///< source address
178 Ipv4Address m_nextHopAddr; ///< next hop address
179 Time tstamp; ///< timestamp
180 /// Ipv4Route
182};
183
185{
186 public:
187 /**
188 * @brief Get the type ID.
189 * @return the object TypeId
190 */
191 static TypeId GetTypeId();
192
194 /**
195 * Construct a DsrNetworkQueue with the given
196 * maximum length and maximum delay.
197 *
198 * @param maxLen Maximum queue size
199 * @param maxDelay Maximum entry lifetime in the queue
200 */
201 DsrNetworkQueue(uint32_t maxLen, Time maxDelay);
202 ~DsrNetworkQueue() override;
203
204 /**
205 * Find the packet entry with a given next hop
206 * @param nextHop the IP address of the next hop
207 * @param entry the DSR queue entry
208 * @returns true if found
209 */
211 /**
212 * Try to find an entry with a particular next hop, and return true if found
213 * @param nextHop the next hop IP address
214 * @returns true if found
215 */
216 bool Find(Ipv4Address nextHop);
217 /**
218 * Push entry in queue, if there is no entry with the same
219 * packet and destination address in queue.
220 *
221 * @param entry packet entry
222 * @return true if the given entry was put in the queue,
223 * false otherwise
224 */
225 bool Enqueue(DsrNetworkQueueEntry& entry);
226 /**
227 * Return first found (the earliest) entry for given destination
228 *
229 * @param entry pointer to the return entry
230 * @return true if an entry is returned,
231 * false otherwise
232 */
233 bool Dequeue(DsrNetworkQueueEntry& entry);
234 /**
235 * Number of entries
236 *
237 * @return the current queue size/length
238 */
240
241 /**
242 * Set the maximum queue size
243 *
244 * @param maxSize the maximum queue size
245 */
246 void SetMaxNetworkSize(uint32_t maxSize);
247 /**
248 * Set the maximum entry lifetime in the queue
249 *
250 * @param delay the maximum entry lifetime
251 */
252 void SetMaxNetworkDelay(Time delay);
253 /**
254 * Return the maximum queue size
255 *
256 * @return the maximum queue size
257 */
259 /**
260 * Return the maximum entry lifetime for this queue
261 *
262 * @return the maximum entry lifetime for this queue
263 */
264 Time GetMaxNetworkDelay() const;
265 /**
266 * Clear the queue
267 */
268 void Flush();
269
270 /**
271 * Return the current queue entry
272 *
273 * @return the current queue entry
274 */
275 std::vector<DsrNetworkQueueEntry>& GetQueue()
276 {
277 return m_dsrNetworkQueue;
278 }
279
280 private:
281 /**
282 * Clean the queue by removing entries that exceeded lifetime.
283 */
284 void Cleanup();
285 std::vector<DsrNetworkQueueEntry> m_dsrNetworkQueue; //!< Queue (vector) of entries
286 uint32_t m_size; //!< Current queue size
287 uint32_t m_maxSize; //!< Maximum queue size
288 Time m_maxDelay; //!< Maximum entry lifetime
289};
290
291} // namespace dsr
292} // namespace ns3
293
294#endif /* DSR_NETWORK_QUEUE_H */
Ipv4 addresses are stored in host order in this class.
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
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
a unique identifier for an interface.
Definition type-id.h:48
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
Introspection did not find any typical Config paths.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.