00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * This program is free software; you can redistribute it and/or modify 00004 * it under the terms of the GNU General Public License version 2 as 00005 * published by the Free Software Foundation; 00006 * 00007 * This program is distributed in the hope that it will be useful, 00008 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00010 * GNU General Public License for more details. 00011 * 00012 * You should have received a copy of the GNU General Public License 00013 * along with this program; if not, write to the Free Software 00014 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00015 * 00016 * Author: Gustavo Carneiro <gjc@inescporto.pt> 00017 */ 00018 00019 #include "ns3/log.h" 00020 #include "bridge-channel.h" 00021 00022 NS_LOG_COMPONENT_DEFINE ("BridgeChannel"); 00023 00024 namespace ns3 { 00025 00026 NS_OBJECT_ENSURE_REGISTERED (BridgeChannel); 00027 00028 TypeId 00029 BridgeChannel::GetTypeId (void) 00030 { 00031 static TypeId tid = TypeId ("ns3::BridgeChannel") 00032 .SetParent<Channel> (); 00033 return tid; 00034 } 00035 00036 BridgeChannel::BridgeChannel () 00037 : Channel ("BridgeChannel") 00038 { 00039 NS_LOG_FUNCTION_NOARGS (); 00040 } 00041 00042 BridgeChannel::~BridgeChannel () 00043 { 00044 NS_LOG_FUNCTION_NOARGS (); 00045 } 00046 00047 void 00048 BridgeChannel::AddChannel (Ptr<Channel> bridgedChannel) 00049 { 00050 m_bridgedChannels.push_back (bridgedChannel); 00051 } 00052 00053 uint32_t 00054 BridgeChannel::GetNDevices (void) const 00055 { 00056 uint32_t ndevices = 0; 00057 for (std::vector< Ptr<Channel> >::const_iterator iter = m_bridgedChannels.begin (); 00058 iter != m_bridgedChannels.end (); iter++) 00059 { 00060 ndevices += (*iter)->GetNDevices (); 00061 } 00062 return ndevices; 00063 } 00064 00065 00066 Ptr<NetDevice> 00067 BridgeChannel::GetDevice (uint32_t i) const 00068 { 00069 uint32_t ndevices = 0; 00070 for (std::vector< Ptr<Channel> >::const_iterator iter = m_bridgedChannels.begin (); 00071 iter != m_bridgedChannels.end (); iter++) 00072 { 00073 if ((i - ndevices) < (*iter)->GetNDevices ()) 00074 { 00075 return (*iter)->GetDevice (i - ndevices); 00076 } 00077 ndevices += (*iter)->GetNDevices (); 00078 } 00079 return NULL; 00080 } 00081 00082 00083 } // namespace ns3