VOL-1838, VOL-1909, VOL-1906 and VOL-1911
Updated Device_handler.go test cases.
Adding Unit testcases for olt_platform.go, olt_event_mgr.go and statsmanager.go
Change-Id: I5b64df9a08fa20dd63bfd729c5f086526a9a1d74
diff --git a/Gopkg.lock b/Gopkg.lock
index f0bef73..cc7c37e 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -533,6 +533,7 @@
"github.com/gogo/protobuf/proto",
"github.com/golang/protobuf/proto",
"github.com/golang/protobuf/ptypes",
+ "github.com/golang/protobuf/ptypes/any",
"github.com/opencord/voltha-go/adapters",
"github.com/opencord/voltha-go/adapters/adapterif",
"github.com/opencord/voltha-go/adapters/common",
@@ -551,6 +552,7 @@
"github.com/opencord/voltha-protos/go/voltha",
"google.golang.org/grpc",
"google.golang.org/grpc/codes",
+ "google.golang.org/grpc/metadata",
"google.golang.org/grpc/status",
]
solver-name = "gps-cdcl"
diff --git a/adaptercore/device_handler_test.go b/adaptercore/device_handler_test.go
index 07d8704..d6c65ea 100644
--- a/adaptercore/device_handler_test.go
+++ b/adaptercore/device_handler_test.go
@@ -18,14 +18,91 @@
package adaptercore
import (
+ "context"
"net"
+ "reflect"
"testing"
+ "github.com/golang/protobuf/ptypes"
+ "github.com/golang/protobuf/ptypes/any"
+ "github.com/opencord/voltha-go/common/log"
+ fu "github.com/opencord/voltha-go/rw_core/utils"
+ "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager"
"github.com/opencord/voltha-openolt-adapter/mocks"
+ ic "github.com/opencord/voltha-protos/go/inter_container"
+ of "github.com/opencord/voltha-protos/go/openflow_13"
+ ofp "github.com/opencord/voltha-protos/go/openflow_13"
+ oop "github.com/opencord/voltha-protos/go/openolt"
"github.com/opencord/voltha-protos/go/voltha"
)
-func newMockDeviceDeviceHandler() *DeviceHandler {
+func init() {
+ _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
+}
+
+func newMockCoreProxy() *mocks.MockCoreProxy {
+ mcp := mocks.MockCoreProxy{}
+ mcp.Devices = make(map[string]*voltha.Device)
+ mcp.Devices["olt"] = &voltha.Device{
+
+ Id: "olt",
+ Root: true,
+ ParentId: "logical_device",
+ ParentPortNo: 1,
+
+ Ports: []*voltha.Port{
+ {PortNo: 1, Label: "pon"},
+ {PortNo: 2, Label: "nni"},
+ },
+ ProxyAddress: &voltha.Device_ProxyAddress{
+ DeviceId: "olt",
+ DeviceType: "onu",
+ ChannelId: 1,
+ ChannelGroupId: 1,
+ },
+ ConnectStatus: 1,
+ }
+ mcp.Devices["onu1"] = &voltha.Device{
+
+ Id: "1",
+ Root: false,
+ ParentId: "olt",
+ ParentPortNo: 1,
+
+ Ports: []*voltha.Port{
+ {PortNo: 1, Label: "pon"},
+ {PortNo: 2, Label: "uni"},
+ },
+ OperStatus: 4,
+ ProxyAddress: &voltha.Device_ProxyAddress{
+ OnuId: 1,
+ ChannelId: 1,
+ ChannelGroupId: 1,
+ },
+ ConnectStatus: 1,
+ }
+ mcp.Devices["onu2"] = &voltha.Device{
+ Id: "2",
+ Root: false,
+ ParentId: "olt",
+ OperStatus: 2,
+ Ports: []*voltha.Port{
+ {PortNo: 1, Label: "pon"},
+ {PortNo: 2, Label: "uni"},
+ },
+
+ ParentPortNo: 1,
+
+ ProxyAddress: &voltha.Device_ProxyAddress{
+ OnuId: 2,
+ ChannelId: 1,
+ ChannelGroupId: 1,
+ },
+ ConnectStatus: 1,
+ }
+ return &mcp
+}
+func newMockDeviceHandler() *DeviceHandler {
device := &voltha.Device{
Id: "olt",
Root: true,
@@ -34,16 +111,35 @@
{PortNo: 1, Label: "pon"},
{PortNo: 2, Label: "nni"},
},
+ ProxyAddress: &voltha.Device_ProxyAddress{
+ DeviceId: "olt",
+ DeviceType: "onu",
+ ChannelId: 1,
+ ChannelGroupId: 1,
+ },
+ ConnectStatus: 1,
}
- return &DeviceHandler{
- deviceID: device.GetId(),
-
- device: device,
- coreProxy: &mocks.MockCoreProxy{},
- AdapterProxy: &mocks.MockAdapterProxy{},
- }
+ cp := newMockCoreProxy()
+ ap := &mocks.MockAdapterProxy{}
+ ep := &mocks.MockEventProxy{}
+ openOLT := &OpenOLT{coreProxy: cp, adapterProxy: ap, eventProxy: ep}
+ dh := NewDeviceHandler(cp, ap, ep, device, openOLT)
+ deviceInf := &oop.DeviceInfo{Vendor: "openolt", Ranges: nil, Model: "openolt", DeviceId: dh.deviceID}
+ dh.resourceMgr = &resourcemanager.OpenOltResourceMgr{DeviceID: dh.deviceID, DeviceType: dh.deviceType, DevInfo: deviceInf}
+ dh.flowMgr = NewFlowManager(dh, dh.resourceMgr)
+ dh.Client = &mocks.MockOpenoltClient{}
+ dh.eventMgr = &OpenOltEventMgr{eventProxy: &mocks.MockEventProxy{}}
+ dh.transitionMap = &TransitionMap{}
+ return dh
}
+func negativeDeviceHandler() *DeviceHandler {
+ dh := newMockDeviceHandler()
+ device := dh.device
+ device.Id = ""
+ dh.adminState = "down"
+ return dh
+}
func Test_generateMacFromHost(t *testing.T) {
type args struct {
host string
@@ -54,8 +150,10 @@
want string
wantErr bool
}{
- {"test1", args{host: "localhost"}, "00:00:7f:00:00:01", false},
- {"test2", args{host: "10.10.10.10"}, "00:00:0a:0a:0a:0a", false},
+ {"generateMacFromHost-1", args{host: "localhost"}, "00:00:7f:00:00:01", false},
+ {"generateMacFromHost-2", args{host: "10.10.10.10"}, "00:00:0a:0a:0a:0a", false},
+ //{"generateMacFromHost-3", args{host: "google.com"}, "00:00:d8:3a:c8:8e", false},
+ {"generateMacFromHost-4", args{host: "testing3"}, "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -79,15 +177,21 @@
args args
want string
}{{
- "test1",
+ "macifyIP-1",
args{ip: net.ParseIP("10.10.10.10")},
"00:00:0a:0a:0a:0a",
},
{
- "test3",
+ "macifyIP-2",
args{ip: net.ParseIP("127.0.0.1")},
"00:00:7f:00:00:01",
- }}
+ },
+ {
+ "macifyIP-3",
+ args{ip: net.ParseIP("127.0.0.1/24")},
+ "",
+ },
+ }
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := macifyIP(tt.args.ip); got != tt.want {
@@ -97,39 +201,25 @@
}
}
-func TestDeviceHandler_GetOfpDeviceInfo(t *testing.T) {
- dh := newMockDeviceDeviceHandler()
- device := &voltha.Device{}
- got, err := dh.GetOfpDeviceInfo(device)
- if err != nil {
- t.Errorf("DeviceHandler.GetOfpDeviceInfo() error = %v", err)
- return
- }
- t.Logf("ofpDeviceInfo %v", got)
-}
-
-func TestDeviceHandler_GetOfpPortInfo(t *testing.T) {
- dh := newMockDeviceDeviceHandler()
- device := &voltha.Device{}
- got, err := dh.GetOfpPortInfo(device, 1)
- if err != nil {
- t.Errorf("DeviceHandler.GetOfpPortInfo() error = %v", err)
- return
- }
- t.Logf("ofpDeviceInfo %v", got)
-}
func TestDeviceHandler_GetChildDevice(t *testing.T) {
- dh := newMockDeviceDeviceHandler()
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
type args struct {
parentPort uint32
onuID uint32
}
tests := []struct {
- name string
- args args
- want *voltha.Device
+ name string
+ devicehandler *DeviceHandler
+ args args
+ want *voltha.Device
}{
- {"test1",
+ {"GetChildDevice-1", dh1,
+ args{parentPort: 1,
+ onuID: 1},
+ &voltha.Device{},
+ },
+ {"GetChildDevice-2", dh2,
args{parentPort: 1,
onuID: 1},
&voltha.Device{},
@@ -137,8 +227,761 @@
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- got := dh.GetChildDevice(tt.args.parentPort, tt.args.onuID)
+ got := tt.devicehandler.GetChildDevice(tt.args.parentPort, tt.args.onuID)
t.Log("onu device id", got)
})
}
}
+
+func TestGetportLabel(t *testing.T) {
+ type args struct {
+ portNum uint32
+ portType voltha.Port_PortType
+ }
+ tests := []struct {
+ name string
+ args args
+ want string
+ }{
+ {"GetportLabel-1", args{portNum: 0, portType: 0}, ""},
+ {"GetportLabel-2", args{portNum: 1, portType: 1}, "nni-1"},
+ {"GetportLabel-3", args{portNum: 2, portType: 2}, ""},
+ {"GetportLabel-4", args{portNum: 3, portType: 3}, "pon-3"},
+ {"GetportLabel-5", args{portNum: 4, portType: 4}, ""},
+ {"GetportLabel-6", args{portNum: 5, portType: 5}, ""},
+ {"GetportLabel-7", args{portNum: 6, portType: 6}, ""},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := GetportLabel(tt.args.portNum, tt.args.portType); got != tt.want {
+ t.Errorf("GetportLabel() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestDeviceHandler_ProcessInterAdapterMessage(t *testing.T) {
+ dh := newMockDeviceHandler()
+ proxyAddr := dh.device.ProxyAddress
+ body := &ic.InterAdapterOmciMessage{
+ Message: []byte("asdfasdfasdfasdfas"),
+ ProxyAddress: proxyAddr,
+ }
+ body2 := &ic.InterAdapterOmciMessage{
+ Message: []byte("asdfasdfasdfasdfas"),
+ //ProxyAddress: &voltha.Device_ProxyAddress{},
+ }
+ body3 := &ic.InterAdapterTechProfileDownloadMessage{}
+ var marshalledData *any.Any
+ var err error
+
+ if marshalledData, err = ptypes.MarshalAny(body); err != nil {
+ log.Errorw("cannot-marshal-request", log.Fields{"error": err})
+ }
+
+ var marshalledData1 *any.Any
+
+ if marshalledData1, err = ptypes.MarshalAny(body2); err != nil {
+ log.Errorw("cannot-marshal-request", log.Fields{"error": err})
+ }
+ var marshalledData2 *any.Any
+
+ if marshalledData2, err = ptypes.MarshalAny(body3); err != nil {
+ log.Errorw("cannot-marshal-request", log.Fields{"error": err})
+ }
+ type args struct {
+ msg *ic.InterAdapterMessage
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {"ProcessInterAdapterMessage-1", args{msg: &ic.InterAdapterMessage{
+ Header: &ic.InterAdapterHeader{
+ Id: "012345",
+ Type: 0,
+ },
+ Body: marshalledData,
+ }}, false},
+ {"ProcessInterAdapterMessage-2", args{msg: &ic.InterAdapterMessage{
+ Header: &ic.InterAdapterHeader{
+ Id: "012345",
+ Type: 1,
+ },
+ Body: marshalledData1,
+ }}, false},
+ {"ProcessInterAdapterMessage-3", args{msg: &ic.InterAdapterMessage{
+ Header: &ic.InterAdapterHeader{
+ Id: "012345",
+ Type: 2,
+ },
+ Body: marshalledData,
+ }}, false},
+ {"ProcessInterAdapterMessage-4", args{msg: &ic.InterAdapterMessage{
+ Header: &ic.InterAdapterHeader{
+ Id: "012345",
+ Type: 3,
+ }, Body: marshalledData,
+ }}, false},
+ {"ProcessInterAdapterMessage-5", args{msg: &ic.InterAdapterMessage{
+ Header: &ic.InterAdapterHeader{
+ Id: "012345",
+ Type: 4,
+ }, Body: marshalledData1,
+ }}, false},
+ {"ProcessInterAdapterMessage-6", args{msg: &ic.InterAdapterMessage{
+ Header: &ic.InterAdapterHeader{
+ Id: "012345",
+ Type: 4,
+ }, Body: marshalledData,
+ }}, false},
+ {"ProcessInterAdapterMessage-7", args{msg: &ic.InterAdapterMessage{
+ Header: &ic.InterAdapterHeader{
+ Id: "012345",
+ Type: 5,
+ }, Body: marshalledData,
+ }}, false},
+ {"ProcessInterAdapterMessage-8", args{msg: &ic.InterAdapterMessage{
+ Header: &ic.InterAdapterHeader{
+ Id: "012345",
+ Type: 6,
+ }, Body: marshalledData,
+ }}, false},
+ {"ProcessInterAdapterMessage-9", args{msg: &ic.InterAdapterMessage{
+ Header: &ic.InterAdapterHeader{
+ Id: "012345",
+ Type: 7,
+ }, Body: marshalledData,
+ }}, false},
+ {"ProcessInterAdapterMessage-10", args{msg: &ic.InterAdapterMessage{
+ Header: &ic.InterAdapterHeader{
+ Id: "012345",
+ Type: 7,
+ }, Body: marshalledData2,
+ }}, false},
+ //marshalledData2
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+
+ if err := dh.ProcessInterAdapterMessage(tt.args.msg); (err != nil) != tt.wantErr {
+ t.Errorf("DeviceHandler.ProcessInterAdapterMessage() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func TestDeviceHandler_sendProxiedMessage(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+ device1 := &voltha.Device{
+ Id: "onu1",
+ Root: false,
+ ParentId: "logical_device",
+ ProxyAddress: &voltha.Device_ProxyAddress{
+ DeviceId: "onu1",
+ DeviceType: "onu",
+ ChannelId: 1,
+ ChannelGroupId: 1,
+ },
+ ConnectStatus: 1,
+ }
+ device2 := device1
+ device2.ConnectStatus = 2
+ iaomciMsg1 := &ic.InterAdapterOmciMessage{
+ ProxyAddress: &voltha.Device_ProxyAddress{
+ DeviceId: "onu2",
+ DeviceType: "onu",
+ ChannelId: 1,
+ ChannelGroupId: 1,
+ //OnuId: 2,
+ },
+ ConnectStatus: 1,
+ }
+ iaomciMsg2 := &ic.InterAdapterOmciMessage{
+ ProxyAddress: &voltha.Device_ProxyAddress{
+ DeviceId: "onu3",
+ DeviceType: "onu",
+ ChannelId: 1,
+ ChannelGroupId: 1,
+ },
+ ConnectStatus: 1,
+ }
+ type args struct {
+ onuDevice *voltha.Device
+ omciMsg *ic.InterAdapterOmciMessage
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ }{
+ {"sendProxiedMessage-1", dh1, args{onuDevice: device1, omciMsg: &ic.InterAdapterOmciMessage{}}},
+ {"sendProxiedMessage-2", dh1, args{onuDevice: device2, omciMsg: &ic.InterAdapterOmciMessage{}}},
+ {"sendProxiedMessage-3", dh1, args{onuDevice: nil, omciMsg: iaomciMsg1}},
+ {"sendProxiedMessage-4", dh1, args{onuDevice: nil, omciMsg: iaomciMsg2}},
+ {"sendProxiedMessage-5", dh2, args{onuDevice: nil, omciMsg: iaomciMsg2}},
+ {"sendProxiedMessage-6", dh2, args{onuDevice: device1, omciMsg: &ic.InterAdapterOmciMessage{}}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ tt.devicehandler.sendProxiedMessage(tt.args.onuDevice, tt.args.omciMsg)
+ })
+ }
+}
+
+func TestDeviceHandler_SendPacketInToCore(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+
+ type args struct {
+ logicalPort uint32
+ packetPayload []byte
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ }{
+ {"SendPacketInToCore-1", dh1, args{logicalPort: 1, packetPayload: []byte("test1")}},
+ {"SendPacketInToCore-2", dh1, args{logicalPort: 1, packetPayload: []byte("")}},
+ {"SendPacketInToCore-3", dh2, args{logicalPort: 1, packetPayload: []byte("test1")}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ tt.devicehandler.SendPacketInToCore(tt.args.logicalPort, tt.args.packetPayload)
+ })
+ }
+}
+
+func TestDeviceHandler_DisableDevice(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+ type args struct {
+ device *voltha.Device
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ wantErr bool
+ }{
+ {"DisableDevice-1", dh1, args{device: dh1.device}, false},
+ {"DisableDevice-2", dh1, args{device: dh1.device}, true},
+ {"DisableDevice-3", dh2, args{device: dh2.device}, true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+
+ if err := tt.devicehandler.DisableDevice(tt.args.device); (err != nil) != tt.wantErr {
+ t.Errorf("DeviceHandler.DisableDevice() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func TestDeviceHandler_ReenableDevice(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+ type args struct {
+ device *voltha.Device
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ wantErr bool
+ }{
+ {"ReenableDevice-1", dh1, args{device: dh1.device}, false},
+ {"ReenableDevice-2", dh1, args{device: &voltha.Device{}}, true},
+ {"ReenableDevice-3", dh2, args{device: dh1.device}, false},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ dh := tt.devicehandler
+ if err := dh.ReenableDevice(tt.args.device); (err != nil) != tt.wantErr {
+ t.Errorf("DeviceHandler.ReenableDevice() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func TestDeviceHandler_RebootDevice(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := newMockDeviceHandler()
+ type args struct {
+ device *voltha.Device
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ wantErr bool
+ }{
+ // TODO: Add test cases.
+ {"RebootDevice-1", dh1, args{device: dh1.device}, false},
+ {"RebootDevice-2", dh1, args{device: dh2.device}, true},
+ {"RebootDevice-3", dh2, args{device: dh2.device}, false},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+
+ if err := tt.devicehandler.RebootDevice(tt.args.device); (err != nil) != tt.wantErr {
+ t.Errorf("DeviceHandler.RebootDevice() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func TestDeviceHandler_handleIndication(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+ dh3 := newMockDeviceHandler()
+ dh3.onus = map[string]*OnuDevice{"onu1": NewOnuDevice("onu1", "onu1", "onu1", 1, 1, "onu1"),
+ "onu2": NewOnuDevice("onu2", "onu2", "onu2", 2, 2, "onu2")}
+ type args struct {
+ indication *oop.Indication
+ }
+ tests := []struct {
+ name string
+ deviceHandler *DeviceHandler
+ args args
+ }{
+ // TODO: Add test cases.
+ {"handleIndication-1", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
+ {"handleIndication-2", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
+ {"handleIndication-3", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
+ {"handleIndication-4", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
+ {"handleIndication-5", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
+ {"handleIndication-6", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
+ {"handleIndication-7", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuDiscInd{OnuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}}}},
+ {"handleIndication-8", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
+ {"handleIndication-9", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
+ {"handleIndication-10", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
+ {"handleIndication-11", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
+ {"handleIndication-12", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
+ {"handleIndication-13", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
+ {"handleIndication-14", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PortStats{PortStats: &oop.PortStatistics{IntfId: 1, RxBytes: 100, RxPackets: 100, RxUcastPackets: 100, RxMcastPackets: 100, RxBcastPackets: 100, RxErrorPackets: 100, TxBytes: 100, TxPackets: 100, TxUcastPackets: 100, TxMcastPackets: 100, TxBcastPackets: 100, TxErrorPackets: 100, RxCrcErrors: 100, BipErrors: 100, Timestamp: 1000}}}}},
+ {"handleIndication-15", dh1, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
+ {"handleIndication-16", dh1, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
+ {"handleIndication-17", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", FlowId: 1234, PortNo: 1}}}}},
+ {"handleIndication-18", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{}}}}},
+
+ // Negative testcases
+ {"handleIndication-19", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
+ {"handleIndication-20", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
+ {"handleIndication-21", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
+ {"handleIndication-22", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
+ {"handleIndication-23", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
+ {"handleIndication-24", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
+ {"handleIndication-25", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuDiscInd{OnuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}}}},
+ {"handleIndication-26", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
+ {"handleIndication-27", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
+ {"handleIndication-28", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
+ {"handleIndication-29", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
+ {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
+ {"handleIndication-31", dh2, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
+ {"handleIndication-32", dh2, args{indication: &oop.Indication{Data: &oop.Indication_PortStats{PortStats: &oop.PortStatistics{IntfId: 1, RxBytes: 100, RxPackets: 100, RxUcastPackets: 100, RxMcastPackets: 100, RxBcastPackets: 100, RxErrorPackets: 100, TxBytes: 100, TxPackets: 100, TxUcastPackets: 100, TxMcastPackets: 100, TxBcastPackets: 100, TxErrorPackets: 100, RxCrcErrors: 100, BipErrors: 100, Timestamp: 1000}}}}},
+ {"handleIndication-33", dh2, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
+ {"handleIndication-34", dh2, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
+ //
+ {"handleIndication-35", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
+ {"handleIndication-36", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
+ {"handleIndication-37", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
+ {"handleIndication-38", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
+ {"handleIndication-30", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
+ {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ dh := tt.deviceHandler
+ dh.handleIndication(tt.args.indication)
+ })
+ }
+}
+
+func TestDeviceHandler_addPort(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+ type args struct {
+ intfID uint32
+ portType voltha.Port_PortType
+ state string
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ }{
+ // State up
+ {"addPort.1", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "up"}},
+ {"addPort.2", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "up"}},
+ {"addPort.3", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "up"}},
+ {"addPort.4", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
+ {"addPort.5", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
+ {"addPort.6", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "up"}},
+ {"addPort.7", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "up"}},
+ {"addPort.8", dh1, args{intfID: 1, portType: 8, state: "up"}},
+ // state discovery
+ {"addPort.9", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "down"}},
+ {"addPort.10", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "down"}},
+ {"addPort.11", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "down"}},
+ {"addPort.12", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
+ {"addPort.13", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
+ {"addPort.14", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "down"}},
+ {"addPort.15", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "down"}},
+ {"addPort.16", dh1, args{intfID: 1, portType: 8, state: "down"}},
+
+ {"addPort.17", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
+ {"addPort.18", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
+ {"addPort.19", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
+ {"addPort.20", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ tt.devicehandler.addPort(tt.args.intfID, tt.args.portType, tt.args.state)
+ })
+ }
+}
+
+func Test_macAddressToUint32Array(t *testing.T) {
+ type args struct {
+ mac string
+ }
+ tests := []struct {
+ name string
+ args args
+ want []uint32
+ }{
+ // TODO: Add test cases.
+ {"macAddressToUint32Array-1", args{mac: "00:00:00:00:00:01"}, []uint32{0, 0, 0, 0, 0, 1}},
+ {"macAddressToUint32Array-2", args{mac: "0abcdef"}, []uint32{11259375}},
+ {"macAddressToUint32Array-3", args{mac: "testing"}, []uint32{1, 2, 3, 4, 5, 6}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := macAddressToUint32Array(tt.args.mac); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("macAddressToUint32Array() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestDeviceHandler_handleOltIndication(t *testing.T) {
+
+ type args struct {
+ oltIndication *oop.OltIndication
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {"handleOltIndication-1", args{oltIndication: &oop.OltIndication{OperState: "up"}}},
+ {"handleOltIndication-2", args{oltIndication: &oop.OltIndication{OperState: "down"}}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ dh := newMockDeviceHandler()
+ dh.handleOltIndication(tt.args.oltIndication)
+ })
+ }
+}
+
+func TestDeviceHandler_AdoptDevice(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+ type args struct {
+ device *voltha.Device
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ }{
+ // TODO: Add test cases.
+ {"AdoptDevice-1", dh1, args{device: dh1.device}},
+ {"AdoptDevice-1", dh2, args{device: dh2.device}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ //dh.doStateInit()
+ // context.
+ //dh.AdoptDevice(tt.args.device)
+ tt.devicehandler.postInit()
+ })
+ }
+}
+
+func TestDeviceHandler_activateONU(t *testing.T) {
+ dh := newMockDeviceHandler()
+ dh1 := negativeDeviceHandler()
+ type args struct {
+ intfID uint32
+ onuID int64
+ serialNum *oop.SerialNumber
+ serialNumber string
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ }{
+ {"activateONU-1", dh, args{intfID: 1, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
+ {"activateONU-2", dh, args{intfID: 2, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
+ {"activateONU-3", dh1, args{intfID: 1, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
+ {"activateONU-4", dh1, args{intfID: 2, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+
+ tt.devicehandler.activateONU(tt.args.intfID, tt.args.onuID,
+ tt.args.serialNum, tt.args.serialNumber)
+ })
+ }
+}
+
+func TestDeviceHandler_start(t *testing.T) {
+ dh := newMockDeviceHandler()
+ dh1 := negativeDeviceHandler()
+ dh.start(context.Background())
+ dh.stop(context.Background())
+
+ dh1.start(context.Background())
+ dh1.stop(context.Background())
+
+}
+
+func TestDeviceHandler_PacketOut(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+ acts := []*ofp.OfpAction{
+ fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
+ fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
+ fu.Output(1),
+ }
+ pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUxBgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
+ type args struct {
+ egressPortNo int
+ packet *of.OfpPacketOut
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ wantErr bool
+ }{
+ // TODO: Add test cases.
+ //{"test1", args{egressPortNo: 0, packet: &ofp.OfpPacketOut{}}, true},
+ {"PacketOut-1", dh1, args{egressPortNo: 0, packet: pktout}, false},
+ {"PacketOut-2", dh2, args{egressPortNo: 1, packet: pktout}, false},
+ {"PacketOut-2", dh2, args{egressPortNo: 115000, packet: pktout}, false},
+ {"PacketOut-3", dh1, args{egressPortNo: 65536, packet: pktout}, false},
+ {"PacketOut-4", dh2, args{egressPortNo: 65535, packet: pktout}, false},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ dh := tt.devicehandler
+ if err := dh.PacketOut(tt.args.egressPortNo, tt.args.packet); (err != nil) != tt.wantErr {
+ t.Errorf("DeviceHandler.PacketOut() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
+//
+func TestDeviceHandler_doStateUp(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := newMockDeviceHandler()
+
+ dh2.deviceID = ""
+ dh3 := negativeDeviceHandler()
+
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ wantErr bool
+ }{
+ {"dostateup-1", dh1, false},
+ {"dostateup-2", dh2, false},
+ {"dostateup-3", dh3, true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if err := tt.devicehandler.doStateUp(); (err != nil) != tt.wantErr {
+ t.Logf("DeviceHandler.doStateUp() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+func TestDeviceHandler_doStateDown(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+ dh3 := newMockDeviceHandler()
+ dh3.device.OperStatus = voltha.OperStatus_UNKNOWN
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ wantErr bool
+ }{
+ {"dostatedown-1", dh1, false},
+ {"dostatedown-2", dh2, true},
+ {"dostatedown-2", dh3, true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if err := tt.devicehandler.doStateDown(); (err != nil) != tt.wantErr {
+ t.Logf("DeviceHandler.doStateDown() error = %v", err)
+ }
+ })
+ }
+}
+
+func TestDeviceHandler_GetOfpDeviceInfo(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+ type args struct {
+ device *voltha.Device
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ wantErr bool
+ }{
+ // TODO: Add test cases.
+ {"GetOfpDeviceInfo-1", dh1, args{dh1.device}, false},
+ {"GetOfpDeviceInfo-2", dh1, args{&voltha.Device{}}, false},
+ {"GetOfpDeviceInfo-3", dh2, args{dh1.device}, false},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ dh := tt.devicehandler
+ _, err := dh.GetOfpDeviceInfo(tt.args.device)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("DeviceHandler.GetOfpDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ })
+ }
+}
+
+func TestDeviceHandler_GetOfpPortInfo(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+ type args struct {
+ device *voltha.Device
+ portNo int64
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ wantErr bool
+ }{
+ {"GetOfpPortInfo-1", dh1, args{device: dh1.device, portNo: 1}, false},
+ {"GetOfpPortInfo-2", dh2, args{device: dh2.device, portNo: 1}, false},
+ {"GetOfpPortInfo-3", dh1, args{device: dh1.device, portNo: 0}, false},
+ {"GetOfpPortInfo-4", dh2, args{device: dh2.device, portNo: 0}, false},
+ {"GetOfpPortInfo-5", dh1, args{device: &voltha.Device{}, portNo: 1}, false},
+ {"GetOfpPortInfo-6", dh2, args{device: &voltha.Device{}, portNo: 0}, false},
+ // TODO: Add test cases.
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ dh := tt.devicehandler
+ _, err := dh.GetOfpPortInfo(tt.args.device, tt.args.portNo)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("DeviceHandler.GetOfpPortInfo() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ })
+ }
+}
+
+func TestDeviceHandler_onuDiscIndication(t *testing.T) {
+
+ dh1 := newMockDeviceHandler()
+ dh1.discOnus = map[string]bool{"onu1": true, "onu2": false}
+ dh2 := negativeDeviceHandler()
+ type args struct {
+ onuDiscInd *oop.OnuDiscIndication
+ sn string
+ }
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ args args
+ }{
+ // TODO: Add test cases.
+ {"onuDiscIndication-1", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
+ {"onuDiscIndication-2", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{}}}},
+ {"onuDiscIndication-3", dh1, args{onuDiscInd: &oop.OnuDiscIndication{SerialNumber: &oop.SerialNumber{}}}},
+ {"onuDiscIndication-4", dh1, args{onuDiscInd: &oop.OnuDiscIndication{}}},
+ {"onuDiscIndication-5", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu1"}},
+ {"onuDiscIndication-6", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu2"}},
+ {"onuDiscIndication-7", dh2, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ tt.devicehandler.onuDiscIndication(tt.args.onuDiscInd, tt.args.sn)
+ })
+ }
+}
+
+func TestDeviceHandler_populateDeviceInfo(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := negativeDeviceHandler()
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+
+ wantErr bool
+ }{
+ // TODO: Add test cases.
+ {"populateDeviceInfo-1", dh1, false},
+ {"populateDeviceInfo-2", dh1, true},
+ {"populateDeviceInfo-3", dh1, true},
+ {"populateDeviceInfo-4", dh1, true},
+ {"populateDeviceInfo-5", dh2, true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+
+ _, err := tt.devicehandler.populateDeviceInfo()
+ if (err != nil) != tt.wantErr {
+ t.Errorf("DeviceHandler.populateDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+
+ })
+ }
+}
+
+func TestDeviceHandler_readIndications(t *testing.T) {
+ dh1 := newMockDeviceHandler()
+ dh2 := newMockDeviceHandler()
+ dh2.adminState = "down"
+ dh3 := newMockDeviceHandler()
+ dh3.device.AdminState = voltha.AdminState_DISABLED
+ dh4 := negativeDeviceHandler()
+ tests := []struct {
+ name string
+ devicehandler *DeviceHandler
+ }{
+ // TODO: Add test cases.
+ {"readIndications-1", dh1},
+ {"readIndications-2", dh2},
+ {"readIndications-3", dh2},
+ {"readIndications-4", dh2},
+ {"readIndications-5", dh2},
+ {"readIndications-6", dh3},
+ {"readIndications-7", dh3},
+ {"readIndications-8", dh4},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ tt.devicehandler.readIndications()
+ })
+ }
+}
diff --git a/adaptercore/olt_platform_test.go b/adaptercore/olt_platform_test.go
new file mode 100644
index 0000000..6f3eb64
--- /dev/null
+++ b/adaptercore/olt_platform_test.go
@@ -0,0 +1,372 @@
+/*
+ * Copyright 2018-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 adaptercore provides the utility for olt devices, flows and statistics
+package adaptercore
+
+import (
+ "math"
+ "reflect"
+ "testing"
+
+ fu "github.com/opencord/voltha-go/rw_core/utils"
+ ofp "github.com/opencord/voltha-protos/go/openflow_13"
+ "github.com/opencord/voltha-protos/go/voltha"
+)
+
+func TestMkUniPortNum(t *testing.T) {
+ type args struct {
+ intfID uint32
+ onuID uint32
+ uniID uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ want uint32
+ }{
+ // TODO: Add test cases.
+ {"MkUniPortNum-1", args{1, 1, 1}, ((1 * 2048) + (1 * 16) + 1)},
+ {"MkUniPortNum-2", args{4, 5, 6}, ((4 * 2048) + (5 * 16) + 6)},
+ // Negative test cases to cover the log.warn
+ {"MkUniPortNum-3", args{4, 130, 6}, ((4 * 2048) + (130 * 16) + 6)},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := MkUniPortNum(tt.args.intfID, tt.args.onuID, tt.args.uniID); got != tt.want {
+ t.Errorf("MkUniPortNum() = %v, want %v", got, tt.want)
+ } else {
+ t.Logf("Expected %v , Actual %v \n", tt.want, got)
+ }
+ })
+ }
+}
+
+func TestOnuIDFromPortNum(t *testing.T) {
+ type args struct {
+ portNum uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ want uint32
+ }{
+ // TODO: Add test cases.
+ {"OnuIDFromPortNum-1", args{portNum: 8096}, ((8096 / 16) & 127)},
+ {"OnuIDFromPortNum-2", args{portNum: 9095}, ((9095 / 16) & 127)},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := OnuIDFromPortNum(tt.args.portNum); got != tt.want {
+ t.Errorf("OnuIDFromPortNum() = %v, want %v", got, tt.want)
+ } else {
+ t.Logf("Expected %v , Actual %v \n", tt.want, got)
+ }
+ })
+ }
+}
+
+func TestIntfIDFromUniPortNum(t *testing.T) {
+ type args struct {
+ portNum uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ want uint32
+ }{
+ // TODO: Add test cases.
+ {"IntfIDFromUniPortNum-1", args{portNum: 8096}, ((8096 / 2048) & 15)},
+ // Negative Testcase
+ {"IntfIDFromUniPortNum-2", args{portNum: 1024}, ((1024 / 2048) & 15)},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := IntfIDFromUniPortNum(tt.args.portNum); got != tt.want {
+ t.Errorf("IntfIDFromUniPortNum() = %v, want %v", got, tt.want)
+ } else {
+ t.Logf("Expected %v , Actual %v \n", tt.want, got)
+ }
+ })
+ }
+}
+
+func TestUniIDFromPortNum(t *testing.T) {
+ type args struct {
+ portNum uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ want uint32
+ }{
+
+ // TODO: Add test cases.
+ {"UniIDFromPortNum-1", args{portNum: 8096}, (8096 & 15)},
+ {"UniIDFromPortNum-2", args{portNum: 1024}, (1024 & 15)},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := UniIDFromPortNum(tt.args.portNum); got != tt.want {
+ t.Errorf("UniIDFromPortNum() = %v, want %v", got, tt.want)
+ } else {
+ t.Logf("Expected %v , Actual %v \n", tt.want, got)
+ }
+ })
+ }
+}
+
+func TestIntfIDToPortNo(t *testing.T) {
+ type args struct {
+ intfID uint32
+ intfType voltha.Port_PortType
+ }
+ tests := []struct {
+ name string
+ args args
+ want uint32
+ }{
+ // TODO: Add test cases.
+ {"IntfIDToPortNo-1", args{intfID: 120, intfType: voltha.Port_ETHERNET_NNI}, (uint32(math.Pow(2, 16)) + 120)},
+ {"IntfIDToPortNo-2", args{intfID: 1024, intfType: voltha.Port_ETHERNET_UNI}, 0},
+ {"IntfIDToPortNo-3", args{intfID: 456, intfType: voltha.Port_PON_OLT}, (uint32(2*math.Pow(2, 28)) + 456)},
+ {"IntfIDToPortNo-4", args{intfID: 28, intfType: voltha.Port_PON_ONU}, 0},
+ {"IntfIDToPortNo-5", args{intfID: 45, intfType: voltha.Port_UNKNOWN}, 0},
+ {"IntfIDToPortNo-6", args{intfID: 45, intfType: voltha.Port_VENET_OLT}, 0},
+ {"IntfIDToPortNo-7", args{intfID: 45, intfType: voltha.Port_VENET_ONU}, 0},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := IntfIDToPortNo(tt.args.intfID, tt.args.intfType); got != tt.want {
+ t.Errorf("IntfIDToPortNo() = %v, want %v", got, tt.want)
+ } else {
+ t.Logf("Expected %v , Actual %v \n", tt.want, got)
+ }
+ })
+ }
+}
+
+func TestIntfIDFromNniPortNum(t *testing.T) {
+ type args struct {
+ portNum uint32
+ }
+
+ tests := []struct {
+ name string
+ args args
+ want uint32
+ }{
+ // TODO: Add test cases.
+ {"IntfIDFromNniPortNum-1", args{portNum: 8081}, 8081},
+ {"IntfIDFromNniPortNum-2", args{portNum: 9090}, 9090},
+ {"IntfIDFromNniPortNum-3", args{portNum: 0}, 0},
+ {"IntfIDFromNniPortNum-3", args{portNum: 65535}, 65535},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := IntfIDFromNniPortNum(tt.args.portNum); got != tt.want {
+ t.Errorf("IntfIDFromNniPortNum() = %v, want %v", got, tt.want)
+ } else {
+ t.Logf("Expected %v , Actual %v \n", tt.want, got)
+ }
+ })
+ }
+}
+
+func TestIntfIDToPortTypeName(t *testing.T) {
+ type args struct {
+ intfID uint32
+ }
+ var input uint32
+ input = uint32(2*math.Pow(2, 28)) | 3
+ tests := []struct {
+ name string
+ args args
+ want voltha.Port_PortType
+ }{
+ // TODO: Add test cases.
+ {"IntfIDToPortTypeName-1", args{intfID: 65536}, voltha.Port_ETHERNET_NNI},
+ {"IntfIDToPortTypeName-2", args{intfID: 1000}, voltha.Port_ETHERNET_UNI},
+ {"IntfIDToPortTypeName-2", args{intfID: input}, voltha.Port_PON_OLT},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := IntfIDToPortTypeName(tt.args.intfID); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("IntfIDToPortTypeName() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestExtractAccessFromFlow(t *testing.T) {
+ type args struct {
+ inPort uint32
+ outPort uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ want uint32
+ want1 uint32
+ want2 uint32
+ want3 uint32
+ }{
+ // TODO: Add test cases.
+ {"ExtractAccessFromFlow-1", args{inPort: 10, outPort: 65536}, 10, 0, 0, 10},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, got1, got2, got3 := ExtractAccessFromFlow(tt.args.inPort, tt.args.outPort)
+ if got != tt.want {
+ t.Errorf("ExtractAccessFromFlow() got = %v, want %v", got, tt.want)
+ }
+ if got1 != tt.want1 {
+ t.Errorf("ExtractAccessFromFlow() got1 = %v, want %v", got1, tt.want1)
+ }
+ if got2 != tt.want2 {
+ t.Errorf("ExtractAccessFromFlow() got2 = %v, want %v", got2, tt.want2)
+ }
+ if got3 != tt.want3 {
+ t.Errorf("ExtractAccessFromFlow() got3 = %v, want %v", got3, tt.want3)
+ }
+ })
+ }
+}
+
+func TestIsUpstream(t *testing.T) {
+ type args struct {
+ outPort uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ // TODO: Add test cases.
+ {"TestIsUpstream-1", args{outPort: 65533}, true},
+ {"TestIsUpstream-2", args{outPort: 65536}, true},
+ {"TestIsUpstream-3", args{outPort: 65537}, true},
+ {"TestIsUpstream-4", args{outPort: 65538}, true},
+ {"TestIsUpstream-5", args{outPort: 65539}, true},
+ {"TestIsUpstream-6", args{outPort: 1000}, false},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := IsUpstream(tt.args.outPort); got != tt.want {
+ t.Errorf("IsUpstream() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestIsControllerBoundFlow(t *testing.T) {
+ type args struct {
+ outPort uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ // TODO: Add test cases.
+ {"IsControllerBoundFlow-1", args{outPort: 65533}, true},
+ {"IsControllerBoundFlow-2", args{outPort: 65536}, false},
+ {"IsControllerBoundFlow-3", args{outPort: 65537}, false},
+ {"IsControllerBoundFlow-4", args{outPort: 65538}, false},
+ {"IsControllerBoundFlow-5", args{outPort: 65539}, false},
+ {"IsControllerBoundFlow-6", args{outPort: 1000}, false},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := IsControllerBoundFlow(tt.args.outPort); got != tt.want {
+ t.Errorf("IsControllerBoundFlow() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestFlowExtractInfo(t *testing.T) {
+ fa := &fu.FlowArgs{
+ MatchFields: []*ofp.OfpOxmOfbField{
+ fu.InPort(2),
+ fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
+ fu.EthType(2048),
+ },
+
+ Actions: []*ofp.OfpAction{
+ fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
+ fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
+ fu.Output(1),
+ },
+ }
+ ofpstats := fu.MkFlowStat(fa)
+ type args struct {
+ flow *ofp.OfpFlowStats
+ flowDirection string
+ }
+ tests := []struct {
+ name string
+ args args
+ want uint32
+ want1 uint32
+ want2 uint32
+ want3 uint32
+ want4 uint32
+ want5 uint32
+ wantErr bool
+ }{
+ // TODO: Add test cases.
+ {"FlowExtractInfo-1", args{flow: ofpstats, flowDirection: "upstream"}, 2, 0, 0, 2, 0, 0, false},
+
+ // Negative Testcases
+ {"FlowExtractInfo-2", args{flow: ofpstats, flowDirection: "downstream"}, 0, 0, 0, 0, 0, 0, true},
+ {"FlowExtractInfo-3", args{flow: nil, flowDirection: "downstream"}, 0, 0, 0, 0, 0, 0, true},
+ {"FlowExtractInfo-4", args{flow: &ofp.OfpFlowStats{}, flowDirection: "downstream"}, 0, 0, 0, 0, 0, 0, true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, got1, got2, got3, got4, got5, err := FlowExtractInfo(tt.args.flow, tt.args.flowDirection)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("FlowExtractInfo() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if got != tt.want {
+ t.Errorf("FlowExtractInfo() got = %v, want %v", got, tt.want)
+ return
+ }
+ if got1 != tt.want1 {
+ t.Errorf("FlowExtractInfo() got1 = %v, want %v", got1, tt.want1)
+ return
+ }
+ if got2 != tt.want2 {
+ t.Errorf("FlowExtractInfo() got2 = %v, want %v", got2, tt.want2)
+ return
+ }
+ if got3 != tt.want3 {
+ t.Errorf("FlowExtractInfo() got3 = %v, want %v", got3, tt.want3)
+ return
+ }
+ if got4 != tt.want4 {
+ t.Errorf("FlowExtractInfo() got4 = %v, want %v", got4, tt.want4)
+ return
+ }
+ if got5 != tt.want5 {
+ t.Errorf("FlowExtractInfo() got5 = %v, want %v", got5, tt.want5)
+ return
+ }
+ })
+ }
+}
diff --git a/adaptercore/openolt_eventmgr_test.go b/adaptercore/openolt_eventmgr_test.go
new file mode 100644
index 0000000..7de341f
--- /dev/null
+++ b/adaptercore/openolt_eventmgr_test.go
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2018-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 adaptercore provides APIs for the openOLT adapter
+package adaptercore
+
+import (
+ "testing"
+ "time"
+
+ "github.com/opencord/voltha-openolt-adapter/mocks"
+ oop "github.com/opencord/voltha-protos/go/openolt"
+)
+
+func mockEventMgr() *OpenOltEventMgr {
+ ep := &mocks.MockEventProxy{}
+ return NewEventMgr(ep)
+}
+func TestOpenOltEventMgr_ProcessEvents(t *testing.T) {
+ em := mockEventMgr()
+ type args struct {
+ alarmInd *oop.AlarmIndication
+ deviceID string
+ raisedTs int64
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ // TODO: Add test cases.
+ // LosIndication alarms
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_LosInd{LosInd: &oop.LosIndication{IntfId: 1, Status: "on"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_LosInd{LosInd: &oop.LosIndication{IntfId: 1}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_LosInd{LosInd: &oop.LosIndication{IntfId: 1, Status: "on"}}}}},
+
+ // OnuAlarmIndication alams
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &oop.OnuAlarmIndication{IntfId: 1, OnuId: 3, LosStatus: "on"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &oop.OnuAlarmIndication{IntfId: 1, OnuId: 3, LosStatus: "off"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &oop.OnuAlarmIndication{IntfId: 1, OnuId: 3, LobStatus: "on"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &oop.OnuAlarmIndication{IntfId: 1, OnuId: 3, LobStatus: "off"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &oop.OnuAlarmIndication{IntfId: 1, OnuId: 3, LopcMissStatus: "on"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &oop.OnuAlarmIndication{IntfId: 1, OnuId: 3, LopcMissStatus: "off"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &oop.OnuAlarmIndication{IntfId: 1, OnuId: 3, LopcMicErrorStatus: "on"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &oop.OnuAlarmIndication{IntfId: 1, OnuId: 3, LopcMicErrorStatus: "off"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &oop.OnuAlarmIndication{IntfId: 1, OnuId: 3}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &oop.OnuAlarmIndication{IntfId: 1, OnuId: 3, LosStatus: "on"}}}}},
+
+ // AlarmIndication_DyingGaspInd
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_DyingGaspInd{DyingGaspInd: &oop.DyingGaspIndication{IntfId: 1, OnuId: 1, Status: "on"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_DyingGaspInd{DyingGaspInd: &oop.DyingGaspIndication{IntfId: 1, OnuId: 1, Status: "off"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_DyingGaspInd{DyingGaspInd: &oop.DyingGaspIndication{IntfId: 1, OnuId: 1}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_DyingGaspInd{DyingGaspInd: &oop.DyingGaspIndication{IntfId: 1, OnuId: 1}}}}},
+
+ // AlarmIndication_OnuActivationFailInd
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuActivationFailInd{OnuActivationFailInd: &oop.OnuActivationFailureIndication{IntfId: 1, OnuId: 3}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuActivationFailInd{OnuActivationFailInd: &oop.OnuActivationFailureIndication{IntfId: 1, OnuId: 3}}}}},
+
+ // AlarmIndication_OnuLossOmciInd
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuLossOmciInd{OnuLossOmciInd: &oop.OnuLossOfOmciChannelIndication{IntfId: 1, OnuId: 3, Status: "on"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuLossOmciInd{OnuLossOmciInd: &oop.OnuLossOfOmciChannelIndication{IntfId: 1, OnuId: 3, Status: "off"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuLossOmciInd{OnuLossOmciInd: &oop.OnuLossOfOmciChannelIndication{IntfId: 1, OnuId: 3, Status: "on"}}}}},
+
+ // AlarmIndication_OnuDriftOfWindowInd
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuDriftOfWindowInd{OnuDriftOfWindowInd: &oop.OnuDriftOfWindowIndication{IntfId: 1, OnuId: 3, Status: "on"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuDriftOfWindowInd{OnuDriftOfWindowInd: &oop.OnuDriftOfWindowIndication{IntfId: 1, OnuId: 3, Status: "off"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuDriftOfWindowInd{OnuDriftOfWindowInd: &oop.OnuDriftOfWindowIndication{IntfId: 1, OnuId: 3, Drift: 10, NewEqd: 10}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuDriftOfWindowInd{OnuDriftOfWindowInd: &oop.OnuDriftOfWindowIndication{IntfId: 1, OnuId: 3, Status: "on"}}}}},
+
+ // AlarmIndication_OnuSignalDegradeInd
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuSignalDegradeInd{OnuSignalDegradeInd: &oop.OnuSignalDegradeIndication{IntfId: 1, OnuId: 3, Status: "on", InverseBitErrorRate: 100}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuSignalDegradeInd{OnuSignalDegradeInd: &oop.OnuSignalDegradeIndication{IntfId: 1, OnuId: 3, Status: "off", InverseBitErrorRate: 100}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuSignalDegradeInd{OnuSignalDegradeInd: &oop.OnuSignalDegradeIndication{IntfId: 1, OnuId: 3, InverseBitErrorRate: 100}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuSignalDegradeInd{OnuSignalDegradeInd: &oop.OnuSignalDegradeIndication{IntfId: 1, OnuId: 3, InverseBitErrorRate: 100}}}}},
+
+ // AlarmIndication_OnuSignalsFailInd
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuSignalsFailInd{OnuSignalsFailInd: &oop.OnuSignalsFailureIndication{IntfId: 1, OnuId: 3, Status: "on"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuSignalsFailInd{OnuSignalsFailInd: &oop.OnuSignalsFailureIndication{IntfId: 1, OnuId: 3, Status: "off"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuSignalsFailInd{OnuSignalsFailInd: &oop.OnuSignalsFailureIndication{IntfId: 1, OnuId: 3, InverseBitErrorRate: 100}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuSignalsFailInd{OnuSignalsFailInd: &oop.OnuSignalsFailureIndication{IntfId: 1, OnuId: 3, InverseBitErrorRate: 100}}}}},
+
+ // AlarmIndication_OnuProcessingErrorInd
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuProcessingErrorInd{OnuProcessingErrorInd: &oop.OnuProcessingErrorIndication{IntfId: 1, OnuId: 3}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuProcessingErrorInd{OnuProcessingErrorInd: &oop.OnuProcessingErrorIndication{IntfId: 1, OnuId: 3}}}}},
+
+ // AlarmIndication_OnuTiwiInd
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuTiwiInd{OnuTiwiInd: &oop.OnuTransmissionInterferenceWarning{IntfId: 1, OnuId: 3, Status: "on"}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuTiwiInd{OnuTiwiInd: &oop.OnuTransmissionInterferenceWarning{IntfId: 1, OnuId: 3, Status: "on", Drift: 100}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuTiwiInd{OnuTiwiInd: &oop.OnuTransmissionInterferenceWarning{IntfId: 1, OnuId: 3}}}, deviceID: "olt", raisedTs: time.Now().Unix()}},
+ {"ProcessEvents-", args{alarmInd: &oop.AlarmIndication{Data: &oop.AlarmIndication_OnuTiwiInd{OnuTiwiInd: &oop.OnuTransmissionInterferenceWarning{IntfId: 1, OnuId: 3}}}}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ em.ProcessEvents(tt.args.alarmInd, tt.args.deviceID, tt.args.raisedTs)
+ })
+ }
+}
+
+func TestOpenOltEventMgr_OnuDiscoveryIndication(t *testing.T) {
+ em := mockEventMgr()
+ type args struct {
+ onuDisc *oop.OnuDiscIndication
+ deviceID string
+ OnuID uint32
+ serialNumber string
+ raisedTs int64
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ // TODO: Add test cases.
+ {"OnuDiscoveryIndication", args{onuDisc: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, deviceID: "olt", OnuID: 3, serialNumber: "1234", raisedTs: time.Now().Unix()}},
+ {"OnuDiscoveryIndication", args{onuDisc: &oop.OnuDiscIndication{}, raisedTs: time.Now().Unix()}},
+ {"OnuDiscoveryIndication", args{onuDisc: &oop.OnuDiscIndication{}}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ em.OnuDiscoveryIndication(tt.args.onuDisc, tt.args.deviceID, tt.args.OnuID, tt.args.serialNumber, tt.args.raisedTs)
+ })
+ }
+}
diff --git a/adaptercore/statsmanager_test.go b/adaptercore/statsmanager_test.go
new file mode 100644
index 0000000..e6ef321
--- /dev/null
+++ b/adaptercore/statsmanager_test.go
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2019-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 adaptercore provides the utility for olt devices, flows and statistics
+package adaptercore
+
+import (
+ "testing"
+
+ "github.com/opencord/voltha-go/common/log"
+ "github.com/opencord/voltha-protos/go/openolt"
+ "github.com/opencord/voltha-protos/go/voltha"
+)
+
+func init() {
+ _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
+}
+func TestOpenOltStatisticsMgr_PortStatisticsIndication(t *testing.T) {
+ device := &voltha.Device{
+ Id: "olt",
+ Root: true,
+ ParentId: "logical_device",
+ Ports: []*voltha.Port{
+ {PortNo: 1, Label: "pon", Type: voltha.Port_ETHERNET_UNI},
+ {PortNo: 2, Label: "nni", Type: voltha.Port_ETHERNET_NNI},
+ },
+ ProxyAddress: &voltha.Device_ProxyAddress{
+ DeviceId: "olt",
+ DeviceType: "onu",
+ ChannelId: 1,
+ ChannelGroupId: 1,
+ },
+ ConnectStatus: 1,
+ }
+ dh := &DeviceHandler{}
+ dh.device = device
+ StatMgr := NewOpenOltStatsMgr(dh)
+
+ type args struct {
+ PortStats *openolt.PortStatistics
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ // TODO: Add test cases.
+ {"PortStatisticsIndication", args{PortStats: &openolt.PortStatistics{}}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+
+ StatMgr.PortStatisticsIndication(tt.args.PortStats)
+ })
+ }
+}
diff --git a/mocks/mockAdapterProxy.go b/mocks/mockAdapterProxy.go
index a91d361..1b8ada7 100644
--- a/mocks/mockAdapterProxy.go
+++ b/mocks/mockAdapterProxy.go
@@ -38,10 +38,8 @@
toDeviceID string,
proxyDeviceID string,
messageID string) error {
- //panic("implement me")
- if ctx == nil || msg == nil || fromAdapter != "" ||
- toAdapter != "" || toDeviceID != "" || proxyDeviceID != "" || messageID != "" {
- return errors.New("sendInterAdapterMessage func parameters cannot be nil")
+ if toDeviceID == "" {
+ return errors.New("no deviceid")
}
return nil
}
diff --git a/mocks/mockCoreProxy.go b/mocks/mockCoreProxy.go
index 6abf628..77b4c08 100644
--- a/mocks/mockCoreProxy.go
+++ b/mocks/mockCoreProxy.go
@@ -20,6 +20,7 @@
import (
"context"
"errors"
+ "fmt"
"github.com/opencord/voltha-go/kafka"
"github.com/opencord/voltha-protos/go/voltha"
@@ -29,106 +30,166 @@
type MockCoreProxy struct {
// Values to be used in test can reside inside this structure
// TODO store relevant info in this, use this info for negative and positive tests
+ Devices map[string]*voltha.Device
}
// UpdateCoreReference mock updatesCoreReference
-func (mp *MockCoreProxy) UpdateCoreReference(deviceID string, coreReference string) {
+func (mcp *MockCoreProxy) UpdateCoreReference(deviceID string, coreReference string) {
panic("implement me")
}
// DeleteCoreReference mock DeleteCoreReference function
-func (mp *MockCoreProxy) DeleteCoreReference(deviceID string) {
+func (mcp *MockCoreProxy) DeleteCoreReference(deviceID string) {
panic("implement me")
}
// GetCoreTopic implements mock GetCoreTopic
-func (mp *MockCoreProxy) GetCoreTopic(deviceID string) kafka.Topic {
+func (mcp *MockCoreProxy) GetCoreTopic(deviceID string) kafka.Topic {
panic("implement me")
}
// GetAdapterTopic implements mock GetAdapterTopic
-func (mp *MockCoreProxy) GetAdapterTopic(args ...string) kafka.Topic {
+func (mcp *MockCoreProxy) GetAdapterTopic(args ...string) kafka.Topic {
panic("implement me")
}
// RegisterAdapter implements mock RegisterAdapter
-func (mp *MockCoreProxy) RegisterAdapter(ctx context.Context, adapter *voltha.Adapter,
+func (mcp *MockCoreProxy) RegisterAdapter(ctx context.Context, adapter *voltha.Adapter,
deviceTypes *voltha.DeviceTypes) error {
if ctx == nil || adapter == nil || deviceTypes == nil {
-
return errors.New("registerAdapter func parameters cannot be nil")
}
return nil
-
}
// DeviceUpdate implements mock DeviceUpdate
-func (mp *MockCoreProxy) DeviceUpdate(ctx context.Context, device *voltha.Device) error {
- panic("implement me")
+func (mcp *MockCoreProxy) DeviceUpdate(ctx context.Context, device *voltha.Device) error {
+ if device.Id == "" {
+ return errors.New("no Device")
+ }
+ return nil
}
// PortCreated implements mock PortCreated
-func (mp *MockCoreProxy) PortCreated(ctx context.Context, deviceID string, port *voltha.Port) error {
- panic("implement me")
+func (mcp *MockCoreProxy) PortCreated(ctx context.Context, deviceID string, port *voltha.Port) error {
+ if deviceID == "" {
+ return errors.New("no deviceID")
+ }
+ if port.Type > 7 {
+ return errors.New("invalid porttype")
+ }
+ return nil
}
// PortsStateUpdate implements mock PortsStateUpdate
-func (mp *MockCoreProxy) PortsStateUpdate(ctx context.Context, deviceID string, operStatus voltha.OperStatus_OperStatus) error {
- panic("implement me")
+func (mcp *MockCoreProxy) PortsStateUpdate(ctx context.Context, deviceID string, operStatus voltha.OperStatus_OperStatus) error {
+ if deviceID == "" {
+ return errors.New("no Device")
+ }
+ return nil
}
// DeleteAllPorts implements mock DeleteAllPorts
-func (mp *MockCoreProxy) DeleteAllPorts(ctx context.Context, deviceID string) error {
- panic("implement me")
+func (mcp *MockCoreProxy) DeleteAllPorts(ctx context.Context, deviceID string) error {
+ if deviceID == "" {
+ return errors.New("no Device id")
+ }
+ return nil
}
// DeviceStateUpdate implements mock DeviceStateUpdate
-func (mp *MockCoreProxy) DeviceStateUpdate(ctx context.Context, deviceID string,
+func (mcp *MockCoreProxy) DeviceStateUpdate(ctx context.Context, deviceID string,
connStatus voltha.ConnectStatus_ConnectStatus, operStatus voltha.OperStatus_OperStatus) error {
- panic("implement me")
+ if deviceID == "" {
+ return errors.New("no Device id")
+ }
+ return nil
}
// ChildDeviceDetected implements mock ChildDeviceDetected
-func (mp *MockCoreProxy) ChildDeviceDetected(ctx context.Context, parentDeviceID string, parentPortNo int,
+func (mcp *MockCoreProxy) ChildDeviceDetected(ctx context.Context, parentdeviceID string, parentPortNo int,
childDeviceType string, channelID int, vendorID string, serialNumber string, onuID int64) (*voltha.Device, error) {
- panic("implement me")
+ if parentdeviceID == "" {
+ return nil, errors.New("no deviceID")
+ }
+ return nil, nil
}
-// ChildDevicesLost implements mock ChildDevicesLost
-func (mp *MockCoreProxy) ChildDevicesLost(ctx context.Context, parentDeviceID string) error {
- panic("implement me")
+// ChildDevicesLost implements mock ChildDevicesLost.
+func (mcp *MockCoreProxy) ChildDevicesLost(ctx context.Context, parentdeviceID string) error {
+ //panic("implement me")
+ if parentdeviceID == "" {
+ return errors.New("no device id")
+ }
+ return nil
}
// ChildDevicesDetected implements mock ChildDevicesDetecte
-func (mp *MockCoreProxy) ChildDevicesDetected(ctx context.Context, parentDeviceID string) error {
- panic("implement me")
+func (mcp *MockCoreProxy) ChildDevicesDetected(ctx context.Context, parentdeviceID string) error {
+ if parentdeviceID == "" {
+ return errors.New("no device id")
+ }
+ return nil
}
// GetDevice implements mock GetDevice
-func (mp *MockCoreProxy) GetDevice(ctx context.Context, parentDeviceID string, deviceID string) (*voltha.Device, error) {
- if parentDeviceID != "" {
- return &voltha.Device{}, nil
+func (mcp *MockCoreProxy) GetDevice(ctx context.Context, parentdeviceID string, deviceID string) (*voltha.Device, error) {
+ if parentdeviceID == "" || deviceID == "" {
+ return &voltha.Device{}, errors.New("no deviceID")
+ }
+ for k, v := range mcp.Devices {
+ if k == "olt" {
+ return v, nil
+ }
}
return nil, errors.New("device detection failed")
}
// GetChildDevice implements mock GetChildDevice
-func (mp *MockCoreProxy) GetChildDevice(ctx context.Context, parentDeviceID string, kwargs map[string]interface{}) (*voltha.Device, error) {
- if parentDeviceID != "" {
- return &voltha.Device{}, nil
+func (mcp *MockCoreProxy) GetChildDevice(ctx context.Context, parentdeviceID string, kwargs map[string]interface{}) (*voltha.Device, error) {
+
+ if parentdeviceID == "" {
+ return nil, errors.New("device detection failed")
}
+ onuID := kwargs["onu_id"]
+ var onuDevice *voltha.Device
+ for _, val := range mcp.Devices {
+ if val.GetId() == fmt.Sprintf("%v", onuID) {
+ onuDevice = val
+ break
+ }
+ }
+ if onuDevice != nil {
+ return onuDevice, nil
+ }
+ //return &voltha.Device{}, nil
return nil, errors.New("device detection failed")
}
// GetChildDevices implements mock GetChildDevices
-func (mp *MockCoreProxy) GetChildDevices(ctx context.Context, parentDeviceID string) (*voltha.Devices, error) {
- if parentDeviceID != "" {
- return &voltha.Devices{}, nil
+func (mcp *MockCoreProxy) GetChildDevices(ctx context.Context, parentdeviceID string) (*voltha.Devices, error) {
+ if parentdeviceID == "" {
+ return nil, errors.New("no deviceID")
+ }
+ onuDevices := make([]*voltha.Device, 0)
+
+ for _, val := range mcp.Devices {
+ if val != nil {
+ onuDevices = append(onuDevices, val)
+ }
+ }
+
+ deviceList := &voltha.Devices{Items: onuDevices}
+ if len(deviceList.Items) > 0 {
+ return deviceList, nil
}
return nil, errors.New("device detection failed")
}
// SendPacketIn implements mock SendPacketIn
-func (mp *MockCoreProxy) SendPacketIn(ctx context.Context, deviceID string, port uint32, pktPayload []byte) error {
- panic("implement me")
+func (mcp *MockCoreProxy) SendPacketIn(ctx context.Context, deviceID string, port uint32, pktPayload []byte) error {
+ if deviceID == "" {
+ return errors.New("no Device ID")
+ }
+ return nil
}
diff --git a/mocks/mockEventproxy.go b/mocks/mockEventproxy.go
new file mode 100644
index 0000000..be3049a
--- /dev/null
+++ b/mocks/mockEventproxy.go
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2018-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 mocks provides the mocks for openolt-adapter.
+package mocks
+
+import (
+ "errors"
+
+ "github.com/opencord/voltha-protos/go/voltha"
+)
+
+// MockEventProxy for mocking EventProxyIntf
+type MockEventProxy struct {
+}
+
+// SendDeviceEvent mocks the SendDeviceEvent function
+func (me *MockEventProxy) SendDeviceEvent(deviceEvent *voltha.DeviceEvent, category voltha.EventCategory_EventCategory,
+ subCategory voltha.EventSubCategory_EventSubCategory, raisedTs int64) error {
+ if raisedTs == 0 {
+ return errors.New("raisedTS cannot be zero")
+ }
+ return nil
+}
diff --git a/mocks/mockOpenOltClient.go b/mocks/mockOpenOltClient.go
new file mode 100644
index 0000000..b3d9077
--- /dev/null
+++ b/mocks/mockOpenOltClient.go
@@ -0,0 +1,224 @@
+/*
+ * Copyright 2018-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 mocks provides the mocks for openolt-adapter.
+package mocks
+
+import (
+ "context"
+ "errors"
+ "io"
+
+ openolt "github.com/opencord/voltha-protos/go/openolt"
+ tech_profile "github.com/opencord/voltha-protos/go/tech_profile"
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/metadata"
+)
+
+// MockOpenoltClient mock struct for OpenoltClient.
+type MockOpenoltClient struct {
+ counter int
+}
+
+// DisableOlt mocks the DisableOlt function of Openoltclient.
+func (ooc *MockOpenoltClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ //return &openolt.Empty{}, nil
+ if ooc.counter == 0 {
+ ooc.counter++
+ return &openolt.Empty{}, nil
+ }
+ return nil, errors.New("disableOlt failed")
+}
+
+// ReenableOlt mocks the ReenableOlt function of Openoltclient.
+func (ooc *MockOpenoltClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ if ooc.counter == 0 {
+ ooc.counter++
+ return &openolt.Empty{}, nil
+ }
+ return nil, errors.New("reenable olt failed")
+}
+
+// ActivateOnu mocks the ActivateOnu function of Openoltclient.
+func (ooc *MockOpenoltClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ if in == nil {
+ return nil, errors.New("invalid onuId")
+ }
+ return &openolt.Empty{}, nil
+}
+
+// DeactivateOnu mocks the DeactivateOnu function of Openoltclient.
+func (ooc *MockOpenoltClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// DeleteOnu mocks the DeleteOnu function of Openoltclient.
+func (ooc *MockOpenoltClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// OmciMsgOut mocks the OmciMsgOut function of Openoltclient.
+func (ooc *MockOpenoltClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ if in == nil {
+ return nil, errors.New("invalid Omci Msg")
+ }
+ return &openolt.Empty{}, nil
+}
+
+// OnuPacketOut mocks the OnuPacketOut function of Openoltclient.
+func (ooc *MockOpenoltClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// UplinkPacketOut mocks the UplinkPacketOut function of Openoltclient.
+func (ooc *MockOpenoltClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// FlowAdd mocks the FlowAdd function of Openoltclient.
+func (ooc *MockOpenoltClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// FlowRemove mocks the FlowRemove function of Openoltclient.
+func (ooc *MockOpenoltClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// HeartbeatCheck mocks the HeartbeatCheck function of Openoltclient.
+func (ooc *MockOpenoltClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) {
+ return nil, nil
+}
+
+// EnablePonIf mocks the EnablePonIf function of Openoltclient.
+func (ooc *MockOpenoltClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// DisablePonIf mocks the DisablePonIf function of Openoltclient.
+func (ooc *MockOpenoltClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// GetDeviceInfo mocks the GetDeviceInfo function of Openoltclient.
+func (ooc *MockOpenoltClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) {
+ if ooc.counter == 0 {
+ ooc.counter++
+ deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "olt", DeviceSerialNumber: "olt"}
+ return deviceInfo, nil
+ }
+ if ooc.counter == 1 {
+ ooc.counter++
+ deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "", DeviceSerialNumber: "olt"}
+ return deviceInfo, nil
+ }
+ if ooc.counter == 2 {
+ ooc.counter++
+ return nil, nil
+ }
+
+ return nil, errors.New("device info not found")
+}
+
+// Reboot mocks the Reboot function of Openoltclient.
+func (ooc *MockOpenoltClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ if ooc.counter == 0 {
+ ooc.counter++
+ return &openolt.Empty{}, nil
+ }
+ return nil, errors.New("reboot failed")
+}
+
+// CollectStatistics mocks the CollectStatistics function of Openoltclient.
+func (ooc *MockOpenoltClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// CreateTrafficSchedulers mocks the CreateTrafficSchedulers function of Openoltclient.
+func (ooc *MockOpenoltClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// RemoveTrafficSchedulers mocks the RemoveTrafficSchedulers function of Openoltclient.
+func (ooc *MockOpenoltClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// CreateTrafficQueues mocks the CreateTrafficQueues function of Openoltclient.
+func (ooc *MockOpenoltClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// RemoveTrafficQueues mocks the RemoveTrafficQueues function of Openoltclient.
+func (ooc *MockOpenoltClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
+ return &openolt.Empty{}, nil
+}
+
+// EnableIndication mocks the EnableIndication function of Openoltclient.
+func (ooc *MockOpenoltClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) {
+ if ooc.counter < 2 {
+ ooc.counter++
+ mockInd := &mockOpenoltEnableIndicationClient{0}
+ return mockInd, nil
+ }
+ if ooc.counter == 2 {
+ ooc.counter++
+ return nil, nil
+ }
+ return nil, errors.New("invalid method invocation")
+}
+
+type mockOpenoltEnableIndicationClient struct {
+ count int
+}
+
+func (mock *mockOpenoltEnableIndicationClient) Recv() (*openolt.Indication, error) {
+ if mock.count == 0 {
+ mock.count = mock.count + 1
+ indi := &openolt.Indication{Data: &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "Down"}}}
+ return indi, nil
+ }
+ if mock.count == 1 {
+ mock.count = mock.count + 1
+ return nil, errors.New("error, while processing indication")
+ }
+
+ return nil, io.EOF
+}
+
+func (mock *mockOpenoltEnableIndicationClient) Header() (metadata.MD, error) {
+ return nil, nil
+}
+
+func (mock *mockOpenoltEnableIndicationClient) Trailer() metadata.MD {
+ return nil
+}
+
+func (mock *mockOpenoltEnableIndicationClient) CloseSend() error {
+ return nil
+}
+
+func (mock *mockOpenoltEnableIndicationClient) Context() context.Context {
+ return context.Background()
+}
+
+func (mock *mockOpenoltEnableIndicationClient) SendMsg(m interface{}) error {
+ return nil
+}
+
+func (mock *mockOpenoltEnableIndicationClient) RecvMsg(m interface{}) error {
+ return nil
+}