OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2012 CTTC |
| 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: Nicola Baldo <nbaldo@cttc.es> |
| 19 */ |
| 20 |
| 21 |
| 22 #include "nist-radio-environment-map-helper.h" |
| 23 |
| 24 #include <ns3/abort.h> |
| 25 #include <ns3/log.h> |
| 26 #include <ns3/double.h> |
| 27 #include <ns3/integer.h> |
| 28 #include <ns3/uinteger.h> |
| 29 #include <ns3/string.h> |
| 30 #include <ns3/boolean.h> |
| 31 #include <ns3/spectrum-channel.h> |
| 32 #include <ns3/config.h> |
| 33 #include <ns3/nist-rem-spectrum-phy.h> |
| 34 #include <ns3/mobility-building-info.h> |
| 35 #include <ns3/constant-position-mobility-model.h> |
| 36 #include <ns3/simulator.h> |
| 37 #include <ns3/node.h> |
| 38 #include <ns3/buildings-helper.h> |
| 39 #include <ns3/nist-lte-spectrum-value-helper.h> |
| 40 |
| 41 #include <fstream> |
| 42 #include <limits> |
| 43 |
| 44 namespace ns3 { |
| 45 |
| 46 NS_LOG_COMPONENT_DEFINE ("NistRadioEnvironmentMapHelper"); |
| 47 |
| 48 NS_OBJECT_ENSURE_REGISTERED (NistRadioEnvironmentMapHelper); |
| 49 |
| 50 NistRadioEnvironmentMapHelper::NistRadioEnvironmentMapHelper () |
| 51 { |
| 52 } |
| 53 |
| 54 |
| 55 NistRadioEnvironmentMapHelper::~NistRadioEnvironmentMapHelper () |
| 56 { |
| 57 } |
| 58 |
| 59 |
| 60 |
| 61 void |
| 62 NistRadioEnvironmentMapHelper::DoDispose () |
| 63 { |
| 64 NS_LOG_FUNCTION (this); |
| 65 } |
| 66 |
| 67 TypeId |
| 68 NistRadioEnvironmentMapHelper::GetTypeId (void) |
| 69 { |
| 70 NS_LOG_FUNCTION ("NistRadioEnvironmentMapHelper::GetTypeId"); |
| 71 static TypeId tid = TypeId ("ns3::NistRadioEnvironmentMapHelper") |
| 72 .SetParent<Object> () |
| 73 .AddConstructor<NistRadioEnvironmentMapHelper> () |
| 74 .AddAttribute ("ChannelPath", "The path to the channel for which the Radio E
nvironment Map is to be generated", |
| 75 StringValue ("/ChannelList/0"), |
| 76 MakeStringAccessor (&NistRadioEnvironmentMapHelper::m_channel
Path), |
| 77 MakeStringChecker ()) |
| 78 .AddAttribute ("OutputFile", "the filename to which the Radio Environment Ma
p is saved", |
| 79 StringValue ("rem.out"), |
| 80 MakeStringAccessor (&NistRadioEnvironmentMapHelper::m_outputF
ile), |
| 81 MakeStringChecker ()) |
| 82 .AddAttribute ("XMin", "The min x coordinate of the map.", |
| 83 DoubleValue (0.0), |
| 84 MakeDoubleAccessor (&NistRadioEnvironmentMapHelper::m_xMin), |
| 85 MakeDoubleChecker<double> ()) |
| 86 .AddAttribute ("YMin", "The min y coordinate of the map.", |
| 87 DoubleValue (0.0), |
| 88 MakeDoubleAccessor (&NistRadioEnvironmentMapHelper::m_yMin), |
| 89 MakeDoubleChecker<double> ()) |
| 90 .AddAttribute ("XMax", "The max x coordinate of the map.", |
| 91 DoubleValue (1.0), |
| 92 MakeDoubleAccessor (&NistRadioEnvironmentMapHelper::m_xMax), |
| 93 MakeDoubleChecker<double> ()) |
| 94 .AddAttribute ("YMax", "The max y coordinate of the map.", |
| 95 DoubleValue (1.0), |
| 96 MakeDoubleAccessor (&NistRadioEnvironmentMapHelper::m_yMax), |
| 97 MakeDoubleChecker<double> ()) |
| 98 .AddAttribute ("XRes", "The resolution (number of points) of the map along th
e x axis.", |
| 99 UintegerValue (100), |
| 100 MakeUintegerAccessor (&NistRadioEnvironmentMapHelper::m_xRes)
, |
| 101 MakeUintegerChecker<uint32_t> (2,std::numeric_limits<uint16_t>
::max ())) |
| 102 .AddAttribute ("YRes", "The resolution (number of points) of the map along t
he y axis.", |
| 103 UintegerValue (100), |
| 104 MakeUintegerAccessor (&NistRadioEnvironmentMapHelper::m_yRes)
, |
| 105 MakeUintegerChecker<uint16_t> (2,std::numeric_limits<uint16_t
>::max ())) |
| 106 .AddAttribute ("Z", "The value of the z coordinate for which the map is to b
e generated", |
| 107 DoubleValue (0.0), |
| 108 MakeDoubleAccessor (&NistRadioEnvironmentMapHelper::m_z), |
| 109 MakeDoubleChecker<double> ()) |
| 110 .AddAttribute ("StopWhenDone", "If true, Simulator::Stop () will be called a
s soon as the REM has been generated", |
| 111 BooleanValue (true), |
| 112 MakeBooleanAccessor (&NistRadioEnvironmentMapHelper::m_stopWh
enDone), |
| 113 MakeBooleanChecker ()) |
| 114 .AddAttribute ("NoisePower", |
| 115 "the power of the measuring instrument noise, in Watts. Defau
lt to a kT of -174 dBm with a noise figure of 9 dB and a bandwidth of 25 LTE Res
ource Blocks", |
| 116 DoubleValue (1.4230e-13), |
| 117 MakeDoubleAccessor (&NistRadioEnvironmentMapHelper::m_noisePo
wer), |
| 118 MakeDoubleChecker<double> ()) |
| 119 .AddAttribute ("MaxPointsPerIteration", "Maximum number of REM points to be
calculated per iteration. Every point consumes approximately 5KB of memory.", |
| 120 UintegerValue (20000), |
| 121 MakeUintegerAccessor (&NistRadioEnvironmentMapHelper::m_maxPo
intsPerIteration), |
| 122 MakeUintegerChecker<uint32_t> (1,std::numeric_limits<uint32_t
>::max ())) |
| 123 .AddAttribute ("Earfcn", |
| 124 "E-UTRA Absolute Radio Frequency Channel Number (EARFCN) " |
| 125 "as per 3GPP 36.101 Section 5.7.3. ", |
| 126 UintegerValue (100), |
| 127 MakeUintegerAccessor (&NistRadioEnvironmentMapHelper::m_earfc
n), |
| 128 MakeUintegerChecker<uint16_t> ()) |
| 129 .AddAttribute ("Bandwidth", |
| 130 "Transmission Bandwidth Configuration (in number of RBs) over
which the SINR will be calculated", |
| 131 UintegerValue (25), |
| 132 MakeUintegerAccessor (&NistRadioEnvironmentMapHelper::SetBand
width,· |
| 133 &NistRadioEnvironmentMapHelper::GetBand
width), |
| 134 MakeUintegerChecker<uint16_t> ()) |
| 135 .AddAttribute ("UseDataChannel", |
| 136 "If true, REM will be generated for PDSCH and for PDCCH other
wise ", |
| 137 BooleanValue (false), |
| 138 MakeBooleanAccessor (&NistRadioEnvironmentMapHelper::m_useDat
aChannel), |
| 139 MakeBooleanChecker ()) |
| 140 .AddAttribute ("RbId", |
| 141 "Resource block Id, for which REM will be generated," |
| 142 "default value is -1, what means REM will be averaged from al
l RBs", |
| 143 IntegerValue (-1), |
| 144 MakeIntegerAccessor (&NistRadioEnvironmentMapHelper::m_rbId), |
| 145 MakeIntegerChecker<int32_t> ()) |
| 146 ; |
| 147 return tid; |
| 148 } |
| 149 |
| 150 |
| 151 uint8_t· |
| 152 NistRadioEnvironmentMapHelper::GetBandwidth () const |
| 153 { |
| 154 return m_bandwidth; |
| 155 } |
| 156 |
| 157 void· |
| 158 NistRadioEnvironmentMapHelper::SetBandwidth (uint8_t bw) |
| 159 { |
| 160 switch (bw) |
| 161 {· |
| 162 case 6: |
| 163 case 15: |
| 164 case 25: |
| 165 case 50: |
| 166 case 75: |
| 167 case 100: |
| 168 m_bandwidth = bw; |
| 169 break; |
| 170 |
| 171 default: |
| 172 NS_FATAL_ERROR ("invalid bandwidth value " << (uint16_t) bw); |
| 173 break; |
| 174 } |
| 175 } |
| 176 |
| 177 |
| 178 |
| 179 void· |
| 180 NistRadioEnvironmentMapHelper::Install () |
| 181 { |
| 182 NS_LOG_FUNCTION (this); |
| 183 if (!m_rem.empty ()) |
| 184 { |
| 185 NS_FATAL_ERROR ("only one REM supported per instance of NistRadioEnvironme
ntMapHelper"); |
| 186 } |
| 187 Config::MatchContainer match = Config::LookupMatches (m_channelPath); |
| 188 if (match.GetN () != 1) |
| 189 { |
| 190 NS_FATAL_ERROR ("Lookup " << m_channelPath << " should have exactly one ma
tch"); |
| 191 } |
| 192 m_channel = match.Get (0)->GetObject<SpectrumChannel> (); |
| 193 NS_ABORT_MSG_IF (m_channel == 0, "object at " << m_channelPath << "is not of t
ype SpectrumChannel"); |
| 194 |
| 195 m_outFile.open (m_outputFile.c_str ()); |
| 196 if (!m_outFile.is_open ()) |
| 197 { |
| 198 NS_FATAL_ERROR ("Can't open file " << (m_outputFile)); |
| 199 return; |
| 200 } |
| 201 ·· |
| 202 double startDelay = 0.0026; |
| 203 |
| 204 if (m_useDataChannel) |
| 205 { |
| 206 //need time to start transmission of data channel |
| 207 startDelay = 0.5001; |
| 208 } |
| 209 |
| 210 Simulator::Schedule (Seconds (startDelay), |
| 211 &NistRadioEnvironmentMapHelper::DelayedInstall, |
| 212 this); |
| 213 } |
| 214 |
| 215 |
| 216 void· |
| 217 NistRadioEnvironmentMapHelper::DelayedInstall () |
| 218 { |
| 219 NS_LOG_FUNCTION (this); |
| 220 m_xStep = (m_xMax - m_xMin)/(m_xRes-1); |
| 221 m_yStep = (m_yMax - m_yMin)/(m_yRes-1); |
| 222 ·· |
| 223 if ((double)m_xRes * (double) m_yRes < (double) m_maxPointsPerIteration) |
| 224 { |
| 225 m_maxPointsPerIteration = m_xRes * m_yRes; |
| 226 } |
| 227 ·· |
| 228 for (uint32_t i = 0; i < m_maxPointsPerIteration; ++i) |
| 229 { |
| 230 NistRemPoint p; |
| 231 p.phy = CreateObject<NistRemSpectrumPhy> (); |
| 232 p.bmm = CreateObject<ConstantPositionMobilityModel> (); |
| 233 Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo
> (); |
| 234 p.bmm->AggregateObject (buildingInfo); // operation usually done by Buildi
ngsHelper::Install |
| 235 p.phy->SetRxSpectrumModel (NistLteSpectrumValueHelper::GetSpectrumModel (m
_earfcn, m_bandwidth)); |
| 236 p.phy->SetMobility (p.bmm); |
| 237 p.phy->SetUseDataChannel (m_useDataChannel); |
| 238 p.phy->SetRbId (m_rbId); |
| 239 m_channel->AddRx (p.phy); |
| 240 m_rem.push_back (p); |
| 241 } |
| 242 |
| 243 double remIterationStartTime = 0.0001; |
| 244 double xMinNext = m_xMin; |
| 245 double yMinNext = m_yMin; |
| 246 uint32_t numPointsCurrentIteration = 0; |
| 247 bool justScheduled = false; |
| 248 for (double x = m_xMin; x < m_xMax + 0.5*m_xStep; x += m_xStep) |
| 249 { |
| 250 for (double y = m_yMin; y < m_yMax + 0.5*m_yStep ; y += m_yStep) |
| 251 { |
| 252 if (justScheduled) |
| 253 { |
| 254 xMinNext = x; |
| 255 yMinNext = y; |
| 256 justScheduled = false; |
| 257 } |
| 258 ·········· |
| 259 ++numPointsCurrentIteration; |
| 260 if ((numPointsCurrentIteration == m_maxPointsPerIteration) |
| 261 || ((x > m_xMax - 0.5*m_xStep) && (y > m_yMax - 0.5*m_yStep)) ) |
| 262 { |
| 263 Simulator::Schedule (Seconds (remIterationStartTime),· |
| 264 &NistRadioEnvironmentMapHelper::RunOneIterati
on, |
| 265 this, xMinNext, x, yMinNext, y); |
| 266 remIterationStartTime += 0.001; |
| 267 justScheduled = true; |
| 268 numPointsCurrentIteration = 0; |
| 269 } |
| 270 }······ |
| 271 } |
| 272 |
| 273 Simulator::Schedule (Seconds (remIterationStartTime),· |
| 274 &NistRadioEnvironmentMapHelper::Finalize, |
| 275 this); |
| 276 } |
| 277 |
| 278 ·· |
| 279 void· |
| 280 NistRadioEnvironmentMapHelper::RunOneIteration (double xMin, double xMax, double
yMin, double yMax) |
| 281 { |
| 282 NS_LOG_FUNCTION (this << xMin << xMax << yMin << yMax); |
| 283 std::list<NistRemPoint>::iterator remIt = m_rem.begin (); |
| 284 double x; |
| 285 double y; |
| 286 for (x = xMin; x < xMax + 0.5*m_xStep; x += m_xStep) |
| 287 { |
| 288 for (y = (x == xMin) ? yMin : m_yMin; |
| 289 y < ((x == xMax) ? yMax : m_yMax) + 0.5*m_yStep; |
| 290 y += m_yStep) |
| 291 { |
| 292 NS_ASSERT (remIt != m_rem.end ()); |
| 293 remIt->bmm->SetPosition (Vector (x, y, m_z)); |
| 294 BuildingsHelper::MakeConsistent (remIt->bmm); |
| 295 ++remIt; |
| 296 }······ |
| 297 } |
| 298 |
| 299 if (remIt != m_rem.end ()) |
| 300 { |
| 301 NS_ASSERT ((x > m_xMax - 0.5*m_xStep) && (y > m_yMax - 0.5*m_yStep)); |
| 302 NS_LOG_LOGIC ("deactivating NistRemSpectrumPhys that are unneeded in the l
ast iteration"); |
| 303 while (remIt != m_rem.end ()) |
| 304 { |
| 305 remIt->phy->Deactivate (); |
| 306 ++remIt; |
| 307 } |
| 308 } |
| 309 |
| 310 Simulator::Schedule (Seconds (0.0005), &NistRadioEnvironmentMapHelper::PrintAn
dReset, this);·· |
| 311 } |
| 312 |
| 313 void· |
| 314 NistRadioEnvironmentMapHelper::PrintAndReset () |
| 315 { |
| 316 NS_LOG_FUNCTION (this); |
| 317 ·· |
| 318 for (std::list<NistRemPoint>::iterator it = m_rem.begin (); |
| 319 it != m_rem.end (); |
| 320 ++it) |
| 321 { |
| 322 if (!(it->phy->IsActive ())) |
| 323 { |
| 324 // should occur only upon last iteration when some NistRemPoint |
| 325 // at the end of the list can be unused |
| 326 break; |
| 327 } |
| 328 Vector pos = it->bmm->GetPosition (); |
| 329 NS_LOG_LOGIC ("output: " << pos.x << "\t"· |
| 330 << pos.y << "\t"· |
| 331 << pos.z << "\t"· |
| 332 << it->phy->GetSinr (m_noisePower)); |
| 333 m_outFile << pos.x << "\t"· |
| 334 << pos.y << "\t"· |
| 335 << pos.z << "\t"· |
| 336 << it->phy->GetSinr (m_noisePower) |
| 337 << std::endl; |
| 338 it->phy->Reset (); |
| 339 } |
| 340 } |
| 341 |
| 342 void· |
| 343 NistRadioEnvironmentMapHelper::Finalize () |
| 344 { |
| 345 NS_LOG_FUNCTION (this); |
| 346 m_outFile.close (); |
| 347 if (m_stopWhenDone) |
| 348 { |
| 349 Simulator::Stop (); |
| 350 } |
| 351 } |
| 352 |
| 353 |
| 354 } // namespace ns3 |
OLD | NEW |