A Discrete-Event Network Simulator
API
dsr-errorbuff.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_ERRORBUFF_H
33 #define DSR_ERRORBUFF_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:
59  Ipv4Address n = Ipv4Address (), Time exp = Simulator::Now (), uint8_t p = 0)
60  : m_packet (pa),
61  m_dst (d),
62  m_source (s),
63  m_nextHop (n),
64  m_expire (exp + Simulator::Now ()),
65  m_protocol (p)
66  {
67  }
73  bool operator== (DsrErrorBuffEntry const & o) const
74  {
75  return ((m_packet == o.m_packet) && (m_source == o.m_source) && (m_nextHop == o.m_nextHop) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
76  }
77 
78  // Fields
80  {
81  return m_packet;
82  }
84  {
85  m_packet = p;
86  }
88  {
89  return m_dst;
90  }
92  {
93  m_dst = d;
94  }
96  {
97  return m_source;
98  }
100  {
101  m_source = s;
102  }
104  {
105  return m_nextHop;
106  }
108  {
109  m_nextHop = n;
110  }
111  void SetExpireTime (Time exp)
112  {
113  m_expire = exp + Simulator::Now ();
114  }
116  {
117  return m_expire - Simulator::Now ();
118  }
119  void SetProtocol (uint8_t p)
120  {
121  m_protocol = p;
122  }
123  uint8_t GetProtocol () const
124  {
125  return m_protocol;
126  }
127 
128 private:
140  uint8_t m_protocol;
141 };
142 
147 /************************************************************************************************************************/
149 {
150 public:
155  {
156  }
158  bool Enqueue (DsrErrorBuffEntry & entry);
160  bool Dequeue (Ipv4Address dst, DsrErrorBuffEntry & entry);
162  void DropPacketForErrLink (Ipv4Address source, Ipv4Address nextHop);
164  bool Find (Ipv4Address dst);
166  uint32_t GetSize ();
167 
168  // Fields
169  uint32_t GetMaxQueueLen () const
170  {
171  return m_maxLen;
172  }
173  void SetMaxQueueLen (uint32_t len)
174  {
175  m_maxLen = len;
176  }
178  {
179  return m_errorBufferTimeout;
180  }
182  {
184  }
185 
186  std::vector<DsrErrorBuffEntry> & GetBuffer ()
187  {
188  return m_errorBuffer;
189  }
190 
191 private:
193  std::vector<DsrErrorBuffEntry> m_errorBuffer;
195  void Purge ();
197  void Drop (DsrErrorBuffEntry en, std::string reason);
199  void DropLink (DsrErrorBuffEntry en, std::string reason);
201  uint32_t m_maxLen;
205  static bool LinkEqual (DsrErrorBuffEntry en, const std::vector<Ipv4Address> link)
206  {
207  return ((en.GetSource () == link[0]) && (en.GetNextHop () == link[1]));
208  }
209 };
210 /*******************************************************************************************************************************/
211 } // namespace dsr
212 } // namespace ns3
213 
214 #endif /* DSR_ERRORBUFF_H */
Time m_expire
Expire time for queue entry.
uint32_t GetSize()
Number of entries.
void SetExpireTime(Time exp)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Time GetExpireTime() const
Control the scheduling of simulation events.
Definition: simulator.h:68
DsrErrorBuffEntry(Ptr< const Packet > pa=0, Ipv4Address d=Ipv4Address(), Ipv4Address s=Ipv4Address(), Ipv4Address n=Ipv4Address(), Time exp=Simulator::Now(), uint8_t p=0)
Create an DsrErrorBuffEntry with the given parameters.
Definition: dsr-errorbuff.h:58
Ipv4Address GetDestination() const
Definition: dsr-errorbuff.h:87
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
void SetPacket(Ptr< const Packet > p)
Definition: dsr-errorbuff.h:83
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
DSR Error Buffer Entry.
Definition: dsr-errorbuff.h:45
DSR error buffer.
void SetDestination(Ipv4Address d)
Definition: dsr-errorbuff.h:91
bool Dequeue(Ipv4Address dst, DsrErrorBuffEntry &entry)
Return first found (the earliest) entry for given destination.
DsrErrorBuffer()
Default constructor.
void DropLink(DsrErrorBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
Ptr< const Packet > m_packet
Data packet.
void SetNextHop(Ipv4Address n)
void DropPacketForErrLink(Ipv4Address source, Ipv4Address nextHop)
Remove all packets with the error link.
void SetErrorBufferTimeout(Time t)
void SetProtocol(uint8_t p)
void SetMaxQueueLen(uint32_t len)
bool Enqueue(DsrErrorBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
bool operator==(DsrErrorBuffEntry const &o) const
Compare send buffer entries.
Definition: dsr-errorbuff.h:73
void Purge()
Remove all expired entries.
std::vector< DsrErrorBuffEntry > & GetBuffer()
uint8_t GetProtocol() const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< DsrErrorBuffEntry > m_errorBuffer
The send buffer to cache unsent packet.
void SetSource(Ipv4Address s)
Definition: dsr-errorbuff.h:99
void Drop(DsrErrorBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
Ipv4Address GetSource() const
Definition: dsr-errorbuff.h:95
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
uint8_t m_protocol
The protocol number.
Ptr< const Packet > GetPacket() const
Definition: dsr-errorbuff.h:79
uint32_t GetMaxQueueLen() const
Time GetErrorBufferTimeout() const
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:340
static bool LinkEqual(DsrErrorBuffEntry en, const std::vector< Ipv4Address > link)
Check if the send buffer entry is the same or not.
Ipv4Address m_nextHop
Nexthop address.
Ipv4Address GetNextHop() const
Ipv4Address m_source
Source address.
Ipv4Address m_dst
Destination address.
Time m_errorBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.