blob: 077f2accd8ba7a0e7605f6b21a70a90bdaaaca99 [file] [log] [blame]
vinokumaf7605fc2023-06-02 18:08:01 +05301/*
2* Copyright 2022-present Open Networking Foundation
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14 */
15
16package application
17
18import (
19 "context"
20 "encoding/json"
21 "net"
22 "reflect"
23 "sync"
24 "testing"
vinokuma04dc9f82023-07-31 15:47:49 +053025 "time"
vinokumaf7605fc2023-06-02 18:08:01 +053026 "voltha-go-controller/internal/pkg/controller"
27 "voltha-go-controller/internal/pkg/intf"
28 "voltha-go-controller/internal/pkg/of"
29 "voltha-go-controller/internal/pkg/util"
30 "voltha-go-controller/internal/test/mocks"
31
bseenivadd66c362026-02-12 19:13:26 +053032 "go.uber.org/mock/gomock"
vinokumaf7605fc2023-06-02 18:08:01 +053033 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
34 "github.com/stretchr/testify/assert"
35 "go.uber.org/atomic"
36)
37
vinokuma02fbfd02023-07-05 15:23:33 +053038var test_data = "1234"
39
vinokumaf7605fc2023-06-02 18:08:01 +053040func TestVoltApplication_RestoreNbDeviceFromDb(t *testing.T) {
41 type args struct {
42 cntx context.Context
43 deviceID string
44 }
45 tests := []struct {
46 name string
47 args args
48 }{
49 {
50 name: "VoltApplication_RestoreNbDeviceFromDb",
51 args: args{
52 cntx: context.Background(),
53 deviceID: "test_device_id",
54 },
55 },
56 {
57 name: "VoltApplication_RestoreNbDeviceFromDb_invalid_Value_type",
58 args: args{
59 cntx: context.Background(),
60 deviceID: "test_device_id1",
61 },
62 },
63 {
64 name: "VoltApplication_RestoreNbDeviceFromDb_unmarshal_error",
65 args: args{
66 cntx: context.Background(),
67 deviceID: "test_device_id1",
68 },
69 },
70 }
71 for _, tt := range tests {
72 t.Run(tt.name, func(t *testing.T) {
73 va := &VoltApplication{
74 NbDevice: sync.Map{},
75 }
76 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
77 db = dbintf
78 switch tt.name {
79 case "VoltApplication_RestoreNbDeviceFromDb":
80 var port PonPortCfg
81 port = PonPortCfg{
82 PortAlarmProfileID: "test",
83 PortID: 256,
84 MaxActiveChannels: 256,
85 ActiveIGMPChannels: 7679,
86 EnableMulticastKPI: false,
87 }
88 b, err := json.Marshal(port)
89 if err != nil {
90 panic(err)
91 }
92 test := map[string]*kvstore.KVPair{}
93 test["test_device_id"] = &kvstore.KVPair{
94 Key: "test_device_id",
95 Value: b,
96 }
97 dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1)
98 got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID)
99 assert.NotNil(t, got)
100 case "VoltApplication_RestoreNbDeviceFromDb_invalid_Value_type":
101 test := map[string]*kvstore.KVPair{}
102 test["test_device_id"] = &kvstore.KVPair{
103 Key: "test_device_id",
vinokuma703a70b2023-07-17 10:06:43 +0530104 Value: invalid_value,
vinokumaf7605fc2023-06-02 18:08:01 +0530105 }
106 dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1)
107 got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID)
108 assert.NotNil(t, got)
109 case "VoltApplication_RestoreNbDeviceFromDb_unmarshal_error":
110 b, err := json.Marshal("error")
111 if err != nil {
112 panic(err)
113 }
114 test := map[string]*kvstore.KVPair{}
115 test["test_device_id"] = &kvstore.KVPair{
116 Key: "test_device_id",
117 Value: b,
118 }
119 dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1)
120 got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID)
121 assert.NotNil(t, got)
122 }
123 })
124 }
125}
126
127func TestVoltApplication_UpdateDeviceConfig(t *testing.T) {
128 type args struct {
129 cntx context.Context
130 deviceConfig *DeviceConfig
131 }
132
133 dvcConfg := &DeviceConfig{
134 SerialNumber: "SDX6320031",
135 HardwareIdentifier: "0.0.0.0",
136 IPAddress: "127.26.1.74",
137 UplinkPort: "43322",
138 NasID: "12345",
139 NniDhcpTrapVid: 123,
140 }
141
142 voltDev := &VoltDevice{
143 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
144 SerialNum: "SDX6320031",
145 NniDhcpTrapVid: 123,
146 }
147 tests := []struct {
148 name string
149 args args
150 }{
151 {
152 name: "SDX6320031",
153 args: args{
154 cntx: context.Background(),
155 deviceConfig: dvcConfg,
156 },
157 },
158 }
159
160 for _, tt := range tests {
161 t.Run(tt.name, func(t *testing.T) {
162 va := &VoltApplication{
163 DevicesDisc: sync.Map{},
164 DevicesConfig: sync.Map{},
165 }
166 va.DevicesDisc.Store("SDX6320031", voltDev)
167 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
168 db = dbintf
169 dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
170
171 va.UpdateDeviceConfig(tt.args.cntx, tt.args.deviceConfig)
172 })
173 }
174}
175
176func TestVoltApplication_RestoreOltFlowService(t *testing.T) {
177 type fields struct {
178 OltFlowServiceConfig OltFlowService
179 }
180 type args struct {
181 cntx context.Context
182 }
183 tests := []struct {
184 name string
185 fields fields
186 args args
187 }{
188 {
189 name: "OltFlowService",
190 args: args{
191 cntx: context.Background(),
192 },
193 fields: fields{
194 OltFlowServiceConfig: OltFlowService{
195 DefaultTechProfileID: 1233,
196 EnableDhcpOnNni: true,
197 EnableIgmpOnNni: false,
198 RemoveFlowsOnDisable: false,
199 },
200 },
201 },
202 }
203 for _, tt := range tests {
204 t.Run(tt.name, func(t *testing.T) {
205 va := &VoltApplication{
206 OltFlowServiceConfig: tt.fields.OltFlowServiceConfig,
207 }
208
209 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
210 db = dbintf
211 dbintf.EXPECT().GetOltFlowService(gomock.Any()).AnyTimes()
212
213 va.RestoreOltFlowService(tt.args.cntx)
214 })
215 }
216}
217
218func TestVoltApplication_UpdateOltFlowService(t *testing.T) {
219 type fields struct {
220 OltFlowServiceConfig OltFlowService
221 }
222 type args struct {
223 cntx context.Context
224 oltFlowService OltFlowService
225 }
226 tests := []struct {
227 name string
228 fields fields
229 args args
230 }{
231 {
232 name: "OltFlowService",
233 args: args{
234 cntx: context.Background(),
235 oltFlowService: OltFlowService{
236 DefaultTechProfileID: 1233,
237 EnableDhcpOnNni: true,
238 EnableIgmpOnNni: false,
239 RemoveFlowsOnDisable: false,
240 },
241 },
242 fields: fields{
243 OltFlowServiceConfig: OltFlowService{
244 DefaultTechProfileID: 1233,
245 EnableDhcpOnNni: true,
246 EnableIgmpOnNni: false,
247 RemoveFlowsOnDisable: false,
248 },
249 },
250 },
251 }
252 for _, tt := range tests {
253 t.Run(tt.name, func(t *testing.T) {
254 va := &VoltApplication{
255 OltFlowServiceConfig: tt.fields.OltFlowServiceConfig,
256 }
257
258 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
259 db = dbintf
260 dbintf.EXPECT().PutOltFlowService(gomock.Any(), gomock.Any()).AnyTimes()
261 va.UpdateOltFlowService(tt.args.cntx, tt.args.oltFlowService)
262 })
263 }
264}
265
266func TestVoltApplication_TriggerPendingVpvDeleteReq(t *testing.T) {
267 type args struct {
268 cntx context.Context
269 device string
270 }
271 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
272 test := map[*VoltPortVnet]bool{}
273 test[&VoltPortVnet{Device: "SDX6320031", Port: "16777472", MacAddr: macAdd}] = true
274 tests := []struct {
275 name string
276 args args
277 }{
278 {
279 name: "SDX6320031",
280 args: args{
281 cntx: context.Background(),
282 device: "SDX6320031",
283 },
284 },
285 }
286 for _, tt := range tests {
287 t.Run(tt.name, func(t *testing.T) {
288 va := &VoltApplication{
289 VoltPortVnetsToDelete: test,
290 }
291 va.TriggerPendingVpvDeleteReq(tt.args.cntx, tt.args.device)
292 })
293 }
294}
295
296func TestVoltApplication_TriggerPendingProfileDeleteReq(t *testing.T) {
297 type args struct {
298 cntx context.Context
299 device string
300 }
301 tests := []struct {
302 name string
303 args args
304 }{
305 {
306 name: "SDX6320031",
307 args: args{
308 cntx: context.Background(),
309 device: "SDX6320031",
310 },
311 },
312 }
313 for _, tt := range tests {
314 t.Run(tt.name, func(t *testing.T) {
315 va := &VoltApplication{
316 DevicesDisc: sync.Map{},
317 }
318 va.TriggerPendingProfileDeleteReq(tt.args.cntx, tt.args.device)
319 })
320 }
321}
322
323func TestVoltApplication_TriggerPendingServiceDeleteReq(t *testing.T) {
324 type args struct {
325 cntx context.Context
326 device string
327 }
328 voltServ := &VoltService{
329 VoltServiceOper: VoltServiceOper{
330 Device: "SDX6320031",
331 ForceDelete: true,
332 },
333 }
334
vinokumaf7605fc2023-06-02 18:08:01 +0530335 tests := []struct {
336 name string
337 args args
338 }{
339 {
340 name: "Positive_Case_TriggerPendingServiceDeleteReq",
341 args: args{
342 cntx: context.Background(),
343 device: "SDX6320031",
344 },
345 },
346 }
347 for _, tt := range tests {
348 t.Run(tt.name, func(t *testing.T) {
349 va := &VoltApplication{
Akash Sonief452f12024-12-12 18:20:28 +0530350 ServicesToDelete: sync.Map{},
vinokumaf7605fc2023-06-02 18:08:01 +0530351 ServiceByName: sync.Map{},
352 DevicesDisc: sync.Map{},
353 }
354
355 va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
Akash Sonief452f12024-12-12 18:20:28 +0530356 va.ServicesToDelete.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", true)
vinokumaf7605fc2023-06-02 18:08:01 +0530357
358 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
359 db = dbintf
360 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
361 dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes()
362 va.TriggerPendingServiceDeleteReq(tt.args.cntx, tt.args.device)
363 })
364 }
365}
366
367func TestVoltApplication_TriggerPendingVnetDeleteReq(t *testing.T) {
368 type args struct {
369 cntx context.Context
370 device string
371 }
372
373 vnetToDel := map[string]bool{}
374 vnetToDel["2310-4096-4096"] = true
375
376 voltVnet := &VoltVnet{
377 Version: "v3",
378 VnetConfig: VnetConfig{
379 Name: "2310-4096-4096",
380 VnetType: "Encapsulation",
381 SVlan: 2310,
382 CVlan: 4096,
383 UniVlan: 4096,
384 SVlanTpid: 33024,
385 },
386 VnetOper: VnetOper{
387 PendingDeviceToDelete: "SDX63200313",
388 },
389 }
390 voltDev := &VoltDevice{
391 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
392 SerialNum: "SDX6320031",
393 NniDhcpTrapVid: 123,
394 }
395
396 tests := []struct {
397 name string
398 args args
399 }{
400 {
401 name: "Negative_Case_TriggerPendingVnetDeleteReq",
402 args: args{
403 cntx: context.Background(),
404 device: "SDX6320031",
405 },
406 },
407 }
408 for _, tt := range tests {
409 t.Run(tt.name, func(t *testing.T) {
410 va := &VoltApplication{
411 VnetsToDelete: vnetToDel,
412 DevicesDisc: sync.Map{},
413 }
414 va.DevicesDisc.Store("SDX6320031", voltDev)
415 va.VnetsByName.Store("2310-4096-4096", voltVnet)
416 va.TriggerPendingVnetDeleteReq(tt.args.cntx, tt.args.device)
417 })
418 }
419}
420
421func TestVoltApplication_UpdateMacInPortMap(t *testing.T) {
422 type args struct {
423 macAddr net.HardwareAddr
424 port string
425 }
426 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
427 macPort := map[string]string{}
vinokuma02fbfd02023-07-05 15:23:33 +0530428 macPort[macAdd.String()] = test_data
vinokumaf7605fc2023-06-02 18:08:01 +0530429 tests := []struct {
430 name string
431 args args
432 }{
433 {
434 name: "Positive_Case_UpdateMacInPortMap",
435 args: args{
436 macAddr: macAdd,
vinokuma02fbfd02023-07-05 15:23:33 +0530437 port: test_data,
vinokumaf7605fc2023-06-02 18:08:01 +0530438 },
439 },
440 }
441 for _, tt := range tests {
442 t.Run(tt.name, func(t *testing.T) {
443 va := &VoltApplication{
444 macPortMap: macPort,
445 }
446 va.UpdateMacInPortMap(tt.args.macAddr, tt.args.port)
447 })
448 }
449}
450
451func TestVoltApplication_GetMacInPortMap(t *testing.T) {
452 type args struct {
453 macAddr net.HardwareAddr
454 }
455 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
456 macPort := map[string]string{}
vinokuma02fbfd02023-07-05 15:23:33 +0530457 macPort[macAdd.String()] = test_data
vinokumaf7605fc2023-06-02 18:08:01 +0530458 tests := []struct {
459 name string
460 args args
461 want string
462 }{
463 {
464 name: "Positive_Case_GetMacInPortMap",
465 args: args{
466 macAddr: macAdd,
467 },
vinokuma02fbfd02023-07-05 15:23:33 +0530468 want: test_data,
vinokumaf7605fc2023-06-02 18:08:01 +0530469 },
470 }
471 for _, tt := range tests {
472 t.Run(tt.name, func(t *testing.T) {
473 va := &VoltApplication{
474 macPortMap: macPort,
475 }
476 if got := va.GetMacInPortMap(tt.args.macAddr); got != tt.want {
477 t.Errorf("VoltApplication.GetMacInPortMap() = %v, want %v", got, tt.want)
478 }
479 })
480 }
481}
482
483func Test_pushFlowFailureNotif(t *testing.T) {
484 type args struct {
485 flowStatus intf.FlowStatus
486 }
487 tests := []struct {
488 name string
489 args args
490 }{
491 {
492 name: "Positive_Case_pushFlowFailureNotif",
493 args: args{
494 flowStatus: intf.FlowStatus{
495 Device: "SDX6320031",
496 Cookie: "68786618880",
497 Status: 0,
498 Flow: &of.VoltSubFlow{
499 Cookie: 68786618880,
500 TableID: 0,
501 Priority: 100,
502 ErrorReason: "",
503 OldCookie: 0,
504 },
505 },
506 },
507 },
508 }
509 for _, tt := range tests {
510 t.Run(tt.name, func(t *testing.T) {
511 pushFlowFailureNotif(tt.args.flowStatus)
512 })
513 }
514}
515
516func TestGetPonPortIDFromUNIPort(t *testing.T) {
517 type args struct {
518 uniPortID uint32
519 }
520 tests := []struct {
521 name string
522 args args
523 want uint32
524 }{
525 {
526 name: "Positive_Case_pushFlowFailureNotif",
527 args: args{
528 uniPortID: 1049600,
529 },
530 want: 1,
531 },
532 }
533 for _, tt := range tests {
534 t.Run(tt.name, func(t *testing.T) {
535 if got := GetPonPortIDFromUNIPort(tt.args.uniPortID); got != tt.want {
536 t.Errorf("GetPonPortIDFromUNIPort() = %v, want %v", got, tt.want)
537 }
538 })
539 }
540}
541
542func TestVoltApplication_ProcessFlowModResultIndication(t *testing.T) {
543 type args struct {
544 cntx context.Context
545 flowStatus intf.FlowStatus
546 }
547 voltDev := &VoltDevice{
548 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
549 SerialNum: "SDX6320031",
550 NniDhcpTrapVid: 123,
551 FlowAddEventMap: util.NewConcurrentMap(),
552 }
553 flowState := intf.FlowStatus{
554 Device: "SDX6320031",
555 Cookie: "68786618880",
556 Status: 1005,
557 FlowModType: 0,
558 Flow: &of.VoltSubFlow{
559 Cookie: 68786618880,
560 OldCookie: 0,
561 TableID: 0,
562 State: 0,
563 Priority: 100,
564 },
565 }
566 flowAddEvent := map[string]*FlowEvent{}
567 flowEvent := &FlowEvent{
568 device: "SDX6320031",
569 cookie: "68786618880",
570 eType: EventTypeControlFlowAdded,
571 }
572 flowAddEvent["68786618880"] = flowEvent
573 voltDev.FlowAddEventMap.Set("6878661888", flowEvent)
574 tests := []struct {
575 name string
576 args args
577 }{
578 {
579 name: "Positive_Case_ProcessFlowModResultIndication",
580 args: args{
581 cntx: context.Background(),
582 flowStatus: flowState,
583 },
584 },
585 {
586 name: "Negetive_Case_ProcessFlowModResultIndication",
587 args: args{
588 cntx: context.Background(),
589 flowStatus: flowState,
590 },
591 },
592 }
593 for _, tt := range tests {
594 t.Run(tt.name, func(t *testing.T) {
595 va := &VoltApplication{
596 DevicesDisc: sync.Map{},
597 }
598 switch tt.name {
599 case "Positive_Case_ProcessFlowModResultIndication":
600 va.DevicesDisc.Store("SDX6320031", voltDev)
601 va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus)
602 case "Negetive_Case_ProcessFlowModResultIndication":
603 va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus)
604 }
605 })
606 }
607}
608func Test_getPendingPoolKey(t *testing.T) {
609 type args struct {
610 mvlan of.VlanType
611 device string
612 }
613
614 tests := []struct {
615 name string
616 args args
617 want string
618 }{
619 {
620 name: "Positive_Case_getPendingPoolKey",
621 args: args{
622 mvlan: of.VlanAny,
623 device: "SDX6320031",
624 },
625 want: "4096_SDX6320031",
626 },
627 }
628 for _, tt := range tests {
629 t.Run(tt.name, func(t *testing.T) {
630 if got := getPendingPoolKey(tt.args.mvlan, tt.args.device); got != tt.want {
631 t.Errorf("getPendingPoolKey() = %v, want %v", got, tt.want)
632 }
633 })
634 }
635}
636
637func TestNewVoltPort(t *testing.T) {
638 type args struct {
639 device string
640 name string
641 id uint32
642 }
643
644 voltPort := &VoltPort{
645 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
646 Device: "SDX6320031",
647 ID: 16777472,
648 State: PortStateDown,
649 ChannelPerSubAlarmRaised: false,
650 Type: VoltPortTypeNni,
651 }
652
653 voltPort1 := &VoltPort{
654 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
655 Device: "SDX6320031",
656 ID: 1049600,
657 State: PortStateDown,
658 ChannelPerSubAlarmRaised: false,
659 PonPort: GetPonPortIDFromUNIPort(1049600),
660 }
661 tests := []struct {
662 name string
663 args args
664 want *VoltPort
665 }{
666 {
667 name: "Positive_Case_TestNewVoltPort",
668 args: args{
669 id: 16777472,
670 device: "SDX6320031",
671 name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
672 },
673 want: voltPort,
674 },
675 {
676 name: "Positive_Case2_TestNewVoltPort",
677 args: args{
678 id: 1049600,
679 device: "SDX6320031",
680 name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
681 },
682 want: voltPort1,
683 },
684 }
685 for _, tt := range tests {
686 t.Run(tt.name, func(t *testing.T) {
687 switch tt.name {
688 case "Positive_Case_TestNewVoltPort":
689 if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) {
690 t.Errorf("NewVoltPort() = %v, want %v", got, tt.want)
691 }
692 case "Positive_Case2_TestNewVoltPort":
693 if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) {
694 t.Errorf("NewVoltPort() = %v, want %v", got, tt.want)
695 }
696 }
697 })
698 }
699}
700
701func TestVoltPort_SetPortID(t *testing.T) {
702 type args struct {
703 id uint32
704 }
705 tests := []struct {
706 name string
707 args args
708 }{
709 {
710 name: "Positive_Case_TestNewVoltPort",
711 args: args{
712 id: 16777472,
713 },
714 },
715 }
716 for _, tt := range tests {
717 t.Run(tt.name, func(t *testing.T) {
718 vp := &VoltPort{
719 ID: 16777472,
720 Type: VoltPortTypeNni,
721 }
722 vp.SetPortID(tt.args.id)
723 })
724 }
725}
726
727func TestNewVoltDevice(t *testing.T) {
728 type args struct {
729 name string
730 slno string
731 southBoundID string
732 }
733
734 devConfig := &DeviceConfig{
735 SerialNumber: "SDX6320033",
736 NniDhcpTrapVid: 4,
737 }
738 voltDevice := &VoltDevice{
739 Name: "11c3175b-50f3-4220-9555-93df733ded1d",
740 SerialNum: "SDX6320033",
741 SouthBoundID: "68580342-6b3e-57cb-9ea4-06125594e330",
742 State: controller.DeviceStateDOWN,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +0530743 NniPort: make([]string, 0),
vinokumaf7605fc2023-06-02 18:08:01 +0530744 icmpv6GroupAdded: false,
745 IgmpDsFlowAppliedForMvlan: make(map[uint16]bool),
746 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
747 MigratingServices: util.NewConcurrentMap(),
748 VpvsBySvlan: util.NewConcurrentMap(),
749 FlowAddEventMap: util.NewConcurrentMap(),
750 FlowDelEventMap: util.NewConcurrentMap(),
751 GlobalDhcpFlowAdded: false,
752 NniDhcpTrapVid: 4,
753 }
754
755 GetApplication().DevicesConfig.Store("SDX6320033", devConfig)
756 tests := []struct {
757 name string
758 args args
759 want *VoltDevice
760 }{
761 {
762 name: "Positive_Case_TestNewVoltDevice",
763 args: args{
764 name: "11c3175b-50f3-4220-9555-93df733ded1d",
765 slno: "SDX6320033",
766 southBoundID: "68580342-6b3e-57cb-9ea4-06125594e330",
767 },
768 want: voltDevice,
769 },
770 }
771 for _, tt := range tests {
772 t.Run(tt.name, func(t *testing.T) {
773 if got := NewVoltDevice(tt.args.name, tt.args.slno, tt.args.southBoundID); !reflect.DeepEqual(got, tt.want) {
774 t.Errorf("NewVoltDevice() = %v, want %v", got, tt.want)
775 }
776 })
777 }
778}
779
780func TestVoltApplication_GetAssociatedVpvsForDevice(t *testing.T) {
781 type args struct {
782 device string
783 svlan of.VlanType
784 }
785
786 voltDev := &VoltDevice{
787 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
788 SerialNum: "SDX6320033",
789 NniDhcpTrapVid: 123,
790 VpvsBySvlan: util.NewConcurrentMap(),
791 }
792
793 cuncurrentMap := &util.ConcurrentMap{
794 Count: atomic.NewUint64(0),
795 }
796
797 voltDev1 := &VoltDevice{
798 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
799 SerialNum: "SDX6320033",
800 NniDhcpTrapVid: 123,
801 VpvsBySvlan: cuncurrentMap,
802 }
803 tests := []struct {
804 name string
805 args args
806 want *util.ConcurrentMap
807 }{
808 {
809 name: "Positive_Case_GetAssociatedVpvsForDevice",
810 args: args{
811 device: "SDX6320033",
812 svlan: of.VlanAny,
813 },
814 want: util.NewConcurrentMap(),
815 },
816 {
817 name: "Positive_Case2_GetAssociatedVpvsForDevice",
818 args: args{
819 device: "SDX6320033",
820 svlan: of.VlanAny,
821 },
822 want: cuncurrentMap,
823 },
824 {
825 name: "Negetive_Case2_GetAssociatedVpvsForDevice",
826 args: args{
827 device: "SDX6320031",
828 svlan: of.VlanAny,
829 },
830 want: nil,
831 },
832 }
833 for _, tt := range tests {
834 t.Run(tt.name, func(t *testing.T) {
835 switch tt.name {
836 case "Positive_Case_GetAssociatedVpvsForDevice":
837 va := &VoltApplication{
838 DevicesDisc: sync.Map{},
839 VnetsBySvlan: util.NewConcurrentMap(),
840 }
841 va.DevicesDisc.Store("SDX6320033", voltDev)
842 if got := va.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
843 t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
844 }
845 case "Positive_Case2_GetAssociatedVpvsForDevice":
846 va1 := &VoltApplication{
847 DevicesDisc: sync.Map{},
848 VnetsBySvlan: cuncurrentMap,
849 }
850 va1.DevicesDisc.Store("SDX6320033", voltDev1)
851 va1.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap)
852 if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
853 t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
854 }
855 case "Negetive_Case2_GetAssociatedVpvsForDevice":
856 va1 := &VoltApplication{
857 DevicesDisc: sync.Map{},
858 }
859 if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
860 t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
861 }
862 }
863 })
864 }
865}
866
867func TestVoltApplication_AssociateVpvsToDevice(t *testing.T) {
868 type args struct {
869 device string
870 vpv *VoltPortVnet
871 }
872
873 vpv := &VoltPortVnet{
874 Device: "SDX6320033",
875 SVlan: of.VlanAny,
876 }
877 voltDev := &VoltDevice{
878 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
879 SerialNum: "SDX6320033",
880 NniDhcpTrapVid: 123,
881 VpvsBySvlan: util.NewConcurrentMap(),
882 }
883 tests := []struct {
884 name string
885 args args
886 }{
887 {
888 name: "Positive_Case_AssociateVpvsToDevice",
889 args: args{
890 device: "SDX6320033",
891 vpv: vpv,
892 },
893 },
894 {
895 name: "Negetive_Case_AssociateVpvsToDevice",
896 args: args{
897 device: "SDX6320033",
898 vpv: vpv,
899 },
900 },
901 }
902 for _, tt := range tests {
903 t.Run(tt.name, func(t *testing.T) {
904 switch tt.name {
905 case "Positive_Case_AssociateVpvsToDevice":
906 va := &VoltApplication{
907 DevicesDisc: sync.Map{},
908 VnetsBySvlan: util.NewConcurrentMap(),
909 }
910 va.DevicesDisc.Store("SDX6320033", voltDev)
911 va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv)
912 case "Negetive_Case_AssociateVpvsToDevice":
913 va := &VoltApplication{
914 DevicesDisc: sync.Map{},
915 VnetsBySvlan: util.NewConcurrentMap(),
916 }
917 va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv)
918 }
919 })
920 }
921}
922
923func TestVoltApplication_DisassociateVpvsFromDevice(t *testing.T) {
924 type args struct {
925 device string
926 vpv *VoltPortVnet
927 }
928 vpv := &VoltPortVnet{
929 Device: "SDX6320033",
930 SVlan: of.VlanAny,
931 }
932
933 voltDev := &VoltDevice{
934 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
935 SerialNum: "SDX6320033",
936 NniDhcpTrapVid: 123,
937 VpvsBySvlan: util.NewConcurrentMap(),
938 }
939 tests := []struct {
940 name string
941 args args
942 }{
943 {
944 name: "Positive_Case_DisassociateVpvsFromDevice",
945 args: args{
946 device: "SDX6320033",
947 vpv: vpv,
948 },
949 },
950 {
951 name: "Negetive_Case_DisassociateVpvsFromDevice",
952 args: args{
953 device: "SDX6320033",
954 vpv: vpv,
955 },
956 },
957 }
958 for _, tt := range tests {
959 t.Run(tt.name, func(t *testing.T) {
960 switch tt.name {
961 case "Positive_Case_DisassociateVpvsFromDevice":
962 va := &VoltApplication{
963 DevicesDisc: sync.Map{},
964 VnetsBySvlan: util.NewConcurrentMap(),
965 }
966 va.DevicesDisc.Store("SDX6320033", voltDev)
967 va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv)
968 case "Negetive_Case_DisassociateVpvsFromDevice":
969 va := &VoltApplication{
970 DevicesDisc: sync.Map{},
971 VnetsBySvlan: util.NewConcurrentMap(),
972 }
973 va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv)
974 }
975 })
976 }
977}
978
979func TestVoltDevice_GetPort(t *testing.T) {
980 type args struct {
981 port string
982 }
983 voltPort := &VoltPort{
984 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
985 Device: "SDX6320031",
986 ID: 16777472,
987 State: PortStateDown,
988 ChannelPerSubAlarmRaised: false,
989 Type: VoltPortTypeNni,
990 }
991 tests := []struct {
992 name string
993 args args
994 want *VoltPort
995 }{
996 {
997 name: "Positive_Case_GetPort",
998 args: args{
999 port: "16777472",
1000 },
1001 want: voltPort,
1002 },
1003 {
1004 name: "Negetive_Case_GetPort",
1005 args: args{
1006 port: "16777472",
1007 },
1008 want: nil,
1009 },
1010 }
1011 for _, tt := range tests {
1012 t.Run(tt.name, func(t *testing.T) {
1013 d := &VoltDevice{
1014 Ports: sync.Map{},
1015 }
1016 switch tt.name {
1017 case "Positive_Case_GetPort":
1018 d.Ports.Store("16777472", voltPort)
1019 if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) {
1020 t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want)
1021 }
1022 case "Negetive_Case_GetPort":
1023 if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) {
1024 t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want)
1025 }
1026 }
1027 })
1028 }
1029}
1030
1031func TestVoltDevice_GetPortNameFromPortID(t *testing.T) {
1032 type args struct {
1033 portID uint32
1034 }
1035 voltPort := &VoltPort{
1036 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1037 Device: "SDX6320031",
1038 ID: 16777472,
1039 State: PortStateDown,
1040 ChannelPerSubAlarmRaised: false,
1041 Type: VoltPortTypeNni,
1042 }
1043 tests := []struct {
1044 name string
1045 args args
1046 want string
1047 }{
1048 {
1049 name: "Positive_Case_GetPort",
1050 args: args{
1051 portID: 16777472,
1052 },
1053 want: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1054 },
1055 }
1056 for _, tt := range tests {
1057 t.Run(tt.name, func(t *testing.T) {
1058 d := &VoltDevice{
1059 Ports: sync.Map{},
1060 }
1061 d.Ports.Store(16777472, voltPort)
1062 if got := d.GetPortNameFromPortID(tt.args.portID); got != tt.want {
1063 t.Errorf("VoltDevice.GetPortNameFromPortID() = %v, want %v", got, tt.want)
1064 }
1065 })
1066 }
1067}
1068
1069func TestVoltDevice_DelPort(t *testing.T) {
1070 type args struct {
1071 port string
1072 }
1073 voltPort := &VoltPort{
1074 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1075 Device: "SDX6320031",
1076 ID: 16777472,
1077 State: PortStateDown,
1078 ChannelPerSubAlarmRaised: false,
1079 Type: VoltPortTypeNni,
1080 }
1081 tests := []struct {
1082 name string
1083 args args
1084 }{
1085 {
1086 name: "Positive_Case_DelPort",
1087 args: args{
1088 port: "16777472",
1089 },
1090 },
1091 {
1092 name: "Negetive_Case_DelPort",
1093 args: args{
1094 port: "16777472",
1095 },
1096 },
1097 }
1098 for _, tt := range tests {
1099 t.Run(tt.name, func(t *testing.T) {
1100 d := &VoltDevice{
1101 Ports: sync.Map{},
1102 }
1103 switch tt.name {
1104 case "Positive_Case_DelPort":
1105 d.Ports.Store("16777472", voltPort)
1106 d.DelPort(tt.args.port)
1107 case "Negetive_Case_DelPort":
1108 d.DelPort(tt.args.port)
1109 }
1110 })
1111 }
1112}
1113
1114func TestVoltDevice_pushFlowsForUnis(t *testing.T) {
Akash Reddy Kankanala16e6c4a2026-02-09 12:52:14 +05301115 NniPort := "nni-16777216"
vinokumaf7605fc2023-06-02 18:08:01 +05301116 type args struct {
1117 cntx context.Context
1118 }
1119 tests := []struct {
1120 name string
1121 args args
1122 }{
1123 {
1124 name: "Positive_Case_pushFlowsForUnis",
1125 args: args{
1126 cntx: context.Background(),
1127 },
1128 },
1129 {
1130 name: "Negetive_Case_pushFlowsForUnis",
1131 args: args{
1132 cntx: context.Background(),
1133 },
1134 },
1135 {
1136 name: "Negetive_Case1_pushFlowsForUnis",
1137 args: args{
1138 cntx: context.Background(),
1139 },
1140 },
1141 }
1142 for _, tt := range tests {
1143 t.Run(tt.name, func(t *testing.T) {
1144 d := &VoltDevice{
1145 Name: "SDX6320031",
1146 SerialNum: "SDX6320031",
1147 Ports: sync.Map{},
1148 }
1149 switch tt.name {
1150 case "Positive_Case_pushFlowsForUnis":
1151 voltPort := &VoltPort{
1152 Name: "16777472",
1153 Device: "SDX6320031",
1154 ID: 16777472,
1155 State: PortStateUp,
1156 ChannelPerSubAlarmRaised: false,
1157 Type: VoltPortTypeNni,
1158 }
1159 d.Ports.Store("16777472", voltPort)
1160 ga := GetApplication()
1161 voltPortVnets := make([]*VoltPortVnet, 0)
1162 voltPortVnet := &VoltPortVnet{
1163 Device: "SDX6320031",
1164 Port: "16777472",
1165 DeleteInProgress: true,
1166 }
1167 voltPortVnets = append(voltPortVnets, voltPortVnet)
1168 ga.VnetsByPort.Store("16777472", voltPortVnets)
1169
Akash Reddy Kankanala16e6c4a2026-02-09 12:52:14 +05301170 d.pushFlowsForUnis(tt.args.cntx, NniPort)
vinokumaf7605fc2023-06-02 18:08:01 +05301171 case "Negetive_Case_pushFlowsForUnis":
1172 voltPort1 := &VoltPort{
1173 Name: "16777472",
1174 Device: "SDX6320031",
1175 ID: 16777472,
1176 State: PortStateDown,
1177 ChannelPerSubAlarmRaised: false,
1178 Type: VoltPortTypeNni,
1179 }
1180 d.Ports.Store("16777472", voltPort1)
Akash Reddy Kankanala16e6c4a2026-02-09 12:52:14 +05301181 d.pushFlowsForUnis(tt.args.cntx, NniPort)
vinokumaf7605fc2023-06-02 18:08:01 +05301182 case "Negetive_Case1_pushFlowsForUnis":
1183 voltPort2 := &VoltPort{
1184 Name: "16777472",
1185 Device: "SDX6320031",
1186 ID: 16777472,
1187 State: PortStateUp,
1188 ChannelPerSubAlarmRaised: false,
1189 Type: VoltPortTypeNni,
1190 }
1191 d.Ports.Store("1677747", voltPort2)
Akash Reddy Kankanala16e6c4a2026-02-09 12:52:14 +05301192 d.pushFlowsForUnis(tt.args.cntx, NniPort)
vinokumaf7605fc2023-06-02 18:08:01 +05301193 }
1194 })
1195 }
1196}
1197
1198func TestNewNbDevice(t *testing.T) {
1199 tests := []struct {
1200 name string
1201 want *NbDevice
1202 }{
1203 {
1204 name: "Positive_Case_pushFlowsForUnis",
1205 want: &NbDevice{},
1206 },
1207 }
1208 for _, tt := range tests {
1209 t.Run(tt.name, func(t *testing.T) {
1210 if got := NewNbDevice(); !reflect.DeepEqual(got, tt.want) {
1211 t.Errorf("NewNbDevice() = %v, want %v", got, tt.want)
1212 }
1213 })
1214 }
1215}
1216
1217func TestNbDevice_WriteToDb(t *testing.T) {
1218 type args struct {
1219 cntx context.Context
1220 portID uint32
1221 ponPort *PonPortCfg
1222 }
1223 tests := []struct {
1224 name string
1225 args args
1226 }{
1227 {
1228 name: "Positive_Case_pushFlowsForUnis",
1229 args: args{
1230 cntx: context.Background(),
1231 portID: controller.NNIPortID,
1232 ponPort: &PonPortCfg{
1233 PortID: controller.NNIPortID,
1234 EnableMulticastKPI: false,
1235 },
1236 },
1237 },
1238 }
1239 for _, tt := range tests {
1240 t.Run(tt.name, func(t *testing.T) {
1241 nbd := &NbDevice{
1242 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1243 }
1244 switch tt.name {
1245 case "Positive_Case_pushFlowsForUnis":
1246 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1247 db = dbintf
1248 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1249 nbd.WriteToDb(tt.args.cntx, tt.args.portID, tt.args.ponPort)
1250 }
1251 })
1252 }
1253}
1254
1255func TestNbDevice_AddPortToNbDevice(t *testing.T) {
1256 type args struct {
1257 cntx context.Context
1258 portID uint32
1259 allowedChannels uint32
1260 enableMulticastKPI bool
1261 portAlarmProfileID string
1262 }
1263 ponPort := &PonPortCfg{
1264 PortID: controller.NNIPortID,
1265 MaxActiveChannels: 123,
1266 EnableMulticastKPI: false,
1267 PortAlarmProfileID: "16777",
1268 }
1269 tests := []struct {
1270 name string
1271 args args
1272 want *PonPortCfg
1273 }{
1274 {
1275 name: "Positive_Case_AddPortToNbDevice",
1276 args: args{
1277 cntx: context.Background(),
1278 portID: controller.NNIPortID,
1279 allowedChannels: 123,
1280 enableMulticastKPI: false,
1281 portAlarmProfileID: "16777",
1282 },
1283 want: ponPort,
1284 },
1285 }
1286 for _, tt := range tests {
1287 t.Run(tt.name, func(t *testing.T) {
1288 nbd := &NbDevice{
1289 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1290 PonPorts: sync.Map{},
1291 }
1292 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1293 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1294 db = dbintf
1295 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1296 if got := nbd.AddPortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1297 t.Errorf("NbDevice.AddPortToNbDevice() = %v, want %v", got, tt.want)
1298 }
1299 })
1300 }
1301}
1302
1303func TestVoltApplication_AddDeviceConfig(t *testing.T) {
1304 type args struct {
1305 cntx context.Context
1306 serialNum string
1307 hardwareIdentifier string
1308 nasID string
1309 ipAddress string
1310 uplinkPort string
Akash Reddy Kankanala105581b2024-09-11 05:20:38 +05301311 nniDhcpTrapID uint16
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301312 nniPorts []string
vinokumaf7605fc2023-06-02 18:08:01 +05301313 }
1314 dvcConfg := &DeviceConfig{
1315 SerialNumber: "SDX6320031",
1316 HardwareIdentifier: "0.0.0.0",
1317 IPAddress: "127.26.1.74",
1318 UplinkPort: "16777216",
1319 NasID: "12345",
1320 NniDhcpTrapVid: 123,
1321 }
1322 voltDev := &VoltDevice{
1323 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1324 SerialNum: "SDX6320031",
1325 NniDhcpTrapVid: 123,
1326 }
1327 tests := []struct {
1328 name string
1329 args args
1330 wantErr bool
1331 }{
1332 {
1333 name: "Positive_Case_AddDeviceConfig",
1334 args: args{
1335 cntx: context.Background(),
1336 serialNum: "SDX6320031",
1337 hardwareIdentifier: "0.0.0.0.",
1338 nasID: "12345",
1339 ipAddress: "127.26.1.74",
1340 uplinkPort: "16777216",
1341 nniDhcpTrapID: 123,
1342 },
1343 wantErr: false,
1344 },
1345 }
1346 for _, tt := range tests {
1347 t.Run(tt.name, func(t *testing.T) {
1348 va := &VoltApplication{
1349 DevicesConfig: sync.Map{},
1350 }
1351 va.DevicesConfig.Store("SDX6320031", dvcConfg)
1352 va.DevicesDisc.Store("SDX6320031", voltDev)
1353 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1354 db = dbintf
1355 dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301356 if err := va.AddDeviceConfig(tt.args.cntx, tt.args.serialNum, tt.args.hardwareIdentifier, tt.args.nasID, tt.args.ipAddress, tt.args.uplinkPort, tt.args.nniDhcpTrapID, tt.args.nniPorts); (err != nil) != tt.wantErr {
vinokumaf7605fc2023-06-02 18:08:01 +05301357 t.Errorf("VoltApplication.AddDeviceConfig() error = %v, wantErr %v", err, tt.wantErr)
1358 }
1359 })
1360 }
1361}
1362
1363func TestVoltApplication_GetDeviceConfig(t *testing.T) {
1364 type args struct {
1365 serNum string
1366 }
1367 dvcConfg := &DeviceConfig{
1368 SerialNumber: "SDX6320031",
1369 HardwareIdentifier: "0.0.0.0",
1370 IPAddress: "127.26.1.74",
1371 UplinkPort: "16777216",
1372 NasID: "12345",
1373 NniDhcpTrapVid: 123,
1374 }
1375 tests := []struct {
1376 name string
1377 args args
1378 want *DeviceConfig
1379 }{
1380 {
1381 name: "Positive_Case_GetDeviceConfig",
1382 args: args{
1383 serNum: "SDX6320031",
1384 },
1385 want: dvcConfg,
1386 },
1387 {
1388 name: "Negetive_Case_GetDeviceConfig",
1389 args: args{
1390 serNum: "SDX6320031",
1391 },
1392 want: nil,
1393 },
1394 }
1395 for _, tt := range tests {
1396 t.Run(tt.name, func(t *testing.T) {
1397 va := &VoltApplication{
1398 DevicesConfig: sync.Map{},
1399 }
1400 switch tt.name {
1401 case "Positive_Case_GetDeviceConfig":
1402 va.DevicesConfig.Store("SDX6320031", dvcConfg)
1403 if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) {
1404 t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want)
1405 }
1406 case "Negetive_Case_GetDeviceConfig":
1407 if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) {
1408 t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want)
1409 }
1410 }
1411 })
1412 }
1413}
1414
1415func TestNbDevice_UpdatePortToNbDevice(t *testing.T) {
1416 type args struct {
1417 cntx context.Context
1418 portID uint32
1419 allowedChannels uint32
1420 enableMulticastKPI bool
1421 portAlarmProfileID string
1422 }
1423 ponPort := &PonPortCfg{
1424 PortID: controller.NNIPortID,
1425 MaxActiveChannels: 123,
1426 EnableMulticastKPI: false,
1427 PortAlarmProfileID: "16777",
1428 }
1429 tests := []struct {
1430 name string
1431 args args
1432 want *PonPortCfg
1433 }{
1434 {
1435 name: "Positive_Case_UpdatePortToNbDevice",
1436 args: args{
1437 cntx: context.Background(),
1438 portID: controller.NNIPortID,
1439 allowedChannels: 123,
1440 enableMulticastKPI: false,
1441 portAlarmProfileID: "16777",
1442 },
1443 want: ponPort,
1444 },
1445 {
1446 name: "Negetive_Case_UpdatePortToNbDevice",
1447 args: args{
1448 cntx: context.Background(),
1449 portID: 0,
1450 allowedChannels: 123,
1451 enableMulticastKPI: false,
1452 portAlarmProfileID: "16777",
1453 },
1454 want: nil,
1455 },
1456 }
1457 for _, tt := range tests {
1458 t.Run(tt.name, func(t *testing.T) {
1459 nbd := &NbDevice{
1460 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1461 PonPorts: sync.Map{},
1462 }
1463 switch tt.name {
1464 case "Positive_Case_UpdatePortToNbDevice":
1465 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1466 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1467 db = dbintf
1468 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1469 if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1470 t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want)
1471 }
1472 case "Negetive_Case_UpdatePortToNbDevice":
1473 if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1474 t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want)
1475 }
1476 }
1477 })
1478 }
1479}
1480
1481func TestNbDevice_DeletePortFromNbDevice(t *testing.T) {
1482 type args struct {
1483 cntx context.Context
1484 portID uint32
1485 }
1486 ponPort := &PonPortCfg{
1487 PortID: controller.NNIPortID,
1488 MaxActiveChannels: 123,
1489 EnableMulticastKPI: false,
1490 PortAlarmProfileID: "16777",
1491 }
1492 tests := []struct {
1493 name string
1494 args args
1495 }{
1496 {
1497 name: "Positive_Case_DeletePortFromNbDevice",
1498 args: args{
1499 portID: controller.NNIPortID,
1500 },
1501 },
1502 }
1503 for _, tt := range tests {
1504 t.Run(tt.name, func(t *testing.T) {
1505 nbd := &NbDevice{
1506 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1507 PonPorts: sync.Map{},
1508 }
1509 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1510 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1511 db = dbintf
1512 dbintf.EXPECT().DelNbDevicePort(nil, "49686e2d-618f-4e8e-bca0-442ab850a63a", controller.NNIPortID).AnyTimes()
1513 nbd.DeletePortFromNbDevice(tt.args.cntx, tt.args.portID)
1514 })
1515 }
1516}
1517
1518func TestVoltDevice_RegisterFlowAddEvent(t *testing.T) {
1519 type args struct {
1520 cookie string
1521 event *FlowEvent
1522 }
1523 flowEvent := &FlowEvent{
1524 device: "SDX6320031",
1525 cookie: "68786618880",
1526 eType: EventTypeControlFlowAdded,
1527 }
1528 tests := []struct {
1529 name string
1530 args args
1531 }{
1532 {
1533 name: "Positive_Case_RegisterFlowAddEvent",
1534 args: args{
1535 cookie: "68786618880",
1536 event: flowEvent,
1537 },
1538 },
1539 }
1540 for _, tt := range tests {
1541 t.Run(tt.name, func(t *testing.T) {
1542 d := &VoltDevice{
1543 FlowAddEventMap: util.NewConcurrentMap(),
1544 }
1545 d.RegisterFlowAddEvent(tt.args.cookie, tt.args.event)
1546 })
1547 }
1548}
1549
1550func TestVoltDevice_RegisterFlowDelEvent(t *testing.T) {
1551 type args struct {
1552 cookie string
1553 event *FlowEvent
1554 }
1555 flowEvent := &FlowEvent{
1556 device: "SDX6320031",
1557 cookie: "68786618880",
1558 eType: EventTypeControlFlowRemoved,
1559 }
1560 tests := []struct {
1561 name string
1562 args args
1563 }{
1564 {
1565 name: "Positive_Case_RegisterFlowDelEvent",
1566 args: args{
1567 cookie: "68786618880",
1568 event: flowEvent,
1569 },
1570 },
1571 }
1572 for _, tt := range tests {
1573 t.Run(tt.name, func(t *testing.T) {
1574 d := &VoltDevice{
1575 FlowDelEventMap: util.NewConcurrentMap(),
1576 }
1577 d.RegisterFlowDelEvent(tt.args.cookie, tt.args.event)
1578 })
1579 }
1580}
1581
1582func TestVoltDevice_UnRegisterFlowEvent(t *testing.T) {
1583 type args struct {
1584 cookie string
1585 flowModType of.Command
1586 }
1587 tests := []struct {
1588 name string
1589 args args
1590 }{
1591 {
1592 name: "Positive_Case_RegisterFlowDelEvent",
1593 args: args{
1594 cookie: "68786618880",
1595 flowModType: of.CommandDel,
1596 },
1597 },
1598 {
1599 name: "Negetive_Case_RegisterFlowDelEvent",
1600 args: args{
1601 cookie: "68786618880",
1602 flowModType: opt82,
1603 },
1604 },
1605 }
1606 for _, tt := range tests {
1607 t.Run(tt.name, func(t *testing.T) {
1608 switch tt.name {
1609 case "Positive_Case_RegisterFlowDelEvent":
1610 d := &VoltDevice{
1611 FlowDelEventMap: util.NewConcurrentMap(),
1612 }
1613 d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType)
1614 case "Negetive_Case_RegisterFlowDelEvent":
1615 d := &VoltDevice{
1616 FlowDelEventMap: util.NewConcurrentMap(),
1617 }
1618 d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType)
1619 }
1620 })
1621 }
1622}
1623
1624func TestVoltApplication_InitStaticConfig(t *testing.T) {
1625 tests := []struct {
1626 name string
1627 }{
1628 {
1629 name: "Positive_Case_InitStaticConfig",
1630 },
1631 }
1632 for _, tt := range tests {
1633 t.Run(tt.name, func(t *testing.T) {
1634 va := &VoltApplication{}
1635 va.InitStaticConfig()
1636 })
1637 }
1638}
1639
1640func TestVoltApplication_SetVendorID(t *testing.T) {
1641 type args struct {
1642 vendorID string
1643 }
1644 tests := []struct {
1645 name string
1646 args args
1647 }{
1648 {
1649 name: "Positive_Case_SetVendorID",
1650 args: args{
1651 vendorID: "DT",
1652 },
1653 },
1654 }
1655 for _, tt := range tests {
1656 t.Run(tt.name, func(t *testing.T) {
1657 va := &VoltApplication{}
1658 va.SetVendorID(tt.args.vendorID)
1659 })
1660 }
1661}
1662
1663func TestVoltApplication_GetVendorID(t *testing.T) {
1664 tests := []struct {
1665 name string
1666 want string
1667 }{
1668 {
1669 name: "Positive_Case_GetVendorID",
1670 want: "DT",
1671 },
1672 }
1673 for _, tt := range tests {
1674 t.Run(tt.name, func(t *testing.T) {
1675 va := &VoltApplication{
1676 vendorID: "DT",
1677 }
1678 if got := va.GetVendorID(); got != tt.want {
1679 t.Errorf("VoltApplication.GetVendorID() = %v, want %v", got, tt.want)
1680 }
1681 })
1682 }
1683}
1684
1685func TestVoltApplication_SetRebootFlag(t *testing.T) {
1686 type args struct {
1687 flag bool
1688 }
1689 tests := []struct {
1690 name string
1691 args args
1692 }{
1693 {
1694 name: "Positive_Case_SetRebootFlag",
1695 args: args{
1696 flag: true,
1697 },
1698 },
1699 }
1700 for _, tt := range tests {
1701 t.Run(tt.name, func(t *testing.T) {
1702 va := &VoltApplication{}
1703 va.SetRebootFlag(tt.args.flag)
1704 })
1705 }
1706}
1707
1708func TestVoltApplication_GetUpgradeFlag(t *testing.T) {
1709 tests := []struct {
1710 name string
1711 want bool
1712 }{
1713 {
1714 name: "Positive_Case_GetUpgradeFlag",
1715 want: true,
1716 },
1717 }
1718 for _, tt := range tests {
1719 t.Run(tt.name, func(t *testing.T) {
1720 va := &VoltApplication{}
1721 isUpgradeComplete = true
1722 if got := va.GetUpgradeFlag(); got != tt.want {
1723 t.Errorf("VoltApplication.GetUpgradeFlag() = %v, want %v", got, tt.want)
1724 }
1725 })
1726 }
1727}
1728
1729func TestVoltApplication_SetUpgradeFlag(t *testing.T) {
1730 type args struct {
1731 flag bool
1732 }
1733 tests := []struct {
1734 name string
1735 args args
1736 }{
1737 {
1738 name: "Positive_Case_GetUpgradeFlag",
1739 args: args{
1740 flag: true,
1741 },
1742 },
1743 }
1744 for _, tt := range tests {
1745 t.Run(tt.name, func(t *testing.T) {
1746 va := &VoltApplication{}
1747 va.SetUpgradeFlag(tt.args.flag)
1748 })
1749 }
1750}
1751
1752func TestVoltApplication_AddDevice(t *testing.T) {
1753 type args struct {
1754 cntx context.Context
1755 device string
1756 slno string
1757 southBoundID string
1758 }
1759 voltDev := &VoltDevice{
1760 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1761 SerialNum: "SDX6320031",
1762 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301763 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05301764 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1765 }
1766 nbd := &NbDevice{
1767 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1768 PonPorts: sync.Map{},
1769 }
1770 ponPortCnf := &PonPortCfg{
1771 PortID: controller.NNIPortID,
1772 MaxActiveChannels: 123,
1773 EnableMulticastKPI: false,
1774 PortAlarmProfileID: "16777",
1775 }
1776 tests := []struct {
1777 name string
1778 args args
1779 }{
1780 {
1781 name: "Positive_Case_AddDevice",
1782 args: args{
1783 cntx: context.Background(),
1784 device: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1785 slno: "SDX6320031",
1786 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1787 },
1788 },
1789 {
1790 name: "Negetive_Case_AddDevice",
1791 args: args{
1792 cntx: context.Background(),
1793 device: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1794 slno: "SDX6320031",
1795 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1796 },
1797 },
1798 }
1799 for _, tt := range tests {
1800 t.Run(tt.name, func(t *testing.T) {
1801 va := &VoltApplication{
1802 DevicesDisc: sync.Map{},
1803 NbDevice: sync.Map{},
1804 }
1805 switch tt.name {
1806 case "Positive_Case_AddDevice":
1807 va.DevicesDisc.Store("SDX6320031", voltDev)
1808 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a123", nbd)
1809 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
1810 va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID)
1811 case "Negetive_Case_AddDevice":
1812 va.DevicesDisc.Store("SDX6320031", voltDev)
1813 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
1814 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1815 db = dbintf
1816 dbintf.EXPECT().GetAllNbPorts(context.Background(), "49686e2d-618f-4e8e-bca0-442ab850a63a123").AnyTimes()
1817 va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID)
1818 }
1819 })
1820 }
1821}
1822
1823func TestVoltApplication_DelDevice(t *testing.T) {
1824 type args struct {
1825 cntx context.Context
1826 device string
1827 }
1828 voltDev := &VoltDevice{
1829 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1830 SerialNum: "SDX6320031",
1831 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301832 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05301833 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1834 }
1835 tests := []struct {
1836 name string
1837 args args
1838 }{
1839 {
1840 name: "Positive_Case_AddDevice",
1841 args: args{
1842 cntx: context.Background(),
1843 device: "SDX6320031",
1844 },
1845 },
1846 {
1847 name: "Delete_Case_AddDevice",
1848 args: args{
1849 cntx: context.Background(),
1850 device: "SDX6320031",
1851 },
1852 },
1853 }
1854 for _, tt := range tests {
1855 t.Run(tt.name, func(t *testing.T) {
1856 va := &VoltApplication{
1857 DevicesDisc: sync.Map{},
1858 }
1859 switch tt.name {
1860 case "Positive_Case_AddDevice":
1861 va.DevicesDisc.Store("SDX6320031", voltDev)
1862 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1863 db = dbintf
1864 dbintf.EXPECT().DelAllRoutesForDevice(context.Background(), "SDX6320031").AnyTimes()
1865 dbintf.EXPECT().GetAllMigrateServicesReq(context.Background(), "SDX6320031").AnyTimes()
1866 dbintf.EXPECT().DelAllGroup(context.Background(), "SDX6320031").AnyTimes()
1867 dbintf.EXPECT().DelAllMeter(context.Background(), "SDX6320031").AnyTimes()
1868 dbintf.EXPECT().DelAllPorts(context.Background(), "SDX6320031").AnyTimes()
1869 va.DelDevice(tt.args.cntx, tt.args.device)
1870 case "Delete_Case_AddDevice":
1871 va.DelDevice(tt.args.cntx, tt.args.device)
1872 }
1873 })
1874 }
1875}
1876
1877func TestVoltApplication_PortAddInd(t *testing.T) {
1878 type args struct {
1879 cntx context.Context
1880 device string
1881 id uint32
1882 portName string
1883 }
1884 voltDev := &VoltDevice{
1885 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1886 SerialNum: "SDX6320031",
1887 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301888 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05301889 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1890 }
1891 tests := []struct {
1892 name string
1893 args args
1894 }{
1895 {
1896 name: "Positive_Case_PortAddInd",
1897 args: args{
1898 cntx: context.Background(),
1899 device: "SDX6320031",
1900 id: controller.NNIPortID,
1901 portName: "16777216",
1902 },
1903 },
1904 {
1905 name: "Negetive_Case_PortAddInd",
1906 args: args{
1907 cntx: context.Background(),
1908 device: "SDX6320031",
1909 id: controller.NNIPortID,
1910 portName: "16777216",
1911 },
1912 },
1913 }
1914 for _, tt := range tests {
1915 t.Run(tt.name, func(t *testing.T) {
1916 va := &VoltApplication{
1917 DevicesDisc: sync.Map{},
1918 }
1919 switch tt.name {
1920 case "Positive_Case_PortAddInd":
1921 va.DevicesDisc.Store("SDX6320031", voltDev)
1922 va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName)
1923 case "Negetive_Case_PortAddInd":
1924 va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName)
1925 }
1926 })
1927 }
1928}
1929
1930func TestVoltApplication_PortUpdateInd(t *testing.T) {
1931 type args struct {
1932 device string
1933 portName string
1934 id uint32
1935 }
1936 voltDev := &VoltDevice{
1937 Name: "SDX6320031",
1938 SerialNum: "SDX6320031",
1939 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301940 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05301941 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1942 }
1943 tests := []struct {
1944 name string
1945 args args
1946 }{
1947 {
1948 name: "Positive_Case_PortUpdateInd",
1949 args: args{
1950 device: "SDX6320031",
1951 id: controller.NNIPortID,
1952 portName: "16777216",
1953 },
1954 },
1955 {
1956 name: "Negetive_Case_PortUpdateInd",
1957 args: args{
1958 device: "SDX6320031",
1959 id: controller.NNIPortID,
1960 portName: "16777216",
1961 },
1962 },
1963 }
1964 for _, tt := range tests {
1965 t.Run(tt.name, func(t *testing.T) {
1966 va := &VoltApplication{
1967 DevicesDisc: sync.Map{},
1968 }
1969 switch tt.name {
1970 case "Positive_Case_PortAddInd":
1971 va.DevicesDisc.Store("SDX6320031", voltDev)
1972 d := &VoltDevice{
1973 Ports: sync.Map{},
1974 }
1975 voltPort := &VoltPort{
1976 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1977 Device: "SDX6320031",
1978 ID: 16777472,
1979 State: PortStateDown,
1980 ChannelPerSubAlarmRaised: false,
1981 Type: VoltPortTypeNni,
1982 }
1983 d.Ports.Store(16777472, voltPort)
1984 va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id)
1985 case "Negetive_Case_PortUpdateInd":
1986 va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id)
1987 }
1988 })
1989 }
1990}
1991
1992func TestVoltApplication_AddNbPonPort(t *testing.T) {
1993 type args struct {
1994 cntx context.Context
1995 oltSbID string
1996 portID uint32
1997 maxAllowedChannels uint32
1998 enableMulticastKPI bool
1999 portAlarmProfileID string
2000 }
2001 voltDev := &VoltDevice{
2002 Name: "SDX6320031",
2003 SerialNum: "SDX6320031",
2004 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302005 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05302006 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2007 }
2008 nbd := &NbDevice{
2009 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2010 }
2011 tests := []struct {
2012 name string
2013 args args
2014 wantErr bool
2015 }{
2016 {
2017 name: "Positive_Case_AddNbPonPort",
2018 args: args{
2019 cntx: context.Background(),
2020 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2021 portID: 16777472,
2022 maxAllowedChannels: 0,
2023 enableMulticastKPI: false,
2024 portAlarmProfileID: "16777",
2025 },
2026 },
2027 {
2028 name: "Negetive_Case_AddNbPonPort",
2029 args: args{
2030 cntx: context.Background(),
2031 oltSbID: "0",
2032 portID: 16777472,
2033 maxAllowedChannels: 0,
2034 enableMulticastKPI: false,
2035 portAlarmProfileID: "16777",
2036 },
2037 },
2038 }
2039 for _, tt := range tests {
2040 t.Run(tt.name, func(t *testing.T) {
2041 va := &VoltApplication{
2042 DevicesDisc: sync.Map{},
2043 NbDevice: sync.Map{},
2044 }
2045 switch tt.name {
2046 case "Positive_Case_AddNbPonPort":
2047 va.DevicesDisc.Store("SDX6320031", voltDev)
2048 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2049 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2050 db = dbintf
2051 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2052 if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2053 t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2054 }
2055 case "Negetive_Case_AddNbPonPort":
2056 va.DevicesDisc.Store("SDX6320031", voltDev)
2057 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2058 db = dbintf
2059 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2060 if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2061 t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2062 }
2063 }
2064 })
2065 }
2066}
2067
2068func TestVoltApplication_UpdateNbPonPort(t *testing.T) {
2069 type args struct {
2070 cntx context.Context
2071 oltSbID string
2072 portID uint32
2073 maxAllowedChannels uint32
2074 enableMulticastKPI bool
2075 portAlarmProfileID string
2076 }
2077 voltDev := &VoltDevice{
2078 Name: "SDX6320031",
2079 SerialNum: "SDX6320031",
2080 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302081 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05302082 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2083 ActiveChannelsPerPon: sync.Map{},
2084 }
2085 nbd := &NbDevice{
2086 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2087 PonPorts: sync.Map{},
2088 }
2089 ponPortCnf := &PonPortCfg{
2090 PortID: controller.NNIPortID,
2091 MaxActiveChannels: 123,
2092 EnableMulticastKPI: false,
2093 PortAlarmProfileID: "16777",
2094 }
2095 tests := []struct {
2096 name string
2097 args args
2098 wantErr bool
2099 }{
2100 {
2101 name: "Positive_Case_UpdateNbPonPort",
2102 args: args{
2103 cntx: context.Background(),
2104 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2105 portID: controller.NNIPortID,
2106 maxAllowedChannels: 0,
2107 enableMulticastKPI: false,
2108 portAlarmProfileID: "16777",
2109 },
2110 wantErr: false,
2111 },
2112 {
2113 name: "Negetive_Case_Port_doesn't_exists",
2114 args: args{
2115 cntx: context.Background(),
2116 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2117 portID: 16777472,
2118 maxAllowedChannels: 0,
2119 enableMulticastKPI: false,
2120 portAlarmProfileID: "16777",
2121 },
2122 wantErr: true,
2123 },
2124 {
2125 name: "Negetive_Case_Device-doesn't-exists",
2126 args: args{
2127 cntx: context.Background(),
2128 oltSbID: "0",
2129 portID: 16777472,
2130 maxAllowedChannels: 0,
2131 enableMulticastKPI: false,
2132 portAlarmProfileID: "16777",
2133 },
2134 wantErr: true,
2135 },
2136 }
2137 for _, tt := range tests {
2138 t.Run(tt.name, func(t *testing.T) {
2139 va := &VoltApplication{
2140 DevicesDisc: sync.Map{},
2141 NbDevice: sync.Map{},
2142 }
2143 switch tt.name {
2144 case "Positive_Case_UpdateNbPonPort":
2145 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2146 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
2147 va.DevicesDisc.Store("SDX6320031", voltDev)
2148 voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf)
2149 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2150 db = dbintf
2151 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2152 if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2153 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2154 }
2155 case "Negetive_Case_Port_doesn't_exists":
2156 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2157 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2158 db = dbintf
2159 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2160 if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2161 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2162 }
2163 case "Negetive_Case_Device-doesn't-exists":
2164 va.DevicesDisc.Store("SDX6320031", voltDev)
2165 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2166 db = dbintf
2167 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2168 if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2169 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2170 }
2171 }
2172 })
2173 }
2174}
2175
2176func TestVoltApplication_DeleteNbPonPort(t *testing.T) {
2177 type args struct {
2178 cntx context.Context
2179 oltSbID string
2180 portID uint32
2181 }
2182 voltDev := &VoltDevice{
2183 Name: "SDX6320031",
2184 SerialNum: "SDX6320031",
2185 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302186 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05302187 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2188 ActiveChannelsPerPon: sync.Map{},
2189 }
2190 nbd := &NbDevice{
2191 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2192 }
2193 ponPortCnf := &PonPortCfg{
2194 PortID: controller.NNIPortID,
2195 MaxActiveChannels: 123,
2196 EnableMulticastKPI: false,
2197 PortAlarmProfileID: "16777",
2198 }
2199 tests := []struct {
2200 name string
2201 args args
2202 wantErr bool
2203 }{
2204 {
2205 name: "Positive_Case_DeleteNbPonPort",
2206 args: args{
2207 cntx: context.Background(),
2208 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2209 portID: controller.NNIPortID,
2210 },
2211 wantErr: false,
2212 },
2213 {
2214 name: "Negetive_Case_DeleteNbPonPort",
2215 args: args{
2216 cntx: context.Background(),
2217 oltSbID: "0",
2218 portID: controller.NNIPortID,
2219 },
2220 wantErr: false,
2221 },
2222 }
2223 for _, tt := range tests {
2224 t.Run(tt.name, func(t *testing.T) {
2225 va := &VoltApplication{
2226 DevicesDisc: sync.Map{},
2227 NbDevice: sync.Map{},
2228 }
2229 switch tt.name {
2230 case "Positive_Case_DeleteNbPonPort":
2231 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2232 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
2233 va.DevicesDisc.Store("SDX6320031", voltDev)
2234 voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf)
2235 va.DevicesDisc.Store("SDX6320031", voltDev)
2236 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2237 db = dbintf
2238 dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2239 if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr {
2240 t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2241 }
2242 case "Negetive_Case_DeleteNbPonPort":
2243 va.DevicesDisc.Store("SDX6320031", voltDev)
2244 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2245 db = dbintf
2246 dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2247 if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr {
2248 t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2249 }
2250 }
2251 })
2252 }
2253}
2254
2255func TestVoltApplication_DeviceUpInd(t *testing.T) {
2256 type args struct {
2257 device string
2258 }
2259 voltDev := &VoltDevice{
2260 Name: "SDX6320031",
2261 SerialNum: "SDX6320031",
2262 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302263 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05302264 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2265 }
2266 tests := []struct {
2267 name string
2268 args args
2269 }{
2270 {
2271 name: "Positive_Case_DeviceUpInd",
2272 args: args{
2273 device: "SDX6320031",
2274 },
2275 },
2276 {
2277 name: "Negetive_Case_DeviceUpInd",
2278 args: args{
2279 device: "o",
2280 },
2281 },
2282 }
2283 for _, tt := range tests {
2284 t.Run(tt.name, func(t *testing.T) {
2285 va := &VoltApplication{
2286 DevicesDisc: sync.Map{},
2287 }
2288 switch tt.name {
2289 case "Positive_Case_DeviceUpInd":
2290 va.DevicesDisc.Store("SDX6320031", voltDev)
2291 va.DeviceUpInd(tt.args.device)
2292 case "Negetive_Case_DeviceUpInd":
2293 va.DeviceUpInd(tt.args.device)
2294 }
2295 })
2296 }
2297}
2298
2299func TestVoltApplication_DeviceDownInd(t *testing.T) {
2300 type args struct {
2301 device string
2302 }
2303 voltDev := &VoltDevice{
2304 Name: "SDX6320031",
2305 SerialNum: "SDX6320031",
2306 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302307 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05302308 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2309 }
2310 tests := []struct {
2311 name string
2312 args args
2313 }{
2314 {
2315 name: "Positive_Case_DeviceDownInd",
2316 args: args{
2317 device: "SDX6320031",
2318 },
2319 },
2320 {
2321 name: "Negetive_Case_DeviceDownInd",
2322 args: args{
2323 device: "o",
2324 },
2325 },
2326 }
2327 for _, tt := range tests {
2328 t.Run(tt.name, func(t *testing.T) {
2329 va := &VoltApplication{
2330 DevicesDisc: sync.Map{},
2331 }
2332 switch tt.name {
2333 case "Positive_Case_DeviceDownInd":
2334 va.DevicesDisc.Store("SDX6320031", voltDev)
2335 va.DeviceDownInd(tt.args.device)
2336 case "Negetive_Case_DeviceDownInd":
2337 va.DeviceDownInd(tt.args.device)
2338 }
2339 })
2340 }
2341}
2342
2343func TestVoltApplication_DeviceRebootInd(t *testing.T) {
2344 type args struct {
2345 cntx context.Context
2346 device string
2347 serialNum string
2348 southBoundID string
2349 }
2350 voltDev := &VoltDevice{
Akash Soni6f369452023-09-19 11:18:28 +05302351 Name: "SDX6320031",
2352 SerialNum: "SDX6320031",
2353 State: controller.DeviceStateREBOOTED,
2354 MigratingServices: util.NewConcurrentMap(),
vinokumaf7605fc2023-06-02 18:08:01 +05302355 }
2356 tests := []struct {
2357 name string
2358 args args
2359 }{
2360 {
2361 name: "Positive_Case_DeviceRebootInd",
2362 args: args{
2363 device: "SDX6320031",
2364 serialNum: "SDX6320031",
2365 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2366 },
2367 },
Akash Soni6f369452023-09-19 11:18:28 +05302368 {
2369 name: "Negetive_Case_DeviceRebootInd",
2370 args: args{
2371 device: "SDX6320031",
2372 serialNum: "SDX6320031",
2373 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2374 },
2375 },
vinokumaf7605fc2023-06-02 18:08:01 +05302376 }
2377 for _, tt := range tests {
2378 t.Run(tt.name, func(t *testing.T) {
2379 va := &VoltApplication{
2380 DevicesDisc: sync.Map{},
2381 }
Akash Soni6f369452023-09-19 11:18:28 +05302382 switch tt.name {
2383 case "Positive_Case_DeviceRebootInd":
2384 va.DevicesDisc.Store("SDX6320031", voltDev)
2385 va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID)
2386 case "Negetive_Case_DeviceRebootInd":
2387 voltDev.State = controller.DeviceStateDOWN
2388 va.DevicesDisc.Store("SDX6320031", voltDev)
2389 GetApplication().DevicesDisc.Store("SDX6320031", voltDev)
2390 va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID)
2391 }
vinokumaf7605fc2023-06-02 18:08:01 +05302392 })
2393 }
2394}
vinokuma02fbfd02023-07-05 15:23:33 +05302395
2396func TestVoltApplication_GetDeviceFromPort(t *testing.T) {
2397 type args struct {
2398 port string
2399 }
2400 voltDev := &VoltDevice{
2401 Name: "SDX6320031",
2402 SerialNum: "SDX6320031",
2403 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302404 NniPort: []string{"16777216"},
vinokuma02fbfd02023-07-05 15:23:33 +05302405 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2406 Ports: sync.Map{},
2407 }
2408 voltPort := &VoltPort{
2409 Name: "16777216",
2410 Device: "SDX6320031",
2411 ID: 16777216,
2412 State: PortStateDown,
2413 ChannelPerSubAlarmRaised: false,
2414 Type: VoltPortTypeNni,
2415 }
2416 tests := []struct {
2417 name string
2418 args args
2419 want *VoltDevice
2420 wantErr bool
2421 }{
2422 {
2423 name: "Positive_Case_GetDeviceFromPort",
2424 args: args{
2425 port: "16777216",
2426 },
2427 want: voltDev,
2428 wantErr: false,
2429 },
2430 }
2431 for _, tt := range tests {
2432 t.Run(tt.name, func(t *testing.T) {
2433 va := &VoltApplication{
2434 DevicesDisc: sync.Map{},
2435 PortsDisc: sync.Map{},
2436 }
2437 va.PortsDisc.Store("16777216", voltPort)
2438 va.DevicesDisc.Store("SDX6320031", voltDev)
2439 got, err := va.GetDeviceFromPort(tt.args.port)
2440 if (err != nil) != tt.wantErr {
2441 t.Errorf("VoltApplication.GetDeviceFromPort() error = %v, wantErr %v", err, tt.wantErr)
2442 return
2443 }
2444 if !reflect.DeepEqual(got, tt.want) {
2445 t.Errorf("VoltApplication.GetDeviceFromPort() = %v, want %v", got, tt.want)
2446 }
2447 })
2448 }
2449}
2450
2451func TestVoltApplication_GetPortID(t *testing.T) {
2452 type args struct {
2453 port string
2454 }
2455 voltPort := &VoltPort{
2456 Name: "16777216",
2457 Device: "SDX6320031",
2458 ID: 16777216,
2459 State: PortStateDown,
2460 ChannelPerSubAlarmRaised: false,
2461 Type: VoltPortTypeNni,
2462 }
2463 tests := []struct {
2464 name string
2465 args args
2466 want uint32
2467 wantErr bool
2468 }{
2469 {
2470 name: "Positive_Case_GetPortID",
2471 args: args{
2472 port: "16777216",
2473 },
2474 want: 16777216,
2475 wantErr: false,
2476 },
2477 }
2478 for _, tt := range tests {
2479 t.Run(tt.name, func(t *testing.T) {
2480 va := &VoltApplication{
2481 PortsDisc: sync.Map{},
2482 }
2483 va.PortsDisc.Store("16777216", voltPort)
2484 got, err := va.GetPortID(tt.args.port)
2485 if (err != nil) != tt.wantErr {
2486 t.Errorf("VoltApplication.GetPortID() error = %v, wantErr %v", err, tt.wantErr)
2487 return
2488 }
2489 if got != tt.want {
2490 t.Errorf("VoltApplication.GetPortID() = %v, want %v", got, tt.want)
2491 }
2492 })
2493 }
2494}
2495
2496func TestVoltApplication_GetPortName(t *testing.T) {
2497 type args struct {
2498 port uint32
2499 }
2500 voltPort := &VoltPort{
2501 Name: "16777216",
2502 Device: "SDX6320031",
2503 ID: 16777216,
2504 State: PortStateDown,
2505 ChannelPerSubAlarmRaised: false,
2506 Type: VoltPortTypeNni,
2507 }
2508 tests := []struct {
2509 name string
2510 args args
2511 want string
2512 wantErr bool
2513 }{
2514 {
2515 name: "Positive_Case_GetPortID",
2516 args: args{
2517 port: 16777216,
2518 },
2519 want: "16777216",
2520 wantErr: false,
2521 },
2522 }
2523 for _, tt := range tests {
2524 t.Run(tt.name, func(t *testing.T) {
2525 va := &VoltApplication{
2526 PortsDisc: sync.Map{},
2527 }
2528 va.PortsDisc.Store("16777216", voltPort)
2529 got, err := va.GetPortName(tt.args.port)
2530 if (err != nil) != tt.wantErr {
2531 t.Errorf("VoltApplication.GetPortName() error = %v, wantErr %v", err, tt.wantErr)
2532 return
2533 }
2534 if got != tt.want {
2535 t.Errorf("VoltApplication.GetPortName() = %v, want %v", got, tt.want)
2536 }
2537 })
2538 }
2539}
2540
2541func TestVoltApplication_PortUpInd(t *testing.T) {
2542 type args struct {
2543 cntx context.Context
2544 device string
2545 port string
2546 }
2547 voltDev := &VoltDevice{
2548 Name: "SDX6320031",
2549 SerialNum: "SDX6320031",
2550 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302551 NniPort: []string{"16777216"},
vinokuma02fbfd02023-07-05 15:23:33 +05302552 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2553 Ports: sync.Map{},
2554 VpvsBySvlan: util.NewConcurrentMap(),
2555 }
2556 voltPort := &VoltPort{
2557 Name: "16777472",
2558 Device: "SDX6320031",
2559 ID: 16777472,
2560 State: PortStateUp,
2561 ChannelPerSubAlarmRaised: false,
2562 Type: VoltPortTypeNni,
2563 }
2564 voltServ := &VoltService{
2565 VoltServiceOper: VoltServiceOper{
2566 Device: "SDX6320031",
2567 },
2568 VoltServiceCfg: VoltServiceCfg{
2569 IsActivated: true,
2570 },
2571 }
2572 voltPortVnets := make([]*VoltPortVnet, 0)
2573 voltPortVnet := &VoltPortVnet{
2574 Device: "SDX6320031",
2575 Port: "16777472",
2576 DeleteInProgress: false,
2577 services: sync.Map{},
2578 SVlan: 4096,
2579 CVlan: 2310,
2580 UniVlan: 4096,
2581 SVlanTpid: 65,
2582 servicesCount: atomic.NewUint64(1),
2583 }
2584 voltPortVnets = append(voltPortVnets, voltPortVnet)
2585
2586 tests := []struct {
2587 name string
2588 args args
2589 }{
2590 {
2591 name: "Positive_Case_PortUpInd",
2592 args: args{
2593 cntx: context.Background(),
2594 port: "16777472",
2595 device: "SDX6320031",
2596 },
2597 },
2598 }
2599 for _, tt := range tests {
2600 t.Run(tt.name, func(t *testing.T) {
2601 va := &VoltApplication{
2602 DevicesDisc: sync.Map{},
2603 VnetsByPort: sync.Map{},
2604 }
2605 va.DevicesDisc.Store("SDX6320031", voltDev)
2606 voltDev.Ports.Store("16777472", voltPort)
2607 va.VnetsByPort.Store("16777472", voltPortVnets)
2608 voltPortVnet.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
2609 voltapp := GetApplication()
2610 voltapp.DevicesDisc.Store("SDX6320031", voltDev)
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302611 voltapp.DevicesConfig.Store("SDX6320031", &DeviceConfig{UplinkPort: "16777216"})
vinokuma02fbfd02023-07-05 15:23:33 +05302612 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2613 db = dbintf
2614 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
Sridhar Ravindra64b19ca2026-01-26 22:19:07 +05302615 va.PortUpInd(tt.args.cntx, tt.args.device, tt.args.port, false)
vinokuma02fbfd02023-07-05 15:23:33 +05302616 })
2617 }
2618}
2619
2620func TestVoltApplication_PortDownInd(t *testing.T) {
2621 type args struct {
2622 cntx context.Context
2623 device string
2624 port string
2625 }
2626 voltDev := &VoltDevice{
2627 Name: "SDX6320031",
2628 SerialNum: "SDX6320031",
2629 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302630 NniPort: []string{"16777216"},
vinokuma02fbfd02023-07-05 15:23:33 +05302631 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2632 Ports: sync.Map{},
2633 VpvsBySvlan: util.NewConcurrentMap(),
2634 }
2635 voltPort := &VoltPort{
2636 Name: "16777472",
2637 Device: "SDX6320031",
2638 ID: 16777472,
2639 State: PortStateDown,
2640 ChannelPerSubAlarmRaised: false,
2641 Type: VoltPortTypeNni,
2642 }
2643 voltPortVnets := make([]*VoltPortVnet, 0)
2644 voltPortVnet := &VoltPortVnet{
2645 Device: "SDX6320031",
2646 Port: "16777472",
2647 DeleteInProgress: false,
2648 services: sync.Map{},
2649 SVlan: 4096,
2650 CVlan: 2310,
2651 UniVlan: 4096,
2652 SVlanTpid: 65,
2653 servicesCount: atomic.NewUint64(1),
2654 }
2655 voltPortVnets = append(voltPortVnets, voltPortVnet)
2656 tests := []struct {
2657 name string
2658 args args
2659 }{
2660 {
2661 name: "Positive_Case_PortDownInd",
2662 args: args{
2663 cntx: context.Background(),
2664 port: "16777472",
2665 device: "SDX6320031",
2666 },
2667 },
2668 }
2669 for _, tt := range tests {
2670 t.Run(tt.name, func(t *testing.T) {
2671 va := &VoltApplication{}
2672 va.DevicesDisc.Store("SDX6320031", voltDev)
2673 voltDev.Ports.Store("16777472", voltPort)
2674 va.VnetsByPort.Store("16777472", voltPortVnets)
2675 voltApp := GetApplication()
2676 voltApp.DevicesDisc.Store("SDX6320031", voltDev)
2677 va.PortDownInd(tt.args.cntx, tt.args.device, tt.args.port)
2678 })
2679 }
2680}
2681
2682func TestVoltApplication_UpdateDeviceSerialNumberList(t *testing.T) {
2683 type args struct {
2684 oldOltSlNo string
2685 newOltSlNo string
2686 }
Akash Soni6f369452023-09-19 11:18:28 +05302687 appMock := mocks.NewMockApp(gomock.NewController(t))
2688 controller.NewController(ctx, appMock)
2689 devicelist := []string{
2690 "SDX6320030",
2691 "SDX6320031",
2692 }
2693 voltVnet := &VoltVnet{
2694 Version: "v3",
2695 VnetConfig: VnetConfig{
2696 Name: "2310-4096-4096",
2697 VnetType: "Encapsulation",
2698 SVlan: 2310,
2699 CVlan: 4096,
2700 UniVlan: 4096,
2701 SVlanTpid: 33024,
2702 DevicesList: devicelist,
2703 },
2704 }
2705 devicesList := make(map[string]OperInProgress)
2706 devicesList["SDX6320030"] = opt82
2707 mvp := &MvlanProfile{
2708 Name: "mvlan_test",
2709 DevicesList: devicesList,
vinokuma02fbfd02023-07-05 15:23:33 +05302710 }
2711 tests := []struct {
2712 name string
2713 args args
2714 }{
2715 {
2716 name: "Positive_Case_UpdateDeviceSerialNumberList",
2717 args: args{
2718 oldOltSlNo: "SDX6320030",
2719 newOltSlNo: "SDX6320031",
2720 },
2721 },
2722 }
2723 for _, tt := range tests {
2724 t.Run(tt.name, func(t *testing.T) {
Akash Soni6f369452023-09-19 11:18:28 +05302725 va := &VoltApplication{
2726 VnetsByName: sync.Map{},
2727 MvlanProfilesByName: sync.Map{},
2728 }
2729 va.VnetsByName.Store("2310-4096-4096", voltVnet)
2730 va.MvlanProfilesByName.Store("mvlan_test", mvp)
vinokuma02fbfd02023-07-05 15:23:33 +05302731 va.UpdateDeviceSerialNumberList(tt.args.oldOltSlNo, tt.args.newOltSlNo)
2732 })
2733 }
2734}
vinokuma04dc9f82023-07-31 15:47:49 +05302735
2736func TestVoltApplication_DeleteMacInPortMap(t *testing.T) {
2737 type args struct {
2738 macAddr net.HardwareAddr
2739 }
2740
2741 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
2742 macPort := map[string]string{}
2743 macPort[macAdd.String()] = test_data
2744
2745 tests := []struct {
2746 name string
2747 args args
2748 }{
2749 {
2750 name: "Positive_Case_DeleteMacInPortMap",
2751 args: args{
2752 macAddr: macAdd,
2753 },
2754 },
2755 }
2756 for _, tt := range tests {
2757 t.Run(tt.name, func(t *testing.T) {
2758 va := &VoltApplication{
2759 macPortMap: macPort,
2760 }
2761 va.DeleteMacInPortMap(tt.args.macAddr)
2762 })
2763 }
2764}
2765
2766func TestVoltApplication_TriggerPendingServiceDeactivateReq(t *testing.T) {
2767 type args struct {
2768 cntx context.Context
2769 device string
2770 }
Akash Sonief452f12024-12-12 18:20:28 +05302771
vinokuma04dc9f82023-07-31 15:47:49 +05302772 voltServ := &VoltService{
2773 VoltServiceOper: VoltServiceOper{
2774 Device: "SDX6320031",
2775 },
2776 VoltServiceCfg: VoltServiceCfg{
2777 Name: "SDX6320031-1_SDX6320031-1-4096-2310-4096-65",
2778 SVlan: 4096,
2779 CVlan: 2310,
2780 UniVlan: 4096,
2781 Port: "16777472",
2782 TechProfileID: 65,
2783 },
2784 }
2785
2786 voltPortVnets := make([]*VoltPortVnet, 0)
2787 voltPortVnet := &VoltPortVnet{
2788 Device: "SDX6320031",
2789 Port: "16777472",
2790 DeleteInProgress: false,
2791 services: sync.Map{},
2792 SVlan: 4096,
2793 CVlan: 2310,
2794 UniVlan: 4096,
2795 SVlanTpid: 65,
2796 servicesCount: atomic.NewUint64(1),
2797 }
2798
2799 voltPortVnets = append(voltPortVnets, voltPortVnet)
2800 tests := []struct {
2801 name string
2802 args args
2803 }{
2804 {
2805 name: "Positive_Case_DeleteMacInPortMap",
2806 args: args{
2807 cntx: context.Background(),
2808 device: "SDX6320031",
2809 },
2810 },
2811 }
2812
2813 for _, tt := range tests {
2814 t.Run(tt.name, func(t *testing.T) {
2815 va := &VoltApplication{
Akash Sonief452f12024-12-12 18:20:28 +05302816 ServicesToDeactivate: sync.Map{},
vinokuma04dc9f82023-07-31 15:47:49 +05302817 ServiceByName: sync.Map{},
2818 VnetsByPort: sync.Map{},
2819 }
2820 va.ServiceByName.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
2821 va.VnetsByPort.Store("16777472", voltPortVnets)
Akash Sonief452f12024-12-12 18:20:28 +05302822 va.ServicesToDeactivate.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", true)
vinokuma04dc9f82023-07-31 15:47:49 +05302823 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2824 db = dbintf
2825 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2826 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
2827 va.TriggerPendingServiceDeactivateReq(tt.args.cntx, tt.args.device)
2828 })
2829 }
2830}
2831
2832func TestVoltApplication_ReadAllFromDb(t *testing.T) {
2833 type args struct {
2834 cntx context.Context
2835 }
2836
2837 migrationInfo := "migration done"
2838 deviceConfig := DeviceConfig{
2839 SerialNumber: "SDX6320031",
2840 UplinkPort: "16777472",
2841 HardwareIdentifier: "0.0.0.0",
2842 IPAddress: "127.26.1.74",
2843 NasID: "12345",
2844 NniDhcpTrapVid: 123,
2845 }
2846
2847 voltVnet := &VoltVnet{
2848 Version: "v3",
2849 VnetConfig: VnetConfig{
2850 Name: "2310-4096-4096",
2851 VnetType: "Encapsulation",
2852 SVlan: 2310,
2853 CVlan: 4096,
2854 UniVlan: 4096,
2855 SVlanTpid: 33024,
2856 },
vinokuma04dc9f82023-07-31 15:47:49 +05302857 VnetOper: VnetOper{
2858 PendingDeviceToDelete: "SDX6320031",
2859 DeleteInProgress: true,
2860 },
2861 }
2862
2863 cuncurrentMap := &util.ConcurrentMap{
2864 Count: atomic.NewUint64(0),
2865 }
2866
2867 vnetToDelete := map[string]bool{}
2868 vnetToDelete["2310-4096-4096"] = true
2869 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
2870 voltPortVnet := &VoltPortVnet{
2871 Device: "SDX6320031",
2872 Port: "16777472",
2873 DeleteInProgress: true,
2874 MacAddr: macAdd,
2875 }
2876
2877 macPortMap := map[string]string{}
2878 voltPortVnetsToDelete := map[*VoltPortVnet]bool{}
2879 voltPortVnetsToDelete[voltPortVnet] = true
Akash Sonib03636c2023-10-31 12:30:59 +05302880 macPortMap[macAdd.String()] = voltPortVnet.Port
vinokuma04dc9f82023-07-31 15:47:49 +05302881
2882 tests := []struct {
2883 name string
2884 args args
2885 }{
2886 {
2887 name: "Positive_Case_ReadAllFromDb",
2888 args: args{
2889 cntx: context.Background(),
2890 },
2891 },
2892 }
2893
2894 for _, tt := range tests {
2895 t.Run(tt.name, func(t *testing.T) {
2896 va := &VoltApplication{
2897 VnetsBySvlan: util.NewConcurrentMap(),
2898 VnetsToDelete: vnetToDelete,
2899 macPortMap: macPortMap,
2900 VoltPortVnetsToDelete: voltPortVnetsToDelete,
2901 VnetsByName: sync.Map{},
2902 }
2903
2904 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2905 db = dbintf
2906 dbintf.EXPECT().GetMeters(gomock.Any()).AnyTimes()
2907 vnet, _ := json.Marshal(voltVnet)
2908 voltVnets := map[string]*kvstore.KVPair{}
2909 voltVnets["2310-4096-4096"] = &kvstore.KVPair{
2910 Key: "2310-4096-4096",
2911 Value: vnet,
2912 }
2913
2914 va.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap)
2915 dbintf.EXPECT().GetVnets(gomock.Any()).AnyTimes().Return(voltVnets, nil).AnyTimes()
2916 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil).AnyTimes()
2917 vpvs, _ := json.Marshal(voltPortVnet)
2918 voltPort := map[string]*kvstore.KVPair{}
2919 voltPort["16777472"] = &kvstore.KVPair{
2920 Key: "16777472",
2921 Value: vpvs,
2922 }
2923 va.VnetsByName.Store("2310-4096-4096", voltVnet)
2924 dbintf.EXPECT().GetVpvs(gomock.Any()).AnyTimes().Return(voltPort, nil).AnyTimes()
2925 dbintf.EXPECT().GetServices(gomock.Any()).AnyTimes()
2926 dbintf.EXPECT().GetMvlans(gomock.Any()).AnyTimes()
2927 dbintf.EXPECT().GetIgmpProfiles(gomock.Any()).AnyTimes()
2928 dbintf.EXPECT().GetMcastConfigs(gomock.Any()).AnyTimes()
2929 dbintf.EXPECT().GetIgmpGroups(gomock.Any()).AnyTimes()
2930 dbintf.EXPECT().GetMigrationInfo(gomock.Any()).Return(migrationInfo, nil).AnyTimes()
2931 dbintf.EXPECT().GetOltFlowService(gomock.Any()).AnyTimes()
2932 b, _ := json.Marshal(deviceConfig)
2933 test := map[string]*kvstore.KVPair{}
2934 test["SDX6320031"] = &kvstore.KVPair{
2935 Key: "SDX6320031",
2936 Value: b,
2937 }
2938 dbintf.EXPECT().GetDeviceConfig(gomock.Any()).Return(test, nil).AnyTimes()
2939 dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2940 va.ReadAllFromDb(tt.args.cntx)
2941 })
2942 }
2943}
2944
2945func TestVoltApplication_RemoveGroupDevicesFromPendingPool(t *testing.T) {
2946 type args struct {
2947 ig *IgmpGroup
2948 }
2949 pendingGroupForDevice := map[string]time.Time{}
2950 pendingGroupForDevice[test_device] = time.Now()
2951 tests := []struct {
2952 name string
2953 args args
2954 }{
2955 {
2956 name: "VoltApplication_RemoveGroupDevicesFromPendingPool",
2957 args: args{
2958 ig: &IgmpGroup{
2959 Version: "test_version",
2960 PendingGroupForDevice: pendingGroupForDevice,
2961 },
2962 },
2963 },
2964 }
2965 for _, tt := range tests {
2966 t.Run(tt.name, func(t *testing.T) {
2967 va := &VoltApplication{}
2968 va.RemoveGroupDevicesFromPendingPool(tt.args.ig)
2969 })
2970 }
2971}
Akash Soni6f369452023-09-19 11:18:28 +05302972
2973func TestVoltDevice_AddPort(t *testing.T) {
2974 type args struct {
2975 port string
2976 id uint32
2977 }
2978
2979 voltPort := &VoltPort{
2980 Name: "16777472",
2981 ID: uint32(256),
2982 }
2983 tests := []struct {
2984 name string
2985 args args
2986 want *VoltPort
2987 }{
2988 {
2989 name: "VoltApplication_AddPort",
2990 args: args{
2991 port: "16777472",
2992 id: uint32(256),
2993 },
2994 want: voltPort,
2995 },
2996 }
2997 for _, tt := range tests {
2998 t.Run(tt.name, func(t *testing.T) {
2999 d := &VoltDevice{}
3000 if got := d.AddPort(tt.args.port, tt.args.id); !reflect.DeepEqual(got, tt.want) {
3001 t.Errorf("VoltDevice.AddPort() = %v, want %v", got, tt.want)
3002 }
3003 })
3004 }
3005}
3006
3007func TestVoltApplication_GetAvailIgmpGroupID(t *testing.T) {
3008 IgmpGroupIds := []*IgmpGroup{}
3009 group := &IgmpGroup{
3010 GroupName: "group1",
3011 GroupID: uint32(256),
3012 }
3013 IgmpGroupIds = append(IgmpGroupIds, group)
3014 tests := []struct {
3015 name string
3016 want *IgmpGroup
3017 }{
3018 {
3019 name: "VoltApplication_GetAvailIgmpGroupID",
3020 want: group,
3021 },
3022 {
3023 name: "VoltApplication_GetAvailIgmpGroupID_Nil",
3024 want: group,
3025 },
3026 }
3027 for _, tt := range tests {
3028 t.Run(tt.name, func(t *testing.T) {
3029 switch tt.name {
3030 case "VoltApplication_GetAvailIgmpGroupID":
3031 va := &VoltApplication{
3032 IgmpGroupIds: IgmpGroupIds,
3033 }
3034 got := va.GetAvailIgmpGroupID()
3035 assert.NotNil(t, got)
3036 case "VoltApplication_GetAvailIgmpGroupID_Nil":
3037 va := &VoltApplication{}
3038 got := va.GetAvailIgmpGroupID()
3039 assert.Nil(t, got)
3040 }
3041 })
3042 }
3043}
3044
3045func TestVoltApplication_GetIgmpGroupID(t *testing.T) {
3046 type args struct {
3047 gid uint32
3048 }
3049 IgmpGroupIds := []*IgmpGroup{}
3050 group := &IgmpGroup{
3051 GroupName: "group1",
3052 GroupID: uint32(256),
3053 }
3054 IgmpGroupIds = append(IgmpGroupIds, group)
3055 tests := []struct {
3056 name string
3057 args args
3058 want *IgmpGroup
3059 wantErr bool
3060 }{
3061 {
3062 name: "VoltApplication_GetIgmpGroupID",
3063 args: args{
3064 gid: uint32(256),
3065 },
3066 want: group,
3067 wantErr: false,
3068 },
3069 {
3070 name: "VoltApplication_GetIgmpGroupID_Error",
3071 args: args{
3072 gid: uint32(256),
3073 },
3074 want: group,
3075 wantErr: true,
3076 },
3077 }
3078 va := &VoltApplication{}
3079 for _, tt := range tests {
3080 t.Run(tt.name, func(t *testing.T) {
3081 switch tt.name {
3082 case "VoltApplication_GetIgmpGroupID":
3083 va = &VoltApplication{
3084 IgmpGroupIds: IgmpGroupIds,
3085 }
3086 got, err := va.GetIgmpGroupID(tt.args.gid)
3087 if (err != nil) != tt.wantErr {
3088 t.Errorf("VoltApplication.GetIgmpGroupID() error = %v, wantErr %v", err, tt.wantErr)
3089 return
3090 }
3091 if !reflect.DeepEqual(got, tt.want) {
3092 t.Errorf("VoltApplication.GetIgmpGroupID() = %v, want %v", got, tt.want)
3093 }
3094 case "VoltApplication_GetIgmpGroupID_Error":
3095 got, err := va.GetIgmpGroupID(tt.args.gid)
3096 if (err != nil) != tt.wantErr {
3097 t.Errorf("VoltApplication.GetIgmpGroupID() error = %v, wantErr %v", err, tt.wantErr)
3098 return
3099 }
3100 assert.Nil(t, got)
3101 }
3102 })
3103 }
3104}
3105
3106func TestVoltApplication_PutIgmpGroupID(t *testing.T) {
3107 type args struct {
3108 ig *IgmpGroup
3109 }
3110 group := &IgmpGroup{
3111 GroupName: "group1",
3112 GroupID: uint32(256),
3113 }
3114 tests := []struct {
3115 name string
3116 args args
3117 }{
3118 {
3119 name: "VoltApplication_GetIgmpGroupID",
3120 args: args{
3121 ig: group,
3122 },
3123 },
3124 }
3125 for _, tt := range tests {
3126 t.Run(tt.name, func(t *testing.T) {
3127 va := &VoltApplication{}
3128 va.PutIgmpGroupID(tt.args.ig)
3129 })
3130 }
3131}
3132
3133func TestVoltApplication_PortDelInd(t *testing.T) {
3134 type args struct {
3135 cntx context.Context
3136 device string
3137 port string
3138 }
3139 voltDev := &VoltDevice{
3140 Name: "49686e2d-618f-4e8e-bca0",
3141 SerialNum: "SDX6320031",
3142 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05303143 NniPort: []string{"16777216"},
Akash Soni6f369452023-09-19 11:18:28 +05303144 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
3145 Ports: sync.Map{},
3146 VpvsBySvlan: util.NewConcurrentMap(),
3147 }
3148
3149 voltPort := &VoltPort{
3150 Name: "16777472",
3151 Device: "SDX6320031",
3152 ID: 16777472,
3153 State: PortStateUp,
3154 ChannelPerSubAlarmRaised: false,
3155 }
3156 voltPortVnets := make([]*VoltPortVnet, 0)
3157 voltPortVnet := &VoltPortVnet{
3158 Device: "SDX6320031",
3159 Port: "16777472",
3160 DeleteInProgress: true,
3161 servicesCount: atomic.NewUint64(0),
3162 }
3163 voltPortVnets = append(voltPortVnets, voltPortVnet)
3164
3165 tests := []struct {
3166 name string
3167 args args
3168 }{
3169 {
3170 name: "VoltApplication_PortDelInd",
3171 args: args{
3172 cntx: context.Background(),
3173 device: "SDX6320031",
3174 port: "16777472",
3175 },
3176 },
3177 {
3178 name: "PortDelInd_Device_Not_Found",
3179 args: args{
3180 cntx: context.Background(),
3181 device: "SDX6320032",
3182 port: "16777472",
3183 },
3184 },
3185 {
3186 name: "PortDelInd_VnetsByPort_Nil",
3187 args: args{
3188 cntx: context.Background(),
3189 device: "SDX6320031",
3190 port: "16777472",
3191 },
3192 },
3193 }
3194 for _, tt := range tests {
3195 t.Run(tt.name, func(t *testing.T) {
3196 switch tt.name {
3197 case "VoltApplication_PortDelInd", "PortDelInd_Device_Not_Found":
3198 va := &VoltApplication{
3199 DevicesDisc: sync.Map{},
3200 PortsDisc: sync.Map{},
3201 }
3202 va.DevicesDisc.Store("SDX6320031", voltDev)
3203 va.PortsDisc.Store("16777472", voltPort)
3204 voltDev.Ports.Store("16777472", voltPort)
3205 va.VnetsByPort.Store("16777472", voltPortVnets)
3206 va.PortDelInd(tt.args.cntx, tt.args.device, tt.args.port)
3207 case "PortDelInd_VnetsByPort_Nil":
3208 va := &VoltApplication{
3209 DevicesDisc: sync.Map{},
3210 PortsDisc: sync.Map{},
3211 }
3212 va.DevicesDisc.Store("SDX6320031", voltDev)
3213 va.PortsDisc.Store("16777472", voltPort)
3214 voltDev.Ports.Store("16777472", voltPort)
3215 va.PortDelInd(tt.args.cntx, tt.args.device, tt.args.port)
3216 }
3217 })
3218 }
3219}
3220
3221func TestVoltApplication_GetGroupFromPendingPool(t *testing.T) {
3222 type args struct {
3223 mvlan of.VlanType
3224 device string
3225 }
3226 igmpPendingPool := map[string]map[*IgmpGroup]bool{}
3227 devices := map[string]*IgmpGroupDevice{}
3228 igmpGroup := map[*IgmpGroup]bool{}
3229 igmpDevice := &IgmpGroupDevice{
3230 Device: "SDX6320031",
3231 SerialNo: "SDX6320032",
3232 GroupName: "group1",
3233 Mvlan: of.VlanAny,
3234 }
3235 devices["SDX6320031"] = igmpDevice
3236 group := &IgmpGroup{
3237 GroupName: "group1",
3238 GroupID: uint32(256),
3239 Mvlan: of.VlanAny,
3240 Devices: devices,
3241 }
3242
3243 igmpGroup[group] = true
3244 igmpPendingPool["4096_SDX6320031"] = igmpGroup
3245 tests := []struct {
3246 name string
3247 args args
3248 want *IgmpGroup
3249 }{
3250 {
3251 name: "GetGroupFromPendingPool",
3252 args: args{
3253 device: "SDX6320031",
3254 mvlan: of.VlanAny,
3255 },
3256 want: nil,
3257 },
3258 }
3259 for _, tt := range tests {
3260 t.Run(tt.name, func(t *testing.T) {
3261 va := &VoltApplication{
3262 IgmpPendingPool: igmpPendingPool,
3263 }
3264 if got := va.GetGroupFromPendingPool(tt.args.mvlan, tt.args.device); !reflect.DeepEqual(got, tt.want) {
3265 t.Errorf("VoltApplication.GetGroupFromPendingPool() = %v, want %v", got, tt.want)
3266 }
3267 })
3268 }
3269}
3270
3271func TestVoltApplication_RemoveGroupsFromPendingPool(t *testing.T) {
3272 type args struct {
3273 cntx context.Context
3274 device string
3275 mvlan of.VlanType
3276 }
3277 tests := []struct {
3278 name string
3279 args args
3280 }{
3281 {
3282 name: "PortDelInd_RemoveGroupsFromPendingPool",
3283 args: args{
3284 cntx: context.Background(),
3285 device: "SDX6320031",
3286 mvlan: of.VlanAny,
3287 },
3288 },
3289 }
3290 for _, tt := range tests {
3291 t.Run(tt.name, func(t *testing.T) {
3292 va := &VoltApplication{
3293 IgmpPendingPool: make(map[string]map[*IgmpGroup]bool),
3294 }
3295 va.RemoveGroupsFromPendingPool(tt.args.cntx, tt.args.device, tt.args.mvlan)
3296 })
3297 }
3298}
3299
3300func TestVoltApplication_AddGroupToPendingPool(t *testing.T) {
3301 type fields struct{}
3302 type args struct {
3303 ig *IgmpGroup
3304 }
3305 devices := map[string]*IgmpGroupDevice{}
3306 igmpDevice := &IgmpGroupDevice{
3307 Device: "SDX6320031",
3308 SerialNo: "SDX6320032",
3309 GroupName: "group1",
3310 Mvlan: of.VlanAny,
3311 }
3312 devices["SDX6320031"] = igmpDevice
3313 group := &IgmpGroup{
3314 GroupName: "group1",
3315 GroupID: uint32(256),
3316 Devices: devices,
3317 }
3318 tests := []struct {
3319 name string
3320 fields fields
3321 args args
3322 }{
3323 {
3324 name: "AddGroupToPendingPool",
3325 args: args{
3326 ig: group,
3327 },
3328 },
3329 }
3330 for _, tt := range tests {
3331 t.Run(tt.name, func(t *testing.T) {
3332 va := &VoltApplication{
3333 IgmpPendingPool: make(map[string]map[*IgmpGroup]bool),
3334 }
3335 va.AddGroupToPendingPool(tt.args.ig)
3336 })
3337 }
3338}
3339
3340func TestVoltApplication_removeExpiredGroups(t *testing.T) {
3341 type args struct {
3342 cntx context.Context
3343 }
3344 group := &IgmpGroup{
3345 GroupName: "group1",
3346 GroupID: uint32(256),
3347 }
3348 tests := []struct {
3349 name string
3350 args args
3351 }{
3352 {
3353 name: "removeExpiredGroups",
3354 args: args{
3355 cntx: context.Background(),
3356 },
3357 },
3358 }
3359 for _, tt := range tests {
3360 t.Run(tt.name, func(t *testing.T) {
3361 va := &VoltApplication{
3362 IgmpGroups: sync.Map{},
3363 }
3364 va.IgmpGroups.Store("group1", group)
3365 va.removeExpiredGroups(tt.args.cntx)
3366 })
3367 }
3368}
3369
3370func TestVoltApplication_GetTaskList(t *testing.T) {
3371 type args struct {
3372 device string
3373 }
3374 appMock := mocks.NewMockApp(gomock.NewController(t))
3375 controller.NewController(ctx, appMock)
3376 device := &controller.Device{
3377 ID: "SDX6320031",
3378 }
3379 dev := map[string]*controller.Device{}
3380 dev["SDX6320031"] = device
3381 tests := []struct {
3382 name string
3383 args args
3384 want map[int]*TaskInfo
3385 }{
3386 {
3387 name: "GetTaskList",
3388 args: args{
3389 device: "SDX6320031",
3390 },
3391 want: map[int]*TaskInfo{},
3392 },
3393 }
3394 for _, tt := range tests {
3395 t.Run(tt.name, func(t *testing.T) {
3396 va := &VoltApplication{}
3397 if got := va.GetTaskList(tt.args.device); !reflect.DeepEqual(got, tt.want) {
3398 t.Errorf("VoltApplication.GetTaskList() = %v, want %v", got, tt.want)
3399 }
3400 })
3401 }
3402}
3403
3404func TestVoltApplication_UpdateMvlanProfilesForDevice(t *testing.T) {
3405 type args struct {
3406 cntx context.Context
3407 device string
3408 }
3409 devicesList := make(map[string]OperInProgress)
3410 devicesList["SDX6320031"] = UpdateInProgress
3411 mvp := &MvlanProfile{
3412 Name: "mvlan_test",
3413 DevicesList: devicesList,
3414 }
3415 voltDev := &VoltDevice{
3416 SerialNum: "SDX6320031",
3417 }
3418 tests := []struct {
3419 name string
3420 args args
3421 }{
3422 {
3423 name: "UpdateMvlanProfilesForDevice",
3424 args: args{
3425 cntx: context.Background(),
3426 device: "SDX6320031",
3427 },
3428 },
3429 }
3430 for _, tt := range tests {
3431 t.Run(tt.name, func(t *testing.T) {
3432 va := &VoltApplication{
3433 DevicesDisc: sync.Map{},
3434 MvlanProfilesByName: sync.Map{},
3435 }
3436 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
3437 db = dbintf
3438 dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
3439 va.DevicesDisc.Store("SDX6320031", voltDev)
3440 va.MvlanProfilesByName.Store("mvlan_test", mvp)
3441 va.UpdateMvlanProfilesForDevice(tt.args.cntx, tt.args.device)
3442 })
3443 }
3444}
3445
3446func TestVoltApplication_HandleFlowClearFlag(t *testing.T) {
3447 type args struct {
3448 cntx context.Context
3449 deviceID string
3450 serialNum string
3451 southBoundID string
3452 }
3453 mblan := map[uint16]bool{}
3454 mblan[uint16(256)] = true
3455 voltDev := &VoltDevice{
3456 SerialNum: "SDX6320031",
3457 MigratingServices: util.NewConcurrentMap(),
3458 IgmpDsFlowAppliedForMvlan: mblan,
3459 }
3460 voltPortVnets := make([]*VoltPortVnet, 0)
3461 voltPortVnet := &VoltPortVnet{
3462 Device: "SDX6320031",
3463 Port: "16777472",
3464 DeleteInProgress: true,
3465 servicesCount: atomic.NewUint64(0),
3466 IgmpEnabled: true,
3467 }
3468 voltPortVnets = append(voltPortVnets, voltPortVnet)
3469 tests := []struct {
3470 name string
3471 args args
3472 }{
3473 {
3474 name: "HandleFlowClearFlag",
3475 args: args{
3476 cntx: context.Background(),
3477 deviceID: "SDX6320031",
3478 serialNum: "SDX6320031",
3479 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
3480 },
3481 },
3482 }
3483 for _, tt := range tests {
3484 t.Run(tt.name, func(t *testing.T) {
3485 va := &VoltApplication{
3486 DevicesDisc: sync.Map{},
3487 VnetsByPort: sync.Map{},
3488 }
3489 GetApplication().DevicesDisc.Store("SDX6320031", voltDev)
3490 va.DevicesDisc.Store("SDX6320031", voltDev)
3491 va.VnetsByPort.Store("16777472", voltPortVnets)
3492 va.HandleFlowClearFlag(tt.args.cntx, tt.args.deviceID, tt.args.serialNum, tt.args.southBoundID)
3493 })
3494 }
3495}
3496
3497func TestVoltApplication_PacketInInd(t *testing.T) {
3498 type args struct {
3499 cntx context.Context
3500 device string
3501 port string
3502 pkt []byte
3503 }
3504 tests := []struct {
3505 name string
3506 args args
3507 }{
3508 {
3509 name: "PacketInInd",
3510 args: args{
3511 cntx: context.Background(),
3512 },
3513 },
3514 }
3515 for _, tt := range tests {
3516 t.Run(tt.name, func(t *testing.T) {
3517 va := &VoltApplication{}
3518 va.PacketInInd(tt.args.cntx, tt.args.device, tt.args.port, tt.args.pkt)
3519 })
3520 }
3521}
3522
3523func TestReceiverUpInd(t *testing.T) {
3524 type args struct {
3525 key interface{}
3526 value interface{}
3527 }
3528 voltServ := &VoltService{
3529 VoltServiceOper: VoltServiceOper{
3530 Device: "SCOM00001c75",
3531 Ipv4Addr: AllSystemsMulticastGroupIP,
3532 Ipv6Addr: AllSystemsMulticastGroupIP,
3533 },
3534 VoltServiceCfg: VoltServiceCfg{
3535 IgmpEnabled: true,
3536 VlanControl: ONUCVlan,
3537 Port: "16777472",
3538 },
3539 }
3540 voltDev := &VoltDevice{
3541 Name: "SCOM00001c75",
3542 SerialNum: "SCOM00001c75",
3543 Ports: sync.Map{},
3544 }
3545 voltPort := &VoltPort{
3546 Name: "16777472",
3547 Device: "SCOM00001c75",
3548 ID: 16777216,
3549 State: PortStateDown,
3550 ChannelPerSubAlarmRaised: false,
3551 Type: VoltPortTypeNni,
3552 }
3553
3554 tests := []struct {
3555 name string
3556 args args
3557 want bool
3558 }{
3559 {
3560 name: "ReceiverUpInd",
3561 args: args{
3562 key: "SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65",
3563 value: voltServ,
3564 },
3565 },
3566 {
3567 name: "ReceiverUpInd_VlanControl",
3568 args: args{
3569 key: "SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65",
3570 value: voltServ,
3571 },
3572 },
3573 }
3574 for _, tt := range tests {
3575 t.Run(tt.name, func(t *testing.T) {
3576 switch tt.name {
3577 case "ReceiverUpInd":
3578 GetApplication().ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
3579 GetApplication().DevicesDisc.Store("SCOM00001c75", voltDev)
3580 GetApplication().PortsDisc.Store("16777472", voltPort)
3581 voltDev.Ports.Store("16777472", voltPort)
3582 if got := ReceiverUpInd(tt.args.key, tt.args.value); got != tt.want {
3583 t.Errorf("ReceiverUpInd() = %v, want %v", got, tt.want)
3584 }
3585 case "ReceiverUpInd_VlanControl":
3586 voltServ.VlanControl = OLTSVlan
3587 GetApplication().ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
3588 if got := ReceiverUpInd(tt.args.key, tt.args.value); got != tt.want {
3589 t.Errorf("ReceiverUpInd() = %v, want %v", got, tt.want)
3590 }
3591 }
3592 })
3593 }
3594}
3595
3596func TestVoltApplication_NniVlanIndToIgmp(t *testing.T) {
3597 type args struct {
3598 cntx context.Context
3599 device *VoltDevice
3600 mvp *MvlanProfile
3601 addFlow bool
3602 }
3603 mblan := map[uint16]bool{}
3604 mblan[uint16(256)] = true
3605 voltDev := &VoltDevice{
3606 Name: "SDX6320031",
3607 SerialNum: "SDX6320031",
3608 IgmpDsFlowAppliedForMvlan: mblan,
3609 Ports: sync.Map{},
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05303610 NniPort: []string{"16777216"},
Akash Soni6f369452023-09-19 11:18:28 +05303611 }
3612 devicesList := make(map[string]OperInProgress)
3613 devicesList["SDX6320030"] = opt82
3614 mvp := &MvlanProfile{
3615 Name: "mvlan_test",
3616 DevicesList: devicesList,
3617 }
3618 voltPort := &VoltPort{
3619 Name: "16777472",
3620 Device: "SDX6320031",
3621 ID: 16777216,
3622 State: PortStateUp,
3623 }
3624 voltPortVnets := make([]*VoltPortVnet, 0)
3625 voltPortVnet := &VoltPortVnet{
3626 Device: "SDX6320031",
3627 Port: "16777472",
3628 IgmpEnabled: true,
3629 MvlanProfileName: "mvlan_test",
3630 services: sync.Map{},
3631 }
3632 voltPortVnets = append(voltPortVnets, voltPortVnet)
3633 tests := []struct {
3634 name string
3635 args args
3636 }{
3637 {
3638 name: "NniVlanIndToIgmp",
3639 args: args{
3640 device: voltDev,
3641 mvp: mvp,
3642 },
3643 },
3644 {
3645 name: "ProcessIgmpDSFlowForMvlan_pushIgmpMcastFlows",
3646 args: args{
3647 cntx: context.Background(),
3648 device: voltDev,
3649 mvp: mvp,
3650 addFlow: true,
3651 },
3652 },
3653 {
3654 name: "ProcessIgmpDSFlowForMvlan_removeIgmpMcastFlows",
3655 args: args{
3656 cntx: context.Background(),
3657 device: voltDev,
3658 mvp: mvp,
3659 addFlow: false,
3660 },
3661 },
3662 }
3663 for _, tt := range tests {
3664 t.Run(tt.name, func(t *testing.T) {
3665 va := &VoltApplication{}
3666 switch tt.name {
3667 case "NniVlanIndToIgmp":
3668 voltDev.Ports.Store("16777472", voltPort)
3669 va.PortsDisc.Store("16777472", voltPort)
3670 va.VnetsByPort.Store("16777472", voltPortVnets)
3671 va.NniVlanIndToIgmp(tt.args.device, tt.args.mvp)
3672 case "ProcessIgmpDSFlowForMvlan_pushIgmpMcastFlows", "ProcessIgmpDSFlowForMvlan_removeIgmpMcastFlows":
3673 voltDev.Ports.Store("16777472", voltPort)
3674 va.ProcessIgmpDSFlowForMvlan(tt.args.cntx, tt.args.device, tt.args.mvp, tt.args.addFlow)
3675 }
3676 })
3677 }
3678}
3679
3680func TestVoltApplication_DeviceDisableInd(t *testing.T) {
3681 type args struct {
3682 cntx context.Context
3683 device string
3684 }
3685 voltDev := &VoltDevice{
3686 Name: "SDX6320031",
3687 SerialNum: "SDX6320031",
3688 Ports: sync.Map{},
3689 State: controller.DeviceStateDOWN,
3690 MigratingServices: util.NewConcurrentMap(),
3691 }
3692 tests := []struct {
3693 name string
3694 args args
3695 }{
3696 {
3697 name: "DeviceDisableInd",
3698 args: args{
3699 device: "SDX6320031",
3700 },
3701 },
3702 {
3703 name: "DeviceDisableInd_DEvice_Not_Found",
3704 args: args{
3705 device: "SDX6320032",
3706 },
3707 },
3708 }
3709 for _, tt := range tests {
3710 t.Run(tt.name, func(t *testing.T) {
3711 va := &VoltApplication{}
3712 va.DevicesDisc.Store("SDX6320031", voltDev)
3713 GetApplication().DevicesDisc.Store("SDX6320031", voltDev)
3714 va.DeviceDisableInd(tt.args.cntx, tt.args.device)
3715 })
3716 }
3717}
3718
3719func TestVoltApplication_ProcessIgmpDSFlowForDevice(t *testing.T) {
3720 type args struct {
3721 cntx context.Context
3722 d *VoltDevice
3723 addFlow bool
3724 }
3725 voltDev := &VoltDevice{
3726 Name: "SDX6320031",
3727 SerialNum: "SDX6320031",
3728 MigratingServices: util.NewConcurrentMap(),
3729 }
3730 devicesList := make(map[string]OperInProgress)
3731 devicesList["SDX6320030"] = opt82
3732 mvp := &MvlanProfile{
3733 Name: "mvlan_test",
3734 DevicesList: devicesList,
3735 }
3736 tests := []struct {
3737 name string
3738 args args
3739 }{
3740 {
3741 name: "DeviceDisableInd_DEvice_Not_Found",
3742 args: args{
3743 cntx: context.Background(),
3744 d: voltDev,
3745 addFlow: true,
3746 },
3747 },
3748 }
3749 for _, tt := range tests {
3750 t.Run(tt.name, func(t *testing.T) {
3751 va := &VoltApplication{}
3752 va.MvlanProfilesByName.Store("mvlan_test", mvp)
3753 va.ProcessIgmpDSFlowForDevice(tt.args.cntx, tt.args.d, tt.args.addFlow)
3754 })
3755 }
3756}
3757
3758func TestVoltApplication_GetPonFromUniPort(t *testing.T) {
3759 type args struct {
3760 port string
3761 }
3762 voltPort := &VoltPort{
3763 Name: "16777472",
3764 Device: "SDX6320031",
3765 ID: 16777216,
3766 State: PortStateUp,
3767 }
3768
3769 tests := []struct {
3770 name string
3771 args args
3772 want string
3773 wantErr bool
3774 }{
3775 {
3776 name: "GetPonFromUniPort_PositiveSenario",
3777 args: args{
3778 port: "16777472",
3779 },
3780 want: "16",
3781 wantErr: false,
3782 },
3783 {
3784 name: "GetPonFromUniPort_NegetiveSenario",
3785 args: args{
3786 port: "16777472",
3787 },
3788 wantErr: true,
3789 },
3790 }
3791 for _, tt := range tests {
3792 t.Run(tt.name, func(t *testing.T) {
3793 va := &VoltApplication{}
3794 switch tt.name {
3795 case "GetPonFromUniPort_PositiveSenario":
3796 va.PortsDisc.Store("16777472", voltPort)
3797 got, err := va.GetPonFromUniPort(tt.args.port)
3798 if (err != nil) != tt.wantErr {
3799 t.Errorf("VoltApplication.GetPonFromUniPort() error = %v, wantErr %v", err, tt.wantErr)
3800 return
3801 }
3802 if got != tt.want {
3803 t.Errorf("VoltApplication.GetPonFromUniPort() = %v, want %v", got, tt.want)
3804 }
3805 case "GetPonFromUniPort_NegetiveSenario":
3806 got, err := va.GetPonFromUniPort(tt.args.port)
3807 if (err != nil) != tt.wantErr {
3808 t.Errorf("VoltApplication.GetPonFromUniPort() error = %v, wantErr %v", err, tt.wantErr)
3809 return
3810 }
3811 if got != tt.want {
3812 t.Errorf("VoltApplication.GetPonFromUniPort() = %v, want %v", got, tt.want)
3813 }
3814 }
3815 })
3816 }
3817}
3818
3819func TestVoltApplication_AddIcmpv6Receivers(t *testing.T) {
3820 type args struct {
3821 device string
3822 portID uint32
3823 }
3824 var receiverList []uint32
3825 port := uint32(256)
3826 receiverList = append(receiverList, port)
3827 tests := []struct {
3828 name string
3829 args args
3830 want []uint32
3831 }{
3832 {
3833 name: "AddIcmpv6Receivers",
3834 args: args{
3835 device: "SDX6320031",
3836 portID: port,
3837 },
3838 want: []uint32{port, port},
3839 },
3840 {
3841 name: "DelIcmpv6Receivers",
3842 args: args{
3843 device: "SDX6320031",
3844 portID: port,
3845 },
3846 want: []uint32{},
3847 },
3848 }
3849 for _, tt := range tests {
3850 t.Run(tt.name, func(t *testing.T) {
3851 va := &VoltApplication{}
3852 switch tt.name {
3853 case "AddIcmpv6Receivers":
3854 va.Icmpv6Receivers.Store("SDX6320031", receiverList)
3855 if got := va.AddIcmpv6Receivers(tt.args.device, tt.args.portID); !reflect.DeepEqual(got, tt.want) {
3856 t.Errorf("VoltApplication.AddIcmpv6Receivers() = %v, want %v", got, tt.want)
3857 }
3858 case "DelIcmpv6Receivers":
3859 va.Icmpv6Receivers.Store("SDX6320031", receiverList)
3860 if got := va.DelIcmpv6Receivers(tt.args.device, tt.args.portID); !reflect.DeepEqual(got, tt.want) {
3861 t.Errorf("VoltApplication.DelIcmpv6Receivers() = %v, want %v", got, tt.want)
3862 }
3863 }
3864 })
3865 }
3866}
3867
3868func TestVoltApplication_ProcessDevFlowForDevice(t *testing.T) {
3869 type args struct {
3870 cntx context.Context
3871 device *VoltDevice
3872 vnet *VoltVnet
3873 enabled bool
3874 }
3875 voltDev := &VoltDevice{
3876 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
3877 SerialNum: "SDX6320031",
3878 NniDhcpTrapVid: 123,
3879 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
3880 }
3881 voltVnet := &VoltVnet{
3882 Version: "v3",
3883 VnetConfig: VnetConfig{
3884 Name: "2310-4096-4096",
3885 VnetType: "Encapsulation",
3886 SVlan: 2310,
3887 CVlan: 4096,
3888 UniVlan: 4096,
3889 SVlanTpid: 33024,
3890 },
3891 VnetOper: VnetOper{
3892 PendingDeviceToDelete: "SDX6320031",
3893 DeleteInProgress: true,
3894 },
3895 }
3896 tests := []struct {
3897 name string
3898 args args
3899 }{
3900 {
3901 name: "ProcessDevFlowForDevice_PushDevFlowForVlan",
3902 args: args{
3903 cntx: context.Background(),
3904 device: voltDev,
3905 vnet: voltVnet,
3906 enabled: true,
3907 },
3908 },
3909 }
3910 for _, tt := range tests {
3911 t.Run(tt.name, func(t *testing.T) {
3912 va := &VoltApplication{}
3913 va.DevicesDisc.Store("SDX6320031", voltDev)
3914 va.VnetsByName.Store("2310-4096-4096", voltVnet)
3915 va.ProcessDevFlowForDevice(tt.args.cntx, tt.args.device, tt.args.vnet, tt.args.enabled)
3916 })
3917 }
3918}