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-errorbuff.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_ERRORBUFF_H
33
#define DSR_ERRORBUFF_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
ErrorBuffEntry
46
{
47
public
:
48
// / c-tor
49
ErrorBuffEntry
(
Ptr<const Packet>
pa = 0,
Ipv4Address
d =
Ipv4Address
(),
Ipv4Address
s =
Ipv4Address
(),
50
Ipv4Address
n =
Ipv4Address
(),
Time
exp =
Simulator::Now
(), uint8_t p = 0)
51
: m_packet (pa),
52
m_dst (d),
53
m_source (s),
54
m_nextHop (n),
55
m_expire (exp +
Simulator::Now
()),
56
m_protocol (p)
57
{
58
}
63
bool
operator==
(
ErrorBuffEntry
const
& o)
const
64
{
65
return
((m_packet == o.m_packet) && (m_source == o.m_source) && (m_nextHop == o.m_nextHop) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
66
}
67
// /\name Fields
68
// \{
69
Ptr<const Packet>
GetPacket ()
const
70
{
71
return
m_packet;
72
}
73
void
SetPacket (
Ptr<const Packet>
p)
74
{
75
m_packet = p;
76
}
77
Ipv4Address GetDestination ()
const
78
{
79
return
m_dst;
80
}
81
void
SetDestination (Ipv4Address d)
82
{
83
m_dst = d;
84
}
85
Ipv4Address GetSource ()
const
86
{
87
return
m_source;
88
}
89
void
SetSource (Ipv4Address s)
90
{
91
m_source = s;
92
}
93
Ipv4Address GetNextHop ()
const
94
{
95
return
m_nextHop;
96
}
97
void
SetNextHop (Ipv4Address n)
98
{
99
m_nextHop = n;
100
}
101
void
SetExpireTime (Time exp)
102
{
103
m_expire = exp +
Simulator::Now
();
104
}
105
Time GetExpireTime ()
const
106
{
107
return
m_expire -
Simulator::Now
();
108
}
109
void
SetProtocol (uint8_t p)
110
{
111
m_protocol = p;
112
}
113
uint8_t GetProtocol ()
const
114
{
115
return
m_protocol;
116
}
117
// \}
118
private
:
119
// / Data packet
120
Ptr<const Packet> m_packet;
121
// / Destination address
122
Ipv4Address m_dst;
123
// / Source address
124
Ipv4Address m_source;
125
// / Nexthop address
126
Ipv4Address m_nextHop;
127
// / Expire time for queue entry
128
Time m_expire;
129
// / The protocol number
130
uint8_t m_protocol;
131
};
132
137
/************************************************************************************************************************/
138
class
ErrorBuffer
139
{
140
public
:
141
// / Default c-tor
142
ErrorBuffer
()
143
{
144
}
145
// / Push entry in queue, if there is no entry with the same packet and destination address in queue.
146
bool
Enqueue
(
ErrorBuffEntry
& entry);
147
// / Return first found (the earliest) entry for given destination
148
bool
Dequeue (
Ipv4Address
dst,
ErrorBuffEntry
& entry);
149
// / Remove all packets with the error link
150
void
DropPacketForErrLink (
Ipv4Address
source,
Ipv4Address
nextHop);
151
// / Finds whether a packet with destination dst exists in the queue
152
bool
Find (
Ipv4Address
dst);
153
// / Number of entries
154
uint32_t GetSize ();
155
// /\name Fields
156
// \{
157
uint32_t GetMaxQueueLen ()
const
158
{
159
return
m_maxLen;
160
}
161
void
SetMaxQueueLen (uint32_t len)
162
{
163
m_maxLen = len;
164
}
165
Time
GetErrorBufferTimeout ()
const
166
{
167
return
m_errorBufferTimeout;
168
}
169
void
SetErrorBufferTimeout (
Time
t)
170
{
171
m_errorBufferTimeout = t;
172
}
173
// \}
174
175
std::vector<ErrorBuffEntry> & GetBuffer ()
176
{
177
return
m_errorBuffer;
178
}
179
180
private
:
181
// / The send buffer to cache unsent packet
182
std::vector<ErrorBuffEntry> m_errorBuffer;
183
// / Remove all expired entries
184
void
Purge ();
185
// / Notify that packet is dropped from queue by timeout
186
void
Drop (
ErrorBuffEntry
en, std::string reason);
187
// / Notify that packet is dropped from queue by timeout
188
void
DropLink (
ErrorBuffEntry
en, std::string reason);
189
// / The maximum number of packets that we allow a routing protocol to buffer.
190
uint32_t m_maxLen;
191
// / The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
192
Time
m_errorBufferTimeout;
193
// / Check if the send buffer entry is the same or not
194
static
bool
LinkEqual (
ErrorBuffEntry
en,
const
std::vector<Ipv4Address> link)
195
{
196
return
((en.GetSource () == link[0]) && (en.GetNextHop () == link[1]));
197
}
198
};
199
/*******************************************************************************************************************************/
200
}
// namespace dsr
201
}
// namespace ns3
202
203
#endif
/* DSR_ERRORBUFF_H */
ns3::Time
keep track of time unit.
Definition:
nstime.h:149
ns3::Ptr< const Packet >
ns3::dsr::ErrorBuffer::Enqueue
bool Enqueue(ErrorBuffEntry &entry)
Definition:
dsr-errorbuff.cc:52
ns3::dsr::ErrorBuffEntry::operator==
bool operator==(ErrorBuffEntry const &o) const
Definition:
dsr-errorbuff.h:63
ns3::dsr::ErrorBuffEntry
DSR Error Buffer Entry.
Definition:
dsr-errorbuff.h:45
ns3::Simulator::Now
static Time Now(void)
Definition:
simulator.cc:179
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:38
ns3::dsr::ErrorBuffer
DSR error buffer.
Definition:
dsr-errorbuff.h:138
src
dsr
model
dsr-errorbuff.h
Generated on Sun Mar 16 2014 11:25:03 for ns-3 by
1.8.6