A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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== (SendBuffEntry const & o) const
70  {
71  return ((m_packet == o.m_packet) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
72  }
73  // /\name Fields
74  // \{
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 (SendBuffEntry & entry);
151  bool Dequeue (Ipv4Address dst, SendBuffEntry & 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<SendBuffEntry> & GetBuffer ()
215  {
216  return m_sendBuffer;
217  }
218 
219 private:
220 
221  std::vector<SendBuffEntry> m_sendBuffer;
222  void Purge ();
223  void Drop (SendBuffEntry en, std::string reason);
224  uint32_t m_maxLen;
226 
234  static bool IsEqual (SendBuffEntry 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 */
Time m_sendBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
bool Find(Ipv4Address dst)
Check if a packet with destination dst exists in the queue.
Time m_expire
Expire time for queue entry.
void Drop(SendBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
uint32_t GetSize()
Number of entries.
Control the scheduling of simulation events.
Definition: simulator.h:63
Ipv4Address m_dst
Destination address.
Ipv4Address GetDestination() const
Definition: dsr-rsendbuff.h:83
std::vector< SendBuffEntry > & GetBuffer()
Return a pointer to the internal queue.
void SetDestination(Ipv4Address d)
Definition: dsr-rsendbuff.h:87
void Purge()
Remove all expired entries.
bool operator==(SendBuffEntry const &o) const
Compare send buffer entries.
Definition: dsr-rsendbuff.h:69
void SetProtocol(uint8_t p)
Definition: dsr-rsendbuff.h:99
uint8_t m_protocol
The protocol number.
SendBuffer()
Default constructor.
void SetPacket(Ptr< const Packet > p)
Definition: dsr-rsendbuff.h:79
DSR Send Buffer Entry.
Definition: dsr-rsendbuff.h:45
SendBuffEntry(Ptr< const Packet > pa=0, Ipv4Address d=Ipv4Address(), Time exp=Simulator::Now(), uint8_t p=0)
Construct SendBuffEntry with the given parameters.
Definition: dsr-rsendbuff.h:56
uint32_t GetMaxQueueLen() const
Return the maximum queue length.
bool Dequeue(Ipv4Address dst, SendBuffEntry &entry)
Return first found (the earliest) entry for the given destination.
Ptr< const Packet > GetPacket() const
Definition: dsr-rsendbuff.h:75
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
void SetExpireTime(Time exp)
Definition: dsr-rsendbuff.h:91
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
uint8_t GetProtocol() const
DSR send buffer.
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.
std::vector< SendBuffEntry > m_sendBuffer
The send buffer to cache unsent packet.
static bool IsEqual(SendBuffEntry en, const Ipv4Address dst)
Check if the send buffer entry is the same or not.
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
void SetSendBufferTimeout(Time t)
Set the entry lifetime in the queue.
void SetMaxQueueLen(uint32_t len)
Set the maximum queue length.
Time GetSendBufferTimeout() const
Return the entry lifetime in the queue.
bool Enqueue(SendBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
Time GetExpireTime() const
Definition: dsr-rsendbuff.h:95
Ptr< const Packet > m_packet
Data packet.