A Discrete-Event Network Simulator
API
uan-helper.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * uan-helper.cc
4 *
5 * Copyright (c) 2008 University of Washington
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation;
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Created on: 9-Oct-2008
21 * Author: Leonard Tracy <lentracy@u.washington.edu>
22 *
23 *
24 */
25
26#include "uan-helper.h"
27#include "ns3/uan-net-device.h"
28#include "ns3/uan-mac.h"
29#include "ns3/uan-phy.h"
30#include "ns3/uan-channel.h"
31#include "ns3/uan-prop-model.h"
32#include "ns3/uan-prop-model-ideal.h"
33#include "ns3/uan-transducer.h"
34#include "ns3/mobility-model.h"
35#include "ns3/log.h"
36#include "ns3/uan-tx-mode.h"
37#include "ns3/config.h"
38#include "ns3/simulator.h"
39#include "ns3/uan-noise-model-default.h"
40
41#include <sstream>
42#include <string>
43
44namespace ns3 {
45
46NS_LOG_COMPONENT_DEFINE ("UanHelper");
47
57static void AsciiPhyTxEvent (std::ostream *os, std::string context,
58 Ptr<const Packet> packet,
59 [[maybe_unused]] double txPowerDb, UanTxMode mode)
60{
61 *os << "+ " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
62}
63
73static void AsciiPhyRxOkEvent (std::ostream *os, std::string context,
74 Ptr<const Packet> packet,
75 [[maybe_unused]] double snr, UanTxMode mode)
76{
77 *os << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
78}
79
81{
82 m_mac.SetTypeId ("ns3::UanMacAloha");
83 m_phy.SetTypeId ("ns3::UanPhyGen");
84 m_transducer.SetTypeId ("ns3::UanTransducerHd");
85
86}
87
89{
90
91}
92
93
94void
95UanHelper::SetMac (std::string macType,
96 std::string n0, const AttributeValue &v0,
97 std::string n1, const AttributeValue &v1,
98 std::string n2, const AttributeValue &v2,
99 std::string n3, const AttributeValue &v3,
100 std::string n4, const AttributeValue &v4,
101 std::string n5, const AttributeValue &v5,
102 std::string n6, const AttributeValue &v6,
103 std::string n7, const AttributeValue &v7)
104{
105 m_mac = ObjectFactory ();
106 m_mac.SetTypeId (macType);
107 m_mac.Set (n0, v0);
108 m_mac.Set (n1, v1);
109 m_mac.Set (n2, v2);
110 m_mac.Set (n3, v3);
111 m_mac.Set (n4, v4);
112 m_mac.Set (n5, v5);
113 m_mac.Set (n6, v6);
114 m_mac.Set (n7, v7);
115}
116
117void
118UanHelper::SetPhy (std::string phyType,
119 std::string n0, const AttributeValue &v0,
120 std::string n1, const AttributeValue &v1,
121 std::string n2, const AttributeValue &v2,
122 std::string n3, const AttributeValue &v3,
123 std::string n4, const AttributeValue &v4,
124 std::string n5, const AttributeValue &v5,
125 std::string n6, const AttributeValue &v6,
126 std::string n7, const AttributeValue &v7)
127{
128 m_phy = ObjectFactory ();
129 m_phy.SetTypeId (phyType);
130 m_phy.Set (n0, v0);
131 m_phy.Set (n1, v1);
132 m_phy.Set (n2, v2);
133 m_phy.Set (n3, v3);
134 m_phy.Set (n4, v4);
135 m_phy.Set (n5, v5);
136 m_phy.Set (n6, v6);
137 m_phy.Set (n7, v7);
138
139}
140
141void
142UanHelper::SetTransducer (std::string type,
143 std::string n0, const AttributeValue &v0,
144 std::string n1, const AttributeValue &v1,
145 std::string n2, const AttributeValue &v2,
146 std::string n3, const AttributeValue &v3,
147 std::string n4, const AttributeValue &v4,
148 std::string n5, const AttributeValue &v5,
149 std::string n6, const AttributeValue &v6,
150 std::string n7, const AttributeValue &v7)
151{
153 m_transducer.SetTypeId (type);
154 m_transducer.Set (n0, v0);
155 m_transducer.Set (n1, v1);
156 m_transducer.Set (n2, v2);
157 m_transducer.Set (n3, v3);
158 m_transducer.Set (n4, v4);
159 m_transducer.Set (n5, v5);
160 m_transducer.Set (n6, v6);
161 m_transducer.Set (n7, v7);
162
163}
164
165void
166UanHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
167{
169 std::ostringstream oss;
170
171 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/RxOk";
173
174 oss.str ("");
175
176 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/Tx";
178}
179
180void
182{
183 for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
184 {
185 Ptr<NetDevice> dev = *i;
186 EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
187 }
188}
189
190void
192{
194 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
195 {
196 Ptr<Node> node = *i;
197 for (uint32_t j = 0; j < node->GetNDevices (); ++j)
198 {
199 devs.Add (node->GetDevice (j));
200 }
201 }
202 EnableAscii (os, devs);
203}
204
205void
207{
209}
210
213{
214 Ptr<UanChannel> channel = CreateObject<UanChannel> ();
215 Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
216 channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
217 channel->SetNoiseModel (noise);
218
219 return Install (c, channel);
220}
221
224{
226 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
227 {
228 Ptr<Node> node = *i;
229
230 Ptr<UanNetDevice> device = Install (node, channel);
231
232 devices.Add (device);
233 NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
234 }
235 return devices;
236}
237
240{
241 Ptr<UanNetDevice> device = CreateObject<UanNetDevice> ();
242
246
247 mac->SetAddress (Mac8Address::Allocate ());
248 device->SetMac (mac);
249 device->SetPhy (phy);
250 device->SetTransducer (trans);
251 device->SetChannel (channel);
252
253 node->AddDevice (device);
254
255 return device;
256}
257
258int64_t
260{
261 int64_t currentStream = stream;
262 Ptr<NetDevice> netDevice;
263 for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
264 {
265 netDevice = (*i);
266 Ptr<UanNetDevice> uan = DynamicCast<UanNetDevice> (netDevice);
267 if (uan)
268 {
269 currentStream += uan->GetPhy ()->AssignStreams (currentStream);
270 currentStream += uan->GetMac ()->AssignStreams (currentStream);
271 }
272 }
273 return (currentStream - stream);
274}
275
276} // end namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:69
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
Definition: mac8-address.cc:92
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
virtual uint32_t GetIfIndex(void) const =0
virtual Ptr< Node > GetNode(void) const =0
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.
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
uint32_t GetId(void) const
Definition: node.cc:109
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
uint32_t GetNDevices(void) const
Definition: node.cc:152
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:144
Instantiate subclasses of ns3::Object.
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.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:572
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
void SetMac(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), 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(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Set MAC attributes.
Definition: uan-helper.cc:95
ObjectFactory m_phy
The PHY layer.
Definition: uan-helper.h:251
ObjectFactory m_transducer
The transducer.
Definition: uan-helper.h:252
void SetPhy(std::string phyType, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), 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(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Set PHY attributes.
Definition: uan-helper.cc:118
static void EnableAscii(std::ostream &os, uint32_t nodeid, uint32_t deviceid)
Enable ascii output on the specified deviceid within the specified nodeid if it is of type ns3::UanNe...
Definition: uan-helper.cc:166
ObjectFactory m_mac
The MAC layer.
Definition: uan-helper.h:250
NetDeviceContainer Install(NodeContainer c) const
This method creates a simple ns3::UanChannel (with a default ns3::UanNoiseModelDefault and ns3::UanPr...
Definition: uan-helper.cc:212
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: uan-helper.cc:259
static void EnableAsciiAll(std::ostream &os)
Enable ascii output on each device which is of the ns3::UanNetDevice type and dump that to the specif...
Definition: uan-helper.cc:206
UanHelper()
Default constructor.
Definition: uan-helper.cc:80
virtual ~UanHelper()
Destructor.
Definition: uan-helper.cc:88
void SetTransducer(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), 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(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Set the transducer attributes.
Definition: uan-helper.cc:142
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:50
Base class for UAN Phy models.
Definition: uan-phy.h:179
Virtual base for Transducer objects.
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:42
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1709
devices
Definition: first.py:39
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static void AsciiPhyRxOkEvent(std::ostream *os, std::string context, Ptr< const Packet > packet, double snr, UanTxMode mode)
Ascii trace callback on successful packet reception.
Definition: uan-helper.cc:73
static void AsciiPhyTxEvent(std::ostream *os, std::string context, Ptr< const Packet > packet, double txPowerDb, UanTxMode mode)
Ascii trace callback on Phy transmit events.
Definition: uan-helper.cc:57
channel
Definition: third.py:92
mac
Definition: third.py:96
phy
Definition: third.py:93