A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("UanHelper");
44 namespace ns3 {
45 
55 static void AsciiPhyTxEvent (std::ostream *os, std::string context,
56  Ptr<const Packet> packet, double txPowerDb, UanTxMode mode)
57 {
58  *os << "+ " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
59 }
60 
70 static void AsciiPhyRxOkEvent (std::ostream *os, std::string context,
71  Ptr<const Packet> packet, double snr, UanTxMode mode)
72 {
73  *os << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
74 }
75 
77 {
78  m_mac.SetTypeId ("ns3::UanMacAloha");
79  m_phy.SetTypeId ("ns3::UanPhyGen");
80  m_transducer.SetTypeId ("ns3::UanTransducerHd");
81 
82 }
83 
85 {
86 
87 }
88 
89 
90 void
91 UanHelper::SetMac (std::string macType,
92  std::string n0, const AttributeValue &v0,
93  std::string n1, const AttributeValue &v1,
94  std::string n2, const AttributeValue &v2,
95  std::string n3, const AttributeValue &v3,
96  std::string n4, const AttributeValue &v4,
97  std::string n5, const AttributeValue &v5,
98  std::string n6, const AttributeValue &v6,
99  std::string n7, const AttributeValue &v7)
100 {
101  m_mac = ObjectFactory ();
102  m_mac.SetTypeId (macType);
103  m_mac.Set (n0, v0);
104  m_mac.Set (n1, v1);
105  m_mac.Set (n2, v2);
106  m_mac.Set (n3, v3);
107  m_mac.Set (n4, v4);
108  m_mac.Set (n5, v5);
109  m_mac.Set (n6, v6);
110  m_mac.Set (n7, v7);
111 }
112 
113 void
114 UanHelper::SetPhy (std::string phyType,
115  std::string n0, const AttributeValue &v0,
116  std::string n1, const AttributeValue &v1,
117  std::string n2, const AttributeValue &v2,
118  std::string n3, const AttributeValue &v3,
119  std::string n4, const AttributeValue &v4,
120  std::string n5, const AttributeValue &v5,
121  std::string n6, const AttributeValue &v6,
122  std::string n7, const AttributeValue &v7)
123 {
124  m_phy = ObjectFactory ();
125  m_phy.SetTypeId (phyType);
126  m_phy.Set (n0, v0);
127  m_phy.Set (n1, v1);
128  m_phy.Set (n2, v2);
129  m_phy.Set (n3, v3);
130  m_phy.Set (n4, v4);
131  m_phy.Set (n5, v5);
132  m_phy.Set (n6, v6);
133  m_phy.Set (n7, v7);
134 
135 }
136 
137 void
138 UanHelper::SetTransducer (std::string type,
139  std::string n0, const AttributeValue &v0,
140  std::string n1, const AttributeValue &v1,
141  std::string n2, const AttributeValue &v2,
142  std::string n3, const AttributeValue &v3,
143  std::string n4, const AttributeValue &v4,
144  std::string n5, const AttributeValue &v5,
145  std::string n6, const AttributeValue &v6,
146  std::string n7, const AttributeValue &v7)
147 {
149  m_transducer.SetTypeId (type);
150  m_transducer.Set (n0, v0);
151  m_transducer.Set (n1, v1);
152  m_transducer.Set (n2, v2);
153  m_transducer.Set (n3, v3);
154  m_transducer.Set (n4, v4);
155  m_transducer.Set (n5, v5);
156  m_transducer.Set (n6, v6);
157  m_transducer.Set (n7, v7);
158 
159 }
160 
161 void
162 UanHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
163 {
165  std::ostringstream oss;
166 
167  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/RxOk";
169 
170  oss.str ("");
171 
172  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/Tx";
173  Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, &os));
174 }
175 
176 void
178 {
179  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
180  {
181  Ptr<NetDevice> dev = *i;
182  EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
183  }
184 }
185 
186 void
188 {
189  NetDeviceContainer devs;
190  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
191  {
192  Ptr<Node> node = *i;
193  for (uint32_t j = 0; j < node->GetNDevices (); ++j)
194  {
195  devs.Add (node->GetDevice (j));
196  }
197  }
198  EnableAscii (os, devs);
199 }
200 
201 void
202 UanHelper::EnableAsciiAll (std::ostream &os)
203 {
205 }
206 
209 {
210  Ptr<UanChannel> channel = CreateObject<UanChannel> ();
211  Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
212  channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
213  channel->SetNoiseModel (noise);
214 
215  return Install (c, channel);
216 }
217 
220 {
222  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
223  {
224  Ptr<Node> node = *i;
225 
226  Ptr<UanNetDevice> device = Install (node, channel);
227 
228  devices.Add (device);
229  NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
230  }
231  return devices;
232 }
233 
236 {
237  Ptr<UanNetDevice> device = CreateObject<UanNetDevice> ();
238 
239  Ptr<UanMac> mac = m_mac.Create<UanMac> ();
240  Ptr<UanPhy> phy = m_phy.Create<UanPhy> ();
242 
243  mac->SetAddress (UanAddress::Allocate ());
244  device->SetMac (mac);
245  device->SetPhy (phy);
246  device->SetTransducer (trans);
247  device->SetChannel (channel);
248 
249  node->AddDevice (device);
250 
251  return device;
252 }
253 
254 int64_t
256 {
257  int64_t currentStream = stream;
258  Ptr<NetDevice> netDevice;
259  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
260  {
261  netDevice = (*i);
262  Ptr<UanNetDevice> uan = DynamicCast<UanNetDevice> (netDevice);
263  if (uan)
264  {
265  currentStream += uan->GetPhy ()->AssignStreams (currentStream);
266  currentStream += uan->GetMac ()->AssignStreams (currentStream);
267  }
268  }
269  return (currentStream - stream);
270 }
271 
272 } // 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:84
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Hold a value for an Attribute.
Definition: attribute.h:56
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Build bound Callbacks which take varying numbers of arguments, and potentially returning a value...
Definition: callback.h:1467
UanHelper()
Defalt constructor.
Definition: uan-helper.cc:76
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
void SetTypeId(TypeId tid)
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:728
Keep track of the current position and velocity of an object.
double GetSeconds(void) const
Definition: nstime.h:272
ObjectFactory m_transducer
The transducer.
Definition: uan-helper.h:251
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:47
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:552
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:91
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:138
Ptr< Object > Create(void) const
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:255
Ptr< NetDevice > GetDevice(uint32_t index) const
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:162
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:70
uint32_t GetNDevices(void) const
Definition: node.cc:142
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)
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
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:202
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:55
instantiate subclasses of ns3::Object.
uint32_t AddDevice(Ptr< NetDevice > device)
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:213
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:208
ObjectFactory m_phy
The PHY layer.
Definition: uan-helper.h:250
Ptr< T > GetObject(void) const
Definition: object.h:362
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:114