EMANE  1.2.1
queuestatuspublisher.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 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 "queuestatuspublisher.h"
34 
36  pQueueStatusTable_{},
37  statusTableInfo_{{0,{}},{1,{}},{2,{}},{3,{}},{4,{}}},
38  fragmentHistogram_{{0,{0}},{1,{0}},{2,{0}},{3,{0}},{4,{0}}}
39 {}
40 
42 {
43  pQueueStatusTable_ =
44  statisticRegistrar.registerTable<std::uint8_t>("QueueStatusTable",
45  {"Queue","Enqueued","Dequeued","Overflow","Too Big","0","1","2","3","4"},
47  "Shows for each queue the number of packets enqueued, dequeued,"
48  " dropped due to queue overflow (enqueue), dropped due to too big"
49  " (dequeue) and which slot classes fragments are being transmitted.");
50 
51  for(const auto & entry : statusTableInfo_)
52  {
53  pQueueStatusTable_->addRow(entry.first,
54  {Any{entry.first},
55  Any{std::get<0>(entry.second)},
56  Any{std::get<1>(entry.second)},
57  Any{std::get<2>(entry.second)},
58  Any{std::get<3>(entry.second)},
59  Any{std::get<4>(entry.second)},
60  Any{std::get<5>(entry.second)},
61  Any{std::get<6>(entry.second)},
62  Any{std::get<7>(entry.second)},
63  Any{std::get<8>(entry.second)}});
64 
65 
66 
67  }
68 
69 
70  pQueueFragmentHistogram_ =
71  statisticRegistrar.registerTable<std::uint8_t>("QueueFragmentHistogram",
72  {"Queue","1","2","3","4","5","6","7","8","9",">9"},
74  "Shows a per queue histogram of the number of message components required to transmit packets.");
75 
76  for(const auto & entry : fragmentHistogram_)
77  {
78  pQueueFragmentHistogram_->addRow(entry.first,
79  {Any{entry.first},
80  Any{std::get<0>(entry.second)},
81  Any{std::get<1>(entry.second)},
82  Any{std::get<2>(entry.second)},
83  Any{std::get<3>(entry.second)},
84  Any{std::get<4>(entry.second)},
85  Any{std::get<5>(entry.second)},
86  Any{std::get<6>(entry.second)},
87  Any{std::get<7>(entry.second)},
88  Any{std::get<8>(entry.second)},
89  Any{std::get<9>(entry.second)}});
90  }
91 
92 
93  pHighWaterMarkQueue_[0] =
94  statisticRegistrar.registerNumeric<std::uint64_t>("highWaterMarkQueue0",
96  "High water mark queue 0");
97 
98  pHighWaterMarkQueue_[1] =
99  statisticRegistrar.registerNumeric<std::uint64_t>("highWaterMarkQueue1",
101  "High water mark queue 1");
102 
103  pHighWaterMarkQueue_[2] =
104  statisticRegistrar.registerNumeric<std::uint64_t>("highWaterMarkQueue2",
106  "High water mark queue 2");
107 
108  pHighWaterMarkQueue_[3] =
109  statisticRegistrar.registerNumeric<std::uint64_t>("highWaterMarkQueue3",
111  "High water mark queue 3");
112 
113  pHighWaterMarkQueue_[4] =
114  statisticRegistrar.registerNumeric<std::uint64_t>("highWaterMarkQueue4",
116  "High water mark queue 4");
117 }
118 
120  DropReason reason,
121  size_t count)
122 {
123 
124  auto & overflow = std::get<2>(statusTableInfo_[u8Queue]);
125  auto & toobig = std::get<3>(statusTableInfo_[u8Queue]);
126 
127  switch(reason)
128  {
130  overflow += count;
131  pQueueStatusTable_->setCell(u8Queue,3,Any{overflow});
132  break;
133 
135  toobig += count;
136  pQueueStatusTable_->setCell(u8Queue,4,Any{toobig});
137  break;
138  }
139 
140  depthQueueInfo_[u8Queue] -= count;
141 }
142 
143 void EMANE::Models::TDMA::QueueStatusPublisher::dequeue(std::uint8_t u8RequestQueue,
144  std::uint8_t u8ActualQueue,
145  const MessageComponents & components)
146 {
147  auto & dequeued = std::get<1>(statusTableInfo_[u8ActualQueue]);
148  auto & queue0 = std::get<4>(statusTableInfo_[u8ActualQueue]);
149  auto & queue1 = std::get<5>(statusTableInfo_[u8ActualQueue]);
150  auto & queue2 = std::get<6>(statusTableInfo_[u8ActualQueue]);
151  auto & queue3 = std::get<7>(statusTableInfo_[u8ActualQueue]);
152  auto & queue4 = std::get<8>(statusTableInfo_[u8ActualQueue]);
153 
154  size_t packetsCompletedSend{};
155 
156  for(const auto & component : components)
157  {
158  if(!component.isMoreFragments())
159  {
160  ++packetsCompletedSend;
161 
162  size_t index{};
163  size_t parts{component.getFragmentIndex() + 1};
164 
165  if(parts <= 9)
166  {
167  index = parts;
168  }
169  else
170  {
171  index = 10;
172  }
173 
174  ++fragmentHistogram_[u8ActualQueue][index-1];
175 
176  pQueueFragmentHistogram_->setCell(u8ActualQueue,
177  index,
178  Any{fragmentHistogram_[u8ActualQueue][index-1]});
179 
180  }
181  }
182 
183  dequeued += packetsCompletedSend;
184 
185  pQueueStatusTable_->setCell(u8ActualQueue,2,Any{dequeued});
186 
187  switch(u8RequestQueue)
188  {
189  case 0:
190  queue0 += components.size();
191  pQueueStatusTable_->setCell(u8ActualQueue,5,Any{queue0});
192  break;
193  case 1:
194  queue1 += components.size();
195  pQueueStatusTable_->setCell(u8ActualQueue,6,Any{queue1});
196  break;
197  case 2:
198  queue2 += components.size();
199  pQueueStatusTable_->setCell(u8ActualQueue,7,Any{queue2});
200  break;
201  case 3:
202  queue3 += components.size();
203  pQueueStatusTable_->setCell(u8ActualQueue,8,Any{queue3});
204  break;
205  case 4:
206  queue4 += components.size();
207  pQueueStatusTable_->setCell(u8ActualQueue,9,Any{queue4});
208  break;
209  }
210 
211  depthQueueInfo_[u8ActualQueue] -= packetsCompletedSend;
212 }
213 
215 {
216  auto & enqueued = std::get<0>(statusTableInfo_[u8Queue]);
217  pQueueStatusTable_->setCell(u8Queue,1,Any{++enqueued});
218 
219  ++depthQueueInfo_[u8Queue];
220 
221  if(depthQueueInfo_[u8Queue] > highWaterMarkQueueInfo_[u8Queue])
222  {
223  highWaterMarkQueueInfo_[u8Queue] = depthQueueInfo_[u8Queue];
224 
225  *pHighWaterMarkQueue_[u8Queue] = highWaterMarkQueueInfo_[u8Queue];
226  }
227 }
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 drop(std::uint8_t u8Queue, DropReason reason, size_t count)
std::list< MessageComponent > MessageComponents
StatisticTable< Key, Compare, scolumn > * registerTable(const std::string &sName, const StatisticTableLabels &labels, const StatisticProperties &properties=StatisticProperties::NONE, const std::string &sDescription="")
void dequeue(std::uint8_t u8RequestQueue, std::uint8_t u8ActualQueue, const MessageComponents &components)
void addRow(const Key &key, const std::vector< Any > &anys={})
void registerStatistics(StatisticRegistrar &registrar)
The Any class can contain an instance of one of any type in its support type set. ...
Definition: any.h:49