VOL-1838 Unit test cases for golang openolt adapter device_handler.go
1.Mocked AdapterproxyIntf and coreproxyIntf Interfaces for unit test cases.
2. Added few unit testcases for the device_handler.go functions
Change-Id: I793d94055d2c0480e614e918c064df51cdf0b0ae
diff --git a/Gopkg.lock b/Gopkg.lock
index d661b29..6b1964c 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -227,10 +227,11 @@
[[projects]]
branch = "voltha-2.1"
- digest = "1:f61d3e7e118422cdadad10942bb1000b90d8e1ba8c87e9e278fcbaf8ea4aa6fa"
+ digest = "1:795dd43b23959662cb93a0d1d1658e127b9f0c0559191eecb077e2986e4dd7a0"
name = "github.com/opencord/voltha-go"
packages = [
"adapters",
+ "adapters/adapterif",
"adapters/common",
"common/log",
"common/ponresourcemanager",
@@ -241,7 +242,7 @@
"rw_core/utils",
]
pruneopts = "UT"
- revision = "057671182103e7e029e919963b03ef4c13e9eb95"
+ revision = "056aa9518661f793e7bcd0af2fa5d90a81b73a1f"
[[projects]]
digest = "1:bc21a70b7c12a8d8c2b008d2d61a313bf4ed8f021be84d815f744a869e69c96f"
@@ -531,8 +532,10 @@
analyzer-version = 1
input-imports = [
"github.com/gogo/protobuf/proto",
+ "github.com/golang/protobuf/proto",
"github.com/golang/protobuf/ptypes",
"github.com/opencord/voltha-go/adapters",
+ "github.com/opencord/voltha-go/adapters/adapterif",
"github.com/opencord/voltha-go/adapters/common",
"github.com/opencord/voltha-go/common/log",
"github.com/opencord/voltha-go/common/ponresourcemanager",
diff --git a/adaptercore/device_handler.go b/adaptercore/device_handler.go
index 52e4afd..95bc170 100644
--- a/adaptercore/device_handler.go
+++ b/adaptercore/device_handler.go
@@ -33,7 +33,7 @@
"github.com/gogo/protobuf/proto"
"github.com/golang/protobuf/ptypes"
- com "github.com/opencord/voltha-go/adapters/common"
+ "github.com/opencord/voltha-go/adapters/adapterif"
"github.com/opencord/voltha-go/common/log"
rsrcMgr "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager"
"github.com/opencord/voltha-protos/go/common"
@@ -51,15 +51,19 @@
MaxTimeOutInMs = 500
)
+func init() {
+ _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
+}
+
//DeviceHandler will interact with the OLT device.
type DeviceHandler struct {
deviceID string
deviceType string
adminState string
device *voltha.Device
- coreProxy *com.CoreProxy
- AdapterProxy *com.AdapterProxy
- EventProxy *com.EventProxy
+ coreProxy adapterif.CoreProxy
+ AdapterProxy adapterif.AdapterProxy
+ EventProxy adapterif.EventProxy
openOLT *OpenOLT
exitChannel chan int
lockDevice sync.RWMutex
@@ -97,7 +101,7 @@
}
//NewDeviceHandler creates a new device handler
-func NewDeviceHandler(cp *com.CoreProxy, ap *com.AdapterProxy, ep *com.EventProxy, device *voltha.Device, adapter *OpenOLT) *DeviceHandler {
+func NewDeviceHandler(cp adapterif.CoreProxy, ap adapterif.AdapterProxy, ep adapterif.EventProxy, device *voltha.Device, adapter *OpenOLT) *DeviceHandler {
var dh DeviceHandler
dh.coreProxy = cp
dh.AdapterProxy = ap
diff --git a/adaptercore/device_handler_test.go b/adaptercore/device_handler_test.go
new file mode 100644
index 0000000..07d8704
--- /dev/null
+++ b/adaptercore/device_handler_test.go
@@ -0,0 +1,144 @@
+/*
+ * 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 (
+ "net"
+ "testing"
+
+ "github.com/opencord/voltha-openolt-adapter/mocks"
+ "github.com/opencord/voltha-protos/go/voltha"
+)
+
+func newMockDeviceDeviceHandler() *DeviceHandler {
+ device := &voltha.Device{
+ Id: "olt",
+ Root: true,
+ ParentId: "logical_device",
+ Ports: []*voltha.Port{
+ {PortNo: 1, Label: "pon"},
+ {PortNo: 2, Label: "nni"},
+ },
+ }
+ return &DeviceHandler{
+ deviceID: device.GetId(),
+
+ device: device,
+ coreProxy: &mocks.MockCoreProxy{},
+ AdapterProxy: &mocks.MockAdapterProxy{},
+ }
+}
+
+func Test_generateMacFromHost(t *testing.T) {
+ type args struct {
+ host string
+ }
+ tests := []struct {
+ name string
+ args args
+ 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},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, err := generateMacFromHost(tt.args.host)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("generateMacFromHost() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if got != tt.want {
+ t.Errorf("generateMacFromHost() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+func Test_macifyIP(t *testing.T) {
+ type args struct {
+ ip net.IP
+ }
+ tests := []struct {
+ name string
+ args args
+ want string
+ }{{
+ "test1",
+ args{ip: net.ParseIP("10.10.10.10")},
+ "00:00:0a:0a:0a:0a",
+ },
+ {
+ "test3",
+ args{ip: net.ParseIP("127.0.0.1")},
+ "00:00:7f:00:00:01",
+ }}
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := macifyIP(tt.args.ip); got != tt.want {
+ t.Errorf("macifyIP() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+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()
+ type args struct {
+ parentPort uint32
+ onuID uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ want *voltha.Device
+ }{
+ {"test1",
+ args{parentPort: 1,
+ onuID: 1},
+ &voltha.Device{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := dh.GetChildDevice(tt.args.parentPort, tt.args.onuID)
+ t.Log("onu device id", got)
+ })
+ }
+}
diff --git a/adaptercore/openolt.go b/adaptercore/openolt.go
index 0da66ff..33ac5d5 100644
--- a/adaptercore/openolt.go
+++ b/adaptercore/openolt.go
@@ -23,7 +23,7 @@
"fmt"
"sync"
- com "github.com/opencord/voltha-go/adapters/common"
+ "github.com/opencord/voltha-go/adapters/adapterif"
"github.com/opencord/voltha-go/common/log"
"github.com/opencord/voltha-go/kafka"
ic "github.com/opencord/voltha-protos/go/inter_container"
@@ -34,9 +34,9 @@
//OpenOLT structure holds the OLT information
type OpenOLT struct {
deviceHandlers map[string]*DeviceHandler
- coreProxy *com.CoreProxy
- adapterProxy *com.AdapterProxy
- eventProxy *com.EventProxy
+ coreProxy adapterif.CoreProxy
+ adapterProxy adapterif.AdapterProxy
+ eventProxy adapterif.EventProxy
kafkaICProxy *kafka.InterContainerProxy
numOnus int
KVStoreHost string
@@ -47,7 +47,10 @@
}
//NewOpenOLT returns a new instance of OpenOLT
-func NewOpenOLT(ctx context.Context, kafkaICProxy *kafka.InterContainerProxy, coreProxy *com.CoreProxy, adapterProxy *com.AdapterProxy, eventProxy *com.EventProxy, onuNumber int, kvStoreHost string, kvStorePort int, KVStoreType string) *OpenOLT {
+func NewOpenOLT(ctx context.Context, kafkaICProxy *kafka.InterContainerProxy,
+ coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
+ eventProxy adapterif.EventProxy, onuNumber int, kvStoreHost string,
+ kvStorePort int, KVStoreType string) *OpenOLT {
var openOLT OpenOLT
openOLT.exitChannel = make(chan int, 1)
openOLT.deviceHandlers = make(map[string]*DeviceHandler)
diff --git a/adaptercore/openolt_eventmgr.go b/adaptercore/openolt_eventmgr.go
index e1cb576..ba74f18 100644
--- a/adaptercore/openolt_eventmgr.go
+++ b/adaptercore/openolt_eventmgr.go
@@ -19,7 +19,8 @@
import (
"fmt"
- com "github.com/opencord/voltha-go/adapters/common"
+
+ "github.com/opencord/voltha-go/adapters/adapterif"
"github.com/opencord/voltha-go/common/log"
oop "github.com/opencord/voltha-protos/go/openolt"
"github.com/opencord/voltha-protos/go/voltha"
@@ -60,11 +61,11 @@
// OpenOltEventMgr struct contains
type OpenOltEventMgr struct {
- eventProxy *com.EventProxy
+ eventProxy adapterif.EventProxy
}
// NewEventMgr is a Function to get a new event manager struct for the OpenOLT to process and publish OpenOLT event
-func NewEventMgr(eventProxy *com.EventProxy) *OpenOltEventMgr {
+func NewEventMgr(eventProxy adapterif.EventProxy) *OpenOltEventMgr {
var em OpenOltEventMgr
em.eventProxy = eventProxy
return &em
diff --git a/main.go b/main.go
index 30efa84..af7ca2e 100644
--- a/main.go
+++ b/main.go
@@ -21,6 +21,14 @@
"context"
"errors"
"fmt"
+ "os"
+ "os/signal"
+ "strconv"
+ "syscall"
+ "time"
+
+ "github.com/opencord/voltha-go/adapters/adapterif"
+
"github.com/opencord/voltha-go/adapters"
com "github.com/opencord/voltha-go/adapters/common"
"github.com/opencord/voltha-go/common/log"
@@ -31,11 +39,6 @@
"github.com/opencord/voltha-openolt-adapter/config/version"
ic "github.com/opencord/voltha-protos/go/inter_container"
"github.com/opencord/voltha-protos/go/voltha"
- "os"
- "os/signal"
- "strconv"
- "syscall"
- "time"
)
type adapter struct {
@@ -45,9 +48,9 @@
kafkaClient kafka.Client
kvClient kvstore.Client
kip *kafka.InterContainerProxy
- coreProxy *com.CoreProxy
- adapterProxy *com.AdapterProxy
- eventProxy *com.EventProxy
+ coreProxy adapterif.CoreProxy
+ adapterProxy adapterif.AdapterProxy
+ eventProxy adapterif.EventProxy
halted bool
exitChannel chan int
receiverChannels []<-chan *ic.InterContainerMessage
@@ -97,7 +100,8 @@
a.eventProxy = com.NewEventProxy(com.MsgClient(a.kafkaClient), com.MsgTopic(kafka.Topic{Name: a.config.EventTopic}))
// Create the open OLT adapter
- if a.iAdapter, err = a.startOpenOLT(ctx, a.kip, a.coreProxy, a.adapterProxy, a.eventProxy, a.config.OnuNumber,
+ if a.iAdapter, err = a.startOpenOLT(ctx, a.kip, a.coreProxy, a.adapterProxy, a.eventProxy,
+ a.config.OnuNumber,
a.config.KVStoreHost, a.config.KVStorePort, a.config.KVStoreType); err != nil {
log.Fatal("error-starting-inter-container-proxy")
}
@@ -207,7 +211,9 @@
return kip, nil
}
-func (a *adapter) startOpenOLT(ctx context.Context, kip *kafka.InterContainerProxy, cp *com.CoreProxy, ap *com.AdapterProxy, ep *com.EventProxy, onuNumber int, kvStoreHost string, kvStorePort int, KVStoreType string) (*ac.OpenOLT, error) {
+func (a *adapter) startOpenOLT(ctx context.Context, kip *kafka.InterContainerProxy,
+ cp adapterif.CoreProxy, ap adapterif.AdapterProxy, ep adapterif.EventProxy, onuNumber int, kvStoreHost string,
+ kvStorePort int, KVStoreType string) (*ac.OpenOLT, error) {
log.Info("starting-open-olt")
var err error
sOLT := ac.NewOpenOLT(ctx, a.kip, cp, ap, ep, onuNumber, kvStoreHost, kvStorePort, KVStoreType)
diff --git a/mocks/mockAdapterProxy.go b/mocks/mockAdapterProxy.go
new file mode 100644
index 0000000..a91d361
--- /dev/null
+++ b/mocks/mockAdapterProxy.go
@@ -0,0 +1,47 @@
+/*
+ * 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"
+
+ "github.com/golang/protobuf/proto"
+ "github.com/opencord/voltha-protos/go/inter_container"
+)
+
+// MockAdapterProxy mocks the AdapterProxy interface.
+type MockAdapterProxy struct {
+}
+
+// SendInterAdapterMessage mocks SendInterAdapterMessage function.
+func (ma *MockAdapterProxy) SendInterAdapterMessage(ctx context.Context,
+ msg proto.Message,
+ msgType inter_container.InterAdapterMessageType_Types,
+ fromAdapter string,
+ toAdapter string,
+ 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")
+ }
+ return nil
+}
diff --git a/mocks/mockCoreProxy.go b/mocks/mockCoreProxy.go
new file mode 100644
index 0000000..6abf628
--- /dev/null
+++ b/mocks/mockCoreProxy.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 mocks provides the mocks for openolt-adapter.
+package mocks
+
+import (
+ "context"
+ "errors"
+
+ "github.com/opencord/voltha-go/kafka"
+ "github.com/opencord/voltha-protos/go/voltha"
+)
+
+// MockCoreProxy mocks the CoreProxy interface
+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
+}
+
+// UpdateCoreReference mock updatesCoreReference
+func (mp *MockCoreProxy) UpdateCoreReference(deviceID string, coreReference string) {
+ panic("implement me")
+}
+
+// DeleteCoreReference mock DeleteCoreReference function
+func (mp *MockCoreProxy) DeleteCoreReference(deviceID string) {
+ panic("implement me")
+}
+
+// GetCoreTopic implements mock GetCoreTopic
+func (mp *MockCoreProxy) GetCoreTopic(deviceID string) kafka.Topic {
+ panic("implement me")
+}
+
+// GetAdapterTopic implements mock GetAdapterTopic
+func (mp *MockCoreProxy) GetAdapterTopic(args ...string) kafka.Topic {
+ panic("implement me")
+}
+
+// RegisterAdapter implements mock RegisterAdapter
+func (mp *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")
+}
+
+// PortCreated implements mock PortCreated
+func (mp *MockCoreProxy) PortCreated(ctx context.Context, deviceID string, port *voltha.Port) error {
+ panic("implement me")
+}
+
+// PortsStateUpdate implements mock PortsStateUpdate
+func (mp *MockCoreProxy) PortsStateUpdate(ctx context.Context, deviceID string, operStatus voltha.OperStatus_OperStatus) error {
+ panic("implement me")
+}
+
+// DeleteAllPorts implements mock DeleteAllPorts
+func (mp *MockCoreProxy) DeleteAllPorts(ctx context.Context, deviceID string) error {
+ panic("implement me")
+}
+
+// DeviceStateUpdate implements mock DeviceStateUpdate
+func (mp *MockCoreProxy) DeviceStateUpdate(ctx context.Context, deviceID string,
+ connStatus voltha.ConnectStatus_ConnectStatus, operStatus voltha.OperStatus_OperStatus) error {
+ panic("implement me")
+}
+
+// ChildDeviceDetected implements mock ChildDeviceDetected
+func (mp *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")
+}
+
+// ChildDevicesLost implements mock ChildDevicesLost
+func (mp *MockCoreProxy) ChildDevicesLost(ctx context.Context, parentDeviceID string) error {
+ panic("implement me")
+}
+
+// ChildDevicesDetected implements mock ChildDevicesDetecte
+func (mp *MockCoreProxy) ChildDevicesDetected(ctx context.Context, parentDeviceID string) error {
+ panic("implement me")
+}
+
+// GetDevice implements mock GetDevice
+func (mp *MockCoreProxy) GetDevice(ctx context.Context, parentDeviceID string, deviceID string) (*voltha.Device, error) {
+ if parentDeviceID != "" {
+ return &voltha.Device{}, 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
+ }
+ 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
+ }
+ 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")
+}
diff --git a/vendor/github.com/opencord/voltha-go/adapters/adapterif/adapter_proxy_if.go b/vendor/github.com/opencord/voltha-go/adapters/adapterif/adapter_proxy_if.go
new file mode 100644
index 0000000..26b1448
--- /dev/null
+++ b/vendor/github.com/opencord/voltha-go/adapters/adapterif/adapter_proxy_if.go
@@ -0,0 +1,36 @@
+/*
+ * 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 adapterif
+
+import (
+ "context"
+
+ "github.com/golang/protobuf/proto"
+ ic "github.com/opencord/voltha-protos/go/inter_container"
+)
+
+// AdapterProxy interface for AdapterProxy implementation.
+type AdapterProxy interface {
+ SendInterAdapterMessage(ctx context.Context,
+ msg proto.Message,
+ msgType ic.InterAdapterMessageType_Types,
+ fromAdapter string,
+ toAdapter string,
+ toDeviceID string,
+ proxyDeviceID string,
+ messageID string) error
+}
diff --git a/vendor/github.com/opencord/voltha-go/adapters/adapterif/core_proxy_if.go b/vendor/github.com/opencord/voltha-go/adapters/adapterif/core_proxy_if.go
new file mode 100644
index 0000000..26d021f
--- /dev/null
+++ b/vendor/github.com/opencord/voltha-go/adapters/adapterif/core_proxy_if.go
@@ -0,0 +1,49 @@
+/*
+ * 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 adapterif
+
+import (
+ "context"
+
+ "github.com/opencord/voltha-protos/go/voltha"
+)
+
+// CoreProxy interface for voltha-go coreproxy.
+type CoreProxy interface {
+ UpdateCoreReference(deviceID string, coreReference string)
+ DeleteCoreReference(deviceID string)
+ // getCoreTopic(deviceID string) kafka.Topic
+ //GetAdapterTopic(args ...string) kafka.Topic
+ // getAdapterTopic(args ...string) kafka.Topic
+ RegisterAdapter(ctx context.Context, adapter *voltha.Adapter, deviceTypes *voltha.DeviceTypes) error
+ DeviceUpdate(ctx context.Context, device *voltha.Device) error
+ PortCreated(ctx context.Context, deviceID string, port *voltha.Port) error
+ PortsStateUpdate(ctx context.Context, deviceID string, operStatus voltha.OperStatus_OperStatus) error
+ DeleteAllPorts(ctx context.Context, deviceID string) error
+ DeviceStateUpdate(ctx context.Context, deviceID string,
+ connStatus voltha.ConnectStatus_ConnectStatus, operStatus voltha.OperStatus_OperStatus) error
+
+ ChildDeviceDetected(ctx context.Context, parentDeviceID string, parentPortNo int,
+ childDeviceType string, channelID int, vendorID string, serialNumber string, onuID int64) (*voltha.Device, error)
+
+ ChildDevicesLost(ctx context.Context, parentDeviceID string) error
+ ChildDevicesDetected(ctx context.Context, parentDeviceID string) error
+ GetDevice(ctx context.Context, parentDeviceID string, deviceID string) (*voltha.Device, error)
+ GetChildDevice(ctx context.Context, parentDeviceID string, kwargs map[string]interface{}) (*voltha.Device, error)
+ GetChildDevices(ctx context.Context, parentDeviceID string) (*voltha.Devices, error)
+ SendPacketIn(ctx context.Context, deviceID string, port uint32, pktPayload []byte) error
+}
diff --git a/vendor/github.com/opencord/voltha-go/adapters/adapterif/events_proxy_if.go b/vendor/github.com/opencord/voltha-go/adapters/adapterif/events_proxy_if.go
new file mode 100644
index 0000000..00a86a5
--- /dev/null
+++ b/vendor/github.com/opencord/voltha-go/adapters/adapterif/events_proxy_if.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 adapterif
+
+import (
+ "github.com/opencord/voltha-protos/go/voltha"
+)
+
+// EventProxy interface for eventproxy
+type EventProxy interface {
+ SendDeviceEvent(deviceEvent *voltha.DeviceEvent, category EventCategory,
+ subCategory EventSubCategory, raisedTs int64) error
+}
+
+const (
+ EventTypeVersion = "0.1"
+)
+
+type (
+ EventType = voltha.EventType_EventType
+ EventCategory = voltha.EventCategory_EventCategory
+ EventSubCategory = voltha.EventSubCategory_EventSubCategory
+)
diff --git a/vendor/github.com/opencord/voltha-go/adapters/common/events_proxy.go b/vendor/github.com/opencord/voltha-go/adapters/common/events_proxy.go
index 1f14b3a..34fcde7 100644
--- a/vendor/github.com/opencord/voltha-go/adapters/common/events_proxy.go
+++ b/vendor/github.com/opencord/voltha-go/adapters/common/events_proxy.go
@@ -19,22 +19,14 @@
import (
"errors"
"fmt"
- "github.com/opencord/voltha-go/common/log"
- "github.com/opencord/voltha-go/kafka"
- "github.com/opencord/voltha-protos/go/voltha"
"strconv"
"strings"
"time"
-)
-const (
- EventTypeVersion = "0.1"
-)
-
-type (
- EventType = voltha.EventType_EventType
- EventCategory = voltha.EventCategory_EventCategory
- EventSubCategory = voltha.EventSubCategory_EventSubCategory
+ "github.com/opencord/voltha-go/adapters/adapterif"
+ "github.com/opencord/voltha-go/common/log"
+ "github.com/opencord/voltha-go/kafka"
+ "github.com/opencord/voltha-protos/go/voltha"
)
type EventProxy struct {
@@ -68,7 +60,7 @@
return fmt.Sprintf("Voltha.openolt.%s.%s", eventName, strconv.FormatInt(time.Now().UnixNano(), 10))
}
-func (ep *EventProxy) getEventHeader(eventName string, category EventCategory, subCategory EventSubCategory, eventType EventType, raisedTs int64) *voltha.EventHeader {
+func (ep *EventProxy) getEventHeader(eventName string, category adapterif.EventCategory, subCategory adapterif.EventSubCategory, eventType adapterif.EventType, raisedTs int64) *voltha.EventHeader {
var header voltha.EventHeader
if strings.Contains(eventName, "_") {
eventName = strings.Join(strings.Split(eventName, "_")[:len(strings.Split(eventName, "_"))-2], "_")
@@ -80,14 +72,14 @@
header.Category = category
header.SubCategory = subCategory
header.Type = eventType
- header.TypeVersion = EventTypeVersion
+ header.TypeVersion = adapterif.EventTypeVersion
header.RaisedTs = float32(raisedTs)
header.ReportedTs = float32(time.Now().UnixNano())
return &header
}
/* Send out device events*/
-func (ep *EventProxy) SendDeviceEvent(deviceEvent *voltha.DeviceEvent, category EventCategory, subCategory EventSubCategory, raisedTs int64) error {
+func (ep *EventProxy) SendDeviceEvent(deviceEvent *voltha.DeviceEvent, category adapterif.EventCategory, subCategory adapterif.EventSubCategory, raisedTs int64) error {
if deviceEvent == nil {
log.Error("Recieved empty device event")
return errors.New("Device event nil")
diff --git a/vendor/github.com/opencord/voltha-go/adapters/common/request_handler.go b/vendor/github.com/opencord/voltha-go/adapters/common/request_handler.go
index b18f1d1..55e04d7 100644
--- a/vendor/github.com/opencord/voltha-go/adapters/common/request_handler.go
+++ b/vendor/github.com/opencord/voltha-go/adapters/common/request_handler.go
@@ -20,6 +20,7 @@
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/empty"
"github.com/opencord/voltha-go/adapters"
+ "github.com/opencord/voltha-go/adapters/adapterif"
"github.com/opencord/voltha-go/common/log"
"github.com/opencord/voltha-go/kafka"
ic "github.com/opencord/voltha-protos/go/inter_container"
@@ -33,10 +34,10 @@
TestMode bool
coreInstanceId string
adapter adapters.IAdapter
- coreProxy *CoreProxy
+ coreProxy adapterif.CoreProxy
}
-func NewRequestHandlerProxy(coreInstanceId string, iadapter adapters.IAdapter, cProxy *CoreProxy) *RequestHandlerProxy {
+func NewRequestHandlerProxy(coreInstanceId string, iadapter adapters.IAdapter, cProxy adapterif.CoreProxy) *RequestHandlerProxy {
var proxy RequestHandlerProxy
proxy.coreInstanceId = coreInstanceId
proxy.adapter = iadapter
diff --git a/vendor/github.com/opencord/voltha-go/common/log/log.go b/vendor/github.com/opencord/voltha-go/common/log/log.go
index 33100dc..fe3a4e0 100644
--- a/vendor/github.com/opencord/voltha-go/common/log/log.go
+++ b/vendor/github.com/opencord/voltha-go/common/log/log.go
@@ -286,6 +286,17 @@
return nil
}
+// Return a list of all packages that have individually-configured loggers
+func GetPackageNames() []string {
+ i := 0
+ keys := make([]string, len(loggers))
+ for k := range loggers {
+ keys[i] = k
+ i++
+ }
+ return keys
+}
+
// UpdateLogger deletes the logger associated with a caller's package and creates a new logger with the
// defaultFields. If a calling package is holding on to a Logger reference obtained from AddPackage invocation, then
// that package needs to invoke UpdateLogger if it needs to make changes to the default fields and obtain a new logger
@@ -371,6 +382,11 @@
return 0, errors.New(fmt.Sprintf("unknown-package-%s", name))
}
+//GetDefaultLogLevel gets the log level used for packages that don't have specific loggers
+func GetDefaultLogLevel() int {
+ return levelToInt(cfg.Level.Level())
+}
+
//SetLogLevel sets the log level for the logger corresponding to the caller's package
func SetLogLevel(level int) error {
pkgName, _, _, _ := getCallerInfo()
@@ -382,6 +398,11 @@
return nil
}
+//SetDefaultLogLevel sets the log level used for packages that don't have specific loggers
+func SetDefaultLogLevel(level int) {
+ setLevel(cfg, level)
+}
+
// CleanUp flushed any buffered log entries. Applications should take care to call
// CleanUp before exiting.
func CleanUp() error {