[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 {