1 // Copyright (C) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 use super::QosLevel; 15 16 /// Capacity of different `Rss` level, which contains `m1`, `m2`, `m3`. 17 /// `m1` represents the size of the full-speed zone. 18 /// `m2` represents the size of the low-speed zone. 19 /// `m3` represents the size of the fair-adjustment zone. 20 #[derive(PartialEq, Eq)] 21 pub(crate) struct RssCapacity(usize, usize, usize, QosLevel, QosLevel, QosLevel); 22 23 impl RssCapacity { 24 pub(crate) const LEVEL0: Self = 25 Self(8, 32, 8, QosLevel::High, QosLevel::Middle, QosLevel::Middle); 26 pub(crate) const LEVEL1: Self = 27 Self(8, 32, 8, QosLevel::High, QosLevel::Middle, QosLevel::Middle); 28 pub(crate) const LEVEL2: Self = 29 Self(8, 32, 8, QosLevel::High, QosLevel::Middle, QosLevel::Middle); 30 pub(crate) const LEVEL3: Self = 31 Self(8, 16, 4, QosLevel::High, QosLevel::Middle, QosLevel::Middle); 32 pub(crate) const LEVEL4: Self = 33 Self(4, 16, 4, QosLevel::High, QosLevel::Middle, QosLevel::Middle); 34 pub(crate) const LEVEL5: Self = 35 Self(4, 8, 4, QosLevel::High, QosLevel::Middle, QosLevel::Middle); 36 pub(crate) const LEVEL6: Self = Self(4, 8, 2, QosLevel::High, QosLevel::Low, QosLevel::Low); 37 pub(crate) const LEVEL7: Self = Self(4, 4, 2, QosLevel::High, QosLevel::Low, QosLevel::Low); 38 new(level: i32) -> Self39 pub(crate) fn new(level: i32) -> Self { 40 match level { 41 0 => Self::LEVEL0, 42 1 => Self::LEVEL1, 43 2 => Self::LEVEL2, 44 3 => Self::LEVEL3, 45 4 => Self::LEVEL4, 46 5 => Self::LEVEL5, 47 6 => Self::LEVEL6, 48 7 => Self::LEVEL7, 49 _ => unreachable!(), 50 } 51 } 52 m1(&self) -> usize53 pub(crate) fn m1(&self) -> usize { 54 self.0 55 } 56 m2(&self) -> usize57 pub(crate) fn m2(&self) -> usize { 58 self.1 59 } 60 m3(&self) -> usize61 pub(crate) fn m3(&self) -> usize { 62 self.2 63 } 64 m1_speed(&self) -> QosLevel65 pub(crate) fn m1_speed(&self) -> QosLevel { 66 self.3 67 } 68 m2_speed(&self) -> QosLevel69 pub(crate) fn m2_speed(&self) -> QosLevel { 70 self.4 71 } 72 m3_speed(&self) -> QosLevel73 pub(crate) fn m3_speed(&self) -> QosLevel { 74 self.5 75 } 76 } 77 78 #[cfg(test)] 79 mod test { 80 use super::*; 81 is_rss_equal(rss1: RssCapacity, rss2: RssCapacity) -> bool82 fn is_rss_equal(rss1: RssCapacity, rss2: RssCapacity) -> bool { 83 rss1.m1() == rss2.m1() 84 && rss1.m2() == rss2.m2() 85 && rss1.m3() == rss2.m3() 86 && rss1.m1_speed() == rss2.m1_speed() 87 && rss1.m2_speed() == rss2.m2_speed() 88 && rss1.m2_speed() == rss2.m2_speed() 89 } 90 91 #[test] ut_rss_capacity()92 fn ut_rss_capacity() { 93 assert_eq!(QosLevel::High as u64, 0u64); 94 assert_eq!(QosLevel::Middle as u64, 800u64); 95 assert_eq!(QosLevel::Low as u64, 400u64); 96 assert!(is_rss_equal( 97 RssCapacity::new(0), 98 RssCapacity(8, 32, 8, QosLevel::High, QosLevel::Middle, QosLevel::Middle,) 99 )); 100 assert!(is_rss_equal( 101 RssCapacity::new(1), 102 RssCapacity(8, 32, 8, QosLevel::High, QosLevel::Middle, QosLevel::Middle,) 103 )); 104 assert!(is_rss_equal( 105 RssCapacity::new(2), 106 RssCapacity(8, 32, 8, QosLevel::High, QosLevel::Middle, QosLevel::Middle,) 107 )); 108 assert!(is_rss_equal( 109 RssCapacity::new(3), 110 RssCapacity(8, 16, 4, QosLevel::High, QosLevel::Middle, QosLevel::Middle,) 111 )); 112 assert!(is_rss_equal( 113 RssCapacity::new(4), 114 RssCapacity(4, 16, 4, QosLevel::High, QosLevel::Middle, QosLevel::Middle,) 115 )); 116 assert!(is_rss_equal( 117 RssCapacity::new(5), 118 RssCapacity(4, 8, 4, QosLevel::High, QosLevel::Middle, QosLevel::Middle,) 119 )); 120 assert!(is_rss_equal( 121 RssCapacity::new(6), 122 RssCapacity(4, 8, 2, QosLevel::High, QosLevel::Low, QosLevel::Low,) 123 )); 124 assert!(is_rss_equal( 125 RssCapacity::new(7), 126 RssCapacity(4, 4, 2, QosLevel::High, QosLevel::Low, QosLevel::Low,) 127 )); 128 } 129 } 130