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-maintain-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 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 {
43
/*
44
* The maintenance buffer is responsible for maintaining packet next hop delivery
45
* The data packet is saved in maintenance buffer whenever the data packet is sent out of send buffer
46
*/
47
/*
48
* The packet timer key for controlling data packet retransmission
49
*/
50
struct
NetworkKey
51
{
52
uint16_t
m_ackId
;
53
Ipv4Address
m_ourAdd
;
54
Ipv4Address
m_nextHop
;
55
Ipv4Address
m_source
;
56
Ipv4Address
m_destination
;
57
62
bool
operator <
(
NetworkKey
const
& o)
const
63
{
64
return
((
m_ackId
< o.
m_ackId
) && (
m_ourAdd
< o.
m_ourAdd
) && (
m_nextHop
< o.
m_nextHop
) && (
m_source
< o.
m_source
)
65
&& (
m_destination
< o.
m_destination
)
66
);
67
}
68
};
69
70
struct
PassiveKey
71
{
72
uint16_t
m_ackId
;
73
Ipv4Address
m_source
;
74
Ipv4Address
m_destination
;
75
uint8_t
m_segsLeft
;
76
81
bool
operator <
(
PassiveKey
const
& o)
const
82
{
83
return
((
m_ackId
< o.
m_ackId
) && (
m_source
< o.
m_source
)
84
&& (
m_destination
< o.
m_destination
) && (
m_segsLeft
< o.
m_segsLeft
)
85
);
86
}
87
};
88
93
class
MaintainBuffEntry
94
{
95
public
:
96
// / c-tor
97
MaintainBuffEntry
(
Ptr<const Packet>
pa = 0,
Ipv4Address
us =
Ipv4Address
(),
98
Ipv4Address
n =
Ipv4Address
(),
Ipv4Address
s =
Ipv4Address
(),
Ipv4Address
dst =
Ipv4Address
(),
99
uint16_t ackId = 0, uint8_t segs = 0,
Time
exp =
Simulator::Now
())
100
:
m_packet
(pa),
101
m_ourAdd
(us),
102
m_nextHop
(n),
103
m_src
(s),
104
m_dst
(dst),
105
m_ackId
(ackId),
106
m_segsLeft
(segs),
107
m_expire
(exp +
Simulator
::
Now
())
108
{
109
}
110
111
// /\name Fields
112
// \{
113
Ptr<const Packet>
GetPacket
()
const
114
{
115
return
m_packet
;
116
}
117
void
SetPacket
(
Ptr<const Packet>
p)
118
{
119
m_packet
= p;
120
}
121
Ipv4Address
GetOurAdd
()
const
122
{
123
return
m_ourAdd
;
124
}
125
void
SetOurAdd
(
Ipv4Address
us)
126
{
127
m_ourAdd
= us;
128
}
129
Ipv4Address
GetNextHop
()
const
130
{
131
return
m_nextHop
;
132
}
133
void
SetNextHop
(
Ipv4Address
n)
134
{
135
m_nextHop
= n;
136
}
137
Ipv4Address
GetDst
()
const
138
{
139
return
m_dst
;
140
}
141
void
SetDst
(
Ipv4Address
n)
142
{
143
m_dst
= n;
144
}
145
Ipv4Address
GetSrc
()
const
146
{
147
return
m_src
;
148
}
149
void
SetSrc
(
Ipv4Address
s)
150
{
151
m_src
= s;
152
}
153
uint16_t
GetAckId
()
const
154
{
155
return
m_ackId
;
156
}
157
void
SetAckId
(uint16_t ackId)
158
{
159
m_ackId
= ackId;
160
}
161
uint8_t
GetSegsLeft
()
const
162
{
163
return
m_segsLeft
;
164
}
165
void
SetSegsLeft
(uint8_t segs)
166
{
167
m_segsLeft
= segs;
168
}
169
void
SetExpireTime
(
Time
exp)
170
{
171
m_expire
= exp +
Simulator::Now
();
172
}
173
Time
GetExpireTime
()
const
174
{
175
return
m_expire
-
Simulator::Now
();
176
}
177
// \}
178
private
:
179
// / Data packet
180
Ptr<const Packet>
m_packet
;
181
// / our own ip address
182
Ipv4Address
m_ourAdd
;
183
// / Next hop Ip address
184
Ipv4Address
m_nextHop
;
185
// / The source address
186
Ipv4Address
m_src
;
187
// / The destination address
188
Ipv4Address
m_dst
;
189
// / The data ack id
190
uint16_t
m_ackId
;
191
// / The ipv4 id
192
uint16_t
m_id
;
193
// / The segments left field
194
uint8_t
m_segsLeft
;
195
// / Expire time for queue entry
196
Time
m_expire
;
197
};
202
/************************************************************************************************************************/
203
class
MaintainBuffer
204
{
205
public
:
206
// / Default c-tor
207
MaintainBuffer
()
208
{
209
}
210
// / Push entry in queue, if there is no entry with the same packet and destination address in queue.
211
bool
Enqueue
(
MaintainBuffEntry
& entry);
212
// / Return first found (the earliest) entry for given destination
213
bool
Dequeue
(
Ipv4Address
dst,
MaintainBuffEntry
& entry);
214
// / Remove all packets with destination IP address dst
215
void
DropPacketWithNextHop
(
Ipv4Address
nextHop);
216
bool
FindMaintainEntry
(
Ptr<Packet>
packet,
Ipv4Address
ourAdd,
Ipv4Address
src,
Ipv4Address
nextHop,
Ipv4Address
dst,
NetworkKey
networkKey);
217
// / Finds whether a packet with destination dst exists in the queue
218
bool
Find
(
Ipv4Address
nextHop);
219
// / Number of entries
220
uint32_t
GetSize
();
221
// /\name Fields
222
// \{
223
uint32_t
GetMaxQueueLen
()
const
224
{
225
return
m_maxLen
;
226
}
227
void
SetMaxQueueLen
(uint32_t len)
228
{
229
m_maxLen
= len;
230
}
231
Time
GetMaintainBufferTimeout
()
const
232
{
233
return
m_maintainBufferTimeout
;
234
}
235
void
SetMaintainBufferTimeout
(
Time
t)
236
{
237
m_maintainBufferTimeout
= t;
238
}
239
bool
AllEqual
(
MaintainBuffEntry
& entry);
240
// / Verify if the maintain buffer entry is the same in every field for network ack
241
bool
NetworkEqual
(
MaintainBuffEntry
& entry);
242
// / Verify if the maintain buffer entry is the same in every field for promiscuous ack
243
bool
PromiscEqual
(
MaintainBuffEntry
& entry);
244
// \}
245
246
private
:
247
// / The vector of maintain buffer entries
248
std::vector<MaintainBuffEntry>
m_maintainBuffer
;
249
std::vector<NetworkKey>
m_allNetworkKey
;
250
// / Remove all expired entries
251
void
Purge
();
252
// / The maximum number of packets that we allow a routing protocol to buffer.
253
uint32_t
m_maxLen
;
254
// / The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
255
Time
m_maintainBufferTimeout
;
256
// / Verify if the maintain buffer is equal or not
257
static
bool
IsEqual
(
MaintainBuffEntry
en,
const
Ipv4Address
nextHop)
258
{
259
return
(en.
GetNextHop
() == nextHop);
260
}
261
};
262
/*******************************************************************************************************************************/
263
}
// namespace dsr
264
}
// namespace ns3
265
#endif
/* DSR_MAINTAIN_BUFF_H */
src
dsr
model
dsr-maintain-buff.h
Generated on Tue Nov 13 2012 10:32:12 for ns-3 by
1.8.1.2