78 lines
1.6 KiB
C++
78 lines
1.6 KiB
C++
#include "switch-channel.h"
|
|
|
|
#include "ns3/log.h"
|
|
|
|
/**
|
|
* \file
|
|
* \ingroup ethernet
|
|
* ns3::SwitchChannel implementation.
|
|
*/
|
|
|
|
namespace ns3
|
|
{
|
|
|
|
NS_LOG_COMPONENT_DEFINE("SwitchChannel");
|
|
|
|
NS_OBJECT_ENSURE_REGISTERED(SwitchChannel);
|
|
|
|
TypeId
|
|
SwitchChannel::GetTypeId()
|
|
{
|
|
static TypeId tid = TypeId("ns3::SwitchChannel")
|
|
.SetParent<Channel>()
|
|
.SetGroupName("Ethernet")
|
|
.AddConstructor<SwitchChannel>();
|
|
return tid;
|
|
}
|
|
|
|
SwitchChannel::SwitchChannel()
|
|
: Channel()
|
|
{
|
|
NS_LOG_FUNCTION_NOARGS();
|
|
}
|
|
|
|
SwitchChannel::~SwitchChannel()
|
|
{
|
|
NS_LOG_FUNCTION_NOARGS();
|
|
|
|
for (auto iter = m_switchedChannels.begin(); iter != m_switchedChannels.end(); iter++)
|
|
{
|
|
*iter = nullptr;
|
|
}
|
|
m_switchedChannels.clear();
|
|
}
|
|
|
|
void
|
|
SwitchChannel::AddChannel(Ptr<Channel> switchedChannel)
|
|
{
|
|
m_switchedChannels.push_back(switchedChannel);
|
|
}
|
|
|
|
std::size_t
|
|
SwitchChannel::GetNDevices() const
|
|
{
|
|
uint32_t ndevices = 0;
|
|
for (auto iter = m_switchedChannels.begin(); iter != m_switchedChannels.end(); iter++)
|
|
{
|
|
ndevices += (*iter)->GetNDevices();
|
|
}
|
|
return ndevices;
|
|
}
|
|
|
|
Ptr<NetDevice>
|
|
SwitchChannel::GetDevice(std::size_t i) const
|
|
{
|
|
std::size_t ndevices = 0;
|
|
for (auto iter = m_switchedChannels.begin(); iter != m_switchedChannels.end(); iter++)
|
|
{
|
|
if ((i - ndevices) < (*iter)->GetNDevices())
|
|
{
|
|
return (*iter)->GetDevice(i - ndevices);
|
|
}
|
|
ndevices += (*iter)->GetNDevices();
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
} // namespace ns3
|