A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
error-channel.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Universita' di Firenze, Italy
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 */
19
20#include "error-channel.h"
21
22#include "simple-net-device.h"
23
24#include "ns3/log.h"
25#include "ns3/node.h"
26#include "ns3/packet.h"
27#include "ns3/simulator.h"
28
29namespace ns3
30{
31
32NS_LOG_COMPONENT_DEFINE("ErrorChannel");
33
34NS_OBJECT_ENSURE_REGISTERED(ErrorChannel);
35
36TypeId
38{
39 static TypeId tid = TypeId("ns3::ErrorChannel")
41 .SetGroupName("Network")
42 .AddConstructor<ErrorChannel>();
43 return tid;
44}
45
47{
49 m_jumping = false;
52 m_duplicate = false;
54}
55
56void
58{
59 m_jumpingTime = delay;
60}
61
62void
64{
65 m_jumping = mode;
67}
68
69void
71{
72 m_duplicateTime = delay;
73}
74
75void
77{
78 m_duplicate = mode;
80}
81
82void
84 uint16_t protocol,
85 Mac48Address to,
86 Mac48Address from,
88{
89 NS_LOG_FUNCTION(p << protocol << to << from << sender);
90 for (auto i = m_devices.begin(); i != m_devices.end(); ++i)
91 {
92 Ptr<SimpleNetDevice> tmp = *i;
93 if (tmp == sender)
94 {
95 continue;
96 }
97 if (m_jumping)
98 {
99 if (m_jumpingState % 2)
100 {
101 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
102 Seconds(0),
104 tmp,
105 p->Copy(),
106 protocol,
107 to,
108 from);
109 }
110 else
111 {
112 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
115 tmp,
116 p->Copy(),
117 protocol,
118 to,
119 from);
120 }
122 }
123 else if (m_duplicate)
124 {
125 if (m_duplicateState % 2)
126 {
127 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
128 Seconds(0),
130 tmp,
131 p->Copy(),
132 protocol,
133 to,
134 from);
135 }
136 else
137 {
138 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
139 Seconds(0),
141 tmp,
142 p->Copy(),
143 protocol,
144 to,
145 from);
146 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
149 tmp,
150 p->Copy(),
151 protocol,
152 to,
153 from);
154 }
156 }
157 else
158 {
159 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
160 Seconds(0),
162 tmp,
163 p->Copy(),
164 protocol,
165 to,
166 from);
167 }
168 }
169}
170
171void
173{
174 m_devices.push_back(device);
175}
176
177std::size_t
179{
180 return m_devices.size();
181}
182
184ErrorChannel::GetDevice(std::size_t i) const
185{
186 return m_devices[i];
187}
188
189} // namespace ns3
A Error channel, introducing deterministic delays on even/odd packets.
Definition: error-channel.h:42
Time m_duplicateTime
Duplicate time in Duplicate mode.
Definition: error-channel.h:93
uint8_t m_duplicateState
Counter for even/odd packets in Duplicate mode.
Definition: error-channel.h:95
static TypeId GetTypeId()
Get the type ID.
std::size_t GetNDevices() const override
bool m_jumping
Flag for Jumping mode.
Definition: error-channel.h:92
std::vector< Ptr< SimpleNetDevice > > m_devices
devices connected by the channel
Definition: error-channel.h:89
void Send(Ptr< Packet > p, uint16_t protocol, Mac48Address to, Mac48Address from, Ptr< SimpleNetDevice > sender) override
A packet is sent by a net device.
void SetJumpingTime(Time delay)
Set the delay for the odd packets (even ones are not delayed)
void SetJumpingMode(bool mode)
Set if the odd packets are delayed (even ones are not delayed ever)
Ptr< NetDevice > GetDevice(std::size_t i) const override
void SetDuplicateMode(bool mode)
Set if the odd packets are duplicated (even ones are not duplicated ever)
Time m_jumpingTime
Delay time in Jumping mode.
Definition: error-channel.h:90
void Add(Ptr< SimpleNetDevice > device) override
Attached a net device to the channel.
void SetDuplicateTime(Time delay)
Set the delay for the odd duplicate packets (even ones are not duplicated)
uint8_t m_jumpingState
Counter for even/odd packets in Jumping mode.
Definition: error-channel.h:91
bool m_duplicate
Flag for Duplicate mode.
Definition: error-channel.h:94
an EUI-48 address
Definition: mac48-address.h:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
A simple channel, for simple things and testing.
void Receive(Ptr< Packet > packet, uint16_t protocol, Mac48Address to, Mac48Address from)
Receive a packet from a connected SimpleChannel.
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:588
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.