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 (auto iter = m_phyList.begin(); iter != m_phyList.end(); ++iter)
132  {
133  if (j == index)
134  {
135  return (*iter)->GetDevice();
136  }
137  j++;
138  }
139 
140  NS_FATAL_ERROR("Unable to get device");
141  return nullptr;
142 }
143 
144 void
146  uint32_t burstSize,
148  bool isFirstBlock,
149  bool isLastBlock,
150  uint64_t frequency,
151  WimaxPhy::ModulationType modulationType,
152  uint8_t direction,
153  double txPowerDbm,
154  Ptr<PacketBurst> burst)
155 {
156  double rxPowerDbm = 0;
157  Ptr<MobilityModel> senderMobility = nullptr;
158  Ptr<MobilityModel> receiverMobility = nullptr;
159  senderMobility = phy->GetDevice()->GetNode()->GetObject<MobilityModel>();
160  SimpleOfdmSendParam* param;
161  for (auto iter = m_phyList.begin(); iter != m_phyList.end(); ++iter)
162  {
163  Time delay = Seconds(0);
164  if (phy != *iter)
165  {
166  double distance = 0;
167  receiverMobility = (*iter)->GetDevice()->GetNode()->GetObject<MobilityModel>();
168  if (receiverMobility && senderMobility && m_loss)
169  {
170  distance = senderMobility->GetDistanceFrom(receiverMobility);
171  delay = Seconds(distance / 300000000.0);
172  rxPowerDbm = m_loss->CalcRxPower(txPowerDbm, senderMobility, receiverMobility);
173  }
174 
175  param = new SimpleOfdmSendParam(burstSize,
176  isFirstBlock,
177  frequency,
178  modulationType,
179  direction,
180  rxPowerDbm,
181  burst);
182  Ptr<Object> dstNetDevice = (*iter)->GetDevice();
183  uint32_t dstNode;
184  if (!dstNetDevice)
185  {
186  dstNode = 0xffffffff;
187  }
188  else
189  {
190  dstNode = dstNetDevice->GetObject<NetDevice>()->GetNode()->GetId();
191  }
193  delay,
195  this,
196  *iter,
197  param);
198  }
199  }
200 }
201 
202 void
204 {
205  rxphy->StartReceive(param->GetBurstSize(),
206  param->GetIsFirstBlock(),
207  param->GetFrequency(),
208  param->GetModulationType(),
209  param->GetDirection(),
210  param->GetRxPowerDbm(),
211  param->GetBurst());
212  delete param;
213 }
214 
215 int64_t
217 {
218  int64_t currentStream = stream;
219  for (auto i = m_phyList.begin(); i != m_phyList.end(); i++)
220  {
221  Ptr<SimpleOfdmWimaxPhy> simpleOfdm = (*i);
222  currentStream += simpleOfdm->AssignStreams(currentStream);
223  }
224  return (currentStream - stream);
225 }
226 
227 } // namespace ns3
228 
229 // 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:77
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:588
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
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:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
phy
Definition: third.py:89