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
ns3::BinaryErrorModel::DoCorrupt
virtual bool DoCorrupt(Ptr< Packet > p)
Definition:
error-channel.cc:129
ns3::Time
keep track of time values and allow control of global simulation resolution
Definition:
nstime.h:81
ns3::Ptr< Packet >
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:311
ns3::ErrorChannel::ErrorChannel
ErrorChannel()
Definition:
error-channel.cc:43
ns3::ErrorNetDevice::Receive
void Receive(Ptr< Packet > packet, uint16_t protocol, Mac48Address to, Mac48Address from)
Definition:
error-net-device.cc:61
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Definition:
log.h:122
ns3::Channel
Abstract Channel Base Class.
Definition:
channel.h:43
ns3::BinaryErrorModel::Reset
void Reset(void)
Definition:
error-channel.cc:141
ns3::BinaryErrorModel::GetTypeId
static TypeId GetTypeId(void)
Definition:
error-channel.cc:109
ns3::ErrorChannel::jumping
bool jumping
Definition:
error-channel.h:69
ns3::ErrorModel
General error model that can be used to corrupt packets.
Definition:
error-model.h:115
ns3::BinaryErrorModel::~BinaryErrorModel
virtual ~BinaryErrorModel()
Definition:
error-channel.cc:123
ns3::BinaryErrorModel::DoReset
virtual void DoReset(void)
Definition:
error-channel.cc:147
ns3::ErrorChannel::jumpingTime
Time jumpingTime
Definition:
error-channel.h:67
ns3::ErrorModel::IsEnabled
bool IsEnabled(void) const
Definition:
error-model.cc:138
ns3::ErrorChannel::m_devices
std::vector< Ptr< ErrorNetDevice > > m_devices
Definition:
error-channel.h:66
ns3::ErrorChannel::GetTypeId
static TypeId GetTypeId(void)
Definition:
error-channel.cc:34
ns3::ErrorChannel::Send
void Send(Ptr< Packet > p, uint16_t protocol, Mac48Address to, Mac48Address from, Ptr< ErrorNetDevice > sender)
Definition:
error-channel.cc:63
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
ns3::Simulator::ScheduleWithContext
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Definition:
simulator.h:904
ns3::ErrorChannel::SetJumpingMode
void SetJumpingMode(bool mode)
Set if the odd packets are delayed (even ones are not delayed ever)
Definition:
error-channel.cc:56
ns3::Packet::Copy
Ptr< Packet > Copy(void) const
Definition:
packet.cc:122
ns3::BinaryErrorModel::counter
uint8_t counter
Definition:
error-channel.h:86
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:41
ns3::ErrorChannel::Add
void Add(Ptr< ErrorNetDevice > device)
Definition:
error-channel.cc:91
ns3::ErrorChannel::jumpingState
uint8_t jumpingState
Definition:
error-channel.h:68
ns3::ErrorChannel::SetJumpingTime
void SetJumpingTime(Time delay)
Set the delay for the odd packets (even ones are not delayed)
Definition:
error-channel.cc:50
ns3::ErrorChannel::GetNDevices
virtual uint32_t GetNDevices(void) const
Definition:
error-channel.cc:97
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
error-channel.h
ns3::BinaryErrorModel::BinaryErrorModel
BinaryErrorModel()
Definition:
error-channel.cc:118
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:610
error-net-device.h
ns3::ErrorChannel::GetDevice
virtual Ptr< NetDevice > GetDevice(uint32_t i) const
Definition:
error-channel.cc:102
src
internet
test
error-channel.cc
Generated on Sat Nov 16 2013 16:17:43 for ns-3 by
1.8.5