A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bridge-channel.cc
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 TypeId
29 BridgeChannel::GetTypeId (void)
30 {
31  static TypeId tid = TypeId ("ns3::BridgeChannel")
32  .SetParent<Channel> ()
33  .AddConstructor<BridgeChannel> ()
34  ;
35  return tid;
36 }
37 
38 BridgeChannel::BridgeChannel ()
39  : Channel ()
40 {
42 }
43 
44 BridgeChannel::~BridgeChannel ()
45 {
47 
48  for (std::vector< Ptr<Channel> >::iterator iter = m_bridgedChannels.begin ();
49  iter != m_bridgedChannels.end (); iter++)
50  {
51  *iter = 0;
52  }
53  m_bridgedChannels.clear ();
54 }
55 
56 
57 void
58 BridgeChannel::AddChannel (Ptr<Channel> bridgedChannel)
59 {
60  m_bridgedChannels.push_back (bridgedChannel);
61 }
62 
63 uint32_t
65 {
66  uint32_t ndevices = 0;
67  for (std::vector< Ptr<Channel> >::const_iterator iter = m_bridgedChannels.begin ();
68  iter != m_bridgedChannels.end (); iter++)
69  {
70  ndevices += (*iter)->GetNDevices ();
71  }
72  return ndevices;
73 }
74 
75 
77 BridgeChannel::GetDevice (uint32_t i) const
78 {
79  uint32_t ndevices = 0;
80  for (std::vector< Ptr<Channel> >::const_iterator iter = m_bridgedChannels.begin ();
81  iter != m_bridgedChannels.end (); iter++)
82  {
83  if ((i - ndevices) < (*iter)->GetNDevices ())
84  {
85  return (*iter)->GetDevice (i - ndevices);
86  }
87  ndevices += (*iter)->GetNDevices ();
88  }
89  return NULL;
90 }
91 
92 
93 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
virtual uint32_t GetNDevices(void) const
virtual Ptr< NetDevice > GetDevice(uint32_t i) const