A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
simple-channel.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#include "simple-channel.h"
9
10#include "simple-net-device.h"
11
12#include "ns3/log.h"
13#include "ns3/node.h"
14#include "ns3/packet.h"
15#include "ns3/simulator.h"
16
17#include <algorithm>
18
19namespace ns3
20{
21
22NS_LOG_COMPONENT_DEFINE("SimpleChannel");
23
24NS_OBJECT_ENSURE_REGISTERED(SimpleChannel);
25
26TypeId
28{
29 static TypeId tid = TypeId("ns3::SimpleChannel")
31 .SetGroupName("Network")
32 .AddConstructor<SimpleChannel>()
33 .AddAttribute("Delay",
34 "Transmission delay through the channel",
38 return tid;
39}
40
45
46void
48 uint16_t protocol,
49 Mac48Address to,
50 Mac48Address from,
52{
53 NS_LOG_FUNCTION(this << p << protocol << to << from << sender);
54 for (auto i = m_devices.begin(); i != m_devices.end(); ++i)
55 {
56 Ptr<SimpleNetDevice> tmp = *i;
57 if (tmp == sender)
58 {
59 continue;
60 }
61 if (m_blackListedDevices.find(tmp) != m_blackListedDevices.end())
62 {
63 if (find(m_blackListedDevices[tmp].begin(), m_blackListedDevices[tmp].end(), sender) !=
64 m_blackListedDevices[tmp].end())
65 {
66 continue;
67 }
68 }
69 Simulator::ScheduleWithContext(tmp->GetNode()->GetId(),
70 m_delay,
72 tmp,
73 p->Copy(),
74 protocol,
75 to,
76 from);
77 }
78}
79
80void
82{
83 NS_LOG_FUNCTION(this << device);
84 m_devices.push_back(device);
85}
86
87std::size_t
89{
90 NS_LOG_FUNCTION(this);
91 return m_devices.size();
92}
93
95SimpleChannel::GetDevice(std::size_t i) const
96{
97 NS_LOG_FUNCTION(this << i);
98 return m_devices[i];
99}
100
101void
103{
104 if (m_blackListedDevices.find(to) != m_blackListedDevices.end())
105 {
106 if (find(m_blackListedDevices[to].begin(), m_blackListedDevices[to].end(), from) ==
107 m_blackListedDevices[to].end())
108 {
109 m_blackListedDevices[to].push_back(from);
110 }
111 }
112 else
113 {
114 m_blackListedDevices[to].push_back(from);
115 }
116}
117
118void
120{
121 if (m_blackListedDevices.find(to) != m_blackListedDevices.end())
122 {
123 auto iter = find(m_blackListedDevices[to].begin(), m_blackListedDevices[to].end(), from);
124 if (iter != m_blackListedDevices[to].end())
125 {
126 m_blackListedDevices[to].erase(iter);
127 }
128 }
129}
130
131} // namespace ns3
Abstract Channel Base Class.
Definition channel.h:34
an EUI-48 address
Smart pointer class similar to boost::intrusive_ptr.
A simple channel, for simple things and testing.
virtual void BlackList(Ptr< SimpleNetDevice > from, Ptr< SimpleNetDevice > to)
Blocks the communications from a NetDevice to another NetDevice.
std::vector< Ptr< SimpleNetDevice > > m_devices
devices connected by the channel
Ptr< NetDevice > GetDevice(std::size_t i) const override
std::map< Ptr< SimpleNetDevice >, std::vector< Ptr< SimpleNetDevice > > > m_blackListedDevices
devices blocked on a device
static TypeId GetTypeId()
Get the type ID.
virtual void Add(Ptr< SimpleNetDevice > device)
Attached a net device to the channel.
Time m_delay
The assigned speed-of-light delay of the channel.
std::size_t GetNDevices() const override
virtual void UnBlackList(Ptr< SimpleNetDevice > from, Ptr< SimpleNetDevice > to)
Un-Blocks the communications from a NetDevice to another NetDevice.
virtual void Send(Ptr< Packet > p, uint16_t protocol, Mac48Address to, Mac48Address from, Ptr< SimpleNetDevice > sender)
A packet is sent by a net device.
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
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.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1396
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416