Fixing topology related interface/class tree

- (Mutable)Topology no longer implements ImmutableTopology

    --- BaseTopology (was ImmutableTopology)
     |
     +-- ImmutableTopology (new)
     |
     +-- MutableTopology (was Topology)
       |
       +-- RefreshableTopology
       |
       +-- TopologyInternal
            This interface is placed in wrong place. To be fixed later.

Change-Id: Ifa9defcc7c0fc22bba19977fe4ea57eaf792275e
diff --git a/src/main/java/net/onrc/onos/core/hostmanager/HostManager.java b/src/main/java/net/onrc/onos/core/hostmanager/HostManager.java
index a5e3bd9..155c3cf 100644
--- a/src/main/java/net/onrc/onos/core/hostmanager/HostManager.java
+++ b/src/main/java/net/onrc/onos/core/hostmanager/HostManager.java
@@ -26,7 +26,7 @@
 import net.onrc.onos.core.packet.Ethernet;
 import net.onrc.onos.core.topology.ITopologyService;
 import net.onrc.onos.core.topology.Port;
-import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.topology.MutableTopology;
 import net.onrc.onos.core.util.Dpid;
 import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.PortNumberUtils;
@@ -52,7 +52,7 @@
             Executors.newSingleThreadScheduledExecutor();
 
     private ITopologyService topologyService;
-    private Topology topology;
+    private MutableTopology mutableTopology;
 
     public enum HostUpdateType {
         ADD, DELETE, UPDATE;
@@ -141,17 +141,17 @@
         // then don't add the host
         // TODO We probably don't need to check this here, it should be done in
         // the Topology module.
-        topology.acquireReadLock();
+        mutableTopology.acquireReadLock();
         try {
-            if (topology.getOutgoingLink(dpid, portNum) != null ||
-                    topology.getIncomingLink(dpid, portNum) != null) {
+            if (mutableTopology.getOutgoingLink(dpid, portNum) != null ||
+                    mutableTopology.getIncomingLink(dpid, portNum) != null) {
                 log.debug("Not adding host {} as " +
                         "there is a link on the port: dpid {} port {}",
                         srcHost.getMacAddress(), dpid, portNum);
                 return Command.CONTINUE;
             }
         } finally {
-            topology.releaseReadLock();
+            mutableTopology.releaseReadLock();
         }
 
         Long mac = eth.getSourceMAC().toLong();
@@ -175,10 +175,10 @@
         @Override
         public void run() {
             log.debug("called HostCleaner");
-            topology.acquireReadLock();
+            mutableTopology.acquireReadLock();
             try {
                 Set<net.onrc.onos.core.topology.Host> deleteSet = new HashSet<>();
-                for (net.onrc.onos.core.topology.Host host : topology.getHosts()) {
+                for (net.onrc.onos.core.topology.Host host : mutableTopology.getHosts()) {
                     long now = System.currentTimeMillis();
                     if ((now - host.getLastSeenTime() > agingMillisecConfig)) {
                         if (log.isTraceEnabled()) {
@@ -198,7 +198,7 @@
                 // all exceptions here.
                 log.error("Exception in host cleanup thread:", e);
             } finally {
-                topology.releaseReadLock();
+                mutableTopology.releaseReadLock();
             }
         }
     }
@@ -259,7 +259,7 @@
         floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
         hostListeners = new CopyOnWriteArrayList<IHostListener>();
         topologyService = context.getServiceImpl(ITopologyService.class);
-        topology = topologyService.getTopology();
+        mutableTopology = topologyService.getTopology();
 
         setHostManagerProperties(context);
     }
@@ -280,9 +280,9 @@
     @Override
     public void deleteHostByMac(MACAddress mac) {
         Host deleteHost = null;
-        topology.acquireReadLock();
+        mutableTopology.acquireReadLock();
         try {
-            net.onrc.onos.core.topology.Host host = topology.getHostByMac(mac);
+            net.onrc.onos.core.topology.Host host = mutableTopology.getHostByMac(mac);
 
             for (Port switchPort : host.getAttachmentPoints()) {
                 // We don't handle vlan now and multiple attachment points.
@@ -295,7 +295,7 @@
                 break; // NOPMD
             }
         } finally {
-            topology.releaseReadLock();
+            mutableTopology.releaseReadLock();
         }
 
         if (deleteHost != null) {
diff --git a/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntime.java b/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntime.java
index d4452e1..194327c 100644
--- a/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntime.java
+++ b/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntime.java
@@ -18,7 +18,7 @@
 import net.onrc.onos.core.intent.PathIntentMap;
 import net.onrc.onos.core.intent.ShortestPathIntent;
 import net.onrc.onos.core.topology.Switch;
-import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.topology.MutableTopology;
 import net.onrc.onos.core.util.Dpid;
 
 import org.slf4j.Logger;
@@ -30,16 +30,16 @@
  * It calculates shortest-path and constrained-shortest-path.
  */
 public class PathCalcRuntime implements IFloodlightService {
-    private Topology topology;
+    private MutableTopology mutableTopology;
     private static final Logger log = LoggerFactory.getLogger(PathCalcRuntime.class);
 
     /**
      * Constructor.
      *
-     * @param topology a topology object to use for the path calculation.
+     * @param mutableTopology a topology object to use for the path calculation.
      */
-    public PathCalcRuntime(Topology topology) {
-        this.topology = topology;
+    public PathCalcRuntime(MutableTopology mutableTopology) {
+        this.mutableTopology = mutableTopology;
     }
 
     /**
@@ -55,7 +55,7 @@
         HashMap<Switch, ConstrainedBFSTree> spfTrees = new HashMap<>();
 
         // TODO optimize locking of Topology
-        topology.acquireReadLock();
+        mutableTopology.acquireReadLock();
 
         for (IntentOperation intentOp : intentOpList) {
             switch (intentOp.operator) {
@@ -70,8 +70,8 @@
                     }
 
                     ShortestPathIntent spIntent = (ShortestPathIntent) intentOp.intent;
-                    Switch srcSwitch = topology.getSwitch(new Dpid(spIntent.getSrcSwitchDpid()));
-                    Switch dstSwitch = topology.getSwitch(new Dpid(spIntent.getDstSwitchDpid()));
+                    Switch srcSwitch = mutableTopology.getSwitch(new Dpid(spIntent.getSrcSwitchDpid()));
+                    Switch dstSwitch = mutableTopology.getSwitch(new Dpid(spIntent.getDstSwitchDpid()));
                     if (srcSwitch == null || dstSwitch == null) {
                         log.debug("Switch not found. src:{}, dst:{}",
                                 spIntent.getSrcSwitchDpid(),
@@ -163,7 +163,7 @@
             }
         }
         // TODO optimize locking of Topology
-        topology.releaseReadLock();
+        mutableTopology.releaseReadLock();
 
         return pathIntentOpList;
     }
diff --git a/src/main/java/net/onrc/onos/core/intent/runtime/web/ShortestPathResource.java b/src/main/java/net/onrc/onos/core/intent/runtime/web/ShortestPathResource.java
index 1abd61d..2910c3d 100644
--- a/src/main/java/net/onrc/onos/core/intent/runtime/web/ShortestPathResource.java
+++ b/src/main/java/net/onrc/onos/core/intent/runtime/web/ShortestPathResource.java
@@ -10,7 +10,7 @@
 import net.onrc.onos.core.topology.Link;
 import net.onrc.onos.core.topology.LinkEvent;
 import net.onrc.onos.core.topology.Switch;
-import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.topology.MutableTopology;
 import net.onrc.onos.core.util.Dpid;
 
 import org.restlet.representation.Representation;
@@ -51,11 +51,11 @@
         // Do the Shortest Path computation and return the result: a list of
         // links.
         //
-        Topology topology = topologyService.getTopology();
-        topology.acquireReadLock();
+        MutableTopology mutableTopology = topologyService.getTopology();
+        mutableTopology.acquireReadLock();
         try {
-            Switch srcSwitch = topology.getSwitch(srcDpid);
-            Switch dstSwitch = topology.getSwitch(dstDpid);
+            Switch srcSwitch = mutableTopology.getSwitch(srcDpid);
+            Switch dstSwitch = mutableTopology.getSwitch(dstDpid);
             if ((srcSwitch == null) || (dstSwitch == null)) {
                 return null;
             }
@@ -66,7 +66,7 @@
             }
             List<Link> links = new LinkedList<>();
             for (LinkEvent linkEvent : path) {
-                Link link = topology.getLink(
+                Link link = mutableTopology.getLink(
                         linkEvent.getSrc().getDpid(),
                         linkEvent.getSrc().getPortNumber(),
                         linkEvent.getDst().getDpid(),
@@ -78,7 +78,7 @@
             }
             return eval(toRepresentation(links, null));
         } finally {
-            topology.releaseReadLock();
+            mutableTopology.releaseReadLock();
         }
     }
 }
diff --git a/src/main/java/net/onrc/onos/core/packetservice/BroadcastPacketOutNotification.java b/src/main/java/net/onrc/onos/core/packetservice/BroadcastPacketOutNotification.java
index 4f96302..f7629d8 100644
--- a/src/main/java/net/onrc/onos/core/packetservice/BroadcastPacketOutNotification.java
+++ b/src/main/java/net/onrc/onos/core/packetservice/BroadcastPacketOutNotification.java
@@ -2,7 +2,7 @@
 
 import java.util.Map;
 
-import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.topology.MutableTopology;
 import net.onrc.onos.core.topology.Port;
 import net.onrc.onos.core.util.Dpid;
 import net.onrc.onos.core.util.PortNumber;
@@ -84,17 +84,17 @@
 
     @Override
     public Multimap<Long, Short> calculateOutPorts(
-            Multimap<Long, Short> localPorts, Topology topology) {
+            Multimap<Long, Short> localPorts, MutableTopology mutableTopology) {
         Multimap<Long, Short> outPorts = HashMultimap.create();
 
         for (Map.Entry<Long, Short> entry : localPorts.entries()) {
             Port globalPort;
-            topology.acquireReadLock();
+            mutableTopology.acquireReadLock();
             try {
-                globalPort = topology.getPort(new Dpid(entry.getKey()),
+                globalPort = mutableTopology.getPort(new Dpid(entry.getKey()),
                     PortNumber.uint16(entry.getValue()));
             } finally {
-                topology.releaseReadLock();
+                mutableTopology.releaseReadLock();
             }
 
             if ((!entry.getKey().equals(inSwitch) ||
diff --git a/src/main/java/net/onrc/onos/core/packetservice/PacketModule.java b/src/main/java/net/onrc/onos/core/packetservice/PacketModule.java
index 61fa735..ce79994 100644
--- a/src/main/java/net/onrc/onos/core/packetservice/PacketModule.java
+++ b/src/main/java/net/onrc/onos/core/packetservice/PacketModule.java
@@ -25,7 +25,7 @@
 import net.onrc.onos.core.topology.ITopologyService;
 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.topology.MutableTopology;
 import net.onrc.onos.core.util.Dpid;
 import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.SwitchPort;
@@ -51,7 +51,7 @@
     private final CopyOnWriteArrayList<IPacketListener> listeners;
 
     private IFloodlightProviderService floodlightProvider;
-    private Topology topology;
+    private MutableTopology mutableTopology;
     private IDatagridService datagrid;
     private IFlowPusherService flowPusher;
 
@@ -76,7 +76,7 @@
                 }
             }
             Multimap<Long, Short> outPorts = value.calculateOutPorts(
-                    localPorts, topology);
+                    localPorts, mutableTopology);
             sendPacketToSwitches(outPorts, value.getPacketData());
         }
 
@@ -164,13 +164,13 @@
         Switch topologySwitch;
         Port inPort;
         try {
-            topology.acquireReadLock();
+            mutableTopology.acquireReadLock();
             Dpid dpid = new Dpid(sw.getId());
             PortNumber p = PortNumber.uint16(inport);
-            topologySwitch = topology.getSwitch(dpid);
-            inPort = topology.getPort(dpid, p);
+            topologySwitch = mutableTopology.getSwitch(dpid);
+            inPort = mutableTopology.getPort(dpid, p);
         } finally {
-            topology.releaseReadLock();
+            mutableTopology.releaseReadLock();
         }
 
         if (topologySwitch == null || inPort == null) {
@@ -217,7 +217,7 @@
             throws FloodlightModuleException {
         floodlightProvider =
                 context.getServiceImpl(IFloodlightProviderService.class);
-        topology = context.getServiceImpl(ITopologyService.class)
+        mutableTopology = context.getServiceImpl(ITopologyService.class)
                 .getTopology();
         datagrid = context.getServiceImpl(IDatagridService.class);
         flowPusher = context.getServiceImpl(IFlowPusherService.class);
diff --git a/src/main/java/net/onrc/onos/core/packetservice/PacketOutNotification.java b/src/main/java/net/onrc/onos/core/packetservice/PacketOutNotification.java
index b92518a..2a577f3 100644
--- a/src/main/java/net/onrc/onos/core/packetservice/PacketOutNotification.java
+++ b/src/main/java/net/onrc/onos/core/packetservice/PacketOutNotification.java
@@ -3,7 +3,7 @@
 import java.io.Serializable;
 import java.util.Arrays;
 
-import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.topology.MutableTopology;
 
 import com.google.common.collect.Multimap;
 
@@ -54,11 +54,11 @@
      * instance.
      *
      * @param localPorts the map of locally-controlled ports
-     * @param topology an instance of the global topology
+     * @param mutableTopology an instance of the global topology
      * @return a multimap of ports that the packet should be sent out,
      * in the form
      * {@code {dpid1 => {portnum1, portnum2, ...}, dpid2 => {portnum1}, ...}}
      */
     public abstract Multimap<Long, Short> calculateOutPorts(
-            Multimap<Long, Short> localPorts, Topology topology);
+            Multimap<Long, Short> localPorts, MutableTopology mutableTopology);
 }
diff --git a/src/main/java/net/onrc/onos/core/packetservice/SinglePacketOutNotification.java b/src/main/java/net/onrc/onos/core/packetservice/SinglePacketOutNotification.java
index 0521434..e9bb7a4 100644
--- a/src/main/java/net/onrc/onos/core/packetservice/SinglePacketOutNotification.java
+++ b/src/main/java/net/onrc/onos/core/packetservice/SinglePacketOutNotification.java
@@ -1,6 +1,6 @@
 package net.onrc.onos.core.packetservice;
 
-import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.topology.MutableTopology;
 
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.Multimap;
@@ -72,7 +72,7 @@
 
     @Override
     public Multimap<Long, Short> calculateOutPorts(
-            Multimap<Long, Short> localPorts, Topology topology) {
+            Multimap<Long, Short> localPorts, MutableTopology mutableTopology) {
         Multimap<Long, Short> outPorts = HashMultimap.create();
 
         if (localPorts.containsEntry(outSwitch, outPort)) {
diff --git a/src/main/java/net/onrc/onos/core/topology/BaseTopology.java b/src/main/java/net/onrc/onos/core/topology/BaseTopology.java
new file mode 100644
index 0000000..6b2bef8
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/topology/BaseTopology.java
@@ -0,0 +1,217 @@
+package net.onrc.onos.core.topology;
+
+import java.util.Collection;
+
+import net.floodlightcontroller.util.MACAddress;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
+import net.onrc.onos.core.util.SwitchPort;
+
+// TODO move to appropriate package. under api??
+/**
+ * BaseTopology interface common to both {@link ImmutableTopology} and {@link MutableTopology}.
+ */
+public interface BaseTopology {
+
+    /**
+     * Gets the switch for a given switch DPID.
+     *
+     * @param dpid the switch dpid.
+     * @return the switch if found, otherwise null.
+     */
+    public Switch getSwitch(Dpid dpid);
+
+    /**
+     * Gets all switches in the network.
+     *
+     * @return all switches in the network.
+     */
+    public Iterable<Switch> getSwitches();
+
+    /**
+     * Gets the port on a switch.
+     *
+     * @param dpid   the switch DPID.
+     * @param portNumber the switch port number.
+     * @return the switch port if found, otherwise null.
+     */
+    public Port getPort(Dpid dpid, PortNumber portNumber);
+
+    /**
+     * Gets the port on a switch.
+     *
+     * @param port port identifier
+     * @return the switch port if found, otherwise null.
+     */
+    public Port getPort(SwitchPort port);
+
+    /**
+     * Gets all ports on a switch specified.
+     *
+     * @param dpid Switch dpid
+     * @return ports.
+     */
+    public Collection<Port> getPorts(Dpid dpid);
+
+    /**
+     * Gets the outgoing link from a switch port.
+     * <p/>
+     * FIXME As a temporary workaround, it will look for type "packet" and
+     * returns it if found, else return whichever link is found first.
+     *
+     * @param dpid   the switch DPID.
+     * @param portNumber the switch port number.
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getOutgoingLink(Dpid dpid, PortNumber portNumber);
+
+    /**
+     * Gets the outgoing link from a switch port.
+     *
+     * @param dpid   the switch DPID.
+     * @param portNumber the switch port number.
+     * @param type   type of the link
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getOutgoingLink(Dpid dpid, PortNumber portNumber, String type);
+
+    /**
+     * Gets the outgoing link from a switch port.
+     * <p/>
+     * FIXME As a temporary workaround, it will look for type "packet" and
+     * returns it if found, else return whichever link is found first.
+     *
+     * @param port port identifier
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getOutgoingLink(SwitchPort port);
+
+    /**
+     * Gets the outgoing link from a switch port.
+     *
+     * @param port port identifier
+     * @param type type of the link
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getOutgoingLink(SwitchPort port, String type);
+
+    /**
+     * Gets all the outgoing link from a switch port.
+     *
+     * @param port port identifier
+     * @return outgoing links
+     */
+    public Collection<Link> getOutgoingLinks(SwitchPort port);
+
+    /**
+     * Gets the incoming link to a switch port.
+     * <p/>
+     * FIXME As a temporary workaround, it will look for type "packet" and
+     * returns it if found, else return whichever link is found first.
+     *
+     * @param dpid   the switch DPID.
+     * @param portNumber the switch port number.
+     * @return the incoming link if found, otherwise null.
+     */
+    public Link getIncomingLink(Dpid dpid, PortNumber portNumber);
+
+    /**
+     * Gets the incoming link to a switch port.
+     * <p/>
+     * FIXME As a temporary workaround, it will look for type "packet" and
+     * returns it if found, else return whichever link is found first.
+     *
+     * @param dpid   the switch DPID.
+     * @param portNumber the switch port number.
+     * @param type type of the link
+     * @return the incoming link if found, otherwise null.
+     */
+    public Link getIncomingLink(Dpid dpid, PortNumber portNumber, String type);
+
+    /**
+     * Gets the incoming link to a switch port.
+     * <p/>
+     * FIXME As a temporary workaround, it will look for type "packet" and
+     * returns it if found, else return whichever link is found first.
+     *
+     * @param port port identifier
+     * @return the incoming link if found, otherwise null.
+     */
+    public Link getIncomingLink(SwitchPort port);
+
+    /**
+     * Gets the incoming link to a switch port.
+     *
+     * @param port port identifier
+     * @param type type of the link
+     * @return the incoming link if found, otherwise null.
+     */
+    public Link getIncomingLink(SwitchPort port, String type);
+
+    /**
+     * Gets all the incoming link from a switch port.
+     *
+     * @param port port identifier
+     * @return incoming links
+     */
+    public Collection<Link> getIncomingLinks(SwitchPort port);
+
+    /**
+     * Gets the outgoing link from a switch and a port to another switch and
+     * a port.
+     *
+     * @param srcDpid   the source switch DPID.
+     * @param srcPortNumber the source switch port number.
+     * @param dstDpid   the destination switch DPID.
+     * @param dstPortNumber the destination switch port number.
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getLink(Dpid srcDpid, PortNumber srcPortNumber,
+                        Dpid dstDpid, PortNumber dstPortNumber);
+
+    /**
+     * Gets the outgoing link from a switch and a port to another switch and
+     * a port.
+     *
+     * @param srcDpid   the source switch DPID.
+     * @param srcPortNumber the source switch port number.
+     * @param dstDpid   the destination switch DPID.
+     * @param dstPortNumber the destination switch port number.
+     * @param type      type of the link
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getLink(Dpid srcDpid, PortNumber srcPortNumber,
+                        Dpid dstDpid, PortNumber dstPortNumber,
+                        String type);
+
+    /**
+     * Gets all links in the network.
+     * <p/>
+     *
+     * @return all links in the network.
+     */
+    public Iterable<Link> getLinks();
+
+    /**
+     * Gets the network device for a given MAC address.
+     *
+     * @param address the MAC address to use.
+     * @return the network device for the MAC address if found, otherwise null.
+     */
+    public Host getHostByMac(MACAddress address);
+
+    /**
+     * Gets all devices in the network.
+     *
+     * @return all devices in the network
+     */
+    public Iterable<Host> getHosts();
+
+    /**
+     * Gets all devices on specified port.
+     *
+     * @param port port which the device is attached
+     * @return all devices attached to the port.
+     */
+    public Collection<Host> getHosts(SwitchPort port);
+}
diff --git a/src/main/java/net/onrc/onos/core/topology/ITopologyService.java b/src/main/java/net/onrc/onos/core/topology/ITopologyService.java
index ecb1212..26b6212 100644
--- a/src/main/java/net/onrc/onos/core/topology/ITopologyService.java
+++ b/src/main/java/net/onrc/onos/core/topology/ITopologyService.java
@@ -11,7 +11,7 @@
      *
      * @return the global Topology object
      */
-    public Topology getTopology();
+    public MutableTopology getTopology();
 
     /**
      * Adds a listener for topology events.
diff --git a/src/main/java/net/onrc/onos/core/topology/ImmutableTopology.java b/src/main/java/net/onrc/onos/core/topology/ImmutableTopology.java
index 0f7ab96..ed5678e 100644
--- a/src/main/java/net/onrc/onos/core/topology/ImmutableTopology.java
+++ b/src/main/java/net/onrc/onos/core/topology/ImmutableTopology.java
@@ -1,216 +1,10 @@
 package net.onrc.onos.core.topology;
 
-import java.util.Collection;
-
-import net.floodlightcontroller.util.MACAddress;
-import net.onrc.onos.core.util.Dpid;
-import net.onrc.onos.core.util.PortNumber;
-import net.onrc.onos.core.util.SwitchPort;
-
+//TODO move to appropriate package under api
 /**
- * ImmutableTopology.
+ * ImmutableTopology, which could be accessed without locking, etc.
  */
-public interface ImmutableTopology {
+public interface ImmutableTopology extends BaseTopology {
 
-    /**
-     * Gets the switch for a given switch DPID.
-     *
-     * @param dpid the switch dpid.
-     * @return the switch if found, otherwise null.
-     */
-    public Switch getSwitch(Dpid dpid);
-
-    /**
-     * Gets all switches in the network.
-     *
-     * @return all switches in the network.
-     */
-    public Iterable<Switch> getSwitches();
-
-    /**
-     * Gets the port on a switch.
-     *
-     * @param dpid   the switch DPID.
-     * @param portNumber the switch port number.
-     * @return the switch port if found, otherwise null.
-     */
-    public Port getPort(Dpid dpid, PortNumber portNumber);
-
-    /**
-     * Gets the port on a switch.
-     *
-     * @param port port identifier
-     * @return the switch port if found, otherwise null.
-     */
-    public Port getPort(SwitchPort port);
-
-    /**
-     * Gets all ports on a switch specified.
-     *
-     * @param dpid Switch dpid
-     * @return ports.
-     */
-    public Collection<Port> getPorts(Dpid dpid);
-
-    /**
-     * Gets the outgoing link from a switch port.
-     * <p/>
-     * FIXME As a temporary workaround, it will look for type "packet" and
-     * returns it if found, else return whichever link is found first.
-     *
-     * @param dpid   the switch DPID.
-     * @param portNumber the switch port number.
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getOutgoingLink(Dpid dpid, PortNumber portNumber);
-
-    /**
-     * Gets the outgoing link from a switch port.
-     *
-     * @param dpid   the switch DPID.
-     * @param portNumber the switch port number.
-     * @param type   type of the link
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getOutgoingLink(Dpid dpid, PortNumber portNumber, String type);
-
-    /**
-     * Gets the outgoing link from a switch port.
-     * <p/>
-     * FIXME As a temporary workaround, it will look for type "packet" and
-     * returns it if found, else return whichever link is found first.
-     *
-     * @param port port identifier
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getOutgoingLink(SwitchPort port);
-
-    /**
-     * Gets the outgoing link from a switch port.
-     *
-     * @param port port identifier
-     * @param type type of the link
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getOutgoingLink(SwitchPort port, String type);
-
-    /**
-     * Gets all the outgoing link from a switch port.
-     *
-     * @param port port identifier
-     * @return outgoing links
-     */
-    public Collection<Link> getOutgoingLinks(SwitchPort port);
-
-    /**
-     * Gets the incoming link to a switch port.
-     * <p/>
-     * FIXME As a temporary workaround, it will look for type "packet" and
-     * returns it if found, else return whichever link is found first.
-     *
-     * @param dpid   the switch DPID.
-     * @param portNumber the switch port number.
-     * @return the incoming link if found, otherwise null.
-     */
-    public Link getIncomingLink(Dpid dpid, PortNumber portNumber);
-
-    /**
-     * Gets the incoming link to a switch port.
-     * <p/>
-     * FIXME As a temporary workaround, it will look for type "packet" and
-     * returns it if found, else return whichever link is found first.
-     *
-     * @param dpid   the switch DPID.
-     * @param portNumber the switch port number.
-     * @param type type of the link
-     * @return the incoming link if found, otherwise null.
-     */
-    public Link getIncomingLink(Dpid dpid, PortNumber portNumber, String type);
-
-    /**
-     * Gets the incoming link to a switch port.
-     * <p/>
-     * FIXME As a temporary workaround, it will look for type "packet" and
-     * returns it if found, else return whichever link is found first.
-     *
-     * @param port port identifier
-     * @return the incoming link if found, otherwise null.
-     */
-    public Link getIncomingLink(SwitchPort port);
-
-    /**
-     * Gets the incoming link to a switch port.
-     *
-     * @param port port identifier
-     * @param type type of the link
-     * @return the incoming link if found, otherwise null.
-     */
-    public Link getIncomingLink(SwitchPort port, String type);
-
-    /**
-     * Gets all the incoming link from a switch port.
-     *
-     * @param port port identifier
-     * @return incoming links
-     */
-    public Collection<Link> getIncomingLinks(SwitchPort port);
-
-    /**
-     * Gets the outgoing link from a switch and a port to another switch and
-     * a port.
-     *
-     * @param srcDpid   the source switch DPID.
-     * @param srcPortNumber the source switch port number.
-     * @param dstDpid   the destination switch DPID.
-     * @param dstPortNumber the destination switch port number.
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getLink(Dpid srcDpid, PortNumber srcPortNumber,
-                        Dpid dstDpid, PortNumber dstPortNumber);
-
-    /**
-     * Gets the outgoing link from a switch and a port to another switch and
-     * a port.
-     *
-     * @param srcDpid   the source switch DPID.
-     * @param srcPortNumber the source switch port number.
-     * @param dstDpid   the destination switch DPID.
-     * @param dstPortNumber the destination switch port number.
-     * @param type      type of the link
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getLink(Dpid srcDpid, PortNumber srcPortNumber,
-                        Dpid dstDpid, PortNumber dstPortNumber,
-                        String type);
-
-    /**
-     * Gets all links in the network.
-     * <p/>
-     *
-     * @return all links in the network.
-     */
-    public Iterable<Link> getLinks();
-
-    /**
-     * Gets the network device for a given MAC address.
-     *
-     * @param address the MAC address to use.
-     * @return the network device for the MAC address if found, otherwise null.
-     */
-    public Host getHostByMac(MACAddress address);
-
-    /**
-     * Gets all devices in the network.
-     *
-     * @return all devices in the network
-     */
-    public Iterable<Host> getHosts();
-
-    /**
-     * Gets all devices on specified port.
-     *
-     * @param port port which the device is attached
-     * @return all devices attached to the port.
-     */
-    public Collection<Host> getHosts(SwitchPort port);
+    // no additional interface needed.
 }
diff --git a/src/main/java/net/onrc/onos/core/topology/Topology.java b/src/main/java/net/onrc/onos/core/topology/MutableTopology.java
similarity index 72%
rename from src/main/java/net/onrc/onos/core/topology/Topology.java
rename to src/main/java/net/onrc/onos/core/topology/MutableTopology.java
index 464f463..7372bcb 100644
--- a/src/main/java/net/onrc/onos/core/topology/Topology.java
+++ b/src/main/java/net/onrc/onos/core/topology/MutableTopology.java
@@ -4,13 +4,20 @@
 
 import org.codehaus.jackson.map.annotate.JsonSerialize;
 
+//TODO move to appropriate package under api
 /**
+ * MutableTopology, which this instance can be updated to new view.
+ * <p>
+ * Requires read-lock to access any information on this topology view.
+ * <p>
+ * Note: This is still read-only view of the topology.
+ * <p>
  * The northbound interface to the topology. This interface
  * is presented to the rest of ONOS. It is currently read-only, as we want
  * only the discovery modules to be allowed to modify the topology.
  */
 @JsonSerialize(using = TopologySerializer.class)
-public interface Topology extends ImmutableTopology {
+public interface MutableTopology extends BaseTopology {
 
     /**
      * Acquire a read lock on the entire topology. The topology will not
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyImpl.java b/src/main/java/net/onrc/onos/core/topology/TopologyImpl.java
index 5411a1b..b50bf48 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyImpl.java
@@ -33,7 +33,7 @@
 /**
  * Class to represent an instance of Topology Snapshot.
  */
-public class TopologyImpl implements Topology, TopologyInternal {
+public class TopologyImpl implements MutableTopology, TopologyInternal {
 
     private static final Logger log = LoggerFactory.getLogger(TopologyImpl.class);
 
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyInternal.java b/src/main/java/net/onrc/onos/core/topology/TopologyInternal.java
index e712795..292e260 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyInternal.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyInternal.java
@@ -8,10 +8,13 @@
 import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.SwitchPort;
 
+// FIXME This Class hierarchy is wrong.
+// - We need BaseTopology + access to self-contained *Event objects.
+//   abstract class implementing BaseTopology?
 /**
  * Interface to reference internal self-contained elements.
  */
-public interface TopologyInternal extends Topology {
+public interface TopologyInternal extends MutableTopology {
     /**
      * Gets a SwitchEvent.
      *
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyManager.java b/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
index 31933e4..62228f0 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
@@ -130,11 +130,11 @@
     }
 
     /**
-     * Get the Topology.
+     * Get the MutableTopology.
      *
-     * @return the Topology.
+     * @return the MutableTopology.
      */
-    Topology getTopology() {
+    MutableTopology getTopology() {
         return topology;
     }
 
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyModule.java b/src/main/java/net/onrc/onos/core/topology/TopologyModule.java
index 07ba2cf..7913fc5 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyModule.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyModule.java
@@ -67,7 +67,7 @@
     }
 
     @Override
-    public Topology getTopology() {
+    public MutableTopology getTopology() {
         return topologyManager.getTopology();
     }
 
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java b/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java
index 7675aae..d27d68e 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java
@@ -69,7 +69,7 @@
 
     private IHostService hostService;
 
-    private Topology topology;
+    private MutableTopology mutableTopology;
 
     private static final String ENABLE_CLEANUP_PROPERTY = "EnableCleanup";
     private boolean cleanupEnabled = true;
@@ -142,7 +142,7 @@
          * registry.
          */
         private void switchCleanup() {
-            Iterable<Switch> switches = topology.getSwitches();
+            Iterable<Switch> switches = mutableTopology.getSwitches();
 
             if (log.isTraceEnabled()) {
                 log.trace("Checking for inactive switches");
@@ -440,7 +440,7 @@
                                 byte[].class,
                                 TopologyEvent.class);
 
-        topology = topologyService.getTopology();
+        mutableTopology = topologyService.getTopology();
 
         // Run the cleanup thread
         String enableCleanup =
diff --git a/src/main/java/net/onrc/onos/core/topology/web/HostsResource.java b/src/main/java/net/onrc/onos/core/topology/web/HostsResource.java
index 301fb9e..70db064 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/HostsResource.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/HostsResource.java
@@ -2,7 +2,7 @@
 
 import static net.onrc.onos.core.topology.web.TopologyResource.eval;
 import net.onrc.onos.core.topology.ITopologyService;
-import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.topology.MutableTopology;
 
 import org.restlet.representation.Representation;
 import org.restlet.resource.Get;
@@ -24,12 +24,12 @@
             (ITopologyService) getContext().getAttributes()
                 .get(ITopologyService.class.getCanonicalName());
 
-        Topology topology = topologyService.getTopology();
-        topology.acquireReadLock();
+        MutableTopology mutableTopology = topologyService.getTopology();
+        mutableTopology.acquireReadLock();
         try {
-            return eval(toRepresentation(topology.getHosts(), null));
+            return eval(toRepresentation(mutableTopology.getHosts(), null));
         } finally {
-            topology.releaseReadLock();
+            mutableTopology.releaseReadLock();
         }
     }
 }
diff --git a/src/main/java/net/onrc/onos/core/topology/web/LinksResource.java b/src/main/java/net/onrc/onos/core/topology/web/LinksResource.java
index 6d910a8..d5fc52c 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/LinksResource.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/LinksResource.java
@@ -2,7 +2,7 @@
 
 import static net.onrc.onos.core.topology.web.TopologyResource.eval;
 import net.onrc.onos.core.topology.ITopologyService;
-import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.topology.MutableTopology;
 
 import org.restlet.representation.Representation;
 import org.restlet.resource.Get;
@@ -24,12 +24,12 @@
             (ITopologyService) getContext().getAttributes()
                 .get(ITopologyService.class.getCanonicalName());
 
-        Topology topology = topologyService.getTopology();
-        topology.acquireReadLock();
+        MutableTopology mutableTopology = topologyService.getTopology();
+        mutableTopology.acquireReadLock();
         try {
-            return eval(toRepresentation(topology.getLinks(), null));
+            return eval(toRepresentation(mutableTopology.getLinks(), null));
         } finally {
-            topology.releaseReadLock();
+            mutableTopology.releaseReadLock();
         }
     }
 }
diff --git a/src/main/java/net/onrc/onos/core/topology/web/SwitchesResource.java b/src/main/java/net/onrc/onos/core/topology/web/SwitchesResource.java
index dfb381e..3eeadbb 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/SwitchesResource.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/SwitchesResource.java
@@ -2,7 +2,7 @@
 
 import static net.onrc.onos.core.topology.web.TopologyResource.eval;
 import net.onrc.onos.core.topology.ITopologyService;
-import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.topology.MutableTopology;
 
 import org.restlet.representation.Representation;
 import org.restlet.resource.Get;
@@ -24,12 +24,12 @@
             (ITopologyService) getContext().getAttributes()
                 .get(ITopologyService.class.getCanonicalName());
 
-        Topology topology = topologyService.getTopology();
-        topology.acquireReadLock();
+        MutableTopology mutableTopology = topologyService.getTopology();
+        mutableTopology.acquireReadLock();
         try {
-            return eval(toRepresentation(topology.getSwitches(), null));
+            return eval(toRepresentation(mutableTopology.getSwitches(), null));
         } finally {
-            topology.releaseReadLock();
+            mutableTopology.releaseReadLock();
         }
     }
 }
diff --git a/src/main/java/net/onrc/onos/core/topology/web/TopologyResource.java b/src/main/java/net/onrc/onos/core/topology/web/TopologyResource.java
index 8068552..7406075 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/TopologyResource.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/TopologyResource.java
@@ -1,7 +1,7 @@
 package net.onrc.onos.core.topology.web;
 
 import net.onrc.onos.core.topology.ITopologyService;
-import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.topology.MutableTopology;
 
 import org.restlet.engine.io.BufferingRepresentation;
 import org.restlet.representation.Representation;
@@ -23,12 +23,12 @@
             (ITopologyService) getContext().getAttributes()
                 .get(ITopologyService.class.getCanonicalName());
 
-        Topology topology = topologyService.getTopology();
-        topology.acquireReadLock();
+        MutableTopology mutableTopology = topologyService.getTopology();
+        mutableTopology.acquireReadLock();
         try {
-            return eval(toRepresentation(topology, null));
+            return eval(toRepresentation(mutableTopology, null));
         } finally {
-            topology.releaseReadLock();
+            mutableTopology.releaseReadLock();
         }
     }
 
diff --git a/src/main/java/net/onrc/onos/core/topology/web/serializers/TopologySerializer.java b/src/main/java/net/onrc/onos/core/topology/web/serializers/TopologySerializer.java
index b241ee4..2e21ab6 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/serializers/TopologySerializer.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/serializers/TopologySerializer.java
@@ -5,7 +5,7 @@
 import net.onrc.onos.core.topology.Host;
 import net.onrc.onos.core.topology.Link;
 import net.onrc.onos.core.topology.Switch;
-import net.onrc.onos.core.topology.Topology;
+import net.onrc.onos.core.topology.MutableTopology;
 
 import org.codehaus.jackson.JsonGenerator;
 import org.codehaus.jackson.map.SerializerProvider;
@@ -14,25 +14,25 @@
 /**
  * JSON serializer for Topology objects.
  */
-public class TopologySerializer extends SerializerBase<Topology> {
+public class TopologySerializer extends SerializerBase<MutableTopology> {
     /**
      * Default constructor.
      */
     public TopologySerializer() {
-        super(Topology.class);
+        super(MutableTopology.class);
     }
 
     /**
      * Serializes a Topology object in JSON.  The resulting JSON contains the
      * switches, links and ports provided by the Topology object.
      *
-     * @param topology the Topology that is being converted to JSON
+     * @param mutableTopology the Topology that is being converted to JSON
      * @param jsonGenerator generator to place the serialized JSON into
      * @param serializerProvider unused but required for method override
      * @throws IOException if the JSON serialization process fails
      */
     @Override
-    public void serialize(Topology topology,
+    public void serialize(MutableTopology mutableTopology,
                           JsonGenerator jsonGenerator,
                           SerializerProvider serializerProvider)
         throws IOException {
@@ -42,21 +42,21 @@
 
         // Output the switches array
         jsonGenerator.writeArrayFieldStart("switches");
-        for (final Switch swtch : topology.getSwitches()) {
+        for (final Switch swtch : mutableTopology.getSwitches()) {
             jsonGenerator.writeObject(swtch);
         }
         jsonGenerator.writeEndArray();
 
         // Output the links array
         jsonGenerator.writeArrayFieldStart("links");
-        for (final Link link : topology.getLinks()) {
+        for (final Link link : mutableTopology.getLinks()) {
             jsonGenerator.writeObject(link);
         }
         jsonGenerator.writeEndArray();
 
         // Output the hosts array
         jsonGenerator.writeArrayFieldStart("hosts");
-        for (final Host host : topology.getHosts()) {
+        for (final Host host : mutableTopology.getHosts()) {
             jsonGenerator.writeObject(host);
         }
         jsonGenerator.writeEndArray();