A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tap-bridge-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 #include "ns3/log.h"
20 #include "ns3/node.h"
21 #include "ns3/enum.h"
22 #include "ns3/tap-bridge.h"
23 #include "ns3/names.h"
24 #include "tap-bridge-helper.h"
25 
26 NS_LOG_COMPONENT_DEFINE ("TapBridgeHelper");
27 
28 namespace ns3 {
29 
31 {
33  m_deviceFactory.SetTypeId ("ns3::TapBridge");
34 }
35 
37 {
39  m_deviceFactory.SetTypeId ("ns3::TapBridge");
40  SetAttribute ("Gateway", Ipv4AddressValue (gateway));
42 }
43 
44 void
45 TapBridgeHelper::SetAttribute (std::string n1, const AttributeValue &v1)
46 {
47  NS_LOG_FUNCTION (n1 << &v1);
48  m_deviceFactory.Set (n1, v1);
49 }
50 
51 
54 {
55  NS_LOG_FUNCTION (node << nd << &v1);
56  m_deviceFactory.Set ("DeviceName", v1);
57  return Install (node, nd);
58 }
59 
62 {
63  NS_LOG_FUNCTION (node << nd);
64  NS_LOG_LOGIC ("Install TapBridge on node " << node->GetId () << " bridging net device " << nd);
65 
67  node->AddDevice (bridge);
68  bridge->SetBridgedNetDevice (nd);
69 
70  return bridge;
71 }
72 
74 TapBridgeHelper::Install (std::string nodeName, Ptr<NetDevice> nd)
75 {
76  Ptr<Node> node = Names::Find<Node> (nodeName);
77  return Install (node, nd);
78 }
79 
81 TapBridgeHelper::Install (Ptr<Node> node, std::string ndName)
82 {
83  Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
84  return Install (node, nd);
85 }
86 
88 TapBridgeHelper::Install (std::string nodeName, std::string ndName)
89 {
90  Ptr<Node> node = Names::Find<Node> (nodeName);
91  Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
92  return Install (node, nd);
93 }
94 
95 } // namespace ns3
void SetAttribute(std::string n1, const AttributeValue &v1)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
Hold a value for an Attribute.
Definition: attribute.h:56
void SetTypeId(TypeId tid)
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
hold variables of type 'enum'
Definition: enum.h:37
Ptr< Object > Create(void) const
A bridge to make it appear that a real host process is connected to an ns-3 net device.
Definition: tap-bridge.h:103
TapBridgeHelper()
Construct a TapBridgeHelper to make life easier for people wanting to have their simulations interact...
NS_LOG_COMPONENT_DEFINE("TapBridgeHelper")
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
ObjectFactory m_deviceFactory
ns-3 creates and configures tap device
Definition: tap-bridge.h:114
void Set(std::string name, const AttributeValue &value)
hold objects of type ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:118
uint32_t GetId(void) const
Definition: node.cc:104
Ptr< NetDevice > Install(Ptr< Node > node, Ptr< NetDevice > nd)
This method installs a TapBridge on the specified Node and forms the bridge with the NetDevice specif...