blob: 6ea2487b0922323207aa75be9567d237018b652f [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 (
Naga Manjunath7615e552019-10-11 22:35:47 +053021 "reflect"
kdarapu891693b2019-09-16 12:33:49 +053022 "testing"
23
Esin Karamanccb714b2019-11-29 15:02:06 +000024 "github.com/opencord/voltha-lib-go/v3/pkg/log"
25 "github.com/opencord/voltha-protos/v3/go/openolt"
26 "github.com/opencord/voltha-protos/v3/go/voltha"
kdarapu891693b2019-09-16 12:33:49 +053027)
28
29func init() {
30 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
31}
32func TestOpenOltStatisticsMgr_PortStatisticsIndication(t *testing.T) {
33 device := &voltha.Device{
34 Id: "olt",
35 Root: true,
36 ParentId: "logical_device",
37 Ports: []*voltha.Port{
38 {PortNo: 1, Label: "pon", Type: voltha.Port_ETHERNET_UNI},
39 {PortNo: 2, Label: "nni", Type: voltha.Port_ETHERNET_NNI},
40 },
41 ProxyAddress: &voltha.Device_ProxyAddress{
42 DeviceId: "olt",
43 DeviceType: "onu",
44 ChannelId: 1,
45 ChannelGroupId: 1,
46 },
47 ConnectStatus: 1,
48 }
Naga Manjunath7615e552019-10-11 22:35:47 +053049 dh := newMockDeviceHandler()
kdarapu891693b2019-09-16 12:33:49 +053050 dh.device = device
51 StatMgr := NewOpenOltStatsMgr(dh)
52
53 type args struct {
54 PortStats *openolt.PortStatistics
55 }
56 tests := []struct {
57 name string
58 args args
59 }{
60 // TODO: Add test cases.
61 {"PortStatisticsIndication", args{PortStats: &openolt.PortStatistics{}}},
62 }
63 for _, tt := range tests {
64 t.Run(tt.name, func(t *testing.T) {
65
Naga Manjunath7615e552019-10-11 22:35:47 +053066 StatMgr.PortStatisticsIndication(tt.args.PortStats, 16)
67 })
68 }
69}
70
71func TestOpenOltStatisticsMgr_publishMetrics(t *testing.T) {
72 type fields struct {
73 Device *DeviceHandler
74 NorthBoundPort map[uint32]*NniPort
75 SouthBoundPort map[uint32]*PonPort
76 }
77 type args struct {
78 portType string
79 val map[string]float32
80 portnum uint32
81 context map[string]string
82 }
83 ctx := map[string]string{}
84 ctx["deviceID"] = "Test"
85 ponmap := map[uint32]*PonPort{}
86 ponmap[0] = &PonPort{
87 PONID: 0,
88 DeviceID: "onu1",
89 IntfID: 0,
90 PortNum: 0,
91 PortID: 0,
92 Label: "",
93 ONUs: nil,
94 ONUsByID: nil,
95 RxBytes: 0,
96 RxPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000097 RxUcastPackets: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +053098 RxMcastPackets: 0,
99 RxBcastPackets: 0,
100 RxErrorPackets: 0,
101 TxBytes: 0,
102 TxPackets: 0,
103 TxUcastPackets: 0,
104 TxMcastPackets: 0,
105 TxBcastPackets: 0,
106 TxErrorPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000107 RxCrcErrors: 0,
108 BipErrors: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530109 }
110 nnimap := map[uint32]*NniPort{}
111 nnimap[0] = &NniPort{
112 PortNum: 0,
113 Name: "olt1",
114 LogicalPort: 0,
115 IntfID: 0,
116 RxBytes: 0,
117 RxPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000118 RxUcastPackets: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530119 RxMcastPackets: uint64(1111),
120 RxBcastPackets: 0,
121 RxErrorPackets: 0,
122 TxBytes: 0,
123 TxPackets: 0,
124 TxUcastPackets: 0,
125 TxMcastPackets: 0,
126 TxBcastPackets: 0,
127 TxErrorPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000128 RxCrcErrors: 0,
129 BipErrors: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530130 }
131 pval := make(map[string]float32)
132 pval["rx_bytes"] = float32(111)
133 nval := make(map[string]float32)
134 nval["rx_bytes"] = float32(111)
135 dhandlerNNI := newMockDeviceHandler()
136 dhandlerNNI.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: nil, NorthBoundPort: nnimap}
137 dhandlerPON := newMockDeviceHandler()
138 dhandlerPON.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: ponmap, NorthBoundPort: nil}
139 tests := []struct {
140 name string
141 fields fields
142 args args
143 }{
144 {
145 name: "PublishNNIMetrics-1",
146 fields: fields{
147 Device: dhandlerNNI,
148 NorthBoundPort: nnimap,
149 SouthBoundPort: nil,
150 },
151 args: args{
152 portType: "NNIStats",
153 val: nval,
154 portnum: 0,
155 context: ctx,
156 },
157 },
158 {
159 name: "PublishPONMetrics-1",
160 fields: fields{
161 Device: dhandlerPON,
162 NorthBoundPort: nil,
163 SouthBoundPort: ponmap,
164 },
165 args: args{
166 portType: "PONStats",
167 val: pval,
168 portnum: 0,
169 context: ctx,
170 },
171 },
172 // TODO: Add test cases.
173 }
174 for _, tt := range tests {
175 t.Run(tt.name, func(t *testing.T) {
176 StatMgr := &OpenOltStatisticsMgr{
177 Device: tt.fields.Device,
178 NorthBoundPort: tt.fields.NorthBoundPort,
179 SouthBoundPort: tt.fields.SouthBoundPort,
180 }
181 StatMgr.publishMetrics(tt.args.portType, tt.args.val, tt.args.portnum, tt.args.context, "onu1")
182
183 })
184 }
185}
186
187func TestOpenOltStatisticsMgr_collectNNIMetrics(t *testing.T) {
188 type fields struct {
189 Device *DeviceHandler
190 NorthBoundPort map[uint32]*NniPort
191 SouthBoundPort map[uint32]*PonPort
192 }
193 type args struct {
194 nniID uint32
195 }
196 dhandler := newMockDeviceHandler()
197 pmconfig := make(map[string]*voltha.PmConfig)
198 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
199
200 var res map[string]float32
201 nnimap := map[uint32]*NniPort{}
202 nnimap[0] = &NniPort{Name: "olt"}
203 nnimap[1] = &NniPort{Name: "olt"}
204 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: nil, NorthBoundPort: nnimap}}
205 tests := []struct {
206 name string
207 fields fields
208 args args
209 want map[string]float32
210 }{
211 {"CollectNNIMetrics-1", fields{
212 Device: dh,
213 NorthBoundPort: nnimap,
214 SouthBoundPort: nil,
215 }, args{0}, res},
216 {"CollectNNIMetrics-2", fields{
217 Device: dh,
218 NorthBoundPort: nnimap,
219 SouthBoundPort: nil,
220 }, args{1}, res},
221 // TODO: Add test cases.
222 }
223 for _, tt := range tests {
224 t.Run(tt.name, func(t *testing.T) {
225 StatMgr := &OpenOltStatisticsMgr{
226 Device: tt.fields.Device,
227 NorthBoundPort: tt.fields.NorthBoundPort,
228 SouthBoundPort: tt.fields.SouthBoundPort,
229 }
230 got := StatMgr.collectNNIMetrics(tt.args.nniID)
231 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
232 t.Errorf("collectNNIMetrics() = %v, want %v", got, tt.want)
233 }
234 })
235 }
236}
237
238func TestOpenOltStatisticsMgr_collectPONMetrics(t *testing.T) {
239 type fields struct {
240 Device *DeviceHandler
241 NorthBoundPort map[uint32]*NniPort
242 SouthBoundPort map[uint32]*PonPort
243 }
244 type args struct {
245 pID uint32
246 }
247 dhandler := newMockDeviceHandler()
248 pmconfig := make(map[string]*voltha.PmConfig)
249 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
250
251 var res map[string]float32
252 ponmap := map[uint32]*PonPort{}
253 ponmap[0] = &PonPort{DeviceID: "olt"}
254 ponmap[1] = &PonPort{DeviceID: "olt"}
255 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: ponmap, NorthBoundPort: nil}}
256
257 tests := []struct {
258 name string
259 fields fields
260 args args
261 want map[string]float32
262 }{
263 {"CollectPONMetrics-1", fields{
264 Device: dh,
265 NorthBoundPort: nil,
266 SouthBoundPort: ponmap,
267 }, args{0}, res},
268 // TODO: Add test cases.
269 }
270 for _, tt := range tests {
271 t.Run(tt.name, func(t *testing.T) {
272 StatMgr := &OpenOltStatisticsMgr{
273 Device: tt.fields.Device,
274 NorthBoundPort: tt.fields.NorthBoundPort,
275 SouthBoundPort: tt.fields.SouthBoundPort,
276 }
277 got := StatMgr.collectPONMetrics(tt.args.pID)
278 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
279 t.Errorf("collectPONMetrics() = %v, want %v", got, tt.want)
280 }
kdarapu891693b2019-09-16 12:33:49 +0530281 })
282 }
283}