[VOL-5224] - vgc port delete by port name

Change-Id: I6d8b03b93e0b9ac826f437df468753e93104fab0
diff --git a/internal/pkg/controller/auditdevice.go b/internal/pkg/controller/auditdevice.go
index a0c89e4..461f54a 100644
--- a/internal/pkg/controller/auditdevice.go
+++ b/internal/pkg/controller/auditdevice.go
@@ -110,7 +110,7 @@
 		logger.Infow(ctx, "Missing Ports", log.Fields{"Ports": ofpp.OfpPort, "missingPorts": missingPorts})
 	}
 
-	var excessPorts []uint32
+	excessPorts := make(map[uint32]*DevicePort)
 	GetController().SetAuditFlags(ad.device)
 
 	processPortState := func(id uint32, vgcPort *DevicePort) {
@@ -132,7 +132,7 @@
 		} else {
 			// This port is missing from the received list. This is an
 			// excess port at VGC. This must be added to excess ports
-			excessPorts = append(excessPorts, id)
+			excessPorts[id] = vgcPort
 		}
 		logger.Debugw(ctx, "Processed Port State Ind", log.Fields{"Port No": vgcPort.ID, "Port Name": vgcPort.Name})
 	}
@@ -198,13 +198,13 @@
 }
 
 // DelExcessPorts to delete the excess ports
-func (ad *AuditDevice) DelExcessPorts(cntx context.Context, eps []uint32) {
+func (ad *AuditDevice) DelExcessPorts(cntx context.Context, eps map[uint32]*DevicePort) {
 	logger.Debugw(ctx, "Device Audit - Delete Excess Ports", log.Fields{"NumPorts": len(eps)})
-	for _, id := range eps {
+	for portNo, ep := range eps {
 		// Now delete the port from the device @ VGC
-		logger.Debugw(ctx, "Device Audit - Deleting Port", log.Fields{"PortId": id})
-		if err := ad.device.DelPort(cntx, id); err != nil {
-			logger.Warnw(ctx, "DelPort Failed", log.Fields{"PortId": id, "Reason": err})
+		logger.Debugw(ctx, "Device Audit - Deleting Port", log.Fields{"PortId": portNo})
+		if err := ad.device.DelPort(cntx, ep.ID, ep.Name); err != nil {
+			logger.Warnw(ctx, "DelPort Failed", log.Fields{"PortId": portNo, "Reason": err})
 		}
 	}
 }
diff --git a/internal/pkg/controller/auditdevice_test.go b/internal/pkg/controller/auditdevice_test.go
index b2a76ea..a6477e3 100644
--- a/internal/pkg/controller/auditdevice_test.go
+++ b/internal/pkg/controller/auditdevice_test.go
@@ -30,7 +30,7 @@
 func TestAuditDevice_DelExcessPorts(t *testing.T) {
 	type args struct {
 		cntx context.Context
-		eps  []uint32
+		eps  map[uint32]*DevicePort
 	}
 	subFlows := map[uint64]*of.VoltSubFlow{}
 	vltSubFlow := &of.VoltSubFlow{
@@ -58,7 +58,7 @@
 		ID:    256,
 		State: PortStateUp,
 	}
-	eps := []uint32{256}
+	eps := make(map[uint32]*DevicePort)
 	device := &Device{
 		flows:     subFlows,
 		PortsByID: portsByID,
diff --git a/internal/pkg/controller/audittables.go b/internal/pkg/controller/audittables.go
index b4557cd..f422d52 100644
--- a/internal/pkg/controller/audittables.go
+++ b/internal/pkg/controller/audittables.go
@@ -554,7 +554,7 @@
 		missingPorts[ofpp.OfpPort.PortNo] = ofpp.OfpPort
 	}
 
-	var excessPorts []uint32
+	excessPorts := make(map[uint32]*DevicePort)
 	processPortState := func(id uint32, vgcPort *DevicePort) {
 		logger.Debugw(ctx, "Process Port State Ind", log.Fields{"Port No": vgcPort.ID, "Port Name": vgcPort.Name})
 
@@ -569,7 +569,7 @@
 		} else {
 			// This port is missing from the received list. This is an
 			// excess port at VGC. This must be added to excess ports
-			excessPorts = append(excessPorts, id)
+			excessPorts[id] = vgcPort
 		}
 		logger.Debugw(ctx, "Processed Port State Ind", log.Fields{"Port No": vgcPort.ID, "Port Name": vgcPort.Name})
 	}
@@ -631,13 +631,13 @@
 }
 
 // DelExcessPorts to delete the excess ports
-func (att *AuditTablesTask) DelExcessPorts(cntx context.Context, eps []uint32) {
+func (att *AuditTablesTask) DelExcessPorts(cntx context.Context, eps map[uint32]*DevicePort) {
 	logger.Debugw(ctx, "Device Audit - Delete Excess Ports", log.Fields{"NumPorts": len(eps)})
-	for _, id := range eps {
+	for portNo, ep := range eps {
 		// Now delete the port from the device @ VGC
-		logger.Debugw(ctx, "Device Audit - Deleting Port", log.Fields{"PortId": id})
-		if err := att.device.DelPort(cntx, id); err != nil {
-			logger.Warnw(ctx, "DelPort Failed", log.Fields{"PortId": id, "Reason": err})
+		logger.Debugw(ctx, "Device Audit - Deleting Port", log.Fields{"PortId": portNo})
+		if err := att.device.DelPort(cntx, ep.ID, ep.Name); err != nil {
+			logger.Warnw(ctx, "DelPort Failed", log.Fields{"PortId": portNo, "Reason": err})
 		}
 	}
 }
diff --git a/internal/pkg/controller/changeevent.go b/internal/pkg/controller/changeevent.go
index f221d88..fad74a8 100644
--- a/internal/pkg/controller/changeevent.go
+++ b/internal/pkg/controller/changeevent.go
@@ -80,7 +80,7 @@
 				cet.device.ProcessPortState(ctx, portNo, state)
 			}
 		} else if status.PortStatus.Reason == ofp.OfpPortReason_OFPPR_DELETE {
-			if err := cet.device.DelPort(ctx, portNo); err != nil {
+			if err := cet.device.DelPort(ctx, portNo, portName); err != nil {
 				logger.Warnw(ctx, "DelPort Failed", log.Fields{"Port No": portNo, "Error": err})
 			}
 		} else if status.PortStatus.Reason == ofp.OfpPortReason_OFPPR_MODIFY {
diff --git a/internal/pkg/controller/device.go b/internal/pkg/controller/device.go
index 129b935..618afae 100644
--- a/internal/pkg/controller/device.go
+++ b/internal/pkg/controller/device.go
@@ -508,10 +508,15 @@
 
 // DelPort to delete the port as requested by the device/VOLTHA
 // Inform the application if the port is successfully deleted
-func (d *Device) DelPort(cntx context.Context, id uint32) error {
+func (d *Device) DelPort(cntx context.Context, id uint32, portName string) error {
 	p := d.GetPortByID(id)
 	if p == nil {
-		return errors.New("unknown port")
+		p = d.GetPortByName(portName)
+		if p == nil {
+			return errors.New("unknown port")
+		} else {
+			logger.Infow(ctx, "Found port by name", log.Fields{"PortName": p.Name, "PortID": p.ID})
+		}
 	}
 	if p.State == PortStateUp {
 		GetController().PortDownInd(cntx, d.ID, p.Name)