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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
dsr-maintain-buff.h
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_MAINTAIN_BUFF_H
33
#define DSR_MAINTAIN_BUFF_H
34
35
#include <vector>
36
#include "ns3/ipv4-routing-protocol.h"
37
#include "ns3/simulator.h"
38
#include "ns3/ipv4-header.h"
39
#include "dsr-option-header.h"
40
41
namespace
ns3 {
42
namespace
dsr {
47
struct
LinkKey
48
{
49
Ipv4Address
m_source;
50
Ipv4Address
m_destination;
51
Ipv4Address
m_ourAdd;
52
Ipv4Address
m_nextHop;
53
58
bool
operator <
(
LinkKey
const
& o)
const
59
{
60
return
((m_source < o.m_source) && (m_destination < o.m_destination)
61
&& (m_ourAdd < o.m_nextHop) && (m_nextHop < o.m_nextHop)
62
);
63
}
64
};
65
66
struct
NetworkKey
67
{
68
uint16_t m_ackId;
69
Ipv4Address
m_ourAdd;
70
Ipv4Address
m_nextHop;
71
Ipv4Address
m_source;
72
Ipv4Address
m_destination;
73
78
bool
operator <
(
NetworkKey
const
& o)
const
79
{
80
return
((m_ackId < o.m_ackId) && (m_ourAdd < o.m_ourAdd) && (m_nextHop < o.m_nextHop) && (m_source < o.m_source)
81
&& (m_destination < o.m_destination)
82
);
83
}
84
};
85
86
struct
PassiveKey
87
{
88
uint16_t m_ackId;
89
Ipv4Address
m_source;
90
Ipv4Address
m_destination;
91
uint8_t m_segsLeft;
92
97
bool
operator <
(
PassiveKey
const
& o)
const
98
{
99
return
((m_ackId < o.m_ackId) && (m_source < o.m_source)
100
&& (m_destination < o.m_destination) && (m_segsLeft < o.m_segsLeft)
101
);
102
}
103
};
104
109
class
MaintainBuffEntry
110
{
111
public
:
112
// / c-tor
113
MaintainBuffEntry
(
Ptr<const Packet>
pa = 0,
Ipv4Address
us =
Ipv4Address
(),
114
Ipv4Address
n =
Ipv4Address
(),
Ipv4Address
s =
Ipv4Address
(),
Ipv4Address
dst =
Ipv4Address
(),
115
uint16_t ackId = 0, uint8_t segs = 0,
Time
exp =
Simulator::Now
())
116
: m_packet (pa),
117
m_ourAdd (us),
118
m_nextHop (n),
119
m_src (s),
120
m_dst (dst),
121
m_ackId (ackId),
122
m_segsLeft (segs),
123
m_expire (exp +
Simulator::Now
())
124
{
125
}
126
127
// /\name Fields
128
// \{
129
Ptr<const Packet>
GetPacket ()
const
130
{
131
return
m_packet;
132
}
133
void
SetPacket (
Ptr<const Packet>
p)
134
{
135
m_packet = p;
136
}
137
Ipv4Address
GetOurAdd ()
const
138
{
139
return
m_ourAdd;
140
}
141
void
SetOurAdd (
Ipv4Address
us)
142
{
143
m_ourAdd = us;
144
}
145
Ipv4Address
GetNextHop ()
const
146
{
147
return
m_nextHop;
148
}
149
void
SetNextHop (
Ipv4Address
n)
150
{
151
m_nextHop = n;
152
}
153
Ipv4Address
GetDst ()
const
154
{
155
return
m_dst;
156
}
157
void
SetDst (
Ipv4Address
n)
158
{
159
m_dst = n;
160
}
161
Ipv4Address
GetSrc ()
const
162
{
163
return
m_src;
164
}
165
void
SetSrc (
Ipv4Address
s)
166
{
167
m_src = s;
168
}
169
uint16_t GetAckId ()
const
170
{
171
return
m_ackId;
172
}
173
void
SetAckId (uint16_t ackId)
174
{
175
m_ackId = ackId;
176
}
177
uint8_t GetSegsLeft ()
const
178
{
179
return
m_segsLeft;
180
}
181
void
SetSegsLeft (uint8_t segs)
182
{
183
m_segsLeft = segs;
184
}
185
void
SetExpireTime (
Time
exp)
186
{
187
m_expire = exp +
Simulator::Now
();
188
}
189
Time
GetExpireTime ()
const
190
{
191
return
m_expire -
Simulator::Now
();
192
}
193
// \}
194
private
:
195
// / Data packet
196
Ptr<const Packet>
m_packet;
197
// / Our own ip address
198
Ipv4Address
m_ourAdd;
199
// / Next hop Ip address
200
Ipv4Address
m_nextHop;
201
// / The source address
202
Ipv4Address
m_src;
203
// / The destination address
204
Ipv4Address
m_dst;
205
// / The data ack id
206
uint16_t m_ackId;
207
// / The ipv4 id
208
uint16_t m_id;
209
// / The segments left field
210
uint8_t m_segsLeft;
211
// / Expire time for queue entry
212
Time
m_expire;
213
};
218
/************************************************************************************************************************/
219
class
MaintainBuffer
220
{
221
public
:
222
// / Default c-tor
223
MaintainBuffer
()
224
{
225
}
226
// / Push entry in queue, if there is no entry with the same packet and destination address in queue.
227
bool
Enqueue (
MaintainBuffEntry
& entry);
228
// / Return first found (the earliest) entry for given destination
229
bool
Dequeue (
Ipv4Address
dst,
MaintainBuffEntry
& entry);
230
// / Remove all packets with destination IP address dst
231
void
DropPacketWithNextHop (
Ipv4Address
nextHop);
232
// / Finds whether a packet with destination dst exists in the queue
233
bool
Find (
Ipv4Address
nextHop);
234
// / Number of entries
235
uint32_t GetSize ();
236
// /\name Fields
237
// \{
238
uint32_t GetMaxQueueLen ()
const
239
{
240
return
m_maxLen;
241
}
242
void
SetMaxQueueLen (uint32_t len)
243
{
244
m_maxLen = len;
245
}
246
Time
GetMaintainBufferTimeout ()
const
247
{
248
return
m_maintainBufferTimeout;
249
}
250
void
SetMaintainBufferTimeout (
Time
t)
251
{
252
m_maintainBufferTimeout = t;
253
}
254
// / Verify if all the elements in the maintainence buffer entry is the same
255
bool
AllEqual (
MaintainBuffEntry
& entry);
256
// / Verify if the maintain buffer entry is the same in every field for link ack
257
bool
LinkEqual (
MaintainBuffEntry
& entry);
258
// / Verify if the maintain buffer entry is the same in every field for network ack
259
bool
NetworkEqual (
MaintainBuffEntry
& entry);
260
// / Verify if the maintain buffer entry is the same in every field for promiscuous ack
261
bool
PromiscEqual (
MaintainBuffEntry
& entry);
262
// \}
263
264
private
:
265
// / The vector of maintain buffer entries
266
std::vector<MaintainBuffEntry> m_maintainBuffer;
267
std::vector<NetworkKey> m_allNetworkKey;
268
// / Remove all expired entries
269
void
Purge ();
270
// / The maximum number of packets that we allow a routing protocol to buffer.
271
uint32_t m_maxLen;
272
// / The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
273
Time
m_maintainBufferTimeout;
274
// / Verify if the maintain buffer is equal or not
275
static
bool
IsEqual (
MaintainBuffEntry
en,
const
Ipv4Address
nextHop)
276
{
277
return
(en.GetNextHop () == nextHop);
278
}
279
};
280
/*******************************************************************************************************************************/
281
}
// namespace dsr
282
}
// namespace ns3
283
#endif
/* DSR_MAINTAIN_BUFF_H */
ns3::Time
keep track of time unit.
Definition:
nstime.h:149
ns3::Ptr< const Packet >
ns3::dsr::MaintainBuffer
DSR maintain buffer.
Definition:
dsr-maintain-buff.h:219
ns3::dsr::LinkKey::operator<
bool operator<(LinkKey const &o) const
Definition:
dsr-maintain-buff.h:58
ns3::dsr::NetworkKey::operator<
bool operator<(NetworkKey const &o) const
Definition:
dsr-maintain-buff.h:78
ns3::dsr::PassiveKey
Definition:
dsr-maintain-buff.h:86
ns3::dsr::LinkKey
Definition:
dsr-maintain-buff.h:47
ns3::Simulator::Now
static Time Now(void)
Definition:
simulator.cc:179
ns3::dsr::MaintainBuffEntry
DSR Maintain Buffer Entry.
Definition:
dsr-maintain-buff.h:109
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:38
ns3::dsr::NetworkKey
Definition:
dsr-maintain-buff.h:66
ns3::dsr::PassiveKey::operator<
bool operator<(PassiveKey const &o) const
Definition:
dsr-maintain-buff.h:97
src
dsr
model
dsr-maintain-buff.h
Generated on Sun Mar 16 2014 11:25:03 for ns-3 by
1.8.6