A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dsdv-packet-queue.h
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:
54  : m_packet (pa),
55  m_header (h),
56  m_ucb (ucb),
57  m_ecb (ecb),
58  m_expire (Seconds (0))
59  {
60  }
61 
66  bool operator== (QueueEntry const & o) const
67  {
68  return ((m_packet == o.m_packet) && (m_header.GetDestination () == o.m_header.GetDestination ()) && (m_expire == o.m_expire));
69  }
71  // \{
72  UnicastForwardCallback GetUnicastForwardCallback () const
73  {
74  return m_ucb;
75  }
76  void SetUnicastForwardCallback (UnicastForwardCallback ucb)
77  {
78  m_ucb = ucb;
79  }
80  ErrorCallback GetErrorCallback () const
81  {
82  return m_ecb;
83  }
84  void SetErrorCallback (ErrorCallback ecb)
85  {
86  m_ecb = ecb;
87  }
88  Ptr<const Packet> GetPacket () const
89  {
90  return m_packet;
91  }
92  void SetPacket (Ptr<const Packet> p)
93  {
94  m_packet = p;
95  }
96  Ipv4Header GetIpv4Header () const
97  {
98  return m_header;
99  }
100  void SetIpv4Header (Ipv4Header h)
101  {
102  m_header = h;
103  }
104  void SetExpireTime (Time exp)
105  {
106  m_expire = exp + Simulator::Now ();
107  }
108  Time GetExpireTime () const
109  {
110  return m_expire - Simulator::Now ();
111  }
112  // \}
113 private:
124 };
134 {
135 public:
138  {
139  }
141  bool Enqueue (QueueEntry & entry);
143  bool Dequeue (Ipv4Address dst, QueueEntry & entry);
145  void DropPacketWithDst (Ipv4Address dst);
147  bool Find (Ipv4Address dst);
149  uint32_t
152  uint32_t GetSize ();
154  // \{
155  uint32_t GetMaxQueueLen () const
156  {
157  return m_maxLen;
158  }
159  void SetMaxQueueLen (uint32_t len)
160  {
161  m_maxLen = len;
162  }
163  uint32_t GetMaxPacketsPerDst () const
164  {
165  return m_maxLenPerDst;
166  }
167  void SetMaxPacketsPerDst (uint32_t len)
168  {
169  m_maxLenPerDst = len;
170  }
171  Time GetQueueTimeout () const
172  {
173  return m_queueTimeout;
174  }
175  void SetQueueTimeout (Time t)
176  {
177  m_queueTimeout = t;
178  }
179  // \}
180 
181 private:
182  std::vector<QueueEntry> m_queue;
184  void Purge ();
186  void Drop (QueueEntry en, std::string reason);
188  uint32_t m_maxLen;
190  uint32_t m_maxLenPerDst;
193  static bool IsEqual (QueueEntry en, const Ipv4Address dst)
194  {
195  return (en.GetIpv4Header ().GetDestination () == dst);
196  }
197 };
198 }
199 }
200 #endif /* DSDV_PACKETQUEUE_H */
keep track of time unit.
Definition: nstime.h:149
Callback template class.
Definition: callback.h:369
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:303
QueueEntry(Ptr< const Packet > pa=0, Ipv4Header const &h=Ipv4Header(), UnicastForwardCallback ucb=UnicastForwardCallback(), ErrorCallback ecb=ErrorCallback())
c-tor
Ipv4Header m_header
IP header.
uint32_t GetCountForPacketsWithDst(Ipv4Address dst)
Get count of packets with destination dst in the queue.
DSDV Packet queue.
Packet header for IPv4.
Definition: ipv4-header.h:31
DSDV Queue Entry.
Ptr< const Packet > m_packet
Data packet.
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.
static Time Now(void)
Definition: simulator.cc:179
void Purge()
Remove all expired entries.
Time m_expire
Expire time for queue entry.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
UnicastForwardCallback m_ucb
Unicast forward callback.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
bool operator==(QueueEntry const &o) const
uint32_t GetSize()
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 packet is dropped from queue by timeout.
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...