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
dsdv-packet-queue.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2010 Hemanth Narra
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: Hemanth Narra <hemanth@ittc.ku.com>
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 DSDV_PACKETQUEUE_H
33
#define DSDV_PACKETQUEUE_H
34
35
#include <vector>
36
#include "ns3/ipv4-routing-protocol.h"
37
#include "ns3/simulator.h"
38
39
namespace
ns3 {
40
namespace
dsdv {
45
class
QueueEntry
46
{
47
public
:
48
typedef
Ipv4RoutingProtocol::UnicastForwardCallback
UnicastForwardCallback
;
49
typedef
Ipv4RoutingProtocol::ErrorCallback
ErrorCallback
;
51
QueueEntry
(
Ptr<const Packet>
pa = 0,
Ipv4Header
const
& h =
Ipv4Header
(),
52
UnicastForwardCallback
ucb =
UnicastForwardCallback
(),
53
ErrorCallback
ecb =
ErrorCallback
())
54
:
m_packet
(pa),
55
m_header
(h),
56
m_ucb
(ucb),
57
m_ecb
(ecb),
58
m_expire
(
Seconds
(0))
59
{
60
}
61
66
bool
operator==
(
QueueEntry
const
& o)
const
67
{
68
return
((
m_packet
== o.
m_packet
) && (
m_header
.
GetDestination
() == o.
m_header
.
GetDestination
()) && (
m_expire
== o.
m_expire
));
69
}
71
// \{
72
UnicastForwardCallback
GetUnicastForwardCallback
()
const
73
{
74
return
m_ucb
;
75
}
76
void
SetUnicastForwardCallback
(
UnicastForwardCallback
ucb)
77
{
78
m_ucb
= ucb;
79
}
80
ErrorCallback
GetErrorCallback
()
const
81
{
82
return
m_ecb
;
83
}
84
void
SetErrorCallback
(
ErrorCallback
ecb)
85
{
86
m_ecb
= ecb;
87
}
88
Ptr<const Packet>
GetPacket
()
const
89
{
90
return
m_packet
;
91
}
92
void
SetPacket
(
Ptr<const Packet>
p)
93
{
94
m_packet
= p;
95
}
96
Ipv4Header
GetIpv4Header
()
const
97
{
98
return
m_header
;
99
}
100
void
SetIpv4Header
(
Ipv4Header
h)
101
{
102
m_header
= h;
103
}
104
void
SetExpireTime
(
Time
exp)
105
{
106
m_expire
= exp +
Simulator::Now
();
107
}
108
Time
GetExpireTime
()
const
109
{
110
return
m_expire
-
Simulator::Now
();
111
}
112
// \}
113
private
:
115
Ptr<const Packet>
m_packet
;
117
Ipv4Header
m_header
;
119
UnicastForwardCallback
m_ucb
;
121
ErrorCallback
m_ecb
;
123
Time
m_expire
;
124
};
133
class
PacketQueue
134
{
135
public
:
137
PacketQueue
()
138
{
139
}
141
bool
Enqueue
(
QueueEntry
& entry);
143
bool
Dequeue
(
Ipv4Address
dst,
QueueEntry
& entry);
145
void
DropPacketWithDst
(
Ipv4Address
dst);
147
bool
Find
(
Ipv4Address
dst);
149
uint32_t
150
GetCountForPacketsWithDst
(
Ipv4Address
dst);
152
uint32_t
GetSize
();
154
// \{
155
uint32_t
GetMaxQueueLen
()
const
156
{
157
return
m_maxLen
;
158
}
159
void
SetMaxQueueLen
(uint32_t len)
160
{
161
m_maxLen
= len;
162
}
163
uint32_t
GetMaxPacketsPerDst
()
const
164
{
165
return
m_maxLenPerDst
;
166
}
167
void
SetMaxPacketsPerDst
(uint32_t len)
168
{
169
m_maxLenPerDst
= len;
170
}
171
Time
GetQueueTimeout
()
const
172
{
173
return
m_queueTimeout
;
174
}
175
void
SetQueueTimeout
(
Time
t)
176
{
177
m_queueTimeout
= t;
178
}
179
// \}
180
181
private
:
182
std::vector<QueueEntry>
m_queue
;
184
void
Purge
();
186
void
Drop
(
QueueEntry
en, std::string reason);
188
uint32_t
m_maxLen
;
190
uint32_t
m_maxLenPerDst
;
192
Time
m_queueTimeout
;
193
static
bool
IsEqual
(
QueueEntry
en,
const
Ipv4Address
dst)
194
{
195
return
(en.
GetIpv4Header
().
GetDestination
() == dst);
196
}
197
};
198
}
199
}
200
#endif
/* DSDV_PACKETQUEUE_H */
src
dsdv
model
dsdv-packet-queue.h
Generated on Tue Oct 9 2012 16:45:36 for ns-3 by
1.8.1.2