Topology interface to use Dpid, PortNumber

- Modified Switch interface to use Dpid, PortNumber instead of Long
- Modified Port interface to use Dpid, PortNumber instead of Long
- Modified Topology interface which uses Dpid, PortNumber, SwitchPort

- PortImpl#toString() format has changed: "%d:%d" -> "Dpid#toString():PortNumber#toString"

- Part of ONOS-1564

Change-Id: I8decdbb2fb0cce9e087ad49af3a087b65b8511d7
diff --git a/src/main/java/net/onrc/onos/apps/forwarding/Forwarding.java b/src/main/java/net/onrc/onos/apps/forwarding/Forwarding.java
index 830998c..0a2ed39 100644
--- a/src/main/java/net/onrc/onos/apps/forwarding/Forwarding.java
+++ b/src/main/java/net/onrc/onos/apps/forwarding/Forwarding.java
@@ -262,7 +262,7 @@
         }
 
         packetService.broadcastPacketOutEdge(eth,
-                new SwitchPort(sw.getDpid(), inPort.getNumber().shortValue()));
+                new SwitchPort(sw.getDpid(), inPort.getNumber()));
     }
 
     private void handlePacketIn(Switch sw, Port inPort, Ethernet eth) {
@@ -333,18 +333,17 @@
         }
 
         //This code assumes the device has only one port. It should be problem.
-        net.onrc.onos.core.topology.Port portObject = ports.next();
-        short destinationPort = portObject.getNumber().shortValue();
-        Switch switchObject = portObject.getSwitch();
-        long destinationDpid = switchObject.getDpid();
+        Port destinationPort = ports.next();
+        short destinationPortNum = destinationPort.getNumber().value();
+        Switch destinationSw = destinationPort.getSwitch();
+        long destinationDpid = destinationSw.getDpid().value();
 
-        // TODO eliminate cast
         SwitchPort srcSwitchPort = new SwitchPort(
-                new Dpid(sw.getDpid()),
-                new PortNumber((short) inPort.getNumber().longValue()));
+                sw.getDpid(),
+                inPort.getNumber());
         SwitchPort dstSwitchPort = new SwitchPort(
-                new Dpid(destinationDpid),
-                new PortNumber(destinationPort));
+                destinationSw.getDpid(),
+                destinationPort.getNumber());
 
         MACAddress srcMacAddress = MACAddress.valueOf(eth.getSourceMACAddress());
         MACAddress dstMacAddress = MACAddress.valueOf(eth.getDestinationMACAddress());
@@ -412,7 +411,7 @@
                     net.onrc.onos.core.intent.Path path = pathIntent.getPath();
                     long outPort = -1;
 
-                    if (spfIntent.getDstSwitchDpid() == sw.getDpid()) {
+                    if (spfIntent.getDstSwitchDpid() == sw.getDpid().value()) {
                         log.trace("The packet-in sw dpid {} is on the path.", sw.getDpid());
                         isflowEntryForThisSwitch = true;
                         outPort = spfIntent.getDstPortNumber();
@@ -421,10 +420,10 @@
                     for (Iterator<LinkEvent> i = path.iterator(); i.hasNext();) {
                         LinkEvent le = i.next();
 
-                        if (le.getSrc().dpid.equals(sw.getDpid())) {
+                        if (new Dpid(le.getSrc().dpid).equals(sw.getDpid())) {
                             log.trace("The packet-in sw dpid {} is on the path.", sw.getDpid());
                             isflowEntryForThisSwitch = true;
-                            outPort = le.getSrc().getNumber();
+                            outPort = le.getSrc().getNumber().value();
                             break;
                         }
                     }
@@ -443,21 +442,21 @@
 
                         log.debug("Sending packet out from sw {}, outport{}", sw.getDpid(), outPort);
                         packetService.sendPacket(eth, new SwitchPort(
-                                sw.getDpid(), (short) outPort));
+                                sw.getDpid(), new PortNumber((short) outPort)));
                     }
                 } else {
                     // Flow path has not yet been installed to switches so save the
                     // packet out for later
                     log.trace("Put a packet into the waiting list. flowId {}", existingFlow.intentId);
-                    waitingPackets.put(existingFlow.intentId, new PacketToPush(eth, sw.getDpid()));
+                    waitingPackets.put(existingFlow.intentId, new PacketToPush(eth, sw.getDpid().value()));
                 }
                 return;
             }
 
             String intentId = Long.toString(controllerRegistryService.getNextUniqueId());
             ShortestPathIntent intent = new ShortestPathIntent(intentId,
-                    sw.getDpid(), inPort.getNumber(), srcMacAddress.toLong(),
-                    destinationDpid, destinationPort, dstMacAddress.toLong());
+                    sw.getDpid().value(), inPort.getNumber().value(), srcMacAddress.toLong(),
+                    destinationDpid, destinationPortNum, dstMacAddress.toLong());
 
             intent.setIdleTimeout(idleTimeout + SRC_SWITCH_TIMEOUT_ADJUST_SECOND);
             intent.setFirstSwitchIdleTimeout(idleTimeout);
@@ -467,7 +466,7 @@
                     new Object[]{srcMacAddress, srcSwitchPort, dstMacAddress, dstSwitchPort});
 
              // Add to waiting lists
-            waitingPackets.put(intentId, new PacketToPush(eth, sw.getDpid()));
+            waitingPackets.put(intentId, new PacketToPush(eth, sw.getDpid().value()));
             log.trace("Put a Packet in the wating list. intent ID {}, related pathspec {}", intentId, pathspec);
             pendingFlows.put(pathspec, new PushedFlow(intentId));
             log.trace("Put a Path {} in the pending flow, intent ID {}", pathspec, intentId);
@@ -529,7 +528,7 @@
             outPort = (short) spfIntent.getDstPortNumber();
             log.debug("Path is empty. Maybe devices on the same switch. outPort {}", outPort);
         } else {
-            outPort = graphPath.get(0).getSrc().getNumber().shortValue();
+            outPort = graphPath.get(0).getSrc().getNumber().value();
             log.debug("path{}, outPort {}", graphPath, outPort);
         }
 
diff --git a/src/main/java/net/onrc/onos/apps/proxyarp/ProxyArpManager.java b/src/main/java/net/onrc/onos/apps/proxyarp/ProxyArpManager.java
index 1b3167d..183703c 100644
--- a/src/main/java/net/onrc/onos/apps/proxyarp/ProxyArpManager.java
+++ b/src/main/java/net/onrc/onos/apps/proxyarp/ProxyArpManager.java
@@ -33,6 +33,8 @@
 import net.onrc.onos.core.topology.Port;
 import net.onrc.onos.core.topology.Switch;
 import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.SwitchPort;
 
 import org.openflow.util.HexString;
@@ -372,7 +374,7 @@
             ARP arp = (ARP) eth.getPayload();
             learnArp(arp);
             if (arp.getOpCode() == ARP.OP_REQUEST) {
-                handleArpRequest(sw.getDpid(), inPort.getNumber().shortValue(),
+                handleArpRequest(sw.getDpid().value(), inPort.getNumber().value(),
                         arp, eth);
             } else if (arp.getOpCode() == ARP.OP_REPLY) {
                 // For replies we simply send a notification via Hazelcast
@@ -476,14 +478,14 @@
                         continue;
                     }
 
-                    short outPort = portObject.getNumber().shortValue();
+                    PortNumber outPort = portObject.getNumber();
                     Switch outSwitchObject = portObject.getSwitch();
-                    long outSwitch = outSwitchObject.getDpid();
+                    Dpid outSwitch = outSwitchObject.getDpid();
 
                     if (log.isTraceEnabled()) {
                         log.trace("Probing device {} on port {}/{}",
                                 new Object[]{macAddress,
-                                        HexString.toHexString(outSwitch), outPort});
+                                        outSwitch, outPort});
                     }
 
                     packetService.sendPacket(