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 
20 #include "openflow-switch-helper.h"
21 
22 #include "ns3/log.h"
23 #include "ns3/names.h"
24 #include "ns3/node.h"
25 #include "ns3/openflow-interface.h"
26 #include "ns3/openflow-switch-net-device.h"
27 
28 namespace ns3
29 {
30 
31 NS_LOG_COMPONENT_DEFINE("OpenFlowSwitchHelper");
32 
34 {
36  m_deviceFactory.SetTypeId("ns3::OpenFlowSwitchNetDevice");
37 }
38 
39 void
41 {
43  m_deviceFactory.Set(n1, v1);
44 }
45 
50 {
52  NS_LOG_INFO("**** Install switch device on node " << node->GetId());
53 
54  NetDeviceContainer devs;
56  devs.Add(dev);
57  node->AddDevice(dev);
58 
59  NS_LOG_INFO("**** Set up Controller");
61 
62  for (NetDeviceContainer::Iterator i = c.Begin(); i != c.End(); ++i)
63  {
64  NS_LOG_INFO("**** Add SwitchPort " << *i);
65  dev->AddSwitchPort(*i);
66  }
67  return devs;
68 }
69 
72 {
74  NS_LOG_INFO("**** Install switch device on node " << node->GetId());
75 
76  NetDeviceContainer devs;
78  devs.Add(dev);
79  node->AddDevice(dev);
80 
81  for (NetDeviceContainer::Iterator i = c.Begin(); i != c.End(); ++i)
82  {
83  NS_LOG_INFO("**** Add SwitchPort " << *i);
84  dev->AddSwitchPort(*i);
85  }
86  return devs;
87 }
88 
91 {
93  Ptr<Node> node = Names::Find<Node>(nodeName);
94  return Install(node, c);
95 }
96 
97 } // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
holds a vector of ns3::NetDevice pointers
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
Iterator Begin() const
Get an iterator which refers to the first NetDevice in the container.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Iterator End() const
Get an iterator which indicates past-the-last NetDevice in the container.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:138
uint32_t GetId() const
Definition: node.cc:117
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.
A net device that switches multiple LAN segments via an OpenFlow-compatible flow table.
int AddSwitchPort(Ptr< NetDevice > switchPort)
Add a 'port' to a switch device.
void SetController(Ptr< ofi::Controller > c)
Set up the Switch's controller connection.
#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.