A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-rsendbuff.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Yufei Cheng
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
18 *
19 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
20 * ResiliNets Research Group https://resilinets.org/
21 * Information and Telecommunication Technology Center (ITTC)
22 * and Department of Electrical Engineering and Computer Science
23 * The University of Kansas Lawrence, KS USA.
24 *
25 * Work supported in part by NSF FIND (Future Internet Design) Program
26 * under grant CNS-0626918 (Postmodern Internet Architecture),
27 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
28 * US Department of Defense (DoD), and ITTC at The University of Kansas.
29 */
30
31#ifndef DSR_SENDBUFF_H
32#define DSR_SENDBUFF_H
33
34#include "ns3/ipv4-routing-protocol.h"
35#include "ns3/simulator.h"
36
37#include <vector>
38
39namespace ns3
40{
41namespace dsr
42{
48{
49 public:
60 Time exp = Simulator::Now(),
61 uint8_t p = 0)
62 : m_packet(pa),
63 m_dst(d),
64 m_expire(exp + Simulator::Now()),
65 m_protocol(p)
66 {
67 }
68
74 bool operator==(const DsrSendBuffEntry& o) const
75 {
76 return ((m_packet == o.m_packet) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
77 }
78
79 // Fields
85 {
86 return m_packet;
87 }
88
94 {
95 m_packet = p;
96 }
97
103 {
104 return m_dst;
105 }
106
112 {
113 m_dst = d;
114 }
115
121 {
122 m_expire = exp + Simulator::Now();
123 }
124
130 {
131 return m_expire - Simulator::Now();
132 }
133
138 void SetProtocol(uint8_t p)
139 {
140 m_protocol = p;
141 }
142
147 uint8_t GetProtocol() const
148 {
149 return m_protocol;
150 }
151
152 private:
160 uint8_t m_protocol;
161};
162
167/************************************************************************************************************************/
169{
170 public:
175 {
176 }
177
186 bool Enqueue(DsrSendBuffEntry& entry);
196 bool Dequeue(Ipv4Address dst, DsrSendBuffEntry& entry);
209 bool Find(Ipv4Address dst);
216
223 {
224 return m_maxLen;
225 }
226
233 {
234 m_maxLen = len;
235 }
236
243 {
244 return m_sendBufferTimeout;
245 }
246
253 {
255 }
256
257 // \}
258
264 std::vector<DsrSendBuffEntry>& GetBuffer()
265 {
266 return m_sendBuffer;
267 }
268
269 private:
270 std::vector<DsrSendBuffEntry> m_sendBuffer;
271 void Purge();
272
276 void Drop(DsrSendBuffEntry en, std::string reason);
277
282};
283
284/*******************************************************************************************************************************/
285} // namespace dsr
286} // namespace ns3
287
288#endif /* DSR_SENDBUFF_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Control the scheduling of simulation events.
Definition: simulator.h:68
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
DSR Send Buffer Entry.
Definition: dsr-rsendbuff.h:48
Ipv4Address m_dst
Destination address.
Ptr< const Packet > m_packet
Data packet.
DsrSendBuffEntry(Ptr< const Packet > pa=nullptr, Ipv4Address d=Ipv4Address(), Time exp=Simulator::Now(), uint8_t p=0)
Construct DsrSendBuffEntry with the given parameters.
Definition: dsr-rsendbuff.h:58
uint8_t m_protocol
The protocol number.
void SetDestination(Ipv4Address d)
Set destination address of entry.
void SetPacket(Ptr< const Packet > p)
Set pointer to entry's packet.
Definition: dsr-rsendbuff.h:93
Time GetExpireTime() const
Get expire time for entry.
void SetProtocol(uint8_t p)
Set protocol value.
Ipv4Address GetDestination() const
Get destination address of entry.
Time m_expire
Expire time for queue entry.
uint8_t GetProtocol() const
Get protocol value.
void SetExpireTime(Time exp)
Set expire time for entry.
Ptr< const Packet > GetPacket() const
Get pointer to entry's packet.
Definition: dsr-rsendbuff.h:84
bool operator==(const DsrSendBuffEntry &o) const
Compare send buffer entries.
Definition: dsr-rsendbuff.h:74
DSR send buffer.
void SetMaxQueueLen(uint32_t len)
Set the maximum queue length.
Time GetSendBufferTimeout() const
Return the entry lifetime in the queue.
uint32_t GetSize()
Number of entries.
bool Dequeue(Ipv4Address dst, DsrSendBuffEntry &entry)
Return first found (the earliest) entry for the given destination.
uint32_t GetMaxQueueLen() const
Return the maximum queue length.
void SetSendBufferTimeout(Time t)
Set the entry lifetime in the queue.
void Purge()
Remove all expired entries.
Time m_sendBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
std::vector< DsrSendBuffEntry > m_sendBuffer
The send buffer to cache unsent packet.
std::vector< DsrSendBuffEntry > & GetBuffer()
Return a pointer to the internal queue.
bool Enqueue(DsrSendBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
bool Find(Ipv4Address dst)
Check if a packet with destination dst exists in the queue.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
void Drop(DsrSendBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
DsrSendBuffer()
Default constructor.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
Every class exported by the ns3 library is enclosed in the ns3 namespace.