Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
rtc.h
1 /*
2  * Copyright (c) 2017-2021 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 <protocols/datagram_reassembly.h>
19 #include <protocols/rtc/rtc_ldr.h>
20 #include <protocols/rtc/rtc_rc.h>
21 #include <protocols/rtc/rtc_state.h>
22 #include <protocols/transport_protocol.h>
23 
24 #include <unordered_set>
25 #include <vector>
26 
27 namespace transport {
28 
29 namespace protocol {
30 
31 namespace rtc {
32 
34  public:
36 
38 
39  using TransportProtocol::start;
40 
41  using TransportProtocol::stop;
42 
43  void resume() override;
44 
45  std::size_t transportHeaderLength() override;
46 
47  private:
48  enum class SyncState { catch_up = 0, in_sync = 1, last };
49 
50  private:
51  // setup functions
52  void initParams();
53  void reset() override;
54 
55  void inactiveProducer();
56 
57  // protocol functions
58  void discoveredRtt();
59  void newRound();
60 
61  // window functions
62  void computeMaxSyncWindow();
63  void updateSyncWindow();
64  void decreaseSyncWindow();
65 
66  // packet functions
67  void sendRtxInterest(uint32_t seq);
68  void sendProbeInterest(uint32_t seq);
69  void scheduleNextInterests() override;
70  void onInterestTimeout(Interest::Ptr &interest, const Name &name) override;
71  void onNack(const ContentObject &content_object);
72  void onProbe(const ContentObject &content_object);
73  void onContentObjectReceived(Interest &interest,
74  ContentObject &content_object,
75  std::error_code &ec) override;
76  void onPacketDropped(Interest &interest, ContentObject &content_object,
77  const std::error_code &reason) override {}
78  void onReassemblyFailed(std::uint32_t missing_segment) override {}
79 
80  // interaction with app functions
81  void sendStatsToApp(uint32_t retx_count, uint32_t received_bytes,
82  uint32_t sent_interests, uint32_t lost_data,
83  uint32_t definitely_lost, uint32_t recovered_losses,
84  uint32_t received_nacks, uint32_t received_fec);
85 
86  // FEC functions
87  void onFecPackets(std::vector<std::pair<uint32_t, fec::buffer>> &packets);
88 
89  // protocol state
90  bool start_send_interest_;
91  SyncState current_state_;
92  // cwin vars
93  uint32_t current_sync_win_;
94  uint32_t max_sync_win_;
95 
96  // round timer
97  std::unique_ptr<asio::steady_timer> round_timer_;
98 
99  // scheduler timer (postpone interest sending to explot aggregated interests)
100  std::unique_ptr<asio::steady_timer> scheduler_timer_;
101  bool scheduler_timer_on_;
102  uint64_t last_interest_sent_time_;
103  uint64_t last_interest_sent_seq_;
104 
105  // maximum aggregated interest. if the transport is connected to the forwarder
106  // we cannot use aggregated interests
107  uint32_t max_aggregated_interest_;
108  // maximum number of intereset that can be sent in a loop to avoid packets
109  // dropped by the kernel
110  uint32_t max_sent_int_;
111 
112  // pacing timer (do not send too many interests in a short time to avoid
113  // packet drops in the kernel)
114  std::unique_ptr<asio::steady_timer> pacing_timer_;
115  bool pacing_timer_on_;
116 
117  // timeouts
118  std::unordered_set<uint32_t> timeouts_or_nacks_;
119 
120  std::shared_ptr<RTCState> state_;
121  std::shared_ptr<RTCRateControl> rc_;
122  std::shared_ptr<RTCLossDetectionAndRecovery> ldr_;
123 
124  uint32_t number_;
125 };
126 
127 } // namespace rtc
128 
129 } // namespace protocol
130 
131 } // namespace transport
transport::interface::ConsumerSocket
Main interface for consumer applications.
Definition: socket_consumer.h:48
transport::core::Name
Definition: name.h:45
transport::core::ContentObject
Definition: content_object.h:29
transport::core::Interest
Definition: interest.h:30
transport
Definition: forwarder_config.h:32
transport::protocol::TransportProtocol
Definition: transport_protocol.h:41
transport::protocol::rtc::RTCTransportProtocol::transportHeaderLength
std::size_t transportHeaderLength() override
Get the size of any additional header added by the specific transport implementation.
transport::protocol::rtc::RTCTransportProtocol
Definition: rtc.h:33