A Discrete-Event Network Simulator
API
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 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("TapBridgeHelper");
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)
Set an attribute in the underlying TapBridge net device when these devices are automatically created...
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t GetId(void) const
Definition: node.cc:109
Hold a value for an Attribute.
Definition: attribute.h:68
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Hold variables of type enum.
Definition: enum.h:54
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
A bridge to make it appear that a real host process is connected to an ns-3 net device.
Definition: tap-bridge.h:107
TapBridgeHelper()
Construct a TapBridgeHelper to make life easier for people wanting to have their simulations interact...
ObjectFactory m_deviceFactory
Object factory.
ns-3 creates and configures tap device
Definition: tap-bridge.h:122
Every class exported by the ns3 library is enclosed in the ns3 namespace.
AttributeValue implementation for Ipv4Address.
Definition: ipv4-address.h:363
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
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...