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