blob: 0f07347c603739c58bbad409ca101d2ba3dfc11e [file] [log] [blame]
vinokumaf7605fc2023-06-02 18:08:01 +05301/*
2* Copyright 2022-present Open Networking Foundation
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14 */
15
16package application
17
18import (
19 "context"
20 "encoding/json"
21 "errors"
vinokuma02fbfd02023-07-05 15:23:33 +053022 "net"
23 "reflect"
vinokumaf7605fc2023-06-02 18:08:01 +053024 "sync"
25 "testing"
26 "voltha-go-controller/internal/pkg/controller"
27 cntlr "voltha-go-controller/internal/pkg/controller"
28 "voltha-go-controller/internal/pkg/of"
29 "voltha-go-controller/internal/pkg/util"
30 "voltha-go-controller/internal/test/mocks"
31
32 "github.com/golang/mock/gomock"
33 "github.com/google/gopacket/layers"
34 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
35 "github.com/stretchr/testify/assert"
36 "go.uber.org/atomic"
37)
38
39var test_device = "test_device"
40var voltPort = &VoltPort{
41 Name: "test_name",
42 Device: test_device,
43}
44var voltDevice = &VoltDevice{
vinokuma04dc9f82023-07-31 15:47:49 +053045 Name: "test_name",
46 State: controller.DeviceStateUP,
47 FlowAddEventMap: util.NewConcurrentMap(),
48 FlowDelEventMap: util.NewConcurrentMap(),
49 SerialNum: "test_serial_number",
50 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
51 NniPort: "16777216",
vinokumaf7605fc2023-06-02 18:08:01 +053052}
53
54var voltMeter = &VoltMeter{
vinokuma02fbfd02023-07-05 15:23:33 +053055 Name: "test_volt_meter",
56 Version: "test_version",
57 AssociatedServices: 3,
vinokumaf7605fc2023-06-02 18:08:01 +053058}
59
60var voltVnet = &VoltVnet{
61 Version: "test_version",
62 VnetConfig: VnetConfig{
63 Name: "test_name",
64 },
65}
66
67var voltPortVnet1 = []*VoltPortVnet{
68 {
69 Device: "4096-4096-4096",
70 SVlan: of.VlanAny,
71 CVlan: of.VlanAny,
72 UniVlan: of.VlanAny,
73 IgmpEnabled: true,
74 servicesCount: &atomic.Uint64{},
75 },
76}
77
78var voltDevice1 = &VoltDevice{
79 State: cntlr.DeviceStateDOWN,
80}
81
vinokuma02fbfd02023-07-05 15:23:33 +053082var voltDevice2 = &VoltDevice{
83 Name: "test_name",
84 State: controller.DeviceStateUP,
85 FlowAddEventMap: util.NewConcurrentMap(),
86 FlowDelEventMap: util.NewConcurrentMap(),
87 SerialNum: "test_serial_number",
88 MigratingServices: util.NewConcurrentMap(),
89}
90
91var voltService2 = &VoltService{
92 Version: "test_version",
93 VoltServiceCfg: VoltServiceCfg{
94 VnetID: "test_vnet_id",
95 Port: "test_port",
96 SVlan: of.VlanAny,
97 CVlan: of.VlanAny,
98 UniVlan: of.VlanAny,
99 },
100}
101
vinokumaf7605fc2023-06-02 18:08:01 +0530102var GetDeviceFromPort_error = "GetDeviceFromPort_error"
103
104func TestVoltApplication_RestoreSvcsFromDb(t *testing.T) {
105 type args struct {
106 cntx context.Context
107 }
108 tests := []struct {
109 name string
110 args args
111 }{
112 {
113 name: "VoltApplication_RestoreSvcsFromDb",
114 args: args{
115 cntx: context.Background(),
116 },
117 },
118 {
119 name: "invalid_value_type",
120 args: args{
121 cntx: context.Background(),
122 },
123 },
124 {
125 name: "unmarshal_error",
126 args: args{
127 cntx: context.Background(),
128 },
129 },
130 }
131 for _, tt := range tests {
132 t.Run(tt.name, func(t *testing.T) {
vinokuma02fbfd02023-07-05 15:23:33 +0530133 voltService4 := &VoltService{
vinokumaf7605fc2023-06-02 18:08:01 +0530134 VoltServiceOper: VoltServiceOper{
135 Device: "SDX6320031",
136 ForceDelete: true,
137 DeleteInProgress: true,
138 },
139 VoltServiceCfg: VoltServiceCfg{
140 Name: "test_service_name",
141 },
142 }
143 serviceToDelete := map[string]bool{}
vinokuma02fbfd02023-07-05 15:23:33 +0530144 serviceToDelete[voltService4.VoltServiceCfg.Name] = true
vinokumaf7605fc2023-06-02 18:08:01 +0530145 va := &VoltApplication{
146 ServicesToDelete: serviceToDelete,
147 }
148 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
149 db = dbintf
150 switch tt.name {
151 case "VoltApplication_RestoreSvcsFromDb":
152
vinokuma02fbfd02023-07-05 15:23:33 +0530153 b, err := json.Marshal(voltService4)
vinokumaf7605fc2023-06-02 18:08:01 +0530154 if err != nil {
155 panic(err)
156 }
157 kvPair := map[string]*kvstore.KVPair{}
158 kvPair["key"] = &kvstore.KVPair{
159 Key: "test_key",
160 Value: b,
161 Version: 1,
162 }
163 dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1)
164 va.RestoreSvcsFromDb(tt.args.cntx)
165 case "invalid_value_type":
166 kvPair := map[string]*kvstore.KVPair{}
167 kvPair["key"] = &kvstore.KVPair{
168 Key: "test_key",
vinokuma703a70b2023-07-17 10:06:43 +0530169 Value: invalid_value,
vinokumaf7605fc2023-06-02 18:08:01 +0530170 Version: 1,
171 }
172 dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1)
173 va.RestoreSvcsFromDb(tt.args.cntx)
174 case "unmarshal_error":
175 b, err := json.Marshal("test")
176 if err != nil {
177 panic(err)
178 }
179 kvPair := map[string]*kvstore.KVPair{}
180 kvPair["key"] = &kvstore.KVPair{
181 Key: "test_key",
182 Value: b,
183 Version: 1,
184 }
185 dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1)
186 va.RestoreSvcsFromDb(tt.args.cntx)
187 }
188 })
189 }
190}
191
192func TestVoltService_FlowRemoveFailure(t *testing.T) {
193 type args struct {
194 cntx context.Context
195 cookie string
196 errorCode uint32
197 errReason string
198 }
199 tests := []struct {
200 name string
201 args args
202 }{
203 {
204 name: "VoltService_FlowRemoveFailure",
205 args: args{
206 cntx: context.Background(),
207 cookie: "test_cookie",
208 errorCode: 200,
209 errReason: "test_reason",
210 },
211 },
212 {
213 name: "cookie_not_found",
214 args: args{
215 cntx: context.Background(),
216 cookie: "test_cookie",
217 errorCode: 200,
218 errReason: "test_reason",
219 },
220 },
221 }
222 for _, tt := range tests {
223 t.Run(tt.name, func(t *testing.T) {
224 switch tt.name {
225 case "VoltService_FlowRemoveFailure":
226 associatedFlows := map[string]bool{}
227 associatedFlows["test_cookie"] = true
228 vs := &VoltService{
229 VoltServiceOper: VoltServiceOper{
230 AssociatedFlows: associatedFlows,
231 },
232 }
233 vs.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.errorCode, tt.args.errReason)
234 case "cookie_not_found":
235 associatedFlows := map[string]bool{}
236 associatedFlows["cookie"] = true
237 vs := &VoltService{
238 VoltServiceOper: VoltServiceOper{
239 AssociatedFlows: associatedFlows,
240 },
241 }
242 vs.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.errorCode, tt.args.errReason)
243 }
244 })
245 }
246}
247
248func TestVoltApplication_GetServiceNameFromCookie(t *testing.T) {
249 type args struct {
250 cookie uint64
251 portName string
252 pbit uint8
253 device string
254 tableMetadata uint64
255 }
256 tests := []struct {
257 name string
258 args args
259 }{
260 {
261 name: "VoltApplication_GetServiceNameFromCookie",
262 args: args{
263 cookie: uint64(1),
264 portName: "test_port_name",
265 device: "SDX6320031",
266 pbit: 2,
267 tableMetadata: uint64(2),
268 },
269 },
270 }
271 voltDev := &VoltDevice{
272 Name: "SDX6320031",
273 SerialNum: "SDX6320031",
274 NniDhcpTrapVid: 123,
275 }
276 for _, tt := range tests {
277 t.Run(tt.name, func(t *testing.T) {
278 ga := GetApplication()
279 ga.DevicesDisc.Store("SDX6320031", voltDev)
280 voltPortVnets := make([]*VoltPortVnet, 0)
281 voltPortVnet := &VoltPortVnet{
282 Device: test_device,
283 VlanControl: ONUCVlanOLTSVlan,
284 }
285 voltPortVnets = append(voltPortVnets, voltPortVnet)
286 ga.VnetsByPort.Store("test_port_name", voltPortVnets)
287 got := ga.GetServiceNameFromCookie(tt.args.cookie, tt.args.portName, tt.args.pbit, tt.args.device, tt.args.tableMetadata)
288 assert.Nil(t, got)
289 })
290 }
291}
292
293func TestVoltService_SvcUpInd(t *testing.T) {
294 type args struct {
295 cntx context.Context
296 }
297 tests := []struct {
298 name string
299 args args
300 }{
301 {
302 name: "VoltService_SvcUpInd",
303 args: args{
304 cntx: context.Background(),
305 },
306 },
307 }
308 for _, tt := range tests {
309 t.Run(tt.name, func(t *testing.T) {
310 vs := &VoltService{
311 VoltServiceOper: VoltServiceOper{
312 PendingFlows: make(map[string]bool),
313 },
314 VoltServiceCfg: VoltServiceCfg{
315 SVlanTpid: layers.EthernetTypeDot1Q,
316 MacAddr: layers.EthernetBroadcast,
317 },
318 }
319 vs.Port = test_device
320 vs.Device = "device"
321 ga := GetApplication()
322 _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
323 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
324 db = dbintf
325 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
326 ga.PortsDisc.Store(test_device, voltPort)
327 ga.DevicesDisc.Store(test_device, voltDevice)
328 vs.SvcUpInd(tt.args.cntx)
329 })
330 }
331}
332
333func TestVoltService_SvcDownInd(t *testing.T) {
334 type args struct {
335 cntx context.Context
336 }
337 tests := []struct {
338 name string
339 args args
340 }{
341 {
342 name: "VoltService_SvcDownInd",
343 args: args{
344 cntx: context.Background(),
345 },
346 },
347 }
348 for _, tt := range tests {
349 t.Run(tt.name, func(t *testing.T) {
350 vs := &VoltService{
351 VoltServiceOper: VoltServiceOper{
352 UsHSIAFlowsApplied: true,
353 DsHSIAFlowsApplied: true,
354 },
355 VoltServiceCfg: VoltServiceCfg{
356 SVlanTpid: layers.EthernetTypeQinQ,
357 MacAddr: layers.EthernetBroadcast,
358 },
359 }
360 vs.Port = test_device
361 vs.Device = "device"
362 ga := GetApplication()
363 _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
364 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
365 db = dbintf
366 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
367 ga.PortsDisc.Store(test_device, voltPort)
368 ga.DevicesDisc.Store(test_device, voltDevice)
369 vs.SvcDownInd(tt.args.cntx)
370 })
371 }
372}
373
374func TestVoltApplication_AddService(t *testing.T) {
375 type args struct {
376 cntx context.Context
377 cfg VoltServiceCfg
378 oper *VoltServiceOper
379 }
380 tests := []struct {
381 name string
382 args args
383 }{
384 {
385 name: "VoltApplication_AddService",
386 args: args{
387 cntx: context.Background(),
388 cfg: VoltServiceCfg{
389 Name: "test_name",
390 Port: "test_port",
391 DsMeterProfile: "4096-4096-4096",
392 UsMeterProfile: "4096-4096-4096",
393 SVlan: of.VlanAny,
394 CVlan: of.VlanAny,
395 UniVlan: of.VlanAny,
396 MacLearning: Learn,
397 IsActivated: true,
398 },
399 oper: &VoltServiceOper{
400 Device: "4096-4096-4096",
401 },
402 },
403 },
404 }
405 for _, tt := range tests {
406 t.Run(tt.name, func(t *testing.T) {
407 va := &VoltApplication{
408 MeterMgr: MeterMgr{
409 Meters: sync.Map{},
410 },
411 VnetsByPort: sync.Map{},
412 VnetsByTag: sync.Map{},
413 }
414 va.MeterMgr.Meters.Store("4096-4096-4096", voltMeter)
415 va.VnetsByTag.Store("4096-4096-4096", voltVnet)
416 voltPortVnet1[0].SVlan = of.VlanAny
417 voltPortVnet1[0].CVlan = of.VlanAny
418 voltPortVnet1[0].UniVlan = of.VlanAny
419 voltPortVnet1[0].servicesCount = atomic.NewUint64(uint64(56))
420 voltPortVnet1[0].MacAddr = layers.EthernetBroadcast
421 voltPortVnet1[0].Port = "test_port"
422 va.VnetsByPort.Store("test_port", voltPortVnet1)
423 ga := GetApplication()
424 voltPort1 := &VoltPort{
425 Name: "test_name",
426 Device: test_device,
427 }
428 deviceConfig := &DeviceConfig{
429 SerialNumber: "test_serial_number",
430 }
431 ga.PortsDisc.Store("test_port", voltPort1)
432 ga.DevicesDisc.Store(test_device, voltDevice)
433 ga.DevicesConfig.Store("test_serial_number", deviceConfig)
434 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
435 db = dbintf
436 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
437 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
438 err := va.AddService(tt.args.cntx, tt.args.cfg, tt.args.oper)
439 assert.Nil(t, err)
440 })
441 }
442}
443
444func TestVoltApplication_DelService(t *testing.T) {
445 type args struct {
446 cntx context.Context
447 name string
448 forceDelete bool
449 newSvc *VoltServiceCfg
450 serviceMigration bool
451 }
452 tests := []struct {
453 name string
454 args args
455 }{
456 {
457 name: "VoltApplication_DelService",
458 args: args{
459 cntx: context.Background(),
460 name: "test_name",
461 forceDelete: true,
462 newSvc: &VoltServiceCfg{
463 Name: "vs_cfg_name",
464 Port: "test_port",
465 },
466 serviceMigration: true,
467 },
468 },
vinokuma02fbfd02023-07-05 15:23:33 +0530469 {
470 name: "GetMeterByID_not_nil",
471 args: args{
472 cntx: context.Background(),
473 name: "test_name",
474 forceDelete: true,
475 newSvc: &VoltServiceCfg{
476 Name: "vs_cfg_name",
477 Port: "test_port",
478 },
479 serviceMigration: true,
480 },
481 },
vinokumaf7605fc2023-06-02 18:08:01 +0530482 }
483 for _, tt := range tests {
484 t.Run(tt.name, func(t *testing.T) {
485 va := &VoltApplication{
486 ServiceByName: sync.Map{},
487 VnetsByPort: sync.Map{},
488 }
vinokuma02fbfd02023-07-05 15:23:33 +0530489 voltService3 := &VoltService{
vinokumaf7605fc2023-06-02 18:08:01 +0530490 Version: "test_version",
491 VoltServiceCfg: VoltServiceCfg{
492 Port: "4096-4096-4096",
493 SVlan: of.VlanAny,
494 CVlan: of.VlanAny,
495 UniVlan: of.VlanAny,
496 },
497 }
vinokuma02fbfd02023-07-05 15:23:33 +0530498 switch tt.name {
499 case "VoltApplication_DelService":
500 va.ServiceByName.Store(tt.args.name, voltService3)
501 va.VnetsByPort.Store("4096-4096-4096", voltPortVnet1)
502 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
503 db = dbintf
504 dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes()
505 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
506 va.DelService(tt.args.cntx, tt.args.name, tt.args.forceDelete, tt.args.newSvc, tt.args.serviceMigration)
507 case "GetMeterByID_not_nil":
508 va.ServiceByName.Store(tt.args.name, voltService3)
509 va.VnetsByPort.Store("4096-4096-4096", voltPortVnet1)
510 voltService3.AggDsMeterID = uint32(1)
511 voltService3.DsMeterID = uint32(1)
512 voltService3.UsMeterID = uint32(2)
513 va.MeterMgr.MetersByID.Store(voltService3.AggDsMeterID, voltMeter)
514 va.MeterMgr.MetersByID.Store(voltService3.DsMeterID, voltMeter)
515 va.MeterMgr.MetersByID.Store(voltService3.UsMeterID, voltMeter)
516 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
517 db = dbintf
518 dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes()
519 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
520 va.DelService(tt.args.cntx, tt.args.name, tt.args.forceDelete, tt.args.newSvc, tt.args.serviceMigration)
521 }
vinokumaf7605fc2023-06-02 18:08:01 +0530522 })
523 }
524}
525
526func TestVoltService_FlowInstallSuccess(t *testing.T) {
527 type args struct {
528 cntx context.Context
529 cookie string
530 bwAvailInfo of.BwAvailDetails
531 }
532 tests := []struct {
533 name string
534 args args
535 }{
536 {
537 name: "VoltService_FlowInstallSuccess",
538 args: args{
539 cntx: context.Background(),
540 cookie: "test_cookie",
541 bwAvailInfo: of.BwAvailDetails{
542 PrevBw: "test_prev_BW",
543 PresentBw: "test_present_BW",
544 },
545 },
546 },
547 }
548 for _, tt := range tests {
549 t.Run(tt.name, func(t *testing.T) {
550 pendingFlows := map[string]bool{}
551 pendingFlows["test_cookie"] = true
552 associatedFlows := map[string]bool{}
553 associatedFlows["test_cookie"] = true
554 vs := &VoltService{
555 VoltServiceOper: VoltServiceOper{
556 PendingFlows: pendingFlows,
557 AssociatedFlows: associatedFlows,
558 DsHSIAFlowsApplied: true,
559 },
560 VoltServiceCfg: VoltServiceCfg{
561 Port: "test_port",
562 },
563 }
564 ga := GetApplication()
565 ga.PortsDisc.Store("test_port", voltPort)
566 ga.DevicesDisc.Store(test_device, voltDevice)
567 vs.FlowInstallSuccess(tt.args.cntx, tt.args.cookie, tt.args.bwAvailInfo)
568 })
569 }
570}
571
572func TestVoltService_AddMeterToDevice(t *testing.T) {
573 type args struct {
574 cntx context.Context
575 }
576 tests := []struct {
577 name string
578 args args
579 wantErr bool
580 }{
581 {
582 name: "VoltService_AddMeterToDevice",
583 args: args{
584 cntx: context.Background(),
585 },
586 },
587 {
588 name: GetDeviceFromPort_error,
589 args: args{
590 cntx: context.Background(),
591 },
592 },
593 {
594 name: "DeviceState_down",
595 args: args{
596 cntx: context.Background(),
597 },
598 },
599 }
600 for _, tt := range tests {
601 t.Run(tt.name, func(t *testing.T) {
602 switch tt.name {
603 case "VoltService_AddMeterToDevice":
604 vs := &VoltService{
605 VoltServiceOper: VoltServiceOper{
606 DeleteInProgress: true,
607 },
608 VoltServiceCfg: VoltServiceCfg{
609 Port: "test_port",
610 },
611 }
612 ga := GetApplication()
613 ga.PortsDisc.Store("test_port", voltPort)
614 ga.DevicesDisc.Store(test_device, voltDevice)
615 err := vs.AddMeterToDevice(tt.args.cntx)
616 assert.Nil(t, err)
617 case GetDeviceFromPort_error:
618 vs := &VoltService{
619 VoltServiceOper: VoltServiceOper{
620 DeleteInProgress: true,
621 },
622 VoltServiceCfg: VoltServiceCfg{
623 Port: "",
624 },
625 }
626 err := vs.AddMeterToDevice(tt.args.cntx)
627 assert.NotNil(t, err)
628 case "DeviceState_down":
629 vs := &VoltService{
630 VoltServiceOper: VoltServiceOper{
631 DeleteInProgress: true,
632 },
633 VoltServiceCfg: VoltServiceCfg{
634 Port: "test_port",
635 },
636 }
637 ga := GetApplication()
638 ga.PortsDisc.Store("test_port", voltPort)
639 ga.DevicesDisc.Store(test_device, voltDevice1)
640 err := vs.AddMeterToDevice(tt.args.cntx)
641 assert.Nil(t, err)
642 }
643 })
644 }
645}
646
647func TestVoltService_AddUsHsiaFlows(t *testing.T) {
648 type args struct {
649 cntx context.Context
650 }
651 tests := []struct {
652 name string
653 args args
654 wantErr bool
655 }{
656 {
657 name: "DeleteInProgress_true",
658 args: args{
659 cntx: context.Background(),
660 },
661 },
662 {
663 name: "GetDeviceFromPort_error",
664 args: args{
665 cntx: context.Background(),
666 },
667 },
668 {
669 name: "DeviceState_down",
670 args: args{
671 cntx: context.Background(),
672 },
673 },
674 }
675 for _, tt := range tests {
676 t.Run(tt.name, func(t *testing.T) {
677 switch tt.name {
678 case "DeleteInProgress_true":
679 vs := &VoltService{
680 VoltServiceOper: VoltServiceOper{
681 DeleteInProgress: true,
682 },
683 }
684 err := vs.AddUsHsiaFlows(tt.args.cntx)
685 assert.Nil(t, err)
686 case "GetDeviceFromPort_error":
687 vs := &VoltService{
688 VoltServiceOper: VoltServiceOper{
689 DeleteInProgress: false,
690 },
691 }
692 err := vs.AddUsHsiaFlows(tt.args.cntx)
693 assert.NotNil(t, err)
694 case "DeviceState_down":
695 vs := &VoltService{
696 VoltServiceOper: VoltServiceOper{
697 DeleteInProgress: false,
698 },
699 VoltServiceCfg: VoltServiceCfg{
700 Port: "test_port",
701 },
702 }
703 ga := GetApplication()
704 ga.PortsDisc.Store("test_port", voltPort)
705 ga.DevicesDisc.Store(test_device, voltDevice1)
706 err := vs.AddUsHsiaFlows(tt.args.cntx)
707 assert.Nil(t, err)
708 }
709 })
710 }
711}
712
713func TestVoltService_AddHsiaFlows(t *testing.T) {
714 type args struct {
715 cntx context.Context
716 }
717 tests := []struct {
718 name string
719 args args
720 }{
721 {
722 name: "AddUsHsiaFlows_error",
723 args: args{
724 cntx: context.Background(),
725 },
726 },
727 }
728 for _, tt := range tests {
729 t.Run(tt.name, func(t *testing.T) {
730 vs := &VoltService{
731 VoltServiceCfg: VoltServiceCfg{
732 Port: "test_port",
733 VlanControl: 5,
734 },
735 }
736 ga := GetApplication()
737 ga.PortsDisc.Store("test_port", voltPort)
738 ga.DevicesDisc.Store(test_device, voltDevice)
739 vs.AddHsiaFlows(tt.args.cntx)
740 })
741 }
742}
743
744func TestVoltService_ForceWriteToDb(t *testing.T) {
745 type args struct {
746 cntx context.Context
747 }
748 tests := []struct {
749 name string
750 args args
751 }{
752 {
753 name: "PutService_error",
754 args: args{
755 cntx: context.Background(),
756 },
757 },
758 }
759 for _, tt := range tests {
760 t.Run(tt.name, func(t *testing.T) {
761 switch tt.name {
762 case "PutService_error":
763 vs := &VoltService{}
764 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
765 db = dbintf
766 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("error")).AnyTimes()
767 vs.ForceWriteToDb(tt.args.cntx)
768 }
769 })
770 }
771}
772
773func TestVoltService_isDataRateAttrPresent(t *testing.T) {
774 tests := []struct {
775 name string
776 want bool
777 }{
778 {
779 name: "VoltService_isDataRateAttrPresent",
780 },
781 }
782 for _, tt := range tests {
783 t.Run(tt.name, func(t *testing.T) {
784 vs := &VoltService{}
785 if got := vs.isDataRateAttrPresent(); got != tt.want {
786 t.Errorf("VoltService.isDataRateAttrPresent() = %v, want %v", got, tt.want)
787 }
788 })
789 }
790}
791
792func TestVoltService_GetServicePbit(t *testing.T) {
793 tests := []struct {
794 name string
795 want int
796 }{
797 {
798 name: "VoltService_GetServicePbit",
799 want: -1,
800 },
801 {
802 name: "!IsPbitExist",
803 want: 8,
804 },
805 }
806 for _, tt := range tests {
807 t.Run(tt.name, func(t *testing.T) {
808 switch tt.name {
809 case "VoltService_GetServicePbit":
810 vs := &VoltService{
811 VoltServiceCfg: VoltServiceCfg{
812 Pbits: []of.PbitType{of.PbitMatchAll},
813 },
814 }
815 if got := vs.GetServicePbit(); got != tt.want {
816 t.Errorf("VoltService.GetServicePbit() = %v, want %v", got, tt.want)
817 }
818 case "!IsPbitExist":
819 vs := &VoltService{}
820 if got := vs.GetServicePbit(); got != tt.want {
821 t.Errorf("VoltService.GetServicePbit() = %v, want %v", got, tt.want)
822 }
823 }
824 })
825 }
826}
827
828func TestVoltApplication_DeactivateService(t *testing.T) {
829 type args struct {
830 cntx context.Context
831 deviceID string
832 portNo string
833 sVlan of.VlanType
834 cVlan of.VlanType
835 tpID uint16
836 }
837 tests := []struct {
838 name string
839 args args
840 wantErr bool
841 }{
842 {
843 name: "VoltApplication_DeactivateService",
844 args: args{
845 cntx: context.Background(),
846 deviceID: "test_device_id",
847 portNo: "test_port",
848 sVlan: of.VlanNone,
849 cVlan: of.VlanAny,
850 tpID: AnyVlan,
851 },
852 },
853 {
854 name: "VoltPortVnet_nil",
855 args: args{
856 cntx: context.Background(),
857 deviceID: "test_device_id",
858 portNo: "test_port",
859 sVlan: of.VlanNone,
860 cVlan: of.VlanAny,
861 tpID: AnyVlan,
862 },
863 },
864 {
865 name: "sVlan != of.VlanNone",
866 args: args{
867 cntx: context.Background(),
868 deviceID: "test_device_id",
869 portNo: "test_port",
870 sVlan: of.VlanAny,
871 cVlan: of.VlanAny,
872 tpID: AnyVlan,
873 },
874 },
875 {
876 name: GetDeviceFromPort_error,
877 args: args{
878 cntx: context.Background(),
879 deviceID: "test_device_id",
880 portNo: "test_port",
881 sVlan: of.VlanNone,
882 cVlan: of.VlanAny,
883 tpID: AnyVlan,
884 },
885 },
886 }
887 for _, tt := range tests {
888 t.Run(tt.name, func(t *testing.T) {
889 va := &VoltApplication{
890 ServiceByName: sync.Map{},
891 VnetsByPort: sync.Map{},
892 DevicesDisc: sync.Map{},
893 PortsDisc: sync.Map{},
894 }
895 voltServiceTest := &VoltService{
896 VoltServiceOper: VoltServiceOper{
897 Device: test_device,
898 },
899 Version: "test_version",
900 VoltServiceCfg: VoltServiceCfg{
901 Port: "test_port",
902 Name: "test_name",
903 IsActivated: true,
904 CVlan: of.VlanAny,
905 SVlan: of.VlanAny,
906 UniVlan: of.VlanAny,
907 },
908 }
909 switch tt.name {
910 case "VoltApplication_DeactivateService":
911 va.ServiceByName.Store("test_name", voltServiceTest)
912 va.PortsDisc.Store("test_port", voltPort)
913 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
914 db = dbintf
915 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
916 va.DevicesDisc.Store(test_device, voltDevice)
917 voltDevice.Ports.Store("test_port", voltPort)
918 va.VnetsByPort.Store("test_port", voltPortVnet1)
919 voltPortVnet1[0].servicesCount.Store(uint64(1))
920 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
921 if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
922 t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
923 }
924 case "VoltPortVnet_nil":
925 va.ServiceByName.Store("test_name", voltServiceTest)
926 va.PortsDisc.Store("test_port", voltPort)
927 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
928 db = dbintf
929 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
930 va.DevicesDisc.Store(test_device, voltDevice)
931 voltDevice.Ports.Store("test_port", voltPort)
932 if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
933 t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
934 }
935 case "sVlan != of.VlanNone":
936 va.ServiceByName.Store("test_name", voltServiceTest)
Hitesh Chhabra7d249a02023-07-04 21:33:49 +0530937 err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID)
Sridhar Ravindraf8251e72023-09-06 17:09:30 +0530938 assert.Nil(t, err)
vinokumaf7605fc2023-06-02 18:08:01 +0530939 case GetDeviceFromPort_error:
940 va.ServiceByName.Store("test_name", voltServiceTest)
941 if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
942 t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
943 }
944 }
945 })
946 }
947}
948
949func TestVoltApplication_ActivateService(t *testing.T) {
950 type args struct {
951 cntx context.Context
952 deviceID string
953 portNo string
954 sVlan of.VlanType
955 cVlan of.VlanType
956 tpID uint16
957 }
958 tests := []struct {
959 name string
960 args args
961 wantErr bool
962 }{
963 {
964 name: "VoltApplication_ActivateService",
965 args: args{
966 cntx: context.Background(),
vinokuma02fbfd02023-07-05 15:23:33 +0530967 deviceID: DeviceAny,
vinokumaf7605fc2023-06-02 18:08:01 +0530968 portNo: "test_port",
969 sVlan: of.VlanNone,
970 cVlan: of.VlanAny,
971 tpID: AnyVlan,
972 },
973 },
974 {
975 name: "VoltPortVnet_nil",
976 args: args{
977 cntx: context.Background(),
978 deviceID: "test_name",
979 portNo: "test_port",
980 sVlan: of.VlanNone,
981 cVlan: of.VlanAny,
982 tpID: AnyVlan,
983 },
984 },
985 {
986 name: GetDeviceFromPort_error,
987 args: args{
988 cntx: context.Background(),
989 deviceID: "test_name",
990 portNo: "test_port",
991 sVlan: of.VlanNone,
992 cVlan: of.VlanAny,
993 tpID: AnyVlan,
994 },
995 },
vinokuma02fbfd02023-07-05 15:23:33 +0530996 {
997 name: "deviceID != device.Name",
998 args: args{
999 cntx: context.Background(),
1000 deviceID: "test_name1",
1001 portNo: "test_port",
1002 sVlan: of.VlanNone,
1003 cVlan: of.VlanAny,
1004 tpID: AnyVlan,
1005 },
1006 },
1007 {
1008 name: "sVlan != of.VlanNone && sVlan != vs.SVlan",
1009 args: args{
1010 cntx: context.Background(),
1011 deviceID: "test_name",
1012 portNo: "test_port",
1013 sVlan: 1,
1014 cVlan: of.VlanAny,
1015 tpID: AnyVlan,
1016 },
1017 },
vinokumaf7605fc2023-06-02 18:08:01 +05301018 }
1019 for _, tt := range tests {
1020 t.Run(tt.name, func(t *testing.T) {
1021 va := &VoltApplication{
1022 DevicesDisc: sync.Map{},
1023 }
1024 var voltPortTest = &VoltPort{
1025 Name: "test_name",
1026 State: PortStateUp,
1027 }
1028 voltServiceTest := &VoltService{
1029 VoltServiceOper: VoltServiceOper{
1030 Device: test_device,
1031 },
1032 Version: "test_version",
1033 VoltServiceCfg: VoltServiceCfg{
1034 Port: "test_port",
1035 Name: "test_name",
1036 IsActivated: false,
1037 CVlan: of.VlanAny,
1038 SVlan: of.VlanAny,
1039 UniVlan: of.VlanAny,
1040 },
1041 }
1042 switch tt.name {
1043 case "VoltApplication_ActivateService":
1044 voltPortTest.Device = test_device
1045 va.PortsDisc.Store("test_port", voltPortTest)
1046 va.DevicesDisc.Store(test_device, voltDevice)
1047 va.ServiceByName.Store("test_name", voltServiceTest)
1048 va.VnetsByPort.Store("test_port", voltPortVnet1)
1049 voltDevice.Ports.Store("test_port", voltPortTest)
1050 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1051 db = dbintf
1052 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1053 if err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
1054 t.Errorf("VoltApplication.ActivateService() error = %v, wantErr %v", err, tt.wantErr)
1055 }
1056 case "VoltPortVnet_nil":
1057 voltPortTest.Device = test_device
1058 va.ServiceByName.Store("test_name", voltServiceTest)
1059 va.PortsDisc.Store("test_port", voltPortTest)
1060 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1061 db = dbintf
1062 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1063 va.DevicesDisc.Store(test_device, voltDevice)
1064 voltDevice.Ports.Store("test_port", voltPortTest)
1065 if err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
1066 t.Errorf("VoltApplication.ActivateService() error = %v, wantErr %v", err, tt.wantErr)
1067 }
1068 case GetDeviceFromPort_error:
1069 err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID)
Sridhar Ravindraf8251e72023-09-06 17:09:30 +05301070 assert.Nil(t, err)
vinokuma02fbfd02023-07-05 15:23:33 +05301071 case "deviceID != device.Name":
1072 var voltPortTest1 = &VoltPort{
1073 Name: "test_name",
1074 State: PortStateUp,
1075 Device: test_device,
1076 }
1077 var voltDevice_test = &VoltDevice{
1078 Name: "",
1079 State: controller.DeviceStateUP,
1080 FlowAddEventMap: util.NewConcurrentMap(),
1081 FlowDelEventMap: util.NewConcurrentMap(),
1082 SerialNum: "test_serial_number",
1083 }
1084 va.PortsDisc.Store("test_port", voltPortTest1)
1085 va.DevicesDisc.Store(test_device, voltDevice_test)
1086 err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID)
1087 assert.NotNil(t, err)
1088 case "sVlan != of.VlanNone && sVlan != vs.SVlan":
1089 voltPortTest.Device = test_device
1090 va.PortsDisc.Store("test_port", voltPortTest)
1091 va.DevicesDisc.Store(test_device, voltDevice)
1092 va.ServiceByName.Store("test_name", voltServiceTest)
Hitesh Chhabra7d249a02023-07-04 21:33:49 +05301093 err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID)
Sridhar Ravindraf8251e72023-09-06 17:09:30 +05301094 assert.Nil(t, err)
vinokumaf7605fc2023-06-02 18:08:01 +05301095 }
1096 })
1097 }
1098}
1099
1100func TestVoltApplication_GetProgrammedSubscribers(t *testing.T) {
1101 type args struct {
1102 cntx context.Context
1103 deviceID string
1104 portNo string
1105 }
1106 tests := []struct {
1107 name string
1108 args args
1109 want []*VoltService
1110 wantErr bool
1111 }{
1112 {
1113 name: "VoltApplication_GetProgrammedSubscribers",
1114 args: args{
1115 cntx: context.Background(),
1116 deviceID: test_device,
1117 portNo: "test_port",
1118 },
1119 },
1120 {
1121 name: "portNo_nil",
1122 args: args{
1123 cntx: context.Background(),
1124 deviceID: test_device,
1125 },
1126 },
1127 {
1128 name: "deviceID_nil",
1129 args: args{
1130 cntx: context.Background(),
1131 },
1132 },
1133 }
1134 for _, tt := range tests {
1135 t.Run(tt.name, func(t *testing.T) {
1136 va := &VoltApplication{
1137 vendorID: "test_vendor",
1138 }
1139 voltServiceTest := &VoltService{
1140 VoltServiceOper: VoltServiceOper{
1141 Device: test_device,
1142 },
1143 Version: "test_version",
1144 VoltServiceCfg: VoltServiceCfg{
1145 Port: "test_port",
1146 Name: "test_name",
1147 IsActivated: false,
1148 CVlan: of.VlanAny,
1149 SVlan: of.VlanAny,
1150 UniVlan: of.VlanAny,
1151 },
1152 }
1153 switch tt.name {
1154 case "VoltApplication_GetProgrammedSubscribers":
1155 va.ServiceByName.Store("test_name", voltServiceTest)
1156 got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo)
1157 assert.NotNil(t, got)
1158 assert.Nil(t, err)
1159 case "portNo_nil":
1160 va.ServiceByName.Store("test_name", voltServiceTest)
1161 got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo)
1162 assert.NotNil(t, got)
1163 assert.Nil(t, err)
1164 case "deviceID_nil":
1165 va.ServiceByName.Store("test_name", voltServiceTest)
1166 got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo)
1167 assert.NotNil(t, got)
1168 assert.Nil(t, err)
1169 }
1170 })
1171 }
1172}
1173
1174func TestVoltService_JSONMarshal(t *testing.T) {
1175 tests := []struct {
1176 name string
1177 }{
1178 {
1179 name: "VoltService_JSONMarshal",
1180 },
1181 }
1182 for _, tt := range tests {
1183 t.Run(tt.name, func(t *testing.T) {
1184 vs := &VoltService{
1185 VoltServiceOper: VoltServiceOper{
1186 Device: test_device,
1187 },
1188 Version: "test_version",
1189 VoltServiceCfg: VoltServiceCfg{
1190 Name: "test_name",
1191 },
1192 }
1193 got, err := vs.JSONMarshal()
1194 assert.NotNil(t, got)
1195 assert.Nil(t, err)
1196 })
1197 }
1198}
1199
1200func TestVoltService_triggerServiceInProgressInd(t *testing.T) {
1201 tests := []struct {
1202 name string
1203 }{
1204 {
1205 name: "VoltService_triggerServiceInProgressInd",
1206 },
1207 }
1208 for _, tt := range tests {
1209 t.Run(tt.name, func(t *testing.T) {
1210 vs := &VoltService{
1211 Version: "test_version",
1212 }
1213 vs.triggerServiceInProgressInd()
1214 })
1215 }
1216}
1217
1218func TestVoltService_TriggerAssociatedFlowDelete(t *testing.T) {
1219 type args struct {
1220 cntx context.Context
1221 }
1222 tests := []struct {
1223 name string
1224 args args
1225 want bool
1226 }{
1227 {
1228 name: "VoltService_TriggerAssociatedFlowDelete",
1229 args: args{
1230 cntx: context.Background(),
1231 },
1232 want: true,
1233 },
1234 {
1235 name: "cookieList_nil",
1236 args: args{
1237 cntx: context.Background(),
1238 },
1239 want: false,
1240 },
1241 }
1242 associatedFlows := map[string]bool{}
1243 associatedFlows["5765317"] = true
1244 for _, tt := range tests {
1245 t.Run(tt.name, func(t *testing.T) {
1246 switch tt.name {
1247 case "VoltService_TriggerAssociatedFlowDelete":
1248 vs := &VoltService{
1249 VoltServiceOper: VoltServiceOper{
1250 UsHSIAFlowsApplied: true,
1251 DsHSIAFlowsApplied: true,
1252 AssociatedFlows: associatedFlows,
1253 Device: test_device,
1254 },
1255 }
1256 ga := GetApplication()
1257 ga.DevicesDisc.Store(test_device, voltDevice)
1258 if got := vs.TriggerAssociatedFlowDelete(tt.args.cntx); got != tt.want {
1259 t.Errorf("VoltService.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want)
1260 }
1261 case "cookieList_nil":
1262 vs := &VoltService{
1263 VoltServiceOper: VoltServiceOper{
1264 UsHSIAFlowsApplied: true,
1265 DsHSIAFlowsApplied: true,
1266 Device: test_device,
1267 },
1268 }
1269 ga := GetApplication()
1270 ga.DevicesDisc.Store(test_device, voltDevice)
1271 if got := vs.TriggerAssociatedFlowDelete(tt.args.cntx); got != tt.want {
1272 t.Errorf("VoltService.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want)
1273 }
1274 }
1275 })
1276 }
1277}
1278
1279func TestVoltApplication_DeepEqualServicecfg(t *testing.T) {
1280 type args struct {
1281 evs *VoltServiceCfg
1282 nvs *VoltServiceCfg
1283 }
1284 a := map[int]int{}
1285 a[0] = 0
1286 tests := []struct {
1287 name string
1288 args args
1289 want bool
1290 }{
1291 {
1292 name: "VoltApplication_DeepEqualServicecfg",
1293 args: args{
1294 evs: &VoltServiceCfg{
1295 Port: "test_port",
1296 },
1297 nvs: &VoltServiceCfg{
1298 Port: "test_port",
1299 },
1300 },
1301 want: true,
1302 },
1303 {
1304 name: "nvs.Name != evs.Name",
1305 args: args{
1306 evs: &VoltServiceCfg{
1307 Name: "test_name",
1308 },
1309 nvs: &VoltServiceCfg{
1310 Port: "test_port",
1311 },
1312 },
1313 want: false,
1314 },
1315 {
1316 name: "nvs.UniVlan != evs.UniVlan",
1317 args: args{
1318 evs: &VoltServiceCfg{
1319 UniVlan: of.VlanAny,
1320 },
1321 nvs: &VoltServiceCfg{
1322 Port: "test_port",
1323 },
1324 },
1325 want: false,
1326 },
1327 {
1328 name: "nvs.CVlan != evs.CVlan",
1329 args: args{
1330 evs: &VoltServiceCfg{
1331 CVlan: of.VlanAny,
1332 },
1333 nvs: &VoltServiceCfg{
1334 Port: "test_port",
1335 },
1336 },
1337 want: false,
1338 },
1339 {
1340 name: "nvs.SVlan != evs.SVlan",
1341 args: args{
1342 evs: &VoltServiceCfg{
1343 SVlan: of.VlanAny,
1344 },
1345 nvs: &VoltServiceCfg{
1346 Port: "test_port",
1347 },
1348 },
1349 want: false,
1350 },
1351 {
1352 name: "nvs.SVlanTpid != 0",
1353 args: args{
1354 evs: &VoltServiceCfg{
1355 SVlanTpid: layers.EthernetTypeARP,
1356 },
1357 nvs: &VoltServiceCfg{
1358 SVlanTpid: layers.EthernetTypeCiscoDiscovery,
1359 },
1360 },
1361 want: false,
1362 },
1363 {
1364 name: "nvs.Pbits != evs.Pbits",
1365 args: args{
1366 evs: &VoltServiceCfg{
1367 Pbits: []of.PbitType{
1368 PbitMatchAll,
1369 },
1370 },
1371 nvs: &VoltServiceCfg{
1372 Port: "test_port",
1373 },
1374 },
1375 want: false,
1376 },
1377 {
1378 name: "nvs.DsRemarkPbitsMap != evs.DsRemarkPbitsMap",
1379 args: args{
1380 evs: &VoltServiceCfg{
1381 DsRemarkPbitsMap: a,
1382 },
1383 nvs: &VoltServiceCfg{
1384 Port: "test_port",
1385 },
1386 },
1387 want: false,
1388 },
1389 {
1390 name: "nvs.TechProfileID != evs.TechProfileID",
1391 args: args{
1392 evs: &VoltServiceCfg{
1393 TechProfileID: uint16(1),
1394 },
1395 nvs: &VoltServiceCfg{
1396 Port: "test_port",
1397 },
1398 },
1399 want: false,
1400 },
1401 {
1402 name: "nvs.CircuitID != evs.CircuitID",
1403 args: args{
1404 evs: &VoltServiceCfg{
1405 CircuitID: "test_circuit_id",
1406 },
1407 nvs: &VoltServiceCfg{
1408 Port: "test_port",
1409 },
1410 },
1411 want: false,
1412 },
1413 {
1414 name: "nvs.RemoteID != evs.RemoteID",
1415 args: args{
1416 evs: &VoltServiceCfg{
1417 RemoteID: []byte{1},
1418 },
1419 nvs: &VoltServiceCfg{
1420 Port: "test_port",
1421 },
1422 },
1423 want: false,
1424 },
1425 {
1426 name: "nvs.Port != evs.Port",
1427 args: args{
1428 evs: &VoltServiceCfg{},
1429 nvs: &VoltServiceCfg{
1430 Port: "test_port",
1431 },
1432 },
1433 want: false,
1434 },
1435 {
1436 name: "nvs.PonPort != evs.PonPort",
1437 args: args{
1438 evs: &VoltServiceCfg{},
1439 nvs: &VoltServiceCfg{
1440 PonPort: uint32(1),
1441 },
1442 },
1443 want: false,
1444 },
1445 {
1446 name: "evs.MacLearning == MacLearningNone",
1447 args: args{
1448 evs: &VoltServiceCfg{
1449 MacAddr: layers.EthernetBroadcast,
1450 },
1451 nvs: &VoltServiceCfg{},
1452 },
1453 want: false,
1454 },
1455 {
1456 name: "nvs.IgmpEnabled != evs.IgmpEnabled",
1457 args: args{
1458 evs: &VoltServiceCfg{
1459 IgmpEnabled: true,
1460 },
1461 nvs: &VoltServiceCfg{},
1462 },
1463 want: false,
1464 },
1465 {
1466 name: "nvs.McastService != evs.McastService",
1467 args: args{
1468 evs: &VoltServiceCfg{
1469 McastService: true,
1470 },
1471 nvs: &VoltServiceCfg{},
1472 },
1473 want: false,
1474 },
1475 {
1476 name: "nvs.ONTEtherTypeClassification != evs.ONTEtherTypeClassification",
1477 args: args{
1478 evs: &VoltServiceCfg{
1479 ONTEtherTypeClassification: 1,
1480 },
1481 nvs: &VoltServiceCfg{},
1482 },
1483 want: false,
1484 },
1485 {
1486 name: "nvs.UsMeterProfile != evs.UsMeterProfile",
1487 args: args{
1488 evs: &VoltServiceCfg{
1489 UsMeterProfile: "UsMeterProfile",
1490 },
1491 nvs: &VoltServiceCfg{},
1492 },
1493 want: false,
1494 },
1495 {
1496 name: "nvs.DsMeterProfile != evs.DsMeterProfile",
1497 args: args{
1498 evs: &VoltServiceCfg{
1499 DsMeterProfile: "DsMeterProfile",
1500 },
1501 nvs: &VoltServiceCfg{},
1502 },
1503 want: false,
1504 },
1505 {
1506 name: "nvs.AggDsMeterProfile != evs.AggDsMeterProfile",
1507 args: args{
1508 evs: &VoltServiceCfg{
1509 AggDsMeterProfile: "AggDsMeterProfile",
1510 },
1511 nvs: &VoltServiceCfg{},
1512 },
1513 want: false,
1514 },
1515 {
1516 name: "nvs.VnetID != evs.VnetID",
1517 args: args{
1518 evs: &VoltServiceCfg{
1519 VnetID: "VnetID",
1520 },
1521 nvs: &VoltServiceCfg{},
1522 },
1523 want: false,
1524 },
1525 {
1526 name: "nvs.MvlanProfileName != evs.MvlanProfileName",
1527 args: args{
1528 evs: &VoltServiceCfg{
1529 MvlanProfileName: "MvlanProfileName",
1530 },
1531 nvs: &VoltServiceCfg{},
1532 },
1533 want: false,
1534 },
1535 {
1536 name: "nvs.RemoteIDType != evs.RemoteIDType",
1537 args: args{
1538 evs: &VoltServiceCfg{
1539 RemoteIDType: "RemoteIDType",
1540 },
1541 nvs: &VoltServiceCfg{},
1542 },
1543 want: false,
1544 },
1545 {
1546 name: "nvs.SchedID != evs.SchedID",
1547 args: args{
1548 evs: &VoltServiceCfg{
1549 SchedID: 1,
1550 },
1551 nvs: &VoltServiceCfg{},
1552 },
1553 want: false,
1554 },
1555 {
1556 name: "nvs.AllowTransparent != evs.AllowTransparent",
1557 args: args{
1558 evs: &VoltServiceCfg{
1559 AllowTransparent: true,
1560 },
1561 nvs: &VoltServiceCfg{},
1562 },
1563 want: false,
1564 },
1565 {
1566 name: "nvs.EnableMulticastKPI != evs.EnableMulticastKPI",
1567 args: args{
1568 evs: &VoltServiceCfg{
1569 EnableMulticastKPI: true,
1570 },
1571 nvs: &VoltServiceCfg{},
1572 },
1573 want: false,
1574 },
1575 {
1576 name: "nvs.DataRateAttr != evs.DataRateAttr",
1577 args: args{
1578 evs: &VoltServiceCfg{
1579 DataRateAttr: "DataRateAttr",
1580 },
1581 nvs: &VoltServiceCfg{},
1582 },
1583 want: false,
1584 },
1585 {
1586 name: "nvs.MinDataRateUs != evs.MinDataRateUs",
1587 args: args{
1588 evs: &VoltServiceCfg{
1589 MinDataRateUs: uint32(1),
1590 },
1591 nvs: &VoltServiceCfg{},
1592 },
1593 want: false,
1594 },
1595 {
1596 name: "nvs.MinDataRateDs != evs.MinDataRateDs",
1597 args: args{
1598 evs: &VoltServiceCfg{
1599 MinDataRateDs: uint32(1),
1600 },
1601 nvs: &VoltServiceCfg{},
1602 },
1603 want: false,
1604 },
1605 {
1606 name: "nvs.MaxDataRateUs != evs.MaxDataRateUs",
1607 args: args{
1608 evs: &VoltServiceCfg{
1609 MaxDataRateUs: uint32(1),
1610 },
1611 nvs: &VoltServiceCfg{},
1612 },
1613 want: false,
1614 },
1615 {
1616 name: "nvs.MaxDataRateDs != evs.MaxDataRateDs",
1617 args: args{
1618 evs: &VoltServiceCfg{
1619 MaxDataRateDs: uint32(1),
1620 },
1621 nvs: &VoltServiceCfg{},
1622 },
1623 want: false,
1624 },
vinokuma02fbfd02023-07-05 15:23:33 +05301625 {
1626 name: "nvs.IsOption82Enabled != evs.IsOption82Enabled",
1627 args: args{
1628 evs: &VoltServiceCfg{
1629 IsOption82Enabled: true,
1630 },
1631 nvs: &VoltServiceCfg{},
1632 },
1633 want: false,
1634 },
vinokumaf7605fc2023-06-02 18:08:01 +05301635 }
1636 for _, tt := range tests {
1637 t.Run(tt.name, func(t *testing.T) {
1638 va := &VoltApplication{
1639 vendorID: "test_vendor_id",
1640 }
1641 switch tt.name {
1642 case "VoltApplication_DeepEqualServicecfg", "nvs.Name != evs.Name", "nvs.UniVlan != evs.UniVlan",
1643 "nvs.CVlan != evs.CVlan", "nvs.SVlan != evs.SVlan", "nvs.SVlanTpid != 0", "nvs.Pbits != evs.Pbits",
1644 "nvs.DsRemarkPbitsMap != evs.DsRemarkPbitsMap", "nvs.TechProfileID != evs.TechProfileID",
1645 "nvs.CircuitID != evs.CircuitID", "nvs.RemoteID != evs.RemoteID", "nvs.Port != evs.Port",
1646 "evs.MacLearning == MacLearningNone", "nvs.PonPort != evs.PonPort", "nvs.IgmpEnabled != evs.IgmpEnabled",
1647 "nvs.McastService != evs.McastService", "nvs.ONTEtherTypeClassification != evs.ONTEtherTypeClassification",
1648 "nvs.UsMeterProfile != evs.UsMeterProfile",
1649 "nvs.DsMeterProfile != evs.DsMeterProfile", "nvs.AggDsMeterProfile != evs.AggDsMeterProfile",
1650 "nvs.VnetID != evs.VnetID", "nvs.MvlanProfileName != evs.MvlanProfileName",
1651 "nvs.RemoteIDType != evs.RemoteIDType", "nvs.SchedID != evs.SchedID",
1652 "nvs.AllowTransparent != evs.AllowTransparent",
1653 "nvs.EnableMulticastKPI != evs.EnableMulticastKPI", "nvs.DataRateAttr != evs.DataRateAttr",
1654 "nvs.MinDataRateUs != evs.MinDataRateUs", "nvs.MinDataRateDs != evs.MinDataRateDs",
vinokuma02fbfd02023-07-05 15:23:33 +05301655 "nvs.MaxDataRateUs != evs.MaxDataRateUs", "nvs.MaxDataRateDs != evs.MaxDataRateDs",
1656 "nvs.IsOption82Enabled != evs.IsOption82Enabled":
vinokumaf7605fc2023-06-02 18:08:01 +05301657 if got := va.DeepEqualServicecfg(tt.args.evs, tt.args.nvs); got != tt.want {
1658 t.Errorf("VoltApplication.DeepEqualServicecfg() = %v, want %v", got, tt.want)
1659 }
1660 }
1661 })
1662 }
1663}
vinokuma02fbfd02023-07-05 15:23:33 +05301664
1665func Test_forceUpdateAllServices(t *testing.T) {
1666 type args struct {
1667 cntx context.Context
1668 msr *MigrateServicesRequest
1669 }
1670 servicesList := map[string]bool{}
1671 servicesList[test_device] = true
1672 tests := []struct {
1673 name string
1674 args args
1675 }{
1676 {
1677 name: "forceUpdateAllServices",
1678 args: args{
1679 cntx: context.Background(),
1680 msr: &MigrateServicesRequest{
1681 ID: "test_id",
1682 ServicesList: servicesList,
1683 DeviceID: test_device,
1684 },
1685 },
1686 },
1687 }
1688 for _, tt := range tests {
1689 t.Run(tt.name, func(t *testing.T) {
1690 ga := GetApplication()
1691 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1692 db = dbintf
1693 dbintf.EXPECT().DelMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1694 ga.ServiceByName.Store(test_device, voltService2)
1695 voltService2.VoltServiceOper.Metadata = &MigrateServiceMetadata{
1696 NewVnetID: "test_new_vnet_id",
1697 RequestID: "test_request_id",
1698 }
1699 newConcurrentMap := util.NewConcurrentMap()
1700 ga.DevicesDisc.Store(test_device, voltDevice2)
1701 voltDevice2.MigratingServices.Set("test_vnet_id", newConcurrentMap)
1702 migrateServicesRequest := &MigrateServicesRequest{
1703 ID: "test_id",
1704 ServicesList: servicesList,
1705 }
1706 newConcurrentMap.Set("test_request_id", migrateServicesRequest)
1707 dbintf.EXPECT().PutMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1708 forceUpdateAllServices(tt.args.cntx, tt.args.msr)
1709 })
1710 }
1711}
1712
1713func TestVoltService_updateVnetProfile(t *testing.T) {
1714 type args struct {
1715 cntx context.Context
1716 deviceID string
1717 }
1718 tests := []struct {
1719 name string
1720 args args
1721 }{
1722 {
1723 name: "DeleteInProgress_true",
1724 args: args{
1725 cntx: context.Background(),
1726 deviceID: test_device,
1727 },
1728 },
1729 {
1730 name: "metadata_nil",
1731 args: args{
1732 cntx: context.Background(),
1733 deviceID: test_device,
1734 },
1735 },
1736 }
1737 for _, tt := range tests {
1738 t.Run(tt.name, func(t *testing.T) {
1739 switch tt.name {
1740 case "DeleteInProgress_true":
1741 vs := &VoltService{
1742 VoltServiceOper: VoltServiceOper{
1743 DeleteInProgress: true,
1744 },
1745 }
1746 vs.updateVnetProfile(tt.args.cntx, tt.args.deviceID)
1747 case "metadata_nil":
1748 vs := &VoltService{
1749 VoltServiceOper: VoltServiceOper{
1750 Metadata: &MigrateServiceMetadata{},
1751 },
1752 }
1753 vs.updateVnetProfile(tt.args.cntx, tt.args.deviceID)
1754 }
1755 })
1756 }
1757}
1758
1759func TestMigrateServicesRequest_serviceMigrated(t *testing.T) {
1760 type args struct {
1761 cntx context.Context
1762 serviceName string
1763 }
1764 tests := []struct {
1765 name string
1766 args args
1767 }{
1768 {
1769 name: "ServicesList_nil",
1770 args: args{
1771 cntx: context.Background(),
1772 serviceName: "test_service_name",
1773 },
1774 },
1775 }
1776 for _, tt := range tests {
1777 t.Run(tt.name, func(t *testing.T) {
1778 msr := &MigrateServicesRequest{
1779 ServicesList: map[string]bool{},
1780 }
1781 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1782 db = dbintf
1783 dbintf.EXPECT().DelMigrateServicesReq(gomock.All(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
1784 msr.serviceMigrated(tt.args.cntx, tt.args.serviceName)
1785 })
1786 }
1787}
1788
1789func TestVoltApplication_TriggerPendingMigrateServicesReq(t *testing.T) {
1790 type args struct {
1791 cntx context.Context
1792 device string
1793 }
1794 tests := []struct {
1795 name string
1796 args args
1797 }{
1798 {
1799 name: "VoltApplication_TriggerPendingMigrateServicesReq",
1800 args: args{
1801 cntx: context.Background(),
1802 device: test_device,
1803 },
1804 },
1805 }
1806 for _, tt := range tests {
1807 t.Run(tt.name, func(t *testing.T) {
1808 va := &VoltApplication{
1809 ServiceByName: sync.Map{},
1810 }
1811 migrateServicesRequest := &MigrateServicesRequest{
1812 ID: "test_id",
1813 OldVnetID: "test_vnet_id",
1814 DeviceID: test_device,
1815 }
1816 b, err := json.Marshal(migrateServicesRequest)
1817 if err != nil {
1818 panic(err)
1819 }
1820 kvpair := map[string]*kvstore.KVPair{}
1821 kvpair["test_device_id"] = &kvstore.KVPair{
1822 Key: "test_device_id",
1823 Value: b,
1824 }
1825
1826 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1827 db = dbintf
1828 ga := GetApplication()
1829 ga.DevicesDisc.Store(test_device, voltDevice2)
1830 newConcurrentMap := util.NewConcurrentMap()
1831 voltDevice2.MigratingServices.Set("test_vnet_id", newConcurrentMap)
1832 dbintf.EXPECT().GetAllMigrateServicesReq(gomock.Any(), gomock.Any()).Return(kvpair, nil).AnyTimes()
1833 va.TriggerPendingMigrateServicesReq(tt.args.cntx, tt.args.device)
1834 })
1835 }
1836}
1837
1838func TestVoltApplication_FetchAndProcessAllMigrateServicesReq(t *testing.T) {
1839 type args struct {
1840 cntx context.Context
1841 device string
1842 msrAction func(context.Context, *MigrateServicesRequest)
1843 }
1844 tests := []struct {
1845 name string
1846 args args
1847 }{
1848 {
1849 name: "invalid_value_type",
1850 args: args{
1851 cntx: context.Background(),
1852 device: test_device,
1853 msrAction: func(ctx context.Context, msr *MigrateServicesRequest) {},
1854 },
1855 },
1856 }
1857 for _, tt := range tests {
1858 t.Run(tt.name, func(t *testing.T) {
1859 va := &VoltApplication{
1860 DevicesDisc: sync.Map{},
1861 }
1862 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1863 db = dbintf
1864 kvpair := map[string]*kvstore.KVPair{}
1865 kvpair["test_device_id"] = &kvstore.KVPair{
1866 Key: "test_device_id",
vinokuma703a70b2023-07-17 10:06:43 +05301867 Value: invalid_value,
vinokuma02fbfd02023-07-05 15:23:33 +05301868 }
1869 dbintf.EXPECT().GetAllMigrateServicesReq(gomock.Any(), gomock.Any()).Return(kvpair, nil).AnyTimes()
1870 va.FetchAndProcessAllMigrateServicesReq(tt.args.cntx, tt.args.device, tt.args.msrAction)
1871 })
1872 }
1873}
1874
1875func TestVoltApplication_createMigrateServicesFromString(t *testing.T) {
1876 type args struct {
1877 b []byte
1878 }
1879 tests := []struct {
1880 name string
1881 args args
1882 }{
1883 {
1884 name: "Unmarshal_error",
1885 args: args{
1886 b: []byte{},
1887 },
1888 },
1889 }
1890 for _, tt := range tests {
1891 t.Run(tt.name, func(t *testing.T) {
1892 va := &VoltApplication{
1893 vendorID: test_device,
1894 }
1895 got := va.createMigrateServicesFromString(tt.args.b)
1896 assert.NotNil(t, got)
1897 })
1898 }
1899}
1900
1901func TestVoltApplication_getMigrateServicesRequest(t *testing.T) {
1902 type args struct {
1903 deviceID string
1904 oldVnetID string
1905 requestID string
1906 }
1907 tests := []struct {
1908 name string
1909 args args
1910 want *MigrateServicesRequest
1911 }{
1912 {
1913 name: "GetDevice_nil",
1914 args: args{
1915 deviceID: test_device,
1916 },
1917 },
1918 }
1919 for _, tt := range tests {
1920 t.Run(tt.name, func(t *testing.T) {
1921 va := &VoltApplication{
1922 vendorID: "vendorID",
1923 }
1924 if got := va.getMigrateServicesRequest(tt.args.deviceID, tt.args.oldVnetID, tt.args.requestID); !reflect.DeepEqual(got, tt.want) {
1925 t.Errorf("VoltApplication.getMigrateServicesRequest() = %v, want %v", got, tt.want)
1926 }
1927 })
1928 }
1929}
1930
1931func TestVoltDevice_AddMigratingServices(t *testing.T) {
1932 type args struct {
1933 msr *MigrateServicesRequest
1934 }
1935 tests := []struct {
1936 name string
1937 args args
1938 }{
1939 {
1940 name: "MigratingServices_Get_nil",
1941 args: args{
1942 msr: &MigrateServicesRequest{
1943 ID: "test_id",
1944 },
1945 },
1946 },
1947 }
1948 for _, tt := range tests {
1949 t.Run(tt.name, func(t *testing.T) {
1950 d := &VoltDevice{
1951 MigratingServices: util.NewConcurrentMap(),
1952 }
1953 d.AddMigratingServices(tt.args.msr)
1954 })
1955 }
1956}
1957
1958func TestMigrateServicesRequest_ProcessMigrateServicesProfRequest(t *testing.T) {
1959 type args struct {
1960 cntx context.Context
1961 }
1962 tests := []struct {
1963 name string
1964 args args
1965 }{
1966 {
1967 name: "ServicesList_true",
1968 args: args{
1969 cntx: context.Background(),
1970 },
1971 },
1972 {
1973 name: "ServicesList_false",
1974 args: args{
1975 cntx: context.Background(),
1976 },
1977 },
1978 {
1979 name: "GetVnetByPort_nil",
1980 args: args{
1981 cntx: context.Background(),
1982 },
1983 },
1984 {
1985 name: "UsHSIAFlowsApplied_true",
1986 args: args{
1987 cntx: context.Background(),
1988 },
1989 },
1990 {
1991 name: "ServiceByName_nil",
1992 args: args{
1993 cntx: context.Background(),
1994 },
1995 },
1996 }
1997 for _, tt := range tests {
1998 t.Run(tt.name, func(t *testing.T) {
1999 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2000 db = dbintf
2001 switch tt.name {
2002 case "ServicesList_true":
2003 servicesList := map[string]bool{}
2004 servicesList[test_device] = true
2005 msr := &MigrateServicesRequest{
2006 ServicesList: servicesList,
2007 }
2008 dbintf.EXPECT().DelMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2009 msr.ProcessMigrateServicesProfRequest(tt.args.cntx)
2010 case "ServicesList_false":
2011 servicesList := map[string]bool{}
2012 servicesList[test_device] = false
2013 msr := &MigrateServicesRequest{
2014 ServicesList: servicesList,
2015 }
2016 ga := GetApplication()
2017 ga.ServiceByName.Store(test_device, voltService2)
2018 ga.VnetsByPort.Store("test_port", voltPortVnet1)
2019 msr.ProcessMigrateServicesProfRequest(tt.args.cntx)
2020 case "GetVnetByPort_nil":
2021 servicesList := map[string]bool{}
2022 servicesList[test_device] = false
2023 msr := &MigrateServicesRequest{
2024 ServicesList: servicesList,
2025 }
2026 ga := GetApplication()
2027 var voltService1 = &VoltService{
2028 Version: "test_version",
2029 VoltServiceCfg: VoltServiceCfg{
2030 VnetID: "test_vnet_id",
2031 SVlan: of.VlanAny,
2032 CVlan: of.VlanAny,
2033 UniVlan: of.VlanAny,
2034 },
2035 }
2036 ga.ServiceByName.Store(test_device, voltService1)
2037 ga.VnetsByPort.Store("test_port1", nil)
2038 msr.ProcessMigrateServicesProfRequest(tt.args.cntx)
2039 case "UsHSIAFlowsApplied_true":
2040 servicesList := map[string]bool{}
2041 servicesList[test_device] = false
2042 msr := &MigrateServicesRequest{
2043 ServicesList: servicesList,
2044 }
2045 ga := GetApplication()
2046 voltService2.UsHSIAFlowsApplied = true
2047 ga.ServiceByName.Store(test_device, voltService2)
2048 ga.VnetsByPort.Store("test_port", voltPortVnet1)
2049 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2050 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2051 msr.ProcessMigrateServicesProfRequest(tt.args.cntx)
2052 case "ServiceByName_nil":
2053 servicesList := map[string]bool{}
2054 servicesList[""] = false
2055 msr := &MigrateServicesRequest{
2056 ServicesList: servicesList,
2057 }
2058 msr.ProcessMigrateServicesProfRequest(tt.args.cntx)
2059 }
2060 })
2061 }
2062}
2063
2064func TestVoltApplication_MigrateServices(t *testing.T) {
2065 type args struct {
2066 cntx context.Context
2067 serialNum string
2068 reqID string
2069 oldVnetID string
2070 newVnetID string
2071 serviceList []string
2072 }
2073 tests := []struct {
2074 name string
2075 args args
2076 wantErr bool
2077 }{
2078 {
2079 name: "VoltApplication_MigrateServices",
2080 args: args{
2081 cntx: context.Background(),
2082 serialNum: "test_serial_number",
2083 reqID: "test_reqid",
2084 oldVnetID: "test_old_vnet_id",
2085 newVnetID: "test_new_vnet_id",
2086 serviceList: []string{"test_service_list_1", "test_service_list_2"},
2087 },
2088 },
2089 {
2090 name: "Old Vnet Id not found",
2091 args: args{
2092 cntx: context.Background(),
2093 serialNum: "test_serial_number",
2094 reqID: "test_reqid",
2095 oldVnetID: "",
2096 newVnetID: "test_new_vnet_id",
2097 serviceList: []string{"test_service_list_1", "test_service_list_2"},
2098 },
2099 },
2100 {
2101 name: "New Vnet Id not found",
2102 args: args{
2103 cntx: context.Background(),
2104 serialNum: "test_serial_number",
2105 reqID: "test_reqid",
2106 oldVnetID: "test_old_vnet_id",
2107 newVnetID: "",
2108 serviceList: []string{"test_service_list_1", "test_service_list_2"},
2109 },
2110 },
2111 }
2112 for _, tt := range tests {
2113 t.Run(tt.name, func(t *testing.T) {
2114 va := &VoltApplication{
2115 VnetsByName: sync.Map{},
2116 }
2117 voltVnet2 := &VoltVnet{
2118 Version: "v3",
2119 VnetConfig: VnetConfig{
2120 Name: "2310-4096-4096",
2121 VnetType: "Encapsulation",
2122 SVlan: 2310,
2123 CVlan: 4096,
2124 UniVlan: 4096,
2125 SVlanTpid: 33024,
2126 },
2127 VnetOper: VnetOper{
2128 PendingDeviceToDelete: "SDX63200313",
2129 },
2130 }
2131 switch tt.name {
2132 case "VoltApplication_MigrateServices":
2133 va.VnetsByName.Store("test_old_vnet_id", voltVnet2)
2134 va.VnetsByName.Store("test_new_vnet_id", voltVnet2)
2135 va.DevicesDisc.Store(test_device, voltDevice2)
2136 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2137 db = dbintf
2138 dbintf.EXPECT().PutMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2139 if err := va.MigrateServices(tt.args.cntx, tt.args.serialNum, tt.args.reqID, tt.args.oldVnetID, tt.args.newVnetID, tt.args.serviceList); (err != nil) != tt.wantErr {
2140 t.Errorf("VoltApplication.MigrateServices() error = %v, wantErr %v", err, tt.wantErr)
2141 }
2142 case "Old Vnet Id not found":
2143 va.VnetsByName.Store("test_old_vnet_id", voltVnet2)
2144 err := va.MigrateServices(tt.args.cntx, tt.args.serialNum, tt.args.reqID, tt.args.oldVnetID, tt.args.newVnetID, tt.args.serviceList)
2145 assert.NotNil(t, err)
2146 case "New Vnet Id not found":
2147 va.VnetsByName.Store("test_old_vnet_id", voltVnet2)
2148 va.VnetsByName.Store("test_new_vnet_id", voltVnet2)
2149 err := va.MigrateServices(tt.args.cntx, tt.args.serialNum, tt.args.reqID, tt.args.oldVnetID, tt.args.newVnetID, tt.args.serviceList)
2150 assert.NotNil(t, err)
2151 }
2152 })
2153 }
2154}
2155
2156func TestMigrateServicesRequest_WriteToDB(t *testing.T) {
2157 type args struct {
2158 cntx context.Context
2159 }
2160 tests := []struct {
2161 name string
2162 args args
2163 }{
2164 {
2165 name: "PutMigrateServicesReq_error",
2166 args: args{
2167 cntx: context.Background(),
2168 },
2169 },
2170 }
2171 for _, tt := range tests {
2172 t.Run(tt.name, func(t *testing.T) {
2173 msr := &MigrateServicesRequest{
2174 ID: test_device,
2175 }
2176 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2177 db = dbintf
2178 dbintf.EXPECT().PutMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("error")).Times(1)
2179 msr.WriteToDB(tt.args.cntx)
2180 })
2181 }
2182}
2183
2184func TestVoltService_MatchesVlans(t *testing.T) {
2185 type args struct {
2186 vlans []of.VlanType
2187 }
2188 tests := []struct {
2189 name string
2190 args args
2191 want bool
2192 }{
2193 {
2194 name: "vlans_nil",
2195 args: args{
2196 vlans: []of.VlanType{},
2197 },
2198 want: false,
2199 },
2200 {
2201 name: "MatchesVlans",
2202 args: args{
2203 vlans: []of.VlanType{
2204 of.VlanAny,
2205 },
2206 },
2207 want: true,
2208 },
2209 {
2210 name: "vlans[0] != vs.CVlan",
2211 args: args{
2212 vlans: []of.VlanType{
2213 of.VlanNone,
2214 },
2215 },
2216 want: false,
2217 },
2218 }
2219 for _, tt := range tests {
2220 t.Run(tt.name, func(t *testing.T) {
2221 vs := &VoltService{
2222 VoltServiceCfg: VoltServiceCfg{CVlan: of.VlanAny},
2223 }
2224 switch tt.name {
2225 case "vlans_nil", "MatchesVlans", "vlans[0] != vs.CVlan":
2226 if got := vs.MatchesVlans(tt.args.vlans); got != tt.want {
2227 t.Errorf("VoltService.MatchesVlans() = %v, want %v", got, tt.want)
2228 }
2229 }
2230 })
2231 }
2232}
2233
2234func TestVoltService_MatchesPbits(t *testing.T) {
2235 type args struct {
2236 pbits []of.PbitType
2237 }
2238 tests := []struct {
2239 name string
2240 args args
2241 want bool
2242 }{
2243 {
2244 name: "VoltService_MatchesPbits",
2245 args: args{
2246 pbits: []of.PbitType{
2247 of.PbitMatchAll,
2248 },
2249 },
2250 want: true,
2251 },
2252 {
2253 name: "PbitType_nil",
2254 args: args{
2255 pbits: []of.PbitType{},
2256 },
2257 want: false,
2258 },
2259 }
2260 for _, tt := range tests {
2261 t.Run(tt.name, func(t *testing.T) {
2262 vs := &VoltService{
2263 VoltServiceCfg: VoltServiceCfg{
2264 Pbits: []of.PbitType{
2265 of.PbitMatchAll,
2266 },
2267 },
2268 }
2269 switch tt.name {
2270 case "VoltService_MatchesPbits", "PbitType_nil":
2271 if got := vs.MatchesPbits(tt.args.pbits); got != tt.want {
2272 t.Errorf("VoltService.MatchesPbits() = %v, want %v", got, tt.want)
2273 }
2274 }
2275 })
2276 }
2277}
2278
2279func TestVoltApplication_DelServiceWithPrefix(t *testing.T) {
2280 type args struct {
2281 cntx context.Context
2282 prefix string
2283 }
2284 tests := []struct {
2285 name string
2286 args args
2287 }{
2288 {
2289 name: "VoltApplication_DelServiceWithPrefix",
2290 args: args{
2291 cntx: context.Background(),
2292 prefix: test_device,
2293 },
2294 },
2295 }
2296 for _, tt := range tests {
2297 t.Run(tt.name, func(t *testing.T) {
2298 va := &VoltApplication{
2299 VnetsBySvlan: util.NewConcurrentMap(),
2300 }
2301 va.ServiceByName.Store(test_device, voltService)
2302 va.VnetsByName.Store("0-0-0", voltVnet)
2303 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2304 db = dbintf
2305 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
2306 cuncurrentMap := &util.ConcurrentMap{
2307 Count: atomic.NewUint64(0),
2308 }
2309 va.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap)
2310 dbintf.EXPECT().DelVnet(gomock.Any(), gomock.Any()).Return(nil).Times(1)
Hitesh Chhabra7d249a02023-07-04 21:33:49 +05302311 err := va.DelServiceWithPrefix(tt.args.cntx, tt.args.prefix)
2312 assert.Nil(t, err)
vinokuma02fbfd02023-07-05 15:23:33 +05302313 })
2314 }
2315}
2316
2317func TestVoltService_FlowInstallFailure(t *testing.T) {
2318 type args struct {
2319 cookie string
2320 errorCode uint32
2321 errReason string
2322 }
2323 tests := []struct {
2324 name string
2325 args args
2326 }{
2327 {
2328 name: "VoltService_FlowInstallFailure",
2329 args: args{
2330 cookie: "test_cookie",
2331 errorCode: uint32(1),
2332 errReason: "err_reason",
2333 },
2334 },
2335 {
2336 name: "PendingFlows[cookie]_false",
2337 args: args{
2338 cookie: "test_cookie",
2339 errorCode: uint32(1),
2340 errReason: "err_reason",
2341 },
2342 },
2343 }
2344 pendingFlows := map[string]bool{}
2345 pendingFlows["test_cookie"] = true
2346 for _, tt := range tests {
2347 t.Run(tt.name, func(t *testing.T) {
2348 vs := &VoltService{
2349 VoltServiceOper: VoltServiceOper{},
2350 }
2351 switch tt.name {
2352 case "VoltService_FlowInstallFailure":
2353 vs.PendingFlows = pendingFlows
2354 vs.FlowInstallFailure(tt.args.cookie, tt.args.errorCode, tt.args.errReason)
2355 case "PendingFlows[cookie]_false":
2356 vs.FlowInstallFailure(tt.args.cookie, tt.args.errorCode, tt.args.errReason)
2357 }
2358 })
2359 }
2360}
2361
2362func TestVoltService_FlowRemoveSuccess(t *testing.T) {
2363 type args struct {
2364 cntx context.Context
2365 cookie string
2366 }
2367 tests := []struct {
2368 name string
2369 args args
2370 }{
2371 {
2372 name: "GetDevice != nil",
2373 args: args{
2374 cntx: context.Background(),
2375 cookie: "test_cookie",
2376 },
2377 },
2378 }
2379 for _, tt := range tests {
2380 t.Run(tt.name, func(t *testing.T) {
2381 vs := &VoltService{
2382 VoltServiceOper: VoltServiceOper{
2383 Device: test_device,
2384 },
2385 }
2386 ga := GetApplication()
2387 ga.DevicesDisc.Store(test_device, voltDevice2)
2388 voltDevice2.State = controller.DeviceStateUP
2389 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2390 db = dbintf
2391 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2392 vs.FlowRemoveSuccess(tt.args.cntx, tt.args.cookie)
2393 })
2394 }
2395}
2396
2397func TestVoltService_setDSMatchActionVlanT0(t *testing.T) {
2398 type args struct {
2399 flow *of.VoltSubFlow
2400 }
2401 tests := []struct {
2402 name string
2403 args args
2404 wantErr bool
2405 }{
2406 {
2407 name: "VlanControl: ONUCVlanOLTSVlan",
2408 args: args{
2409 flow: &of.VoltSubFlow{
2410 ErrorReason: "test_error_reason",
2411 Cookie: uint64(1),
2412 OldCookie: uint64(2),
2413 TableID: uint32(3),
2414 Priority: uint32(4),
2415 State: uint8(5),
2416 },
2417 },
2418 },
2419 {
2420 name: "VlanControl: OLTCVlanOLTSVlan",
2421 args: args{
2422 flow: &of.VoltSubFlow{
2423 ErrorReason: "test_error_reason",
2424 Cookie: uint64(1),
2425 OldCookie: uint64(2),
2426 TableID: uint32(3),
2427 Priority: uint32(4),
2428 State: uint8(5),
2429 },
2430 },
2431 },
2432 {
2433 name: "VlanControl: ONUCVlan",
2434 args: args{
2435 flow: &of.VoltSubFlow{
2436 ErrorReason: "test_error_reason",
2437 Cookie: uint64(1),
2438 OldCookie: uint64(2),
2439 TableID: uint32(3),
2440 Priority: uint32(4),
2441 State: uint8(5),
2442 },
2443 },
2444 },
2445 {
2446 name: "VlanControl: OLTSVlan",
2447 args: args{
2448 flow: &of.VoltSubFlow{
2449 ErrorReason: "test_error_reason",
2450 Cookie: uint64(1),
2451 OldCookie: uint64(2),
2452 TableID: uint32(3),
2453 Priority: uint32(4),
2454 State: uint8(5),
2455 },
2456 },
2457 },
2458 {
2459 name: "VlanControl: OLTSVlan && UniVlan != of.VlanAny",
2460 args: args{
2461 flow: &of.VoltSubFlow{
2462 ErrorReason: "test_error_reason",
2463 Cookie: uint64(1),
2464 OldCookie: uint64(2),
2465 TableID: uint32(3),
2466 Priority: uint32(4),
2467 State: uint8(5),
2468 },
2469 },
2470 },
2471 {
2472 name: "invalid VlanControl",
2473 args: args{
2474 flow: &of.VoltSubFlow{
2475 ErrorReason: "test_error_reason",
2476 Cookie: uint64(1),
2477 OldCookie: uint64(2),
2478 TableID: uint32(3),
2479 Priority: uint32(4),
2480 State: uint8(5),
2481 },
2482 },
2483 },
2484 }
2485 for _, tt := range tests {
2486 t.Run(tt.name, func(t *testing.T) {
2487 vs := &VoltService{
2488 VoltServiceCfg: VoltServiceCfg{
2489 SVlan: of.VlanAny,
2490 UniVlan: of.VlanAny,
2491 VlanControl: ONUCVlanOLTSVlan,
2492 },
2493 }
2494 switch tt.name {
2495 case "VlanControl: ONUCVlanOLTSVlan":
2496 vs.VlanControl = ONUCVlanOLTSVlan
2497 if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2498 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2499 }
2500 case "VlanControl: OLTCVlanOLTSVlan":
2501 vs.VlanControl = OLTCVlanOLTSVlan
2502 if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2503 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2504 }
2505 case "VlanControl: ONUCVlan":
2506 vs.VlanControl = ONUCVlan
2507 if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2508 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2509 }
2510 case "VlanControl: OLTSVlan":
2511 vs.VlanControl = OLTSVlan
2512 vs.UniVlan = vs.CVlan
2513 if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2514 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2515 }
2516 case "VlanControl: OLTSVlan && UniVlan != of.VlanAny":
2517 vs.VlanControl = OLTSVlan
2518 if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2519 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2520 }
2521 case "invalid VlanControl":
2522 vs.VlanControl = 5
2523 err := vs.setDSMatchActionVlanT0(tt.args.flow)
2524 assert.NotNil(t, err)
2525 }
2526 })
2527 }
2528}
2529
2530func TestVoltService_setUSMatchActionVlanT1(t *testing.T) {
2531 type args struct {
2532 flow *of.VoltSubFlow
2533 }
2534 tests := []struct {
2535 name string
2536 args args
2537 wantErr bool
2538 }{
2539 {
2540 name: "VlanControl: ONUCVlanOLTSVlan",
2541 args: args{
2542 flow: &of.VoltSubFlow{
2543 ErrorReason: "test_error_reason",
2544 Cookie: uint64(1),
2545 OldCookie: uint64(2),
2546 TableID: uint32(3),
2547 Priority: uint32(4),
2548 State: uint8(5),
2549 },
2550 },
2551 },
2552 {
2553 name: "VlanControl: OLTCVlanOLTSVlan",
2554 args: args{
2555 flow: &of.VoltSubFlow{
2556 ErrorReason: "test_error_reason",
2557 Cookie: uint64(1),
2558 OldCookie: uint64(2),
2559 TableID: uint32(3),
2560 Priority: uint32(4),
2561 State: uint8(5),
2562 },
2563 },
2564 },
2565 {
2566 name: "VlanControl: ONUCVlan",
2567 args: args{
2568 flow: &of.VoltSubFlow{
2569 ErrorReason: "test_error_reason",
2570 Cookie: uint64(1),
2571 OldCookie: uint64(2),
2572 TableID: uint32(3),
2573 Priority: uint32(4),
2574 State: uint8(5),
2575 },
2576 },
2577 },
2578 {
2579 name: "VlanControl: OLTSVlan",
2580 args: args{
2581 flow: &of.VoltSubFlow{
2582 ErrorReason: "test_error_reason",
2583 Cookie: uint64(1),
2584 OldCookie: uint64(2),
2585 TableID: uint32(3),
2586 Priority: uint32(4),
2587 State: uint8(5),
2588 },
2589 },
2590 },
2591 {
2592 name: "VlanControl: OLTSVlan vs.UniVlan != of.VlanAny && vs.UniVlan != of.VlanNone",
2593 args: args{
2594 flow: &of.VoltSubFlow{
2595 ErrorReason: "test_error_reason",
2596 Cookie: uint64(1),
2597 OldCookie: uint64(2),
2598 TableID: uint32(3),
2599 Priority: uint32(4),
2600 State: uint8(5),
2601 },
2602 },
2603 },
2604 {
2605 name: "VlanControl: OLTSVlan vs.UniVlan == of.VlanNone",
2606 args: args{
2607 flow: &of.VoltSubFlow{
2608 ErrorReason: "test_error_reason",
2609 Cookie: uint64(1),
2610 OldCookie: uint64(2),
2611 TableID: uint32(3),
2612 Priority: uint32(4),
2613 State: uint8(5),
2614 },
2615 },
2616 },
2617 {
2618 name: "VlanControl: default",
2619 args: args{
2620 flow: &of.VoltSubFlow{
2621 ErrorReason: "test_error_reason",
2622 Cookie: uint64(1),
2623 OldCookie: uint64(2),
2624 TableID: uint32(3),
2625 Priority: uint32(4),
2626 State: uint8(5),
2627 },
2628 },
2629 },
2630 }
2631 for _, tt := range tests {
2632 t.Run(tt.name, func(t *testing.T) {
2633 vs := &VoltService{
2634 VoltServiceCfg: VoltServiceCfg{
2635 SVlan: of.VlanAny,
2636 UniVlan: of.VlanAny,
2637 VlanControl: ONUCVlanOLTSVlan,
2638 },
2639 }
2640 switch tt.name {
2641 case "VlanControl: ONUCVlanOLTSVlan":
2642 vs.VlanControl = ONUCVlanOLTSVlan
2643 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2644 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2645 }
2646 case "VlanControl: OLTCVlanOLTSVlan":
2647 vs.VlanControl = OLTCVlanOLTSVlan
2648 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2649 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2650 }
2651 case "VlanControl: ONUCVlan":
2652 vs.VlanControl = ONUCVlan
2653 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2654 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2655 }
2656 case "VlanControl: OLTSVlan":
2657 vs.VlanControl = OLTSVlan
2658 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2659 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2660 }
2661 case "VlanControl: OLTSVlan vs.UniVlan != of.VlanAny && vs.UniVlan != of.VlanNone":
2662 vs.VlanControl = OLTSVlan
2663 vs.UniVlan = vs.CVlan
2664 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2665 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2666 }
2667 case "VlanControl: OLTSVlan vs.UniVlan == of.VlanNone":
2668 vs.VlanControl = OLTSVlan
2669 vs.UniVlan = of.VlanNone
2670 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2671 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2672 }
2673 case "VlanControl: default":
2674 vs.VlanControl = 6
2675 err := vs.setUSMatchActionVlanT1(tt.args.flow)
2676 assert.NotNil(t, err)
2677 }
2678 })
2679 }
2680}
2681
2682func TestVoltService_setUSMatchActionVlanT0(t *testing.T) {
2683 type args struct {
2684 flow *of.VoltSubFlow
2685 }
2686 tests := []struct {
2687 name string
2688 args args
2689 wantErr bool
2690 }{
2691 {
2692 name: "vs.VlanControl: ONUCVlanOLTSVlan",
2693 args: args{
2694 flow: &of.VoltSubFlow{
2695 ErrorReason: "test_error_reason",
2696 Cookie: uint64(1),
2697 OldCookie: uint64(2),
2698 TableID: uint32(3),
2699 Priority: uint32(4),
2700 State: uint8(5),
2701 },
2702 },
2703 },
2704 {
2705 name: "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone",
2706 args: args{
2707 flow: &of.VoltSubFlow{
2708 ErrorReason: "test_error_reason",
2709 Cookie: uint64(1),
2710 OldCookie: uint64(2),
2711 TableID: uint32(3),
2712 Priority: uint32(4),
2713 State: uint8(5),
2714 },
2715 },
2716 },
2717 {
2718 name: "vs.VlanControl: OLTCVlanOLTSVlan",
2719 args: args{
2720 flow: &of.VoltSubFlow{
2721 ErrorReason: "test_error_reason",
2722 Cookie: uint64(1),
2723 OldCookie: uint64(2),
2724 TableID: uint32(3),
2725 Priority: uint32(4),
2726 State: uint8(5),
2727 },
2728 },
2729 },
2730 {
2731 name: "vs.VlanControl: ONUCVlan",
2732 args: args{
2733 flow: &of.VoltSubFlow{
2734 ErrorReason: "test_error_reason",
2735 Cookie: uint64(1),
2736 OldCookie: uint64(2),
2737 TableID: uint32(3),
2738 Priority: uint32(4),
2739 State: uint8(5),
2740 },
2741 },
2742 },
2743 {
2744 name: "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone",
2745 args: args{
2746 flow: &of.VoltSubFlow{
2747 ErrorReason: "test_error_reason",
2748 Cookie: uint64(1),
2749 OldCookie: uint64(2),
2750 TableID: uint32(3),
2751 Priority: uint32(4),
2752 State: uint8(5),
2753 },
2754 },
2755 },
2756 {
2757 name: "vs.VlanControl: OLTSVlan",
2758 args: args{
2759 flow: &of.VoltSubFlow{
2760 ErrorReason: "test_error_reason",
2761 Cookie: uint64(1),
2762 OldCookie: uint64(2),
2763 TableID: uint32(3),
2764 Priority: uint32(4),
2765 State: uint8(5),
2766 },
2767 },
2768 },
2769 }
2770 for _, tt := range tests {
2771 t.Run(tt.name, func(t *testing.T) {
2772 vs := &VoltService{}
2773 switch tt.name {
2774 case "vs.VlanControl: ONUCVlanOLTSVlan":
2775 vs.VlanControl = ONUCVlanOLTSVlan
2776 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2777 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2778 }
2779 case "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone":
2780 vs.VlanControl = ONUCVlanOLTSVlan
2781 vs.UniVlan = of.VlanNone
2782 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2783 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2784 }
2785 case "vs.VlanControl: OLTCVlanOLTSVlan":
2786 vs.VlanControl = OLTCVlanOLTSVlan
2787 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2788 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2789 }
2790 case "vs.VlanControl: ONUCVlan":
2791 vs.VlanControl = ONUCVlan
2792 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2793 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2794 }
2795 case "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone":
2796 vs.VlanControl = ONUCVlan
2797 vs.UniVlan = of.VlanNone
2798 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2799 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2800 }
2801 case "vs.VlanControl: OLTSVlan":
2802 vs.VlanControl = OLTSVlan
2803 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2804 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2805 }
2806 }
2807 })
2808 }
2809}
2810
2811func TestVoltService_setDSMatchActionVlanT1(t *testing.T) {
2812 type args struct {
2813 flow *of.VoltSubFlow
2814 }
2815 tests := []struct {
2816 name string
2817 args args
2818 wantErr bool
2819 }{
2820 {
2821 name: "vs.VlanControl: ONUCVlanOLTSVlan",
2822 args: args{
2823 flow: &of.VoltSubFlow{
2824 ErrorReason: "test_error_reason",
2825 Cookie: uint64(1),
2826 OldCookie: uint64(2),
2827 TableID: uint32(3),
2828 Priority: uint32(4),
2829 State: uint8(5),
2830 },
2831 },
2832 },
2833 {
2834 name: "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone",
2835 args: args{
2836 flow: &of.VoltSubFlow{
2837 ErrorReason: "test_error_reason",
2838 Cookie: uint64(1),
2839 OldCookie: uint64(2),
2840 TableID: uint32(3),
2841 Priority: uint32(4),
2842 State: uint8(5),
2843 },
2844 },
2845 },
2846 {
2847 name: "vs.VlanControl: OLTCVlanOLTSVlan",
2848 args: args{
2849 flow: &of.VoltSubFlow{
2850 ErrorReason: "test_error_reason",
2851 Cookie: uint64(1),
2852 OldCookie: uint64(2),
2853 TableID: uint32(3),
2854 Priority: uint32(4),
2855 State: uint8(5),
2856 },
2857 },
2858 },
2859 {
2860 name: "vs.VlanControl: ONUCVlan",
2861 args: args{
2862 flow: &of.VoltSubFlow{
2863 ErrorReason: "test_error_reason",
2864 Cookie: uint64(1),
2865 OldCookie: uint64(2),
2866 TableID: uint32(3),
2867 Priority: uint32(4),
2868 State: uint8(5),
2869 },
2870 },
2871 },
2872 {
2873 name: "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone",
2874 args: args{
2875 flow: &of.VoltSubFlow{
2876 ErrorReason: "test_error_reason",
2877 Cookie: uint64(1),
2878 OldCookie: uint64(2),
2879 TableID: uint32(3),
2880 Priority: uint32(4),
2881 State: uint8(5),
2882 },
2883 },
2884 },
2885 {
2886 name: "vs.VlanControl: OLTSVlan",
2887 args: args{
2888 flow: &of.VoltSubFlow{
2889 ErrorReason: "test_error_reason",
2890 Cookie: uint64(1),
2891 OldCookie: uint64(2),
2892 TableID: uint32(3),
2893 Priority: uint32(4),
2894 State: uint8(5),
2895 },
2896 },
2897 },
2898 {
2899 name: "vs.VlanControl: default",
2900 args: args{
2901 flow: &of.VoltSubFlow{
2902 ErrorReason: "test_error_reason",
2903 Cookie: uint64(1),
2904 OldCookie: uint64(2),
2905 TableID: uint32(3),
2906 Priority: uint32(4),
2907 State: uint8(5),
2908 },
2909 },
2910 },
2911 }
2912 for _, tt := range tests {
2913 t.Run(tt.name, func(t *testing.T) {
2914 vs := &VoltService{}
2915 switch tt.name {
2916 case "vs.VlanControl: ONUCVlanOLTSVlan":
2917 vs.VlanControl = ONUCVlanOLTSVlan
2918 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2919 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2920 }
2921 case "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone":
2922 vs.VlanControl = ONUCVlanOLTSVlan
2923 vs.UniVlan = of.VlanNone
2924 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2925 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2926 }
2927 case "vs.VlanControl: OLTCVlanOLTSVlan":
2928 vs.VlanControl = OLTCVlanOLTSVlan
2929 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2930 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2931 }
2932 case "vs.VlanControl: ONUCVlan":
2933 vs.VlanControl = ONUCVlan
2934 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2935 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2936 }
2937 case "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone":
2938 vs.VlanControl = ONUCVlan
2939 vs.UniVlan = of.VlanNone
2940 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2941 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2942 }
2943 case "vs.VlanControl: OLTSVlan":
2944 vs.VlanControl = OLTSVlan
2945 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2946 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2947 }
2948 case "vs.VlanControl: default":
2949 vs.VlanControl = 6
2950 err := vs.setDSMatchActionVlanT1(tt.args.flow)
2951 assert.NotNil(t, err)
2952 }
2953 })
2954 }
2955}
2956
2957func TestVoltService_SetIpv6Addr(t *testing.T) {
2958 type args struct {
2959 addr net.IP
2960 }
2961 tests := []struct {
2962 name string
2963 args args
2964 }{
2965 {
2966 name: "SetIpv6Addr",
2967 args: args{
2968 addr: AllSystemsMulticastGroupIP,
2969 },
2970 },
2971 }
2972 for _, tt := range tests {
2973 t.Run(tt.name, func(t *testing.T) {
2974 vs := &VoltService{}
2975 vs.SetIpv6Addr(tt.args.addr)
2976 })
2977 }
2978}
2979
2980func TestVoltService_SetIpv4Addr(t *testing.T) {
2981 type args struct {
2982 addr net.IP
2983 }
2984 tests := []struct {
2985 name string
2986 args args
2987 }{
2988 {
2989 name: "VoltService_SetIpv4Addr",
2990 args: args{
2991 addr: AllSystemsMulticastGroupIP,
2992 },
2993 },
2994 }
2995 for _, tt := range tests {
2996 t.Run(tt.name, func(t *testing.T) {
2997 vs := &VoltService{}
2998 vs.SetIpv4Addr(tt.args.addr)
2999 })
3000 }
3001}
3002
3003func TestVoltService_SetMacAddr(t *testing.T) {
3004 type args struct {
3005 addr net.HardwareAddr
3006 }
3007 tests := []struct {
3008 name string
3009 args args
3010 }{
3011 {
3012 name: "VoltService_SetMacAddr",
3013 args: args{
3014 addr: BroadcastMAC,
3015 },
3016 },
3017 }
3018 for _, tt := range tests {
3019 t.Run(tt.name, func(t *testing.T) {
3020 vs := &VoltService{}
3021 vs.SetMacAddr(tt.args.addr)
3022 })
3023 }
3024}
3025
3026func TestVoltService_GetCircuitID(t *testing.T) {
3027 tests := []struct {
3028 name string
3029 want []byte
3030 }{
3031 {
3032 name: "VoltService_GetCircuitID",
3033 },
3034 }
3035 for _, tt := range tests {
3036 t.Run(tt.name, func(t *testing.T) {
3037 vs := &VoltService{}
3038 _ = vs.GetCircuitID()
3039 })
3040 }
3041}
3042
3043func TestVoltService_GetRemoteID(t *testing.T) {
3044 tests := []struct {
3045 name string
3046 want []byte
3047 }{
3048 {
3049 name: "VoltService_GetRemoteID",
3050 },
3051 }
3052 for _, tt := range tests {
3053 t.Run(tt.name, func(t *testing.T) {
3054 vs := &VoltService{}
3055 _ = vs.GetRemoteID()
3056 })
3057 }
3058}
3059
3060func TestVoltService_IPAssigned(t *testing.T) {
3061 tests := []struct {
3062 name string
3063 want bool
3064 }{
3065 {
3066 name: "VoltService_IPAssigned",
3067 },
3068 }
3069 for _, tt := range tests {
3070 t.Run(tt.name, func(t *testing.T) {
3071 vs := &VoltService{}
3072 _ = vs.IPAssigned()
3073 })
3074 }
3075}