A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
29 
30 NS_LOG_COMPONENT_DEFINE ("UanTransducerHd");
31 
32 namespace ns3 {
33 
34 NS_OBJECT_ENSURE_REGISTERED (UanTransducerHd);
35 
37  : UanTransducer (),
38  m_state (RX),
39  m_endTxTime (Seconds (0)),
40  m_cleared (false)
41 {
42 }
43 
45 {
46 }
47 
48 void
50 {
51  if (m_cleared)
52  {
53  return;
54  }
55  m_cleared = true;
56  if (m_channel)
57  {
58  m_channel->Clear ();
59  m_channel = 0;
60  }
61 
62  UanPhyList::iterator it = m_phyList.begin ();
63  for (; it != m_phyList.end (); it++)
64  {
65  if (*it)
66  {
67  (*it)->Clear ();
68  *it = 0;
69  }
70  }
71  ArrivalList::iterator ait = m_arrivalList.begin ();
72  for (; ait != m_arrivalList.end (); ait++)
73  {
74  ait->GetPacket () = 0;
75  }
76  m_phyList.clear ();
77  m_arrivalList.clear ();
79 }
80 
81 void
83 {
84  Clear ();
86 }
87 TypeId
89 {
90  static TypeId tid = TypeId ("ns3::UanTransducerHd")
91  .SetParent<Object> ()
92  .AddConstructor<UanTransducerHd> ()
93  ;
94  return tid;
95 }
96 
99 {
100  return m_state;
101 }
102 
103 
104 bool
106 {
107  return m_state == RX;
108 }
109 
110 bool
112 {
113  return m_state == TX;
114 
115 }
116 
119 {
120  return m_arrivalList;
121 }
122 
123 void
125  double rxPowerDb,
126  UanTxMode txMode,
127  UanPdp pdp)
128 {
129  UanPacketArrival arrival (packet,
130  rxPowerDb,
131  txMode,
132  pdp,
133  Simulator::Now ());
134 
135  m_arrivalList.push_back (arrival);
136  Time txDelay = Seconds (packet->GetSize () * 8.0 / txMode.GetDataRateBps ());
137  Simulator::Schedule (txDelay, &UanTransducerHd::RemoveArrival, this, arrival);
138  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Transducer in receive");
139  if (m_state == RX)
140  {
141  NS_LOG_DEBUG ("Transducer state = RX");
142  UanPhyList::const_iterator it = m_phyList.begin ();
143  for (; it != m_phyList.end (); it++)
144  {
145  NS_LOG_DEBUG ("Calling StartRx");
146  (*it)->StartRxPacket (packet, rxPowerDb, txMode, pdp);
147  }
148  }
149 }
150 
151 void
153  Ptr<Packet> packet,
154  double txPowerDb,
155  UanTxMode txMode)
156 {
157  if (m_state == TX)
158  {
160  src->NotifyTxDrop(packet); // traced source netanim
161  }
162  else
163  {
164  m_state = TX;
165  src->NotifyTxBegin(packet); // traced source netanim
166  }
167 
168 
169  Time delay = Seconds (packet->GetSize () * 8.0 / txMode.GetDataRateBps ());
170  NS_LOG_DEBUG ("Transducer transmitting: TX delay = "
171  << delay << " seconds for packet size "
172  << packet->GetSize () << " bytes and rate = "
173  << txMode.GetDataRateBps () << " bps");
174  UanPhyList::const_iterator it = m_phyList.begin ();
175  for (; it != m_phyList.end (); it++)
176  {
177  if (src != (*it))
178  {
179  (*it)->NotifyTransStartTx (packet, txPowerDb, txMode);
180  }
181  }
182  m_channel->TxPacket (Ptr<UanTransducer> (this), packet, txPowerDb, txMode);
183 
184 
185  delay = std::max (delay, m_endTxTime - Simulator::Now ());
186 
188  m_endTxTime = Simulator::Now () + delay;
189  Simulator::Schedule(delay, &UanPhy::NotifyTxEnd, src, packet); // traced source netanim
190 }
191 
192 void
194 {
195  NS_ASSERT (m_state == TX);
196  m_state = RX;
197  m_endTxTime = Seconds (0);
198 }
199 void
201 {
202  NS_LOG_DEBUG ("Transducer setting channel");
203  m_channel = chan;
204 
205 }
208 {
209  return m_channel;
210 }
211 void
213 {
214  m_phyList.push_back (phy);
215 }
216 
219 {
220  return m_phyList;
221 }
222 
223 void
225 {
226 
227  // Remove entry from arrival list
228  ArrivalList::iterator it = m_arrivalList.begin ();
229  for (; it != m_arrivalList.end (); it++)
230  {
231  if (it->GetPacket () == arrival.GetPacket ())
232  {
233  m_arrivalList.erase (it);
234  break;
235  }
236  }
237  UanPhyList::const_iterator ait = m_phyList.begin ();
238  for (; ait != m_phyList.end (); ait++)
239  {
240  (*ait)->NotifyIntChange ();
241  }
242 
243 }
244 
245 } // namespace ns3
static TypeId GetTypeId(void)
Register this type.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
EventId m_endTxEvent
Event scheduled for end of transmission.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
void EndTx(void)
Handle end of transmission event.
std::list< Ptr< UanPhy > > UanPhyList
List of UanPhy objects.
virtual const UanPhyList & GetPhyList(void) const
Get the list of physical layer above this transducer.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
virtual bool IsTx(void) const
Is the state transmitting?
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:335
ArrivalList m_arrivalList
List of arriving packets which overlap in time.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:825
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've been cleared.
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Ptr< Packet > GetPacket(void) const
Get the arriving packet.
virtual Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
virtual ~UanTransducerHd()
Dummy destructor, see DoDispose.
uint32_t GetDataRateBps(void) const
Get the data rate of the transmit mode.
Definition: uan-tx-mode.cc:45
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.
virtual const ArrivalList & GetArrivalList(void) const
Get the list of overlapped (in time) packets at this transducer.
UanTransducerHd()
Constructor.
static void Remove(const EventId &id)
Remove an event from the event list.
Definition: simulator.cc:258
void RemoveArrival(UanPacketArrival arrival)
Remove an entry from the arrival list.
Time m_endTxTime
Time at which transmission will be completed.
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
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 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:213
virtual State GetState(void) const
Get the transducer state.
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:47
State
Transducer state.
a base class which provides memory management and object aggregation
Definition: object.h:64
virtual void Transmit(Ptr< UanPhy > src, Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)
Transmit a packet from this transducer.
virtual bool IsRx(void) const
Is the state receiving (or available for reception)?
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
void NotifyTxEnd(Ptr< const Packet > packet)
Called when the transducer finishes transmitting a packet.
Definition: uan-phy.cc:103
State m_state
Transducer state.
Class consisting of packet arrival information (Time, RxPower, mode, PDP).