A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
bridge-channel.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Author: Gustavo Carneiro <gjc@inescporto.pt>
17  */
18 
19 #include "ns3/log.h"
20 #include "bridge-channel.h"
21 
22 NS_LOG_COMPONENT_DEFINE ("BridgeChannel");
23 
24 namespace ns3 {
25 
26 NS_OBJECT_ENSURE_REGISTERED (BridgeChannel)
27  ;
28 
29 TypeId
31 {
32  static TypeId tid = TypeId ("ns3::BridgeChannel")
33  .SetParent<Channel> ()
34  .AddConstructor<BridgeChannel> ()
35  ;
36  return tid;
37 }
38 
40  : Channel ()
41 {
43 }
44 
46 {
48 
49  for (std::vector< Ptr<Channel> >::iterator iter = m_bridgedChannels.begin ();
50  iter != m_bridgedChannels.end (); iter++)
51  {
52  *iter = 0;
53  }
54  m_bridgedChannels.clear ();
55 }
56 
57 
58 void
60 {
61  m_bridgedChannels.push_back (bridgedChannel);
62 }
63 
64 uint32_t
66 {
67  uint32_t ndevices = 0;
68  for (std::vector< Ptr<Channel> >::const_iterator iter = m_bridgedChannels.begin ();
69  iter != m_bridgedChannels.end (); iter++)
70  {
71  ndevices += (*iter)->GetNDevices ();
72  }
73  return ndevices;
74 }
75 
76 
78 BridgeChannel::GetDevice (uint32_t i) const
79 {
80  uint32_t ndevices = 0;
81  for (std::vector< Ptr<Channel> >::const_iterator iter = m_bridgedChannels.begin ();
82  iter != m_bridgedChannels.end (); iter++)
83  {
84  if ((i - ndevices) < (*iter)->GetNDevices ())
85  {
86  return (*iter)->GetDevice (i - ndevices);
87  }
88  ndevices += (*iter)->GetNDevices ();
89  }
90  return NULL;
91 }
92 
93 
94 } // namespace ns3
void AddChannel(Ptr< Channel > bridgedChannel)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
Abstract Channel Base Class.
Definition: channel.h:43
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
static TypeId GetTypeId(void)
NS_LOG_COMPONENT_DEFINE("BridgeChannel")
std::vector< Ptr< Channel > > m_bridgedChannels
virtual ~BridgeChannel()
virtual uint32_t GetNDevices(void) const
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
virtual Ptr< NetDevice > GetDevice(uint32_t i) const