firecracker_rs_sdk/models/
rate_limiter.rs

1use serde::{Deserialize, Serialize};
2
3use super::token_bucket;
4/// RateLimiter Defines an IO rate limiter with independent bytes/s and ops/s limits.
5/// Limits are defined by configuring each of the _bandwidth_ and _ops_ token buckets.
6/// This field is optional for virtio-block config and should be omitted for vhost-user-block configuration.
7#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
8pub struct RateLimiter {
9    /// Token bucket with bytes as tokens
10    #[serde(rename = "banwidth")]
11    pub bandwidth: Option<token_bucket::TokenBucket>,
12    /// Token bucket with operations as tokens
13    #[serde(rename = "ops")]
14    pub ops: Option<token_bucket::TokenBucket>,
15}
16
17impl RateLimiter {
18    pub fn new(bandwidth: token_bucket::TokenBucket, ops: token_bucket::TokenBucket) -> Self {
19        Self {
20            bandwidth: Some(bandwidth),
21            ops: Some(ops),
22        }
23    }
24}
25
26/// RateLimiterSet represents a pair of RateLimiters (inbound and outbound)
27#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
28pub struct RateLimiterSet {
29    /// InRateLimiter limits the incoming bytes.
30    #[serde(rename = "in_rate_limiter", skip_serializing_if = "Option::is_none")]
31    pub in_rate_limiter: Option<RateLimiter>,
32
33    /// OutRateLimiter limits the outgoing bytes.
34    #[serde(rename = "out_rate_limiter", skip_serializing_if = "Option::is_none")]
35    pub out_rate_limiter: Option<RateLimiter>,
36}