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 * SPDX-License-Identifier: GPL-2.0-only
7 *
8 * Created on: 9-Oct-2008
9 * Author: Leonard Tracy <lentracy@u.washington.edu>
10 *
11 *
12 */
13
14#include "uan-helper.h"
15
16#include "ns3/config.h"
17#include "ns3/log.h"
18#include "ns3/mobility-model.h"
19#include "ns3/simulator.h"
20#include "ns3/uan-channel.h"
21#include "ns3/uan-mac.h"
22#include "ns3/uan-net-device.h"
23#include "ns3/uan-noise-model-default.h"
24#include "ns3/uan-phy.h"
25#include "ns3/uan-prop-model-ideal.h"
26#include "ns3/uan-prop-model.h"
27#include "ns3/uan-transducer.h"
28#include "ns3/uan-tx-mode.h"
29
30#include <sstream>
31#include <string>
32
33namespace ns3
34{
35
36NS_LOG_COMPONENT_DEFINE("UanHelper");
37
38/**
39 * Ascii trace callback on Phy transmit events.
40 *
41 * \param os The output stream.
42 * \param context The node and device ids.
43 * \param packet The transmitted packet.
44 * \param txPowerDb The transmission power.
45 * \param mode The transmission mode.
46 */
47static void
48AsciiPhyTxEvent(std::ostream* os,
49 std::string context,
50 Ptr<const Packet> packet,
51 double txPowerDb [[maybe_unused]],
52 UanTxMode mode [[maybe_unused]])
53{
54 *os << "+ " << Simulator::Now().GetSeconds() << " " << context << " " << *packet << std::endl;
55}
56
57/**
58 * Ascii trace callback on successful packet reception.
59 *
60 * \param os The output stream.
61 * \param context The node and device ids.
62 * \param packet The received packet.
63 * \param snr The received signal to noise ratio.
64 * \param mode The channel transmission mode.
65 */
66static void
67AsciiPhyRxOkEvent(std::ostream* os,
68 std::string context,
69 Ptr<const Packet> packet,
70 double snr [[maybe_unused]],
71 UanTxMode mode [[maybe_unused]])
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
86
87void
88UanHelper::EnableAscii(std::ostream& os, uint32_t nodeid, uint32_t deviceid)
89{
91 std::ostringstream oss;
92
93 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/RxOk";
95
96 oss.str("");
97
98 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::UanNetDevice/Phy/Tx";
100}
101
102void
104{
105 for (auto i = d.Begin(); i != d.End(); ++i)
106 {
107 Ptr<NetDevice> dev = *i;
108 EnableAscii(os, dev->GetNode()->GetId(), dev->GetIfIndex());
109 }
110}
111
112void
114{
116 for (auto i = n.Begin(); i != n.End(); ++i)
117 {
118 Ptr<Node> node = *i;
119 for (uint32_t j = 0; j < node->GetNDevices(); ++j)
120 {
121 devs.Add(node->GetDevice(j));
122 }
123 }
124 EnableAscii(os, devs);
125}
126
127void
129{
131}
132
135{
138 channel->SetPropagationModel(CreateObject<UanPropModelIdeal>());
139 channel->SetNoiseModel(noise);
140
141 return Install(c, channel);
142}
143
146{
147 NetDeviceContainer devices;
148 for (auto i = c.Begin(); i != c.End(); i++)
149 {
150 Ptr<Node> node = *i;
151
152 Ptr<UanNetDevice> device = Install(node, channel);
153
154 devices.Add(device);
155 NS_LOG_DEBUG("node=" << node << ", mob=" << node->GetObject<MobilityModel>());
156 }
157 return devices;
158}
159
162{
164
168
169 mac->SetAddress(Mac8Address::Allocate());
170 device->SetMac(mac);
171 device->SetPhy(phy);
172 device->SetTransducer(trans);
173 device->SetChannel(channel);
174
175 node->AddDevice(device);
176
177 return device;
178}
179
180int64_t
182{
183 int64_t currentStream = stream;
184 Ptr<NetDevice> netDevice;
185 for (auto i = c.Begin(); i != c.End(); ++i)
186 {
187 netDevice = (*i);
189 if (uan)
190 {
191 currentStream += uan->GetPhy()->AssignStreams(currentStream);
192 currentStream += uan->GetMac()->AssignStreams(currentStream);
193 }
194 }
195 return (currentStream - stream);
196}
197
198} // end namespace ns3
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
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:585
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
ObjectFactory m_phy
The PHY layer.
Definition uan-helper.h:176
ObjectFactory m_transducer
The transducer.
Definition uan-helper.h:177
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:88
ObjectFactory m_mac
The MAC layer.
Definition uan-helper.h:175
NetDeviceContainer Install(NodeContainer c) const
This method creates a simple ns3::UanChannel (with a default ns3::UanNoiseModelDefault and ns3::UanPr...
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
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...
UanHelper()
Default constructor.
Definition uan-helper.cc:76
virtual ~UanHelper()
Destructor.
Definition uan-helper.cc:83
Virtual base class for all UAN MAC protocols.
Definition uan-mac.h:35
Base class for UAN Phy models.
Definition uan-phy.h:167
Virtual base for Transducer objects.
Abstraction of packet modulation information.
Definition uan-tx-mode.h:32
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:967
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Definition callback.h:745
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
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:67
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
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:48