A Discrete-Event Network Simulator
API
simple-ofdm-wimax-channel.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008, 2009 INRIA, UDcast
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: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19  * <amine.ismail@udcast.com>
20  */
21 
22 #include "ns3/simulator.h"
23 #include "ns3/callback.h"
24 #include "ns3/nstime.h"
25 #include "ns3/event-id.h"
26 #include "ns3/assert.h"
27 #include "ns3/net-device.h"
28 #include "ns3/node.h"
29 #include "wimax-phy.h"
30 #include "simple-ofdm-wimax-phy.h"
32 #include "ns3/mobility-model.h"
33 #include "ns3/cost231-propagation-loss-model.h"
34 #include "simple-ofdm-send-param.h"
35 
36 namespace ns3 {
37 
38 NS_LOG_COMPONENT_DEFINE ("simpleOfdmWimaxChannel");
39 
40 // NS_OBJECT_ENSURE_REGISTERED (simpleOfdmWimaxChannel);
41 
42 
44 {
45  m_loss = 0;
46 }
47 
49 {
50  m_phyList.clear ();
51 }
52 
53 /* static */
54 TypeId
56 {
57  static TypeId tid = TypeId ("ns3::SimpleOfdmWimaxChannel")
59  .SetGroupName ("Wimax")
60  .AddConstructor<SimpleOfdmWimaxChannel> ()
61  ;
62  return tid;
63 }
64 
66 {
67  switch (propModel)
68  {
69  case RANDOM_PROPAGATION:
70  m_loss = CreateObject<RandomPropagationLossModel> ();
71  break;
72 
73  case FRIIS_PROPAGATION:
74  m_loss = CreateObject<FriisPropagationLossModel> ();
75  break;
77  m_loss = CreateObject<LogDistancePropagationLossModel> ();
78  break;
79 
81  m_loss = CreateObject<Cost231PropagationLossModel> ();
82  break;
83 
84  default:
85  m_loss = 0;
86  }
87 
88 }
89 
90 void
92 {
93 
94  switch (propModel)
95  {
96  case RANDOM_PROPAGATION:
97  m_loss = CreateObject<RandomPropagationLossModel> ();
98  break;
99 
100  case FRIIS_PROPAGATION:
101  m_loss = CreateObject<FriisPropagationLossModel> ();
102  break;
104  m_loss = CreateObject<LogDistancePropagationLossModel> ();
105  break;
106 
107  case COST231_PROPAGATION:
108  m_loss = CreateObject<Cost231PropagationLossModel> ();
109  break;
110 
111  default:
112  m_loss = 0;
113  }
114 
115 }
116 
117 void
119 {
120  Ptr<SimpleOfdmWimaxPhy> o_phy = phy->GetObject<SimpleOfdmWimaxPhy> ();
121  m_phyList.push_back (o_phy);
122 }
123 
124 std::size_t
126 {
127  return m_phyList.size ();
128 }
129 
131 SimpleOfdmWimaxChannel::DoGetDevice (std::size_t index) const
132 {
133  std::size_t j = 0;
134  for (std::list<Ptr<SimpleOfdmWimaxPhy> >::const_iterator iter = m_phyList.begin (); iter != m_phyList.end (); ++iter)
135  {
136  if (j == index)
137  {
138  return (*iter)->GetDevice ();
139  }
140  j++;
141  }
142 
143  NS_FATAL_ERROR ("Unable to get device");
144  return 0;
145 }
146 
147 void
149  uint32_t burstSize,
151  bool isFirstBlock,
152  bool isLastBlock,
153  uint64_t frequency,
154  WimaxPhy::ModulationType modulationType,
155  uint8_t direction,
156  double txPowerDbm,
157  Ptr<PacketBurst> burst)
158 {
159  double rxPowerDbm = 0;
160  Ptr<MobilityModel> senderMobility = 0;
161  Ptr<MobilityModel> receiverMobility = 0;
162  senderMobility = phy->GetDevice ()->GetNode ()->GetObject<MobilityModel> ();
163  simpleOfdmSendParam * param;
164  for (std::list<Ptr<SimpleOfdmWimaxPhy> >::iterator iter = m_phyList.begin (); iter != m_phyList.end (); ++iter)
165  {
166  Time delay = Seconds (0);
167  if (phy != *iter)
168  {
169  double distance = 0;
170  receiverMobility = (*iter)->GetDevice ()->GetNode ()->GetObject<MobilityModel> ();
171  if (receiverMobility != 0 && senderMobility != 0 && m_loss != 0)
172  {
173  distance = senderMobility->GetDistanceFrom (receiverMobility);
174  delay = Seconds (distance/300000000.0);
175  rxPowerDbm = m_loss->CalcRxPower (txPowerDbm, senderMobility, receiverMobility);
176  }
177 
178  param = new simpleOfdmSendParam (burstSize,
179  isFirstBlock,
180  frequency,
181  modulationType,
182  direction,
183  rxPowerDbm,
184  burst);
185  Ptr<Object> dstNetDevice = (*iter)->GetDevice ();
186  uint32_t dstNode;
187  if (dstNetDevice == 0)
188  {
189  dstNode = 0xffffffff;
190  }
191  else
192  {
193  dstNode = dstNetDevice->GetObject<NetDevice> ()->GetNode ()->GetId ();
194  }
196  delay,
198  this,
199  *iter,
200  param);
201  }
202  }
203 
204 }
205 
206 void
208 {
209  rxphy->StartReceive (param->GetBurstSize (),
210  param->GetIsFirstBlock (),
211  param->GetFrequency (),
212  param->GetModulationType (),
213  param->GetDirection (),
214  param->GetRxPowerDbm (),
215  param->GetBurst ());
216  delete param;
217 }
218 
219 int64_t
221 {
222  int64_t currentStream = stream;
223  typedef std::list<Ptr<SimpleOfdmWimaxPhy> > PhyList;
224  for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i++)
225  {
226  Ptr<SimpleOfdmWimaxPhy> simpleOfdm = (*i);
227  currentStream += simpleOfdm->AssignStreams (currentStream);
228  }
229  return (currentStream - stream);
230 }
231 
232 }
233 // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account all the PropagationLossModel(s) chained to the current one...
The channel object to attach Wimax NetDevices.
Definition: wimax-channel.h:40
SimpleOfdmWimaxPhy class.
SimpleOfdmWimaxChannel class.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
simpleOfdmSendParam class
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
phy
Definition: third.py:93
Keep track of the current position and velocity of an object.
static TypeId GetTypeId(void)
Register this type.
void Send(Time BlockTime, uint32_t burstSize, Ptr< WimaxPhy > phy, bool isFirstBlock, bool isLastBlock, uint64_t frequency, WimaxPhy::ModulationType modulationType, uint8_t direction, double txPowerDbm, Ptr< PacketBurst > burst)
Sends a dummy fec block to all connected physical devices.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
WimaxPhy::ModulationType GetModulationType(void)
std::list< Ptr< SimpleOfdmWimaxPhy > > m_phyList
phy list
#define list
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::size_t DoGetNDevices(void) const
Get number of devices function.
void SetPropagationModel(PropModel propModel)
sets the propagation model
Ptr< NetDevice > DoGetDevice(std::size_t i) const
Get device function.
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:49
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:1483
Network layer to device interface.
Definition: net-device.h:95
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
void EndSendDummyBlock(Ptr< SimpleOfdmWimaxPhy > rxphy, simpleOfdmSendParam *param)
End send dummy block function.
Ptr< PacketBurst > GetBurst(void)
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
Ptr< PropagationLossModel > m_loss
loss
void DoAttach(Ptr< WimaxPhy > phy)
Attach functiion.