A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
simple-net-device-helper.cc
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
21
22#include "ns3/abort.h"
23#include "ns3/boolean.h"
24#include "ns3/config.h"
25#include "ns3/log.h"
26#include "ns3/names.h"
27#include "ns3/net-device-queue-interface.h"
28#include "ns3/object-factory.h"
29#include "ns3/packet.h"
30#include "ns3/simple-channel.h"
31#include "ns3/simple-net-device.h"
32#include "ns3/simulator.h"
33#include "ns3/trace-helper.h"
34
35#include <string>
36
37namespace ns3
38{
39
40NS_LOG_COMPONENT_DEFINE("SimpleNetDeviceHelper");
41
43{
44 m_queueFactory.SetTypeId("ns3::DropTailQueue<Packet>");
45 m_deviceFactory.SetTypeId("ns3::SimpleNetDevice");
46 m_channelFactory.SetTypeId("ns3::SimpleChannel");
47 m_pointToPointMode = false;
49}
50
51void
53{
54 m_deviceFactory.Set(n1, v1);
55}
56
57void
59{
60 m_channelFactory.Set(n1, v1);
61}
62
63void
65{
66 m_pointToPointMode = pointToPointMode;
67}
68
69void
71{
72 m_enableFlowControl = false;
73}
74
77{
79 return Install(node, channel);
80}
81
84{
85 return NetDeviceContainer(InstallPriv(node, channel));
86}
87
90{
92
93 return Install(c, channel);
94}
95
98{
100
101 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); i++)
102 {
103 devs.Add(InstallPriv(*i, channel));
104 }
105
106 return devs;
107}
108
111{
113 device->SetAttribute("PointToPointMode", BooleanValue(m_pointToPointMode));
114 device->SetAddress(Mac48Address::Allocate());
115 node->AddDevice(device);
116 device->SetChannel(channel);
118 device->SetQueue(queue);
119 NS_ASSERT_MSG(!m_pointToPointMode || (channel->GetNDevices() <= 2),
120 "Device set to PointToPoint and more than 2 devices on the channel.");
122 {
123 // Aggregate a NetDeviceQueueInterface object
124 Ptr<NetDeviceQueueInterface> ndqi = CreateObject<NetDeviceQueueInterface>();
125 ndqi->GetTxQueue(0)->ConnectQueueTraces(queue);
126 device->AggregateObject(ndqi);
127 }
128 return device;
129}
130
131} // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
AttributeValue implementation for Boolean.
Definition: boolean.h:37
static Mac48Address Allocate()
Allocate a new Mac48Address.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
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:78
Template class for packet Queues.
Definition: queue.h:267
A simple channel, for simple things and testing.
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)
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.
This device assumes 48-bit mac addressing; there is also the possibility to add an ErrorModel if you ...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Every class exported by the ns3 library is enclosed in the ns3 namespace.