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"
32#include "ns3/mobility-model.h"
33#include "ns3/cost231-propagation-loss-model.h"
35
36namespace ns3 {
37
38NS_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 */
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 {
70 m_loss = CreateObject<RandomPropagationLossModel> ();
71 break;
72
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
90void
92{
93
94 switch (propModel)
95 {
97 m_loss = CreateObject<RandomPropagationLossModel> ();
98 break;
99
101 m_loss = CreateObject<FriisPropagationLossModel> ();
102 break;
104 m_loss = CreateObject<LogDistancePropagationLossModel> ();
105 break;
106
108 m_loss = CreateObject<Cost231PropagationLossModel> ();
109 break;
110
111 default:
112 m_loss = 0;
113 }
114
115}
116
117void
119{
120 Ptr<SimpleOfdmWimaxPhy> o_phy = phy->GetObject<SimpleOfdmWimaxPhy> ();
121 m_phyList.push_back (o_phy);
122}
123
124std::size_t
126{
127 return m_phyList.size ();
128}
129
131SimpleOfdmWimaxChannel::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
147void
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
206void
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
219int64_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
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:96
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
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:74
SimpleOfdmWimaxChannel class.
Ptr< PropagationLossModel > m_loss
loss
void SetPropagationModel(PropModel propModel)
sets the propagation model
std::size_t DoGetNDevices(void) const
Get number of devices function.
void EndSendDummyBlock(Ptr< SimpleOfdmWimaxPhy > rxphy, simpleOfdmSendParam *param)
End send dummy block function.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void DoAttach(Ptr< WimaxPhy > phy)
Attach functiion.
Ptr< NetDevice > DoGetDevice(std::size_t i) const
Get device function.
std::list< Ptr< SimpleOfdmWimaxPhy > > m_phyList
phy list
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.
SimpleOfdmWimaxPhy class.
static void ScheduleWithContext(uint32_t context, Time const &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:571
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
The channel object to attach Wimax NetDevices.
Definition: wimax-channel.h:41
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:52
simpleOfdmSendParam class
WimaxPhy::ModulationType GetModulationType(void)
Ptr< PacketBurst > GetBurst(void)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
phy
Definition: third.py:93
#define list