A Discrete-Event Network Simulator
API
openflow-switch-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Blake Hurd
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  * Author: Blake Hurd <naimorai@gmail.com>
19  */
20 #ifdef NS3_OPENFLOW
21 
22 #include "openflow-switch-helper.h"
23 #include "ns3/log.h"
24 #include "ns3/openflow-switch-net-device.h"
25 #include "ns3/openflow-interface.h"
26 #include "ns3/node.h"
27 #include "ns3/names.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("OpenFlowSwitchHelper");
32 
34 {
36  m_deviceFactory.SetTypeId ("ns3::OpenFlowSwitchNetDevice");
37 }
38 
39 void
40 OpenFlowSwitchHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
41 {
43  m_deviceFactory.Set (n1, v1);
44 }
45 
46 NetDeviceContainer
47 OpenFlowSwitchHelper::Install (Ptr<Node> node, NetDeviceContainer c, Ptr<ns3::ofi::Controller> controller)
48 {
50  NS_LOG_INFO ("**** Install switch device on node " << node->GetId ());
51 
52  NetDeviceContainer devs;
53  Ptr<OpenFlowSwitchNetDevice> dev = m_deviceFactory.Create<OpenFlowSwitchNetDevice> ();
54  devs.Add (dev);
55  node->AddDevice (dev);
56 
57  NS_LOG_INFO ("**** Set up Controller");
58  dev->SetController (controller);
59 
60  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
61  {
62  NS_LOG_INFO ("**** Add SwitchPort " << *i);
63  dev->AddSwitchPort (*i);
64  }
65  return devs;
66 }
67 
68 NetDeviceContainer
69 OpenFlowSwitchHelper::Install (Ptr<Node> node, NetDeviceContainer c)
70 {
72  NS_LOG_INFO ("**** Install switch device on node " << node->GetId ());
73 
74  NetDeviceContainer devs;
75  Ptr<OpenFlowSwitchNetDevice> dev = m_deviceFactory.Create<OpenFlowSwitchNetDevice> ();
76  devs.Add (dev);
77  node->AddDevice (dev);
78 
79  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
80  {
81  NS_LOG_INFO ("**** Add SwitchPort " << *i);
82  dev->AddSwitchPort (*i);
83  }
84  return devs;
85 }
86 
87 NetDeviceContainer
88 OpenFlowSwitchHelper::Install (std::string nodeName, NetDeviceContainer c)
89 {
91  Ptr<Node> node = Names::Find<Node> (nodeName);
92  return Install (node, c);
93 }
94 
95 } // namespace ns3
96 
97 #endif // NS3_OPENFLOW
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:201
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c, Ptr< ns3::ofi::Controller > controller)
This method creates an ns3::OpenFlowSwitchNetDevice with the attributes configured by OpenFlowSwitchH...
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
ObjectFactory m_deviceFactory
Object factory.