blob: b4be7350603450d46c380f201edcac6dce8a3457 [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 (
Esin Karamanccb714b2019-11-29 15:02:06 +000021 "github.com/opencord/voltha-protos/v3/go/openolt"
22 "github.com/opencord/voltha-protos/v3/go/voltha"
Girish Kumar2ad402b2020-03-20 19:45:12 +000023 "reflect"
24 "testing"
kdarapu891693b2019-09-16 12:33:49 +053025)
26
kdarapu891693b2019-09-16 12:33:49 +053027func TestOpenOltStatisticsMgr_PortStatisticsIndication(t *testing.T) {
28 device := &voltha.Device{
29 Id: "olt",
30 Root: true,
31 ParentId: "logical_device",
32 Ports: []*voltha.Port{
33 {PortNo: 1, Label: "pon", Type: voltha.Port_ETHERNET_UNI},
34 {PortNo: 2, Label: "nni", Type: voltha.Port_ETHERNET_NNI},
35 },
36 ProxyAddress: &voltha.Device_ProxyAddress{
37 DeviceId: "olt",
38 DeviceType: "onu",
39 ChannelId: 1,
40 ChannelGroupId: 1,
41 },
42 ConnectStatus: 1,
43 }
Naga Manjunath7615e552019-10-11 22:35:47 +053044 dh := newMockDeviceHandler()
kdarapu891693b2019-09-16 12:33:49 +053045 dh.device = device
46 StatMgr := NewOpenOltStatsMgr(dh)
47
48 type args struct {
49 PortStats *openolt.PortStatistics
50 }
51 tests := []struct {
52 name string
53 args args
54 }{
55 // TODO: Add test cases.
56 {"PortStatisticsIndication", args{PortStats: &openolt.PortStatistics{}}},
57 }
58 for _, tt := range tests {
59 t.Run(tt.name, func(t *testing.T) {
60
Naga Manjunath7615e552019-10-11 22:35:47 +053061 StatMgr.PortStatisticsIndication(tt.args.PortStats, 16)
62 })
63 }
64}
65
66func TestOpenOltStatisticsMgr_publishMetrics(t *testing.T) {
67 type fields struct {
68 Device *DeviceHandler
69 NorthBoundPort map[uint32]*NniPort
70 SouthBoundPort map[uint32]*PonPort
71 }
72 type args struct {
73 portType string
74 val map[string]float32
75 portnum uint32
76 context map[string]string
77 }
78 ctx := map[string]string{}
79 ctx["deviceID"] = "Test"
80 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{
147 portType: "NNIStats",
148 val: nval,
149 portnum: 0,
150 context: ctx,
151 },
152 },
153 {
154 name: "PublishPONMetrics-1",
155 fields: fields{
156 Device: dhandlerPON,
157 NorthBoundPort: nil,
158 SouthBoundPort: ponmap,
159 },
160 args: args{
161 portType: "PONStats",
162 val: pval,
163 portnum: 0,
164 context: ctx,
165 },
166 },
167 // TODO: Add test cases.
168 }
169 for _, tt := range tests {
170 t.Run(tt.name, func(t *testing.T) {
171 StatMgr := &OpenOltStatisticsMgr{
172 Device: tt.fields.Device,
173 NorthBoundPort: tt.fields.NorthBoundPort,
174 SouthBoundPort: tt.fields.SouthBoundPort,
175 }
176 StatMgr.publishMetrics(tt.args.portType, tt.args.val, tt.args.portnum, tt.args.context, "onu1")
177
178 })
179 }
180}
181
182func TestOpenOltStatisticsMgr_collectNNIMetrics(t *testing.T) {
183 type fields struct {
184 Device *DeviceHandler
185 NorthBoundPort map[uint32]*NniPort
186 SouthBoundPort map[uint32]*PonPort
187 }
188 type args struct {
189 nniID uint32
190 }
191 dhandler := newMockDeviceHandler()
192 pmconfig := make(map[string]*voltha.PmConfig)
193 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
194
195 var res map[string]float32
196 nnimap := map[uint32]*NniPort{}
197 nnimap[0] = &NniPort{Name: "olt"}
198 nnimap[1] = &NniPort{Name: "olt"}
199 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: nil, NorthBoundPort: nnimap}}
200 tests := []struct {
201 name string
202 fields fields
203 args args
204 want map[string]float32
205 }{
206 {"CollectNNIMetrics-1", fields{
207 Device: dh,
208 NorthBoundPort: nnimap,
209 SouthBoundPort: nil,
210 }, args{0}, res},
211 {"CollectNNIMetrics-2", fields{
212 Device: dh,
213 NorthBoundPort: nnimap,
214 SouthBoundPort: nil,
215 }, args{1}, res},
216 // TODO: Add test cases.
217 }
218 for _, tt := range tests {
219 t.Run(tt.name, func(t *testing.T) {
220 StatMgr := &OpenOltStatisticsMgr{
221 Device: tt.fields.Device,
222 NorthBoundPort: tt.fields.NorthBoundPort,
223 SouthBoundPort: tt.fields.SouthBoundPort,
224 }
225 got := StatMgr.collectNNIMetrics(tt.args.nniID)
226 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
227 t.Errorf("collectNNIMetrics() = %v, want %v", got, tt.want)
228 }
229 })
230 }
231}
232
233func TestOpenOltStatisticsMgr_collectPONMetrics(t *testing.T) {
234 type fields struct {
235 Device *DeviceHandler
236 NorthBoundPort map[uint32]*NniPort
237 SouthBoundPort map[uint32]*PonPort
238 }
239 type args struct {
240 pID uint32
241 }
242 dhandler := newMockDeviceHandler()
243 pmconfig := make(map[string]*voltha.PmConfig)
244 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
245
246 var res map[string]float32
247 ponmap := map[uint32]*PonPort{}
248 ponmap[0] = &PonPort{DeviceID: "olt"}
249 ponmap[1] = &PonPort{DeviceID: "olt"}
250 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: ponmap, NorthBoundPort: nil}}
251
252 tests := []struct {
253 name string
254 fields fields
255 args args
256 want map[string]float32
257 }{
258 {"CollectPONMetrics-1", fields{
259 Device: dh,
260 NorthBoundPort: nil,
261 SouthBoundPort: ponmap,
262 }, args{0}, res},
263 // TODO: Add test cases.
264 }
265 for _, tt := range tests {
266 t.Run(tt.name, func(t *testing.T) {
267 StatMgr := &OpenOltStatisticsMgr{
268 Device: tt.fields.Device,
269 NorthBoundPort: tt.fields.NorthBoundPort,
270 SouthBoundPort: tt.fields.SouthBoundPort,
271 }
272 got := StatMgr.collectPONMetrics(tt.args.pID)
273 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
274 t.Errorf("collectPONMetrics() = %v, want %v", got, tt.want)
275 }
kdarapu891693b2019-09-16 12:33:49 +0530276 })
277 }
278}