[VOL-1950] Fixed exception on Disable of Invalid Logical Device port
Change-Id: I3e3aa4cd402de6152cb7f5f0104e2a9feef2bf51
diff --git a/rw_core/core/logical_device_agent.go b/rw_core/core/logical_device_agent.go
index 2c72b6d..c896b44 100644
--- a/rw_core/core/logical_device_agent.go
+++ b/rw_core/core/logical_device_agent.go
@@ -1368,19 +1368,19 @@
}
// enableLogicalPort enables the logical port
-func (agent *LogicalDeviceAgent) enableLogicalPort(lPort *voltha.LogicalPort) error {
+func (agent *LogicalDeviceAgent) enableLogicalPort(lPortId string) error {
agent.lockLogicalDevice.Lock()
defer agent.lockLogicalDevice.Unlock()
// Get the most up to date logical device
var logicaldevice *voltha.LogicalDevice
if logicaldevice, _ = agent.getLogicalDeviceWithoutLock(); logicaldevice == nil {
- log.Debugw("no-logical-device", log.Fields{"logicalDeviceId": agent.logicalDeviceId, "logicalPortId": lPort.Id})
+ log.Debugw("no-logical-device", log.Fields{"logicalDeviceId": agent.logicalDeviceId, "logicalPortId": lPortId})
return nil
}
index := -1
for i, logicalPort := range logicaldevice.Ports {
- if logicalPort.Id == lPort.Id {
+ if logicalPort.Id == lPortId {
index = i
break
}
@@ -1388,25 +1388,25 @@
if index >= 0 {
logicaldevice.Ports[index].OfpPort.Config = logicaldevice.Ports[index].OfpPort.Config & ^uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN)
return agent.updateLogicalDeviceWithoutLock(logicaldevice)
+ } else {
+ return status.Errorf(codes.NotFound, "Port %s on Logical Device %s", lPortId, agent.logicalDeviceId)
}
- //TODO: Trigger subsequent actions on the device
- return nil
}
// disableLogicalPort disabled the logical port
-func (agent *LogicalDeviceAgent) disableLogicalPort(lPort *voltha.LogicalPort) error {
+func (agent *LogicalDeviceAgent) disableLogicalPort(lPortId string) error {
agent.lockLogicalDevice.Lock()
defer agent.lockLogicalDevice.Unlock()
// Get the most up to date logical device
var logicaldevice *voltha.LogicalDevice
if logicaldevice, _ = agent.getLogicalDeviceWithoutLock(); logicaldevice == nil {
- log.Debugw("no-logical-device", log.Fields{"logicalDeviceId": agent.logicalDeviceId, "logicalPortId": lPort.Id})
+ log.Debugw("no-logical-device", log.Fields{"logicalDeviceId": agent.logicalDeviceId, "logicalPortId": lPortId})
return nil
}
index := -1
for i, logicalPort := range logicaldevice.Ports {
- if logicalPort.Id == lPort.Id {
+ if logicalPort.Id == lPortId {
index = i
break
}
@@ -1414,9 +1414,9 @@
if index >= 0 {
logicaldevice.Ports[index].OfpPort.Config = (logicaldevice.Ports[index].OfpPort.Config & ^uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN)) | uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN)
return agent.updateLogicalDeviceWithoutLock(logicaldevice)
+ } else {
+ return status.Errorf(codes.NotFound, "Port %s on Logical Device %s", lPortId, agent.logicalDeviceId)
}
- //TODO: Trigger subsequent actions on the device
- return nil
}
func (agent *LogicalDeviceAgent) getPreCalculatedRoute(ingress, egress uint32) []graph.RouteHop {
diff --git a/rw_core/core/logical_device_manager.go b/rw_core/core/logical_device_manager.go
index ac4a5e2..b3ccd11 100644
--- a/rw_core/core/logical_device_manager.go
+++ b/rw_core/core/logical_device_manager.go
@@ -550,15 +550,9 @@
func (ldMgr *LogicalDeviceManager) enableLogicalPort(ctx context.Context, id *voltha.LogicalPortId, ch chan interface{}) {
log.Debugw("enableLogicalPort", log.Fields{"logicalDeviceId": id})
var res interface{}
- // Get logical port
- var logicalPort *voltha.LogicalPort
- var err error
- if logicalPort, err = ldMgr.getLogicalPort(id); err != nil {
- log.Debugw("no-logical-device-port-present", log.Fields{"logicalPortId": id.PortId})
- res = err
- }
+
if agent := ldMgr.getLogicalDeviceAgent(id.Id); agent != nil {
- res = agent.enableLogicalPort(logicalPort)
+ res = agent.enableLogicalPort(id.PortId)
log.Debugw("enableLogicalPort-result", log.Fields{"result": res})
} else {
res = status.Errorf(codes.NotFound, "%s", id.Id)
@@ -569,15 +563,9 @@
func (ldMgr *LogicalDeviceManager) disableLogicalPort(ctx context.Context, id *voltha.LogicalPortId, ch chan interface{}) {
log.Debugw("disableLogicalPort", log.Fields{"logicalDeviceId": id})
var res interface{}
- // Get logical port
- var logicalPort *voltha.LogicalPort
- var err error
- if logicalPort, err = ldMgr.getLogicalPort(id); err != nil {
- log.Debugw("no-logical-device-port-present", log.Fields{"logicalPortId": id.PortId})
- res = err
- }
+
if agent := ldMgr.getLogicalDeviceAgent(id.Id); agent != nil {
- res = agent.disableLogicalPort(logicalPort)
+ res = agent.disableLogicalPort(id.PortId)
log.Debugw("disableLogicalPort-result", log.Fields{"result": res})
} else {
res = status.Errorf(codes.NotFound, "%s", id.Id)