A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-channel.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Leonard Tracy <lentracy@gmail.com>
7 */
8
9#include "uan-channel.h"
10
11#include "uan-net-device.h"
13#include "uan-phy.h"
15#include "uan-prop-model.h"
16#include "uan-transducer.h"
17#include "uan-tx-mode.h"
18
19#include "ns3/log.h"
20#include "ns3/mobility-model.h"
21#include "ns3/net-device.h"
22#include "ns3/node.h"
23#include "ns3/object.h"
24#include "ns3/packet.h"
25#include "ns3/pointer.h"
26#include "ns3/simulator.h"
27#include "ns3/string.h"
28
29namespace ns3
30{
31
32NS_LOG_COMPONENT_DEFINE("UanChannel");
33
35
36TypeId
38{
39 static TypeId tid = TypeId("ns3::UanChannel")
41 .SetGroupName("Uan")
42 .AddConstructor<UanChannel>()
43 .AddAttribute("PropagationModel",
44 "A pointer to the propagation model.",
45 StringValue("ns3::UanPropModelIdeal"),
48 .AddAttribute("NoiseModel",
49 "A pointer to the model of the channel ambient noise.",
50 StringValue("ns3::UanNoiseModelDefault"),
53
54 return tid;
55}
56
58 : Channel(),
59 m_prop(nullptr),
60 m_cleared(false)
61{
62}
63
67
68void
70{
71 if (m_cleared)
72 {
73 return;
74 }
75 m_cleared = true;
76 auto it = m_devList.begin();
77 for (; it != m_devList.end(); it++)
78 {
79 if (it->first)
80 {
81 it->first->Clear();
82 it->first = nullptr;
83 }
84 if (it->second)
85 {
86 it->second->Clear();
87 it->second = nullptr;
88 }
89 }
90 m_devList.clear();
91 if (m_prop)
92 {
93 m_prop->Clear();
94 m_prop = nullptr;
95 }
96 if (m_noise)
97 {
98 m_noise->Clear();
99 m_noise = nullptr;
100 }
101}
102
103void
109
110void
112{
113 NS_LOG_DEBUG("Set Prop Model " << this);
114 m_prop = prop;
115}
116
117std::size_t
119{
120 return m_devList.size();
121}
122
124UanChannel::GetDevice(std::size_t i) const
125{
126 return m_devList[i].first;
127}
128
129void
131{
132 NS_LOG_DEBUG("Adding dev/trans pair number " << m_devList.size());
133 m_devList.emplace_back(dev, trans);
134}
135
136void
137UanChannel::TxPacket(Ptr<UanTransducer> src, Ptr<Packet> packet, double txPowerDb, UanTxMode txMode)
138{
139 Ptr<MobilityModel> senderMobility = nullptr;
140
141 NS_LOG_DEBUG("Channel scheduling");
142 for (auto i = m_devList.begin(); i != m_devList.end(); i++)
143 {
144 if (src == i->second)
145 {
146 senderMobility = i->first->GetNode()->GetObject<MobilityModel>();
147 break;
148 }
149 }
150 NS_ASSERT(senderMobility);
151 uint32_t j = 0;
152 auto i = m_devList.begin();
153 for (; i != m_devList.end(); i++)
154 {
155 if (src != i->second)
156 {
157 NS_LOG_DEBUG("Scheduling " << i->first->GetMac()->GetAddress());
158 Ptr<MobilityModel> rcvrMobility = i->first->GetNode()->GetObject<MobilityModel>();
159 Time delay = m_prop->GetDelay(senderMobility, rcvrMobility, txMode);
160 UanPdp pdp = m_prop->GetPdp(senderMobility, rcvrMobility, txMode);
161 double rxPowerDb =
162 txPowerDb - m_prop->GetPathLossDb(senderMobility, rcvrMobility, txMode);
163
164 NS_LOG_DEBUG("txPowerDb="
165 << txPowerDb << "dB, rxPowerDb=" << rxPowerDb << "dB, distance="
166 << senderMobility->GetDistanceFrom(rcvrMobility) << "m, delay=" << delay);
167
168 uint32_t dstNodeId = i->first->GetNode()->GetId();
169 Ptr<Packet> copy = packet->Copy();
171 delay,
173 this,
174 j,
175 copy,
176 rxPowerDb,
177 txMode,
178 pdp);
179 }
180 j++;
181 }
182}
183
184void
186{
187 NS_ASSERT(noise);
188 m_noise = noise;
189}
190
191void
192UanChannel::SendUp(uint32_t i, Ptr<Packet> packet, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
193{
194 NS_LOG_DEBUG("Channel: In sendup");
195 m_devList[i].second->Receive(packet, rxPowerDb, txMode, pdp);
196}
197
198double
200{
202 double noise = m_noise->GetNoiseDbHz(fKhz);
203 return noise;
204}
205
206} // namespace ns3
Abstract Channel Base Class.
Definition channel.h:34
Keep track of the current position and velocity of an object.
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition simulator.h:577
Hold variables of type string.
Definition string.h:45
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Channel class used by UAN devices.
Definition uan-channel.h:36
void SetNoiseModel(Ptr< UanNoiseModel > noise)
Set the noise model this channel will use to determine ambient channel noise.
double GetNoiseDbHz(double fKhz)
Get the noise level on the channel.
void AddDevice(Ptr< UanNetDevice > dev, Ptr< UanTransducer > trans)
Adds device to receiver list for this channel.
UanChannel()
Constructor.
Ptr< UanPropModel > m_prop
The propagation model.
static TypeId GetTypeId()
Register this type.
Ptr< UanNoiseModel > m_noise
The noise model.
~UanChannel() override
Dummy destructor, see DoDispose.
void DoDispose() override
Destructor implementation.
virtual void TxPacket(Ptr< UanTransducer > src, Ptr< Packet > packet, double txPowerDb, UanTxMode txmode)
Send a packet out on the channel.
std::size_t GetNDevices() const override
bool m_cleared
Has Clear ever been called on the channel.
Ptr< NetDevice > GetDevice(std::size_t i) const override
UanDeviceList m_devList
The list of devices on this channel.
void SendUp(uint32_t i, Ptr< Packet > packet, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Send a packet up to the receiving UanTransducer.
void Clear()
Clear all pointer references.
void SetPropagationModel(Ptr< UanPropModel > prop)
Set the propagation model this channel will use for path loss/propagation delay.
The power delay profile returned by propagation models.
Abstraction of packet modulation information.
Definition uan-tx-mode.h:32
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition pointer.h:248
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:269
#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
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.