A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("simpleOfdmWimaxChannel");
37 
38 namespace ns3 {
39 // NS_OBJECT_ENSURE_REGISTERED (simpleOfdmWimaxChannel)
40 // ;
41 
42 
44 {
45  m_loss = 0;
46 }
47 
49 {
50  m_phyList.clear ();
51 }
52 
54 {
55  switch (propModel)
56  {
57  case RANDOM_PROPAGATION:
58  m_loss = CreateObject<RandomPropagationLossModel> ();
59  break;
60 
61  case FRIIS_PROPAGATION:
62  m_loss = CreateObject<FriisPropagationLossModel> ();
63  break;
65  m_loss = CreateObject<LogDistancePropagationLossModel> ();
66  break;
67 
69  m_loss = CreateObject<Cost231PropagationLossModel> ();
70  break;
71 
72  default:
73  m_loss = 0;
74  }
75 
76 }
77 
78 void
80 {
81 
82  switch (propModel)
83  {
84  case RANDOM_PROPAGATION:
85  m_loss = CreateObject<RandomPropagationLossModel> ();
86  break;
87 
88  case FRIIS_PROPAGATION:
89  m_loss = CreateObject<FriisPropagationLossModel> ();
90  break;
92  m_loss = CreateObject<LogDistancePropagationLossModel> ();
93  break;
94 
96  m_loss = CreateObject<Cost231PropagationLossModel> ();
97  break;
98 
99  default:
100  m_loss = 0;
101  }
102 
103 }
104 
105 void
107 {
108  Ptr<SimpleOfdmWimaxPhy> o_phy = phy->GetObject<SimpleOfdmWimaxPhy> ();
109  m_phyList.push_back (o_phy);
110 }
111 
112 uint32_t
114 {
115  return m_phyList.size ();
116 }
117 
120 {
121  uint32_t j = 0;
122  for (std::list<Ptr<SimpleOfdmWimaxPhy> >::const_iterator iter = m_phyList.begin (); iter != m_phyList.end (); ++iter)
123  {
124  if (j == index)
125  {
126  return (*iter)->GetDevice ();
127  }
128  j++;
129  }
130 
131  NS_FATAL_ERROR ("Unable to get device");
132  return 0;
133 }
134 
135 void
137  uint32_t burstSize,
138  Ptr<WimaxPhy> phy,
139  bool isFirstBlock,
140  bool isLastBlock,
141  uint64_t frequency,
142  WimaxPhy::ModulationType modulationType,
143  uint8_t direction,
144  double txPowerDbm,
145  Ptr<PacketBurst> burst)
146 {
147  double rxPowerDbm = 0;
148  Ptr<MobilityModel> senderMobility = 0;
149  Ptr<MobilityModel> receiverMobility = 0;
150  senderMobility = phy->GetDevice ()->GetNode ()->GetObject<MobilityModel> ();
151  simpleOfdmSendParam * param;
152  for (std::list<Ptr<SimpleOfdmWimaxPhy> >::iterator iter = m_phyList.begin (); iter != m_phyList.end (); ++iter)
153  {
154  Time delay = Seconds (0);
155  if (phy != *iter)
156  {
157  double distance = 0;
158  receiverMobility = (*iter)->GetDevice ()->GetNode ()->GetObject<MobilityModel> ();
159  if (receiverMobility != 0 && senderMobility != 0 && m_loss != 0)
160  {
161  distance = senderMobility->GetDistanceFrom (receiverMobility);
162  delay = Seconds (distance/300000000.0);
163  rxPowerDbm = m_loss->CalcRxPower (txPowerDbm, senderMobility, receiverMobility);
164  }
165 
166  param = new simpleOfdmSendParam (burstSize,
167  isFirstBlock,
168  frequency,
169  modulationType,
170  direction,
171  rxPowerDbm,
172  burst);
173  Ptr<Object> dstNetDevice = (*iter)->GetDevice ();
174  uint32_t dstNode;
175  if (dstNetDevice == 0)
176  {
177  dstNode = 0xffffffff;
178  }
179  else
180  {
181  dstNode = dstNetDevice->GetObject<NetDevice> ()->GetNode ()->GetId ();
182  }
184  delay,
186  this,
187  *iter,
188  param);
189  }
190  }
191 
192 }
193 
194 void
196 {
197  rxphy->StartReceive (param->GetBurstSize (),
198  param->GetIsFirstBlock (),
199  param->GetFrequency (),
200  param->GetModulationType (),
201  param->GetDirection (),
202  param->GetRxPowerDbm (),
203  param->GetBurst ());
204  delete param;
205 }
206 
207 int64_t
209 {
210  int64_t currentStream = stream;
211  typedef std::list<Ptr<SimpleOfdmWimaxPhy> > PhyList;
212  for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i++)
213  {
214  Ptr<SimpleOfdmWimaxPhy> simpleOfdm = (*i);
215  currentStream += simpleOfdm->AssignStreams (currentStream);
216  }
217  return (currentStream - stream);
218 }
219 
220 }
221 // namespace ns3
Ptr< NetDevice > DoGetDevice(uint32_t i) const
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
double GetDistanceFrom(Ptr< const MobilityModel > position) const
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
Keep track of the current position and velocity of an object.
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.
WimaxPhy::ModulationType GetModulationType(void)
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
std::list< Ptr< SimpleOfdmWimaxPhy > > m_phyList
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:904
#define list
void SetPropagationModel(PropModel propModel)
sets the propagation model
Network layer to device interface.
Definition: net-device.h:75
NS_LOG_COMPONENT_DEFINE("simpleOfdmWimaxChannel")
void EndSendDummyBlock(Ptr< SimpleOfdmWimaxPhy > rxphy, simpleOfdmSendParam *param)
Ptr< PacketBurst > GetBurst(void)
Ptr< T > GetObject(void) const
Definition: object.h:361
Ptr< PropagationLossModel > m_loss
void DoAttach(Ptr< WimaxPhy > phy)