A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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 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_SENDBUFF_H
33
#define DSR_SENDBUFF_H
34
35
#include <vector>
36
#include "ns3/ipv4-routing-protocol.h"
37
#include "ns3/simulator.h"
38
39
namespace
ns3 {
40
namespace
dsr {
45
class
SendBuffEntry
46
{
47
public
:
48
// / c-tor
49
SendBuffEntry
(
Ptr<const Packet>
pa = 0,
Ipv4Address
d =
Ipv4Address
(),
50
Time
exp =
Simulator::Now
(), uint8_t p = 0)
51
:
m_packet
(pa),
52
m_dst
(d),
53
m_expire
(exp +
Simulator
::
Now
()),
54
m_protocol
(p)
55
{
56
}
61
bool
operator==
(
SendBuffEntry
const
& o)
const
62
{
63
return
((
m_packet
== o.
m_packet
) && (
m_dst
== o.
m_dst
) && (
m_expire
== o.
m_expire
));
64
}
65
// /\name Fields
66
// \{
67
Ptr<const Packet>
GetPacket
()
const
68
{
69
return
m_packet
;
70
}
71
void
SetPacket
(
Ptr<const Packet>
p)
72
{
73
m_packet
= p;
74
}
75
Ipv4Address
GetDestination
()
const
76
{
77
return
m_dst
;
78
}
79
void
SetDestination
(
Ipv4Address
d)
80
{
81
m_dst
= d;
82
}
83
void
SetExpireTime
(
Time
exp)
84
{
85
m_expire
= exp +
Simulator::Now
();
86
}
87
Time
GetExpireTime
()
const
88
{
89
return
m_expire
-
Simulator::Now
();
90
}
91
void
SetProtocol
(uint8_t p)
92
{
93
m_protocol
= p;
94
}
95
uint8_t
GetProtocol
()
const
96
{
97
return
m_protocol
;
98
}
99
// \}
100
private
:
101
// / Data packet
102
Ptr<const Packet>
m_packet
;
103
// / Destination address
104
Ipv4Address
m_dst
;
105
// / Expire time for queue entry
106
Time
m_expire
;
107
// / The protocol number
108
uint8_t
m_protocol
;
109
};
110
115
/************************************************************************************************************************/
116
class
SendBuffer
117
{
118
public
:
119
// / Default c-tor
120
SendBuffer
()
121
{
122
}
123
// / Push entry in queue, if there is no entry with the same packet and destination address in queue.
124
bool
Enqueue
(
SendBuffEntry
& entry);
125
// / Return first found (the earliest) entry for given destination
126
bool
Dequeue
(
Ipv4Address
dst,
SendBuffEntry
& entry);
127
// / Remove all packets with destination IP address dst
128
void
DropPacketWithDst
(
Ipv4Address
dst);
129
// / Finds whether a packet with destination dst exists in the queue
130
bool
Find
(
Ipv4Address
dst);
131
// / Number of entries
132
uint32_t
GetSize
();
133
// /\name Fields
134
// \{
135
uint32_t
GetMaxQueueLen
()
const
136
{
137
return
m_maxLen
;
138
}
139
void
SetMaxQueueLen
(uint32_t len)
140
{
141
m_maxLen
= len;
142
}
143
Time
GetSendBufferTimeout
()
const
144
{
145
return
m_sendBufferTimeout
;
146
}
147
void
SetSendBufferTimeout
(
Time
t)
148
{
149
m_sendBufferTimeout
= t;
150
}
151
// \}
152
153
std::vector<SendBuffEntry> &
GetBuffer
()
154
{
155
return
m_sendBuffer
;
156
}
157
158
private
:
159
160
std::vector<SendBuffEntry>
m_sendBuffer
;
161
void
Purge
();
162
void
Drop
(
SendBuffEntry
en, std::string reason);
163
uint32_t
m_maxLen
;
164
Time
m_sendBufferTimeout
;
165
static
bool
IsEqual
(
SendBuffEntry
en,
const
Ipv4Address
dst)
166
{
167
return
(en.
GetDestination
() == dst);
168
}
169
};
170
/*******************************************************************************************************************************/
171
}
// namespace dsr
172
}
// namespace ns3
173
174
#endif
/* DSR_SENDBUFF_H */
src
dsr
model
dsr-rsendbuff.h
Generated on Tue May 14 2013 11:08:20 for ns-3 by
1.8.1.2