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 
TapBridgeHelper()30 TapBridgeHelper::TapBridgeHelper ()
31 {
32   NS_LOG_FUNCTION_NOARGS ();
33   m_deviceFactory.SetTypeId ("ns3::TapBridge");
34 }
35 
TapBridgeHelper(Ipv4Address gateway)36 TapBridgeHelper::TapBridgeHelper (Ipv4Address gateway)
37 {
38   NS_LOG_FUNCTION_NOARGS ();
39   m_deviceFactory.SetTypeId ("ns3::TapBridge");
40   SetAttribute ("Gateway", Ipv4AddressValue (gateway));
41   SetAttribute ("Mode", EnumValue (TapBridge::CONFIGURE_LOCAL));
42 }
43 
44 void
SetAttribute(std::string n1,const AttributeValue & v1)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 
52 Ptr<NetDevice>
Install(Ptr<Node> node,Ptr<NetDevice> nd,const AttributeValue & v1)53 TapBridgeHelper::Install (Ptr<Node> node, Ptr<NetDevice> nd, const AttributeValue &v1)
54 {
55   NS_LOG_FUNCTION (node << nd << &v1);
56   m_deviceFactory.Set ("DeviceName", v1);
57   return Install (node, nd);
58 }
59 
60 Ptr<NetDevice>
Install(Ptr<Node> node,Ptr<NetDevice> nd)61 TapBridgeHelper::Install (Ptr<Node> node, Ptr<NetDevice> nd)
62 {
63   NS_LOG_FUNCTION (node << nd);
64   NS_LOG_LOGIC ("Install TapBridge on node " << node->GetId () << " bridging net device " << nd);
65 
66   Ptr<TapBridge> bridge = m_deviceFactory.Create<TapBridge> ();
67   node->AddDevice (bridge);
68   bridge->SetBridgedNetDevice (nd);
69 
70   return bridge;
71 }
72 
73 Ptr<NetDevice>
Install(std::string nodeName,Ptr<NetDevice> nd)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 
80 Ptr<NetDevice>
Install(Ptr<Node> node,std::string ndName)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 
87 Ptr<NetDevice>
Install(std::string nodeName,std::string ndName)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
96