[VOL-2404] : RW-Core changes for handling OLT Reboot Scenario

- When the OLT's connection status goes from REACHABLE to UNREACHABLE
  in ENABLED/DISABLED admin state, delete all the logical ports,
  child devices, logical device and device flows.

- When OLT's connection status becomes reachable again, child devices,
  ports will be re-discovered again. The logical device will be recreated
  again.

- Will not handle the case where OLT goes UNREACHABLE when OLT is disabled
  as part of voltha2.3 release

Change-Id: I34c0c538b44afa19e889e9631f0a738060a58fef
diff --git a/rw_core/core/logical_device_agent.go b/rw_core/core/logical_device_agent.go
index 4e029c8..a6ce9ab 100644
--- a/rw_core/core/logical_device_agent.go
+++ b/rw_core/core/logical_device_agent.go
@@ -529,8 +529,8 @@
 	return err
 }
 
-// deleteAllLogicalPorts deletes all logical ports associated with this device
-func (agent *LogicalDeviceAgent) deleteAllLogicalPorts(ctx context.Context, device *voltha.Device) error {
+// deleteAllLogicalPorts deletes all logical ports associated with this logical device
+func (agent *LogicalDeviceAgent) deleteAllLogicalPorts(ctx context.Context) error {
 	log.Infow("updatePortsState-start", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
 	if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
 		return err
@@ -540,21 +540,13 @@
 	ld := agent.getLogicalDeviceWithoutLock()
 
 	cloned := (proto.Clone(ld)).(*voltha.LogicalDevice)
-	updateLogicalPorts := []*voltha.LogicalPort{}
-	for _, lport := range cloned.Ports {
-		if lport.DeviceId != device.Id {
-			updateLogicalPorts = append(updateLogicalPorts, lport)
-		}
-	}
-	if len(updateLogicalPorts) < len(cloned.Ports) {
-		cloned.Ports = updateLogicalPorts
-		// Updating the logical device will trigger the poprt change events to be populated to the controller
-		if err := agent.updateLogicalDeviceWithoutLock(ctx, cloned); err != nil {
-			log.Warnw("logical-device-update-failed", log.Fields{"ldeviceId": agent.logicalDeviceID, "error": err})
-			return err
-		}
-	} else {
-		log.Debugw("no-change-required", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
+	var updateLogicalPorts []*voltha.LogicalPort
+	// Update an empty ports slice to remove all the ports
+	cloned.Ports = updateLogicalPorts
+
+	if err := agent.updateLogicalDeviceWithoutLock(ctx, cloned); err != nil {
+		log.Warnw("logical-device-update-failed", log.Fields{"ldeviceId": agent.logicalDeviceID, "error": err})
+		return err
 	}
 	return nil
 }