blob: 5eef19273726d9356f72ec3bde89c604b339c937 [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
32 "github.com/golang/mock/gomock"
33 "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) {
1115 type args struct {
1116 cntx context.Context
1117 }
1118 tests := []struct {
1119 name string
1120 args args
1121 }{
1122 {
1123 name: "Positive_Case_pushFlowsForUnis",
1124 args: args{
1125 cntx: context.Background(),
1126 },
1127 },
1128 {
1129 name: "Negetive_Case_pushFlowsForUnis",
1130 args: args{
1131 cntx: context.Background(),
1132 },
1133 },
1134 {
1135 name: "Negetive_Case1_pushFlowsForUnis",
1136 args: args{
1137 cntx: context.Background(),
1138 },
1139 },
1140 }
1141 for _, tt := range tests {
1142 t.Run(tt.name, func(t *testing.T) {
1143 d := &VoltDevice{
1144 Name: "SDX6320031",
1145 SerialNum: "SDX6320031",
1146 Ports: sync.Map{},
1147 }
1148 switch tt.name {
1149 case "Positive_Case_pushFlowsForUnis":
1150 voltPort := &VoltPort{
1151 Name: "16777472",
1152 Device: "SDX6320031",
1153 ID: 16777472,
1154 State: PortStateUp,
1155 ChannelPerSubAlarmRaised: false,
1156 Type: VoltPortTypeNni,
1157 }
1158 d.Ports.Store("16777472", voltPort)
1159 ga := GetApplication()
1160 voltPortVnets := make([]*VoltPortVnet, 0)
1161 voltPortVnet := &VoltPortVnet{
1162 Device: "SDX6320031",
1163 Port: "16777472",
1164 DeleteInProgress: true,
1165 }
1166 voltPortVnets = append(voltPortVnets, voltPortVnet)
1167 ga.VnetsByPort.Store("16777472", voltPortVnets)
1168
1169 d.pushFlowsForUnis(tt.args.cntx)
1170 case "Negetive_Case_pushFlowsForUnis":
1171 voltPort1 := &VoltPort{
1172 Name: "16777472",
1173 Device: "SDX6320031",
1174 ID: 16777472,
1175 State: PortStateDown,
1176 ChannelPerSubAlarmRaised: false,
1177 Type: VoltPortTypeNni,
1178 }
1179 d.Ports.Store("16777472", voltPort1)
1180 d.pushFlowsForUnis(tt.args.cntx)
1181 case "Negetive_Case1_pushFlowsForUnis":
1182 voltPort2 := &VoltPort{
1183 Name: "16777472",
1184 Device: "SDX6320031",
1185 ID: 16777472,
1186 State: PortStateUp,
1187 ChannelPerSubAlarmRaised: false,
1188 Type: VoltPortTypeNni,
1189 }
1190 d.Ports.Store("1677747", voltPort2)
1191 d.pushFlowsForUnis(tt.args.cntx)
1192 }
1193 })
1194 }
1195}
1196
1197func TestNewNbDevice(t *testing.T) {
1198 tests := []struct {
1199 name string
1200 want *NbDevice
1201 }{
1202 {
1203 name: "Positive_Case_pushFlowsForUnis",
1204 want: &NbDevice{},
1205 },
1206 }
1207 for _, tt := range tests {
1208 t.Run(tt.name, func(t *testing.T) {
1209 if got := NewNbDevice(); !reflect.DeepEqual(got, tt.want) {
1210 t.Errorf("NewNbDevice() = %v, want %v", got, tt.want)
1211 }
1212 })
1213 }
1214}
1215
1216func TestNbDevice_WriteToDb(t *testing.T) {
1217 type args struct {
1218 cntx context.Context
1219 portID uint32
1220 ponPort *PonPortCfg
1221 }
1222 tests := []struct {
1223 name string
1224 args args
1225 }{
1226 {
1227 name: "Positive_Case_pushFlowsForUnis",
1228 args: args{
1229 cntx: context.Background(),
1230 portID: controller.NNIPortID,
1231 ponPort: &PonPortCfg{
1232 PortID: controller.NNIPortID,
1233 EnableMulticastKPI: false,
1234 },
1235 },
1236 },
1237 }
1238 for _, tt := range tests {
1239 t.Run(tt.name, func(t *testing.T) {
1240 nbd := &NbDevice{
1241 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1242 }
1243 switch tt.name {
1244 case "Positive_Case_pushFlowsForUnis":
1245 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1246 db = dbintf
1247 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1248 nbd.WriteToDb(tt.args.cntx, tt.args.portID, tt.args.ponPort)
1249 }
1250 })
1251 }
1252}
1253
1254func TestNbDevice_AddPortToNbDevice(t *testing.T) {
1255 type args struct {
1256 cntx context.Context
1257 portID uint32
1258 allowedChannels uint32
1259 enableMulticastKPI bool
1260 portAlarmProfileID string
1261 }
1262 ponPort := &PonPortCfg{
1263 PortID: controller.NNIPortID,
1264 MaxActiveChannels: 123,
1265 EnableMulticastKPI: false,
1266 PortAlarmProfileID: "16777",
1267 }
1268 tests := []struct {
1269 name string
1270 args args
1271 want *PonPortCfg
1272 }{
1273 {
1274 name: "Positive_Case_AddPortToNbDevice",
1275 args: args{
1276 cntx: context.Background(),
1277 portID: controller.NNIPortID,
1278 allowedChannels: 123,
1279 enableMulticastKPI: false,
1280 portAlarmProfileID: "16777",
1281 },
1282 want: ponPort,
1283 },
1284 }
1285 for _, tt := range tests {
1286 t.Run(tt.name, func(t *testing.T) {
1287 nbd := &NbDevice{
1288 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1289 PonPorts: sync.Map{},
1290 }
1291 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1292 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1293 db = dbintf
1294 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1295 if got := nbd.AddPortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1296 t.Errorf("NbDevice.AddPortToNbDevice() = %v, want %v", got, tt.want)
1297 }
1298 })
1299 }
1300}
1301
1302func TestVoltApplication_AddDeviceConfig(t *testing.T) {
1303 type args struct {
1304 cntx context.Context
1305 serialNum string
1306 hardwareIdentifier string
1307 nasID string
1308 ipAddress string
1309 uplinkPort string
Akash Reddy Kankanala105581b2024-09-11 05:20:38 +05301310 nniDhcpTrapID uint16
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301311 nniPorts []string
vinokumaf7605fc2023-06-02 18:08:01 +05301312 }
1313 dvcConfg := &DeviceConfig{
1314 SerialNumber: "SDX6320031",
1315 HardwareIdentifier: "0.0.0.0",
1316 IPAddress: "127.26.1.74",
1317 UplinkPort: "16777216",
1318 NasID: "12345",
1319 NniDhcpTrapVid: 123,
1320 }
1321 voltDev := &VoltDevice{
1322 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1323 SerialNum: "SDX6320031",
1324 NniDhcpTrapVid: 123,
1325 }
1326 tests := []struct {
1327 name string
1328 args args
1329 wantErr bool
1330 }{
1331 {
1332 name: "Positive_Case_AddDeviceConfig",
1333 args: args{
1334 cntx: context.Background(),
1335 serialNum: "SDX6320031",
1336 hardwareIdentifier: "0.0.0.0.",
1337 nasID: "12345",
1338 ipAddress: "127.26.1.74",
1339 uplinkPort: "16777216",
1340 nniDhcpTrapID: 123,
1341 },
1342 wantErr: false,
1343 },
1344 }
1345 for _, tt := range tests {
1346 t.Run(tt.name, func(t *testing.T) {
1347 va := &VoltApplication{
1348 DevicesConfig: sync.Map{},
1349 }
1350 va.DevicesConfig.Store("SDX6320031", dvcConfg)
1351 va.DevicesDisc.Store("SDX6320031", voltDev)
1352 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1353 db = dbintf
1354 dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301355 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 +05301356 t.Errorf("VoltApplication.AddDeviceConfig() error = %v, wantErr %v", err, tt.wantErr)
1357 }
1358 })
1359 }
1360}
1361
1362func TestVoltApplication_GetDeviceConfig(t *testing.T) {
1363 type args struct {
1364 serNum string
1365 }
1366 dvcConfg := &DeviceConfig{
1367 SerialNumber: "SDX6320031",
1368 HardwareIdentifier: "0.0.0.0",
1369 IPAddress: "127.26.1.74",
1370 UplinkPort: "16777216",
1371 NasID: "12345",
1372 NniDhcpTrapVid: 123,
1373 }
1374 tests := []struct {
1375 name string
1376 args args
1377 want *DeviceConfig
1378 }{
1379 {
1380 name: "Positive_Case_GetDeviceConfig",
1381 args: args{
1382 serNum: "SDX6320031",
1383 },
1384 want: dvcConfg,
1385 },
1386 {
1387 name: "Negetive_Case_GetDeviceConfig",
1388 args: args{
1389 serNum: "SDX6320031",
1390 },
1391 want: nil,
1392 },
1393 }
1394 for _, tt := range tests {
1395 t.Run(tt.name, func(t *testing.T) {
1396 va := &VoltApplication{
1397 DevicesConfig: sync.Map{},
1398 }
1399 switch tt.name {
1400 case "Positive_Case_GetDeviceConfig":
1401 va.DevicesConfig.Store("SDX6320031", dvcConfg)
1402 if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) {
1403 t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want)
1404 }
1405 case "Negetive_Case_GetDeviceConfig":
1406 if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) {
1407 t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want)
1408 }
1409 }
1410 })
1411 }
1412}
1413
1414func TestNbDevice_UpdatePortToNbDevice(t *testing.T) {
1415 type args struct {
1416 cntx context.Context
1417 portID uint32
1418 allowedChannels uint32
1419 enableMulticastKPI bool
1420 portAlarmProfileID string
1421 }
1422 ponPort := &PonPortCfg{
1423 PortID: controller.NNIPortID,
1424 MaxActiveChannels: 123,
1425 EnableMulticastKPI: false,
1426 PortAlarmProfileID: "16777",
1427 }
1428 tests := []struct {
1429 name string
1430 args args
1431 want *PonPortCfg
1432 }{
1433 {
1434 name: "Positive_Case_UpdatePortToNbDevice",
1435 args: args{
1436 cntx: context.Background(),
1437 portID: controller.NNIPortID,
1438 allowedChannels: 123,
1439 enableMulticastKPI: false,
1440 portAlarmProfileID: "16777",
1441 },
1442 want: ponPort,
1443 },
1444 {
1445 name: "Negetive_Case_UpdatePortToNbDevice",
1446 args: args{
1447 cntx: context.Background(),
1448 portID: 0,
1449 allowedChannels: 123,
1450 enableMulticastKPI: false,
1451 portAlarmProfileID: "16777",
1452 },
1453 want: nil,
1454 },
1455 }
1456 for _, tt := range tests {
1457 t.Run(tt.name, func(t *testing.T) {
1458 nbd := &NbDevice{
1459 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1460 PonPorts: sync.Map{},
1461 }
1462 switch tt.name {
1463 case "Positive_Case_UpdatePortToNbDevice":
1464 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1465 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1466 db = dbintf
1467 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1468 if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1469 t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want)
1470 }
1471 case "Negetive_Case_UpdatePortToNbDevice":
1472 if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1473 t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want)
1474 }
1475 }
1476 })
1477 }
1478}
1479
1480func TestNbDevice_DeletePortFromNbDevice(t *testing.T) {
1481 type args struct {
1482 cntx context.Context
1483 portID uint32
1484 }
1485 ponPort := &PonPortCfg{
1486 PortID: controller.NNIPortID,
1487 MaxActiveChannels: 123,
1488 EnableMulticastKPI: false,
1489 PortAlarmProfileID: "16777",
1490 }
1491 tests := []struct {
1492 name string
1493 args args
1494 }{
1495 {
1496 name: "Positive_Case_DeletePortFromNbDevice",
1497 args: args{
1498 portID: controller.NNIPortID,
1499 },
1500 },
1501 }
1502 for _, tt := range tests {
1503 t.Run(tt.name, func(t *testing.T) {
1504 nbd := &NbDevice{
1505 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1506 PonPorts: sync.Map{},
1507 }
1508 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1509 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1510 db = dbintf
1511 dbintf.EXPECT().DelNbDevicePort(nil, "49686e2d-618f-4e8e-bca0-442ab850a63a", controller.NNIPortID).AnyTimes()
1512 nbd.DeletePortFromNbDevice(tt.args.cntx, tt.args.portID)
1513 })
1514 }
1515}
1516
1517func TestVoltDevice_RegisterFlowAddEvent(t *testing.T) {
1518 type args struct {
1519 cookie string
1520 event *FlowEvent
1521 }
1522 flowEvent := &FlowEvent{
1523 device: "SDX6320031",
1524 cookie: "68786618880",
1525 eType: EventTypeControlFlowAdded,
1526 }
1527 tests := []struct {
1528 name string
1529 args args
1530 }{
1531 {
1532 name: "Positive_Case_RegisterFlowAddEvent",
1533 args: args{
1534 cookie: "68786618880",
1535 event: flowEvent,
1536 },
1537 },
1538 }
1539 for _, tt := range tests {
1540 t.Run(tt.name, func(t *testing.T) {
1541 d := &VoltDevice{
1542 FlowAddEventMap: util.NewConcurrentMap(),
1543 }
1544 d.RegisterFlowAddEvent(tt.args.cookie, tt.args.event)
1545 })
1546 }
1547}
1548
1549func TestVoltDevice_RegisterFlowDelEvent(t *testing.T) {
1550 type args struct {
1551 cookie string
1552 event *FlowEvent
1553 }
1554 flowEvent := &FlowEvent{
1555 device: "SDX6320031",
1556 cookie: "68786618880",
1557 eType: EventTypeControlFlowRemoved,
1558 }
1559 tests := []struct {
1560 name string
1561 args args
1562 }{
1563 {
1564 name: "Positive_Case_RegisterFlowDelEvent",
1565 args: args{
1566 cookie: "68786618880",
1567 event: flowEvent,
1568 },
1569 },
1570 }
1571 for _, tt := range tests {
1572 t.Run(tt.name, func(t *testing.T) {
1573 d := &VoltDevice{
1574 FlowDelEventMap: util.NewConcurrentMap(),
1575 }
1576 d.RegisterFlowDelEvent(tt.args.cookie, tt.args.event)
1577 })
1578 }
1579}
1580
1581func TestVoltDevice_UnRegisterFlowEvent(t *testing.T) {
1582 type args struct {
1583 cookie string
1584 flowModType of.Command
1585 }
1586 tests := []struct {
1587 name string
1588 args args
1589 }{
1590 {
1591 name: "Positive_Case_RegisterFlowDelEvent",
1592 args: args{
1593 cookie: "68786618880",
1594 flowModType: of.CommandDel,
1595 },
1596 },
1597 {
1598 name: "Negetive_Case_RegisterFlowDelEvent",
1599 args: args{
1600 cookie: "68786618880",
1601 flowModType: opt82,
1602 },
1603 },
1604 }
1605 for _, tt := range tests {
1606 t.Run(tt.name, func(t *testing.T) {
1607 switch tt.name {
1608 case "Positive_Case_RegisterFlowDelEvent":
1609 d := &VoltDevice{
1610 FlowDelEventMap: util.NewConcurrentMap(),
1611 }
1612 d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType)
1613 case "Negetive_Case_RegisterFlowDelEvent":
1614 d := &VoltDevice{
1615 FlowDelEventMap: util.NewConcurrentMap(),
1616 }
1617 d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType)
1618 }
1619 })
1620 }
1621}
1622
1623func TestVoltApplication_InitStaticConfig(t *testing.T) {
1624 tests := []struct {
1625 name string
1626 }{
1627 {
1628 name: "Positive_Case_InitStaticConfig",
1629 },
1630 }
1631 for _, tt := range tests {
1632 t.Run(tt.name, func(t *testing.T) {
1633 va := &VoltApplication{}
1634 va.InitStaticConfig()
1635 })
1636 }
1637}
1638
1639func TestVoltApplication_SetVendorID(t *testing.T) {
1640 type args struct {
1641 vendorID string
1642 }
1643 tests := []struct {
1644 name string
1645 args args
1646 }{
1647 {
1648 name: "Positive_Case_SetVendorID",
1649 args: args{
1650 vendorID: "DT",
1651 },
1652 },
1653 }
1654 for _, tt := range tests {
1655 t.Run(tt.name, func(t *testing.T) {
1656 va := &VoltApplication{}
1657 va.SetVendorID(tt.args.vendorID)
1658 })
1659 }
1660}
1661
1662func TestVoltApplication_GetVendorID(t *testing.T) {
1663 tests := []struct {
1664 name string
1665 want string
1666 }{
1667 {
1668 name: "Positive_Case_GetVendorID",
1669 want: "DT",
1670 },
1671 }
1672 for _, tt := range tests {
1673 t.Run(tt.name, func(t *testing.T) {
1674 va := &VoltApplication{
1675 vendorID: "DT",
1676 }
1677 if got := va.GetVendorID(); got != tt.want {
1678 t.Errorf("VoltApplication.GetVendorID() = %v, want %v", got, tt.want)
1679 }
1680 })
1681 }
1682}
1683
1684func TestVoltApplication_SetRebootFlag(t *testing.T) {
1685 type args struct {
1686 flag bool
1687 }
1688 tests := []struct {
1689 name string
1690 args args
1691 }{
1692 {
1693 name: "Positive_Case_SetRebootFlag",
1694 args: args{
1695 flag: true,
1696 },
1697 },
1698 }
1699 for _, tt := range tests {
1700 t.Run(tt.name, func(t *testing.T) {
1701 va := &VoltApplication{}
1702 va.SetRebootFlag(tt.args.flag)
1703 })
1704 }
1705}
1706
1707func TestVoltApplication_GetUpgradeFlag(t *testing.T) {
1708 tests := []struct {
1709 name string
1710 want bool
1711 }{
1712 {
1713 name: "Positive_Case_GetUpgradeFlag",
1714 want: true,
1715 },
1716 }
1717 for _, tt := range tests {
1718 t.Run(tt.name, func(t *testing.T) {
1719 va := &VoltApplication{}
1720 isUpgradeComplete = true
1721 if got := va.GetUpgradeFlag(); got != tt.want {
1722 t.Errorf("VoltApplication.GetUpgradeFlag() = %v, want %v", got, tt.want)
1723 }
1724 })
1725 }
1726}
1727
1728func TestVoltApplication_SetUpgradeFlag(t *testing.T) {
1729 type args struct {
1730 flag bool
1731 }
1732 tests := []struct {
1733 name string
1734 args args
1735 }{
1736 {
1737 name: "Positive_Case_GetUpgradeFlag",
1738 args: args{
1739 flag: true,
1740 },
1741 },
1742 }
1743 for _, tt := range tests {
1744 t.Run(tt.name, func(t *testing.T) {
1745 va := &VoltApplication{}
1746 va.SetUpgradeFlag(tt.args.flag)
1747 })
1748 }
1749}
1750
1751func TestVoltApplication_AddDevice(t *testing.T) {
1752 type args struct {
1753 cntx context.Context
1754 device string
1755 slno string
1756 southBoundID string
1757 }
1758 voltDev := &VoltDevice{
1759 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1760 SerialNum: "SDX6320031",
1761 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301762 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05301763 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1764 }
1765 nbd := &NbDevice{
1766 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1767 PonPorts: sync.Map{},
1768 }
1769 ponPortCnf := &PonPortCfg{
1770 PortID: controller.NNIPortID,
1771 MaxActiveChannels: 123,
1772 EnableMulticastKPI: false,
1773 PortAlarmProfileID: "16777",
1774 }
1775 tests := []struct {
1776 name string
1777 args args
1778 }{
1779 {
1780 name: "Positive_Case_AddDevice",
1781 args: args{
1782 cntx: context.Background(),
1783 device: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1784 slno: "SDX6320031",
1785 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1786 },
1787 },
1788 {
1789 name: "Negetive_Case_AddDevice",
1790 args: args{
1791 cntx: context.Background(),
1792 device: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1793 slno: "SDX6320031",
1794 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1795 },
1796 },
1797 }
1798 for _, tt := range tests {
1799 t.Run(tt.name, func(t *testing.T) {
1800 va := &VoltApplication{
1801 DevicesDisc: sync.Map{},
1802 NbDevice: sync.Map{},
1803 }
1804 switch tt.name {
1805 case "Positive_Case_AddDevice":
1806 va.DevicesDisc.Store("SDX6320031", voltDev)
1807 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a123", nbd)
1808 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
1809 va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID)
1810 case "Negetive_Case_AddDevice":
1811 va.DevicesDisc.Store("SDX6320031", voltDev)
1812 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
1813 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1814 db = dbintf
1815 dbintf.EXPECT().GetAllNbPorts(context.Background(), "49686e2d-618f-4e8e-bca0-442ab850a63a123").AnyTimes()
1816 va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID)
1817 }
1818 })
1819 }
1820}
1821
1822func TestVoltApplication_DelDevice(t *testing.T) {
1823 type args struct {
1824 cntx context.Context
1825 device string
1826 }
1827 voltDev := &VoltDevice{
1828 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1829 SerialNum: "SDX6320031",
1830 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301831 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05301832 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1833 }
1834 tests := []struct {
1835 name string
1836 args args
1837 }{
1838 {
1839 name: "Positive_Case_AddDevice",
1840 args: args{
1841 cntx: context.Background(),
1842 device: "SDX6320031",
1843 },
1844 },
1845 {
1846 name: "Delete_Case_AddDevice",
1847 args: args{
1848 cntx: context.Background(),
1849 device: "SDX6320031",
1850 },
1851 },
1852 }
1853 for _, tt := range tests {
1854 t.Run(tt.name, func(t *testing.T) {
1855 va := &VoltApplication{
1856 DevicesDisc: sync.Map{},
1857 }
1858 switch tt.name {
1859 case "Positive_Case_AddDevice":
1860 va.DevicesDisc.Store("SDX6320031", voltDev)
1861 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1862 db = dbintf
1863 dbintf.EXPECT().DelAllRoutesForDevice(context.Background(), "SDX6320031").AnyTimes()
1864 dbintf.EXPECT().GetAllMigrateServicesReq(context.Background(), "SDX6320031").AnyTimes()
1865 dbintf.EXPECT().DelAllGroup(context.Background(), "SDX6320031").AnyTimes()
1866 dbintf.EXPECT().DelAllMeter(context.Background(), "SDX6320031").AnyTimes()
1867 dbintf.EXPECT().DelAllPorts(context.Background(), "SDX6320031").AnyTimes()
1868 va.DelDevice(tt.args.cntx, tt.args.device)
1869 case "Delete_Case_AddDevice":
1870 va.DelDevice(tt.args.cntx, tt.args.device)
1871 }
1872 })
1873 }
1874}
1875
1876func TestVoltApplication_PortAddInd(t *testing.T) {
1877 type args struct {
1878 cntx context.Context
1879 device string
1880 id uint32
1881 portName string
1882 }
1883 voltDev := &VoltDevice{
1884 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1885 SerialNum: "SDX6320031",
1886 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301887 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05301888 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1889 }
1890 tests := []struct {
1891 name string
1892 args args
1893 }{
1894 {
1895 name: "Positive_Case_PortAddInd",
1896 args: args{
1897 cntx: context.Background(),
1898 device: "SDX6320031",
1899 id: controller.NNIPortID,
1900 portName: "16777216",
1901 },
1902 },
1903 {
1904 name: "Negetive_Case_PortAddInd",
1905 args: args{
1906 cntx: context.Background(),
1907 device: "SDX6320031",
1908 id: controller.NNIPortID,
1909 portName: "16777216",
1910 },
1911 },
1912 }
1913 for _, tt := range tests {
1914 t.Run(tt.name, func(t *testing.T) {
1915 va := &VoltApplication{
1916 DevicesDisc: sync.Map{},
1917 }
1918 switch tt.name {
1919 case "Positive_Case_PortAddInd":
1920 va.DevicesDisc.Store("SDX6320031", voltDev)
1921 va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName)
1922 case "Negetive_Case_PortAddInd":
1923 va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName)
1924 }
1925 })
1926 }
1927}
1928
1929func TestVoltApplication_PortUpdateInd(t *testing.T) {
1930 type args struct {
1931 device string
1932 portName string
1933 id uint32
1934 }
1935 voltDev := &VoltDevice{
1936 Name: "SDX6320031",
1937 SerialNum: "SDX6320031",
1938 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05301939 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05301940 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1941 }
1942 tests := []struct {
1943 name string
1944 args args
1945 }{
1946 {
1947 name: "Positive_Case_PortUpdateInd",
1948 args: args{
1949 device: "SDX6320031",
1950 id: controller.NNIPortID,
1951 portName: "16777216",
1952 },
1953 },
1954 {
1955 name: "Negetive_Case_PortUpdateInd",
1956 args: args{
1957 device: "SDX6320031",
1958 id: controller.NNIPortID,
1959 portName: "16777216",
1960 },
1961 },
1962 }
1963 for _, tt := range tests {
1964 t.Run(tt.name, func(t *testing.T) {
1965 va := &VoltApplication{
1966 DevicesDisc: sync.Map{},
1967 }
1968 switch tt.name {
1969 case "Positive_Case_PortAddInd":
1970 va.DevicesDisc.Store("SDX6320031", voltDev)
1971 d := &VoltDevice{
1972 Ports: sync.Map{},
1973 }
1974 voltPort := &VoltPort{
1975 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1976 Device: "SDX6320031",
1977 ID: 16777472,
1978 State: PortStateDown,
1979 ChannelPerSubAlarmRaised: false,
1980 Type: VoltPortTypeNni,
1981 }
1982 d.Ports.Store(16777472, voltPort)
1983 va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id)
1984 case "Negetive_Case_PortUpdateInd":
1985 va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id)
1986 }
1987 })
1988 }
1989}
1990
1991func TestVoltApplication_AddNbPonPort(t *testing.T) {
1992 type args struct {
1993 cntx context.Context
1994 oltSbID string
1995 portID uint32
1996 maxAllowedChannels uint32
1997 enableMulticastKPI bool
1998 portAlarmProfileID string
1999 }
2000 voltDev := &VoltDevice{
2001 Name: "SDX6320031",
2002 SerialNum: "SDX6320031",
2003 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302004 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05302005 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2006 }
2007 nbd := &NbDevice{
2008 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2009 }
2010 tests := []struct {
2011 name string
2012 args args
2013 wantErr bool
2014 }{
2015 {
2016 name: "Positive_Case_AddNbPonPort",
2017 args: args{
2018 cntx: context.Background(),
2019 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2020 portID: 16777472,
2021 maxAllowedChannels: 0,
2022 enableMulticastKPI: false,
2023 portAlarmProfileID: "16777",
2024 },
2025 },
2026 {
2027 name: "Negetive_Case_AddNbPonPort",
2028 args: args{
2029 cntx: context.Background(),
2030 oltSbID: "0",
2031 portID: 16777472,
2032 maxAllowedChannels: 0,
2033 enableMulticastKPI: false,
2034 portAlarmProfileID: "16777",
2035 },
2036 },
2037 }
2038 for _, tt := range tests {
2039 t.Run(tt.name, func(t *testing.T) {
2040 va := &VoltApplication{
2041 DevicesDisc: sync.Map{},
2042 NbDevice: sync.Map{},
2043 }
2044 switch tt.name {
2045 case "Positive_Case_AddNbPonPort":
2046 va.DevicesDisc.Store("SDX6320031", voltDev)
2047 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2048 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2049 db = dbintf
2050 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2051 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 {
2052 t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2053 }
2054 case "Negetive_Case_AddNbPonPort":
2055 va.DevicesDisc.Store("SDX6320031", voltDev)
2056 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2057 db = dbintf
2058 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2059 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 {
2060 t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2061 }
2062 }
2063 })
2064 }
2065}
2066
2067func TestVoltApplication_UpdateNbPonPort(t *testing.T) {
2068 type args struct {
2069 cntx context.Context
2070 oltSbID string
2071 portID uint32
2072 maxAllowedChannels uint32
2073 enableMulticastKPI bool
2074 portAlarmProfileID string
2075 }
2076 voltDev := &VoltDevice{
2077 Name: "SDX6320031",
2078 SerialNum: "SDX6320031",
2079 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302080 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05302081 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2082 ActiveChannelsPerPon: sync.Map{},
2083 }
2084 nbd := &NbDevice{
2085 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2086 PonPorts: sync.Map{},
2087 }
2088 ponPortCnf := &PonPortCfg{
2089 PortID: controller.NNIPortID,
2090 MaxActiveChannels: 123,
2091 EnableMulticastKPI: false,
2092 PortAlarmProfileID: "16777",
2093 }
2094 tests := []struct {
2095 name string
2096 args args
2097 wantErr bool
2098 }{
2099 {
2100 name: "Positive_Case_UpdateNbPonPort",
2101 args: args{
2102 cntx: context.Background(),
2103 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2104 portID: controller.NNIPortID,
2105 maxAllowedChannels: 0,
2106 enableMulticastKPI: false,
2107 portAlarmProfileID: "16777",
2108 },
2109 wantErr: false,
2110 },
2111 {
2112 name: "Negetive_Case_Port_doesn't_exists",
2113 args: args{
2114 cntx: context.Background(),
2115 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2116 portID: 16777472,
2117 maxAllowedChannels: 0,
2118 enableMulticastKPI: false,
2119 portAlarmProfileID: "16777",
2120 },
2121 wantErr: true,
2122 },
2123 {
2124 name: "Negetive_Case_Device-doesn't-exists",
2125 args: args{
2126 cntx: context.Background(),
2127 oltSbID: "0",
2128 portID: 16777472,
2129 maxAllowedChannels: 0,
2130 enableMulticastKPI: false,
2131 portAlarmProfileID: "16777",
2132 },
2133 wantErr: true,
2134 },
2135 }
2136 for _, tt := range tests {
2137 t.Run(tt.name, func(t *testing.T) {
2138 va := &VoltApplication{
2139 DevicesDisc: sync.Map{},
2140 NbDevice: sync.Map{},
2141 }
2142 switch tt.name {
2143 case "Positive_Case_UpdateNbPonPort":
2144 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2145 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
2146 va.DevicesDisc.Store("SDX6320031", voltDev)
2147 voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf)
2148 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2149 db = dbintf
2150 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2151 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 {
2152 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2153 }
2154 case "Negetive_Case_Port_doesn't_exists":
2155 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2156 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2157 db = dbintf
2158 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2159 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 {
2160 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2161 }
2162 case "Negetive_Case_Device-doesn't-exists":
2163 va.DevicesDisc.Store("SDX6320031", voltDev)
2164 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2165 db = dbintf
2166 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2167 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 {
2168 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2169 }
2170 }
2171 })
2172 }
2173}
2174
2175func TestVoltApplication_DeleteNbPonPort(t *testing.T) {
2176 type args struct {
2177 cntx context.Context
2178 oltSbID string
2179 portID uint32
2180 }
2181 voltDev := &VoltDevice{
2182 Name: "SDX6320031",
2183 SerialNum: "SDX6320031",
2184 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302185 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05302186 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2187 ActiveChannelsPerPon: sync.Map{},
2188 }
2189 nbd := &NbDevice{
2190 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2191 }
2192 ponPortCnf := &PonPortCfg{
2193 PortID: controller.NNIPortID,
2194 MaxActiveChannels: 123,
2195 EnableMulticastKPI: false,
2196 PortAlarmProfileID: "16777",
2197 }
2198 tests := []struct {
2199 name string
2200 args args
2201 wantErr bool
2202 }{
2203 {
2204 name: "Positive_Case_DeleteNbPonPort",
2205 args: args{
2206 cntx: context.Background(),
2207 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2208 portID: controller.NNIPortID,
2209 },
2210 wantErr: false,
2211 },
2212 {
2213 name: "Negetive_Case_DeleteNbPonPort",
2214 args: args{
2215 cntx: context.Background(),
2216 oltSbID: "0",
2217 portID: controller.NNIPortID,
2218 },
2219 wantErr: false,
2220 },
2221 }
2222 for _, tt := range tests {
2223 t.Run(tt.name, func(t *testing.T) {
2224 va := &VoltApplication{
2225 DevicesDisc: sync.Map{},
2226 NbDevice: sync.Map{},
2227 }
2228 switch tt.name {
2229 case "Positive_Case_DeleteNbPonPort":
2230 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2231 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
2232 va.DevicesDisc.Store("SDX6320031", voltDev)
2233 voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf)
2234 va.DevicesDisc.Store("SDX6320031", voltDev)
2235 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2236 db = dbintf
2237 dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2238 if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr {
2239 t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2240 }
2241 case "Negetive_Case_DeleteNbPonPort":
2242 va.DevicesDisc.Store("SDX6320031", voltDev)
2243 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2244 db = dbintf
2245 dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2246 if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr {
2247 t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2248 }
2249 }
2250 })
2251 }
2252}
2253
2254func TestVoltApplication_DeviceUpInd(t *testing.T) {
2255 type args struct {
2256 device string
2257 }
2258 voltDev := &VoltDevice{
2259 Name: "SDX6320031",
2260 SerialNum: "SDX6320031",
2261 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302262 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05302263 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2264 }
2265 tests := []struct {
2266 name string
2267 args args
2268 }{
2269 {
2270 name: "Positive_Case_DeviceUpInd",
2271 args: args{
2272 device: "SDX6320031",
2273 },
2274 },
2275 {
2276 name: "Negetive_Case_DeviceUpInd",
2277 args: args{
2278 device: "o",
2279 },
2280 },
2281 }
2282 for _, tt := range tests {
2283 t.Run(tt.name, func(t *testing.T) {
2284 va := &VoltApplication{
2285 DevicesDisc: sync.Map{},
2286 }
2287 switch tt.name {
2288 case "Positive_Case_DeviceUpInd":
2289 va.DevicesDisc.Store("SDX6320031", voltDev)
2290 va.DeviceUpInd(tt.args.device)
2291 case "Negetive_Case_DeviceUpInd":
2292 va.DeviceUpInd(tt.args.device)
2293 }
2294 })
2295 }
2296}
2297
2298func TestVoltApplication_DeviceDownInd(t *testing.T) {
2299 type args struct {
2300 device string
2301 }
2302 voltDev := &VoltDevice{
2303 Name: "SDX6320031",
2304 SerialNum: "SDX6320031",
2305 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302306 NniPort: []string{"16777216"},
vinokumaf7605fc2023-06-02 18:08:01 +05302307 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2308 }
2309 tests := []struct {
2310 name string
2311 args args
2312 }{
2313 {
2314 name: "Positive_Case_DeviceDownInd",
2315 args: args{
2316 device: "SDX6320031",
2317 },
2318 },
2319 {
2320 name: "Negetive_Case_DeviceDownInd",
2321 args: args{
2322 device: "o",
2323 },
2324 },
2325 }
2326 for _, tt := range tests {
2327 t.Run(tt.name, func(t *testing.T) {
2328 va := &VoltApplication{
2329 DevicesDisc: sync.Map{},
2330 }
2331 switch tt.name {
2332 case "Positive_Case_DeviceDownInd":
2333 va.DevicesDisc.Store("SDX6320031", voltDev)
2334 va.DeviceDownInd(tt.args.device)
2335 case "Negetive_Case_DeviceDownInd":
2336 va.DeviceDownInd(tt.args.device)
2337 }
2338 })
2339 }
2340}
2341
2342func TestVoltApplication_DeviceRebootInd(t *testing.T) {
2343 type args struct {
2344 cntx context.Context
2345 device string
2346 serialNum string
2347 southBoundID string
2348 }
2349 voltDev := &VoltDevice{
Akash Soni6f369452023-09-19 11:18:28 +05302350 Name: "SDX6320031",
2351 SerialNum: "SDX6320031",
2352 State: controller.DeviceStateREBOOTED,
2353 MigratingServices: util.NewConcurrentMap(),
vinokumaf7605fc2023-06-02 18:08:01 +05302354 }
2355 tests := []struct {
2356 name string
2357 args args
2358 }{
2359 {
2360 name: "Positive_Case_DeviceRebootInd",
2361 args: args{
2362 device: "SDX6320031",
2363 serialNum: "SDX6320031",
2364 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2365 },
2366 },
Akash Soni6f369452023-09-19 11:18:28 +05302367 {
2368 name: "Negetive_Case_DeviceRebootInd",
2369 args: args{
2370 device: "SDX6320031",
2371 serialNum: "SDX6320031",
2372 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2373 },
2374 },
vinokumaf7605fc2023-06-02 18:08:01 +05302375 }
2376 for _, tt := range tests {
2377 t.Run(tt.name, func(t *testing.T) {
2378 va := &VoltApplication{
2379 DevicesDisc: sync.Map{},
2380 }
Akash Soni6f369452023-09-19 11:18:28 +05302381 switch tt.name {
2382 case "Positive_Case_DeviceRebootInd":
2383 va.DevicesDisc.Store("SDX6320031", voltDev)
2384 va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID)
2385 case "Negetive_Case_DeviceRebootInd":
2386 voltDev.State = controller.DeviceStateDOWN
2387 va.DevicesDisc.Store("SDX6320031", voltDev)
2388 GetApplication().DevicesDisc.Store("SDX6320031", voltDev)
2389 va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID)
2390 }
vinokumaf7605fc2023-06-02 18:08:01 +05302391 })
2392 }
2393}
vinokuma02fbfd02023-07-05 15:23:33 +05302394
2395func TestVoltApplication_GetDeviceFromPort(t *testing.T) {
2396 type args struct {
2397 port string
2398 }
2399 voltDev := &VoltDevice{
2400 Name: "SDX6320031",
2401 SerialNum: "SDX6320031",
2402 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302403 NniPort: []string{"16777216"},
vinokuma02fbfd02023-07-05 15:23:33 +05302404 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2405 Ports: sync.Map{},
2406 }
2407 voltPort := &VoltPort{
2408 Name: "16777216",
2409 Device: "SDX6320031",
2410 ID: 16777216,
2411 State: PortStateDown,
2412 ChannelPerSubAlarmRaised: false,
2413 Type: VoltPortTypeNni,
2414 }
2415 tests := []struct {
2416 name string
2417 args args
2418 want *VoltDevice
2419 wantErr bool
2420 }{
2421 {
2422 name: "Positive_Case_GetDeviceFromPort",
2423 args: args{
2424 port: "16777216",
2425 },
2426 want: voltDev,
2427 wantErr: false,
2428 },
2429 }
2430 for _, tt := range tests {
2431 t.Run(tt.name, func(t *testing.T) {
2432 va := &VoltApplication{
2433 DevicesDisc: sync.Map{},
2434 PortsDisc: sync.Map{},
2435 }
2436 va.PortsDisc.Store("16777216", voltPort)
2437 va.DevicesDisc.Store("SDX6320031", voltDev)
2438 got, err := va.GetDeviceFromPort(tt.args.port)
2439 if (err != nil) != tt.wantErr {
2440 t.Errorf("VoltApplication.GetDeviceFromPort() error = %v, wantErr %v", err, tt.wantErr)
2441 return
2442 }
2443 if !reflect.DeepEqual(got, tt.want) {
2444 t.Errorf("VoltApplication.GetDeviceFromPort() = %v, want %v", got, tt.want)
2445 }
2446 })
2447 }
2448}
2449
2450func TestVoltApplication_GetPortID(t *testing.T) {
2451 type args struct {
2452 port string
2453 }
2454 voltPort := &VoltPort{
2455 Name: "16777216",
2456 Device: "SDX6320031",
2457 ID: 16777216,
2458 State: PortStateDown,
2459 ChannelPerSubAlarmRaised: false,
2460 Type: VoltPortTypeNni,
2461 }
2462 tests := []struct {
2463 name string
2464 args args
2465 want uint32
2466 wantErr bool
2467 }{
2468 {
2469 name: "Positive_Case_GetPortID",
2470 args: args{
2471 port: "16777216",
2472 },
2473 want: 16777216,
2474 wantErr: false,
2475 },
2476 }
2477 for _, tt := range tests {
2478 t.Run(tt.name, func(t *testing.T) {
2479 va := &VoltApplication{
2480 PortsDisc: sync.Map{},
2481 }
2482 va.PortsDisc.Store("16777216", voltPort)
2483 got, err := va.GetPortID(tt.args.port)
2484 if (err != nil) != tt.wantErr {
2485 t.Errorf("VoltApplication.GetPortID() error = %v, wantErr %v", err, tt.wantErr)
2486 return
2487 }
2488 if got != tt.want {
2489 t.Errorf("VoltApplication.GetPortID() = %v, want %v", got, tt.want)
2490 }
2491 })
2492 }
2493}
2494
2495func TestVoltApplication_GetPortName(t *testing.T) {
2496 type args struct {
2497 port uint32
2498 }
2499 voltPort := &VoltPort{
2500 Name: "16777216",
2501 Device: "SDX6320031",
2502 ID: 16777216,
2503 State: PortStateDown,
2504 ChannelPerSubAlarmRaised: false,
2505 Type: VoltPortTypeNni,
2506 }
2507 tests := []struct {
2508 name string
2509 args args
2510 want string
2511 wantErr bool
2512 }{
2513 {
2514 name: "Positive_Case_GetPortID",
2515 args: args{
2516 port: 16777216,
2517 },
2518 want: "16777216",
2519 wantErr: false,
2520 },
2521 }
2522 for _, tt := range tests {
2523 t.Run(tt.name, func(t *testing.T) {
2524 va := &VoltApplication{
2525 PortsDisc: sync.Map{},
2526 }
2527 va.PortsDisc.Store("16777216", voltPort)
2528 got, err := va.GetPortName(tt.args.port)
2529 if (err != nil) != tt.wantErr {
2530 t.Errorf("VoltApplication.GetPortName() error = %v, wantErr %v", err, tt.wantErr)
2531 return
2532 }
2533 if got != tt.want {
2534 t.Errorf("VoltApplication.GetPortName() = %v, want %v", got, tt.want)
2535 }
2536 })
2537 }
2538}
2539
2540func TestVoltApplication_PortUpInd(t *testing.T) {
2541 type args struct {
2542 cntx context.Context
2543 device string
2544 port string
2545 }
2546 voltDev := &VoltDevice{
2547 Name: "SDX6320031",
2548 SerialNum: "SDX6320031",
2549 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302550 NniPort: []string{"16777216"},
vinokuma02fbfd02023-07-05 15:23:33 +05302551 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2552 Ports: sync.Map{},
2553 VpvsBySvlan: util.NewConcurrentMap(),
2554 }
2555 voltPort := &VoltPort{
2556 Name: "16777472",
2557 Device: "SDX6320031",
2558 ID: 16777472,
2559 State: PortStateUp,
2560 ChannelPerSubAlarmRaised: false,
2561 Type: VoltPortTypeNni,
2562 }
2563 voltServ := &VoltService{
2564 VoltServiceOper: VoltServiceOper{
2565 Device: "SDX6320031",
2566 },
2567 VoltServiceCfg: VoltServiceCfg{
2568 IsActivated: true,
2569 },
2570 }
2571 voltPortVnets := make([]*VoltPortVnet, 0)
2572 voltPortVnet := &VoltPortVnet{
2573 Device: "SDX6320031",
2574 Port: "16777472",
2575 DeleteInProgress: false,
2576 services: sync.Map{},
2577 SVlan: 4096,
2578 CVlan: 2310,
2579 UniVlan: 4096,
2580 SVlanTpid: 65,
2581 servicesCount: atomic.NewUint64(1),
2582 }
2583 voltPortVnets = append(voltPortVnets, voltPortVnet)
2584
2585 tests := []struct {
2586 name string
2587 args args
2588 }{
2589 {
2590 name: "Positive_Case_PortUpInd",
2591 args: args{
2592 cntx: context.Background(),
2593 port: "16777472",
2594 device: "SDX6320031",
2595 },
2596 },
2597 }
2598 for _, tt := range tests {
2599 t.Run(tt.name, func(t *testing.T) {
2600 va := &VoltApplication{
2601 DevicesDisc: sync.Map{},
2602 VnetsByPort: sync.Map{},
2603 }
2604 va.DevicesDisc.Store("SDX6320031", voltDev)
2605 voltDev.Ports.Store("16777472", voltPort)
2606 va.VnetsByPort.Store("16777472", voltPortVnets)
2607 voltPortVnet.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
2608 voltapp := GetApplication()
2609 voltapp.DevicesDisc.Store("SDX6320031", voltDev)
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302610 voltapp.DevicesConfig.Store("SDX6320031", &DeviceConfig{UplinkPort: "16777216"})
vinokuma02fbfd02023-07-05 15:23:33 +05302611 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2612 db = dbintf
2613 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2614 va.PortUpInd(tt.args.cntx, tt.args.device, tt.args.port)
2615 })
2616 }
2617}
2618
2619func TestVoltApplication_PortDownInd(t *testing.T) {
2620 type args struct {
2621 cntx context.Context
2622 device string
2623 port string
2624 }
2625 voltDev := &VoltDevice{
2626 Name: "SDX6320031",
2627 SerialNum: "SDX6320031",
2628 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05302629 NniPort: []string{"16777216"},
vinokuma02fbfd02023-07-05 15:23:33 +05302630 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2631 Ports: sync.Map{},
2632 VpvsBySvlan: util.NewConcurrentMap(),
2633 }
2634 voltPort := &VoltPort{
2635 Name: "16777472",
2636 Device: "SDX6320031",
2637 ID: 16777472,
2638 State: PortStateDown,
2639 ChannelPerSubAlarmRaised: false,
2640 Type: VoltPortTypeNni,
2641 }
2642 voltPortVnets := make([]*VoltPortVnet, 0)
2643 voltPortVnet := &VoltPortVnet{
2644 Device: "SDX6320031",
2645 Port: "16777472",
2646 DeleteInProgress: false,
2647 services: sync.Map{},
2648 SVlan: 4096,
2649 CVlan: 2310,
2650 UniVlan: 4096,
2651 SVlanTpid: 65,
2652 servicesCount: atomic.NewUint64(1),
2653 }
2654 voltPortVnets = append(voltPortVnets, voltPortVnet)
2655 tests := []struct {
2656 name string
2657 args args
2658 }{
2659 {
2660 name: "Positive_Case_PortDownInd",
2661 args: args{
2662 cntx: context.Background(),
2663 port: "16777472",
2664 device: "SDX6320031",
2665 },
2666 },
2667 }
2668 for _, tt := range tests {
2669 t.Run(tt.name, func(t *testing.T) {
2670 va := &VoltApplication{}
2671 va.DevicesDisc.Store("SDX6320031", voltDev)
2672 voltDev.Ports.Store("16777472", voltPort)
2673 va.VnetsByPort.Store("16777472", voltPortVnets)
2674 voltApp := GetApplication()
2675 voltApp.DevicesDisc.Store("SDX6320031", voltDev)
2676 va.PortDownInd(tt.args.cntx, tt.args.device, tt.args.port)
2677 })
2678 }
2679}
2680
2681func TestVoltApplication_UpdateDeviceSerialNumberList(t *testing.T) {
2682 type args struct {
2683 oldOltSlNo string
2684 newOltSlNo string
2685 }
Akash Soni6f369452023-09-19 11:18:28 +05302686 appMock := mocks.NewMockApp(gomock.NewController(t))
2687 controller.NewController(ctx, appMock)
2688 devicelist := []string{
2689 "SDX6320030",
2690 "SDX6320031",
2691 }
2692 voltVnet := &VoltVnet{
2693 Version: "v3",
2694 VnetConfig: VnetConfig{
2695 Name: "2310-4096-4096",
2696 VnetType: "Encapsulation",
2697 SVlan: 2310,
2698 CVlan: 4096,
2699 UniVlan: 4096,
2700 SVlanTpid: 33024,
2701 DevicesList: devicelist,
2702 },
2703 }
2704 devicesList := make(map[string]OperInProgress)
2705 devicesList["SDX6320030"] = opt82
2706 mvp := &MvlanProfile{
2707 Name: "mvlan_test",
2708 DevicesList: devicesList,
vinokuma02fbfd02023-07-05 15:23:33 +05302709 }
2710 tests := []struct {
2711 name string
2712 args args
2713 }{
2714 {
2715 name: "Positive_Case_UpdateDeviceSerialNumberList",
2716 args: args{
2717 oldOltSlNo: "SDX6320030",
2718 newOltSlNo: "SDX6320031",
2719 },
2720 },
2721 }
2722 for _, tt := range tests {
2723 t.Run(tt.name, func(t *testing.T) {
Akash Soni6f369452023-09-19 11:18:28 +05302724 va := &VoltApplication{
2725 VnetsByName: sync.Map{},
2726 MvlanProfilesByName: sync.Map{},
2727 }
2728 va.VnetsByName.Store("2310-4096-4096", voltVnet)
2729 va.MvlanProfilesByName.Store("mvlan_test", mvp)
vinokuma02fbfd02023-07-05 15:23:33 +05302730 va.UpdateDeviceSerialNumberList(tt.args.oldOltSlNo, tt.args.newOltSlNo)
2731 })
2732 }
2733}
vinokuma04dc9f82023-07-31 15:47:49 +05302734
2735func TestVoltApplication_DeleteMacInPortMap(t *testing.T) {
2736 type args struct {
2737 macAddr net.HardwareAddr
2738 }
2739
2740 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
2741 macPort := map[string]string{}
2742 macPort[macAdd.String()] = test_data
2743
2744 tests := []struct {
2745 name string
2746 args args
2747 }{
2748 {
2749 name: "Positive_Case_DeleteMacInPortMap",
2750 args: args{
2751 macAddr: macAdd,
2752 },
2753 },
2754 }
2755 for _, tt := range tests {
2756 t.Run(tt.name, func(t *testing.T) {
2757 va := &VoltApplication{
2758 macPortMap: macPort,
2759 }
2760 va.DeleteMacInPortMap(tt.args.macAddr)
2761 })
2762 }
2763}
2764
2765func TestVoltApplication_TriggerPendingServiceDeactivateReq(t *testing.T) {
2766 type args struct {
2767 cntx context.Context
2768 device string
2769 }
Akash Sonief452f12024-12-12 18:20:28 +05302770
vinokuma04dc9f82023-07-31 15:47:49 +05302771 voltServ := &VoltService{
2772 VoltServiceOper: VoltServiceOper{
2773 Device: "SDX6320031",
2774 },
2775 VoltServiceCfg: VoltServiceCfg{
2776 Name: "SDX6320031-1_SDX6320031-1-4096-2310-4096-65",
2777 SVlan: 4096,
2778 CVlan: 2310,
2779 UniVlan: 4096,
2780 Port: "16777472",
2781 TechProfileID: 65,
2782 },
2783 }
2784
2785 voltPortVnets := make([]*VoltPortVnet, 0)
2786 voltPortVnet := &VoltPortVnet{
2787 Device: "SDX6320031",
2788 Port: "16777472",
2789 DeleteInProgress: false,
2790 services: sync.Map{},
2791 SVlan: 4096,
2792 CVlan: 2310,
2793 UniVlan: 4096,
2794 SVlanTpid: 65,
2795 servicesCount: atomic.NewUint64(1),
2796 }
2797
2798 voltPortVnets = append(voltPortVnets, voltPortVnet)
2799 tests := []struct {
2800 name string
2801 args args
2802 }{
2803 {
2804 name: "Positive_Case_DeleteMacInPortMap",
2805 args: args{
2806 cntx: context.Background(),
2807 device: "SDX6320031",
2808 },
2809 },
2810 }
2811
2812 for _, tt := range tests {
2813 t.Run(tt.name, func(t *testing.T) {
2814 va := &VoltApplication{
Akash Sonief452f12024-12-12 18:20:28 +05302815 ServicesToDeactivate: sync.Map{},
vinokuma04dc9f82023-07-31 15:47:49 +05302816 ServiceByName: sync.Map{},
2817 VnetsByPort: sync.Map{},
2818 }
2819 va.ServiceByName.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
2820 va.VnetsByPort.Store("16777472", voltPortVnets)
Akash Sonief452f12024-12-12 18:20:28 +05302821 va.ServicesToDeactivate.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", true)
vinokuma04dc9f82023-07-31 15:47:49 +05302822 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2823 db = dbintf
2824 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2825 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
2826 va.TriggerPendingServiceDeactivateReq(tt.args.cntx, tt.args.device)
2827 })
2828 }
2829}
2830
2831func TestVoltApplication_ReadAllFromDb(t *testing.T) {
2832 type args struct {
2833 cntx context.Context
2834 }
2835
2836 migrationInfo := "migration done"
2837 deviceConfig := DeviceConfig{
2838 SerialNumber: "SDX6320031",
2839 UplinkPort: "16777472",
2840 HardwareIdentifier: "0.0.0.0",
2841 IPAddress: "127.26.1.74",
2842 NasID: "12345",
2843 NniDhcpTrapVid: 123,
2844 }
2845
2846 voltVnet := &VoltVnet{
2847 Version: "v3",
2848 VnetConfig: VnetConfig{
2849 Name: "2310-4096-4096",
2850 VnetType: "Encapsulation",
2851 SVlan: 2310,
2852 CVlan: 4096,
2853 UniVlan: 4096,
2854 SVlanTpid: 33024,
2855 },
vinokuma04dc9f82023-07-31 15:47:49 +05302856 VnetOper: VnetOper{
2857 PendingDeviceToDelete: "SDX6320031",
2858 DeleteInProgress: true,
2859 },
2860 }
2861
2862 cuncurrentMap := &util.ConcurrentMap{
2863 Count: atomic.NewUint64(0),
2864 }
2865
2866 vnetToDelete := map[string]bool{}
2867 vnetToDelete["2310-4096-4096"] = true
2868 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
2869 voltPortVnet := &VoltPortVnet{
2870 Device: "SDX6320031",
2871 Port: "16777472",
2872 DeleteInProgress: true,
2873 MacAddr: macAdd,
2874 }
2875
2876 macPortMap := map[string]string{}
2877 voltPortVnetsToDelete := map[*VoltPortVnet]bool{}
2878 voltPortVnetsToDelete[voltPortVnet] = true
Akash Sonib03636c2023-10-31 12:30:59 +05302879 macPortMap[macAdd.String()] = voltPortVnet.Port
vinokuma04dc9f82023-07-31 15:47:49 +05302880
2881 tests := []struct {
2882 name string
2883 args args
2884 }{
2885 {
2886 name: "Positive_Case_ReadAllFromDb",
2887 args: args{
2888 cntx: context.Background(),
2889 },
2890 },
2891 }
2892
2893 for _, tt := range tests {
2894 t.Run(tt.name, func(t *testing.T) {
2895 va := &VoltApplication{
2896 VnetsBySvlan: util.NewConcurrentMap(),
2897 VnetsToDelete: vnetToDelete,
2898 macPortMap: macPortMap,
2899 VoltPortVnetsToDelete: voltPortVnetsToDelete,
2900 VnetsByName: sync.Map{},
2901 }
2902
2903 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2904 db = dbintf
2905 dbintf.EXPECT().GetMeters(gomock.Any()).AnyTimes()
2906 vnet, _ := json.Marshal(voltVnet)
2907 voltVnets := map[string]*kvstore.KVPair{}
2908 voltVnets["2310-4096-4096"] = &kvstore.KVPair{
2909 Key: "2310-4096-4096",
2910 Value: vnet,
2911 }
2912
2913 va.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap)
2914 dbintf.EXPECT().GetVnets(gomock.Any()).AnyTimes().Return(voltVnets, nil).AnyTimes()
2915 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil).AnyTimes()
2916 vpvs, _ := json.Marshal(voltPortVnet)
2917 voltPort := map[string]*kvstore.KVPair{}
2918 voltPort["16777472"] = &kvstore.KVPair{
2919 Key: "16777472",
2920 Value: vpvs,
2921 }
2922 va.VnetsByName.Store("2310-4096-4096", voltVnet)
2923 dbintf.EXPECT().GetVpvs(gomock.Any()).AnyTimes().Return(voltPort, nil).AnyTimes()
2924 dbintf.EXPECT().GetServices(gomock.Any()).AnyTimes()
2925 dbintf.EXPECT().GetMvlans(gomock.Any()).AnyTimes()
2926 dbintf.EXPECT().GetIgmpProfiles(gomock.Any()).AnyTimes()
2927 dbintf.EXPECT().GetMcastConfigs(gomock.Any()).AnyTimes()
2928 dbintf.EXPECT().GetIgmpGroups(gomock.Any()).AnyTimes()
2929 dbintf.EXPECT().GetMigrationInfo(gomock.Any()).Return(migrationInfo, nil).AnyTimes()
2930 dbintf.EXPECT().GetOltFlowService(gomock.Any()).AnyTimes()
2931 b, _ := json.Marshal(deviceConfig)
2932 test := map[string]*kvstore.KVPair{}
2933 test["SDX6320031"] = &kvstore.KVPair{
2934 Key: "SDX6320031",
2935 Value: b,
2936 }
2937 dbintf.EXPECT().GetDeviceConfig(gomock.Any()).Return(test, nil).AnyTimes()
2938 dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2939 va.ReadAllFromDb(tt.args.cntx)
2940 })
2941 }
2942}
2943
2944func TestVoltApplication_RemoveGroupDevicesFromPendingPool(t *testing.T) {
2945 type args struct {
2946 ig *IgmpGroup
2947 }
2948 pendingGroupForDevice := map[string]time.Time{}
2949 pendingGroupForDevice[test_device] = time.Now()
2950 tests := []struct {
2951 name string
2952 args args
2953 }{
2954 {
2955 name: "VoltApplication_RemoveGroupDevicesFromPendingPool",
2956 args: args{
2957 ig: &IgmpGroup{
2958 Version: "test_version",
2959 PendingGroupForDevice: pendingGroupForDevice,
2960 },
2961 },
2962 },
2963 }
2964 for _, tt := range tests {
2965 t.Run(tt.name, func(t *testing.T) {
2966 va := &VoltApplication{}
2967 va.RemoveGroupDevicesFromPendingPool(tt.args.ig)
2968 })
2969 }
2970}
Akash Soni6f369452023-09-19 11:18:28 +05302971
2972func TestVoltDevice_AddPort(t *testing.T) {
2973 type args struct {
2974 port string
2975 id uint32
2976 }
2977
2978 voltPort := &VoltPort{
2979 Name: "16777472",
2980 ID: uint32(256),
2981 }
2982 tests := []struct {
2983 name string
2984 args args
2985 want *VoltPort
2986 }{
2987 {
2988 name: "VoltApplication_AddPort",
2989 args: args{
2990 port: "16777472",
2991 id: uint32(256),
2992 },
2993 want: voltPort,
2994 },
2995 }
2996 for _, tt := range tests {
2997 t.Run(tt.name, func(t *testing.T) {
2998 d := &VoltDevice{}
2999 if got := d.AddPort(tt.args.port, tt.args.id); !reflect.DeepEqual(got, tt.want) {
3000 t.Errorf("VoltDevice.AddPort() = %v, want %v", got, tt.want)
3001 }
3002 })
3003 }
3004}
3005
3006func TestVoltApplication_GetAvailIgmpGroupID(t *testing.T) {
3007 IgmpGroupIds := []*IgmpGroup{}
3008 group := &IgmpGroup{
3009 GroupName: "group1",
3010 GroupID: uint32(256),
3011 }
3012 IgmpGroupIds = append(IgmpGroupIds, group)
3013 tests := []struct {
3014 name string
3015 want *IgmpGroup
3016 }{
3017 {
3018 name: "VoltApplication_GetAvailIgmpGroupID",
3019 want: group,
3020 },
3021 {
3022 name: "VoltApplication_GetAvailIgmpGroupID_Nil",
3023 want: group,
3024 },
3025 }
3026 for _, tt := range tests {
3027 t.Run(tt.name, func(t *testing.T) {
3028 switch tt.name {
3029 case "VoltApplication_GetAvailIgmpGroupID":
3030 va := &VoltApplication{
3031 IgmpGroupIds: IgmpGroupIds,
3032 }
3033 got := va.GetAvailIgmpGroupID()
3034 assert.NotNil(t, got)
3035 case "VoltApplication_GetAvailIgmpGroupID_Nil":
3036 va := &VoltApplication{}
3037 got := va.GetAvailIgmpGroupID()
3038 assert.Nil(t, got)
3039 }
3040 })
3041 }
3042}
3043
3044func TestVoltApplication_GetIgmpGroupID(t *testing.T) {
3045 type args struct {
3046 gid uint32
3047 }
3048 IgmpGroupIds := []*IgmpGroup{}
3049 group := &IgmpGroup{
3050 GroupName: "group1",
3051 GroupID: uint32(256),
3052 }
3053 IgmpGroupIds = append(IgmpGroupIds, group)
3054 tests := []struct {
3055 name string
3056 args args
3057 want *IgmpGroup
3058 wantErr bool
3059 }{
3060 {
3061 name: "VoltApplication_GetIgmpGroupID",
3062 args: args{
3063 gid: uint32(256),
3064 },
3065 want: group,
3066 wantErr: false,
3067 },
3068 {
3069 name: "VoltApplication_GetIgmpGroupID_Error",
3070 args: args{
3071 gid: uint32(256),
3072 },
3073 want: group,
3074 wantErr: true,
3075 },
3076 }
3077 va := &VoltApplication{}
3078 for _, tt := range tests {
3079 t.Run(tt.name, func(t *testing.T) {
3080 switch tt.name {
3081 case "VoltApplication_GetIgmpGroupID":
3082 va = &VoltApplication{
3083 IgmpGroupIds: IgmpGroupIds,
3084 }
3085 got, err := va.GetIgmpGroupID(tt.args.gid)
3086 if (err != nil) != tt.wantErr {
3087 t.Errorf("VoltApplication.GetIgmpGroupID() error = %v, wantErr %v", err, tt.wantErr)
3088 return
3089 }
3090 if !reflect.DeepEqual(got, tt.want) {
3091 t.Errorf("VoltApplication.GetIgmpGroupID() = %v, want %v", got, tt.want)
3092 }
3093 case "VoltApplication_GetIgmpGroupID_Error":
3094 got, err := va.GetIgmpGroupID(tt.args.gid)
3095 if (err != nil) != tt.wantErr {
3096 t.Errorf("VoltApplication.GetIgmpGroupID() error = %v, wantErr %v", err, tt.wantErr)
3097 return
3098 }
3099 assert.Nil(t, got)
3100 }
3101 })
3102 }
3103}
3104
3105func TestVoltApplication_PutIgmpGroupID(t *testing.T) {
3106 type args struct {
3107 ig *IgmpGroup
3108 }
3109 group := &IgmpGroup{
3110 GroupName: "group1",
3111 GroupID: uint32(256),
3112 }
3113 tests := []struct {
3114 name string
3115 args args
3116 }{
3117 {
3118 name: "VoltApplication_GetIgmpGroupID",
3119 args: args{
3120 ig: group,
3121 },
3122 },
3123 }
3124 for _, tt := range tests {
3125 t.Run(tt.name, func(t *testing.T) {
3126 va := &VoltApplication{}
3127 va.PutIgmpGroupID(tt.args.ig)
3128 })
3129 }
3130}
3131
3132func TestVoltApplication_PortDelInd(t *testing.T) {
3133 type args struct {
3134 cntx context.Context
3135 device string
3136 port string
3137 }
3138 voltDev := &VoltDevice{
3139 Name: "49686e2d-618f-4e8e-bca0",
3140 SerialNum: "SDX6320031",
3141 NniDhcpTrapVid: 123,
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05303142 NniPort: []string{"16777216"},
Akash Soni6f369452023-09-19 11:18:28 +05303143 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
3144 Ports: sync.Map{},
3145 VpvsBySvlan: util.NewConcurrentMap(),
3146 }
3147
3148 voltPort := &VoltPort{
3149 Name: "16777472",
3150 Device: "SDX6320031",
3151 ID: 16777472,
3152 State: PortStateUp,
3153 ChannelPerSubAlarmRaised: false,
3154 }
3155 voltPortVnets := make([]*VoltPortVnet, 0)
3156 voltPortVnet := &VoltPortVnet{
3157 Device: "SDX6320031",
3158 Port: "16777472",
3159 DeleteInProgress: true,
3160 servicesCount: atomic.NewUint64(0),
3161 }
3162 voltPortVnets = append(voltPortVnets, voltPortVnet)
3163
3164 tests := []struct {
3165 name string
3166 args args
3167 }{
3168 {
3169 name: "VoltApplication_PortDelInd",
3170 args: args{
3171 cntx: context.Background(),
3172 device: "SDX6320031",
3173 port: "16777472",
3174 },
3175 },
3176 {
3177 name: "PortDelInd_Device_Not_Found",
3178 args: args{
3179 cntx: context.Background(),
3180 device: "SDX6320032",
3181 port: "16777472",
3182 },
3183 },
3184 {
3185 name: "PortDelInd_VnetsByPort_Nil",
3186 args: args{
3187 cntx: context.Background(),
3188 device: "SDX6320031",
3189 port: "16777472",
3190 },
3191 },
3192 }
3193 for _, tt := range tests {
3194 t.Run(tt.name, func(t *testing.T) {
3195 switch tt.name {
3196 case "VoltApplication_PortDelInd", "PortDelInd_Device_Not_Found":
3197 va := &VoltApplication{
3198 DevicesDisc: sync.Map{},
3199 PortsDisc: sync.Map{},
3200 }
3201 va.DevicesDisc.Store("SDX6320031", voltDev)
3202 va.PortsDisc.Store("16777472", voltPort)
3203 voltDev.Ports.Store("16777472", voltPort)
3204 va.VnetsByPort.Store("16777472", voltPortVnets)
3205 va.PortDelInd(tt.args.cntx, tt.args.device, tt.args.port)
3206 case "PortDelInd_VnetsByPort_Nil":
3207 va := &VoltApplication{
3208 DevicesDisc: sync.Map{},
3209 PortsDisc: sync.Map{},
3210 }
3211 va.DevicesDisc.Store("SDX6320031", voltDev)
3212 va.PortsDisc.Store("16777472", voltPort)
3213 voltDev.Ports.Store("16777472", voltPort)
3214 va.PortDelInd(tt.args.cntx, tt.args.device, tt.args.port)
3215 }
3216 })
3217 }
3218}
3219
3220func TestVoltApplication_GetGroupFromPendingPool(t *testing.T) {
3221 type args struct {
3222 mvlan of.VlanType
3223 device string
3224 }
3225 igmpPendingPool := map[string]map[*IgmpGroup]bool{}
3226 devices := map[string]*IgmpGroupDevice{}
3227 igmpGroup := map[*IgmpGroup]bool{}
3228 igmpDevice := &IgmpGroupDevice{
3229 Device: "SDX6320031",
3230 SerialNo: "SDX6320032",
3231 GroupName: "group1",
3232 Mvlan: of.VlanAny,
3233 }
3234 devices["SDX6320031"] = igmpDevice
3235 group := &IgmpGroup{
3236 GroupName: "group1",
3237 GroupID: uint32(256),
3238 Mvlan: of.VlanAny,
3239 Devices: devices,
3240 }
3241
3242 igmpGroup[group] = true
3243 igmpPendingPool["4096_SDX6320031"] = igmpGroup
3244 tests := []struct {
3245 name string
3246 args args
3247 want *IgmpGroup
3248 }{
3249 {
3250 name: "GetGroupFromPendingPool",
3251 args: args{
3252 device: "SDX6320031",
3253 mvlan: of.VlanAny,
3254 },
3255 want: nil,
3256 },
3257 }
3258 for _, tt := range tests {
3259 t.Run(tt.name, func(t *testing.T) {
3260 va := &VoltApplication{
3261 IgmpPendingPool: igmpPendingPool,
3262 }
3263 if got := va.GetGroupFromPendingPool(tt.args.mvlan, tt.args.device); !reflect.DeepEqual(got, tt.want) {
3264 t.Errorf("VoltApplication.GetGroupFromPendingPool() = %v, want %v", got, tt.want)
3265 }
3266 })
3267 }
3268}
3269
3270func TestVoltApplication_RemoveGroupsFromPendingPool(t *testing.T) {
3271 type args struct {
3272 cntx context.Context
3273 device string
3274 mvlan of.VlanType
3275 }
3276 tests := []struct {
3277 name string
3278 args args
3279 }{
3280 {
3281 name: "PortDelInd_RemoveGroupsFromPendingPool",
3282 args: args{
3283 cntx: context.Background(),
3284 device: "SDX6320031",
3285 mvlan: of.VlanAny,
3286 },
3287 },
3288 }
3289 for _, tt := range tests {
3290 t.Run(tt.name, func(t *testing.T) {
3291 va := &VoltApplication{
3292 IgmpPendingPool: make(map[string]map[*IgmpGroup]bool),
3293 }
3294 va.RemoveGroupsFromPendingPool(tt.args.cntx, tt.args.device, tt.args.mvlan)
3295 })
3296 }
3297}
3298
3299func TestVoltApplication_AddGroupToPendingPool(t *testing.T) {
3300 type fields struct{}
3301 type args struct {
3302 ig *IgmpGroup
3303 }
3304 devices := map[string]*IgmpGroupDevice{}
3305 igmpDevice := &IgmpGroupDevice{
3306 Device: "SDX6320031",
3307 SerialNo: "SDX6320032",
3308 GroupName: "group1",
3309 Mvlan: of.VlanAny,
3310 }
3311 devices["SDX6320031"] = igmpDevice
3312 group := &IgmpGroup{
3313 GroupName: "group1",
3314 GroupID: uint32(256),
3315 Devices: devices,
3316 }
3317 tests := []struct {
3318 name string
3319 fields fields
3320 args args
3321 }{
3322 {
3323 name: "AddGroupToPendingPool",
3324 args: args{
3325 ig: group,
3326 },
3327 },
3328 }
3329 for _, tt := range tests {
3330 t.Run(tt.name, func(t *testing.T) {
3331 va := &VoltApplication{
3332 IgmpPendingPool: make(map[string]map[*IgmpGroup]bool),
3333 }
3334 va.AddGroupToPendingPool(tt.args.ig)
3335 })
3336 }
3337}
3338
3339func TestVoltApplication_removeExpiredGroups(t *testing.T) {
3340 type args struct {
3341 cntx context.Context
3342 }
3343 group := &IgmpGroup{
3344 GroupName: "group1",
3345 GroupID: uint32(256),
3346 }
3347 tests := []struct {
3348 name string
3349 args args
3350 }{
3351 {
3352 name: "removeExpiredGroups",
3353 args: args{
3354 cntx: context.Background(),
3355 },
3356 },
3357 }
3358 for _, tt := range tests {
3359 t.Run(tt.name, func(t *testing.T) {
3360 va := &VoltApplication{
3361 IgmpGroups: sync.Map{},
3362 }
3363 va.IgmpGroups.Store("group1", group)
3364 va.removeExpiredGroups(tt.args.cntx)
3365 })
3366 }
3367}
3368
3369func TestVoltApplication_GetTaskList(t *testing.T) {
3370 type args struct {
3371 device string
3372 }
3373 appMock := mocks.NewMockApp(gomock.NewController(t))
3374 controller.NewController(ctx, appMock)
3375 device := &controller.Device{
3376 ID: "SDX6320031",
3377 }
3378 dev := map[string]*controller.Device{}
3379 dev["SDX6320031"] = device
3380 tests := []struct {
3381 name string
3382 args args
3383 want map[int]*TaskInfo
3384 }{
3385 {
3386 name: "GetTaskList",
3387 args: args{
3388 device: "SDX6320031",
3389 },
3390 want: map[int]*TaskInfo{},
3391 },
3392 }
3393 for _, tt := range tests {
3394 t.Run(tt.name, func(t *testing.T) {
3395 va := &VoltApplication{}
3396 if got := va.GetTaskList(tt.args.device); !reflect.DeepEqual(got, tt.want) {
3397 t.Errorf("VoltApplication.GetTaskList() = %v, want %v", got, tt.want)
3398 }
3399 })
3400 }
3401}
3402
3403func TestVoltApplication_UpdateMvlanProfilesForDevice(t *testing.T) {
3404 type args struct {
3405 cntx context.Context
3406 device string
3407 }
3408 devicesList := make(map[string]OperInProgress)
3409 devicesList["SDX6320031"] = UpdateInProgress
3410 mvp := &MvlanProfile{
3411 Name: "mvlan_test",
3412 DevicesList: devicesList,
3413 }
3414 voltDev := &VoltDevice{
3415 SerialNum: "SDX6320031",
3416 }
3417 tests := []struct {
3418 name string
3419 args args
3420 }{
3421 {
3422 name: "UpdateMvlanProfilesForDevice",
3423 args: args{
3424 cntx: context.Background(),
3425 device: "SDX6320031",
3426 },
3427 },
3428 }
3429 for _, tt := range tests {
3430 t.Run(tt.name, func(t *testing.T) {
3431 va := &VoltApplication{
3432 DevicesDisc: sync.Map{},
3433 MvlanProfilesByName: sync.Map{},
3434 }
3435 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
3436 db = dbintf
3437 dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
3438 va.DevicesDisc.Store("SDX6320031", voltDev)
3439 va.MvlanProfilesByName.Store("mvlan_test", mvp)
3440 va.UpdateMvlanProfilesForDevice(tt.args.cntx, tt.args.device)
3441 })
3442 }
3443}
3444
3445func TestVoltApplication_HandleFlowClearFlag(t *testing.T) {
3446 type args struct {
3447 cntx context.Context
3448 deviceID string
3449 serialNum string
3450 southBoundID string
3451 }
3452 mblan := map[uint16]bool{}
3453 mblan[uint16(256)] = true
3454 voltDev := &VoltDevice{
3455 SerialNum: "SDX6320031",
3456 MigratingServices: util.NewConcurrentMap(),
3457 IgmpDsFlowAppliedForMvlan: mblan,
3458 }
3459 voltPortVnets := make([]*VoltPortVnet, 0)
3460 voltPortVnet := &VoltPortVnet{
3461 Device: "SDX6320031",
3462 Port: "16777472",
3463 DeleteInProgress: true,
3464 servicesCount: atomic.NewUint64(0),
3465 IgmpEnabled: true,
3466 }
3467 voltPortVnets = append(voltPortVnets, voltPortVnet)
3468 tests := []struct {
3469 name string
3470 args args
3471 }{
3472 {
3473 name: "HandleFlowClearFlag",
3474 args: args{
3475 cntx: context.Background(),
3476 deviceID: "SDX6320031",
3477 serialNum: "SDX6320031",
3478 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
3479 },
3480 },
3481 }
3482 for _, tt := range tests {
3483 t.Run(tt.name, func(t *testing.T) {
3484 va := &VoltApplication{
3485 DevicesDisc: sync.Map{},
3486 VnetsByPort: sync.Map{},
3487 }
3488 GetApplication().DevicesDisc.Store("SDX6320031", voltDev)
3489 va.DevicesDisc.Store("SDX6320031", voltDev)
3490 va.VnetsByPort.Store("16777472", voltPortVnets)
3491 va.HandleFlowClearFlag(tt.args.cntx, tt.args.deviceID, tt.args.serialNum, tt.args.southBoundID)
3492 })
3493 }
3494}
3495
3496func TestVoltApplication_PacketInInd(t *testing.T) {
3497 type args struct {
3498 cntx context.Context
3499 device string
3500 port string
3501 pkt []byte
3502 }
3503 tests := []struct {
3504 name string
3505 args args
3506 }{
3507 {
3508 name: "PacketInInd",
3509 args: args{
3510 cntx: context.Background(),
3511 },
3512 },
3513 }
3514 for _, tt := range tests {
3515 t.Run(tt.name, func(t *testing.T) {
3516 va := &VoltApplication{}
3517 va.PacketInInd(tt.args.cntx, tt.args.device, tt.args.port, tt.args.pkt)
3518 })
3519 }
3520}
3521
3522func TestReceiverUpInd(t *testing.T) {
3523 type args struct {
3524 key interface{}
3525 value interface{}
3526 }
3527 voltServ := &VoltService{
3528 VoltServiceOper: VoltServiceOper{
3529 Device: "SCOM00001c75",
3530 Ipv4Addr: AllSystemsMulticastGroupIP,
3531 Ipv6Addr: AllSystemsMulticastGroupIP,
3532 },
3533 VoltServiceCfg: VoltServiceCfg{
3534 IgmpEnabled: true,
3535 VlanControl: ONUCVlan,
3536 Port: "16777472",
3537 },
3538 }
3539 voltDev := &VoltDevice{
3540 Name: "SCOM00001c75",
3541 SerialNum: "SCOM00001c75",
3542 Ports: sync.Map{},
3543 }
3544 voltPort := &VoltPort{
3545 Name: "16777472",
3546 Device: "SCOM00001c75",
3547 ID: 16777216,
3548 State: PortStateDown,
3549 ChannelPerSubAlarmRaised: false,
3550 Type: VoltPortTypeNni,
3551 }
3552
3553 tests := []struct {
3554 name string
3555 args args
3556 want bool
3557 }{
3558 {
3559 name: "ReceiverUpInd",
3560 args: args{
3561 key: "SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65",
3562 value: voltServ,
3563 },
3564 },
3565 {
3566 name: "ReceiverUpInd_VlanControl",
3567 args: args{
3568 key: "SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65",
3569 value: voltServ,
3570 },
3571 },
3572 }
3573 for _, tt := range tests {
3574 t.Run(tt.name, func(t *testing.T) {
3575 switch tt.name {
3576 case "ReceiverUpInd":
3577 GetApplication().ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
3578 GetApplication().DevicesDisc.Store("SCOM00001c75", voltDev)
3579 GetApplication().PortsDisc.Store("16777472", voltPort)
3580 voltDev.Ports.Store("16777472", voltPort)
3581 if got := ReceiverUpInd(tt.args.key, tt.args.value); got != tt.want {
3582 t.Errorf("ReceiverUpInd() = %v, want %v", got, tt.want)
3583 }
3584 case "ReceiverUpInd_VlanControl":
3585 voltServ.VlanControl = OLTSVlan
3586 GetApplication().ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
3587 if got := ReceiverUpInd(tt.args.key, tt.args.value); got != tt.want {
3588 t.Errorf("ReceiverUpInd() = %v, want %v", got, tt.want)
3589 }
3590 }
3591 })
3592 }
3593}
3594
3595func TestVoltApplication_NniVlanIndToIgmp(t *testing.T) {
3596 type args struct {
3597 cntx context.Context
3598 device *VoltDevice
3599 mvp *MvlanProfile
3600 addFlow bool
3601 }
3602 mblan := map[uint16]bool{}
3603 mblan[uint16(256)] = true
3604 voltDev := &VoltDevice{
3605 Name: "SDX6320031",
3606 SerialNum: "SDX6320031",
3607 IgmpDsFlowAppliedForMvlan: mblan,
3608 Ports: sync.Map{},
Sridhar Ravindrab76eb162025-07-02 01:25:10 +05303609 NniPort: []string{"16777216"},
Akash Soni6f369452023-09-19 11:18:28 +05303610 }
3611 devicesList := make(map[string]OperInProgress)
3612 devicesList["SDX6320030"] = opt82
3613 mvp := &MvlanProfile{
3614 Name: "mvlan_test",
3615 DevicesList: devicesList,
3616 }
3617 voltPort := &VoltPort{
3618 Name: "16777472",
3619 Device: "SDX6320031",
3620 ID: 16777216,
3621 State: PortStateUp,
3622 }
3623 voltPortVnets := make([]*VoltPortVnet, 0)
3624 voltPortVnet := &VoltPortVnet{
3625 Device: "SDX6320031",
3626 Port: "16777472",
3627 IgmpEnabled: true,
3628 MvlanProfileName: "mvlan_test",
3629 services: sync.Map{},
3630 }
3631 voltPortVnets = append(voltPortVnets, voltPortVnet)
3632 tests := []struct {
3633 name string
3634 args args
3635 }{
3636 {
3637 name: "NniVlanIndToIgmp",
3638 args: args{
3639 device: voltDev,
3640 mvp: mvp,
3641 },
3642 },
3643 {
3644 name: "ProcessIgmpDSFlowForMvlan_pushIgmpMcastFlows",
3645 args: args{
3646 cntx: context.Background(),
3647 device: voltDev,
3648 mvp: mvp,
3649 addFlow: true,
3650 },
3651 },
3652 {
3653 name: "ProcessIgmpDSFlowForMvlan_removeIgmpMcastFlows",
3654 args: args{
3655 cntx: context.Background(),
3656 device: voltDev,
3657 mvp: mvp,
3658 addFlow: false,
3659 },
3660 },
3661 }
3662 for _, tt := range tests {
3663 t.Run(tt.name, func(t *testing.T) {
3664 va := &VoltApplication{}
3665 switch tt.name {
3666 case "NniVlanIndToIgmp":
3667 voltDev.Ports.Store("16777472", voltPort)
3668 va.PortsDisc.Store("16777472", voltPort)
3669 va.VnetsByPort.Store("16777472", voltPortVnets)
3670 va.NniVlanIndToIgmp(tt.args.device, tt.args.mvp)
3671 case "ProcessIgmpDSFlowForMvlan_pushIgmpMcastFlows", "ProcessIgmpDSFlowForMvlan_removeIgmpMcastFlows":
3672 voltDev.Ports.Store("16777472", voltPort)
3673 va.ProcessIgmpDSFlowForMvlan(tt.args.cntx, tt.args.device, tt.args.mvp, tt.args.addFlow)
3674 }
3675 })
3676 }
3677}
3678
3679func TestVoltApplication_DeviceDisableInd(t *testing.T) {
3680 type args struct {
3681 cntx context.Context
3682 device string
3683 }
3684 voltDev := &VoltDevice{
3685 Name: "SDX6320031",
3686 SerialNum: "SDX6320031",
3687 Ports: sync.Map{},
3688 State: controller.DeviceStateDOWN,
3689 MigratingServices: util.NewConcurrentMap(),
3690 }
3691 tests := []struct {
3692 name string
3693 args args
3694 }{
3695 {
3696 name: "DeviceDisableInd",
3697 args: args{
3698 device: "SDX6320031",
3699 },
3700 },
3701 {
3702 name: "DeviceDisableInd_DEvice_Not_Found",
3703 args: args{
3704 device: "SDX6320032",
3705 },
3706 },
3707 }
3708 for _, tt := range tests {
3709 t.Run(tt.name, func(t *testing.T) {
3710 va := &VoltApplication{}
3711 va.DevicesDisc.Store("SDX6320031", voltDev)
3712 GetApplication().DevicesDisc.Store("SDX6320031", voltDev)
3713 va.DeviceDisableInd(tt.args.cntx, tt.args.device)
3714 })
3715 }
3716}
3717
3718func TestVoltApplication_ProcessIgmpDSFlowForDevice(t *testing.T) {
3719 type args struct {
3720 cntx context.Context
3721 d *VoltDevice
3722 addFlow bool
3723 }
3724 voltDev := &VoltDevice{
3725 Name: "SDX6320031",
3726 SerialNum: "SDX6320031",
3727 MigratingServices: util.NewConcurrentMap(),
3728 }
3729 devicesList := make(map[string]OperInProgress)
3730 devicesList["SDX6320030"] = opt82
3731 mvp := &MvlanProfile{
3732 Name: "mvlan_test",
3733 DevicesList: devicesList,
3734 }
3735 tests := []struct {
3736 name string
3737 args args
3738 }{
3739 {
3740 name: "DeviceDisableInd_DEvice_Not_Found",
3741 args: args{
3742 cntx: context.Background(),
3743 d: voltDev,
3744 addFlow: true,
3745 },
3746 },
3747 }
3748 for _, tt := range tests {
3749 t.Run(tt.name, func(t *testing.T) {
3750 va := &VoltApplication{}
3751 va.MvlanProfilesByName.Store("mvlan_test", mvp)
3752 va.ProcessIgmpDSFlowForDevice(tt.args.cntx, tt.args.d, tt.args.addFlow)
3753 })
3754 }
3755}
3756
3757func TestVoltApplication_GetPonFromUniPort(t *testing.T) {
3758 type args struct {
3759 port string
3760 }
3761 voltPort := &VoltPort{
3762 Name: "16777472",
3763 Device: "SDX6320031",
3764 ID: 16777216,
3765 State: PortStateUp,
3766 }
3767
3768 tests := []struct {
3769 name string
3770 args args
3771 want string
3772 wantErr bool
3773 }{
3774 {
3775 name: "GetPonFromUniPort_PositiveSenario",
3776 args: args{
3777 port: "16777472",
3778 },
3779 want: "16",
3780 wantErr: false,
3781 },
3782 {
3783 name: "GetPonFromUniPort_NegetiveSenario",
3784 args: args{
3785 port: "16777472",
3786 },
3787 wantErr: true,
3788 },
3789 }
3790 for _, tt := range tests {
3791 t.Run(tt.name, func(t *testing.T) {
3792 va := &VoltApplication{}
3793 switch tt.name {
3794 case "GetPonFromUniPort_PositiveSenario":
3795 va.PortsDisc.Store("16777472", voltPort)
3796 got, err := va.GetPonFromUniPort(tt.args.port)
3797 if (err != nil) != tt.wantErr {
3798 t.Errorf("VoltApplication.GetPonFromUniPort() error = %v, wantErr %v", err, tt.wantErr)
3799 return
3800 }
3801 if got != tt.want {
3802 t.Errorf("VoltApplication.GetPonFromUniPort() = %v, want %v", got, tt.want)
3803 }
3804 case "GetPonFromUniPort_NegetiveSenario":
3805 got, err := va.GetPonFromUniPort(tt.args.port)
3806 if (err != nil) != tt.wantErr {
3807 t.Errorf("VoltApplication.GetPonFromUniPort() error = %v, wantErr %v", err, tt.wantErr)
3808 return
3809 }
3810 if got != tt.want {
3811 t.Errorf("VoltApplication.GetPonFromUniPort() = %v, want %v", got, tt.want)
3812 }
3813 }
3814 })
3815 }
3816}
3817
3818func TestVoltApplication_AddIcmpv6Receivers(t *testing.T) {
3819 type args struct {
3820 device string
3821 portID uint32
3822 }
3823 var receiverList []uint32
3824 port := uint32(256)
3825 receiverList = append(receiverList, port)
3826 tests := []struct {
3827 name string
3828 args args
3829 want []uint32
3830 }{
3831 {
3832 name: "AddIcmpv6Receivers",
3833 args: args{
3834 device: "SDX6320031",
3835 portID: port,
3836 },
3837 want: []uint32{port, port},
3838 },
3839 {
3840 name: "DelIcmpv6Receivers",
3841 args: args{
3842 device: "SDX6320031",
3843 portID: port,
3844 },
3845 want: []uint32{},
3846 },
3847 }
3848 for _, tt := range tests {
3849 t.Run(tt.name, func(t *testing.T) {
3850 va := &VoltApplication{}
3851 switch tt.name {
3852 case "AddIcmpv6Receivers":
3853 va.Icmpv6Receivers.Store("SDX6320031", receiverList)
3854 if got := va.AddIcmpv6Receivers(tt.args.device, tt.args.portID); !reflect.DeepEqual(got, tt.want) {
3855 t.Errorf("VoltApplication.AddIcmpv6Receivers() = %v, want %v", got, tt.want)
3856 }
3857 case "DelIcmpv6Receivers":
3858 va.Icmpv6Receivers.Store("SDX6320031", receiverList)
3859 if got := va.DelIcmpv6Receivers(tt.args.device, tt.args.portID); !reflect.DeepEqual(got, tt.want) {
3860 t.Errorf("VoltApplication.DelIcmpv6Receivers() = %v, want %v", got, tt.want)
3861 }
3862 }
3863 })
3864 }
3865}
3866
3867func TestVoltApplication_ProcessDevFlowForDevice(t *testing.T) {
3868 type args struct {
3869 cntx context.Context
3870 device *VoltDevice
3871 vnet *VoltVnet
3872 enabled bool
3873 }
3874 voltDev := &VoltDevice{
3875 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
3876 SerialNum: "SDX6320031",
3877 NniDhcpTrapVid: 123,
3878 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
3879 }
3880 voltVnet := &VoltVnet{
3881 Version: "v3",
3882 VnetConfig: VnetConfig{
3883 Name: "2310-4096-4096",
3884 VnetType: "Encapsulation",
3885 SVlan: 2310,
3886 CVlan: 4096,
3887 UniVlan: 4096,
3888 SVlanTpid: 33024,
3889 },
3890 VnetOper: VnetOper{
3891 PendingDeviceToDelete: "SDX6320031",
3892 DeleteInProgress: true,
3893 },
3894 }
3895 tests := []struct {
3896 name string
3897 args args
3898 }{
3899 {
3900 name: "ProcessDevFlowForDevice_PushDevFlowForVlan",
3901 args: args{
3902 cntx: context.Background(),
3903 device: voltDev,
3904 vnet: voltVnet,
3905 enabled: true,
3906 },
3907 },
3908 }
3909 for _, tt := range tests {
3910 t.Run(tt.name, func(t *testing.T) {
3911 va := &VoltApplication{}
3912 va.DevicesDisc.Store("SDX6320031", voltDev)
3913 va.VnetsByName.Store("2310-4096-4096", voltVnet)
3914 va.ProcessDevFlowForDevice(tt.args.cntx, tt.args.device, tt.args.vnet, tt.args.enabled)
3915 })
3916 }
3917}