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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8
9#include "error-channel.h"
10
11#include "simple-net-device.h"
12
13#include "ns3/log.h"
14#include "ns3/node.h"
15#include "ns3/packet.h"
16#include "ns3/simulator.h"
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("ErrorChannel");
22
23NS_OBJECT_ENSURE_REGISTERED(ErrorChannel);
24
25TypeId
27{
28 static TypeId tid = TypeId("ns3::ErrorChannel")
30 .SetGroupName("Network")
31 .AddConstructor<ErrorChannel>();
32 return tid;
33}
34
36{
38 m_jumping = false;
41 m_duplicate = false;
43}
44
45void
50
51void
53{
54 m_jumping = mode;
56}
57
58void
63
64void
66{
67 m_duplicate = mode;
69}
70
71void
73 uint16_t protocol,
74 Mac48Address to,
75 Mac48Address from,
77{
78 NS_LOG_FUNCTION(p << protocol << to << from << sender);
79 for (auto i = m_devices.begin(); i != m_devices.end(); ++i)
80 {
81 Ptr<SimpleNetDevice> tmp = *i;
82 if (tmp == sender)
83 {
84 continue;
85 }
86 if (m_jumping)
87 {
88 if (m_jumpingState % 2)
89 {
90 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
91 Seconds(0),
93 tmp,
94 p->Copy(),
95 protocol,
96 to,
97 from);
98 }
99 else
100 {
101 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
104 tmp,
105 p->Copy(),
106 protocol,
107 to,
108 from);
109 }
111 }
112 else if (m_duplicate)
113 {
114 if (m_duplicateState % 2)
115 {
116 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
117 Seconds(0),
119 tmp,
120 p->Copy(),
121 protocol,
122 to,
123 from);
124 }
125 else
126 {
127 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
128 Seconds(0),
130 tmp,
131 p->Copy(),
132 protocol,
133 to,
134 from);
135 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
138 tmp,
139 p->Copy(),
140 protocol,
141 to,
142 from);
143 }
145 }
146 else
147 {
148 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
149 Seconds(0),
151 tmp,
152 p->Copy(),
153 protocol,
154 to,
155 from);
156 }
157 }
158}
159
160void
162{
163 m_devices.push_back(device);
164}
165
166std::size_t
168{
169 return m_devices.size();
170}
171
173ErrorChannel::GetDevice(std::size_t i) const
174{
175 return m_devices[i];
176}
177
178} // namespace ns3
A Error channel, introducing deterministic delays on even/odd packets.
Time m_duplicateTime
Duplicate time in Duplicate mode.
uint8_t m_duplicateState
Counter for even/odd packets in Duplicate mode.
static TypeId GetTypeId()
Get the type ID.
std::size_t GetNDevices() const override
bool m_jumping
Flag for Jumping mode.
std::vector< Ptr< SimpleNetDevice > > m_devices
devices connected by the channel
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.
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.
bool m_duplicate
Flag for Duplicate mode.
an EUI-48 address
Smart pointer class similar to boost::intrusive_ptr.
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:577
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.