Adding UTs part-1
Change-Id: I7fdb7751f536d1a616cf2a81b7ef16747d71f692
diff --git a/internal/pkg/application/application_test.go b/internal/pkg/application/application_test.go
new file mode 100644
index 0000000..ca2e2b9
--- /dev/null
+++ b/internal/pkg/application/application_test.go
@@ -0,0 +1,2377 @@
+/*
+* Copyright 2022-present Open Networking Foundation
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package application
+
+import (
+ "context"
+ "encoding/json"
+ "net"
+ "reflect"
+ "sync"
+ "testing"
+ "voltha-go-controller/internal/pkg/controller"
+ "voltha-go-controller/internal/pkg/intf"
+ "voltha-go-controller/internal/pkg/of"
+ "voltha-go-controller/internal/pkg/util"
+ "voltha-go-controller/internal/test/mocks"
+
+ "github.com/golang/mock/gomock"
+ "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
+ "github.com/stretchr/testify/assert"
+ "go.uber.org/atomic"
+)
+
+func TestVoltApplication_RestoreNbDeviceFromDb(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ deviceID string
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltApplication_RestoreNbDeviceFromDb",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "test_device_id",
+ },
+ },
+ {
+ name: "VoltApplication_RestoreNbDeviceFromDb_invalid_Value_type",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "test_device_id1",
+ },
+ },
+ {
+ name: "VoltApplication_RestoreNbDeviceFromDb_unmarshal_error",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "test_device_id1",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ NbDevice: sync.Map{},
+ }
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ switch tt.name {
+ case "VoltApplication_RestoreNbDeviceFromDb":
+ var port PonPortCfg
+ port = PonPortCfg{
+ PortAlarmProfileID: "test",
+ PortID: 256,
+ MaxActiveChannels: 256,
+ ActiveIGMPChannels: 7679,
+ EnableMulticastKPI: false,
+ }
+ b, err := json.Marshal(port)
+ if err != nil {
+ panic(err)
+ }
+ test := map[string]*kvstore.KVPair{}
+ test["test_device_id"] = &kvstore.KVPair{
+ Key: "test_device_id",
+ Value: b,
+ }
+ dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1)
+ got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID)
+ assert.NotNil(t, got)
+ case "VoltApplication_RestoreNbDeviceFromDb_invalid_Value_type":
+ test := map[string]*kvstore.KVPair{}
+ test["test_device_id"] = &kvstore.KVPair{
+ Key: "test_device_id",
+ Value: "invalid_value",
+ }
+ dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1)
+ got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID)
+ assert.NotNil(t, got)
+ case "VoltApplication_RestoreNbDeviceFromDb_unmarshal_error":
+ b, err := json.Marshal("error")
+ if err != nil {
+ panic(err)
+ }
+ test := map[string]*kvstore.KVPair{}
+ test["test_device_id"] = &kvstore.KVPair{
+ Key: "test_device_id",
+ Value: b,
+ }
+ dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1)
+ got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID)
+ assert.NotNil(t, got)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_UpdateDeviceConfig(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ deviceConfig *DeviceConfig
+ }
+
+ dvcConfg := &DeviceConfig{
+ SerialNumber: "SDX6320031",
+ HardwareIdentifier: "0.0.0.0",
+ IPAddress: "127.26.1.74",
+ UplinkPort: "43322",
+ NasID: "12345",
+ NniDhcpTrapVid: 123,
+ }
+
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "SDX6320031",
+ args: args{
+ cntx: context.Background(),
+ deviceConfig: dvcConfg,
+ },
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ DevicesConfig: sync.Map{},
+ }
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+
+ va.UpdateDeviceConfig(tt.args.cntx, tt.args.deviceConfig)
+ })
+ }
+}
+
+func TestVoltApplication_RestoreOltFlowService(t *testing.T) {
+ type fields struct {
+ OltFlowServiceConfig OltFlowService
+ }
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ }{
+ {
+ name: "OltFlowService",
+ args: args{
+ cntx: context.Background(),
+ },
+ fields: fields{
+ OltFlowServiceConfig: OltFlowService{
+ DefaultTechProfileID: 1233,
+ EnableDhcpOnNni: true,
+ EnableIgmpOnNni: false,
+ RemoveFlowsOnDisable: false,
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ OltFlowServiceConfig: tt.fields.OltFlowServiceConfig,
+ }
+
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().GetOltFlowService(gomock.Any()).AnyTimes()
+
+ va.RestoreOltFlowService(tt.args.cntx)
+ })
+ }
+}
+
+func TestVoltApplication_UpdateOltFlowService(t *testing.T) {
+ type fields struct {
+ OltFlowServiceConfig OltFlowService
+ }
+ type args struct {
+ cntx context.Context
+ oltFlowService OltFlowService
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ }{
+ {
+ name: "OltFlowService",
+ args: args{
+ cntx: context.Background(),
+ oltFlowService: OltFlowService{
+ DefaultTechProfileID: 1233,
+ EnableDhcpOnNni: true,
+ EnableIgmpOnNni: false,
+ RemoveFlowsOnDisable: false,
+ },
+ },
+ fields: fields{
+ OltFlowServiceConfig: OltFlowService{
+ DefaultTechProfileID: 1233,
+ EnableDhcpOnNni: true,
+ EnableIgmpOnNni: false,
+ RemoveFlowsOnDisable: false,
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ OltFlowServiceConfig: tt.fields.OltFlowServiceConfig,
+ }
+
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutOltFlowService(gomock.Any(), gomock.Any()).AnyTimes()
+ va.UpdateOltFlowService(tt.args.cntx, tt.args.oltFlowService)
+ })
+ }
+}
+
+func TestVoltApplication_TriggerPendingVpvDeleteReq(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ }
+ macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
+ test := map[*VoltPortVnet]bool{}
+ test[&VoltPortVnet{Device: "SDX6320031", Port: "16777472", MacAddr: macAdd}] = true
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "SDX6320031",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ VoltPortVnetsToDelete: test,
+ }
+ va.TriggerPendingVpvDeleteReq(tt.args.cntx, tt.args.device)
+ })
+ }
+}
+
+func TestVoltApplication_TriggerPendingProfileDeleteReq(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "SDX6320031",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ }
+ va.TriggerPendingProfileDeleteReq(tt.args.cntx, tt.args.device)
+ })
+ }
+}
+
+func TestVoltApplication_TriggerPendingServiceDeleteReq(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ }
+ voltServ := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ Device: "SDX6320031",
+ ForceDelete: true,
+ },
+ }
+
+ servicesToDel := map[string]bool{}
+ servicesToDel["SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65"] = true
+
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_TriggerPendingServiceDeleteReq",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ ServicesToDelete: servicesToDel,
+ ServiceByName: sync.Map{},
+ DevicesDisc: sync.Map{},
+ }
+
+ va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
+
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes()
+ va.TriggerPendingServiceDeleteReq(tt.args.cntx, tt.args.device)
+ })
+ }
+}
+
+func TestVoltApplication_TriggerPendingVnetDeleteReq(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ }
+
+ vnetToDel := map[string]bool{}
+ vnetToDel["2310-4096-4096"] = true
+
+ voltVnet := &VoltVnet{
+ Version: "v3",
+ VnetConfig: VnetConfig{
+ Name: "2310-4096-4096",
+ VnetType: "Encapsulation",
+ SVlan: 2310,
+ CVlan: 4096,
+ UniVlan: 4096,
+ SVlanTpid: 33024,
+ },
+ VnetOper: VnetOper{
+ PendingDeviceToDelete: "SDX63200313",
+ },
+ }
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ }
+
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Negative_Case_TriggerPendingVnetDeleteReq",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ VnetsToDelete: vnetToDel,
+ DevicesDisc: sync.Map{},
+ }
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.VnetsByName.Store("2310-4096-4096", voltVnet)
+ va.TriggerPendingVnetDeleteReq(tt.args.cntx, tt.args.device)
+ })
+ }
+}
+
+func TestVoltApplication_UpdateMacInPortMap(t *testing.T) {
+ type args struct {
+ macAddr net.HardwareAddr
+ port string
+ }
+ macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
+ macPort := map[string]string{}
+ macPort[macAdd.String()] = "1234"
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_UpdateMacInPortMap",
+ args: args{
+ macAddr: macAdd,
+ port: "1234",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ macPortMap: macPort,
+ }
+ va.UpdateMacInPortMap(tt.args.macAddr, tt.args.port)
+ })
+ }
+}
+
+func TestVoltApplication_GetMacInPortMap(t *testing.T) {
+ type args struct {
+ macAddr net.HardwareAddr
+ }
+ macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
+ macPort := map[string]string{}
+ macPort[macAdd.String()] = "1234"
+ tests := []struct {
+ name string
+ args args
+ want string
+ }{
+ {
+ name: "Positive_Case_GetMacInPortMap",
+ args: args{
+ macAddr: macAdd,
+ },
+ want: "1234",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ macPortMap: macPort,
+ }
+ if got := va.GetMacInPortMap(tt.args.macAddr); got != tt.want {
+ t.Errorf("VoltApplication.GetMacInPortMap() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func Test_pushFlowFailureNotif(t *testing.T) {
+ type args struct {
+ flowStatus intf.FlowStatus
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_pushFlowFailureNotif",
+ args: args{
+ flowStatus: intf.FlowStatus{
+ Device: "SDX6320031",
+ Cookie: "68786618880",
+ Status: 0,
+ Flow: &of.VoltSubFlow{
+ Cookie: 68786618880,
+ TableID: 0,
+ Priority: 100,
+ ErrorReason: "",
+ OldCookie: 0,
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ pushFlowFailureNotif(tt.args.flowStatus)
+ })
+ }
+}
+
+func TestGetPonPortIDFromUNIPort(t *testing.T) {
+ type args struct {
+ uniPortID uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ want uint32
+ }{
+ {
+ name: "Positive_Case_pushFlowFailureNotif",
+ args: args{
+ uniPortID: 1049600,
+ },
+ want: 1,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := GetPonPortIDFromUNIPort(tt.args.uniPortID); got != tt.want {
+ t.Errorf("GetPonPortIDFromUNIPort() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_ProcessFlowModResultIndication(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ flowStatus intf.FlowStatus
+ }
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ FlowAddEventMap: util.NewConcurrentMap(),
+ }
+ flowState := intf.FlowStatus{
+ Device: "SDX6320031",
+ Cookie: "68786618880",
+ Status: 1005,
+ FlowModType: 0,
+ Flow: &of.VoltSubFlow{
+ Cookie: 68786618880,
+ OldCookie: 0,
+ TableID: 0,
+ State: 0,
+ Priority: 100,
+ },
+ }
+ flowAddEvent := map[string]*FlowEvent{}
+ flowEvent := &FlowEvent{
+ device: "SDX6320031",
+ cookie: "68786618880",
+ eType: EventTypeControlFlowAdded,
+ }
+ flowAddEvent["68786618880"] = flowEvent
+ voltDev.FlowAddEventMap.Set("6878661888", flowEvent)
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_ProcessFlowModResultIndication",
+ args: args{
+ cntx: context.Background(),
+ flowStatus: flowState,
+ },
+ },
+ {
+ name: "Negetive_Case_ProcessFlowModResultIndication",
+ args: args{
+ cntx: context.Background(),
+ flowStatus: flowState,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_ProcessFlowModResultIndication":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus)
+ case "Negetive_Case_ProcessFlowModResultIndication":
+ va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus)
+ }
+ })
+ }
+}
+func Test_getPendingPoolKey(t *testing.T) {
+ type args struct {
+ mvlan of.VlanType
+ device string
+ }
+
+ tests := []struct {
+ name string
+ args args
+ want string
+ }{
+ {
+ name: "Positive_Case_getPendingPoolKey",
+ args: args{
+ mvlan: of.VlanAny,
+ device: "SDX6320031",
+ },
+ want: "4096_SDX6320031",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := getPendingPoolKey(tt.args.mvlan, tt.args.device); got != tt.want {
+ t.Errorf("getPendingPoolKey() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewVoltPort(t *testing.T) {
+ type args struct {
+ device string
+ name string
+ id uint32
+ }
+
+ voltPort := &VoltPort{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ Device: "SDX6320031",
+ ID: 16777472,
+ State: PortStateDown,
+ ChannelPerSubAlarmRaised: false,
+ Type: VoltPortTypeNni,
+ }
+
+ voltPort1 := &VoltPort{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ Device: "SDX6320031",
+ ID: 1049600,
+ State: PortStateDown,
+ ChannelPerSubAlarmRaised: false,
+ PonPort: GetPonPortIDFromUNIPort(1049600),
+ }
+ tests := []struct {
+ name string
+ args args
+ want *VoltPort
+ }{
+ {
+ name: "Positive_Case_TestNewVoltPort",
+ args: args{
+ id: 16777472,
+ device: "SDX6320031",
+ name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ },
+ want: voltPort,
+ },
+ {
+ name: "Positive_Case2_TestNewVoltPort",
+ args: args{
+ id: 1049600,
+ device: "SDX6320031",
+ name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ },
+ want: voltPort1,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "Positive_Case_TestNewVoltPort":
+ if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewVoltPort() = %v, want %v", got, tt.want)
+ }
+ case "Positive_Case2_TestNewVoltPort":
+ if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewVoltPort() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltPort_SetPortID(t *testing.T) {
+ type args struct {
+ id uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_TestNewVoltPort",
+ args: args{
+ id: 16777472,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vp := &VoltPort{
+ ID: 16777472,
+ Type: VoltPortTypeNni,
+ }
+ vp.SetPortID(tt.args.id)
+ })
+ }
+}
+
+func TestNewVoltDevice(t *testing.T) {
+ type args struct {
+ name string
+ slno string
+ southBoundID string
+ }
+
+ devConfig := &DeviceConfig{
+ SerialNumber: "SDX6320033",
+ NniDhcpTrapVid: 4,
+ }
+ voltDevice := &VoltDevice{
+ Name: "11c3175b-50f3-4220-9555-93df733ded1d",
+ SerialNum: "SDX6320033",
+ SouthBoundID: "68580342-6b3e-57cb-9ea4-06125594e330",
+ State: controller.DeviceStateDOWN,
+ NniPort: "",
+ icmpv6GroupAdded: false,
+ IgmpDsFlowAppliedForMvlan: make(map[uint16]bool),
+ ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
+ MigratingServices: util.NewConcurrentMap(),
+ VpvsBySvlan: util.NewConcurrentMap(),
+ FlowAddEventMap: util.NewConcurrentMap(),
+ FlowDelEventMap: util.NewConcurrentMap(),
+ GlobalDhcpFlowAdded: false,
+ NniDhcpTrapVid: 4,
+ }
+
+ GetApplication().DevicesConfig.Store("SDX6320033", devConfig)
+ tests := []struct {
+ name string
+ args args
+ want *VoltDevice
+ }{
+ {
+ name: "Positive_Case_TestNewVoltDevice",
+ args: args{
+ name: "11c3175b-50f3-4220-9555-93df733ded1d",
+ slno: "SDX6320033",
+ southBoundID: "68580342-6b3e-57cb-9ea4-06125594e330",
+ },
+ want: voltDevice,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewVoltDevice(tt.args.name, tt.args.slno, tt.args.southBoundID); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewVoltDevice() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_GetAssociatedVpvsForDevice(t *testing.T) {
+ type args struct {
+ device string
+ svlan of.VlanType
+ }
+
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320033",
+ NniDhcpTrapVid: 123,
+ VpvsBySvlan: util.NewConcurrentMap(),
+ }
+
+ cuncurrentMap := &util.ConcurrentMap{
+ Count: atomic.NewUint64(0),
+ }
+
+ voltDev1 := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320033",
+ NniDhcpTrapVid: 123,
+ VpvsBySvlan: cuncurrentMap,
+ }
+ tests := []struct {
+ name string
+ args args
+ want *util.ConcurrentMap
+ }{
+ {
+ name: "Positive_Case_GetAssociatedVpvsForDevice",
+ args: args{
+ device: "SDX6320033",
+ svlan: of.VlanAny,
+ },
+ want: util.NewConcurrentMap(),
+ },
+ {
+ name: "Positive_Case2_GetAssociatedVpvsForDevice",
+ args: args{
+ device: "SDX6320033",
+ svlan: of.VlanAny,
+ },
+ want: cuncurrentMap,
+ },
+ {
+ name: "Negetive_Case2_GetAssociatedVpvsForDevice",
+ args: args{
+ device: "SDX6320031",
+ svlan: of.VlanAny,
+ },
+ want: nil,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "Positive_Case_GetAssociatedVpvsForDevice":
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ VnetsBySvlan: util.NewConcurrentMap(),
+ }
+ va.DevicesDisc.Store("SDX6320033", voltDev)
+ if got := va.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
+ }
+ case "Positive_Case2_GetAssociatedVpvsForDevice":
+ va1 := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ VnetsBySvlan: cuncurrentMap,
+ }
+ va1.DevicesDisc.Store("SDX6320033", voltDev1)
+ va1.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap)
+ if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
+ }
+ case "Negetive_Case2_GetAssociatedVpvsForDevice":
+ va1 := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ }
+ if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltApplication_AssociateVpvsToDevice(t *testing.T) {
+ type args struct {
+ device string
+ vpv *VoltPortVnet
+ }
+
+ vpv := &VoltPortVnet{
+ Device: "SDX6320033",
+ SVlan: of.VlanAny,
+ }
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320033",
+ NniDhcpTrapVid: 123,
+ VpvsBySvlan: util.NewConcurrentMap(),
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_AssociateVpvsToDevice",
+ args: args{
+ device: "SDX6320033",
+ vpv: vpv,
+ },
+ },
+ {
+ name: "Negetive_Case_AssociateVpvsToDevice",
+ args: args{
+ device: "SDX6320033",
+ vpv: vpv,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "Positive_Case_AssociateVpvsToDevice":
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ VnetsBySvlan: util.NewConcurrentMap(),
+ }
+ va.DevicesDisc.Store("SDX6320033", voltDev)
+ va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv)
+ case "Negetive_Case_AssociateVpvsToDevice":
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ VnetsBySvlan: util.NewConcurrentMap(),
+ }
+ va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_DisassociateVpvsFromDevice(t *testing.T) {
+ type args struct {
+ device string
+ vpv *VoltPortVnet
+ }
+ vpv := &VoltPortVnet{
+ Device: "SDX6320033",
+ SVlan: of.VlanAny,
+ }
+
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320033",
+ NniDhcpTrapVid: 123,
+ VpvsBySvlan: util.NewConcurrentMap(),
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_DisassociateVpvsFromDevice",
+ args: args{
+ device: "SDX6320033",
+ vpv: vpv,
+ },
+ },
+ {
+ name: "Negetive_Case_DisassociateVpvsFromDevice",
+ args: args{
+ device: "SDX6320033",
+ vpv: vpv,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "Positive_Case_DisassociateVpvsFromDevice":
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ VnetsBySvlan: util.NewConcurrentMap(),
+ }
+ va.DevicesDisc.Store("SDX6320033", voltDev)
+ va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv)
+ case "Negetive_Case_DisassociateVpvsFromDevice":
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ VnetsBySvlan: util.NewConcurrentMap(),
+ }
+ va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv)
+ }
+ })
+ }
+}
+
+func TestVoltDevice_GetPort(t *testing.T) {
+ type args struct {
+ port string
+ }
+ voltPort := &VoltPort{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ Device: "SDX6320031",
+ ID: 16777472,
+ State: PortStateDown,
+ ChannelPerSubAlarmRaised: false,
+ Type: VoltPortTypeNni,
+ }
+ tests := []struct {
+ name string
+ args args
+ want *VoltPort
+ }{
+ {
+ name: "Positive_Case_GetPort",
+ args: args{
+ port: "16777472",
+ },
+ want: voltPort,
+ },
+ {
+ name: "Negetive_Case_GetPort",
+ args: args{
+ port: "16777472",
+ },
+ want: nil,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &VoltDevice{
+ Ports: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_GetPort":
+ d.Ports.Store("16777472", voltPort)
+ if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want)
+ }
+ case "Negetive_Case_GetPort":
+ if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltDevice_GetPortNameFromPortID(t *testing.T) {
+ type args struct {
+ portID uint32
+ }
+ voltPort := &VoltPort{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ Device: "SDX6320031",
+ ID: 16777472,
+ State: PortStateDown,
+ ChannelPerSubAlarmRaised: false,
+ Type: VoltPortTypeNni,
+ }
+ tests := []struct {
+ name string
+ args args
+ want string
+ }{
+ {
+ name: "Positive_Case_GetPort",
+ args: args{
+ portID: 16777472,
+ },
+ want: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &VoltDevice{
+ Ports: sync.Map{},
+ }
+ d.Ports.Store(16777472, voltPort)
+ if got := d.GetPortNameFromPortID(tt.args.portID); got != tt.want {
+ t.Errorf("VoltDevice.GetPortNameFromPortID() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltDevice_DelPort(t *testing.T) {
+ type args struct {
+ port string
+ }
+ voltPort := &VoltPort{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ Device: "SDX6320031",
+ ID: 16777472,
+ State: PortStateDown,
+ ChannelPerSubAlarmRaised: false,
+ Type: VoltPortTypeNni,
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_DelPort",
+ args: args{
+ port: "16777472",
+ },
+ },
+ {
+ name: "Negetive_Case_DelPort",
+ args: args{
+ port: "16777472",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &VoltDevice{
+ Ports: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_DelPort":
+ d.Ports.Store("16777472", voltPort)
+ d.DelPort(tt.args.port)
+ case "Negetive_Case_DelPort":
+ d.DelPort(tt.args.port)
+ }
+ })
+ }
+}
+
+func TestVoltDevice_pushFlowsForUnis(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_pushFlowsForUnis",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ {
+ name: "Negetive_Case_pushFlowsForUnis",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ {
+ name: "Negetive_Case1_pushFlowsForUnis",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ Ports: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_pushFlowsForUnis":
+ voltPort := &VoltPort{
+ Name: "16777472",
+ Device: "SDX6320031",
+ ID: 16777472,
+ State: PortStateUp,
+ ChannelPerSubAlarmRaised: false,
+ Type: VoltPortTypeNni,
+ }
+ d.Ports.Store("16777472", voltPort)
+ ga := GetApplication()
+ voltPortVnets := make([]*VoltPortVnet, 0)
+ voltPortVnet := &VoltPortVnet{
+ Device: "SDX6320031",
+ Port: "16777472",
+ DeleteInProgress: true,
+ }
+ voltPortVnets = append(voltPortVnets, voltPortVnet)
+ ga.VnetsByPort.Store("16777472", voltPortVnets)
+
+ d.pushFlowsForUnis(tt.args.cntx)
+ case "Negetive_Case_pushFlowsForUnis":
+ voltPort1 := &VoltPort{
+ Name: "16777472",
+ Device: "SDX6320031",
+ ID: 16777472,
+ State: PortStateDown,
+ ChannelPerSubAlarmRaised: false,
+ Type: VoltPortTypeNni,
+ }
+ d.Ports.Store("16777472", voltPort1)
+ d.pushFlowsForUnis(tt.args.cntx)
+ case "Negetive_Case1_pushFlowsForUnis":
+ voltPort2 := &VoltPort{
+ Name: "16777472",
+ Device: "SDX6320031",
+ ID: 16777472,
+ State: PortStateUp,
+ ChannelPerSubAlarmRaised: false,
+ Type: VoltPortTypeNni,
+ }
+ d.Ports.Store("1677747", voltPort2)
+ d.pushFlowsForUnis(tt.args.cntx)
+ }
+ })
+ }
+}
+
+func TestNewNbDevice(t *testing.T) {
+ tests := []struct {
+ name string
+ want *NbDevice
+ }{
+ {
+ name: "Positive_Case_pushFlowsForUnis",
+ want: &NbDevice{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewNbDevice(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewNbDevice() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNbDevice_WriteToDb(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ portID uint32
+ ponPort *PonPortCfg
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_pushFlowsForUnis",
+ args: args{
+ cntx: context.Background(),
+ portID: controller.NNIPortID,
+ ponPort: &PonPortCfg{
+ PortID: controller.NNIPortID,
+ EnableMulticastKPI: false,
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ nbd := &NbDevice{
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ }
+ switch tt.name {
+ case "Positive_Case_pushFlowsForUnis":
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+ nbd.WriteToDb(tt.args.cntx, tt.args.portID, tt.args.ponPort)
+ }
+ })
+ }
+}
+
+func TestNbDevice_AddPortToNbDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ portID uint32
+ allowedChannels uint32
+ enableMulticastKPI bool
+ portAlarmProfileID string
+ }
+ ponPort := &PonPortCfg{
+ PortID: controller.NNIPortID,
+ MaxActiveChannels: 123,
+ EnableMulticastKPI: false,
+ PortAlarmProfileID: "16777",
+ }
+ tests := []struct {
+ name string
+ args args
+ want *PonPortCfg
+ }{
+ {
+ name: "Positive_Case_AddPortToNbDevice",
+ args: args{
+ cntx: context.Background(),
+ portID: controller.NNIPortID,
+ allowedChannels: 123,
+ enableMulticastKPI: false,
+ portAlarmProfileID: "16777",
+ },
+ want: ponPort,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ nbd := &NbDevice{
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ PonPorts: sync.Map{},
+ }
+ nbd.PonPorts.Store(controller.NNIPortID, ponPort)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+ if got := nbd.AddPortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NbDevice.AddPortToNbDevice() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_AddDeviceConfig(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ serialNum string
+ hardwareIdentifier string
+ nasID string
+ ipAddress string
+ uplinkPort string
+ nniDhcpTrapID int
+ }
+ dvcConfg := &DeviceConfig{
+ SerialNumber: "SDX6320031",
+ HardwareIdentifier: "0.0.0.0",
+ IPAddress: "127.26.1.74",
+ UplinkPort: "16777216",
+ NasID: "12345",
+ NniDhcpTrapVid: 123,
+ }
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "Positive_Case_AddDeviceConfig",
+ args: args{
+ cntx: context.Background(),
+ serialNum: "SDX6320031",
+ hardwareIdentifier: "0.0.0.0.",
+ nasID: "12345",
+ ipAddress: "127.26.1.74",
+ uplinkPort: "16777216",
+ nniDhcpTrapID: 123,
+ },
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesConfig: sync.Map{},
+ }
+ va.DevicesConfig.Store("SDX6320031", dvcConfg)
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ if err := va.AddDeviceConfig(tt.args.cntx, tt.args.serialNum, tt.args.hardwareIdentifier, tt.args.nasID, tt.args.ipAddress, tt.args.uplinkPort, tt.args.nniDhcpTrapID); (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.AddDeviceConfig() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_GetDeviceConfig(t *testing.T) {
+ type args struct {
+ serNum string
+ }
+ dvcConfg := &DeviceConfig{
+ SerialNumber: "SDX6320031",
+ HardwareIdentifier: "0.0.0.0",
+ IPAddress: "127.26.1.74",
+ UplinkPort: "16777216",
+ NasID: "12345",
+ NniDhcpTrapVid: 123,
+ }
+ tests := []struct {
+ name string
+ args args
+ want *DeviceConfig
+ }{
+ {
+ name: "Positive_Case_GetDeviceConfig",
+ args: args{
+ serNum: "SDX6320031",
+ },
+ want: dvcConfg,
+ },
+ {
+ name: "Negetive_Case_GetDeviceConfig",
+ args: args{
+ serNum: "SDX6320031",
+ },
+ want: nil,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesConfig: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_GetDeviceConfig":
+ va.DevicesConfig.Store("SDX6320031", dvcConfg)
+ if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want)
+ }
+ case "Negetive_Case_GetDeviceConfig":
+ if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
+
+func TestNbDevice_UpdatePortToNbDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ portID uint32
+ allowedChannels uint32
+ enableMulticastKPI bool
+ portAlarmProfileID string
+ }
+ ponPort := &PonPortCfg{
+ PortID: controller.NNIPortID,
+ MaxActiveChannels: 123,
+ EnableMulticastKPI: false,
+ PortAlarmProfileID: "16777",
+ }
+ tests := []struct {
+ name string
+ args args
+ want *PonPortCfg
+ }{
+ {
+ name: "Positive_Case_UpdatePortToNbDevice",
+ args: args{
+ cntx: context.Background(),
+ portID: controller.NNIPortID,
+ allowedChannels: 123,
+ enableMulticastKPI: false,
+ portAlarmProfileID: "16777",
+ },
+ want: ponPort,
+ },
+ {
+ name: "Negetive_Case_UpdatePortToNbDevice",
+ args: args{
+ cntx: context.Background(),
+ portID: 0,
+ allowedChannels: 123,
+ enableMulticastKPI: false,
+ portAlarmProfileID: "16777",
+ },
+ want: nil,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ nbd := &NbDevice{
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ PonPorts: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_UpdatePortToNbDevice":
+ nbd.PonPorts.Store(controller.NNIPortID, ponPort)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+ if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want)
+ }
+ case "Negetive_Case_UpdatePortToNbDevice":
+ if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
+
+func TestNbDevice_DeletePortFromNbDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ portID uint32
+ }
+ ponPort := &PonPortCfg{
+ PortID: controller.NNIPortID,
+ MaxActiveChannels: 123,
+ EnableMulticastKPI: false,
+ PortAlarmProfileID: "16777",
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_DeletePortFromNbDevice",
+ args: args{
+ portID: controller.NNIPortID,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ nbd := &NbDevice{
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ PonPorts: sync.Map{},
+ }
+ nbd.PonPorts.Store(controller.NNIPortID, ponPort)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().DelNbDevicePort(nil, "49686e2d-618f-4e8e-bca0-442ab850a63a", controller.NNIPortID).AnyTimes()
+ nbd.DeletePortFromNbDevice(tt.args.cntx, tt.args.portID)
+ })
+ }
+}
+
+func TestVoltDevice_RegisterFlowAddEvent(t *testing.T) {
+ type args struct {
+ cookie string
+ event *FlowEvent
+ }
+ flowEvent := &FlowEvent{
+ device: "SDX6320031",
+ cookie: "68786618880",
+ eType: EventTypeControlFlowAdded,
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_RegisterFlowAddEvent",
+ args: args{
+ cookie: "68786618880",
+ event: flowEvent,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &VoltDevice{
+ FlowAddEventMap: util.NewConcurrentMap(),
+ }
+ d.RegisterFlowAddEvent(tt.args.cookie, tt.args.event)
+ })
+ }
+}
+
+func TestVoltDevice_RegisterFlowDelEvent(t *testing.T) {
+ type args struct {
+ cookie string
+ event *FlowEvent
+ }
+ flowEvent := &FlowEvent{
+ device: "SDX6320031",
+ cookie: "68786618880",
+ eType: EventTypeControlFlowRemoved,
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_RegisterFlowDelEvent",
+ args: args{
+ cookie: "68786618880",
+ event: flowEvent,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &VoltDevice{
+ FlowDelEventMap: util.NewConcurrentMap(),
+ }
+ d.RegisterFlowDelEvent(tt.args.cookie, tt.args.event)
+ })
+ }
+}
+
+func TestVoltDevice_UnRegisterFlowEvent(t *testing.T) {
+ type args struct {
+ cookie string
+ flowModType of.Command
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_RegisterFlowDelEvent",
+ args: args{
+ cookie: "68786618880",
+ flowModType: of.CommandDel,
+ },
+ },
+ {
+ name: "Negetive_Case_RegisterFlowDelEvent",
+ args: args{
+ cookie: "68786618880",
+ flowModType: opt82,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "Positive_Case_RegisterFlowDelEvent":
+ d := &VoltDevice{
+ FlowDelEventMap: util.NewConcurrentMap(),
+ }
+ d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType)
+ case "Negetive_Case_RegisterFlowDelEvent":
+ d := &VoltDevice{
+ FlowDelEventMap: util.NewConcurrentMap(),
+ }
+ d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_InitStaticConfig(t *testing.T) {
+ tests := []struct {
+ name string
+ }{
+ {
+ name: "Positive_Case_InitStaticConfig",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.InitStaticConfig()
+ })
+ }
+}
+
+func TestVoltApplication_SetVendorID(t *testing.T) {
+ type args struct {
+ vendorID string
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_SetVendorID",
+ args: args{
+ vendorID: "DT",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.SetVendorID(tt.args.vendorID)
+ })
+ }
+}
+
+func TestVoltApplication_GetVendorID(t *testing.T) {
+ tests := []struct {
+ name string
+ want string
+ }{
+ {
+ name: "Positive_Case_GetVendorID",
+ want: "DT",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ vendorID: "DT",
+ }
+ if got := va.GetVendorID(); got != tt.want {
+ t.Errorf("VoltApplication.GetVendorID() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_SetRebootFlag(t *testing.T) {
+ type args struct {
+ flag bool
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_SetRebootFlag",
+ args: args{
+ flag: true,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.SetRebootFlag(tt.args.flag)
+ })
+ }
+}
+
+func TestVoltApplication_GetUpgradeFlag(t *testing.T) {
+ tests := []struct {
+ name string
+ want bool
+ }{
+ {
+ name: "Positive_Case_GetUpgradeFlag",
+ want: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ isUpgradeComplete = true
+ if got := va.GetUpgradeFlag(); got != tt.want {
+ t.Errorf("VoltApplication.GetUpgradeFlag() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_SetUpgradeFlag(t *testing.T) {
+ type args struct {
+ flag bool
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_GetUpgradeFlag",
+ args: args{
+ flag: true,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.SetUpgradeFlag(tt.args.flag)
+ })
+ }
+}
+
+func TestVoltApplication_AddDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ slno string
+ southBoundID string
+ }
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ NniPort: "16777216",
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
+ }
+ nbd := &NbDevice{
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
+ PonPorts: sync.Map{},
+ }
+ ponPortCnf := &PonPortCfg{
+ PortID: controller.NNIPortID,
+ MaxActiveChannels: 123,
+ EnableMulticastKPI: false,
+ PortAlarmProfileID: "16777",
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_AddDevice",
+ args: args{
+ cntx: context.Background(),
+ device: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ slno: "SDX6320031",
+ southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
+ },
+ },
+ {
+ name: "Negetive_Case_AddDevice",
+ args: args{
+ cntx: context.Background(),
+ device: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ slno: "SDX6320031",
+ southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ NbDevice: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_AddDevice":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a123", nbd)
+ nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
+ va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID)
+ case "Negetive_Case_AddDevice":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().GetAllNbPorts(context.Background(), "49686e2d-618f-4e8e-bca0-442ab850a63a123").AnyTimes()
+ va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_DelDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ }
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ NniPort: "16777216",
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_AddDevice",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ },
+ },
+ {
+ name: "Delete_Case_AddDevice",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_AddDevice":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().DelAllRoutesForDevice(context.Background(), "SDX6320031").AnyTimes()
+ dbintf.EXPECT().GetAllMigrateServicesReq(context.Background(), "SDX6320031").AnyTimes()
+ dbintf.EXPECT().DelAllGroup(context.Background(), "SDX6320031").AnyTimes()
+ dbintf.EXPECT().DelAllMeter(context.Background(), "SDX6320031").AnyTimes()
+ dbintf.EXPECT().DelAllPorts(context.Background(), "SDX6320031").AnyTimes()
+ va.DelDevice(tt.args.cntx, tt.args.device)
+ case "Delete_Case_AddDevice":
+ va.DelDevice(tt.args.cntx, tt.args.device)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_PortAddInd(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ id uint32
+ portName string
+ }
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ NniPort: "16777216",
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_PortAddInd",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ id: controller.NNIPortID,
+ portName: "16777216",
+ },
+ },
+ {
+ name: "Negetive_Case_PortAddInd",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ id: controller.NNIPortID,
+ portName: "16777216",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_PortAddInd":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName)
+ case "Negetive_Case_PortAddInd":
+ va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_PortUpdateInd(t *testing.T) {
+ type args struct {
+ device string
+ portName string
+ id uint32
+ }
+ voltDev := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ NniPort: "16777216",
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_PortUpdateInd",
+ args: args{
+ device: "SDX6320031",
+ id: controller.NNIPortID,
+ portName: "16777216",
+ },
+ },
+ {
+ name: "Negetive_Case_PortUpdateInd",
+ args: args{
+ device: "SDX6320031",
+ id: controller.NNIPortID,
+ portName: "16777216",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_PortAddInd":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ d := &VoltDevice{
+ Ports: sync.Map{},
+ }
+ voltPort := &VoltPort{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ Device: "SDX6320031",
+ ID: 16777472,
+ State: PortStateDown,
+ ChannelPerSubAlarmRaised: false,
+ Type: VoltPortTypeNni,
+ }
+ d.Ports.Store(16777472, voltPort)
+ va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id)
+ case "Negetive_Case_PortUpdateInd":
+ va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_AddNbPonPort(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ oltSbID string
+ portID uint32
+ maxAllowedChannels uint32
+ enableMulticastKPI bool
+ portAlarmProfileID string
+ }
+ voltDev := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ NniPort: "16777216",
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ }
+ nbd := &NbDevice{
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "Positive_Case_AddNbPonPort",
+ args: args{
+ cntx: context.Background(),
+ oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ portID: 16777472,
+ maxAllowedChannels: 0,
+ enableMulticastKPI: false,
+ portAlarmProfileID: "16777",
+ },
+ },
+ {
+ name: "Negetive_Case_AddNbPonPort",
+ args: args{
+ cntx: context.Background(),
+ oltSbID: "0",
+ portID: 16777472,
+ maxAllowedChannels: 0,
+ enableMulticastKPI: false,
+ portAlarmProfileID: "16777",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ NbDevice: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_AddNbPonPort":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+ if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "Negetive_Case_AddNbPonPort":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+ if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltApplication_UpdateNbPonPort(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ oltSbID string
+ portID uint32
+ maxAllowedChannels uint32
+ enableMulticastKPI bool
+ portAlarmProfileID string
+ }
+ voltDev := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ NniPort: "16777216",
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ ActiveChannelsPerPon: sync.Map{},
+ }
+ nbd := &NbDevice{
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ PonPorts: sync.Map{},
+ }
+ ponPortCnf := &PonPortCfg{
+ PortID: controller.NNIPortID,
+ MaxActiveChannels: 123,
+ EnableMulticastKPI: false,
+ PortAlarmProfileID: "16777",
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "Positive_Case_UpdateNbPonPort",
+ args: args{
+ cntx: context.Background(),
+ oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ portID: controller.NNIPortID,
+ maxAllowedChannels: 0,
+ enableMulticastKPI: false,
+ portAlarmProfileID: "16777",
+ },
+ wantErr: false,
+ },
+ {
+ name: "Negetive_Case_Port_doesn't_exists",
+ args: args{
+ cntx: context.Background(),
+ oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ portID: 16777472,
+ maxAllowedChannels: 0,
+ enableMulticastKPI: false,
+ portAlarmProfileID: "16777",
+ },
+ wantErr: true,
+ },
+ {
+ name: "Negetive_Case_Device-doesn't-exists",
+ args: args{
+ cntx: context.Background(),
+ oltSbID: "0",
+ portID: 16777472,
+ maxAllowedChannels: 0,
+ enableMulticastKPI: false,
+ portAlarmProfileID: "16777",
+ },
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ NbDevice: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_UpdateNbPonPort":
+ va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
+ nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+ if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "Negetive_Case_Port_doesn't_exists":
+ va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+ if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "Negetive_Case_Device-doesn't-exists":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+ if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltApplication_DeleteNbPonPort(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ oltSbID string
+ portID uint32
+ }
+ voltDev := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ NniPort: "16777216",
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ ActiveChannelsPerPon: sync.Map{},
+ }
+ nbd := &NbDevice{
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ }
+ ponPortCnf := &PonPortCfg{
+ PortID: controller.NNIPortID,
+ MaxActiveChannels: 123,
+ EnableMulticastKPI: false,
+ PortAlarmProfileID: "16777",
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "Positive_Case_DeleteNbPonPort",
+ args: args{
+ cntx: context.Background(),
+ oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ portID: controller.NNIPortID,
+ },
+ wantErr: false,
+ },
+ {
+ name: "Negetive_Case_DeleteNbPonPort",
+ args: args{
+ cntx: context.Background(),
+ oltSbID: "0",
+ portID: controller.NNIPortID,
+ },
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ NbDevice: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_DeleteNbPonPort":
+ va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
+ nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf)
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+ if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "Negetive_Case_DeleteNbPonPort":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+ if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltApplication_DeviceUpInd(t *testing.T) {
+ type args struct {
+ device string
+ }
+ voltDev := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ NniPort: "16777216",
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_DeviceUpInd",
+ args: args{
+ device: "SDX6320031",
+ },
+ },
+ {
+ name: "Negetive_Case_DeviceUpInd",
+ args: args{
+ device: "o",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_DeviceUpInd":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.DeviceUpInd(tt.args.device)
+ case "Negetive_Case_DeviceUpInd":
+ va.DeviceUpInd(tt.args.device)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_DeviceDownInd(t *testing.T) {
+ type args struct {
+ device string
+ }
+ voltDev := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ NniPort: "16777216",
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_DeviceDownInd",
+ args: args{
+ device: "SDX6320031",
+ },
+ },
+ {
+ name: "Negetive_Case_DeviceDownInd",
+ args: args{
+ device: "o",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ }
+ switch tt.name {
+ case "Positive_Case_DeviceDownInd":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.DeviceDownInd(tt.args.device)
+ case "Negetive_Case_DeviceDownInd":
+ va.DeviceDownInd(tt.args.device)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_DeviceRebootInd(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ serialNum string
+ southBoundID string
+ }
+ voltDev := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ NniPort: "16777216",
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ State: controller.DeviceStateREBOOTED,
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Positive_Case_DeviceRebootInd",
+ args: args{
+ device: "SDX6320031",
+ serialNum: "SDX6320031",
+ southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ }
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID)
+ })
+ }
+}
diff --git a/internal/pkg/application/flowevent_test.go b/internal/pkg/application/flowevent_test.go
new file mode 100644
index 0000000..400176a
--- /dev/null
+++ b/internal/pkg/application/flowevent_test.go
@@ -0,0 +1,290 @@
+/*
+* Copyright 2022-present Open Networking Foundation
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package application
+
+import (
+ "context"
+ "testing"
+ "voltha-go-controller/internal/pkg/intf"
+ "voltha-go-controller/internal/pkg/of"
+ "voltha-go-controller/internal/pkg/util"
+ "voltha-go-controller/internal/test/mocks"
+
+ "github.com/golang/mock/gomock"
+)
+
+var voltPortVnet = &VoltPortVnet{
+ Device: "test_device",
+}
+var voltService = &VoltService{
+ Version: "test_version",
+}
+
+func TestExecuteFlowEvent(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ vd *VoltDevice
+ cookie string
+ flowStatus intf.FlowStatus
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "ExecuteFlowEvent_add",
+ args: args{
+ cntx: context.Background(),
+ vd: &VoltDevice{
+ SouthBoundID: "test_device_id",
+ FlowAddEventMap: util.NewConcurrentMap(),
+ },
+ cookie: "test_cookie",
+ flowStatus: intf.FlowStatus{
+ Device: "test_device",
+ FlowModType: of.CommandAdd,
+ },
+ },
+ },
+ {
+ name: "ExecuteFlowEvent_del",
+ args: args{
+ cntx: context.Background(),
+ vd: &VoltDevice{
+ SouthBoundID: "test_device_id",
+ FlowDelEventMap: util.NewConcurrentMap(),
+ },
+ cookie: "test_cookie",
+ flowStatus: intf.FlowStatus{
+ Device: "test_device",
+ FlowModType: of.CommandDel,
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "ExecuteFlowEvent_add":
+ if got := ExecuteFlowEvent(tt.args.cntx, tt.args.vd, tt.args.cookie, tt.args.flowStatus); got != tt.want {
+ t.Errorf("ExecuteFlowEvent() = %v, want %v", got, tt.want)
+ }
+ case "ExecuteFlowEvent_del":
+ if got := ExecuteFlowEvent(tt.args.cntx, tt.args.vd, tt.args.cookie, tt.args.flowStatus); got != tt.want {
+ t.Errorf("ExecuteFlowEvent() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
+
+func TestInitEventFuncMapper(t *testing.T) {
+ tests := []struct {
+ name string
+ }{
+ {
+ name: "InitEventFuncMapper",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ InitEventFuncMapper()
+ })
+ }
+}
+
+func TestProcessUsIgmpFlowAddEvent(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ event *FlowEvent
+ flowStatus intf.FlowStatus
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "ProcessUsIgmpFlowAddEvent",
+ args: args{
+ cntx: context.Background(),
+ event: &FlowEvent{
+ device: "test_device",
+ eType: EventTypeControlFlowAdded,
+ eventData: voltPortVnet,
+ },
+ flowStatus: intf.FlowStatus{
+ Device: "test_device",
+ Status: uint32(0),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ProcessUsIgmpFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
+ })
+ }
+}
+
+func TestProcessServiceFlowAddEvent(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ event *FlowEvent
+ flowStatus intf.FlowStatus
+ }
+
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "ProcessServiceFlowAddEvent",
+ args: args{
+ cntx: context.Background(),
+ event: &FlowEvent{
+ device: "test_device",
+ eventData: voltService,
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ProcessServiceFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
+ })
+ }
+}
+
+func TestProcessControlFlowAddEvent(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ event *FlowEvent
+ flowStatus intf.FlowStatus
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "ProcessControlFlowAddEvent",
+ args: args{
+ cntx: context.Background(),
+ event: &FlowEvent{
+ eventData: voltPortVnet,
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ProcessControlFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
+ })
+ }
+}
+
+func TestProcessServiceFlowDelEvent(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ event *FlowEvent
+ flowStatus intf.FlowStatus
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "ProcessServiceFlowDelEvent",
+ args: args{
+ cntx: context.Background(),
+ event: &FlowEvent{
+ eventData: voltService,
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
+ ProcessServiceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
+ })
+ }
+}
+
+func TestProcessControlFlowDelEvent(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ event *FlowEvent
+ flowStatus intf.FlowStatus
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "ProcessControlFlowDelEvent",
+ args: args{
+ cntx: context.Background(),
+ event: &FlowEvent{
+ eventData: voltPortVnet,
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
+ ProcessControlFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
+ })
+ }
+}
+
+func TestProcessMcastFlowDelEvent(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ event *FlowEvent
+ flowStatus intf.FlowStatus
+ }
+ mvlanProfile := &MvlanProfile{
+ Version: "test_version",
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "ProcessMcastFlowDelEvent",
+ args: args{
+ cntx: context.Background(),
+ event: &FlowEvent{
+ eventData: mvlanProfile,
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
+ ProcessMcastFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
+ })
+ }
+}
diff --git a/internal/pkg/application/igmp_test.go b/internal/pkg/application/igmp_test.go
new file mode 100644
index 0000000..9e1e940
--- /dev/null
+++ b/internal/pkg/application/igmp_test.go
@@ -0,0 +1,36 @@
+/*
+* Copyright 2022-present Open Networking Foundation
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package application
+
+import (
+ "testing"
+)
+
+func TestVoltApplication_InitIgmpSrcMac(t *testing.T) {
+ tests := []struct {
+ name string
+ }{
+ {
+ name: "test",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.InitIgmpSrcMac()
+ })
+ }
+}
diff --git a/internal/pkg/application/service_test.go b/internal/pkg/application/service_test.go
new file mode 100644
index 0000000..b9c458b
--- /dev/null
+++ b/internal/pkg/application/service_test.go
@@ -0,0 +1,1552 @@
+/*
+* Copyright 2022-present Open Networking Foundation
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package application
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "sync"
+ "testing"
+ "voltha-go-controller/internal/pkg/controller"
+ cntlr "voltha-go-controller/internal/pkg/controller"
+ "voltha-go-controller/internal/pkg/of"
+ "voltha-go-controller/internal/pkg/util"
+ "voltha-go-controller/internal/test/mocks"
+
+ "github.com/golang/mock/gomock"
+ "github.com/google/gopacket/layers"
+ "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
+ "github.com/stretchr/testify/assert"
+ "go.uber.org/atomic"
+)
+
+var test_device = "test_device"
+var voltPort = &VoltPort{
+ Name: "test_name",
+ Device: test_device,
+}
+var voltDevice = &VoltDevice{
+ Name: "test_name",
+ State: controller.DeviceStateUP,
+ FlowAddEventMap: util.NewConcurrentMap(),
+ FlowDelEventMap: util.NewConcurrentMap(),
+ SerialNum: "test_serial_number",
+}
+
+var voltMeter = &VoltMeter{
+ Name: "test_volt_meter",
+ Version: "test_version",
+}
+
+var voltVnet = &VoltVnet{
+ Version: "test_version",
+ VnetConfig: VnetConfig{
+ Name: "test_name",
+ },
+}
+
+var voltPortVnet1 = []*VoltPortVnet{
+ {
+ Device: "4096-4096-4096",
+ SVlan: of.VlanAny,
+ CVlan: of.VlanAny,
+ UniVlan: of.VlanAny,
+ IgmpEnabled: true,
+ servicesCount: &atomic.Uint64{},
+ },
+}
+
+var voltDevice1 = &VoltDevice{
+ State: cntlr.DeviceStateDOWN,
+}
+
+var GetDeviceFromPort_error = "GetDeviceFromPort_error"
+
+func TestVoltApplication_RestoreSvcsFromDb(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltApplication_RestoreSvcsFromDb",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ {
+ name: "invalid_value_type",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ {
+ name: "unmarshal_error",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ voltService := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ Device: "SDX6320031",
+ ForceDelete: true,
+ DeleteInProgress: true,
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ Name: "test_service_name",
+ },
+ }
+ serviceToDelete := map[string]bool{}
+ serviceToDelete[voltService.VoltServiceCfg.Name] = true
+ va := &VoltApplication{
+ ServicesToDelete: serviceToDelete,
+ }
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ switch tt.name {
+ case "VoltApplication_RestoreSvcsFromDb":
+
+ b, err := json.Marshal(voltService)
+ if err != nil {
+ panic(err)
+ }
+ kvPair := map[string]*kvstore.KVPair{}
+ kvPair["key"] = &kvstore.KVPair{
+ Key: "test_key",
+ Value: b,
+ Version: 1,
+ }
+ dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1)
+ va.RestoreSvcsFromDb(tt.args.cntx)
+ case "invalid_value_type":
+ kvPair := map[string]*kvstore.KVPair{}
+ kvPair["key"] = &kvstore.KVPair{
+ Key: "test_key",
+ Value: "invalid_value",
+ Version: 1,
+ }
+ dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1)
+ va.RestoreSvcsFromDb(tt.args.cntx)
+ case "unmarshal_error":
+ b, err := json.Marshal("test")
+ if err != nil {
+ panic(err)
+ }
+ kvPair := map[string]*kvstore.KVPair{}
+ kvPair["key"] = &kvstore.KVPair{
+ Key: "test_key",
+ Value: b,
+ Version: 1,
+ }
+ dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1)
+ va.RestoreSvcsFromDb(tt.args.cntx)
+ }
+ })
+ }
+}
+
+func TestVoltService_FlowRemoveFailure(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ cookie string
+ errorCode uint32
+ errReason string
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltService_FlowRemoveFailure",
+ args: args{
+ cntx: context.Background(),
+ cookie: "test_cookie",
+ errorCode: 200,
+ errReason: "test_reason",
+ },
+ },
+ {
+ name: "cookie_not_found",
+ args: args{
+ cntx: context.Background(),
+ cookie: "test_cookie",
+ errorCode: 200,
+ errReason: "test_reason",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "VoltService_FlowRemoveFailure":
+ associatedFlows := map[string]bool{}
+ associatedFlows["test_cookie"] = true
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ AssociatedFlows: associatedFlows,
+ },
+ }
+ vs.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.errorCode, tt.args.errReason)
+ case "cookie_not_found":
+ associatedFlows := map[string]bool{}
+ associatedFlows["cookie"] = true
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ AssociatedFlows: associatedFlows,
+ },
+ }
+ vs.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.errorCode, tt.args.errReason)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_GetServiceNameFromCookie(t *testing.T) {
+ type args struct {
+ cookie uint64
+ portName string
+ pbit uint8
+ device string
+ tableMetadata uint64
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltApplication_GetServiceNameFromCookie",
+ args: args{
+ cookie: uint64(1),
+ portName: "test_port_name",
+ device: "SDX6320031",
+ pbit: 2,
+ tableMetadata: uint64(2),
+ },
+ },
+ }
+ voltDev := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ga := GetApplication()
+ ga.DevicesDisc.Store("SDX6320031", voltDev)
+ voltPortVnets := make([]*VoltPortVnet, 0)
+ voltPortVnet := &VoltPortVnet{
+ Device: test_device,
+ VlanControl: ONUCVlanOLTSVlan,
+ }
+ voltPortVnets = append(voltPortVnets, voltPortVnet)
+ ga.VnetsByPort.Store("test_port_name", voltPortVnets)
+ got := ga.GetServiceNameFromCookie(tt.args.cookie, tt.args.portName, tt.args.pbit, tt.args.device, tt.args.tableMetadata)
+ assert.Nil(t, got)
+ })
+ }
+}
+
+func TestVoltService_SvcUpInd(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltService_SvcUpInd",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ PendingFlows: make(map[string]bool),
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ SVlanTpid: layers.EthernetTypeDot1Q,
+ MacAddr: layers.EthernetBroadcast,
+ },
+ }
+ vs.Port = test_device
+ vs.Device = "device"
+ ga := GetApplication()
+ _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ ga.PortsDisc.Store(test_device, voltPort)
+ ga.DevicesDisc.Store(test_device, voltDevice)
+ vs.SvcUpInd(tt.args.cntx)
+ })
+ }
+}
+
+func TestVoltService_SvcDownInd(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltService_SvcDownInd",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ UsHSIAFlowsApplied: true,
+ DsHSIAFlowsApplied: true,
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ SVlanTpid: layers.EthernetTypeQinQ,
+ MacAddr: layers.EthernetBroadcast,
+ },
+ }
+ vs.Port = test_device
+ vs.Device = "device"
+ ga := GetApplication()
+ _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ ga.PortsDisc.Store(test_device, voltPort)
+ ga.DevicesDisc.Store(test_device, voltDevice)
+ vs.SvcDownInd(tt.args.cntx)
+ })
+ }
+}
+
+func TestVoltApplication_AddService(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ cfg VoltServiceCfg
+ oper *VoltServiceOper
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltApplication_AddService",
+ args: args{
+ cntx: context.Background(),
+ cfg: VoltServiceCfg{
+ Name: "test_name",
+ Port: "test_port",
+ DsMeterProfile: "4096-4096-4096",
+ UsMeterProfile: "4096-4096-4096",
+ SVlan: of.VlanAny,
+ CVlan: of.VlanAny,
+ UniVlan: of.VlanAny,
+ MacLearning: Learn,
+ IsActivated: true,
+ },
+ oper: &VoltServiceOper{
+ Device: "4096-4096-4096",
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ MeterMgr: MeterMgr{
+ Meters: sync.Map{},
+ },
+ VnetsByPort: sync.Map{},
+ VnetsByTag: sync.Map{},
+ }
+ va.MeterMgr.Meters.Store("4096-4096-4096", voltMeter)
+ va.VnetsByTag.Store("4096-4096-4096", voltVnet)
+ voltPortVnet1[0].SVlan = of.VlanAny
+ voltPortVnet1[0].CVlan = of.VlanAny
+ voltPortVnet1[0].UniVlan = of.VlanAny
+ voltPortVnet1[0].servicesCount = atomic.NewUint64(uint64(56))
+ voltPortVnet1[0].MacAddr = layers.EthernetBroadcast
+ voltPortVnet1[0].Port = "test_port"
+ va.VnetsByPort.Store("test_port", voltPortVnet1)
+ ga := GetApplication()
+ voltPort1 := &VoltPort{
+ Name: "test_name",
+ Device: test_device,
+ }
+ deviceConfig := &DeviceConfig{
+ SerialNumber: "test_serial_number",
+ }
+ ga.PortsDisc.Store("test_port", voltPort1)
+ ga.DevicesDisc.Store(test_device, voltDevice)
+ ga.DevicesConfig.Store("test_serial_number", deviceConfig)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
+ err := va.AddService(tt.args.cntx, tt.args.cfg, tt.args.oper)
+ assert.Nil(t, err)
+ })
+ }
+}
+
+func TestVoltApplication_DelService(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ name string
+ forceDelete bool
+ newSvc *VoltServiceCfg
+ serviceMigration bool
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltApplication_DelService",
+ args: args{
+ cntx: context.Background(),
+ name: "test_name",
+ forceDelete: true,
+ newSvc: &VoltServiceCfg{
+ Name: "vs_cfg_name",
+ Port: "test_port",
+ },
+ serviceMigration: true,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ ServiceByName: sync.Map{},
+ VnetsByPort: sync.Map{},
+ }
+ voltService := &VoltService{
+ Version: "test_version",
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "4096-4096-4096",
+ SVlan: of.VlanAny,
+ CVlan: of.VlanAny,
+ UniVlan: of.VlanAny,
+ },
+ }
+ va.ServiceByName.Store(tt.args.name, voltService)
+ va.VnetsByPort.Store("4096-4096-4096", voltPortVnet1)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes()
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ va.DelService(tt.args.cntx, tt.args.name, tt.args.forceDelete, tt.args.newSvc, tt.args.serviceMigration)
+ })
+ }
+}
+
+func TestVoltService_FlowInstallSuccess(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ cookie string
+ bwAvailInfo of.BwAvailDetails
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltService_FlowInstallSuccess",
+ args: args{
+ cntx: context.Background(),
+ cookie: "test_cookie",
+ bwAvailInfo: of.BwAvailDetails{
+ PrevBw: "test_prev_BW",
+ PresentBw: "test_present_BW",
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ pendingFlows := map[string]bool{}
+ pendingFlows["test_cookie"] = true
+ associatedFlows := map[string]bool{}
+ associatedFlows["test_cookie"] = true
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ PendingFlows: pendingFlows,
+ AssociatedFlows: associatedFlows,
+ DsHSIAFlowsApplied: true,
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "test_port",
+ },
+ }
+ ga := GetApplication()
+ ga.PortsDisc.Store("test_port", voltPort)
+ ga.DevicesDisc.Store(test_device, voltDevice)
+ vs.FlowInstallSuccess(tt.args.cntx, tt.args.cookie, tt.args.bwAvailInfo)
+ })
+ }
+}
+
+func TestVoltService_AddMeterToDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "VoltService_AddMeterToDevice",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ {
+ name: GetDeviceFromPort_error,
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ {
+ name: "DeviceState_down",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "VoltService_AddMeterToDevice":
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ DeleteInProgress: true,
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "test_port",
+ },
+ }
+ ga := GetApplication()
+ ga.PortsDisc.Store("test_port", voltPort)
+ ga.DevicesDisc.Store(test_device, voltDevice)
+ err := vs.AddMeterToDevice(tt.args.cntx)
+ assert.Nil(t, err)
+ case GetDeviceFromPort_error:
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ DeleteInProgress: true,
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "",
+ },
+ }
+ err := vs.AddMeterToDevice(tt.args.cntx)
+ assert.NotNil(t, err)
+ case "DeviceState_down":
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ DeleteInProgress: true,
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "test_port",
+ },
+ }
+ ga := GetApplication()
+ ga.PortsDisc.Store("test_port", voltPort)
+ ga.DevicesDisc.Store(test_device, voltDevice1)
+ err := vs.AddMeterToDevice(tt.args.cntx)
+ assert.Nil(t, err)
+ }
+ })
+ }
+}
+
+func TestVoltService_AddUsHsiaFlows(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "DeleteInProgress_true",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ {
+ name: "GetDeviceFromPort_error",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ {
+ name: "DeviceState_down",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "DeleteInProgress_true":
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ DeleteInProgress: true,
+ },
+ }
+ err := vs.AddUsHsiaFlows(tt.args.cntx)
+ assert.Nil(t, err)
+ case "GetDeviceFromPort_error":
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ DeleteInProgress: false,
+ },
+ }
+ err := vs.AddUsHsiaFlows(tt.args.cntx)
+ assert.NotNil(t, err)
+ case "DeviceState_down":
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ DeleteInProgress: false,
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "test_port",
+ },
+ }
+ ga := GetApplication()
+ ga.PortsDisc.Store("test_port", voltPort)
+ ga.DevicesDisc.Store(test_device, voltDevice1)
+ err := vs.AddUsHsiaFlows(tt.args.cntx)
+ assert.Nil(t, err)
+ }
+ })
+ }
+}
+
+func TestVoltService_AddHsiaFlows(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "AddUsHsiaFlows_error",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vs := &VoltService{
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "test_port",
+ VlanControl: 5,
+ },
+ }
+ ga := GetApplication()
+ ga.PortsDisc.Store("test_port", voltPort)
+ ga.DevicesDisc.Store(test_device, voltDevice)
+ vs.AddHsiaFlows(tt.args.cntx)
+ })
+ }
+}
+
+func TestVoltService_ForceWriteToDb(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "PutService_error",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "PutService_error":
+ vs := &VoltService{}
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("error")).AnyTimes()
+ vs.ForceWriteToDb(tt.args.cntx)
+ }
+ })
+ }
+}
+
+func TestVoltService_isDataRateAttrPresent(t *testing.T) {
+ tests := []struct {
+ name string
+ want bool
+ }{
+ {
+ name: "VoltService_isDataRateAttrPresent",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vs := &VoltService{}
+ if got := vs.isDataRateAttrPresent(); got != tt.want {
+ t.Errorf("VoltService.isDataRateAttrPresent() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltService_GetServicePbit(t *testing.T) {
+ tests := []struct {
+ name string
+ want int
+ }{
+ {
+ name: "VoltService_GetServicePbit",
+ want: -1,
+ },
+ {
+ name: "!IsPbitExist",
+ want: 8,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "VoltService_GetServicePbit":
+ vs := &VoltService{
+ VoltServiceCfg: VoltServiceCfg{
+ Pbits: []of.PbitType{of.PbitMatchAll},
+ },
+ }
+ if got := vs.GetServicePbit(); got != tt.want {
+ t.Errorf("VoltService.GetServicePbit() = %v, want %v", got, tt.want)
+ }
+ case "!IsPbitExist":
+ vs := &VoltService{}
+ if got := vs.GetServicePbit(); got != tt.want {
+ t.Errorf("VoltService.GetServicePbit() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltApplication_DeactivateService(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ deviceID string
+ portNo string
+ sVlan of.VlanType
+ cVlan of.VlanType
+ tpID uint16
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "VoltApplication_DeactivateService",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "test_device_id",
+ portNo: "test_port",
+ sVlan: of.VlanNone,
+ cVlan: of.VlanAny,
+ tpID: AnyVlan,
+ },
+ },
+ {
+ name: "VoltPortVnet_nil",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "test_device_id",
+ portNo: "test_port",
+ sVlan: of.VlanNone,
+ cVlan: of.VlanAny,
+ tpID: AnyVlan,
+ },
+ },
+ {
+ name: "sVlan != of.VlanNone",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "test_device_id",
+ portNo: "test_port",
+ sVlan: of.VlanAny,
+ cVlan: of.VlanAny,
+ tpID: AnyVlan,
+ },
+ },
+ {
+ name: GetDeviceFromPort_error,
+ args: args{
+ cntx: context.Background(),
+ deviceID: "test_device_id",
+ portNo: "test_port",
+ sVlan: of.VlanNone,
+ cVlan: of.VlanAny,
+ tpID: AnyVlan,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ ServiceByName: sync.Map{},
+ VnetsByPort: sync.Map{},
+ DevicesDisc: sync.Map{},
+ PortsDisc: sync.Map{},
+ }
+ voltServiceTest := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ Device: test_device,
+ },
+ Version: "test_version",
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "test_port",
+ Name: "test_name",
+ IsActivated: true,
+ CVlan: of.VlanAny,
+ SVlan: of.VlanAny,
+ UniVlan: of.VlanAny,
+ },
+ }
+ switch tt.name {
+ case "VoltApplication_DeactivateService":
+ va.ServiceByName.Store("test_name", voltServiceTest)
+ va.PortsDisc.Store("test_port", voltPort)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ va.DevicesDisc.Store(test_device, voltDevice)
+ voltDevice.Ports.Store("test_port", voltPort)
+ va.VnetsByPort.Store("test_port", voltPortVnet1)
+ voltPortVnet1[0].servicesCount.Store(uint64(1))
+ dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ 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 {
+ t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "VoltPortVnet_nil":
+ va.ServiceByName.Store("test_name", voltServiceTest)
+ va.PortsDisc.Store("test_port", voltPort)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ va.DevicesDisc.Store(test_device, voltDevice)
+ voltDevice.Ports.Store("test_port", voltPort)
+ 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 {
+ t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "sVlan != of.VlanNone":
+ va.ServiceByName.Store("test_name", voltServiceTest)
+ 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 {
+ t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case GetDeviceFromPort_error:
+ va.ServiceByName.Store("test_name", voltServiceTest)
+ 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 {
+ t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltApplication_ActivateService(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ deviceID string
+ portNo string
+ sVlan of.VlanType
+ cVlan of.VlanType
+ tpID uint16
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "VoltApplication_ActivateService",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "test_name",
+ portNo: "test_port",
+ sVlan: of.VlanNone,
+ cVlan: of.VlanAny,
+ tpID: AnyVlan,
+ },
+ },
+ {
+ name: "VoltPortVnet_nil",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "test_name",
+ portNo: "test_port",
+ sVlan: of.VlanNone,
+ cVlan: of.VlanAny,
+ tpID: AnyVlan,
+ },
+ },
+ {
+ name: GetDeviceFromPort_error,
+ args: args{
+ cntx: context.Background(),
+ deviceID: "test_name",
+ portNo: "test_port",
+ sVlan: of.VlanNone,
+ cVlan: of.VlanAny,
+ tpID: AnyVlan,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ }
+ var voltPortTest = &VoltPort{
+ Name: "test_name",
+ State: PortStateUp,
+ }
+ voltServiceTest := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ Device: test_device,
+ },
+ Version: "test_version",
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "test_port",
+ Name: "test_name",
+ IsActivated: false,
+ CVlan: of.VlanAny,
+ SVlan: of.VlanAny,
+ UniVlan: of.VlanAny,
+ },
+ }
+ switch tt.name {
+ case "VoltApplication_ActivateService":
+ voltPortTest.Device = test_device
+ va.PortsDisc.Store("test_port", voltPortTest)
+ va.DevicesDisc.Store(test_device, voltDevice)
+ va.ServiceByName.Store("test_name", voltServiceTest)
+ va.VnetsByPort.Store("test_port", voltPortVnet1)
+ voltDevice.Ports.Store("test_port", voltPortTest)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ 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 {
+ t.Errorf("VoltApplication.ActivateService() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "VoltPortVnet_nil":
+ voltPortTest.Device = test_device
+ va.ServiceByName.Store("test_name", voltServiceTest)
+ va.PortsDisc.Store("test_port", voltPortTest)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ va.DevicesDisc.Store(test_device, voltDevice)
+ voltDevice.Ports.Store("test_port", voltPortTest)
+ 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 {
+ t.Errorf("VoltApplication.ActivateService() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case GetDeviceFromPort_error:
+ err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID)
+ assert.NotNil(t, err)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_GetProgrammedSubscribers(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ deviceID string
+ portNo string
+ }
+ tests := []struct {
+ name string
+ args args
+ want []*VoltService
+ wantErr bool
+ }{
+ {
+ name: "VoltApplication_GetProgrammedSubscribers",
+ args: args{
+ cntx: context.Background(),
+ deviceID: test_device,
+ portNo: "test_port",
+ },
+ },
+ {
+ name: "portNo_nil",
+ args: args{
+ cntx: context.Background(),
+ deviceID: test_device,
+ },
+ },
+ {
+ name: "deviceID_nil",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ vendorID: "test_vendor",
+ }
+ voltServiceTest := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ Device: test_device,
+ },
+ Version: "test_version",
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "test_port",
+ Name: "test_name",
+ IsActivated: false,
+ CVlan: of.VlanAny,
+ SVlan: of.VlanAny,
+ UniVlan: of.VlanAny,
+ },
+ }
+ switch tt.name {
+ case "VoltApplication_GetProgrammedSubscribers":
+ va.ServiceByName.Store("test_name", voltServiceTest)
+ got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo)
+ assert.NotNil(t, got)
+ assert.Nil(t, err)
+ case "portNo_nil":
+ va.ServiceByName.Store("test_name", voltServiceTest)
+ got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo)
+ assert.NotNil(t, got)
+ assert.Nil(t, err)
+ case "deviceID_nil":
+ va.ServiceByName.Store("test_name", voltServiceTest)
+ got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo)
+ assert.NotNil(t, got)
+ assert.Nil(t, err)
+ }
+ })
+ }
+}
+
+func TestVoltService_JSONMarshal(t *testing.T) {
+ tests := []struct {
+ name string
+ }{
+ {
+ name: "VoltService_JSONMarshal",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ Device: test_device,
+ },
+ Version: "test_version",
+ VoltServiceCfg: VoltServiceCfg{
+ Name: "test_name",
+ },
+ }
+ got, err := vs.JSONMarshal()
+ assert.NotNil(t, got)
+ assert.Nil(t, err)
+ })
+ }
+}
+
+func TestVoltService_triggerServiceInProgressInd(t *testing.T) {
+ tests := []struct {
+ name string
+ }{
+ {
+ name: "VoltService_triggerServiceInProgressInd",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vs := &VoltService{
+ Version: "test_version",
+ }
+ vs.triggerServiceInProgressInd()
+ })
+ }
+}
+
+func TestVoltService_TriggerAssociatedFlowDelete(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "VoltService_TriggerAssociatedFlowDelete",
+ args: args{
+ cntx: context.Background(),
+ },
+ want: true,
+ },
+ {
+ name: "cookieList_nil",
+ args: args{
+ cntx: context.Background(),
+ },
+ want: false,
+ },
+ }
+ associatedFlows := map[string]bool{}
+ associatedFlows["5765317"] = true
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "VoltService_TriggerAssociatedFlowDelete":
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ UsHSIAFlowsApplied: true,
+ DsHSIAFlowsApplied: true,
+ AssociatedFlows: associatedFlows,
+ Device: test_device,
+ },
+ }
+ ga := GetApplication()
+ ga.DevicesDisc.Store(test_device, voltDevice)
+ if got := vs.TriggerAssociatedFlowDelete(tt.args.cntx); got != tt.want {
+ t.Errorf("VoltService.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want)
+ }
+ case "cookieList_nil":
+ vs := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ UsHSIAFlowsApplied: true,
+ DsHSIAFlowsApplied: true,
+ Device: test_device,
+ },
+ }
+ ga := GetApplication()
+ ga.DevicesDisc.Store(test_device, voltDevice)
+ if got := vs.TriggerAssociatedFlowDelete(tt.args.cntx); got != tt.want {
+ t.Errorf("VoltService.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltApplication_DeepEqualServicecfg(t *testing.T) {
+ type args struct {
+ evs *VoltServiceCfg
+ nvs *VoltServiceCfg
+ }
+ a := map[int]int{}
+ a[0] = 0
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "VoltApplication_DeepEqualServicecfg",
+ args: args{
+ evs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ nvs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ },
+ want: true,
+ },
+ {
+ name: "nvs.Name != evs.Name",
+ args: args{
+ evs: &VoltServiceCfg{
+ Name: "test_name",
+ },
+ nvs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ },
+ want: false,
+ },
+ {
+ name: "nvs.UniVlan != evs.UniVlan",
+ args: args{
+ evs: &VoltServiceCfg{
+ UniVlan: of.VlanAny,
+ },
+ nvs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ },
+ want: false,
+ },
+ {
+ name: "nvs.CVlan != evs.CVlan",
+ args: args{
+ evs: &VoltServiceCfg{
+ CVlan: of.VlanAny,
+ },
+ nvs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ },
+ want: false,
+ },
+ {
+ name: "nvs.SVlan != evs.SVlan",
+ args: args{
+ evs: &VoltServiceCfg{
+ SVlan: of.VlanAny,
+ },
+ nvs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ },
+ want: false,
+ },
+ {
+ name: "nvs.SVlanTpid != 0",
+ args: args{
+ evs: &VoltServiceCfg{
+ SVlanTpid: layers.EthernetTypeARP,
+ },
+ nvs: &VoltServiceCfg{
+ SVlanTpid: layers.EthernetTypeCiscoDiscovery,
+ },
+ },
+ want: false,
+ },
+ {
+ name: "nvs.Pbits != evs.Pbits",
+ args: args{
+ evs: &VoltServiceCfg{
+ Pbits: []of.PbitType{
+ PbitMatchAll,
+ },
+ },
+ nvs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ },
+ want: false,
+ },
+ {
+ name: "nvs.DsRemarkPbitsMap != evs.DsRemarkPbitsMap",
+ args: args{
+ evs: &VoltServiceCfg{
+ DsRemarkPbitsMap: a,
+ },
+ nvs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ },
+ want: false,
+ },
+ {
+ name: "nvs.TechProfileID != evs.TechProfileID",
+ args: args{
+ evs: &VoltServiceCfg{
+ TechProfileID: uint16(1),
+ },
+ nvs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ },
+ want: false,
+ },
+ {
+ name: "nvs.CircuitID != evs.CircuitID",
+ args: args{
+ evs: &VoltServiceCfg{
+ CircuitID: "test_circuit_id",
+ },
+ nvs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ },
+ want: false,
+ },
+ {
+ name: "nvs.RemoteID != evs.RemoteID",
+ args: args{
+ evs: &VoltServiceCfg{
+ RemoteID: []byte{1},
+ },
+ nvs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ },
+ want: false,
+ },
+ {
+ name: "nvs.Port != evs.Port",
+ args: args{
+ evs: &VoltServiceCfg{},
+ nvs: &VoltServiceCfg{
+ Port: "test_port",
+ },
+ },
+ want: false,
+ },
+ {
+ name: "nvs.PonPort != evs.PonPort",
+ args: args{
+ evs: &VoltServiceCfg{},
+ nvs: &VoltServiceCfg{
+ PonPort: uint32(1),
+ },
+ },
+ want: false,
+ },
+ {
+ name: "evs.MacLearning == MacLearningNone",
+ args: args{
+ evs: &VoltServiceCfg{
+ MacAddr: layers.EthernetBroadcast,
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.IgmpEnabled != evs.IgmpEnabled",
+ args: args{
+ evs: &VoltServiceCfg{
+ IgmpEnabled: true,
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.McastService != evs.McastService",
+ args: args{
+ evs: &VoltServiceCfg{
+ McastService: true,
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.ONTEtherTypeClassification != evs.ONTEtherTypeClassification",
+ args: args{
+ evs: &VoltServiceCfg{
+ ONTEtherTypeClassification: 1,
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.UsMeterProfile != evs.UsMeterProfile",
+ args: args{
+ evs: &VoltServiceCfg{
+ UsMeterProfile: "UsMeterProfile",
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.DsMeterProfile != evs.DsMeterProfile",
+ args: args{
+ evs: &VoltServiceCfg{
+ DsMeterProfile: "DsMeterProfile",
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.AggDsMeterProfile != evs.AggDsMeterProfile",
+ args: args{
+ evs: &VoltServiceCfg{
+ AggDsMeterProfile: "AggDsMeterProfile",
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.VnetID != evs.VnetID",
+ args: args{
+ evs: &VoltServiceCfg{
+ VnetID: "VnetID",
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.MvlanProfileName != evs.MvlanProfileName",
+ args: args{
+ evs: &VoltServiceCfg{
+ MvlanProfileName: "MvlanProfileName",
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.RemoteIDType != evs.RemoteIDType",
+ args: args{
+ evs: &VoltServiceCfg{
+ RemoteIDType: "RemoteIDType",
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.SchedID != evs.SchedID",
+ args: args{
+ evs: &VoltServiceCfg{
+ SchedID: 1,
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.AllowTransparent != evs.AllowTransparent",
+ args: args{
+ evs: &VoltServiceCfg{
+ AllowTransparent: true,
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.EnableMulticastKPI != evs.EnableMulticastKPI",
+ args: args{
+ evs: &VoltServiceCfg{
+ EnableMulticastKPI: true,
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.DataRateAttr != evs.DataRateAttr",
+ args: args{
+ evs: &VoltServiceCfg{
+ DataRateAttr: "DataRateAttr",
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.MinDataRateUs != evs.MinDataRateUs",
+ args: args{
+ evs: &VoltServiceCfg{
+ MinDataRateUs: uint32(1),
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.MinDataRateDs != evs.MinDataRateDs",
+ args: args{
+ evs: &VoltServiceCfg{
+ MinDataRateDs: uint32(1),
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.MaxDataRateUs != evs.MaxDataRateUs",
+ args: args{
+ evs: &VoltServiceCfg{
+ MaxDataRateUs: uint32(1),
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ {
+ name: "nvs.MaxDataRateDs != evs.MaxDataRateDs",
+ args: args{
+ evs: &VoltServiceCfg{
+ MaxDataRateDs: uint32(1),
+ },
+ nvs: &VoltServiceCfg{},
+ },
+ want: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ vendorID: "test_vendor_id",
+ }
+ switch tt.name {
+ case "VoltApplication_DeepEqualServicecfg", "nvs.Name != evs.Name", "nvs.UniVlan != evs.UniVlan",
+ "nvs.CVlan != evs.CVlan", "nvs.SVlan != evs.SVlan", "nvs.SVlanTpid != 0", "nvs.Pbits != evs.Pbits",
+ "nvs.DsRemarkPbitsMap != evs.DsRemarkPbitsMap", "nvs.TechProfileID != evs.TechProfileID",
+ "nvs.CircuitID != evs.CircuitID", "nvs.RemoteID != evs.RemoteID", "nvs.Port != evs.Port",
+ "evs.MacLearning == MacLearningNone", "nvs.PonPort != evs.PonPort", "nvs.IgmpEnabled != evs.IgmpEnabled",
+ "nvs.McastService != evs.McastService", "nvs.ONTEtherTypeClassification != evs.ONTEtherTypeClassification",
+ "nvs.UsMeterProfile != evs.UsMeterProfile",
+ "nvs.DsMeterProfile != evs.DsMeterProfile", "nvs.AggDsMeterProfile != evs.AggDsMeterProfile",
+ "nvs.VnetID != evs.VnetID", "nvs.MvlanProfileName != evs.MvlanProfileName",
+ "nvs.RemoteIDType != evs.RemoteIDType", "nvs.SchedID != evs.SchedID",
+ "nvs.AllowTransparent != evs.AllowTransparent",
+ "nvs.EnableMulticastKPI != evs.EnableMulticastKPI", "nvs.DataRateAttr != evs.DataRateAttr",
+ "nvs.MinDataRateUs != evs.MinDataRateUs", "nvs.MinDataRateDs != evs.MinDataRateDs",
+ "nvs.MaxDataRateUs != evs.MaxDataRateUs", "nvs.MaxDataRateDs != evs.MaxDataRateDs":
+ if got := va.DeepEqualServicecfg(tt.args.evs, tt.args.nvs); got != tt.want {
+ t.Errorf("VoltApplication.DeepEqualServicecfg() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}