blob: f909128a1d697c8051be9c855c24a8231bb4b4c8 [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
Scott Bakerdbd960e2020-02-28 08:57:51 -080022//Package core provides the utility for olt devices, flows and statistics
23package core
cbabua9e04cc2019-10-03 12:35:45 +053024
25import (
26 "context"
27 "errors"
Kent Hagermanf1db18b2020-07-08 13:38:15 -040028 "reflect"
Kent Hagermanf1db18b2020-07-08 13:38:15 -040029 "testing"
30
khenaidoo106c61a2021-08-11 18:05:46 -040031 conf "github.com/opencord/voltha-lib-go/v7/pkg/config"
32 vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
serkant.uluderya7b8211e2021-02-24 16:39:18 +030033
khenaidoo106c61a2021-08-11 18:05:46 -040034 "github.com/opencord/voltha-lib-go/v7/pkg/events"
35 fu "github.com/opencord/voltha-lib-go/v7/pkg/flows"
36 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080037 "github.com/opencord/voltha-openolt-adapter/internal/pkg/config"
Thomas Lee S94109f12020-03-03 16:39:29 +053038 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
khenaidoodc2116e2021-10-19 17:33:19 -040039 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
khenaidoo106c61a2021-08-11 18:05:46 -040040 "github.com/opencord/voltha-protos/v5/go/openflow_13"
41 ofp "github.com/opencord/voltha-protos/v5/go/openflow_13"
42 "github.com/opencord/voltha-protos/v5/go/voltha"
cbabua9e04cc2019-10-03 12:35:45 +053043)
44
cbabubef89432019-10-18 11:47:27 +020045// mocks the OpenOLT struct.
cbabua9e04cc2019-10-03 12:35:45 +053046type fields struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -040047 deviceHandlers map[string]*DeviceHandler
khenaidoo106c61a2021-08-11 18:05:46 -040048 coreClient *vgrpc.Client
Himani Chawlacd407802020-12-10 12:08:59 +053049 eventProxy *events.EventProxy
Kent Hagermane6ff1012020-07-14 15:07:53 -040050 numOnus int
51 KVStoreAddress string
52 KVStoreType string
khenaidooefff76e2021-12-15 16:51:30 -050053 exitChannel chan struct{}
Kent Hagermane6ff1012020-07-14 15:07:53 -040054 ctx context.Context
cbabua9e04cc2019-10-03 12:35:45 +053055}
56
cbabubef89432019-10-18 11:47:27 +020057// mockOlt mocks OpenOLT struct.
cbabua9e04cc2019-10-03 12:35:45 +053058func mockOlt() *fields {
cbabua9e04cc2019-10-03 12:35:45 +053059 dh := newMockDeviceHandler()
60 newOlt := &fields{}
61 newOlt.deviceHandlers = map[string]*DeviceHandler{}
62 newOlt.deviceHandlers[dh.device.Id] = dh
63 return newOlt
64}
65
cbabubef89432019-10-18 11:47:27 +020066// testOltObject maps fields type to OpenOLt type.
cbabua9e04cc2019-10-03 12:35:45 +053067func testOltObject(testOlt *fields) *OpenOLT {
68 return &OpenOLT{
69 deviceHandlers: testOlt.deviceHandlers,
cbabua9e04cc2019-10-03 12:35:45 +053070 eventProxy: testOlt.eventProxy,
cbabua9e04cc2019-10-03 12:35:45 +053071 numOnus: testOlt.numOnus,
Neha Sharma3f221ae2020-04-29 19:02:12 +000072 KVStoreAddress: testOlt.KVStoreAddress,
cbabua9e04cc2019-10-03 12:35:45 +053073 KVStoreType: testOlt.KVStoreType,
74 exitChannel: testOlt.exitChannel,
75 }
76}
77
cbabubef89432019-10-18 11:47:27 +020078// mockDevice mocks Device.
cbabua9e04cc2019-10-03 12:35:45 +053079func mockDevice() *voltha.Device {
Kent Hagermanf1db18b2020-07-08 13:38:15 -040080 return &voltha.Device{
cbabua9e04cc2019-10-03 12:35:45 +053081 Id: "olt",
82 Root: true,
83 ParentId: "logical_device",
cbabua9e04cc2019-10-03 12:35:45 +053084 ProxyAddress: &voltha.Device_ProxyAddress{
85 DeviceId: "olt",
86 DeviceType: "onu",
87 ChannelId: 1,
88 ChannelGroupId: 1,
89 },
90 ConnectStatus: 1,
91 }
cbabua9e04cc2019-10-03 12:35:45 +053092}
93
94func TestNewOpenOLT(t *testing.T) {
95 tests := []struct {
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053096 name string
97 fields *fields
98 configFlags *config.AdapterFlags
Matteo Scandolodfa7a972020-11-06 13:03:40 -080099 cm *conf.ConfigManager
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530100 want *OpenOLT
cbabua9e04cc2019-10-03 12:35:45 +0530101 }{
serkant.uluderya7b8211e2021-02-24 16:39:18 +0300102 {"newopenolt-1", &fields{}, &config.AdapterFlags{OnuNumber: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "etcd"}, &conf.ConfigManager{},
103 &OpenOLT{numOnus: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "etcd"}},
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800104 {"newopenolt-2", &fields{}, &config.AdapterFlags{OnuNumber: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"}, &conf.ConfigManager{},
Neha Sharma3f221ae2020-04-29 19:02:12 +0000105 &OpenOLT{numOnus: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"}},
cbabua9e04cc2019-10-03 12:35:45 +0530106 }
107 for _, tt := range tests {
108 t.Run(tt.name, func(t *testing.T) {
khenaidoo106c61a2021-08-11 18:05:46 -0400109 if got := NewOpenOLT(tt.fields.ctx, tt.fields.coreClient,
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800110 tt.fields.eventProxy, tt.configFlags, tt.cm); reflect.TypeOf(got) != reflect.TypeOf(tt.want) && got != nil {
cbabua9e04cc2019-10-03 12:35:45 +0530111 t.Errorf("NewOpenOLT() error = %v, wantErr %v", got, tt.want)
112 }
113 })
114 }
115}
116
khenaidoo106c61a2021-08-11 18:05:46 -0400117func TestOpenOLT_ActivateImageUpdate(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530118 type args struct {
khenaidoodc2116e2021-10-19 17:33:19 -0400119 request *ca.ImageDownloadMessage
cbabua9e04cc2019-10-03 12:35:45 +0530120 }
121 tests := []struct {
122 name string
123 fields *fields
124 args args
125 want *voltha.ImageDownload
126 wantErr error
127 }{
128 {"activate_image_upate-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530129 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530130 {"activate_image_upate-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123CDE"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530131 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530132 {"activate_image_upate-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123EFG"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530133 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530134 }
135 for _, tt := range tests {
136 t.Run(tt.name, func(t *testing.T) {
137 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400138 got, err := oo.ActivateImageUpdate(context.Background(), tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800139 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530140 t.Errorf("Activate_image_update() error = %v, wantErr %v", err, tt.wantErr)
141 }
142 })
143 }
144}
145
khenaidoo106c61a2021-08-11 18:05:46 -0400146func TestOpenOLT_AdoptDevice(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530147 type args struct {
148 device *voltha.Device
149 }
150 var device = mockDevice()
kesavand39e0aa32020-01-28 20:58:50 -0500151 device.Id = "olt"
Thomas Lee S94109f12020-03-03 16:39:29 +0530152 nilDevice := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
cbabua9e04cc2019-10-03 12:35:45 +0530153 tests := []struct {
154 name string
155 fields *fields
156 args args
157 wantErr error
158 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800159 {"adopt_device-1", mockOlt(), args{}, nilDevice},
160 {"adopt_device-2", mockOlt(), args{device}, nilDevice},
161 {"adopt_device-3", mockOlt(), args{mockDevice()}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530162 }
163 for _, tt := range tests {
164 t.Run(tt.name, func(t *testing.T) {
165 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400166 _, err := oo.AdoptDevice(context.Background(), tt.args.device)
cbabua9e04cc2019-10-03 12:35:45 +0530167 if (err != nil) && (reflect.TypeOf(err) !=
168 reflect.TypeOf(tt.wantErr)) && (tt.args.device == nil) {
169 t.Errorf("Adopt_device() error = %v, wantErr %v", err, tt.wantErr)
170 }
171 if err == nil {
172 t.Log("return'd nil")
173 }
174 })
175 }
176}
177
khenaidoo106c61a2021-08-11 18:05:46 -0400178func TestOpenOLT_CancelImageDownload(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530179 type args struct {
khenaidoodc2116e2021-10-19 17:33:19 -0400180 request *ca.ImageDownloadMessage
cbabua9e04cc2019-10-03 12:35:45 +0530181 }
182 tests := []struct {
183 name string
184 fields *fields
185 args args
186 want *voltha.ImageDownload
187 wantErr error
188 }{
189 {"cancel_image_download-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530190 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530191 {"cancel_image_download-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123IJK"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530192 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530193 {"cancel_image_download-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123KLM"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530194 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530195 }
196 for _, tt := range tests {
197 t.Run(tt.name, func(t *testing.T) {
198 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400199 got, err := oo.CancelImageDownload(context.Background(), tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800200 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530201 t.Errorf("Cancel_image_download() error = %v, wantErr %v", err, tt.wantErr)
202 }
203 })
204 }
205}
206
khenaidoo106c61a2021-08-11 18:05:46 -0400207func TestOpenOLT_DeleteDevice(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530208 type args struct {
209 device *voltha.Device
210 }
211 tests := []struct {
212 name string
213 fields *fields
214 args args
215 wantErr error
216 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800217 {"delete_device-1", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530218 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530219 }
220 for _, tt := range tests {
221 t.Run(tt.name, func(t *testing.T) {
222 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400223 if _, err := oo.DeleteDevice(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530224 t.Errorf("Delete_device() error = %v, wantErr %v", err, tt.wantErr)
225 }
226 })
227 }
228}
229
khenaidoo106c61a2021-08-11 18:05:46 -0400230func TestOpenOLT_DisableDevice(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530231 type args struct {
232 device *voltha.Device
233 }
234 tests := []struct {
235 name string
236 fields *fields
237 args args
238 wantErr error
239 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800240 {"disable_device-1", mockOlt(), args{mockDevice()}, nil},
241 {"disable_device-2", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530242 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530243 }
244 for _, tt := range tests {
245 t.Run(tt.name, func(t *testing.T) {
246 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400247 if _, err := oo.DisableDevice(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530248 t.Errorf("Disable_device() error = %v, wantErr %v", err, tt.wantErr)
249 }
250 })
251 }
252}
253
khenaidoo106c61a2021-08-11 18:05:46 -0400254func TestOpenOLT_DownloadImage(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530255 type args struct {
khenaidoodc2116e2021-10-19 17:33:19 -0400256 request *ca.ImageDownloadMessage
cbabua9e04cc2019-10-03 12:35:45 +0530257 }
258 tests := []struct {
259 name string
260 fields *fields
261 args args
262 want *voltha.ImageDownload
263 wantErr error
264 }{
265 {"download_image-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530266 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530267 {"download_image-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530268 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530269 {"download_image-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123RTY"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530270 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530271 }
272 for _, tt := range tests {
273 t.Run(tt.name, func(t *testing.T) {
274 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400275 got, err := oo.DownloadImage(context.Background(), tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800276 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530277 t.Errorf("Download_image() error = %v, wantErr %v", err, tt.wantErr)
278 }
279 })
280 }
281}
282
khenaidoo106c61a2021-08-11 18:05:46 -0400283func TestOpenOLT_GetImageDownloadStatus(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530284 type args struct {
khenaidoodc2116e2021-10-19 17:33:19 -0400285 request *ca.ImageDownloadMessage
cbabua9e04cc2019-10-03 12:35:45 +0530286 }
287 tests := []struct {
288 name string
289 fields *fields
290 args args
291 want *voltha.ImageDownload
292 wantErr error
293 }{
294 {"get_image_download_status-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530295 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530296 {"get_image_download_status-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530297 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530298 {"get_image_download_status-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123DFG"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530299 olterrors.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)
khenaidoo106c61a2021-08-11 18:05:46 -0400304 got, err := oo.GetImageDownloadStatus(context.Background(), tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800305 if err != tt.wantErr && got == nil {
306 t.Errorf("Get_image_download_status() got = %v want = %v error = %v, wantErr %v",
307 got, tt.want, err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530308 }
309 })
310 }
311}
312
khenaidoo106c61a2021-08-11 18:05:46 -0400313func TestOpenOLT_GetOfpDeviceInfo(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530314 type args struct {
315 device *voltha.Device
316 }
317 tests := []struct {
318 name string
319 fields *fields
320 args args
khenaidoodc2116e2021-10-19 17:33:19 -0400321 want *ca.SwitchCapability
cbabua9e04cc2019-10-03 12:35:45 +0530322 wantErr error
323 }{
khenaidoodc2116e2021-10-19 17:33:19 -0400324 {"get_ofp_device_info-1", mockOlt(), args{mockDevice()}, &ca.SwitchCapability{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800325 Desc: &openflow_13.OfpDesc{
326 MfrDesc: "VOLTHA Project",
327 HwDesc: "open_pon",
328 SwDesc: "open_pon",
329 },
330 SwitchFeatures: &openflow_13.OfpSwitchFeatures{
331 NBuffers: uint32(256),
332 NTables: uint32(2),
333 Capabilities: uint32(15),
334 },
335 }, nil},
336 {"get_ofp_device_info-2", &fields{}, args{mockDevice()}, nil,
Thomas Lee S94109f12020-03-03 16:39:29 +0530337 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530338 }
339 for _, tt := range tests {
340 t.Run(tt.name, func(t *testing.T) {
341 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400342 got, err := oo.GetOfpDeviceInfo(context.Background(), tt.args.device)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800343 if !reflect.DeepEqual(err, tt.wantErr) || !reflect.DeepEqual(got, tt.want) {
344 t.Errorf("Get_ofp_device_info() got = %v want = %v error = %v, wantErr = %v",
345 got, tt.want, err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530346 }
347 })
348 }
349}
350
khenaidoo106c61a2021-08-11 18:05:46 -0400351func TestOpenOLT_RebootDevice(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530352 type args struct {
353 device *voltha.Device
354 }
355 tests := []struct {
356 name string
357 fields *fields
358 args args
359 wantErr error
360 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800361 {"reboot_device-1", mockOlt(), args{mockDevice()}, nil},
362 {"reboot_device-2", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530363 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530364 }
365 for _, tt := range tests {
366 t.Run(tt.name, func(t *testing.T) {
367 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400368 if _, err := oo.RebootDevice(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530369 t.Errorf("Reboot_device() error = %v, wantErr %v", err, tt.wantErr)
370 }
371 })
372 }
373}
374
khenaidoo106c61a2021-08-11 18:05:46 -0400375func TestOpenOLT_SendPacketOut(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530376 acts := []*ofp.OfpAction{
377 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
378 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
379 fu.Output(1),
380 }
381 type args struct {
382 deviceID string
383 egressPortNo int
384 packet *openflow_13.OfpPacketOut
385 }
386 pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUx" +
387 "BgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+" +
388 "GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
389 tests := []struct {
390 name string
391 fields *fields
392 args args
393 wantErr error
394 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800395 {"receive_packet_out-1", mockOlt(), args{mockDevice().Id, 1, pktout}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530396 {"receive_packet_out-2", mockOlt(), args{"1234", 1, pktout},
Thomas Lee S94109f12020-03-03 16:39:29 +0530397 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "1234"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530398 }
399 for _, tt := range tests {
400 t.Run(tt.name, func(t *testing.T) {
401 oo := testOltObject(tt.fields)
khenaidoodc2116e2021-10-19 17:33:19 -0400402 if _, err := oo.SendPacketOut(context.Background(), &ca.PacketOut{
khenaidoo106c61a2021-08-11 18:05:46 -0400403 DeviceId: tt.args.deviceID,
404 EgressPortNo: uint32(tt.args.egressPortNo),
405 Packet: tt.args.packet}); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530406 t.Errorf("Receive_packet_out() error = %v, wantErr %v", err, tt.wantErr)
407 }
408 })
409 }
410}
411
khenaidoo106c61a2021-08-11 18:05:46 -0400412func TestOpenOLT_ReconcileDevice(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530413 type args struct {
414 device *voltha.Device
415 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530416 expectedError := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
cbabua9e04cc2019-10-03 12:35:45 +0530417 tests := []struct {
418 name string
419 fields *fields
420 args args
421 wantErr error
422 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800423 {"reconcile_device-1", &fields{}, args{}, expectedError},
424 {"reconcile_device-2", &fields{}, args{}, expectedError},
425 {"reconcile_device-3", &fields{}, args{}, expectedError},
cbabua9e04cc2019-10-03 12:35:45 +0530426 }
427 for _, tt := range tests {
428 t.Run(tt.name, func(t *testing.T) {
429 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400430 if _, err := oo.ReconcileDevice(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530431 t.Errorf("Reconcile_device() error = %v, wantErr %v", err, tt.wantErr)
432 }
433 })
434 }
435}
436
khenaidoo106c61a2021-08-11 18:05:46 -0400437func TestOpenOLT_ReEnableDevice(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530438 type args struct {
439 device *voltha.Device
440 }
441 tests := []struct {
442 name string
443 fields *fields
444 args args
445 wantErr error
446 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800447 {"reenable_device-1", mockOlt(), args{mockDevice()}, nil},
448 {"reenable_device-2", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530449 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530450 }
451 for _, tt := range tests {
452 t.Run(tt.name, func(t *testing.T) {
453 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400454 if _, err := oo.ReEnableDevice(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530455 t.Errorf("Reenable_device() error = %v, wantErr %v", err, tt.wantErr)
456 }
457 })
458 }
459}
460
khenaidoo106c61a2021-08-11 18:05:46 -0400461func TestOpenOLT_RevertImageUpdate(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530462 type args struct {
khenaidoodc2116e2021-10-19 17:33:19 -0400463 request *ca.ImageDownloadMessage
cbabua9e04cc2019-10-03 12:35:45 +0530464 }
465 tests := []struct {
466 name string
467 fields *fields
468 args args
469 want *voltha.ImageDownload
470 wantErr error
471 }{
472 {"revert_image_update-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530473 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530474 {"revert_image_update-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123TYU"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530475 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530476 {"revert_image_update-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123GTH"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530477 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530478 }
479 for _, tt := range tests {
480 t.Run(tt.name, func(t *testing.T) {
481 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400482 got, err := oo.RevertImageUpdate(context.Background(), tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800483 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530484 t.Log("error :", err)
485 }
486 })
487 }
488}
489
khenaidoo106c61a2021-08-11 18:05:46 -0400490func TestOpenOLT_SelfTestDevice(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530491 type args struct {
492 device *voltha.Device
493 }
494 tests := []struct {
495 name string
496 fields *fields
497 args args
498 wantErr error
499 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530500 {"self_test_device-1", &fields{}, args{}, olterrors.ErrNotImplemented},
501 {"self_test_device-2", &fields{}, args{}, olterrors.ErrNotImplemented},
502 {"self_test_device-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530503 }
504 for _, tt := range tests {
505 t.Run(tt.name, func(t *testing.T) {
506 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400507 if _, err := oo.SelfTestDevice(context.Background(), tt.args.device); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530508 t.Errorf("Self_test_device() error = %v, wantErr %v", err, tt.wantErr)
509 }
510 })
511 }
512}
513
514func TestOpenOLT_Start(t *testing.T) {
515 type args struct {
516 ctx context.Context
517 }
518 tests := []struct {
519 name string
520 fields *fields
521 args args
522 wantErr error
523 }{
524 {"start-1", &fields{}, args{}, errors.New("start error")},
525 }
526 for _, tt := range tests {
527 t.Run(tt.name, func(t *testing.T) {
528 oo := testOltObject(tt.fields)
529 if err := oo.Start(tt.args.ctx); err != nil {
530 t.Errorf("Start() error = %v, wantErr %v", err, tt.wantErr)
531 }
532 })
533 }
534}
535
536func TestOpenOLT_Stop(t *testing.T) {
537 type args struct {
538 ctx context.Context
539 }
540 tests := []struct {
541 name string
542 fields *fields
543 args args
544 wantErr error
545 }{
khenaidooefff76e2021-12-15 16:51:30 -0500546 {"stop-1", &fields{exitChannel: make(chan struct{})}, args{}, errors.New("stop error")},
cbabua9e04cc2019-10-03 12:35:45 +0530547 }
548 for _, tt := range tests {
549 t.Run(tt.name, func(t *testing.T) {
550 oo := testOltObject(tt.fields)
Kent Hagermane6ff1012020-07-14 15:07:53 -0400551 if err := oo.Start(tt.args.ctx); err != nil {
552 t.Error(err)
553 }
cbabua9e04cc2019-10-03 12:35:45 +0530554 if err := oo.Stop(tt.args.ctx); err != nil {
555 t.Errorf("Stop() error = %v, wantErr %v", err, tt.wantErr)
556 }
557 })
558 }
559}
560
khenaidoo106c61a2021-08-11 18:05:46 -0400561func TestOpenOLT_SuppressEvent(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530562 type args struct {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000563 filter *voltha.EventFilter
cbabua9e04cc2019-10-03 12:35:45 +0530564 }
565 tests := []struct {
566 name string
567 fields *fields
568 args args
569 wantErr error
570 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530571 {"suppress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented},
572 {"suppress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented},
573 {"suppress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530574 }
575 for _, tt := range tests {
576 t.Run(tt.name, func(t *testing.T) {
577 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400578 if _, err := oo.SuppressEvent(context.Background(), tt.args.filter); err != tt.wantErr {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000579 t.Errorf("Suppress_event() error = %v, wantErr %v", err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530580 }
581 })
582 }
583}
584
khenaidoo106c61a2021-08-11 18:05:46 -0400585func TestOpenOLT_UnSuppressEvent(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530586 type args struct {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000587 filter *voltha.EventFilter
cbabua9e04cc2019-10-03 12:35:45 +0530588 }
589 tests := []struct {
590 name string
591 fields *fields
592 args args
593 wantErr error
594 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530595 {"unsupress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented},
596 {"unsupress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented},
597 {"unsupress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530598 }
599 for _, tt := range tests {
600 t.Run(tt.name, func(t *testing.T) {
601 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400602 if _, err := oo.UnSuppressEvent(context.Background(), tt.args.filter); err != tt.wantErr {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000603 t.Errorf("Unsuppress_event() error = %v, wantErr %v", err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530604 }
605 })
606 }
607}
608
khenaidoo106c61a2021-08-11 18:05:46 -0400609func TestOpenOLT_UpdateFlowsBulk(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530610 type args struct {
611 device *voltha.Device
khenaidoodc2116e2021-10-19 17:33:19 -0400612 flows *ofp.Flows
613 groups *ofp.FlowGroups
614 flowMetadata *ofp.FlowMetadata
cbabua9e04cc2019-10-03 12:35:45 +0530615 }
616 tests := []struct {
617 name string
618 fields *fields
619 args args
620 wantErr error
621 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530622 {"update_flows_bulk-1", &fields{}, args{}, olterrors.ErrNotImplemented},
623 {"update_flows_bulk-2", &fields{}, args{}, olterrors.ErrNotImplemented},
624 {"update_flows_bulk-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530625 }
626 for _, tt := range tests {
627 t.Run(tt.name, func(t *testing.T) {
628 oo := testOltObject(tt.fields)
khenaidoodc2116e2021-10-19 17:33:19 -0400629 if _, err := oo.UpdateFlowsBulk(context.Background(), &ca.BulkFlows{
khenaidoo106c61a2021-08-11 18:05:46 -0400630 Device: tt.args.device,
631 Flows: tt.args.flows,
632 Groups: tt.args.groups,
633 FlowMetadata: tt.args.flowMetadata,
634 }); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530635 t.Errorf("Update_flows_bulk() error = %v, wantErr %v", err, tt.wantErr)
636 }
637 })
638 }
639}
640
khenaidoo106c61a2021-08-11 18:05:46 -0400641func TestOpenOLT_UpdateFlowsIncrementally(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530642 type args struct {
643 device *voltha.Device
644 flows *openflow_13.FlowChanges
645 groups *openflow_13.FlowGroupChanges
khenaidoodc2116e2021-10-19 17:33:19 -0400646 flowMetadata *ofp.FlowMetadata
cbabua9e04cc2019-10-03 12:35:45 +0530647 }
648
649 tests := []struct {
650 name string
651 fields *fields
652 args args
653 wantErr error
654 }{
655 {"update_flows_incrementally-1", &fields{}, args{device: mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530656 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800657 {"update_flows_incrementally-2", mockOlt(), args{device: mockDevice()}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530658 }
659 for _, tt := range tests {
660 t.Run(tt.name, func(t *testing.T) {
661 oo := testOltObject(tt.fields)
khenaidoodc2116e2021-10-19 17:33:19 -0400662 if _, err := oo.UpdateFlowsIncrementally(context.Background(), &ca.IncrementalFlows{
khenaidoo106c61a2021-08-11 18:05:46 -0400663 Device: tt.args.device,
664 Flows: tt.args.flows,
665 Groups: tt.args.groups,
666 FlowMetadata: tt.args.flowMetadata}); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530667 t.Errorf("Update_flows_incrementally() error = %v, wantErr %v", err, tt.wantErr)
668 }
669 })
670 }
671}
672
khenaidoo106c61a2021-08-11 18:05:46 -0400673func TestOpenOLT_UpdatePmConfig(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530674 type args struct {
675 device *voltha.Device
676 pmConfigs *voltha.PmConfigs
677 }
678 tests := []struct {
679 name string
680 fields *fields
681 args args
682 wantErr error
683 }{
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000684 {"update_pm_config-1", mockOlt(), args{device: mockDevice(), pmConfigs: &voltha.PmConfigs{DefaultFreq: 150, Grouped: false, FreqOverride: false}}, nil},
685 {"update_pm_config-2", &fields{}, args{device: mockDevice(), pmConfigs: &voltha.PmConfigs{DefaultFreq: 150, Grouped: false, FreqOverride: false}}, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530686 }
687 for _, tt := range tests {
688 t.Run(tt.name, func(t *testing.T) {
689 oo := testOltObject(tt.fields)
khenaidoodc2116e2021-10-19 17:33:19 -0400690 if _, err := oo.UpdatePmConfig(context.Background(), &ca.PmConfigsInfo{DeviceId: tt.args.device.Id, PmConfigs: tt.args.pmConfigs}); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530691 t.Errorf("Update_pm_config() error = %v, wantErr %v", err, tt.wantErr)
692 }
693
694 })
695 }
696}
697
698func TestOpenOLT_deleteDeviceHandlerToMap(t *testing.T) {
699 type args struct {
700 agent *DeviceHandler
701 }
702 tests := []struct {
703 name string
704 fields *fields
705 args args
706 }{
707 {"delete_device_handler_map-1", mockOlt(), args{newMockDeviceHandler()}},
708 }
709 for _, tt := range tests {
710 t.Run(tt.name, func(t *testing.T) {
711 oo := testOltObject(tt.fields)
712 oo.deleteDeviceHandlerToMap(tt.args.agent)
713 if len(oo.deviceHandlers) > 0 {
714 t.Errorf("delete device manager failed")
715 }
716 })
717 }
718}
kesavand39e0aa32020-01-28 20:58:50 -0500719
khenaidoo106c61a2021-08-11 18:05:46 -0400720func TestOpenOLT_EnablePort(t *testing.T) {
kesavand39e0aa32020-01-28 20:58:50 -0500721 type args struct {
khenaidoo106c61a2021-08-11 18:05:46 -0400722 port *voltha.Port
kesavand39e0aa32020-01-28 20:58:50 -0500723 }
724 tests := []struct {
725 name string
726 fields *fields
727 args args
728 wantErr bool
729 }{
730 // TODO: Add test cases.
khenaidoo106c61a2021-08-11 18:05:46 -0400731 {"Enable_port-1", mockOlt(), args{port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1, DeviceId: "olt"}}, false},
732 {"Enable_port-2", mockOlt(), args{port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1, DeviceId: "olt"}}, true},
kesavand39e0aa32020-01-28 20:58:50 -0500733 }
734 for _, tt := range tests {
735 t.Run(tt.name, func(t *testing.T) {
736 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400737 if _, err := oo.EnablePort(context.Background(), tt.args.port); (err != nil) != tt.wantErr {
kesavand39e0aa32020-01-28 20:58:50 -0500738 t.Errorf("OpenOLT.Enable_port() error = %v, wantErr %v", err, tt.wantErr)
739 }
740 })
741 }
742}
743
khenaidoo106c61a2021-08-11 18:05:46 -0400744func TestOpenOLT_DisablePort(t *testing.T) {
kesavand39e0aa32020-01-28 20:58:50 -0500745 type args struct {
khenaidoo106c61a2021-08-11 18:05:46 -0400746 port *voltha.Port
kesavand39e0aa32020-01-28 20:58:50 -0500747 }
748 tests := []struct {
749 name string
750 fields *fields
751 args args
752 wantErr bool
753 }{
754 // TODO: Add test cases.
khenaidoo106c61a2021-08-11 18:05:46 -0400755 {"Disable_port-1", mockOlt(), args{port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1, DeviceId: "olt"}}, false},
756 {"Disable_port-2", mockOlt(), args{port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1, DeviceId: "olt"}}, true},
kesavand39e0aa32020-01-28 20:58:50 -0500757 }
758 for _, tt := range tests {
759 t.Run(tt.name, func(t *testing.T) {
760 oo := testOltObject(tt.fields)
khenaidoo106c61a2021-08-11 18:05:46 -0400761 if _, err := oo.DisablePort(context.Background(), tt.args.port); (err != nil) != tt.wantErr {
kesavand39e0aa32020-01-28 20:58:50 -0500762 t.Errorf("OpenOLT.Disable_port() error = %v, wantErr %v", err, tt.wantErr)
763 }
764 })
765 }
766}