A Discrete-Event Network Simulator
API
bridge-channel.cc
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 *
15 * Author: Gustavo Carneiro <gjc@inescporto.pt>
16 */
17
18#include "bridge-channel.h"
19
20#include "ns3/log.h"
21
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("BridgeChannel");
32
33NS_OBJECT_ENSURE_REGISTERED(BridgeChannel);
34
35TypeId
37{
38 static TypeId tid = TypeId("ns3::BridgeChannel")
40 .SetGroupName("Bridge")
41 .AddConstructor<BridgeChannel>();
42 return tid;
43}
44
46 : Channel()
47{
49}
50
52{
54
55 for (std::vector<Ptr<Channel>>::iterator iter = m_bridgedChannels.begin();
56 iter != m_bridgedChannels.end();
57 iter++)
58 {
59 *iter = nullptr;
60 }
61 m_bridgedChannels.clear();
62}
63
64void
66{
67 m_bridgedChannels.push_back(bridgedChannel);
68}
69
70std::size_t
72{
73 uint32_t ndevices = 0;
74 for (std::vector<Ptr<Channel>>::const_iterator iter = m_bridgedChannels.begin();
75 iter != m_bridgedChannels.end();
76 iter++)
77 {
78 ndevices += (*iter)->GetNDevices();
79 }
80 return ndevices;
81}
82
84BridgeChannel::GetDevice(std::size_t i) const
85{
86 std::size_t ndevices = 0;
87 for (std::vector<Ptr<Channel>>::const_iterator iter = m_bridgedChannels.begin();
88 iter != m_bridgedChannels.end();
89 iter++)
90 {
91 if ((i - ndevices) < (*iter)->GetNDevices())
92 {
93 return (*iter)->GetDevice(i - ndevices);
94 }
95 ndevices += (*iter)->GetNDevices();
96 }
97 return nullptr;
98}
99
100} // namespace ns3
ns3::BridgeChannel declaration.
Virtual channel implementation for bridges (BridgeNetDevice).
~BridgeChannel() override
void AddChannel(Ptr< Channel > bridgedChannel)
Adds a channel to the bridged pool.
static TypeId GetTypeId()
Get the type ID.
std::vector< Ptr< Channel > > m_bridgedChannels
pool of bridged channels
std::size_t GetNDevices() const override
Ptr< NetDevice > GetDevice(std::size_t i) const override
Abstract Channel Base Class.
Definition: channel.h:45
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.