A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
86  //\{
88  {
89  return m_packet;
90  }
92  {
93  m_packet = p;
94  }
96  {
97  return m_ipv4Route;
98  }
100  {
101  m_ipv4Route = route;
102  }
104  {
105  return m_srcAddr;
106  }
108  {
109  m_srcAddr = addr;
110  }
112  {
113  return m_nextHopAddr;
114  }
116  {
117  m_nextHopAddr = addr;
118  }
120  {
121  return tstamp;
122  }
124  {
125  tstamp = time;
126  }
127  //\}
128 private:
136 };
137 
138 class DsrNetworkQueue : public Object
139 {
140 public:
141  static TypeId GetTypeId (void);
142 
143  DsrNetworkQueue ();
151  DsrNetworkQueue (uint32_t maxLen, Time maxDelay);
152  ~DsrNetworkQueue ();
153 
155  bool Find (Ipv4Address nextHop);
164  bool Enqueue (DsrNetworkQueueEntry & entry);
172  bool Dequeue (DsrNetworkQueueEntry & entry);
178  uint32_t GetSize ();
179 
185  void SetMaxNetworkSize (uint32_t maxSize);
191  void SetMaxNetworkDelay (Time delay);
197  uint32_t GetMaxNetworkSize (void) const;
203  Time GetMaxNetworkDelay (void) const;
207  void Flush (void);
208 
209  std::vector<DsrNetworkQueueEntry> & GetQueue ()
210  {
211  return m_dsrNetworkQueue;
212  }
213 
214 private:
218  void Cleanup (void);
219  std::vector<DsrNetworkQueueEntry> m_dsrNetworkQueue;
220  uint32_t m_size;
221  uint32_t m_maxSize;
223 };
224 
225 } // namespace dsr
226 } // namespace ns3
227 
228 #endif /* DSR_NETWORK_QUEUE_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
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 operator==(DsrNetworkQueueEntry const &o) const
Compare send buffer 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.
Doxygen introspection did not find any typical Config paths.
void SetPacket(Ptr< const Packet > p)
bool Dequeue(DsrNetworkQueueEntry &entry)
Return first found (the earliest) entry for given destination.
Ptr< const Packet > GetPacket() const
Ptr< const Packet > m_packet
Data packet.
void SetIpv4Route(Ptr< Ipv4Route > route)
Ptr< SampleEmitter > s
Time tstamp
DSR Network Queue Entry.
uint32_t GetMaxNetworkSize(void) const
Return the maximum queue size.
Ipv4Address GetNextHopAddress() const
void SetMaxNetworkDelay(Time delay)
Set the maximum entry lifetime in the queue.
Time GetMaxNetworkDelay(void) const
Return the maximum entry lifetime for this queue.
Ptr< Ipv4Route > m_ipv4Route
Ipv4Route.
Ipv4Address m_srcAddr
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
std::vector< DsrNetworkQueueEntry > & GetQueue()
bool FindPacketWithNexthop(Ipv4Address nextHop, DsrNetworkQueueEntry &entry)
void Cleanup(void)
Clean the queue by removing entries that exceeded lifetime.
uint32_t m_size
Current queue size.
void SetInsertedTimeStamp(Time time)
Ipv4Address GetSourceAddress() const
Ptr< Ipv4Route > GetIpv4Route() const
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
void SetSourceAddress(Ipv4Address addr)
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)
void SetMaxNetworkSize(uint32_t maxSize)
Set the maximum queue size.
a base class which provides memory management and object aggregation
Definition: object.h:64
Time GetInsertedTimeStamp(void) const
a unique identifier for an interface.
Definition: type-id.h:49
Ipv4Address m_nextHopAddr
bool Find(Ipv4Address nextHop)
void SetNextHopAddress(Ipv4Address addr)