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 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("UanTransducerHd");
33 
34 NS_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 
49 void
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 
82 void
84 {
85  Clear ();
87 }
88 TypeId
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 
111 bool
113 {
114  return m_state == RX;
115 }
116 
117 bool
119 {
120  return m_state == TX;
121 
122 }
123 
126 {
127  return m_arrivalList;
128 }
129 
130 void
132 {
133  m_rxGainDb = gainDb;
134 }
135 
136 double
138 {
139  return m_rxGainDb;
140 }
141 
142 double
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 
151 void
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 (Simulator::Now ().GetSeconds () << " 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 
183 void
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 
224 void
226 {
227  NS_ASSERT (m_state == TX);
228  m_state = RX;
229  m_endTxTime = Seconds (0);
230 }
231 void
233 {
234  NS_LOG_DEBUG ("Transducer setting channel");
235  m_channel = chan;
236 
237 }
240 {
241  return m_channel;
242 }
243 void
245 {
246  m_phyList.push_back (phy);
247 }
248 
251 {
252  return m_phyList;
253 }
254 
255 void
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
static TypeId GetTypeId(void)
Register this type.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
EventId m_endTxEvent
Event scheduled for end of transmission.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual const UanPhyList & GetPhyList(void) const
Get the list of physical layer above this transducer.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void EndTx(void)
Handle end of transmission event.
std::list< Ptr< UanPhy > > UanPhyList
List of UanPhy objects.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
ArrivalList m_arrivalList
List of arriving packets which overlap in time.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
virtual bool IsRx(void) const
Is the state receiving (or available for reception)?
Ptr< UanChannel > m_channel
The attached channel.
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.
bool m_cleared
Flab when we&#39;ve been cleared.
virtual void DoDispose()
Destructor implementation.
phy
Definition: third.py:86
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1381
#define max(a, b)
Definition: 80211b.c:43
virtual ~UanTransducerHd()
Dummy destructor, see DoDispose.
The power delay profile returned by propagation models.
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
Virtual base for Transducer objects.
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
Ptr< Packet > GetPacket(void) const
Get the arriving packet.
UanTransducerHd()
Constructor.
static void Remove(const EventId &id)
Remove an event from the event list.
Definition: simulator.cc:336
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual State GetState(void) const
Get the transducer state.
double m_rxGainDb
Receive gain in dB.
virtual double GetRxGainDb(void)
Get the receiver gain added to signal at receiver in dB.
void RemoveArrival(UanPacketArrival arrival)
Remove an entry from the arrival list.
Time m_endTxTime
Time at which transmission will be completed.
virtual const ArrivalList & GetArrivalList(void) const
Get the list of overlapped (in time) packets at this transducer.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
virtual double ApplyRxGainDb(double rxPowerDb, UanTxMode mode)
Apply receiver gain in dB to the received power.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
virtual void SetChannel(Ptr< UanChannel > chan)
Attach this transducer to a channel.
virtual void AddPhy(Ptr< UanPhy >)
Attach a physical network layer above this transducer.
virtual void SetRxGainDb(double gainDb)
Set the receiver gain.
virtual void Clear(void)
Clears all pointer references.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
The PHY layer is receiving a packet.
virtual Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
UanPhyList m_phyList
List of physical layers attached above this tranducer.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
State
Transducer state.
virtual void Transmit(Ptr< UanPhy > src, Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)
Transmit a packet from this transducer.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
virtual bool IsTx(void) const
Is the state transmitting?
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void NotifyTxEnd(Ptr< const Packet > packet)
Called when the transducer finishes transmitting a packet.
Definition: uan-phy.cc:120
State m_state
Transducer state.
Half duplex implementation of transducer object.
Class consisting of packet arrival information (Time, RxPower, mode, PDP).