A Discrete-Event Network Simulator
API
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 
42 namespace ns3
43 {
44 namespace dsr
45 {
46 
48 {
50  DSR_DATA_PACKET = 2
51 };
52 
58 {
59  public:
72  Time exp = Simulator::Now(),
73  Ptr<Ipv4Route> r = nullptr)
74  : m_packet(pa),
75  m_srcAddr(s),
76  m_nextHopAddr(n),
77  tstamp(exp),
78  m_ipv4Route(r)
79  {
80  }
81 
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) &&
91  (m_ipv4Route == o.m_ipv4Route));
92  }
93 
94  // Fields
100  {
101  return m_packet;
102  }
103 
109  {
110  m_packet = p;
111  }
112 
118  {
119  return m_ipv4Route;
120  }
121 
127  {
128  m_ipv4Route = route;
129  }
130 
136  {
137  return m_srcAddr;
138  }
139 
145  {
146  m_srcAddr = addr;
147  }
148 
154  {
155  return m_nextHopAddr;
156  }
157 
163  {
164  m_nextHopAddr = addr;
165  }
166 
172  {
173  return tstamp;
174  }
175 
181  {
182  tstamp = time;
183  }
184 
185  private:
193 };
194 
195 class DsrNetworkQueue : public Object
196 {
197  public:
202  static TypeId GetTypeId();
203 
204  DsrNetworkQueue();
212  DsrNetworkQueue(uint32_t maxLen, Time maxDelay);
213  ~DsrNetworkQueue() override;
214 
227  bool Find(Ipv4Address nextHop);
236  bool Enqueue(DsrNetworkQueueEntry& entry);
244  bool Dequeue(DsrNetworkQueueEntry& entry);
250  uint32_t GetSize();
251 
257  void SetMaxNetworkSize(uint32_t maxSize);
263  void SetMaxNetworkDelay(Time delay);
269  uint32_t GetMaxNetworkSize() const;
275  Time GetMaxNetworkDelay() const;
279  void Flush();
280 
286  std::vector<DsrNetworkQueueEntry>& GetQueue()
287  {
288  return m_dsrNetworkQueue;
289  }
290 
291  private:
295  void Cleanup();
296  std::vector<DsrNetworkQueueEntry> m_dsrNetworkQueue;
297  uint32_t m_size;
298  uint32_t m_maxSize;
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
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 > m_ipv4Route
Ipv4Route.
bool operator==(const DsrNetworkQueueEntry &o) const
Compare send buffer entries.
Ipv4Address m_srcAddr
source address
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.
Ptr< const Packet > GetPacket() const
Get packet function.
void SetInsertedTimeStamp(Time time)
Set inserted time stamp function.
void SetSourceAddress(Ipv4Address addr)
Set source address function.
Ptr< Ipv4Route > GetIpv4Route() const
Get IP route 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.
std::vector< DsrNetworkQueueEntry > & GetQueue()
Return the current queue entry.
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.
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.