network_queue.h (2213B)
1 /* 2 * Copyright 2025 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef API_TEST_NETWORK_EMULATION_NETWORK_QUEUE_H_ 12 #define API_TEST_NETWORK_EMULATION_NETWORK_QUEUE_H_ 13 14 #include <cstddef> 15 #include <memory> 16 #include <optional> 17 #include <vector> 18 19 #include "api/test/simulated_network.h" 20 #include "api/units/timestamp.h" 21 22 namespace webrtc { 23 24 // NetworkQueue defines the interface for a queue used in network simulation. 25 // The purpose is to allow for different AQM implementations. 26 // A queue should not modify PacketInFlightInfo except for the explicit 27 // congestion notification field (ecn). 28 class NetworkQueue { 29 public: 30 // Max capacity a queue is expected to handle. 31 constexpr static size_t kMaxPacketCapacity = 10000; 32 33 virtual ~NetworkQueue() = default; 34 // Sets the max capacity of the queue. If there are already more than 35 // `max_capacitiy` packets in the queue, the behaviour depends on the 36 // implementation. 37 virtual void SetMaxPacketCapacity(size_t max_capactiy) = 0; 38 // Enqueues a packet. 39 // Must return true if the packet is enqueued successfully, false otherwise. 40 virtual bool EnqueuePacket(const PacketInFlightInfo& packet_info) = 0; 41 // Next packet that can be dequeued. 42 virtual std::optional<PacketInFlightInfo> PeekNextPacket() const = 0; 43 // Dequeues a packet. 44 // or std::nullopt if there are no enqueued packets. 45 virtual std::optional<PacketInFlightInfo> DequeuePacket( 46 Timestamp time_now) = 0; 47 48 // Dequeues all packets that are dropped by the queue itself after being 49 // enqueued. 50 virtual std::vector<PacketInFlightInfo> DequeueDroppedPackets() = 0; 51 virtual bool empty() const = 0; 52 }; 53 54 class NetworkQueueFactory { 55 public: 56 virtual ~NetworkQueueFactory() = default; 57 virtual std::unique_ptr<NetworkQueue> CreateQueue() = 0; 58 }; 59 60 } // namespace webrtc 61 #endif // API_TEST_NETWORK_EMULATION_NETWORK_QUEUE_H_