A Discrete-Event Network Simulator
API
dsdv-packet-queue.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Hemanth Narra
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: Hemanth Narra <hemanth@ittc.ku.com>
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 DSDV_PACKETQUEUE_H
33 #define DSDV_PACKETQUEUE_H
34 
35 #include <vector>
36 #include "ns3/ipv4-routing-protocol.h"
37 #include "ns3/simulator.h"
38 
39 namespace ns3 {
40 namespace dsdv {
46 {
47 public:
63  : m_packet (pa),
64  m_header (h),
65  m_ucb (ucb),
66  m_ecb (ecb),
67  m_expire (Seconds (0))
68  {
69  }
70 
76  bool operator== (QueueEntry const & o) const
77  {
78  return ((m_packet == o.m_packet) && (m_header.GetDestination () == o.m_header.GetDestination ()) && (m_expire == o.m_expire));
79  }
80 
81  // Fields
87  {
88  return m_ucb;
89  }
95  {
96  m_ucb = ucb;
97  }
103  {
104  return m_ecb;
105  }
111  {
112  m_ecb = ecb;
113  }
119  {
120  return m_packet;
121  }
127  {
128  m_packet = p;
129  }
135  {
136  return m_header;
137  }
143  {
144  m_header = h;
145  }
150  void SetExpireTime (Time exp)
151  {
152  m_expire = exp + Simulator::Now ();
153  }
159  {
160  return m_expire - Simulator::Now ();
161  }
162 
163 private:
174 };
184 {
185 public:
188  {
189  }
195  bool Enqueue (QueueEntry & entry);
203  bool Dequeue (Ipv4Address dst, QueueEntry & entry);
208  void DropPacketWithDst (Ipv4Address dst);
214  bool Find (Ipv4Address dst);
220  uint32_t
226  uint32_t GetSize ();
227 
228  // Fields
233  uint32_t GetMaxQueueLen () const
234  {
235  return m_maxLen;
236  }
241  void SetMaxQueueLen (uint32_t len)
242  {
243  m_maxLen = len;
244  }
249  uint32_t GetMaxPacketsPerDst () const
250  {
251  return m_maxLenPerDst;
252  }
257  void SetMaxPacketsPerDst (uint32_t len)
258  {
259  m_maxLenPerDst = len;
260  }
266  {
267  return m_queueTimeout;
268  }
274  {
275  m_queueTimeout = t;
276  }
277 
278 private:
279  std::vector<QueueEntry> m_queue;
280  void Purge ();
287  void Drop (QueueEntry en, std::string reason);
289  uint32_t m_maxLen;
291  uint32_t m_maxLenPerDst;
294 };
295 }
296 }
297 #endif /* DSDV_PACKETQUEUE_H */
std::vector< QueueEntry > m_queue
the queue
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Callback template class.
Definition: callback.h:1278
void SetUnicastForwardCallback(UnicastForwardCallback ucb)
Set unicast forward callback function.
Ptr< const Packet > GetPacket() const
Get packet.
QueueEntry(Ptr< const Packet > pa=0, Ipv4Header const &h=Ipv4Header(), UnicastForwardCallback ucb=UnicastForwardCallback(), ErrorCallback ecb=ErrorCallback())
c-tor
void SetMaxPacketsPerDst(uint32_t len)
Set maximum packets per destination.
void SetIpv4Header(Ipv4Header h)
Set IP header.
Ipv4Header m_header
IP header.
uint32_t GetCountForPacketsWithDst(Ipv4Address dst)
Get count of packets with destination dst in the queue.
DSDV Packet queue.
Ipv4RoutingProtocol::UnicastForwardCallback UnicastForwardCallback
Unicast forward call back function typedef.
Time GetQueueTimeout() const
Get queue timeout.
Packet header for IPv4.
Definition: ipv4-header.h:33
DSDV Queue Entry.
Ptr< const Packet > m_packet
Data packet.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
PacketQueue()
Default c-tor.
Time GetExpireTime() const
Get expire time.
UnicastForwardCallback GetUnicastForwardCallback() const
Get unicast forward callback function.
void SetQueueTimeout(Time t)
Set queue timeout.
Ipv4RoutingProtocol::ErrorCallback ErrorCallback
Error callback function typedef.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
void Purge()
Remove all expired entries.
void SetExpireTime(Time exp)
Set expire time.
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
Ipv4Header GetIpv4Header() const
Get IP header.
Time m_expire
Expire time for queue entry.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
UnicastForwardCallback m_ucb
Unicast forward callback.
bool operator==(QueueEntry const &o) const
Compare queue entries.
void SetPacket(Ptr< const Packet > p)
Set packet.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ErrorCallback GetErrorCallback() const
Get error callback function.
void SetErrorCallback(ErrorCallback ecb)
Set error callback function.
uint32_t GetSize()
Get the number of entries.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
ErrorCallback m_ecb
Error callback.
void Drop(QueueEntry en, std::string reason)
Notify that the packet is dropped from queue due to timeout.
uint32_t GetMaxPacketsPerDst() const
Get maximum packets per destination.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
Time m_queueTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
uint32_t m_maxLenPerDst
The maximum number of packets that we allow per destination to buffer.
bool Enqueue(QueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...