A Discrete-Event Network Simulator
API
dsr-passive-buff.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 https://resilinets.org/
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_PASSIVEBUFF_H
33#define DSR_PASSIVEBUFF_H
34
35#include <vector>
36#include "ns3/ipv4-routing-protocol.h"
37#include "ns3/simulator.h"
38
39namespace ns3 {
40namespace dsr {
46{
47public:
62 Ipv4Address n = Ipv4Address (), uint16_t i = 0, uint16_t f = 0, uint8_t seg = 0, Time exp = Simulator::Now (),
63 uint8_t p = 0)
64 : m_packet (pa),
65 m_dst (d),
66 m_source (s),
67 m_nextHop (n),
70 m_segsLeft (seg),
71 m_expire (exp + Simulator::Now ()),
72 m_protocol (p)
73 {
74 }
80 bool operator== (DsrPassiveBuffEntry const & o) const
81 {
82 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));
83 }
84
85 // Fields
91 {
92 return m_packet;
93 }
99 {
100 m_packet = p;
101 }
107 {
108 return m_dst;
109 }
115 {
116 m_dst = d;
117 }
123 {
124 return m_source;
125 }
131 {
132 m_source = s;
133 }
139 {
140 return m_nextHop;
141 }
147 {
148 m_nextHop = n;
149 }
154 uint16_t GetIdentification () const
155 {
156 return m_identification;
157 }
162 void SetIdentification (uint16_t i)
163 {
165 }
170 uint16_t GetFragmentOffset () const
171 {
172 return m_fragmentOffset;
173 }
178 void SetFragmentOffset (uint16_t f)
179 {
181 }
186 uint8_t GetSegsLeft () const
187 {
188 return m_segsLeft;
189 }
194 void SetSegsLeft (uint8_t seg)
195 {
196 m_segsLeft = seg;
197 }
203 {
204 m_expire = exp + Simulator::Now ();
205 }
211 {
212 return m_expire - Simulator::Now ();
213 }
218 void SetProtocol (uint8_t p)
219 {
220 m_protocol = p;
221 }
226 uint8_t GetProtocol () const
227 {
228 return m_protocol;
229 }
230
231private:
245 uint8_t m_segsLeft;
249 uint8_t m_protocol;
250};
251
257/************************************************************************************************************************/
259{
260public:
265 static TypeId GetTypeId ();
266
268 virtual ~DsrPassiveBuffer ();
269
273 bool Enqueue (DsrPassiveBuffEntry & entry);
278 bool Dequeue (Ipv4Address dst, DsrPassiveBuffEntry & entry);
282 bool Find (Ipv4Address dst);
288 bool AllEqual (DsrPassiveBuffEntry & entry);
291 uint32_t GetSize ();
292
293 // Fields
299 {
300 return m_maxLen;
301 }
307 {
308 m_maxLen = len;
309 }
315 {
317 }
323 {
325 }
326
327private:
329 std::vector<DsrPassiveBuffEntry> m_passiveBuffer;
331 void Purge ();
335 void Drop (DsrPassiveBuffEntry en, std::string reason);
339 void DropLink (DsrPassiveBuffEntry en, std::string reason);
348 static bool LinkEqual (DsrPassiveBuffEntry en, const std::vector<Ipv4Address> link)
349 {
350 return ((en.GetSource () == link[0]) && (en.GetNextHop () == link[1]));
351 }
352};
353/*******************************************************************************************************************************/
354} // namespace dsr
355} // namespace ns3
356
357#endif /* DSR_PASSIVEBUFF_H */
double f(double x, void *params)
Definition: 80211b.c:70
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
A base class which provides memory management and object aggregation.
Definition: object.h:88
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:104
a unique identifier for an interface.
Definition: type-id.h:59
DSR Passive Buffer Entry.
uint8_t m_protocol
The protocol number.
void SetExpireTime(Time exp)
Set expire time.
uint16_t m_fragmentOffset
Fragment offset.
Ipv4Address GetDestination() const
Get destination address function.
void SetIdentification(uint16_t i)
Set identification function.
void SetDestination(Ipv4Address d)
Set destination address function.
uint8_t m_segsLeft
Segments left.
uint8_t GetProtocol() const
Get protocol.
bool operator==(DsrPassiveBuffEntry const &o) const
Compare send buffer entries.
Ipv4Address m_dst
Destination address.
void SetNextHop(Ipv4Address n)
Set next hop address function.
Ptr< const Packet > GetPacket() const
Get packet function.
Ipv4Address GetNextHop() const
Get next hop address function.
void SetSegsLeft(uint8_t seg)
Set segments left.
uint16_t m_identification
Identification.
Ipv4Address GetSource() const
Get source address function.
void SetSource(Ipv4Address s)
Set surce address function.
Ipv4Address m_nextHop
Nexthop address.
Ptr< const Packet > m_packet
Data packet.
void SetProtocol(uint8_t p)
Set protocol function.
Time GetExpireTime() const
Get expire time.
uint8_t GetSegsLeft() const
Get segments left function.
void SetPacket(Ptr< const Packet > p)
Set packet function.
uint16_t GetIdentification() const
Get identification function.
uint16_t GetFragmentOffset() const
Get fragment offset function.
Ipv4Address m_source
Source address.
DsrPassiveBuffEntry(Ptr< const Packet > pa=0, Ipv4Address d=Ipv4Address(), Ipv4Address s=Ipv4Address(), Ipv4Address n=Ipv4Address(), uint16_t i=0, uint16_t f=0, uint8_t seg=0, Time exp=Simulator::Now(), uint8_t p=0)
Construct a DsrPassiveBuffEntry with the given parameters.
Time m_expire
Expire time for queue entry.
void SetFragmentOffset(uint16_t f)
Set fragment offset function.
Time GetPassiveBufferTimeout() const
Get passive buffer timeout.
bool Enqueue(DsrPassiveBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
void SetPassiveBufferTimeout(Time t)
Set passive buffer timeout.
uint32_t GetSize()
Number of entries.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
bool Dequeue(Ipv4Address dst, DsrPassiveBuffEntry &entry)
Return first found (the earliest) entry for given destination.
void DropLink(DsrPassiveBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
Time m_passiveBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
void Purge()
Remove all expired entries.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
static bool LinkEqual(DsrPassiveBuffEntry en, const std::vector< Ipv4Address > link)
Check if the send buffer entry is the same or not.
std::vector< DsrPassiveBuffEntry > m_passiveBuffer
The send buffer to cache unsent packet.
void Drop(DsrPassiveBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
static TypeId GetTypeId()
Get the type ID.
bool AllEqual(DsrPassiveBuffEntry &entry)
Check if all the entries in passive buffer entry is all equal or not.
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.