blob: 5a26bea0bceeeca30d81254f4ea4e1adcd1da548 [file] [log] [blame]
vinokuma703a70b2023-07-17 10:06:43 +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"
vinokuma04dc9f82023-07-31 15:47:49 +053020 "encoding/json"
21 "net"
vinokuma703a70b2023-07-17 10:06:43 +053022 "reflect"
vinokuma04dc9f82023-07-31 15:47:49 +053023 "sync"
vinokuma703a70b2023-07-17 10:06:43 +053024 "testing"
25 cntlr "voltha-go-controller/internal/pkg/controller"
26 "voltha-go-controller/internal/pkg/of"
27 "voltha-go-controller/internal/pkg/util"
28 "voltha-go-controller/internal/test/mocks"
29
30 "github.com/golang/mock/gomock"
vinokuma04dc9f82023-07-31 15:47:49 +053031 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
vinokuma703a70b2023-07-17 10:06:43 +053032 "github.com/stretchr/testify/assert"
33)
34
35func TestVoltPortVnet_JSONMarshal(t *testing.T) {
36 tests := []struct {
37 name string
38 want []byte
39 wantErr bool
40 }{
41 {
42 name: "VoltPortVnet_JSONMarshal",
43 },
44 }
45 for _, tt := range tests {
46 t.Run(tt.name, func(t *testing.T) {
47 vpv := &VoltPortVnet{}
48 _, err := vpv.JSONMarshal()
49 if (err != nil) != tt.wantErr {
50 t.Errorf("VoltPortVnet.JSONMarshal() error = %v, wantErr %v", err, tt.wantErr)
51 return
52 }
53 })
54 }
55}
56
57func TestVoltPortVnet_IsServiceActivated(t *testing.T) {
58 type args struct {
59 cntx context.Context
60 }
61 tests := []struct {
62 name string
63 args args
64 want bool
65 }{
66 {
67 name: "VoltPortVnet_IsServiceActivated",
68 args: args{
69 cntx: context.Background(),
70 },
71 },
72 }
73 for _, tt := range tests {
74 t.Run(tt.name, func(t *testing.T) {
75 vpv := &VoltPortVnet{}
76 voltServ := &VoltService{
77 VoltServiceOper: VoltServiceOper{
78 Device: test_device,
79 ForceDelete: true,
80 },
81 }
82 vpv.services.Store(test_device, voltServ)
83 if got := vpv.IsServiceActivated(tt.args.cntx); got != tt.want {
84 t.Errorf("VoltPortVnet.IsServiceActivated() = %v, want %v", got, tt.want)
85 }
86 })
87 }
88}
89
90func TestVoltVnet_JSONMarshal(t *testing.T) {
91 tests := []struct {
92 name string
93 want []byte
94 wantErr bool
95 }{
96 {
97 name: "VoltVnet_JSONMarshal",
98 },
99 }
100 for _, tt := range tests {
101 t.Run(tt.name, func(t *testing.T) {
102 vv := &VoltVnet{}
103 _, err := vv.JSONMarshal()
104 if (err != nil) != tt.wantErr {
105 t.Errorf("VoltVnet.JSONMarshal() error = %v, wantErr %v", err, tt.wantErr)
106 return
107 }
108 })
109 }
110}
111
112func TestVoltVnet_TriggerAssociatedFlowDelete(t *testing.T) {
113 type args struct {
114 cntx context.Context
115 device string
116 }
117 tests := []struct {
118 name string
119 args args
120 want bool
121 }{
122 {
123 name: "VoltVnet_TriggerAssociatedFlowDelete",
124 args: args{
125 cntx: context.Background(),
126 device: test_device,
127 },
128 want: true,
129 },
130 {
131 name: "cookieList_empty",
132 args: args{
133 cntx: context.Background(),
134 device: test_device,
135 },
136 want: false,
137 },
138 }
139 for _, tt := range tests {
140 t.Run(tt.name, func(t *testing.T) {
141 vv := &VoltVnet{}
142 switch tt.name {
143 case "VoltVnet_TriggerAssociatedFlowDelete":
144 cookie := map[string]bool{}
145 cookie["1234"] = true
146 pendingDeleteFlow := map[string]map[string]bool{}
147 pendingDeleteFlow[test_device] = cookie
148 vv.PendingDeleteFlow = pendingDeleteFlow
149 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
150 db = dbintf
151 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
152 if got := vv.TriggerAssociatedFlowDelete(tt.args.cntx, tt.args.device); got != tt.want {
153 t.Errorf("VoltVnet.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want)
154 }
155 case "cookieList_empty":
156 if got := vv.TriggerAssociatedFlowDelete(tt.args.cntx, tt.args.device); got != tt.want {
157 t.Errorf("VoltVnet.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want)
158 }
159 }
160 })
161 }
162}
163
164func TestVoltApplication_GetMatchingMcastService(t *testing.T) {
165 type args struct {
166 port string
167 device string
168 cvlan of.VlanType
169 }
170 tests := []struct {
171 name string
172 args args
173 want *VoltService
174 }{
175 {
176 name: "VoltApplication_GetMatchingMcastService",
177 args: args{
178 port: "test_port",
179 device: test_device,
180 cvlan: of.VlanAny,
181 },
182 },
183 {
184 name: "dIntf_error",
185 args: args{
186 port: "test_port",
187 device: test_device,
188 cvlan: of.VlanAny,
189 },
190 },
191 {
192 name: "port == d.NniPort",
193 args: args{
194 port: "test_port",
195 device: test_device,
196 cvlan: of.VlanAny,
197 },
198 },
199 {
200 name: "vnets_error",
201 args: args{
202 port: "",
203 device: test_device,
204 cvlan: of.VlanAny,
205 },
206 },
207 }
208 for _, tt := range tests {
209 t.Run(tt.name, func(t *testing.T) {
210 va := &VoltApplication{}
211 switch tt.name {
212 case "VoltApplication_GetMatchingMcastService":
213 va.DevicesDisc.Store(test_device, voltDevice)
214 va.VnetsByPort.Store("test_port", voltPortVnet1)
215 if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) {
216 t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want)
217 }
218 case "dIntf_error":
219 if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) {
220 t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want)
221 }
222 case "port == d.NniPort":
223 va.DevicesDisc.Store(test_device, voltDevice)
224 voltDevice.NniPort = "test_port"
225 if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) {
226 t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want)
227 }
228 case "vnets_error":
229 va.DevicesDisc.Store(test_device, voltDevice)
230 va.VnetsByPort.Store("test_port1", voltPortVnet1)
231 if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) {
232 t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want)
233 }
234 }
235 })
236 }
237}
238
239func TestVoltPortVnet_IgmpFlowInstallFailure(t *testing.T) {
240 type args struct {
241 cookie string
242 errorCode uint32
243 errReason string
244 }
245 tests := []struct {
246 name string
247 args args
248 }{
249 {
250 name: "VoltPortVnet_IgmpFlowInstallFailure",
251 args: args{
252 cookie: "test_cookie",
253 errorCode: uint32(1),
254 errReason: "errReason",
255 },
256 },
257 }
258 for _, tt := range tests {
259 t.Run(tt.name, func(t *testing.T) {
260 vpv := &VoltPortVnet{}
261 switch tt.name {
262 case "VoltPortVnet_IgmpFlowInstallFailure":
263 voltService.IgmpEnabled = true
264 vpv.services.Store("test_cookie", voltService)
265 vpv.IgmpFlowInstallFailure(tt.args.cookie, tt.args.errorCode, tt.args.errReason)
266 }
267 })
268 }
269}
270
271func TestVoltVnet_FlowRemoveFailure(t *testing.T) {
272 type args struct {
273 cntx context.Context
274 cookie string
275 device string
276 errorCode uint32
277 errReason string
278 }
279 tests := []struct {
280 name string
281 args args
282 }{
283 {
284 name: "VoltVnet_FlowRemoveFailure",
285 args: args{
286 cntx: context.Background(),
287 cookie: "1234",
288 device: test_device,
289 },
290 },
291 {
292 name: "mismatch_cookie",
293 args: args{
294 cntx: context.Background(),
295 cookie: "1234",
296 device: test_device,
297 },
298 },
299 }
300 for _, tt := range tests {
301 t.Run(tt.name, func(t *testing.T) {
302 vv := &VoltVnet{}
303 switch tt.name {
304 case "VoltVnet_FlowRemoveFailure":
305 cookie := map[string]bool{}
306 cookie["1234"] = true
307 pendingDeleteFlow := map[string]map[string]bool{}
308 pendingDeleteFlow[test_device] = cookie
309 vv.PendingDeleteFlow = pendingDeleteFlow
310 vv.DeleteInProgress = true
311 vv.Name = "test_name"
312 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
313 db = dbintf
314 dbintf.EXPECT().DelVnet(tt.args.cntx, "test_name").Return(nil).Times(1)
315 vv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason)
316 case "mismatch_cookie":
317 cookie := map[string]bool{}
318 cookie["12345"] = true
319 pendingDeleteFlow := map[string]map[string]bool{}
320 pendingDeleteFlow[test_device] = cookie
321 vv.PendingDeleteFlow = pendingDeleteFlow
322 vv.DeleteInProgress = true
323 vv.Name = "test_name"
324 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
325 db = dbintf
326 dbintf.EXPECT().DelVnet(tt.args.cntx, "test_name").Return(nil).Times(1)
327 vv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason)
328 }
329 })
330 }
331}
332
333func TestVoltVnet_FlowRemoveSuccess(t *testing.T) {
334 type args struct {
335 cntx context.Context
336 cookie string
337 device string
338 }
339 tests := []struct {
340 name string
341 args args
342 }{
343 {
344 name: "VoltVnet_FlowRemoveSuccess",
345 args: args{
346 cntx: context.Background(),
347 cookie: "1234",
348 device: test_device,
349 },
350 },
351 }
352 for _, tt := range tests {
353 t.Run(tt.name, func(t *testing.T) {
354 vv := &VoltVnet{}
355 cookie := map[string]bool{}
356 cookie["1234"] = true
357 pendingDeleteFlow := map[string]map[string]bool{}
358 pendingDeleteFlow[test_device] = cookie
359 vv.PendingDeleteFlow = pendingDeleteFlow
360 ga := GetApplication()
361 voltDevice.ConfiguredVlanForDeviceFlows = util.NewConcurrentMap()
362 ga.DevicesDisc.Store(test_device, voltDevice)
363 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
364 db = dbintf
365 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
366 vv.FlowRemoveSuccess(tt.args.cntx, tt.args.cookie, tt.args.device)
367 })
368 }
369}
370
371func TestVoltPortVnet_FlowRemoveFailure(t *testing.T) {
372 type args struct {
373 cntx context.Context
374 cookie string
375 device string
376 errorCode uint32
377 errReason string
378 }
379 tests := []struct {
380 name string
381 args args
382 }{
383 {
384 name: "VoltPortVnet_FlowRemoveFailure",
385 args: args{
386 cntx: context.Background(),
387 cookie: "1234",
388 device: test_device,
389 },
390 },
391 {
392 name: "DeleteInProgress_false",
393 args: args{
394 cntx: context.Background(),
395 cookie: "1234",
396 device: test_device,
397 },
398 },
399 }
400 for _, tt := range tests {
401 t.Run(tt.name, func(t *testing.T) {
402 vpv := &VoltPortVnet{}
403 switch tt.name {
404 case "VoltPortVnet_FlowRemoveFailure":
405 vpv.services.Store("1234", voltService)
406 vpv.DeleteInProgress = true
407 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
408 db = dbintf
409 dbintf.EXPECT().DelVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
410 vpv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason)
411 case "DeleteInProgress_false":
412 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
413 db = dbintf
414 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
415 vpv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason)
416 }
417 })
418 }
419}
420
421func TestVoltPortVnet_PushFlows(t *testing.T) {
422 type args struct {
423 cntx context.Context
424 device *VoltDevice
425 flow *of.VoltFlow
426 }
427 vsf := make(map[uint64]*of.VoltSubFlow)
428 vsf[uint64(1)] = &of.VoltSubFlow{
429 Cookie: uint64(1234),
430 }
431 tests := []struct {
432 name string
433 args args
434 wantErr bool
435 }{
436 {
437 name: "VoltPortVnet_PushFlows",
438 args: args{
439 cntx: context.Background(),
440 device: voltDevice,
441 flow: &of.VoltFlow{
442 PortName: "test_port",
443 SubFlows: vsf,
444 },
445 },
446 },
447 }
448 for _, tt := range tests {
449 t.Run(tt.name, func(t *testing.T) {
450 vpv := &VoltPortVnet{}
451 _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
452 err := vpv.PushFlows(tt.args.cntx, tt.args.device, tt.args.flow)
453 assert.NotNil(t, err)
454 })
455 }
456}
457
458func TestVoltPortVnet_isVlanMatching(t *testing.T) {
459 type args struct {
460 cvlan of.VlanType
461 svlan of.VlanType
462 }
463 tests := []struct {
464 name string
465 args args
466 want bool
467 }{
468 {
469 name: "VoltPortVnet_isVlanMatching",
470 args: args{
471 cvlan: of.VlanAny,
472 svlan: of.VlanAny,
473 },
474 want: true,
475 },
476 {
477 name: "vpv.VlanControl_nil",
478 args: args{
479 cvlan: of.VlanAny,
480 svlan: of.VlanAny,
481 },
482 want: true,
483 },
484 }
485 for _, tt := range tests {
486 t.Run(tt.name, func(t *testing.T) {
487 vpv := &VoltPortVnet{}
488 switch tt.name {
489 case "VoltPortVnet_isVlanMatching":
490 vpv.VlanControl = ONUCVlanOLTSVlan
491 vpv.SVlan = of.VlanAny
492 vpv.CVlan = of.VlanAny
493 if got := vpv.isVlanMatching(tt.args.cvlan, tt.args.svlan); got != tt.want {
494 t.Errorf("VoltPortVnet.isVlanMatching() = %v, want %v", got, tt.want)
495 }
496 }
497 })
498 }
499}
500
501func TestProcessIcmpv6McGroup(t *testing.T) {
502 type args struct {
503 device string
504 delete bool
505 }
506 tests := []struct {
507 name string
508 args args
509 wantErr bool
510 }{
511 {
512 name: "TestProcessIcmpv6McGroup",
513 args: args{
514 device: test_device,
515 delete: false,
516 },
517 },
518 }
519 for _, tt := range tests {
520 t.Run(tt.name, func(t *testing.T) {
521 err := ProcessIcmpv6McGroup(tt.args.device, tt.args.delete)
522 assert.NotNil(t, err)
523 })
524 }
525}
526
527func TestVoltVnet_setPbitRemarking(t *testing.T) {
528 tests := []struct {
529 name string
530 want uint32
531 }{
532 {
533 name: "VoltVnet_setPbitRemarking",
534 },
535 }
536 for _, tt := range tests {
537 t.Run(tt.name, func(t *testing.T) {
538 vv := &VoltVnet{}
539 a := make(map[of.PbitType]of.PbitType)
540 a[of.PbitMatchAll] = of.PbitMatchAll
541 vv.CtrlPktPbitRemark = a
542 if got := vv.setPbitRemarking(); got != tt.want {
543 t.Errorf("VoltVnet.setPbitRemarking() = %v, want %v", got, tt.want)
544 }
545 })
546 }
547}
548
549func TestBuildDSArpFlow(t *testing.T) {
550 type args struct {
551 inport uint32
552 vnet *VoltVnet
553 }
554 tests := []struct {
555 name string
556 args args
557 want *of.VoltFlow
558 }{
559 {
560 name: "BuildDSArpFlow",
561 args: args{
562 inport: uint32(1),
563 vnet: &VoltVnet{
564 Version: "test_version",
565 },
566 },
567 },
568 }
569 for _, tt := range tests {
570 t.Run(tt.name, func(t *testing.T) {
571 switch tt.name {
572 case "BuildDSArpFlow":
573 got := BuildDSArpFlow(tt.args.inport, tt.args.vnet)
574 assert.NotNil(t, got)
575 }
576 })
577 }
578}
579
580func TestBuildICMPv6Flow(t *testing.T) {
581 type args struct {
582 inport uint32
583 vnet *VoltVnet
584 }
585 tests := []struct {
586 name string
587 args args
588 want *of.VoltFlow
589 }{
590 {
591 name: "BuildICMPv6Flow",
592 args: args{
593 inport: uint32(1),
594 vnet: &VoltVnet{
595 Version: "test_version",
596 },
597 },
598 },
599 }
600 for _, tt := range tests {
601 t.Run(tt.name, func(t *testing.T) {
602 got := BuildICMPv6Flow(tt.args.inport, tt.args.vnet)
603 assert.NotNil(t, got)
604 })
605 }
606}
607
608func TestVoltApplication_DeleteDevFlowForVlanFromDevice(t *testing.T) {
609 type args struct {
610 cntx context.Context
611 vnet *VoltVnet
612 deviceSerialNum string
613 }
614 tests := []struct {
615 name string
616 args args
617 }{
618 {
619 name: "device.SerialNum != deviceSerialNum",
620 args: args{
621 cntx: context.Background(),
622 vnet: &VoltVnet{
623 Version: "test_version",
624 },
625 },
626 },
627 {
628 name: "VoltApplication_DeleteDevFlowForVlanFromDevice",
629 args: args{
630 cntx: context.Background(),
631 vnet: &VoltVnet{
632 Version: "test_version",
633 },
634 deviceSerialNum: "test_serial_number",
635 },
636 },
637 }
638 for _, tt := range tests {
639 t.Run(tt.name, func(t *testing.T) {
640 va := &VoltApplication{}
641 switch tt.name {
642 case "device.SerialNum != deviceSerialNum":
643 va.DevicesDisc.Store(test_device, voltDevice)
644 va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum)
645 case "VoltApplication_DeleteDevFlowForVlanFromDevice":
646 va.DevicesDisc.Store(test_device, voltDevice)
647 va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum)
648 }
649 })
650 }
651}
vinokuma04dc9f82023-07-31 15:47:49 +0530652
653func TestVoltApplication_RestoreVnetsFromDb(t *testing.T) {
654 type args struct {
655 cntx context.Context
656 }
657 tests := []struct {
658 name string
659 args args
660 }{
661 {
662 name: "VoltApplication_RestoreVnetsFromDb",
663 args: args{
664 cntx: context.Background(),
665 },
666 },
667 }
668 for _, tt := range tests {
669 t.Run(tt.name, func(t *testing.T) {
670 vnetsToDelete := map[string]bool{}
671 vnetsToDelete["test_name"] = true
672 va := &VoltApplication{
673 VnetsBySvlan: util.NewConcurrentMap(),
674 VnetsToDelete: vnetsToDelete,
675 }
676 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
677 db = dbintf
678 vnets := map[string]*kvstore.KVPair{}
679 voltVnet.SVlan = of.VlanAny
680 b, err := json.Marshal(voltVnet)
681 if err != nil {
682 panic(err)
683 }
684 vnets["test_device_id"] = &kvstore.KVPair{
685 Key: "test_device_id",
686 Value: b,
687 }
688 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
689 dbintf.EXPECT().GetVnets(tt.args.cntx).Return(vnets, nil)
690 va.RestoreVnetsFromDb(tt.args.cntx)
691 })
692 }
693}
694
695func TestVoltApplication_DeleteDevFlowForDevice(t *testing.T) {
696 type args struct {
697 cntx context.Context
698 device *VoltDevice
699 }
700 tests := []struct {
701 name string
702 args args
703 }{
704 {
705 name: "VoltApplication_DeleteDevFlowForDevice",
706 args: args{
707 cntx: context.Background(),
708 device: &VoltDevice{
709 Name: test_device,
710 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
711 },
712 },
713 },
714 }
715 var voltVnet_DeleteDevFlowForDevice = &VoltVnet{
716 Version: "test_version",
717 VnetConfig: VnetConfig{
718 Name: "test_name",
719 SVlan: of.VlanAny,
720 CVlan: of.VlanAny,
721 },
722 }
723 for _, tt := range tests {
724 t.Run(tt.name, func(t *testing.T) {
725 va := &VoltApplication{}
726 va.VnetsByName.Store("4096-4096-0", voltVnet_DeleteDevFlowForDevice)
727 //tt.args.device.ConfiguredVlanForDeviceFlows.SyncMap.Store("4096-4069-0", util.NewConcurrentMap())
728 va.DeleteDevFlowForDevice(tt.args.cntx, tt.args.device)
729 })
730 }
731}
732
733func TestVoltApplication_DelVnetFromPort(t *testing.T) {
734 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
735 vpv_test := []*VoltPortVnet{
736 {
737 Device: test_device,
738 Port: "test_port",
739 MacAddr: macAdd,
740 VnetName: "test_vnet_name",
741 },
742 }
743 type args struct {
744 cntx context.Context
745 port string
746 vpv *VoltPortVnet
747 }
748 tests := []struct {
749 name string
750 args args
751 }{
752 {
753 name: "VoltApplication_DelVnetFromPort",
754 args: args{
755 cntx: context.Background(),
756 port: "test_port",
757 vpv: &VoltPortVnet{
758 Device: test_device,
759 Port: "test_port",
760 MacAddr: macAdd,
761 VnetName: "test_vnet_name",
762 },
763 },
764 },
765 }
766 for _, tt := range tests {
767 t.Run(tt.name, func(t *testing.T) {
768 va := &VoltApplication{}
769 va.VnetsByPort.Store("test_port", vpv_test)
770 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
771 db = dbintf
772 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
773 dbintf.EXPECT().DelVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
774 va.VnetsByName.Store("test_vnet_name", &VoltVnet{
775 Version: "test_version",
776 })
777 va.DelVnetFromPort(tt.args.cntx, tt.args.port, tt.args.vpv)
778 })
779 }
780}
781
782func TestVoltApplication_PushDevFlowForVlan(t *testing.T) {
783 type args struct {
784 cntx context.Context
785 vnet *VoltVnet
786 }
787 tests := []struct {
788 name string
789 args args
790 }{
791 {
792 name: "VoltApplication_PushDevFlowForVlan",
793 args: args{
794 cntx: context.Background(),
795 vnet: &VoltVnet{
796 Version: "test_version",
797 VnetConfig: VnetConfig{
798 DevicesList: []string{"test_serialNum"},
799 SVlan: of.VlanAny,
800 },
801 },
802 },
803 },
804 }
805 for _, tt := range tests {
806 t.Run(tt.name, func(t *testing.T) {
807 va := &VoltApplication{}
808 voltDevice.SerialNum = "test_serialNum"
809 voltDevice.VlanPortStatus.Store(uint16(of.VlanAny), true)
810 voltDevice.Name = test_device
811 va.DevicesDisc.Store(test_device, voltDevice)
812 ga := GetApplication()
813 ga.DevicesDisc.Store(test_device, voltDevice)
814 _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
815 va.PushDevFlowForVlan(tt.args.cntx, tt.args.vnet)
816 })
817 }
818}
819
820func TestVoltApplication_PushDevFlowForDevice(t *testing.T) {
821 type args struct {
822 cntx context.Context
823 device *VoltDevice
824 }
825 tests := []struct {
826 name string
827 args args
828 }{
829 {
830 name: "device.ConfiguredVlanForDeviceFlows is ok",
831 args: args{
832 cntx: context.Background(),
833 device: &VoltDevice{
834 Name: test_device,
835 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
836 },
837 },
838 },
839 {
840 name: "device.VlanPortStatus is false",
841 args: args{
842 cntx: context.Background(),
843 device: &VoltDevice{
844 Name: test_device,
845 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
846 NniPort: "test_nni_port",
847 },
848 },
849 },
850 {
851 name: "device.VlanPortStatus is true",
852 args: args{
853 cntx: context.Background(),
854 device: &VoltDevice{
855 Name: test_device,
856 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
857 NniPort: "test_nni_port",
858 VlanPortStatus: sync.Map{},
859 },
860 },
861 },
862 }
863 for _, tt := range tests {
864 t.Run(tt.name, func(t *testing.T) {
865 va := &VoltApplication{}
866 switch tt.name {
867 case "device.ConfiguredVlanForDeviceFlows is ok":
868 va.VnetsByName.Store("test_vnet_name", &VoltVnet{
869 Version: "test_version",
870 })
871 tt.args.device.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap())
872 va.PushDevFlowForDevice(tt.args.cntx, tt.args.device)
873 case "device.VlanPortStatus is false":
874 va.VnetsByName.Store("test_vnet_name", &VoltVnet{
875 Version: "test_version",
876 })
877 va.PortsDisc.Store("test_nni_port", &VoltPort{
878 Name: "test_name",
879 })
880 va.PushDevFlowForDevice(tt.args.cntx, tt.args.device)
881 case "device.VlanPortStatus is true":
882 va.VnetsByName.Store("test_vnet_name", &VoltVnet{
883 Version: "test_version",
884 VnetConfig: VnetConfig{
885 SVlan: of.VlanAny,
886 },
887 })
888 va.PortsDisc.Store("test_nni_port", &VoltPort{
889 Name: "test_name",
890 })
891 tt.args.device.VlanPortStatus.Store(uint16(of.VlanAny), true)
892 va.PushDevFlowForDevice(tt.args.cntx, tt.args.device)
893 }
894 })
895 }
896}