blob: 9e7bd162868be44803ba9fabfdfe396bd5667d1b [file] [log] [blame]
Gamze Abaka52e35922021-03-12 10:48:34 +00001/*
2 * Copyright 2019-present Open Networking Foundation
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 */
16package meters
17
18import (
19 "context"
20 "github.com/opencord/voltha-protos/v4/go/openflow_13"
21 "github.com/stretchr/testify/assert"
22 "testing"
23)
24
25func 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
58func 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
77func 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
91func 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
116func 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}