blob: 940704a9b3594bc4992f52657f1d4a442ceb0056 [file] [log] [blame]
cbabua9e04cc2019-10-03 12:35:45 +05301/*
2 * Copyright 2018-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
cbabubef89432019-10-18 11:47:27 +020017/*
18This file contains unit test cases for functions in the file openolt.go.
19This file also implements the fields struct to mock the Openolt and few utility functions.
20*/
21
22//Package adaptercore provides the utility for olt devices, flows and statistics
cbabua9e04cc2019-10-03 12:35:45 +053023package adaptercore
24
25import (
26 "context"
27 "errors"
Esin Karamanccb714b2019-11-29 15:02:06 +000028 com "github.com/opencord/voltha-lib-go/v3/pkg/adapters/common"
29 fu "github.com/opencord/voltha-lib-go/v3/pkg/flows"
30 "github.com/opencord/voltha-lib-go/v3/pkg/kafka"
David K. Bainbridge794735f2020-02-11 21:01:37 -080031 "github.com/opencord/voltha-lib-go/v3/pkg/log"
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053032 "github.com/opencord/voltha-openolt-adapter/config"
Esin Karamanccb714b2019-11-29 15:02:06 +000033 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
34 "github.com/opencord/voltha-protos/v3/go/openflow_13"
35 ofp "github.com/opencord/voltha-protos/v3/go/openflow_13"
36 "github.com/opencord/voltha-protos/v3/go/voltha"
kesavand39e0aa32020-01-28 20:58:50 -050037 "reflect"
38 "sync"
39 "testing"
cbabua9e04cc2019-10-03 12:35:45 +053040)
41
cbabubef89432019-10-18 11:47:27 +020042// mocks the OpenOLT struct.
cbabua9e04cc2019-10-03 12:35:45 +053043type fields struct {
44 deviceHandlers map[string]*DeviceHandler
45 coreProxy *com.CoreProxy
46 adapterProxy *com.AdapterProxy
47 eventProxy *com.EventProxy
npujarec5762e2020-01-01 14:08:48 +053048 kafkaICProxy kafka.InterContainerProxy
cbabua9e04cc2019-10-03 12:35:45 +053049 numOnus int
50 KVStoreHost string
51 KVStorePort int
52 KVStoreType string
53 exitChannel chan int
54 lockDeviceHandlersMap sync.RWMutex
55 ctx context.Context
56}
57
cbabubef89432019-10-18 11:47:27 +020058// mockOlt mocks OpenOLT struct.
cbabua9e04cc2019-10-03 12:35:45 +053059func mockOlt() *fields {
cbabua9e04cc2019-10-03 12:35:45 +053060 dh := newMockDeviceHandler()
61 newOlt := &fields{}
62 newOlt.deviceHandlers = map[string]*DeviceHandler{}
63 newOlt.deviceHandlers[dh.device.Id] = dh
64 return newOlt
65}
66
cbabubef89432019-10-18 11:47:27 +020067// testOltObject maps fields type to OpenOLt type.
cbabua9e04cc2019-10-03 12:35:45 +053068func testOltObject(testOlt *fields) *OpenOLT {
69 return &OpenOLT{
70 deviceHandlers: testOlt.deviceHandlers,
71 coreProxy: testOlt.coreProxy,
72 adapterProxy: testOlt.adapterProxy,
73 eventProxy: testOlt.eventProxy,
74 kafkaICProxy: testOlt.kafkaICProxy,
75 numOnus: testOlt.numOnus,
76 KVStoreHost: testOlt.KVStoreHost,
77 KVStorePort: testOlt.KVStorePort,
78 KVStoreType: testOlt.KVStoreType,
79 exitChannel: testOlt.exitChannel,
80 }
81}
82
cbabubef89432019-10-18 11:47:27 +020083// mockDevice mocks Device.
cbabua9e04cc2019-10-03 12:35:45 +053084func mockDevice() *voltha.Device {
85 device := &voltha.Device{
86 Id: "olt",
87 Root: true,
88 ParentId: "logical_device",
89 Ports: []*voltha.Port{
90 {PortNo: 1, Label: "pon"},
91 {PortNo: 2, Label: "nni"},
92 },
93 ProxyAddress: &voltha.Device_ProxyAddress{
94 DeviceId: "olt",
95 DeviceType: "onu",
96 ChannelId: 1,
97 ChannelGroupId: 1,
98 },
99 ConnectStatus: 1,
100 }
101 return device
102}
103
104func TestNewOpenOLT(t *testing.T) {
105 tests := []struct {
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530106 name string
107 fields *fields
108 configFlags *config.AdapterFlags
109 want *OpenOLT
cbabua9e04cc2019-10-03 12:35:45 +0530110 }{
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530111 {"newopenolt-1", &fields{}, &config.AdapterFlags{OnuNumber: 1, KVStorePort: 1, KVStoreType: "consul", KVStoreHost: "1.1.1.1"},
cbabua9e04cc2019-10-03 12:35:45 +0530112 &OpenOLT{numOnus: 1, KVStorePort: 1, KVStoreType: "consul", KVStoreHost: "1.1.1.1"}},
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530113 {"newopenolt-2", &fields{}, &config.AdapterFlags{OnuNumber: 2, KVStorePort: 2, KVStoreType: "etcd", KVStoreHost: "2.2.2.2"},
cbabua9e04cc2019-10-03 12:35:45 +0530114 &OpenOLT{numOnus: 2, KVStorePort: 2, KVStoreType: "etcd", KVStoreHost: "2.2.2.2"}},
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530115 {"newopenolt-3", &fields{}, &config.AdapterFlags{OnuNumber: 3, KVStorePort: 3, KVStoreType: "consul", KVStoreHost: "3.3.3.3"},
cbabua9e04cc2019-10-03 12:35:45 +0530116 &OpenOLT{numOnus: 3, KVStorePort: 3, KVStoreType: "consul", KVStoreHost: "3.3.3.3"}},
117 }
118 for _, tt := range tests {
119 t.Run(tt.name, func(t *testing.T) {
120 if got := NewOpenOLT(tt.fields.ctx, tt.fields.kafkaICProxy, tt.fields.coreProxy, tt.fields.adapterProxy,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530121 tt.fields.eventProxy, tt.configFlags); reflect.TypeOf(got) != reflect.TypeOf(tt.want) && got != nil {
cbabua9e04cc2019-10-03 12:35:45 +0530122 t.Errorf("NewOpenOLT() error = %v, wantErr %v", got, tt.want)
123 }
124 })
125 }
126}
127
128func TestOpenOLT_Abandon_device(t *testing.T) {
129 type args struct {
130 device *voltha.Device
131 }
132 tests := []struct {
133 name string
134 fields *fields
135 args args
136 wantErr error
137 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800138 {"abandon_device-1", &fields{}, args{}, ErrNotImplemented},
139 {"abandon_device-2", &fields{}, args{}, ErrNotImplemented},
140 {"abandon_device-3", &fields{}, args{}, ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530141 }
142 for _, tt := range tests {
143 t.Run(tt.name, func(t *testing.T) {
144 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800145 if err := oo.Abandon_device(tt.args.device); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530146 t.Errorf("Abandon_device() error = %v, wantErr %v", err, tt.wantErr)
147 }
148 })
149 }
150}
151
152func TestOpenOLT_Activate_image_update(t *testing.T) {
153 type args struct {
154 device *voltha.Device
155 request *voltha.ImageDownload
156 }
157 tests := []struct {
158 name string
159 fields *fields
160 args args
161 want *voltha.ImageDownload
162 wantErr error
163 }{
164 {"activate_image_upate-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800165 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530166 {"activate_image_upate-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123CDE"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800167 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530168 {"activate_image_upate-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123EFG"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800169 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530170 }
171 for _, tt := range tests {
172 t.Run(tt.name, func(t *testing.T) {
173 oo := testOltObject(tt.fields)
174 got, err := oo.Activate_image_update(tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800175 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530176 t.Errorf("Activate_image_update() error = %v, wantErr %v", err, tt.wantErr)
177 }
178 })
179 }
180}
181
182func TestOpenOLT_Adapter_descriptor(t *testing.T) {
183 tests := []struct {
184 name string
185 fields *fields
186 wantErr error
187 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800188 {"adapter_descriptor-1", &fields{}, ErrNotImplemented},
189 {"adapter_descriptor-2", &fields{}, ErrNotImplemented},
190 {"adapter_descriptor-3", &fields{}, ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530191 }
192 for _, tt := range tests {
193 t.Run(tt.name, func(t *testing.T) {
194 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800195 if err := oo.Adapter_descriptor(); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530196 t.Errorf("Adapter_descriptor() error = %v, wantErr %v", err, tt.wantErr)
197 }
198 })
199 }
200}
201
202func TestOpenOLT_Adopt_device(t *testing.T) {
203 type args struct {
204 device *voltha.Device
205 }
206 var device = mockDevice()
kesavand39e0aa32020-01-28 20:58:50 -0500207 device.Id = "olt"
David K. Bainbridge794735f2020-02-11 21:01:37 -0800208 nilDevice := NewErrInvalidValue(log.Fields{"device": nil}, nil)
cbabua9e04cc2019-10-03 12:35:45 +0530209 tests := []struct {
210 name string
211 fields *fields
212 args args
213 wantErr error
214 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800215 {"adopt_device-1", mockOlt(), args{}, nilDevice},
216 {"adopt_device-2", mockOlt(), args{device}, nilDevice},
217 {"adopt_device-3", mockOlt(), args{mockDevice()}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530218 }
219 for _, tt := range tests {
220 t.Run(tt.name, func(t *testing.T) {
221 oo := testOltObject(tt.fields)
222 err := oo.Adopt_device(tt.args.device)
223 if (err != nil) && (reflect.TypeOf(err) !=
224 reflect.TypeOf(tt.wantErr)) && (tt.args.device == nil) {
225 t.Errorf("Adopt_device() error = %v, wantErr %v", err, tt.wantErr)
226 }
227 if err == nil {
228 t.Log("return'd nil")
229 }
230 })
231 }
232}
233
234func TestOpenOLT_Cancel_image_download(t *testing.T) {
235 type args struct {
236 device *voltha.Device
237 request *voltha.ImageDownload
238 }
239 tests := []struct {
240 name string
241 fields *fields
242 args args
243 want *voltha.ImageDownload
244 wantErr error
245 }{
246 {"cancel_image_download-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800247 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530248 {"cancel_image_download-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123IJK"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800249 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530250 {"cancel_image_download-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123KLM"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800251 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530252 }
253 for _, tt := range tests {
254 t.Run(tt.name, func(t *testing.T) {
255 oo := testOltObject(tt.fields)
256 got, err := oo.Cancel_image_download(tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800257 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530258 t.Errorf("Cancel_image_download() error = %v, wantErr %v", err, tt.wantErr)
259 }
260 })
261 }
262}
263
264func TestOpenOLT_Delete_device(t *testing.T) {
265 type args struct {
266 device *voltha.Device
267 }
268 tests := []struct {
269 name string
270 fields *fields
271 args args
272 wantErr error
273 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800274 {"delete_device-1", &fields{}, args{mockDevice()},
275 NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530276 }
277 for _, tt := range tests {
278 t.Run(tt.name, func(t *testing.T) {
279 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800280 if err := oo.Delete_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530281 t.Errorf("Delete_device() error = %v, wantErr %v", err, tt.wantErr)
282 }
283 })
284 }
285}
286
287func TestOpenOLT_Device_types(t *testing.T) {
288 tests := []struct {
289 name string
290 fields *fields
291 want *voltha.DeviceTypes
292 wantErr error
293 }{
294 {"device_types-1", &fields{}, &voltha.DeviceTypes{},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800295 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530296 {"device_types-2", &fields{}, &voltha.DeviceTypes{},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800297 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530298 {"device_types-3", &fields{}, &voltha.DeviceTypes{},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800299 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530300 }
301 for _, tt := range tests {
302 t.Run(tt.name, func(t *testing.T) {
303 oo := testOltObject(tt.fields)
304 got, err := oo.Device_types()
David K. Bainbridge794735f2020-02-11 21:01:37 -0800305 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530306 t.Errorf("Device_types() error = %v, wantErr %v", err, tt.wantErr)
307 }
308 })
309 }
310}
311
312func TestOpenOLT_Disable_device(t *testing.T) {
313 type args struct {
314 device *voltha.Device
315 }
316 tests := []struct {
317 name string
318 fields *fields
319 args args
320 wantErr error
321 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800322 {"disable_device-1", mockOlt(), args{mockDevice()}, nil},
323 {"disable_device-2", &fields{}, args{mockDevice()},
324 NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530325 }
326 for _, tt := range tests {
327 t.Run(tt.name, func(t *testing.T) {
328 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800329 if err := oo.Disable_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530330 t.Errorf("Disable_device() error = %v, wantErr %v", err, tt.wantErr)
331 }
332 })
333 }
334}
335
336func TestOpenOLT_Download_image(t *testing.T) {
337 type args struct {
338 device *voltha.Device
339 request *voltha.ImageDownload
340 }
341 tests := []struct {
342 name string
343 fields *fields
344 args args
345 want *voltha.ImageDownload
346 wantErr error
347 }{
348 {"download_image-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800349 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530350 {"download_image-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800351 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530352 {"download_image-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123RTY"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800353 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530354 }
355 for _, tt := range tests {
356 t.Run(tt.name, func(t *testing.T) {
357 oo := testOltObject(tt.fields)
358 got, err := oo.Download_image(tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800359 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530360 t.Errorf("Download_image() error = %v, wantErr %v", err, tt.wantErr)
361 }
362 })
363 }
364}
365
366func TestOpenOLT_Get_device_details(t *testing.T) {
367 type args struct {
368 device *voltha.Device
369 }
370 tests := []struct {
371 name string
372 fields *fields
373 args args
374 wantErr error
375 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800376 {"get_device_details-1", &fields{}, args{}, ErrNotImplemented},
377 {"get_device_details-2", &fields{}, args{}, ErrNotImplemented},
378 {"get_device_details-3", &fields{}, args{}, ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530379 }
380 for _, tt := range tests {
381 t.Run(tt.name, func(t *testing.T) {
382 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800383 if err := oo.Get_device_details(tt.args.device); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530384 t.Errorf("Get_device_details() error = %v, wantErr %v", err, tt.wantErr)
385 }
386 })
387 }
388}
389
390func TestOpenOLT_Get_image_download_status(t *testing.T) {
391 type args struct {
392 device *voltha.Device
393 request *voltha.ImageDownload
394 }
395 tests := []struct {
396 name string
397 fields *fields
398 args args
399 want *voltha.ImageDownload
400 wantErr error
401 }{
402 {"get_image_download_status-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800403 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530404 {"get_image_download_status-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800405 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530406 {"get_image_download_status-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123DFG"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800407 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530408 }
409 for _, tt := range tests {
410 t.Run(tt.name, func(t *testing.T) {
411 oo := testOltObject(tt.fields)
412 got, err := oo.Get_image_download_status(tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800413 if err != tt.wantErr && got == nil {
414 t.Errorf("Get_image_download_status() got = %v want = %v error = %v, wantErr %v",
415 got, tt.want, err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530416 }
417 })
418 }
419}
420
421func TestOpenOLT_Get_ofp_device_info(t *testing.T) {
422 type args struct {
423 device *voltha.Device
424 }
425 tests := []struct {
426 name string
427 fields *fields
428 args args
429 want *ic.SwitchCapability
430 wantErr error
431 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800432 {"get_ofp_device_info-1", mockOlt(), args{mockDevice()}, &ic.SwitchCapability{
433 Desc: &openflow_13.OfpDesc{
434 MfrDesc: "VOLTHA Project",
435 HwDesc: "open_pon",
436 SwDesc: "open_pon",
437 },
438 SwitchFeatures: &openflow_13.OfpSwitchFeatures{
439 NBuffers: uint32(256),
440 NTables: uint32(2),
441 Capabilities: uint32(15),
442 },
443 }, nil},
444 {"get_ofp_device_info-2", &fields{}, args{mockDevice()}, nil,
445 NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530446 }
447 for _, tt := range tests {
448 t.Run(tt.name, func(t *testing.T) {
449 oo := testOltObject(tt.fields)
450 got, err := oo.Get_ofp_device_info(tt.args.device)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800451 if !reflect.DeepEqual(err, tt.wantErr) || !reflect.DeepEqual(got, tt.want) {
452 t.Errorf("Get_ofp_device_info() got = %v want = %v error = %v, wantErr = %v",
453 got, tt.want, err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530454 }
455 })
456 }
457}
458
459func TestOpenOLT_Get_ofp_port_info(t *testing.T) {
460 type args struct {
461 device *voltha.Device
462 portNo int64
463 }
464 tests := []struct {
465 name string
466 fields *fields
467 args args
468 want *ic.PortCapability
469 wantErr error
470 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800471 {"get_ofp_port_info-1", mockOlt(), args{mockDevice(), 1}, &ic.PortCapability{
472 Port: &voltha.LogicalPort{
473 DeviceId: "olt",
474 DevicePortNo: uint32(1),
475 OfpPort: &openflow_13.OfpPort{
476 HwAddr: []uint32{1, 2, 3, 4, 5, 6},
477 State: uint32(4),
478 Curr: uint32(4128),
479 Advertised: uint32(4128),
480 Peer: uint32(4128),
481 CurrSpeed: uint32(32),
482 MaxSpeed: uint32(32),
483 },
484 },
485 }, nil},
486 {"get_ofp_port_info-2", &fields{}, args{mockDevice(), 1}, nil,
487 NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530488 }
489 for _, tt := range tests {
490 t.Run(tt.name, func(t *testing.T) {
491 oo := testOltObject(tt.fields)
492 got, err := oo.Get_ofp_port_info(tt.args.device, tt.args.portNo)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800493 if !reflect.DeepEqual(err, tt.wantErr) || !reflect.DeepEqual(got, tt.want) {
494 t.Errorf("Get_ofp_port_info() got = %v want = %v error = %v, wantErr = %v",
495 got, tt.want, err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530496 }
497 })
498 }
499}
500
501func TestOpenOLT_Health(t *testing.T) {
502 tests := []struct {
503 name string
504 fields *fields
505 want *voltha.HealthStatus
506 wantErr error
507 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800508 {"health-1", &fields{}, &voltha.HealthStatus{}, ErrNotImplemented},
509 {"health-2", &fields{}, &voltha.HealthStatus{}, ErrNotImplemented},
510 {"health-3", &fields{}, &voltha.HealthStatus{}, ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530511 }
512 for _, tt := range tests {
513 t.Run(tt.name, func(t *testing.T) {
514 oo := testOltObject(tt.fields)
515 got, err := oo.Health()
David K. Bainbridge794735f2020-02-11 21:01:37 -0800516 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530517 t.Errorf("Get_ofp_port_info() error = %v, wantErr %v", err, tt.wantErr)
518 }
519 })
520 }
521}
522
523func TestOpenOLT_Process_inter_adapter_message(t *testing.T) {
524 type args struct {
525 msg *ic.InterAdapterMessage
526 }
527 var message1 = args{
528 msg: &ic.InterAdapterMessage{
529 Header: &ic.InterAdapterHeader{
530 Id: "olt",
531 ProxyDeviceId: "",
532 ToDeviceId: "onu1",
533 },
534 },
535 }
536 var message2 = args{
537 msg: &ic.InterAdapterMessage{
538 Header: &ic.InterAdapterHeader{
539 Id: "olt",
540 ProxyDeviceId: "olt",
541 ToDeviceId: "olt",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800542 Type: ic.InterAdapterMessageType_OMCI_REQUEST,
543 },
544 },
545 }
546 var message3 = args{
547 msg: &ic.InterAdapterMessage{
548 Header: &ic.InterAdapterHeader{
549 Id: "olt",
550 ProxyDeviceId: "olt",
551 ToDeviceId: "olt",
552 Type: ic.InterAdapterMessageType_FLOW_REQUEST,
cbabua9e04cc2019-10-03 12:35:45 +0530553 },
554 },
555 }
556 tests := []struct {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800557 name string
558 fields *fields
559 args args
560 wantErrType reflect.Type
cbabua9e04cc2019-10-03 12:35:45 +0530561 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800562 {"process_inter_adaptor_messgae-1", mockOlt(), message1,
563 reflect.TypeOf(&ErrNotFound{})},
564 {"process_inter_adaptor_messgae-2", mockOlt(), message2,
565 reflect.TypeOf(errors.New("message is nil"))},
566 {"process_inter_adaptor_messgae-3", mockOlt(), message3,
567 reflect.TypeOf(&ErrInvalidValue{})},
cbabua9e04cc2019-10-03 12:35:45 +0530568 }
569 for _, tt := range tests {
570 t.Run(tt.name, func(t *testing.T) {
571 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800572 if err := oo.Process_inter_adapter_message(tt.args.msg); reflect.TypeOf(err) != tt.wantErrType {
573 t.Errorf("Process_inter_adapter_message() error = %v, wantErr %v",
574 reflect.TypeOf(err), tt.wantErrType)
cbabua9e04cc2019-10-03 12:35:45 +0530575 }
576 })
577 }
578}
579
580func TestOpenOLT_Reboot_device(t *testing.T) {
581 type args struct {
582 device *voltha.Device
583 }
584 tests := []struct {
585 name string
586 fields *fields
587 args args
588 wantErr error
589 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800590 {"reboot_device-1", mockOlt(), args{mockDevice()}, nil},
591 {"reboot_device-2", &fields{}, args{mockDevice()},
592 NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530593 }
594 for _, tt := range tests {
595 t.Run(tt.name, func(t *testing.T) {
596 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800597 if err := oo.Reboot_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530598 t.Errorf("Reboot_device() error = %v, wantErr %v", err, tt.wantErr)
599 }
600 })
601 }
602}
603
604func TestOpenOLT_Receive_packet_out(t *testing.T) {
605 acts := []*ofp.OfpAction{
606 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
607 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
608 fu.Output(1),
609 }
610 type args struct {
611 deviceID string
612 egressPortNo int
613 packet *openflow_13.OfpPacketOut
614 }
615 pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUx" +
616 "BgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+" +
617 "GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
618 tests := []struct {
619 name string
620 fields *fields
621 args args
622 wantErr error
623 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800624 {"receive_packet_out-1", mockOlt(), args{mockDevice().Id, 1, pktout}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530625 {"receive_packet_out-2", mockOlt(), args{"1234", 1, pktout},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800626 NewErrNotFound("device-handler", log.Fields{"device-id": "1234"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530627 }
628 for _, tt := range tests {
629 t.Run(tt.name, func(t *testing.T) {
630 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800631 if err := oo.Receive_packet_out(tt.args.deviceID, tt.args.egressPortNo, tt.args.packet); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530632 t.Errorf("Receive_packet_out() error = %v, wantErr %v", err, tt.wantErr)
633 }
634 })
635 }
636}
637
638func TestOpenOLT_Reconcile_device(t *testing.T) {
639 type args struct {
640 device *voltha.Device
641 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800642 expectedError := NewErrInvalidValue(log.Fields{"device": nil}, nil)
cbabua9e04cc2019-10-03 12:35:45 +0530643 tests := []struct {
644 name string
645 fields *fields
646 args args
647 wantErr error
648 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800649 {"reconcile_device-1", &fields{}, args{}, expectedError},
650 {"reconcile_device-2", &fields{}, args{}, expectedError},
651 {"reconcile_device-3", &fields{}, args{}, expectedError},
cbabua9e04cc2019-10-03 12:35:45 +0530652 }
653 for _, tt := range tests {
654 t.Run(tt.name, func(t *testing.T) {
655 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800656 if err := oo.Reconcile_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530657 t.Errorf("Reconcile_device() error = %v, wantErr %v", err, tt.wantErr)
658 }
659 })
660 }
661}
662
663func TestOpenOLT_Reenable_device(t *testing.T) {
664 type args struct {
665 device *voltha.Device
666 }
667 tests := []struct {
668 name string
669 fields *fields
670 args args
671 wantErr error
672 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800673 {"reenable_device-1", mockOlt(), args{mockDevice()}, nil},
674 {"reenable_device-2", &fields{}, args{mockDevice()},
675 NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530676 }
677 for _, tt := range tests {
678 t.Run(tt.name, func(t *testing.T) {
679 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800680 if err := oo.Reenable_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530681 t.Errorf("Reenable_device() error = %v, wantErr %v", err, tt.wantErr)
682 }
683 })
684 }
685}
686
687func TestOpenOLT_Revert_image_update(t *testing.T) {
688 type args struct {
689 device *voltha.Device
690 request *voltha.ImageDownload
691 }
692 tests := []struct {
693 name string
694 fields *fields
695 args args
696 want *voltha.ImageDownload
697 wantErr error
698 }{
699 {"revert_image_update-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800700 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530701 {"revert_image_update-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123TYU"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800702 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530703 {"revert_image_update-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123GTH"},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800704 ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530705 }
706 for _, tt := range tests {
707 t.Run(tt.name, func(t *testing.T) {
708 oo := testOltObject(tt.fields)
709 got, err := oo.Revert_image_update(tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800710 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530711 t.Log("error :", err)
712 }
713 })
714 }
715}
716
717func TestOpenOLT_Self_test_device(t *testing.T) {
718 type args struct {
719 device *voltha.Device
720 }
721 tests := []struct {
722 name string
723 fields *fields
724 args args
725 wantErr error
726 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800727 {"self_test_device-1", &fields{}, args{}, ErrNotImplemented},
728 {"self_test_device-2", &fields{}, args{}, ErrNotImplemented},
729 {"self_test_device-3", &fields{}, args{}, ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530730 }
731 for _, tt := range tests {
732 t.Run(tt.name, func(t *testing.T) {
733 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800734 if err := oo.Self_test_device(tt.args.device); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530735 t.Errorf("Self_test_device() error = %v, wantErr %v", err, tt.wantErr)
736 }
737 })
738 }
739}
740
741func TestOpenOLT_Start(t *testing.T) {
742 type args struct {
743 ctx context.Context
744 }
745 tests := []struct {
746 name string
747 fields *fields
748 args args
749 wantErr error
750 }{
751 {"start-1", &fields{}, args{}, errors.New("start error")},
752 }
753 for _, tt := range tests {
754 t.Run(tt.name, func(t *testing.T) {
755 oo := testOltObject(tt.fields)
756 if err := oo.Start(tt.args.ctx); err != nil {
757 t.Errorf("Start() error = %v, wantErr %v", err, tt.wantErr)
758 }
759 })
760 }
761}
762
763func TestOpenOLT_Stop(t *testing.T) {
764 type args struct {
765 ctx context.Context
766 }
767 tests := []struct {
768 name string
769 fields *fields
770 args args
771 wantErr error
772 }{
773 {"stop-1", &fields{exitChannel: make(chan int, 1)}, args{}, errors.New("stop error")},
774 }
775 for _, tt := range tests {
776 t.Run(tt.name, func(t *testing.T) {
777 oo := testOltObject(tt.fields)
778 oo.Start(tt.args.ctx)
779 if err := oo.Stop(tt.args.ctx); err != nil {
780 t.Errorf("Stop() error = %v, wantErr %v", err, tt.wantErr)
781 }
782 })
783 }
784}
785
Devmalya Pauldd23a992019-11-14 07:06:31 +0000786func TestOpenOLT_Suppress_event(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530787 type args struct {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000788 filter *voltha.EventFilter
cbabua9e04cc2019-10-03 12:35:45 +0530789 }
790 tests := []struct {
791 name string
792 fields *fields
793 args args
794 wantErr error
795 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800796 {"suppress_event-1", &fields{}, args{}, ErrNotImplemented},
797 {"suppress_event-2", &fields{}, args{}, ErrNotImplemented},
798 {"suppress_event-3", &fields{}, args{}, ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530799 }
800 for _, tt := range tests {
801 t.Run(tt.name, func(t *testing.T) {
802 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800803 if err := oo.Suppress_event(tt.args.filter); err != tt.wantErr {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000804 t.Errorf("Suppress_event() error = %v, wantErr %v", err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530805 }
806 })
807 }
808}
809
Devmalya Pauldd23a992019-11-14 07:06:31 +0000810func TestOpenOLT_Unsuppress_event(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530811 type args struct {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000812 filter *voltha.EventFilter
cbabua9e04cc2019-10-03 12:35:45 +0530813 }
814 tests := []struct {
815 name string
816 fields *fields
817 args args
818 wantErr error
819 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800820 {"unsupress_event-1", &fields{}, args{}, ErrNotImplemented},
821 {"unsupress_event-2", &fields{}, args{}, ErrNotImplemented},
822 {"unsupress_event-3", &fields{}, args{}, ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530823 }
824 for _, tt := range tests {
825 t.Run(tt.name, func(t *testing.T) {
826 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800827 if err := oo.Unsuppress_event(tt.args.filter); err != tt.wantErr {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000828 t.Errorf("Unsuppress_event() error = %v, wantErr %v", err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530829 }
830 })
831 }
832}
833
834func TestOpenOLT_Update_flows_bulk(t *testing.T) {
835 type args struct {
836 device *voltha.Device
837 flows *voltha.Flows
838 groups *voltha.FlowGroups
839 flowMetadata *voltha.FlowMetadata
840 }
841 tests := []struct {
842 name string
843 fields *fields
844 args args
845 wantErr error
846 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800847 {"update_flows_bulk-1", &fields{}, args{}, ErrNotImplemented},
848 {"update_flows_bulk-2", &fields{}, args{}, ErrNotImplemented},
849 {"update_flows_bulk-3", &fields{}, args{}, ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530850 }
851 for _, tt := range tests {
852 t.Run(tt.name, func(t *testing.T) {
853 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800854 if err := oo.Update_flows_bulk(tt.args.device, tt.args.flows, tt.args.groups, tt.args.flowMetadata); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530855 t.Errorf("Update_flows_bulk() error = %v, wantErr %v", err, tt.wantErr)
856 }
857 })
858 }
859}
860
861func TestOpenOLT_Update_flows_incrementally(t *testing.T) {
862 type args struct {
863 device *voltha.Device
864 flows *openflow_13.FlowChanges
865 groups *openflow_13.FlowGroupChanges
866 flowMetadata *voltha.FlowMetadata
867 }
868
869 tests := []struct {
870 name string
871 fields *fields
872 args args
873 wantErr error
874 }{
875 {"update_flows_incrementally-1", &fields{}, args{device: mockDevice()},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800876 NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
877 {"update_flows_incrementally-2", mockOlt(), args{device: mockDevice()}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530878 }
879 for _, tt := range tests {
880 t.Run(tt.name, func(t *testing.T) {
881 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800882 if err := oo.Update_flows_incrementally(tt.args.device, tt.args.flows, tt.args.groups, tt.args.flowMetadata); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530883 t.Errorf("Update_flows_incrementally() error = %v, wantErr %v", err, tt.wantErr)
884 }
885 })
886 }
887}
888
889func TestOpenOLT_Update_pm_config(t *testing.T) {
890 type args struct {
891 device *voltha.Device
892 pmConfigs *voltha.PmConfigs
893 }
894 tests := []struct {
895 name string
896 fields *fields
897 args args
898 wantErr error
899 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800900 {"update_pm_config-1", &fields{}, args{}, ErrNotImplemented},
901 {"update_pm_config-2", &fields{}, args{}, ErrNotImplemented},
902 {"update_pm_config-3", &fields{}, args{}, ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530903 }
904 for _, tt := range tests {
905 t.Run(tt.name, func(t *testing.T) {
906 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800907 if err := oo.Update_pm_config(tt.args.device, tt.args.pmConfigs); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530908 t.Errorf("Update_pm_config() error = %v, wantErr %v", err, tt.wantErr)
909 }
910
911 })
912 }
913}
914
915func TestOpenOLT_deleteDeviceHandlerToMap(t *testing.T) {
916 type args struct {
917 agent *DeviceHandler
918 }
919 tests := []struct {
920 name string
921 fields *fields
922 args args
923 }{
924 {"delete_device_handler_map-1", mockOlt(), args{newMockDeviceHandler()}},
925 }
926 for _, tt := range tests {
927 t.Run(tt.name, func(t *testing.T) {
928 oo := testOltObject(tt.fields)
929 oo.deleteDeviceHandlerToMap(tt.args.agent)
930 if len(oo.deviceHandlers) > 0 {
931 t.Errorf("delete device manager failed")
932 }
933 })
934 }
935}
kesavand39e0aa32020-01-28 20:58:50 -0500936
937func TestOpenOLT_Enable_port(t *testing.T) {
938 type args struct {
939 deviceID string
940 port *voltha.Port
941 }
942 tests := []struct {
943 name string
944 fields *fields
945 args args
946 wantErr bool
947 }{
948 // TODO: Add test cases.
949 {"Enable_port-1", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1}}, false},
950 {"Enable_port-2", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1}}, true},
951 }
952 for _, tt := range tests {
953 t.Run(tt.name, func(t *testing.T) {
954 oo := testOltObject(tt.fields)
955 if err := oo.Enable_port(tt.args.deviceID, tt.args.port); (err != nil) != tt.wantErr {
956 t.Errorf("OpenOLT.Enable_port() error = %v, wantErr %v", err, tt.wantErr)
957 }
958 })
959 }
960}
961
962func TestOpenOLT_Disable_port(t *testing.T) {
963 type args struct {
964 deviceID string
965 port *voltha.Port
966 }
967 tests := []struct {
968 name string
969 fields *fields
970 args args
971 wantErr bool
972 }{
973 // TODO: Add test cases.
974 {"Disable_port-1", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1}}, false},
975 {"Disable_port-2", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1}}, true},
976 }
977 for _, tt := range tests {
978 t.Run(tt.name, func(t *testing.T) {
979 oo := testOltObject(tt.fields)
980 if err := oo.Disable_port(tt.args.deviceID, tt.args.port); (err != nil) != tt.wantErr {
981 t.Errorf("OpenOLT.Disable_port() error = %v, wantErr %v", err, tt.wantErr)
982 }
983 })
984 }
985}