A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-transducer-hd.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-transducer-hd.h"
10
11#include "uan-channel.h"
12#include "uan-phy.h"
13#include "uan-prop-model.h"
14
15#include "ns3/double.h"
16#include "ns3/log.h"
17#include "ns3/pointer.h"
18#include "ns3/simulator.h"
19
20namespace ns3
21{
22
23NS_LOG_COMPONENT_DEFINE("UanTransducerHd");
24
25NS_OBJECT_ENSURE_REGISTERED(UanTransducerHd);
26
28 : UanTransducer(),
29 m_state(RX),
30 m_endTxTime(Seconds(0)),
31 m_cleared(false),
32 m_rxGainDb(0)
33{
34}
35
39
40void
42{
43 if (m_cleared)
44 {
45 return;
46 }
47 m_cleared = true;
48 if (m_channel)
49 {
50 m_channel->Clear();
51 m_channel = nullptr;
52 }
53
54 auto it = m_phyList.begin();
55 for (; it != m_phyList.end(); it++)
56 {
57 if (*it)
58 {
59 (*it)->Clear();
60 *it = nullptr;
61 }
62 }
63 auto ait = m_arrivalList.begin();
64 for (; ait != m_arrivalList.end(); ait++)
65 {
66 ait->GetPacket() = nullptr;
67 }
68 m_phyList.clear();
69 m_arrivalList.clear();
71}
72
73void
79
82{
83 static TypeId tid = TypeId("ns3::UanTransducerHd")
85 .SetGroupName("Uan")
86 .AddConstructor<UanTransducerHd>()
87 .AddAttribute("RxGainDb",
88 "Gain in Db added to incoming signal at receiver.",
89 DoubleValue(0),
92 return tid;
93}
94
97{
98 return m_state;
99}
100
101bool
103{
104 return m_state == RX;
105}
106
107bool
109{
110 return m_state == TX;
111}
112
115{
116 return m_arrivalList;
117}
118
119void
121{
122 m_rxGainDb = gainDb;
123}
124
125double
130
131double
133{
134 NS_LOG_FUNCTION(this << rxPowerDb << mode);
135 rxPowerDb += GetRxGainDb();
136 NS_LOG_DEBUG("Rx power after RX gain = " << rxPowerDb << " db re uPa");
137 return rxPowerDb;
138}
139
140void
141UanTransducerHd::Receive(Ptr<Packet> packet, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
142{
143 NS_LOG_FUNCTION(this << packet << rxPowerDb << txMode << pdp);
144 // Apply receiver gain in dB
145 rxPowerDb = ApplyRxGainDb(rxPowerDb, txMode);
146
147 UanPacketArrival arrival(packet, rxPowerDb, txMode, pdp, Simulator::Now());
148
149 m_arrivalList.push_back(arrival);
150 Time txDelay = Seconds(packet->GetSize() * 8.0 / txMode.GetDataRateBps());
151 Simulator::Schedule(txDelay, &UanTransducerHd::RemoveArrival, this, arrival);
152 NS_LOG_DEBUG(Now().As(Time::S) << " Transducer in receive");
153 if (m_state == RX)
154 {
155 NS_LOG_DEBUG("Transducer state = RX");
156 auto it = m_phyList.begin();
157 for (; it != m_phyList.end(); it++)
158 {
159 NS_LOG_DEBUG("Calling StartRx");
160 (*it)->StartRxPacket(packet, rxPowerDb, txMode, pdp);
161 }
162 }
163}
164
165void
166UanTransducerHd::Transmit(Ptr<UanPhy> src, Ptr<Packet> packet, double txPowerDb, UanTxMode txMode)
167{
168 if (m_state == TX)
169 {
171 src->NotifyTxDrop(packet); // traced source netanim
172 }
173 else
174 {
175 m_state = TX;
176 src->NotifyTxBegin(packet); // traced source netanim
177 }
178
179 Time delay = Seconds(packet->GetSize() * 8.0 / txMode.GetDataRateBps());
180 NS_LOG_DEBUG("Transducer transmitting: TX delay = "
181 << delay << " seconds for packet size " << packet->GetSize()
182 << " bytes and rate = " << txMode.GetDataRateBps() << " bps");
183 auto it = m_phyList.begin();
184 for (; it != m_phyList.end(); it++)
185 {
186 if (src != (*it))
187 {
188 (*it)->NotifyTransStartTx(packet, txPowerDb, txMode);
189 }
190 }
191 m_channel->TxPacket(Ptr<UanTransducer>(this), packet, txPowerDb, txMode);
192
193 delay = std::max(delay, m_endTxTime - Simulator::Now());
194
196 m_endTxTime = Simulator::Now() + delay;
197 Simulator::Schedule(delay, &UanPhy::NotifyTxEnd, src, packet); // traced source netanim
198}
199
200void
207
208void
210{
211 NS_LOG_DEBUG("Transducer setting channel");
212 m_channel = chan;
213}
214
217{
218 return m_channel;
219}
220
221void
223{
224 m_phyList.push_back(phy);
225}
226
229{
230 return m_phyList;
231}
232
233void
235{
236 // Remove entry from arrival list
237 auto it = m_arrivalList.begin();
238 for (; it != m_arrivalList.end(); it++)
239 {
240 if (it->GetPacket() == arrival.GetPacket())
241 {
242 m_arrivalList.erase(it);
243 break;
244 }
245 }
246 auto ait = m_phyList.begin();
247 for (; ait != m_phyList.end(); ait++)
248 {
249 (*ait)->NotifyIntChange();
250 }
251}
252
253} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition event-id.cc:44
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
@ S
second
Definition nstime.h:105
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Class consisting of packet arrival information (Time, RxPower, mode, PDP).
Ptr< Packet > GetPacket() const
Get the arriving packet.
The power delay profile returned by propagation models.
void NotifyTxEnd(Ptr< const Packet > packet)
Called when the transducer finishes transmitting a packet.
Definition uan-phy.cc:105
Half duplex implementation of transducer object.
void EndTx()
Handle end of transmission event.
State GetState() const override
Get the transducer state.
void SetChannel(Ptr< UanChannel > chan) override
Attach this transducer to a channel.
void Clear() override
Clears all pointer references.
bool IsTx() const override
Is the state transmitting?
Ptr< UanChannel > GetChannel() const override
Get the attached channel.
State m_state
Transducer state.
bool m_cleared
Flab when we've been cleared.
static TypeId GetTypeId()
Register this type.
void Transmit(Ptr< UanPhy > src, Ptr< Packet > packet, double txPowerDb, UanTxMode txMode) override
Transmit a packet from this transducer.
double m_rxGainDb
Receive gain in dB.
Ptr< UanChannel > m_channel
The attached channel.
const UanPhyList & GetPhyList() const override
Get the list of physical layer above this transducer.
ArrivalList m_arrivalList
List of arriving packets which overlap in time.
~UanTransducerHd() override
Dummy destructor, see DoDispose.
void RemoveArrival(UanPacketArrival arrival)
Remove an entry from the arrival list.
void SetRxGainDb(double gainDb) override
Set the receiver gain.
bool IsRx() const override
Is the state receiving (or available for reception)?
EventId m_endTxEvent
Event scheduled for end of transmission.
void AddPhy(Ptr< UanPhy >) override
Attach a physical network layer above this transducer.
double GetRxGainDb() override
Get the receiver gain added to signal at receiver in dB.
double ApplyRxGainDb(double rxPowerDb, UanTxMode mode) override
Apply receiver gain in dB to the received power.
UanTransducerHd()
Constructor.
void Receive(Ptr< Packet > packet, double rxPowerDb, UanTxMode txMode, UanPdp pdp) override
Notify this object that a new packet has arrived at this nodes location.
Time m_endTxTime
Time at which transmission will be completed.
void DoDispose() override
Destructor implementation.
const ArrivalList & GetArrivalList() const override
Get the list of overlapped (in time) packets at this transducer.
UanPhyList m_phyList
List of physical layers attached above this tranducer.
Virtual base for Transducer objects.
State
Transducer state.
@ TX
Transmitting.
std::list< Ptr< UanPhy > > UanPhyList
List of UanPhy objects.
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
Abstraction of packet modulation information.
Definition uan-tx-mode.h:32
uint32_t GetDataRateBps() const
Get the data rate of the transmit mode.
#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
#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_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ RX
The PHY layer is receiving a packet.
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32