A Discrete-Event Network Simulator
API
uan-transducer-hd.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2009 University of Washington
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Leonard Tracy <lentracy@gmail.com>
19 */
20
21#include "uan-transducer-hd.h"
22#include "ns3/simulator.h"
23#include "ns3/uan-prop-model.h"
24#include "uan-phy.h"
25#include "uan-channel.h"
26#include "ns3/log.h"
27#include "ns3/pointer.h"
28#include "ns3/double.h"
29
30namespace ns3 {
31
32NS_LOG_COMPONENT_DEFINE ("UanTransducerHd");
33
34NS_OBJECT_ENSURE_REGISTERED (UanTransducerHd);
35
37 : UanTransducer (),
38 m_state (RX),
39 m_endTxTime (Seconds (0)),
40 m_cleared (false),
41 m_rxGainDb (0)
42{
43}
44
46{
47}
48
49void
51{
52 if (m_cleared)
53 {
54 return;
55 }
56 m_cleared = true;
57 if (m_channel)
58 {
59 m_channel->Clear ();
60 m_channel = 0;
61 }
62
63 UanPhyList::iterator it = m_phyList.begin ();
64 for (; it != m_phyList.end (); it++)
65 {
66 if (*it)
67 {
68 (*it)->Clear ();
69 *it = 0;
70 }
71 }
72 ArrivalList::iterator ait = m_arrivalList.begin ();
73 for (; ait != m_arrivalList.end (); ait++)
74 {
75 ait->GetPacket () = 0;
76 }
77 m_phyList.clear ();
78 m_arrivalList.clear ();
80}
81
82void
84{
85 Clear ();
87}
90{
91 static TypeId tid = TypeId ("ns3::UanTransducerHd")
93 .SetGroupName ("Uan")
94 .AddConstructor<UanTransducerHd> ()
95 .AddAttribute ("RxGainDb",
96 "Gain in Db added to incoming signal at receiver.",
97 DoubleValue (0),
99 MakeDoubleChecker<double> ())
100 ;
101 return tid;
102}
103
106{
107 return m_state;
108}
109
110
111bool
113{
114 return m_state == RX;
115}
116
117bool
119{
120 return m_state == TX;
121
122}
123
126{
127 return m_arrivalList;
128}
129
130void
132{
133 m_rxGainDb = gainDb;
134}
135
136double
138{
139 return m_rxGainDb;
140}
141
142double
144{
145 NS_LOG_FUNCTION (this << rxPowerDb << mode);
146 rxPowerDb += GetRxGainDb ();
147 NS_LOG_DEBUG ("Rx power after RX gain = " << rxPowerDb << " db re uPa");
148 return rxPowerDb;
149}
150
151void
153 double rxPowerDb,
154 UanTxMode txMode,
155 UanPdp pdp)
156{
157 NS_LOG_FUNCTION (this << packet << rxPowerDb << txMode << pdp);
158 //Apply receiver gain in dB
159 rxPowerDb = ApplyRxGainDb (rxPowerDb, txMode);
160
161 UanPacketArrival arrival (packet,
162 rxPowerDb,
163 txMode,
164 pdp,
165 Simulator::Now ());
166
167 m_arrivalList.push_back (arrival);
168 Time txDelay = Seconds (packet->GetSize () * 8.0 / txMode.GetDataRateBps ());
169 Simulator::Schedule (txDelay, &UanTransducerHd::RemoveArrival, this, arrival);
170 NS_LOG_DEBUG (Now ().As (Time::S) << " Transducer in receive");
171 if (m_state == RX)
172 {
173 NS_LOG_DEBUG ("Transducer state = RX");
174 UanPhyList::const_iterator it = m_phyList.begin ();
175 for (; it != m_phyList.end (); it++)
176 {
177 NS_LOG_DEBUG ("Calling StartRx");
178 (*it)->StartRxPacket (packet, rxPowerDb, txMode, pdp);
179 }
180 }
181}
182
183void
185 Ptr<Packet> packet,
186 double txPowerDb,
187 UanTxMode txMode)
188{
189 if (m_state == TX)
190 {
192 src->NotifyTxDrop(packet); // traced source netanim
193 }
194 else
195 {
196 m_state = TX;
197 src->NotifyTxBegin(packet); // traced source netanim
198 }
199
200
201 Time delay = Seconds (packet->GetSize () * 8.0 / txMode.GetDataRateBps ());
202 NS_LOG_DEBUG ("Transducer transmitting: TX delay = "
203 << delay << " seconds for packet size "
204 << packet->GetSize () << " bytes and rate = "
205 << txMode.GetDataRateBps () << " bps");
206 UanPhyList::const_iterator it = m_phyList.begin ();
207 for (; it != m_phyList.end (); it++)
208 {
209 if (src != (*it))
210 {
211 (*it)->NotifyTransStartTx (packet, txPowerDb, txMode);
212 }
213 }
214 m_channel->TxPacket (Ptr<UanTransducer> (this), packet, txPowerDb, txMode);
215
216
217 delay = std::max (delay, m_endTxTime - Simulator::Now ());
218
220 m_endTxTime = Simulator::Now () + delay;
221 Simulator::Schedule(delay, &UanPhy::NotifyTxEnd, src, packet); // traced source netanim
222}
223
224void
226{
227 NS_ASSERT (m_state == TX);
228 m_state = RX;
229 m_endTxTime = Seconds (0);
230}
231void
233{
234 NS_LOG_DEBUG ("Transducer setting channel");
235 m_channel = chan;
236
237}
240{
241 return m_channel;
242}
243void
245{
246 m_phyList.push_back (phy);
247}
248
251{
252 return m_phyList;
253}
254
255void
257{
258
259 // Remove entry from arrival list
260 ArrivalList::iterator it = m_arrivalList.begin ();
261 for (; it != m_arrivalList.end (); it++)
262 {
263 if (it->GetPacket () == arrival.GetPacket ())
264 {
265 m_arrivalList.erase (it);
266 break;
267 }
268 }
269 UanPhyList::const_iterator ait = m_phyList.begin ();
270 for (; ait != m_phyList.end (); ait++)
271 {
272 (*ait)->NotifyIntChange ();
273 }
274
275}
276
277} // namespace ns3
#define max(a, b)
Definition: 80211b.c:43
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
@ S
second
Definition: nstime.h:114
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Class consisting of packet arrival information (Time, RxPower, mode, PDP).
Ptr< Packet > GetPacket(void) 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:120
Half duplex implementation of transducer object.
void EndTx(void)
Handle end of transmission event.
virtual bool IsTx(void) const
Is the state transmitting?
virtual void DoDispose()
Destructor implementation.
virtual void SetRxGainDb(double gainDb)
Set the receiver gain.
State m_state
Transducer state.
bool m_cleared
Flab when we've been cleared.
virtual void Clear(void)
Clears all pointer references.
virtual void Transmit(Ptr< UanPhy > src, Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)
Transmit a packet from this transducer.
double m_rxGainDb
Receive gain in dB.
Ptr< UanChannel > m_channel
The attached channel.
ArrivalList m_arrivalList
List of arriving packets which overlap in time.
virtual bool IsRx(void) const
Is the state receiving (or available for reception)?
void RemoveArrival(UanPacketArrival arrival)
Remove an entry from the arrival list.
virtual State GetState(void) const
Get the transducer state.
virtual const ArrivalList & GetArrivalList(void) const
Get the list of overlapped (in time) packets at this transducer.
virtual void AddPhy(Ptr< UanPhy >)
Attach a physical network layer above this transducer.
virtual void Receive(Ptr< Packet > packet, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Notify this object that a new packet has arrived at this nodes location.
EventId m_endTxEvent
Event scheduled for end of transmission.
virtual Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
virtual double GetRxGainDb(void)
Get the receiver gain added to signal at receiver in dB.
UanTransducerHd()
Constructor.
virtual const UanPhyList & GetPhyList(void) const
Get the list of physical layer above this transducer.
virtual ~UanTransducerHd()
Dummy destructor, see DoDispose.
Time m_endTxTime
Time at which transmission will be completed.
static TypeId GetTypeId(void)
Register this type.
virtual void SetChannel(Ptr< UanChannel > chan)
Attach this transducer to a channel.
virtual double ApplyRxGainDb(double rxPowerDb, UanTxMode mode)
Apply receiver gain in dB to the received power.
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:42
uint32_t GetDataRateBps(void) const
Get the data rate of the transmit mode.
Definition: uan-tx-mode.cc:45
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:42
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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:45
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
phy
Definition: third.py:93
@ RX
The PHY layer is receiving a packet.