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