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