blob: c687e55119bb028be6a139dd8233df5c4e8af9ab [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 "errors"
vinokuma02fbfd02023-07-05 15:23:33 +053022 "net"
23 "reflect"
vinokumaf7605fc2023-06-02 18:08:01 +053024 "sync"
25 "testing"
26 "voltha-go-controller/internal/pkg/controller"
27 cntlr "voltha-go-controller/internal/pkg/controller"
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/google/gopacket/layers"
34 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
35 "github.com/stretchr/testify/assert"
36 "go.uber.org/atomic"
37)
38
39var test_device = "test_device"
40var voltPort = &VoltPort{
41 Name: "test_name",
42 Device: test_device,
43}
44var voltDevice = &VoltDevice{
45 Name: "test_name",
46 State: controller.DeviceStateUP,
47 FlowAddEventMap: util.NewConcurrentMap(),
48 FlowDelEventMap: util.NewConcurrentMap(),
49 SerialNum: "test_serial_number",
50}
51
52var voltMeter = &VoltMeter{
vinokuma02fbfd02023-07-05 15:23:33 +053053 Name: "test_volt_meter",
54 Version: "test_version",
55 AssociatedServices: 3,
vinokumaf7605fc2023-06-02 18:08:01 +053056}
57
58var voltVnet = &VoltVnet{
59 Version: "test_version",
60 VnetConfig: VnetConfig{
61 Name: "test_name",
62 },
63}
64
65var voltPortVnet1 = []*VoltPortVnet{
66 {
67 Device: "4096-4096-4096",
68 SVlan: of.VlanAny,
69 CVlan: of.VlanAny,
70 UniVlan: of.VlanAny,
71 IgmpEnabled: true,
72 servicesCount: &atomic.Uint64{},
73 },
74}
75
76var voltDevice1 = &VoltDevice{
77 State: cntlr.DeviceStateDOWN,
78}
79
vinokuma02fbfd02023-07-05 15:23:33 +053080var voltDevice2 = &VoltDevice{
81 Name: "test_name",
82 State: controller.DeviceStateUP,
83 FlowAddEventMap: util.NewConcurrentMap(),
84 FlowDelEventMap: util.NewConcurrentMap(),
85 SerialNum: "test_serial_number",
86 MigratingServices: util.NewConcurrentMap(),
87}
88
89var voltService2 = &VoltService{
90 Version: "test_version",
91 VoltServiceCfg: VoltServiceCfg{
92 VnetID: "test_vnet_id",
93 Port: "test_port",
94 SVlan: of.VlanAny,
95 CVlan: of.VlanAny,
96 UniVlan: of.VlanAny,
97 },
98}
99
vinokumaf7605fc2023-06-02 18:08:01 +0530100var GetDeviceFromPort_error = "GetDeviceFromPort_error"
101
102func TestVoltApplication_RestoreSvcsFromDb(t *testing.T) {
103 type args struct {
104 cntx context.Context
105 }
106 tests := []struct {
107 name string
108 args args
109 }{
110 {
111 name: "VoltApplication_RestoreSvcsFromDb",
112 args: args{
113 cntx: context.Background(),
114 },
115 },
116 {
117 name: "invalid_value_type",
118 args: args{
119 cntx: context.Background(),
120 },
121 },
122 {
123 name: "unmarshal_error",
124 args: args{
125 cntx: context.Background(),
126 },
127 },
128 }
129 for _, tt := range tests {
130 t.Run(tt.name, func(t *testing.T) {
vinokuma02fbfd02023-07-05 15:23:33 +0530131 voltService4 := &VoltService{
vinokumaf7605fc2023-06-02 18:08:01 +0530132 VoltServiceOper: VoltServiceOper{
133 Device: "SDX6320031",
134 ForceDelete: true,
135 DeleteInProgress: true,
136 },
137 VoltServiceCfg: VoltServiceCfg{
138 Name: "test_service_name",
139 },
140 }
141 serviceToDelete := map[string]bool{}
vinokuma02fbfd02023-07-05 15:23:33 +0530142 serviceToDelete[voltService4.VoltServiceCfg.Name] = true
vinokumaf7605fc2023-06-02 18:08:01 +0530143 va := &VoltApplication{
144 ServicesToDelete: serviceToDelete,
145 }
146 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
147 db = dbintf
148 switch tt.name {
149 case "VoltApplication_RestoreSvcsFromDb":
150
vinokuma02fbfd02023-07-05 15:23:33 +0530151 b, err := json.Marshal(voltService4)
vinokumaf7605fc2023-06-02 18:08:01 +0530152 if err != nil {
153 panic(err)
154 }
155 kvPair := map[string]*kvstore.KVPair{}
156 kvPair["key"] = &kvstore.KVPair{
157 Key: "test_key",
158 Value: b,
159 Version: 1,
160 }
161 dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1)
162 va.RestoreSvcsFromDb(tt.args.cntx)
163 case "invalid_value_type":
164 kvPair := map[string]*kvstore.KVPair{}
165 kvPair["key"] = &kvstore.KVPair{
166 Key: "test_key",
167 Value: "invalid_value",
168 Version: 1,
169 }
170 dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1)
171 va.RestoreSvcsFromDb(tt.args.cntx)
172 case "unmarshal_error":
173 b, err := json.Marshal("test")
174 if err != nil {
175 panic(err)
176 }
177 kvPair := map[string]*kvstore.KVPair{}
178 kvPair["key"] = &kvstore.KVPair{
179 Key: "test_key",
180 Value: b,
181 Version: 1,
182 }
183 dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1)
184 va.RestoreSvcsFromDb(tt.args.cntx)
185 }
186 })
187 }
188}
189
190func TestVoltService_FlowRemoveFailure(t *testing.T) {
191 type args struct {
192 cntx context.Context
193 cookie string
194 errorCode uint32
195 errReason string
196 }
197 tests := []struct {
198 name string
199 args args
200 }{
201 {
202 name: "VoltService_FlowRemoveFailure",
203 args: args{
204 cntx: context.Background(),
205 cookie: "test_cookie",
206 errorCode: 200,
207 errReason: "test_reason",
208 },
209 },
210 {
211 name: "cookie_not_found",
212 args: args{
213 cntx: context.Background(),
214 cookie: "test_cookie",
215 errorCode: 200,
216 errReason: "test_reason",
217 },
218 },
219 }
220 for _, tt := range tests {
221 t.Run(tt.name, func(t *testing.T) {
222 switch tt.name {
223 case "VoltService_FlowRemoveFailure":
224 associatedFlows := map[string]bool{}
225 associatedFlows["test_cookie"] = true
226 vs := &VoltService{
227 VoltServiceOper: VoltServiceOper{
228 AssociatedFlows: associatedFlows,
229 },
230 }
231 vs.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.errorCode, tt.args.errReason)
232 case "cookie_not_found":
233 associatedFlows := map[string]bool{}
234 associatedFlows["cookie"] = true
235 vs := &VoltService{
236 VoltServiceOper: VoltServiceOper{
237 AssociatedFlows: associatedFlows,
238 },
239 }
240 vs.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.errorCode, tt.args.errReason)
241 }
242 })
243 }
244}
245
246func TestVoltApplication_GetServiceNameFromCookie(t *testing.T) {
247 type args struct {
248 cookie uint64
249 portName string
250 pbit uint8
251 device string
252 tableMetadata uint64
253 }
254 tests := []struct {
255 name string
256 args args
257 }{
258 {
259 name: "VoltApplication_GetServiceNameFromCookie",
260 args: args{
261 cookie: uint64(1),
262 portName: "test_port_name",
263 device: "SDX6320031",
264 pbit: 2,
265 tableMetadata: uint64(2),
266 },
267 },
268 }
269 voltDev := &VoltDevice{
270 Name: "SDX6320031",
271 SerialNum: "SDX6320031",
272 NniDhcpTrapVid: 123,
273 }
274 for _, tt := range tests {
275 t.Run(tt.name, func(t *testing.T) {
276 ga := GetApplication()
277 ga.DevicesDisc.Store("SDX6320031", voltDev)
278 voltPortVnets := make([]*VoltPortVnet, 0)
279 voltPortVnet := &VoltPortVnet{
280 Device: test_device,
281 VlanControl: ONUCVlanOLTSVlan,
282 }
283 voltPortVnets = append(voltPortVnets, voltPortVnet)
284 ga.VnetsByPort.Store("test_port_name", voltPortVnets)
285 got := ga.GetServiceNameFromCookie(tt.args.cookie, tt.args.portName, tt.args.pbit, tt.args.device, tt.args.tableMetadata)
286 assert.Nil(t, got)
287 })
288 }
289}
290
291func TestVoltService_SvcUpInd(t *testing.T) {
292 type args struct {
293 cntx context.Context
294 }
295 tests := []struct {
296 name string
297 args args
298 }{
299 {
300 name: "VoltService_SvcUpInd",
301 args: args{
302 cntx: context.Background(),
303 },
304 },
305 }
306 for _, tt := range tests {
307 t.Run(tt.name, func(t *testing.T) {
308 vs := &VoltService{
309 VoltServiceOper: VoltServiceOper{
310 PendingFlows: make(map[string]bool),
311 },
312 VoltServiceCfg: VoltServiceCfg{
313 SVlanTpid: layers.EthernetTypeDot1Q,
314 MacAddr: layers.EthernetBroadcast,
315 },
316 }
317 vs.Port = test_device
318 vs.Device = "device"
319 ga := GetApplication()
320 _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
321 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
322 db = dbintf
323 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
324 ga.PortsDisc.Store(test_device, voltPort)
325 ga.DevicesDisc.Store(test_device, voltDevice)
326 vs.SvcUpInd(tt.args.cntx)
327 })
328 }
329}
330
331func TestVoltService_SvcDownInd(t *testing.T) {
332 type args struct {
333 cntx context.Context
334 }
335 tests := []struct {
336 name string
337 args args
338 }{
339 {
340 name: "VoltService_SvcDownInd",
341 args: args{
342 cntx: context.Background(),
343 },
344 },
345 }
346 for _, tt := range tests {
347 t.Run(tt.name, func(t *testing.T) {
348 vs := &VoltService{
349 VoltServiceOper: VoltServiceOper{
350 UsHSIAFlowsApplied: true,
351 DsHSIAFlowsApplied: true,
352 },
353 VoltServiceCfg: VoltServiceCfg{
354 SVlanTpid: layers.EthernetTypeQinQ,
355 MacAddr: layers.EthernetBroadcast,
356 },
357 }
358 vs.Port = test_device
359 vs.Device = "device"
360 ga := GetApplication()
361 _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
362 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
363 db = dbintf
364 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
365 ga.PortsDisc.Store(test_device, voltPort)
366 ga.DevicesDisc.Store(test_device, voltDevice)
367 vs.SvcDownInd(tt.args.cntx)
368 })
369 }
370}
371
372func TestVoltApplication_AddService(t *testing.T) {
373 type args struct {
374 cntx context.Context
375 cfg VoltServiceCfg
376 oper *VoltServiceOper
377 }
378 tests := []struct {
379 name string
380 args args
381 }{
382 {
383 name: "VoltApplication_AddService",
384 args: args{
385 cntx: context.Background(),
386 cfg: VoltServiceCfg{
387 Name: "test_name",
388 Port: "test_port",
389 DsMeterProfile: "4096-4096-4096",
390 UsMeterProfile: "4096-4096-4096",
391 SVlan: of.VlanAny,
392 CVlan: of.VlanAny,
393 UniVlan: of.VlanAny,
394 MacLearning: Learn,
395 IsActivated: true,
396 },
397 oper: &VoltServiceOper{
398 Device: "4096-4096-4096",
399 },
400 },
401 },
402 }
403 for _, tt := range tests {
404 t.Run(tt.name, func(t *testing.T) {
405 va := &VoltApplication{
406 MeterMgr: MeterMgr{
407 Meters: sync.Map{},
408 },
409 VnetsByPort: sync.Map{},
410 VnetsByTag: sync.Map{},
411 }
412 va.MeterMgr.Meters.Store("4096-4096-4096", voltMeter)
413 va.VnetsByTag.Store("4096-4096-4096", voltVnet)
414 voltPortVnet1[0].SVlan = of.VlanAny
415 voltPortVnet1[0].CVlan = of.VlanAny
416 voltPortVnet1[0].UniVlan = of.VlanAny
417 voltPortVnet1[0].servicesCount = atomic.NewUint64(uint64(56))
418 voltPortVnet1[0].MacAddr = layers.EthernetBroadcast
419 voltPortVnet1[0].Port = "test_port"
420 va.VnetsByPort.Store("test_port", voltPortVnet1)
421 ga := GetApplication()
422 voltPort1 := &VoltPort{
423 Name: "test_name",
424 Device: test_device,
425 }
426 deviceConfig := &DeviceConfig{
427 SerialNumber: "test_serial_number",
428 }
429 ga.PortsDisc.Store("test_port", voltPort1)
430 ga.DevicesDisc.Store(test_device, voltDevice)
431 ga.DevicesConfig.Store("test_serial_number", deviceConfig)
432 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
433 db = dbintf
434 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
435 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
436 err := va.AddService(tt.args.cntx, tt.args.cfg, tt.args.oper)
437 assert.Nil(t, err)
438 })
439 }
440}
441
442func TestVoltApplication_DelService(t *testing.T) {
443 type args struct {
444 cntx context.Context
445 name string
446 forceDelete bool
447 newSvc *VoltServiceCfg
448 serviceMigration bool
449 }
450 tests := []struct {
451 name string
452 args args
453 }{
454 {
455 name: "VoltApplication_DelService",
456 args: args{
457 cntx: context.Background(),
458 name: "test_name",
459 forceDelete: true,
460 newSvc: &VoltServiceCfg{
461 Name: "vs_cfg_name",
462 Port: "test_port",
463 },
464 serviceMigration: true,
465 },
466 },
vinokuma02fbfd02023-07-05 15:23:33 +0530467 {
468 name: "GetMeterByID_not_nil",
469 args: args{
470 cntx: context.Background(),
471 name: "test_name",
472 forceDelete: true,
473 newSvc: &VoltServiceCfg{
474 Name: "vs_cfg_name",
475 Port: "test_port",
476 },
477 serviceMigration: true,
478 },
479 },
vinokumaf7605fc2023-06-02 18:08:01 +0530480 }
481 for _, tt := range tests {
482 t.Run(tt.name, func(t *testing.T) {
483 va := &VoltApplication{
484 ServiceByName: sync.Map{},
485 VnetsByPort: sync.Map{},
486 }
vinokuma02fbfd02023-07-05 15:23:33 +0530487 voltService3 := &VoltService{
vinokumaf7605fc2023-06-02 18:08:01 +0530488 Version: "test_version",
489 VoltServiceCfg: VoltServiceCfg{
490 Port: "4096-4096-4096",
491 SVlan: of.VlanAny,
492 CVlan: of.VlanAny,
493 UniVlan: of.VlanAny,
494 },
495 }
vinokuma02fbfd02023-07-05 15:23:33 +0530496 switch tt.name {
497 case "VoltApplication_DelService":
498 va.ServiceByName.Store(tt.args.name, voltService3)
499 va.VnetsByPort.Store("4096-4096-4096", voltPortVnet1)
500 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
501 db = dbintf
502 dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes()
503 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
504 va.DelService(tt.args.cntx, tt.args.name, tt.args.forceDelete, tt.args.newSvc, tt.args.serviceMigration)
505 case "GetMeterByID_not_nil":
506 va.ServiceByName.Store(tt.args.name, voltService3)
507 va.VnetsByPort.Store("4096-4096-4096", voltPortVnet1)
508 voltService3.AggDsMeterID = uint32(1)
509 voltService3.DsMeterID = uint32(1)
510 voltService3.UsMeterID = uint32(2)
511 va.MeterMgr.MetersByID.Store(voltService3.AggDsMeterID, voltMeter)
512 va.MeterMgr.MetersByID.Store(voltService3.DsMeterID, voltMeter)
513 va.MeterMgr.MetersByID.Store(voltService3.UsMeterID, voltMeter)
514 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
515 db = dbintf
516 dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes()
517 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
518 va.DelService(tt.args.cntx, tt.args.name, tt.args.forceDelete, tt.args.newSvc, tt.args.serviceMigration)
519 }
vinokumaf7605fc2023-06-02 18:08:01 +0530520 })
521 }
522}
523
524func TestVoltService_FlowInstallSuccess(t *testing.T) {
525 type args struct {
526 cntx context.Context
527 cookie string
528 bwAvailInfo of.BwAvailDetails
529 }
530 tests := []struct {
531 name string
532 args args
533 }{
534 {
535 name: "VoltService_FlowInstallSuccess",
536 args: args{
537 cntx: context.Background(),
538 cookie: "test_cookie",
539 bwAvailInfo: of.BwAvailDetails{
540 PrevBw: "test_prev_BW",
541 PresentBw: "test_present_BW",
542 },
543 },
544 },
545 }
546 for _, tt := range tests {
547 t.Run(tt.name, func(t *testing.T) {
548 pendingFlows := map[string]bool{}
549 pendingFlows["test_cookie"] = true
550 associatedFlows := map[string]bool{}
551 associatedFlows["test_cookie"] = true
552 vs := &VoltService{
553 VoltServiceOper: VoltServiceOper{
554 PendingFlows: pendingFlows,
555 AssociatedFlows: associatedFlows,
556 DsHSIAFlowsApplied: true,
557 },
558 VoltServiceCfg: VoltServiceCfg{
559 Port: "test_port",
560 },
561 }
562 ga := GetApplication()
563 ga.PortsDisc.Store("test_port", voltPort)
564 ga.DevicesDisc.Store(test_device, voltDevice)
565 vs.FlowInstallSuccess(tt.args.cntx, tt.args.cookie, tt.args.bwAvailInfo)
566 })
567 }
568}
569
570func TestVoltService_AddMeterToDevice(t *testing.T) {
571 type args struct {
572 cntx context.Context
573 }
574 tests := []struct {
575 name string
576 args args
577 wantErr bool
578 }{
579 {
580 name: "VoltService_AddMeterToDevice",
581 args: args{
582 cntx: context.Background(),
583 },
584 },
585 {
586 name: GetDeviceFromPort_error,
587 args: args{
588 cntx: context.Background(),
589 },
590 },
591 {
592 name: "DeviceState_down",
593 args: args{
594 cntx: context.Background(),
595 },
596 },
597 }
598 for _, tt := range tests {
599 t.Run(tt.name, func(t *testing.T) {
600 switch tt.name {
601 case "VoltService_AddMeterToDevice":
602 vs := &VoltService{
603 VoltServiceOper: VoltServiceOper{
604 DeleteInProgress: true,
605 },
606 VoltServiceCfg: VoltServiceCfg{
607 Port: "test_port",
608 },
609 }
610 ga := GetApplication()
611 ga.PortsDisc.Store("test_port", voltPort)
612 ga.DevicesDisc.Store(test_device, voltDevice)
613 err := vs.AddMeterToDevice(tt.args.cntx)
614 assert.Nil(t, err)
615 case GetDeviceFromPort_error:
616 vs := &VoltService{
617 VoltServiceOper: VoltServiceOper{
618 DeleteInProgress: true,
619 },
620 VoltServiceCfg: VoltServiceCfg{
621 Port: "",
622 },
623 }
624 err := vs.AddMeterToDevice(tt.args.cntx)
625 assert.NotNil(t, err)
626 case "DeviceState_down":
627 vs := &VoltService{
628 VoltServiceOper: VoltServiceOper{
629 DeleteInProgress: true,
630 },
631 VoltServiceCfg: VoltServiceCfg{
632 Port: "test_port",
633 },
634 }
635 ga := GetApplication()
636 ga.PortsDisc.Store("test_port", voltPort)
637 ga.DevicesDisc.Store(test_device, voltDevice1)
638 err := vs.AddMeterToDevice(tt.args.cntx)
639 assert.Nil(t, err)
640 }
641 })
642 }
643}
644
645func TestVoltService_AddUsHsiaFlows(t *testing.T) {
646 type args struct {
647 cntx context.Context
648 }
649 tests := []struct {
650 name string
651 args args
652 wantErr bool
653 }{
654 {
655 name: "DeleteInProgress_true",
656 args: args{
657 cntx: context.Background(),
658 },
659 },
660 {
661 name: "GetDeviceFromPort_error",
662 args: args{
663 cntx: context.Background(),
664 },
665 },
666 {
667 name: "DeviceState_down",
668 args: args{
669 cntx: context.Background(),
670 },
671 },
672 }
673 for _, tt := range tests {
674 t.Run(tt.name, func(t *testing.T) {
675 switch tt.name {
676 case "DeleteInProgress_true":
677 vs := &VoltService{
678 VoltServiceOper: VoltServiceOper{
679 DeleteInProgress: true,
680 },
681 }
682 err := vs.AddUsHsiaFlows(tt.args.cntx)
683 assert.Nil(t, err)
684 case "GetDeviceFromPort_error":
685 vs := &VoltService{
686 VoltServiceOper: VoltServiceOper{
687 DeleteInProgress: false,
688 },
689 }
690 err := vs.AddUsHsiaFlows(tt.args.cntx)
691 assert.NotNil(t, err)
692 case "DeviceState_down":
693 vs := &VoltService{
694 VoltServiceOper: VoltServiceOper{
695 DeleteInProgress: false,
696 },
697 VoltServiceCfg: VoltServiceCfg{
698 Port: "test_port",
699 },
700 }
701 ga := GetApplication()
702 ga.PortsDisc.Store("test_port", voltPort)
703 ga.DevicesDisc.Store(test_device, voltDevice1)
704 err := vs.AddUsHsiaFlows(tt.args.cntx)
705 assert.Nil(t, err)
706 }
707 })
708 }
709}
710
711func TestVoltService_AddHsiaFlows(t *testing.T) {
712 type args struct {
713 cntx context.Context
714 }
715 tests := []struct {
716 name string
717 args args
718 }{
719 {
720 name: "AddUsHsiaFlows_error",
721 args: args{
722 cntx: context.Background(),
723 },
724 },
725 }
726 for _, tt := range tests {
727 t.Run(tt.name, func(t *testing.T) {
728 vs := &VoltService{
729 VoltServiceCfg: VoltServiceCfg{
730 Port: "test_port",
731 VlanControl: 5,
732 },
733 }
734 ga := GetApplication()
735 ga.PortsDisc.Store("test_port", voltPort)
736 ga.DevicesDisc.Store(test_device, voltDevice)
737 vs.AddHsiaFlows(tt.args.cntx)
738 })
739 }
740}
741
742func TestVoltService_ForceWriteToDb(t *testing.T) {
743 type args struct {
744 cntx context.Context
745 }
746 tests := []struct {
747 name string
748 args args
749 }{
750 {
751 name: "PutService_error",
752 args: args{
753 cntx: context.Background(),
754 },
755 },
756 }
757 for _, tt := range tests {
758 t.Run(tt.name, func(t *testing.T) {
759 switch tt.name {
760 case "PutService_error":
761 vs := &VoltService{}
762 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
763 db = dbintf
764 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("error")).AnyTimes()
765 vs.ForceWriteToDb(tt.args.cntx)
766 }
767 })
768 }
769}
770
771func TestVoltService_isDataRateAttrPresent(t *testing.T) {
772 tests := []struct {
773 name string
774 want bool
775 }{
776 {
777 name: "VoltService_isDataRateAttrPresent",
778 },
779 }
780 for _, tt := range tests {
781 t.Run(tt.name, func(t *testing.T) {
782 vs := &VoltService{}
783 if got := vs.isDataRateAttrPresent(); got != tt.want {
784 t.Errorf("VoltService.isDataRateAttrPresent() = %v, want %v", got, tt.want)
785 }
786 })
787 }
788}
789
790func TestVoltService_GetServicePbit(t *testing.T) {
791 tests := []struct {
792 name string
793 want int
794 }{
795 {
796 name: "VoltService_GetServicePbit",
797 want: -1,
798 },
799 {
800 name: "!IsPbitExist",
801 want: 8,
802 },
803 }
804 for _, tt := range tests {
805 t.Run(tt.name, func(t *testing.T) {
806 switch tt.name {
807 case "VoltService_GetServicePbit":
808 vs := &VoltService{
809 VoltServiceCfg: VoltServiceCfg{
810 Pbits: []of.PbitType{of.PbitMatchAll},
811 },
812 }
813 if got := vs.GetServicePbit(); got != tt.want {
814 t.Errorf("VoltService.GetServicePbit() = %v, want %v", got, tt.want)
815 }
816 case "!IsPbitExist":
817 vs := &VoltService{}
818 if got := vs.GetServicePbit(); got != tt.want {
819 t.Errorf("VoltService.GetServicePbit() = %v, want %v", got, tt.want)
820 }
821 }
822 })
823 }
824}
825
826func TestVoltApplication_DeactivateService(t *testing.T) {
827 type args struct {
828 cntx context.Context
829 deviceID string
830 portNo string
831 sVlan of.VlanType
832 cVlan of.VlanType
833 tpID uint16
834 }
835 tests := []struct {
836 name string
837 args args
838 wantErr bool
839 }{
840 {
841 name: "VoltApplication_DeactivateService",
842 args: args{
843 cntx: context.Background(),
844 deviceID: "test_device_id",
845 portNo: "test_port",
846 sVlan: of.VlanNone,
847 cVlan: of.VlanAny,
848 tpID: AnyVlan,
849 },
850 },
851 {
852 name: "VoltPortVnet_nil",
853 args: args{
854 cntx: context.Background(),
855 deviceID: "test_device_id",
856 portNo: "test_port",
857 sVlan: of.VlanNone,
858 cVlan: of.VlanAny,
859 tpID: AnyVlan,
860 },
861 },
862 {
863 name: "sVlan != of.VlanNone",
864 args: args{
865 cntx: context.Background(),
866 deviceID: "test_device_id",
867 portNo: "test_port",
868 sVlan: of.VlanAny,
869 cVlan: of.VlanAny,
870 tpID: AnyVlan,
871 },
872 },
873 {
874 name: GetDeviceFromPort_error,
875 args: args{
876 cntx: context.Background(),
877 deviceID: "test_device_id",
878 portNo: "test_port",
879 sVlan: of.VlanNone,
880 cVlan: of.VlanAny,
881 tpID: AnyVlan,
882 },
883 },
884 }
885 for _, tt := range tests {
886 t.Run(tt.name, func(t *testing.T) {
887 va := &VoltApplication{
888 ServiceByName: sync.Map{},
889 VnetsByPort: sync.Map{},
890 DevicesDisc: sync.Map{},
891 PortsDisc: sync.Map{},
892 }
893 voltServiceTest := &VoltService{
894 VoltServiceOper: VoltServiceOper{
895 Device: test_device,
896 },
897 Version: "test_version",
898 VoltServiceCfg: VoltServiceCfg{
899 Port: "test_port",
900 Name: "test_name",
901 IsActivated: true,
902 CVlan: of.VlanAny,
903 SVlan: of.VlanAny,
904 UniVlan: of.VlanAny,
905 },
906 }
907 switch tt.name {
908 case "VoltApplication_DeactivateService":
909 va.ServiceByName.Store("test_name", voltServiceTest)
910 va.PortsDisc.Store("test_port", voltPort)
911 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
912 db = dbintf
913 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
914 va.DevicesDisc.Store(test_device, voltDevice)
915 voltDevice.Ports.Store("test_port", voltPort)
916 va.VnetsByPort.Store("test_port", voltPortVnet1)
917 voltPortVnet1[0].servicesCount.Store(uint64(1))
918 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
919 if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
920 t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
921 }
922 case "VoltPortVnet_nil":
923 va.ServiceByName.Store("test_name", voltServiceTest)
924 va.PortsDisc.Store("test_port", voltPort)
925 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
926 db = dbintf
927 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
928 va.DevicesDisc.Store(test_device, voltDevice)
929 voltDevice.Ports.Store("test_port", voltPort)
930 if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
931 t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
932 }
933 case "sVlan != of.VlanNone":
934 va.ServiceByName.Store("test_name", voltServiceTest)
935 if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
936 t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
937 }
938 case GetDeviceFromPort_error:
939 va.ServiceByName.Store("test_name", voltServiceTest)
940 if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
941 t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
942 }
943 }
944 })
945 }
946}
947
948func TestVoltApplication_ActivateService(t *testing.T) {
949 type args struct {
950 cntx context.Context
951 deviceID string
952 portNo string
953 sVlan of.VlanType
954 cVlan of.VlanType
955 tpID uint16
956 }
957 tests := []struct {
958 name string
959 args args
960 wantErr bool
961 }{
962 {
963 name: "VoltApplication_ActivateService",
964 args: args{
965 cntx: context.Background(),
vinokuma02fbfd02023-07-05 15:23:33 +0530966 deviceID: DeviceAny,
vinokumaf7605fc2023-06-02 18:08:01 +0530967 portNo: "test_port",
968 sVlan: of.VlanNone,
969 cVlan: of.VlanAny,
970 tpID: AnyVlan,
971 },
972 },
973 {
974 name: "VoltPortVnet_nil",
975 args: args{
976 cntx: context.Background(),
977 deviceID: "test_name",
978 portNo: "test_port",
979 sVlan: of.VlanNone,
980 cVlan: of.VlanAny,
981 tpID: AnyVlan,
982 },
983 },
984 {
985 name: GetDeviceFromPort_error,
986 args: args{
987 cntx: context.Background(),
988 deviceID: "test_name",
989 portNo: "test_port",
990 sVlan: of.VlanNone,
991 cVlan: of.VlanAny,
992 tpID: AnyVlan,
993 },
994 },
vinokuma02fbfd02023-07-05 15:23:33 +0530995 {
996 name: "deviceID != device.Name",
997 args: args{
998 cntx: context.Background(),
999 deviceID: "test_name1",
1000 portNo: "test_port",
1001 sVlan: of.VlanNone,
1002 cVlan: of.VlanAny,
1003 tpID: AnyVlan,
1004 },
1005 },
1006 {
1007 name: "sVlan != of.VlanNone && sVlan != vs.SVlan",
1008 args: args{
1009 cntx: context.Background(),
1010 deviceID: "test_name",
1011 portNo: "test_port",
1012 sVlan: 1,
1013 cVlan: of.VlanAny,
1014 tpID: AnyVlan,
1015 },
1016 },
vinokumaf7605fc2023-06-02 18:08:01 +05301017 }
1018 for _, tt := range tests {
1019 t.Run(tt.name, func(t *testing.T) {
1020 va := &VoltApplication{
1021 DevicesDisc: sync.Map{},
1022 }
1023 var voltPortTest = &VoltPort{
1024 Name: "test_name",
1025 State: PortStateUp,
1026 }
1027 voltServiceTest := &VoltService{
1028 VoltServiceOper: VoltServiceOper{
1029 Device: test_device,
1030 },
1031 Version: "test_version",
1032 VoltServiceCfg: VoltServiceCfg{
1033 Port: "test_port",
1034 Name: "test_name",
1035 IsActivated: false,
1036 CVlan: of.VlanAny,
1037 SVlan: of.VlanAny,
1038 UniVlan: of.VlanAny,
1039 },
1040 }
1041 switch tt.name {
1042 case "VoltApplication_ActivateService":
1043 voltPortTest.Device = test_device
1044 va.PortsDisc.Store("test_port", voltPortTest)
1045 va.DevicesDisc.Store(test_device, voltDevice)
1046 va.ServiceByName.Store("test_name", voltServiceTest)
1047 va.VnetsByPort.Store("test_port", voltPortVnet1)
1048 voltDevice.Ports.Store("test_port", voltPortTest)
1049 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1050 db = dbintf
1051 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1052 if err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
1053 t.Errorf("VoltApplication.ActivateService() error = %v, wantErr %v", err, tt.wantErr)
1054 }
1055 case "VoltPortVnet_nil":
1056 voltPortTest.Device = test_device
1057 va.ServiceByName.Store("test_name", voltServiceTest)
1058 va.PortsDisc.Store("test_port", voltPortTest)
1059 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1060 db = dbintf
1061 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1062 va.DevicesDisc.Store(test_device, voltDevice)
1063 voltDevice.Ports.Store("test_port", voltPortTest)
1064 if err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
1065 t.Errorf("VoltApplication.ActivateService() error = %v, wantErr %v", err, tt.wantErr)
1066 }
1067 case GetDeviceFromPort_error:
1068 err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID)
1069 assert.NotNil(t, err)
vinokuma02fbfd02023-07-05 15:23:33 +05301070 case "deviceID != device.Name":
1071 var voltPortTest1 = &VoltPort{
1072 Name: "test_name",
1073 State: PortStateUp,
1074 Device: test_device,
1075 }
1076 var voltDevice_test = &VoltDevice{
1077 Name: "",
1078 State: controller.DeviceStateUP,
1079 FlowAddEventMap: util.NewConcurrentMap(),
1080 FlowDelEventMap: util.NewConcurrentMap(),
1081 SerialNum: "test_serial_number",
1082 }
1083 va.PortsDisc.Store("test_port", voltPortTest1)
1084 va.DevicesDisc.Store(test_device, voltDevice_test)
1085 err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID)
1086 assert.NotNil(t, err)
1087 case "sVlan != of.VlanNone && sVlan != vs.SVlan":
1088 voltPortTest.Device = test_device
1089 va.PortsDisc.Store("test_port", voltPortTest)
1090 va.DevicesDisc.Store(test_device, voltDevice)
1091 va.ServiceByName.Store("test_name", voltServiceTest)
1092 if err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
1093 t.Errorf("VoltApplication.ActivateService() error = %v, wantErr %v", err, tt.wantErr)
1094 }
vinokumaf7605fc2023-06-02 18:08:01 +05301095 }
1096 })
1097 }
1098}
1099
1100func TestVoltApplication_GetProgrammedSubscribers(t *testing.T) {
1101 type args struct {
1102 cntx context.Context
1103 deviceID string
1104 portNo string
1105 }
1106 tests := []struct {
1107 name string
1108 args args
1109 want []*VoltService
1110 wantErr bool
1111 }{
1112 {
1113 name: "VoltApplication_GetProgrammedSubscribers",
1114 args: args{
1115 cntx: context.Background(),
1116 deviceID: test_device,
1117 portNo: "test_port",
1118 },
1119 },
1120 {
1121 name: "portNo_nil",
1122 args: args{
1123 cntx: context.Background(),
1124 deviceID: test_device,
1125 },
1126 },
1127 {
1128 name: "deviceID_nil",
1129 args: args{
1130 cntx: context.Background(),
1131 },
1132 },
1133 }
1134 for _, tt := range tests {
1135 t.Run(tt.name, func(t *testing.T) {
1136 va := &VoltApplication{
1137 vendorID: "test_vendor",
1138 }
1139 voltServiceTest := &VoltService{
1140 VoltServiceOper: VoltServiceOper{
1141 Device: test_device,
1142 },
1143 Version: "test_version",
1144 VoltServiceCfg: VoltServiceCfg{
1145 Port: "test_port",
1146 Name: "test_name",
1147 IsActivated: false,
1148 CVlan: of.VlanAny,
1149 SVlan: of.VlanAny,
1150 UniVlan: of.VlanAny,
1151 },
1152 }
1153 switch tt.name {
1154 case "VoltApplication_GetProgrammedSubscribers":
1155 va.ServiceByName.Store("test_name", voltServiceTest)
1156 got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo)
1157 assert.NotNil(t, got)
1158 assert.Nil(t, err)
1159 case "portNo_nil":
1160 va.ServiceByName.Store("test_name", voltServiceTest)
1161 got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo)
1162 assert.NotNil(t, got)
1163 assert.Nil(t, err)
1164 case "deviceID_nil":
1165 va.ServiceByName.Store("test_name", voltServiceTest)
1166 got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo)
1167 assert.NotNil(t, got)
1168 assert.Nil(t, err)
1169 }
1170 })
1171 }
1172}
1173
1174func TestVoltService_JSONMarshal(t *testing.T) {
1175 tests := []struct {
1176 name string
1177 }{
1178 {
1179 name: "VoltService_JSONMarshal",
1180 },
1181 }
1182 for _, tt := range tests {
1183 t.Run(tt.name, func(t *testing.T) {
1184 vs := &VoltService{
1185 VoltServiceOper: VoltServiceOper{
1186 Device: test_device,
1187 },
1188 Version: "test_version",
1189 VoltServiceCfg: VoltServiceCfg{
1190 Name: "test_name",
1191 },
1192 }
1193 got, err := vs.JSONMarshal()
1194 assert.NotNil(t, got)
1195 assert.Nil(t, err)
1196 })
1197 }
1198}
1199
1200func TestVoltService_triggerServiceInProgressInd(t *testing.T) {
1201 tests := []struct {
1202 name string
1203 }{
1204 {
1205 name: "VoltService_triggerServiceInProgressInd",
1206 },
1207 }
1208 for _, tt := range tests {
1209 t.Run(tt.name, func(t *testing.T) {
1210 vs := &VoltService{
1211 Version: "test_version",
1212 }
1213 vs.triggerServiceInProgressInd()
1214 })
1215 }
1216}
1217
1218func TestVoltService_TriggerAssociatedFlowDelete(t *testing.T) {
1219 type args struct {
1220 cntx context.Context
1221 }
1222 tests := []struct {
1223 name string
1224 args args
1225 want bool
1226 }{
1227 {
1228 name: "VoltService_TriggerAssociatedFlowDelete",
1229 args: args{
1230 cntx: context.Background(),
1231 },
1232 want: true,
1233 },
1234 {
1235 name: "cookieList_nil",
1236 args: args{
1237 cntx: context.Background(),
1238 },
1239 want: false,
1240 },
1241 }
1242 associatedFlows := map[string]bool{}
1243 associatedFlows["5765317"] = true
1244 for _, tt := range tests {
1245 t.Run(tt.name, func(t *testing.T) {
1246 switch tt.name {
1247 case "VoltService_TriggerAssociatedFlowDelete":
1248 vs := &VoltService{
1249 VoltServiceOper: VoltServiceOper{
1250 UsHSIAFlowsApplied: true,
1251 DsHSIAFlowsApplied: true,
1252 AssociatedFlows: associatedFlows,
1253 Device: test_device,
1254 },
1255 }
1256 ga := GetApplication()
1257 ga.DevicesDisc.Store(test_device, voltDevice)
1258 if got := vs.TriggerAssociatedFlowDelete(tt.args.cntx); got != tt.want {
1259 t.Errorf("VoltService.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want)
1260 }
1261 case "cookieList_nil":
1262 vs := &VoltService{
1263 VoltServiceOper: VoltServiceOper{
1264 UsHSIAFlowsApplied: true,
1265 DsHSIAFlowsApplied: true,
1266 Device: test_device,
1267 },
1268 }
1269 ga := GetApplication()
1270 ga.DevicesDisc.Store(test_device, voltDevice)
1271 if got := vs.TriggerAssociatedFlowDelete(tt.args.cntx); got != tt.want {
1272 t.Errorf("VoltService.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want)
1273 }
1274 }
1275 })
1276 }
1277}
1278
1279func TestVoltApplication_DeepEqualServicecfg(t *testing.T) {
1280 type args struct {
1281 evs *VoltServiceCfg
1282 nvs *VoltServiceCfg
1283 }
1284 a := map[int]int{}
1285 a[0] = 0
1286 tests := []struct {
1287 name string
1288 args args
1289 want bool
1290 }{
1291 {
1292 name: "VoltApplication_DeepEqualServicecfg",
1293 args: args{
1294 evs: &VoltServiceCfg{
1295 Port: "test_port",
1296 },
1297 nvs: &VoltServiceCfg{
1298 Port: "test_port",
1299 },
1300 },
1301 want: true,
1302 },
1303 {
1304 name: "nvs.Name != evs.Name",
1305 args: args{
1306 evs: &VoltServiceCfg{
1307 Name: "test_name",
1308 },
1309 nvs: &VoltServiceCfg{
1310 Port: "test_port",
1311 },
1312 },
1313 want: false,
1314 },
1315 {
1316 name: "nvs.UniVlan != evs.UniVlan",
1317 args: args{
1318 evs: &VoltServiceCfg{
1319 UniVlan: of.VlanAny,
1320 },
1321 nvs: &VoltServiceCfg{
1322 Port: "test_port",
1323 },
1324 },
1325 want: false,
1326 },
1327 {
1328 name: "nvs.CVlan != evs.CVlan",
1329 args: args{
1330 evs: &VoltServiceCfg{
1331 CVlan: of.VlanAny,
1332 },
1333 nvs: &VoltServiceCfg{
1334 Port: "test_port",
1335 },
1336 },
1337 want: false,
1338 },
1339 {
1340 name: "nvs.SVlan != evs.SVlan",
1341 args: args{
1342 evs: &VoltServiceCfg{
1343 SVlan: of.VlanAny,
1344 },
1345 nvs: &VoltServiceCfg{
1346 Port: "test_port",
1347 },
1348 },
1349 want: false,
1350 },
1351 {
1352 name: "nvs.SVlanTpid != 0",
1353 args: args{
1354 evs: &VoltServiceCfg{
1355 SVlanTpid: layers.EthernetTypeARP,
1356 },
1357 nvs: &VoltServiceCfg{
1358 SVlanTpid: layers.EthernetTypeCiscoDiscovery,
1359 },
1360 },
1361 want: false,
1362 },
1363 {
1364 name: "nvs.Pbits != evs.Pbits",
1365 args: args{
1366 evs: &VoltServiceCfg{
1367 Pbits: []of.PbitType{
1368 PbitMatchAll,
1369 },
1370 },
1371 nvs: &VoltServiceCfg{
1372 Port: "test_port",
1373 },
1374 },
1375 want: false,
1376 },
1377 {
1378 name: "nvs.DsRemarkPbitsMap != evs.DsRemarkPbitsMap",
1379 args: args{
1380 evs: &VoltServiceCfg{
1381 DsRemarkPbitsMap: a,
1382 },
1383 nvs: &VoltServiceCfg{
1384 Port: "test_port",
1385 },
1386 },
1387 want: false,
1388 },
1389 {
1390 name: "nvs.TechProfileID != evs.TechProfileID",
1391 args: args{
1392 evs: &VoltServiceCfg{
1393 TechProfileID: uint16(1),
1394 },
1395 nvs: &VoltServiceCfg{
1396 Port: "test_port",
1397 },
1398 },
1399 want: false,
1400 },
1401 {
1402 name: "nvs.CircuitID != evs.CircuitID",
1403 args: args{
1404 evs: &VoltServiceCfg{
1405 CircuitID: "test_circuit_id",
1406 },
1407 nvs: &VoltServiceCfg{
1408 Port: "test_port",
1409 },
1410 },
1411 want: false,
1412 },
1413 {
1414 name: "nvs.RemoteID != evs.RemoteID",
1415 args: args{
1416 evs: &VoltServiceCfg{
1417 RemoteID: []byte{1},
1418 },
1419 nvs: &VoltServiceCfg{
1420 Port: "test_port",
1421 },
1422 },
1423 want: false,
1424 },
1425 {
1426 name: "nvs.Port != evs.Port",
1427 args: args{
1428 evs: &VoltServiceCfg{},
1429 nvs: &VoltServiceCfg{
1430 Port: "test_port",
1431 },
1432 },
1433 want: false,
1434 },
1435 {
1436 name: "nvs.PonPort != evs.PonPort",
1437 args: args{
1438 evs: &VoltServiceCfg{},
1439 nvs: &VoltServiceCfg{
1440 PonPort: uint32(1),
1441 },
1442 },
1443 want: false,
1444 },
1445 {
1446 name: "evs.MacLearning == MacLearningNone",
1447 args: args{
1448 evs: &VoltServiceCfg{
1449 MacAddr: layers.EthernetBroadcast,
1450 },
1451 nvs: &VoltServiceCfg{},
1452 },
1453 want: false,
1454 },
1455 {
1456 name: "nvs.IgmpEnabled != evs.IgmpEnabled",
1457 args: args{
1458 evs: &VoltServiceCfg{
1459 IgmpEnabled: true,
1460 },
1461 nvs: &VoltServiceCfg{},
1462 },
1463 want: false,
1464 },
1465 {
1466 name: "nvs.McastService != evs.McastService",
1467 args: args{
1468 evs: &VoltServiceCfg{
1469 McastService: true,
1470 },
1471 nvs: &VoltServiceCfg{},
1472 },
1473 want: false,
1474 },
1475 {
1476 name: "nvs.ONTEtherTypeClassification != evs.ONTEtherTypeClassification",
1477 args: args{
1478 evs: &VoltServiceCfg{
1479 ONTEtherTypeClassification: 1,
1480 },
1481 nvs: &VoltServiceCfg{},
1482 },
1483 want: false,
1484 },
1485 {
1486 name: "nvs.UsMeterProfile != evs.UsMeterProfile",
1487 args: args{
1488 evs: &VoltServiceCfg{
1489 UsMeterProfile: "UsMeterProfile",
1490 },
1491 nvs: &VoltServiceCfg{},
1492 },
1493 want: false,
1494 },
1495 {
1496 name: "nvs.DsMeterProfile != evs.DsMeterProfile",
1497 args: args{
1498 evs: &VoltServiceCfg{
1499 DsMeterProfile: "DsMeterProfile",
1500 },
1501 nvs: &VoltServiceCfg{},
1502 },
1503 want: false,
1504 },
1505 {
1506 name: "nvs.AggDsMeterProfile != evs.AggDsMeterProfile",
1507 args: args{
1508 evs: &VoltServiceCfg{
1509 AggDsMeterProfile: "AggDsMeterProfile",
1510 },
1511 nvs: &VoltServiceCfg{},
1512 },
1513 want: false,
1514 },
1515 {
1516 name: "nvs.VnetID != evs.VnetID",
1517 args: args{
1518 evs: &VoltServiceCfg{
1519 VnetID: "VnetID",
1520 },
1521 nvs: &VoltServiceCfg{},
1522 },
1523 want: false,
1524 },
1525 {
1526 name: "nvs.MvlanProfileName != evs.MvlanProfileName",
1527 args: args{
1528 evs: &VoltServiceCfg{
1529 MvlanProfileName: "MvlanProfileName",
1530 },
1531 nvs: &VoltServiceCfg{},
1532 },
1533 want: false,
1534 },
1535 {
1536 name: "nvs.RemoteIDType != evs.RemoteIDType",
1537 args: args{
1538 evs: &VoltServiceCfg{
1539 RemoteIDType: "RemoteIDType",
1540 },
1541 nvs: &VoltServiceCfg{},
1542 },
1543 want: false,
1544 },
1545 {
1546 name: "nvs.SchedID != evs.SchedID",
1547 args: args{
1548 evs: &VoltServiceCfg{
1549 SchedID: 1,
1550 },
1551 nvs: &VoltServiceCfg{},
1552 },
1553 want: false,
1554 },
1555 {
1556 name: "nvs.AllowTransparent != evs.AllowTransparent",
1557 args: args{
1558 evs: &VoltServiceCfg{
1559 AllowTransparent: true,
1560 },
1561 nvs: &VoltServiceCfg{},
1562 },
1563 want: false,
1564 },
1565 {
1566 name: "nvs.EnableMulticastKPI != evs.EnableMulticastKPI",
1567 args: args{
1568 evs: &VoltServiceCfg{
1569 EnableMulticastKPI: true,
1570 },
1571 nvs: &VoltServiceCfg{},
1572 },
1573 want: false,
1574 },
1575 {
1576 name: "nvs.DataRateAttr != evs.DataRateAttr",
1577 args: args{
1578 evs: &VoltServiceCfg{
1579 DataRateAttr: "DataRateAttr",
1580 },
1581 nvs: &VoltServiceCfg{},
1582 },
1583 want: false,
1584 },
1585 {
1586 name: "nvs.MinDataRateUs != evs.MinDataRateUs",
1587 args: args{
1588 evs: &VoltServiceCfg{
1589 MinDataRateUs: uint32(1),
1590 },
1591 nvs: &VoltServiceCfg{},
1592 },
1593 want: false,
1594 },
1595 {
1596 name: "nvs.MinDataRateDs != evs.MinDataRateDs",
1597 args: args{
1598 evs: &VoltServiceCfg{
1599 MinDataRateDs: uint32(1),
1600 },
1601 nvs: &VoltServiceCfg{},
1602 },
1603 want: false,
1604 },
1605 {
1606 name: "nvs.MaxDataRateUs != evs.MaxDataRateUs",
1607 args: args{
1608 evs: &VoltServiceCfg{
1609 MaxDataRateUs: uint32(1),
1610 },
1611 nvs: &VoltServiceCfg{},
1612 },
1613 want: false,
1614 },
1615 {
1616 name: "nvs.MaxDataRateDs != evs.MaxDataRateDs",
1617 args: args{
1618 evs: &VoltServiceCfg{
1619 MaxDataRateDs: uint32(1),
1620 },
1621 nvs: &VoltServiceCfg{},
1622 },
1623 want: false,
1624 },
vinokuma02fbfd02023-07-05 15:23:33 +05301625 {
1626 name: "nvs.IsOption82Enabled != evs.IsOption82Enabled",
1627 args: args{
1628 evs: &VoltServiceCfg{
1629 IsOption82Enabled: true,
1630 },
1631 nvs: &VoltServiceCfg{},
1632 },
1633 want: false,
1634 },
vinokumaf7605fc2023-06-02 18:08:01 +05301635 }
1636 for _, tt := range tests {
1637 t.Run(tt.name, func(t *testing.T) {
1638 va := &VoltApplication{
1639 vendorID: "test_vendor_id",
1640 }
1641 switch tt.name {
1642 case "VoltApplication_DeepEqualServicecfg", "nvs.Name != evs.Name", "nvs.UniVlan != evs.UniVlan",
1643 "nvs.CVlan != evs.CVlan", "nvs.SVlan != evs.SVlan", "nvs.SVlanTpid != 0", "nvs.Pbits != evs.Pbits",
1644 "nvs.DsRemarkPbitsMap != evs.DsRemarkPbitsMap", "nvs.TechProfileID != evs.TechProfileID",
1645 "nvs.CircuitID != evs.CircuitID", "nvs.RemoteID != evs.RemoteID", "nvs.Port != evs.Port",
1646 "evs.MacLearning == MacLearningNone", "nvs.PonPort != evs.PonPort", "nvs.IgmpEnabled != evs.IgmpEnabled",
1647 "nvs.McastService != evs.McastService", "nvs.ONTEtherTypeClassification != evs.ONTEtherTypeClassification",
1648 "nvs.UsMeterProfile != evs.UsMeterProfile",
1649 "nvs.DsMeterProfile != evs.DsMeterProfile", "nvs.AggDsMeterProfile != evs.AggDsMeterProfile",
1650 "nvs.VnetID != evs.VnetID", "nvs.MvlanProfileName != evs.MvlanProfileName",
1651 "nvs.RemoteIDType != evs.RemoteIDType", "nvs.SchedID != evs.SchedID",
1652 "nvs.AllowTransparent != evs.AllowTransparent",
1653 "nvs.EnableMulticastKPI != evs.EnableMulticastKPI", "nvs.DataRateAttr != evs.DataRateAttr",
1654 "nvs.MinDataRateUs != evs.MinDataRateUs", "nvs.MinDataRateDs != evs.MinDataRateDs",
vinokuma02fbfd02023-07-05 15:23:33 +05301655 "nvs.MaxDataRateUs != evs.MaxDataRateUs", "nvs.MaxDataRateDs != evs.MaxDataRateDs",
1656 "nvs.IsOption82Enabled != evs.IsOption82Enabled":
vinokumaf7605fc2023-06-02 18:08:01 +05301657 if got := va.DeepEqualServicecfg(tt.args.evs, tt.args.nvs); got != tt.want {
1658 t.Errorf("VoltApplication.DeepEqualServicecfg() = %v, want %v", got, tt.want)
1659 }
1660 }
1661 })
1662 }
1663}
vinokuma02fbfd02023-07-05 15:23:33 +05301664
1665func Test_forceUpdateAllServices(t *testing.T) {
1666 type args struct {
1667 cntx context.Context
1668 msr *MigrateServicesRequest
1669 }
1670 servicesList := map[string]bool{}
1671 servicesList[test_device] = true
1672 tests := []struct {
1673 name string
1674 args args
1675 }{
1676 {
1677 name: "forceUpdateAllServices",
1678 args: args{
1679 cntx: context.Background(),
1680 msr: &MigrateServicesRequest{
1681 ID: "test_id",
1682 ServicesList: servicesList,
1683 DeviceID: test_device,
1684 },
1685 },
1686 },
1687 }
1688 for _, tt := range tests {
1689 t.Run(tt.name, func(t *testing.T) {
1690 ga := GetApplication()
1691 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1692 db = dbintf
1693 dbintf.EXPECT().DelMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1694 ga.ServiceByName.Store(test_device, voltService2)
1695 voltService2.VoltServiceOper.Metadata = &MigrateServiceMetadata{
1696 NewVnetID: "test_new_vnet_id",
1697 RequestID: "test_request_id",
1698 }
1699 newConcurrentMap := util.NewConcurrentMap()
1700 ga.DevicesDisc.Store(test_device, voltDevice2)
1701 voltDevice2.MigratingServices.Set("test_vnet_id", newConcurrentMap)
1702 migrateServicesRequest := &MigrateServicesRequest{
1703 ID: "test_id",
1704 ServicesList: servicesList,
1705 }
1706 newConcurrentMap.Set("test_request_id", migrateServicesRequest)
1707 dbintf.EXPECT().PutMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1708 forceUpdateAllServices(tt.args.cntx, tt.args.msr)
1709 })
1710 }
1711}
1712
1713func TestVoltService_updateVnetProfile(t *testing.T) {
1714 type args struct {
1715 cntx context.Context
1716 deviceID string
1717 }
1718 tests := []struct {
1719 name string
1720 args args
1721 }{
1722 {
1723 name: "DeleteInProgress_true",
1724 args: args{
1725 cntx: context.Background(),
1726 deviceID: test_device,
1727 },
1728 },
1729 {
1730 name: "metadata_nil",
1731 args: args{
1732 cntx: context.Background(),
1733 deviceID: test_device,
1734 },
1735 },
1736 }
1737 for _, tt := range tests {
1738 t.Run(tt.name, func(t *testing.T) {
1739 switch tt.name {
1740 case "DeleteInProgress_true":
1741 vs := &VoltService{
1742 VoltServiceOper: VoltServiceOper{
1743 DeleteInProgress: true,
1744 },
1745 }
1746 vs.updateVnetProfile(tt.args.cntx, tt.args.deviceID)
1747 case "metadata_nil":
1748 vs := &VoltService{
1749 VoltServiceOper: VoltServiceOper{
1750 Metadata: &MigrateServiceMetadata{},
1751 },
1752 }
1753 vs.updateVnetProfile(tt.args.cntx, tt.args.deviceID)
1754 }
1755 })
1756 }
1757}
1758
1759func TestMigrateServicesRequest_serviceMigrated(t *testing.T) {
1760 type args struct {
1761 cntx context.Context
1762 serviceName string
1763 }
1764 tests := []struct {
1765 name string
1766 args args
1767 }{
1768 {
1769 name: "ServicesList_nil",
1770 args: args{
1771 cntx: context.Background(),
1772 serviceName: "test_service_name",
1773 },
1774 },
1775 }
1776 for _, tt := range tests {
1777 t.Run(tt.name, func(t *testing.T) {
1778 msr := &MigrateServicesRequest{
1779 ServicesList: map[string]bool{},
1780 }
1781 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1782 db = dbintf
1783 dbintf.EXPECT().DelMigrateServicesReq(gomock.All(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
1784 msr.serviceMigrated(tt.args.cntx, tt.args.serviceName)
1785 })
1786 }
1787}
1788
1789func TestVoltApplication_TriggerPendingMigrateServicesReq(t *testing.T) {
1790 type args struct {
1791 cntx context.Context
1792 device string
1793 }
1794 tests := []struct {
1795 name string
1796 args args
1797 }{
1798 {
1799 name: "VoltApplication_TriggerPendingMigrateServicesReq",
1800 args: args{
1801 cntx: context.Background(),
1802 device: test_device,
1803 },
1804 },
1805 }
1806 for _, tt := range tests {
1807 t.Run(tt.name, func(t *testing.T) {
1808 va := &VoltApplication{
1809 ServiceByName: sync.Map{},
1810 }
1811 migrateServicesRequest := &MigrateServicesRequest{
1812 ID: "test_id",
1813 OldVnetID: "test_vnet_id",
1814 DeviceID: test_device,
1815 }
1816 b, err := json.Marshal(migrateServicesRequest)
1817 if err != nil {
1818 panic(err)
1819 }
1820 kvpair := map[string]*kvstore.KVPair{}
1821 kvpair["test_device_id"] = &kvstore.KVPair{
1822 Key: "test_device_id",
1823 Value: b,
1824 }
1825
1826 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1827 db = dbintf
1828 ga := GetApplication()
1829 ga.DevicesDisc.Store(test_device, voltDevice2)
1830 newConcurrentMap := util.NewConcurrentMap()
1831 voltDevice2.MigratingServices.Set("test_vnet_id", newConcurrentMap)
1832 dbintf.EXPECT().GetAllMigrateServicesReq(gomock.Any(), gomock.Any()).Return(kvpair, nil).AnyTimes()
1833 va.TriggerPendingMigrateServicesReq(tt.args.cntx, tt.args.device)
1834 })
1835 }
1836}
1837
1838func TestVoltApplication_FetchAndProcessAllMigrateServicesReq(t *testing.T) {
1839 type args struct {
1840 cntx context.Context
1841 device string
1842 msrAction func(context.Context, *MigrateServicesRequest)
1843 }
1844 tests := []struct {
1845 name string
1846 args args
1847 }{
1848 {
1849 name: "invalid_value_type",
1850 args: args{
1851 cntx: context.Background(),
1852 device: test_device,
1853 msrAction: func(ctx context.Context, msr *MigrateServicesRequest) {},
1854 },
1855 },
1856 }
1857 for _, tt := range tests {
1858 t.Run(tt.name, func(t *testing.T) {
1859 va := &VoltApplication{
1860 DevicesDisc: sync.Map{},
1861 }
1862 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1863 db = dbintf
1864 kvpair := map[string]*kvstore.KVPair{}
1865 kvpair["test_device_id"] = &kvstore.KVPair{
1866 Key: "test_device_id",
1867 Value: "invalid_value",
1868 }
1869 dbintf.EXPECT().GetAllMigrateServicesReq(gomock.Any(), gomock.Any()).Return(kvpair, nil).AnyTimes()
1870 va.FetchAndProcessAllMigrateServicesReq(tt.args.cntx, tt.args.device, tt.args.msrAction)
1871 })
1872 }
1873}
1874
1875func TestVoltApplication_createMigrateServicesFromString(t *testing.T) {
1876 type args struct {
1877 b []byte
1878 }
1879 tests := []struct {
1880 name string
1881 args args
1882 }{
1883 {
1884 name: "Unmarshal_error",
1885 args: args{
1886 b: []byte{},
1887 },
1888 },
1889 }
1890 for _, tt := range tests {
1891 t.Run(tt.name, func(t *testing.T) {
1892 va := &VoltApplication{
1893 vendorID: test_device,
1894 }
1895 got := va.createMigrateServicesFromString(tt.args.b)
1896 assert.NotNil(t, got)
1897 })
1898 }
1899}
1900
1901func TestVoltApplication_getMigrateServicesRequest(t *testing.T) {
1902 type args struct {
1903 deviceID string
1904 oldVnetID string
1905 requestID string
1906 }
1907 tests := []struct {
1908 name string
1909 args args
1910 want *MigrateServicesRequest
1911 }{
1912 {
1913 name: "GetDevice_nil",
1914 args: args{
1915 deviceID: test_device,
1916 },
1917 },
1918 }
1919 for _, tt := range tests {
1920 t.Run(tt.name, func(t *testing.T) {
1921 va := &VoltApplication{
1922 vendorID: "vendorID",
1923 }
1924 if got := va.getMigrateServicesRequest(tt.args.deviceID, tt.args.oldVnetID, tt.args.requestID); !reflect.DeepEqual(got, tt.want) {
1925 t.Errorf("VoltApplication.getMigrateServicesRequest() = %v, want %v", got, tt.want)
1926 }
1927 })
1928 }
1929}
1930
1931func TestVoltDevice_AddMigratingServices(t *testing.T) {
1932 type args struct {
1933 msr *MigrateServicesRequest
1934 }
1935 tests := []struct {
1936 name string
1937 args args
1938 }{
1939 {
1940 name: "MigratingServices_Get_nil",
1941 args: args{
1942 msr: &MigrateServicesRequest{
1943 ID: "test_id",
1944 },
1945 },
1946 },
1947 }
1948 for _, tt := range tests {
1949 t.Run(tt.name, func(t *testing.T) {
1950 d := &VoltDevice{
1951 MigratingServices: util.NewConcurrentMap(),
1952 }
1953 d.AddMigratingServices(tt.args.msr)
1954 })
1955 }
1956}
1957
1958func TestMigrateServicesRequest_ProcessMigrateServicesProfRequest(t *testing.T) {
1959 type args struct {
1960 cntx context.Context
1961 }
1962 tests := []struct {
1963 name string
1964 args args
1965 }{
1966 {
1967 name: "ServicesList_true",
1968 args: args{
1969 cntx: context.Background(),
1970 },
1971 },
1972 {
1973 name: "ServicesList_false",
1974 args: args{
1975 cntx: context.Background(),
1976 },
1977 },
1978 {
1979 name: "GetVnetByPort_nil",
1980 args: args{
1981 cntx: context.Background(),
1982 },
1983 },
1984 {
1985 name: "UsHSIAFlowsApplied_true",
1986 args: args{
1987 cntx: context.Background(),
1988 },
1989 },
1990 {
1991 name: "ServiceByName_nil",
1992 args: args{
1993 cntx: context.Background(),
1994 },
1995 },
1996 }
1997 for _, tt := range tests {
1998 t.Run(tt.name, func(t *testing.T) {
1999 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2000 db = dbintf
2001 switch tt.name {
2002 case "ServicesList_true":
2003 servicesList := map[string]bool{}
2004 servicesList[test_device] = true
2005 msr := &MigrateServicesRequest{
2006 ServicesList: servicesList,
2007 }
2008 dbintf.EXPECT().DelMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2009 msr.ProcessMigrateServicesProfRequest(tt.args.cntx)
2010 case "ServicesList_false":
2011 servicesList := map[string]bool{}
2012 servicesList[test_device] = false
2013 msr := &MigrateServicesRequest{
2014 ServicesList: servicesList,
2015 }
2016 ga := GetApplication()
2017 ga.ServiceByName.Store(test_device, voltService2)
2018 ga.VnetsByPort.Store("test_port", voltPortVnet1)
2019 msr.ProcessMigrateServicesProfRequest(tt.args.cntx)
2020 case "GetVnetByPort_nil":
2021 servicesList := map[string]bool{}
2022 servicesList[test_device] = false
2023 msr := &MigrateServicesRequest{
2024 ServicesList: servicesList,
2025 }
2026 ga := GetApplication()
2027 var voltService1 = &VoltService{
2028 Version: "test_version",
2029 VoltServiceCfg: VoltServiceCfg{
2030 VnetID: "test_vnet_id",
2031 SVlan: of.VlanAny,
2032 CVlan: of.VlanAny,
2033 UniVlan: of.VlanAny,
2034 },
2035 }
2036 ga.ServiceByName.Store(test_device, voltService1)
2037 ga.VnetsByPort.Store("test_port1", nil)
2038 msr.ProcessMigrateServicesProfRequest(tt.args.cntx)
2039 case "UsHSIAFlowsApplied_true":
2040 servicesList := map[string]bool{}
2041 servicesList[test_device] = false
2042 msr := &MigrateServicesRequest{
2043 ServicesList: servicesList,
2044 }
2045 ga := GetApplication()
2046 voltService2.UsHSIAFlowsApplied = true
2047 ga.ServiceByName.Store(test_device, voltService2)
2048 ga.VnetsByPort.Store("test_port", voltPortVnet1)
2049 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2050 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2051 msr.ProcessMigrateServicesProfRequest(tt.args.cntx)
2052 case "ServiceByName_nil":
2053 servicesList := map[string]bool{}
2054 servicesList[""] = false
2055 msr := &MigrateServicesRequest{
2056 ServicesList: servicesList,
2057 }
2058 msr.ProcessMigrateServicesProfRequest(tt.args.cntx)
2059 }
2060 })
2061 }
2062}
2063
2064func TestVoltApplication_MigrateServices(t *testing.T) {
2065 type args struct {
2066 cntx context.Context
2067 serialNum string
2068 reqID string
2069 oldVnetID string
2070 newVnetID string
2071 serviceList []string
2072 }
2073 tests := []struct {
2074 name string
2075 args args
2076 wantErr bool
2077 }{
2078 {
2079 name: "VoltApplication_MigrateServices",
2080 args: args{
2081 cntx: context.Background(),
2082 serialNum: "test_serial_number",
2083 reqID: "test_reqid",
2084 oldVnetID: "test_old_vnet_id",
2085 newVnetID: "test_new_vnet_id",
2086 serviceList: []string{"test_service_list_1", "test_service_list_2"},
2087 },
2088 },
2089 {
2090 name: "Old Vnet Id not found",
2091 args: args{
2092 cntx: context.Background(),
2093 serialNum: "test_serial_number",
2094 reqID: "test_reqid",
2095 oldVnetID: "",
2096 newVnetID: "test_new_vnet_id",
2097 serviceList: []string{"test_service_list_1", "test_service_list_2"},
2098 },
2099 },
2100 {
2101 name: "New Vnet Id not found",
2102 args: args{
2103 cntx: context.Background(),
2104 serialNum: "test_serial_number",
2105 reqID: "test_reqid",
2106 oldVnetID: "test_old_vnet_id",
2107 newVnetID: "",
2108 serviceList: []string{"test_service_list_1", "test_service_list_2"},
2109 },
2110 },
2111 }
2112 for _, tt := range tests {
2113 t.Run(tt.name, func(t *testing.T) {
2114 va := &VoltApplication{
2115 VnetsByName: sync.Map{},
2116 }
2117 voltVnet2 := &VoltVnet{
2118 Version: "v3",
2119 VnetConfig: VnetConfig{
2120 Name: "2310-4096-4096",
2121 VnetType: "Encapsulation",
2122 SVlan: 2310,
2123 CVlan: 4096,
2124 UniVlan: 4096,
2125 SVlanTpid: 33024,
2126 },
2127 VnetOper: VnetOper{
2128 PendingDeviceToDelete: "SDX63200313",
2129 },
2130 }
2131 switch tt.name {
2132 case "VoltApplication_MigrateServices":
2133 va.VnetsByName.Store("test_old_vnet_id", voltVnet2)
2134 va.VnetsByName.Store("test_new_vnet_id", voltVnet2)
2135 va.DevicesDisc.Store(test_device, voltDevice2)
2136 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2137 db = dbintf
2138 dbintf.EXPECT().PutMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2139 if err := va.MigrateServices(tt.args.cntx, tt.args.serialNum, tt.args.reqID, tt.args.oldVnetID, tt.args.newVnetID, tt.args.serviceList); (err != nil) != tt.wantErr {
2140 t.Errorf("VoltApplication.MigrateServices() error = %v, wantErr %v", err, tt.wantErr)
2141 }
2142 case "Old Vnet Id not found":
2143 va.VnetsByName.Store("test_old_vnet_id", voltVnet2)
2144 err := va.MigrateServices(tt.args.cntx, tt.args.serialNum, tt.args.reqID, tt.args.oldVnetID, tt.args.newVnetID, tt.args.serviceList)
2145 assert.NotNil(t, err)
2146 case "New Vnet Id not found":
2147 va.VnetsByName.Store("test_old_vnet_id", voltVnet2)
2148 va.VnetsByName.Store("test_new_vnet_id", voltVnet2)
2149 err := va.MigrateServices(tt.args.cntx, tt.args.serialNum, tt.args.reqID, tt.args.oldVnetID, tt.args.newVnetID, tt.args.serviceList)
2150 assert.NotNil(t, err)
2151 }
2152 })
2153 }
2154}
2155
2156func TestMigrateServicesRequest_WriteToDB(t *testing.T) {
2157 type args struct {
2158 cntx context.Context
2159 }
2160 tests := []struct {
2161 name string
2162 args args
2163 }{
2164 {
2165 name: "PutMigrateServicesReq_error",
2166 args: args{
2167 cntx: context.Background(),
2168 },
2169 },
2170 }
2171 for _, tt := range tests {
2172 t.Run(tt.name, func(t *testing.T) {
2173 msr := &MigrateServicesRequest{
2174 ID: test_device,
2175 }
2176 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2177 db = dbintf
2178 dbintf.EXPECT().PutMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("error")).Times(1)
2179 msr.WriteToDB(tt.args.cntx)
2180 })
2181 }
2182}
2183
2184func TestVoltService_MatchesVlans(t *testing.T) {
2185 type args struct {
2186 vlans []of.VlanType
2187 }
2188 tests := []struct {
2189 name string
2190 args args
2191 want bool
2192 }{
2193 {
2194 name: "vlans_nil",
2195 args: args{
2196 vlans: []of.VlanType{},
2197 },
2198 want: false,
2199 },
2200 {
2201 name: "MatchesVlans",
2202 args: args{
2203 vlans: []of.VlanType{
2204 of.VlanAny,
2205 },
2206 },
2207 want: true,
2208 },
2209 {
2210 name: "vlans[0] != vs.CVlan",
2211 args: args{
2212 vlans: []of.VlanType{
2213 of.VlanNone,
2214 },
2215 },
2216 want: false,
2217 },
2218 }
2219 for _, tt := range tests {
2220 t.Run(tt.name, func(t *testing.T) {
2221 vs := &VoltService{
2222 VoltServiceCfg: VoltServiceCfg{CVlan: of.VlanAny},
2223 }
2224 switch tt.name {
2225 case "vlans_nil", "MatchesVlans", "vlans[0] != vs.CVlan":
2226 if got := vs.MatchesVlans(tt.args.vlans); got != tt.want {
2227 t.Errorf("VoltService.MatchesVlans() = %v, want %v", got, tt.want)
2228 }
2229 }
2230 })
2231 }
2232}
2233
2234func TestVoltService_MatchesPbits(t *testing.T) {
2235 type args struct {
2236 pbits []of.PbitType
2237 }
2238 tests := []struct {
2239 name string
2240 args args
2241 want bool
2242 }{
2243 {
2244 name: "VoltService_MatchesPbits",
2245 args: args{
2246 pbits: []of.PbitType{
2247 of.PbitMatchAll,
2248 },
2249 },
2250 want: true,
2251 },
2252 {
2253 name: "PbitType_nil",
2254 args: args{
2255 pbits: []of.PbitType{},
2256 },
2257 want: false,
2258 },
2259 }
2260 for _, tt := range tests {
2261 t.Run(tt.name, func(t *testing.T) {
2262 vs := &VoltService{
2263 VoltServiceCfg: VoltServiceCfg{
2264 Pbits: []of.PbitType{
2265 of.PbitMatchAll,
2266 },
2267 },
2268 }
2269 switch tt.name {
2270 case "VoltService_MatchesPbits", "PbitType_nil":
2271 if got := vs.MatchesPbits(tt.args.pbits); got != tt.want {
2272 t.Errorf("VoltService.MatchesPbits() = %v, want %v", got, tt.want)
2273 }
2274 }
2275 })
2276 }
2277}
2278
2279func TestVoltApplication_DelServiceWithPrefix(t *testing.T) {
2280 type args struct {
2281 cntx context.Context
2282 prefix string
2283 }
2284 tests := []struct {
2285 name string
2286 args args
2287 }{
2288 {
2289 name: "VoltApplication_DelServiceWithPrefix",
2290 args: args{
2291 cntx: context.Background(),
2292 prefix: test_device,
2293 },
2294 },
2295 }
2296 for _, tt := range tests {
2297 t.Run(tt.name, func(t *testing.T) {
2298 va := &VoltApplication{
2299 VnetsBySvlan: util.NewConcurrentMap(),
2300 }
2301 va.ServiceByName.Store(test_device, voltService)
2302 va.VnetsByName.Store("0-0-0", voltVnet)
2303 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2304 db = dbintf
2305 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
2306 cuncurrentMap := &util.ConcurrentMap{
2307 Count: atomic.NewUint64(0),
2308 }
2309 va.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap)
2310 dbintf.EXPECT().DelVnet(gomock.Any(), gomock.Any()).Return(nil).Times(1)
2311 va.DelServiceWithPrefix(tt.args.cntx, tt.args.prefix)
2312 })
2313 }
2314}
2315
2316func TestVoltService_FlowInstallFailure(t *testing.T) {
2317 type args struct {
2318 cookie string
2319 errorCode uint32
2320 errReason string
2321 }
2322 tests := []struct {
2323 name string
2324 args args
2325 }{
2326 {
2327 name: "VoltService_FlowInstallFailure",
2328 args: args{
2329 cookie: "test_cookie",
2330 errorCode: uint32(1),
2331 errReason: "err_reason",
2332 },
2333 },
2334 {
2335 name: "PendingFlows[cookie]_false",
2336 args: args{
2337 cookie: "test_cookie",
2338 errorCode: uint32(1),
2339 errReason: "err_reason",
2340 },
2341 },
2342 }
2343 pendingFlows := map[string]bool{}
2344 pendingFlows["test_cookie"] = true
2345 for _, tt := range tests {
2346 t.Run(tt.name, func(t *testing.T) {
2347 vs := &VoltService{
2348 VoltServiceOper: VoltServiceOper{},
2349 }
2350 switch tt.name {
2351 case "VoltService_FlowInstallFailure":
2352 vs.PendingFlows = pendingFlows
2353 vs.FlowInstallFailure(tt.args.cookie, tt.args.errorCode, tt.args.errReason)
2354 case "PendingFlows[cookie]_false":
2355 vs.FlowInstallFailure(tt.args.cookie, tt.args.errorCode, tt.args.errReason)
2356 }
2357 })
2358 }
2359}
2360
2361func TestVoltService_FlowRemoveSuccess(t *testing.T) {
2362 type args struct {
2363 cntx context.Context
2364 cookie string
2365 }
2366 tests := []struct {
2367 name string
2368 args args
2369 }{
2370 {
2371 name: "GetDevice != nil",
2372 args: args{
2373 cntx: context.Background(),
2374 cookie: "test_cookie",
2375 },
2376 },
2377 }
2378 for _, tt := range tests {
2379 t.Run(tt.name, func(t *testing.T) {
2380 vs := &VoltService{
2381 VoltServiceOper: VoltServiceOper{
2382 Device: test_device,
2383 },
2384 }
2385 ga := GetApplication()
2386 ga.DevicesDisc.Store(test_device, voltDevice2)
2387 voltDevice2.State = controller.DeviceStateUP
2388 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2389 db = dbintf
2390 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2391 vs.FlowRemoveSuccess(tt.args.cntx, tt.args.cookie)
2392 })
2393 }
2394}
2395
2396func TestVoltService_setDSMatchActionVlanT0(t *testing.T) {
2397 type args struct {
2398 flow *of.VoltSubFlow
2399 }
2400 tests := []struct {
2401 name string
2402 args args
2403 wantErr bool
2404 }{
2405 {
2406 name: "VlanControl: ONUCVlanOLTSVlan",
2407 args: args{
2408 flow: &of.VoltSubFlow{
2409 ErrorReason: "test_error_reason",
2410 Cookie: uint64(1),
2411 OldCookie: uint64(2),
2412 TableID: uint32(3),
2413 Priority: uint32(4),
2414 State: uint8(5),
2415 },
2416 },
2417 },
2418 {
2419 name: "VlanControl: OLTCVlanOLTSVlan",
2420 args: args{
2421 flow: &of.VoltSubFlow{
2422 ErrorReason: "test_error_reason",
2423 Cookie: uint64(1),
2424 OldCookie: uint64(2),
2425 TableID: uint32(3),
2426 Priority: uint32(4),
2427 State: uint8(5),
2428 },
2429 },
2430 },
2431 {
2432 name: "VlanControl: ONUCVlan",
2433 args: args{
2434 flow: &of.VoltSubFlow{
2435 ErrorReason: "test_error_reason",
2436 Cookie: uint64(1),
2437 OldCookie: uint64(2),
2438 TableID: uint32(3),
2439 Priority: uint32(4),
2440 State: uint8(5),
2441 },
2442 },
2443 },
2444 {
2445 name: "VlanControl: OLTSVlan",
2446 args: args{
2447 flow: &of.VoltSubFlow{
2448 ErrorReason: "test_error_reason",
2449 Cookie: uint64(1),
2450 OldCookie: uint64(2),
2451 TableID: uint32(3),
2452 Priority: uint32(4),
2453 State: uint8(5),
2454 },
2455 },
2456 },
2457 {
2458 name: "VlanControl: OLTSVlan && UniVlan != of.VlanAny",
2459 args: args{
2460 flow: &of.VoltSubFlow{
2461 ErrorReason: "test_error_reason",
2462 Cookie: uint64(1),
2463 OldCookie: uint64(2),
2464 TableID: uint32(3),
2465 Priority: uint32(4),
2466 State: uint8(5),
2467 },
2468 },
2469 },
2470 {
2471 name: "invalid VlanControl",
2472 args: args{
2473 flow: &of.VoltSubFlow{
2474 ErrorReason: "test_error_reason",
2475 Cookie: uint64(1),
2476 OldCookie: uint64(2),
2477 TableID: uint32(3),
2478 Priority: uint32(4),
2479 State: uint8(5),
2480 },
2481 },
2482 },
2483 }
2484 for _, tt := range tests {
2485 t.Run(tt.name, func(t *testing.T) {
2486 vs := &VoltService{
2487 VoltServiceCfg: VoltServiceCfg{
2488 SVlan: of.VlanAny,
2489 UniVlan: of.VlanAny,
2490 VlanControl: ONUCVlanOLTSVlan,
2491 },
2492 }
2493 switch tt.name {
2494 case "VlanControl: ONUCVlanOLTSVlan":
2495 vs.VlanControl = ONUCVlanOLTSVlan
2496 if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2497 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2498 }
2499 case "VlanControl: OLTCVlanOLTSVlan":
2500 vs.VlanControl = OLTCVlanOLTSVlan
2501 if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2502 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2503 }
2504 case "VlanControl: ONUCVlan":
2505 vs.VlanControl = ONUCVlan
2506 if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2507 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2508 }
2509 case "VlanControl: OLTSVlan":
2510 vs.VlanControl = OLTSVlan
2511 vs.UniVlan = vs.CVlan
2512 if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2513 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2514 }
2515 case "VlanControl: OLTSVlan && UniVlan != of.VlanAny":
2516 vs.VlanControl = OLTSVlan
2517 if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2518 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2519 }
2520 case "invalid VlanControl":
2521 vs.VlanControl = 5
2522 err := vs.setDSMatchActionVlanT0(tt.args.flow)
2523 assert.NotNil(t, err)
2524 }
2525 })
2526 }
2527}
2528
2529func TestVoltService_setUSMatchActionVlanT1(t *testing.T) {
2530 type args struct {
2531 flow *of.VoltSubFlow
2532 }
2533 tests := []struct {
2534 name string
2535 args args
2536 wantErr bool
2537 }{
2538 {
2539 name: "VlanControl: ONUCVlanOLTSVlan",
2540 args: args{
2541 flow: &of.VoltSubFlow{
2542 ErrorReason: "test_error_reason",
2543 Cookie: uint64(1),
2544 OldCookie: uint64(2),
2545 TableID: uint32(3),
2546 Priority: uint32(4),
2547 State: uint8(5),
2548 },
2549 },
2550 },
2551 {
2552 name: "VlanControl: OLTCVlanOLTSVlan",
2553 args: args{
2554 flow: &of.VoltSubFlow{
2555 ErrorReason: "test_error_reason",
2556 Cookie: uint64(1),
2557 OldCookie: uint64(2),
2558 TableID: uint32(3),
2559 Priority: uint32(4),
2560 State: uint8(5),
2561 },
2562 },
2563 },
2564 {
2565 name: "VlanControl: ONUCVlan",
2566 args: args{
2567 flow: &of.VoltSubFlow{
2568 ErrorReason: "test_error_reason",
2569 Cookie: uint64(1),
2570 OldCookie: uint64(2),
2571 TableID: uint32(3),
2572 Priority: uint32(4),
2573 State: uint8(5),
2574 },
2575 },
2576 },
2577 {
2578 name: "VlanControl: OLTSVlan",
2579 args: args{
2580 flow: &of.VoltSubFlow{
2581 ErrorReason: "test_error_reason",
2582 Cookie: uint64(1),
2583 OldCookie: uint64(2),
2584 TableID: uint32(3),
2585 Priority: uint32(4),
2586 State: uint8(5),
2587 },
2588 },
2589 },
2590 {
2591 name: "VlanControl: OLTSVlan vs.UniVlan != of.VlanAny && vs.UniVlan != of.VlanNone",
2592 args: args{
2593 flow: &of.VoltSubFlow{
2594 ErrorReason: "test_error_reason",
2595 Cookie: uint64(1),
2596 OldCookie: uint64(2),
2597 TableID: uint32(3),
2598 Priority: uint32(4),
2599 State: uint8(5),
2600 },
2601 },
2602 },
2603 {
2604 name: "VlanControl: OLTSVlan vs.UniVlan == of.VlanNone",
2605 args: args{
2606 flow: &of.VoltSubFlow{
2607 ErrorReason: "test_error_reason",
2608 Cookie: uint64(1),
2609 OldCookie: uint64(2),
2610 TableID: uint32(3),
2611 Priority: uint32(4),
2612 State: uint8(5),
2613 },
2614 },
2615 },
2616 {
2617 name: "VlanControl: default",
2618 args: args{
2619 flow: &of.VoltSubFlow{
2620 ErrorReason: "test_error_reason",
2621 Cookie: uint64(1),
2622 OldCookie: uint64(2),
2623 TableID: uint32(3),
2624 Priority: uint32(4),
2625 State: uint8(5),
2626 },
2627 },
2628 },
2629 }
2630 for _, tt := range tests {
2631 t.Run(tt.name, func(t *testing.T) {
2632 vs := &VoltService{
2633 VoltServiceCfg: VoltServiceCfg{
2634 SVlan: of.VlanAny,
2635 UniVlan: of.VlanAny,
2636 VlanControl: ONUCVlanOLTSVlan,
2637 },
2638 }
2639 switch tt.name {
2640 case "VlanControl: ONUCVlanOLTSVlan":
2641 vs.VlanControl = ONUCVlanOLTSVlan
2642 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2643 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2644 }
2645 case "VlanControl: OLTCVlanOLTSVlan":
2646 vs.VlanControl = OLTCVlanOLTSVlan
2647 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2648 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2649 }
2650 case "VlanControl: ONUCVlan":
2651 vs.VlanControl = ONUCVlan
2652 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2653 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2654 }
2655 case "VlanControl: OLTSVlan":
2656 vs.VlanControl = OLTSVlan
2657 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2658 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2659 }
2660 case "VlanControl: OLTSVlan vs.UniVlan != of.VlanAny && vs.UniVlan != of.VlanNone":
2661 vs.VlanControl = OLTSVlan
2662 vs.UniVlan = vs.CVlan
2663 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2664 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2665 }
2666 case "VlanControl: OLTSVlan vs.UniVlan == of.VlanNone":
2667 vs.VlanControl = OLTSVlan
2668 vs.UniVlan = of.VlanNone
2669 if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2670 t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2671 }
2672 case "VlanControl: default":
2673 vs.VlanControl = 6
2674 err := vs.setUSMatchActionVlanT1(tt.args.flow)
2675 assert.NotNil(t, err)
2676 }
2677 })
2678 }
2679}
2680
2681func TestVoltService_setUSMatchActionVlanT0(t *testing.T) {
2682 type args struct {
2683 flow *of.VoltSubFlow
2684 }
2685 tests := []struct {
2686 name string
2687 args args
2688 wantErr bool
2689 }{
2690 {
2691 name: "vs.VlanControl: ONUCVlanOLTSVlan",
2692 args: args{
2693 flow: &of.VoltSubFlow{
2694 ErrorReason: "test_error_reason",
2695 Cookie: uint64(1),
2696 OldCookie: uint64(2),
2697 TableID: uint32(3),
2698 Priority: uint32(4),
2699 State: uint8(5),
2700 },
2701 },
2702 },
2703 {
2704 name: "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone",
2705 args: args{
2706 flow: &of.VoltSubFlow{
2707 ErrorReason: "test_error_reason",
2708 Cookie: uint64(1),
2709 OldCookie: uint64(2),
2710 TableID: uint32(3),
2711 Priority: uint32(4),
2712 State: uint8(5),
2713 },
2714 },
2715 },
2716 {
2717 name: "vs.VlanControl: OLTCVlanOLTSVlan",
2718 args: args{
2719 flow: &of.VoltSubFlow{
2720 ErrorReason: "test_error_reason",
2721 Cookie: uint64(1),
2722 OldCookie: uint64(2),
2723 TableID: uint32(3),
2724 Priority: uint32(4),
2725 State: uint8(5),
2726 },
2727 },
2728 },
2729 {
2730 name: "vs.VlanControl: ONUCVlan",
2731 args: args{
2732 flow: &of.VoltSubFlow{
2733 ErrorReason: "test_error_reason",
2734 Cookie: uint64(1),
2735 OldCookie: uint64(2),
2736 TableID: uint32(3),
2737 Priority: uint32(4),
2738 State: uint8(5),
2739 },
2740 },
2741 },
2742 {
2743 name: "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone",
2744 args: args{
2745 flow: &of.VoltSubFlow{
2746 ErrorReason: "test_error_reason",
2747 Cookie: uint64(1),
2748 OldCookie: uint64(2),
2749 TableID: uint32(3),
2750 Priority: uint32(4),
2751 State: uint8(5),
2752 },
2753 },
2754 },
2755 {
2756 name: "vs.VlanControl: OLTSVlan",
2757 args: args{
2758 flow: &of.VoltSubFlow{
2759 ErrorReason: "test_error_reason",
2760 Cookie: uint64(1),
2761 OldCookie: uint64(2),
2762 TableID: uint32(3),
2763 Priority: uint32(4),
2764 State: uint8(5),
2765 },
2766 },
2767 },
2768 }
2769 for _, tt := range tests {
2770 t.Run(tt.name, func(t *testing.T) {
2771 vs := &VoltService{}
2772 switch tt.name {
2773 case "vs.VlanControl: ONUCVlanOLTSVlan":
2774 vs.VlanControl = ONUCVlanOLTSVlan
2775 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2776 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2777 }
2778 case "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone":
2779 vs.VlanControl = ONUCVlanOLTSVlan
2780 vs.UniVlan = of.VlanNone
2781 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2782 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2783 }
2784 case "vs.VlanControl: OLTCVlanOLTSVlan":
2785 vs.VlanControl = OLTCVlanOLTSVlan
2786 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2787 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2788 }
2789 case "vs.VlanControl: ONUCVlan":
2790 vs.VlanControl = ONUCVlan
2791 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2792 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2793 }
2794 case "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone":
2795 vs.VlanControl = ONUCVlan
2796 vs.UniVlan = of.VlanNone
2797 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2798 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2799 }
2800 case "vs.VlanControl: OLTSVlan":
2801 vs.VlanControl = OLTSVlan
2802 if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr {
2803 t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr)
2804 }
2805 }
2806 })
2807 }
2808}
2809
2810func TestVoltService_setDSMatchActionVlanT1(t *testing.T) {
2811 type args struct {
2812 flow *of.VoltSubFlow
2813 }
2814 tests := []struct {
2815 name string
2816 args args
2817 wantErr bool
2818 }{
2819 {
2820 name: "vs.VlanControl: ONUCVlanOLTSVlan",
2821 args: args{
2822 flow: &of.VoltSubFlow{
2823 ErrorReason: "test_error_reason",
2824 Cookie: uint64(1),
2825 OldCookie: uint64(2),
2826 TableID: uint32(3),
2827 Priority: uint32(4),
2828 State: uint8(5),
2829 },
2830 },
2831 },
2832 {
2833 name: "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone",
2834 args: args{
2835 flow: &of.VoltSubFlow{
2836 ErrorReason: "test_error_reason",
2837 Cookie: uint64(1),
2838 OldCookie: uint64(2),
2839 TableID: uint32(3),
2840 Priority: uint32(4),
2841 State: uint8(5),
2842 },
2843 },
2844 },
2845 {
2846 name: "vs.VlanControl: OLTCVlanOLTSVlan",
2847 args: args{
2848 flow: &of.VoltSubFlow{
2849 ErrorReason: "test_error_reason",
2850 Cookie: uint64(1),
2851 OldCookie: uint64(2),
2852 TableID: uint32(3),
2853 Priority: uint32(4),
2854 State: uint8(5),
2855 },
2856 },
2857 },
2858 {
2859 name: "vs.VlanControl: ONUCVlan",
2860 args: args{
2861 flow: &of.VoltSubFlow{
2862 ErrorReason: "test_error_reason",
2863 Cookie: uint64(1),
2864 OldCookie: uint64(2),
2865 TableID: uint32(3),
2866 Priority: uint32(4),
2867 State: uint8(5),
2868 },
2869 },
2870 },
2871 {
2872 name: "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone",
2873 args: args{
2874 flow: &of.VoltSubFlow{
2875 ErrorReason: "test_error_reason",
2876 Cookie: uint64(1),
2877 OldCookie: uint64(2),
2878 TableID: uint32(3),
2879 Priority: uint32(4),
2880 State: uint8(5),
2881 },
2882 },
2883 },
2884 {
2885 name: "vs.VlanControl: OLTSVlan",
2886 args: args{
2887 flow: &of.VoltSubFlow{
2888 ErrorReason: "test_error_reason",
2889 Cookie: uint64(1),
2890 OldCookie: uint64(2),
2891 TableID: uint32(3),
2892 Priority: uint32(4),
2893 State: uint8(5),
2894 },
2895 },
2896 },
2897 {
2898 name: "vs.VlanControl: default",
2899 args: args{
2900 flow: &of.VoltSubFlow{
2901 ErrorReason: "test_error_reason",
2902 Cookie: uint64(1),
2903 OldCookie: uint64(2),
2904 TableID: uint32(3),
2905 Priority: uint32(4),
2906 State: uint8(5),
2907 },
2908 },
2909 },
2910 }
2911 for _, tt := range tests {
2912 t.Run(tt.name, func(t *testing.T) {
2913 vs := &VoltService{}
2914 switch tt.name {
2915 case "vs.VlanControl: ONUCVlanOLTSVlan":
2916 vs.VlanControl = ONUCVlanOLTSVlan
2917 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2918 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2919 }
2920 case "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone":
2921 vs.VlanControl = ONUCVlanOLTSVlan
2922 vs.UniVlan = of.VlanNone
2923 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2924 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2925 }
2926 case "vs.VlanControl: OLTCVlanOLTSVlan":
2927 vs.VlanControl = OLTCVlanOLTSVlan
2928 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2929 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2930 }
2931 case "vs.VlanControl: ONUCVlan":
2932 vs.VlanControl = ONUCVlan
2933 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2934 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2935 }
2936 case "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone":
2937 vs.VlanControl = ONUCVlan
2938 vs.UniVlan = of.VlanNone
2939 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2940 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2941 }
2942 case "vs.VlanControl: OLTSVlan":
2943 vs.VlanControl = OLTSVlan
2944 if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr {
2945 t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr)
2946 }
2947 case "vs.VlanControl: default":
2948 vs.VlanControl = 6
2949 err := vs.setDSMatchActionVlanT1(tt.args.flow)
2950 assert.NotNil(t, err)
2951 }
2952 })
2953 }
2954}
2955
2956func TestVoltService_SetIpv6Addr(t *testing.T) {
2957 type args struct {
2958 addr net.IP
2959 }
2960 tests := []struct {
2961 name string
2962 args args
2963 }{
2964 {
2965 name: "SetIpv6Addr",
2966 args: args{
2967 addr: AllSystemsMulticastGroupIP,
2968 },
2969 },
2970 }
2971 for _, tt := range tests {
2972 t.Run(tt.name, func(t *testing.T) {
2973 vs := &VoltService{}
2974 vs.SetIpv6Addr(tt.args.addr)
2975 })
2976 }
2977}
2978
2979func TestVoltService_SetIpv4Addr(t *testing.T) {
2980 type args struct {
2981 addr net.IP
2982 }
2983 tests := []struct {
2984 name string
2985 args args
2986 }{
2987 {
2988 name: "VoltService_SetIpv4Addr",
2989 args: args{
2990 addr: AllSystemsMulticastGroupIP,
2991 },
2992 },
2993 }
2994 for _, tt := range tests {
2995 t.Run(tt.name, func(t *testing.T) {
2996 vs := &VoltService{}
2997 vs.SetIpv4Addr(tt.args.addr)
2998 })
2999 }
3000}
3001
3002func TestVoltService_SetMacAddr(t *testing.T) {
3003 type args struct {
3004 addr net.HardwareAddr
3005 }
3006 tests := []struct {
3007 name string
3008 args args
3009 }{
3010 {
3011 name: "VoltService_SetMacAddr",
3012 args: args{
3013 addr: BroadcastMAC,
3014 },
3015 },
3016 }
3017 for _, tt := range tests {
3018 t.Run(tt.name, func(t *testing.T) {
3019 vs := &VoltService{}
3020 vs.SetMacAddr(tt.args.addr)
3021 })
3022 }
3023}
3024
3025func TestVoltService_GetCircuitID(t *testing.T) {
3026 tests := []struct {
3027 name string
3028 want []byte
3029 }{
3030 {
3031 name: "VoltService_GetCircuitID",
3032 },
3033 }
3034 for _, tt := range tests {
3035 t.Run(tt.name, func(t *testing.T) {
3036 vs := &VoltService{}
3037 _ = vs.GetCircuitID()
3038 })
3039 }
3040}
3041
3042func TestVoltService_GetRemoteID(t *testing.T) {
3043 tests := []struct {
3044 name string
3045 want []byte
3046 }{
3047 {
3048 name: "VoltService_GetRemoteID",
3049 },
3050 }
3051 for _, tt := range tests {
3052 t.Run(tt.name, func(t *testing.T) {
3053 vs := &VoltService{}
3054 _ = vs.GetRemoteID()
3055 })
3056 }
3057}
3058
3059func TestVoltService_IPAssigned(t *testing.T) {
3060 tests := []struct {
3061 name string
3062 want bool
3063 }{
3064 {
3065 name: "VoltService_IPAssigned",
3066 },
3067 }
3068 for _, tt := range tests {
3069 t.Run(tt.name, func(t *testing.T) {
3070 vs := &VoltService{}
3071 _ = vs.IPAssigned()
3072 })
3073 }
3074}