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
76  {
77  return m_packet;
78  }
80  {
81  m_packet = p;
82  }
84  {
85  return m_dst;
86  }
88  {
89  m_dst = d;
90  }
91  void SetExpireTime (Time exp)
92  {
93  m_expire = exp + Simulator::Now ();
94  }
96  {
97  return m_expire - Simulator::Now ();
98  }
99  void SetProtocol (uint8_t p)
100  {
101  m_protocol = p;
102  }
103  uint8_t GetProtocol () const
104  {
105  return m_protocol;
106  }
107 
108 private:
116  uint8_t m_protocol;
117 };
118 
123 /************************************************************************************************************************/
125 {
126 public:
131  {
132  }
141  bool Enqueue (DsrSendBuffEntry & entry);
151  bool Dequeue (Ipv4Address dst, DsrSendBuffEntry & entry);
157  void DropPacketWithDst (Ipv4Address dst);
164  bool Find (Ipv4Address dst);
170  uint32_t GetSize ();
176  uint32_t GetMaxQueueLen () const
177  {
178  return m_maxLen;
179  }
185  void SetMaxQueueLen (uint32_t len)
186  {
187  m_maxLen = len;
188  }
195  {
196  return m_sendBufferTimeout;
197  }
204  {
206  }
207  // \}
208 
214  std::vector<DsrSendBuffEntry> & GetBuffer ()
215  {
216  return m_sendBuffer;
217  }
218 
219 private:
220 
221  std::vector<DsrSendBuffEntry> m_sendBuffer;
222  void Purge ();
223  void Drop (DsrSendBuffEntry en, std::string reason);
224  uint32_t m_maxLen;
226 
234  static bool IsEqual (DsrSendBuffEntry en, const Ipv4Address dst)
235  {
236  return (en.GetDestination () == dst);
237  }
238 };
239 /*******************************************************************************************************************************/
240 } // namespace dsr
241 } // namespace ns3
242 
243 #endif /* DSR_SENDBUFF_H */
uint32_t GetSize()
Number of entries.
DSR send buffer.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
static bool IsEqual(DsrSendBuffEntry en, const Ipv4Address dst)
Check if the send buffer entry is the same or not.
Control the scheduling of simulation events.
Definition: simulator.h:68
Time GetSendBufferTimeout() const
Return the entry lifetime in the queue.
std::vector< DsrSendBuffEntry > m_sendBuffer
The send buffer to cache unsent packet.
Time m_expire
Expire time for queue entry.
Ptr< const Packet > GetPacket() const
Definition: dsr-rsendbuff.h:75
void SetDestination(Ipv4Address d)
Definition: dsr-rsendbuff.h:87
Ipv4Address m_dst
Destination address.
void SetProtocol(uint8_t p)
Definition: dsr-rsendbuff.h:99
std::vector< DsrSendBuffEntry > & GetBuffer()
Return a pointer to the internal queue.
void SetPacket(Ptr< const Packet > p)
Definition: dsr-rsendbuff.h:79
void Purge()
Remove all expired entries.
void SetExpireTime(Time exp)
Definition: dsr-rsendbuff.h:91
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
bool operator==(DsrSendBuffEntry const &o) const
Compare send buffer entries.
Definition: dsr-rsendbuff.h:69
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.
Ipv4Address GetDestination() const
Definition: dsr-rsendbuff.h:83
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:224
DSR Send Buffer Entry.
Definition: dsr-rsendbuff.h:45
Time GetExpireTime() const
Definition: dsr-rsendbuff.h:95
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
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
uint32_t GetMaxQueueLen() const
Return the maximum queue length.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:340
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.
uint8_t GetProtocol() const