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