Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
statistics.h
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <hicn/transport/portability/c_portability.h>
19 
20 #include <cstdint>
21 
22 namespace transport {
23 
24 namespace interface {
25 
26 class IcnObserver {
27  public:
28  virtual ~IcnObserver(){};
29 
30  virtual void notifyStats(double throughput) = 0;
31  virtual void notifyDownloadTime(double downloadTime) = 0;
32 };
33 
35 
37  static constexpr double default_alpha = 0.7;
38 
39  public:
40  TransportStatistics(double alpha = default_alpha)
41  : retx_count_(0),
42  bytes_received_(0),
43  average_rtt_(0),
44  avg_window_size_(0),
45  interest_tx_(0),
46  alpha_(alpha),
47  loss_ratio_(0.0),
48  queuing_delay_(0.0),
49  interest_FEC_tx_(0),
50  bytes_FEC_received_(0),
51  lost_data_(0),
52  definitely_lost_data_(0),
53  recovered_data_(0),
54  status_(-1),
55  // avg_data_rtt_(0),
56  avg_pending_pkt_(0.0),
57  received_nacks_(0),
58  received_fec_(0) {}
59 
60  TRANSPORT_ALWAYS_INLINE void updateRetxCount(uint64_t retx) {
61  retx_count_ += retx;
62  }
63 
64  TRANSPORT_ALWAYS_INLINE void updateBytesRecv(uint64_t bytes) {
65  bytes_received_ += bytes;
66  }
67 
68  TRANSPORT_ALWAYS_INLINE void updateAverageRtt(uint64_t rtt) {
69  average_rtt_ = (alpha_ * average_rtt_) + ((1. - alpha_) * double(rtt));
70  }
71 
72  TRANSPORT_ALWAYS_INLINE void updateAverageWindowSize(double current_window) {
73  avg_window_size_ =
74  (alpha_ * avg_window_size_) + ((1. - alpha_) * current_window);
75  }
76 
77  TRANSPORT_ALWAYS_INLINE void updateInterestTx(uint64_t int_tx) {
78  interest_tx_ += int_tx;
79  }
80 
81  TRANSPORT_ALWAYS_INLINE void updateLossRatio(double loss_ratio) {
82  loss_ratio_ = loss_ratio;
83  }
84 
85  TRANSPORT_ALWAYS_INLINE void updateQueuingDelay(double queuing_delay) {
86  queuing_delay_ = queuing_delay;
87  }
88 
89  TRANSPORT_ALWAYS_INLINE void updateInterestFecTx(uint64_t int_tx) {
90  interest_FEC_tx_ += int_tx;
91  }
92 
93  TRANSPORT_ALWAYS_INLINE void updateBytesFecRecv(uint64_t bytes) {
94  bytes_FEC_received_ += bytes;
95  }
96 
97  TRANSPORT_ALWAYS_INLINE void updateLostData(uint64_t pkt) {
98  lost_data_ += pkt;
99  }
100 
101  TRANSPORT_ALWAYS_INLINE void updateDefinitelyLostData(uint64_t pkt) {
102  definitely_lost_data_ += pkt;
103  }
104 
105  TRANSPORT_ALWAYS_INLINE void updateRecoveredData(uint64_t bytes) {
106  recovered_data_ += bytes;
107  }
108 
109  TRANSPORT_ALWAYS_INLINE void updateCCState(int status) { status_ = status; }
110 
111  TRANSPORT_ALWAYS_INLINE void updateAveragePendingPktCount(double pkt) {
112  avg_pending_pkt_ = (alpha_ * avg_pending_pkt_) + ((1. - alpha_) * pkt);
113  }
114 
115  TRANSPORT_ALWAYS_INLINE void updateReceivedNacks(uint32_t nacks) {
116  received_nacks_ += nacks;
117  }
118 
119  TRANSPORT_ALWAYS_INLINE void updateReceivedFEC(uint32_t pkt) {
120  received_fec_ += pkt;
121  }
122 
123  TRANSPORT_ALWAYS_INLINE uint64_t getRetxCount() const { return retx_count_; }
124 
125  TRANSPORT_ALWAYS_INLINE uint64_t getBytesRecv() const {
126  return bytes_received_;
127  }
128 
129  TRANSPORT_ALWAYS_INLINE double getAverageRtt() const { return average_rtt_; }
130 
131  TRANSPORT_ALWAYS_INLINE double getAverageWindowSize() const {
132  return avg_window_size_;
133  }
134 
135  TRANSPORT_ALWAYS_INLINE uint64_t getInterestTx() const {
136  return interest_tx_;
137  }
138 
139  TRANSPORT_ALWAYS_INLINE double getLossRatio() const { return loss_ratio_; }
140 
141  TRANSPORT_ALWAYS_INLINE double getQueuingDelay() const {
142  return queuing_delay_;
143  }
144 
145  TRANSPORT_ALWAYS_INLINE uint64_t getInterestFecTxCount() const {
146  return interest_FEC_tx_;
147  }
148 
149  TRANSPORT_ALWAYS_INLINE uint64_t getBytesFecRecv() const {
150  return bytes_FEC_received_;
151  }
152 
153  TRANSPORT_ALWAYS_INLINE uint64_t getLostData() const { return lost_data_; }
154 
155  TRANSPORT_ALWAYS_INLINE uint64_t getDefinitelyLostData() const {
156  return definitely_lost_data_;
157  }
158 
159  TRANSPORT_ALWAYS_INLINE uint64_t getBytesRecoveredData() const {
160  return recovered_data_;
161  }
162 
163  TRANSPORT_ALWAYS_INLINE int getCCStatus() const { return status_; }
164 
165  TRANSPORT_ALWAYS_INLINE double getAveragePendingPktCount() const {
166  return avg_pending_pkt_;
167  }
168 
169  TRANSPORT_ALWAYS_INLINE uint32_t getReceivedNacks() const {
170  return received_nacks_;
171  }
172 
173  TRANSPORT_ALWAYS_INLINE uint32_t getReceivedFEC() const {
174  return received_fec_;
175  }
176 
177  TRANSPORT_ALWAYS_INLINE void setAlpha(double val) { alpha_ = val; }
178 
179  TRANSPORT_ALWAYS_INLINE void reset() {
180  retx_count_ = 0;
181  bytes_received_ = 0;
182  average_rtt_ = 0;
183  avg_window_size_ = 0;
184  interest_tx_ = 0;
185  loss_ratio_ = 0;
186  interest_FEC_tx_ = 0;
187  bytes_FEC_received_ = 0;
188  lost_data_ = 0;
189  definitely_lost_data_ = 0;
190  recovered_data_ = 0;
191  status_ = 0;
192  // avg_data_rtt_ = 0;
193  avg_pending_pkt_ = 0;
194  received_nacks_ = 0;
195  received_fec_ = 0;
196  }
197 
198  private:
199  uint64_t retx_count_;
200  uint64_t bytes_received_;
201  double average_rtt_;
202  double avg_window_size_;
203  uint64_t interest_tx_;
204  double alpha_;
205  double loss_ratio_;
206  double queuing_delay_;
207  uint64_t interest_FEC_tx_;
208  uint64_t bytes_FEC_received_;
209  uint64_t lost_data_;
210  uint64_t definitely_lost_data_;
211  uint64_t recovered_data_;
212  int status_; // transport status (e.g. sync status, congestion etc.)
213  double avg_pending_pkt_;
214  uint32_t received_nacks_;
215  uint32_t received_fec_;
216 };
217 
218 } // namespace interface
219 
220 } // end namespace transport
transport::interface::TransportStatistics
Definition: statistics.h:36
transport
Definition: forwarder_config.h:32
transport::interface::IcnObserver
Definition: statistics.h:26
transport::interface::ProductionStatistics
Definition: statistics.h:34