A Discrete-Event Network Simulator
API
uan-helper.cc
Go to the documentation of this file.
1 /*
2  * uan-helper.cc
3  *
4  * Copyright (c) 2008 University of Washington
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Created on: 9-Oct-2008
20  * Author: Leonard Tracy <lentracy@u.washington.edu>
21  *
22  *
23  */
24 
25 #include "uan-helper.h"
26 #include "ns3/uan-net-device.h"
27 #include "ns3/uan-mac.h"
28 #include "ns3/uan-phy.h"
29 #include "ns3/uan-channel.h"
30 #include "ns3/uan-prop-model.h"
31 #include "ns3/uan-prop-model-ideal.h"
32 #include "ns3/uan-transducer.h"
33 #include "ns3/mobility-model.h"
34 #include "ns3/log.h"
35 #include "ns3/uan-tx-mode.h"
36 #include "ns3/config.h"
37 #include "ns3/simulator.h"
38 #include "ns3/uan-noise-model-default.h"
39 
40 #include <sstream>
41 #include <string>
42 
43 namespace ns3 {
44 
45 NS_LOG_COMPONENT_DEFINE ("UanHelper");
46 
56 static void AsciiPhyTxEvent (std::ostream *os, std::string context,
57  Ptr<const Packet> packet, double txPowerDb, UanTxMode mode)
58 {
59  *os << "+ " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
60 }
61 
71 static void AsciiPhyRxOkEvent (std::ostream *os, std::string context,
72  Ptr<const Packet> packet, double snr, UanTxMode mode)
73 {
74  *os << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
75 }
76 
78 {
79  m_mac.SetTypeId ("ns3::UanMacAloha");
80  m_phy.SetTypeId ("ns3::UanPhyGen");
81  m_transducer.SetTypeId ("ns3::UanTransducerHd");
82 
83 }
84 
86 {
87 
88 }
89 
90 
91 void
92 UanHelper::SetMac (std::string macType,
93  std::string n0, const AttributeValue &v0,
94  std::string n1, const AttributeValue &v1,
95  std::string n2, const AttributeValue &v2,
96  std::string n3, const AttributeValue &v3,
97  std::string n4, const AttributeValue &v4,
98  std::string n5, const AttributeValue &v5,
99  std::string n6, const AttributeValue &v6,
100  std::string n7, const AttributeValue &v7)
101 {
102  m_mac = ObjectFactory ();
103  m_mac.SetTypeId (macType);
104  m_mac.Set (n0, v0);
105  m_mac.Set (n1, v1);
106  m_mac.Set (n2, v2);
107  m_mac.Set (n3, v3);
108  m_mac.Set (n4, v4);
109  m_mac.Set (n5, v5);
110  m_mac.Set (n6, v6);
111  m_mac.Set (n7, v7);
112 }
113 
114 void
115 UanHelper::SetPhy (std::string phyType,
116  std::string n0, const AttributeValue &v0,
117  std::string n1, const AttributeValue &v1,
118  std::string n2, const AttributeValue &v2,
119  std::string n3, const AttributeValue &v3,
120  std::string n4, const AttributeValue &v4,
121  std::string n5, const AttributeValue &v5,
122  std::string n6, const AttributeValue &v6,
123  std::string n7, const AttributeValue &v7)
124 {
125  m_phy = ObjectFactory ();
126  m_phy.SetTypeId (phyType);
127  m_phy.Set (n0, v0);
128  m_phy.Set (n1, v1);
129  m_phy.Set (n2, v2);
130  m_phy.Set (n3, v3);
131  m_phy.Set (n4, v4);
132  m_phy.Set (n5, v5);
133  m_phy.Set (n6, v6);
134  m_phy.Set (n7, v7);
135 
136 }
137 
138 void
139 UanHelper::SetTransducer (std::string type,
140  std::string n0, const AttributeValue &v0,
141  std::string n1, const AttributeValue &v1,
142  std::string n2, const AttributeValue &v2,
143  std::string n3, const AttributeValue &v3,
144  std::string n4, const AttributeValue &v4,
145  std::string n5, const AttributeValue &v5,
146  std::string n6, const AttributeValue &v6,
147  std::string n7, const AttributeValue &v7)
148 {
150  m_transducer.SetTypeId (type);
151  m_transducer.Set (n0, v0);
152  m_transducer.Set (n1, v1);
153  m_transducer.Set (n2, v2);
154  m_transducer.Set (n3, v3);
155  m_transducer.Set (n4, v4);
156  m_transducer.Set (n5, v5);
157  m_transducer.Set (n6, v6);
158  m_transducer.Set (n7, v7);
159 
160 }
161 
162 void
163 UanHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
164 {
166  std::ostringstream oss;
167 
168  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/RxOk";
170 
171  oss.str ("");
172 
173  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/Tx";
174  Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, &os));
175 }
176 
177 void
179 {
180  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
181  {
182  Ptr<NetDevice> dev = *i;
183  EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
184  }
185 }
186 
187 void
189 {
190  NetDeviceContainer devs;
191  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
192  {
193  Ptr<Node> node = *i;
194  for (uint32_t j = 0; j < node->GetNDevices (); ++j)
195  {
196  devs.Add (node->GetDevice (j));
197  }
198  }
199  EnableAscii (os, devs);
200 }
201 
202 void
203 UanHelper::EnableAsciiAll (std::ostream &os)
204 {
206 }
207 
210 {
211  Ptr<UanChannel> channel = CreateObject<UanChannel> ();
212  Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
213  channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
214  channel->SetNoiseModel (noise);
215 
216  return Install (c, channel);
217 }
218 
221 {
223  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
224  {
225  Ptr<Node> node = *i;
226 
227  Ptr<UanNetDevice> device = Install (node, channel);
228 
229  devices.Add (device);
230  NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
231  }
232  return devices;
233 }
234 
237 {
238  Ptr<UanNetDevice> device = CreateObject<UanNetDevice> ();
239 
240  Ptr<UanMac> mac = m_mac.Create<UanMac> ();
241  Ptr<UanPhy> phy = m_phy.Create<UanPhy> ();
243 
244  mac->SetAddress (UanAddress::Allocate ());
245  device->SetMac (mac);
246  device->SetPhy (phy);
247  device->SetTransducer (trans);
248  device->SetChannel (channel);
249 
250  node->AddDevice (device);
251 
252  return device;
253 }
254 
255 int64_t
257 {
258  int64_t currentStream = stream;
259  Ptr<NetDevice> netDevice;
260  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
261  {
262  netDevice = (*i);
263  Ptr<UanNetDevice> uan = DynamicCast<UanNetDevice> (netDevice);
264  if (uan)
265  {
266  currentStream += uan->GetPhy ()->AssignStreams (currentStream);
267  currentStream += uan->GetMac ()->AssignStreams (currentStream);
268  }
269  }
270  return (currentStream - stream);
271 }
272 
273 } // end namespace ns3
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:85
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
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:1487
UanHelper()
Defalt constructor.
Definition: uan-helper.cc:77
#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.
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:738
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:327
ObjectFactory m_transducer
The transducer.
Definition: uan-helper.h:251
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:48
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:547
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:92
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:139
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:249
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:256
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:134
Virtual base for Transducer objects.
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:163
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:71
uint32_t GetNDevices(void) const
Definition: node.cc:142
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:223
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:203
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:56
Instantiate subclasses of ns3::Object.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:120
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:236
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:209
ObjectFactory m_phy
The PHY layer.
Definition: uan-helper.h:250
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
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:115