blob: a2e5b0a78389296af06b987fd2b5ae0cb02f485d [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"
Akash Sonib03636c2023-10-31 12:30:59 +053025 "voltha-go-controller/internal/pkg/controller"
vinokuma703a70b2023-07-17 10:06:43 +053026 cntlr "voltha-go-controller/internal/pkg/controller"
27 "voltha-go-controller/internal/pkg/of"
28 "voltha-go-controller/internal/pkg/util"
29 "voltha-go-controller/internal/test/mocks"
30
31 "github.com/golang/mock/gomock"
Akash Soni230e6212023-10-16 10:46:07 +053032 "github.com/google/gopacket/layers"
vinokuma04dc9f82023-07-31 15:47:49 +053033 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
vinokuma703a70b2023-07-17 10:06:43 +053034 "github.com/stretchr/testify/assert"
Akash Soni230e6212023-10-16 10:46:07 +053035 "go.uber.org/atomic"
vinokuma703a70b2023-07-17 10:06:43 +053036)
37
Akash Sonib03636c2023-10-31 12:30:59 +053038const deviceName = "SDX6320031"
39
vinokuma703a70b2023-07-17 10:06:43 +053040func TestVoltPortVnet_JSONMarshal(t *testing.T) {
41 tests := []struct {
42 name string
43 want []byte
44 wantErr bool
45 }{
46 {
47 name: "VoltPortVnet_JSONMarshal",
48 },
49 }
50 for _, tt := range tests {
51 t.Run(tt.name, func(t *testing.T) {
52 vpv := &VoltPortVnet{}
53 _, err := vpv.JSONMarshal()
54 if (err != nil) != tt.wantErr {
55 t.Errorf("VoltPortVnet.JSONMarshal() error = %v, wantErr %v", err, tt.wantErr)
56 return
57 }
58 })
59 }
60}
61
62func TestVoltPortVnet_IsServiceActivated(t *testing.T) {
63 type args struct {
64 cntx context.Context
65 }
66 tests := []struct {
67 name string
68 args args
69 want bool
70 }{
71 {
72 name: "VoltPortVnet_IsServiceActivated",
73 args: args{
74 cntx: context.Background(),
75 },
76 },
77 }
78 for _, tt := range tests {
79 t.Run(tt.name, func(t *testing.T) {
80 vpv := &VoltPortVnet{}
81 voltServ := &VoltService{
82 VoltServiceOper: VoltServiceOper{
83 Device: test_device,
84 ForceDelete: true,
85 },
86 }
87 vpv.services.Store(test_device, voltServ)
Sridhar Ravindrab76eb162025-07-02 01:25:10 +053088 if got, _ := vpv.IsServiceActivated(tt.args.cntx); got != tt.want {
vinokuma703a70b2023-07-17 10:06:43 +053089 t.Errorf("VoltPortVnet.IsServiceActivated() = %v, want %v", got, tt.want)
90 }
91 })
92 }
93}
94
95func TestVoltVnet_JSONMarshal(t *testing.T) {
96 tests := []struct {
97 name string
98 want []byte
99 wantErr bool
100 }{
101 {
102 name: "VoltVnet_JSONMarshal",
103 },
104 }
105 for _, tt := range tests {
106 t.Run(tt.name, func(t *testing.T) {
107 vv := &VoltVnet{}
108 _, err := vv.JSONMarshal()
109 if (err != nil) != tt.wantErr {
110 t.Errorf("VoltVnet.JSONMarshal() error = %v, wantErr %v", err, tt.wantErr)
111 return
112 }
113 })
114 }
115}
116
117func TestVoltVnet_TriggerAssociatedFlowDelete(t *testing.T) {
118 type args struct {
119 cntx context.Context
120 device string
121 }
122 tests := []struct {
123 name string
124 args args
125 want bool
126 }{
127 {
128 name: "VoltVnet_TriggerAssociatedFlowDelete",
129 args: args{
130 cntx: context.Background(),
131 device: test_device,
132 },
133 want: true,
134 },
135 {
136 name: "cookieList_empty",
137 args: args{
138 cntx: context.Background(),
139 device: test_device,
140 },
141 want: false,
142 },
143 }
144 for _, tt := range tests {
145 t.Run(tt.name, func(t *testing.T) {
146 vv := &VoltVnet{}
147 switch tt.name {
148 case "VoltVnet_TriggerAssociatedFlowDelete":
149 cookie := map[string]bool{}
150 cookie["1234"] = true
151 pendingDeleteFlow := map[string]map[string]bool{}
152 pendingDeleteFlow[test_device] = cookie
153 vv.PendingDeleteFlow = pendingDeleteFlow
154 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
155 db = dbintf
156 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
157 if got := vv.TriggerAssociatedFlowDelete(tt.args.cntx, tt.args.device); got != tt.want {
158 t.Errorf("VoltVnet.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want)
159 }
160 case "cookieList_empty":
161 if got := vv.TriggerAssociatedFlowDelete(tt.args.cntx, tt.args.device); got != tt.want {
162 t.Errorf("VoltVnet.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want)
163 }
164 }
165 })
166 }
167}
168
169func TestVoltApplication_GetMatchingMcastService(t *testing.T) {
170 type args struct {
171 port string
172 device string
173 cvlan of.VlanType
174 }
175 tests := []struct {
176 name string
177 args args
178 want *VoltService
179 }{
180 {
181 name: "VoltApplication_GetMatchingMcastService",
182 args: args{
183 port: "test_port",
184 device: test_device,
185 cvlan: of.VlanAny,
186 },
187 },
188 {
189 name: "dIntf_error",
190 args: args{
191 port: "test_port",
192 device: test_device,
193 cvlan: of.VlanAny,
194 },
195 },
196 {
197 name: "port == d.NniPort",
198 args: args{
199 port: "test_port",
200 device: test_device,
201 cvlan: of.VlanAny,
202 },
203 },
204 {
205 name: "vnets_error",
206 args: args{
207 port: "",
208 device: test_device,
209 cvlan: of.VlanAny,
210 },
211 },
212 }
213 for _, tt := range tests {
214 t.Run(tt.name, func(t *testing.T) {
215 va := &VoltApplication{}
216 switch tt.name {
217 case "VoltApplication_GetMatchingMcastService":
218 va.DevicesDisc.Store(test_device, voltDevice)
219 va.VnetsByPort.Store("test_port", voltPortVnet1)
220 if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) {
221 t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want)
222 }
223 case "dIntf_error":
224 if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) {
225 t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want)
226 }
227 case "port == d.NniPort":
228 va.DevicesDisc.Store(test_device, voltDevice)
Sridhar Ravindrab76eb162025-07-02 01:25:10 +0530229 voltDevice.NniPort = []string{"test_port"}
vinokuma703a70b2023-07-17 10:06:43 +0530230 if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) {
231 t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want)
232 }
233 case "vnets_error":
234 va.DevicesDisc.Store(test_device, voltDevice)
235 va.VnetsByPort.Store("test_port1", voltPortVnet1)
236 if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) {
237 t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want)
238 }
239 }
240 })
241 }
242}
243
244func TestVoltPortVnet_IgmpFlowInstallFailure(t *testing.T) {
245 type args struct {
246 cookie string
247 errorCode uint32
248 errReason string
249 }
250 tests := []struct {
251 name string
252 args args
253 }{
254 {
255 name: "VoltPortVnet_IgmpFlowInstallFailure",
256 args: args{
257 cookie: "test_cookie",
258 errorCode: uint32(1),
259 errReason: "errReason",
260 },
261 },
262 }
263 for _, tt := range tests {
264 t.Run(tt.name, func(t *testing.T) {
265 vpv := &VoltPortVnet{}
266 switch tt.name {
267 case "VoltPortVnet_IgmpFlowInstallFailure":
268 voltService.IgmpEnabled = true
269 vpv.services.Store("test_cookie", voltService)
270 vpv.IgmpFlowInstallFailure(tt.args.cookie, tt.args.errorCode, tt.args.errReason)
271 }
272 })
273 }
274}
275
276func TestVoltVnet_FlowRemoveFailure(t *testing.T) {
277 type args struct {
278 cntx context.Context
279 cookie string
280 device string
281 errorCode uint32
282 errReason string
283 }
284 tests := []struct {
285 name string
286 args args
287 }{
288 {
289 name: "VoltVnet_FlowRemoveFailure",
290 args: args{
291 cntx: context.Background(),
292 cookie: "1234",
293 device: test_device,
294 },
295 },
296 {
297 name: "mismatch_cookie",
298 args: args{
299 cntx: context.Background(),
300 cookie: "1234",
301 device: test_device,
302 },
303 },
304 }
305 for _, tt := range tests {
306 t.Run(tt.name, func(t *testing.T) {
307 vv := &VoltVnet{}
308 switch tt.name {
309 case "VoltVnet_FlowRemoveFailure":
310 cookie := map[string]bool{}
311 cookie["1234"] = true
312 pendingDeleteFlow := map[string]map[string]bool{}
313 pendingDeleteFlow[test_device] = cookie
314 vv.PendingDeleteFlow = pendingDeleteFlow
315 vv.DeleteInProgress = true
316 vv.Name = "test_name"
Abhay Kumarfe505f22025-11-10 14:16:31 +0000317 vv.VnetPortLock = sync.RWMutex{}
vinokuma703a70b2023-07-17 10:06:43 +0530318 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
319 db = dbintf
Abhay Kumarfe505f22025-11-10 14:16:31 +0000320 dbintf.EXPECT().DelVnet(tt.args.cntx, "test_name").Return(nil).AnyTimes()
vinokuma703a70b2023-07-17 10:06:43 +0530321 vv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason)
322 case "mismatch_cookie":
323 cookie := map[string]bool{}
324 cookie["12345"] = true
325 pendingDeleteFlow := map[string]map[string]bool{}
326 pendingDeleteFlow[test_device] = cookie
327 vv.PendingDeleteFlow = pendingDeleteFlow
328 vv.DeleteInProgress = true
329 vv.Name = "test_name"
Abhay Kumarfe505f22025-11-10 14:16:31 +0000330 vv.VnetPortLock = sync.RWMutex{}
vinokuma703a70b2023-07-17 10:06:43 +0530331 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
332 db = dbintf
Abhay Kumarfe505f22025-11-10 14:16:31 +0000333 dbintf.EXPECT().DelVnet(tt.args.cntx, "test_name").Return(nil).AnyTimes()
vinokuma703a70b2023-07-17 10:06:43 +0530334 vv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason)
335 }
336 })
337 }
338}
339
340func TestVoltVnet_FlowRemoveSuccess(t *testing.T) {
341 type args struct {
342 cntx context.Context
343 cookie string
344 device string
345 }
346 tests := []struct {
347 name string
348 args args
349 }{
350 {
351 name: "VoltVnet_FlowRemoveSuccess",
352 args: args{
353 cntx: context.Background(),
354 cookie: "1234",
355 device: test_device,
356 },
357 },
358 }
359 for _, tt := range tests {
360 t.Run(tt.name, func(t *testing.T) {
361 vv := &VoltVnet{}
362 cookie := map[string]bool{}
363 cookie["1234"] = true
364 pendingDeleteFlow := map[string]map[string]bool{}
365 pendingDeleteFlow[test_device] = cookie
366 vv.PendingDeleteFlow = pendingDeleteFlow
367 ga := GetApplication()
368 voltDevice.ConfiguredVlanForDeviceFlows = util.NewConcurrentMap()
369 ga.DevicesDisc.Store(test_device, voltDevice)
370 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
371 db = dbintf
372 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
373 vv.FlowRemoveSuccess(tt.args.cntx, tt.args.cookie, tt.args.device)
374 })
375 }
376}
377
378func TestVoltPortVnet_FlowRemoveFailure(t *testing.T) {
379 type args struct {
380 cntx context.Context
381 cookie string
382 device string
383 errorCode uint32
384 errReason string
385 }
386 tests := []struct {
387 name string
388 args args
389 }{
390 {
391 name: "VoltPortVnet_FlowRemoveFailure",
392 args: args{
393 cntx: context.Background(),
394 cookie: "1234",
395 device: test_device,
396 },
397 },
398 {
399 name: "DeleteInProgress_false",
400 args: args{
401 cntx: context.Background(),
402 cookie: "1234",
403 device: test_device,
404 },
405 },
406 }
407 for _, tt := range tests {
408 t.Run(tt.name, func(t *testing.T) {
409 vpv := &VoltPortVnet{}
410 switch tt.name {
411 case "VoltPortVnet_FlowRemoveFailure":
412 vpv.services.Store("1234", voltService)
413 vpv.DeleteInProgress = true
414 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
415 db = dbintf
416 dbintf.EXPECT().DelVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
417 vpv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason)
418 case "DeleteInProgress_false":
419 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
420 db = dbintf
421 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
422 vpv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason)
423 }
424 })
425 }
426}
427
428func TestVoltPortVnet_PushFlows(t *testing.T) {
429 type args struct {
430 cntx context.Context
431 device *VoltDevice
432 flow *of.VoltFlow
433 }
434 vsf := make(map[uint64]*of.VoltSubFlow)
435 vsf[uint64(1)] = &of.VoltSubFlow{
436 Cookie: uint64(1234),
437 }
438 tests := []struct {
439 name string
440 args args
441 wantErr bool
442 }{
443 {
444 name: "VoltPortVnet_PushFlows",
445 args: args{
446 cntx: context.Background(),
447 device: voltDevice,
448 flow: &of.VoltFlow{
449 PortName: "test_port",
450 SubFlows: vsf,
451 },
452 },
453 },
454 }
455 for _, tt := range tests {
456 t.Run(tt.name, func(t *testing.T) {
457 vpv := &VoltPortVnet{}
458 _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
459 err := vpv.PushFlows(tt.args.cntx, tt.args.device, tt.args.flow)
460 assert.NotNil(t, err)
461 })
462 }
463}
464
465func TestVoltPortVnet_isVlanMatching(t *testing.T) {
466 type args struct {
467 cvlan of.VlanType
468 svlan of.VlanType
469 }
470 tests := []struct {
471 name string
472 args args
473 want bool
474 }{
475 {
476 name: "VoltPortVnet_isVlanMatching",
477 args: args{
478 cvlan: of.VlanAny,
479 svlan: of.VlanAny,
480 },
481 want: true,
482 },
483 {
484 name: "vpv.VlanControl_nil",
485 args: args{
486 cvlan: of.VlanAny,
487 svlan: of.VlanAny,
488 },
489 want: true,
490 },
491 }
492 for _, tt := range tests {
493 t.Run(tt.name, func(t *testing.T) {
494 vpv := &VoltPortVnet{}
495 switch tt.name {
496 case "VoltPortVnet_isVlanMatching":
497 vpv.VlanControl = ONUCVlanOLTSVlan
498 vpv.SVlan = of.VlanAny
499 vpv.CVlan = of.VlanAny
500 if got := vpv.isVlanMatching(tt.args.cvlan, tt.args.svlan); got != tt.want {
501 t.Errorf("VoltPortVnet.isVlanMatching() = %v, want %v", got, tt.want)
502 }
503 }
504 })
505 }
506}
507
508func TestProcessIcmpv6McGroup(t *testing.T) {
509 type args struct {
510 device string
511 delete bool
512 }
513 tests := []struct {
514 name string
515 args args
516 wantErr bool
517 }{
518 {
519 name: "TestProcessIcmpv6McGroup",
520 args: args{
521 device: test_device,
522 delete: false,
523 },
524 },
525 }
526 for _, tt := range tests {
527 t.Run(tt.name, func(t *testing.T) {
528 err := ProcessIcmpv6McGroup(tt.args.device, tt.args.delete)
529 assert.NotNil(t, err)
530 })
531 }
532}
533
534func TestVoltVnet_setPbitRemarking(t *testing.T) {
535 tests := []struct {
536 name string
537 want uint32
538 }{
539 {
540 name: "VoltVnet_setPbitRemarking",
541 },
542 }
543 for _, tt := range tests {
544 t.Run(tt.name, func(t *testing.T) {
545 vv := &VoltVnet{}
546 a := make(map[of.PbitType]of.PbitType)
547 a[of.PbitMatchAll] = of.PbitMatchAll
548 vv.CtrlPktPbitRemark = a
549 if got := vv.setPbitRemarking(); got != tt.want {
550 t.Errorf("VoltVnet.setPbitRemarking() = %v, want %v", got, tt.want)
551 }
552 })
553 }
554}
555
556func TestBuildDSArpFlow(t *testing.T) {
557 type args struct {
558 inport uint32
559 vnet *VoltVnet
560 }
561 tests := []struct {
562 name string
563 args args
564 want *of.VoltFlow
565 }{
566 {
567 name: "BuildDSArpFlow",
568 args: args{
569 inport: uint32(1),
570 vnet: &VoltVnet{
571 Version: "test_version",
572 },
573 },
574 },
575 }
576 for _, tt := range tests {
577 t.Run(tt.name, func(t *testing.T) {
578 switch tt.name {
579 case "BuildDSArpFlow":
580 got := BuildDSArpFlow(tt.args.inport, tt.args.vnet)
581 assert.NotNil(t, got)
582 }
583 })
584 }
585}
586
587func TestBuildICMPv6Flow(t *testing.T) {
588 type args struct {
589 inport uint32
590 vnet *VoltVnet
591 }
592 tests := []struct {
593 name string
594 args args
595 want *of.VoltFlow
596 }{
597 {
598 name: "BuildICMPv6Flow",
599 args: args{
600 inport: uint32(1),
601 vnet: &VoltVnet{
602 Version: "test_version",
603 },
604 },
605 },
606 }
607 for _, tt := range tests {
608 t.Run(tt.name, func(t *testing.T) {
609 got := BuildICMPv6Flow(tt.args.inport, tt.args.vnet)
610 assert.NotNil(t, got)
611 })
612 }
613}
614
615func TestVoltApplication_DeleteDevFlowForVlanFromDevice(t *testing.T) {
616 type args struct {
617 cntx context.Context
618 vnet *VoltVnet
619 deviceSerialNum string
620 }
Akash Sonib03636c2023-10-31 12:30:59 +0530621 voltDev := &VoltDevice{
622 Name: "SDX6320031",
623 SerialNum: "SDX6320031",
624 NniDhcpTrapVid: 123,
625 State: cntlr.DeviceStateUP,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +0530626 NniPort: []string{"16777472"},
Akash Sonib03636c2023-10-31 12:30:59 +0530627 Ports: sync.Map{},
628 FlowDelEventMap: util.NewConcurrentMap(),
629 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
630 }
631 voltVnet = &VoltVnet{
632 Version: "v3",
633 VnetConfig: VnetConfig{
634 Name: "2310-4096-4096",
635 VnetType: "Encapsulation",
636 },
637 VnetOper: VnetOper{
638 PendingDeviceToDelete: "SDX6320031",
639 DeleteInProgress: true,
640 PendingDeleteFlow: make(map[string]map[string]bool),
641 },
642 }
643 voltPort := &VoltPort{
644 Name: "16777472",
645 Device: "SDX6320031",
646 ID: 16777472,
647 State: PortStateUp,
648 ChannelPerSubAlarmRaised: false,
649 }
vinokuma703a70b2023-07-17 10:06:43 +0530650 tests := []struct {
651 name string
652 args args
653 }{
654 {
655 name: "device.SerialNum != deviceSerialNum",
656 args: args{
657 cntx: context.Background(),
Akash Sonib03636c2023-10-31 12:30:59 +0530658 vnet: voltVnet,
vinokuma703a70b2023-07-17 10:06:43 +0530659 },
660 },
661 {
Akash Sonib03636c2023-10-31 12:30:59 +0530662 name: "DeleteDevFlowForVlanFromDevice",
vinokuma703a70b2023-07-17 10:06:43 +0530663 args: args{
Akash Sonib03636c2023-10-31 12:30:59 +0530664 cntx: context.Background(),
665 deviceSerialNum: "SDX6320031",
666 vnet: voltVnet,
667 },
668 },
669 {
670 name: "DeleteDevFlowForVlanFromDevice_PortStateDown",
671 args: args{
672 cntx: context.Background(),
673 deviceSerialNum: "SDX6320031",
674 vnet: voltVnet,
vinokuma703a70b2023-07-17 10:06:43 +0530675 },
676 },
677 }
678 for _, tt := range tests {
679 t.Run(tt.name, func(t *testing.T) {
Akash Sonib03636c2023-10-31 12:30:59 +0530680 va := &VoltApplication{
681 DevicesDisc: sync.Map{},
682 }
vinokuma703a70b2023-07-17 10:06:43 +0530683 switch tt.name {
684 case "device.SerialNum != deviceSerialNum":
685 va.DevicesDisc.Store(test_device, voltDevice)
686 va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum)
Akash Sonib03636c2023-10-31 12:30:59 +0530687 case "DeleteDevFlowForVlanFromDevice":
688 va.DevicesDisc.Store("SDX6320031", voltDev)
689 va.VnetsByName.Store("2310-4096-4096", voltVnet)
690 voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap())
691 va.PortsDisc.Store("16777472", voltPort)
692 appMock := mocks.NewMockApp(gomock.NewController(t))
693 cntlr.NewController(ctx, appMock)
694 vc := cntlr.GetController()
Akash Sonib03636c2023-10-31 12:30:59 +0530695 portsByName := map[string]*cntlr.DevicePort{}
696 portsByName["16777472"] = &cntlr.DevicePort{
697 Name: "16777472",
698 ID: 256,
699 State: cntlr.PortStateUp,
700 }
701 device := &cntlr.Device{
702 ID: "SDX6320031",
703 PortsByName: portsByName,
704 }
bseenivaa8cb94c2024-12-16 13:37:17 +0530705 vc.Devices.Store("SDX6320031", device)
Akash Sonib03636c2023-10-31 12:30:59 +0530706 va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum)
707 case "DeleteDevFlowForVlanFromDevice_PortStateDown":
708 voltDev.Name = ""
709 va.DevicesDisc.Store("SDX6320031", voltDev)
710 va.VnetsByName.Store("2310-4096-4096", voltVnet)
711 voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap())
712 va.PortsDisc.Store("16777472", voltPort)
713 appMock := mocks.NewMockApp(gomock.NewController(t))
714 cntlr.NewController(ctx, appMock)
715 vc := cntlr.GetController()
Akash Sonib03636c2023-10-31 12:30:59 +0530716 portsByName := map[string]*cntlr.DevicePort{}
717 portsByName["16777472"] = &cntlr.DevicePort{
718 Name: "16777472",
719 ID: 256,
720 State: cntlr.PortStateUp,
721 }
722 device := &cntlr.Device{
723 ID: "SDX6320031",
724 PortsByName: portsByName,
725 }
bseenivaa8cb94c2024-12-16 13:37:17 +0530726 vc.Devices.Store("SDX6320031", device)
vinokuma703a70b2023-07-17 10:06:43 +0530727 va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum)
728 }
729 })
730 }
731}
vinokuma04dc9f82023-07-31 15:47:49 +0530732
733func TestVoltApplication_RestoreVnetsFromDb(t *testing.T) {
734 type args struct {
735 cntx context.Context
736 }
737 tests := []struct {
738 name string
739 args args
740 }{
741 {
742 name: "VoltApplication_RestoreVnetsFromDb",
743 args: args{
744 cntx: context.Background(),
745 },
746 },
747 }
748 for _, tt := range tests {
749 t.Run(tt.name, func(t *testing.T) {
750 vnetsToDelete := map[string]bool{}
751 vnetsToDelete["test_name"] = true
752 va := &VoltApplication{
753 VnetsBySvlan: util.NewConcurrentMap(),
754 VnetsToDelete: vnetsToDelete,
755 }
756 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
757 db = dbintf
758 vnets := map[string]*kvstore.KVPair{}
759 voltVnet.SVlan = of.VlanAny
760 b, err := json.Marshal(voltVnet)
761 if err != nil {
762 panic(err)
763 }
764 vnets["test_device_id"] = &kvstore.KVPair{
765 Key: "test_device_id",
766 Value: b,
767 }
Abhay Kumarfe505f22025-11-10 14:16:31 +0000768 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
vinokuma04dc9f82023-07-31 15:47:49 +0530769 dbintf.EXPECT().GetVnets(tt.args.cntx).Return(vnets, nil)
770 va.RestoreVnetsFromDb(tt.args.cntx)
771 })
772 }
773}
774
775func TestVoltApplication_DeleteDevFlowForDevice(t *testing.T) {
776 type args struct {
777 cntx context.Context
778 device *VoltDevice
779 }
Akash Sonib03636c2023-10-31 12:30:59 +0530780 voltDev := &VoltDevice{
781 Name: "SDX6320031",
782 SerialNum: "SDX6320031",
783 NniDhcpTrapVid: 123,
784 State: cntlr.DeviceStateUP,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +0530785 NniPort: []string{"16777472"},
Akash Sonib03636c2023-10-31 12:30:59 +0530786 FlowDelEventMap: util.NewConcurrentMap(),
787 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
788 icmpv6GroupAdded: true,
789 }
790 voltVnet = &VoltVnet{
791 Version: "v3",
792 VnetConfig: VnetConfig{
793 Name: "2310-4096-4096",
794 VnetType: "Encapsulation",
795 },
796 VnetOper: VnetOper{
797 PendingDeviceToDelete: "SDX6320031",
798 DeleteInProgress: true,
799 PendingDeleteFlow: make(map[string]map[string]bool),
800 },
801 }
802 voltPort := &VoltPort{
803 Name: "16777472",
804 Device: "SDX6320031",
805 ID: 16777472,
806 State: PortStateUp,
807 ChannelPerSubAlarmRaised: false,
808 }
vinokuma04dc9f82023-07-31 15:47:49 +0530809 tests := []struct {
810 name string
811 args args
812 }{
813 {
Akash Sonib03636c2023-10-31 12:30:59 +0530814 name: "DeleteDevFlowForDevice",
vinokuma04dc9f82023-07-31 15:47:49 +0530815 args: args{
Akash Sonib03636c2023-10-31 12:30:59 +0530816 cntx: context.Background(),
817 device: voltDev,
vinokuma04dc9f82023-07-31 15:47:49 +0530818 },
819 },
820 }
vinokuma04dc9f82023-07-31 15:47:49 +0530821 for _, tt := range tests {
822 t.Run(tt.name, func(t *testing.T) {
823 va := &VoltApplication{}
Akash Sonib03636c2023-10-31 12:30:59 +0530824 switch tt.name {
825 case "DeleteDevFlowForDevice":
826 va.DevicesDisc.Store("SDX6320031", voltDev)
827 va.VnetsByName.Store("2310-4096-4096", voltVnet)
828 voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap())
829 va.PortsDisc.Store("16777472", voltPort)
830 voltApp := GetApplication()
831 voltApp.DevicesDisc.Store("SDX6320031", voltDev)
832 appMock := mocks.NewMockApp(gomock.NewController(t))
833 cntlr.NewController(ctx, appMock)
834 vc := cntlr.GetController()
Akash Sonib03636c2023-10-31 12:30:59 +0530835 portsByName := map[string]*cntlr.DevicePort{}
836 portsByName["16777472"] = &cntlr.DevicePort{
837 Name: "16777472",
838 ID: 256,
839 State: cntlr.PortStateUp,
840 }
841 device := &cntlr.Device{
842 ID: "SDX6320031",
843 PortsByName: portsByName,
844 }
bseenivaa8cb94c2024-12-16 13:37:17 +0530845 vc.Devices.Store("SDX6320031", device)
Akash Sonib03636c2023-10-31 12:30:59 +0530846 va.DeleteDevFlowForDevice(tt.args.cntx, tt.args.device)
847 }
vinokuma04dc9f82023-07-31 15:47:49 +0530848 })
849 }
850}
851
852func TestVoltApplication_DelVnetFromPort(t *testing.T) {
853 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
854 vpv_test := []*VoltPortVnet{
855 {
856 Device: test_device,
857 Port: "test_port",
858 MacAddr: macAdd,
859 VnetName: "test_vnet_name",
860 },
861 }
862 type args struct {
863 cntx context.Context
864 port string
865 vpv *VoltPortVnet
866 }
867 tests := []struct {
868 name string
869 args args
870 }{
871 {
872 name: "VoltApplication_DelVnetFromPort",
873 args: args{
874 cntx: context.Background(),
875 port: "test_port",
876 vpv: &VoltPortVnet{
877 Device: test_device,
878 Port: "test_port",
879 MacAddr: macAdd,
880 VnetName: "test_vnet_name",
881 },
882 },
883 },
884 }
885 for _, tt := range tests {
886 t.Run(tt.name, func(t *testing.T) {
887 va := &VoltApplication{}
888 va.VnetsByPort.Store("test_port", vpv_test)
889 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
890 db = dbintf
891 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
892 dbintf.EXPECT().DelVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
893 va.VnetsByName.Store("test_vnet_name", &VoltVnet{
894 Version: "test_version",
895 })
896 va.DelVnetFromPort(tt.args.cntx, tt.args.port, tt.args.vpv)
897 })
898 }
899}
900
901func TestVoltApplication_PushDevFlowForVlan(t *testing.T) {
902 type args struct {
903 cntx context.Context
904 vnet *VoltVnet
905 }
Akash Sonib03636c2023-10-31 12:30:59 +0530906 voltDev := &VoltDevice{
907 Name: "SDX6320031",
908 SerialNum: "SDX6320031",
909 NniDhcpTrapVid: 123,
910 State: cntlr.DeviceStateUP,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +0530911 NniPort: []string{"16777472"},
Akash Sonib03636c2023-10-31 12:30:59 +0530912 FlowDelEventMap: util.NewConcurrentMap(),
913 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
914 icmpv6GroupAdded: true,
915 VlanPortStatus: sync.Map{},
916 }
917 voltVnet := &VoltVnet{
918 Version: "v3",
919 VnetConfig: VnetConfig{
920 Name: "2310-4096-4096",
921 VnetType: "Encapsulation",
922 DevicesList: []string{"SDX6320031"},
923 SVlan: 0,
924 },
925 VnetOper: VnetOper{
926 PendingDeviceToDelete: "SDX6320031",
927 DeleteInProgress: true,
928 PendingDeleteFlow: make(map[string]map[string]bool),
929 },
930 }
931 voltPort := &VoltPort{
932 Name: "16777216",
933 Device: "SDX6320031",
934 ID: 16777216,
935 State: PortStateUp,
936 ChannelPerSubAlarmRaised: false,
937 }
vinokuma04dc9f82023-07-31 15:47:49 +0530938 tests := []struct {
939 name string
940 args args
941 }{
942 {
943 name: "VoltApplication_PushDevFlowForVlan",
944 args: args{
945 cntx: context.Background(),
946 vnet: &VoltVnet{
947 Version: "test_version",
948 VnetConfig: VnetConfig{
949 DevicesList: []string{"test_serialNum"},
950 SVlan: of.VlanAny,
951 },
952 },
953 },
954 },
Akash Sonib03636c2023-10-31 12:30:59 +0530955 // {
956 // name: "PushDevFlowForVlan",
957 // args: args{
958 // cntx: context.Background(),
959 // vnet: voltVnet,
960 // },
961 // },
vinokuma04dc9f82023-07-31 15:47:49 +0530962 }
963 for _, tt := range tests {
964 t.Run(tt.name, func(t *testing.T) {
965 va := &VoltApplication{}
Akash Sonib03636c2023-10-31 12:30:59 +0530966 switch tt.name {
967 case "VoltApplication_PushDevFlowForVlan":
968 voltDevice.SerialNum = "test_serialNum"
969 voltDevice.VlanPortStatus.Store(uint16(of.VlanAny), true)
970 voltDevice.Name = test_device
971 va.DevicesDisc.Store(test_device, voltDevice)
972 va.PortsDisc.Store("16777216", voltPort)
973 ga := GetApplication()
974 ga.DevicesDisc.Store(test_device, voltDevice)
975 _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
976 va.PushDevFlowForVlan(tt.args.cntx, tt.args.vnet)
977 case "PushDevFlowForVlan":
978 va.DevicesDisc.Store("SDX6320031", voltDev)
979 voltDevice.VlanPortStatus.Store(uint16(0), true)
980 va.VnetsByName.Store("2310-4096-4096", voltVnet)
981 voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap())
982 va.PortsDisc.Store("16777472", voltPort)
983 voltApp := GetApplication()
984 voltApp.DevicesDisc.Store("SDX6320031", voltDev)
985 _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
986 va.PushDevFlowForVlan(tt.args.cntx, tt.args.vnet)
987 }
vinokuma04dc9f82023-07-31 15:47:49 +0530988 })
989 }
990}
991
992func TestVoltApplication_PushDevFlowForDevice(t *testing.T) {
993 type args struct {
994 cntx context.Context
995 device *VoltDevice
996 }
997 tests := []struct {
998 name string
999 args args
1000 }{
1001 {
1002 name: "device.ConfiguredVlanForDeviceFlows is ok",
1003 args: args{
1004 cntx: context.Background(),
1005 device: &VoltDevice{
1006 Name: test_device,
1007 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
1008 },
1009 },
1010 },
1011 {
1012 name: "device.VlanPortStatus is false",
1013 args: args{
1014 cntx: context.Background(),
1015 device: &VoltDevice{
1016 Name: test_device,
1017 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301018 NniPort: []string{"test_nni_port"},
vinokuma04dc9f82023-07-31 15:47:49 +05301019 },
1020 },
1021 },
1022 {
1023 name: "device.VlanPortStatus is true",
1024 args: args{
1025 cntx: context.Background(),
1026 device: &VoltDevice{
1027 Name: test_device,
1028 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301029 NniPort: []string{"test_nni_port"},
vinokuma04dc9f82023-07-31 15:47:49 +05301030 VlanPortStatus: sync.Map{},
1031 },
1032 },
1033 },
1034 }
1035 for _, tt := range tests {
1036 t.Run(tt.name, func(t *testing.T) {
1037 va := &VoltApplication{}
1038 switch tt.name {
1039 case "device.ConfiguredVlanForDeviceFlows is ok":
1040 va.VnetsByName.Store("test_vnet_name", &VoltVnet{
1041 Version: "test_version",
1042 })
1043 tt.args.device.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap())
1044 va.PushDevFlowForDevice(tt.args.cntx, tt.args.device)
1045 case "device.VlanPortStatus is false":
1046 va.VnetsByName.Store("test_vnet_name", &VoltVnet{
1047 Version: "test_version",
1048 })
1049 va.PortsDisc.Store("test_nni_port", &VoltPort{
1050 Name: "test_name",
1051 })
1052 va.PushDevFlowForDevice(tt.args.cntx, tt.args.device)
1053 case "device.VlanPortStatus is true":
1054 va.VnetsByName.Store("test_vnet_name", &VoltVnet{
1055 Version: "test_version",
1056 VnetConfig: VnetConfig{
1057 SVlan: of.VlanAny,
1058 },
1059 })
1060 va.PortsDisc.Store("test_nni_port", &VoltPort{
1061 Name: "test_name",
1062 })
1063 tt.args.device.VlanPortStatus.Store(uint16(of.VlanAny), true)
1064 va.PushDevFlowForDevice(tt.args.cntx, tt.args.device)
1065 }
1066 })
1067 }
1068}
Akash Soni230e6212023-10-16 10:46:07 +05301069
1070func TestNewVoltPortVnet(t *testing.T) {
1071 type args struct {
1072 vnet *VoltVnet
1073 }
1074 usDhcpPbit := []of.PbitType{}
1075 usDhcpPbit = append(usDhcpPbit, PbitMatchNone)
1076 tests := []struct {
1077 name string
1078 args args
1079 want *VoltPortVnet
1080 }{
1081 {
1082 name: "NewVoltPortVnet",
1083 args: args{
1084 vnet: &VoltVnet{
1085 VnetConfig: VnetConfig{
1086 UsDhcpPbit: usDhcpPbit,
1087 },
1088 },
1089 },
1090 want: &VoltPortVnet{},
1091 },
1092 }
1093 for _, tt := range tests {
1094 t.Run(tt.name, func(t *testing.T) {
1095 got := NewVoltPortVnet(tt.args.vnet)
1096 assert.NotNil(t, got)
1097 })
1098 }
1099}
1100
1101func TestVoltPortVnet_GetCircuitID(t *testing.T) {
1102 vpv := &VoltPortVnet{}
1103 got := vpv.GetCircuitID()
1104 assert.Nil(t, got)
1105 got1 := vpv.GetRemoteID()
1106 assert.Nil(t, got1)
1107 got3 := vpv.GetDhcpState()
1108 assert.NotNil(t, got3)
1109 got4 := vpv.GetPppoeIaState()
1110 assert.NotNil(t, got4)
1111 got5 := vpv.GetDhcpv6State()
1112 assert.NotNil(t, got5)
1113}
1114
1115func TestVoltPortVnet_GetNniVlans(t *testing.T) {
1116 tests := []struct {
1117 name string
1118 want uint16
1119 want1 uint16
1120 }{
1121 {
1122 name: "GetNniVlans",
1123 want: uint16(of.VlanAny),
1124 want1: uint16(of.VlanAny),
1125 },
1126 {
1127 name: "GetNniVlans_OLTSVlan",
1128 want: uint16(of.VlanAny),
1129 want1: uint16(of.VlanNone),
1130 },
1131 {
1132 name: "GetNniVlans_Default",
1133 want: uint16(of.VlanNone),
1134 want1: uint16(of.VlanNone),
1135 },
1136 }
1137 for _, tt := range tests {
1138 t.Run(tt.name, func(t *testing.T) {
1139 vpv := &VoltPortVnet{
1140 VlanControl: ONUCVlanOLTSVlan,
1141 SVlan: of.VlanAny,
1142 CVlan: of.VlanAny,
1143 }
1144 switch tt.name {
1145 case "GetNniVlans":
1146 got, got1 := vpv.GetNniVlans()
1147 if got != tt.want {
1148 t.Errorf("VoltPortVnet.GetNniVlans() got = %v, want %v", got, tt.want)
1149 }
1150 if got1 != tt.want1 {
1151 t.Errorf("VoltPortVnet.GetNniVlans() got1 = %v, want %v", got1, tt.want1)
1152 }
1153 case "GetNniVlans_OLTSVlan":
1154 vpv.VlanControl = OLTSVlan
1155 got, got1 := vpv.GetNniVlans()
1156 if got != tt.want {
1157 t.Errorf("VoltPortVnet.GetNniVlans() got = %v, want %v", got, tt.want)
1158 }
1159 if got1 != tt.want1 {
1160 t.Errorf("VoltPortVnet.GetNniVlans() got1 = %v, want %v", got1, tt.want1)
1161 }
1162 case "GetNniVlans_Default":
1163 vpv.VlanControl = opt82
1164 got, got1 := vpv.GetNniVlans()
1165 if got != tt.want {
1166 t.Errorf("VoltPortVnet.GetNniVlans() got = %v, want %v", got, tt.want)
1167 }
1168 if got1 != tt.want1 {
1169 t.Errorf("VoltPortVnet.GetNniVlans() got1 = %v, want %v", got1, tt.want1)
1170 }
1171 }
1172 })
1173 }
1174}
1175
1176func TestVoltPortVnet_GetService(t *testing.T) {
1177 type args struct {
1178 name string
1179 }
1180 voltServ := &VoltService{
1181 VoltServiceOper: VoltServiceOper{
1182 Device: "SDX6320031",
1183 },
1184 VoltServiceCfg: VoltServiceCfg{
1185 IsActivated: true,
1186 },
1187 }
1188 tests := []struct {
1189 name string
1190 args args
1191 want *VoltService
1192 want1 bool
1193 }{
1194 {
1195 name: "GetService",
1196 args: args{
1197 name: "SDX6320031-1_SDX6320031-1-4096-2310-4096-65",
1198 },
1199 want: voltServ,
1200 want1: true,
1201 },
1202 }
1203 for _, tt := range tests {
1204 t.Run(tt.name, func(t *testing.T) {
1205 vpv := &VoltPortVnet{}
1206 vpv.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
1207 got, got1 := vpv.GetService(tt.args.name)
1208 if !reflect.DeepEqual(got, tt.want) {
1209 t.Errorf("VoltPortVnet.GetService() got = %v, want %v", got, tt.want)
1210 }
1211 if got1 != tt.want1 {
1212 t.Errorf("VoltPortVnet.GetService() got1 = %v, want %v", got1, tt.want1)
1213 }
1214 })
1215 }
1216}
1217
1218func TestVoltPortVnet_ProcessDhcpSuccess(t *testing.T) {
1219 type args struct {
1220 cntx context.Context
1221 res *layers.DHCPv4
1222 }
1223 tests := []struct {
1224 name string
1225 args args
1226 }{
1227 {
1228 name: "ProcessDhcpSuccess",
1229 args: args{
1230 cntx: context.Background(),
1231 res: &layers.DHCPv4{},
1232 },
1233 },
1234 }
1235 for _, tt := range tests {
1236 t.Run(tt.name, func(t *testing.T) {
1237 vpv := &VoltPortVnet{
1238 servicesCount: atomic.NewUint64(0),
1239 }
1240 vpv.ProcessDhcpSuccess(tt.args.cntx, tt.args.res)
1241 })
1242 }
1243}
1244
1245func TestVoltPortVnet_ProcessDhcpResult(t *testing.T) {
1246 type args struct {
1247 cntx context.Context
1248 res *layers.DHCPv4
1249 }
1250 tests := []struct {
1251 name string
1252 args args
1253 }{
1254 {
1255 name: "ProcessDhcpResult",
1256 args: args{
1257 cntx: context.Background(),
1258 res: &layers.DHCPv4{},
1259 },
1260 },
1261 }
1262 for _, tt := range tests {
1263 t.Run(tt.name, func(t *testing.T) {
1264 vpv := &VoltPortVnet{}
1265 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1266 db = dbintf
1267 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1268 vpv.ProcessDhcpResult(tt.args.cntx, tt.args.res)
1269 })
1270 }
1271}
1272
1273func TestVoltVnet_associatePortToVnet(t *testing.T) {
1274 type args struct {
1275 port string
1276 }
1277 tests := []struct {
1278 name string
1279 args args
1280 }{
1281 {
1282 name: "ProcessDhcpResult",
1283 args: args{
1284 port: "SDX6320031-1",
1285 },
1286 },
1287 }
1288 for _, tt := range tests {
1289 t.Run(tt.name, func(t *testing.T) {
1290 vv := &VoltVnet{}
1291 vv.associatePortToVnet(tt.args.port)
1292 })
1293 }
1294}
1295
1296func TestVoltPortVnet_ProcessDhcpv6Result(t *testing.T) {
1297 type args struct {
1298 cntx context.Context
1299 ipv6Addr net.IP
1300 leaseTime uint32
1301 }
1302 tests := []struct {
1303 name string
1304 args args
1305 }{
1306 {
1307 name: "ProcessDhcpResult",
1308 args: args{
1309 cntx: context.Background(),
1310 ipv6Addr: AllSystemsMulticastGroupIP,
1311 leaseTime: uint32(128),
1312 },
1313 },
1314 }
1315 for _, tt := range tests {
1316 t.Run(tt.name, func(t *testing.T) {
1317 vpv := &VoltPortVnet{}
1318 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1319 db = dbintf
1320 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1321 vpv.ProcessDhcpv6Result(tt.args.cntx, tt.args.ipv6Addr, tt.args.leaseTime)
1322 })
1323 }
1324}
1325
1326func TestAddSvcUsMeterToDevice(t *testing.T) {
1327 type args struct {
1328 cntx context.Context
1329 key interface{}
1330 value interface{}
1331 flag bool
1332 }
1333 vpv := &VoltApplication{}
1334 voltServ := &VoltService{
1335 VoltServiceOper: VoltServiceOper{
1336 Device: test_device,
1337 ForceDelete: true,
1338 },
1339 }
1340 vpv.ServiceByName.Store(test_device, voltServ)
1341 tests := []struct {
1342 name string
1343 args args
1344 want bool
1345 }{
1346 {
1347 name: "ProcessDhcpResult",
1348 args: args{
1349 cntx: context.Background(),
1350 key: test_device,
1351 value: voltServ,
1352 },
1353 },
1354 }
1355 for _, tt := range tests {
1356 t.Run(tt.name, func(t *testing.T) {
1357 if got := AddSvcUsMeterToDevice(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag); got != tt.want {
1358 t.Errorf("AddSvcUsMeterToDevice() = %v, want %v", got, tt.want)
1359 }
1360 })
1361 }
1362}
1363
1364func TestClearFlagsInService(t *testing.T) {
1365 type args struct {
1366 cntx context.Context
1367 key interface{}
1368 value interface{}
1369 flag bool
1370 }
1371 vpv := &VoltPortVnet{}
1372 voltServ := &VoltService{
1373 VoltServiceOper: VoltServiceOper{
1374 Device: "SDX6320031",
1375 },
1376 VoltServiceCfg: VoltServiceCfg{
1377 IsActivated: true,
1378 },
1379 }
1380 vpv.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
1381 tests := []struct {
1382 name string
1383 args args
1384 want bool
1385 }{
1386 {
1387 name: "ClearFlagsInService",
1388 args: args{
1389 cntx: context.Background(),
1390 key: test_device,
1391 value: voltServ,
1392 },
1393 },
1394 }
1395 for _, tt := range tests {
1396 t.Run(tt.name, func(t *testing.T) {
1397 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1398 db = dbintf
1399 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1400 got := ClearFlagsInService(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag)
1401 assert.NotNil(t, got)
1402 })
1403 }
1404}
1405
1406func TestVoltPortVnet_DelDhcpFlows(t *testing.T) {
1407 type args struct {
1408 cntx context.Context
1409 }
1410 tests := []struct {
1411 name string
1412 args args
1413 }{
1414 {
1415 name: "DelDhcpFlows",
1416 args: args{
1417 cntx: context.Background(),
1418 },
1419 },
1420 }
1421 for _, tt := range tests {
1422 t.Run(tt.name, func(t *testing.T) {
1423 vpv := &VoltPortVnet{}
1424 vpv.DelDhcpFlows(tt.args.cntx)
1425 })
1426 }
1427}
1428
Akash Sonib03636c2023-10-31 12:30:59 +05301429func TestVoltPortVnet_PushFlowsForPortVnet(t *testing.T) {
1430 type args struct {
1431 cntx context.Context
1432 d *VoltDevice
1433 }
1434 va := GetApplication()
1435 voltDev := &VoltDevice{
1436 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1437 SerialNum: "SDX6320031",
1438 NniDhcpTrapVid: 123,
1439 State: cntlr.DeviceStateUP,
1440 FlowAddEventMap: util.NewConcurrentMap(),
1441 Ports: sync.Map{},
1442 }
1443 va.DevicesDisc.Store("SDX6320031", voltDev)
1444 voltPort := &VoltPort{
1445 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1446 Device: "SDX6320031",
1447 ID: 16777472,
1448 State: PortStateUp,
1449 Type: VoltPortTypeNni,
1450 }
1451 voltDev.Ports.Store("16777472", voltPort)
1452 tests := []struct {
1453 name string
1454 args args
1455 }{
1456 {
1457 name: "PushFlowsForPortVnet",
1458 args: args{
1459 cntx: context.Background(),
1460 d: voltDev,
1461 },
1462 },
1463 {
1464 name: "PushFlowsForPortVnet_PortDown",
1465 args: args{
1466 cntx: context.Background(),
1467 d: voltDev,
1468 },
1469 },
1470 }
1471 for _, tt := range tests {
1472 t.Run(tt.name, func(t *testing.T) {
1473 vpv := &VoltPortVnet{}
1474 switch tt.name {
1475 case "PushFlowsForPortVnet_PortDown":
1476 vpv.PushFlowsForPortVnet(tt.args.cntx, tt.args.d)
1477 case "PushFlowsForPortVnet":
1478 vpv.Port = "16777472"
1479 vpv.PushFlowsForPortVnet(tt.args.cntx, tt.args.d)
1480 }
1481 })
1482 }
1483}
1484
1485func TestVoltPortVnet_setLearntMAC(t *testing.T) {
1486 type args struct {
1487 cntx context.Context
1488 key interface{}
1489 value interface{}
1490 flag bool
1491 }
1492 voltServ := &VoltService{
1493 VoltServiceOper: VoltServiceOper{
1494 Device: test_device,
1495 ForceDelete: true,
1496 },
1497 }
1498 tests := []struct {
1499 name string
1500 args args
1501 want bool
1502 }{
1503 {
1504 name: "setLearntMAC",
1505 args: args{
1506 cntx: context.Background(),
1507 key: test_device,
1508 value: voltServ,
1509 },
1510 want: true,
1511 },
1512 {
1513 name: "updateIPv4AndProvisionFlows",
1514 args: args{
1515 cntx: context.Background(),
1516 key: test_device,
1517 value: voltServ,
1518 },
1519 want: true,
1520 },
1521 {
1522 name: "updateIPv6AndProvisionFlows",
1523 args: args{
1524 cntx: context.Background(),
1525 key: test_device,
1526 value: voltServ,
1527 },
1528 want: true,
1529 },
1530 }
1531 for _, tt := range tests {
1532 t.Run(tt.name, func(t *testing.T) {
1533 vpv := &VoltPortVnet{
1534 MacAddr: net.HardwareAddr(pendingPoolTimer),
1535 Ipv4Addr: AllSystemsMulticastGroupIP,
1536 Ipv6Addr: AllSystemsMulticastGroupIP,
1537 }
1538 vpv.services.Store(test_device, voltServ)
1539 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1540 db = dbintf
1541 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
1542 switch tt.name {
1543 case "setLearntMAC":
1544 if got := vpv.setLearntMAC(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag); got != tt.want {
1545 t.Errorf("VoltPortVnet.setLearntMAC() = %v, want %v", got, tt.want)
1546 }
1547 case "updateIPv4AndProvisionFlows":
1548 if got := vpv.updateIPv4AndProvisionFlows(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag); got != tt.want {
1549 t.Errorf("VoltPortVnet.updateIPv4AndProvisionFlows() = %v, want %v", got, tt.want)
1550 }
1551 case "updateIPv6AndProvisionFlows":
1552 if got := vpv.updateIPv6AndProvisionFlows(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag); got != tt.want {
1553 t.Errorf("VoltPortVnet.updateIPv6AndProvisionFlows() = %v, want %v", got, tt.want)
1554 }
1555 }
1556 })
1557 }
1558}
1559
1560func TestAddMeterToDevice(t *testing.T) {
1561 type args struct {
1562 cntx context.Context
1563 key interface{}
1564 value interface{}
1565 flag bool
1566 }
1567 voltServ := &VoltService{
1568 VoltServiceOper: VoltServiceOper{
1569 Device: test_device,
1570 ForceDelete: true,
1571 },
1572 }
1573 tests := []struct {
1574 name string
1575 args args
1576 want bool
1577 }{
1578 {
1579 name: "TestAddMeterToDevice",
1580 args: args{
1581 cntx: context.Background(),
1582 key: test_device,
1583 value: voltServ,
1584 },
1585 want: true,
1586 },
1587 }
1588 for _, tt := range tests {
1589 t.Run(tt.name, func(t *testing.T) {
1590 if got := AddMeterToDevice(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag); got != tt.want {
1591 t.Errorf("AddMeterToDevice() = %v, want %v", got, tt.want)
1592 }
1593 })
1594 }
1595}
1596
1597func TestVoltPortVnet_AddUsArpFlows(t *testing.T) {
1598 type args struct {
1599 cntx context.Context
1600 }
1601 va := GetApplication()
1602 voltDev := &VoltDevice{
1603 Name: "SDX6320031",
1604 SerialNum: "SDX6320031",
1605 NniDhcpTrapVid: 123,
1606 State: cntlr.DeviceStateUP,
1607 FlowAddEventMap: util.NewConcurrentMap(),
1608 Ports: sync.Map{},
1609 }
1610 voltPort := &VoltPort{
1611 Name: "16777472",
1612 Device: "SDX6320031",
1613 ID: 16777472,
1614 State: PortStateUp,
1615 ChannelPerSubAlarmRaised: false,
1616 }
1617 tests := []struct {
1618 name string
1619 args args
1620 wantErr bool
1621 }{
1622 {
1623 name: "AddUsArpFlows",
1624 args: args{
1625 cntx: context.Background(),
1626 },
1627 wantErr: true,
1628 },
1629 {
1630 name: "AddUsArpFlows_DeviceNotFound",
1631 args: args{
1632 cntx: context.Background(),
1633 },
1634 wantErr: true,
1635 },
1636 {
1637 name: "AddUsArpFlows_DeviceStateDOWN",
1638 args: args{
1639 cntx: context.Background(),
1640 },
1641 },
1642 }
1643 for _, tt := range tests {
1644 t.Run(tt.name, func(t *testing.T) {
1645 vpv := &VoltPortVnet{
1646 Device: deviceName,
1647 MacLearning: MacLearningNone,
1648 MacAddr: BroadcastMAC,
1649 Port: "16777472",
1650 }
1651 va.DevicesDisc.Store(deviceName, voltDev)
1652 va.PortsDisc.Store("16777472", voltPort)
1653 appMock := mocks.NewMockApp(gomock.NewController(t))
1654 cntlr.NewController(ctx, appMock)
1655 vc := cntlr.GetController()
Akash Sonib03636c2023-10-31 12:30:59 +05301656 portsByName := map[string]*cntlr.DevicePort{}
1657 portsByName["16777472"] = &cntlr.DevicePort{
1658 Name: "16777472",
1659 ID: 256,
1660 }
1661 device := &cntlr.Device{
1662 ID: deviceName,
1663 PortsByName: portsByName,
1664 }
bseenivaa8cb94c2024-12-16 13:37:17 +05301665 vc.Devices.Store("SDX6320031", device)
Akash Sonib03636c2023-10-31 12:30:59 +05301666 switch tt.name {
1667 case "AddUsArpFlows":
1668 if err := vpv.AddUsArpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1669 t.Errorf("VoltPortVnet.AddUsArpFlows() error = %v, wantErr %v", err, tt.wantErr)
1670 }
1671 case "AddUsArpFlows_DeviceNotFound":
1672 vpv.Device = ""
1673 if err := vpv.AddUsArpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1674 t.Errorf("VoltPortVnet.AddUsArpFlows() error = %v, wantErr %v", err, tt.wantErr)
1675 }
1676 case "AddUsArpFlows_DeviceStateDOWN":
1677 vpv.Device = deviceName
1678 voltDev.State = cntlr.DeviceStateDOWN
1679 if err := vpv.AddUsArpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1680 t.Errorf("VoltPortVnet.AddUsArpFlows() error = %v, wantErr %v", err, tt.wantErr)
1681 }
1682 }
1683 })
1684 }
1685}
1686
Akash Soni230e6212023-10-16 10:46:07 +05301687func TestVoltPortVnet_AddDsDhcpFlows(t *testing.T) {
1688 type args struct {
1689 cntx context.Context
1690 }
1691 va := GetApplication()
1692 voltDev := &VoltDevice{
1693 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1694 SerialNum: "SDX6320031",
1695 NniDhcpTrapVid: 123,
1696 State: cntlr.DeviceStateUP,
1697 FlowAddEventMap: util.NewConcurrentMap(),
1698 }
1699 va.DevicesDisc.Store("SDX6320031", voltDev)
1700 voltPort := &VoltPort{
1701 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1702 Device: "SDX6320031",
1703 ID: 16777472,
1704 State: PortStateDown,
1705 ChannelPerSubAlarmRaised: false,
1706 Type: VoltPortTypeNni,
1707 }
1708 tests := []struct {
1709 name string
1710 args args
1711 wantErr bool
1712 }{
1713 {
1714 name: "AddDsDhcpFlows",
1715 args: args{
1716 cntx: context.Background(),
1717 },
1718 },
1719 {
1720 name: "AddDsDhcpFlows_DeviceNotFound",
1721 args: args{
1722 cntx: context.Background(),
1723 },
1724 wantErr: true,
1725 },
1726 {
1727 name: "AddDsDhcpFlows_StateDown",
1728 args: args{
1729 cntx: context.Background(),
1730 },
1731 },
1732 {
1733 name: "AddDsDhcpFlows_GlobalDhcpFlowAdded",
1734 args: args{
1735 cntx: context.Background(),
1736 },
1737 },
1738 {
1739 name: "AddDsDhcpFlows_PositiveSenario",
1740 args: args{
1741 cntx: context.Background(),
1742 },
1743 },
1744 }
1745 for _, tt := range tests {
1746 t.Run(tt.name, func(t *testing.T) {
1747 vpv := &VoltPortVnet{
1748 Device: "SDX6320031",
1749 }
1750 switch tt.name {
1751 case "AddDsDhcpFlows":
1752 if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1753 t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
1754 }
1755 case "AddDsDhcpFlows_DeviceNotFound":
1756 vpv.Device = ""
1757 if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1758 t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
1759 }
1760 case "AddDsDhcpFlows_StateDown":
1761 voltDev.State = cntlr.DeviceStateDOWN
1762 if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1763 t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
1764 }
1765 case "AddDsDhcpFlows_GlobalDhcpFlowAdded":
Akash Sonib03636c2023-10-31 12:30:59 +05301766 vpv.Device = deviceName
Akash Soni230e6212023-10-16 10:46:07 +05301767 voltDev.State = cntlr.DeviceStateUP
1768 voltDev.GlobalDhcpFlowAdded = true
1769 if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1770 t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
1771 }
1772 case "AddDsDhcpFlows_PositiveSenario":
Akash Sonib03636c2023-10-31 12:30:59 +05301773 vpv.Device = deviceName
Akash Soni230e6212023-10-16 10:46:07 +05301774 voltDev.State = cntlr.DeviceStateUP
1775 voltDev.GlobalDhcpFlowAdded = false
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301776 voltDev.NniPort = []string{"16777472"}
Akash Soni230e6212023-10-16 10:46:07 +05301777 va.PortsDisc.Store("16777472", voltPort)
1778 appMock := mocks.NewMockApp(gomock.NewController(t))
1779 cntlr.NewController(ctx, appMock)
1780 vc := cntlr.GetController()
1781 device := &cntlr.Device{
1782 ID: "SDX6320031",
1783 }
bseenivaa8cb94c2024-12-16 13:37:17 +05301784 vc.Devices.Store("SDX6320031", device)
Akash Soni230e6212023-10-16 10:46:07 +05301785 if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1786 t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
1787 }
1788 }
1789 })
1790 }
1791}
Akash Sonib03636c2023-10-31 12:30:59 +05301792
1793func TestVoltPortVnet_AddUsDhcpFlows(t *testing.T) {
1794 type args struct {
1795 cntx context.Context
1796 }
1797 va := GetApplication()
1798 voltDev := &VoltDevice{
1799 Name: "SDX6320031",
1800 SerialNum: "SDX6320031",
1801 NniDhcpTrapVid: 123,
1802 State: cntlr.DeviceStateUP,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301803 NniPort: []string{"16777472"},
Akash Sonib03636c2023-10-31 12:30:59 +05301804 FlowAddEventMap: util.NewConcurrentMap(),
1805 }
1806 va.DevicesDisc.Store("SDX6320031", voltDev)
1807 voltPort := &VoltPort{
1808 Name: "16777472",
1809 Device: "SDX6320031",
1810 ID: 16777472,
1811 State: PortStateDown,
1812 ChannelPerSubAlarmRaised: false,
1813 Type: VoltPortTypeNni,
1814 }
1815 tests := []struct {
1816 name string
1817 args args
1818 wantErr bool
1819 }{
1820 {
1821 name: "AddUsDhcpFlows_PositiveSenario",
1822 args: args{
1823 cntx: context.Background(),
1824 },
1825 },
1826 {
1827 name: "AddUsDhcpFlows_StateDown",
1828 args: args{
1829 cntx: context.Background(),
1830 },
1831 },
1832 {
1833 name: "AddUsDhcpFlows_DeviceNotFound",
1834 args: args{
1835 cntx: context.Background(),
1836 },
1837 wantErr: true,
1838 },
1839 {
1840 name: "AddUsDhcpFlows_GlobalDhcpFlowAdded",
1841 args: args{
1842 cntx: context.Background(),
1843 },
1844 },
1845 }
1846 for _, tt := range tests {
1847 t.Run(tt.name, func(t *testing.T) {
1848 vpv := &VoltPortVnet{
1849 Device: "SDX6320031",
1850 VnetType: DpuMgmtTraffic,
1851 Port: "16777472",
1852 }
1853 switch tt.name {
1854 case "AddUsDhcpFlows_PositiveSenario":
1855 va.PortsDisc.Store("16777472", voltPort)
1856 appMock := mocks.NewMockApp(gomock.NewController(t))
1857 cntlr.NewController(ctx, appMock)
1858 vc := cntlr.GetController()
1859 device := &cntlr.Device{
1860 ID: "SDX6320031",
1861 }
bseenivaa8cb94c2024-12-16 13:37:17 +05301862 vc.Devices.Store("SDX6320031", device)
Akash Sonib03636c2023-10-31 12:30:59 +05301863 if err := vpv.AddUsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1864 t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
1865 }
1866 case "AddUsDhcpFlows_DeviceNotFound":
1867 vpv.Device = ""
1868 if err := vpv.AddUsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1869 t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
1870 }
1871 case "AddUsDhcpFlows_StateDown":
1872 voltDev.State = cntlr.DeviceStateDOWN
1873 if err := vpv.AddUsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1874 t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
1875 }
1876 case "AddUsDhcpFlows_GlobalDhcpFlowAdded":
1877 vpv.Device = "SDX6320031"
1878 voltDev.State = cntlr.DeviceStateUP
1879 vpv.Port = ""
1880 if err := vpv.AddUsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1881 t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
1882 }
1883 }
1884 })
1885 }
1886}
1887
1888func TestVoltPortVnet_AddUsPppoeFlows(t *testing.T) {
1889 type args struct {
1890 cntx context.Context
1891 }
1892 va := GetApplication()
1893 voltDev := &VoltDevice{
1894 Name: "SDX6320031",
1895 SerialNum: "SDX6320031",
1896 NniDhcpTrapVid: 123,
1897 State: cntlr.DeviceStateUP,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301898 NniPort: []string{"16777472"},
Akash Sonib03636c2023-10-31 12:30:59 +05301899 FlowAddEventMap: util.NewConcurrentMap(),
1900 }
1901 voltPort := &VoltPort{
1902 Name: "16777472",
1903 Device: "SDX6320031",
1904 ID: 16777472,
1905 State: PortStateUp,
1906 ChannelPerSubAlarmRaised: false,
1907 }
1908 va.DevicesDisc.Store("SDX6320031", voltDev)
1909 va.PortsDisc.Store("16777472", voltPort)
1910 tests := []struct {
1911 name string
1912 args args
1913 wantErr bool
1914 }{
1915 {
1916 name: "AddUsPppoeFlows",
1917 args: args{
1918 cntx: context.Background(),
1919 },
1920 wantErr: true,
1921 },
1922 {
1923 name: "AddDsPppoeFlows",
1924 args: args{
1925 cntx: context.Background(),
1926 },
1927 wantErr: true,
1928 },
1929 {
1930 name: "AddUsPppoeFlows_StateDown",
1931 args: args{
1932 cntx: context.Background(),
1933 },
1934 },
1935 {
1936 name: "AddDsPppoeFlows_StateDown",
1937 args: args{
1938 cntx: context.Background(),
1939 },
1940 },
1941 {
1942 name: "AddUsPppoeFlows_DeviceNotFound",
1943 args: args{
1944 cntx: context.Background(),
1945 },
1946 wantErr: true,
1947 },
1948 {
1949 name: "AddDsPppoeFlows_DeviceNotFound",
1950 args: args{
1951 cntx: context.Background(),
1952 },
1953 wantErr: true,
1954 },
1955 }
1956 for _, tt := range tests {
1957 t.Run(tt.name, func(t *testing.T) {
1958 vpv := &VoltPortVnet{
1959 Device: "SDX6320031",
1960 MacLearning: MacLearningNone,
1961 MacAddr: net.HardwareAddr(pendingPoolTimer),
1962 }
1963 switch tt.name {
1964 case "AddUsPppoeFlows":
1965 if err := vpv.AddUsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1966 t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr)
1967 }
1968 case "AddDsPppoeFlows":
1969 appMock := mocks.NewMockApp(gomock.NewController(t))
1970 cntlr.NewController(ctx, appMock)
1971 vc := cntlr.GetController()
Akash Sonib03636c2023-10-31 12:30:59 +05301972 portsByName := map[string]*cntlr.DevicePort{}
1973 portsByName["16777472"] = &cntlr.DevicePort{
1974 Name: "16777472",
1975 ID: 256,
1976 }
1977 device := &cntlr.Device{
1978 ID: "SDX6320031",
1979 PortsByName: portsByName,
1980 }
bseenivaa8cb94c2024-12-16 13:37:17 +05301981 vc.Devices.Store("SDX6320031", device)
Akash Sonib03636c2023-10-31 12:30:59 +05301982 if err := vpv.AddDsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1983 t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr)
1984 }
1985 case "AddUsPppoeFlows_StateDown":
1986 voltDev.State = cntlr.DeviceStateDOWN
1987 if err := vpv.AddUsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1988 t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr)
1989 }
1990 case "AddDsPppoeFlows_StateDown":
1991 voltDev.State = cntlr.DeviceStateDOWN
1992 if err := vpv.AddDsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1993 t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr)
1994 }
1995 case "AddUsPppoeFlows_DeviceNotFound":
1996 vpv.Device = ""
1997 if err := vpv.AddUsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr {
1998 t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr)
1999 }
2000 case "AddDsPppoeFlows_DeviceNotFound":
2001 vpv.Device = ""
2002 if err := vpv.AddDsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr {
2003 t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr)
2004 }
2005 }
2006 })
2007 }
2008}
2009
2010func TestVoltPortVnet_AddIgmpFlows(t *testing.T) {
2011 type args struct {
2012 cntx context.Context
2013 }
2014 var voltPortTest = &VoltPort{
2015 Name: "test_name",
2016 State: PortStateUp,
2017 }
2018 tests := []struct {
2019 name string
2020 args args
2021 wantErr bool
2022 }{
2023 {
2024 name: "AddIgmpFlows",
2025 args: args{
2026 cntx: context.Background(),
2027 },
2028 wantErr: true,
2029 },
2030 }
2031 for _, tt := range tests {
2032 t.Run(tt.name, func(t *testing.T) {
2033 vpv := &VoltPortVnet{
2034 MvlanProfileName: "mvlan_profile",
2035 }
2036 va := GetApplication()
2037 va.PortsDisc.Store("test_port", voltPortTest)
2038 if err := vpv.AddIgmpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
2039 t.Errorf("VoltPortVnet.AddIgmpFlows() error = %v, wantErr %v", err, tt.wantErr)
2040 }
2041 })
2042 }
2043}
2044
2045func TestVoltPortVnet_BuildUsDhcp6Flows(t *testing.T) {
2046 voltPort := &VoltPort{
2047 Name: "16777216",
2048 Device: "SDX6320031",
2049 ID: 16777216,
2050 State: PortStateDown,
2051 ChannelPerSubAlarmRaised: false,
2052 Type: VoltPortTypeNni,
2053 }
2054 voltService := &VoltService{
2055 Version: "test_version",
2056 VoltServiceCfg: VoltServiceCfg{
2057 VnetID: "test_vnet_id",
2058 Port: "16777216",
2059 SVlan: of.VlanAny,
2060 CVlan: of.VlanAny,
2061 UniVlan: of.VlanAny,
2062 },
2063 }
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302064 deviceConfig := &DeviceConfig{
2065 SerialNumber: "SDX6320031",
2066 HardwareIdentifier: "dummy_hardware_identifier",
2067 IPAddress: "10.9.8.7",
2068 UplinkPort: "16777216",
2069 NasID: "nas_id",
2070 NniDhcpTrapVid: 123,
2071 }
Akash Sonib03636c2023-10-31 12:30:59 +05302072 voltDev := &VoltDevice{
2073 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2074 SerialNum: "SDX6320031",
2075 NniDhcpTrapVid: 123,
2076 State: cntlr.DeviceStateUP,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302077 NniPort: []string{"16777472"},
Akash Sonib03636c2023-10-31 12:30:59 +05302078 Ports: sync.Map{},
2079 }
2080 tests := []struct {
2081 name string
2082 want *of.VoltFlow
2083 wantErr bool
2084 }{
2085 {
2086 name: "BuildUsDhcp6Flows",
2087 want: &of.VoltFlow{},
2088 },
2089 {
2090 name: "BuildDsDhcp6Flows",
2091 want: &of.VoltFlow{},
2092 },
2093 {
2094 name: "BuildDsDhcp6Flows_DeviceNotFound",
2095 want: &of.VoltFlow{},
2096 wantErr: true,
2097 },
2098 {
2099 name: "BuildUsDhcp6Flows_portnotfound",
2100 want: &of.VoltFlow{},
2101 wantErr: true,
2102 },
2103 {
2104 name: "BuildDsDhcp6Flows_portnotfound",
2105 want: &of.VoltFlow{},
2106 wantErr: true,
2107 },
2108 }
2109 for _, tt := range tests {
2110 t.Run(tt.name, func(t *testing.T) {
2111 vpv := &VoltPortVnet{
2112 Port: "16777216",
2113 services: sync.Map{},
2114 AllowTransparent: true,
2115 Device: "SDX6320031",
2116 }
2117 va := GetApplication()
2118 va.PortsDisc.Store("16777216", voltPort)
2119 vpv.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltService)
2120 switch tt.name {
2121 case "BuildUsDhcp6Flows":
2122 got, err := vpv.BuildUsDhcp6Flows()
2123 if (err != nil) != tt.wantErr {
2124 t.Errorf("VoltPortVnet.BuildUsDhcp6Flows() error = %v, wantErr %v", err, tt.wantErr)
2125 return
2126 }
2127 assert.NotNil(t, got)
2128 case "BuildDsDhcp6Flows":
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302129 voltDev.NniPort = []string{"16777216"}
akashreddykeb418f12025-10-30 10:58:42 +05302130 voltDev.Ports.Store("16777216", voltPort)
Akash Sonib03636c2023-10-31 12:30:59 +05302131 va.DevicesDisc.Store("SDX6320031", voltDev)
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302132 va.DevicesConfig.Store("SDX6320031", deviceConfig)
Akash Sonib03636c2023-10-31 12:30:59 +05302133 got, err := vpv.BuildDsDhcp6Flows()
2134 if (err != nil) != tt.wantErr {
2135 t.Errorf("VoltPortVnet.BuildDsDhcp6Flows() error = %v, wantErr %v", err, tt.wantErr)
2136 return
2137 }
2138 assert.NotNil(t, got)
2139 case "BuildDsDhcp6Flows_DeviceNotFound":
2140 vpv.Device = ""
2141 got, err := vpv.BuildDsDhcp6Flows()
2142 if (err != nil) != tt.wantErr {
2143 t.Errorf("VoltPortVnet.BuildDsDhcp6Flows() error = %v, wantErr %v", err, tt.wantErr)
2144 return
2145 }
2146 assert.Nil(t, got)
2147 case "BuildUsDhcp6Flows_portnotfound":
2148 vpv.Port = ""
2149 got, err := vpv.BuildUsDhcp6Flows()
2150 if (err != nil) != tt.wantErr {
2151 t.Errorf("VoltPortVnet.BuildUsDhcp6Flows_portnotfound() error = %v, wantErr %v", err, tt.wantErr)
2152 return
2153 }
2154 assert.Nil(t, got)
2155 case "BuildDsDhcp6Flows_portnotfound":
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302156 voltDev.NniPort = []string{"abc"}
Akash Sonib03636c2023-10-31 12:30:59 +05302157 got, err := vpv.BuildDsDhcp6Flows()
2158 if (err != nil) != tt.wantErr {
2159 t.Errorf("VoltPortVnet.BuildDsDhcp6Flows_portnotfound() error = %v, wantErr %v", err, tt.wantErr)
2160 return
2161 }
2162 assert.Nil(t, got)
2163 }
2164 })
2165 }
2166}
2167
2168func TestVoltPortVnet_setUsMatchVlan(t *testing.T) {
2169 type args struct {
2170 flow *of.VoltSubFlow
2171 }
2172 tests := []struct {
2173 name string
2174 args args
2175 wantErr bool
2176 }{
2177 {
2178 name: "setUsMatchVlan",
2179 args: args{
2180 flow: &of.VoltSubFlow{},
2181 },
2182 },
2183 {
2184 name: "OLTCVlanOLTSVlan",
2185 args: args{
2186 flow: &of.VoltSubFlow{},
2187 },
2188 },
2189 {
2190 name: "ONUCVlan",
2191 args: args{
2192 flow: &of.VoltSubFlow{},
2193 },
2194 },
2195 {
2196 name: "OLTSVlan",
2197 args: args{
2198 flow: &of.VoltSubFlow{},
2199 },
2200 },
2201 {
2202 name: "Default",
2203 args: args{
2204 flow: &of.VoltSubFlow{},
2205 },
2206 wantErr: true,
2207 },
2208 {
2209 name: "setDsMatchVlan_OLTCVlanOLTSVlan",
2210 args: args{
2211 flow: &of.VoltSubFlow{},
2212 },
2213 },
2214 {
2215 name: "setDsMatchVlan_Default",
2216 args: args{
2217 flow: &of.VoltSubFlow{},
2218 },
2219 },
2220 }
2221 for _, tt := range tests {
2222 t.Run(tt.name, func(t *testing.T) {
2223 vpv := &VoltPortVnet{
2224 VlanControl: ONUCVlanOLTSVlan,
2225 }
2226 switch tt.name {
2227 case "setUsMatchVlan":
2228 if err := vpv.setUsMatchVlan(tt.args.flow); (err != nil) != tt.wantErr {
2229 t.Errorf("VoltPortVnet.setUsMatchVlan() error = %v, wantErr %v", err, tt.wantErr)
2230 }
2231 case "OLTCVlanOLTSVlan":
2232 vpv.VlanControl = OLTCVlanOLTSVlan
2233 if err := vpv.setUsMatchVlan(tt.args.flow); (err != nil) != tt.wantErr {
2234 t.Errorf("VoltPortVnet.setUsMatchVlan() error = %v, wantErr %v", err, tt.wantErr)
2235 }
2236 case "ONUCVlan":
2237 vpv.VlanControl = ONUCVlan
2238 if err := vpv.setUsMatchVlan(tt.args.flow); (err != nil) != tt.wantErr {
2239 t.Errorf("VoltPortVnet.setUsMatchVlan() error = %v, wantErr %v", err, tt.wantErr)
2240 }
2241 case "OLTSVlan":
2242 vpv.VlanControl = OLTSVlan
2243 if err := vpv.setUsMatchVlan(tt.args.flow); (err != nil) != tt.wantErr {
2244 t.Errorf("VoltPortVnet.setUsMatchVlan() error = %v, wantErr %v", err, tt.wantErr)
2245 }
2246 case "Default":
2247 vpv.VlanControl = opt82
2248 if err := vpv.setUsMatchVlan(tt.args.flow); (err != nil) != tt.wantErr {
2249 t.Errorf("VoltPortVnet.setUsMatchVlan() error = %v, wantErr %v", err, tt.wantErr)
2250 }
2251 case "setDsMatchVlan_OLTCVlanOLTSVlan":
2252 vpv.VlanControl = OLTCVlanOLTSVlan
2253 vpv.setDsMatchVlan(tt.args.flow)
2254 case "setDsMatchVlan_Default":
2255 vpv.VlanControl = opt82
2256 vpv.setDsMatchVlan(tt.args.flow)
2257 }
2258 })
2259 }
2260}
2261
2262func TestVoltPortVnet_BuildIgmpFlows(t *testing.T) {
2263 va := GetApplication()
2264 devicesList := make(map[string]OperInProgress)
2265 devicesList["SDX6320030"] = opt82
2266 mvp := &MvlanProfile{
2267 Name: "mvlan_test",
2268 DevicesList: devicesList,
2269 }
2270 va.MvlanProfilesByName.Store("mvlan_test", mvp)
2271 voltPort := &VoltPort{
2272 Name: "16777472",
2273 Device: "SDX6320031",
2274 ID: 16777472,
2275 State: PortStateUp,
2276 ChannelPerSubAlarmRaised: false,
2277 }
2278 va.PortsDisc.Store("16777472", voltPort)
2279 tests := []struct {
2280 name string
2281 want *of.VoltFlow
2282 wantErr bool
2283 }{
2284 {
2285 name: "BuildIgmpFlows",
2286 want: &of.VoltFlow{},
2287 },
2288 {
2289 name: "BuildIgmpFlows_McastService_False",
2290 want: &of.VoltFlow{},
2291 },
2292 {
2293 name: "BuildIgmpFlows_PortNotFound",
2294 want: nil,
2295 wantErr: true,
2296 },
2297 }
2298 for _, tt := range tests {
2299 t.Run(tt.name, func(t *testing.T) {
2300 vpv := &VoltPortVnet{
2301 Port: "16777472",
2302 MvlanProfileName: "mvlan_test",
2303 MacLearning: MacLearningNone,
2304 MacAddr: util.Uint32ToByte(uint32(23)),
2305 McastService: true,
2306 AllowTransparent: true,
2307 }
2308
2309 switch tt.name {
2310 case "BuildIgmpFlows":
2311 got, err := vpv.BuildIgmpFlows()
2312 if (err != nil) != tt.wantErr {
2313 t.Errorf("VoltPortVnet.BuildIgmpFlows() error = %v, wantErr %v", err, tt.wantErr)
2314 return
2315 }
2316 assert.NotNil(t, got)
2317 case "BuildIgmpFlows_McastService_False":
2318 vpv.McastService = false
2319 vpv.services.Store("16777472", &VoltService{})
2320 got, err := vpv.BuildIgmpFlows()
2321 if (err != nil) != tt.wantErr {
2322 t.Errorf("VoltPortVnet.BuildIgmpFlows() error = %v, wantErr %v", err, tt.wantErr)
2323 return
2324 }
2325 assert.NotNil(t, got)
2326 case "BuildIgmpFlows_PortNotFound":
2327 vpv.Port = ""
2328 got, err := vpv.BuildIgmpFlows()
2329 if (err != nil) != tt.wantErr {
2330 t.Errorf("VoltPortVnet.BuildIgmpFlows() error = %v, wantErr %v", err, tt.wantErr)
2331 return
2332 }
2333 assert.Nil(t, got)
2334 }
2335 })
2336 }
2337}
2338
2339func TestVoltPortVnet_SetMacAddr(t *testing.T) {
2340 type args struct {
2341 cntx context.Context
2342 addr net.HardwareAddr
2343 }
2344 addr, _ := net.ParseMAC("00:00:11:00:00:00")
2345 macAddr, _ := net.ParseMAC("00:00:00:00:00:11")
2346 tests := []struct {
2347 name string
2348 args args
2349 }{
2350 {
2351 name: "SetMacAddr",
2352 args: args{
2353 cntx: context.Background(),
2354 addr: addr,
2355 },
2356 },
2357 }
2358 for _, tt := range tests {
2359 t.Run(tt.name, func(t *testing.T) {
2360 vpv := &VoltPortVnet{
2361 MacAddr: macAddr,
2362 MacLearning: MaxLenDhcpv6DUID,
2363 FlowsApplied: true,
2364 }
2365 switch tt.name {
2366 case "SetMacAddr":
2367 vpv.SetMacAddr(tt.args.cntx, tt.args.addr)
2368 }
2369 })
2370 }
2371}
2372
2373func TestVoltPortVnet_AddTrapFlows(t *testing.T) {
2374 type args struct {
2375 cntx context.Context
2376 }
2377 tests := []struct {
2378 name string
2379 args args
2380 }{
2381 {
2382 name: "AddTrapFlows",
2383 args: args{
2384 cntx: context.Background(),
2385 },
2386 },
2387 {
2388 name: "AddTrapFlows_ArpRelay",
2389 args: args{
2390 cntx: context.Background(),
2391 },
2392 },
2393 {
2394 name: "AddTrapFlows_PppoeIa",
2395 args: args{
2396 cntx: context.Background(),
2397 },
2398 },
2399 }
2400 for _, tt := range tests {
2401 t.Run(tt.name, func(t *testing.T) {
2402 vpv := &VoltPortVnet{
2403 DhcpRelay: true,
2404 DeleteInProgress: true,
2405 }
2406 switch tt.name {
2407 case "AddTrapFlows":
2408 vpv.AddTrapFlows(tt.args.cntx)
2409 case "AddTrapFlows_ArpRelay":
2410 vpv.DhcpRelay = false
2411 vpv.ArpRelay = true
2412 vpv.AddTrapFlows(tt.args.cntx)
2413 case "AddTrapFlows_PppoeIa":
2414 vpv.DhcpRelay = false
2415 vpv.ArpRelay = false
2416 vpv.PppoeIa = true
2417 vpv.AddTrapFlows(tt.args.cntx)
2418 }
2419 })
2420 }
2421}
2422
2423func TestVoltPortVnet_DelTrapFlows(t *testing.T) {
2424 type args struct {
2425 cntx context.Context
2426 }
2427 tests := []struct {
2428 name string
2429 args args
2430 }{
2431 {
2432 name: "DelTrapFlows",
2433 args: args{
2434 cntx: context.Background(),
2435 },
2436 },
2437 }
2438 for _, tt := range tests {
2439 t.Run(tt.name, func(t *testing.T) {
2440 vpv := &VoltPortVnet{
2441 FlowsApplied: true,
2442 DhcpRelay: true,
2443 DeleteInProgress: true,
2444 }
2445 switch tt.name {
2446 case "DelTrapFlows":
2447 vpv.DelTrapFlows(tt.args.cntx)
2448 }
2449 })
2450 }
2451}
2452
2453func TestVoltPortVnet_delDsDhcp4Flows(t *testing.T) {
2454 type args struct {
2455 cntx context.Context
2456 device *VoltDevice
2457 }
2458 voltDev := &VoltDevice{
2459 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2460 SerialNum: "SDX6320031",
2461 NniDhcpTrapVid: 123,
2462 State: cntlr.DeviceStateUP,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302463 NniPort: []string{"16777472"},
Akash Sonib03636c2023-10-31 12:30:59 +05302464 Ports: sync.Map{},
2465 FlowDelEventMap: util.NewConcurrentMap(),
2466 }
2467 va := GetApplication()
2468 devicesList := make(map[string]OperInProgress)
2469 devicesList["SDX6320031"] = opt82
2470 mvp := &MvlanProfile{
2471 Name: "mvlan_test",
2472 DevicesList: devicesList,
2473 }
2474 va.MvlanProfilesByName.Store("mvlan_test", mvp)
2475 voltPort := &VoltPort{
2476 Name: "16777472",
2477 Device: "SDX6320031",
2478 ID: 16777472,
2479 State: PortStateUp,
2480 ChannelPerSubAlarmRaised: false,
2481 }
2482 va.DevicesDisc.Store("SDX6320031", voltDev)
2483 va.PortsDisc.Store("16777472", voltPort)
2484 appMock := mocks.NewMockApp(gomock.NewController(t))
2485 controller.NewController(ctx, appMock)
2486 vc := cntlr.GetController()
Akash Sonib03636c2023-10-31 12:30:59 +05302487 portsByName := map[string]*cntlr.DevicePort{}
2488 portsByName["16777472"] = &cntlr.DevicePort{
2489 Name: "16777472",
2490 ID: 256,
2491 }
2492 device := &cntlr.Device{
2493 ID: deviceName,
2494 PortsByName: portsByName,
2495 }
bseenivaa8cb94c2024-12-16 13:37:17 +05302496 vc.Devices.Store("SDX6320031", device)
Akash Sonib03636c2023-10-31 12:30:59 +05302497 tests := []struct {
2498 name string
2499 args args
2500 wantErr bool
2501 }{
2502 {
2503 name: "delDsDhcp4Flows",
2504 args: args{
2505 cntx: context.Background(),
2506 device: voltDev,
2507 },
2508 wantErr: true,
2509 },
2510 }
2511 for _, tt := range tests {
2512 t.Run(tt.name, func(t *testing.T) {
2513 vpv := &VoltPortVnet{
2514 Device: "SDX6320031",
2515 Port: "16777472",
2516 MvlanProfileName: "mvlan_test",
2517 MacLearning: MacLearningNone,
2518 MacAddr: util.Uint32ToByte(uint32(23)),
2519 McastService: true,
2520 AllowTransparent: true,
2521 PendingDeleteFlow: make(map[string]bool),
2522 }
2523 if err := vpv.delDsDhcp4Flows(tt.args.cntx, tt.args.device); (err != nil) != tt.wantErr {
2524 t.Errorf("VoltPortVnet.delDsDhcp4Flows() error = %v, wantErr %v", err, tt.wantErr)
2525 }
2526 })
2527 }
2528}
2529
2530func TestVoltApplication_DeleteDevFlowForVlan(t *testing.T) {
2531 type args struct {
2532 cntx context.Context
2533 vnet *VoltVnet
2534 }
2535 voltDev := &VoltDevice{
2536 Name: "SDX6320031",
2537 SerialNum: "SDX6320031",
2538 NniDhcpTrapVid: 123,
2539 State: cntlr.DeviceStateUP,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302540 NniPort: []string{"16777472"},
Akash Sonib03636c2023-10-31 12:30:59 +05302541 Ports: sync.Map{},
2542 FlowDelEventMap: util.NewConcurrentMap(),
2543 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
2544 }
2545 voltVnet := &VoltVnet{
2546 Version: "v3",
2547 VnetConfig: VnetConfig{
2548 Name: "2310-4096-4096",
2549 VnetType: "Encapsulation",
2550 },
2551 VnetOper: VnetOper{
2552 PendingDeviceToDelete: "SDX6320031",
2553 DeleteInProgress: true,
2554 PendingDeleteFlow: make(map[string]map[string]bool),
2555 },
2556 }
2557 voltPort := &VoltPort{
2558 Name: "16777472",
2559 Device: "SDX6320031",
2560 ID: 16777472,
2561 State: PortStateUp,
2562 ChannelPerSubAlarmRaised: false,
2563 }
2564 tests := []struct {
2565 name string
2566 args args
2567 }{
2568 {
2569 name: "DeleteDevFlowForVlan",
2570 args: args{
2571 cntx: context.Background(),
2572 vnet: voltVnet,
2573 },
2574 },
2575 {
2576 name: "DeleteDevFlowForVlan_PortStateDown",
2577 args: args{
2578 cntx: context.Background(),
2579 vnet: voltVnet,
2580 },
2581 },
2582 }
2583 for _, tt := range tests {
2584 t.Run(tt.name, func(t *testing.T) {
2585 va := &VoltApplication{}
2586 switch tt.name {
2587 case "DeleteDevFlowForVlan":
2588 va.DevicesDisc.Store("SDX6320031", voltDev)
2589 va.VnetsByName.Store("2310-4096-4096", voltVnet)
2590 voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap())
2591 va.PortsDisc.Store("16777472", voltPort)
2592 appMock := mocks.NewMockApp(gomock.NewController(t))
2593 cntlr.NewController(ctx, appMock)
2594 vc := cntlr.GetController()
Akash Sonib03636c2023-10-31 12:30:59 +05302595 portsByName := map[string]*cntlr.DevicePort{}
2596 portsByName["16777472"] = &cntlr.DevicePort{
2597 Name: "16777472",
2598 ID: 256,
2599 State: cntlr.PortStateUp,
2600 }
2601 device := &cntlr.Device{
2602 ID: "SDX6320031",
2603 PortsByName: portsByName,
2604 }
bseenivaa8cb94c2024-12-16 13:37:17 +05302605 vc.Devices.Store("SDX6320031", device)
Akash Sonib03636c2023-10-31 12:30:59 +05302606 va.DeleteDevFlowForVlan(tt.args.cntx, tt.args.vnet)
2607 case "DeleteDevFlowForVlan_PortStateDown":
2608 voltDev.Name = ""
2609 va.DevicesDisc.Store("SDX6320031", voltDev)
2610 va.VnetsByName.Store("2310-4096-4096", voltVnet)
2611 voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap())
2612 va.PortsDisc.Store("16777472", voltPort)
2613 appMock := mocks.NewMockApp(gomock.NewController(t))
2614 cntlr.NewController(ctx, appMock)
2615 vc := cntlr.GetController()
Akash Sonib03636c2023-10-31 12:30:59 +05302616 portsByName := map[string]*cntlr.DevicePort{}
2617 portsByName["16777472"] = &cntlr.DevicePort{
2618 Name: "16777472",
2619 ID: 256,
2620 State: cntlr.PortStateUp,
2621 }
2622 device := &cntlr.Device{
2623 ID: "SDX6320031",
2624 PortsByName: portsByName,
2625 }
bseenivaa8cb94c2024-12-16 13:37:17 +05302626 vc.Devices.Store("SDX6320031", device)
Akash Sonib03636c2023-10-31 12:30:59 +05302627 va.DeleteDevFlowForVlan(tt.args.cntx, tt.args.vnet)
2628 }
2629 })
2630 }
2631}