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
error-channel.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2011 Universita' di Firenze, Italy
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: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19
*/
20
#include "
error-channel.h
"
21
#include "
error-net-device.h
"
22
#include "ns3/simulator.h"
23
#include "ns3/packet.h"
24
#include "ns3/node.h"
25
#include "ns3/log.h"
26
27
NS_LOG_COMPONENT_DEFINE
(
"ErrorChannel"
);
28
29
namespace
ns3 {
30
31
NS_OBJECT_ENSURE_REGISTERED
(ErrorChannel);
32
33
TypeId
34
ErrorChannel::GetTypeId
(
void
)
35
{
36
static
TypeId
tid =
TypeId
(
"ns3::ErrorChannel"
)
37
.
SetParent
<
Channel
> ()
38
.AddConstructor<ErrorChannel> ()
39
;
40
return
tid;
41
}
42
43
ErrorChannel::ErrorChannel
()
44
{
45
jumping
=
false
;
46
jumpingState
= 0;
47
}
48
49
void
50
ErrorChannel::SetJumpingTime
(
Time
delay)
51
{
52
jumpingTime
= delay;
53
}
54
55
void
56
ErrorChannel::SetJumpingMode
(
bool
mode)
57
{
58
jumping
= mode;
59
jumpingState
= 0;
60
}
61
62
void
63
ErrorChannel::Send
(
Ptr<Packet>
p, uint16_t protocol,
64
Mac48Address
to,
Mac48Address
from,
65
Ptr<ErrorNetDevice>
sender)
66
{
67
NS_LOG_FUNCTION
(p << protocol << to << from << sender);
68
for
(std::vector<
Ptr<ErrorNetDevice>
>::const_iterator i =
m_devices
.begin (); i !=
m_devices
.end (); ++i)
69
{
70
Ptr<ErrorNetDevice>
tmp = *i;
71
if
(tmp == sender)
72
{
73
continue
;
74
}
75
if
( !
jumping
||
jumpingState
%2 )
76
{
77
Simulator::ScheduleWithContext
(tmp->
GetNode
()->
GetId
(),
Seconds
(0),
78
&
ErrorNetDevice::Receive
, tmp, p->
Copy
(), protocol, to, from);
79
jumpingState
++;
80
}
81
else
82
{
83
Simulator::ScheduleWithContext
(tmp->
GetNode
()->
GetId
(),
jumpingTime
,
84
&
ErrorNetDevice::Receive
, tmp, p->
Copy
(), protocol, to, from);
85
jumpingState
++;
86
}
87
}
88
}
89
90
void
91
ErrorChannel::Add
(
Ptr<ErrorNetDevice>
device)
92
{
93
m_devices
.push_back (device);
94
}
95
96
uint32_t
97
ErrorChannel::GetNDevices
(
void
)
const
98
{
99
return
m_devices
.size ();
100
}
101
Ptr<NetDevice>
102
ErrorChannel::GetDevice
(uint32_t i)
const
103
{
104
return
m_devices
[i];
105
}
106
107
NS_OBJECT_ENSURE_REGISTERED
(
ErrorModel
);
108
109
TypeId
BinaryErrorModel::GetTypeId
(
void
)
110
{
111
static
TypeId
tid =
TypeId
(
"ns3::BinaryErrorModel"
)
112
.
SetParent
<
ErrorModel
> ()
113
.AddConstructor<BinaryErrorModel> ()
114
;
115
return
tid;
116
}
117
118
BinaryErrorModel::BinaryErrorModel
()
119
{
120
counter
= 0;
121
}
122
123
BinaryErrorModel::~BinaryErrorModel
()
124
{
125
}
126
127
128
bool
129
BinaryErrorModel::DoCorrupt
(
Ptr<Packet>
p)
130
{
131
if
(!
IsEnabled
())
132
{
133
return
false
;
134
}
135
bool
ret =
counter
%2;
136
counter
++;
137
return
ret;
138
}
139
140
void
141
BinaryErrorModel::Reset
(
void
)
142
{
143
DoReset
();
144
}
145
146
void
147
BinaryErrorModel::DoReset
(
void
)
148
{
149
counter
= 0;
150
}
151
152
153
}
// namespace ns3
src
internet
test
error-channel.cc
Generated on Tue May 14 2013 11:08:23 for ns-3 by
1.8.1.2