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
84  {
85  return m_packet;
86  }
92  {
93  m_packet = p;
94  }
100  {
101  return m_dst;
102  }
108  {
109  m_dst = d;
110  }
116  {
117  return m_source;
118  }
124  {
125  m_source = s;
126  }
132  {
133  return m_nextHop;
134  }
140  {
141  m_nextHop = n;
142  }
147  void SetExpireTime (Time exp)
148  {
149  m_expire = exp + Simulator::Now ();
150  }
156  {
157  return m_expire - Simulator::Now ();
158  }
163  void SetProtocol (uint8_t p)
164  {
165  m_protocol = p;
166  }
171  uint8_t GetProtocol () const
172  {
173  return m_protocol;
174  }
175 
176 private:
188  uint8_t m_protocol;
189 };
190 
195 /************************************************************************************************************************/
197 {
198 public:
203  {
204  }
211  bool Enqueue (DsrErrorBuffEntry & entry);
218  bool Dequeue (Ipv4Address dst, DsrErrorBuffEntry & entry);
224  void DropPacketForErrLink (Ipv4Address source, Ipv4Address nextHop);
230  bool Find (Ipv4Address dst);
235  uint32_t GetSize ();
236 
237  // Fields
242  uint32_t GetMaxQueueLen () const
243  {
244  return m_maxLen;
245  }
250  void SetMaxQueueLen (uint32_t len)
251  {
252  m_maxLen = len;
253  }
259  {
260  return m_errorBufferTimeout;
261  }
267  {
269  }
274  std::vector<DsrErrorBuffEntry> & GetBuffer ()
275  {
276  return m_errorBuffer;
277  }
278 
279 private:
281  std::vector<DsrErrorBuffEntry> m_errorBuffer;
283  void Purge ();
290  void Drop (DsrErrorBuffEntry en, std::string reason);
296  void DropLink (DsrErrorBuffEntry en, std::string reason);
298  uint32_t m_maxLen;
301 };
302 /*******************************************************************************************************************************/
303 } // namespace dsr
304 } // namespace ns3
305 
306 #endif /* DSR_ERRORBUFF_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Control the scheduling of simulation events.
Definition: simulator.h:69
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
DSR Error Buffer Entry.
Definition: dsr-errorbuff.h:46
bool operator==(DsrErrorBuffEntry const &o) const
Compare send buffer entries.
Definition: dsr-errorbuff.h:73
void SetDestination(Ipv4Address d)
Set destination address.
Ipv4Address m_nextHop
Nexthop address.
void SetNextHop(Ipv4Address n)
Set next hop.
Ptr< const Packet > m_packet
Data packet.
void SetSource(Ipv4Address s)
Set source address.
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
void SetProtocol(uint8_t p)
Set protocol number.
void SetExpireTime(Time exp)
Set expire time.
Ipv4Address m_source
Source address.
Ipv4Address m_dst
Destination address.
Ipv4Address GetNextHop() const
Get next hop.
Ptr< const Packet > GetPacket() const
Get packet from entry.
Definition: dsr-errorbuff.h:83
Ipv4Address GetSource() const
Get source address.
Time GetExpireTime() const
Get expire time.
void SetPacket(Ptr< const Packet > p)
Set packet for entry.
Definition: dsr-errorbuff.h:91
uint8_t m_protocol
The protocol number.
Time m_expire
Expire time for queue entry.
Ipv4Address GetDestination() const
Get destination address.
Definition: dsr-errorbuff.h:99
uint8_t GetProtocol() const
Get protocol number.
DSR error buffer.
Time m_errorBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
std::vector< DsrErrorBuffEntry > & GetBuffer()
Get error buffer entry.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
Time GetErrorBufferTimeout() const
Get error buffer timeout.
bool Enqueue(DsrErrorBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
void DropLink(DsrErrorBuffEntry en, std::string reason)
Notify that packet is dropped from queue by link error.
bool Dequeue(Ipv4Address dst, DsrErrorBuffEntry &entry)
Return first found (the earliest) entry for given destination.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
DsrErrorBuffer()
Default constructor.
void DropPacketForErrLink(Ipv4Address source, Ipv4Address nextHop)
Remove all packets with the error link.
void SetErrorBufferTimeout(Time t)
Set error buffer timeout.
uint32_t GetSize()
Returns the number of entries in the queue.
std::vector< DsrErrorBuffEntry > m_errorBuffer
The send buffer to cache unsent packet.
void Drop(DsrErrorBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
void Purge()
Remove all expired entries.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Every class exported by the ns3 library is enclosed in the ns3 namespace.