1 /** @file
2  *
3  *  A brief file description
4  *
5  *  @section license License
6  *
7  *  Licensed to the Apache Software Foundation (ASF) under one
8  *  or more contributor license agreements.  See the NOTICE file
9  *  distributed with this work for additional information
10  *  regarding copyright ownership.  The ASF licenses this file
11  *  to you under the Apache License, Version 2.0 (the
12  *  "License"); you may not use this file except in compliance
13  *  with the License.  You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  *  Unless required by applicable law or agreed to in writing, software
18  *  distributed under the License is distributed on an "AS IS" BASIS,
19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  *  See the License for the specific language governing permissions and
21  *  limitations under the License.
22  */
23 
24 #pragma once
25 
26 #include "QUICTypes.h"
27 #include "QUICContext.h"
28 #include "QUICCongestionController.h"
29 
30 class QUICNewRenoCongestionController : public QUICCongestionController
31 {
32 public:
33   QUICNewRenoCongestionController(QUICContext &context);
~QUICNewRenoCongestionController()34   virtual ~QUICNewRenoCongestionController() {}
35 
36   void on_packet_sent(size_t bytes_sent) override;
37   void on_packets_acked(const std::vector<QUICSentPacketInfoUPtr> &packets) override;
38   virtual void on_packets_lost(const std::map<QUICPacketNumber, QUICSentPacketInfoUPtr> &packets) override;
39   void on_packet_number_space_discarded(size_t bytes_in_flight) override;
40   void process_ecn(const QUICAckFrame &ack, QUICPacketNumberSpace pn_space, ink_hrtime largest_acked_packet_time_sent) override;
41   uint32_t credit() const override;
42   void reset() override;
43 
44   // Debug
45   uint32_t bytes_in_flight() const override;
46   uint32_t congestion_window() const override;
47   uint32_t current_ssthresh() const override;
48 
49   void add_extra_credit() override;
50 
51 private:
52   Ptr<ProxyMutex> _cc_mutex;
53   uint32_t _extra_packets_count = 0;
54   QUICContext &_context;
55   bool _check_credit() const;
56 
57   // Appendix B.  Congestion Control Pseudocode
58   bool _in_congestion_recovery(ink_hrtime sent_time) const;
59   void _congestion_event(ink_hrtime sent_time);
60   bool _in_persistent_congestion(const std::map<QUICPacketNumber, QUICSentPacketInfoUPtr> &lost_packets,
61                                  const QUICSentPacketInfoUPtr &largest_lost_packet);
62   bool _is_app_or_flow_control_limited();
63   void _maybe_send_one_packet();
64   bool _are_all_packets_lost(const std::map<QUICPacketNumber, QUICSentPacketInfoUPtr> &lost_packets,
65                              const QUICSentPacketInfoUPtr &largest_lost_packet, ink_hrtime period) const;
66 
67   // Recovery B.1. Constants of interest
68   // Values will be loaded from records.config via QUICConfig at constructor
69   uint32_t _k_initial_window                  = 0;
70   uint32_t _k_minimum_window                  = 0;
71   float _k_loss_reduction_factor              = 0.0;
72   uint32_t _k_persistent_congestion_threshold = 0;
73 
74   // B.2. Variables of interest
75   uint32_t _max_datagram_size                     = 0;
76   uint32_t _ecn_ce_counters[QUIC_N_PACKET_SPACES] = {0};
77   uint32_t _bytes_in_flight                       = 0;
78   uint32_t _congestion_window                     = 0;
79   ink_hrtime _congestion_recovery_start_time      = 0;
80   uint32_t _ssthresh                              = UINT32_MAX;
81 };
82