EMANE  1.0.1
slotstatustablepublisher.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016 - 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 
34 
36 {
37  pTxSlotStatusTable_ =
38  statisticRegistrar.registerTable<std::uint32_t>("TxSlotStatusTable",
39  {"Index","Frame","Slot","Valid","Missed","Big",".25",".50",".75","1.0","1.25","1.50","1.75",">1.75"},
41  "Shows the number of Tx slot opportunities that were valid or missed based on slot timing deadlines");
42 
43  pRxSlotStatusTable_ =
44  statisticRegistrar.registerTable<std::uint32_t>("RxSlotStatusTable",
45  {"Index","Frame","Slot","Valid","Missed","Idle","Tx","Long","Freq",".25",".50",".75","1.0","1.25","1.50","1.75",">1.75"},
47  "Shows the number of Rx slot receptions that were valid or missed based on slot timing deadlines");
48 }
49 
51 
52 {
53  pTxSlotStatusTable_->clear();
54  pRxSlotStatusTable_->clear();
55 
56  txSlotCounterMap_.clear();
57  rxSlotCounterMap_.clear();
58 }
59 
60 void EMANE::Models::TDMA::SlotStatusTablePublisher::update(std::uint32_t u32RelativeIndex,
61  std::uint32_t u32RelativeSlotIndex,
62  std::uint32_t u32RelativeFrameIndex,
63  Status status,
64  double dSlotRemainingRatio)
65 {
66  switch(status)
67  {
68  case Status::TX_GOOD:
69  case Status::TX_MISSED:
70  case Status::TX_TOOBIG:
71  updateTx(u32RelativeIndex,
72  u32RelativeSlotIndex,
73  u32RelativeFrameIndex,
74  status,
75  dSlotRemainingRatio);
76  break;
77 
78  case Status::RX_GOOD:
79  case Status::RX_MISSED:
80  case Status::RX_IDLE:
81  case Status::RX_TX:
82  case Status::RX_TOOLONG:
84  updateRx(u32RelativeIndex,
85  u32RelativeSlotIndex,
86  u32RelativeFrameIndex,
87  status,
88  dSlotRemainingRatio);
89  break;
90  }
91 }
92 
93 void EMANE::Models::TDMA::SlotStatusTablePublisher::updateTx(std::uint32_t u32RelativeIndex,
94  std::uint32_t u32RelativeSlotIndex,
95  std::uint32_t u32RelativeFrameIndex,
96  Status status,
97  double dSlotRemainingRatio)
98 {
99  auto iter = txSlotCounterMap_.find(u32RelativeIndex);
100 
101  if(iter == txSlotCounterMap_.end())
102  {
103  iter = txSlotCounterMap_.insert({u32RelativeIndex,std::make_tuple(0ULL,0ULL,0ULL,std::array<std::uint64_t,8>())}).first;
104 
105  pTxSlotStatusTable_->addRow(u32RelativeIndex,
106  {Any{u32RelativeIndex},
107  Any{u32RelativeSlotIndex},
108  Any{u32RelativeFrameIndex},
109  Any{0L},
110  Any{0L},
111  Any{0L},
112  Any{0L},
113  Any{0L},
114  Any{0L},
115  Any{0L},
116  Any{0L},
117  Any{0L},
118  Any{0L},
119  Any{0L}});
120 
121  }
122 
123  auto & valid = std::get<0>(iter->second);
124  auto & missed = std::get<1>(iter->second);
125  auto & toobig = std::get<2>(iter->second);
126  auto & quantile = std::get<3>(iter->second);
127 
128  switch(status)
129  {
130  case Status::TX_GOOD:
131  pTxSlotStatusTable_->setCell(u32RelativeIndex,3,Any{++valid});
132  break;
133  case Status::TX_MISSED:
134  pTxSlotStatusTable_->setCell(u32RelativeIndex,4,Any{++missed});
135  break;
136  case Status::TX_TOOBIG:
137  pTxSlotStatusTable_->setCell(u32RelativeIndex,5,Any{++toobig});
138  break;
139  default:
140  break;
141  }
142 
143  double dSlotPassedRatio = 1 - dSlotRemainingRatio;
144  int iQuantileIndex {};
145 
146  if(dSlotPassedRatio <= 0.25)
147  {
148  iQuantileIndex = 0;
149  }
150  else if(dSlotPassedRatio <= 0.50)
151  {
152  iQuantileIndex = 1;
153  }
154  else if(dSlotPassedRatio <= 0.75)
155  {
156  iQuantileIndex = 2;
157  }
158  else if(dSlotPassedRatio <= 1.00)
159  {
160  iQuantileIndex = 3;
161  }
162  else if(dSlotPassedRatio <= 1.25)
163  {
164  iQuantileIndex = 4;
165  }
166  else if(dSlotPassedRatio <= 1.50)
167  {
168  iQuantileIndex = 5;
169  }
170  else if(dSlotPassedRatio <= 1.75)
171  {
172  iQuantileIndex = 6;
173  }
174  else
175  {
176  iQuantileIndex = 7;
177  }
178 
179  pTxSlotStatusTable_->setCell(u32RelativeIndex,iQuantileIndex+6,Any{++quantile[iQuantileIndex]});
180 }
181 
182 void EMANE::Models::TDMA::SlotStatusTablePublisher::updateRx(std::uint32_t u32RelativeIndex,
183  std::uint32_t u32RelativeSlotIndex,
184  std::uint32_t u32RelativeFrameIndex,
185  Status status,
186  double dSlotRemainingRatio)
187 {
188  auto iter = rxSlotCounterMap_.find(u32RelativeIndex);
189 
190  if(iter == rxSlotCounterMap_.end())
191  {
192  iter = rxSlotCounterMap_.insert({u32RelativeIndex,std::make_tuple(0ULL,0ULL,0ULL,0ULL,0ULL,0ULL,std::array<std::uint64_t,8>())}).first;
193 
194  pRxSlotStatusTable_->addRow(u32RelativeIndex,
195  {Any{u32RelativeIndex},
196  Any{u32RelativeSlotIndex},
197  Any{u32RelativeFrameIndex},
198  Any{0L},
199  Any{0L},
200  Any{0L},
201  Any{0L},
202  Any{0L},
203  Any{0L},
204  Any{0L},
205  Any{0L},
206  Any{0L},
207  Any{0L},
208  Any{0L},
209  Any{0L},
210  Any{0L},
211  Any{0L}});
212 
213  }
214 
215  auto & valid = std::get<0>(iter->second);
216  auto & missed = std::get<1>(iter->second);
217  auto & rxidle = std::get<2>(iter->second);
218  auto & rxtx = std::get<3>(iter->second);
219  auto & rxtoolong = std::get<4>(iter->second);
220  auto & rxwrongfreq = std::get<5>(iter->second);
221  auto & quantile = std::get<6>(iter->second);
222 
223  switch(status)
224  {
225  case Status::RX_GOOD:
226  pRxSlotStatusTable_->setCell(u32RelativeIndex,3,Any{++valid});
227  break;
228  case Status::RX_MISSED:
229  pRxSlotStatusTable_->setCell(u32RelativeIndex,4,Any{++missed});
230  break;
231  case Status::RX_IDLE:
232  pRxSlotStatusTable_->setCell(u32RelativeIndex,5,Any{++rxidle});
233  break;
234  case Status::RX_TX:
235  pRxSlotStatusTable_->setCell(u32RelativeIndex,6,Any{++rxtx});
236  break;
237  case Status::RX_TOOLONG:
238  pRxSlotStatusTable_->setCell(u32RelativeIndex,7,Any{++rxtoolong});
239  break;
241  pRxSlotStatusTable_->setCell(u32RelativeIndex,8,Any{++rxwrongfreq});
242  break;
243  default:
244  break;
245  }
246 
247  // ratio is either how much is left (< 1) or how much went over
248  double dSlotPassedRatio{dSlotRemainingRatio};
249 
250  if(dSlotRemainingRatio < 1)
251  {
252  dSlotPassedRatio = 1 - dSlotRemainingRatio;
253  }
254 
255  int iQuantileIndex {};
256 
257  if(dSlotPassedRatio <= 0.25)
258  {
259  iQuantileIndex = 0;
260  }
261  else if(dSlotPassedRatio <= 0.50)
262  {
263  iQuantileIndex = 1;
264  }
265  else if(dSlotPassedRatio <= 0.75)
266  {
267  iQuantileIndex = 2;
268  }
269  else if(dSlotPassedRatio <= 1.00)
270  {
271  iQuantileIndex = 3;
272  }
273  else if(dSlotPassedRatio <= 1.25)
274  {
275  iQuantileIndex = 4;
276  }
277  else if(dSlotPassedRatio <= 1.50)
278  {
279  iQuantileIndex = 5;
280  }
281  else if(dSlotPassedRatio <= 1.75)
282  {
283  iQuantileIndex = 6;
284  }
285  else
286  {
287  iQuantileIndex = 7;
288  }
289 
290  pRxSlotStatusTable_->setCell(u32RelativeIndex,iQuantileIndex+9,Any{++quantile[iQuantileIndex]});
291 }
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