ONOS-539 - Capture port names so CLI can display them

Change-Id: I40b24c401c782a452a66c081623f5bba5ea5c9af
diff --git a/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java b/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java
index 044a1a3..c8c5d47 100644
--- a/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java
+++ b/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java
@@ -56,6 +56,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import com.google.common.base.Strings;
+
 import static org.onosproject.net.DeviceId.deviceId;
 import static org.onosproject.net.Port.Type.COPPER;
 import static org.onosproject.net.Port.Type.FIBER;
@@ -265,6 +267,23 @@
         }
 
         /**
+         * Creates an annotation for the port name if one is available.
+         *
+         * @param port description of the port
+         * @return annotation containing the port name if one is found,
+         *         null otherwise
+         */
+        private SparseAnnotations makePortNameAnnotation(OFPortDesc port) {
+            SparseAnnotations annotations = null;
+            String portName = Strings.emptyToNull(port.getName());
+            if (portName != null) {
+                annotations = DefaultAnnotations.builder()
+                        .set("portName", portName).build();
+            }
+            return annotations;
+        }
+
+        /**
          * Build a portDescription from a given port.
          *
          * @param port the port to build from.
@@ -276,7 +295,9 @@
                     !port.getState().contains(OFPortState.LINK_DOWN) &&
                             !port.getConfig().contains(OFPortConfig.PORT_DOWN);
             Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER;
-            return new DefaultPortDescription(portNo, enabled, type, portSpeed(port));
+            SparseAnnotations annotations = makePortNameAnnotation(port);
+            return new DefaultPortDescription(portNo, enabled, type,
+                                              portSpeed(port), annotations);
         }
 
         private PortDescription buildPortDescription(OFPortStatus status) {
@@ -286,7 +307,9 @@
             } else {
                 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
                 Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER;
-                return new DefaultPortDescription(portNo, false, type, portSpeed(port));
+                SparseAnnotations annotations = makePortNameAnnotation(port);
+                return new DefaultPortDescription(portNo, false, type,
+                                                  portSpeed(port), annotations);
             }
         }