UT-Part 6 with overall coverage upto 45%
Change-Id: I4960bae8429ae34d88a2f98f288f72d582f9e788
diff --git a/internal/pkg/application/application.go b/internal/pkg/application/application.go
index 3ddb29c..51c13ea 100644
--- a/internal/pkg/application/application.go
+++ b/internal/pkg/application/application.go
@@ -37,6 +37,7 @@
"voltha-go-controller/internal/pkg/intf"
"voltha-go-controller/internal/pkg/of"
"voltha-go-controller/internal/pkg/tasks"
+ common "voltha-go-controller/internal/pkg/types"
"voltha-go-controller/internal/pkg/util"
"voltha-go-controller/log"
)
@@ -216,6 +217,11 @@
NniDhcpTrapVid of.VlanType
GlobalDhcpFlowAdded bool
icmpv6GroupAdded bool
+ VoltDeviceIntr VoltDevInterface
+}
+
+type VoltDevInterface interface {
+ GetPortNameFromPortID(portID uint32) string
}
// NewVoltDevice : Constructor for the device
@@ -399,6 +405,33 @@
// The declaration of the singleton object
var vapplication *VoltApplication
+type VoltAppInterface interface {
+ AddVnet(cntx context.Context, cfg VnetConfig, oper *VnetOper) error
+ AddService(cntx context.Context, cfg VoltServiceCfg, oper *VoltServiceOper) error
+ AddDeviceConfig(cntx context.Context, serialNum, hardwareIdentifier, nasID, ipAddress, uplinkPort string, nniDhcpTrapID int) error
+ GetFlowProvisionStatus(portNo string) FlowProvisionStatus
+ DelServiceWithPrefix(cntx context.Context, prefix string) error
+ GetDevice(device string) *VoltDevice
+ GetTaskList(device string) map[int]*TaskInfo
+ AddMeterProf(cntx context.Context, cfg VoltMeter)
+ AddMvlanProfile(cntx context.Context, name string, mvlan of.VlanType, ponVlan of.VlanType, groups map[string][]string, isChannelBasedGroup bool, OLTSerialNum []string, activeChannelsPerPon int, proxy map[string]common.MulticastGroupProxy) error
+ DelMvlanProfile(cntx context.Context, name string) error
+ GetMvlanProfileByTag(vlan of.VlanType) *MvlanProfile
+ AddMcastConfig(cntx context.Context, MvlanProfileID string, IgmpProfileID string, IgmpProxyIP string, OltSerialNum string) error
+ DelMeterProf(cntx context.Context, name string) error
+ GetMeterByName(name string) (*VoltMeter, bool)
+ UpdateDeviceConfig(cntx context.Context, deviceConfig *DeviceConfig)
+ GetDeviceConfig(serNum string) *DeviceConfig
+ GetAllocations(cntx context.Context, deviceID string) ([]DhcpAllocation, error)
+ GetAllMacLearnerInfo() ([]MacLearnerInfo, error)
+ GetMacLearnerInfo(cntx context.Context, deviceID, portNumber, vlanID string) (MacLearnerInfo, error)
+ ActivateService(cntx context.Context, deviceID, portNo string, sVlan, cVlan of.VlanType, tpID uint16) error
+ DeactivateService(cntx context.Context, deviceID, portNo string, sVlan, cVlan of.VlanType, tpID uint16) error
+ GetProgrammedSubscribers(cntx context.Context, deviceID, portNo string) ([]*VoltService, error)
+ UpdateOltFlowService(cntx context.Context, oltFlowService OltFlowService)
+ GetIgnoredPorts() (map[string][]string, error)
+}
+
// VoltApplication fields :
// ServiceByName - Stores the services by the name as key
// A record of NB configuration.
@@ -669,6 +702,7 @@
go va.Start(context.Background(), TimerCfg{tick: time.Duration(GroupExpiryTime) * time.Minute}, pendingPoolTimer)
InitEventFuncMapper()
db = database.GetDatabase()
+
return &va
}
diff --git a/internal/pkg/application/application_test.go b/internal/pkg/application/application_test.go
index 7d92230..9b6b985 100644
--- a/internal/pkg/application/application_test.go
+++ b/internal/pkg/application/application_test.go
@@ -2348,12 +2348,10 @@
southBoundID string
}
voltDev := &VoltDevice{
- Name: "SDX6320031",
- SerialNum: "SDX6320031",
- NniDhcpTrapVid: 123,
- NniPort: "16777216",
- SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
- State: controller.DeviceStateREBOOTED,
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ State: controller.DeviceStateREBOOTED,
+ MigratingServices: util.NewConcurrentMap(),
}
tests := []struct {
name string
@@ -2367,14 +2365,30 @@
southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
},
},
+ {
+ name: "Negetive_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)
+ switch tt.name {
+ case "Positive_Case_DeviceRebootInd":
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID)
+ case "Negetive_Case_DeviceRebootInd":
+ voltDev.State = controller.DeviceStateDOWN
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ GetApplication().DevicesDisc.Store("SDX6320031", voltDev)
+ va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID)
+ }
})
}
}
@@ -2669,14 +2683,29 @@
oldOltSlNo string
newOltSlNo string
}
- voltDev := &VoltDevice{
- Name: "49686e2d-618f-4e8e-bca0",
- SerialNum: "SDX6320031",
- NniDhcpTrapVid: 123,
- NniPort: "16777472",
- SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
- Ports: sync.Map{},
- VpvsBySvlan: util.NewConcurrentMap(),
+ appMock := mocks.NewMockApp(gomock.NewController(t))
+ controller.NewController(ctx, appMock)
+ devicelist := []string{
+ "SDX6320030",
+ "SDX6320031",
+ }
+ voltVnet := &VoltVnet{
+ Version: "v3",
+ VnetConfig: VnetConfig{
+ Name: "2310-4096-4096",
+ VnetType: "Encapsulation",
+ SVlan: 2310,
+ CVlan: 4096,
+ UniVlan: 4096,
+ SVlanTpid: 33024,
+ DevicesList: devicelist,
+ },
+ }
+ devicesList := make(map[string]OperInProgress)
+ devicesList["SDX6320030"] = opt82
+ mvp := &MvlanProfile{
+ Name: "mvlan_test",
+ DevicesList: devicesList,
}
tests := []struct {
name string
@@ -2692,8 +2721,12 @@
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- va := &VoltApplication{}
- va.DevicesDisc.Store("SDX6320031", voltDev)
+ va := &VoltApplication{
+ VnetsByName: sync.Map{},
+ MvlanProfilesByName: sync.Map{},
+ }
+ va.VnetsByName.Store("2310-4096-4096", voltVnet)
+ va.MvlanProfilesByName.Store("mvlan_test", mvp)
va.UpdateDeviceSerialNumberList(tt.args.oldOltSlNo, tt.args.newOltSlNo)
})
}
@@ -2820,7 +2853,6 @@
UniVlan: 4096,
SVlanTpid: 33024,
},
-
VnetOper: VnetOper{
PendingDeviceToDelete: "SDX6320031",
DeleteInProgress: true,
@@ -2936,3 +2968,950 @@
})
}
}
+
+func TestVoltDevice_AddPort(t *testing.T) {
+ type args struct {
+ port string
+ id uint32
+ }
+
+ voltPort := &VoltPort{
+ Name: "16777472",
+ ID: uint32(256),
+ }
+ tests := []struct {
+ name string
+ args args
+ want *VoltPort
+ }{
+ {
+ name: "VoltApplication_AddPort",
+ args: args{
+ port: "16777472",
+ id: uint32(256),
+ },
+ want: voltPort,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &VoltDevice{}
+ if got := d.AddPort(tt.args.port, tt.args.id); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltDevice.AddPort() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_GetAvailIgmpGroupID(t *testing.T) {
+ IgmpGroupIds := []*IgmpGroup{}
+ group := &IgmpGroup{
+ GroupName: "group1",
+ GroupID: uint32(256),
+ }
+ IgmpGroupIds = append(IgmpGroupIds, group)
+ tests := []struct {
+ name string
+ want *IgmpGroup
+ }{
+ {
+ name: "VoltApplication_GetAvailIgmpGroupID",
+ want: group,
+ },
+ {
+ name: "VoltApplication_GetAvailIgmpGroupID_Nil",
+ want: group,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "VoltApplication_GetAvailIgmpGroupID":
+ va := &VoltApplication{
+ IgmpGroupIds: IgmpGroupIds,
+ }
+ got := va.GetAvailIgmpGroupID()
+ assert.NotNil(t, got)
+ case "VoltApplication_GetAvailIgmpGroupID_Nil":
+ va := &VoltApplication{}
+ got := va.GetAvailIgmpGroupID()
+ assert.Nil(t, got)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_GetIgmpGroupID(t *testing.T) {
+ type args struct {
+ gid uint32
+ }
+ IgmpGroupIds := []*IgmpGroup{}
+ group := &IgmpGroup{
+ GroupName: "group1",
+ GroupID: uint32(256),
+ }
+ IgmpGroupIds = append(IgmpGroupIds, group)
+ tests := []struct {
+ name string
+ args args
+ want *IgmpGroup
+ wantErr bool
+ }{
+ {
+ name: "VoltApplication_GetIgmpGroupID",
+ args: args{
+ gid: uint32(256),
+ },
+ want: group,
+ wantErr: false,
+ },
+ {
+ name: "VoltApplication_GetIgmpGroupID_Error",
+ args: args{
+ gid: uint32(256),
+ },
+ want: group,
+ wantErr: true,
+ },
+ }
+ va := &VoltApplication{}
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "VoltApplication_GetIgmpGroupID":
+ va = &VoltApplication{
+ IgmpGroupIds: IgmpGroupIds,
+ }
+ got, err := va.GetIgmpGroupID(tt.args.gid)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.GetIgmpGroupID() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetIgmpGroupID() = %v, want %v", got, tt.want)
+ }
+ case "VoltApplication_GetIgmpGroupID_Error":
+ got, err := va.GetIgmpGroupID(tt.args.gid)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.GetIgmpGroupID() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ assert.Nil(t, got)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_PutIgmpGroupID(t *testing.T) {
+ type args struct {
+ ig *IgmpGroup
+ }
+ group := &IgmpGroup{
+ GroupName: "group1",
+ GroupID: uint32(256),
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltApplication_GetIgmpGroupID",
+ args: args{
+ ig: group,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.PutIgmpGroupID(tt.args.ig)
+ })
+ }
+}
+
+func TestVoltApplication_PortDelInd(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ port string
+ }
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ NniPort: "16777472",
+ SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ Ports: sync.Map{},
+ VpvsBySvlan: util.NewConcurrentMap(),
+ }
+
+ voltPort := &VoltPort{
+ Name: "16777472",
+ Device: "SDX6320031",
+ ID: 16777472,
+ State: PortStateUp,
+ ChannelPerSubAlarmRaised: false,
+ }
+ voltPortVnets := make([]*VoltPortVnet, 0)
+ voltPortVnet := &VoltPortVnet{
+ Device: "SDX6320031",
+ Port: "16777472",
+ DeleteInProgress: true,
+ servicesCount: atomic.NewUint64(0),
+ }
+ voltPortVnets = append(voltPortVnets, voltPortVnet)
+
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltApplication_PortDelInd",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ port: "16777472",
+ },
+ },
+ {
+ name: "PortDelInd_Device_Not_Found",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320032",
+ port: "16777472",
+ },
+ },
+ {
+ name: "PortDelInd_VnetsByPort_Nil",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ port: "16777472",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "VoltApplication_PortDelInd", "PortDelInd_Device_Not_Found":
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ PortsDisc: sync.Map{},
+ }
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.PortsDisc.Store("16777472", voltPort)
+ voltDev.Ports.Store("16777472", voltPort)
+ va.VnetsByPort.Store("16777472", voltPortVnets)
+ va.PortDelInd(tt.args.cntx, tt.args.device, tt.args.port)
+ case "PortDelInd_VnetsByPort_Nil":
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ PortsDisc: sync.Map{},
+ }
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.PortsDisc.Store("16777472", voltPort)
+ voltDev.Ports.Store("16777472", voltPort)
+ va.PortDelInd(tt.args.cntx, tt.args.device, tt.args.port)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_GetGroupFromPendingPool(t *testing.T) {
+ type args struct {
+ mvlan of.VlanType
+ device string
+ }
+ igmpPendingPool := map[string]map[*IgmpGroup]bool{}
+ devices := map[string]*IgmpGroupDevice{}
+ igmpGroup := map[*IgmpGroup]bool{}
+ igmpDevice := &IgmpGroupDevice{
+ Device: "SDX6320031",
+ SerialNo: "SDX6320032",
+ GroupName: "group1",
+ Mvlan: of.VlanAny,
+ }
+ devices["SDX6320031"] = igmpDevice
+ group := &IgmpGroup{
+ GroupName: "group1",
+ GroupID: uint32(256),
+ Mvlan: of.VlanAny,
+ Devices: devices,
+ }
+
+ igmpGroup[group] = true
+ igmpPendingPool["4096_SDX6320031"] = igmpGroup
+ tests := []struct {
+ name string
+ args args
+ want *IgmpGroup
+ }{
+ {
+ name: "GetGroupFromPendingPool",
+ args: args{
+ device: "SDX6320031",
+ mvlan: of.VlanAny,
+ },
+ want: nil,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ IgmpPendingPool: igmpPendingPool,
+ }
+ if got := va.GetGroupFromPendingPool(tt.args.mvlan, tt.args.device); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetGroupFromPendingPool() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_RemoveGroupsFromPendingPool(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ mvlan of.VlanType
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "PortDelInd_RemoveGroupsFromPendingPool",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ mvlan: of.VlanAny,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ IgmpPendingPool: make(map[string]map[*IgmpGroup]bool),
+ }
+ va.RemoveGroupsFromPendingPool(tt.args.cntx, tt.args.device, tt.args.mvlan)
+ })
+ }
+}
+
+func TestVoltApplication_AddGroupToPendingPool(t *testing.T) {
+ type fields struct{}
+ type args struct {
+ ig *IgmpGroup
+ }
+ devices := map[string]*IgmpGroupDevice{}
+ igmpDevice := &IgmpGroupDevice{
+ Device: "SDX6320031",
+ SerialNo: "SDX6320032",
+ GroupName: "group1",
+ Mvlan: of.VlanAny,
+ }
+ devices["SDX6320031"] = igmpDevice
+ group := &IgmpGroup{
+ GroupName: "group1",
+ GroupID: uint32(256),
+ Devices: devices,
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ }{
+ {
+ name: "AddGroupToPendingPool",
+ args: args{
+ ig: group,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ IgmpPendingPool: make(map[string]map[*IgmpGroup]bool),
+ }
+ va.AddGroupToPendingPool(tt.args.ig)
+ })
+ }
+}
+
+func TestVoltApplication_removeExpiredGroups(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ group := &IgmpGroup{
+ GroupName: "group1",
+ GroupID: uint32(256),
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "removeExpiredGroups",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ IgmpGroups: sync.Map{},
+ }
+ va.IgmpGroups.Store("group1", group)
+ va.removeExpiredGroups(tt.args.cntx)
+ })
+ }
+}
+
+func TestVoltApplication_GetTaskList(t *testing.T) {
+ type args struct {
+ device string
+ }
+ appMock := mocks.NewMockApp(gomock.NewController(t))
+ controller.NewController(ctx, appMock)
+ device := &controller.Device{
+ ID: "SDX6320031",
+ }
+ dev := map[string]*controller.Device{}
+ dev["SDX6320031"] = device
+ tests := []struct {
+ name string
+ args args
+ want map[int]*TaskInfo
+ }{
+ {
+ name: "GetTaskList",
+ args: args{
+ device: "SDX6320031",
+ },
+ want: map[int]*TaskInfo{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ if got := va.GetTaskList(tt.args.device); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetTaskList() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_UpdateMvlanProfilesForDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ }
+ devicesList := make(map[string]OperInProgress)
+ devicesList["SDX6320031"] = UpdateInProgress
+ mvp := &MvlanProfile{
+ Name: "mvlan_test",
+ DevicesList: devicesList,
+ }
+ voltDev := &VoltDevice{
+ SerialNum: "SDX6320031",
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "UpdateMvlanProfilesForDevice",
+ args: args{
+ cntx: context.Background(),
+ device: "SDX6320031",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{
+ DevicesDisc: sync.Map{},
+ MvlanProfilesByName: sync.Map{},
+ }
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.MvlanProfilesByName.Store("mvlan_test", mvp)
+ va.UpdateMvlanProfilesForDevice(tt.args.cntx, tt.args.device)
+ })
+ }
+}
+
+func TestVoltApplication_HandleFlowClearFlag(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ deviceID string
+ serialNum string
+ southBoundID string
+ }
+ mblan := map[uint16]bool{}
+ mblan[uint16(256)] = true
+ voltDev := &VoltDevice{
+ SerialNum: "SDX6320031",
+ MigratingServices: util.NewConcurrentMap(),
+ IgmpDsFlowAppliedForMvlan: mblan,
+ }
+ voltPortVnets := make([]*VoltPortVnet, 0)
+ voltPortVnet := &VoltPortVnet{
+ Device: "SDX6320031",
+ Port: "16777472",
+ DeleteInProgress: true,
+ servicesCount: atomic.NewUint64(0),
+ IgmpEnabled: true,
+ }
+ voltPortVnets = append(voltPortVnets, voltPortVnet)
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "HandleFlowClearFlag",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "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{},
+ VnetsByPort: sync.Map{},
+ }
+ GetApplication().DevicesDisc.Store("SDX6320031", voltDev)
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.VnetsByPort.Store("16777472", voltPortVnets)
+ va.HandleFlowClearFlag(tt.args.cntx, tt.args.deviceID, tt.args.serialNum, tt.args.southBoundID)
+ })
+ }
+}
+
+func TestVoltApplication_PacketInInd(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ port string
+ pkt []byte
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "PacketInInd",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.PacketInInd(tt.args.cntx, tt.args.device, tt.args.port, tt.args.pkt)
+ })
+ }
+}
+
+func TestReceiverUpInd(t *testing.T) {
+ type args struct {
+ key interface{}
+ value interface{}
+ }
+ voltServ := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ Device: "SCOM00001c75",
+ Ipv4Addr: AllSystemsMulticastGroupIP,
+ Ipv6Addr: AllSystemsMulticastGroupIP,
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ IgmpEnabled: true,
+ VlanControl: ONUCVlan,
+ Port: "16777472",
+ },
+ }
+ voltDev := &VoltDevice{
+ Name: "SCOM00001c75",
+ SerialNum: "SCOM00001c75",
+ Ports: sync.Map{},
+ }
+ voltPort := &VoltPort{
+ Name: "16777472",
+ Device: "SCOM00001c75",
+ ID: 16777216,
+ State: PortStateDown,
+ ChannelPerSubAlarmRaised: false,
+ Type: VoltPortTypeNni,
+ }
+
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "ReceiverUpInd",
+ args: args{
+ key: "SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65",
+ value: voltServ,
+ },
+ },
+ {
+ name: "ReceiverUpInd_VlanControl",
+ args: args{
+ key: "SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65",
+ value: voltServ,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "ReceiverUpInd":
+ GetApplication().ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
+ GetApplication().DevicesDisc.Store("SCOM00001c75", voltDev)
+ GetApplication().PortsDisc.Store("16777472", voltPort)
+ voltDev.Ports.Store("16777472", voltPort)
+ if got := ReceiverUpInd(tt.args.key, tt.args.value); got != tt.want {
+ t.Errorf("ReceiverUpInd() = %v, want %v", got, tt.want)
+ }
+ case "ReceiverUpInd_VlanControl":
+ voltServ.VlanControl = OLTSVlan
+ GetApplication().ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
+ if got := ReceiverUpInd(tt.args.key, tt.args.value); got != tt.want {
+ t.Errorf("ReceiverUpInd() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltApplication_NniVlanIndToIgmp(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device *VoltDevice
+ mvp *MvlanProfile
+ addFlow bool
+ }
+ mblan := map[uint16]bool{}
+ mblan[uint16(256)] = true
+ voltDev := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ IgmpDsFlowAppliedForMvlan: mblan,
+ Ports: sync.Map{},
+ NniPort: "16777472",
+ }
+ devicesList := make(map[string]OperInProgress)
+ devicesList["SDX6320030"] = opt82
+ mvp := &MvlanProfile{
+ Name: "mvlan_test",
+ DevicesList: devicesList,
+ }
+ voltPort := &VoltPort{
+ Name: "16777472",
+ Device: "SDX6320031",
+ ID: 16777216,
+ State: PortStateUp,
+ }
+ voltPortVnets := make([]*VoltPortVnet, 0)
+ voltPortVnet := &VoltPortVnet{
+ Device: "SDX6320031",
+ Port: "16777472",
+ IgmpEnabled: true,
+ MvlanProfileName: "mvlan_test",
+ services: sync.Map{},
+ }
+ voltPortVnets = append(voltPortVnets, voltPortVnet)
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "NniVlanIndToIgmp",
+ args: args{
+ device: voltDev,
+ mvp: mvp,
+ },
+ },
+ {
+ name: "ProcessIgmpDSFlowForMvlan_pushIgmpMcastFlows",
+ args: args{
+ cntx: context.Background(),
+ device: voltDev,
+ mvp: mvp,
+ addFlow: true,
+ },
+ },
+ {
+ name: "ProcessIgmpDSFlowForMvlan_removeIgmpMcastFlows",
+ args: args{
+ cntx: context.Background(),
+ device: voltDev,
+ mvp: mvp,
+ addFlow: false,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ switch tt.name {
+ case "NniVlanIndToIgmp":
+ voltDev.Ports.Store("16777472", voltPort)
+ va.PortsDisc.Store("16777472", voltPort)
+ va.VnetsByPort.Store("16777472", voltPortVnets)
+ va.NniVlanIndToIgmp(tt.args.device, tt.args.mvp)
+ case "ProcessIgmpDSFlowForMvlan_pushIgmpMcastFlows", "ProcessIgmpDSFlowForMvlan_removeIgmpMcastFlows":
+ voltDev.Ports.Store("16777472", voltPort)
+ va.ProcessIgmpDSFlowForMvlan(tt.args.cntx, tt.args.device, tt.args.mvp, tt.args.addFlow)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_DeviceDisableInd(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device string
+ }
+ voltDev := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ Ports: sync.Map{},
+ State: controller.DeviceStateDOWN,
+ MigratingServices: util.NewConcurrentMap(),
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "DeviceDisableInd",
+ args: args{
+ device: "SDX6320031",
+ },
+ },
+ {
+ name: "DeviceDisableInd_DEvice_Not_Found",
+ args: args{
+ device: "SDX6320032",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ GetApplication().DevicesDisc.Store("SDX6320031", voltDev)
+ va.DeviceDisableInd(tt.args.cntx, tt.args.device)
+ })
+ }
+}
+
+func TestVoltApplication_ProcessIgmpDSFlowForDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ d *VoltDevice
+ addFlow bool
+ }
+ voltDev := &VoltDevice{
+ Name: "SDX6320031",
+ SerialNum: "SDX6320031",
+ MigratingServices: util.NewConcurrentMap(),
+ }
+ devicesList := make(map[string]OperInProgress)
+ devicesList["SDX6320030"] = opt82
+ mvp := &MvlanProfile{
+ Name: "mvlan_test",
+ DevicesList: devicesList,
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "DeviceDisableInd_DEvice_Not_Found",
+ args: args{
+ cntx: context.Background(),
+ d: voltDev,
+ addFlow: true,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.MvlanProfilesByName.Store("mvlan_test", mvp)
+ va.ProcessIgmpDSFlowForDevice(tt.args.cntx, tt.args.d, tt.args.addFlow)
+ })
+ }
+}
+
+func TestVoltApplication_GetPonFromUniPort(t *testing.T) {
+ type args struct {
+ port string
+ }
+ voltPort := &VoltPort{
+ Name: "16777472",
+ Device: "SDX6320031",
+ ID: 16777216,
+ State: PortStateUp,
+ }
+
+ tests := []struct {
+ name string
+ args args
+ want string
+ wantErr bool
+ }{
+ {
+ name: "GetPonFromUniPort_PositiveSenario",
+ args: args{
+ port: "16777472",
+ },
+ want: "16",
+ wantErr: false,
+ },
+ {
+ name: "GetPonFromUniPort_NegetiveSenario",
+ args: args{
+ port: "16777472",
+ },
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ switch tt.name {
+ case "GetPonFromUniPort_PositiveSenario":
+ va.PortsDisc.Store("16777472", voltPort)
+ got, err := va.GetPonFromUniPort(tt.args.port)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.GetPonFromUniPort() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if got != tt.want {
+ t.Errorf("VoltApplication.GetPonFromUniPort() = %v, want %v", got, tt.want)
+ }
+ case "GetPonFromUniPort_NegetiveSenario":
+ got, err := va.GetPonFromUniPort(tt.args.port)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.GetPonFromUniPort() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if got != tt.want {
+ t.Errorf("VoltApplication.GetPonFromUniPort() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltApplication_AddIcmpv6Receivers(t *testing.T) {
+ type args struct {
+ device string
+ portID uint32
+ }
+ var receiverList []uint32
+ port := uint32(256)
+ receiverList = append(receiverList, port)
+ tests := []struct {
+ name string
+ args args
+ want []uint32
+ }{
+ {
+ name: "AddIcmpv6Receivers",
+ args: args{
+ device: "SDX6320031",
+ portID: port,
+ },
+ want: []uint32{port, port},
+ },
+ {
+ name: "DelIcmpv6Receivers",
+ args: args{
+ device: "SDX6320031",
+ portID: port,
+ },
+ want: []uint32{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ switch tt.name {
+ case "AddIcmpv6Receivers":
+ va.Icmpv6Receivers.Store("SDX6320031", receiverList)
+ if got := va.AddIcmpv6Receivers(tt.args.device, tt.args.portID); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.AddIcmpv6Receivers() = %v, want %v", got, tt.want)
+ }
+ case "DelIcmpv6Receivers":
+ va.Icmpv6Receivers.Store("SDX6320031", receiverList)
+ if got := va.DelIcmpv6Receivers(tt.args.device, tt.args.portID); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.DelIcmpv6Receivers() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltApplication_ProcessDevFlowForDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device *VoltDevice
+ vnet *VoltVnet
+ enabled bool
+ }
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
+ }
+ voltVnet := &VoltVnet{
+ Version: "v3",
+ VnetConfig: VnetConfig{
+ Name: "2310-4096-4096",
+ VnetType: "Encapsulation",
+ SVlan: 2310,
+ CVlan: 4096,
+ UniVlan: 4096,
+ SVlanTpid: 33024,
+ },
+ VnetOper: VnetOper{
+ PendingDeviceToDelete: "SDX6320031",
+ DeleteInProgress: true,
+ },
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "ProcessDevFlowForDevice_PushDevFlowForVlan",
+ args: args{
+ cntx: context.Background(),
+ device: voltDev,
+ vnet: voltVnet,
+ enabled: true,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ va.VnetsByName.Store("2310-4096-4096", voltVnet)
+ va.ProcessDevFlowForDevice(tt.args.cntx, tt.args.device, tt.args.vnet, tt.args.enabled)
+ })
+ }
+}
diff --git a/internal/pkg/application/dhcprelay_test.go b/internal/pkg/application/dhcprelay_test.go
index 2354d41..c7bfd23 100644
--- a/internal/pkg/application/dhcprelay_test.go
+++ b/internal/pkg/application/dhcprelay_test.go
@@ -605,6 +605,27 @@
portNumber string
vlanID string
}
+ vpv := &VoltPortVnet{
+ Device: "SDX6320031",
+ Port: "SDX6320031-1",
+ SVlan: of.VlanAny,
+ MacAddr: BroadcastMAC,
+ }
+ sessions := map[[6]byte]IDhcpRelaySession{}
+ key := [6]byte{1, 2, 3, 4, 5, 6}
+ sessions[key] = vpv
+ network := make(map[uint32]*DhcpRelayVnet)
+ network[uint32(256)] = &DhcpRelayVnet{
+ sessions: sessions,
+ }
+ dhcpNws.Networks = network
+ svlan := of.VlanAny
+ macLearning := MacLearnerInfo{
+ DeviceID: "SDX6320031",
+ PortNumber: "SDX6320031-1",
+ VlanID: svlan.String(),
+ MacAddress: BroadcastMAC.String(),
+ }
tests := []struct {
name string
args args
@@ -615,10 +636,21 @@
name: "VoltApplication_GetMacLearnerInfo",
args: args{
cntx: context.Background(),
- deviceID: test_device,
- portNumber: "test_port_number",
- vlanID: "test_vlanID",
+ deviceID: "SDX6320031",
+ portNumber: "SDX6320031-1",
+ vlanID: svlan.String(),
},
+ want: macLearning,
+ },
+ {
+ name: "VoltApplication_GetMacLearnerInfo_svlan_empty",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "SDX6320031",
+ portNumber: "SDX6320031-1",
+ vlanID: "",
+ },
+ want: macLearning,
},
}
for _, tt := range tests {
@@ -635,3 +667,125 @@
})
}
}
+
+func TestVoltApplication_GetAllocations(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ deviceID string
+ }
+ allocation := []DhcpAllocation{}
+ vpv := &VoltPortVnet{
+ Device: "SDX6320031",
+ services: sync.Map{},
+ }
+ voltServ := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ Device: "SDX6320031",
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ Name: "SDX6320031-1_SDX6320031-1-4096-2310-4096-65",
+ },
+ }
+ sessions := map[[6]byte]IDhcpRelaySession{}
+ key := [6]byte{1, 2, 3, 4, 5, 6}
+ sessions[key] = vpv
+ network := make(map[uint32]*DhcpRelayVnet)
+ network[uint32(256)] = &DhcpRelayVnet{
+ sessions: sessions,
+ }
+ dhcpNws.Networks = network
+ tests := []struct {
+ name string
+ args args
+ want []DhcpAllocation
+ wantErr bool
+ }{
+ {
+ name: "VoltApplication_GetAllocations",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "SDX6320031",
+ },
+ want: allocation,
+ },
+ {
+ name: "GetAllocations_with_Services",
+ args: args{
+ cntx: context.Background(),
+ deviceID: "SDX6320031",
+ },
+ want: allocation,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ switch tt.name {
+ case "VoltApplication_GetAllocations":
+ got, err := va.GetAllocations(tt.args.cntx, tt.args.deviceID)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.GetAllocations() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ assert.NotNil(t, got)
+ case "GetAllocations_with_Services":
+ vpv.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
+ got, err := va.GetAllocations(tt.args.cntx, tt.args.deviceID)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.GetAllocations() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ assert.NotNil(t, got)
+ }
+ })
+ }
+}
+
+func TestVoltApplication_GetAllMacLearnerInfo(t *testing.T) {
+ vpv := &VoltPortVnet{
+ Device: "SDX6320031",
+ Port: "SDX6320031-1",
+ SVlan: of.VlanAny,
+ MacAddr: BroadcastMAC,
+ }
+ sessions := map[[6]byte]IDhcpRelaySession{}
+ key := [6]byte{1, 2, 3, 4, 5, 6}
+ sessions[key] = vpv
+ network := make(map[uint32]*DhcpRelayVnet)
+ network[uint32(256)] = &DhcpRelayVnet{
+ sessions: sessions,
+ }
+ dhcpNws.Networks = network
+ svlan := of.VlanAny
+ macLearningList := []MacLearnerInfo{}
+ macLearning := MacLearnerInfo{
+ DeviceID: "SDX6320031",
+ PortNumber: "SDX6320031-1",
+ VlanID: svlan.String(),
+ MacAddress: BroadcastMAC.String(),
+ }
+ macLearningList = append(macLearningList, macLearning)
+ tests := []struct {
+ name string
+ want []MacLearnerInfo
+ wantErr bool
+ }{
+ {
+ name: "VoltApplication_GetAllMacLearnerInfo",
+ want: macLearningList,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ got, err := va.GetAllMacLearnerInfo()
+ if (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.GetAllMacLearnerInfo() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetAllMacLearnerInfo() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/internal/pkg/application/igmp_test.go b/internal/pkg/application/igmp_test.go
index 9e1e940..8f132bd 100644
--- a/internal/pkg/application/igmp_test.go
+++ b/internal/pkg/application/igmp_test.go
@@ -16,7 +16,17 @@
package application
import (
+ "context"
+ "net"
"testing"
+ "time"
+ "voltha-go-controller/internal/pkg/of"
+ common "voltha-go-controller/internal/pkg/types"
+ "voltha-go-controller/internal/test/mocks"
+
+ "github.com/golang/mock/gomock"
+ "github.com/google/gopacket/layers"
+ "github.com/stretchr/testify/assert"
)
func TestVoltApplication_InitIgmpSrcMac(t *testing.T) {
@@ -34,3 +44,511 @@
})
}
}
+
+func TestVoltApplication_UpdateIgmpProfile(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ igmpProfileConfig *common.IGMPConfig
+ }
+ igmpConfig := &common.IGMPConfig{
+ ProfileID: "test_profile_id",
+ FastLeave: &vgcRebooted,
+ PeriodicQuery: &isUpgradeComplete,
+ WithRAUpLink: &isUpgradeComplete,
+ WithRADownLink: &isUpgradeComplete,
+ }
+ igmpProfile_data := &IgmpProfile{
+ ProfileID: "test_profile_id",
+ }
+
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "UpdateIgmpProfile",
+ args: args{
+ cntx: context.Background(),
+ igmpProfileConfig: igmpConfig,
+ },
+ },
+ {
+ name: "UpdateIgmpProfile_Profile_not_found",
+ args: args{
+ cntx: context.Background(),
+ igmpProfileConfig: igmpConfig,
+ },
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ switch tt.name {
+ case "UpdateIgmpProfile":
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutIgmpProfile(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
+ va.IgmpProfilesByName.Store("test_profile_id", igmpProfile_data)
+ if err := va.UpdateIgmpProfile(tt.args.cntx, tt.args.igmpProfileConfig); (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.UpdateIgmpProfile() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "UpdateIgmpProfile_Profile_not_found":
+ igmpConfig.ProfileID = ""
+ if err := va.UpdateIgmpProfile(tt.args.cntx, tt.args.igmpProfileConfig); (err != nil) != tt.wantErr {
+ t.Errorf("VoltApplication.UpdateIgmpProfile() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltApplication_resetIgmpProfileToDefault(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ igmpProfile_data := &IgmpProfile{
+ ProfileID: "test_profile_id",
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "resetIgmpProfileToDefault",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.IgmpProfilesByName.Store("", igmpProfile_data)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutIgmpProfile(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
+ va.resetIgmpProfileToDefault(tt.args.cntx)
+ })
+ }
+}
+
+func Test_ipv4ToUint(t *testing.T) {
+ type args struct {
+ ip net.IP
+ }
+ tests := []struct {
+ name string
+ args args
+ want uint32
+ }{
+ {
+ name: "ipv4ToUint",
+ args: args{
+ ip: AllSystemsMulticastGroupIP,
+ },
+ want: 3758096385,
+ },
+ {
+ name: "ipv4ToUint",
+ args: args{
+ ip: nil,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := ipv4ToUint(tt.args.ip); got != tt.want {
+ t.Errorf("ipv4ToUint() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestIgmpUsEthLayer(t *testing.T) {
+ type args struct {
+ mcip net.IP
+ }
+ tests := []struct {
+ name string
+ args args
+ want *layers.Ethernet
+ }{
+ {
+ name: "IgmpUsEthLayer",
+ args: args{
+ mcip: AllSystemsMulticastGroupIP,
+ },
+ want: &layers.Ethernet{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := IgmpUsEthLayer(tt.args.mcip)
+ assert.NotNil(t, got)
+ })
+ }
+}
+
+func TestIgmpUsDot1qLayer(t *testing.T) {
+ type args struct {
+ vlan of.VlanType
+ priority uint8
+ }
+ tests := []struct {
+ name string
+ args args
+ want *layers.Dot1Q
+ }{
+ {
+ name: "IgmpUsDot1qLayer",
+ args: args{
+ vlan: of.VlanAny,
+ priority: 0,
+ },
+ want: &layers.Dot1Q{},
+ },
+ {
+ name: "IgmpDsDot1qLayer",
+ args: args{
+ vlan: of.VlanAny,
+ priority: 0,
+ },
+ want: &layers.Dot1Q{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "IgmpUsDot1qLayer":
+ got := IgmpUsDot1qLayer(tt.args.vlan, tt.args.priority)
+ assert.NotNil(t, got)
+ case "IgmpDsDot1qLayer":
+ got := IgmpDsDot1qLayer(tt.args.vlan, tt.args.priority)
+ assert.NotNil(t, got)
+ }
+ })
+ }
+}
+
+func TestIgmpv2UsIpv4Layer(t *testing.T) {
+ type args struct {
+ src net.IP
+ mcip net.IP
+ }
+ tests := []struct {
+ name string
+ args args
+ want *layers.IPv4
+ }{
+ {
+ name: "Igmpv2UsIpv4Layer",
+ args: args{
+ src: AllSystemsMulticastGroupIP,
+ mcip: AllSystemsMulticastGroupIP,
+ },
+ want: &layers.IPv4{},
+ },
+ {
+ name: "IgmpDsIpv4Layer",
+ args: args{
+ src: AllSystemsMulticastGroupIP,
+ mcip: net.ParseIP("0.0.0.0"),
+ },
+ want: &layers.IPv4{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "Igmpv2UsIpv4Layer":
+ got := Igmpv2UsIpv4Layer(tt.args.src, tt.args.mcip)
+ assert.NotNil(t, got)
+ case "IgmpDsIpv4Layer":
+ got := IgmpDsIpv4Layer(tt.args.src, tt.args.mcip)
+ assert.NotNil(t, got)
+ }
+ })
+ }
+}
+
+func TestIgmpv3UsIpv4Layer(t *testing.T) {
+ type args struct {
+ src net.IP
+ }
+ tests := []struct {
+ name string
+ args args
+ want *layers.IPv4
+ }{
+ {
+ name: "Igmpv3UsIpv4Layer",
+ args: args{
+ src: AllSystemsMulticastGroupIP,
+ },
+ want: &layers.IPv4{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := Igmpv3UsIpv4Layer(tt.args.src)
+ assert.NotNil(t, got)
+ })
+ }
+}
+
+func TestIgmpDsEthLayer(t *testing.T) {
+ type args struct {
+ mcip net.IP
+ }
+ tests := []struct {
+ name string
+ args args
+ want *layers.Ethernet
+ }{
+ {
+ name: "IgmpDsEthLayer",
+ args: args{
+ mcip: AllSystemsMulticastGroupIP,
+ },
+ want: &layers.Ethernet{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := IgmpDsEthLayer(tt.args.mcip)
+ assert.NotNil(t, got)
+ })
+ }
+}
+
+func TestIgmpQueryv2Layer(t *testing.T) {
+ type args struct {
+ mcip net.IP
+ resptime time.Duration
+ }
+ tests := []struct {
+ name string
+ args args
+ want *layers.IGMPv1or2
+ }{
+ {
+ name: "IgmpQueryv2Laye",
+ args: args{
+ mcip: AllSystemsMulticastGroupIP,
+ resptime: time.Microsecond,
+ },
+ want: &layers.IGMPv1or2{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := IgmpQueryv2Layer(tt.args.mcip, tt.args.resptime)
+ assert.NotNil(t, got)
+ })
+ }
+}
+
+func TestIgmpQueryv3Layer(t *testing.T) {
+ type args struct {
+ mcip net.IP
+ resptime time.Duration
+ }
+ tests := []struct {
+ name string
+ args args
+ want *layers.IGMP
+ }{
+ {
+ name: "IgmpQueryv3Layer",
+ args: args{
+ mcip: AllSystemsMulticastGroupIP,
+ resptime: time.Microsecond,
+ },
+ want: &layers.IGMP{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := IgmpQueryv3Layer(tt.args.mcip, tt.args.resptime)
+ assert.NotNil(t, got)
+ })
+ }
+}
+
+func TestIgmpReportv2Layer(t *testing.T) {
+ type args struct {
+ mcip net.IP
+ }
+ tests := []struct {
+ name string
+ args args
+ want *layers.IGMPv1or2
+ }{
+ {
+ name: "IgmpReportv2Layer",
+ args: args{
+ mcip: AllSystemsMulticastGroupIP,
+ },
+ want: &layers.IGMPv1or2{},
+ },
+ {
+ name: "IgmpLeavev2Layer",
+ args: args{
+ mcip: AllSystemsMulticastGroupIP,
+ },
+ want: &layers.IGMPv1or2{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "IgmpReportv2Layer":
+ got := IgmpReportv2Layer(tt.args.mcip)
+ assert.NotNil(t, got)
+ case "IgmpLeavev2Layer":
+ got := IgmpLeavev2Layer(tt.args.mcip)
+ assert.NotNil(t, got)
+ }
+ })
+ }
+}
+
+func TestIgmpReportv3Layer(t *testing.T) {
+ type args struct {
+ mcip net.IP
+ incl bool
+ srclist []net.IP
+ }
+ tests := []struct {
+ name string
+ args args
+ want *layers.IGMP
+ }{
+ {
+ name: "IgmpReportv3Layer",
+ args: args{
+ mcip: AllSystemsMulticastGroupIP,
+ incl: true,
+ },
+ want: &layers.IGMP{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := IgmpReportv3Layer(tt.args.mcip, tt.args.incl, tt.args.srclist)
+ assert.NotNil(t, got)
+ })
+ }
+}
+
+//func TestIgmpv2QueryPacket(t *testing.T) {
+// type args struct {
+// mcip net.IP
+// vlan of.VlanType
+// selfip net.IP
+// pbit uint8
+// maxResp uint32
+// }
+// tests := []struct {
+// name string
+// args args
+// want []byte
+// wantErr bool
+// }{
+// {
+// name: "IgmpReportv3Layer",
+// args: args{
+// vlan: 22,
+// selfip: net.ParseIP("224.0.0.1"),
+// pbit: 0,
+// maxResp: 1,
+// mcip: net.ParseIP("0.0.0.0"),
+// },
+// wantErr: true,
+// },
+// }
+// for _, tt := range tests {
+// t.Run(tt.name, func(t *testing.T) {
+// got, err := Igmpv2QueryPacket(tt.args.mcip, tt.args.vlan, tt.args.selfip, tt.args.pbit, tt.args.maxResp)
+// if (err != nil) != tt.wantErr {
+// t.Errorf("Igmpv2QueryPacket() error = %v, wantErr %v", err, tt.wantErr)
+// return
+// }
+// if !reflect.DeepEqual(got, tt.want) {
+// t.Errorf("Igmpv2QueryPacket() = %v, want %v", got, tt.want)
+// }
+// })
+// }
+// }
+
+func Test_getVersion(t *testing.T) {
+ type args struct {
+ ver string
+ }
+ tests := []struct {
+ name string
+ args args
+ want uint8
+ }{
+ {
+ name: "getVersion_IgmpVersion2",
+ args: args{
+ ver: "2",
+ },
+ want: IgmpVersion2,
+ },
+ {
+ name: "getVersion_IgmpVersion2",
+ args: args{
+ ver: "0",
+ },
+ want: IgmpVersion3,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := getVersion(tt.args.ver); got != tt.want {
+ t.Errorf("getVersion() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestIsIPPresent(t *testing.T) {
+ type args struct {
+ i net.IP
+ ips []net.IP
+ }
+ ips := []net.IP{}
+ ips = append(ips, AllSystemsMulticastGroupIP)
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "TestIsIPPresent_True",
+ args: args{
+ i: AllSystemsMulticastGroupIP,
+ ips: ips,
+ },
+ want: true,
+ },
+ {
+ name: "TestIsIPPresent_False",
+ args: args{
+ ips: ips,
+ },
+ want: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := IsIPPresent(tt.args.i, tt.args.ips); got != tt.want {
+ t.Errorf("IsIPPresent() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/internal/pkg/application/meters.go b/internal/pkg/application/meters.go
index a7fa722..cc61a4f 100644
--- a/internal/pkg/application/meters.go
+++ b/internal/pkg/application/meters.go
@@ -314,13 +314,13 @@
mm := &va.MeterMgr
if _, ok := mm.GetMeterByName(name); !ok {
logger.Warnw(ctx, "Meter profile does not exist", log.Fields{"Name": name})
- return errors.New("Meter profile doesn't exist")
+ return errors.New("meter profile doesn't exist")
}
cfg, _ := mm.GetMeterByName(name)
if cfg.AssociatedServices != 0 {
logger.Warnw(ctx, "Mismatch in submgr and vgc oeter profile service reference",
log.Fields{"MeterProfile": name, "serviceCount": cfg.AssociatedServices})
- return errors.New("Service reference is not 0")
+ return errors.New("service reference is not 0")
}
// TODO : delete from all devices
delmeterFromDevice := func(key interface{}, value interface{}) bool {
diff --git a/internal/pkg/controller/controller.go b/internal/pkg/controller/controller.go
index 9ccb21d..7e1a726 100644
--- a/internal/pkg/controller/controller.go
+++ b/internal/pkg/controller/controller.go
@@ -48,6 +48,19 @@
var db database.DBIntf
+type VoltControllerInterface interface {
+ GetDevice(id string) (*Device, error)
+ GetAllPendingFlows() ([]*of.VoltSubFlow, error)
+ GetAllFlows() ([]*of.VoltSubFlow, error)
+ GetFlows(deviceID string) ([]*of.VoltSubFlow, error)
+ GetFlow(deviceID string, cookie uint64) (*of.VoltSubFlow, error)
+ GetGroups(cntx context.Context, id uint32) (*of.Group, error)
+ GetGroupList() ([]*of.Group, error)
+ GetMeterInfo(cntx context.Context, id uint32) (map[string]*of.Meter, error)
+ GetAllMeterInfo() (map[string][]*of.Meter, error)
+ GetTaskList(device string) []tasks.Task
+}
+
// VoltController structure
type VoltController struct {
ctx context.Context
@@ -517,7 +530,7 @@
return d.GetTaskList()
}
-// AddBlockedDevices to add devices to blocked devices list
+// AddBlockedDevices to add Devices to blocked Devices list
func (v *VoltController) AddBlockedDevices(deviceSerialNumber string) {
v.BlockedDeviceList.Set(deviceSerialNumber, deviceSerialNumber)
}
diff --git a/internal/pkg/controller/controller_test.go b/internal/pkg/controller/controller_test.go
index 2c4b993..235bffe 100644
--- a/internal/pkg/controller/controller_test.go
+++ b/internal/pkg/controller/controller_test.go
@@ -23,6 +23,7 @@
"voltha-go-controller/internal/pkg/intf"
"voltha-go-controller/internal/pkg/of"
"voltha-go-controller/internal/pkg/tasks"
+ "voltha-go-controller/internal/pkg/util"
"voltha-go-controller/internal/pkg/vpagent"
"voltha-go-controller/internal/test/mocks"
@@ -946,7 +947,7 @@
type args struct {
device string
}
- rebootInProgressDevices := map[string]string{}
+ rebootInProgressdevices := map[string]string{}
device := &Device{
ctx: context.Background(),
ID: "SDX6320031",
@@ -976,7 +977,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- rebootInProgressDevices: rebootInProgressDevices,
+ rebootInProgressDevices: rebootInProgressdevices,
devices: dev,
}
switch tt.name {
@@ -997,12 +998,12 @@
type args struct {
device string
}
- rebootInProgressDevices := map[string]string{}
+ rebootInProgressdevices := map[string]string{}
device := &Device{
ctx: context.Background(),
ID: "SDX6320031",
}
- rebootInProgressDevices["SDX6320031"] = "done"
+ rebootInProgressdevices["SDX6320031"] = "done"
dev := map[string]*Device{}
dev["SDX6320031"] = device
tests := []struct {
@@ -1021,7 +1022,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- rebootInProgressDevices: rebootInProgressDevices,
+ rebootInProgressDevices: rebootInProgressdevices,
devices: dev,
}
if got := v.ReSetRebootInProgressForDevice(tt.args.device); got != tt.want {
@@ -1030,3 +1031,201 @@
})
}
}
+
+func TestVoltController_IsBlockedDevice(t *testing.T) {
+ type args struct {
+ deviceserialNumber string
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "IsBlockedDevice",
+ args: args{
+ deviceserialNumber: "SDX6320031",
+ },
+ want: false,
+ },
+ {
+ name: "deviceserialNumber",
+ args: args{
+ deviceserialNumber: "SDX6320031",
+ },
+ want: false,
+ },
+ {
+ name: "AddBlockeddevices",
+ args: args{
+ deviceserialNumber: "SDX6320031",
+ },
+ want: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ v := &VoltController{
+ BlockedDeviceList: util.NewConcurrentMap(),
+ }
+ switch tt.name {
+ case "IsBlockedDevice":
+ if got := v.IsBlockedDevice(tt.args.deviceserialNumber); got != tt.want {
+ t.Errorf("VoltController.IsBlockedDevice() = %v, want %v", got, tt.want)
+ }
+ case "deviceserialNumber":
+ v.DelBlockedDevices(tt.args.deviceserialNumber)
+ case "AddBlockeddevices":
+ v.AddBlockedDevices(tt.args.deviceserialNumber)
+ }
+ })
+ }
+}
+
+func TestVoltController_SetDeviceTableSyncDuration(t *testing.T) {
+ type args struct {
+ duration int
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "SetDeviceTableSyncDuration",
+ args: args{
+ duration: 1,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ v := &VoltController{}
+ switch tt.name {
+ case "SetDeviceTableSyncDuration":
+ v.SetDeviceTableSyncDuration(tt.args.duration)
+ v.GetDeviceTableSyncDuration()
+ }
+ })
+ }
+}
+
+func TestVoltController_IsRebootInProgressForDevice(t *testing.T) {
+ type args struct {
+ device string
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "SetDeviceTableSyncDuration",
+ args: args{
+ device: "SDX6320031",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ v := &VoltController{}
+ if got := v.IsRebootInProgressForDevice(tt.args.device); got != tt.want {
+ t.Errorf("VoltController.IsRebootInProgressForDevice() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltController_GroupUpdate(t *testing.T) {
+ type args struct {
+ port string
+ device string
+ group *of.Group
+ }
+ portsByName := map[string]*DevicePort{}
+ portsByName["SDX6320031-1"] = &DevicePort{
+ Name: "SDX6320031-1",
+ ID: 256,
+ }
+ device := &Device{
+ ctx: context.Background(),
+ ID: "SDX6320031",
+ groups: sync.Map{},
+ PortsByName: portsByName,
+ }
+ dev := map[string]*Device{}
+ dev["SDX6320031"] = device
+ grp := &of.Group{
+ Device: "SDX6320031",
+ GroupID: uint32(256),
+ State: 1,
+ SetVlan: of.VlanAny,
+ }
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutGroup(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "GroupUpdate",
+ args: args{
+ port: "SDX6320031-1",
+ device: "SDX6320031",
+ group: grp,
+ },
+ wantErr: false,
+ },
+ {
+ name: "DeviceNOtFound_Error",
+ args: args{
+ device: "SDX632003134",
+ },
+ wantErr: true,
+ },
+ {
+ name: "PortNOtFound_Error",
+ args: args{
+ device: "SDX6320031",
+ port: "SDX632003134",
+ },
+ wantErr: true,
+ },
+ {
+ name: "ContextNill_Error",
+ args: args{
+ device: "SDX6320031",
+ port: "SDX6320031-1",
+ },
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "GroupUpdate", "DeviceNOtFound_Error", "PortNOtFound_Error":
+ v := &VoltController{
+ devices: dev,
+ }
+ if err := v.GroupUpdate(tt.args.port, tt.args.device, tt.args.group); (err != nil) != tt.wantErr {
+ t.Errorf("VoltController.GroupUpdate() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "ContextNill_Error":
+ device := &Device{
+ ID: "SDX6320031",
+ groups: sync.Map{},
+ PortsByName: portsByName,
+ }
+ dev := map[string]*Device{}
+ dev["SDX6320031"] = device
+ v := &VoltController{
+ devices: dev,
+ }
+ if err := v.GroupUpdate(tt.args.port, tt.args.device, tt.args.group); (err != nil) != tt.wantErr {
+ t.Errorf("VoltController.GroupUpdate() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ }
+ })
+ }
+}
diff --git a/internal/pkg/controller/device.go b/internal/pkg/controller/device.go
index 57474a0..193c3fb 100644
--- a/internal/pkg/controller/device.go
+++ b/internal/pkg/controller/device.go
@@ -119,6 +119,10 @@
DeviceStateDELETED DeviceState = "DELETED"
)
+type DeviceInterface interface {
+ SetFlowHash(cntx context.Context, hash uint32)
+}
+
// Device structure
type Device struct {
ctx context.Context
diff --git a/internal/pkg/controller/device_test.go b/internal/pkg/controller/device_test.go
index 11084fd..8f35aef 100644
--- a/internal/pkg/controller/device_test.go
+++ b/internal/pkg/controller/device_test.go
@@ -209,3 +209,73 @@
})
}
}
+
+func TestDevice_PacketOutReq(t *testing.T) {
+ type args struct {
+ outport string
+ inport string
+ data []byte
+ isCustomPkt bool
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "Device_PacketOutReq",
+ args: args{
+ outport: "test_out_port",
+ inport: "test_in_port",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ portByName := make(map[string]*DevicePort)
+ portByName["test_in_port"] = &DevicePort{
+ Name: "test_device",
+ }
+ portByName["test_out_port"] = &DevicePort{
+ Name: "test_device",
+ }
+ packetOutChannel := make(chan *ofp.PacketOut, 2)
+
+ d := &Device{
+ packetOutChannel: packetOutChannel,
+ PortsByName: portByName,
+ }
+ if err := d.PacketOutReq(tt.args.outport, tt.args.inport, tt.args.data, tt.args.isCustomPkt); (err != nil) != tt.wantErr {
+ t.Errorf("Device.PacketOutReq() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func TestDevice_SetFlowHash(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ hash uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Device_SetFlowHash",
+ args: args{
+ cntx: context.Background(),
+ hash: uint32(2),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &Device{}
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutFlowHash(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
+ d.SetFlowHash(tt.args.cntx, tt.args.hash)
+ })
+ }
+}