[SDFAB-295] Inconsistent format of port number in host location

This patch updates fabric.p4 interpreter. Additionally, fixes also
the HostProbingProvider by adding a translation step also there.

Change-Id: I8d1f0f8b6827453e5bdc240ea902960f92ed7e14
diff --git a/providers/hostprobing/src/main/java/org/onosproject/provider/hostprobing/impl/DefaultHostProbingProvider.java b/providers/hostprobing/src/main/java/org/onosproject/provider/hostprobing/impl/DefaultHostProbingProvider.java
index 522ed20..079489e 100644
--- a/providers/hostprobing/src/main/java/org/onosproject/provider/hostprobing/impl/DefaultHostProbingProvider.java
+++ b/providers/hostprobing/src/main/java/org/onosproject/provider/hostprobing/impl/DefaultHostProbingProvider.java
@@ -29,6 +29,8 @@
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.Host;
 import org.onosproject.net.HostLocation;
+import org.onosproject.net.Port;
+import org.onosproject.net.device.DeviceService;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.host.HostProbe;
@@ -84,6 +86,9 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
     private MastershipService mastershipService;
 
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    private DeviceService deviceService;
+
     private HostProviderService providerService;
     private HostProbingProviderService hostProbingProviderService;
     private ExecutorService packetHandler;
@@ -170,16 +175,23 @@
                 case PROBE_FAIL:
                     // Remove this location if this is a verify probe.
                     if (hostProbe.mode() == ProbeMode.VERIFY) {
+                        ConnectPoint oldConnectPoint = hostProbe.connectPoint();
+                        if (!oldConnectPoint.port().hasName()) {
+                            oldConnectPoint = translateSwitchPort(oldConnectPoint);
+                        }
                         providerService.removeLocationFromHost(hostProbe.id(),
-                                new HostLocation(hostProbe.connectPoint(), 0L));
+                                new HostLocation(oldConnectPoint, 0L));
                     }
                     break;
                 case PROBE_COMPLETED:
                     // Add this location if this is a discover probe.
                     if (hostProbe.mode() == ProbeMode.DISCOVER) {
-                        HostLocation newLocation = new HostLocation(hostProbe.connectPoint(),
-                                System.currentTimeMillis());
-                        providerService.addLocationToHost(hostProbe.id(), newLocation);
+                        ConnectPoint newConnectPoint = hostProbe.connectPoint();
+                        if (!newConnectPoint.port().hasName()) {
+                            newConnectPoint = translateSwitchPort(newConnectPoint);
+                        }
+                        providerService.addLocationToHost(hostProbe.id(),
+                                new HostLocation(newConnectPoint, System.currentTimeMillis()));
                     }
                     break;
                 default:
@@ -247,4 +259,14 @@
                 treatment, ByteBuffer.wrap(probe.serialize()));
         packetService.emit(outboundPacket);
     }
+
+    /* Connect point generated from netcfg may not have port name
+       we use the device service as translation service */
+    private ConnectPoint translateSwitchPort(ConnectPoint connectPoint) {
+        Port devicePort = deviceService.getPort(connectPoint);
+        if (devicePort != null) {
+            return new ConnectPoint(connectPoint.deviceId(), devicePort.number());
+        }
+        return connectPoint;
+    }
 }