A Discrete-Event Network Simulator
API
simple-net-device-helper.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014 Universita' di Firenze
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19 */
20
21#include "ns3/abort.h"
22#include "ns3/log.h"
23#include "ns3/simulator.h"
24#include "ns3/object-factory.h"
25#include "ns3/queue.h"
26#include "ns3/net-device-queue-interface.h"
27#include "ns3/simple-net-device.h"
28#include "ns3/simple-channel.h"
29#include "ns3/config.h"
30#include "ns3/packet.h"
31#include "ns3/names.h"
32#include "ns3/boolean.h"
33
34#include "ns3/trace-helper.h"
36
37#include <string>
38
39namespace ns3 {
40
41NS_LOG_COMPONENT_DEFINE ("SimpleNetDeviceHelper");
42
44{
45 m_queueFactory.SetTypeId ("ns3::DropTailQueue<Packet>");
46 m_deviceFactory.SetTypeId ("ns3::SimpleNetDevice");
47 m_channelFactory.SetTypeId ("ns3::SimpleChannel");
48 m_pointToPointMode = false;
50}
51
52void
54 std::string n1, const AttributeValue &v1,
55 std::string n2, const AttributeValue &v2,
56 std::string n3, const AttributeValue &v3,
57 std::string n4, const AttributeValue &v4)
58{
60
62 m_queueFactory.Set (n1, v1);
63 m_queueFactory.Set (n2, v2);
64 m_queueFactory.Set (n3, v3);
65 m_queueFactory.Set (n4, v4);
66}
67
68void
70 std::string n1, const AttributeValue &v1,
71 std::string n2, const AttributeValue &v2,
72 std::string n3, const AttributeValue &v3,
73 std::string n4, const AttributeValue &v4)
74{
76 m_channelFactory.Set (n1, v1);
77 m_channelFactory.Set (n2, v2);
78 m_channelFactory.Set (n3, v3);
79 m_channelFactory.Set (n4, v4);
80}
81
82void
84{
85 m_deviceFactory.Set (n1, v1);
86}
87
88void
90{
91 m_channelFactory.Set (n1, v1);
92}
93
94void
96{
97 m_pointToPointMode = pointToPointMode;
98}
99
100void
102{
103 m_enableFlowControl = false;
104}
105
108{
110 return Install (node, channel);
111}
112
115{
116 return NetDeviceContainer (InstallPriv (node, channel));
117}
118
121{
123
124 return Install (c, channel);
125}
126
129{
131
132 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
133 {
134 devs.Add (InstallPriv (*i, channel));
135 }
136
137 return devs;
138}
139
142{
144 device->SetAttribute ("PointToPointMode", BooleanValue (m_pointToPointMode));
145 device->SetAddress (Mac48Address::Allocate ());
146 node->AddDevice (device);
147 device->SetChannel (channel);
149 device->SetQueue (queue);
150 NS_ASSERT_MSG (!m_pointToPointMode || (channel->GetNDevices () <= 2), "Device set to PointToPoint and more than 2 devices on the channel.");
152 {
153 // Aggregate a NetDeviceQueueInterface object
154 Ptr<NetDeviceQueueInterface> ndqi = CreateObject<NetDeviceQueueInterface> ();
155 ndqi->GetTxQueue (0)->ConnectQueueTraces (queue);
156 device->AggregateObject (ndqi);
157 }
158 return device;
159}
160
161} // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:69
AttributeValue implementation for Boolean.
Definition: boolean.h:37
static Mac48Address Allocate(void)
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 Begin(void) const
Get an iterator which refers to the first Node in the container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
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
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 SetChannel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue())
Each net device must have a channel to pass packets through.
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 SetQueue(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue())
Each net device must have a queue to pass packets through.
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.
void DisableFlowControl(void)
Disable flow control only if you know what you are doing.
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:88
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Every class exported by the ns3 library is enclosed in the ns3 namespace.
channel
Definition: third.py:92