satellite-phy-tx.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Magister Solutions Ltd.
4  * Copyright (c) 2018 CNES
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Jani Puttonen <jani.puttonen@magister.fi>
20  * Author: Mathias Ettinger <mettinger@toulouse.viveris.com>
21  */
22 
23 #include "satellite-phy-tx.h"
24 
26 #include "satellite-channel.h"
27 #include "satellite-phy.h"
29 #include "satellite-utils.h"
30 
31 #include <ns3/boolean.h>
32 #include <ns3/double.h>
33 #include <ns3/enum.h>
34 #include <ns3/log.h>
35 #include <ns3/object-factory.h>
36 #include <ns3/simulator.h>
37 
38 #include <cmath>
39 
40 NS_LOG_COMPONENT_DEFINE("SatPhyTx");
41 
42 namespace ns3
43 {
44 
45 NS_OBJECT_ENSURE_REGISTERED(SatPhyTx);
46 
48  : m_maxAntennaGain(),
49  m_state(RECONFIGURING),
50  m_beamId(),
51  m_txMode(),
52  m_defaultFadingValue()
53 {
54  NS_LOG_FUNCTION(this);
55 }
56 
58 {
59  NS_LOG_FUNCTION(this);
60 }
61 
62 void
64 {
65  NS_LOG_FUNCTION(this);
66  m_channel = 0;
67  m_mobility = 0;
69  Object::DoDispose();
70 }
71 
72 std::ostream&
73 operator<<(std::ostream& os, SatPhyTx::State s)
74 {
75  switch (s)
76  {
77  case SatPhyTx::IDLE:
78  os << "IDLE";
79  break;
80  case SatPhyTx::TX:
81  os << "TX";
82  break;
84  os << "RECONFIGURING";
85  break;
86  default:
87  os << "UNKNOWN";
88  break;
89  }
90  return os;
91 }
92 
93 TypeId
95 {
96  static TypeId tid = TypeId("ns3::SatPhyTx")
97  .SetParent<Object>()
98  .AddAttribute("TxMode",
99  "Tx mode of this Phy Tx.",
100  EnumValue(SatPhyTx::NORMAL),
101  MakeEnumAccessor(&SatPhyTx::m_txMode),
102  MakeEnumChecker(SatPhyTx::NORMAL,
103  "Normal Tx mode",
105  "Transparent Tx mode"));
106  return tid;
107 }
108 
109 void
111 {
112  NS_LOG_FUNCTION(this << gain_db);
113 
115 }
116 
117 double
118 SatPhyTx::GetAntennaGain(Ptr<MobilityModel> mobility)
119 {
120  NS_LOG_FUNCTION(this);
121 
122  double gain_W(m_maxAntennaGain);
123 
124  // Get the transmit antenna gain at the receiver position.
125  // E.g. GEO satellite transmits to the UT receiver.
127  {
128  Ptr<SatMobilityModel> m = DynamicCast<SatMobilityModel>(mobility);
129  gain_W = m_antennaGainPattern->GetAntennaGain_lin(m->GetGeoPosition(), m_satMobility);
130  }
131 
137  return gain_W;
138 }
139 
140 void
142 {
143  NS_LOG_FUNCTION(this << fadingValue);
144 
145  m_defaultFadingValue = fadingValue;
146 }
147 
148 double
149 SatPhyTx::GetFadingValue(Address macAddress, SatEnums::ChannelType_t channelType)
150 {
151  NS_LOG_FUNCTION(this << macAddress << channelType);
152 
153  double fadingValue = m_defaultFadingValue;
154 
155  if (m_fadingContainer)
156  {
157  fadingValue = m_fadingContainer->GetFading(macAddress, channelType);
158  }
159  // Returns value 1 if fading is not set, as fading value is used as multiplier
160  return fadingValue;
161 }
162 
163 void
164 SatPhyTx::SetFadingContainer(Ptr<SatBaseFading> fadingContainer)
165 {
166  NS_LOG_FUNCTION(this);
167  NS_ASSERT(m_fadingContainer == nullptr);
168 
169  m_fadingContainer = fadingContainer;
170 }
171 
172 Ptr<MobilityModel>
174 {
175  NS_LOG_FUNCTION(this);
176  NS_ASSERT(m_mobility != nullptr);
177 
178  return m_mobility;
179 }
180 
181 void
182 SatPhyTx::SetMobility(Ptr<MobilityModel> m)
183 {
184  NS_LOG_FUNCTION(this << m);
185  NS_ASSERT(m_mobility == nullptr);
186 
187  m_mobility = m;
188 }
189 
190 void
191 SatPhyTx::SetAntennaGainPattern(Ptr<SatAntennaGainPattern> agp, Ptr<SatMobilityModel> mobility)
192 {
193  NS_LOG_FUNCTION(this);
194  NS_ASSERT(m_antennaGainPattern == nullptr);
195 
196  m_antennaGainPattern = agp;
197  m_satMobility = mobility;
198 }
199 
200 void
201 SatPhyTx::SetChannel(Ptr<SatChannel> c)
202 {
203  NS_LOG_FUNCTION(this << c);
204  NS_ASSERT(m_channel == nullptr);
205 
206  m_channel = c;
207  ChangeState(IDLE);
208 }
209 
210 void
212 {
213  NS_LOG_FUNCTION(this);
214  NS_ASSERT(m_channel != nullptr);
215 
216  m_channel = NULL;
218 }
219 
220 Ptr<SatChannel>
222 {
223  NS_LOG_FUNCTION(this);
224  NS_ASSERT(m_channel != nullptr);
225 
226  return m_channel;
227 }
228 
229 void
231 {
232  NS_LOG_FUNCTION(this << newState);
233  NS_LOG_INFO(this << " state: " << m_state << " -> " << newState);
234  m_state = newState;
235 }
236 
237 void
238 SatPhyTx::StartTx(Ptr<SatSignalParameters> txParams)
239 {
240  NS_LOG_FUNCTION(this << txParams);
241  NS_LOG_INFO("State: " << m_state);
242 
243  switch (m_state)
244  {
245  case TX:
246  NS_FATAL_ERROR("cannot TX while already TX: the MAC should avoid this");
247  break;
248 
249  case IDLE: {
250  NS_ASSERT(m_channel);
251  ChangeState(TX);
252  m_channel->StartTx(txParams);
253 
263  if (m_txMode == TRANSPARENT)
264  {
265  EndTx();
266  }
267  else
268  {
269  Simulator::Schedule(txParams->m_duration, &SatPhyTx::EndTx, this);
270  }
271  }
272  break;
273 
274  case RECONFIGURING:
275  break;
276 
277  default:
278  NS_FATAL_ERROR("unknown state");
279  break;
280  }
281 }
282 
283 void
285 {
286  NS_LOG_FUNCTION(this);
287  NS_LOG_INFO(this << " state: " << m_state);
288 
289  if (m_state != TX)
290  {
291  NS_FATAL_ERROR("SatPhyTx::EndTx - unexpected state!");
292  }
293 
294  ChangeState(IDLE);
295 }
296 
297 void
298 SatPhyTx::SetSatId(uint32_t satId)
299 {
300  NS_LOG_FUNCTION(this << satId);
301  m_satId = satId;
302 }
303 
304 void
305 SatPhyTx::SetBeamId(uint32_t beamId)
306 {
307  NS_LOG_FUNCTION(this << beamId);
308  m_beamId = beamId;
309 }
310 
311 bool
313 {
314  NS_LOG_FUNCTION(this);
315 
316  return m_state == TX;
317 }
318 
319 bool
321 {
322  NS_LOG_FUNCTION(this);
323  return m_state != RECONFIGURING;
324 }
325 
326 } // namespace ns3
ChannelType_t
Types of channel.
void SetDefaultFadingValue(double fadingValue)
Function for setting the default fading value.
void SetSatId(uint32_t satId)
Set the satellite id for all the transmissions from this SatPhyTx.
bool CanTransmit(void) const
Tell whether or not this channel can transmit data.
Ptr< SatAntennaGainPattern > m_antennaGainPattern
void SetChannel(Ptr< SatChannel > c)
double m_maxAntennaGain
Configured maximum antenna gain in linear.
double GetFadingValue(Address macAddress, SatEnums::ChannelType_t channelType)
Get fading value.
Ptr< MobilityModel > m_mobility
Ptr< MobilityModel > GetMobility()
SatPhyTxMode_t m_txMode
void SetAntennaGainPattern(Ptr< SatAntennaGainPattern > agp, Ptr< SatMobilityModel > mobility)
bool IsTransmitting(void) const
Tell whether or not this channel is transmitting data.
virtual void EndTx()
void SetBeamId(uint32_t beamId)
Set the beam id for all the transmissions from this SatPhyTx.
double m_defaultFadingValue
Default fading value.
void ChangeState(State newState)
virtual void StartTx(Ptr< SatSignalParameters > txParams)
Start packet transmission to the channel.
void SetMobility(Ptr< MobilityModel > m)
State
PHY states.
Ptr< SatMobilityModel > m_satMobility
SatPhyTx()
Default constructor.
Ptr< SatBaseFading > m_fadingContainer
Fading container for fading model.
Ptr< SatChannel > GetChannel()
double GetAntennaGain(Ptr< MobilityModel > mobility)
Get antenna gain based on position or in case that antenna pattern is not configured,...
Ptr< SatChannel > m_channel
virtual ~SatPhyTx()
Destructor for SatPhyTx.
virtual void DoDispose()
Dispose of this class instance.
void SetMaxAntennaGain_Db(double gain_db)
Set the maximum Antenna gain in Db.
void SetFadingContainer(Ptr< SatBaseFading > fadingContainer)
Set fading container.
static TypeId GetTypeId(void)
inherited from Object
static T DbToLinear(T db)
Converts decibels to linear.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
std::ostream & operator<<(std::ostream &os, const GeoCoordinate &coordinate)