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  *os << "+ " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
61 }
62 
72 static void AsciiPhyRxOkEvent (std::ostream *os, std::string context,
73  Ptr<const Packet> packet, double snr, UanTxMode mode)
74 {
75  *os << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
76 }
77 
79 {
80  m_mac.SetTypeId ("ns3::UanMacAloha");
81  m_phy.SetTypeId ("ns3::UanPhyGen");
82  m_transducer.SetTypeId ("ns3::UanTransducerHd");
83 
84 }
85 
87 {
88 
89 }
90 
91 
92 void
93 UanHelper::SetMac (std::string macType,
94  std::string n0, const AttributeValue &v0,
95  std::string n1, const AttributeValue &v1,
96  std::string n2, const AttributeValue &v2,
97  std::string n3, const AttributeValue &v3,
98  std::string n4, const AttributeValue &v4,
99  std::string n5, const AttributeValue &v5,
100  std::string n6, const AttributeValue &v6,
101  std::string n7, const AttributeValue &v7)
102 {
103  m_mac = ObjectFactory ();
104  m_mac.SetTypeId (macType);
105  m_mac.Set (n0, v0);
106  m_mac.Set (n1, v1);
107  m_mac.Set (n2, v2);
108  m_mac.Set (n3, v3);
109  m_mac.Set (n4, v4);
110  m_mac.Set (n5, v5);
111  m_mac.Set (n6, v6);
112  m_mac.Set (n7, v7);
113 }
114 
115 void
116 UanHelper::SetPhy (std::string phyType,
117  std::string n0, const AttributeValue &v0,
118  std::string n1, const AttributeValue &v1,
119  std::string n2, const AttributeValue &v2,
120  std::string n3, const AttributeValue &v3,
121  std::string n4, const AttributeValue &v4,
122  std::string n5, const AttributeValue &v5,
123  std::string n6, const AttributeValue &v6,
124  std::string n7, const AttributeValue &v7)
125 {
126  m_phy = ObjectFactory ();
127  m_phy.SetTypeId (phyType);
128  m_phy.Set (n0, v0);
129  m_phy.Set (n1, v1);
130  m_phy.Set (n2, v2);
131  m_phy.Set (n3, v3);
132  m_phy.Set (n4, v4);
133  m_phy.Set (n5, v5);
134  m_phy.Set (n6, v6);
135  m_phy.Set (n7, v7);
136 
137 }
138 
139 void
140 UanHelper::SetTransducer (std::string type,
141  std::string n0, const AttributeValue &v0,
142  std::string n1, const AttributeValue &v1,
143  std::string n2, const AttributeValue &v2,
144  std::string n3, const AttributeValue &v3,
145  std::string n4, const AttributeValue &v4,
146  std::string n5, const AttributeValue &v5,
147  std::string n6, const AttributeValue &v6,
148  std::string n7, const AttributeValue &v7)
149 {
151  m_transducer.SetTypeId (type);
152  m_transducer.Set (n0, v0);
153  m_transducer.Set (n1, v1);
154  m_transducer.Set (n2, v2);
155  m_transducer.Set (n3, v3);
156  m_transducer.Set (n4, v4);
157  m_transducer.Set (n5, v5);
158  m_transducer.Set (n6, v6);
159  m_transducer.Set (n7, v7);
160 
161 }
162 
163 void
164 UanHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
165 {
167  std::ostringstream oss;
168 
169  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/RxOk";
171 
172  oss.str ("");
173 
174  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/Tx";
175  Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, &os));
176 }
177 
178 void
180 {
181  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
182  {
183  Ptr<NetDevice> dev = *i;
184  EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
185  }
186 }
187 
188 void
190 {
191  NetDeviceContainer devs;
192  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
193  {
194  Ptr<Node> node = *i;
195  for (uint32_t j = 0; j < node->GetNDevices (); ++j)
196  {
197  devs.Add (node->GetDevice (j));
198  }
199  }
200  EnableAscii (os, devs);
201 }
202 
203 void
204 UanHelper::EnableAsciiAll (std::ostream &os)
205 {
207 }
208 
211 {
212  Ptr<UanChannel> channel = CreateObject<UanChannel> ();
213  Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
214  channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
215  channel->SetNoiseModel (noise);
216 
217  return Install (c, channel);
218 }
219 
222 {
224  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
225  {
226  Ptr<Node> node = *i;
227 
228  Ptr<UanNetDevice> device = Install (node, channel);
229 
230  devices.Add (device);
231  NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
232  }
233  return devices;
234 }
235 
238 {
239  Ptr<UanNetDevice> device = CreateObject<UanNetDevice> ();
240 
244 
245  mac->SetAddress (UanAddress::Allocate ());
246  device->SetMac (mac);
247  device->SetPhy (phy);
248  device->SetTransducer (trans);
249  device->SetChannel (channel);
250 
251  node->AddDevice (device);
252 
253  return device;
254 }
255 
256 int64_t
258 {
259  int64_t currentStream = stream;
260  Ptr<NetDevice> netDevice;
261  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
262  {
263  netDevice = (*i);
264  Ptr<UanNetDevice> uan = DynamicCast<UanNetDevice> (netDevice);
265  if (uan)
266  {
267  currentStream += uan->GetPhy ()->AssignStreams (currentStream);
268  currentStream += uan->GetMac ()->AssignStreams (currentStream);
269  }
270  }
271  return (currentStream - stream);
272 }
273 
274 } // end namespace ns3
tuple channel
Definition: third.py:85
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
tuple devices
Definition: first.py:32
virtual ~UanHelper()
Destructor.
Definition: uan-helper.cc:86
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Hold a value for an Attribute.
Definition: attribute.h:68
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1686
UanHelper()
Defalt constructor.
Definition: uan-helper.cc:78
#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.
Keep track of the current position and velocity of an object.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
ObjectFactory m_transducer
The transducer.
Definition: uan-helper.h:252
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:48
tuple phy
Definition: third.py:86
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:534
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:93
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:140
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.
ObjectFactory m_mac
The MAC layer.
Definition: uan-helper.h:250
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
holds a vector of ns3::NetDevice pointers
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:257
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:142
Virtual base for Transducer objects.
tuple mac
Definition: third.py:92
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:164
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:843
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:72
uint32_t GetNDevices(void) const
Definition: node.cc:150
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.
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
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:204
Base class for UAN Phy models.
Definition: uan-phy.h:175
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
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
Instantiate subclasses of ns3::Object.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:128
static UanAddress Allocate()
Allocates UanAddress from 0-254.
Definition: uan-address.cc:97
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
NetDeviceContainer Install(NodeContainer c) const
This method creates a simple ns3::UanChannel (with a default ns3::UanNoiseModelDefault and ns3::UanPr...
Definition: uan-helper.cc:210
ObjectFactory m_phy
The PHY layer.
Definition: uan-helper.h:251
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:116