A Discrete-Event Network Simulator
API
dsr-rsendbuff.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_SENDBUFF_H
33 #define DSR_SENDBUFF_H
34 
35 #include <vector>
36 #include "ns3/ipv4-routing-protocol.h"
37 #include "ns3/simulator.h"
38 
39 namespace ns3 {
40 namespace dsr {
46 {
47 public:
57  Time exp = Simulator::Now (), uint8_t p = 0)
58  : m_packet (pa),
59  m_dst (d),
60  m_expire (exp + Simulator::Now ()),
61  m_protocol (p)
62  {
63  }
69  bool operator== (DsrSendBuffEntry const & o) const
70  {
71  return ((m_packet == o.m_packet) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
72  }
73 
74  // Fields
80  {
81  return m_packet;
82  }
88  {
89  m_packet = p;
90  }
96  {
97  return m_dst;
98  }
104  {
105  m_dst = d;
106  }
111  void SetExpireTime (Time exp)
112  {
113  m_expire = exp + Simulator::Now ();
114  }
120  {
121  return m_expire - Simulator::Now ();
122  }
127  void SetProtocol (uint8_t p)
128  {
129  m_protocol = p;
130  }
135  uint8_t GetProtocol () const
136  {
137  return m_protocol;
138  }
139 
140 private:
148  uint8_t m_protocol;
149 };
150 
155 /************************************************************************************************************************/
157 {
158 public:
163  {
164  }
173  bool Enqueue (DsrSendBuffEntry & entry);
183  bool Dequeue (Ipv4Address dst, DsrSendBuffEntry & entry);
189  void DropPacketWithDst (Ipv4Address dst);
196  bool Find (Ipv4Address dst);
202  uint32_t GetSize ();
208  uint32_t GetMaxQueueLen () const
209  {
210  return m_maxLen;
211  }
217  void SetMaxQueueLen (uint32_t len)
218  {
219  m_maxLen = len;
220  }
227  {
228  return m_sendBufferTimeout;
229  }
236  {
238  }
239  // \}
240 
246  std::vector<DsrSendBuffEntry> & GetBuffer ()
247  {
248  return m_sendBuffer;
249  }
250 
251 private:
252  std::vector<DsrSendBuffEntry> m_sendBuffer;
253  void Purge ();
254 
258  void Drop (DsrSendBuffEntry en, std::string reason);
259 
260  uint32_t m_maxLen;
262 };
263 /*******************************************************************************************************************************/
264 } // namespace dsr
265 } // namespace ns3
266 
267 #endif /* DSR_SENDBUFF_H */
uint32_t GetSize()
Number of entries.
DSR send buffer.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Control the scheduling of simulation events.
Definition: simulator.h:68
Ipv4Address GetDestination() const
Get destination address of entry.
Definition: dsr-rsendbuff.h:95
std::vector< DsrSendBuffEntry > m_sendBuffer
The send buffer to cache unsent packet.
Time m_expire
Expire time for queue entry.
void SetDestination(Ipv4Address d)
Set destination address of entry.
Ipv4Address m_dst
Destination address.
uint8_t GetProtocol() const
Get protocol value.
void SetProtocol(uint8_t p)
Set protocol value.
std::vector< DsrSendBuffEntry > & GetBuffer()
Return a pointer to the internal queue.
void SetPacket(Ptr< const Packet > p)
Set pointer to entry&#39;s packet.
Definition: dsr-rsendbuff.h:87
bool operator==(DsrSendBuffEntry const &o) const
Compare send buffer entries.
Definition: dsr-rsendbuff.h:69
uint32_t GetMaxQueueLen() const
Return the maximum queue length.
void Purge()
Remove all expired entries.
Ptr< const Packet > GetPacket() const
Get pointer to entry&#39;s packet.
Definition: dsr-rsendbuff.h:79
void SetExpireTime(Time exp)
Set expire time for entry.
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
DsrSendBuffer()
Default constructor.
void SetSendBufferTimeout(Time t)
Set the entry lifetime in the queue.
Time m_sendBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
void Drop(DsrSendBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
bool Find(Ipv4Address dst)
Check if a packet with destination dst exists in the queue.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time GetExpireTime() const
Get expire time for entry.
bool Enqueue(DsrSendBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
DSR Send Buffer Entry.
Definition: dsr-rsendbuff.h:45
Time GetSendBufferTimeout() const
Return the entry lifetime in the queue.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
void SetMaxQueueLen(uint32_t len)
Set the maximum queue length.
DsrSendBuffEntry(Ptr< const Packet > pa=0, Ipv4Address d=Ipv4Address(), Time exp=Simulator::Now(), uint8_t p=0)
Construct DsrSendBuffEntry with the given parameters.
Definition: dsr-rsendbuff.h:56
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
Ptr< const Packet > m_packet
Data packet.
uint8_t m_protocol
The protocol number.
bool Dequeue(Ipv4Address dst, DsrSendBuffEntry &entry)
Return first found (the earliest) entry for the given destination.