A Discrete-Event Network Simulator
API
simple-ofdm-wimax-channel.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007,2008, 2009 INRIA, UDcast
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
18  * <amine.ismail@udcast.com>
19  */
20 
22 
23 #include "simple-ofdm-send-param.h"
24 #include "simple-ofdm-wimax-phy.h"
25 #include "wimax-phy.h"
26 
27 #include "ns3/assert.h"
28 #include "ns3/callback.h"
29 #include "ns3/cost231-propagation-loss-model.h"
30 #include "ns3/event-id.h"
31 #include "ns3/mobility-model.h"
32 #include "ns3/net-device.h"
33 #include "ns3/node.h"
34 #include "ns3/nstime.h"
35 #include "ns3/simulator.h"
36 
37 namespace ns3
38 {
39 
40 NS_LOG_COMPONENT_DEFINE("simpleOfdmWimaxChannel");
41 
42 // NS_OBJECT_ENSURE_REGISTERED (simpleOfdmWimaxChannel);
43 
45 {
46  m_loss = nullptr;
47 }
48 
50 {
51  m_phyList.clear();
52 }
53 
54 /* static */
55 TypeId
57 {
58  static TypeId tid = TypeId("ns3::SimpleOfdmWimaxChannel")
60  .SetGroupName("Wimax")
61  .AddConstructor<SimpleOfdmWimaxChannel>();
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 = nullptr;
86  }
87 }
88 
89 void
91 {
92  switch (propModel)
93  {
94  case RANDOM_PROPAGATION:
95  m_loss = CreateObject<RandomPropagationLossModel>();
96  break;
97 
98  case FRIIS_PROPAGATION:
99  m_loss = CreateObject<FriisPropagationLossModel>();
100  break;
102  m_loss = CreateObject<LogDistancePropagationLossModel>();
103  break;
104 
105  case COST231_PROPAGATION:
106  m_loss = CreateObject<Cost231PropagationLossModel>();
107  break;
108 
109  default:
110  m_loss = nullptr;
111  }
112 }
113 
114 void
116 {
117  Ptr<SimpleOfdmWimaxPhy> o_phy = phy->GetObject<SimpleOfdmWimaxPhy>();
118  m_phyList.push_back(o_phy);
119 }
120 
121 std::size_t
123 {
124  return m_phyList.size();
125 }
126 
128 SimpleOfdmWimaxChannel::DoGetDevice(std::size_t index) const
129 {
130  std::size_t j = 0;
131  for (std::list<Ptr<SimpleOfdmWimaxPhy>>::const_iterator iter = m_phyList.begin();
132  iter != m_phyList.end();
133  ++iter)
134  {
135  if (j == index)
136  {
137  return (*iter)->GetDevice();
138  }
139  j++;
140  }
141 
142  NS_FATAL_ERROR("Unable to get device");
143  return nullptr;
144 }
145 
146 void
148  uint32_t burstSize,
150  bool isFirstBlock,
151  bool isLastBlock,
152  uint64_t frequency,
153  WimaxPhy::ModulationType modulationType,
154  uint8_t direction,
155  double txPowerDbm,
156  Ptr<PacketBurst> burst)
157 {
158  double rxPowerDbm = 0;
159  Ptr<MobilityModel> senderMobility = nullptr;
160  Ptr<MobilityModel> receiverMobility = nullptr;
161  senderMobility = phy->GetDevice()->GetNode()->GetObject<MobilityModel>();
162  SimpleOfdmSendParam* param;
163  for (std::list<Ptr<SimpleOfdmWimaxPhy>>::iterator iter = m_phyList.begin();
164  iter != m_phyList.end();
165  ++iter)
166  {
167  Time delay = Seconds(0);
168  if (phy != *iter)
169  {
170  double distance = 0;
171  receiverMobility = (*iter)->GetDevice()->GetNode()->GetObject<MobilityModel>();
172  if (receiverMobility && senderMobility && m_loss)
173  {
174  distance = senderMobility->GetDistanceFrom(receiverMobility);
175  delay = Seconds(distance / 300000000.0);
176  rxPowerDbm = m_loss->CalcRxPower(txPowerDbm, senderMobility, receiverMobility);
177  }
178 
179  param = new SimpleOfdmSendParam(burstSize,
180  isFirstBlock,
181  frequency,
182  modulationType,
183  direction,
184  rxPowerDbm,
185  burst);
186  Ptr<Object> dstNetDevice = (*iter)->GetDevice();
187  uint32_t dstNode;
188  if (!dstNetDevice)
189  {
190  dstNode = 0xffffffff;
191  }
192  else
193  {
194  dstNode = dstNetDevice->GetObject<NetDevice>()->GetNode()->GetId();
195  }
197  delay,
199  this,
200  *iter,
201  param);
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 } // namespace ns3
233 
234 // namespace ns3
Keep track of the current position and velocity of an object.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
Network layer to device interface.
Definition: net-device.h:98
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
SimpleOfdmSendParam class.
WimaxPhy::ModulationType GetModulationType()
SimpleOfdmWimaxChannel class.
Ptr< PropagationLossModel > m_loss
loss
void SetPropagationModel(PropModel propModel)
sets the propagation model
void DoAttach(Ptr< WimaxPhy > phy) override
Attach function.
std::size_t DoGetNDevices() const override
Get number of devices function.
static TypeId GetTypeId()
Register this type.
std::list< Ptr< SimpleOfdmWimaxPhy > > m_phyList
phy list
void EndSendDummyBlock(Ptr< SimpleOfdmWimaxPhy > rxphy, SimpleOfdmSendParam *param)
End send dummy block function.
Ptr< NetDevice > DoGetDevice(std::size_t i) const override
Get device function.
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.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
SimpleOfdmWimaxPhy class.
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:587
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
The channel object to attach Wimax NetDevices.
Definition: wimax-channel.h:43
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:54
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Every class exported by the ns3 library is enclosed in the ns3 namespace.
phy
Definition: third.py:82
#define list