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/simple-net-device.h"
27 #include "ns3/simple-channel.h"
28 #include "ns3/config.h"
29 #include "ns3/packet.h"
30 #include "ns3/names.h"
31 #include "ns3/boolean.h"
32 
33 #include "ns3/trace-helper.h"
35 
36 #include <string>
37 
38 namespace ns3 {
39 
40 NS_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;
48 }
49 
50 void
52  std::string n1, const AttributeValue &v1,
53  std::string n2, const AttributeValue &v2,
54  std::string n3, const AttributeValue &v3,
55  std::string n4, const AttributeValue &v4)
56 {
58 
60  m_queueFactory.Set (n1, v1);
61  m_queueFactory.Set (n2, v2);
62  m_queueFactory.Set (n3, v3);
63  m_queueFactory.Set (n4, v4);
64 }
65 
66 void
68  std::string n1, const AttributeValue &v1,
69  std::string n2, const AttributeValue &v2,
70  std::string n3, const AttributeValue &v3,
71  std::string n4, const AttributeValue &v4)
72 {
74  m_channelFactory.Set (n1, v1);
75  m_channelFactory.Set (n2, v2);
76  m_channelFactory.Set (n3, v3);
77  m_channelFactory.Set (n4, v4);
78 }
79 
80 void
82 {
83  m_deviceFactory.Set (n1, v1);
84 }
85 
86 void
88 {
89  m_channelFactory.Set (n1, v1);
90 }
91 
92 void
94 {
95  m_pointToPointMode = pointToPointMode;
96 }
97 
100 {
102  return Install (node, channel);
103 }
104 
107 {
108  return NetDeviceContainer (InstallPriv (node, channel));
109 }
110 
113 {
115 
116  return Install (c, channel);
117 }
118 
121 {
122  NetDeviceContainer devs;
123 
124  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
125  {
126  devs.Add (InstallPriv (*i, channel));
127  }
128 
129  return devs;
130 }
131 
134 {
136  device->SetAttribute ("PointToPointMode", BooleanValue (m_pointToPointMode));
137  device->SetAddress (Mac48Address::Allocate ());
138  node->AddDevice (device);
139  device->SetChannel (channel);
141  device->SetQueue (queue);
142  NS_ASSERT_MSG (!m_pointToPointMode || (channel->GetNDevices () <= 2), "Device set to PointToPoint and more than 2 devices on the channel.");
143  return device;
144 }
145 
146 } // namespace ns3
tuple channel
Definition: third.py:85
ObjectFactory m_deviceFactory
NetDevice factory.
AttributeValue implementation for Boolean.
Definition: boolean.h:36
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Hold a value for an Attribute.
Definition: attribute.h:68
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
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:104
NS_ASSERT_MSG(false,"Ipv4AddressGenerator::MaskToIndex(): Impossible")
static Mac48Address Allocate(void)
Allocate a new Mac48Address.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
This device assumes 48-bit mac addressing; there is also the possibility to add an ErrorModel if you ...
holds a vector of ns3::NetDevice pointers
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
ObjectFactory m_channelFactory
Channel factory.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
SimpleNetDeviceHelper()
Construct a SimpleNetDeviceHelper.
ObjectFactory m_queueFactory
Queue factory.
bool m_pointToPointMode
Install PointToPoint SimpleNetDevice or Broadcast ones.
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
Ptr< NetDevice > InstallPriv(Ptr< Node > node, Ptr< SimpleChannel > channel) const
This method creates an ns3::SimpleNetDevice with the attributes configured by 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.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:128
A simple channel, for simple things and testing.
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.