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::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
96{
98 std::ostringstream oss;
99
100 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/RxOk";
102
103 oss.str ("");
104
105 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/Tx";
107}
108
109void
111{
112 for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
113 {
114 Ptr<NetDevice> dev = *i;
115 EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
116 }
117}
118
119void
121{
123 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
124 {
125 Ptr<Node> node = *i;
126 for (uint32_t j = 0; j < node->GetNDevices (); ++j)
127 {
128 devs.Add (node->GetDevice (j));
129 }
130 }
131 EnableAscii (os, devs);
132}
133
134void
136{
138}
139
142{
143 Ptr<UanChannel> channel = CreateObject<UanChannel> ();
144 Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
145 channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
146 channel->SetNoiseModel (noise);
147
148 return Install (c, channel);
149}
150
153{
155 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
156 {
157 Ptr<Node> node = *i;
158
159 Ptr<UanNetDevice> device = Install (node, channel);
160
161 devices.Add (device);
162 NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
163 }
164 return devices;
165}
166
169{
170 Ptr<UanNetDevice> device = CreateObject<UanNetDevice> ();
171
175
176 mac->SetAddress (Mac8Address::Allocate ());
177 device->SetMac (mac);
178 device->SetPhy (phy);
179 device->SetTransducer (trans);
180 device->SetChannel (channel);
181
182 node->AddDevice (device);
183
184 return device;
185}
186
187int64_t
189{
190 int64_t currentStream = stream;
191 Ptr<NetDevice> netDevice;
192 for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
193 {
194 netDevice = (*i);
195 Ptr<UanNetDevice> uan = DynamicCast<UanNetDevice> (netDevice);
196 if (uan)
197 {
198 currentStream += uan->GetPhy ()->AssignStreams (currentStream);
199 currentStream += uan->GetMac ()->AssignStreams (currentStream);
200 }
201 }
202 return (currentStream - stream);
203}
204
205} // end namespace ns3
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
Definition: mac8-address.cc:99
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.
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()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
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
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:380
ObjectFactory m_phy
The PHY layer.
Definition: uan-helper.h:187
ObjectFactory m_transducer
The transducer.
Definition: uan-helper.h:188
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:95
ObjectFactory m_mac
The MAC layer.
Definition: uan-helper.h:186
NetDeviceContainer Install(NodeContainer c) const
This method creates a simple ns3::UanChannel (with a default ns3::UanNoiseModelDefault and ns3::UanPr...
Definition: uan-helper.cc:141
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:188
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:135
UanHelper()
Default constructor.
Definition: uan-helper.cc:80
virtual ~UanHelper()
Destructor.
Definition: uan-helper.cc:88
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:206
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:274
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs... bargs)
Make Callbacks with varying number of bound arguments.
Definition: callback.h:714
devices
Definition: first.py:35
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:83
mac
Definition: third.py:87
phy
Definition: third.py:84