A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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== (ErrorBuffEntry 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  }
78  // \{
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 (ErrorBuffEntry & entry);
160  bool Dequeue (Ipv4Address dst, ErrorBuffEntry & entry);
162  void DropPacketForErrLink (Ipv4Address source, Ipv4Address nextHop);
164  bool Find (Ipv4Address dst);
166  uint32_t GetSize ();
168  // \{
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 
187  std::vector<ErrorBuffEntry> & GetBuffer ()
188  {
189  return m_errorBuffer;
190  }
191 
192 private:
194  std::vector<ErrorBuffEntry> m_errorBuffer;
196  void Purge ();
198  void Drop (ErrorBuffEntry en, std::string reason);
200  void DropLink (ErrorBuffEntry en, std::string reason);
202  uint32_t m_maxLen;
206  static bool LinkEqual (ErrorBuffEntry en, const std::vector<Ipv4Address> link)
207  {
208  return ((en.GetSource () == link[0]) && (en.GetNextHop () == link[1]));
209  }
210 };
211 /*******************************************************************************************************************************/
212 } // namespace dsr
213 } // namespace ns3
214 
215 #endif /* DSR_ERRORBUFF_H */
bool Dequeue(Ipv4Address dst, ErrorBuffEntry &entry)
Return first found (the earliest) entry for given destination.
ErrorBuffEntry(Ptr< const Packet > pa=0, Ipv4Address d=Ipv4Address(), Ipv4Address s=Ipv4Address(), Ipv4Address n=Ipv4Address(), Time exp=Simulator::Now(), uint8_t p=0)
Create an ErrorBuffEntry with the given parameters.
Definition: dsr-errorbuff.h:58
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
Control the scheduling of simulation events.
Definition: simulator.h:62
void SetDestination(Ipv4Address d)
Definition: dsr-errorbuff.h:91
Time m_errorBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
void SetErrorBufferTimeout(Time t)
bool Enqueue(ErrorBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
void DropPacketForErrLink(Ipv4Address source, Ipv4Address nextHop)
Remove all packets with the error link.
uint32_t GetMaxQueueLen() const
Ipv4Address m_source
Source address.
uint8_t GetProtocol() const
void SetSource(Ipv4Address s)
Definition: dsr-errorbuff.h:99
uint8_t m_protocol
The protocol number.
Time m_expire
Expire time for queue entry.
void SetPacket(Ptr< const Packet > p)
Definition: dsr-errorbuff.h:83
Ipv4Address GetNextHop() const
Ptr< SampleEmitter > s
bool operator==(ErrorBuffEntry const &o) const
Compare send buffer entries.
Definition: dsr-errorbuff.h:73
void Purge()
Remove all expired entries.
void DropLink(ErrorBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
Ptr< const Packet > GetPacket() const
Definition: dsr-errorbuff.h:79
static bool LinkEqual(ErrorBuffEntry en, const std::vector< Ipv4Address > link)
Check if the send buffer entry is the same or not.
Ipv4Address GetDestination() const
Definition: dsr-errorbuff.h:87
uint32_t GetSize()
Number of entries.
void SetProtocol(uint8_t p)
Ptr< const Packet > m_packet
Data packet.
DSR Error Buffer Entry.
Definition: dsr-errorbuff.h:45
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
void SetMaxQueueLen(uint32_t len)
void SetNextHop(Ipv4Address n)
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Ipv4Address m_dst
Destination address.
ErrorBuffer()
Default constructor.
Ipv4Address GetSource() const
Definition: dsr-errorbuff.h:95
void Drop(ErrorBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
Ipv4Address m_nextHop
Nexthop address.
DSR error buffer.
Time GetErrorBufferTimeout() const
void SetExpireTime(Time exp)
Time GetExpireTime() const
std::vector< ErrorBuffEntry > & GetBuffer()
std::vector< ErrorBuffEntry > m_errorBuffer
The send buffer to cache unsent packet.