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 * 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_NETWORK_QUEUE_H
32#define DSR_NETWORK_QUEUE_H
33
34#include "dsr-option-header.h"
35
36#include "ns3/ipv4-header.h"
37#include "ns3/ipv4-routing-protocol.h"
38#include "ns3/simulator.h"
39
40#include <vector>
41
42namespace ns3
43{
44namespace dsr
45{
46
48{
51};
52
53/**
54 * \ingroup dsr
55 * \brief DSR Network Queue Entry
56 */
58{
59 public:
60 /**
61 * Construct a DsrNetworkQueueEntry with the given parameters
62 *
63 * \param pa packet
64 * \param s IPv4 address of the source
65 * \param n IPv4 address of the next hop node
66 * \param exp expiration time
67 * \param r Route
68 */
72 Time exp = Simulator::Now(),
73 Ptr<Ipv4Route> r = nullptr)
74 : m_packet(pa),
75 m_srcAddr(s),
77 tstamp(exp),
79 {
80 }
81
82 /**
83 * Compare send buffer entries
84 * \param o entry to compare
85 * \return true if equal
86 */
87 bool operator==(const DsrNetworkQueueEntry& o) const
88 {
89 return ((m_packet == o.m_packet) && (m_srcAddr == o.m_srcAddr) &&
90 (m_nextHopAddr == o.m_nextHopAddr) && (tstamp == o.tstamp) &&
92 }
93
94 // Fields
95 /**
96 * Get packet function
97 * \returns the current packet
98 */
100 {
101 return m_packet;
102 }
103
104 /**
105 * Set packet function
106 * \param p the current packet
107 */
109 {
110 m_packet = p;
111 }
112
113 /**
114 * Get IP route function
115 * \returns the IP route
116 */
118 {
119 return m_ipv4Route;
120 }
121
122 /**
123 * Set IP route function
124 * \param route
125 */
127 {
128 m_ipv4Route = route;
129 }
130
131 /**
132 * Get source address function
133 * \returns the source IP address
134 */
136 {
137 return m_srcAddr;
138 }
139
140 /**
141 * Set source address function
142 * \param addr the source IP address
143 */
145 {
146 m_srcAddr = addr;
147 }
148
149 /**
150 * Get next hop address function
151 * \returns the next hop IP address
152 */
154 {
155 return m_nextHopAddr;
156 }
157
158 /**
159 * Set next hop address function
160 * \param addr the next hop IP address
161 */
163 {
164 m_nextHopAddr = addr;
165 }
166
167 /**
168 * Get inserted time stamp function
169 * \returns the inserted time stamp
170 */
172 {
173 return tstamp;
174 }
175
176 /**
177 * Set inserted time stamp function
178 * \param time the inserted timestamp
179 */
181 {
182 tstamp = time;
183 }
184
185 private:
186 /// Data packet
188 Ipv4Address m_srcAddr; ///< source address
189 Ipv4Address m_nextHopAddr; ///< next hop address
190 Time tstamp; ///< timestamp
191 /// Ipv4Route
193};
194
196{
197 public:
198 /**
199 * \brief Get the type ID.
200 * \return the object TypeId
201 */
202 static TypeId GetTypeId();
203
205 /**
206 * Construct a DsrNetworkQueue with the given
207 * maximum length and maximum delay.
208 *
209 * \param maxLen Maximum queue size
210 * \param maxDelay Maximum entry lifetime in the queue
211 */
212 DsrNetworkQueue(uint32_t maxLen, Time maxDelay);
213 ~DsrNetworkQueue() override;
214
215 /**
216 * Find the packet entry with a given next hop
217 * \param nextHop the IP address of the next hop
218 * \param entry the DSR queue entry
219 * \returns true if found
220 */
222 /**
223 * Try to find an entry with a particular next hop, and return true if found
224 * \param nextHop the next hop IP address
225 * \returns true if found
226 */
227 bool Find(Ipv4Address nextHop);
228 /**
229 * Push entry in queue, if there is no entry with the same
230 * packet and destination address in queue.
231 *
232 * \param entry packet entry
233 * \return true if the given entry was put in the queue,
234 * false otherwise
235 */
236 bool Enqueue(DsrNetworkQueueEntry& entry);
237 /**
238 * Return first found (the earliest) entry for given destination
239 *
240 * \param entry pointer to the return entry
241 * \return true if an entry is returned,
242 * false otherwise
243 */
244 bool Dequeue(DsrNetworkQueueEntry& entry);
245 /**
246 * Number of entries
247 *
248 * \return the current queue size/length
249 */
251
252 /**
253 * Set the maximum queue size
254 *
255 * \param maxSize the maximum queue size
256 */
257 void SetMaxNetworkSize(uint32_t maxSize);
258 /**
259 * Set the maximum entry lifetime in the queue
260 *
261 * \param delay the maximum entry lifetime
262 */
263 void SetMaxNetworkDelay(Time delay);
264 /**
265 * Return the maximum queue size
266 *
267 * \return the maximum queue size
268 */
270 /**
271 * Return the maximum entry lifetime for this queue
272 *
273 * \return the maximum entry lifetime for this queue
274 */
275 Time GetMaxNetworkDelay() const;
276 /**
277 * Clear the queue
278 */
279 void Flush();
280
281 /**
282 * Return the current queue entry
283 *
284 * \return the current queue entry
285 */
286 std::vector<DsrNetworkQueueEntry>& GetQueue()
287 {
288 return m_dsrNetworkQueue;
289 }
290
291 private:
292 /**
293 * Clean the queue by removing entries that exceeded lifetime.
294 */
295 void Cleanup();
296 std::vector<DsrNetworkQueueEntry> m_dsrNetworkQueue; //!< Queue (vector) of entries
297 uint32_t m_size; //!< Current queue size
298 uint32_t m_maxSize; //!< Maximum queue size
299 Time m_maxDelay; //!< Maximum entry lifetime
300};
301
302} // namespace dsr
303} // namespace ns3
304
305#endif /* DSR_NETWORK_QUEUE_H */
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:77
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
a unique identifier for an interface.
Definition: type-id.h:59
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.