A Discrete-Event Network Simulator
API
dsr-rsendbuff.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_SENDBUFF_H
33#define DSR_SENDBUFF_H
34
35#include <vector>
36#include "ns3/ipv4-routing-protocol.h"
37#include "ns3/simulator.h"
38
39namespace ns3 {
40namespace dsr {
46{
47public:
57 Time exp = Simulator::Now (), uint8_t p = 0)
58 : m_packet (pa),
59 m_dst (d),
60 m_expire (exp + Simulator::Now ()),
61 m_protocol (p)
62 {
63 }
69 bool operator== (DsrSendBuffEntry const & o) const
70 {
71 return ((m_packet == o.m_packet) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
72 }
73
74 // Fields
80 {
81 return m_packet;
82 }
88 {
89 m_packet = p;
90 }
96 {
97 return m_dst;
98 }
104 {
105 m_dst = d;
106 }
112 {
113 m_expire = exp + Simulator::Now ();
114 }
120 {
121 return m_expire - Simulator::Now ();
122 }
127 void SetProtocol (uint8_t p)
128 {
129 m_protocol = p;
130 }
135 uint8_t GetProtocol () const
136 {
137 return m_protocol;
138 }
139
140private:
148 uint8_t m_protocol;
149};
150
155/************************************************************************************************************************/
157{
158public:
163 {
164 }
173 bool Enqueue (DsrSendBuffEntry & entry);
183 bool Dequeue (Ipv4Address dst, DsrSendBuffEntry & entry);
196 bool Find (Ipv4Address dst);
202 uint32_t GetSize ();
209 {
210 return m_maxLen;
211 }
218 {
219 m_maxLen = len;
220 }
227 {
228 return m_sendBufferTimeout;
229 }
236 {
238 }
239 // \}
240
246 std::vector<DsrSendBuffEntry> & GetBuffer ()
247 {
248 return m_sendBuffer;
249 }
250
251private:
252 std::vector<DsrSendBuffEntry> m_sendBuffer;
253 void Purge ();
254
258 void Drop (DsrSendBuffEntry en, std::string reason);
259
262};
263/*******************************************************************************************************************************/
264} // namespace dsr
265} // namespace ns3
266
267#endif /* DSR_SENDBUFF_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:104
DSR Send Buffer Entry.
Definition: dsr-rsendbuff.h:46
Ipv4Address m_dst
Destination address.
Ptr< const Packet > m_packet
Data packet.
uint8_t m_protocol
The protocol number.
void SetDestination(Ipv4Address d)
Set destination address of entry.
DsrSendBuffEntry(Ptr< const Packet > pa=0, Ipv4Address d=Ipv4Address(), Time exp=Simulator::Now(), uint8_t p=0)
Construct DsrSendBuffEntry with the given parameters.
Definition: dsr-rsendbuff.h:56
void SetPacket(Ptr< const Packet > p)
Set pointer to entry's packet.
Definition: dsr-rsendbuff.h:87
Time GetExpireTime() const
Get expire time for entry.
void SetProtocol(uint8_t p)
Set protocol value.
Ipv4Address GetDestination() const
Get destination address of entry.
Definition: dsr-rsendbuff.h:95
Time m_expire
Expire time for queue entry.
uint8_t GetProtocol() const
Get protocol value.
void SetExpireTime(Time exp)
Set expire time for entry.
bool operator==(DsrSendBuffEntry const &o) const
Compare send buffer entries.
Definition: dsr-rsendbuff.h:69
Ptr< const Packet > GetPacket() const
Get pointer to entry's packet.
Definition: dsr-rsendbuff.h:79
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(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.