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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8
10
11#include "trace-helper.h"
12
13#include "ns3/abort.h"
14#include "ns3/boolean.h"
15#include "ns3/config.h"
16#include "ns3/log.h"
17#include "ns3/names.h"
18#include "ns3/net-device-queue-interface.h"
19#include "ns3/object-factory.h"
20#include "ns3/packet.h"
21#include "ns3/simple-channel.h"
22#include "ns3/simple-net-device.h"
23#include "ns3/simulator.h"
24
25#include <string>
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("SimpleNetDeviceHelper");
31
33{
34 m_queueFactory.SetTypeId("ns3::DropTailQueue<Packet>");
35 m_deviceFactory.SetTypeId("ns3::SimpleNetDevice");
36 m_channelFactory.SetTypeId("ns3::SimpleChannel");
37 m_pointToPointMode = false;
39}
40
41void
43{
44 m_deviceFactory.Set(n1, v1);
45}
46
47void
52
53void
55{
56 m_pointToPointMode = pointToPointMode;
57}
58
59void
64
67{
69 return Install(node, channel);
70}
71
74{
75 return NetDeviceContainer(InstallPriv(node, channel));
76}
77
80{
82
83 return Install(c, channel);
84}
85
88{
90
91 for (auto i = c.Begin(); i != c.End(); i++)
92 {
93 devs.Add(InstallPriv(*i, channel));
94 }
95
96 return devs;
97}
98
101{
103 device->SetAttribute("PointToPointMode", BooleanValue(m_pointToPointMode));
104 device->SetAddress(Mac48Address::Allocate());
105 node->AddDevice(device);
106 device->SetChannel(channel);
108 device->SetQueue(queue);
109 NS_ASSERT_MSG(!m_pointToPointMode || (channel->GetNDevices() <= 2),
110 "Device set to PointToPoint and more than 2 devices on the channel.");
112 {
113 // Aggregate a NetDeviceQueueInterface object
115 ndqi->GetTxQueue(0)->ConnectQueueTraces(queue);
116 device->AggregateObject(ndqi);
117 }
118 return device;
119}
120
121} // namespace ns3
Hold a value for an Attribute.
Definition attribute.h:59
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.
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.
Template class for packet Queues.
Definition queue.h:257
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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.