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  ;
36 
38  : UanTransducer (),
39  m_state (RX),
40  m_endTxTime (Seconds (0)),
41  m_cleared (false)
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")
92  .SetParent<Object> ()
93  .AddConstructor<UanTransducerHd> ()
94  ;
95  return tid;
96 }
97 
100 {
101  return m_state;
102 }
103 
104 
105 bool
107 {
108  return m_state == RX;
109 }
110 
111 bool
113 {
114  return m_state == TX;
115 
116 }
117 
120 {
121  return m_arrivalList;
122 }
123 
124 void
126  double rxPowerDb,
127  UanTxMode txMode,
128  UanPdp pdp)
129 {
130  UanPacketArrival arrival (packet,
131  rxPowerDb,
132  txMode,
133  pdp,
134  Simulator::Now ());
135 
136  m_arrivalList.push_back (arrival);
137  Time txDelay = Seconds (packet->GetSize () * 8.0 / txMode.GetDataRateBps ());
138  Simulator::Schedule (txDelay, &UanTransducerHd::RemoveArrival, this, arrival);
139  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Transducer in receive");
140  if (m_state == RX)
141  {
142  NS_LOG_DEBUG ("Transducer state = RX");
143  UanPhyList::const_iterator it = m_phyList.begin ();
144  for (; it != m_phyList.end (); it++)
145  {
146  NS_LOG_DEBUG ("Calling StartRx");
147  (*it)->StartRxPacket (packet, rxPowerDb, txMode, pdp);
148  }
149  }
150 }
151 
152 void
154  Ptr<Packet> packet,
155  double txPowerDb,
156  UanTxMode txMode)
157 {
158  if (m_state == TX)
159  {
161  src->NotifyTxDrop(packet); // traced source netanim
162  }
163  else
164  {
165  m_state = TX;
166  src->NotifyTxBegin(packet); // traced source netanim
167  }
168 
169 
170  Time delay = Seconds (packet->GetSize () * 8.0 / txMode.GetDataRateBps ());
171  NS_LOG_DEBUG ("Transducer transmitting: TX delay = "
172  << delay << " seconds for packet size "
173  << packet->GetSize () << " bytes and rate = "
174  << txMode.GetDataRateBps () << " bps");
175  UanPhyList::const_iterator it = m_phyList.begin ();
176  for (; it != m_phyList.end (); it++)
177  {
178  if (src != (*it))
179  {
180  (*it)->NotifyTransStartTx (packet, txPowerDb, txMode);
181  }
182  }
183  m_channel->TxPacket (Ptr<UanTransducer> (this), packet, txPowerDb, txMode);
184 
185 
186  delay = std::max (delay, m_endTxTime - Simulator::Now ());
187 
189  m_endTxTime = Simulator::Now () + delay;
190  Simulator::Schedule(delay, &UanPhy::NotifyTxEnd, src, packet); // traced source netanim
191 }
192 
193 void
195 {
196  NS_ASSERT (m_state == TX);
197  m_state = RX;
198  m_endTxTime = Seconds (0);
199 }
200 void
202 {
203  NS_LOG_DEBUG ("Transducer setting channel");
204  m_channel = chan;
205 
206 }
209 {
210  return m_channel;
211 }
212 void
214 {
215  m_phyList.push_back (phy);
216 }
217 
220 {
221  return m_phyList;
222 }
223 
224 void
226 {
227 
228  // Remove entry from arrival list
229  ArrivalList::iterator it = m_arrivalList.begin ();
230  for (; it != m_arrivalList.end (); it++)
231  {
232  if (it->GetPacket () == arrival.GetPacket ())
233  {
234  m_arrivalList.erase (it);
235  break;
236  }
237  }
238  UanPhyList::const_iterator ait = m_phyList.begin ();
239  for (; ait != m_phyList.end (); ait++)
240  {
241  (*ait)->NotifyIntChange ();
242  }
243 
244 }
245 
246 } // namespace ns3
static TypeId GetTypeId(void)
Register this type.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
EventId m_endTxEvent
Event scheduled for end of transmission.
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)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
uint32_t GetSize(void) const
Definition: packet.h:650
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:336
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:824
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.
NS_LOG_COMPONENT_DEFINE("UanTransducerHd")
virtual void Clear(void)
Clears all pointer references.
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
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:63
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:611
void NotifyTxEnd(Ptr< const Packet > packet)
Called when the transducer finishes transmitting a packet.
Definition: uan-phy.cc:106
State m_state
Transducer state.
Class consisting of packet arrival information (Time, RxPower, mode, PDP).