A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
csma-helper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef CSMA_HELPER_H
20#define CSMA_HELPER_H
21
22#include "ns3/attribute.h"
23#include "ns3/csma-channel.h"
24#include "ns3/net-device-container.h"
25#include "ns3/node-container.h"
26#include "ns3/object-factory.h"
27#include "ns3/queue.h"
28#include "ns3/trace-helper.h"
29
30#include <string>
31
32namespace ns3
33{
34
35class Packet;
36
37/**
38 * \ingroup csma
39 * \brief build a set of CsmaNetDevice objects
40 *
41 * Normally we eschew multiple inheritance, however, the classes
42 * PcapUserHelperForDevice and AsciiTraceUserHelperForDevice are
43 * treated as "mixins". A mixin is a self-contained class that
44 * encapsulates a general attribute or a set of functionality that
45 * may be of interest to many other classes.
46 */
48{
49 public:
50 /**
51 * Construct a CsmaHelper.
52 */
53 CsmaHelper();
54
55 ~CsmaHelper() override
56 {
57 }
58
59 /**
60 * \tparam Ts \deduced Argument types
61 * \param type the type of queue
62 * \param [in] args Name and AttributeValue pairs to set.
63 *
64 * Set the type of queue to create and associated to each
65 * CsmaNetDevice created through CsmaHelper::Install.
66 */
67 template <typename... Ts>
68 void SetQueue(std::string type, Ts&&... args);
69
70 /**
71 * \param n1 the name of the attribute to set
72 * \param v1 the value of the attribute to set
73 *
74 * Set these attributes on each ns3::CsmaNetDevice created
75 * by CsmaHelper::Install
76 */
77 void SetDeviceAttribute(std::string n1, const AttributeValue& v1);
78
79 /**
80 * \param n1 the name of the attribute to set
81 * \param v1 the value of the attribute to set
82 *
83 * Set these attributes on each ns3::CsmaChannel created
84 * by CsmaHelper::Install
85 */
86 void SetChannelAttribute(std::string n1, const AttributeValue& v1);
87
88 /**
89 * Disable flow control only if you know what you are doing. By disabling
90 * flow control, this NetDevice will be sent packets even if there is no
91 * room for them (such packets will be likely dropped by this NetDevice).
92 * Also, any queue disc installed on this NetDevice will have no effect,
93 * as every packet enqueued to the traffic control layer queue disc will
94 * be immediately dequeued.
95 */
96 void DisableFlowControl();
97
98 /**
99 * This method creates an ns3::CsmaChannel with the attributes configured by
100 * CsmaHelper::SetChannelAttribute, an ns3::CsmaNetDevice with the attributes
101 * configured by CsmaHelper::SetDeviceAttribute and then adds the device
102 * to the node and attaches the channel to the device.
103 *
104 * \param node The node to install the device in
105 * \returns A container holding the added net device.
106 */
108
109 /**
110 * This method creates an ns3::CsmaChannel with the attributes configured by
111 * CsmaHelper::SetChannelAttribute, an ns3::CsmaNetDevice with the attributes
112 * configured by CsmaHelper::SetDeviceAttribute and then adds the device
113 * to the node and attaches the channel to the device.
114 *
115 * \param name The name of the node to install the device in
116 * \returns A container holding the added net device.
117 */
118 NetDeviceContainer Install(std::string name) const;
119
120 /**
121 * This method creates an ns3::CsmaNetDevice with the attributes configured by
122 * CsmaHelper::SetDeviceAttribute and then adds the device to the node and
123 * attaches the provided channel to the device.
124 *
125 * \param node The node to install the device in
126 * \param channel The channel to attach to the device.
127 * \returns A container holding the added net device.
128 */
130
131 /**
132 * This method creates an ns3::CsmaNetDevice with the attributes configured by
133 * CsmaHelper::SetDeviceAttribute and then adds the device to the node and
134 * attaches the provided channel to the device.
135 *
136 * \param node The node to install the device in
137 * \param channelName The name of the channel to attach to the device.
138 * \returns A container holding the added net device.
139 */
140 NetDeviceContainer Install(Ptr<Node> node, std::string channelName) const;
141
142 /**
143 * This method creates an ns3::CsmaNetDevice with the attributes configured by
144 * CsmaHelper::SetDeviceAttribute and then adds the device to the node and
145 * attaches the provided channel to the device.
146 *
147 * \param nodeName The name of the node to install the device in
148 * \param channel The channel to attach to the device.
149 * \returns A container holding the added net device.
150 */
151 NetDeviceContainer Install(std::string nodeName, Ptr<CsmaChannel> channel) const;
152
153 /**
154 * This method creates an ns3::CsmaNetDevice with the attributes configured by
155 * CsmaHelper::SetDeviceAttribute and then adds the device to the node and
156 * attaches the provided channel to the device.
157 *
158 * \param nodeName The name of the node to install the device in
159 * \param channelName The name of the channel to attach to the device.
160 * \returns A container holding the added net device.
161 */
162 NetDeviceContainer Install(std::string nodeName, std::string channelName) const;
163
164 /**
165 * This method creates an ns3::CsmaChannel with the attributes configured by
166 * CsmaHelper::SetChannelAttribute. For each Ptr<node> in the provided
167 * container: it creates an ns3::CsmaNetDevice (with the attributes
168 * configured by CsmaHelper::SetDeviceAttribute); adds the device to the
169 * node; and attaches the channel to the device.
170 *
171 * \param c The NodeContainer holding the nodes to be changed.
172 * \returns A container holding the added net devices.
173 */
175
176 /**
177 * For each Ptr<node> in the provided container, this method creates an
178 * ns3::CsmaNetDevice (with the attributes configured by
179 * CsmaHelper::SetDeviceAttribute); adds the device to the node; and attaches
180 * the provided channel to the device.
181 *
182 * \param c The NodeContainer holding the nodes to be changed.
183 * \param channel The channel to attach to the devices.
184 * \returns A container holding the added net devices.
185 */
187
188 /**
189 * For each Ptr<node> in the provided container, this method creates an
190 * ns3::CsmaNetDevice (with the attributes configured by
191 * CsmaHelper::SetDeviceAttribute); adds the device to the node; and attaches
192 * the provided channel to the device.
193 *
194 * \param c The NodeContainer holding the nodes to be changed.
195 * \param channelName The name of the channel to attach to the devices.
196 * \returns A container holding the added net devices.
197 */
198 NetDeviceContainer Install(const NodeContainer& c, std::string channelName) const;
199
200 /**
201 * Assign a fixed random variable stream number to the random variables
202 * used by this model. Return the number of streams (possibly zero) that
203 * have been assigned. The Install() method should have previously been
204 * called by the user.
205 *
206 * \param c NetDeviceContainer of the set of net devices for which the
207 * CsmaNetDevice should be modified to use a fixed stream
208 * \param stream first stream index to use
209 * \return the number of stream indices assigned by this helper
210 */
211 int64_t AssignStreams(NetDeviceContainer c, int64_t stream);
212
213 private:
214 /**
215 * This method creates an ns3::CsmaNetDevice with the attributes configured by
216 * CsmaHelper::SetDeviceAttribute and then adds the device to the node and
217 * attaches the provided channel to the device.
218 *
219 * \param node The node to install the device in
220 * \param channel The channel to attach to the device.
221 * \returns A container holding the added net device.
222 */
224
225 /**
226 * \brief Enable pcap output on the indicated net device.
227 *
228 * NetDevice-specific implementation mechanism for hooking the trace and
229 * writing to the trace file.
230 *
231 * \param prefix Filename prefix to use for pcap files.
232 * \param nd Net device for which you want to enable tracing.
233 * \param promiscuous If true capture all possible packets available at the device.
234 * \param explicitFilename Treat the prefix as an explicit filename if true
235 */
236 void EnablePcapInternal(std::string prefix,
238 bool promiscuous,
239 bool explicitFilename) override;
240
241 /**
242 * \brief Enable ascii trace output on the indicated net device.
243 *
244 * NetDevice-specific implementation mechanism for hooking the trace and
245 * writing to the trace file.
246 *
247 * \param stream The output stream object to use when logging ascii traces.
248 * \param prefix Filename prefix to use for ascii trace files.
249 * \param nd Net device for which you want to enable tracing.
250 * \param explicitFilename Treat the prefix as an explicit filename if true
251 */
253 std::string prefix,
255 bool explicitFilename) override;
256
257 ObjectFactory m_queueFactory; //!< factory for the queues
258 ObjectFactory m_deviceFactory; //!< factory for the NetDevices
259 ObjectFactory m_channelFactory; //!< factory for the channel
260 bool m_enableFlowControl; //!< whether to enable flow control
261};
262
263/***************************************************************
264 * Implementation of the templates declared above.
265 ***************************************************************/
266
267template <typename... Ts>
268void
269CsmaHelper::SetQueue(std::string type, Ts&&... args)
270{
272
274 m_queueFactory.Set(std::forward<Ts>(args)...);
275}
276
277} // namespace ns3
278
279#endif /* CSMA_HELPER_H */
Base class providing common user-level ascii trace operations for helpers representing net devices.
Definition: trace-helper.h:729
Hold a value for an Attribute.
Definition: attribute.h:70
build a set of CsmaNetDevice objects
Definition: csma-helper.h:48
void SetQueue(std::string type, Ts &&... args)
Definition: csma-helper.h:269
ObjectFactory m_channelFactory
factory for the channel
Definition: csma-helper.h:259
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:50
void EnableAsciiInternal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename) override
Enable ascii trace output on the indicated net device.
Definition: csma-helper.cc:111
bool m_enableFlowControl
whether to enable flow control
Definition: csma-helper.h:260
Ptr< NetDevice > InstallPriv(Ptr< Node > node, Ptr< CsmaChannel > channel) const
This method creates an ns3::CsmaNetDevice with the attributes configured by CsmaHelper::SetDeviceAttr...
Definition: csma-helper.cc:313
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:56
CsmaHelper()
Construct a CsmaHelper.
Definition: csma-helper.cc:41
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: csma-helper.cc:296
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Definition: csma-helper.cc:226
void DisableFlowControl()
Disable flow control only if you know what you are doing.
Definition: csma-helper.cc:62
ObjectFactory m_queueFactory
factory for the queues
Definition: csma-helper.h:257
void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename) override
Enable pcap output on the indicated net device.
Definition: csma-helper.cc:68
ObjectFactory m_deviceFactory
factory for the NetDevices
Definition: csma-helper.h:258
~CsmaHelper() override
Definition: csma-helper.h:55
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.
Base class providing common user-level pcap operations for helpers representing net devices.
Definition: trace-helper.h:624
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
Every class exported by the ns3 library is enclosed in the ns3 namespace.