EMANE  1.2.1
slotstatustablepublisher.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016,2018 - Adjacent Link LLC, Bridgewater,
3  * New Jersey
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Adjacent Link LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
35 
37 {
38  pTxSlotStatusTable_ =
39  statisticRegistrar.registerTable<std::uint32_t>("TxSlotStatusTable",
40  {"Index",
41  "Frame",
42  "Slot",
43  "Valid",
44  "Missed",
45  "Big",
46  ".25",
47  ".50",
48  ".75",
49  "1.0",
50  "1.25",
51  "1.50",
52  "1.75",
53  ">1.75"},
55  "Shows the number of Tx slot opportunities that were valid or missed based on slot timing deadlines");
56 
57  pRxSlotStatusTable_ =
58  statisticRegistrar.registerTable<std::uint32_t>("RxSlotStatusTable",
59  {"Index",
60  "Frame",
61  "Slot",
62  "Valid",
63  "Missed",
64  "Idle",
65  "Tx",
66  "Long",
67  "Freq",
68  "Lock",
69  ".25",
70  ".50",
71  ".75",
72  "1.0",
73  "1.25",
74  "1.50",
75  "1.75",
76  ">1.75"},
78  "Shows the number of Rx slot receptions that were valid or missed based on slot timing deadlines");
79 }
80 
82 
83 {
84  pTxSlotStatusTable_->clear();
85  pRxSlotStatusTable_->clear();
86 
87  txSlotCounterMap_.clear();
88  rxSlotCounterMap_.clear();
89 }
90 
91 void EMANE::Models::TDMA::SlotStatusTablePublisher::update(std::uint32_t u32RelativeIndex,
92  std::uint32_t u32RelativeSlotIndex,
93  std::uint32_t u32RelativeFrameIndex,
94  Status status,
95  double dSlotRemainingRatio)
96 {
97  switch(status)
98  {
99  case Status::TX_GOOD:
100  case Status::TX_MISSED:
101  case Status::TX_TOOBIG:
102  updateTx(u32RelativeIndex,
103  u32RelativeSlotIndex,
104  u32RelativeFrameIndex,
105  status,
106  dSlotRemainingRatio);
107  break;
108 
109  case Status::RX_GOOD:
110  case Status::RX_MISSED:
111  case Status::RX_IDLE:
112  case Status::RX_TX:
113  case Status::RX_TOOLONG:
115  case Status::RX_LOCK:
116  updateRx(u32RelativeIndex,
117  u32RelativeSlotIndex,
118  u32RelativeFrameIndex,
119  status,
120  dSlotRemainingRatio);
121  break;
122  }
123 }
124 
125 void EMANE::Models::TDMA::SlotStatusTablePublisher::updateTx(std::uint32_t u32RelativeIndex,
126  std::uint32_t u32RelativeSlotIndex,
127  std::uint32_t u32RelativeFrameIndex,
128  Status status,
129  double dSlotPortionRatio)
130 {
131  auto iter = txSlotCounterMap_.find(u32RelativeIndex);
132 
133  if(iter == txSlotCounterMap_.end())
134  {
135  iter = txSlotCounterMap_.insert({u32RelativeIndex,std::make_tuple(0ULL,0ULL,0ULL,std::array<std::uint64_t,8>())}).first;
136 
137  pTxSlotStatusTable_->addRow(u32RelativeIndex,
138  {Any{u32RelativeIndex},
139  Any{u32RelativeSlotIndex},
140  Any{u32RelativeFrameIndex},
141  Any{0L},
142  Any{0L},
143  Any{0L},
144  Any{0L},
145  Any{0L},
146  Any{0L},
147  Any{0L},
148  Any{0L},
149  Any{0L},
150  Any{0L},
151  Any{0L}});
152 
153  }
154 
155  auto & valid = std::get<0>(iter->second);
156  auto & missed = std::get<1>(iter->second);
157  auto & toobig = std::get<2>(iter->second);
158  auto & quantile = std::get<3>(iter->second);
159 
160  switch(status)
161  {
162  case Status::TX_GOOD:
163  pTxSlotStatusTable_->setCell(u32RelativeIndex,3,Any{++valid});
164  break;
165  case Status::TX_MISSED:
166  pTxSlotStatusTable_->setCell(u32RelativeIndex,4,Any{++missed});
167  break;
168  case Status::TX_TOOBIG:
169  pTxSlotStatusTable_->setCell(u32RelativeIndex,5,Any{++toobig});
170  break;
171  default:
172  break;
173  }
174 
175  int iQuantileIndex {};
176 
177  if(dSlotPortionRatio <= 0.25)
178  {
179  iQuantileIndex = 0;
180  }
181  else if(dSlotPortionRatio <= 0.50)
182  {
183  iQuantileIndex = 1;
184  }
185  else if(dSlotPortionRatio <= 0.75)
186  {
187  iQuantileIndex = 2;
188  }
189  else if(dSlotPortionRatio <= 1.00)
190  {
191  iQuantileIndex = 3;
192  }
193  else if(dSlotPortionRatio <= 1.25)
194  {
195  iQuantileIndex = 4;
196  }
197  else if(dSlotPortionRatio <= 1.50)
198  {
199  iQuantileIndex = 5;
200  }
201  else if(dSlotPortionRatio <= 1.75)
202  {
203  iQuantileIndex = 6;
204  }
205  else
206  {
207  iQuantileIndex = 7;
208  }
209 
210  pTxSlotStatusTable_->setCell(u32RelativeIndex,iQuantileIndex+6,Any{++quantile[iQuantileIndex]});
211 }
212 
213 void EMANE::Models::TDMA::SlotStatusTablePublisher::updateRx(std::uint32_t u32RelativeIndex,
214  std::uint32_t u32RelativeSlotIndex,
215  std::uint32_t u32RelativeFrameIndex,
216  Status status,
217  double dSlotPortionRatio)
218 {
219  auto iter = rxSlotCounterMap_.find(u32RelativeIndex);
220 
221  if(iter == rxSlotCounterMap_.end())
222  {
223  iter = rxSlotCounterMap_.insert({u32RelativeIndex,std::make_tuple(0ULL,0ULL,0ULL,0ULL,0ULL,0ULL,0ULL,std::array<std::uint64_t,8>())}).first;
224 
225  pRxSlotStatusTable_->addRow(u32RelativeIndex,
226  {Any{u32RelativeIndex},
227  Any{u32RelativeSlotIndex},
228  Any{u32RelativeFrameIndex},
229  Any{0L},
230  Any{0L},
231  Any{0L},
232  Any{0L},
233  Any{0L},
234  Any{0L},
235  Any{0L},
236  Any{0L},
237  Any{0L},
238  Any{0L},
239  Any{0L},
240  Any{0L},
241  Any{0L},
242  Any{0L},
243  Any{0L}});
244 
245  }
246 
247  auto & valid = std::get<0>(iter->second);
248  auto & missed = std::get<1>(iter->second);
249  auto & rxidle = std::get<2>(iter->second);
250  auto & rxtx = std::get<3>(iter->second);
251  auto & rxtoolong = std::get<4>(iter->second);
252  auto & rxwrongfreq = std::get<5>(iter->second);
253  auto & rxlock = std::get<6>(iter->second);
254  auto & quantile = std::get<7>(iter->second);
255 
256  switch(status)
257  {
258  case Status::RX_GOOD:
259  pRxSlotStatusTable_->setCell(u32RelativeIndex,3,Any{++valid});
260  break;
261  case Status::RX_MISSED:
262  pRxSlotStatusTable_->setCell(u32RelativeIndex,4,Any{++missed});
263  break;
264  case Status::RX_IDLE:
265  pRxSlotStatusTable_->setCell(u32RelativeIndex,5,Any{++rxidle});
266  break;
267  case Status::RX_TX:
268  pRxSlotStatusTable_->setCell(u32RelativeIndex,6,Any{++rxtx});
269  break;
270  case Status::RX_TOOLONG:
271  pRxSlotStatusTable_->setCell(u32RelativeIndex,7,Any{++rxtoolong});
272  break;
274  pRxSlotStatusTable_->setCell(u32RelativeIndex,8,Any{++rxwrongfreq});
275  break;
276  case Status::RX_LOCK:
277  pRxSlotStatusTable_->setCell(u32RelativeIndex,9,Any{++rxlock});
278  break;
279  default:
280  break;
281  }
282 
283  int iQuantileIndex {};
284 
285  if(dSlotPortionRatio <= 0.25)
286  {
287  iQuantileIndex = 0;
288  }
289  else if(dSlotPortionRatio <= 0.50)
290  {
291  iQuantileIndex = 1;
292  }
293  else if(dSlotPortionRatio <= 0.75)
294  {
295  iQuantileIndex = 2;
296  }
297  else if(dSlotPortionRatio <= 1.00)
298  {
299  iQuantileIndex = 3;
300  }
301  else if(dSlotPortionRatio <= 1.25)
302  {
303  iQuantileIndex = 4;
304  }
305  else if(dSlotPortionRatio <= 1.50)
306  {
307  iQuantileIndex = 5;
308  }
309  else if(dSlotPortionRatio <= 1.75)
310  {
311  iQuantileIndex = 6;
312  }
313  else
314  {
315  iQuantileIndex = 7;
316  }
317 
318  pRxSlotStatusTable_->setCell(u32RelativeIndex,iQuantileIndex+10,Any{++quantile[iQuantileIndex]});
319 }
void registerStatistics(StatisticRegistrar &registrar)
void setCell(const Key &key, std::size_t columnIndex, const Any &any)
The StatisticRegistrar allows NEM layers to register statistics and statistic tables. Statistics and Statistic tables are owned by the emulator framework and a borrowed reference is returned to the registering NEM layer.
void update(std::uint32_t u32RelativeIndex, std::uint32_t u32RelativeFrameIndex, std::uint32_t u32RelativeSlotIndex, Status status, double dSlotRemainingRatio)
StatisticTable< Key, Compare, scolumn > * registerTable(const std::string &sName, const StatisticTableLabels &labels, const StatisticProperties &properties=StatisticProperties::NONE, const std::string &sDescription="")
void addRow(const Key &key, const std::vector< Any > &anys={})
The Any class can contain an instance of one of any type in its support type set. ...
Definition: any.h:49