A Discrete-Event Network Simulator
API
dsr-network-queue.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Yufei Cheng
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
19  *
20  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22  * Information and Telecommunication Technology Center (ITTC)
23  * and Department of Electrical Engineering and Computer Science
24  * The University of Kansas Lawrence, KS USA.
25  *
26  * Work supported in part by NSF FIND (Future Internet Design) Program
27  * under grant CNS-0626918 (Postmodern Internet Architecture),
28  * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29  * US Department of Defense (DoD), and ITTC at The University of Kansas.
30  */
31 
32 #ifndef DSR_NETWORK_QUEUE_H
33 #define DSR_NETWORK_QUEUE_H
34 
35 #include <vector>
36 #include "ns3/ipv4-routing-protocol.h"
37 #include "ns3/simulator.h"
38 #include "ns3/ipv4-header.h"
39 #include "dsr-option-header.h"
40 
41 namespace ns3 {
42 namespace dsr {
43 
45 {
48 };
54 {
55 public:
66  Time exp = Simulator::Now (), Ptr<Ipv4Route> r = 0)
67  : m_packet (pa),
68  m_srcAddr (s),
69  m_nextHopAddr (n),
70  tstamp (exp),
71  m_ipv4Route (r)
72  {
73  }
79  bool operator== (DsrNetworkQueueEntry const & o) const
80  {
81  return ((m_packet == o.m_packet) && (m_srcAddr == o.m_srcAddr) && (m_nextHopAddr == o.m_nextHopAddr)
82  && (tstamp == o.tstamp) && (m_ipv4Route == o.m_ipv4Route));
83  }
84 
85  // Fields
91  {
92  return m_packet;
93  }
99  {
100  m_packet = p;
101  }
107  {
108  return m_ipv4Route;
109  }
115  {
116  m_ipv4Route = route;
117  }
123  {
124  return m_srcAddr;
125  }
131  {
132  m_srcAddr = addr;
133  }
139  {
140  return m_nextHopAddr;
141  }
147  {
148  m_nextHopAddr = addr;
149  }
155  {
156  return tstamp;
157  }
163  {
164  tstamp = time;
165  }
166 
167 private:
175 };
176 
177 class DsrNetworkQueue : public Object
178 {
179 public:
184  static TypeId GetTypeId (void);
185 
186  DsrNetworkQueue ();
194  DsrNetworkQueue (uint32_t maxLen, Time maxDelay);
195  ~DsrNetworkQueue ();
196 
209  bool Find (Ipv4Address nextHop);
218  bool Enqueue (DsrNetworkQueueEntry & entry);
226  bool Dequeue (DsrNetworkQueueEntry & entry);
232  uint32_t GetSize ();
233 
239  void SetMaxNetworkSize (uint32_t maxSize);
245  void SetMaxNetworkDelay (Time delay);
251  uint32_t GetMaxNetworkSize (void) const;
257  Time GetMaxNetworkDelay (void) const;
261  void Flush (void);
262 
268  std::vector<DsrNetworkQueueEntry> & GetQueue ()
269  {
270  return m_dsrNetworkQueue;
271  }
272 
273 private:
277  void Cleanup (void);
278  std::vector<DsrNetworkQueueEntry> m_dsrNetworkQueue;
279  uint32_t m_size;
280  uint32_t m_maxSize;
282 };
283 
284 } // namespace dsr
285 } // namespace ns3
286 
287 #endif /* DSR_NETWORK_QUEUE_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
DsrNetworkQueueEntry(Ptr< const Packet > pa=0, Ipv4Address s=Ipv4Address(), Ipv4Address n=Ipv4Address(), Time exp=Simulator::Now(), Ptr< Ipv4Route > r=0)
Construct a DsrNetworkQueueEntry with the given parameters.
uint32_t GetSize()
Number of entries.
bool Enqueue(DsrNetworkQueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
uint32_t m_maxSize
Maximum queue size.
Introspection did not find any typical Config paths.
void SetPacket(Ptr< const Packet > p)
Set packet function.
bool Dequeue(DsrNetworkQueueEntry &entry)
Return first found (the earliest) entry for given destination.
Ipv4Address GetNextHopAddress() const
Get next hop address function.
Time GetMaxNetworkDelay(void) const
Return the maximum entry lifetime for this queue.
Ptr< const Packet > m_packet
Data packet.
void SetIpv4Route(Ptr< Ipv4Route > route)
Set IP route function.
Time tstamp
timestamp
DSR Network Queue Entry.
uint32_t GetMaxNetworkSize(void) const
Return the maximum queue size.
void SetMaxNetworkDelay(Time delay)
Set the maximum entry lifetime in the queue.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< Ipv4Route > m_ipv4Route
Ipv4Route.
Ipv4Address m_srcAddr
source address
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
std::vector< DsrNetworkQueueEntry > & GetQueue()
Return the current queue entry.
bool FindPacketWithNexthop(Ipv4Address nextHop, DsrNetworkQueueEntry &entry)
Find the packet entry with a given next hop.
void Cleanup(void)
Clean the queue by removing entries that exceeded lifetime.
uint32_t m_size
Current queue size.
void SetInsertedTimeStamp(Time time)
Set inserted time stamp function.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
void SetSourceAddress(Ipv4Address addr)
Set source address function.
void Flush(void)
Clear the queue.
std::vector< DsrNetworkQueueEntry > m_dsrNetworkQueue
Queue (vector) of entries.
Time m_maxDelay
Maximum entry lifetime.
static TypeId GetTypeId(void)
Get the type ID.
Ptr< Ipv4Route > GetIpv4Route() const
Get IP route function.
void SetMaxNetworkSize(uint32_t maxSize)
Set the maximum queue size.
Time GetInsertedTimeStamp(void) const
Get inserted time stamp function.
A base class which provides memory management and object aggregation.
Definition: object.h:87
bool operator==(DsrNetworkQueueEntry const &o) const
Compare send buffer entries.
Ptr< const Packet > GetPacket() const
Get packet function.
a unique identifier for an interface.
Definition: type-id.h:58
Ipv4Address m_nextHopAddr
next hop address
bool Find(Ipv4Address nextHop)
Try to find an entry with a particular next hop, and return true if found.
void SetNextHopAddress(Ipv4Address addr)
Set next hop address function.
Ipv4Address GetSourceAddress() const
Get source address function.