[VOL-1707]
Run golang SCA tools on the golang openolt adapter and fix the errors.
Used golangci-lint tool.
Makefile integrated with new target for running golangci-lint tool.
Change-Id: I8458d75bf4a997d6f93740acf10a03bf43c554c7
diff --git a/adaptercore/device_handler.go b/adaptercore/device_handler.go
index 5fddcf7..de23653 100644
--- a/adaptercore/device_handler.go
+++ b/adaptercore/device_handler.go
@@ -13,6 +13,8 @@
* 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 (
@@ -44,7 +46,7 @@
//DeviceHandler will interact with the OLT device.
type DeviceHandler struct {
- deviceId string
+ deviceID string
deviceType string
adminState string
device *voltha.Device
@@ -60,27 +62,28 @@
resourceMgr *rsrcMgr.OpenOltResourceMgr
discOnus map[string]bool
onus map[string]*OnuDevice
- nniIntfId int
+ nniIntfID int
}
+//OnuDevice represents ONU related info
type OnuDevice struct {
- deviceId string
+ deviceID string
deviceType string
serialNumber string
- onuId uint32
- intfId uint32
- proxyDeviceId string
+ onuID uint32
+ intfID uint32
+ proxyDeviceID string
}
//NewOnuDevice creates a new Onu Device
-func NewOnuDevice(devId string, deviceTp string, serialNum string, onuId uint32, intfId uint32, proxyDevId string) *OnuDevice {
+func NewOnuDevice(devID, deviceTp, serialNum string, onuID, intfID uint32, proxyDevID string) *OnuDevice {
var device OnuDevice
- device.deviceId = devId
+ device.deviceID = devID
device.deviceType = deviceTp
device.serialNumber = serialNum
- device.onuId = onuId
- device.intfId = intfId
- device.proxyDeviceId = proxyDevId
+ device.onuID = onuID
+ device.intfID = intfID
+ device.proxyDeviceID = proxyDevID
return &device
}
@@ -90,7 +93,7 @@
dh.coreProxy = cp
dh.AdapterProxy = ap
cloned := (proto.Clone(device)).(*voltha.Device)
- dh.deviceId = cloned.Id
+ dh.deviceID = cloned.Id
dh.deviceType = cloned.Type
dh.adminState = "up"
dh.device = cloned
@@ -99,10 +102,10 @@
dh.discOnus = make(map[string]bool)
dh.lockDevice = sync.RWMutex{}
dh.onus = make(map[string]*OnuDevice)
- // The nniIntfId is initialized to -1 (invalid) and set to right value
+ // The nniIntfID is initialized to -1 (invalid) and set to right value
// when the first IntfOperInd with status as "up" is received for
// any one of the available NNI port on the OLT device.
- dh.nniIntfId = -1
+ dh.nniIntfID = -1
//TODO initialize the support classes.
return &dh
@@ -140,6 +143,7 @@
return result
}
+//GetportLabel returns the label for the NNI and the PON port based on port number and port type
func GetportLabel(portNum uint32, portType voltha.Port_PortType) string {
if portType == voltha.Port_ETHERNET_NNI {
@@ -153,14 +157,14 @@
return ""
}
-func (dh *DeviceHandler) addPort(intfId uint32, portType voltha.Port_PortType, state string) {
+func (dh *DeviceHandler) addPort(intfID uint32, portType voltha.Port_PortType, state string) {
var operStatus common.OperStatus_OperStatus
if state == "up" {
operStatus = voltha.OperStatus_ACTIVE
} else {
operStatus = voltha.OperStatus_DISCOVERED
}
- portNum := IntfIdToPortNo(intfId, portType)
+ portNum := IntfIDToPortNo(intfID, portType)
label := GetportLabel(portNum, portType)
if len(label) == 0 {
log.Errorw("Invalid-port-label", log.Fields{"portNum": portNum, "portType": portType})
@@ -175,14 +179,14 @@
}
log.Debugw("Sending port update to core", log.Fields{"port": port})
// Synchronous call to update device - this method is run in its own go routine
- if err := dh.coreProxy.PortCreated(nil, dh.device.Id, port); err != nil {
- log.Errorw("error-creating-port", log.Fields{"deviceId": dh.device.Id, "portType": portType, "error": err})
- return
+ if err := dh.coreProxy.PortCreated(context.TODO(), dh.device.Id, port); err != nil {
+ log.Errorw("error-creating-nni-port", log.Fields{"deviceID": dh.device.Id, "portType": portType, "error": err})
}
+
// Once we have successfully added the NNI port to the core, if the
- // locally cached nniIntfId is set to invalid (-1), set it to the right value.
- if portType == voltha.Port_ETHERNET_NNI && dh.nniIntfId == -1 {
- dh.nniIntfId = int(intfId)
+ // locally cached nniIntfID is set to invalid (-1), set it to the right value.
+ if portType == voltha.Port_ETHERNET_NNI && dh.nniIntfID == -1 {
+ dh.nniIntfID = int(intfID)
}
}
@@ -198,11 +202,11 @@
return
}
/* get device state */
- device, err := dh.coreProxy.GetDevice(nil, dh.device.Id, dh.device.Id)
+ device, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, dh.device.Id)
if err != nil || device == nil {
/*TODO: needs to handle error scenarios */
log.Errorw("Failed to fetch device info", log.Fields{"err": err})
-
+ return
}
// When the device is in DISABLED and Adapter container restarts, we need to
// rebuild the locally maintained admin state.
@@ -236,66 +240,74 @@
continue
}
}
- switch indication.Data.(type) {
- case *oop.Indication_OltInd:
- oltInd := indication.GetOltInd()
- if oltInd.OperState == "up" {
- dh.transitionMap.Handle(DeviceUpInd)
- } else if oltInd.OperState == "down" {
- dh.transitionMap.Handle(DeviceDownInd)
- }
- case *oop.Indication_IntfInd:
- intfInd := indication.GetIntfInd()
- go dh.addPort(intfInd.GetIntfId(), voltha.Port_PON_OLT, intfInd.GetOperState())
- log.Infow("Received interface indication ", log.Fields{"InterfaceInd": intfInd})
- case *oop.Indication_IntfOperInd:
- intfOperInd := indication.GetIntfOperInd()
- if intfOperInd.GetType() == "nni" {
- go dh.addPort(intfOperInd.GetIntfId(), voltha.Port_ETHERNET_NNI, intfOperInd.GetOperState())
- } else if intfOperInd.GetType() == "pon" {
- // TODO: Check what needs to be handled here for When PON PORT down, ONU will be down
- // Handle pon port update
- }
- log.Infow("Received interface oper indication ", log.Fields{"InterfaceOperInd": intfOperInd})
- case *oop.Indication_OnuDiscInd:
- onuDiscInd := indication.GetOnuDiscInd()
- log.Infow("Received Onu discovery indication ", log.Fields{"OnuDiscInd": onuDiscInd})
- //onuId,err := dh.resourceMgr.GetONUID(onuDiscInd.GetIntfId())
- //onuId,err := dh.resourceMgr.GetONUID(onuDiscInd.GetIntfId())
- // TODO Get onu ID from the resource manager
- var onuId uint32 = 1
- /*if err != nil{
- log.Errorw("onu-id-unavailable",log.Fields{"intfId":onuDiscInd.GetIntfId()})
- return
- }*/
+ dh.handleIndication(indication)
- sn := dh.stringifySerialNumber(onuDiscInd.SerialNumber)
- go dh.onuDiscIndication(onuDiscInd, onuId, sn)
- case *oop.Indication_OnuInd:
- onuInd := indication.GetOnuInd()
- log.Infow("Received Onu indication ", log.Fields{"OnuInd": onuInd})
- go dh.onuIndication(onuInd)
- case *oop.Indication_OmciInd:
- omciInd := indication.GetOmciInd()
- log.Infow("Received Omci indication ", log.Fields{"OmciInd": omciInd})
- if err := dh.omciIndication(omciInd); err != nil {
- log.Errorw("send-omci-indication-errr", log.Fields{"error": err, "omciInd": omciInd})
- }
- case *oop.Indication_PktInd:
- pktInd := indication.GetPktInd()
- log.Infow("Received pakcet indication ", log.Fields{"PktInd": pktInd})
- go dh.handlePacketIndication(pktInd)
- case *oop.Indication_PortStats:
- portStats := indication.GetPortStats()
- log.Infow("Received port stats indication", log.Fields{"PortStats": portStats})
- case *oop.Indication_FlowStats:
- flowStats := indication.GetFlowStats()
- log.Infow("Received flow stats", log.Fields{"FlowStats": flowStats})
- case *oop.Indication_AlarmInd:
- alarmInd := indication.GetAlarmInd()
- log.Infow("Received alarm indication ", log.Fields{"AlarmInd": alarmInd})
+ }
+}
+
+func (dh *DeviceHandler) handleOltIndication(oltIndication *oop.OltIndication) {
+ if oltIndication.OperState == "up" {
+ dh.transitionMap.Handle(DeviceUpInd)
+ } else if oltIndication.OperState == "down" {
+ dh.transitionMap.Handle(DeviceDownInd)
+ }
+}
+
+func (dh *DeviceHandler) handleIndication(indication *oop.Indication) {
+ switch indication.Data.(type) {
+ case *oop.Indication_OltInd:
+ dh.handleOltIndication(indication.GetOltInd())
+ case *oop.Indication_IntfInd:
+ intfInd := indication.GetIntfInd()
+ go dh.addPort(intfInd.GetIntfId(), voltha.Port_PON_OLT, intfInd.GetOperState())
+ log.Infow("Received interface indication ", log.Fields{"InterfaceInd": intfInd})
+ case *oop.Indication_IntfOperInd:
+ intfOperInd := indication.GetIntfOperInd()
+ if intfOperInd.GetType() == "nni" {
+ go dh.addPort(intfOperInd.GetIntfId(), voltha.Port_ETHERNET_NNI, intfOperInd.GetOperState())
+ } else if intfOperInd.GetType() == "pon" {
+ // TODO: Check what needs to be handled here for When PON PORT down, ONU will be down
+ // Handle pon port update
}
+ log.Infow("Received interface oper indication ", log.Fields{"InterfaceOperInd": intfOperInd})
+ case *oop.Indication_OnuDiscInd:
+ onuDiscInd := indication.GetOnuDiscInd()
+ log.Infow("Received Onu discovery indication ", log.Fields{"OnuDiscInd": onuDiscInd})
+ //onuID,err := dh.resourceMgr.GetONUID(onuDiscInd.GetIntfId())
+ //onuID,err := dh.resourceMgr.GetONUID(onuDiscInd.GetIntfId())
+ // TODO Get onu ID from the resource manager
+ var onuID uint32 = 1
+ /*if err != nil{
+ log.Errorw("onu-id-unavailable",log.Fields{"intfID":onuDiscInd.GetIntfId()})
+ return
+ }*/
+
+ sn := dh.stringifySerialNumber(onuDiscInd.SerialNumber)
+ go dh.onuDiscIndication(onuDiscInd, onuID, sn)
+ case *oop.Indication_OnuInd:
+ onuInd := indication.GetOnuInd()
+ log.Infow("Received Onu indication ", log.Fields{"OnuInd": onuInd})
+ go dh.onuIndication(onuInd)
+ case *oop.Indication_OmciInd:
+ omciInd := indication.GetOmciInd()
+ log.Infow("Received Omci indication ", log.Fields{"OmciInd": omciInd})
+ if err := dh.omciIndication(omciInd); err != nil {
+ log.Errorw("send-omci-indication-errr", log.Fields{"error": err, "omciInd": omciInd})
+ }
+ case *oop.Indication_PktInd:
+ pktInd := indication.GetPktInd()
+ log.Infow("Received pakcet indication ", log.Fields{"PktInd": pktInd})
+ go dh.handlePacketIndication(pktInd)
+ case *oop.Indication_PortStats:
+ portStats := indication.GetPortStats()
+ log.Infow("Received port stats indication", log.Fields{"PortStats": portStats})
+ case *oop.Indication_FlowStats:
+ flowStats := indication.GetFlowStats()
+ log.Infow("Received flow stats", log.Fields{"FlowStats": flowStats})
+ case *oop.Indication_AlarmInd:
+ alarmInd := indication.GetAlarmInd()
+ log.Infow("Received alarm indication ", log.Fields{"AlarmInd": alarmInd})
}
}
@@ -304,7 +316,7 @@
// Synchronous call to update device state - this method is run in its own go routine
if err := dh.coreProxy.DeviceStateUpdate(context.Background(), dh.device.Id, voltha.ConnectStatus_REACHABLE,
voltha.OperStatus_ACTIVE); err != nil {
- log.Errorw("Failed to update device with OLT UP indication", log.Fields{"deviceId": dh.device.Id, "error": err})
+ log.Errorw("Failed to update device with OLT UP indication", log.Fields{"deviceID": dh.device.Id, "error": err})
return err
}
return nil
@@ -314,17 +326,18 @@
func (dh *DeviceHandler) doStateDown() error {
log.Debug("do-state-down-start")
- device, err := dh.coreProxy.GetDevice(nil, dh.device.Id, dh.device.Id)
+ device, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, dh.device.Id)
if err != nil || device == nil {
/*TODO: needs to handle error scenarios */
log.Errorw("Failed to fetch device device", log.Fields{"err": err})
+ return errors.New("failed to fetch device device")
}
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports state on that device to disable
- if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
- log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
- return err
+ if er := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_UNKNOWN); er != nil {
+ log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": er})
+ return er
}
//Update the device oper state and connection status
@@ -332,15 +345,15 @@
cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE
dh.device = cloned
- if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
- log.Errorw("error-updating-device-state", log.Fields{"deviceId": device.Id, "error": err})
- return err
+ if er := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil {
+ log.Errorw("error-updating-device-state", log.Fields{"deviceID": device.Id, "error": er})
+ return er
}
//get the child device for the parent device
- onuDevices, err := dh.coreProxy.GetChildDevices(nil, dh.device.Id)
+ onuDevices, err := dh.coreProxy.GetChildDevices(context.TODO(), dh.device.Id)
if err != nil {
- log.Errorw("failed to get child devices information", log.Fields{"deviceId": dh.device.Id, "error": err})
+ log.Errorw("failed to get child devices information", log.Fields{"deviceID": dh.device.Id, "error": err})
return err
}
for _, onuDevice := range onuDevices.Items {
@@ -348,10 +361,15 @@
// Update onu state as down in onu adapter
onuInd := oop.OnuIndication{}
onuInd.OperState = "down"
- dh.AdapterProxy.SendInterAdapterMessage(nil, &onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
-
+ er := dh.AdapterProxy.SendInterAdapterMessage(context.TODO(), &onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST,
+ "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
+ if er != nil {
+ log.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd,
+ "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id})
+ return er
+ }
}
- log.Debugw("do-state-down-end", log.Fields{"deviceId": device.Id})
+ log.Debugw("do-state-down-end", log.Fields{"deviceID": device.Id})
return nil
}
@@ -360,7 +378,7 @@
var err error
dh.clientCon, err = grpc.Dial(dh.device.GetHostAndPort(), grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
- log.Errorw("Failed to dial device", log.Fields{"DeviceId": dh.deviceId, "HostAndPort": dh.device.GetHostAndPort(), "err": err})
+ log.Errorw("Failed to dial device", log.Fields{"DeviceId": dh.deviceID, "HostAndPort": dh.device.GetHostAndPort(), "err": err})
return err
}
return nil
@@ -380,7 +398,7 @@
// Case where OLT is disabled and then rebooted.
if dh.adminState == "down" {
log.Debugln("do-state-connected--device-admin-state-down")
- device, err := dh.coreProxy.GetDevice(nil, dh.device.Id, dh.device.Id)
+ device, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, dh.device.Id)
if err != nil || device == nil {
/*TODO: needs to handle error scenarios */
log.Errorw("Failed to fetch device device", log.Fields{"err": err})
@@ -390,8 +408,8 @@
cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE
cloned.OperStatus = voltha.OperStatus_UNKNOWN
dh.device = cloned
- if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
- log.Errorw("error-updating-device-state", log.Fields{"deviceId": dh.device.Id, "error": err})
+ if er := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); er != nil {
+ log.Errorw("error-updating-device-state", log.Fields{"deviceID": dh.device.Id, "error": er})
}
// Since the device was disabled before the OLT was rebooted, enfore the OLT to be Disabled after re-connection.
@@ -412,7 +430,7 @@
}
if deviceInfo == nil {
log.Errorw("Device info is nil", log.Fields{})
- return errors.New("Failed to get device info from OLT")
+ return errors.New("failed to get device info from OLT")
}
log.Debugw("Fetched device info", log.Fields{"deviceInfo": deviceInfo})
dh.device.Root = true
@@ -425,33 +443,34 @@
dh.device.MacAddress = "0a:0b:0c:0d:0e:0f"
// Synchronous call to update device - this method is run in its own go routine
- if err := dh.coreProxy.DeviceUpdate(nil, dh.device); err != nil {
- log.Errorw("error-updating-device", log.Fields{"deviceId": dh.device.Id, "error": err})
+ if er := dh.coreProxy.DeviceUpdate(context.TODO(), dh.device); er != nil {
+ log.Errorw("error-updating-device", log.Fields{"deviceID": dh.device.Id, "error": er})
}
- device, err := dh.coreProxy.GetDevice(nil, dh.device.Id, dh.device.Id)
+ device, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, dh.device.Id)
if err != nil || device == nil {
/*TODO: needs to handle error scenarios */
log.Errorw("Failed to fetch device device", log.Fields{"err": err})
+ return err
}
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports (if available) on that device to ACTIVE.
// The ports do not normally exist, unless the device is coming back from a reboot
- if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
- log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ if err := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
+ log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": err})
return err
}
KVStoreHostPort := fmt.Sprintf("%s:%d", dh.openOLT.KVStoreHost, dh.openOLT.KVStorePort)
// Instantiate resource manager
- if dh.resourceMgr = rsrcMgr.NewResourceMgr(dh.deviceId, KVStoreHostPort, dh.openOLT.KVStoreType, dh.deviceType, deviceInfo); dh.resourceMgr == nil {
+ if dh.resourceMgr = rsrcMgr.NewResourceMgr(dh.deviceID, KVStoreHostPort, dh.openOLT.KVStoreType, dh.deviceType, deviceInfo); dh.resourceMgr == nil {
log.Error("Error while instantiating resource manager")
- return errors.New("Instantiating resource manager failed")
+ return errors.New("instantiating resource manager failed")
}
// Instantiate flow manager
if dh.flowMgr = NewFlowManager(dh, dh.resourceMgr); dh.flowMgr == nil {
log.Error("Error while instantiating flow manager")
- return errors.New("Instantiating flow manager failed")
+ return errors.New("instantiating flow manager failed")
}
/* TODO: Instantiate Alarm , stats , BW managers */
@@ -460,14 +479,14 @@
return nil
}
-// AdoptDevice adopts the OLT device
+//AdoptDevice adopts the OLT device
func (dh *DeviceHandler) AdoptDevice(device *voltha.Device) {
dh.transitionMap = NewTransitionMap(dh)
- log.Infow("AdoptDevice", log.Fields{"deviceId": device.Id, "Address": device.GetHostAndPort()})
+ log.Infow("Adopt_device", log.Fields{"deviceID": device.Id, "Address": device.GetHostAndPort()})
dh.transitionMap.Handle(DeviceInit)
}
-// GetOfpDeviceInfo Get the Ofp device information
+//GetOfpDeviceInfo Gets the Ofp information of the given device
func (dh *DeviceHandler) GetOfpDeviceInfo(device *voltha.Device) (*ic.SwitchCapability, error) {
return &ic.SwitchCapability{
Desc: &of.OfpDesc{
@@ -487,18 +506,18 @@
}, nil
}
-// GetOfpPortInfo Get Ofp port information
+//GetOfpPortInfo Get Ofp port information
func (dh *DeviceHandler) GetOfpPortInfo(device *voltha.Device, portNo int64) (*ic.PortCapability, error) {
- cap := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
+ capacity := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
return &ic.PortCapability{
Port: &voltha.LogicalPort{
OfpPort: &of.OfpPort{
HwAddr: macAddressToUint32Array(dh.device.MacAddress),
Config: 0,
State: uint32(of.OfpPortState_OFPPS_LIVE),
- Curr: cap,
- Advertised: cap,
- Peer: cap,
+ Curr: capacity,
+ Advertised: capacity,
+ Peer: capacity,
CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
},
@@ -509,58 +528,60 @@
}
func (dh *DeviceHandler) omciIndication(omciInd *oop.OmciIndication) error {
- log.Debugw("omci indication", log.Fields{"intfId": omciInd.IntfId, "onuId": omciInd.OnuId})
+ log.Debugw("omci indication", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
var deviceType string
- var deviceId string
- var proxyDeviceId string
+ var deviceID string
+ var proxyDeviceID string
onuKey := dh.formOnuKey(omciInd.IntfId, omciInd.OnuId)
if onuInCache, ok := dh.onus[onuKey]; !ok {
- log.Debugw("omci indication for a device not in cache.", log.Fields{"intfId": omciInd.IntfId, "onuId": omciInd.OnuId})
- ponPort := IntfIdToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT)
+ log.Debugw("omci indication for a device not in cache.", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
+ ponPort := IntfIDToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT)
kwargs := make(map[string]interface{})
kwargs["onu_id"] = omciInd.OnuId
kwargs["parent_port_no"] = ponPort
- if onuDevice, err := dh.coreProxy.GetChildDevice(nil, dh.device.Id, kwargs); err != nil {
- log.Errorw("onu not found", log.Fields{"intfId": omciInd.IntfId, "onuId": omciInd.OnuId})
+ onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs)
+ if err != nil {
+ log.Errorw("onu not found", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
return err
- } else {
- deviceType = onuDevice.Type
- deviceId = onuDevice.Id
- proxyDeviceId = onuDevice.ProxyAddress.DeviceId
- //if not exist in cache, then add to cache.
- dh.onus[onuKey] = NewOnuDevice(deviceId, deviceType, onuDevice.SerialNumber, omciInd.OnuId, omciInd.IntfId, proxyDeviceId)
}
+ deviceType = onuDevice.Type
+ deviceID = onuDevice.Id
+ proxyDeviceID = onuDevice.ProxyAddress.DeviceId
+ //if not exist in cache, then add to cache.
+ dh.onus[onuKey] = NewOnuDevice(deviceID, deviceType, onuDevice.SerialNumber, omciInd.OnuId, omciInd.IntfId, proxyDeviceID)
} else {
//found in cache
- log.Debugw("omci indication for a device in cache.", log.Fields{"intfId": omciInd.IntfId, "onuId": omciInd.OnuId})
+ log.Debugw("omci indication for a device in cache.", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
deviceType = onuInCache.deviceType
- deviceId = onuInCache.deviceId
- proxyDeviceId = onuInCache.proxyDeviceId
+ deviceID = onuInCache.deviceID
+ proxyDeviceID = onuInCache.proxyDeviceID
}
omciMsg := &ic.InterAdapterOmciMessage{Message: omciInd.Pkt}
if sendErr := dh.AdapterProxy.SendInterAdapterMessage(context.Background(), omciMsg,
ic.InterAdapterMessageType_OMCI_REQUEST, dh.deviceType, deviceType,
- deviceId, proxyDeviceId, ""); sendErr != nil {
- log.Errorw("send omci request error", log.Fields{"fromAdapter": dh.deviceType, "toAdapter": deviceType, "onuId": deviceId, "proxyDeviceId": proxyDeviceId})
+ deviceID, proxyDeviceID, ""); sendErr != nil {
+ log.Errorw("send omci request error", log.Fields{"fromAdapter": dh.deviceType, "toAdapter": deviceType, "onuID": deviceID, "proxyDeviceID": proxyDeviceID})
return sendErr
}
return nil
}
-// Process_inter_adapter_message process inter adater message
-func (dh *DeviceHandler) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
- log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id})
+//ProcessInterAdapterMessage sends the proxied messages to the target device
+// If the proxy address is not found in the unmarshalled message, it first fetches the onu device for which the message
+// is meant, and then send the unmarshalled omci message to this onu
+func (dh *DeviceHandler) ProcessInterAdapterMessage(msg *ic.InterAdapterMessage) error {
+ log.Debugw("Process_inter_adapter_message", log.Fields{"msgID": msg.Header.Id})
if msg.Header.Type == ic.InterAdapterMessageType_OMCI_REQUEST {
- msgId := msg.Header.Id
+ msgID := msg.Header.Id
fromTopic := msg.Header.FromTopic
toTopic := msg.Header.ToTopic
- toDeviceId := msg.Header.ToDeviceId
- proxyDeviceId := msg.Header.ProxyDeviceId
+ toDeviceID := msg.Header.ToDeviceId
+ proxyDeviceID := msg.Header.ProxyDeviceId
- log.Debugw("omci request message header", log.Fields{"msgId": msgId, "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceId": toDeviceId, "proxyDeviceId": proxyDeviceId})
+ log.Debugw("omci request message header", log.Fields{"msgID": msgID, "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceID": toDeviceID, "proxyDeviceID": proxyDeviceID})
msgBody := msg.GetBody()
@@ -571,15 +592,16 @@
}
if omciMsg.GetProxyAddress() == nil {
- if onuDevice, err := dh.coreProxy.GetDevice(nil, dh.device.Id, toDeviceId); err != nil {
- log.Errorw("onu not found", log.Fields{"onuDeviceId": toDeviceId, "error": err})
+ onuDevice, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, toDeviceID)
+ if err != nil {
+ log.Errorw("onu not found", log.Fields{"onuDeviceId": toDeviceID, "error": err})
return err
- } else {
- log.Debugw("device retrieved from core", log.Fields{"msgId": msgId, "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceId": toDeviceId, "proxyDeviceId": proxyDeviceId})
- dh.sendProxiedMessage(onuDevice, omciMsg)
}
+ log.Debugw("device retrieved from core", log.Fields{"msgID": msgID, "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceID": toDeviceID, "proxyDeviceID": proxyDeviceID})
+ dh.sendProxiedMessage(onuDevice, omciMsg)
+
} else {
- log.Debugw("Proxy Address found in omci message", log.Fields{"msgId": msgId, "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceId": toDeviceId, "proxyDeviceId": proxyDeviceId})
+ log.Debugw("Proxy Address found in omci message", log.Fields{"msgID": msgID, "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceID": toDeviceID, "proxyDeviceID": proxyDeviceID})
dh.sendProxiedMessage(nil, omciMsg)
}
@@ -590,35 +612,39 @@
}
func (dh *DeviceHandler) sendProxiedMessage(onuDevice *voltha.Device, omciMsg *ic.InterAdapterOmciMessage) {
- var intfId uint32
- var onuId uint32
- var status common.ConnectStatus_ConnectStatus
+ var intfID uint32
+ var onuID uint32
+ var connectStatus common.ConnectStatus_ConnectStatus
if onuDevice != nil {
- intfId = onuDevice.ProxyAddress.GetChannelId()
- onuId = onuDevice.ProxyAddress.GetOnuId()
- status = onuDevice.ConnectStatus
+ intfID = onuDevice.ProxyAddress.GetChannelId()
+ onuID = onuDevice.ProxyAddress.GetOnuId()
+ connectStatus = onuDevice.ConnectStatus
} else {
- intfId = omciMsg.GetProxyAddress().GetChannelId()
- onuId = omciMsg.GetProxyAddress().GetOnuId()
- status = omciMsg.GetConnectStatus()
+ intfID = omciMsg.GetProxyAddress().GetChannelId()
+ onuID = omciMsg.GetProxyAddress().GetOnuId()
+ connectStatus = omciMsg.GetConnectStatus()
}
- if status != voltha.ConnectStatus_REACHABLE {
- log.Debugw("ONU is not reachable, cannot send OMCI", log.Fields{"intfId": intfId, "onuId": onuId})
+ if connectStatus != voltha.ConnectStatus_REACHABLE {
+ log.Debugw("ONU is not reachable, cannot send OMCI", log.Fields{"intfID": intfID, "onuID": onuID})
return
}
- omciMessage := &oop.OmciMsg{IntfId: intfId, OnuId: onuId, Pkt: omciMsg.Message}
+ omciMessage := &oop.OmciMsg{IntfId: intfID, OnuId: onuID, Pkt: omciMsg.Message}
- dh.Client.OmciMsgOut(context.Background(), omciMessage)
- log.Debugw("omci-message-sent", log.Fields{"intfId": intfId, "onuId": onuId, "omciMsg": string(omciMsg.GetMessage())})
+ _, err := dh.Client.OmciMsgOut(context.Background(), omciMessage)
+ if err != nil {
+ log.Errorw("unable to send omci-msg-out", log.Fields{"IntfID": intfID, "OnuID": onuID, "Msg": omciMessage})
+ return
+ }
+ log.Debugw("omci-message-sent", log.Fields{"intfID": intfID, "onuID": onuID, "omciMsg": string(omciMsg.GetMessage())})
}
-func (dh *DeviceHandler) activateONU(intfId uint32, onuId int64, serialNum *oop.SerialNumber, serialNumber string) {
- log.Debugw("activate-onu", log.Fields{"intfId": intfId, "onuId": onuId, "serialNum": serialNum, "serialNumber": serialNumber})
- dh.flowMgr.UpdateOnuInfo(intfId, uint32(onuId), serialNumber)
+func (dh *DeviceHandler) activateONU(intfID uint32, onuID int64, serialNum *oop.SerialNumber, serialNumber string) {
+ log.Debugw("activate-onu", log.Fields{"intfID": intfID, "onuID": onuID, "serialNum": serialNum, "serialNumber": serialNumber})
+ dh.flowMgr.UpdateOnuInfo(intfID, uint32(onuID), serialNumber)
// TODO: need resource manager
var pir uint32 = 1000000
- Onu := oop.Onu{IntfId: intfId, OnuId: uint32(onuId), SerialNumber: serialNum, Pir: pir}
+ Onu := oop.Onu{IntfId: intfID, OnuId: uint32(onuID), SerialNumber: serialNum, Pir: pir}
if _, err := dh.Client.ActivateOnu(context.Background(), &Onu); err != nil {
st, _ := status.FromError(err)
if st.Code() == codes.AlreadyExists {
@@ -631,9 +657,9 @@
}
}
-func (dh *DeviceHandler) onuDiscIndication(onuDiscInd *oop.OnuDiscIndication, onuId uint32, sn string) error {
- channelId := onuDiscInd.GetIntfId()
- parentPortNo := IntfIdToPortNo(onuDiscInd.GetIntfId(), voltha.Port_PON_OLT)
+func (dh *DeviceHandler) onuDiscIndication(onuDiscInd *oop.OnuDiscIndication, onuID uint32, sn string) error {
+ channelID := onuDiscInd.GetIntfId()
+ parentPortNo := IntfIDToPortNo(onuDiscInd.GetIntfId(), voltha.Port_PON_OLT)
if _, ok := dh.discOnus[sn]; ok {
log.Debugw("onu-sn-is-already-being-processed", log.Fields{"sn": sn})
return nil
@@ -651,41 +677,49 @@
if sn != "" {
kwargs["serial_number"] = sn
}
- kwargs["onu_id"] = onuId
+ kwargs["onu_id"] = onuID
kwargs["parent_port_no"] = parentPortNo
- onuDevice, err := dh.coreProxy.GetChildDevice(nil, dh.device.Id, kwargs)
- if onuDevice == nil {
- if err := dh.coreProxy.ChildDeviceDetected(nil, dh.device.Id, int(parentPortNo), "brcm_openomci_onu", int(channelId), string(onuDiscInd.SerialNumber.GetVendorId()), sn, int64(onuId)); err != nil {
- log.Errorw("Create onu error", log.Fields{"parent_id": dh.device.Id, "ponPort": onuDiscInd.GetIntfId(), "onuId": onuId, "sn": sn, "error": err})
- return err
+ onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs)
+ if onuDevice == nil || err != nil {
+ if er := dh.coreProxy.ChildDeviceDetected(context.TODO(), dh.device.Id, int(parentPortNo),
+ "brcm_openomci_onu", int(channelID),
+ string(onuDiscInd.SerialNumber.GetVendorId()), sn, int64(onuID)); er != nil {
+ log.Errorw("Create onu error",
+ log.Fields{"parent_id": dh.device.Id, "ponPort": onuDiscInd.GetIntfId(),
+ "onuID": onuID, "sn": sn, "error": er})
+ return er
}
}
- onuDevice, err = dh.coreProxy.GetChildDevice(nil, dh.device.Id, kwargs)
+ onuDevice, err = dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs)
if err != nil {
log.Errorw("failed to get ONU device information", log.Fields{"err": err})
return err
}
- dh.coreProxy.DeviceStateUpdate(nil, onuDevice.Id, common.ConnectStatus_REACHABLE, common.OperStatus_DISCOVERED)
- log.Debugw("onu-discovered-reachable", log.Fields{"deviceId": onuDevice.Id})
+ er := dh.coreProxy.DeviceStateUpdate(context.TODO(), onuDevice.Id, common.ConnectStatus_REACHABLE, common.OperStatus_DISCOVERED)
+ if er != nil {
+ log.Errorw("Unable to update device state", log.Fields{"DeviceID": onuDevice.Id})
+ return er
+ }
+ log.Debugw("onu-discovered-reachable", log.Fields{"deviceID": onuDevice.Id})
for i := 0; i < 10; i++ {
- if onuDevice, _ := dh.coreProxy.GetChildDevice(nil, dh.device.Id, kwargs); onuDevice != nil {
- dh.activateONU(onuDiscInd.IntfId, int64(onuId), onuDiscInd.SerialNumber, sn)
+ onuDevice, _ := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs)
+ if onuDevice != nil {
+ dh.activateONU(onuDiscInd.IntfId, int64(onuID), onuDiscInd.SerialNumber, sn)
return nil
- } else {
- time.Sleep(1 * time.Second)
- log.Debugln("Sleep 1 seconds to active onu, retry times ", i+1)
}
+ time.Sleep(1 * time.Second)
+ log.Debugln("Sleep 1 seconds to active onu, retry times ", i+1)
}
- log.Errorw("Cannot query onu, dont activate it.", log.Fields{"parent_id": dh.device.Id, "ponPort": onuDiscInd.GetIntfId(), "onuId": onuId, "sn": sn})
- return errors.New("Failed to activate onu")
+ log.Errorw("Cannot query onu, dont activate it.", log.Fields{"parent_id": dh.device.Id, "ponPort": onuDiscInd.GetIntfId(), "onuID": onuID, "sn": sn})
+ return errors.New("failed to activate onu")
}
func (dh *DeviceHandler) onuIndication(onuInd *oop.OnuIndication) {
serialNumber := dh.stringifySerialNumber(onuInd.SerialNumber)
kwargs := make(map[string]interface{})
- ponPort := IntfIdToPortNo(onuInd.GetIntfId(), voltha.Port_PON_OLT)
+ ponPort := IntfIDToPortNo(onuInd.GetIntfId(), voltha.Port_PON_OLT)
if serialNumber != "" {
kwargs["serial_number"] = serialNumber
@@ -693,9 +727,9 @@
kwargs["onu_id"] = onuInd.OnuId
kwargs["parent_port_no"] = ponPort
}
- if onuDevice, _ := dh.coreProxy.GetChildDevice(nil, dh.device.Id, kwargs); onuDevice != nil {
+ if onuDevice, _ := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs); onuDevice != nil {
if onuDevice.ParentPortNo != ponPort {
- //log.Warnw("ONU-is-on-a-different-intf-id-now", log.Fields{"previousIntfId": intfIdFromPortNo(onuDevice.ParentPortNo), "currentIntfId": onuInd.GetIntfId()})
+ //log.Warnw("ONU-is-on-a-different-intf-id-now", log.Fields{"previousIntfId": intfIDFromPortNo(onuDevice.ParentPortNo), "currentIntfId": onuInd.GetIntfId()})
log.Warnw("ONU-is-on-a-different-intf-id-now", log.Fields{"previousIntfId": onuDevice.ParentPortNo, "currentIntfId": ponPort})
}
@@ -704,66 +738,98 @@
}
onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.GetOnuId())
dh.onus[onuKey] = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuInd.GetOnuId(), onuInd.GetIntfId(), onuDevice.ProxyAddress.DeviceId)
+ dh.updateOnuAdminState(onuInd)
+ dh.updateOnuStates(onuDevice, onuInd)
- // adminState
- if onuInd.AdminState == "down" {
- if onuInd.OperState != "down" {
- log.Errorw("ONU-admin-state-down-and-oper-status-not-down", log.Fields{"operState": onuInd.OperState})
- // Forcing the oper state change code to execute
- onuInd.OperState = "down"
- }
- // Port and logical port update is taken care of by oper state block
- } else if onuInd.AdminState == "up" {
- log.Debugln("received-onu-admin-state up")
- } else {
- log.Errorw("Invalid-or-not-implemented-admin-state", log.Fields{"received-admin-state": onuInd.AdminState})
- }
- log.Debugln("admin-state-dealt-with")
-
- // operState
- if onuInd.OperState == "down" {
- if onuDevice.ConnectStatus != common.ConnectStatus_UNREACHABLE {
- dh.coreProxy.DeviceStateUpdate(nil, onuDevice.Id, common.ConnectStatus_UNREACHABLE, onuDevice.OperStatus)
- log.Debugln("onu-oper-state-is-down")
- }
- if onuDevice.OperStatus != common.OperStatus_DISCOVERED {
- dh.coreProxy.DeviceStateUpdate(nil, onuDevice.Id, common.ConnectStatus_UNREACHABLE, common.OperStatus_DISCOVERED)
- }
- log.Debugw("inter-adapter-send-onu-ind", log.Fields{"onuIndication": onuInd})
-
- // TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference
- dh.AdapterProxy.SendInterAdapterMessage(nil, onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
- } else if onuInd.OperState == "up" {
- if onuDevice.ConnectStatus != common.ConnectStatus_REACHABLE {
- dh.coreProxy.DeviceStateUpdate(nil, onuDevice.Id, common.ConnectStatus_REACHABLE, onuDevice.OperStatus)
-
- }
- if onuDevice.OperStatus != common.OperStatus_DISCOVERED {
- log.Warnw("ignore onu indication", log.Fields{"intfId": onuInd.IntfId, "onuId": onuInd.OnuId, "operStatus": onuDevice.OperStatus, "msgOperStatus": onuInd.OperState})
- return
- }
- dh.AdapterProxy.SendInterAdapterMessage(nil, onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
- } else {
- log.Warnw("Not-implemented-or-invalid-value-of-oper-state", log.Fields{"operState": onuInd.OperState})
- }
} else {
- log.Errorw("onu not found", log.Fields{"intfId": onuInd.IntfId, "onuId": onuInd.OnuId})
+ log.Errorw("onu not found", log.Fields{"intfID": onuInd.IntfId, "onuID": onuInd.OnuId})
return
}
}
+func (dh *DeviceHandler) updateOnuStates(onuDevice *voltha.Device, onuInd *oop.OnuIndication) {
+ onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.GetOnuId())
+ dh.onus[onuKey] = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuInd.GetOnuId(), onuInd.GetIntfId(), onuDevice.ProxyAddress.DeviceId)
+ dh.updateOnuAdminState(onuInd)
+ // operState
+ if onuInd.OperState == "down" {
+ if onuDevice.ConnectStatus != common.ConnectStatus_UNREACHABLE {
+ err := dh.coreProxy.DeviceStateUpdate(context.TODO(), onuDevice.Id, common.ConnectStatus_UNREACHABLE,
+ onuDevice.OperStatus)
+ if err != nil {
+ log.Errorw("unable to update onu state", log.Fields{"DeviceID": onuDevice.Id})
+ return
+ }
+ log.Debugln("onu-oper-state-is-down")
+ }
+ if onuDevice.OperStatus != common.OperStatus_DISCOVERED {
+ err := dh.coreProxy.DeviceStateUpdate(context.TODO(), onuDevice.Id, common.ConnectStatus_UNREACHABLE,
+ common.OperStatus_DISCOVERED)
+ if err != nil {
+ log.Errorw("unable to update onu state", log.Fields{"DeviceID": onuDevice.Id})
+ return
+ }
+ }
+ log.Debugw("inter-adapter-send-onu-ind", log.Fields{"onuIndication": onuInd})
+
+ // TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference
+ err := dh.AdapterProxy.SendInterAdapterMessage(context.TODO(), onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST,
+ "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
+ if err != nil {
+ log.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd,
+ "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id})
+ }
+ } else if onuInd.OperState == "up" {
+ if onuDevice.ConnectStatus != common.ConnectStatus_REACHABLE {
+ err := dh.coreProxy.DeviceStateUpdate(context.TODO(), onuDevice.Id, common.ConnectStatus_REACHABLE, onuDevice.OperStatus)
+ if err != nil {
+ log.Errorw("unable to update onu state", log.Fields{"DeviceID": onuDevice.Id})
+ return
+ }
+ }
+ if onuDevice.OperStatus != common.OperStatus_DISCOVERED {
+ log.Warnw("ignore onu indication", log.Fields{"intfID": onuInd.IntfId, "onuID": onuInd.OnuId, "operStatus": onuDevice.OperStatus, "msgOperStatus": onuInd.OperState})
+ return
+ }
+ err := dh.AdapterProxy.SendInterAdapterMessage(context.TODO(), onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST,
+ "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
+ if err != nil {
+ log.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd,
+ "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id})
+ return
+ }
+ } else {
+ log.Warnw("Not-implemented-or-invalid-value-of-oper-state", log.Fields{"operState": onuInd.OperState})
+ }
+}
+
+func (dh *DeviceHandler) updateOnuAdminState(onuInd *oop.OnuIndication) {
+ if onuInd.AdminState == "down" {
+ if onuInd.OperState != "down" {
+ log.Errorw("ONU-admin-state-down-and-oper-status-not-down", log.Fields{"operState": onuInd.OperState})
+ // Forcing the oper state change code to execute
+ onuInd.OperState = "down"
+ }
+ // Port and logical port update is taken care of by oper state block
+ } else if onuInd.AdminState == "up" {
+ log.Debugln("received-onu-admin-state up")
+ } else {
+ log.Errorw("Invalid-or-not-implemented-admin-state", log.Fields{"received-admin-state": onuInd.AdminState})
+ }
+ log.Debugln("admin-state-dealt-with")
+}
+
func (dh *DeviceHandler) stringifySerialNumber(serialNum *oop.SerialNumber) string {
if serialNum != nil {
return string(serialNum.VendorId) + dh.stringifyVendorSpecific(serialNum.VendorSpecific)
- } else {
- return ""
}
+ return ""
}
func (dh *DeviceHandler) stringifyVendorSpecific(vendorSpecific []byte) string {
tmp := fmt.Sprintf("%x", (uint32(vendorSpecific[0])>>4)&0x0f) +
- fmt.Sprintf("%x", (uint32(vendorSpecific[0]&0x0f))) +
+ fmt.Sprintf("%x", uint32(vendorSpecific[0]&0x0f)) +
fmt.Sprintf("%x", (uint32(vendorSpecific[1])>>4)&0x0f) +
fmt.Sprintf("%x", (uint32(vendorSpecific[1]))&0x0f) +
fmt.Sprintf("%x", (uint32(vendorSpecific[2])>>4)&0x0f) +
@@ -773,35 +839,41 @@
return tmp
}
-// flows
-func (dh *DeviceHandler) Update_flows_bulk() error {
- return errors.New("UnImplemented")
+//UpdateFlowsBulk upates the bulk flow
+func (dh *DeviceHandler) UpdateFlowsBulk() error {
+ return errors.New("unimplemented")
}
-func (dh *DeviceHandler) GetChildDevice(parentPort uint32, onuId uint32) *voltha.Device {
- log.Debugw("GetChildDevice", log.Fields{"pon port": parentPort, "onuId": onuId})
+
+//GetChildDevice returns the child device for given parent port and onu id
+func (dh *DeviceHandler) GetChildDevice(parentPort, onuID uint32) *voltha.Device {
+ log.Debugw("GetChildDevice", log.Fields{"pon port": parentPort, "onuID": onuID})
kwargs := make(map[string]interface{})
- kwargs["onu_id"] = onuId
+ kwargs["onu_id"] = onuID
kwargs["parent_port_no"] = parentPort
- onuDevice, err := dh.coreProxy.GetChildDevice(nil, dh.device.Id, kwargs)
+ onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs)
if err != nil {
- log.Errorw("onu not found", log.Fields{"intfId": parentPort, "onuId": onuId})
+ log.Errorw("onu not found", log.Fields{"intfID": parentPort, "onuID": onuID})
return nil
}
log.Debugw("Successfully received child device from core", log.Fields{"child_device": *onuDevice})
return onuDevice
}
+// SendPacketInToCore sends packet-in to core
+// For this, it calls SendPacketIn of the core-proxy which uses a device specific topic to send the request.
+// The adapter handling the device creates a device specific topic
func (dh *DeviceHandler) SendPacketInToCore(logicalPort uint32, packetPayload []byte) {
log.Debugw("SendPacketInToCore", log.Fields{"port": logicalPort, "packetPayload": packetPayload})
- if err := dh.coreProxy.SendPacketIn(nil, dh.device.Id, logicalPort, packetPayload); err != nil {
+ if err := dh.coreProxy.SendPacketIn(context.TODO(), dh.device.Id, logicalPort, packetPayload); err != nil {
log.Errorw("Error sending packetin to core", log.Fields{"error": err})
return
}
log.Debug("Sent packet-in to core successfully")
}
+//UpdateFlowsIncrementally updates the device flow
func (dh *DeviceHandler) UpdateFlowsIncrementally(device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges) error {
- log.Debugw("In UpdateFlowsIncrementally", log.Fields{"deviceId": device.Id, "flows": flows, "groups": groups})
+ log.Debugw("In Update_flows_incrementally", log.Fields{"deviceID": device.Id, "flows": flows, "groups": groups})
if flows != nil {
for _, flow := range flows.ToAdd.Items {
log.Debug("Adding flow", log.Fields{"deviceId": device.Id, "flowToAdd": flow})
@@ -812,15 +884,20 @@
dh.flowMgr.RemoveFlow(flow)
}
}
- if groups != nil {
+ if groups != nil && flows != nil {
for _, flow := range flows.ToRemove.Items {
- log.Debug("Removing flow", log.Fields{"deviceId": device.Id, "flowToRemove": flow})
+ log.Debug("Removing flow", log.Fields{"deviceID": device.Id, "flowToRemove": flow})
// dh.flowMgr.RemoveFlow(flow)
}
}
return nil
}
+//DisableDevice disables the given device
+//It marks the following for the given device:
+//Device-Handler Admin-State : down
+//Device Port-State: UNKNOWN
+//Device Oper-State: UNKNOWN
func (dh *DeviceHandler) DisableDevice(device *voltha.Device) error {
if _, err := dh.Client.DisableOlt(context.Background(), new(oop.Empty)); err != nil {
log.Errorw("Failed to disable olt ", log.Fields{"err": err})
@@ -833,8 +910,8 @@
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports state on that device to disable
- if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
- log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ if err := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
+ log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": err})
return err
}
@@ -842,14 +919,19 @@
cloned.OperStatus = voltha.OperStatus_UNKNOWN
dh.device = cloned
- if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
- log.Errorw("error-updating-device-state", log.Fields{"deviceId": device.Id, "error": err})
+ if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+ log.Errorw("error-updating-device-state", log.Fields{"deviceID": device.Id, "error": err})
return err
}
- log.Debugw("DisableDevice-end", log.Fields{"deviceId": device.Id})
+ log.Debugw("Disable_device-end", log.Fields{"deviceID": device.Id})
return nil
}
+//ReenableDevice re-enables the olt device after disable
+//It marks the following for the given device:
+//Device-Handler Admin-State : up
+//Device Port-State: ACTIVE
+//Device Oper-State: ACTIVE
func (dh *DeviceHandler) ReenableDevice(device *voltha.Device) error {
if _, err := dh.Client.ReenableOlt(context.Background(), new(oop.Empty)); err != nil {
log.Errorw("Failed to reenable olt ", log.Fields{"err": err})
@@ -863,8 +945,8 @@
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports state on that device to enable
- if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
- log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ if err := dh.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
+ log.Errorw("updating-ports-failed", log.Fields{"deviceID": device.Id, "error": err})
return err
}
@@ -872,22 +954,23 @@
cloned.OperStatus = voltha.OperStatus_ACTIVE
dh.device = cloned
- if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
- log.Errorw("error-updating-device-state", log.Fields{"deviceId": device.Id, "error": err})
+ if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+ log.Errorw("error-updating-device-state", log.Fields{"deviceID": device.Id, "error": err})
return err
}
- log.Debugw("ReEnableDevice-end", log.Fields{"deviceId": device.Id})
+ log.Debugw("ReEnableDevice-end", log.Fields{"deviceID": device.Id})
return nil
}
+//RebootDevice reboots the given device
func (dh *DeviceHandler) RebootDevice(device *voltha.Device) error {
if _, err := dh.Client.Reboot(context.Background(), new(oop.Empty)); err != nil {
log.Errorw("Failed to reboot olt ", log.Fields{"err": err})
return err
}
- log.Debugw("rebooted-device-successfully", log.Fields{"deviceId": device.Id})
+ log.Debugw("rebooted-device-successfully", log.Fields{"deviceID": device.Id})
return nil
}
@@ -900,15 +983,16 @@
return
}
log.Debugw("sending packet-in to core", log.Fields{"logicalPortNum": logicalPortNum, "packet": *packetIn})
- if err := dh.coreProxy.SendPacketIn(nil, dh.device.Id, logicalPortNum, packetIn.Pkt); err != nil {
+ if err := dh.coreProxy.SendPacketIn(context.TODO(), dh.device.Id, logicalPortNum, packetIn.Pkt); err != nil {
log.Errorw("Error sending packet-in to core", log.Fields{"error": err})
return
}
log.Debug("Success sending packet-in to core!")
}
-func (dh *DeviceHandler) PacketOut(egress_port_no int, packet *of.OfpPacketOut) error {
- log.Debugw("PacketOut", log.Fields{"deviceId": dh.deviceId, "egress_port_no": egress_port_no, "pkt-length": len(packet.Data)})
+// PacketOut sends packet-out from VOLTHA to OLT on the egress port provided
+func (dh *DeviceHandler) PacketOut(egressPortNo int, packet *of.OfpPacketOut) error {
+ log.Debugw("PacketOut", log.Fields{"deviceID": dh.deviceID, "egress_port_no": egressPortNo, "pkt-length": len(packet.Data)})
var etherFrame ethernet.Frame
err := (ðerFrame).UnmarshalBinary(packet.Data)
if err != nil {
@@ -916,7 +1000,7 @@
return err
}
log.Debugw("Ethernet Frame", log.Fields{"Frame": etherFrame})
- egressPortType := IntfIdToPortTypeName(uint32(egress_port_no))
+ egressPortType := IntfIDToPortTypeName(uint32(egressPortNo))
if egressPortType == voltha.Port_ETHERNET_UNI {
if etherFrame.VLAN != nil { // If double tag, remove the outer tag
nextEthType := (uint16(packet.Data[16]) << 8) | uint16(packet.Data[17])
@@ -934,35 +1018,34 @@
log.Debug("Double tagged packet , removed outer vlan", log.Fields{"New frame": etherFrame})
}
}
- intfId := IntfIdFromUniPortNum(uint32(egress_port_no))
- onuId := OnuIdFromPortNum(uint32(egress_port_no))
- uniId := UniIdFromPortNum(uint32(egress_port_no))
- /*gemPortId, err := dh.flowMgr.GetPacketOutGemPortId(intfId, onuId, uint32(egress_port_no))
+ intfID := IntfIDFromUniPortNum(uint32(egressPortNo))
+ onuID := OnuIDFromPortNum(uint32(egressPortNo))
+ uniID := UniIDFromPortNum(uint32(egressPortNo))
+ /*gemPortId, err := dh.flowMgr.GetPacketOutGemPortId(intfID, onuID, uint32(egress_port_no))
if err != nil{
log.Errorw("Error while getting gemport to packet-out",log.Fields{"error": err})
return err
}*/
- onuPkt := oop.OnuPacket{IntfId: intfId, OnuId: onuId, PortNo: uint32(egress_port_no), Pkt: packet.Data}
- log.Debug("sending-packet-to-ONU", log.Fields{"egress_port_no": egress_port_no, "IntfId": intfId, "onuId": onuId,
- "uniId": uniId, "packet": packet.Data})
+ onuPkt := oop.OnuPacket{IntfId: intfID, OnuId: onuID, PortNo: uint32(egressPortNo), Pkt: packet.Data}
+ log.Debug("sending-packet-to-ONU", log.Fields{"egress_port_no": egressPortNo, "IntfId": intfID, "onuID": onuID,
+ "uniID": uniID, "packet": packet.Data})
if _, err := dh.Client.OnuPacketOut(context.Background(), &onuPkt); err != nil {
log.Errorw("Error while sending packet-out to ONU", log.Fields{"error": err})
return err
}
} else if egressPortType == voltha.Port_ETHERNET_NNI {
- uplinkPkt := oop.UplinkPacket{IntfId: IntfIdFromNniPortNum(uint32(egress_port_no)), Pkt: packet.Data}
+ uplinkPkt := oop.UplinkPacket{IntfId: IntfIDFromNniPortNum(uint32(egressPortNo)), Pkt: packet.Data}
log.Debug("sending-packet-to-uplink", log.Fields{"uplink_pkt": uplinkPkt})
if _, err := dh.Client.UplinkPacketOut(context.Background(), &uplinkPkt); err != nil {
log.Errorw("Error while sending packet-out to uplink", log.Fields{"error": err})
return err
}
} else {
- log.Warnw("Packet-out-to-this-interface-type-not-implemented", log.Fields{"egress_port_no": egress_port_no, "egressPortType": egressPortType})
+ log.Warnw("Packet-out-to-this-interface-type-not-implemented", log.Fields{"egress_port_no": egressPortNo, "egressPortType": egressPortType})
}
return nil
}
-func (dh *DeviceHandler) formOnuKey(intfId uint32, onuId uint32) string {
- return ("" + strconv.Itoa(int(intfId)) + "." + strconv.Itoa(int(onuId)))
-
+func (dh *DeviceHandler) formOnuKey(intfID, onuID uint32) string {
+ return "" + strconv.Itoa(int(intfID)) + "." + strconv.Itoa(int(onuID))
}