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 * 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: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 */
19#ifndef SIMPLE_NETDEVICE_HELPER_H
20#define SIMPLE_NETDEVICE_HELPER_H
21
23#include "node-container.h"
24
25#include "ns3/attribute.h"
26#include "ns3/object-factory.h"
27#include "ns3/queue.h"
28#include "ns3/simple-channel.h"
29
30#include <string>
31
32namespace ns3
33{
34
35/**
36 * \brief build a set of SimpleNetDevice objects
37 */
39{
40 public:
41 /**
42 * Construct a SimpleNetDeviceHelper.
43 */
45
47 {
48 }
49
50 /**
51 * Each net device must have a queue to pass packets through.
52 * This method allows one to set the type of the queue that is automatically
53 * created when the device is created and attached to a node.
54 *
55 * \tparam Ts \deduced Argument types
56 * \param type the type of queue
57 * \param [in] args Name and AttributeValue pairs to set.
58 *
59 * Set the type of queue to create and associated to each
60 * SimpleNetDevice created through SimpleNetDeviceHelper::Install.
61 */
62 template <typename... Ts>
63 void SetQueue(std::string type, Ts&&... args);
64
65 /**
66 * Each net device must have a channel to pass packets through.
67 * This method allows one to set the type of the channel that is automatically
68 * created when the device is created and attached to a node.
69 *
70 * \tparam Ts \deduced Argument types
71 * \param type the type of channel
72 * \param [in] args Name and AttributeValue pairs to set.
73 *
74 * Set the type of channel to create and associated to each
75 * SimpleNetDevice created through SimpleNetDeviceHelper::Install.
76 */
77 template <typename... Ts>
78 void SetChannel(std::string type, Ts&&... args);
79
80 /**
81 * \param n1 the name of the attribute to set
82 * \param v1 the value of the attribute to set
83 *
84 * Set these attributes on each ns3::SimpleNetDevice created
85 * by SimpleNetDeviceHelper::Install
86 */
87 void SetDeviceAttribute(std::string n1, const AttributeValue& v1);
88
89 /**
90 * \param n1 the name of the attribute to set
91 * \param v1 the value of the attribute to set
92 *
93 * Set these attributes on each ns3::CsmaChannel created
94 * by SimpleNetDeviceHelper::Install
95 */
96 void SetChannelAttribute(std::string n1, const AttributeValue& v1);
97
98 /**
99 * SimpleNetDevice is Broadcast capable and ARP needing. This function
100 * limits the number of SimpleNetDevices on one channel to two, disables
101 * Broadcast and ARP and enables PointToPoint mode.
102 *
103 * \warning It must be used before installing a NetDevice on a node.
104 *
105 * \param pointToPointMode True for PointToPoint SimpleNetDevice
106 */
107 void SetNetDevicePointToPointMode(bool pointToPointMode);
108
109 /**
110 * Disable flow control only if you know what you are doing. By disabling
111 * flow control, this NetDevice will be sent packets even if there is no
112 * room for them (such packets will be likely dropped by this NetDevice).
113 * Also, any queue disc installed on this NetDevice will have no effect,
114 * as every packet enqueued to the traffic control layer queue disc will
115 * be immediately dequeued.
116 */
117 void DisableFlowControl();
118
119 /**
120 * This method creates an ns3::SimpleChannel with the attributes configured by
121 * SimpleNetDeviceHelper::SetChannelAttribute, an ns3::SimpleNetDevice with the attributes
122 * configured by SimpleNetDeviceHelper::SetDeviceAttribute and then adds the device
123 * to the node and attaches the channel to the device.
124 *
125 * \param node The node to install the device in
126 * \returns A container holding the added net device.
127 */
129
130 /**
131 * This method creates an ns3::SimpleNetDevice with the attributes configured by
132 * SimpleNetDeviceHelper::SetDeviceAttribute and then adds the device to the node and
133 * attaches the provided channel to the device.
134 *
135 * \param node The node to install the device in
136 * \param channel The channel to attach to the device.
137 * \returns A container holding the added net device.
138 */
140
141 /**
142 * This method creates an ns3::SimpleChannel with the attributes configured by
143 * SimpleNetDeviceHelper::SetChannelAttribute. For each Ptr<node> in the provided
144 * container: it creates an ns3::SimpleNetDevice (with the attributes
145 * configured by SimpleNetDeviceHelper::SetDeviceAttribute); adds the device to the
146 * node; and attaches the channel to the device.
147 *
148 * \param c The NodeContainer holding the nodes to be changed.
149 * \returns A container holding the added net devices.
150 */
152
153 /**
154 * For each Ptr<node> in the provided container, this method creates an
155 * ns3::SimpleNetDevice (with the attributes configured by
156 * SimpleNetDeviceHelper::SetDeviceAttribute); adds the device to the node; and attaches
157 * the provided channel to the device.
158 *
159 * \param c The NodeContainer holding the nodes to be changed.
160 * \param channel The channel to attach to the devices.
161 * \returns A container holding the added net devices.
162 */
164
165 private:
166 /**
167 * This method creates an ns3::SimpleNetDevice with the attributes configured by
168 * SimpleNetDeviceHelper::SetDeviceAttribute and then adds the device to the node and
169 * attaches the provided channel to the device.
170 *
171 * \param node The node to install the device in
172 * \param channel The channel to attach to the device.
173 * \returns The new net device.
174 */
176
177 ObjectFactory m_queueFactory; //!< Queue factory
178 ObjectFactory m_deviceFactory; //!< NetDevice factory
179 ObjectFactory m_channelFactory; //!< Channel factory
180 bool m_pointToPointMode; //!< Install PointToPoint SimpleNetDevice or Broadcast ones
181 bool m_enableFlowControl; //!< whether to enable flow control
182};
183
184/***************************************************************
185 * Implementation of the templates declared above.
186 ***************************************************************/
187
188template <typename... Ts>
189void
190SimpleNetDeviceHelper::SetQueue(std::string type, Ts&&... args)
191{
193
195 m_queueFactory.Set(std::forward<Ts>(args)...);
196}
197
198template <typename... Ts>
199void
200SimpleNetDeviceHelper::SetChannel(std::string type, Ts&&... args)
201{
203 m_channelFactory.Set(std::forward<Ts>(args)...);
204}
205
206} // namespace ns3
207
208#endif /* SIMPLE_NETDEVICE_HELPER_H */
Hold a value for an Attribute.
Definition: attribute.h:70
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.
Definition: ptr.h:77
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:73
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.