blob: 0155330218572aff69a14f72183cc8e1f1d72c5e [file] [log] [blame]
kdarapu891693b2019-09-16 12:33:49 +05301/*
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 */
16
Scott Bakerdbd960e2020-02-28 08:57:51 -080017//Package core provides the utility for olt devices, flows and statistics
18package core
kdarapu891693b2019-09-16 12:33:49 +053019
20import (
Neha Sharma96b7bf22020-06-15 10:37:32 +000021 "context"
Kishore Darapuaaf9c102020-05-04 13:06:57 +053022 "fmt"
Girish Kumar2ad402b2020-03-20 19:45:12 +000023 "reflect"
24 "testing"
Kent Hagermane6ff1012020-07-14 15:07:53 -040025
26 "github.com/opencord/voltha-protos/v3/go/openolt"
27 "github.com/opencord/voltha-protos/v3/go/voltha"
kdarapu891693b2019-09-16 12:33:49 +053028)
29
kdarapu891693b2019-09-16 12:33:49 +053030func TestOpenOltStatisticsMgr_PortStatisticsIndication(t *testing.T) {
31 device := &voltha.Device{
32 Id: "olt",
33 Root: true,
34 ParentId: "logical_device",
kdarapu891693b2019-09-16 12:33:49 +053035 ProxyAddress: &voltha.Device_ProxyAddress{
36 DeviceId: "olt",
37 DeviceType: "onu",
38 ChannelId: 1,
39 ChannelGroupId: 1,
40 },
41 ConnectStatus: 1,
42 }
Naga Manjunath7615e552019-10-11 22:35:47 +053043 dh := newMockDeviceHandler()
kdarapu891693b2019-09-16 12:33:49 +053044 dh.device = device
Neha Sharma96b7bf22020-06-15 10:37:32 +000045 StatMgr := NewOpenOltStatsMgr(context.Background(), dh)
kdarapu891693b2019-09-16 12:33:49 +053046
47 type args struct {
48 PortStats *openolt.PortStatistics
49 }
50 tests := []struct {
51 name string
52 args args
53 }{
54 // TODO: Add test cases.
55 {"PortStatisticsIndication", args{PortStats: &openolt.PortStatistics{}}},
56 }
57 for _, tt := range tests {
58 t.Run(tt.name, func(t *testing.T) {
59
Neha Sharma96b7bf22020-06-15 10:37:32 +000060 StatMgr.PortStatisticsIndication(context.Background(), tt.args.PortStats, 16)
Naga Manjunath7615e552019-10-11 22:35:47 +053061 })
62 }
63}
64
65func TestOpenOltStatisticsMgr_publishMetrics(t *testing.T) {
66 type fields struct {
67 Device *DeviceHandler
68 NorthBoundPort map[uint32]*NniPort
69 SouthBoundPort map[uint32]*PonPort
70 }
71 type args struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -040072 val map[string]float32
73 port *voltha.Port
Naga Manjunath7615e552019-10-11 22:35:47 +053074 }
Naga Manjunath7615e552019-10-11 22:35:47 +053075 ponmap := map[uint32]*PonPort{}
76 ponmap[0] = &PonPort{
77 PONID: 0,
78 DeviceID: "onu1",
79 IntfID: 0,
80 PortNum: 0,
81 PortID: 0,
82 Label: "",
83 ONUs: nil,
84 ONUsByID: nil,
85 RxBytes: 0,
86 RxPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000087 RxUcastPackets: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +053088 RxMcastPackets: 0,
89 RxBcastPackets: 0,
90 RxErrorPackets: 0,
91 TxBytes: 0,
92 TxPackets: 0,
93 TxUcastPackets: 0,
94 TxMcastPackets: 0,
95 TxBcastPackets: 0,
96 TxErrorPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000097 RxCrcErrors: 0,
98 BipErrors: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +053099 }
100 nnimap := map[uint32]*NniPort{}
101 nnimap[0] = &NniPort{
102 PortNum: 0,
103 Name: "olt1",
104 LogicalPort: 0,
105 IntfID: 0,
106 RxBytes: 0,
107 RxPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000108 RxUcastPackets: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530109 RxMcastPackets: uint64(1111),
110 RxBcastPackets: 0,
111 RxErrorPackets: 0,
112 TxBytes: 0,
113 TxPackets: 0,
114 TxUcastPackets: 0,
115 TxMcastPackets: 0,
116 TxBcastPackets: 0,
117 TxErrorPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000118 RxCrcErrors: 0,
119 BipErrors: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530120 }
121 pval := make(map[string]float32)
122 pval["rx_bytes"] = float32(111)
123 nval := make(map[string]float32)
124 nval["rx_bytes"] = float32(111)
125 dhandlerNNI := newMockDeviceHandler()
126 dhandlerNNI.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: nil, NorthBoundPort: nnimap}
127 dhandlerPON := newMockDeviceHandler()
128 dhandlerPON.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: ponmap, NorthBoundPort: nil}
129 tests := []struct {
130 name string
131 fields fields
132 args args
133 }{
134 {
135 name: "PublishNNIMetrics-1",
136 fields: fields{
137 Device: dhandlerNNI,
138 NorthBoundPort: nnimap,
139 SouthBoundPort: nil,
140 },
141 args: args{
Girish Gowdra34815db2020-05-11 17:18:04 -0700142 val: nval,
143 port: &voltha.Port{PortNo: 0, Label: fmt.Sprintf("%s%d", "nni-", 0), Type: voltha.Port_ETHERNET_NNI},
Naga Manjunath7615e552019-10-11 22:35:47 +0530144 },
145 },
146 {
147 name: "PublishPONMetrics-1",
148 fields: fields{
149 Device: dhandlerPON,
150 NorthBoundPort: nil,
151 SouthBoundPort: ponmap,
152 },
153 args: args{
Girish Gowdra34815db2020-05-11 17:18:04 -0700154 val: pval,
155 port: &voltha.Port{PortNo: 1, Label: fmt.Sprintf("%s%d", "pon-", 1), Type: voltha.Port_PON_OLT},
Naga Manjunath7615e552019-10-11 22:35:47 +0530156 },
157 },
158 // TODO: Add test cases.
159 }
160 for _, tt := range tests {
161 t.Run(tt.name, func(t *testing.T) {
162 StatMgr := &OpenOltStatisticsMgr{
163 Device: tt.fields.Device,
164 NorthBoundPort: tt.fields.NorthBoundPort,
165 SouthBoundPort: tt.fields.SouthBoundPort,
166 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000167 StatMgr.publishMetrics(context.Background(), tt.args.val, tt.args.port, "onu1", "openolt")
Naga Manjunath7615e552019-10-11 22:35:47 +0530168 })
169 }
170}
171
172func TestOpenOltStatisticsMgr_collectNNIMetrics(t *testing.T) {
173 type fields struct {
174 Device *DeviceHandler
175 NorthBoundPort map[uint32]*NniPort
176 SouthBoundPort map[uint32]*PonPort
177 }
178 type args struct {
179 nniID uint32
180 }
181 dhandler := newMockDeviceHandler()
182 pmconfig := make(map[string]*voltha.PmConfig)
183 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
184
185 var res map[string]float32
186 nnimap := map[uint32]*NniPort{}
187 nnimap[0] = &NniPort{Name: "olt"}
188 nnimap[1] = &NniPort{Name: "olt"}
189 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: nil, NorthBoundPort: nnimap}}
190 tests := []struct {
191 name string
192 fields fields
193 args args
194 want map[string]float32
195 }{
196 {"CollectNNIMetrics-1", fields{
197 Device: dh,
198 NorthBoundPort: nnimap,
199 SouthBoundPort: nil,
200 }, args{0}, res},
201 {"CollectNNIMetrics-2", fields{
202 Device: dh,
203 NorthBoundPort: nnimap,
204 SouthBoundPort: nil,
205 }, args{1}, res},
206 // TODO: Add test cases.
207 }
208 for _, tt := range tests {
209 t.Run(tt.name, func(t *testing.T) {
210 StatMgr := &OpenOltStatisticsMgr{
211 Device: tt.fields.Device,
212 NorthBoundPort: tt.fields.NorthBoundPort,
213 SouthBoundPort: tt.fields.SouthBoundPort,
214 }
215 got := StatMgr.collectNNIMetrics(tt.args.nniID)
216 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
217 t.Errorf("collectNNIMetrics() = %v, want %v", got, tt.want)
218 }
219 })
220 }
221}
222
223func TestOpenOltStatisticsMgr_collectPONMetrics(t *testing.T) {
224 type fields struct {
225 Device *DeviceHandler
226 NorthBoundPort map[uint32]*NniPort
227 SouthBoundPort map[uint32]*PonPort
228 }
229 type args struct {
230 pID uint32
231 }
232 dhandler := newMockDeviceHandler()
233 pmconfig := make(map[string]*voltha.PmConfig)
234 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
235
236 var res map[string]float32
237 ponmap := map[uint32]*PonPort{}
238 ponmap[0] = &PonPort{DeviceID: "olt"}
239 ponmap[1] = &PonPort{DeviceID: "olt"}
240 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: ponmap, NorthBoundPort: nil}}
241
242 tests := []struct {
243 name string
244 fields fields
245 args args
246 want map[string]float32
247 }{
248 {"CollectPONMetrics-1", fields{
249 Device: dh,
250 NorthBoundPort: nil,
251 SouthBoundPort: ponmap,
252 }, args{0}, res},
253 // TODO: Add test cases.
254 }
255 for _, tt := range tests {
256 t.Run(tt.name, func(t *testing.T) {
257 StatMgr := &OpenOltStatisticsMgr{
258 Device: tt.fields.Device,
259 NorthBoundPort: tt.fields.NorthBoundPort,
260 SouthBoundPort: tt.fields.SouthBoundPort,
261 }
262 got := StatMgr.collectPONMetrics(tt.args.pID)
263 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
264 t.Errorf("collectPONMetrics() = %v, want %v", got, tt.want)
265 }
kdarapu891693b2019-09-16 12:33:49 +0530266 })
267 }
268}