EMANE  1.2.1
nakagamifadingalgorithm.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2018 - Adjacent Link LLC, Bridgewater, New Jersey
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Adjacent Link LLC nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
36 #include <random>
37 #include <map>
38 
40  PlatformServiceProvider * pPlatformService,
41  const std::string & sPrefix):
42  FadingAlgorithm{"nakagami",id,pPlatformService,sPrefix},
43  dm0_{},
44  dm1_{},
45  dm2_{},
46  dDistance0Meters_{},
47  dDistance1Meters_{}{}
48 
50 {
51  auto & configRegistrar = registrar.configurationRegistrar();
52 
53  configRegistrar.registerNumeric<double>(sPrefix_ + "nakagami.m0",
56  {0.75},
57  "Defines the shape factor to use for distance"
58  " < fading.nakagami.distance0.",
59  0.5);
60 
61  configRegistrar.registerNumeric<double>(sPrefix_ + "nakagami.m1",
64  {1.0},
65  "Defines the shape factor to use for distance"
66  " >= fading.nakagami.distance0 and <"
67  " fading.nakagami.distance1.",
68  0.5);
69 
70  configRegistrar.registerNumeric<double>(sPrefix_ + "nakagami.m2",
73  {200},
74  "Defines the shape factor to use for distance"
75  " >= fading.nakagami.distance1.",
76  0.5);
77 
78  configRegistrar.registerNumeric<double>(sPrefix_ + "nakagami.distance0",
81  {100},
82  "Defines the distance in meters used for"
83  " lower bound shape selection.");
84 
85  configRegistrar.registerNumeric<double>(sPrefix_ + "nakagami.distance1",
88  {250},
89  "Defines the distance in meters used for"
90  " upper bound shape selection.");
91 
92  configRegistrar.registerValidator([this](const ConfigurationUpdate & update) noexcept
93  {
94  std::map<std::string,std::vector<Any>> parameters;
95 
96  std::transform(update.begin(),
97  update.end(),
98  std::inserter(parameters,parameters.end()),
99  [](const ConfigurationUpdate::value_type & p)
100  {
101  return std::make_pair(p.first,p.second);
102  });
103 
104  if(parameters[sPrefix_ + "nakagami.distance0"][0].asDouble() >=
105  parameters[sPrefix_ + "nakagami.distance1"][0].asDouble())
106  {
107  return std::make_pair("nakagami.distance0 < nakagami.distance1", false);
108  }
109 
110  return std::make_pair("",true);
111  });
112 }
113 
115 {
116  configure_i(update);
117 }
118 
120 {
121  configure_i(update);
122 }
123 
124 void EMANE::NakagamiFadingAlgorithm::configure_i(const ConfigurationUpdate & update)
125 {
126  for(const auto & item : update)
127  {
128  if(item.first == sPrefix_ + "nakagami.m0")
129  {
130  dm0_ = item.second[0].asDouble();
131 
133  INFO_LEVEL,
134  "PHYI %03hu FrameworkPHY::NakagamiFadingAlgorithm::%s: %s = %lf",
135  id_,
136  __func__,
137  item.first.c_str(),
138  dm0_);
139  }
140  else if(item.first == sPrefix_ + "nakagami.m1")
141  {
142  dm1_ = item.second[0].asDouble();
143 
145  INFO_LEVEL,
146  "PHYI %03hu FrameworkPHY::NakagamiFadingAlgorithm::%s: %s = %lf",
147  id_,
148  __func__,
149  item.first.c_str(),
150  dm1_);
151  }
152  else if(item.first == sPrefix_ + "nakagami.m2")
153  {
154  dm2_ = item.second[0].asDouble();
155 
157  INFO_LEVEL,
158  "PHYI %03hu FrameworkPHY::NakagamiFadingAlgorithm::%s: %s = %lf",
159  id_,
160  __func__,
161  item.first.c_str(),
162  dm1_);
163  }
164  else if(item.first == sPrefix_ + "nakagami.distance0")
165  {
166  dDistance0Meters_ = item.second[0].asDouble();
167 
169  INFO_LEVEL,
170  "PHYI %03hu FrameworkPHY::NakagamiFadingAlgorithm::%s: %s = %lf",
171  id_,
172  __func__,
173  item.first.c_str(),
174  dDistance0Meters_);
175  }
176  else if(item.first == sPrefix_ + "nakagami.distance1")
177  {
178  dDistance1Meters_ = item.second[0].asDouble();
179 
181  INFO_LEVEL,
182  "PHYI %03hu FrameworkPHY::NakagamiFadingAlgorithm::%s: %s = %lf",
183  id_,
184  __func__,
185  item.first.c_str(),
186  dDistance1Meters_);
187  }
188  }
189 }
The Registrar interface provides access to all of the emulator registrars.
Definition: registrar.h:50
virtual ConfigurationRegistrar & configurationRegistrar()=0
The PlatformServiceProvider interface provides access to emulator services.
void modify(const ConfigurationUpdate &update) override
void configure(const ConfigurationUpdate &update)
std::uint16_t NEMId
Definition: types.h:52
const std::string sPrefix_
virtual LogServiceProvider & logService()=0
NakagamiFadingAlgorithm(NEMId id, PlatformServiceProvider *pPlatformService, const std::string &sPrefix)
std::vector< ConfigurationNameAnyValues > ConfigurationUpdate
void registerNumeric(const std::string &sName, const ConfigurationProperties &properties=ConfigurationProperties::NONE, const std::initializer_list< T > &values={}, const std::string &sUsage="", T minValue=std::numeric_limits< T >::lowest(), T maxValue=std::numeric_limits< T >::max(), std::size_t minOccurs=1, std::size_t maxOccurs=1, const std::string &sRegexPattern={})
void initialize(Registrar &registrar) override
#define LOGGER_STANDARD_LOGGING(logger, level, fmt, args...)
PlatformServiceProvider *const pPlatformService_