[VOL-2573] Delete all logical ports on OLT Delete

Change-Id: Id809e176fe3a902aabea8cbce573fbf9710d9b10
diff --git a/rw_core/core/logical_device_agent.go b/rw_core/core/logical_device_agent.go
index fc9dd92..25a073a 100644
--- a/rw_core/core/logical_device_agent.go
+++ b/rw_core/core/logical_device_agent.go
@@ -519,6 +519,34 @@
 	return nil
 }
 
+// deleteAllUNILogicalPorts deletes all UNI logical ports associated with this parent device
+func (agent *LogicalDeviceAgent) deleteAllUNILogicalPorts(ctx context.Context, parentDevice *voltha.Device) error {
+	log.Debugw("delete-all-uni-logical-ports", log.Fields{"logical-device-id": agent.logicalDeviceID})
+	agent.lockLogicalDevice.Lock()
+	defer agent.lockLogicalDevice.Unlock()
+	// Get the latest logical device info
+	ld := agent.getLogicalDeviceWithoutLock()
+
+	cloned := (proto.Clone(ld)).(*voltha.LogicalDevice)
+	updateLogicalPorts := []*voltha.LogicalPort{}
+	for _, lport := range cloned.Ports {
+		// Save NNI ports only
+		if agent.isNNIPort(lport.DevicePortNo) {
+			updateLogicalPorts = append(updateLogicalPorts, lport)
+		}
+	}
+	if len(updateLogicalPorts) < len(cloned.Ports) {
+		cloned.Ports = updateLogicalPorts
+		// Updating the logical device will trigger the port change events to be populated to the controller
+		if err := agent.updateLogicalDeviceWithoutLock(ctx, cloned); err != nil {
+			return err
+		}
+	} else {
+		log.Debugw("no-change-required", log.Fields{"logical-device-id": agent.logicalDeviceID})
+	}
+	return nil
+}
+
 //updateLogicalDeviceWithoutLock updates the model with the logical device.  It clones the logicaldevice before saving it
 func (agent *LogicalDeviceAgent) updateLogicalDeviceWithoutLock(ctx context.Context, logicalDevice *voltha.LogicalDevice) error {
 	updateCtx := context.WithValue(ctx, model.RequestTimestamp, time.Now().UnixNano())