Remove PortEvent.SwitchPort

- JSON format of util.SwitchPort has changed to match PortEvent.SwitchPort.
  (not sure if it was currently used in public API)
- Note: SwitchPort#toString() format is different. Log messages, etc. may have changed.
   PortEvent.SwitchPort : "(dpid@number)" both decimal
   util.SwitchPort : "00:00:...:01/number" dpid as HexString, number as decimal

- Part of ONOS-1564

Change-Id: I19ea06de7a701f0f7aaae0a7ed6f0726c0133a91
diff --git a/src/main/java/net/onrc/onos/core/util/SwitchPort.java b/src/main/java/net/onrc/onos/core/util/SwitchPort.java
index b3ed985..c2079a0 100644
--- a/src/main/java/net/onrc/onos/core/util/SwitchPort.java
+++ b/src/main/java/net/onrc/onos/core/util/SwitchPort.java
@@ -1,19 +1,22 @@
 package net.onrc.onos.core.util;
 
-import org.codehaus.jackson.annotate.JsonProperty;
+import net.onrc.onos.core.util.serializers.SwitchPortSerializer;
+
+import org.codehaus.jackson.map.annotate.JsonSerialize;
 
 /**
  * The class representing a Switch-Port.
  * This class is immutable.
  */
+@JsonSerialize(using = SwitchPortSerializer.class)
 public final class SwitchPort {
     private final Dpid dpid;        // The DPID of the switch
     private final PortNumber port;        // The port of the switch
 
     /**
-     * Default constructor.
+     * Default constructor for Serializer to use.
      */
-    public SwitchPort() {
+    protected SwitchPort() {
         this.dpid = null;
         this.port = null;
     }
@@ -41,26 +44,53 @@
     }
 
     /**
+     * Constructor for the specified primitive values of a DPID and port.
+     *
+     * @param dpid the DPID to use
+     * @param port the port number to use
+     */
+    public SwitchPort(Long dpid, Long port) {
+        this.dpid = new Dpid(dpid);
+        this.port = new PortNumber(port.shortValue());
+    }
+
+    /**
      * Get the DPID value of the Switch-Port.
      *
      * @return the DPID value of the Switch-Port.
      */
-    @JsonProperty("dpid")
     public Dpid dpid() {
         return dpid;
     }
 
     /**
+     * Get the DPID value of the Switch-Port.
+     *
+     * @return the DPID value of the Switch-Port.
+     */
+    public Dpid getDpid() {
+        return dpid;
+    }
+
+    /**
      * Get the port value of the Switch-Port.
      *
      * @return the port value of the Switch-Port.
      */
-    @JsonProperty("port")
     public PortNumber port() {
         return port;
     }
 
     /**
+     * Get the port value of the Switch-Port.
+     *
+     * @return the port value of the Switch-Port.
+     */
+    public PortNumber getNumber() {
+        return port;
+    }
+
+    /**
      * Convert the Switch-Port value to a string.
      * <p/>
      * The string has the following form:
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
index aeb0c33..dc15810 100644
--- a/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
+++ b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
@@ -51,6 +51,7 @@
 import net.onrc.onos.core.util.IPv6Net;
 import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.Switch;
+import net.onrc.onos.core.util.SwitchPort;
 
 import com.esotericsoftware.kryo.Kryo;
 
@@ -184,14 +185,13 @@
         kryo.register(MACAddress.class);
         kryo.register(PortNumber.class);
         kryo.register(Switch.class);
-        // kryo.register(SwitchPort.class);
+        kryo.register(SwitchPort.class);
 
         // New data model-related classes
         kryo.register(DeviceEvent.class);
         kryo.register(LinkedList.class);
         kryo.register(LinkEvent.class);
         kryo.register(PortEvent.class);
-        kryo.register(PortEvent.SwitchPort.class);
         kryo.register(SwitchEvent.class);
         kryo.register(TopologyEvent.class);
 
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/SwitchPortSerializer.java b/src/main/java/net/onrc/onos/core/util/serializers/SwitchPortSerializer.java
new file mode 100644
index 0000000..4ec491b
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/util/serializers/SwitchPortSerializer.java
@@ -0,0 +1,45 @@
+package net.onrc.onos.core.util.serializers;
+
+import net.onrc.onos.core.util.SwitchPort;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.map.SerializerProvider;
+import org.codehaus.jackson.map.ser.std.SerializerBase;
+import java.io.IOException;
+
+/**
+ * JSON Serializer for SwitchPorts.
+ */
+public class SwitchPortSerializer extends SerializerBase<SwitchPort> {
+
+    /**
+     * Public constructor - just calls its super class constructor.
+     */
+    public SwitchPortSerializer() {
+        super(SwitchPort.class);
+    }
+
+    /**
+     * Serializes a SwitchPort object.
+     *
+     * @param switchPort object to serialize
+     * @param jsonGenerator generator to add the serialized object to
+     * @param serializerProvider not used
+     * @throws IOException if the serialization fails
+     */
+    @Override
+    public void serialize(final SwitchPort switchPort,
+                          final JsonGenerator jsonGenerator,
+                          final SerializerProvider serializerProvider)
+            throws IOException {
+        jsonGenerator.writeStartObject();
+
+        jsonGenerator.writeStringField("dpid",
+                                       switchPort.getDpid().toString());
+        jsonGenerator.writeStringField("portNumber",
+                                       switchPort.getNumber().toString());
+
+        jsonGenerator.writeEndObject();
+    }
+
+}