A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
33
OpenFlowSwitchHelper::OpenFlowSwitchHelper
()
34
{
35
NS_LOG_FUNCTION_NOARGS
();
36
m_deviceFactory
.
SetTypeId
(
"ns3::OpenFlowSwitchNetDevice"
);
37
}
38
39
void
40
OpenFlowSwitchHelper::SetDeviceAttribute
(std::string n1,
const
AttributeValue
& v1)
41
{
42
NS_LOG_FUNCTION_NOARGS
();
43
m_deviceFactory
.
Set
(n1, v1);
44
}
45
46
NetDeviceContainer
47
OpenFlowSwitchHelper::Install
(
Ptr<Node>
node,
48
NetDeviceContainer
c,
49
Ptr<ns3::ofi::Controller>
controller
)
50
{
51
NS_LOG_FUNCTION_NOARGS
();
52
NS_LOG_INFO
(
"**** Install switch device on node "
<< node->
GetId
());
53
54
NetDeviceContainer
devs;
55
Ptr<OpenFlowSwitchNetDevice>
dev =
m_deviceFactory
.
Create
<
OpenFlowSwitchNetDevice
>();
56
devs.
Add
(dev);
57
node->
AddDevice
(dev);
58
59
NS_LOG_INFO
(
"**** Set up Controller"
);
60
dev->
SetController
(
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
70
NetDeviceContainer
71
OpenFlowSwitchHelper::Install
(
Ptr<Node>
node,
NetDeviceContainer
c)
72
{
73
NS_LOG_FUNCTION_NOARGS
();
74
NS_LOG_INFO
(
"**** Install switch device on node "
<< node->
GetId
());
75
76
NetDeviceContainer
devs;
77
Ptr<OpenFlowSwitchNetDevice>
dev =
m_deviceFactory
.
Create
<
OpenFlowSwitchNetDevice
>();
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
89
NetDeviceContainer
90
OpenFlowSwitchHelper::Install
(std::string nodeName,
NetDeviceContainer
c)
91
{
92
NS_LOG_FUNCTION_NOARGS
();
93
Ptr<Node>
node = Names::Find<Node>(nodeName);
94
return
Install
(node, c);
95
}
96
97
}
// namespace ns3
ns3::AttributeValue
Hold a value for an Attribute.
Definition:
attribute.h:70
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition:
net-device-container.h:43
ns3::NetDeviceContainer::Iterator
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
Definition:
net-device-container.h:46
ns3::NetDeviceContainer::Begin
Iterator Begin() const
Get an iterator which refers to the first NetDevice in the container.
Definition:
net-device-container.cc:49
ns3::NetDeviceContainer::Add
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Definition:
net-device-container.cc:73
ns3::NetDeviceContainer::End
Iterator End() const
Get an iterator which indicates past-the-last NetDevice in the container.
Definition:
net-device-container.cc:55
ns3::Node::AddDevice
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition:
node.cc:138
ns3::Node::GetId
uint32_t GetId() const
Definition:
node.cc:117
ns3::ObjectFactory::Create
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
Definition:
object-factory.cc:93
ns3::ObjectFactory::Set
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Definition:
object-factory.h:220
ns3::ObjectFactory::SetTypeId
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Definition:
object-factory.cc:42
ns3::OpenFlowSwitchHelper::Install
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c, Ptr< ns3::ofi::Controller > controller)
This method creates an ns3::OpenFlowSwitchNetDevice with the attributes configured by OpenFlowSwitchH...
Definition:
openflow-switch-helper.cc:47
ns3::OpenFlowSwitchHelper::m_deviceFactory
ObjectFactory m_deviceFactory
Object factory.
Definition:
openflow-switch-helper.h:96
ns3::OpenFlowSwitchHelper::OpenFlowSwitchHelper
OpenFlowSwitchHelper()
Definition:
openflow-switch-helper.cc:33
ns3::OpenFlowSwitchHelper::SetDeviceAttribute
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Set an attribute on each ns3::OpenFlowSwitchNetDevice created by OpenFlowSwitchHelper::Install.
Definition:
openflow-switch-helper.cc:40
ns3::OpenFlowSwitchNetDevice
A net device that switches multiple LAN segments via an OpenFlow-compatible flow table.
Definition:
openflow-switch-net-device.h:91
ns3::OpenFlowSwitchNetDevice::AddSwitchPort
int AddSwitchPort(Ptr< NetDevice > switchPort)
Add a 'port' to a switch device.
Definition:
openflow-switch-net-device.cc:170
ns3::OpenFlowSwitchNetDevice::SetController
void SetController(Ptr< ofi::Controller > c)
Set up the Switch's controller connection.
Definition:
openflow-switch-net-device.cc:157
ns3::Ptr< Node >
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition:
log-macros-enabled.h:206
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition:
log.h:275
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
openflow-switch.controller
controller
Definition:
openflow-switch.py:55
openflow-switch-helper.h
src
openflow
helper
openflow-switch-helper.cc
Generated on Sun Mar 3 2024 17:11:07 for ns-3 by
1.9.1