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
87  {
88  return m_packet;
89  }
91  {
92  m_packet = p;
93  }
95  {
96  return m_ipv4Route;
97  }
99  {
100  m_ipv4Route = route;
101  }
103  {
104  return m_srcAddr;
105  }
107  {
108  m_srcAddr = addr;
109  }
111  {
112  return m_nextHopAddr;
113  }
115  {
116  m_nextHopAddr = addr;
117  }
119  {
120  return tstamp;
121  }
123  {
124  tstamp = time;
125  }
126 
127 private:
135 };
136 
137 class DsrNetworkQueue : public Object
138 {
139 public:
140  static TypeId GetTypeId (void);
141 
142  DsrNetworkQueue ();
150  DsrNetworkQueue (uint32_t maxLen, Time maxDelay);
151  ~DsrNetworkQueue ();
152 
154  bool Find (Ipv4Address nextHop);
163  bool Enqueue (DsrNetworkQueueEntry & entry);
171  bool Dequeue (DsrNetworkQueueEntry & entry);
177  uint32_t GetSize ();
178 
184  void SetMaxNetworkSize (uint32_t maxSize);
190  void SetMaxNetworkDelay (Time delay);
196  uint32_t GetMaxNetworkSize (void) const;
202  Time GetMaxNetworkDelay (void) const;
206  void Flush (void);
207 
208  std::vector<DsrNetworkQueueEntry> & GetQueue ()
209  {
210  return m_dsrNetworkQueue;
211  }
212 
213 private:
217  void Cleanup (void);
218  std::vector<DsrNetworkQueueEntry> m_dsrNetworkQueue;
219  uint32_t m_size;
220  uint32_t m_maxSize;
222 };
223 
224 } // namespace dsr
225 } // namespace ns3
226 
227 #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 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.
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)
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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 virtual time.
Definition: simulator.cc:224
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:40
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:87
Time GetInsertedTimeStamp(void) const
a unique identifier for an interface.
Definition: type-id.h:58
Ipv4Address m_nextHopAddr
bool Find(Ipv4Address nextHop)
void SetNextHopAddress(Ipv4Address addr)