blob: cfbc04a0da1b22a9bc1ef6ae829e5247ca125384 [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",
kdarapu891693b2019-09-16 12:33:49 +053034 ProxyAddress: &voltha.Device_ProxyAddress{
35 DeviceId: "olt",
36 DeviceType: "onu",
37 ChannelId: 1,
38 ChannelGroupId: 1,
39 },
40 ConnectStatus: 1,
41 }
Naga Manjunath7615e552019-10-11 22:35:47 +053042 dh := newMockDeviceHandler()
kdarapu891693b2019-09-16 12:33:49 +053043 dh.device = device
Neha Sharma96b7bf22020-06-15 10:37:32 +000044 StatMgr := NewOpenOltStatsMgr(context.Background(), dh)
kdarapu891693b2019-09-16 12:33:49 +053045
46 type args struct {
47 PortStats *openolt.PortStatistics
48 }
49 tests := []struct {
50 name string
51 args args
52 }{
53 // TODO: Add test cases.
54 {"PortStatisticsIndication", args{PortStats: &openolt.PortStatistics{}}},
55 }
56 for _, tt := range tests {
57 t.Run(tt.name, func(t *testing.T) {
58
Neha Sharma96b7bf22020-06-15 10:37:32 +000059 StatMgr.PortStatisticsIndication(context.Background(), tt.args.PortStats, 16)
Naga Manjunath7615e552019-10-11 22:35:47 +053060 })
61 }
62}
63
64func TestOpenOltStatisticsMgr_publishMetrics(t *testing.T) {
65 type fields struct {
66 Device *DeviceHandler
67 NorthBoundPort map[uint32]*NniPort
68 SouthBoundPort map[uint32]*PonPort
69 }
70 type args struct {
Kishore Darapuaaf9c102020-05-04 13:06:57 +053071 portType voltha.Port_PortType
Naga Manjunath7615e552019-10-11 22:35:47 +053072 val map[string]float32
Kishore Darapuaaf9c102020-05-04 13:06:57 +053073 port *voltha.Port
Naga Manjunath7615e552019-10-11 22:35:47 +053074 context map[string]string
75 }
Naga Manjunath7615e552019-10-11 22:35:47 +053076 ponmap := map[uint32]*PonPort{}
77 ponmap[0] = &PonPort{
78 PONID: 0,
79 DeviceID: "onu1",
80 IntfID: 0,
81 PortNum: 0,
82 PortID: 0,
83 Label: "",
84 ONUs: nil,
85 ONUsByID: nil,
86 RxBytes: 0,
87 RxPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000088 RxUcastPackets: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +053089 RxMcastPackets: 0,
90 RxBcastPackets: 0,
91 RxErrorPackets: 0,
92 TxBytes: 0,
93 TxPackets: 0,
94 TxUcastPackets: 0,
95 TxMcastPackets: 0,
96 TxBcastPackets: 0,
97 TxErrorPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000098 RxCrcErrors: 0,
99 BipErrors: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530100 }
101 nnimap := map[uint32]*NniPort{}
102 nnimap[0] = &NniPort{
103 PortNum: 0,
104 Name: "olt1",
105 LogicalPort: 0,
106 IntfID: 0,
107 RxBytes: 0,
108 RxPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000109 RxUcastPackets: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530110 RxMcastPackets: uint64(1111),
111 RxBcastPackets: 0,
112 RxErrorPackets: 0,
113 TxBytes: 0,
114 TxPackets: 0,
115 TxUcastPackets: 0,
116 TxMcastPackets: 0,
117 TxBcastPackets: 0,
118 TxErrorPackets: 0,
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000119 RxCrcErrors: 0,
120 BipErrors: 0,
Naga Manjunath7615e552019-10-11 22:35:47 +0530121 }
122 pval := make(map[string]float32)
123 pval["rx_bytes"] = float32(111)
124 nval := make(map[string]float32)
125 nval["rx_bytes"] = float32(111)
126 dhandlerNNI := newMockDeviceHandler()
127 dhandlerNNI.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: nil, NorthBoundPort: nnimap}
128 dhandlerPON := newMockDeviceHandler()
129 dhandlerPON.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: ponmap, NorthBoundPort: nil}
130 tests := []struct {
131 name string
132 fields fields
133 args args
134 }{
135 {
136 name: "PublishNNIMetrics-1",
137 fields: fields{
138 Device: dhandlerNNI,
139 NorthBoundPort: nnimap,
140 SouthBoundPort: nil,
141 },
142 args: args{
Girish Gowdra34815db2020-05-11 17:18:04 -0700143 val: nval,
144 port: &voltha.Port{PortNo: 0, Label: fmt.Sprintf("%s%d", "nni-", 0), Type: voltha.Port_ETHERNET_NNI},
Naga Manjunath7615e552019-10-11 22:35:47 +0530145 },
146 },
147 {
148 name: "PublishPONMetrics-1",
149 fields: fields{
150 Device: dhandlerPON,
151 NorthBoundPort: nil,
152 SouthBoundPort: ponmap,
153 },
154 args: args{
Girish Gowdra34815db2020-05-11 17:18:04 -0700155 val: pval,
156 port: &voltha.Port{PortNo: 1, Label: fmt.Sprintf("%s%d", "pon-", 1), Type: voltha.Port_PON_OLT},
Naga Manjunath7615e552019-10-11 22:35:47 +0530157 },
158 },
159 // TODO: Add test cases.
160 }
161 for _, tt := range tests {
162 t.Run(tt.name, func(t *testing.T) {
163 StatMgr := &OpenOltStatisticsMgr{
164 Device: tt.fields.Device,
165 NorthBoundPort: tt.fields.NorthBoundPort,
166 SouthBoundPort: tt.fields.SouthBoundPort,
167 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000168 StatMgr.publishMetrics(context.Background(), tt.args.val, tt.args.port, "onu1", "openolt")
Naga Manjunath7615e552019-10-11 22:35:47 +0530169 })
170 }
171}
172
173func TestOpenOltStatisticsMgr_collectNNIMetrics(t *testing.T) {
174 type fields struct {
175 Device *DeviceHandler
176 NorthBoundPort map[uint32]*NniPort
177 SouthBoundPort map[uint32]*PonPort
178 }
179 type args struct {
180 nniID uint32
181 }
182 dhandler := newMockDeviceHandler()
183 pmconfig := make(map[string]*voltha.PmConfig)
184 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
185
186 var res map[string]float32
187 nnimap := map[uint32]*NniPort{}
188 nnimap[0] = &NniPort{Name: "olt"}
189 nnimap[1] = &NniPort{Name: "olt"}
190 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: nil, NorthBoundPort: nnimap}}
191 tests := []struct {
192 name string
193 fields fields
194 args args
195 want map[string]float32
196 }{
197 {"CollectNNIMetrics-1", fields{
198 Device: dh,
199 NorthBoundPort: nnimap,
200 SouthBoundPort: nil,
201 }, args{0}, res},
202 {"CollectNNIMetrics-2", fields{
203 Device: dh,
204 NorthBoundPort: nnimap,
205 SouthBoundPort: nil,
206 }, args{1}, res},
207 // TODO: Add test cases.
208 }
209 for _, tt := range tests {
210 t.Run(tt.name, func(t *testing.T) {
211 StatMgr := &OpenOltStatisticsMgr{
212 Device: tt.fields.Device,
213 NorthBoundPort: tt.fields.NorthBoundPort,
214 SouthBoundPort: tt.fields.SouthBoundPort,
215 }
216 got := StatMgr.collectNNIMetrics(tt.args.nniID)
217 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
218 t.Errorf("collectNNIMetrics() = %v, want %v", got, tt.want)
219 }
220 })
221 }
222}
223
224func TestOpenOltStatisticsMgr_collectPONMetrics(t *testing.T) {
225 type fields struct {
226 Device *DeviceHandler
227 NorthBoundPort map[uint32]*NniPort
228 SouthBoundPort map[uint32]*PonPort
229 }
230 type args struct {
231 pID uint32
232 }
233 dhandler := newMockDeviceHandler()
234 pmconfig := make(map[string]*voltha.PmConfig)
235 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
236
237 var res map[string]float32
238 ponmap := map[uint32]*PonPort{}
239 ponmap[0] = &PonPort{DeviceID: "olt"}
240 ponmap[1] = &PonPort{DeviceID: "olt"}
241 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: ponmap, NorthBoundPort: nil}}
242
243 tests := []struct {
244 name string
245 fields fields
246 args args
247 want map[string]float32
248 }{
249 {"CollectPONMetrics-1", fields{
250 Device: dh,
251 NorthBoundPort: nil,
252 SouthBoundPort: ponmap,
253 }, args{0}, res},
254 // TODO: Add test cases.
255 }
256 for _, tt := range tests {
257 t.Run(tt.name, func(t *testing.T) {
258 StatMgr := &OpenOltStatisticsMgr{
259 Device: tt.fields.Device,
260 NorthBoundPort: tt.fields.NorthBoundPort,
261 SouthBoundPort: tt.fields.SouthBoundPort,
262 }
263 got := StatMgr.collectPONMetrics(tt.args.pID)
264 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
265 t.Errorf("collectPONMetrics() = %v, want %v", got, tt.want)
266 }
kdarapu891693b2019-09-16 12:33:49 +0530267 })
268 }
269}