A Discrete-Event Network Simulator
API
openflow-switch-helper.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Blake Hurd
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Blake Hurd <naimorai@gmail.com>
18  */
19 #ifdef NS3_OPENFLOW
20 
21 #include "openflow-switch-helper.h"
22 
23 #include "ns3/log.h"
24 #include "ns3/names.h"
25 #include "ns3/node.h"
26 #include "ns3/openflow-interface.h"
27 #include "ns3/openflow-switch-net-device.h"
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("OpenFlowSwitchHelper");
33 
35 {
37  m_deviceFactory.SetTypeId("ns3::OpenFlowSwitchNetDevice");
38 }
39 
40 void
41 OpenFlowSwitchHelper::SetDeviceAttribute(std::string n1, const AttributeValue& v1)
42 {
44  m_deviceFactory.Set(n1, v1);
45 }
46 
47 NetDeviceContainer
48 OpenFlowSwitchHelper::Install(Ptr<Node> node,
49  NetDeviceContainer c,
50  Ptr<ns3::ofi::Controller> controller)
51 {
53  NS_LOG_INFO("**** Install switch device on node " << node->GetId());
54 
55  NetDeviceContainer devs;
56  Ptr<OpenFlowSwitchNetDevice> dev = m_deviceFactory.Create<OpenFlowSwitchNetDevice>();
57  devs.Add(dev);
58  node->AddDevice(dev);
59 
60  NS_LOG_INFO("**** Set up Controller");
61  dev->SetController(controller);
62 
63  for (NetDeviceContainer::Iterator i = c.Begin(); i != c.End(); ++i)
64  {
65  NS_LOG_INFO("**** Add SwitchPort " << *i);
66  dev->AddSwitchPort(*i);
67  }
68  return devs;
69 }
70 
71 NetDeviceContainer
72 OpenFlowSwitchHelper::Install(Ptr<Node> node, NetDeviceContainer c)
73 {
75  NS_LOG_INFO("**** Install switch device on node " << node->GetId());
76 
77  NetDeviceContainer devs;
78  Ptr<OpenFlowSwitchNetDevice> dev = m_deviceFactory.Create<OpenFlowSwitchNetDevice>();
79  devs.Add(dev);
80  node->AddDevice(dev);
81 
82  for (NetDeviceContainer::Iterator i = c.Begin(); i != c.End(); ++i)
83  {
84  NS_LOG_INFO("**** Add SwitchPort " << *i);
85  dev->AddSwitchPort(*i);
86  }
87  return devs;
88 }
89 
90 NetDeviceContainer
91 OpenFlowSwitchHelper::Install(std::string nodeName, NetDeviceContainer c)
92 {
94  Ptr<Node> node = Names::Find<Node>(nodeName);
95  return Install(node, c);
96 }
97 
98 } // namespace ns3
99 
100 #endif // NS3_OPENFLOW
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c, Ptr< ns3::ofi::Controller > controller)
This method creates an ns3::OpenFlowSwitchNetDevice with the attributes configured by OpenFlowSwitchH...
ObjectFactory m_deviceFactory
Object factory.
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Set an attribute on each ns3::OpenFlowSwitchNetDevice created by OpenFlowSwitchHelper::Install.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Every class exported by the ns3 library is enclosed in the ns3 namespace.