blob: f7f82462766b9bc482160e6c64dc3847ad3b778a [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 (
Kishore Darapuaaf9c102020-05-04 13:06:57 +053021 "fmt"
Esin Karamanccb714b2019-11-29 15:02:06 +000022 "github.com/opencord/voltha-protos/v3/go/openolt"
23 "github.com/opencord/voltha-protos/v3/go/voltha"
Girish Kumar2ad402b2020-03-20 19:45:12 +000024 "reflect"
25 "testing"
kdarapu891693b2019-09-16 12:33:49 +053026)
27
kdarapu891693b2019-09-16 12:33:49 +053028func TestOpenOltStatisticsMgr_PortStatisticsIndication(t *testing.T) {
29 device := &voltha.Device{
30 Id: "olt",
31 Root: true,
32 ParentId: "logical_device",
33 Ports: []*voltha.Port{
34 {PortNo: 1, Label: "pon", Type: voltha.Port_ETHERNET_UNI},
35 {PortNo: 2, Label: "nni", Type: voltha.Port_ETHERNET_NNI},
36 },
37 ProxyAddress: &voltha.Device_ProxyAddress{
38 DeviceId: "olt",
39 DeviceType: "onu",
40 ChannelId: 1,
41 ChannelGroupId: 1,
42 },
43 ConnectStatus: 1,
44 }
Naga Manjunath7615e552019-10-11 22:35:47 +053045 dh := newMockDeviceHandler()
kdarapu891693b2019-09-16 12:33:49 +053046 dh.device = device
47 StatMgr := NewOpenOltStatsMgr(dh)
48
49 type args struct {
50 PortStats *openolt.PortStatistics
51 }
52 tests := []struct {
53 name string
54 args args
55 }{
56 // TODO: Add test cases.
57 {"PortStatisticsIndication", args{PortStats: &openolt.PortStatistics{}}},
58 }
59 for _, tt := range tests {
60 t.Run(tt.name, func(t *testing.T) {
61
Naga Manjunath7615e552019-10-11 22:35:47 +053062 StatMgr.PortStatisticsIndication(tt.args.PortStats, 16)
63 })
64 }
65}
66
67func TestOpenOltStatisticsMgr_publishMetrics(t *testing.T) {
68 type fields struct {
69 Device *DeviceHandler
70 NorthBoundPort map[uint32]*NniPort
71 SouthBoundPort map[uint32]*PonPort
72 }
73 type args struct {
Kishore Darapuaaf9c102020-05-04 13:06:57 +053074 portType voltha.Port_PortType
Naga Manjunath7615e552019-10-11 22:35:47 +053075 val map[string]float32
Kishore Darapuaaf9c102020-05-04 13:06:57 +053076 port *voltha.Port
Naga Manjunath7615e552019-10-11 22:35:47 +053077 context map[string]string
78 }
Naga Manjunath7615e552019-10-11 22:35:47 +053079 ponmap := map[uint32]*PonPort{}
80 ponmap[0] = &PonPort{
81 PONID: 0,
82 DeviceID: "onu1",
83 IntfID: 0,
84 PortNum: 0,
85 PortID: 0,
86 Label: "",
87 ONUs: nil,
88 ONUsByID: nil,
89 RxBytes: 0,
90 RxPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000091 RxUcastPackets: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +053092 RxMcastPackets: 0,
93 RxBcastPackets: 0,
94 RxErrorPackets: 0,
95 TxBytes: 0,
96 TxPackets: 0,
97 TxUcastPackets: 0,
98 TxMcastPackets: 0,
99 TxBcastPackets: 0,
100 TxErrorPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000101 RxCrcErrors: 0,
102 BipErrors: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530103 }
104 nnimap := map[uint32]*NniPort{}
105 nnimap[0] = &NniPort{
106 PortNum: 0,
107 Name: "olt1",
108 LogicalPort: 0,
109 IntfID: 0,
110 RxBytes: 0,
111 RxPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000112 RxUcastPackets: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530113 RxMcastPackets: uint64(1111),
114 RxBcastPackets: 0,
115 RxErrorPackets: 0,
116 TxBytes: 0,
117 TxPackets: 0,
118 TxUcastPackets: 0,
119 TxMcastPackets: 0,
120 TxBcastPackets: 0,
121 TxErrorPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000122 RxCrcErrors: 0,
123 BipErrors: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530124 }
125 pval := make(map[string]float32)
126 pval["rx_bytes"] = float32(111)
127 nval := make(map[string]float32)
128 nval["rx_bytes"] = float32(111)
129 dhandlerNNI := newMockDeviceHandler()
130 dhandlerNNI.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: nil, NorthBoundPort: nnimap}
131 dhandlerPON := newMockDeviceHandler()
132 dhandlerPON.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: ponmap, NorthBoundPort: nil}
133 tests := []struct {
134 name string
135 fields fields
136 args args
137 }{
138 {
139 name: "PublishNNIMetrics-1",
140 fields: fields{
141 Device: dhandlerNNI,
142 NorthBoundPort: nnimap,
143 SouthBoundPort: nil,
144 },
145 args: args{
Girish Gowdra34815db2020-05-11 17:18:04 -0700146 val: nval,
147 port: &voltha.Port{PortNo: 0, Label: fmt.Sprintf("%s%d", "nni-", 0), Type: voltha.Port_ETHERNET_NNI},
Naga Manjunath7615e552019-10-11 22:35:47 +0530148 },
149 },
150 {
151 name: "PublishPONMetrics-1",
152 fields: fields{
153 Device: dhandlerPON,
154 NorthBoundPort: nil,
155 SouthBoundPort: ponmap,
156 },
157 args: args{
Girish Gowdra34815db2020-05-11 17:18:04 -0700158 val: pval,
159 port: &voltha.Port{PortNo: 1, Label: fmt.Sprintf("%s%d", "pon-", 1), Type: voltha.Port_PON_OLT},
Naga Manjunath7615e552019-10-11 22:35:47 +0530160 },
161 },
162 // TODO: Add test cases.
163 }
164 for _, tt := range tests {
165 t.Run(tt.name, func(t *testing.T) {
166 StatMgr := &OpenOltStatisticsMgr{
167 Device: tt.fields.Device,
168 NorthBoundPort: tt.fields.NorthBoundPort,
169 SouthBoundPort: tt.fields.SouthBoundPort,
170 }
Girish Gowdra34815db2020-05-11 17:18:04 -0700171 StatMgr.publishMetrics(tt.args.val, tt.args.port, "onu1", "openolt")
Naga Manjunath7615e552019-10-11 22:35:47 +0530172 })
173 }
174}
175
176func TestOpenOltStatisticsMgr_collectNNIMetrics(t *testing.T) {
177 type fields struct {
178 Device *DeviceHandler
179 NorthBoundPort map[uint32]*NniPort
180 SouthBoundPort map[uint32]*PonPort
181 }
182 type args struct {
183 nniID uint32
184 }
185 dhandler := newMockDeviceHandler()
186 pmconfig := make(map[string]*voltha.PmConfig)
187 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
188
189 var res map[string]float32
190 nnimap := map[uint32]*NniPort{}
191 nnimap[0] = &NniPort{Name: "olt"}
192 nnimap[1] = &NniPort{Name: "olt"}
193 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: nil, NorthBoundPort: nnimap}}
194 tests := []struct {
195 name string
196 fields fields
197 args args
198 want map[string]float32
199 }{
200 {"CollectNNIMetrics-1", fields{
201 Device: dh,
202 NorthBoundPort: nnimap,
203 SouthBoundPort: nil,
204 }, args{0}, res},
205 {"CollectNNIMetrics-2", fields{
206 Device: dh,
207 NorthBoundPort: nnimap,
208 SouthBoundPort: nil,
209 }, args{1}, res},
210 // TODO: Add test cases.
211 }
212 for _, tt := range tests {
213 t.Run(tt.name, func(t *testing.T) {
214 StatMgr := &OpenOltStatisticsMgr{
215 Device: tt.fields.Device,
216 NorthBoundPort: tt.fields.NorthBoundPort,
217 SouthBoundPort: tt.fields.SouthBoundPort,
218 }
219 got := StatMgr.collectNNIMetrics(tt.args.nniID)
220 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
221 t.Errorf("collectNNIMetrics() = %v, want %v", got, tt.want)
222 }
223 })
224 }
225}
226
227func TestOpenOltStatisticsMgr_collectPONMetrics(t *testing.T) {
228 type fields struct {
229 Device *DeviceHandler
230 NorthBoundPort map[uint32]*NniPort
231 SouthBoundPort map[uint32]*PonPort
232 }
233 type args struct {
234 pID uint32
235 }
236 dhandler := newMockDeviceHandler()
237 pmconfig := make(map[string]*voltha.PmConfig)
238 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
239
240 var res map[string]float32
241 ponmap := map[uint32]*PonPort{}
242 ponmap[0] = &PonPort{DeviceID: "olt"}
243 ponmap[1] = &PonPort{DeviceID: "olt"}
244 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: ponmap, NorthBoundPort: nil}}
245
246 tests := []struct {
247 name string
248 fields fields
249 args args
250 want map[string]float32
251 }{
252 {"CollectPONMetrics-1", fields{
253 Device: dh,
254 NorthBoundPort: nil,
255 SouthBoundPort: ponmap,
256 }, args{0}, res},
257 // TODO: Add test cases.
258 }
259 for _, tt := range tests {
260 t.Run(tt.name, func(t *testing.T) {
261 StatMgr := &OpenOltStatisticsMgr{
262 Device: tt.fields.Device,
263 NorthBoundPort: tt.fields.NorthBoundPort,
264 SouthBoundPort: tt.fields.SouthBoundPort,
265 }
266 got := StatMgr.collectPONMetrics(tt.args.pID)
267 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
268 t.Errorf("collectPONMetrics() = %v, want %v", got, tt.want)
269 }
kdarapu891693b2019-09-16 12:33:49 +0530270 })
271 }
272}