A Discrete-Event Network Simulator
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
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
21namespace ns3
22{
23
24/**
25 * \brief build a set of SimpleNetDevice objects
26 */
28{
29 public:
30 /**
31 * Construct a SimpleNetDeviceHelper.
32 */
34
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 */
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 */
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 */
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 */
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 */
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
177template <typename... Ts>
178void
179SimpleNetDeviceHelper::SetQueue(std::string type, Ts&&... args)
180{
182
184 m_queueFactory.Set(std::forward<Ts>(args)...);
185}
186
187template <typename... Ts>
188void
189SimpleNetDeviceHelper::SetChannel(std::string type, Ts&&... args)
190{
192 m_channelFactory.Set(std::forward<Ts>(args)...);
193}
194
195} // namespace ns3
196
197#endif /* SIMPLE_NETDEVICE_HELPER_H */
Hold a value for an Attribute.
Definition attribute.h:59
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Instantiate subclasses of ns3::Object.
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.
Smart pointer class similar to boost::intrusive_ptr.
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
build a set of SimpleNetDevice objects
void SetQueue(std::string type, Ts &&... args)
Each net device must have a queue to pass packets through.
bool m_enableFlowControl
whether to enable flow control
Ptr< NetDevice > InstallPriv(Ptr< Node > node, Ptr< SimpleChannel > channel) const
This method creates an ns3::SimpleNetDevice with the attributes configured by SimpleNetDeviceHelper::...
ObjectFactory m_deviceFactory
NetDevice factory.
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
ObjectFactory m_channelFactory
Channel factory.
ObjectFactory m_queueFactory
Queue factory.
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
void SetChannel(std::string type, Ts &&... args)
Each net device must have a channel to pass packets through.
SimpleNetDeviceHelper()
Construct a SimpleNetDeviceHelper.
void DisableFlowControl()
Disable flow control only if you know what you are doing.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
bool m_pointToPointMode
Install PointToPoint SimpleNetDevice or Broadcast ones.
Every class exported by the ns3 library is enclosed in the ns3 namespace.