blob: 3bb9c72b96d40efd86a8ef7bc1e1d1a6c4baab62 [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
335 servicesToDel := map[string]bool{}
336 servicesToDel["SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65"] = true
337
338 tests := []struct {
339 name string
340 args args
341 }{
342 {
343 name: "Positive_Case_TriggerPendingServiceDeleteReq",
344 args: args{
345 cntx: context.Background(),
346 device: "SDX6320031",
347 },
348 },
349 }
350 for _, tt := range tests {
351 t.Run(tt.name, func(t *testing.T) {
352 va := &VoltApplication{
353 ServicesToDelete: servicesToDel,
354 ServiceByName: sync.Map{},
355 DevicesDisc: sync.Map{},
356 }
357
358 va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
359
360 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
361 db = dbintf
362 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
363 dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes()
364 va.TriggerPendingServiceDeleteReq(tt.args.cntx, tt.args.device)
365 })
366 }
367}
368
369func TestVoltApplication_TriggerPendingVnetDeleteReq(t *testing.T) {
370 type args struct {
371 cntx context.Context
372 device string
373 }
374
375 vnetToDel := map[string]bool{}
376 vnetToDel["2310-4096-4096"] = true
377
378 voltVnet := &VoltVnet{
379 Version: "v3",
380 VnetConfig: VnetConfig{
381 Name: "2310-4096-4096",
382 VnetType: "Encapsulation",
383 SVlan: 2310,
384 CVlan: 4096,
385 UniVlan: 4096,
386 SVlanTpid: 33024,
387 },
388 VnetOper: VnetOper{
389 PendingDeviceToDelete: "SDX63200313",
390 },
391 }
392 voltDev := &VoltDevice{
393 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
394 SerialNum: "SDX6320031",
395 NniDhcpTrapVid: 123,
396 }
397
398 tests := []struct {
399 name string
400 args args
401 }{
402 {
403 name: "Negative_Case_TriggerPendingVnetDeleteReq",
404 args: args{
405 cntx: context.Background(),
406 device: "SDX6320031",
407 },
408 },
409 }
410 for _, tt := range tests {
411 t.Run(tt.name, func(t *testing.T) {
412 va := &VoltApplication{
413 VnetsToDelete: vnetToDel,
414 DevicesDisc: sync.Map{},
415 }
416 va.DevicesDisc.Store("SDX6320031", voltDev)
417 va.VnetsByName.Store("2310-4096-4096", voltVnet)
418 va.TriggerPendingVnetDeleteReq(tt.args.cntx, tt.args.device)
419 })
420 }
421}
422
423func TestVoltApplication_UpdateMacInPortMap(t *testing.T) {
424 type args struct {
425 macAddr net.HardwareAddr
426 port string
427 }
428 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
429 macPort := map[string]string{}
vinokuma02fbfd02023-07-05 15:23:33 +0530430 macPort[macAdd.String()] = test_data
vinokumaf7605fc2023-06-02 18:08:01 +0530431 tests := []struct {
432 name string
433 args args
434 }{
435 {
436 name: "Positive_Case_UpdateMacInPortMap",
437 args: args{
438 macAddr: macAdd,
vinokuma02fbfd02023-07-05 15:23:33 +0530439 port: test_data,
vinokumaf7605fc2023-06-02 18:08:01 +0530440 },
441 },
442 }
443 for _, tt := range tests {
444 t.Run(tt.name, func(t *testing.T) {
445 va := &VoltApplication{
446 macPortMap: macPort,
447 }
448 va.UpdateMacInPortMap(tt.args.macAddr, tt.args.port)
449 })
450 }
451}
452
453func TestVoltApplication_GetMacInPortMap(t *testing.T) {
454 type args struct {
455 macAddr net.HardwareAddr
456 }
457 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
458 macPort := map[string]string{}
vinokuma02fbfd02023-07-05 15:23:33 +0530459 macPort[macAdd.String()] = test_data
vinokumaf7605fc2023-06-02 18:08:01 +0530460 tests := []struct {
461 name string
462 args args
463 want string
464 }{
465 {
466 name: "Positive_Case_GetMacInPortMap",
467 args: args{
468 macAddr: macAdd,
469 },
vinokuma02fbfd02023-07-05 15:23:33 +0530470 want: test_data,
vinokumaf7605fc2023-06-02 18:08:01 +0530471 },
472 }
473 for _, tt := range tests {
474 t.Run(tt.name, func(t *testing.T) {
475 va := &VoltApplication{
476 macPortMap: macPort,
477 }
478 if got := va.GetMacInPortMap(tt.args.macAddr); got != tt.want {
479 t.Errorf("VoltApplication.GetMacInPortMap() = %v, want %v", got, tt.want)
480 }
481 })
482 }
483}
484
485func Test_pushFlowFailureNotif(t *testing.T) {
486 type args struct {
487 flowStatus intf.FlowStatus
488 }
489 tests := []struct {
490 name string
491 args args
492 }{
493 {
494 name: "Positive_Case_pushFlowFailureNotif",
495 args: args{
496 flowStatus: intf.FlowStatus{
497 Device: "SDX6320031",
498 Cookie: "68786618880",
499 Status: 0,
500 Flow: &of.VoltSubFlow{
501 Cookie: 68786618880,
502 TableID: 0,
503 Priority: 100,
504 ErrorReason: "",
505 OldCookie: 0,
506 },
507 },
508 },
509 },
510 }
511 for _, tt := range tests {
512 t.Run(tt.name, func(t *testing.T) {
513 pushFlowFailureNotif(tt.args.flowStatus)
514 })
515 }
516}
517
518func TestGetPonPortIDFromUNIPort(t *testing.T) {
519 type args struct {
520 uniPortID uint32
521 }
522 tests := []struct {
523 name string
524 args args
525 want uint32
526 }{
527 {
528 name: "Positive_Case_pushFlowFailureNotif",
529 args: args{
530 uniPortID: 1049600,
531 },
532 want: 1,
533 },
534 }
535 for _, tt := range tests {
536 t.Run(tt.name, func(t *testing.T) {
537 if got := GetPonPortIDFromUNIPort(tt.args.uniPortID); got != tt.want {
538 t.Errorf("GetPonPortIDFromUNIPort() = %v, want %v", got, tt.want)
539 }
540 })
541 }
542}
543
544func TestVoltApplication_ProcessFlowModResultIndication(t *testing.T) {
545 type args struct {
546 cntx context.Context
547 flowStatus intf.FlowStatus
548 }
549 voltDev := &VoltDevice{
550 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
551 SerialNum: "SDX6320031",
552 NniDhcpTrapVid: 123,
553 FlowAddEventMap: util.NewConcurrentMap(),
554 }
555 flowState := intf.FlowStatus{
556 Device: "SDX6320031",
557 Cookie: "68786618880",
558 Status: 1005,
559 FlowModType: 0,
560 Flow: &of.VoltSubFlow{
561 Cookie: 68786618880,
562 OldCookie: 0,
563 TableID: 0,
564 State: 0,
565 Priority: 100,
566 },
567 }
568 flowAddEvent := map[string]*FlowEvent{}
569 flowEvent := &FlowEvent{
570 device: "SDX6320031",
571 cookie: "68786618880",
572 eType: EventTypeControlFlowAdded,
573 }
574 flowAddEvent["68786618880"] = flowEvent
575 voltDev.FlowAddEventMap.Set("6878661888", flowEvent)
576 tests := []struct {
577 name string
578 args args
579 }{
580 {
581 name: "Positive_Case_ProcessFlowModResultIndication",
582 args: args{
583 cntx: context.Background(),
584 flowStatus: flowState,
585 },
586 },
587 {
588 name: "Negetive_Case_ProcessFlowModResultIndication",
589 args: args{
590 cntx: context.Background(),
591 flowStatus: flowState,
592 },
593 },
594 }
595 for _, tt := range tests {
596 t.Run(tt.name, func(t *testing.T) {
597 va := &VoltApplication{
598 DevicesDisc: sync.Map{},
599 }
600 switch tt.name {
601 case "Positive_Case_ProcessFlowModResultIndication":
602 va.DevicesDisc.Store("SDX6320031", voltDev)
603 va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus)
604 case "Negetive_Case_ProcessFlowModResultIndication":
605 va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus)
606 }
607 })
608 }
609}
610func Test_getPendingPoolKey(t *testing.T) {
611 type args struct {
612 mvlan of.VlanType
613 device string
614 }
615
616 tests := []struct {
617 name string
618 args args
619 want string
620 }{
621 {
622 name: "Positive_Case_getPendingPoolKey",
623 args: args{
624 mvlan: of.VlanAny,
625 device: "SDX6320031",
626 },
627 want: "4096_SDX6320031",
628 },
629 }
630 for _, tt := range tests {
631 t.Run(tt.name, func(t *testing.T) {
632 if got := getPendingPoolKey(tt.args.mvlan, tt.args.device); got != tt.want {
633 t.Errorf("getPendingPoolKey() = %v, want %v", got, tt.want)
634 }
635 })
636 }
637}
638
639func TestNewVoltPort(t *testing.T) {
640 type args struct {
641 device string
642 name string
643 id uint32
644 }
645
646 voltPort := &VoltPort{
647 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
648 Device: "SDX6320031",
649 ID: 16777472,
650 State: PortStateDown,
651 ChannelPerSubAlarmRaised: false,
652 Type: VoltPortTypeNni,
653 }
654
655 voltPort1 := &VoltPort{
656 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
657 Device: "SDX6320031",
658 ID: 1049600,
659 State: PortStateDown,
660 ChannelPerSubAlarmRaised: false,
661 PonPort: GetPonPortIDFromUNIPort(1049600),
662 }
663 tests := []struct {
664 name string
665 args args
666 want *VoltPort
667 }{
668 {
669 name: "Positive_Case_TestNewVoltPort",
670 args: args{
671 id: 16777472,
672 device: "SDX6320031",
673 name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
674 },
675 want: voltPort,
676 },
677 {
678 name: "Positive_Case2_TestNewVoltPort",
679 args: args{
680 id: 1049600,
681 device: "SDX6320031",
682 name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
683 },
684 want: voltPort1,
685 },
686 }
687 for _, tt := range tests {
688 t.Run(tt.name, func(t *testing.T) {
689 switch tt.name {
690 case "Positive_Case_TestNewVoltPort":
691 if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) {
692 t.Errorf("NewVoltPort() = %v, want %v", got, tt.want)
693 }
694 case "Positive_Case2_TestNewVoltPort":
695 if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) {
696 t.Errorf("NewVoltPort() = %v, want %v", got, tt.want)
697 }
698 }
699 })
700 }
701}
702
703func TestVoltPort_SetPortID(t *testing.T) {
704 type args struct {
705 id uint32
706 }
707 tests := []struct {
708 name string
709 args args
710 }{
711 {
712 name: "Positive_Case_TestNewVoltPort",
713 args: args{
714 id: 16777472,
715 },
716 },
717 }
718 for _, tt := range tests {
719 t.Run(tt.name, func(t *testing.T) {
720 vp := &VoltPort{
721 ID: 16777472,
722 Type: VoltPortTypeNni,
723 }
724 vp.SetPortID(tt.args.id)
725 })
726 }
727}
728
729func TestNewVoltDevice(t *testing.T) {
730 type args struct {
731 name string
732 slno string
733 southBoundID string
734 }
735
736 devConfig := &DeviceConfig{
737 SerialNumber: "SDX6320033",
738 NniDhcpTrapVid: 4,
739 }
740 voltDevice := &VoltDevice{
741 Name: "11c3175b-50f3-4220-9555-93df733ded1d",
742 SerialNum: "SDX6320033",
743 SouthBoundID: "68580342-6b3e-57cb-9ea4-06125594e330",
744 State: controller.DeviceStateDOWN,
745 NniPort: "",
746 icmpv6GroupAdded: false,
747 IgmpDsFlowAppliedForMvlan: make(map[uint16]bool),
748 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
749 MigratingServices: util.NewConcurrentMap(),
750 VpvsBySvlan: util.NewConcurrentMap(),
751 FlowAddEventMap: util.NewConcurrentMap(),
752 FlowDelEventMap: util.NewConcurrentMap(),
753 GlobalDhcpFlowAdded: false,
754 NniDhcpTrapVid: 4,
755 }
756
757 GetApplication().DevicesConfig.Store("SDX6320033", devConfig)
758 tests := []struct {
759 name string
760 args args
761 want *VoltDevice
762 }{
763 {
764 name: "Positive_Case_TestNewVoltDevice",
765 args: args{
766 name: "11c3175b-50f3-4220-9555-93df733ded1d",
767 slno: "SDX6320033",
768 southBoundID: "68580342-6b3e-57cb-9ea4-06125594e330",
769 },
770 want: voltDevice,
771 },
772 }
773 for _, tt := range tests {
774 t.Run(tt.name, func(t *testing.T) {
775 if got := NewVoltDevice(tt.args.name, tt.args.slno, tt.args.southBoundID); !reflect.DeepEqual(got, tt.want) {
776 t.Errorf("NewVoltDevice() = %v, want %v", got, tt.want)
777 }
778 })
779 }
780}
781
782func TestVoltApplication_GetAssociatedVpvsForDevice(t *testing.T) {
783 type args struct {
784 device string
785 svlan of.VlanType
786 }
787
788 voltDev := &VoltDevice{
789 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
790 SerialNum: "SDX6320033",
791 NniDhcpTrapVid: 123,
792 VpvsBySvlan: util.NewConcurrentMap(),
793 }
794
795 cuncurrentMap := &util.ConcurrentMap{
796 Count: atomic.NewUint64(0),
797 }
798
799 voltDev1 := &VoltDevice{
800 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
801 SerialNum: "SDX6320033",
802 NniDhcpTrapVid: 123,
803 VpvsBySvlan: cuncurrentMap,
804 }
805 tests := []struct {
806 name string
807 args args
808 want *util.ConcurrentMap
809 }{
810 {
811 name: "Positive_Case_GetAssociatedVpvsForDevice",
812 args: args{
813 device: "SDX6320033",
814 svlan: of.VlanAny,
815 },
816 want: util.NewConcurrentMap(),
817 },
818 {
819 name: "Positive_Case2_GetAssociatedVpvsForDevice",
820 args: args{
821 device: "SDX6320033",
822 svlan: of.VlanAny,
823 },
824 want: cuncurrentMap,
825 },
826 {
827 name: "Negetive_Case2_GetAssociatedVpvsForDevice",
828 args: args{
829 device: "SDX6320031",
830 svlan: of.VlanAny,
831 },
832 want: nil,
833 },
834 }
835 for _, tt := range tests {
836 t.Run(tt.name, func(t *testing.T) {
837 switch tt.name {
838 case "Positive_Case_GetAssociatedVpvsForDevice":
839 va := &VoltApplication{
840 DevicesDisc: sync.Map{},
841 VnetsBySvlan: util.NewConcurrentMap(),
842 }
843 va.DevicesDisc.Store("SDX6320033", voltDev)
844 if got := va.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
845 t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
846 }
847 case "Positive_Case2_GetAssociatedVpvsForDevice":
848 va1 := &VoltApplication{
849 DevicesDisc: sync.Map{},
850 VnetsBySvlan: cuncurrentMap,
851 }
852 va1.DevicesDisc.Store("SDX6320033", voltDev1)
853 va1.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap)
854 if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
855 t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
856 }
857 case "Negetive_Case2_GetAssociatedVpvsForDevice":
858 va1 := &VoltApplication{
859 DevicesDisc: sync.Map{},
860 }
861 if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
862 t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
863 }
864 }
865 })
866 }
867}
868
869func TestVoltApplication_AssociateVpvsToDevice(t *testing.T) {
870 type args struct {
871 device string
872 vpv *VoltPortVnet
873 }
874
875 vpv := &VoltPortVnet{
876 Device: "SDX6320033",
877 SVlan: of.VlanAny,
878 }
879 voltDev := &VoltDevice{
880 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
881 SerialNum: "SDX6320033",
882 NniDhcpTrapVid: 123,
883 VpvsBySvlan: util.NewConcurrentMap(),
884 }
885 tests := []struct {
886 name string
887 args args
888 }{
889 {
890 name: "Positive_Case_AssociateVpvsToDevice",
891 args: args{
892 device: "SDX6320033",
893 vpv: vpv,
894 },
895 },
896 {
897 name: "Negetive_Case_AssociateVpvsToDevice",
898 args: args{
899 device: "SDX6320033",
900 vpv: vpv,
901 },
902 },
903 }
904 for _, tt := range tests {
905 t.Run(tt.name, func(t *testing.T) {
906 switch tt.name {
907 case "Positive_Case_AssociateVpvsToDevice":
908 va := &VoltApplication{
909 DevicesDisc: sync.Map{},
910 VnetsBySvlan: util.NewConcurrentMap(),
911 }
912 va.DevicesDisc.Store("SDX6320033", voltDev)
913 va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv)
914 case "Negetive_Case_AssociateVpvsToDevice":
915 va := &VoltApplication{
916 DevicesDisc: sync.Map{},
917 VnetsBySvlan: util.NewConcurrentMap(),
918 }
919 va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv)
920 }
921 })
922 }
923}
924
925func TestVoltApplication_DisassociateVpvsFromDevice(t *testing.T) {
926 type args struct {
927 device string
928 vpv *VoltPortVnet
929 }
930 vpv := &VoltPortVnet{
931 Device: "SDX6320033",
932 SVlan: of.VlanAny,
933 }
934
935 voltDev := &VoltDevice{
936 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
937 SerialNum: "SDX6320033",
938 NniDhcpTrapVid: 123,
939 VpvsBySvlan: util.NewConcurrentMap(),
940 }
941 tests := []struct {
942 name string
943 args args
944 }{
945 {
946 name: "Positive_Case_DisassociateVpvsFromDevice",
947 args: args{
948 device: "SDX6320033",
949 vpv: vpv,
950 },
951 },
952 {
953 name: "Negetive_Case_DisassociateVpvsFromDevice",
954 args: args{
955 device: "SDX6320033",
956 vpv: vpv,
957 },
958 },
959 }
960 for _, tt := range tests {
961 t.Run(tt.name, func(t *testing.T) {
962 switch tt.name {
963 case "Positive_Case_DisassociateVpvsFromDevice":
964 va := &VoltApplication{
965 DevicesDisc: sync.Map{},
966 VnetsBySvlan: util.NewConcurrentMap(),
967 }
968 va.DevicesDisc.Store("SDX6320033", voltDev)
969 va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv)
970 case "Negetive_Case_DisassociateVpvsFromDevice":
971 va := &VoltApplication{
972 DevicesDisc: sync.Map{},
973 VnetsBySvlan: util.NewConcurrentMap(),
974 }
975 va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv)
976 }
977 })
978 }
979}
980
981func TestVoltDevice_GetPort(t *testing.T) {
982 type args struct {
983 port string
984 }
985 voltPort := &VoltPort{
986 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
987 Device: "SDX6320031",
988 ID: 16777472,
989 State: PortStateDown,
990 ChannelPerSubAlarmRaised: false,
991 Type: VoltPortTypeNni,
992 }
993 tests := []struct {
994 name string
995 args args
996 want *VoltPort
997 }{
998 {
999 name: "Positive_Case_GetPort",
1000 args: args{
1001 port: "16777472",
1002 },
1003 want: voltPort,
1004 },
1005 {
1006 name: "Negetive_Case_GetPort",
1007 args: args{
1008 port: "16777472",
1009 },
1010 want: nil,
1011 },
1012 }
1013 for _, tt := range tests {
1014 t.Run(tt.name, func(t *testing.T) {
1015 d := &VoltDevice{
1016 Ports: sync.Map{},
1017 }
1018 switch tt.name {
1019 case "Positive_Case_GetPort":
1020 d.Ports.Store("16777472", voltPort)
1021 if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) {
1022 t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want)
1023 }
1024 case "Negetive_Case_GetPort":
1025 if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) {
1026 t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want)
1027 }
1028 }
1029 })
1030 }
1031}
1032
1033func TestVoltDevice_GetPortNameFromPortID(t *testing.T) {
1034 type args struct {
1035 portID uint32
1036 }
1037 voltPort := &VoltPort{
1038 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1039 Device: "SDX6320031",
1040 ID: 16777472,
1041 State: PortStateDown,
1042 ChannelPerSubAlarmRaised: false,
1043 Type: VoltPortTypeNni,
1044 }
1045 tests := []struct {
1046 name string
1047 args args
1048 want string
1049 }{
1050 {
1051 name: "Positive_Case_GetPort",
1052 args: args{
1053 portID: 16777472,
1054 },
1055 want: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1056 },
1057 }
1058 for _, tt := range tests {
1059 t.Run(tt.name, func(t *testing.T) {
1060 d := &VoltDevice{
1061 Ports: sync.Map{},
1062 }
1063 d.Ports.Store(16777472, voltPort)
1064 if got := d.GetPortNameFromPortID(tt.args.portID); got != tt.want {
1065 t.Errorf("VoltDevice.GetPortNameFromPortID() = %v, want %v", got, tt.want)
1066 }
1067 })
1068 }
1069}
1070
1071func TestVoltDevice_DelPort(t *testing.T) {
1072 type args struct {
1073 port string
1074 }
1075 voltPort := &VoltPort{
1076 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1077 Device: "SDX6320031",
1078 ID: 16777472,
1079 State: PortStateDown,
1080 ChannelPerSubAlarmRaised: false,
1081 Type: VoltPortTypeNni,
1082 }
1083 tests := []struct {
1084 name string
1085 args args
1086 }{
1087 {
1088 name: "Positive_Case_DelPort",
1089 args: args{
1090 port: "16777472",
1091 },
1092 },
1093 {
1094 name: "Negetive_Case_DelPort",
1095 args: args{
1096 port: "16777472",
1097 },
1098 },
1099 }
1100 for _, tt := range tests {
1101 t.Run(tt.name, func(t *testing.T) {
1102 d := &VoltDevice{
1103 Ports: sync.Map{},
1104 }
1105 switch tt.name {
1106 case "Positive_Case_DelPort":
1107 d.Ports.Store("16777472", voltPort)
1108 d.DelPort(tt.args.port)
1109 case "Negetive_Case_DelPort":
1110 d.DelPort(tt.args.port)
1111 }
1112 })
1113 }
1114}
1115
1116func TestVoltDevice_pushFlowsForUnis(t *testing.T) {
1117 type args struct {
1118 cntx context.Context
1119 }
1120 tests := []struct {
1121 name string
1122 args args
1123 }{
1124 {
1125 name: "Positive_Case_pushFlowsForUnis",
1126 args: args{
1127 cntx: context.Background(),
1128 },
1129 },
1130 {
1131 name: "Negetive_Case_pushFlowsForUnis",
1132 args: args{
1133 cntx: context.Background(),
1134 },
1135 },
1136 {
1137 name: "Negetive_Case1_pushFlowsForUnis",
1138 args: args{
1139 cntx: context.Background(),
1140 },
1141 },
1142 }
1143 for _, tt := range tests {
1144 t.Run(tt.name, func(t *testing.T) {
1145 d := &VoltDevice{
1146 Name: "SDX6320031",
1147 SerialNum: "SDX6320031",
1148 Ports: sync.Map{},
1149 }
1150 switch tt.name {
1151 case "Positive_Case_pushFlowsForUnis":
1152 voltPort := &VoltPort{
1153 Name: "16777472",
1154 Device: "SDX6320031",
1155 ID: 16777472,
1156 State: PortStateUp,
1157 ChannelPerSubAlarmRaised: false,
1158 Type: VoltPortTypeNni,
1159 }
1160 d.Ports.Store("16777472", voltPort)
1161 ga := GetApplication()
1162 voltPortVnets := make([]*VoltPortVnet, 0)
1163 voltPortVnet := &VoltPortVnet{
1164 Device: "SDX6320031",
1165 Port: "16777472",
1166 DeleteInProgress: true,
1167 }
1168 voltPortVnets = append(voltPortVnets, voltPortVnet)
1169 ga.VnetsByPort.Store("16777472", voltPortVnets)
1170
1171 d.pushFlowsForUnis(tt.args.cntx)
1172 case "Negetive_Case_pushFlowsForUnis":
1173 voltPort1 := &VoltPort{
1174 Name: "16777472",
1175 Device: "SDX6320031",
1176 ID: 16777472,
1177 State: PortStateDown,
1178 ChannelPerSubAlarmRaised: false,
1179 Type: VoltPortTypeNni,
1180 }
1181 d.Ports.Store("16777472", voltPort1)
1182 d.pushFlowsForUnis(tt.args.cntx)
1183 case "Negetive_Case1_pushFlowsForUnis":
1184 voltPort2 := &VoltPort{
1185 Name: "16777472",
1186 Device: "SDX6320031",
1187 ID: 16777472,
1188 State: PortStateUp,
1189 ChannelPerSubAlarmRaised: false,
1190 Type: VoltPortTypeNni,
1191 }
1192 d.Ports.Store("1677747", voltPort2)
1193 d.pushFlowsForUnis(tt.args.cntx)
1194 }
1195 })
1196 }
1197}
1198
1199func TestNewNbDevice(t *testing.T) {
1200 tests := []struct {
1201 name string
1202 want *NbDevice
1203 }{
1204 {
1205 name: "Positive_Case_pushFlowsForUnis",
1206 want: &NbDevice{},
1207 },
1208 }
1209 for _, tt := range tests {
1210 t.Run(tt.name, func(t *testing.T) {
1211 if got := NewNbDevice(); !reflect.DeepEqual(got, tt.want) {
1212 t.Errorf("NewNbDevice() = %v, want %v", got, tt.want)
1213 }
1214 })
1215 }
1216}
1217
1218func TestNbDevice_WriteToDb(t *testing.T) {
1219 type args struct {
1220 cntx context.Context
1221 portID uint32
1222 ponPort *PonPortCfg
1223 }
1224 tests := []struct {
1225 name string
1226 args args
1227 }{
1228 {
1229 name: "Positive_Case_pushFlowsForUnis",
1230 args: args{
1231 cntx: context.Background(),
1232 portID: controller.NNIPortID,
1233 ponPort: &PonPortCfg{
1234 PortID: controller.NNIPortID,
1235 EnableMulticastKPI: false,
1236 },
1237 },
1238 },
1239 }
1240 for _, tt := range tests {
1241 t.Run(tt.name, func(t *testing.T) {
1242 nbd := &NbDevice{
1243 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1244 }
1245 switch tt.name {
1246 case "Positive_Case_pushFlowsForUnis":
1247 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1248 db = dbintf
1249 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1250 nbd.WriteToDb(tt.args.cntx, tt.args.portID, tt.args.ponPort)
1251 }
1252 })
1253 }
1254}
1255
1256func TestNbDevice_AddPortToNbDevice(t *testing.T) {
1257 type args struct {
1258 cntx context.Context
1259 portID uint32
1260 allowedChannels uint32
1261 enableMulticastKPI bool
1262 portAlarmProfileID string
1263 }
1264 ponPort := &PonPortCfg{
1265 PortID: controller.NNIPortID,
1266 MaxActiveChannels: 123,
1267 EnableMulticastKPI: false,
1268 PortAlarmProfileID: "16777",
1269 }
1270 tests := []struct {
1271 name string
1272 args args
1273 want *PonPortCfg
1274 }{
1275 {
1276 name: "Positive_Case_AddPortToNbDevice",
1277 args: args{
1278 cntx: context.Background(),
1279 portID: controller.NNIPortID,
1280 allowedChannels: 123,
1281 enableMulticastKPI: false,
1282 portAlarmProfileID: "16777",
1283 },
1284 want: ponPort,
1285 },
1286 }
1287 for _, tt := range tests {
1288 t.Run(tt.name, func(t *testing.T) {
1289 nbd := &NbDevice{
1290 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1291 PonPorts: sync.Map{},
1292 }
1293 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1294 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1295 db = dbintf
1296 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1297 if got := nbd.AddPortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1298 t.Errorf("NbDevice.AddPortToNbDevice() = %v, want %v", got, tt.want)
1299 }
1300 })
1301 }
1302}
1303
1304func TestVoltApplication_AddDeviceConfig(t *testing.T) {
1305 type args struct {
1306 cntx context.Context
1307 serialNum string
1308 hardwareIdentifier string
1309 nasID string
1310 ipAddress string
1311 uplinkPort string
1312 nniDhcpTrapID int
1313 }
1314 dvcConfg := &DeviceConfig{
1315 SerialNumber: "SDX6320031",
1316 HardwareIdentifier: "0.0.0.0",
1317 IPAddress: "127.26.1.74",
1318 UplinkPort: "16777216",
1319 NasID: "12345",
1320 NniDhcpTrapVid: 123,
1321 }
1322 voltDev := &VoltDevice{
1323 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1324 SerialNum: "SDX6320031",
1325 NniDhcpTrapVid: 123,
1326 }
1327 tests := []struct {
1328 name string
1329 args args
1330 wantErr bool
1331 }{
1332 {
1333 name: "Positive_Case_AddDeviceConfig",
1334 args: args{
1335 cntx: context.Background(),
1336 serialNum: "SDX6320031",
1337 hardwareIdentifier: "0.0.0.0.",
1338 nasID: "12345",
1339 ipAddress: "127.26.1.74",
1340 uplinkPort: "16777216",
1341 nniDhcpTrapID: 123,
1342 },
1343 wantErr: false,
1344 },
1345 }
1346 for _, tt := range tests {
1347 t.Run(tt.name, func(t *testing.T) {
1348 va := &VoltApplication{
1349 DevicesConfig: sync.Map{},
1350 }
1351 va.DevicesConfig.Store("SDX6320031", dvcConfg)
1352 va.DevicesDisc.Store("SDX6320031", voltDev)
1353 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1354 db = dbintf
1355 dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1356 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); (err != nil) != tt.wantErr {
1357 t.Errorf("VoltApplication.AddDeviceConfig() error = %v, wantErr %v", err, tt.wantErr)
1358 }
1359 })
1360 }
1361}
1362
1363func TestVoltApplication_GetDeviceConfig(t *testing.T) {
1364 type args struct {
1365 serNum string
1366 }
1367 dvcConfg := &DeviceConfig{
1368 SerialNumber: "SDX6320031",
1369 HardwareIdentifier: "0.0.0.0",
1370 IPAddress: "127.26.1.74",
1371 UplinkPort: "16777216",
1372 NasID: "12345",
1373 NniDhcpTrapVid: 123,
1374 }
1375 tests := []struct {
1376 name string
1377 args args
1378 want *DeviceConfig
1379 }{
1380 {
1381 name: "Positive_Case_GetDeviceConfig",
1382 args: args{
1383 serNum: "SDX6320031",
1384 },
1385 want: dvcConfg,
1386 },
1387 {
1388 name: "Negetive_Case_GetDeviceConfig",
1389 args: args{
1390 serNum: "SDX6320031",
1391 },
1392 want: nil,
1393 },
1394 }
1395 for _, tt := range tests {
1396 t.Run(tt.name, func(t *testing.T) {
1397 va := &VoltApplication{
1398 DevicesConfig: sync.Map{},
1399 }
1400 switch tt.name {
1401 case "Positive_Case_GetDeviceConfig":
1402 va.DevicesConfig.Store("SDX6320031", dvcConfg)
1403 if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) {
1404 t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want)
1405 }
1406 case "Negetive_Case_GetDeviceConfig":
1407 if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) {
1408 t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want)
1409 }
1410 }
1411 })
1412 }
1413}
1414
1415func TestNbDevice_UpdatePortToNbDevice(t *testing.T) {
1416 type args struct {
1417 cntx context.Context
1418 portID uint32
1419 allowedChannels uint32
1420 enableMulticastKPI bool
1421 portAlarmProfileID string
1422 }
1423 ponPort := &PonPortCfg{
1424 PortID: controller.NNIPortID,
1425 MaxActiveChannels: 123,
1426 EnableMulticastKPI: false,
1427 PortAlarmProfileID: "16777",
1428 }
1429 tests := []struct {
1430 name string
1431 args args
1432 want *PonPortCfg
1433 }{
1434 {
1435 name: "Positive_Case_UpdatePortToNbDevice",
1436 args: args{
1437 cntx: context.Background(),
1438 portID: controller.NNIPortID,
1439 allowedChannels: 123,
1440 enableMulticastKPI: false,
1441 portAlarmProfileID: "16777",
1442 },
1443 want: ponPort,
1444 },
1445 {
1446 name: "Negetive_Case_UpdatePortToNbDevice",
1447 args: args{
1448 cntx: context.Background(),
1449 portID: 0,
1450 allowedChannels: 123,
1451 enableMulticastKPI: false,
1452 portAlarmProfileID: "16777",
1453 },
1454 want: nil,
1455 },
1456 }
1457 for _, tt := range tests {
1458 t.Run(tt.name, func(t *testing.T) {
1459 nbd := &NbDevice{
1460 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1461 PonPorts: sync.Map{},
1462 }
1463 switch tt.name {
1464 case "Positive_Case_UpdatePortToNbDevice":
1465 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1466 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1467 db = dbintf
1468 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1469 if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1470 t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want)
1471 }
1472 case "Negetive_Case_UpdatePortToNbDevice":
1473 if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1474 t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want)
1475 }
1476 }
1477 })
1478 }
1479}
1480
1481func TestNbDevice_DeletePortFromNbDevice(t *testing.T) {
1482 type args struct {
1483 cntx context.Context
1484 portID uint32
1485 }
1486 ponPort := &PonPortCfg{
1487 PortID: controller.NNIPortID,
1488 MaxActiveChannels: 123,
1489 EnableMulticastKPI: false,
1490 PortAlarmProfileID: "16777",
1491 }
1492 tests := []struct {
1493 name string
1494 args args
1495 }{
1496 {
1497 name: "Positive_Case_DeletePortFromNbDevice",
1498 args: args{
1499 portID: controller.NNIPortID,
1500 },
1501 },
1502 }
1503 for _, tt := range tests {
1504 t.Run(tt.name, func(t *testing.T) {
1505 nbd := &NbDevice{
1506 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1507 PonPorts: sync.Map{},
1508 }
1509 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1510 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1511 db = dbintf
1512 dbintf.EXPECT().DelNbDevicePort(nil, "49686e2d-618f-4e8e-bca0-442ab850a63a", controller.NNIPortID).AnyTimes()
1513 nbd.DeletePortFromNbDevice(tt.args.cntx, tt.args.portID)
1514 })
1515 }
1516}
1517
1518func TestVoltDevice_RegisterFlowAddEvent(t *testing.T) {
1519 type args struct {
1520 cookie string
1521 event *FlowEvent
1522 }
1523 flowEvent := &FlowEvent{
1524 device: "SDX6320031",
1525 cookie: "68786618880",
1526 eType: EventTypeControlFlowAdded,
1527 }
1528 tests := []struct {
1529 name string
1530 args args
1531 }{
1532 {
1533 name: "Positive_Case_RegisterFlowAddEvent",
1534 args: args{
1535 cookie: "68786618880",
1536 event: flowEvent,
1537 },
1538 },
1539 }
1540 for _, tt := range tests {
1541 t.Run(tt.name, func(t *testing.T) {
1542 d := &VoltDevice{
1543 FlowAddEventMap: util.NewConcurrentMap(),
1544 }
1545 d.RegisterFlowAddEvent(tt.args.cookie, tt.args.event)
1546 })
1547 }
1548}
1549
1550func TestVoltDevice_RegisterFlowDelEvent(t *testing.T) {
1551 type args struct {
1552 cookie string
1553 event *FlowEvent
1554 }
1555 flowEvent := &FlowEvent{
1556 device: "SDX6320031",
1557 cookie: "68786618880",
1558 eType: EventTypeControlFlowRemoved,
1559 }
1560 tests := []struct {
1561 name string
1562 args args
1563 }{
1564 {
1565 name: "Positive_Case_RegisterFlowDelEvent",
1566 args: args{
1567 cookie: "68786618880",
1568 event: flowEvent,
1569 },
1570 },
1571 }
1572 for _, tt := range tests {
1573 t.Run(tt.name, func(t *testing.T) {
1574 d := &VoltDevice{
1575 FlowDelEventMap: util.NewConcurrentMap(),
1576 }
1577 d.RegisterFlowDelEvent(tt.args.cookie, tt.args.event)
1578 })
1579 }
1580}
1581
1582func TestVoltDevice_UnRegisterFlowEvent(t *testing.T) {
1583 type args struct {
1584 cookie string
1585 flowModType of.Command
1586 }
1587 tests := []struct {
1588 name string
1589 args args
1590 }{
1591 {
1592 name: "Positive_Case_RegisterFlowDelEvent",
1593 args: args{
1594 cookie: "68786618880",
1595 flowModType: of.CommandDel,
1596 },
1597 },
1598 {
1599 name: "Negetive_Case_RegisterFlowDelEvent",
1600 args: args{
1601 cookie: "68786618880",
1602 flowModType: opt82,
1603 },
1604 },
1605 }
1606 for _, tt := range tests {
1607 t.Run(tt.name, func(t *testing.T) {
1608 switch tt.name {
1609 case "Positive_Case_RegisterFlowDelEvent":
1610 d := &VoltDevice{
1611 FlowDelEventMap: util.NewConcurrentMap(),
1612 }
1613 d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType)
1614 case "Negetive_Case_RegisterFlowDelEvent":
1615 d := &VoltDevice{
1616 FlowDelEventMap: util.NewConcurrentMap(),
1617 }
1618 d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType)
1619 }
1620 })
1621 }
1622}
1623
1624func TestVoltApplication_InitStaticConfig(t *testing.T) {
1625 tests := []struct {
1626 name string
1627 }{
1628 {
1629 name: "Positive_Case_InitStaticConfig",
1630 },
1631 }
1632 for _, tt := range tests {
1633 t.Run(tt.name, func(t *testing.T) {
1634 va := &VoltApplication{}
1635 va.InitStaticConfig()
1636 })
1637 }
1638}
1639
1640func TestVoltApplication_SetVendorID(t *testing.T) {
1641 type args struct {
1642 vendorID string
1643 }
1644 tests := []struct {
1645 name string
1646 args args
1647 }{
1648 {
1649 name: "Positive_Case_SetVendorID",
1650 args: args{
1651 vendorID: "DT",
1652 },
1653 },
1654 }
1655 for _, tt := range tests {
1656 t.Run(tt.name, func(t *testing.T) {
1657 va := &VoltApplication{}
1658 va.SetVendorID(tt.args.vendorID)
1659 })
1660 }
1661}
1662
1663func TestVoltApplication_GetVendorID(t *testing.T) {
1664 tests := []struct {
1665 name string
1666 want string
1667 }{
1668 {
1669 name: "Positive_Case_GetVendorID",
1670 want: "DT",
1671 },
1672 }
1673 for _, tt := range tests {
1674 t.Run(tt.name, func(t *testing.T) {
1675 va := &VoltApplication{
1676 vendorID: "DT",
1677 }
1678 if got := va.GetVendorID(); got != tt.want {
1679 t.Errorf("VoltApplication.GetVendorID() = %v, want %v", got, tt.want)
1680 }
1681 })
1682 }
1683}
1684
1685func TestVoltApplication_SetRebootFlag(t *testing.T) {
1686 type args struct {
1687 flag bool
1688 }
1689 tests := []struct {
1690 name string
1691 args args
1692 }{
1693 {
1694 name: "Positive_Case_SetRebootFlag",
1695 args: args{
1696 flag: true,
1697 },
1698 },
1699 }
1700 for _, tt := range tests {
1701 t.Run(tt.name, func(t *testing.T) {
1702 va := &VoltApplication{}
1703 va.SetRebootFlag(tt.args.flag)
1704 })
1705 }
1706}
1707
1708func TestVoltApplication_GetUpgradeFlag(t *testing.T) {
1709 tests := []struct {
1710 name string
1711 want bool
1712 }{
1713 {
1714 name: "Positive_Case_GetUpgradeFlag",
1715 want: true,
1716 },
1717 }
1718 for _, tt := range tests {
1719 t.Run(tt.name, func(t *testing.T) {
1720 va := &VoltApplication{}
1721 isUpgradeComplete = true
1722 if got := va.GetUpgradeFlag(); got != tt.want {
1723 t.Errorf("VoltApplication.GetUpgradeFlag() = %v, want %v", got, tt.want)
1724 }
1725 })
1726 }
1727}
1728
1729func TestVoltApplication_SetUpgradeFlag(t *testing.T) {
1730 type args struct {
1731 flag bool
1732 }
1733 tests := []struct {
1734 name string
1735 args args
1736 }{
1737 {
1738 name: "Positive_Case_GetUpgradeFlag",
1739 args: args{
1740 flag: true,
1741 },
1742 },
1743 }
1744 for _, tt := range tests {
1745 t.Run(tt.name, func(t *testing.T) {
1746 va := &VoltApplication{}
1747 va.SetUpgradeFlag(tt.args.flag)
1748 })
1749 }
1750}
1751
1752func TestVoltApplication_AddDevice(t *testing.T) {
1753 type args struct {
1754 cntx context.Context
1755 device string
1756 slno string
1757 southBoundID string
1758 }
1759 voltDev := &VoltDevice{
1760 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1761 SerialNum: "SDX6320031",
1762 NniDhcpTrapVid: 123,
1763 NniPort: "16777216",
1764 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1765 }
1766 nbd := &NbDevice{
1767 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1768 PonPorts: sync.Map{},
1769 }
1770 ponPortCnf := &PonPortCfg{
1771 PortID: controller.NNIPortID,
1772 MaxActiveChannels: 123,
1773 EnableMulticastKPI: false,
1774 PortAlarmProfileID: "16777",
1775 }
1776 tests := []struct {
1777 name string
1778 args args
1779 }{
1780 {
1781 name: "Positive_Case_AddDevice",
1782 args: args{
1783 cntx: context.Background(),
1784 device: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1785 slno: "SDX6320031",
1786 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1787 },
1788 },
1789 {
1790 name: "Negetive_Case_AddDevice",
1791 args: args{
1792 cntx: context.Background(),
1793 device: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1794 slno: "SDX6320031",
1795 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1796 },
1797 },
1798 }
1799 for _, tt := range tests {
1800 t.Run(tt.name, func(t *testing.T) {
1801 va := &VoltApplication{
1802 DevicesDisc: sync.Map{},
1803 NbDevice: sync.Map{},
1804 }
1805 switch tt.name {
1806 case "Positive_Case_AddDevice":
1807 va.DevicesDisc.Store("SDX6320031", voltDev)
1808 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a123", nbd)
1809 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
1810 va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID)
1811 case "Negetive_Case_AddDevice":
1812 va.DevicesDisc.Store("SDX6320031", voltDev)
1813 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
1814 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1815 db = dbintf
1816 dbintf.EXPECT().GetAllNbPorts(context.Background(), "49686e2d-618f-4e8e-bca0-442ab850a63a123").AnyTimes()
1817 va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID)
1818 }
1819 })
1820 }
1821}
1822
1823func TestVoltApplication_DelDevice(t *testing.T) {
1824 type args struct {
1825 cntx context.Context
1826 device string
1827 }
1828 voltDev := &VoltDevice{
1829 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1830 SerialNum: "SDX6320031",
1831 NniDhcpTrapVid: 123,
1832 NniPort: "16777216",
1833 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1834 }
1835 tests := []struct {
1836 name string
1837 args args
1838 }{
1839 {
1840 name: "Positive_Case_AddDevice",
1841 args: args{
1842 cntx: context.Background(),
1843 device: "SDX6320031",
1844 },
1845 },
1846 {
1847 name: "Delete_Case_AddDevice",
1848 args: args{
1849 cntx: context.Background(),
1850 device: "SDX6320031",
1851 },
1852 },
1853 }
1854 for _, tt := range tests {
1855 t.Run(tt.name, func(t *testing.T) {
1856 va := &VoltApplication{
1857 DevicesDisc: sync.Map{},
1858 }
1859 switch tt.name {
1860 case "Positive_Case_AddDevice":
1861 va.DevicesDisc.Store("SDX6320031", voltDev)
1862 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1863 db = dbintf
1864 dbintf.EXPECT().DelAllRoutesForDevice(context.Background(), "SDX6320031").AnyTimes()
1865 dbintf.EXPECT().GetAllMigrateServicesReq(context.Background(), "SDX6320031").AnyTimes()
1866 dbintf.EXPECT().DelAllGroup(context.Background(), "SDX6320031").AnyTimes()
1867 dbintf.EXPECT().DelAllMeter(context.Background(), "SDX6320031").AnyTimes()
1868 dbintf.EXPECT().DelAllPorts(context.Background(), "SDX6320031").AnyTimes()
1869 va.DelDevice(tt.args.cntx, tt.args.device)
1870 case "Delete_Case_AddDevice":
1871 va.DelDevice(tt.args.cntx, tt.args.device)
1872 }
1873 })
1874 }
1875}
1876
1877func TestVoltApplication_PortAddInd(t *testing.T) {
1878 type args struct {
1879 cntx context.Context
1880 device string
1881 id uint32
1882 portName string
1883 }
1884 voltDev := &VoltDevice{
1885 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1886 SerialNum: "SDX6320031",
1887 NniDhcpTrapVid: 123,
1888 NniPort: "16777216",
1889 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1890 }
1891 tests := []struct {
1892 name string
1893 args args
1894 }{
1895 {
1896 name: "Positive_Case_PortAddInd",
1897 args: args{
1898 cntx: context.Background(),
1899 device: "SDX6320031",
1900 id: controller.NNIPortID,
1901 portName: "16777216",
1902 },
1903 },
1904 {
1905 name: "Negetive_Case_PortAddInd",
1906 args: args{
1907 cntx: context.Background(),
1908 device: "SDX6320031",
1909 id: controller.NNIPortID,
1910 portName: "16777216",
1911 },
1912 },
1913 }
1914 for _, tt := range tests {
1915 t.Run(tt.name, func(t *testing.T) {
1916 va := &VoltApplication{
1917 DevicesDisc: sync.Map{},
1918 }
1919 switch tt.name {
1920 case "Positive_Case_PortAddInd":
1921 va.DevicesDisc.Store("SDX6320031", voltDev)
1922 va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName)
1923 case "Negetive_Case_PortAddInd":
1924 va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName)
1925 }
1926 })
1927 }
1928}
1929
1930func TestVoltApplication_PortUpdateInd(t *testing.T) {
1931 type args struct {
1932 device string
1933 portName string
1934 id uint32
1935 }
1936 voltDev := &VoltDevice{
1937 Name: "SDX6320031",
1938 SerialNum: "SDX6320031",
1939 NniDhcpTrapVid: 123,
1940 NniPort: "16777216",
1941 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1942 }
1943 tests := []struct {
1944 name string
1945 args args
1946 }{
1947 {
1948 name: "Positive_Case_PortUpdateInd",
1949 args: args{
1950 device: "SDX6320031",
1951 id: controller.NNIPortID,
1952 portName: "16777216",
1953 },
1954 },
1955 {
1956 name: "Negetive_Case_PortUpdateInd",
1957 args: args{
1958 device: "SDX6320031",
1959 id: controller.NNIPortID,
1960 portName: "16777216",
1961 },
1962 },
1963 }
1964 for _, tt := range tests {
1965 t.Run(tt.name, func(t *testing.T) {
1966 va := &VoltApplication{
1967 DevicesDisc: sync.Map{},
1968 }
1969 switch tt.name {
1970 case "Positive_Case_PortAddInd":
1971 va.DevicesDisc.Store("SDX6320031", voltDev)
1972 d := &VoltDevice{
1973 Ports: sync.Map{},
1974 }
1975 voltPort := &VoltPort{
1976 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1977 Device: "SDX6320031",
1978 ID: 16777472,
1979 State: PortStateDown,
1980 ChannelPerSubAlarmRaised: false,
1981 Type: VoltPortTypeNni,
1982 }
1983 d.Ports.Store(16777472, voltPort)
1984 va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id)
1985 case "Negetive_Case_PortUpdateInd":
1986 va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id)
1987 }
1988 })
1989 }
1990}
1991
1992func TestVoltApplication_AddNbPonPort(t *testing.T) {
1993 type args struct {
1994 cntx context.Context
1995 oltSbID string
1996 portID uint32
1997 maxAllowedChannels uint32
1998 enableMulticastKPI bool
1999 portAlarmProfileID string
2000 }
2001 voltDev := &VoltDevice{
2002 Name: "SDX6320031",
2003 SerialNum: "SDX6320031",
2004 NniDhcpTrapVid: 123,
2005 NniPort: "16777216",
2006 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2007 }
2008 nbd := &NbDevice{
2009 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2010 }
2011 tests := []struct {
2012 name string
2013 args args
2014 wantErr bool
2015 }{
2016 {
2017 name: "Positive_Case_AddNbPonPort",
2018 args: args{
2019 cntx: context.Background(),
2020 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2021 portID: 16777472,
2022 maxAllowedChannels: 0,
2023 enableMulticastKPI: false,
2024 portAlarmProfileID: "16777",
2025 },
2026 },
2027 {
2028 name: "Negetive_Case_AddNbPonPort",
2029 args: args{
2030 cntx: context.Background(),
2031 oltSbID: "0",
2032 portID: 16777472,
2033 maxAllowedChannels: 0,
2034 enableMulticastKPI: false,
2035 portAlarmProfileID: "16777",
2036 },
2037 },
2038 }
2039 for _, tt := range tests {
2040 t.Run(tt.name, func(t *testing.T) {
2041 va := &VoltApplication{
2042 DevicesDisc: sync.Map{},
2043 NbDevice: sync.Map{},
2044 }
2045 switch tt.name {
2046 case "Positive_Case_AddNbPonPort":
2047 va.DevicesDisc.Store("SDX6320031", voltDev)
2048 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2049 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2050 db = dbintf
2051 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2052 if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2053 t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2054 }
2055 case "Negetive_Case_AddNbPonPort":
2056 va.DevicesDisc.Store("SDX6320031", voltDev)
2057 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2058 db = dbintf
2059 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2060 if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2061 t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2062 }
2063 }
2064 })
2065 }
2066}
2067
2068func TestVoltApplication_UpdateNbPonPort(t *testing.T) {
2069 type args struct {
2070 cntx context.Context
2071 oltSbID string
2072 portID uint32
2073 maxAllowedChannels uint32
2074 enableMulticastKPI bool
2075 portAlarmProfileID string
2076 }
2077 voltDev := &VoltDevice{
2078 Name: "SDX6320031",
2079 SerialNum: "SDX6320031",
2080 NniDhcpTrapVid: 123,
2081 NniPort: "16777216",
2082 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2083 ActiveChannelsPerPon: sync.Map{},
2084 }
2085 nbd := &NbDevice{
2086 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2087 PonPorts: sync.Map{},
2088 }
2089 ponPortCnf := &PonPortCfg{
2090 PortID: controller.NNIPortID,
2091 MaxActiveChannels: 123,
2092 EnableMulticastKPI: false,
2093 PortAlarmProfileID: "16777",
2094 }
2095 tests := []struct {
2096 name string
2097 args args
2098 wantErr bool
2099 }{
2100 {
2101 name: "Positive_Case_UpdateNbPonPort",
2102 args: args{
2103 cntx: context.Background(),
2104 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2105 portID: controller.NNIPortID,
2106 maxAllowedChannels: 0,
2107 enableMulticastKPI: false,
2108 portAlarmProfileID: "16777",
2109 },
2110 wantErr: false,
2111 },
2112 {
2113 name: "Negetive_Case_Port_doesn't_exists",
2114 args: args{
2115 cntx: context.Background(),
2116 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2117 portID: 16777472,
2118 maxAllowedChannels: 0,
2119 enableMulticastKPI: false,
2120 portAlarmProfileID: "16777",
2121 },
2122 wantErr: true,
2123 },
2124 {
2125 name: "Negetive_Case_Device-doesn't-exists",
2126 args: args{
2127 cntx: context.Background(),
2128 oltSbID: "0",
2129 portID: 16777472,
2130 maxAllowedChannels: 0,
2131 enableMulticastKPI: false,
2132 portAlarmProfileID: "16777",
2133 },
2134 wantErr: true,
2135 },
2136 }
2137 for _, tt := range tests {
2138 t.Run(tt.name, func(t *testing.T) {
2139 va := &VoltApplication{
2140 DevicesDisc: sync.Map{},
2141 NbDevice: sync.Map{},
2142 }
2143 switch tt.name {
2144 case "Positive_Case_UpdateNbPonPort":
2145 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2146 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
2147 va.DevicesDisc.Store("SDX6320031", voltDev)
2148 voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf)
2149 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2150 db = dbintf
2151 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2152 if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2153 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2154 }
2155 case "Negetive_Case_Port_doesn't_exists":
2156 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2157 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2158 db = dbintf
2159 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2160 if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2161 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2162 }
2163 case "Negetive_Case_Device-doesn't-exists":
2164 va.DevicesDisc.Store("SDX6320031", voltDev)
2165 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2166 db = dbintf
2167 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2168 if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2169 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2170 }
2171 }
2172 })
2173 }
2174}
2175
2176func TestVoltApplication_DeleteNbPonPort(t *testing.T) {
2177 type args struct {
2178 cntx context.Context
2179 oltSbID string
2180 portID uint32
2181 }
2182 voltDev := &VoltDevice{
2183 Name: "SDX6320031",
2184 SerialNum: "SDX6320031",
2185 NniDhcpTrapVid: 123,
2186 NniPort: "16777216",
2187 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2188 ActiveChannelsPerPon: sync.Map{},
2189 }
2190 nbd := &NbDevice{
2191 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2192 }
2193 ponPortCnf := &PonPortCfg{
2194 PortID: controller.NNIPortID,
2195 MaxActiveChannels: 123,
2196 EnableMulticastKPI: false,
2197 PortAlarmProfileID: "16777",
2198 }
2199 tests := []struct {
2200 name string
2201 args args
2202 wantErr bool
2203 }{
2204 {
2205 name: "Positive_Case_DeleteNbPonPort",
2206 args: args{
2207 cntx: context.Background(),
2208 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2209 portID: controller.NNIPortID,
2210 },
2211 wantErr: false,
2212 },
2213 {
2214 name: "Negetive_Case_DeleteNbPonPort",
2215 args: args{
2216 cntx: context.Background(),
2217 oltSbID: "0",
2218 portID: controller.NNIPortID,
2219 },
2220 wantErr: false,
2221 },
2222 }
2223 for _, tt := range tests {
2224 t.Run(tt.name, func(t *testing.T) {
2225 va := &VoltApplication{
2226 DevicesDisc: sync.Map{},
2227 NbDevice: sync.Map{},
2228 }
2229 switch tt.name {
2230 case "Positive_Case_DeleteNbPonPort":
2231 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2232 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
2233 va.DevicesDisc.Store("SDX6320031", voltDev)
2234 voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf)
2235 va.DevicesDisc.Store("SDX6320031", voltDev)
2236 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2237 db = dbintf
2238 dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2239 if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr {
2240 t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2241 }
2242 case "Negetive_Case_DeleteNbPonPort":
2243 va.DevicesDisc.Store("SDX6320031", voltDev)
2244 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2245 db = dbintf
2246 dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2247 if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr {
2248 t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2249 }
2250 }
2251 })
2252 }
2253}
2254
2255func TestVoltApplication_DeviceUpInd(t *testing.T) {
2256 type args struct {
2257 device string
2258 }
2259 voltDev := &VoltDevice{
2260 Name: "SDX6320031",
2261 SerialNum: "SDX6320031",
2262 NniDhcpTrapVid: 123,
2263 NniPort: "16777216",
2264 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2265 }
2266 tests := []struct {
2267 name string
2268 args args
2269 }{
2270 {
2271 name: "Positive_Case_DeviceUpInd",
2272 args: args{
2273 device: "SDX6320031",
2274 },
2275 },
2276 {
2277 name: "Negetive_Case_DeviceUpInd",
2278 args: args{
2279 device: "o",
2280 },
2281 },
2282 }
2283 for _, tt := range tests {
2284 t.Run(tt.name, func(t *testing.T) {
2285 va := &VoltApplication{
2286 DevicesDisc: sync.Map{},
2287 }
2288 switch tt.name {
2289 case "Positive_Case_DeviceUpInd":
2290 va.DevicesDisc.Store("SDX6320031", voltDev)
2291 va.DeviceUpInd(tt.args.device)
2292 case "Negetive_Case_DeviceUpInd":
2293 va.DeviceUpInd(tt.args.device)
2294 }
2295 })
2296 }
2297}
2298
2299func TestVoltApplication_DeviceDownInd(t *testing.T) {
2300 type args struct {
2301 device string
2302 }
2303 voltDev := &VoltDevice{
2304 Name: "SDX6320031",
2305 SerialNum: "SDX6320031",
2306 NniDhcpTrapVid: 123,
2307 NniPort: "16777216",
2308 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2309 }
2310 tests := []struct {
2311 name string
2312 args args
2313 }{
2314 {
2315 name: "Positive_Case_DeviceDownInd",
2316 args: args{
2317 device: "SDX6320031",
2318 },
2319 },
2320 {
2321 name: "Negetive_Case_DeviceDownInd",
2322 args: args{
2323 device: "o",
2324 },
2325 },
2326 }
2327 for _, tt := range tests {
2328 t.Run(tt.name, func(t *testing.T) {
2329 va := &VoltApplication{
2330 DevicesDisc: sync.Map{},
2331 }
2332 switch tt.name {
2333 case "Positive_Case_DeviceDownInd":
2334 va.DevicesDisc.Store("SDX6320031", voltDev)
2335 va.DeviceDownInd(tt.args.device)
2336 case "Negetive_Case_DeviceDownInd":
2337 va.DeviceDownInd(tt.args.device)
2338 }
2339 })
2340 }
2341}
2342
2343func TestVoltApplication_DeviceRebootInd(t *testing.T) {
2344 type args struct {
2345 cntx context.Context
2346 device string
2347 serialNum string
2348 southBoundID string
2349 }
2350 voltDev := &VoltDevice{
Akash Soni6f369452023-09-19 11:18:28 +05302351 Name: "SDX6320031",
2352 SerialNum: "SDX6320031",
2353 State: controller.DeviceStateREBOOTED,
2354 MigratingServices: util.NewConcurrentMap(),
vinokumaf7605fc2023-06-02 18:08:01 +05302355 }
2356 tests := []struct {
2357 name string
2358 args args
2359 }{
2360 {
2361 name: "Positive_Case_DeviceRebootInd",
2362 args: args{
2363 device: "SDX6320031",
2364 serialNum: "SDX6320031",
2365 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2366 },
2367 },
Akash Soni6f369452023-09-19 11:18:28 +05302368 {
2369 name: "Negetive_Case_DeviceRebootInd",
2370 args: args{
2371 device: "SDX6320031",
2372 serialNum: "SDX6320031",
2373 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2374 },
2375 },
vinokumaf7605fc2023-06-02 18:08:01 +05302376 }
2377 for _, tt := range tests {
2378 t.Run(tt.name, func(t *testing.T) {
2379 va := &VoltApplication{
2380 DevicesDisc: sync.Map{},
2381 }
Akash Soni6f369452023-09-19 11:18:28 +05302382 switch tt.name {
2383 case "Positive_Case_DeviceRebootInd":
2384 va.DevicesDisc.Store("SDX6320031", voltDev)
2385 va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID)
2386 case "Negetive_Case_DeviceRebootInd":
2387 voltDev.State = controller.DeviceStateDOWN
2388 va.DevicesDisc.Store("SDX6320031", voltDev)
2389 GetApplication().DevicesDisc.Store("SDX6320031", voltDev)
2390 va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID)
2391 }
vinokumaf7605fc2023-06-02 18:08:01 +05302392 })
2393 }
2394}
vinokuma02fbfd02023-07-05 15:23:33 +05302395
2396func TestVoltApplication_GetDeviceFromPort(t *testing.T) {
2397 type args struct {
2398 port string
2399 }
2400 voltDev := &VoltDevice{
2401 Name: "SDX6320031",
2402 SerialNum: "SDX6320031",
2403 NniDhcpTrapVid: 123,
2404 NniPort: "16777216",
2405 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2406 Ports: sync.Map{},
2407 }
2408 voltPort := &VoltPort{
2409 Name: "16777216",
2410 Device: "SDX6320031",
2411 ID: 16777216,
2412 State: PortStateDown,
2413 ChannelPerSubAlarmRaised: false,
2414 Type: VoltPortTypeNni,
2415 }
2416 tests := []struct {
2417 name string
2418 args args
2419 want *VoltDevice
2420 wantErr bool
2421 }{
2422 {
2423 name: "Positive_Case_GetDeviceFromPort",
2424 args: args{
2425 port: "16777216",
2426 },
2427 want: voltDev,
2428 wantErr: false,
2429 },
2430 }
2431 for _, tt := range tests {
2432 t.Run(tt.name, func(t *testing.T) {
2433 va := &VoltApplication{
2434 DevicesDisc: sync.Map{},
2435 PortsDisc: sync.Map{},
2436 }
2437 va.PortsDisc.Store("16777216", voltPort)
2438 va.DevicesDisc.Store("SDX6320031", voltDev)
2439 got, err := va.GetDeviceFromPort(tt.args.port)
2440 if (err != nil) != tt.wantErr {
2441 t.Errorf("VoltApplication.GetDeviceFromPort() error = %v, wantErr %v", err, tt.wantErr)
2442 return
2443 }
2444 if !reflect.DeepEqual(got, tt.want) {
2445 t.Errorf("VoltApplication.GetDeviceFromPort() = %v, want %v", got, tt.want)
2446 }
2447 })
2448 }
2449}
2450
2451func TestVoltApplication_GetPortID(t *testing.T) {
2452 type args struct {
2453 port string
2454 }
2455 voltPort := &VoltPort{
2456 Name: "16777216",
2457 Device: "SDX6320031",
2458 ID: 16777216,
2459 State: PortStateDown,
2460 ChannelPerSubAlarmRaised: false,
2461 Type: VoltPortTypeNni,
2462 }
2463 tests := []struct {
2464 name string
2465 args args
2466 want uint32
2467 wantErr bool
2468 }{
2469 {
2470 name: "Positive_Case_GetPortID",
2471 args: args{
2472 port: "16777216",
2473 },
2474 want: 16777216,
2475 wantErr: false,
2476 },
2477 }
2478 for _, tt := range tests {
2479 t.Run(tt.name, func(t *testing.T) {
2480 va := &VoltApplication{
2481 PortsDisc: sync.Map{},
2482 }
2483 va.PortsDisc.Store("16777216", voltPort)
2484 got, err := va.GetPortID(tt.args.port)
2485 if (err != nil) != tt.wantErr {
2486 t.Errorf("VoltApplication.GetPortID() error = %v, wantErr %v", err, tt.wantErr)
2487 return
2488 }
2489 if got != tt.want {
2490 t.Errorf("VoltApplication.GetPortID() = %v, want %v", got, tt.want)
2491 }
2492 })
2493 }
2494}
2495
2496func TestVoltApplication_GetPortName(t *testing.T) {
2497 type args struct {
2498 port uint32
2499 }
2500 voltPort := &VoltPort{
2501 Name: "16777216",
2502 Device: "SDX6320031",
2503 ID: 16777216,
2504 State: PortStateDown,
2505 ChannelPerSubAlarmRaised: false,
2506 Type: VoltPortTypeNni,
2507 }
2508 tests := []struct {
2509 name string
2510 args args
2511 want string
2512 wantErr bool
2513 }{
2514 {
2515 name: "Positive_Case_GetPortID",
2516 args: args{
2517 port: 16777216,
2518 },
2519 want: "16777216",
2520 wantErr: false,
2521 },
2522 }
2523 for _, tt := range tests {
2524 t.Run(tt.name, func(t *testing.T) {
2525 va := &VoltApplication{
2526 PortsDisc: sync.Map{},
2527 }
2528 va.PortsDisc.Store("16777216", voltPort)
2529 got, err := va.GetPortName(tt.args.port)
2530 if (err != nil) != tt.wantErr {
2531 t.Errorf("VoltApplication.GetPortName() error = %v, wantErr %v", err, tt.wantErr)
2532 return
2533 }
2534 if got != tt.want {
2535 t.Errorf("VoltApplication.GetPortName() = %v, want %v", got, tt.want)
2536 }
2537 })
2538 }
2539}
2540
2541func TestVoltApplication_PortUpInd(t *testing.T) {
2542 type args struct {
2543 cntx context.Context
2544 device string
2545 port string
2546 }
2547 voltDev := &VoltDevice{
2548 Name: "SDX6320031",
2549 SerialNum: "SDX6320031",
2550 NniDhcpTrapVid: 123,
2551 NniPort: "16777472",
2552 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2553 Ports: sync.Map{},
2554 VpvsBySvlan: util.NewConcurrentMap(),
2555 }
2556 voltPort := &VoltPort{
2557 Name: "16777472",
2558 Device: "SDX6320031",
2559 ID: 16777472,
2560 State: PortStateUp,
2561 ChannelPerSubAlarmRaised: false,
2562 Type: VoltPortTypeNni,
2563 }
2564 voltServ := &VoltService{
2565 VoltServiceOper: VoltServiceOper{
2566 Device: "SDX6320031",
2567 },
2568 VoltServiceCfg: VoltServiceCfg{
2569 IsActivated: true,
2570 },
2571 }
2572 voltPortVnets := make([]*VoltPortVnet, 0)
2573 voltPortVnet := &VoltPortVnet{
2574 Device: "SDX6320031",
2575 Port: "16777472",
2576 DeleteInProgress: false,
2577 services: sync.Map{},
2578 SVlan: 4096,
2579 CVlan: 2310,
2580 UniVlan: 4096,
2581 SVlanTpid: 65,
2582 servicesCount: atomic.NewUint64(1),
2583 }
2584 voltPortVnets = append(voltPortVnets, voltPortVnet)
2585
2586 tests := []struct {
2587 name string
2588 args args
2589 }{
2590 {
2591 name: "Positive_Case_PortUpInd",
2592 args: args{
2593 cntx: context.Background(),
2594 port: "16777472",
2595 device: "SDX6320031",
2596 },
2597 },
2598 }
2599 for _, tt := range tests {
2600 t.Run(tt.name, func(t *testing.T) {
2601 va := &VoltApplication{
2602 DevicesDisc: sync.Map{},
2603 VnetsByPort: sync.Map{},
2604 }
2605 va.DevicesDisc.Store("SDX6320031", voltDev)
2606 voltDev.Ports.Store("16777472", voltPort)
2607 va.VnetsByPort.Store("16777472", voltPortVnets)
2608 voltPortVnet.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
2609 voltapp := GetApplication()
2610 voltapp.DevicesDisc.Store("SDX6320031", voltDev)
2611 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,
2629 NniPort: "16777472",
2630 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 }
2770 ServicesDeactivate := map[string]bool{}
2771 ServicesDeactivate["SDX6320031-1_SDX6320031-1-4096-2310-4096-65"] = true
2772 voltServ := &VoltService{
2773 VoltServiceOper: VoltServiceOper{
2774 Device: "SDX6320031",
2775 },
2776 VoltServiceCfg: VoltServiceCfg{
2777 Name: "SDX6320031-1_SDX6320031-1-4096-2310-4096-65",
2778 SVlan: 4096,
2779 CVlan: 2310,
2780 UniVlan: 4096,
2781 Port: "16777472",
2782 TechProfileID: 65,
2783 },
2784 }
2785
2786 voltPortVnets := make([]*VoltPortVnet, 0)
2787 voltPortVnet := &VoltPortVnet{
2788 Device: "SDX6320031",
2789 Port: "16777472",
2790 DeleteInProgress: false,
2791 services: sync.Map{},
2792 SVlan: 4096,
2793 CVlan: 2310,
2794 UniVlan: 4096,
2795 SVlanTpid: 65,
2796 servicesCount: atomic.NewUint64(1),
2797 }
2798
2799 voltPortVnets = append(voltPortVnets, voltPortVnet)
2800 tests := []struct {
2801 name string
2802 args args
2803 }{
2804 {
2805 name: "Positive_Case_DeleteMacInPortMap",
2806 args: args{
2807 cntx: context.Background(),
2808 device: "SDX6320031",
2809 },
2810 },
2811 }
2812
2813 for _, tt := range tests {
2814 t.Run(tt.name, func(t *testing.T) {
2815 va := &VoltApplication{
2816 ServicesToDeactivate: ServicesDeactivate,
2817 ServiceByName: sync.Map{},
2818 VnetsByPort: sync.Map{},
2819 }
2820 va.ServiceByName.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
2821 va.VnetsByPort.Store("16777472", voltPortVnets)
2822 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,
3142 NniPort: "16777472",
3143 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{},
3609 NniPort: "16777472",
3610 }
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}