17 #include <hicn/transport/config.h>
18 #include <hicn/transport/core/asio_wrapper.h>
19 #include <hicn/transport/core/content_object.h>
20 #include <hicn/transport/core/name.h>
21 #include <protocols/indexer.h>
22 #include <protocols/rtc/probe_handler.h>
23 #include <protocols/rtc/rtc_data_path.h>
34 enum class PacketState : uint8_t { RECEIVED, LOST, UNKNOWN };
36 class RTCState : std::enable_shared_from_this<RTCState> {
38 using DiscoveredRttCallback = std::function<void()>;
42 ProbeHandler::SendProbeCallback &&rtt_probes_callback,
43 DiscoveredRttCallback &&discovered_rtt_callback,
44 asio::io_service &io_service);
49 void onSendNewInterest(
const core::Name *interest_name);
50 void onTimeout(uint32_t seq,
bool lost);
51 void onLossDetected(uint32_t seq);
52 void onRetransmission(uint32_t seq);
58 void onPacketLost(uint32_t seq);
59 void onPacketRecoveredRtx(uint32_t seq);
60 void onPacketRecoveredFec(uint32_t seq);
64 void onNewRound(
double round_len,
bool in_sync);
67 uint32_t getProducerPath()
const {
68 if (mainPathIsValid())
return main_path_->getPathId();
73 bool isRttDiscovered()
const {
return init_rtt_; }
75 uint64_t getRTT()
const {
76 if (mainPathIsValid())
return main_path_->getMinRtt();
79 void resetRttStats() {
80 if (mainPathIsValid()) main_path_->clearRtt();
83 double getQueuing()
const {
84 if (mainPathIsValid())
return main_path_->getQueuingDealy();
87 double getIAT()
const {
88 if (mainPathIsValid())
return main_path_->getInterArrivalGap();
92 double getJitter()
const {
93 if (mainPathIsValid())
return main_path_->getJitter();
98 uint64_t getInterestSentTime(uint32_t seq) {
99 auto it = pending_interests_.find(seq);
100 if (it != pending_interests_.end())
return it->second;
104 bool isPending(uint32_t seq) {
105 if (pending_interests_.find(seq) != pending_interests_.end())
return true;
109 uint32_t getPendingInterestNumber()
const {
110 return pending_interests_.size();
113 PacketState isReceivedOrLost(uint32_t seq) {
114 auto it = received_or_lost_packets_.find(seq);
115 if (it != received_or_lost_packets_.end())
return it->second;
116 return PacketState::UNKNOWN;
120 double getLossRate()
const {
return loss_rate_; }
121 double getAvgLossRate()
const {
return avg_loss_rate_; }
122 double getMaxLossRate()
const {
return max_loss_rate_; }
123 double getLastRoundLossRate()
const {
return last_round_loss_rate_; }
124 double getResidualLossRate()
const {
return residual_loss_rate_; }
126 uint32_t getLostData()
const {
return packets_lost_; };
127 uint32_t getRecoveredLosses()
const {
return losses_recovered_; }
129 uint32_t getDefinitelyLostPackets()
const {
return definitely_lost_pkt_; }
131 uint32_t getHighestSeqReceived()
const {
return highest_seq_received_; }
133 uint32_t getHighestSeqReceivedInOrder()
const {
134 return highest_seq_received_in_order_;
138 uint32_t getReceivedFecPackets()
const {
return received_fec_pkt_; }
139 uint32_t getPendingFecPackets()
const {
return pending_fec_pkt_; }
142 uint32_t getReceivedBytesInRound()
const {
return received_bytes_; }
143 uint32_t getReceivedNacksInRound()
const {
144 return received_nacks_last_round_;
146 uint32_t getSentInterestInRound()
const {
return sent_interests_last_round_; }
147 uint32_t getSentRtxInRound()
const {
return sent_rtx_last_round_; }
150 double getAvailableBw()
const {
return 0.0; };
151 double getProducerRate()
const {
return production_rate_; }
152 double getReceivedRate()
const {
return received_rate_; }
153 double getAveragePacketSize()
const {
return avg_packet_size_; }
156 uint32_t getRoundsWithoutNacks()
const {
return rounds_without_nacks_; }
157 uint32_t getLastSeqNacked()
const {
return last_seq_nacked_; }
160 bool isProducerActive()
const {
return producer_is_active_; }
163 double getPacketFromCacheRatio()
const {
return data_from_cache_rate_; }
165 std::map<uint32_t, uint64_t>::iterator getPendingInterestsMapBegin() {
166 return pending_interests_.begin();
168 std::map<uint32_t, uint64_t>::iterator getPendingInterestsMapEnd() {
169 return pending_interests_.end();
180 void updateLossRate();
182 void addRecvOrLost(uint32_t seq, PacketState state);
184 void setInitRttTimer(uint32_t wait);
185 void checkInitRttTimer();
187 bool mainPathIsValid()
const {
188 if (main_path_ !=
nullptr)
195 uint32_t sent_interests_;
197 uint32_t received_data_;
198 uint32_t received_nacks_;
199 uint32_t received_timeouts_;
200 uint32_t received_probes_;
203 int32_t packets_lost_;
204 int32_t losses_recovered_;
205 uint32_t definitely_lost_pkt_;
206 uint32_t first_seq_in_round_;
207 uint32_t highest_seq_received_;
208 uint32_t highest_seq_received_in_order_;
209 uint32_t last_seq_nacked_;
211 double avg_loss_rate_;
212 double max_loss_rate_;
213 double last_round_loss_rate_;
214 double residual_loss_rate_;
217 uint32_t received_bytes_;
218 double avg_packet_size_;
219 double production_rate_;
220 double received_rate_;
226 bool nack_on_last_round_;
227 uint32_t received_nacks_last_round_;
230 uint32_t received_packets_last_round_;
231 uint32_t received_data_last_round_;
232 uint32_t received_data_from_cache_;
233 double data_from_cache_rate_;
234 uint32_t sent_interests_last_round_;
235 uint32_t sent_rtx_last_round_;
238 uint32_t received_fec_pkt_;
239 uint32_t pending_fec_pkt_;
243 uint32_t rounds_without_nacks_;
244 uint32_t rounds_without_packets_;
247 uint64_t first_interest_sent_time_;
248 uint32_t first_interest_sent_seq_;
254 last_production_seq_;
255 uint64_t last_prod_update_;
259 std::unordered_map<uint32_t, std::shared_ptr<RTCDataPath>> path_table_;
260 std::shared_ptr<RTCDataPath> main_path_;
264 std::map<uint32_t, PacketState> received_or_lost_packets_;
267 std::map<uint32_t, uint64_t> pending_interests_;
273 uint32_t last_interest_sent_;
274 std::unordered_set<uint32_t> skipped_interests_;
277 std::shared_ptr<ProbeHandler> rtt_probes_;
279 std::unique_ptr<asio::steady_timer> init_rtt_timer_;
282 DiscoveredRttCallback discovered_rtt_callback_;