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
simple-net-device-helper.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2014 Universita' di Firenze
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7
*/
8
#ifndef SIMPLE_NETDEVICE_HELPER_H
9
#define SIMPLE_NETDEVICE_HELPER_H
10
11
#include "
net-device-container.h
"
12
#include "
node-container.h
"
13
14
#include "ns3/attribute.h"
15
#include "ns3/object-factory.h"
16
#include "ns3/queue.h"
17
#include "ns3/simple-channel.h"
18
19
#include <string>
20
21
namespace
ns3
22
{
23
24
/**
25
* @brief build a set of SimpleNetDevice objects
26
*/
27
class
SimpleNetDeviceHelper
28
{
29
public
:
30
/**
31
* Construct a SimpleNetDeviceHelper.
32
*/
33
SimpleNetDeviceHelper
();
34
35
virtual
~SimpleNetDeviceHelper
()
36
{
37
}
38
39
/**
40
* Each net device must have a queue to pass packets through.
41
* This method allows one to set the type of the queue that is automatically
42
* created when the device is created and attached to a node.
43
*
44
* @tparam Ts \deduced Argument types
45
* @param type the type of queue
46
* @param [in] args Name and AttributeValue pairs to set.
47
*
48
* Set the type of queue to create and associated to each
49
* SimpleNetDevice created through SimpleNetDeviceHelper::Install.
50
*/
51
template
<
typename
... Ts>
52
void
SetQueue
(std::string type, Ts&&... args);
53
54
/**
55
* Each net device must have a channel to pass packets through.
56
* This method allows one to set the type of the channel that is automatically
57
* created when the device is created and attached to a node.
58
*
59
* @tparam Ts \deduced Argument types
60
* @param type the type of channel
61
* @param [in] args Name and AttributeValue pairs to set.
62
*
63
* Set the type of channel to create and associated to each
64
* SimpleNetDevice created through SimpleNetDeviceHelper::Install.
65
*/
66
template
<
typename
... Ts>
67
void
SetChannel
(std::string type, Ts&&... args);
68
69
/**
70
* @param n1 the name of the attribute to set
71
* @param v1 the value of the attribute to set
72
*
73
* Set these attributes on each ns3::SimpleNetDevice created
74
* by SimpleNetDeviceHelper::Install
75
*/
76
void
SetDeviceAttribute
(std::string n1,
const
AttributeValue
& v1);
77
78
/**
79
* @param n1 the name of the attribute to set
80
* @param v1 the value of the attribute to set
81
*
82
* Set these attributes on each ns3::CsmaChannel created
83
* by SimpleNetDeviceHelper::Install
84
*/
85
void
SetChannelAttribute
(std::string n1,
const
AttributeValue
& v1);
86
87
/**
88
* SimpleNetDevice is Broadcast capable and ARP needing. This function
89
* limits the number of SimpleNetDevices on one channel to two, disables
90
* Broadcast and ARP and enables PointToPoint mode.
91
*
92
* @warning It must be used before installing a NetDevice on a node.
93
*
94
* @param pointToPointMode True for PointToPoint SimpleNetDevice
95
*/
96
void
SetNetDevicePointToPointMode
(
bool
pointToPointMode);
97
98
/**
99
* Disable flow control only if you know what you are doing. By disabling
100
* flow control, this NetDevice will be sent packets even if there is no
101
* room for them (such packets will be likely dropped by this NetDevice).
102
* Also, any queue disc installed on this NetDevice will have no effect,
103
* as every packet enqueued to the traffic control layer queue disc will
104
* be immediately dequeued.
105
*/
106
void
DisableFlowControl
();
107
108
/**
109
* This method creates an ns3::SimpleChannel with the attributes configured by
110
* SimpleNetDeviceHelper::SetChannelAttribute, an ns3::SimpleNetDevice with the attributes
111
* configured by SimpleNetDeviceHelper::SetDeviceAttribute and then adds the device
112
* to the node and attaches the channel to the device.
113
*
114
* @param node The node to install the device in
115
* @returns A container holding the added net device.
116
*/
117
NetDeviceContainer
Install
(
Ptr<Node>
node)
const
;
118
119
/**
120
* This method creates an ns3::SimpleNetDevice with the attributes configured by
121
* SimpleNetDeviceHelper::SetDeviceAttribute and then adds the device to the node and
122
* attaches the provided channel to the device.
123
*
124
* @param node The node to install the device in
125
* @param channel The channel to attach to the device.
126
* @returns A container holding the added net device.
127
*/
128
NetDeviceContainer
Install
(
Ptr<Node>
node,
Ptr<SimpleChannel>
channel)
const
;
129
130
/**
131
* This method creates an ns3::SimpleChannel with the attributes configured by
132
* SimpleNetDeviceHelper::SetChannelAttribute. For each Ptr<node> in the provided
133
* container: it creates an ns3::SimpleNetDevice (with the attributes
134
* configured by SimpleNetDeviceHelper::SetDeviceAttribute); adds the device to the
135
* node; and attaches the channel to the device.
136
*
137
* @param c The NodeContainer holding the nodes to be changed.
138
* @returns A container holding the added net devices.
139
*/
140
NetDeviceContainer
Install
(
const
NodeContainer
& c)
const
;
141
142
/**
143
* For each Ptr<node> in the provided container, this method creates an
144
* ns3::SimpleNetDevice (with the attributes configured by
145
* SimpleNetDeviceHelper::SetDeviceAttribute); adds the device to the node; and attaches
146
* the provided channel to the device.
147
*
148
* @param c The NodeContainer holding the nodes to be changed.
149
* @param channel The channel to attach to the devices.
150
* @returns A container holding the added net devices.
151
*/
152
NetDeviceContainer
Install
(
const
NodeContainer
& c,
Ptr<SimpleChannel>
channel)
const
;
153
154
private
:
155
/**
156
* This method creates an ns3::SimpleNetDevice with the attributes configured by
157
* SimpleNetDeviceHelper::SetDeviceAttribute and then adds the device to the node and
158
* attaches the provided channel to the device.
159
*
160
* @param node The node to install the device in
161
* @param channel The channel to attach to the device.
162
* @returns The new net device.
163
*/
164
Ptr<NetDevice>
InstallPriv
(
Ptr<Node>
node,
Ptr<SimpleChannel>
channel)
const
;
165
166
ObjectFactory
m_queueFactory
;
//!< Queue factory
167
ObjectFactory
m_deviceFactory
;
//!< NetDevice factory
168
ObjectFactory
m_channelFactory
;
//!< Channel factory
169
bool
m_pointToPointMode
;
//!< Install PointToPoint SimpleNetDevice or Broadcast ones
170
bool
m_enableFlowControl
;
//!< whether to enable flow control
171
};
172
173
/***************************************************************
174
* Implementation of the templates declared above.
175
***************************************************************/
176
177
template
<
typename
... Ts>
178
void
179
SimpleNetDeviceHelper::SetQueue
(std::string type, Ts&&... args)
180
{
181
QueueBase::AppendItemTypeIfNotPresent
(type,
"Packet"
);
182
183
m_queueFactory
.SetTypeId(type);
184
m_queueFactory
.Set(std::forward<Ts>(args)...);
185
}
186
187
template
<
typename
... Ts>
188
void
189
SimpleNetDeviceHelper::SetChannel
(std::string type, Ts&&... args)
190
{
191
m_channelFactory
.SetTypeId(type);
192
m_channelFactory
.Set(std::forward<Ts>(args)...);
193
}
194
195
}
// namespace ns3
196
197
#endif
/* SIMPLE_NETDEVICE_HELPER_H */
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::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
ns3::ObjectFactory
Instantiate subclasses of ns3::Object.
Definition
object-factory.h:37
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::QueueBase::AppendItemTypeIfNotPresent
static void AppendItemTypeIfNotPresent(std::string &typeId, const std::string &itemType)
Append the item type to the provided type ID if the latter does not end with '>'.
Definition
queue.cc:62
ns3::SimpleNetDeviceHelper::SetQueue
void SetQueue(std::string type, Ts &&... args)
Each net device must have a queue to pass packets through.
Definition
simple-net-device-helper.h:179
ns3::SimpleNetDeviceHelper::~SimpleNetDeviceHelper
virtual ~SimpleNetDeviceHelper()
Definition
simple-net-device-helper.h:35
ns3::SimpleNetDeviceHelper::m_enableFlowControl
bool m_enableFlowControl
whether to enable flow control
Definition
simple-net-device-helper.h:170
ns3::SimpleNetDeviceHelper::InstallPriv
Ptr< NetDevice > InstallPriv(Ptr< Node > node, Ptr< SimpleChannel > channel) const
This method creates an ns3::SimpleNetDevice with the attributes configured by SimpleNetDeviceHelper::...
Definition
simple-net-device-helper.cc:100
ns3::SimpleNetDeviceHelper::m_deviceFactory
ObjectFactory m_deviceFactory
NetDevice factory.
Definition
simple-net-device-helper.h:167
ns3::SimpleNetDeviceHelper::SetChannelAttribute
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
Definition
simple-net-device-helper.cc:48
ns3::SimpleNetDeviceHelper::m_channelFactory
ObjectFactory m_channelFactory
Channel factory.
Definition
simple-net-device-helper.h:168
ns3::SimpleNetDeviceHelper::m_queueFactory
ObjectFactory m_queueFactory
Queue factory.
Definition
simple-net-device-helper.h:166
ns3::SimpleNetDeviceHelper::SetNetDevicePointToPointMode
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
Definition
simple-net-device-helper.cc:54
ns3::SimpleNetDeviceHelper::SetDeviceAttribute
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Definition
simple-net-device-helper.cc:42
ns3::SimpleNetDeviceHelper::SetChannel
void SetChannel(std::string type, Ts &&... args)
Each net device must have a channel to pass packets through.
Definition
simple-net-device-helper.h:189
ns3::SimpleNetDeviceHelper::SimpleNetDeviceHelper
SimpleNetDeviceHelper()
Construct a SimpleNetDeviceHelper.
Definition
simple-net-device-helper.cc:32
ns3::SimpleNetDeviceHelper::DisableFlowControl
void DisableFlowControl()
Disable flow control only if you know what you are doing.
Definition
simple-net-device-helper.cc:60
ns3::SimpleNetDeviceHelper::Install
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
Definition
simple-net-device-helper.cc:66
ns3::SimpleNetDeviceHelper::m_pointToPointMode
bool m_pointToPointMode
Install PointToPoint SimpleNetDevice or Broadcast ones.
Definition
simple-net-device-helper.h:169
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
net-device-container.h
node-container.h
src
network
helper
simple-net-device-helper.h
Generated on Wed Jun 11 2025 13:15:35 for ns-3 by
1.13.2