blob: 499fda9dd7ccec566ab6c0fc00b635d06b7290a3 [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 }
79 ctx := map[string]string{}
80 ctx["deviceID"] = "Test"
81 ponmap := map[uint32]*PonPort{}
82 ponmap[0] = &PonPort{
83 PONID: 0,
84 DeviceID: "onu1",
85 IntfID: 0,
86 PortNum: 0,
87 PortID: 0,
88 Label: "",
89 ONUs: nil,
90 ONUsByID: nil,
91 RxBytes: 0,
92 RxPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000093 RxUcastPackets: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +053094 RxMcastPackets: 0,
95 RxBcastPackets: 0,
96 RxErrorPackets: 0,
97 TxBytes: 0,
98 TxPackets: 0,
99 TxUcastPackets: 0,
100 TxMcastPackets: 0,
101 TxBcastPackets: 0,
102 TxErrorPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000103 RxCrcErrors: 0,
104 BipErrors: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530105 }
106 nnimap := map[uint32]*NniPort{}
107 nnimap[0] = &NniPort{
108 PortNum: 0,
109 Name: "olt1",
110 LogicalPort: 0,
111 IntfID: 0,
112 RxBytes: 0,
113 RxPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000114 RxUcastPackets: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530115 RxMcastPackets: uint64(1111),
116 RxBcastPackets: 0,
117 RxErrorPackets: 0,
118 TxBytes: 0,
119 TxPackets: 0,
120 TxUcastPackets: 0,
121 TxMcastPackets: 0,
122 TxBcastPackets: 0,
123 TxErrorPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000124 RxCrcErrors: 0,
125 BipErrors: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530126 }
127 pval := make(map[string]float32)
128 pval["rx_bytes"] = float32(111)
129 nval := make(map[string]float32)
130 nval["rx_bytes"] = float32(111)
131 dhandlerNNI := newMockDeviceHandler()
132 dhandlerNNI.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: nil, NorthBoundPort: nnimap}
133 dhandlerPON := newMockDeviceHandler()
134 dhandlerPON.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: ponmap, NorthBoundPort: nil}
135 tests := []struct {
136 name string
137 fields fields
138 args args
139 }{
140 {
141 name: "PublishNNIMetrics-1",
142 fields: fields{
143 Device: dhandlerNNI,
144 NorthBoundPort: nnimap,
145 SouthBoundPort: nil,
146 },
147 args: args{
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530148 val: nval,
149 port: &voltha.Port{PortNo: 0, Label: fmt.Sprintf("%s%d", "nni-", 0), Type: voltha.Port_ETHERNET_NNI},
150 context: ctx,
Naga Manjunath7615e552019-10-11 22:35:47 +0530151 },
152 },
153 {
154 name: "PublishPONMetrics-1",
155 fields: fields{
156 Device: dhandlerPON,
157 NorthBoundPort: nil,
158 SouthBoundPort: ponmap,
159 },
160 args: args{
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530161 val: pval,
162 port: &voltha.Port{PortNo: 1, Label: fmt.Sprintf("%s%d", "pon-", 1), Type: voltha.Port_PON_OLT},
163 context: ctx,
Naga Manjunath7615e552019-10-11 22:35:47 +0530164 },
165 },
166 // TODO: Add test cases.
167 }
168 for _, tt := range tests {
169 t.Run(tt.name, func(t *testing.T) {
170 StatMgr := &OpenOltStatisticsMgr{
171 Device: tt.fields.Device,
172 NorthBoundPort: tt.fields.NorthBoundPort,
173 SouthBoundPort: tt.fields.SouthBoundPort,
174 }
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530175 StatMgr.publishMetrics(tt.args.val, tt.args.port, tt.args.context, "onu1")
Naga Manjunath7615e552019-10-11 22:35:47 +0530176 })
177 }
178}
179
180func TestOpenOltStatisticsMgr_collectNNIMetrics(t *testing.T) {
181 type fields struct {
182 Device *DeviceHandler
183 NorthBoundPort map[uint32]*NniPort
184 SouthBoundPort map[uint32]*PonPort
185 }
186 type args struct {
187 nniID uint32
188 }
189 dhandler := newMockDeviceHandler()
190 pmconfig := make(map[string]*voltha.PmConfig)
191 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
192
193 var res map[string]float32
194 nnimap := map[uint32]*NniPort{}
195 nnimap[0] = &NniPort{Name: "olt"}
196 nnimap[1] = &NniPort{Name: "olt"}
197 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: nil, NorthBoundPort: nnimap}}
198 tests := []struct {
199 name string
200 fields fields
201 args args
202 want map[string]float32
203 }{
204 {"CollectNNIMetrics-1", fields{
205 Device: dh,
206 NorthBoundPort: nnimap,
207 SouthBoundPort: nil,
208 }, args{0}, res},
209 {"CollectNNIMetrics-2", fields{
210 Device: dh,
211 NorthBoundPort: nnimap,
212 SouthBoundPort: nil,
213 }, args{1}, res},
214 // TODO: Add test cases.
215 }
216 for _, tt := range tests {
217 t.Run(tt.name, func(t *testing.T) {
218 StatMgr := &OpenOltStatisticsMgr{
219 Device: tt.fields.Device,
220 NorthBoundPort: tt.fields.NorthBoundPort,
221 SouthBoundPort: tt.fields.SouthBoundPort,
222 }
223 got := StatMgr.collectNNIMetrics(tt.args.nniID)
224 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
225 t.Errorf("collectNNIMetrics() = %v, want %v", got, tt.want)
226 }
227 })
228 }
229}
230
231func TestOpenOltStatisticsMgr_collectPONMetrics(t *testing.T) {
232 type fields struct {
233 Device *DeviceHandler
234 NorthBoundPort map[uint32]*NniPort
235 SouthBoundPort map[uint32]*PonPort
236 }
237 type args struct {
238 pID uint32
239 }
240 dhandler := newMockDeviceHandler()
241 pmconfig := make(map[string]*voltha.PmConfig)
242 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
243
244 var res map[string]float32
245 ponmap := map[uint32]*PonPort{}
246 ponmap[0] = &PonPort{DeviceID: "olt"}
247 ponmap[1] = &PonPort{DeviceID: "olt"}
248 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: ponmap, NorthBoundPort: nil}}
249
250 tests := []struct {
251 name string
252 fields fields
253 args args
254 want map[string]float32
255 }{
256 {"CollectPONMetrics-1", fields{
257 Device: dh,
258 NorthBoundPort: nil,
259 SouthBoundPort: ponmap,
260 }, args{0}, res},
261 // TODO: Add test cases.
262 }
263 for _, tt := range tests {
264 t.Run(tt.name, func(t *testing.T) {
265 StatMgr := &OpenOltStatisticsMgr{
266 Device: tt.fields.Device,
267 NorthBoundPort: tt.fields.NorthBoundPort,
268 SouthBoundPort: tt.fields.SouthBoundPort,
269 }
270 got := StatMgr.collectPONMetrics(tt.args.pID)
271 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
272 t.Errorf("collectPONMetrics() = %v, want %v", got, tt.want)
273 }
kdarapu891693b2019-09-16 12:33:49 +0530274 })
275 }
276}