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 
44 namespace ns3 {
45 
46 NS_LOG_COMPONENT_DEFINE ("UanHelper");
47 
57 static void AsciiPhyTxEvent (std::ostream *os, std::string context,
58  Ptr<const Packet> packet, double txPowerDb, UanTxMode mode)
59 {
60  NS_UNUSED (txPowerDb);
61  *os << "+ " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
62 }
63 
73 static void AsciiPhyRxOkEvent (std::ostream *os, std::string context,
74  Ptr<const Packet> packet, double snr, UanTxMode mode)
75 {
76  NS_UNUSED (snr);
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 
94 void
95 UanHelper::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 
117 void
118 UanHelper::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 
141 void
142 UanHelper::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 
165 void
166 UanHelper::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";
177  Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, &os));
178 }
179 
180 void
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 
190 void
192 {
193  NetDeviceContainer devs;
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 
205 void
206 UanHelper::EnableAsciiAll (std::ostream &os)
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 
258 int64_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
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::Node::GetId
uint32_t GetId(void) const
Definition: node.cc:109
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::UanHelper::UanHelper
UanHelper()
Default constructor.
Definition: uan-helper.cc:80
ns3::UanHelper::SetMac
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
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
ns3::Packet::EnablePrinting
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:572
ns3::AttributeValue
Hold a value for an Attribute.
Definition: attribute.h:69
third.channel
channel
Definition: third.py:92
ns3::NodeContainer::GetGlobal
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Definition: node-container.cc:134
ns3::Mac8Address::Allocate
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
Definition: mac8-address.cc:92
ns3::UanHelper::~UanHelper
virtual ~UanHelper()
Destructor.
Definition: uan-helper.cc:88
third.mac
mac
Definition: third.py:99
first.devices
devices
Definition: first.py:39
ns3::UanPhy
Base class for UAN Phy models.
Definition: uan-phy.h:179
ns3::UanHelper::EnableAsciiAll
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
ns3::Ptr< const Packet >
ns3::AsciiPhyRxOkEvent
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
ns3::NetDeviceContainer::Begin
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
Definition: net-device-container.cc:46
ns3::NodeContainer::Begin
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Definition: node-container.cc:77
uan-helper.h
ns3::AsciiPhyTxEvent
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
ns3::NetDevice::GetNode
virtual Ptr< Node > GetNode(void) const =0
ns3::UanHelper::m_mac
ObjectFactory m_mac
The MAC layer.
Definition: uan-helper.h:250
ns3::Node::GetDevice
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:144
NS_UNUSED
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
ns3::ObjectFactory
Instantiate subclasses of ns3::Object.
Definition: object-factory.h:48
ns3::UanTxMode
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:42
ns3::Node::AddDevice
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
ns3::NetDeviceContainer::End
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
Definition: net-device-container.cc:51
ns3::UanHelper::AssignStreams
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
ns3::NetDeviceContainer::Iterator
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
Definition: net-device-container.h:45
ns3::NodeContainer::Iterator
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Definition: node-container.h:42
ns3::Config::Connect
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::UanMac
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:50
ns3::MakeBoundCallback
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1703
ns3::ObjectFactory::Set
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Definition: object-factory.h:223
ns3::UanHelper::m_phy
ObjectFactory m_phy
The PHY layer.
Definition: uan-helper.h:251
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition: mobility-model.h:40
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
ns3::UanHelper::EnableAscii
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
ns3::NodeContainer::End
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Definition: node-container.cc:82
ns3::ObjectFactory::SetTypeId
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Definition: object-factory.cc:40
ns3::ObjectFactory::Create
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Definition: object-factory.cc:98
ns3::Node::GetNDevices
uint32_t GetNDevices(void) const
Definition: node.cc:152
ns3::UanHelper::SetTransducer
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
ns3::UanTransducer
Virtual base for Transducer objects.
Definition: uan-transducer.h:139
ns3::UanHelper::Install
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
ns3::NetDevice::GetIfIndex
virtual uint32_t GetIfIndex(void) const =0
ns3::NetDeviceContainer::Add
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Definition: net-device-container.cc:67
ns3::Time::GetSeconds
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:380
sample-rng-plot.n
n
Definition: sample-rng-plot.py:37
ns3::UanHelper::m_transducer
ObjectFactory m_transducer
The transducer.
Definition: uan-helper.h:252
third.phy
phy
Definition: third.py:93
ns3::UanHelper::SetPhy
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