Topology related util class.
- We may need them to adapt Immutable*Topology as Mutable*Topology.
Part of ONOS-1925
Change-Id: I5782ef9f9b9441946b112e374a87059ab0a0df01
diff --git a/src/main/java/net/onrc/onos/core/topology/ImmutableInternalTopologyWrapper.java b/src/main/java/net/onrc/onos/core/topology/ImmutableInternalTopologyWrapper.java
new file mode 100644
index 0000000..8a2a89a
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/topology/ImmutableInternalTopologyWrapper.java
@@ -0,0 +1,119 @@
+package net.onrc.onos.core.topology;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Collection;
+
+import net.floodlightcontroller.util.MACAddress;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.LinkTuple;
+import net.onrc.onos.core.util.OnosInstanceId;
+import net.onrc.onos.core.util.PortNumber;
+import net.onrc.onos.core.util.SwitchPort;
+
+/**
+ * Wrapper to access {@link ImmutableInternalTopology} as {@link MutableInternalTopology}.
+ */
+public final class ImmutableInternalTopologyWrapper implements MutableInternalTopology {
+
+ private final ImmutableInternalTopology wrapped;
+
+ /**
+ * Constructor.
+ *
+ * @param toWrap {@link ImmutableInternalTopology} to wrap
+ */
+ public ImmutableInternalTopologyWrapper(ImmutableInternalTopology toWrap) {
+ this.wrapped = checkNotNull(toWrap);
+ }
+
+ @Override
+ public void acquireReadLock() {
+ // no-op
+ }
+
+ @Override
+ public void releaseReadLock() {
+ // no-op
+ }
+
+ @Override
+ public SwitchEvent getSwitchEvent(Dpid dpid) {
+ return wrapped.getSwitchEvent(dpid);
+ }
+
+ @Override
+ public Collection<SwitchEvent> getAllSwitchEvents() {
+ return wrapped.getAllSwitchEvents();
+ }
+
+ @Override
+ public PortEvent getPortEvent(SwitchPort port) {
+ return wrapped.getPortEvent(port);
+ }
+
+ @Override
+ public PortEvent getPortEvent(Dpid dpid, PortNumber portNumber) {
+ return wrapped.getPortEvent(dpid, portNumber);
+ }
+
+ @Override
+ public Collection<PortEvent> getPortEvents(Dpid dpid) {
+ return wrapped.getPortEvents(dpid);
+ }
+
+ @Override
+ public Collection<PortEvent> getAllPortEvents() {
+ return wrapped.getAllPortEvents();
+ }
+
+ @Override
+ public LinkEvent getLinkEvent(LinkTuple linkId) {
+ return wrapped.getLinkEvent(linkId);
+ }
+
+ @Override
+ public LinkEvent getLinkEvent(LinkTuple linkId, String type) {
+ return wrapped.getLinkEvent(linkId, type);
+ }
+
+ @Override
+ public Collection<LinkEvent> getLinkEvents(LinkTuple linkId) {
+ return wrapped.getLinkEvents(linkId);
+ }
+
+ @Override
+ public Collection<LinkEvent> getAllLinkEvents() {
+ return wrapped.getAllLinkEvents();
+ }
+
+ @Override
+ public HostEvent getHostEvent(MACAddress mac) {
+ return wrapped.getHostEvent(mac);
+ }
+
+ @Override
+ public Collection<HostEvent> getAllHostEvents() {
+ return wrapped.getAllHostEvents();
+ }
+
+ @Override
+ public Collection<LinkEvent> getLinkEventsFrom(SwitchPort srcPort) {
+ return wrapped.getLinkEventsFrom(srcPort);
+ }
+
+ @Override
+ public Collection<LinkEvent> getLinkEventsTo(SwitchPort dstPort) {
+ return wrapped.getLinkEventsTo(dstPort);
+ }
+
+ @Override
+ public Collection<HostEvent> getHostEvents(SwitchPort port) {
+ return wrapped.getHostEvents(port);
+ }
+
+ @Override
+ public OnosInstanceId getSwitchMaster(Dpid dpid) {
+ return wrapped.getSwitchMaster(dpid);
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/topology/ImmutableTopologyWrapper.java b/src/main/java/net/onrc/onos/core/topology/ImmutableTopologyWrapper.java
new file mode 100644
index 0000000..c44dc3b
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/topology/ImmutableTopologyWrapper.java
@@ -0,0 +1,150 @@
+package net.onrc.onos.core.topology;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Collection;
+
+import net.floodlightcontroller.util.MACAddress;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.OnosInstanceId;
+import net.onrc.onos.core.util.PortNumber;
+import net.onrc.onos.core.util.SwitchPort;
+
+/**
+ * Wrapper to access {@link ImmutableTopology} as {@link MutableTopology}.
+ */
+public final class ImmutableTopologyWrapper implements MutableTopology {
+
+ private final ImmutableTopology wrapped;
+
+ /**
+ * Constructor.
+ *
+ * @param toWrap {@link ImmutableTopology} to wrap
+ */
+ public ImmutableTopologyWrapper(ImmutableTopology toWrap) {
+ this.wrapped = checkNotNull(toWrap);
+ }
+
+ @Override
+ public void acquireReadLock() {
+ // no-op
+ }
+
+ @Override
+ public void releaseReadLock() {
+ // no-op
+ }
+
+ @Override
+ public Switch getSwitch(Dpid dpid) {
+ return wrapped.getSwitch(dpid);
+ }
+
+ @Override
+ public Iterable<Switch> getSwitches() {
+ return wrapped.getSwitches();
+ }
+
+ @Override
+ public Port getPort(Dpid dpid, PortNumber portNumber) {
+ return wrapped.getPort(dpid, portNumber);
+ }
+
+ @Override
+ public Port getPort(SwitchPort port) {
+ return wrapped.getPort(port);
+ }
+
+ @Override
+ public Collection<Port> getPorts(Dpid dpid) {
+ return wrapped.getPorts(dpid);
+ }
+
+ @Override
+ public Link getOutgoingLink(Dpid dpid, PortNumber portNumber) {
+ return wrapped.getOutgoingLink(dpid, portNumber);
+ }
+
+ @Override
+ public Link getOutgoingLink(Dpid dpid, PortNumber portNumber, String type) {
+ return wrapped.getOutgoingLink(dpid, portNumber, type);
+ }
+
+ @Override
+ public Link getOutgoingLink(SwitchPort port) {
+ return wrapped.getOutgoingLink(port);
+ }
+
+ @Override
+ public Link getOutgoingLink(SwitchPort port, String type) {
+ return wrapped.getOutgoingLink(port, type);
+ }
+
+ @Override
+ public Collection<Link> getOutgoingLinks(SwitchPort port) {
+ return wrapped.getOutgoingLinks(port);
+ }
+
+ @Override
+ public Link getIncomingLink(Dpid dpid, PortNumber portNumber) {
+ return wrapped.getIncomingLink(dpid, portNumber);
+ }
+
+ @Override
+ public Link getIncomingLink(Dpid dpid, PortNumber portNumber, String type) {
+ return wrapped.getIncomingLink(dpid, portNumber, type);
+ }
+
+ @Override
+ public Link getIncomingLink(SwitchPort port) {
+ return wrapped.getIncomingLink(port);
+ }
+
+ @Override
+ public Link getIncomingLink(SwitchPort port, String type) {
+ return wrapped.getIncomingLink(port, type);
+ }
+
+ @Override
+ public Collection<Link> getIncomingLinks(SwitchPort port) {
+ return wrapped.getIncomingLinks(port);
+ }
+
+ @Override
+ public Link getLink(Dpid srcDpid, PortNumber srcPortNumber, Dpid dstDpid,
+ PortNumber dstPortNumber) {
+ return wrapped.getLink(srcDpid, srcPortNumber, dstDpid, dstPortNumber);
+ }
+
+ @Override
+ public Link getLink(Dpid srcDpid, PortNumber srcPortNumber, Dpid dstDpid,
+ PortNumber dstPortNumber, String type) {
+ return wrapped.getLink(srcDpid, srcPortNumber, dstDpid, dstPortNumber, type);
+ }
+
+ @Override
+ public Iterable<Link> getLinks() {
+ return wrapped.getLinks();
+ }
+
+ @Override
+ public Host getHostByMac(MACAddress address) {
+ return wrapped.getHostByMac(address);
+ }
+
+ @Override
+ public Iterable<Host> getHosts() {
+ return wrapped.getHosts();
+ }
+
+ @Override
+ public Collection<Host> getHosts(SwitchPort port) {
+ return wrapped.getHosts(port);
+ }
+
+ @Override
+ public OnosInstanceId getSwitchMaster(Dpid dpid) {
+ return wrapped.getSwitchMaster(dpid);
+ }
+}