A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
openflow-switch-helper.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011 Blake Hurd
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Blake Hurd <naimorai@gmail.com>
7
*/
8
9
#include "
openflow-switch-helper.h
"
10
11
#include "ns3/log.h"
12
#include "ns3/names.h"
13
#include "ns3/node.h"
14
#include "ns3/openflow-interface.h"
15
#include "ns3/openflow-switch-net-device.h"
16
17
namespace
ns3
18
{
19
20
NS_LOG_COMPONENT_DEFINE
(
"OpenFlowSwitchHelper"
);
21
22
OpenFlowSwitchHelper::OpenFlowSwitchHelper
()
23
{
24
NS_LOG_FUNCTION_NOARGS
();
25
m_deviceFactory
.
SetTypeId
(
"ns3::OpenFlowSwitchNetDevice"
);
26
}
27
28
void
29
OpenFlowSwitchHelper::SetDeviceAttribute
(std::string
n1
,
const
AttributeValue
&
v1
)
30
{
31
NS_LOG_FUNCTION_NOARGS
();
32
m_deviceFactory
.
Set
(
n1
,
v1
);
33
}
34
35
NetDeviceContainer
36
OpenFlowSwitchHelper::Install
(
Ptr<Node>
node,
37
NetDeviceContainer
c
,
38
Ptr<ns3::ofi::Controller>
controller)
39
{
40
NS_LOG_FUNCTION_NOARGS
();
41
NS_LOG_INFO
(
"**** Install switch device on node "
<< node->GetId());
42
43
NetDeviceContainer
devs
;
44
Ptr<OpenFlowSwitchNetDevice>
dev =
m_deviceFactory
.
Create
<
OpenFlowSwitchNetDevice
>();
45
devs
.Add(dev);
46
node->AddDevice(dev);
47
48
NS_LOG_INFO
(
"**** Set up Controller"
);
49
dev->SetController(controller);
50
51
for
(
NetDeviceContainer::Iterator
i
=
c
.Begin();
i
!=
c
.End(); ++
i
)
52
{
53
NS_LOG_INFO
(
"**** Add SwitchPort "
<< *
i
);
54
dev->AddSwitchPort(*
i
);
55
}
56
return
devs
;
57
}
58
59
NetDeviceContainer
60
OpenFlowSwitchHelper::Install
(
Ptr<Node>
node,
NetDeviceContainer
c
)
61
{
62
NS_LOG_FUNCTION_NOARGS
();
63
NS_LOG_INFO
(
"**** Install switch device on node "
<< node->GetId());
64
65
NetDeviceContainer
devs
;
66
Ptr<OpenFlowSwitchNetDevice>
dev =
m_deviceFactory
.
Create
<
OpenFlowSwitchNetDevice
>();
67
devs
.Add(dev);
68
node->AddDevice(dev);
69
70
for
(
NetDeviceContainer::Iterator
i
=
c
.Begin();
i
!=
c
.End(); ++
i
)
71
{
72
NS_LOG_INFO
(
"**** Add SwitchPort "
<< *
i
);
73
dev->AddSwitchPort(*
i
);
74
}
75
return
devs
;
76
}
77
78
NetDeviceContainer
79
OpenFlowSwitchHelper::Install
(std::string
nodeName
,
NetDeviceContainer
c
)
80
{
81
NS_LOG_FUNCTION_NOARGS
();
82
Ptr<Node>
node = Names::Find<Node>(
nodeName
);
83
return
Install
(node,
c
);
84
}
85
86
}
// namespace ns3
ns3::AttributeValue
Hold a value for an Attribute.
Definition
attribute.h:59
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition
net-device-container.h:32
ns3::NetDeviceContainer::Iterator
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
Definition
net-device-container.h:35
ns3::ObjectFactory::Create
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
Definition
object-factory.cc:82
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:213
ns3::ObjectFactory::SetTypeId
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Definition
object-factory.cc:31
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:36
ns3::OpenFlowSwitchHelper::m_deviceFactory
ObjectFactory m_deviceFactory
Object factory.
Definition
openflow-switch-helper.h:85
ns3::OpenFlowSwitchHelper::OpenFlowSwitchHelper
OpenFlowSwitchHelper()
Definition
openflow-switch-helper.cc:22
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:29
ns3::OpenFlowSwitchNetDevice
A net device that switches multiple LAN segments via an OpenFlow-compatible flow table.
Definition
openflow-switch-net-device.h:80
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition
log-macros-enabled.h:195
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition
log.h:264
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
openflow-switch-helper.h
src
openflow
helper
openflow-switch-helper.cc
Generated on Mon Dec 15 2025 15:22:02 for ns-3 by
1.9.8