EMANE  1.2.1
configurationvalidator.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - 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 
33 #include "configurationvalidator.h"
34 
35 #include <map>
36 
37 std::pair<std::string,bool>
39 {
40  std::map<std::string,std::vector<Any>> parameters;
41 
42  std::transform(updates.begin(),
43  updates.end(),
44  std::inserter(parameters,parameters.end()),
45  [](const ConfigurationUpdate::value_type & p)
46  {
47  return std::make_pair(p.first,p.second);
48  });
49 
50  if(parameters["cwmin0"][0] >= parameters["cwmax0"][0])
51  {
52  return std::make_pair("cwmin0 must be less than cwmax0", false);
53  }
54 
55  if(parameters["cwmin1"][0] >= parameters["cwmax1"][0])
56  {
57  return std::make_pair("cwmin1 must be less than cwmax1", false);
58  }
59 
60  if(parameters["cwmin2"][0] >= parameters["cwmax2"][0])
61  {
62  return std::make_pair("cwmin2 must be less than cwmax2", false);
63  }
64 
65  if(parameters["cwmin3"][0] >= parameters["cwmax3"][0])
66  {
67  return std::make_pair("cwmin3 must be less than cwmax3", false);
68  }
69 
70  // 80211A
71  if(parameters["mode"][0].asUINT8() == 1)
72  {
73  // unicast data rate index is only valid for 5 to 12 inclusive
74  if(parameters["unicastrate"][0].asUINT8() < 5 || parameters["unicastrate"][0].asUINT8() > 12)
75  {
76  return std::make_pair("unicastrate range is [5-12] for mode 80211A", false);
77  }
78 
79  // broadcast data rate index is only valid for 5 to 12 inclusive
80  if(parameters["multicastrate"][0].asUINT8() < 5 || parameters["multicastrate"][0].asUINT8() > 12)
81  {
82  return std::make_pair("multicastrate range [5-12] for mode 80211A", false);
83  }
84  }
85 
86  // 80211B
87  if(parameters["mode"][0].asUINT8() == 2 || parameters["mode"][0].asUINT8() == 0)
88  {
89  // unicast data rate index is only valid for 1 to 4 inclusive
90  if(parameters["unicastrate"][0].asUINT8() < 1 || parameters["unicastrate"][0].asUINT8() > 4)
91  {
92  return std::make_pair("unicastrate range [1-4] for mode 80211B", false);
93  }
94 
95  // broadcast data rate index is only valid for 1 to 4 inclusive
96  if(parameters["multicastrate"][0].asUINT8() < 1 || parameters["multicastrate"][0].asUINT8() > 4)
97  {
98  return std::make_pair("multicastrate range [1-4] for mode 80211B", false);
99  }
100  }
101 
102  // 80211BG
103  if(parameters["mode"][0].asUINT8() == 3)
104  {
105  // unicast data rate index is only valid for 1 to 12 inclusive
106  if(parameters["unicastrate"][0].asUINT8() < 1 || parameters["unicastrate"][0].asUINT8() > 12)
107  {
108  return std::make_pair("unicastrate range [1-12] for mode 80211BG", false);
109  }
110 
111  // broadcast data rate index is only valid for 1 to 12 inclusive
112  if(parameters["multicastrate"][0].asUINT8() < 1 || parameters["multicastrate"][0].asUINT8() > 12)
113  {
114  return std::make_pair("multicastrate range [1-12] for mode 80211BG", false);
115  }
116  }
117 
118 
119  return std::make_pair("", true);
120 }
std::pair< std::string, bool > configurationValidator(const ConfigurationUpdate &updates) noexcept
std::vector< ConfigurationNameAnyValues > ConfigurationUpdate