A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
27#include "ns3/config.h"
28#include "ns3/log.h"
29#include "ns3/mobility-model.h"
30#include "ns3/simulator.h"
31#include "ns3/uan-channel.h"
32#include "ns3/uan-mac.h"
33#include "ns3/uan-net-device.h"
34#include "ns3/uan-noise-model-default.h"
35#include "ns3/uan-phy.h"
36#include "ns3/uan-prop-model-ideal.h"
37#include "ns3/uan-prop-model.h"
38#include "ns3/uan-transducer.h"
39#include "ns3/uan-tx-mode.h"
40
41#include <sstream>
42#include <string>
43
44namespace ns3
45{
46
47NS_LOG_COMPONENT_DEFINE("UanHelper");
48
49/**
50 * Ascii trace callback on Phy transmit events.
51 *
52 * \param os The output stream.
53 * \param context The node and device ids.
54 * \param packet The transmitted packet.
55 * \param txPowerDb The transmission power.
56 * \param mode The transmission mode.
57 */
58static void
59AsciiPhyTxEvent(std::ostream* os,
60 std::string context,
61 Ptr<const Packet> packet,
62 double txPowerDb [[maybe_unused]],
63 UanTxMode mode [[maybe_unused]])
64{
65 *os << "+ " << Simulator::Now().GetSeconds() << " " << context << " " << *packet << std::endl;
66}
67
68/**
69 * Ascii trace callback on successful packet reception.
70 *
71 * \param os The output stream.
72 * \param context The node and device ids.
73 * \param packet The received packet.
74 * \param snr The received signal to noise ratio.
75 * \param mode The channel transmission mode.
76 */
77static void
78AsciiPhyRxOkEvent(std::ostream* os,
79 std::string context,
80 Ptr<const Packet> packet,
81 double snr [[maybe_unused]],
82 UanTxMode mode [[maybe_unused]])
83{
84 *os << "r " << Simulator::Now().GetSeconds() << " " << context << " " << *packet << std::endl;
85}
86
88{
89 m_mac.SetTypeId("ns3::UanMacAloha");
90 m_phy.SetTypeId("ns3::UanPhyGen");
91 m_transducer.SetTypeId("ns3::UanTransducerHd");
92}
93
95{
96}
97
98void
99UanHelper::EnableAscii(std::ostream& os, uint32_t nodeid, uint32_t deviceid)
100{
102 std::ostringstream oss;
103
104 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/RxOk";
106
107 oss.str("");
108
109 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/Tx";
111}
112
113void
115{
116 for (auto i = d.Begin(); i != d.End(); ++i)
117 {
118 Ptr<NetDevice> dev = *i;
119 EnableAscii(os, dev->GetNode()->GetId(), dev->GetIfIndex());
120 }
121}
122
123void
125{
127 for (auto i = n.Begin(); i != n.End(); ++i)
128 {
129 Ptr<Node> node = *i;
130 for (uint32_t j = 0; j < node->GetNDevices(); ++j)
131 {
132 devs.Add(node->GetDevice(j));
133 }
134 }
135 EnableAscii(os, devs);
136}
137
138void
140{
142}
143
146{
147 Ptr<UanChannel> channel = CreateObject<UanChannel>();
148 Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault>();
149 channel->SetPropagationModel(CreateObject<UanPropModelIdeal>());
150 channel->SetNoiseModel(noise);
151
152 return Install(c, channel);
153}
154
157{
158 NetDeviceContainer devices;
159 for (auto i = c.Begin(); i != c.End(); i++)
160 {
161 Ptr<Node> node = *i;
162
163 Ptr<UanNetDevice> device = Install(node, channel);
164
165 devices.Add(device);
166 NS_LOG_DEBUG("node=" << node << ", mob=" << node->GetObject<MobilityModel>());
167 }
168 return devices;
169}
170
173{
174 Ptr<UanNetDevice> device = CreateObject<UanNetDevice>();
175
179
180 mac->SetAddress(Mac8Address::Allocate());
181 device->SetMac(mac);
182 device->SetPhy(phy);
183 device->SetTransducer(trans);
184 device->SetChannel(channel);
185
186 node->AddDevice(device);
187
188 return device;
189}
190
191int64_t
193{
194 int64_t currentStream = stream;
195 Ptr<NetDevice> netDevice;
196 for (auto i = c.Begin(); i != c.End(); ++i)
197 {
198 netDevice = (*i);
199 Ptr<UanNetDevice> uan = DynamicCast<UanNetDevice>(netDevice);
200 if (uan)
201 {
202 currentStream += uan->GetPhy()->AssignStreams(currentStream);
203 currentStream += uan->GetMac()->AssignStreams(currentStream);
204 }
205 }
206 return (currentStream - stream);
207}
208
209} // end namespace ns3
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
Definition: mac8-address.cc:94
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
Iterator Begin() 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.
Iterator End() const
Get an iterator which indicates past-the-last NetDevice in the container.
keep track of a set of node pointers.
Iterator End() 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 ...
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Object > Create() 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.
static void EnablePrinting()
Enable printing packets metadata.
Definition: packet.cc:596
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
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:99
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:145
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:192
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:139
UanHelper()
Default constructor.
Definition: uan-helper.cc:87
virtual ~UanHelper()
Destructor.
Definition: uan-helper.cc:94
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:46
Base class for UAN Phy models.
Definition: uan-phy.h:178
Virtual base for Transducer objects.
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:43
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:978
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Definition: callback.h:767
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:78
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:59