Gamze Abaka | 52e3592 | 2021-03-12 10:48:34 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 2 | * Copyright 2019-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Gamze Abaka | 52e3592 | 2021-03-12 10:48:34 +0000 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package meters |
| 17 | |
| 18 | import ( |
| 19 | "context" |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 20 | "github.com/opencord/voltha-protos/v5/go/openflow_13" |
Gamze Abaka | 52e3592 | 2021-03-12 10:48:34 +0000 | [diff] [blame] | 21 | "github.com/stretchr/testify/assert" |
| 22 | "testing" |
| 23 | ) |
| 24 | |
| 25 | func TestMeters_TestTcontType1(t *testing.T) { |
| 26 | //tcont-type-1 |
| 27 | meterConfig := &openflow_13.OfpMeterConfig{ |
| 28 | MeterId: 1, |
| 29 | Bands: []*openflow_13.OfpMeterBandHeader{ |
| 30 | { |
| 31 | Rate: 10000, |
| 32 | BurstSize: 0, |
| 33 | }, |
| 34 | }, |
| 35 | } |
| 36 | shapingInfo, _ := GetTrafficShapingInfo(context.Background(), meterConfig) |
| 37 | assert.Equal(t, uint32(10000), shapingInfo.Gir) |
| 38 | |
| 39 | //tcont-type-1 |
| 40 | meterConfig = &openflow_13.OfpMeterConfig{ |
| 41 | MeterId: 1, |
| 42 | Bands: []*openflow_13.OfpMeterBandHeader{ |
| 43 | { |
| 44 | Rate: 10000, |
| 45 | BurstSize: 0, |
| 46 | }, |
| 47 | { |
| 48 | Rate: 10000, |
| 49 | BurstSize: 0, |
| 50 | }, |
| 51 | }, |
| 52 | } |
| 53 | shapingInfo, _ = GetTrafficShapingInfo(context.Background(), meterConfig) |
| 54 | assert.Equal(t, uint32(10000), shapingInfo.Pir) |
| 55 | assert.Equal(t, uint32(10000), shapingInfo.Gir) |
| 56 | } |
| 57 | |
| 58 | func TestMeters_TestTcontType2and3(t *testing.T) { |
| 59 | meterConfig := &openflow_13.OfpMeterConfig{ |
| 60 | MeterId: 1, |
| 61 | Bands: []*openflow_13.OfpMeterBandHeader{ |
| 62 | { |
| 63 | Rate: 10000, |
| 64 | BurstSize: 2000, |
| 65 | }, |
| 66 | { |
| 67 | Rate: 30000, |
| 68 | BurstSize: 3000, |
| 69 | }, |
| 70 | }, |
| 71 | } |
| 72 | shapingInfo, _ := GetTrafficShapingInfo(context.Background(), meterConfig) |
| 73 | assert.Equal(t, uint32(30000), shapingInfo.Pir) |
| 74 | assert.Equal(t, uint32(10000), shapingInfo.Cir) |
| 75 | } |
| 76 | |
| 77 | func TestMeters_TestTcontType4(t *testing.T) { |
| 78 | meterConfig := &openflow_13.OfpMeterConfig{ |
| 79 | MeterId: 1, |
| 80 | Bands: []*openflow_13.OfpMeterBandHeader{ |
| 81 | { |
| 82 | Rate: 10000, |
| 83 | BurstSize: 1000, |
| 84 | }, |
| 85 | }, |
| 86 | } |
| 87 | shapingInfo, _ := GetTrafficShapingInfo(context.Background(), meterConfig) |
| 88 | assert.Equal(t, uint32(10000), shapingInfo.Pir) |
| 89 | } |
| 90 | |
| 91 | func TestMeters_TestTcontType5(t *testing.T) { |
| 92 | meterConfig := &openflow_13.OfpMeterConfig{ |
| 93 | MeterId: 1, |
| 94 | Bands: []*openflow_13.OfpMeterBandHeader{ |
| 95 | { |
| 96 | Rate: 10000, |
| 97 | BurstSize: 0, |
| 98 | }, |
| 99 | { |
| 100 | Rate: 20000, |
| 101 | BurstSize: 4000, |
| 102 | }, |
| 103 | { |
| 104 | Rate: 30000, |
| 105 | BurstSize: 5000, |
| 106 | }, |
| 107 | }, |
| 108 | } |
| 109 | shapingInfo, _ := GetTrafficShapingInfo(context.Background(), meterConfig) |
| 110 | assert.Equal(t, uint32(30000), shapingInfo.Pir) |
| 111 | assert.Equal(t, uint32(10000), shapingInfo.Gir) |
| 112 | assert.Equal(t, uint32(20000), shapingInfo.Cir) |
| 113 | assert.Equal(t, uint32(5000), shapingInfo.Pbs) |
| 114 | } |
| 115 | |
| 116 | func TestMeters_TestInvalidValues(t *testing.T) { |
| 117 | // cir not found |
| 118 | meterConfig := &openflow_13.OfpMeterConfig{ |
| 119 | MeterId: 1, |
| 120 | Bands: []*openflow_13.OfpMeterBandHeader{ |
| 121 | { |
| 122 | Rate: 10000, |
| 123 | BurstSize: 0, |
| 124 | }, |
| 125 | { |
| 126 | Rate: 20000, |
| 127 | BurstSize: 4000, |
| 128 | }, |
| 129 | }, |
| 130 | } |
| 131 | shapingInfo, _ := GetTrafficShapingInfo(context.Background(), meterConfig) |
| 132 | assert.Nil(t, shapingInfo) |
| 133 | |
| 134 | // gir not found |
| 135 | meterConfig = &openflow_13.OfpMeterConfig{ |
| 136 | MeterId: 1, |
| 137 | Bands: []*openflow_13.OfpMeterBandHeader{ |
| 138 | { |
| 139 | Rate: 10000, |
| 140 | BurstSize: 3000, |
| 141 | }, |
| 142 | { |
| 143 | Rate: 20000, |
| 144 | BurstSize: 4000, |
| 145 | }, |
| 146 | { |
| 147 | Rate: 30000, |
| 148 | BurstSize: 5000, |
| 149 | }, |
| 150 | }, |
| 151 | } |
| 152 | shapingInfo, _ = GetTrafficShapingInfo(context.Background(), meterConfig) |
| 153 | assert.Nil(t, shapingInfo) |
| 154 | |
| 155 | //gir not found |
| 156 | meterConfig = &openflow_13.OfpMeterConfig{ |
| 157 | MeterId: 1, |
| 158 | Bands: []*openflow_13.OfpMeterBandHeader{ |
| 159 | { |
| 160 | Rate: 10000, |
| 161 | BurstSize: 0, |
| 162 | }, |
| 163 | { |
| 164 | Rate: 20000, |
| 165 | BurstSize: 0, |
| 166 | }, |
| 167 | { |
| 168 | Rate: 30000, |
| 169 | BurstSize: 5000, |
| 170 | }, |
| 171 | }, |
| 172 | } |
| 173 | shapingInfo, _ = GetTrafficShapingInfo(context.Background(), meterConfig) |
| 174 | assert.Nil(t, shapingInfo) |
| 175 | } |