Cleanup of the Topology-related unit tests.
No functional changes.

 * Split lines that are too long
 * Minor edits of some of the Javadoc comments and other comments
 * Use PortNumber.uint32() to allocate PortNumber objects instead of
   using the old mechanism of (short) casting.
 * Rename: device -> host
 * Reorder the position of some of the tests to match closely
   their position in the tested class TopologyManager
 * Misc other minor cleanups

Change-Id: I72f1a81ded5706bd86095f088afcc86e38c70eeb
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 3cfcb18..6afffb6 100644
--- a/src/test/java/net/onrc/onos/core/topology/MockTopology.java
+++ b/src/test/java/net/onrc/onos/core/topology/MockTopology.java
@@ -8,7 +8,7 @@
 
 /**
  * A mock class of Topology.
- * This class should be used only by test codes.
+ * This class should be used only by test code.
  */
 public class MockTopology extends TopologyImpl {
     // TODO this class doesn't seem like it should extend TopologyImpl. It
@@ -34,11 +34,14 @@
         return this.getPort(port.getSwitchPort());
     }
 
-    public void addBidirectionalLinks(Long srcDpid, Long srcPortNo, Long dstDpid, Long dstPortNo) {
+    public void addBidirectionalLinks(Long srcDpid, Long srcPortNo,
+                                      Long dstDpid, Long dstPortNo) {
         addBidirectionalLinks(srcDpid, srcPortNo, dstDpid, dstPortNo, null);
     }
 
-    public void addBidirectionalLinks(Long srcDpid, Long srcPortNo, Long dstDpid, Long dstPortNo, Double capacity) {
+    public void addBidirectionalLinks(Long srcDpid, Long srcPortNo,
+                                      Long dstDpid, Long dstPortNo,
+                                      Double capacity) {
         LinkEvent[] links = new LinkEvent[2];
         final SwitchPort src = new SwitchPort(srcDpid, srcPortNo);
         final SwitchPort dst = new SwitchPort(dstDpid, dstPortNo);
@@ -54,7 +57,7 @@
     }
 
     /**
-     * create sample topology of 4 switches and 5 bidirectional links.
+     * Creates a sample topology of 4 switches and 5 bidirectional links.
      * <pre>
      * [1] --- [2]
      *  |    /  |
@@ -91,7 +94,7 @@
     }
 
     /**
-     * create sample topology of 4 switches and 5 bidirectional links.
+     * Creates a sample topology of 4 switches and 5 bidirectional links.
      * <pre>
      *
      *
@@ -143,7 +146,8 @@
         addBidirectionalLinks(2L, 24L, 4L, 42L, 1000.0);
     }
 
-    public void removeLink(Long srcDpid, Long srcPortNo, Long dstDpid, Long dstPortNo) {
+    public void removeLink(Long srcDpid, Long srcPortNo, Long dstDpid,
+                           Long dstPortNo) {
         this.removeLink(new Dpid(srcDpid),
                            new PortNumber(srcPortNo.shortValue()),
                            new Dpid(dstDpid),
@@ -151,7 +155,7 @@
     }
 
     public void removeLink(Dpid srcDpid, PortNumber srcPortNo,
-            Dpid dstDpid, PortNumber dstPortNo) {
+                           Dpid dstDpid, PortNumber dstPortNo) {
         this.removeLink(srcDpid, srcPortNo, dstDpid, dstPortNo,
                 TopologyElement.TYPE_PACKET_LAYER);
     }
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 2b6dbab..99a7993 100644
--- a/src/test/java/net/onrc/onos/core/topology/TopologyImplTest.java
+++ b/src/test/java/net/onrc/onos/core/topology/TopologyImplTest.java
@@ -19,18 +19,23 @@
 /**
  * Unit tests for the TopologyImpl Class in the Topology module.
  * These test cases check the sanity of getSwitch/removeSwitch,
- * getLink/removeLink, getDevice/removeDevice, and getPort functions and
- * verify the data objects inside the global graphDB through a injected network.
- * The injected network has a ring topology with a large number of switches (configurable), and
- * each switch is associated with one device and connected to two other switches.
+ * getLink/removeLink, getHost/removeHost, and getPort functions and verify
+ * the data objects inside the global graphDB through a injected network.
+ * The injected network has a ring topology with a large number of switches
+ * (configurable), andeach switch is associated with one host and connected to
+ * two other switches.
  */
 public class TopologyImplTest {
     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());
+    private static final int SWITCH_HOST_PORT = 1;
+    private static final PortNumber PORT_NUMBER_HOST =
+        PortNumber.uint32(SWITCH_HOST_PORT);
+    private static final int SWITCH_PORT_1 = 2;
+    private static final PortNumber PORT_NUMBER_1 =
+        PortNumber.uint32(SWITCH_PORT_1);
+    private static final int SWITCH_PORT_2 = 3;
+    private static final PortNumber PORT_NUMBER_2 =
+        PortNumber.uint32(SWITCH_PORT_2);
 
     // Set the test network size, it should be larger than 3
     private static final long TEST_SWITCH_NUM = 100L;
@@ -48,18 +53,20 @@
             testTopology.putSwitch(testSwitch);
             testTopology.putPort(new PortEvent(dpid, PORT_NUMBER_1));
             testTopology.putPort(new PortEvent(dpid, PORT_NUMBER_2));
-            PortEvent hostPort = new PortEvent(dpid,
-                    new PortNumber(SWITCH_HOST_PORT.shortValue()));
+            PortEvent hostPort = new PortEvent(dpid, PORT_NUMBER_HOST);
             testTopology.putPort(hostPort);
 
             // Create a host for each switch
-            MACAddress devMac = MACAddress.valueOf(switchID);
-            HostEvent testHost = new HostEvent(devMac);
+            MACAddress hostMac = MACAddress.valueOf(switchID);
+            HostEvent testHost = new HostEvent(hostMac);
             testHost.addAttachmentPoint(hostPort.getSwitchPort());
             testTopology.putHost(testHost);
         }
 
-        // Create one bidirectional link b/w two switches to construct a ring topology
+        //
+        // Create one bidirectional link b/w two switches to construct a ring
+        // topology.
+        //
         for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) {
             final Dpid dpidA = new Dpid(switchID);
             final Dpid dpidB = new Dpid(switchID % TEST_SWITCH_NUM + 1);
@@ -110,7 +117,7 @@
      */
     @Test
     public void testGetPort() {
-        PortNumber bogusPortNum = new PortNumber((short) (SWITCH_PORT_2 + 1));
+        PortNumber bogusPortNum = PortNumber.uint32(SWITCH_PORT_2 + 1);
         for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) {
             // Verify ports are in the graphDB
             final Dpid dpid = new Dpid(switchID);
@@ -157,9 +164,11 @@
 
 
 
-            // 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());
+            // Confirm the link is formed properly
+            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))));
         }
@@ -173,7 +182,7 @@
      */
     @Test
     public void testGetOutgoingLink() {
-        PortNumber bogusPortNum = new PortNumber((short) (SWITCH_PORT_2 + 1));
+        PortNumber bogusPortNum = PortNumber.uint32(SWITCH_PORT_2 + 1);
         for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) {
             final Dpid dpid = new Dpid(switchID);
             assertNotNull(testTopology.getOutgoingLink(dpid, PORT_NUMBER_1));
@@ -199,7 +208,7 @@
      */
     @Test
     public void testGetIncomingLink() {
-        PortNumber bogusPortNum = new PortNumber((short) (SWITCH_PORT_2 + 1));
+        PortNumber bogusPortNum = PortNumber.uint32(SWITCH_PORT_2 + 1);
         for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) {
             // Verify the links are in the graphDB
             final Dpid dpid = new Dpid(switchID);
@@ -230,10 +239,10 @@
     @Test
     public void testGetHostByMac() {
         for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) {
-            MACAddress devMac = MACAddress.valueOf(switchID);
+            MACAddress hostMac = MACAddress.valueOf(switchID);
 
-            // Verify the device is in the graphDB
-            assertNotNull(testTopology.getHostByMac(devMac));
+            // Verify the host is in the graphDB
+            assertNotNull(testTopology.getHostByMac(hostMac));
         }
     }
 
@@ -242,14 +251,14 @@
      */
     @Test
     public void testRemoveHost() {
-        int devCount = 0;
+        int hostCount = 0;
         Iterator<Host> itr = testTopology.getHosts().iterator();
         while (itr.hasNext()) {
-            Host currDev = itr.next();
-            final MACAddress mac = currDev.getMacAddress();
+            Host currHost = itr.next();
+            final MACAddress mac = currHost.getMacAddress();
             testTopology.removeHost(mac);
             assertNull(testTopology.getHostByMac(mac));
-            devCount++;
+            hostCount++;
         }
         for (Switch sw : testTopology.getSwitches()) {
             for (Port port : sw.getPorts()) {
@@ -258,7 +267,7 @@
         }
 
         // Verify all hosts have been removed successfully
-        assertEquals(TEST_HOST_NUM, devCount);
+        assertEquals(TEST_HOST_NUM, hostCount);
     }
 
     /**
@@ -295,7 +304,8 @@
     public void testRemoveSwitch() {
         for (long switchID = 1; switchID <= TEST_SWITCH_NUM; switchID++) {
             final Dpid dpid = new Dpid(switchID);
-            Iterator<Host> itr = testTopology.getSwitch(dpid).getHosts().iterator();
+            Iterator<Host> itr =
+                testTopology.getSwitch(dpid).getHosts().iterator();
             while (itr.hasNext()) {
                 testTopology.removeHost(itr.next().getMacAddress());
             }
diff --git a/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java b/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java
index f7fe753..c99768b 100644
--- a/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java
+++ b/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java
@@ -38,8 +38,10 @@
 /**
  * Unit tests for the TopologyManager class in the Topology module.
  * These test cases only check the sanity of functions in the TopologyManager.
- * Note that we do not test the eventHandler functions in the TopologyManager class.
- * DatagridService, DataStoreService, eventChannel, and controllerRegistryService are mocked out.
+ * Note that we do not test the eventHandler functions in the TopologyManager
+ * class.
+ * DatagridService, DataStoreService, eventChannel, and
+ * controllerRegistryService are mocked out.
  */
 public class TopologyManagerTest extends UnitTest {
     private TopologyManager theTopologyManager;
@@ -50,7 +52,8 @@
     private IControllerRegistryService registryService;
     private CopyOnWriteArrayList<ITopologyListener> topologyListeners;
     private Collection<TopologyEvent> allTopologyEvents;
-    private OnosInstanceId onosInstanceId = new OnosInstanceId("ONOS-Test-Instance-ID");
+    private OnosInstanceId onosInstanceId =
+        new OnosInstanceId("ONOS-Test-Instance-ID");
 
     @SuppressWarnings("unchecked")
     @Before
@@ -120,158 +123,29 @@
     }
 
     private void setupTopologyManager() {
-        // Create a topologyManager object for testing
+        // Create a TopologyManager object for testing
         topologyListeners = new CopyOnWriteArrayList<>();
-        theTopologyManager = new TopologyManager(registryService, topologyListeners);
+        theTopologyManager = new TopologyManager(registryService,
+                                                 topologyListeners);
 
-        // replace EventHandler to avoid thread from starting
+        // Replace the eventHandler to prevent the thread from starting
         TestUtils.setField(theTopologyManager, "eventHandler",
             EasyMock.createNiceMock(TopologyManager.EventHandler.class));
         theTopologyManager.startup(datagridService);
 
-        // replace data store with Mocked object
+        // Replace the data store with a mocked object
         TestUtils.setField(theTopologyManager, "datastore", dataStoreService);
     }
 
     /**
-     * Test the Switch discovered and Port discovered functions.
-     */
-    @Test
-    public void testPutSwitchAndPortDiscoveryEvent() {
-        // Mock the eventChannel functions first
-        eventChannel.addEntry(anyObject(byte[].class),
-                anyObject(TopologyEvent.class));
-        EasyMock.expectLastCall().times(3, 3); // (1 switch + 1 port), 1 port
-        replay(eventChannel);
-
-        setupTopologyManager();
-
-        // mockSwitch has one port
-        Dpid swDPId = new Dpid(100L);
-        PortNumber portId = new PortNumber((short) 1);
-
-        // Generate a new switch event along with a port event
-        SwitchEvent switchEvent = new SwitchEvent(swDPId);
-
-        Collection<PortEvent> portEvents = new ArrayList<PortEvent>();
-        portEvents.add(new PortEvent(swDPId, portId));
-
-        // Call the topologyManager function for adding a switch
-        theTopologyManager.putSwitchDiscoveryEvent(switchEvent, portEvents);
-
-        for (PortEvent portEvent : portEvents) {
-            // Call the topologyManager function for adding a port
-            theTopologyManager.putPortDiscoveryEvent(portEvent);
-        }
-
-        // Verify the function calls
-        verify(eventChannel);
-
-    }
-
-    /**
-     * Test the switch and port removed functions.
-     */
-    @Test
-    public void testRemoveSwitchAndPortDiscoveryEvent() {
-        // Mock the eventChannel functions first
-        eventChannel.removeEntry(anyObject(byte[].class));
-        EasyMock.expectLastCall().times(2, 2); //1 switch, 1 port
-        replay(eventChannel);
-
-        setupTopologyManager();
-
-        Dpid swDPId = new Dpid(100L);
-        PortNumber portId = new PortNumber((short) 1);
-
-        // Generate a port event
-        Collection<PortEvent> portEvents = new ArrayList<PortEvent>();
-        portEvents.add(new PortEvent(swDPId, portId));
-
-        // Call the topologyManager function for removing a port
-        for (PortEvent portEvent : portEvents) {
-            theTopologyManager.removePortDiscoveryEvent(portEvent);
-        }
-
-        // Call the topologyManager function for removing a switch
-        SwitchEvent switchEvent = new SwitchEvent(swDPId);
-        theTopologyManager.removeSwitchDiscoveryEvent(switchEvent);
-
-        // Verify the function calls
-        verify(eventChannel);
-
-    }
-
-    /**
-     * Test the device discovered function.
-     */
-    @Test
-    public void testPutDeviceDiscoveryEvent() {
-        // Mock the eventChannel functions first
-        eventChannel.addEntry(anyObject(byte[].class),
-                anyObject(TopologyEvent.class));
-        EasyMock.expectLastCall().times(1, 1); // 1 device
-        replay(eventChannel);
-
-        setupTopologyManager();
-
-        long swDPId = 100L;
-        long portId = 1L;
-
-        // Generate a new device event
-        MACAddress devMac = MACAddress.valueOf("00:AA:11:BB:33:CC");
-        SwitchPort sp = new SwitchPort(swDPId, portId);
-        List<SwitchPort> spLists = new ArrayList<SwitchPort>();
-        spLists.add(sp);
-        HostEvent hostEvent = new HostEvent(devMac);
-        hostEvent.setAttachmentPoints(spLists);
-
-        // Call the topologyManager function for adding a device
-        theTopologyManager.putHostDiscoveryEvent(hostEvent);
-
-        // Verify the function calls
-        verify(eventChannel);
-    }
-
-    /**
-     * Test the device removed function.
-     */
-    @Test
-    public void testRemoveDeviceDiscoveryEvent() {
-        // Mock the eventChannel functions first
-        eventChannel.removeEntry(anyObject(byte[].class));
-        EasyMock.expectLastCall().times(1, 1); // 1 device
-        replay(eventChannel);
-
-        setupTopologyManager();
-
-        long swDPId = 100L;
-        long portId = 1L;
-
-        // Generate a new device event
-        MACAddress devMac = MACAddress.valueOf("00:AA:11:BB:33:CC");
-        SwitchPort sp = new SwitchPort(swDPId, portId);
-        List<SwitchPort> spLists = new ArrayList<SwitchPort>();
-        spLists.add(sp);
-        HostEvent hostEvent = new HostEvent(devMac);
-        hostEvent.setAttachmentPoints(spLists);
-
-        // Call the topologyManager function for removing a device
-        theTopologyManager.removeHostDiscoveryEvent(hostEvent);
-
-        // Verify the function calls
-        verify(eventChannel);
-    }
-
-    /**
      * Test the Switch Mastership updated event.
      */
     @Test
     public void testPutSwitchMastershipEvent() {
         // Mock the eventChannel functions first
         eventChannel.addEntry(anyObject(byte[].class),
-                anyObject(TopologyEvent.class));
-        EasyMock.expectLastCall().times(1, 1); // 1 event
+                              anyObject(TopologyEvent.class));
+        EasyMock.expectLastCall().times(1, 1);          // 1 event
         replay(eventChannel);
 
         setupTopologyManager();
@@ -296,7 +170,7 @@
     public void testRemoveSwitchMastershipEvent() {
         // Mock the eventChannel functions first
         eventChannel.removeEntry(anyObject(byte[].class));
-        EasyMock.expectLastCall().times(1, 1); // 1 event
+        EasyMock.expectLastCall().times(1, 1);          // 1 event
         replay(eventChannel);
 
         setupTopologyManager();
@@ -315,43 +189,113 @@
     }
 
     /**
+     * Test the Switch discovered and Port discovered functions.
+     */
+    @Test
+    public void testPutSwitchAndPortDiscoveryEvent() {
+        // Mock the eventChannel functions first
+        eventChannel.addEntry(anyObject(byte[].class),
+                              anyObject(TopologyEvent.class));
+        EasyMock.expectLastCall().times(3, 3);  // (1 switch + 1 port), 1 port
+        replay(eventChannel);
+
+        setupTopologyManager();
+
+        // mockSwitch has one port
+        Dpid swDpid = new Dpid(100L);
+        PortNumber portNumber = PortNumber.uint32(1);
+
+        // Generate a new Switch Event along with a Port Event
+        SwitchEvent switchEvent = new SwitchEvent(swDpid);
+
+        Collection<PortEvent> portEvents = new ArrayList<PortEvent>();
+        portEvents.add(new PortEvent(swDpid, portNumber));
+
+        // Call the topologyManager function for adding a switch
+        theTopologyManager.putSwitchDiscoveryEvent(switchEvent, portEvents);
+
+        for (PortEvent portEvent : portEvents) {
+            // Call the topologyManager function for adding a port
+            theTopologyManager.putPortDiscoveryEvent(portEvent);
+        }
+
+        // Verify the function calls
+        verify(eventChannel);
+
+    }
+
+    /**
+     * Test the switch and port removed functions.
+     */
+    @Test
+    public void testRemoveSwitchAndPortDiscoveryEvent() {
+        // Mock the eventChannel functions first
+        eventChannel.removeEntry(anyObject(byte[].class));
+        EasyMock.expectLastCall().times(2, 2);          // 1 switch, 1 port
+        replay(eventChannel);
+
+        setupTopologyManager();
+
+        Dpid swDpid = new Dpid(100L);
+        PortNumber portNumber = PortNumber.uint32(1);
+
+        // Generate a Port Event
+        Collection<PortEvent> portEvents = new ArrayList<PortEvent>();
+        portEvents.add(new PortEvent(swDpid, portNumber));
+
+        // Call the topologyManager function for removing a port
+        for (PortEvent portEvent : portEvents) {
+            theTopologyManager.removePortDiscoveryEvent(portEvent);
+        }
+
+        // Call the topologyManager function for removing a switch
+        SwitchEvent switchEvent = new SwitchEvent(swDpid);
+        theTopologyManager.removeSwitchDiscoveryEvent(switchEvent);
+
+        // Verify the function calls
+        verify(eventChannel);
+
+    }
+
+    /**
      * Test the link discovered function.
      */
     @Test
     public void testPutLinkDiscoveryEvent() {
         // Mock the eventChannel functions first
         eventChannel.addEntry(anyObject(byte[].class),
-                anyObject(TopologyEvent.class));
-        EasyMock.expectLastCall().times(5, 5); // (2 switch + 2 port + 1 link)
+                              anyObject(TopologyEvent.class));
+        EasyMock.expectLastCall().times(5, 5);  // (2 switch + 2 port + 1 link)
         replay(eventChannel);
 
         setupTopologyManager();
 
         // Assign the switch and port IDs
-        Dpid sw1DPId = new Dpid(100L);
-        PortNumber port1Id = new PortNumber((short) 1);
-        Dpid sw2DPId = new Dpid(200L);
-        PortNumber port2Id = new PortNumber((short) 2);
+        Dpid swDpid1 = new Dpid(100L);
+        PortNumber portNumber1 = PortNumber.uint32(1);
+        Dpid swDpid2 = new Dpid(200L);
+        PortNumber portNumber2 = PortNumber.uint32(2);
 
         // Generate the switch and port events
-        SwitchEvent switchEvent1 = new SwitchEvent(sw1DPId);
+        SwitchEvent switchEvent1 = new SwitchEvent(swDpid1);
         Collection<PortEvent> portEvents1 = new ArrayList<PortEvent>();
-        portEvents1.add(new PortEvent(sw1DPId, port1Id));
+        portEvents1.add(new PortEvent(swDpid1, portNumber1));
 
         // Call the topologyManager function for adding a switch
         theTopologyManager.putSwitchDiscoveryEvent(switchEvent1, portEvents1);
 
-        // Generate the switch and port events
-        SwitchEvent switchEvent2 = new SwitchEvent(sw2DPId);
+        // Generate the Switch and Port Events
+        SwitchEvent switchEvent2 = new SwitchEvent(swDpid2);
         Collection<PortEvent> portEvents2 = new ArrayList<PortEvent>();
-        portEvents2.add(new PortEvent(sw2DPId, port2Id));
+        portEvents2.add(new PortEvent(swDpid2, portNumber2));
 
         // Call the topologyManager function for adding a switch
         theTopologyManager.putSwitchDiscoveryEvent(switchEvent2, portEvents2);
 
-        // Create the link
-        LinkEvent linkEvent = new LinkEvent(new SwitchPort(sw1DPId, port1Id),
-                                            new SwitchPort(sw2DPId, port2Id));
+        // Create the Link Event
+        LinkEvent linkEvent =
+            new LinkEvent(new SwitchPort(swDpid1, portNumber1),
+                          new SwitchPort(swDpid2, portNumber2));
         theTopologyManager.putLinkDiscoveryEvent(linkEvent);
 
         // Verify the function calls
@@ -365,37 +309,37 @@
     public void testRemoveLinkDiscoveryEvent() {
         // Mock the eventChannel functions first
         eventChannel.removeEntry(anyObject(byte[].class));
-        EasyMock.expectLastCall().times(1, 1); // (1 link)
+        EasyMock.expectLastCall().times(1, 1);          // (1 link)
         replay(eventChannel);
 
         setupTopologyManager();
 
         // Assign the switch and port IDs
-        Dpid sw1DPId = new Dpid(100L);
-        PortNumber port1Id = new PortNumber((short) 1);
-        Dpid sw2DPId = new Dpid(200L);
-        PortNumber port2Id = new PortNumber((short) 2);
+        Dpid swDpid1 = new Dpid(100L);
+        PortNumber portNumber1 = PortNumber.uint32(1);
+        Dpid swDpid2 = new Dpid(200L);
+        PortNumber portNumber2 = PortNumber.uint32(2);
 
-        // Generate the switch and port events
-        SwitchEvent switchEvent1 = new SwitchEvent(sw1DPId);
+        // Generate the Switch and Port Events
+        SwitchEvent switchEvent1 = new SwitchEvent(swDpid1);
         Collection<PortEvent> portEvents1 = new ArrayList<PortEvent>();
-        portEvents1.add(new PortEvent(sw1DPId, port1Id));
+        portEvents1.add(new PortEvent(swDpid1, portNumber1));
 
         // Call the topologyManager function for adding a switch
         theTopologyManager.putSwitchDiscoveryEvent(switchEvent1, portEvents1);
 
-        // Generate the switch and port events
-        SwitchEvent switchEvent2 = new SwitchEvent(sw2DPId);
+        // Generate the Switch and port Events
+        SwitchEvent switchEvent2 = new SwitchEvent(swDpid2);
         Collection<PortEvent> portEvents2 = new ArrayList<PortEvent>();
-        portEvents2.add(new PortEvent(sw2DPId, port2Id));
+        portEvents2.add(new PortEvent(swDpid2, portNumber2));
 
         // Call the topologyManager function for adding a switch
         theTopologyManager.putSwitchDiscoveryEvent(switchEvent2, portEvents2);
 
         // Remove the link
         LinkEvent linkEventRemove =
-            new LinkEvent(new SwitchPort(sw1DPId, port1Id),
-                          new SwitchPort(sw2DPId, port2Id));
+            new LinkEvent(new SwitchPort(swDpid1, portNumber1),
+                          new SwitchPort(swDpid2, portNumber2));
         theTopologyManager.removeLinkDiscoveryEvent(linkEventRemove);
 
         // Verify the function calls
@@ -403,6 +347,67 @@
     }
 
     /**
+     * Test the host discovered function.
+     */
+    @Test
+    public void testPutHostDiscoveryEvent() {
+        // Mock the eventChannel functions first
+        eventChannel.addEntry(anyObject(byte[].class),
+                              anyObject(TopologyEvent.class));
+        EasyMock.expectLastCall().times(1, 1);          // 1 host
+        replay(eventChannel);
+
+        setupTopologyManager();
+
+        Dpid swDpid = new Dpid(100L);
+        PortNumber portNumber = PortNumber.uint32(1);
+
+        // Generate a new Host Event
+        MACAddress hostMac = MACAddress.valueOf("00:AA:11:BB:33:CC");
+        SwitchPort sp = new SwitchPort(swDpid, portNumber);
+        List<SwitchPort> spLists = new ArrayList<SwitchPort>();
+        spLists.add(sp);
+        HostEvent hostEvent = new HostEvent(hostMac);
+        hostEvent.setAttachmentPoints(spLists);
+
+        // Call the topologyManager function for adding a host
+        theTopologyManager.putHostDiscoveryEvent(hostEvent);
+
+        // Verify the function calls
+        verify(eventChannel);
+    }
+
+    /**
+     * Test the host removed function.
+     */
+    @Test
+    public void testRemoveHostDiscoveryEvent() {
+        // Mock the eventChannel functions first
+        eventChannel.removeEntry(anyObject(byte[].class));
+        EasyMock.expectLastCall().times(1, 1);          // 1 host
+        replay(eventChannel);
+
+        setupTopologyManager();
+
+        Dpid swDpid = new Dpid(100L);
+        PortNumber portNumber = PortNumber.uint32(1);
+
+        // Generate a new Host Event
+        MACAddress hostMac = MACAddress.valueOf("00:AA:11:BB:33:CC");
+        SwitchPort sp = new SwitchPort(swDpid, portNumber);
+        List<SwitchPort> spLists = new ArrayList<SwitchPort>();
+        spLists.add(sp);
+        HostEvent hostEvent = new HostEvent(hostMac);
+        hostEvent.setAttachmentPoints(spLists);
+
+        // Call the topologyManager function for removing a host
+        theTopologyManager.removeHostDiscoveryEvent(hostEvent);
+
+        // Verify the function calls
+        verify(eventChannel);
+    }
+
+    /**
      * Test to confirm topology replica transformation.
      */
     @Test
@@ -413,16 +418,18 @@
         SwitchEvent sw = new SwitchEvent(dpid);
         sw.createStringAttribute("foo", "bar");
 
-        TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
+        TestUtils.callMethod(theTopologyManager, "addSwitch",
+                             SwitchEvent.class, sw);
 
-        // check topology structure
-        TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
+        // Check the topology structure
+        TopologyInternal topology =
+            (TopologyInternal) theTopologyManager.getTopology();
         SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
         assertEquals(sw, swInTopo);
         assertTrue(swInTopo.isFrozen());
         assertEquals("bar", swInTopo.getStringAttribute("foo"));
 
-        // check events to be fired
+        // Check the events to be fired
         List<SwitchEvent> apiAddedSwitchEvents
             = TestUtils.getField(theTopologyManager, "apiAddedSwitchEvents");
         assertThat(apiAddedSwitchEvents, hasItem(sw));
@@ -439,27 +446,30 @@
         SwitchEvent sw = new SwitchEvent(dpid);
         sw.createStringAttribute("foo", "bar");
 
-        final PortNumber portNumber = new PortNumber((short) 2);
+        final PortNumber portNumber = PortNumber.uint32(2);
         PortEvent port = new PortEvent(dpid, portNumber);
         port.createStringAttribute("fuzz", "buzz");
 
-        TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, port);
+        TestUtils.callMethod(theTopologyManager, "addSwitch",
+                             SwitchEvent.class, sw);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, port);
 
-        // check topology structure
-        TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
+        // Check the topology structure
+        TopologyInternal topology =
+            (TopologyInternal) theTopologyManager.getTopology();
         SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
         assertEquals(sw, swInTopo);
         assertTrue(swInTopo.isFrozen());
         assertEquals("bar", swInTopo.getStringAttribute("foo"));
 
-        final SwitchPort portId = new SwitchPort(dpid, portNumber);
-        PortEvent portInTopo = topology.getPortEvent(portId);
+        final SwitchPort switchPort = new SwitchPort(dpid, portNumber);
+        PortEvent portInTopo = topology.getPortEvent(switchPort);
         assertEquals(port, portInTopo);
         assertTrue(portInTopo.isFrozen());
         assertEquals("buzz", portInTopo.getStringAttribute("fuzz"));
 
-        // check events to be fired
+        // Check the events to be fired
         List<PortEvent> apiAddedPortEvents
             = TestUtils.getField(theTopologyManager, "apiAddedPortEvents");
         assertThat(apiAddedPortEvents, hasItem(port));
@@ -476,34 +486,37 @@
         SwitchEvent sw = new SwitchEvent(dpid);
         sw.createStringAttribute("foo", "bar");
 
-        final PortNumber portNumber = new PortNumber((short) 2);
+        final PortNumber portNumber = PortNumber.uint32(2);
         PortEvent port = new PortEvent(dpid, portNumber);
         port.createStringAttribute("fuzz", "buzz");
 
-        TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, port);
+        TestUtils.callMethod(theTopologyManager, "addSwitch",
+                             SwitchEvent.class, sw);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, port);
 
-        // check topology structure
-        TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
+        // Check the topology structure
+        TopologyInternal topology =
+            (TopologyInternal) theTopologyManager.getTopology();
         SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
         assertEquals(sw, swInTopo);
         assertTrue(swInTopo.isFrozen());
         assertEquals("bar", swInTopo.getStringAttribute("foo"));
 
-        final SwitchPort portId = new SwitchPort(dpid, portNumber);
-        PortEvent portInTopo = topology.getPortEvent(portId);
+        final SwitchPort switchPort = new SwitchPort(dpid, portNumber);
+        PortEvent portInTopo = topology.getPortEvent(switchPort);
         assertEquals(port, portInTopo);
         assertTrue(portInTopo.isFrozen());
         assertEquals("buzz", portInTopo.getStringAttribute("fuzz"));
 
-        // remove in proper order
+        // Remove in proper order
         TestUtils.callMethod(theTopologyManager, "removePort",
                             PortEvent.class, new PortEvent(port));
         TestUtils.callMethod(theTopologyManager, "removeSwitch",
                             SwitchEvent.class, new SwitchEvent(sw));
 
 
-        // check events to be fired
+        // Check the events to be fired
         List<PortEvent> apiRemovedPortEvents
             = TestUtils.getField(theTopologyManager, "apiRemovedPortEvents");
         assertThat(apiRemovedPortEvents, hasItem(port));
@@ -516,42 +529,45 @@
      * Test to confirm topology replica transformation.
      */
     @Test
-    public void testRemoveSwitch() {
+    public void testRemoveSwitchWithoutPortRemoval() {
         setupTopologyManager();
 
         final Dpid dpid = new Dpid(1);
         SwitchEvent sw = new SwitchEvent(dpid);
         sw.createStringAttribute("foo", "bar");
 
-        final PortNumber portNumber = new PortNumber((short) 2);
+        final PortNumber portNumber = PortNumber.uint32(2);
         PortEvent port = new PortEvent(dpid, portNumber);
         port.createStringAttribute("fuzz", "buzz");
 
-        TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, port);
+        TestUtils.callMethod(theTopologyManager, "addSwitch",
+                             SwitchEvent.class, sw);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, port);
 
-        // check topology structure
-        TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
+        // Check the topology structure
+        TopologyInternal topology =
+            (TopologyInternal) theTopologyManager.getTopology();
         SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
         assertEquals(sw, swInTopo);
         assertTrue(swInTopo.isFrozen());
         assertEquals("bar", swInTopo.getStringAttribute("foo"));
 
-        final SwitchPort portId = new SwitchPort(dpid, portNumber);
-        PortEvent portInTopo = topology.getPortEvent(portId);
+        final SwitchPort switchPort = new SwitchPort(dpid, portNumber);
+        PortEvent portInTopo = topology.getPortEvent(switchPort);
         assertEquals(port, portInTopo);
         assertTrue(portInTopo.isFrozen());
         assertEquals("buzz", portInTopo.getStringAttribute("fuzz"));
 
-        // remove in in-proper order
+        // Remove in in-proper order
 //        TestUtils.callMethod(theTopologyManager, "removePort",
 //                            PortEvent.class, new PortEvent(port));
         TestUtils.callMethod(theTopologyManager, "removeSwitch",
                             SwitchEvent.class, new SwitchEvent(sw));
 
 
-        // check events to be fired
-        // outcome should be the same as #testRemovePortThenSwitch
+        // Check the events to be fired
+        // The outcome should be the same as #testRemovePortThenSwitch
         List<PortEvent> apiRemovedPortEvents
             = TestUtils.getField(theTopologyManager, "apiRemovedPortEvents");
         assertThat(apiRemovedPortEvents, hasItem(port));
@@ -571,42 +587,50 @@
         SwitchEvent sw = new SwitchEvent(dpid);
         sw.createStringAttribute("foo", "bar");
 
-        final PortNumber portNumberA = new PortNumber((short) 2);
+        final PortNumber portNumberA = PortNumber.uint32(2);
         PortEvent portA = new PortEvent(dpid, portNumberA);
         portA.createStringAttribute("fuzz", "buzz");
 
-        final PortNumber portNumberB = new PortNumber((short) 3);
+        final PortNumber portNumberB = PortNumber.uint32(3);
         PortEvent portB = new PortEvent(dpid, portNumberB);
         portB.createStringAttribute("fizz", "buz");
 
-        LinkEvent linkA = new LinkEvent(portA.getSwitchPort(), portB.getSwitchPort());
+        LinkEvent linkA = new LinkEvent(portA.getSwitchPort(),
+                                        portB.getSwitchPort());
         linkA.createStringAttribute(TopologyElement.TYPE,
                                     TopologyElement.TYPE_OPTICAL_LAYER);
-        LinkEvent linkB = new LinkEvent(portB.getSwitchPort(), portA.getSwitchPort());
+        LinkEvent linkB = new LinkEvent(portB.getSwitchPort(),
+                                        portA.getSwitchPort());
         linkB.createStringAttribute(TopologyElement.TYPE,
                                     TopologyElement.TYPE_OPTICAL_LAYER);
 
-        TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portA);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portB);
-        TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkA);
-        TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkB);
+        TestUtils.callMethod(theTopologyManager, "addSwitch",
+                             SwitchEvent.class, sw);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portA);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portB);
+        TestUtils.callMethod(theTopologyManager, "addLink",
+                             LinkEvent.class, linkA);
+        TestUtils.callMethod(theTopologyManager, "addLink",
+                             LinkEvent.class, linkB);
 
-        // check topology structure
-        TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
+        // Check the topology structure
+        TopologyInternal topology =
+            (TopologyInternal) theTopologyManager.getTopology();
         SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
         assertEquals(sw, swInTopo);
         assertTrue(swInTopo.isFrozen());
         assertEquals("bar", swInTopo.getStringAttribute("foo"));
 
-        final SwitchPort portIdA = new SwitchPort(dpid, portNumberA);
-        PortEvent portAInTopo = topology.getPortEvent(portIdA);
+        final SwitchPort switchPortA = new SwitchPort(dpid, portNumberA);
+        PortEvent portAInTopo = topology.getPortEvent(switchPortA);
         assertEquals(portA, portAInTopo);
         assertTrue(portAInTopo.isFrozen());
         assertEquals("buzz", portAInTopo.getStringAttribute("fuzz"));
 
-        final SwitchPort portIdB = new SwitchPort(dpid, portNumberB);
-        PortEvent portBInTopo = topology.getPortEvent(portIdB);
+        final SwitchPort switchPortB = new SwitchPort(dpid, portNumberB);
+        PortEvent portBInTopo = topology.getPortEvent(switchPortB);
         assertEquals(portB, portBInTopo);
         assertTrue(portBInTopo.isFrozen());
         assertEquals("buz", portBInTopo.getStringAttribute("fizz"));
@@ -614,14 +638,16 @@
         LinkEvent linkAInTopo = topology.getLinkEvent(linkA.getLinkTuple());
         assertEquals(linkA, linkAInTopo);
         assertTrue(linkAInTopo.isFrozen());
-        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkAInTopo.getType());
+        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER,
+                     linkAInTopo.getType());
 
         LinkEvent linkBInTopo = topology.getLinkEvent(linkB.getLinkTuple());
         assertEquals(linkB, linkBInTopo);
         assertTrue(linkBInTopo.isFrozen());
-        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkBInTopo.getType());
+        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER,
+                     linkBInTopo.getType());
 
-        // check events to be fired
+        // Check the events to be fired
         List<LinkEvent> apiAddedLinkEvents
             = TestUtils.getField(theTopologyManager, "apiAddedLinkEvents");
         assertThat(apiAddedLinkEvents, containsInAnyOrder(linkA, linkB));
@@ -638,15 +664,15 @@
         SwitchEvent sw = new SwitchEvent(dpid);
         sw.createStringAttribute("foo", "bar");
 
-        final PortNumber portNumberA = new PortNumber((short) 2);
+        final PortNumber portNumberA = PortNumber.uint32(2);
         PortEvent portA = new PortEvent(dpid, portNumberA);
         portA.createStringAttribute("fuzz", "buzz");
 
-        final PortNumber portNumberB = new PortNumber((short) 3);
+        final PortNumber portNumberB = PortNumber.uint32(3);
         PortEvent portB = new PortEvent(dpid, portNumberB);
         portB.createStringAttribute("fizz", "buz");
 
-        final PortNumber portNumberC = new PortNumber((short) 4);
+        final PortNumber portNumberC = PortNumber.uint32(4);
         PortEvent portC = new PortEvent(dpid, portNumberC);
         portC.createStringAttribute("fizz", "buz");
 
@@ -664,38 +690,49 @@
         hostB.setLastSeenTime(timestampB);
 
 
-        LinkEvent linkA = new LinkEvent(portA.getSwitchPort(), portB.getSwitchPort());
+        LinkEvent linkA = new LinkEvent(portA.getSwitchPort(),
+                                        portB.getSwitchPort());
         linkA.createStringAttribute(TopologyElement.TYPE,
                                     TopologyElement.TYPE_OPTICAL_LAYER);
-        LinkEvent linkB = new LinkEvent(portB.getSwitchPort(), portA.getSwitchPort());
+        LinkEvent linkB = new LinkEvent(portB.getSwitchPort(),
+                                        portA.getSwitchPort());
         linkB.createStringAttribute(TopologyElement.TYPE,
                                     TopologyElement.TYPE_OPTICAL_LAYER);
 
-        TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portA);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portB);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portC);
-        TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostA);
-        TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostB);
+        TestUtils.callMethod(theTopologyManager, "addSwitch",
+                             SwitchEvent.class, sw);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portA);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portB);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portC);
+        TestUtils.callMethod(theTopologyManager, "addHost",
+                             HostEvent.class, hostA);
+        TestUtils.callMethod(theTopologyManager, "addHost",
+                             HostEvent.class, hostB);
 
-        TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkA);
-        TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkB);
+        TestUtils.callMethod(theTopologyManager, "addLink",
+                             LinkEvent.class, linkA);
+        TestUtils.callMethod(theTopologyManager, "addLink",
+                             LinkEvent.class, linkB);
 
-        // check topology structure
-        TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
+        // Check the topology structure
+        TopologyInternal topology =
+            (TopologyInternal) theTopologyManager.getTopology();
         SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
         assertEquals(sw, swInTopo);
         assertTrue(swInTopo.isFrozen());
         assertEquals("bar", swInTopo.getStringAttribute("foo"));
 
-        final SwitchPort portIdA = new SwitchPort(dpid, portNumberA);
-        PortEvent portAInTopo = topology.getPortEvent(portIdA);
+        final SwitchPort switchPortA = new SwitchPort(dpid, portNumberA);
+        PortEvent portAInTopo = topology.getPortEvent(switchPortA);
         assertEquals(portA, portAInTopo);
         assertTrue(portAInTopo.isFrozen());
         assertEquals("buzz", portAInTopo.getStringAttribute("fuzz"));
 
-        final SwitchPort portIdB = new SwitchPort(dpid, portNumberB);
-        PortEvent portBInTopo = topology.getPortEvent(portIdB);
+        final SwitchPort switchPortB = new SwitchPort(dpid, portNumberB);
+        PortEvent portBInTopo = topology.getPortEvent(switchPortB);
         assertEquals(portB, portBInTopo);
         assertTrue(portBInTopo.isFrozen());
         assertEquals("buz", portBInTopo.getStringAttribute("fizz"));
@@ -713,14 +750,16 @@
         LinkEvent linkAInTopo = topology.getLinkEvent(linkA.getLinkTuple());
         assertEquals(linkA, linkAInTopo);
         assertTrue(linkAInTopo.isFrozen());
-        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkAInTopo.getType());
+        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER,
+                     linkAInTopo.getType());
 
         LinkEvent linkBInTopo = topology.getLinkEvent(linkB.getLinkTuple());
         assertEquals(linkB, linkBInTopo);
         assertTrue(linkBInTopo.isFrozen());
-        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkBInTopo.getType());
+        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER,
+                     linkBInTopo.getType());
 
-        // check events to be fired
+        // Check the events to be fired
         List<HostEvent> apiAddedHostEvents
             = TestUtils.getField(theTopologyManager, "apiAddedHostEvents");
         assertThat(apiAddedHostEvents, hasItem(hostBrev));
@@ -744,42 +783,50 @@
         SwitchEvent sw = new SwitchEvent(dpid);
         sw.createStringAttribute("foo", "bar");
 
-        final PortNumber portNumberA = new PortNumber((short) 2);
+        final PortNumber portNumberA = PortNumber.uint32(2);
         PortEvent portA = new PortEvent(dpid, portNumberA);
         portA.createStringAttribute("fuzz", "buzz");
 
-        final PortNumber portNumberB = new PortNumber((short) 3);
+        final PortNumber portNumberB = PortNumber.uint32(3);
         PortEvent portB = new PortEvent(dpid, portNumberB);
         portB.createStringAttribute("fizz", "buz");
 
-        LinkEvent linkA = new LinkEvent(portA.getSwitchPort(), portB.getSwitchPort());
+        LinkEvent linkA = new LinkEvent(portA.getSwitchPort(),
+                                        portB.getSwitchPort());
         linkA.createStringAttribute(TopologyElement.TYPE,
                                     TopologyElement.TYPE_OPTICAL_LAYER);
-        LinkEvent linkB = new LinkEvent(portB.getSwitchPort(), portA.getSwitchPort());
+        LinkEvent linkB = new LinkEvent(portB.getSwitchPort(),
+                                        portA.getSwitchPort());
         linkB.createStringAttribute(TopologyElement.TYPE,
                                     TopologyElement.TYPE_OPTICAL_LAYER);
 
-        TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portA);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portB);
-        TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkA);
-        TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkB);
+        TestUtils.callMethod(theTopologyManager, "addSwitch",
+                             SwitchEvent.class, sw);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portA);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portB);
+        TestUtils.callMethod(theTopologyManager, "addLink",
+                             LinkEvent.class, linkA);
+        TestUtils.callMethod(theTopologyManager, "addLink",
+                             LinkEvent.class, linkB);
 
-        // check topology structure
-        TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
+        // Check the topology structure
+        TopologyInternal topology =
+            (TopologyInternal) theTopologyManager.getTopology();
         SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
         assertEquals(sw, swInTopo);
         assertTrue(swInTopo.isFrozen());
         assertEquals("bar", swInTopo.getStringAttribute("foo"));
 
-        final SwitchPort portIdA = new SwitchPort(dpid, portNumberA);
-        PortEvent portAInTopo = topology.getPortEvent(portIdA);
+        final SwitchPort switchPortA = new SwitchPort(dpid, portNumberA);
+        PortEvent portAInTopo = topology.getPortEvent(switchPortA);
         assertEquals(portA, portAInTopo);
         assertTrue(portAInTopo.isFrozen());
         assertEquals("buzz", portAInTopo.getStringAttribute("fuzz"));
 
-        final SwitchPort portIdB = new SwitchPort(dpid, portNumberB);
-        PortEvent portBInTopo = topology.getPortEvent(portIdB);
+        final SwitchPort switchPortB = new SwitchPort(dpid, portNumberB);
+        PortEvent portBInTopo = topology.getPortEvent(switchPortB);
         assertEquals(portB, portBInTopo);
         assertTrue(portBInTopo.isFrozen());
         assertEquals("buz", portBInTopo.getStringAttribute("fizz"));
@@ -787,26 +834,29 @@
         LinkEvent linkAInTopo = topology.getLinkEvent(linkA.getLinkTuple());
         assertEquals(linkA, linkAInTopo);
         assertTrue(linkAInTopo.isFrozen());
-        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkAInTopo.getType());
+        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER,
+                     linkAInTopo.getType());
 
 
         LinkEvent linkBInTopo = topology.getLinkEvent(linkB.getLinkTuple());
         assertEquals(linkB, linkBInTopo);
         assertTrue(linkBInTopo.isFrozen());
-        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkBInTopo.getType());
+        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER,
+                     linkBInTopo.getType());
 
-        // check events to be fired
+        // Check the events to be fired
         // FIXME if link flapped (linkA in this scenario),
         //  linkA appears in both removed and added is this expected behavior?
         List<LinkEvent> apiAddedLinkEvents
             = TestUtils.getField(theTopologyManager, "apiAddedLinkEvents");
         assertThat(apiAddedLinkEvents, containsInAnyOrder(linkA, linkB));
 
-        // clear event before removing Link
+        // Clear the events before removing the link
         apiAddedLinkEvents.clear();
 
-        // remove link
-        TestUtils.callMethod(theTopologyManager, "removeLink", LinkEvent.class, new LinkEvent(linkA));
+        // Remove the link
+        TestUtils.callMethod(theTopologyManager, "removeLink",
+                             LinkEvent.class, new LinkEvent(linkA));
 
         LinkEvent linkANotInTopo = topology.getLinkEvent(linkA.getLinkTuple());
         assertNull(linkANotInTopo);
@@ -827,31 +877,39 @@
         SwitchEvent sw = new SwitchEvent(dpid);
         sw.createStringAttribute("foo", "bar");
 
-        final PortNumber portNumberA = new PortNumber((short) 2);
+        final PortNumber portNumberA = PortNumber.uint32(2);
         PortEvent portA = new PortEvent(dpid, portNumberA);
         portA.createStringAttribute("fuzz", "buzz");
 
-        final PortNumber portNumberB = new PortNumber((short) 3);
+        final PortNumber portNumberB = PortNumber.uint32(3);
         PortEvent portB = new PortEvent(dpid, portNumberB);
         portB.createStringAttribute("fizz", "buz");
 
-        final PortNumber portNumberC = new PortNumber((short) 4);
+        final PortNumber portNumberC = PortNumber.uint32(4);
         PortEvent portC = new PortEvent(dpid, portNumberC);
         portC.createStringAttribute("fizz", "buz");
 
-        LinkEvent linkA = new LinkEvent(portA.getSwitchPort(), portB.getSwitchPort());
+        LinkEvent linkA = new LinkEvent(portA.getSwitchPort(),
+                                        portB.getSwitchPort());
         linkA.createStringAttribute(TopologyElement.TYPE,
                                     TopologyElement.TYPE_OPTICAL_LAYER);
-        LinkEvent linkB = new LinkEvent(portB.getSwitchPort(), portA.getSwitchPort());
+        LinkEvent linkB = new LinkEvent(portB.getSwitchPort(),
+                                        portA.getSwitchPort());
         linkB.createStringAttribute(TopologyElement.TYPE,
                                     TopologyElement.TYPE_OPTICAL_LAYER);
 
-        TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portA);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portB);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portC);
-        TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkA);
-        TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkB);
+        TestUtils.callMethod(theTopologyManager, "addSwitch",
+                             SwitchEvent.class, sw);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portA);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portB);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portC);
+        TestUtils.callMethod(theTopologyManager, "addLink",
+                             LinkEvent.class, linkA);
+        TestUtils.callMethod(theTopologyManager, "addLink",
+                             LinkEvent.class, linkB);
 
         // Add hostA attached to a port which already has a link
         final MACAddress macA = MACAddress.valueOf(666L);
@@ -860,7 +918,8 @@
         final long timestampA = 392893200L;
         hostA.setLastSeenTime(timestampA);
 
-        TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostA);
+        TestUtils.callMethod(theTopologyManager, "addHost",
+                             HostEvent.class, hostA);
 
         // Add hostB attached to multiple ports,
         // some of them which already has a link
@@ -871,23 +930,25 @@
         final long timestampB = 392893201L;
         hostB.setLastSeenTime(timestampB);
 
-        TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostB);
+        TestUtils.callMethod(theTopologyManager, "addHost",
+                             HostEvent.class, hostB);
 
-        // check topology structure
-        TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
+        // Check the topology structure
+        TopologyInternal topology =
+            (TopologyInternal) theTopologyManager.getTopology();
         SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
         assertEquals(sw, swInTopo);
         assertTrue(swInTopo.isFrozen());
         assertEquals("bar", swInTopo.getStringAttribute("foo"));
 
-        final SwitchPort portIdA = new SwitchPort(dpid, portNumberA);
-        PortEvent portAInTopo = topology.getPortEvent(portIdA);
+        final SwitchPort switchPortA = new SwitchPort(dpid, portNumberA);
+        PortEvent portAInTopo = topology.getPortEvent(switchPortA);
         assertEquals(portA, portAInTopo);
         assertTrue(portAInTopo.isFrozen());
         assertEquals("buzz", portAInTopo.getStringAttribute("fuzz"));
 
-        final SwitchPort portIdB = new SwitchPort(dpid, portNumberB);
-        PortEvent portBInTopo = topology.getPortEvent(portIdB);
+        final SwitchPort switchPortB = new SwitchPort(dpid, portNumberB);
+        PortEvent portBInTopo = topology.getPortEvent(switchPortB);
         assertEquals(portB, portBInTopo);
         assertTrue(portBInTopo.isFrozen());
         assertEquals("buz", portBInTopo.getStringAttribute("fizz"));
@@ -905,14 +966,16 @@
         LinkEvent linkAInTopo = topology.getLinkEvent(linkA.getLinkTuple());
         assertEquals(linkA, linkAInTopo);
         assertTrue(linkAInTopo.isFrozen());
-        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkAInTopo.getType());
+        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER,
+                     linkAInTopo.getType());
 
         LinkEvent linkBInTopo = topology.getLinkEvent(linkB.getLinkTuple());
         assertEquals(linkB, linkBInTopo);
         assertTrue(linkBInTopo.isFrozen());
-        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkBInTopo.getType());
+        assertEquals(TopologyElement.TYPE_OPTICAL_LAYER,
+                     linkBInTopo.getType());
 
-        // check events to be fired
+        // Check the events to be fired
         // hostB should be added with reduced attachment points
         List<HostEvent> apiAddedHostEvents
             = TestUtils.getField(theTopologyManager, "apiAddedHostEvents");
@@ -939,22 +1002,26 @@
         SwitchEvent sw = new SwitchEvent(dpid);
         sw.createStringAttribute("foo", "bar");
 
-        final PortNumber portNumberA = new PortNumber((short) 2);
+        final PortNumber portNumberA = PortNumber.uint32(2);
         PortEvent portA = new PortEvent(dpid, portNumberA);
         portA.createStringAttribute("fuzz", "buzz");
 
-        final PortNumber portNumberB = new PortNumber((short) 3);
+        final PortNumber portNumberB = PortNumber.uint32(3);
         PortEvent portB = new PortEvent(dpid, portNumberB);
         portB.createStringAttribute("fizz", "buz");
 
-        final PortNumber portNumberC = new PortNumber((short) 4);
+        final PortNumber portNumberC = PortNumber.uint32(4);
         PortEvent portC = new PortEvent(dpid, portNumberC);
         portC.createStringAttribute("fizz", "buz");
 
-        TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portA);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portB);
-        TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portC);
+        TestUtils.callMethod(theTopologyManager, "addSwitch",
+                             SwitchEvent.class, sw);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portA);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portB);
+        TestUtils.callMethod(theTopologyManager, "addPort",
+                             PortEvent.class, portC);
 
         // Add hostA attached to a port which already has a link
         final MACAddress macA = MACAddress.valueOf(666L);
@@ -963,40 +1030,43 @@
         final long timestampA = 392893200L;
         hostA.setLastSeenTime(timestampA);
 
-        TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostA);
+        TestUtils.callMethod(theTopologyManager, "addHost",
+                             HostEvent.class, hostA);
 
 
-        // check topology structure
-        TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
+        // Check the topology structure
+        TopologyInternal topology =
+            (TopologyInternal) theTopologyManager.getTopology();
         SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
         assertEquals(sw, swInTopo);
         assertTrue(swInTopo.isFrozen());
         assertEquals("bar", swInTopo.getStringAttribute("foo"));
 
-        final SwitchPort portIdA = new SwitchPort(dpid, portNumberA);
-        PortEvent portAInTopo = topology.getPortEvent(portIdA);
+        final SwitchPort switchPortA = new SwitchPort(dpid, portNumberA);
+        PortEvent portAInTopo = topology.getPortEvent(switchPortA);
         assertEquals(portA, portAInTopo);
         assertTrue(portAInTopo.isFrozen());
         assertEquals("buzz", portAInTopo.getStringAttribute("fuzz"));
 
-        final SwitchPort portIdB = new SwitchPort(dpid, portNumberB);
-        PortEvent portBInTopo = topology.getPortEvent(portIdB);
+        final SwitchPort switchPortB = new SwitchPort(dpid, portNumberB);
+        PortEvent portBInTopo = topology.getPortEvent(switchPortB);
         assertEquals(portB, portBInTopo);
         assertTrue(portBInTopo.isFrozen());
         assertEquals("buz", portBInTopo.getStringAttribute("fizz"));
 
         // hostA expected to be there
         assertEquals(hostA, topology.getHostEvent(macA));
-        assertEquals(timestampA, topology.getHostEvent(macA).getLastSeenTime());
+        assertEquals(timestampA,
+                     topology.getHostEvent(macA).getLastSeenTime());
 
-        // check events to be fired
+        // Check the events to be fired
         // hostA should be added
         List<HostEvent> apiAddedHostEvents
             = TestUtils.getField(theTopologyManager, "apiAddedHostEvents");
         assertThat(apiAddedHostEvents, hasItem(hostA));
 
 
-        // clear event before moving host
+        // Clear the events before moving the host
         apiAddedHostEvents.clear();
 
         HostEvent hostAmoved = new HostEvent(macA);
@@ -1004,10 +1074,12 @@
         final long timestampAmoved = 392893201L;
         hostAmoved.setLastSeenTime(timestampAmoved);
 
-        TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostAmoved);
+        TestUtils.callMethod(theTopologyManager, "addHost",
+                             HostEvent.class, hostAmoved);
 
         assertEquals(hostAmoved, topology.getHostEvent(macA));
-        assertEquals(timestampAmoved, topology.getHostEvent(macA).getLastSeenTime());
+        assertEquals(timestampAmoved,
+                     topology.getHostEvent(macA).getLastSeenTime());
 
         // hostA expected to be there with new attachment point
         apiAddedHostEvents