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/test/java/net/onrc/onos/apps/proxyarp/ProxyArpManagerTest.java b/src/test/java/net/onrc/onos/apps/proxyarp/ProxyArpManagerTest.java
index fe64c9e..5976add 100644
--- a/src/test/java/net/onrc/onos/apps/proxyarp/ProxyArpManagerTest.java
+++ b/src/test/java/net/onrc/onos/apps/proxyarp/ProxyArpManagerTest.java
@@ -2,6 +2,7 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.nio.ByteBuffer;
@@ -30,6 +31,8 @@
 import net.onrc.onos.core.topology.Topology;
 import net.onrc.onos.core.topology.Port;
 import net.onrc.onos.core.topology.Switch;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
 
 import org.easymock.EasyMock;
 import org.junit.After;
@@ -67,8 +70,8 @@
     byte[] srcByteMac, dstByteMac;
     MACAddress dstMac, srcMac, cachedMac1, cachedMac2;
     InetAddress srcIp, dstIp, cachedIp1, cachedIp2;
-    Long sw1Dpid;
-    Short sw1Inport, sw1Outport;
+    Dpid sw1Dpid;
+    PortNumber sw1Inport, sw1Outport;
     Short vlanId;
     ARP arpRequest, arpReply, rarpRequest;
     Ethernet ethArpRequest, ethArpReply, ethRarpRequest, ethArpOtherOp;
@@ -113,9 +116,9 @@
         cachedIp1 = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(cachedStrIp1));
         cachedIp2 = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(cachedStrIp2));
 
-        sw1Dpid = 1L;
-        sw1Inport = 1;
-        sw1Outport = 2;
+        sw1Dpid = new Dpid(1L);
+        sw1Inport = new PortNumber((short) 1);
+        sw1Outport = new PortNumber((short) 2);
         vlanId = 1;
 
         //Made tested packets
@@ -223,8 +226,8 @@
     }
 
     private void prepareExpectForGeneral() {
-        EasyMock.expect(inPort1.getNumber()).andReturn((long) sw1Inport).anyTimes();
-        EasyMock.expect(outPort1.getNumber()).andReturn((long) sw1Outport).anyTimes();
+        EasyMock.expect(inPort1.getNumber()).andReturn(sw1Inport).anyTimes();
+        EasyMock.expect(outPort1.getNumber()).andReturn(sw1Outport).anyTimes();
         EasyMock.expect(outPort1.getOutgoingLink()).andReturn(null).anyTimes();
         EasyMock.expect(outPort1.getIncomingLink()).andReturn(null).anyTimes();
         EasyMock.expect(outPort1.getSwitch()).andReturn(sw1).anyTimes();
diff --git a/src/test/java/net/onrc/onos/core/devicemanager/OnosDeviceManagerTest.java b/src/test/java/net/onrc/onos/core/devicemanager/OnosDeviceManagerTest.java
index 22900cc..39e739f 100644
--- a/src/test/java/net/onrc/onos/core/devicemanager/OnosDeviceManagerTest.java
+++ b/src/test/java/net/onrc/onos/core/devicemanager/OnosDeviceManagerTest.java
@@ -32,6 +32,8 @@
 import net.onrc.onos.core.topology.ITopologyListener;
 import net.onrc.onos.core.topology.ITopologyService;
 import net.onrc.onos.core.topology.MockTopology;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
 
 import org.easymock.EasyMock;
 import org.junit.After;
@@ -83,7 +85,7 @@
 
         expect(datagridService.createChannel("onos.device", Long.class, OnosDevice.class))
         .andReturn(eventChannel).once();
-        expect(topology.getOutgoingLink(1L, 100L)).andReturn(null).anyTimes();
+        expect(topology.getOutgoingLink(new Dpid(1L), new PortNumber((short) 100))).andReturn(null).anyTimes();
         expect(datagridService.addListener(
                 eq("onos.device"),
                 anyObject(IEventChannelListener.class),
diff --git a/src/test/java/net/onrc/onos/core/intent/ConstrainedBFSTreeTest.java b/src/test/java/net/onrc/onos/core/intent/ConstrainedBFSTreeTest.java
index 9a3aaa2..b9d2b07 100644
--- a/src/test/java/net/onrc/onos/core/intent/ConstrainedBFSTreeTest.java
+++ b/src/test/java/net/onrc/onos/core/intent/ConstrainedBFSTreeTest.java
@@ -6,6 +6,8 @@
 import net.onrc.onos.core.intent.IntentOperation.Operator;
 import net.onrc.onos.core.topology.LinkEvent;
 import net.onrc.onos.core.topology.MockTopology;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
 
 import org.junit.After;
 import org.junit.Before;
@@ -15,6 +17,19 @@
  * Unit tests for ConstrainedBFSTree class.
  */
 public class ConstrainedBFSTreeTest {
+    private static final Dpid DPID_1 = new Dpid(1L);
+    private static final Dpid DPID_2 = new Dpid(2L);
+    private static final Dpid DPID_3 = new Dpid(3L);
+    private static final Dpid DPID_4 = new Dpid(4L);
+
+    private static final PortNumber PORT_NUMBER_12 = new PortNumber((short) 12);
+    private static final PortNumber PORT_NUMBER_14 = new PortNumber((short) 14);
+    private static final PortNumber PORT_NUMBER_21 = new PortNumber((short) 21);
+    private static final PortNumber PORT_NUMBER_23 = new PortNumber((short) 23);
+    private static final PortNumber PORT_NUMBER_41 = new PortNumber((short) 41);
+    private static final PortNumber PORT_NUMBER_42 = new PortNumber((short) 42);
+    private static final PortNumber PORT_NUMBER_43 = new PortNumber((short) 43);
+
     static final long LOCAL_PORT = 0xFFFEL;
 
     @Before
@@ -29,7 +44,7 @@
     public void testCreate() {
         MockTopology topology = new MockTopology();
         topology.createSampleTopology1();
-        ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(1L));
+        ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(DPID_1));
         assertNotNull(tree);
     }
 
@@ -38,7 +53,7 @@
         MockTopology topology = new MockTopology();
         topology.createSampleTopology1();
         PathIntentMap intents = new PathIntentMap();
-        ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(1L), intents, 1000.0);
+        ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(DPID_1), intents, 1000.0);
         assertNotNull(tree);
     }
 
@@ -46,56 +61,56 @@
     public void testGetPath() {
         MockTopology topology = new MockTopology();
         topology.createSampleTopology1();
-        ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(1L));
-        Path path11 = tree.getPath(topology.getSwitch(1L));
-        Path path12 = tree.getPath(topology.getSwitch(2L));
-        Path path13 = tree.getPath(topology.getSwitch(3L));
-        Path path14 = tree.getPath(topology.getSwitch(4L));
+        ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(DPID_1));
+        Path path11 = tree.getPath(topology.getSwitch(DPID_1));
+        Path path12 = tree.getPath(topology.getSwitch(DPID_2));
+        Path path13 = tree.getPath(topology.getSwitch(DPID_3));
+        Path path14 = tree.getPath(topology.getSwitch(DPID_4));
 
         assertNotNull(path11);
         assertEquals(0, path11.size());
 
         assertNotNull(path12);
         assertEquals(1, path12.size());
-        assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 12L)), path12.get(0));
+        assertEquals(new LinkEvent(topology.getOutgoingLink(DPID_1, PORT_NUMBER_12)), path12.get(0));
 
         assertNotNull(path13);
         assertEquals(2, path13.size());
-        if (path13.get(0).getDst().getDpid() == 2L) {
-            assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 12L)), path13.get(0));
-            assertEquals(new LinkEvent(topology.getOutgoingLink(2L, 23L)), path13.get(1));
+        if (path13.get(0).getDst().getDpid().value() == 2L) {
+            assertEquals(new LinkEvent(topology.getOutgoingLink(DPID_1, PORT_NUMBER_12)), path13.get(0));
+            assertEquals(new LinkEvent(topology.getOutgoingLink(DPID_2, PORT_NUMBER_23)), path13.get(1));
         } else {
-            assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 14L)), path13.get(0));
-            assertEquals(new LinkEvent(topology.getOutgoingLink(4L, 43L)), path13.get(1));
+            assertEquals(new LinkEvent(topology.getOutgoingLink(DPID_1, PORT_NUMBER_14)), path13.get(0));
+            assertEquals(new LinkEvent(topology.getOutgoingLink(DPID_4, PORT_NUMBER_43)), path13.get(1));
         }
 
         assertNotNull(path14);
         assertEquals(1, path14.size());
-        assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 14L)), path14.get(0));
+        assertEquals(new LinkEvent(topology.getOutgoingLink(DPID_1, PORT_NUMBER_14)), path14.get(0));
     }
 
     @Test
     public void testGetPathNull() {
         MockTopology topology = new MockTopology();
         topology.createSampleTopology1();
-        topology.removeLink(1L, 12L, 2L, 21L);
-        topology.removeLink(1L, 14L, 4L, 41L);
+        topology.removeLink(DPID_1, PORT_NUMBER_12, DPID_2, PORT_NUMBER_21);
+        topology.removeLink(DPID_1, PORT_NUMBER_14, DPID_4, PORT_NUMBER_41);
         // now, there is no path from switch 1, but to switch1
 
-        ConstrainedBFSTree tree1 = new ConstrainedBFSTree(topology.getSwitch(1L));
-        Path path12 = tree1.getPath(topology.getSwitch(2L));
-        Path path13 = tree1.getPath(topology.getSwitch(3L));
-        Path path14 = tree1.getPath(topology.getSwitch(4L));
+        ConstrainedBFSTree tree1 = new ConstrainedBFSTree(topology.getSwitch(DPID_1));
+        Path path12 = tree1.getPath(topology.getSwitch(DPID_2));
+        Path path13 = tree1.getPath(topology.getSwitch(DPID_3));
+        Path path14 = tree1.getPath(topology.getSwitch(DPID_4));
 
-        ConstrainedBFSTree tree2 = new ConstrainedBFSTree(topology.getSwitch(2L));
-        Path path21 = tree2.getPath(topology.getSwitch(1L));
+        ConstrainedBFSTree tree2 = new ConstrainedBFSTree(topology.getSwitch(DPID_2));
+        Path path21 = tree2.getPath(topology.getSwitch(DPID_1));
 
         assertNull(path12);
         assertNull(path13);
         assertNull(path14);
         assertNotNull(path21);
         assertEquals(1, path21.size());
-        assertEquals(new LinkEvent(topology.getOutgoingLink(2L, 21L)), path21.get(0));
+        assertEquals(new LinkEvent(topology.getOutgoingLink(DPID_2, PORT_NUMBER_21)), path21.get(0));
     }
 
     @Test
@@ -112,33 +127,33 @@
                 "2", 1L, LOCAL_PORT, 0x333L, 2L, LOCAL_PORT, 0x444L, 600.0);
 
         // calculate path of the intent1
-        ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(1L), intents, 600.0);
-        Path path1 = tree.getPath(topology.getSwitch(2L));
+        ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(DPID_1), intents, 600.0);
+        Path path1 = tree.getPath(topology.getSwitch(DPID_2));
 
         assertNotNull(path1);
         assertEquals(1, path1.size());
-        assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 12L)), path1.get(0));
+        assertEquals(new LinkEvent(topology.getOutgoingLink(DPID_1, PORT_NUMBER_12)), path1.get(0));
 
         PathIntent pathIntent1 = new PathIntent("pi1", path1, 600.0, intent1);
         intentOps.add(Operator.ADD, pathIntent1);
         intents.executeOperations(intentOps);
 
         // calculate path of the intent2
-        tree = new ConstrainedBFSTree(topology.getSwitch(1L), intents, 600.0);
-        Path path2 = tree.getPath(topology.getSwitch(2L));
+        tree = new ConstrainedBFSTree(topology.getSwitch(DPID_1), intents, 600.0);
+        Path path2 = tree.getPath(topology.getSwitch(DPID_2));
 
         assertNotNull(path2);
         assertEquals(2, path2.size());
-        assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 14L)), path2.get(0));
-        assertEquals(new LinkEvent(topology.getOutgoingLink(4L, 42L)), path2.get(1));
+        assertEquals(new LinkEvent(topology.getOutgoingLink(DPID_1, PORT_NUMBER_14)), path2.get(0));
+        assertEquals(new LinkEvent(topology.getOutgoingLink(DPID_4, PORT_NUMBER_42)), path2.get(1));
 
         PathIntent pathIntent2 = new PathIntent("pi2", path2, 600.0, intent2);
         intentOps.add(Operator.ADD, pathIntent2);
         intents.executeOperations(intentOps);
 
         // calculate path of the intent3
-        tree = new ConstrainedBFSTree(topology.getSwitch(1L), intents, 600.0);
-        Path path3 = tree.getPath(topology.getSwitch(2L));
+        tree = new ConstrainedBFSTree(topology.getSwitch(DPID_1), intents, 600.0);
+        Path path3 = tree.getPath(topology.getSwitch(DPID_2));
 
         assertNull(path3);
     }
diff --git a/src/test/java/net/onrc/onos/core/intent/PathIntentMapTest.java b/src/test/java/net/onrc/onos/core/intent/PathIntentMapTest.java
index 2f3cac4..69b0fc2 100644
--- a/src/test/java/net/onrc/onos/core/intent/PathIntentMapTest.java
+++ b/src/test/java/net/onrc/onos/core/intent/PathIntentMapTest.java
@@ -13,6 +13,8 @@
 import net.onrc.onos.core.topology.LinkEvent;
 import net.onrc.onos.core.topology.Port;
 import net.onrc.onos.core.topology.Switch;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
 
 import org.junit.After;
 import org.junit.Before;
@@ -31,10 +33,10 @@
         sw2 = createMock(Switch.class);
         sw3 = createMock(Switch.class);
         sw4 = createMock(Switch.class);
-        expect(sw1.getDpid()).andReturn(1L).anyTimes();
-        expect(sw2.getDpid()).andReturn(2L).anyTimes();
-        expect(sw3.getDpid()).andReturn(3L).anyTimes();
-        expect(sw4.getDpid()).andReturn(4L).anyTimes();
+        expect(sw1.getDpid()).andReturn(new Dpid(1L)).anyTimes();
+        expect(sw2.getDpid()).andReturn(new Dpid(2L)).anyTimes();
+        expect(sw3.getDpid()).andReturn(new Dpid(3L)).anyTimes();
+        expect(sw4.getDpid()).andReturn(new Dpid(4L)).anyTimes();
         replay(sw1);
         replay(sw2);
         replay(sw3);
@@ -46,12 +48,12 @@
         port23 = createMock(Port.class);
         port31 = createMock(Port.class);
         port41 = createMock(Port.class);
-        expect(port11.getNumber()).andReturn(1L).anyTimes();
-        expect(port22.getNumber()).andReturn(2L).anyTimes();
-        expect(port21.getNumber()).andReturn(1L).anyTimes();
-        expect(port23.getNumber()).andReturn(3L).anyTimes();
-        expect(port31.getNumber()).andReturn(1L).anyTimes();
-        expect(port41.getNumber()).andReturn(1L).anyTimes();
+        expect(port11.getNumber()).andReturn(new PortNumber((short) 1)).anyTimes();
+        expect(port22.getNumber()).andReturn(new PortNumber((short) 2)).anyTimes();
+        expect(port21.getNumber()).andReturn(new PortNumber((short) 1)).anyTimes();
+        expect(port23.getNumber()).andReturn(new PortNumber((short) 3)).anyTimes();
+        expect(port31.getNumber()).andReturn(new PortNumber((short) 1)).anyTimes();
+        expect(port41.getNumber()).andReturn(new PortNumber((short) 1)).anyTimes();
         replay(port11);
         replay(port22);
         replay(port21);
diff --git a/src/test/java/net/onrc/onos/core/intent/PathIntentTest.java b/src/test/java/net/onrc/onos/core/intent/PathIntentTest.java
index 43ce79f..1b9e482 100644
--- a/src/test/java/net/onrc/onos/core/intent/PathIntentTest.java
+++ b/src/test/java/net/onrc/onos/core/intent/PathIntentTest.java
@@ -2,6 +2,8 @@
 
 import static org.junit.Assert.assertEquals;
 import net.onrc.onos.core.topology.LinkEvent;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.serializers.KryoFactory;
 
 import org.junit.After;
@@ -16,6 +18,15 @@
  * Unit tests for PathIntent.
  */
 public class PathIntentTest {
+
+    private static final Dpid DPID_1 = new Dpid(1L);
+    private static final Dpid DPID_2 = new Dpid(2L);
+    private static final Dpid DPID_3 = new Dpid(3L);
+    private static final Dpid DPID_4 = new Dpid(4L);
+
+    private static final PortNumber PORT_NUMBER_1 = new PortNumber((short) 1);
+    private static final PortNumber PORT_NUMBER_2 = new PortNumber((short) 2);
+
     @Before
     public void setUp() throws Exception {
     }
@@ -68,20 +79,20 @@
         assertEquals("11", pathIntent2.getId());
         Path path2 = pathIntent2.getPath();
 
-        assertEquals(Long.valueOf(1L), path2.get(0).getSrc().getDpid());
-        assertEquals(Long.valueOf(1L), path2.get(0).getSrc().getNumber());
-        assertEquals(Long.valueOf(2L), path2.get(0).getDst().getDpid());
-        assertEquals(Long.valueOf(2L), path2.get(0).getDst().getNumber());
+        assertEquals(DPID_1, path2.get(0).getSrc().getDpid());
+        assertEquals(PORT_NUMBER_1, path2.get(0).getSrc().getNumber());
+        assertEquals(DPID_2, path2.get(0).getDst().getDpid());
+        assertEquals(PORT_NUMBER_2, path2.get(0).getDst().getNumber());
 
-        assertEquals(Long.valueOf(2L), path2.get(1).getSrc().getDpid());
-        assertEquals(Long.valueOf(1L), path2.get(1).getSrc().getNumber());
-        assertEquals(Long.valueOf(3L), path2.get(1).getDst().getDpid());
-        assertEquals(Long.valueOf(2L), path2.get(1).getDst().getNumber());
+        assertEquals(DPID_2, path2.get(1).getSrc().getDpid());
+        assertEquals(PORT_NUMBER_1, path2.get(1).getSrc().getNumber());
+        assertEquals(DPID_3, path2.get(1).getDst().getDpid());
+        assertEquals(PORT_NUMBER_2, path2.get(1).getDst().getNumber());
 
-        assertEquals(Long.valueOf(3L), path2.get(2).getSrc().getDpid());
-        assertEquals(Long.valueOf(1L), path2.get(2).getSrc().getNumber());
-        assertEquals(Long.valueOf(4L), path2.get(2).getDst().getDpid());
-        assertEquals(Long.valueOf(2L), path2.get(2).getDst().getNumber());
+        assertEquals(DPID_3, path2.get(2).getSrc().getDpid());
+        assertEquals(PORT_NUMBER_1, path2.get(2).getSrc().getNumber());
+        assertEquals(DPID_4, path2.get(2).getDst().getDpid());
+        assertEquals(PORT_NUMBER_2, path2.get(2).getDst().getNumber());
 
         assertEquals(123.45, pathIntent2.getBandwidth(), 0.0);
 
diff --git a/src/test/java/net/onrc/onos/core/topology/MockTopology.java b/src/test/java/net/onrc/onos/core/topology/MockTopology.java
index 888779a..80f309c 100644
--- a/src/test/java/net/onrc/onos/core/topology/MockTopology.java
+++ b/src/test/java/net/onrc/onos/core/topology/MockTopology.java
@@ -1,6 +1,8 @@
 package net.onrc.onos.core.topology;
 
 import net.floodlightcontroller.util.MACAddress;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
 
 /**
  * A mock class of Topology.
@@ -25,8 +27,16 @@
 
     public Link[] addBidirectionalLinks(Long srcDpid, Long srcPortNo, Long dstDpid, Long dstPortNo) {
         Link[] links = new Link[2];
-        links[0] = new LinkImpl(this, getPort(srcDpid, srcPortNo), getPort(dstDpid, dstPortNo));
-        links[1] = new LinkImpl(this, getPort(dstDpid, dstPortNo), getPort(srcDpid, srcPortNo));
+        final Dpid srcDpidObj = new Dpid(srcDpid);
+        final Dpid dstDpidObj = new Dpid(dstDpid);
+        final PortNumber srcPortNum = new PortNumber(srcPortNo.shortValue());
+        final PortNumber dstPortNum = new PortNumber(dstPortNo.shortValue());
+        links[0] = new LinkImpl(this,
+                getPort(srcDpidObj, srcPortNum),
+                getPort(dstDpidObj, dstPortNum));
+        links[1] = new LinkImpl(this,
+                getPort(dstDpidObj, dstPortNum),
+                getPort(srcDpidObj, srcPortNum));
 
         putLink(links[0]);
         putLink(links[1]);
@@ -135,6 +145,14 @@
     }
 
     public void removeLink(Long srcDpid, Long srcPortNo, Long dstDpid, Long dstPortNo) {
-        removeLink(getLink(srcDpid, srcPortNo, dstDpid, dstPortNo));
+        removeLink(getLink(new Dpid(srcDpid),
+                           new PortNumber(srcPortNo.shortValue()),
+                           new Dpid(dstDpid),
+                           new PortNumber(dstPortNo.shortValue())));
+    }
+
+    public void removeLink(Dpid srcDpid, PortNumber srcPortNo,
+                           Dpid dstDpid, PortNumber dstPortNo) {
+        super.removeLink(getLink(srcDpid, srcPortNo, dstDpid, dstPortNo));
     }
 }
diff --git a/src/test/java/net/onrc/onos/core/topology/TopologyImplTest.java b/src/test/java/net/onrc/onos/core/topology/TopologyImplTest.java
index 2501425..cc7ac9c 100644
--- a/src/test/java/net/onrc/onos/core/topology/TopologyImplTest.java
+++ b/src/test/java/net/onrc/onos/core/topology/TopologyImplTest.java
@@ -1,14 +1,13 @@
 package net.onrc.onos.core.topology;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
+import static org.hamcrest.Matchers.*;
 
 import java.util.Iterator;
 
 import net.floodlightcontroller.util.MACAddress;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
 
 import org.junit.After;
 import org.junit.Before;
@@ -26,7 +25,9 @@
     private TopologyImpl testTopology;
     private static final Long SWITCH_HOST_PORT = 1L;
     private static final Long SWITCH_PORT_1 = 2L;
+    private static final PortNumber PORT_NUMBER_1 = new PortNumber(SWITCH_PORT_1.shortValue());
     private static final Long SWITCH_PORT_2 = 3L;
+    private static final PortNumber PORT_NUMBER_2 = new PortNumber(SWITCH_PORT_2.shortValue());
 
     // Set the test network size, it should be larger than 3
     private static final long TEST_SWITCH_NUM = 100L;
@@ -53,12 +54,12 @@
         // Create one bidirectional link b/w two switches to construct a ring topology
         for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) {
             LinkImpl testLinkEast = new LinkImpl(testTopology,
-                    testTopology.getPort(switchID, SWITCH_PORT_2),
-                    testTopology.getPort(switchID % TEST_SWITCH_NUM + 1, SWITCH_PORT_1)
+                    testTopology.getPort(new Dpid(switchID), PORT_NUMBER_2),
+                    testTopology.getPort(new Dpid(switchID % TEST_SWITCH_NUM + 1), PORT_NUMBER_1)
                     );
             LinkImpl testLinkWest = new LinkImpl(testTopology,
-                    testTopology.getPort(switchID % TEST_SWITCH_NUM + 1, SWITCH_PORT_1),
-                    testTopology.getPort(switchID, SWITCH_PORT_2)
+                    testTopology.getPort(new Dpid(switchID % TEST_SWITCH_NUM + 1), PORT_NUMBER_1),
+                    testTopology.getPort(new Dpid(switchID), PORT_NUMBER_2)
                     );
             testTopology.putLink(testLinkEast);
             testTopology.putLink(testLinkWest);
@@ -76,17 +77,18 @@
     @Test
     public void testGetSwitch() {
         // Verify the switch is in the graphDB
-        assertNotNull(testTopology.getSwitch(TEST_SWITCH_NUM - 1));
+        assertNotNull(testTopology.getSwitch(new Dpid(TEST_SWITCH_NUM - 1)));
 
         // Verify there is no such switch in the graphDB
-        assertNull(testTopology.getSwitch(TEST_SWITCH_NUM + 1));
-        long swID = 0;
+        assertNull(testTopology.getSwitch(new Dpid(TEST_SWITCH_NUM + 1)));
         long index = 0;
         Iterator<Switch> itr =  testTopology.getSwitches().iterator();
         while (itr.hasNext()) {
             index++;
-            swID = itr.next().getDpid();
-            assertTrue(swID >= 1 && swID <= TEST_SWITCH_NUM);
+            Dpid swID = itr.next().getDpid();
+            assertThat(swID.value(),
+                    is(both(greaterThanOrEqualTo(1L))
+                       .and(lessThanOrEqualTo(TEST_SWITCH_NUM))));
         }
 
         // Verify the total number of switches
@@ -98,13 +100,14 @@
      */
     @Test
     public void testGetPort() {
+        PortNumber bogusPortNum = new PortNumber((short) (SWITCH_PORT_2 + 1));
         for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) {
             // Verify ports are in the graphDB
-            assertNotNull(testTopology.getSwitch(switchID).getPort(SWITCH_PORT_1));
-            assertNotNull(testTopology.getSwitch(switchID).getPort(SWITCH_PORT_2));
+            assertNotNull(testTopology.getSwitch(new Dpid(switchID)).getPort(PORT_NUMBER_1));
+            assertNotNull(testTopology.getSwitch(new Dpid(switchID)).getPort(PORT_NUMBER_2));
 
             // Verify there is no such port in the graphDB
-            assertNull(testTopology.getSwitch(switchID).getPort(SWITCH_PORT_2 + 1));
+            assertNull(testTopology.getSwitch(new Dpid(switchID)).getPort(bogusPortNum));
         }
     }
 
@@ -113,11 +116,11 @@
      */
     @Test
     public void testGetLink() {
-        long sw1ID = 1L;
-        long sw2ID = 3L;
+        Dpid sw1ID = new Dpid(1L);
+        Dpid sw3ID = new Dpid(3L);
 
         // Verify there is no such link b/w these two switches
-        assertNull((testTopology.getSwitch(sw1ID)).getLinkToNeighbor(sw2ID));
+        assertNull((testTopology.getSwitch(sw1ID)).getLinkToNeighbor(sw3ID));
         long index = 0;
         Iterator<Link> itr = testTopology.getLinks().iterator();
         while (itr.hasNext()) {
@@ -125,11 +128,12 @@
             Link objectLink = itr.next();
             Switch srcSw = (objectLink.getSrcSwitch());
             Switch dstSw = (objectLink.getDstSwitch());
-            if (srcSw.getDpid() < TEST_SWITCH_NUM && dstSw.getDpid() < TEST_SWITCH_NUM) {
-                // Verify the link relationship
-                assertTrue((srcSw.getDpid() == dstSw.getDpid() - 1
-                        || (srcSw.getDpid() == dstSw.getDpid() + 1)));
-            }
+
+            // confirm link is forming a link
+            final long smallerDpid = Math.min(srcSw.getDpid().value(), dstSw.getDpid().value());
+            final long largerDpid = Math.max(srcSw.getDpid().value(), dstSw.getDpid().value());
+            assertThat(largerDpid - smallerDpid,
+                is(either(equalTo(1L)).or(equalTo(TEST_SWITCH_NUM - 1))));
         }
 
         // Verify the total number of links
@@ -141,12 +145,13 @@
      */
     @Test
     public void testGetOutgoingLink() {
+        PortNumber bogusPortNum = new PortNumber((short) (SWITCH_PORT_2 + 1));
         for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) {
-            assertNotNull(testTopology.getOutgoingLink(switchID, SWITCH_PORT_1));
-            assertNotNull(testTopology.getOutgoingLink(switchID, SWITCH_PORT_2));
+            assertNotNull(testTopology.getOutgoingLink(new Dpid(switchID), PORT_NUMBER_1));
+            assertNotNull(testTopology.getOutgoingLink(new Dpid(switchID), PORT_NUMBER_2));
 
             // Verify there is no such link in the graphDB
-            assertNull(testTopology.getOutgoingLink(switchID, SWITCH_PORT_1 + 2));
+            assertNull(testTopology.getOutgoingLink(new Dpid(switchID), bogusPortNum));
         }
     }
 
@@ -155,13 +160,17 @@
      */
     @Test
     public void testGetIncomingLink() {
+        PortNumber bogusPortNum = new PortNumber((short) (SWITCH_PORT_2 + 1));
         for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) {
             // Verify the links are in the graphDB
-            assertNotNull(testTopology.getIncomingLink(switchID, SWITCH_PORT_1));
-            assertNotNull(testTopology.getIncomingLink(switchID, SWITCH_PORT_2));
+            assertNotNull(testTopology.getIncomingLink(
+                                           new Dpid(switchID), PORT_NUMBER_1));
+            assertNotNull(testTopology.getIncomingLink(
+                                           new Dpid(switchID), PORT_NUMBER_2));
 
             // Verify there is no such link in the graphDB
-            assertNull(testTopology.getIncomingLink(switchID, SWITCH_PORT_1 + 2));
+            assertNull(testTopology.getIncomingLink(
+                                        new Dpid(switchID), bogusPortNum));
         }
     }
 
@@ -213,7 +222,8 @@
             testTopology.removeLink(objectLink);
 
             // Verify the link was removed successfully
-            assertNull(testTopology.getLink(srcSw.getDpid(), srcPort.getNumber(),
+            assertNull(testTopology.getLink(
+                    srcSw.getDpid(), srcPort.getNumber(),
                     dstSw.getDpid(), dstPort.getNumber()));
         }
 
@@ -227,14 +237,14 @@
     @Test
     public void testRemoveSwitch() {
         for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) {
-            Iterator<Device> itr = testTopology.getSwitch(switchID).getDevices().iterator();
+            Iterator<Device> itr = testTopology.getSwitch(new Dpid(switchID)).getDevices().iterator();
             while (itr.hasNext()) {
                 testTopology.removeDevice((Device) itr);
             }
             testTopology.removeSwitch(switchID);
 
             // Verify the switch has been removed from the graphDB successfully
-            assertNull(testTopology.getSwitch(switchID));
+            assertNull(testTopology.getSwitch(new Dpid(switchID)));
         }
 
         // Verify all switches have been removed successfully