blob: 211f82a5517a02a180dda2f73d0fe043645843c9 [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
17//Package adaptercore provides the utility for olt devices, flows and statistics
18package adaptercore
19
20import (
Naga Manjunath7615e552019-10-11 22:35:47 +053021 "reflect"
kdarapu891693b2019-09-16 12:33:49 +053022 "testing"
23
Scott Baker51290152019-10-24 14:23:20 -070024 "github.com/opencord/voltha-lib-go/v2/pkg/log"
Scott Bakerc6e54cb2019-11-04 09:31:25 -080025 "github.com/opencord/voltha-protos/v2/go/openolt"
26 "github.com/opencord/voltha-protos/v2/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,
97 RxMcastPackets: 0,
98 RxBcastPackets: 0,
99 RxErrorPackets: 0,
100 TxBytes: 0,
101 TxPackets: 0,
102 TxUcastPackets: 0,
103 TxMcastPackets: 0,
104 TxBcastPackets: 0,
105 TxErrorPackets: 0,
106 }
107 nnimap := map[uint32]*NniPort{}
108 nnimap[0] = &NniPort{
109 PortNum: 0,
110 Name: "olt1",
111 LogicalPort: 0,
112 IntfID: 0,
113 RxBytes: 0,
114 RxPackets: 0,
115 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,
124 }
125 pval := make(map[string]float32)
126 pval["rx_bytes"] = float32(111)
127 nval := make(map[string]float32)
128 nval["rx_bytes"] = float32(111)
129 dhandlerNNI := newMockDeviceHandler()
130 dhandlerNNI.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: nil, NorthBoundPort: nnimap}
131 dhandlerPON := newMockDeviceHandler()
132 dhandlerPON.portStats = &OpenOltStatisticsMgr{Device: nil, SouthBoundPort: ponmap, NorthBoundPort: nil}
133 tests := []struct {
134 name string
135 fields fields
136 args args
137 }{
138 {
139 name: "PublishNNIMetrics-1",
140 fields: fields{
141 Device: dhandlerNNI,
142 NorthBoundPort: nnimap,
143 SouthBoundPort: nil,
144 },
145 args: args{
146 portType: "NNIStats",
147 val: nval,
148 portnum: 0,
149 context: ctx,
150 },
151 },
152 {
153 name: "PublishPONMetrics-1",
154 fields: fields{
155 Device: dhandlerPON,
156 NorthBoundPort: nil,
157 SouthBoundPort: ponmap,
158 },
159 args: args{
160 portType: "PONStats",
161 val: pval,
162 portnum: 0,
163 context: ctx,
164 },
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 }
175 StatMgr.publishMetrics(tt.args.portType, tt.args.val, tt.args.portnum, tt.args.context, "onu1")
176
177 })
178 }
179}
180
181func TestOpenOltStatisticsMgr_collectNNIMetrics(t *testing.T) {
182 type fields struct {
183 Device *DeviceHandler
184 NorthBoundPort map[uint32]*NniPort
185 SouthBoundPort map[uint32]*PonPort
186 }
187 type args struct {
188 nniID uint32
189 }
190 dhandler := newMockDeviceHandler()
191 pmconfig := make(map[string]*voltha.PmConfig)
192 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
193
194 var res map[string]float32
195 nnimap := map[uint32]*NniPort{}
196 nnimap[0] = &NniPort{Name: "olt"}
197 nnimap[1] = &NniPort{Name: "olt"}
198 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: nil, NorthBoundPort: nnimap}}
199 tests := []struct {
200 name string
201 fields fields
202 args args
203 want map[string]float32
204 }{
205 {"CollectNNIMetrics-1", fields{
206 Device: dh,
207 NorthBoundPort: nnimap,
208 SouthBoundPort: nil,
209 }, args{0}, res},
210 {"CollectNNIMetrics-2", fields{
211 Device: dh,
212 NorthBoundPort: nnimap,
213 SouthBoundPort: nil,
214 }, args{1}, res},
215 // TODO: Add test cases.
216 }
217 for _, tt := range tests {
218 t.Run(tt.name, func(t *testing.T) {
219 StatMgr := &OpenOltStatisticsMgr{
220 Device: tt.fields.Device,
221 NorthBoundPort: tt.fields.NorthBoundPort,
222 SouthBoundPort: tt.fields.SouthBoundPort,
223 }
224 got := StatMgr.collectNNIMetrics(tt.args.nniID)
225 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
226 t.Errorf("collectNNIMetrics() = %v, want %v", got, tt.want)
227 }
228 })
229 }
230}
231
232func TestOpenOltStatisticsMgr_collectPONMetrics(t *testing.T) {
233 type fields struct {
234 Device *DeviceHandler
235 NorthBoundPort map[uint32]*NniPort
236 SouthBoundPort map[uint32]*PonPort
237 }
238 type args struct {
239 pID uint32
240 }
241 dhandler := newMockDeviceHandler()
242 pmconfig := make(map[string]*voltha.PmConfig)
243 pmconfig["rx_bytes"] = &voltha.PmConfig{Name: "olt"}
244
245 var res map[string]float32
246 ponmap := map[uint32]*PonPort{}
247 ponmap[0] = &PonPort{DeviceID: "olt"}
248 ponmap[1] = &PonPort{DeviceID: "olt"}
249 dh := &DeviceHandler{portStats: &OpenOltStatisticsMgr{Device: dhandler, SouthBoundPort: ponmap, NorthBoundPort: nil}}
250
251 tests := []struct {
252 name string
253 fields fields
254 args args
255 want map[string]float32
256 }{
257 {"CollectPONMetrics-1", fields{
258 Device: dh,
259 NorthBoundPort: nil,
260 SouthBoundPort: ponmap,
261 }, args{0}, res},
262 // TODO: Add test cases.
263 }
264 for _, tt := range tests {
265 t.Run(tt.name, func(t *testing.T) {
266 StatMgr := &OpenOltStatisticsMgr{
267 Device: tt.fields.Device,
268 NorthBoundPort: tt.fields.NorthBoundPort,
269 SouthBoundPort: tt.fields.SouthBoundPort,
270 }
271 got := StatMgr.collectPONMetrics(tt.args.pID)
272 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
273 t.Errorf("collectPONMetrics() = %v, want %v", got, tt.want)
274 }
kdarapu891693b2019-09-16 12:33:49 +0530275 })
276 }
277}