Fix checkstyle whitespace issues - WHITESPACE ONLY
Change-Id: Ic205c1afd639c6008d61d9de95cb764eeb6238ca
diff --git a/src/main/java/net/onrc/onos/core/topology/Device.java b/src/main/java/net/onrc/onos/core/topology/Device.java
index 25a27be..48035b3 100644
--- a/src/main/java/net/onrc/onos/core/topology/Device.java
+++ b/src/main/java/net/onrc/onos/core/topology/Device.java
@@ -7,12 +7,11 @@
/**
* Interface of Device Object exposed to the "NB" read-only Topology.
- *
+ * <p/>
* TODO What a Device Object represent is unclear at the moment.
- *
+ * <p/>
* Everything returned by these interfaces must be either Unmodifiable view,
* immutable object, or a copy of the original "SB" In-memory Topology.
- *
*/
public interface Device {
/**
@@ -31,7 +30,7 @@
/**
* Get the device attachment points.
- *
+ * <p/>
* Add requirement for Iteration order? Latest observed port first.
*
* @return the device attachment points.
@@ -40,7 +39,7 @@
/**
* Get the device last seen time.
- *
+ * <p/>
* TODO: what is the time definition?
*
* @return the device last seen time.
diff --git a/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java b/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java
index f7331a0..48d50e4 100644
--- a/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java
@@ -12,16 +12,15 @@
/**
* Self-contained Device event(s) Object
- *
+ * <p/>
* Device event differ from other events.
* Device Event represent add/remove of attachmentPoint or ipAddress.
* Not add/remove of the DeviceObject itself.
- *
+ * <p/>
* Multiple attachmentPoints can be specified to batch events into 1 object.
* Each should be treated as independent events.
- *
+ * <p/>
* TODO: We probably want common base class/interface for Self-Contained Event Object
- *
*/
public class DeviceEvent {
private final MACAddress mac;
@@ -34,24 +33,24 @@
*/
@Deprecated
public DeviceEvent() {
- mac = null;
+ mac = null;
}
public DeviceEvent(MACAddress mac) {
- if (mac == null) {
- throw new IllegalArgumentException("Device mac cannot be null");
- }
- this.mac = mac;
- this.attachmentPoints = new LinkedList<>();
- this.ipAddresses = new HashSet<>();
+ if (mac == null) {
+ throw new IllegalArgumentException("Device mac cannot be null");
+ }
+ this.mac = mac;
+ this.attachmentPoints = new LinkedList<>();
+ this.ipAddresses = new HashSet<>();
}
public MACAddress getMac() {
- return mac;
+ return mac;
}
public List<SwitchPort> getAttachmentPoints() {
- return attachmentPoints;
+ return attachmentPoints;
}
public Set<InetAddress> getIpAddresses() {
@@ -59,46 +58,46 @@
}
public void setAttachmentPoints(List<SwitchPort> attachmentPoints) {
- this.attachmentPoints = attachmentPoints;
+ this.attachmentPoints = attachmentPoints;
}
public void addAttachmentPoint(SwitchPort attachmentPoint) {
- // may need to maintain uniqness
- this.attachmentPoints.add(0, attachmentPoint);
+ // may need to maintain uniqness
+ this.attachmentPoints.add(0, attachmentPoint);
}
public boolean addIpAddress(InetAddress addr) {
- return this.ipAddresses.add(addr);
+ return this.ipAddresses.add(addr);
}
public boolean removeIpAddress(InetAddress addr) {
- return this.ipAddresses.remove(addr);
+ return this.ipAddresses.remove(addr);
}
@Override
public String toString() {
- return "[DeviceEvent " + mac + " attachmentPoints:" + attachmentPoints + " ipAddr:" + ipAddresses + "]";
+ return "[DeviceEvent " + mac + " attachmentPoints:" + attachmentPoints + " ipAddr:" + ipAddresses + "]";
}
// Assuming mac is unique cluster-wide
public static ByteBuffer getDeviceID(final byte[] mac) {
- return (ByteBuffer) ByteBuffer.allocate(2 + mac.length).putChar('D').put(mac).flip();
+ return (ByteBuffer) ByteBuffer.allocate(2 + mac.length).putChar('D').put(mac).flip();
}
public byte[] getID() {
- return getDeviceID(mac.toBytes()).array();
+ return getDeviceID(mac.toBytes()).array();
}
public ByteBuffer getIDasByteBuffer() {
- return getDeviceID(mac.toBytes());
+ return getDeviceID(mac.toBytes());
}
- public long getLastSeenTime() {
- return lastSeenTime;
- }
+ public long getLastSeenTime() {
+ return lastSeenTime;
+ }
- public void setLastSeenTime(long lastSeenTime) {
- this.lastSeenTime = lastSeenTime;
- }
+ public void setLastSeenTime(long lastSeenTime) {
+ this.lastSeenTime = lastSeenTime;
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/DeviceImpl.java b/src/main/java/net/onrc/onos/core/topology/DeviceImpl.java
index 5b96e08..6a4f16b 100644
--- a/src/main/java/net/onrc/onos/core/topology/DeviceImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/DeviceImpl.java
@@ -20,71 +20,75 @@
private long lastSeenTime;
public DeviceImpl(NetworkGraph graph, MACAddress mac) {
- super(graph);
- this.macAddr = mac;
- this.attachmentPoints = new LinkedList<>();
- this.ipAddresses = new HashSet<>();
+ super(graph);
+ this.macAddr = mac;
+ this.attachmentPoints = new LinkedList<>();
+ this.ipAddresses = new HashSet<>();
}
@Override
public MACAddress getMacAddress() {
- return this.macAddr;
+ return this.macAddr;
}
@Override
public Collection<InetAddress> getIpAddress() {
- return Collections.unmodifiableSet(ipAddresses);
+ return Collections.unmodifiableSet(ipAddresses);
}
@Override
public Iterable<Port> getAttachmentPoints() {
- return Collections.unmodifiableList(this.attachmentPoints);
+ return Collections.unmodifiableList(this.attachmentPoints);
}
@Override
public long getLastSeenTime() {
- return lastSeenTime;
+ return lastSeenTime;
}
@Override
public String toString() {
- return macAddr.toString();
+ return macAddr.toString();
}
-
+
void setLastSeenTime(long lastSeenTime) {
- this.lastSeenTime = lastSeenTime;
+ this.lastSeenTime = lastSeenTime;
}
/**
* Only {@link TopologyManager} should use this method
+ *
* @param p
*/
void addAttachmentPoint(Port p) {
- this.attachmentPoints.remove(p);
- this.attachmentPoints.addFirst(p);
+ this.attachmentPoints.remove(p);
+ this.attachmentPoints.addFirst(p);
}
/**
* Only {@link TopologyManager} should use this method
+ *
* @param p
*/
boolean removeAttachmentPoint(Port p) {
- return this.attachmentPoints.remove(p);
+ return this.attachmentPoints.remove(p);
}
/**
* Only {@link TopologyManager} should use this method
+ *
* @param p
*/
boolean addIpAddress(InetAddress addr) {
- return this.ipAddresses.add(addr);
+ return this.ipAddresses.add(addr);
}
/**
* Only {@link TopologyManager} should use this method
+ *
* @param p
*/
boolean removeIpAddress(InetAddress addr) {
- return this.ipAddresses.remove(addr);
+ return this.ipAddresses.remove(addr);
}
}
diff --git a/src/main/java/net/onrc/onos/core/topology/INetworkGraphListener.java b/src/main/java/net/onrc/onos/core/topology/INetworkGraphListener.java
index c64b126..9e53222 100644
--- a/src/main/java/net/onrc/onos/core/topology/INetworkGraphListener.java
+++ b/src/main/java/net/onrc/onos/core/topology/INetworkGraphListener.java
@@ -9,36 +9,36 @@
public interface INetworkGraphListener {
/**
* Network Graph events.
- *
+ * <p/>
* The recommended ordering rules for applying/processing the events is:
- * (a) Process "added" events before "removed" events.
- * (b) The ordering of the "added" events should be:
- * addedSwitchEvents, addedPortEvents, addedLinkEvents,
- * addedDeviceEvents
- * The above ordering guarantees that adding a port for example
- * will be processed after the corresponding switch itself is added.
- * (c) The ordering of the "removed" events should be:
- * removedDeviceEvents, removedLinkEvents, removedPortEvents,
- * removedSwitchEvents
- * The above ordering guarantees that removing a port for example
- * will be processed before the corresponding switch itself is
- * removed.
+ * (a) Process "added" events before "removed" events.
+ * (b) The ordering of the "added" events should be:
+ * addedSwitchEvents, addedPortEvents, addedLinkEvents,
+ * addedDeviceEvents
+ * The above ordering guarantees that adding a port for example
+ * will be processed after the corresponding switch itself is added.
+ * (c) The ordering of the "removed" events should be:
+ * removedDeviceEvents, removedLinkEvents, removedPortEvents,
+ * removedSwitchEvents
+ * The above ordering guarantees that removing a port for example
+ * will be processed before the corresponding switch itself is
+ * removed.
*
- * @param addedSwitchEvents the Added Switch Events.
+ * @param addedSwitchEvents the Added Switch Events.
* @param removedSwitchEvents the Removed Switch Events.
- * @param addedPortEvents the Added Port Events.
- * @param removedPortEvents the Removed Port Events.
- * @param addedLinkEvents the Added Link Events.
- * @param removedLinkEvents the Removed Link Events.
- * @param addedDeviceEvents the Added Device Events.
+ * @param addedPortEvents the Added Port Events.
+ * @param removedPortEvents the Removed Port Events.
+ * @param addedLinkEvents the Added Link Events.
+ * @param removedLinkEvents the Removed Link Events.
+ * @param addedDeviceEvents the Added Device Events.
* @param removedDeviceEvents the Removed Device Events.
*/
public void networkGraphEvents(Collection<SwitchEvent> addedSwitchEvents,
- Collection<SwitchEvent> removedSwitchEvents,
- Collection<PortEvent> addedPortEvents,
- Collection<PortEvent> removedPortEvents,
- Collection<LinkEvent> addedLinkEvents,
- Collection<LinkEvent> removedLinkEvents,
- Collection<DeviceEvent> addedDeviceEvents,
- Collection<DeviceEvent> removedDeviceEvents);
+ Collection<SwitchEvent> removedSwitchEvents,
+ Collection<PortEvent> addedPortEvents,
+ Collection<PortEvent> removedPortEvents,
+ Collection<LinkEvent> addedLinkEvents,
+ Collection<LinkEvent> removedLinkEvents,
+ Collection<DeviceEvent> addedDeviceEvents,
+ Collection<DeviceEvent> removedDeviceEvents);
}
diff --git a/src/main/java/net/onrc/onos/core/topology/INetworkGraphService.java b/src/main/java/net/onrc/onos/core/topology/INetworkGraphService.java
index 9d4cb3a..18eb785 100644
--- a/src/main/java/net/onrc/onos/core/topology/INetworkGraphService.java
+++ b/src/main/java/net/onrc/onos/core/topology/INetworkGraphService.java
@@ -6,13 +6,15 @@
* Interface for providing the Network Graph Service to other modules.
*/
public interface INetworkGraphService extends IFloodlightService {
- /**
- * Allows a module to get a reference to the global network graph object.
- * @return
- */
+ /**
+ * Allows a module to get a reference to the global network graph object.
+ *
+ * @return
+ */
public NetworkGraph getNetworkGraph();
public void registerNetworkGraphListener(INetworkGraphListener listener);
+
public void deregisterNetworkGraphListener(INetworkGraphListener listener);
/**
@@ -20,6 +22,7 @@
* the network graph.
* TODO Figure out how to hide the southbound interface from
* applications/modules that shouldn't touch it
+ *
* @return
*/
public NetworkGraphDiscoveryInterface getNetworkGraphDiscoveryInterface();
diff --git a/src/main/java/net/onrc/onos/core/topology/Link.java b/src/main/java/net/onrc/onos/core/topology/Link.java
index f73bccf..2acf7dc 100644
--- a/src/main/java/net/onrc/onos/core/topology/Link.java
+++ b/src/main/java/net/onrc/onos/core/topology/Link.java
@@ -2,10 +2,9 @@
/**
* Interface of Link Object exposed to the "NB" read-only Topology.
- *
+ * <p/>
* Everything returned by these interfaces must be either Unmodifiable view,
* immutable object, or a copy of the original "SB" In-memory Topology.
- *
*/
public interface Link {
/**
@@ -38,7 +37,7 @@
/**
* Get the last seen time for the link.
- *
+ * <p/>
* TODO: Not implemented yet.
* TODO: what is the time definition?
*
@@ -48,7 +47,7 @@
/**
* Get the link cost.
- *
+ * <p/>
* TODO: What is the unit?
*
* @param return the link cost.
@@ -57,7 +56,7 @@
/**
* Get the link capacity.
- *
+ * <p/>
* TODO: What is the unit?
*
* @return the link capacity.
diff --git a/src/main/java/net/onrc/onos/core/topology/LinkEvent.java b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
index bf43155..7434ad9 100644
--- a/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
@@ -6,9 +6,8 @@
/**
* Self-contained Link event Object
- *
+ * <p/>
* TODO: We probably want common base class/interface for Self-Contained Event Object
- *
*/
public class LinkEvent {
protected final SwitchPort src;
@@ -19,83 +18,83 @@
*/
@Deprecated
public LinkEvent() {
- src = null;
- dst = null;
+ src = null;
+ dst = null;
}
public LinkEvent(Long src_dpid, Long src_port_no, Long dst_dpid,
- Long dst_port_no) {
- src = new SwitchPort(src_dpid, src_port_no);
- dst = new SwitchPort(dst_dpid, dst_port_no);
+ Long dst_port_no) {
+ src = new SwitchPort(src_dpid, src_port_no);
+ dst = new SwitchPort(dst_dpid, dst_port_no);
}
public LinkEvent(Link link) {
- src = new SwitchPort(link.getSrcSwitch().getDpid(),
- link.getSrcPort().getNumber());
- dst = new SwitchPort(link.getDstSwitch().getDpid(),
- link.getDstPort().getNumber());
+ src = new SwitchPort(link.getSrcSwitch().getDpid(),
+ link.getSrcPort().getNumber());
+ dst = new SwitchPort(link.getDstSwitch().getDpid(),
+ link.getDstPort().getNumber());
}
public SwitchPort getSrc() {
- return src;
+ return src;
}
public SwitchPort getDst() {
- return dst;
+ return dst;
}
@Override
public String toString() {
- return "[LinkEvent " + src + "->" + dst + "]";
+ return "[LinkEvent " + src + "->" + dst + "]";
}
public static final int LINKID_BYTES = 2 + PortEvent.PORTID_BYTES * 2;
public static ByteBuffer getLinkID(Long src_dpid, Long src_port_no,
- Long dst_dpid, Long dst_port_no) {
- return (ByteBuffer) ByteBuffer.allocate(LinkEvent.LINKID_BYTES).putChar('L')
- .put(PortEvent.getPortID(src_dpid, src_port_no))
- .put(PortEvent.getPortID(dst_dpid, dst_port_no)).flip();
+ Long dst_dpid, Long dst_port_no) {
+ return (ByteBuffer) ByteBuffer.allocate(LinkEvent.LINKID_BYTES).putChar('L')
+ .put(PortEvent.getPortID(src_dpid, src_port_no))
+ .put(PortEvent.getPortID(dst_dpid, dst_port_no)).flip();
}
public byte[] getID() {
- return getLinkID(src.getDpid(), src.getNumber(),
- dst.getDpid(), dst.getNumber()).array();
+ return getLinkID(src.getDpid(), src.getNumber(),
+ dst.getDpid(), dst.getNumber()).array();
}
public ByteBuffer getIDasByteBuffer() {
- return getLinkID(src.getDpid(), src.getNumber(),
- dst.getDpid(), dst.getNumber());
+ return getLinkID(src.getDpid(), src.getNumber(),
+ dst.getDpid(), dst.getNumber());
}
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((dst == null) ? 0 : dst.hashCode());
- result = prime * result + ((src == null) ? 0 : src.hashCode());
- return result;
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((dst == null) ? 0 : dst.hashCode());
+ result = prime * result + ((src == null) ? 0 : src.hashCode());
+ return result;
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- LinkEvent other = (LinkEvent) obj;
- if (dst == null) {
- if (other.dst != null)
- return false;
- } else if (!dst.equals(other.dst))
- return false;
- if (src == null) {
- if (other.src != null)
- return false;
- } else if (!src.equals(other.src))
- return false;
- return true;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ LinkEvent other = (LinkEvent) obj;
+ if (dst == null) {
+ if (other.dst != null)
+ return false;
+ } else if (!dst.equals(other.dst))
+ return false;
+ if (src == null) {
+ if (other.src != null)
+ return false;
+ } else if (!src.equals(other.src))
+ return false;
+ return true;
}
}
\ No newline at end of file
diff --git a/src/main/java/net/onrc/onos/core/topology/LinkImpl.java b/src/main/java/net/onrc/onos/core/topology/LinkImpl.java
index d95d4fd..4333e38 100644
--- a/src/main/java/net/onrc/onos/core/topology/LinkImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/LinkImpl.java
@@ -2,93 +2,94 @@
/**
* Link Object stored in In-memory Topology.
- *
+ * <p/>
* TODO REMOVE following design memo: This object itself may hold the DBObject,
* but this Object itself will not issue any read/write to the DataStore.
*/
public class LinkImpl extends NetworkGraphObject implements Link {
- protected Port srcPort;
- protected Port dstPort;
+ protected Port srcPort;
+ protected Port dstPort;
- protected static final Double DEFAULT_CAPACITY = Double.POSITIVE_INFINITY;
- protected Double capacity = DEFAULT_CAPACITY;
+ protected static final Double DEFAULT_CAPACITY = Double.POSITIVE_INFINITY;
+ protected Double capacity = DEFAULT_CAPACITY;
- protected static final int DEFAULT_COST = 1;
- protected int cost = DEFAULT_COST;
+ protected static final int DEFAULT_COST = 1;
+ protected int cost = DEFAULT_COST;
- /**
- * Constructor for when a link is read from the database and the Ports
- * already exist in the in-memory network graph.
- * @param graph
- * @param srcPort
- * @param dstPort
- */
- public LinkImpl(NetworkGraph graph, Port srcPort, Port dstPort) {
- super(graph);
- this.srcPort = srcPort;
- this.dstPort = dstPort;
- setToPorts();
- }
+ /**
+ * Constructor for when a link is read from the database and the Ports
+ * already exist in the in-memory network graph.
+ *
+ * @param graph
+ * @param srcPort
+ * @param dstPort
+ */
+ public LinkImpl(NetworkGraph graph, Port srcPort, Port dstPort) {
+ super(graph);
+ this.srcPort = srcPort;
+ this.dstPort = dstPort;
+ setToPorts();
+ }
- @Override
- public Switch getSrcSwitch() {
- return srcPort.getSwitch();
- }
+ @Override
+ public Switch getSrcSwitch() {
+ return srcPort.getSwitch();
+ }
- @Override
- public Port getSrcPort() {
- return srcPort;
- }
+ @Override
+ public Port getSrcPort() {
+ return srcPort;
+ }
- @Override
- public Switch getDstSwitch() {
- return dstPort.getSwitch();
- }
+ @Override
+ public Switch getDstSwitch() {
+ return dstPort.getSwitch();
+ }
- @Override
- public Port getDstPort() {
- return dstPort;
- }
+ @Override
+ public Port getDstPort() {
+ return dstPort;
+ }
- protected void setToPorts() {
- ((PortImpl)srcPort).setOutgoingLink(this);
- ((PortImpl)dstPort).setIncomingLink(this);
- }
+ protected void setToPorts() {
+ ((PortImpl) srcPort).setOutgoingLink(this);
+ ((PortImpl) dstPort).setIncomingLink(this);
+ }
- protected void unsetFromPorts() {
- ((PortImpl)srcPort).setOutgoingLink(null);
- ((PortImpl)dstPort).setIncomingLink(null);
- }
+ protected void unsetFromPorts() {
+ ((PortImpl) srcPort).setOutgoingLink(null);
+ ((PortImpl) dstPort).setIncomingLink(null);
+ }
- @Override
- public long getLastSeenTime() {
- // TODO Auto-generated method stub
- return 0;
- }
+ @Override
+ public long getLastSeenTime() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
- @Override
- public int getCost() {
- return cost;
- }
+ @Override
+ public int getCost() {
+ return cost;
+ }
- public void setCost(int cost) {
- this.cost = cost;
- }
+ public void setCost(int cost) {
+ this.cost = cost;
+ }
- @Override
- public Double getCapacity() {
- return capacity;
- }
+ @Override
+ public Double getCapacity() {
+ return capacity;
+ }
- public void setCapacity(Double capacity) {
- this.capacity = capacity;
- }
+ public void setCapacity(Double capacity) {
+ this.capacity = capacity;
+ }
- @Override
- public String toString() {
- return String.format("%s --(cap:%f Mbps)--> %s",
- getSrcPort().toString(),
- getCapacity(),
- getDstPort().toString());
- }
+ @Override
+ public String toString() {
+ return String.format("%s --(cap:%f Mbps)--> %s",
+ getSrcPort().toString(),
+ getCapacity(),
+ getDstPort().toString());
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/NetworkGraph.java b/src/main/java/net/onrc/onos/core/topology/NetworkGraph.java
index 4e83263..3c583b4 100644
--- a/src/main/java/net/onrc/onos/core/topology/NetworkGraph.java
+++ b/src/main/java/net/onrc/onos/core/topology/NetworkGraph.java
@@ -28,7 +28,7 @@
/**
* Get the port on a switch.
*
- * @param dpid the switch DPID.
+ * @param dpid the switch DPID.
* @param number the switch port number.
* @return the switch port if found, otherwise null.
*/
@@ -37,7 +37,7 @@
/**
* Get the outgoing link for a switch and a port.
*
- * @param dpid the switch DPID.
+ * @param dpid the switch DPID.
* @param number the switch port number.
* @return the outgoing link if found, otherwise null.
*/
@@ -47,18 +47,18 @@
* Get the outgoing link from a switch and a port to another switch and
* a port.
*
- * @param srcDpid the source switch DPID.
+ * @param srcDpid the source switch DPID.
* @param srcNumber the source switch port number.
- * @param dstDpid the destination switch DPID.
+ * @param dstDpid the destination switch DPID.
* @param dstNumber the destination switch port number.
* @return the outgoing link if found, otherwise null.
*/
public Link getLink(Long srcDpid, Long srcNumber, Long dstDpid,
- Long dstNumber);
+ Long dstNumber);
/**
* Get all links in the network.
- *
+ * <p/>
* TODO: Not clear if this method is needed. Remove if not used.
*
* @return all links in the network.
@@ -80,15 +80,15 @@
* @return the network device for the MAC address if found, otherwise null.
*/
public Device getDeviceByMac(MACAddress address);
-
+
/**
- * Acquire a read lock on the entire topology. The topology will not
- * change while readers have the lock. Must be released using
+ * Acquire a read lock on the entire topology. The topology will not
+ * change while readers have the lock. Must be released using
* {@link releaseReadLock()}. This method will block until a read lock is
* available.
*/
public void acquireReadLock();
-
+
/**
* Release the read lock on the topology.
*/
diff --git a/src/main/java/net/onrc/onos/core/topology/NetworkGraphDatastore.java b/src/main/java/net/onrc/onos/core/topology/NetworkGraphDatastore.java
index 8488297..488915f 100644
--- a/src/main/java/net/onrc/onos/core/topology/NetworkGraphDatastore.java
+++ b/src/main/java/net/onrc/onos/core/topology/NetworkGraphDatastore.java
@@ -26,203 +26,202 @@
* mutate the graph. This class will maintain the invariants of the network
* graph. The southbound discovery modules will use this interface to update
* the network graph as they learn about the state of the network.
- *
+ * <p/>
* Modification to the Network Map by this module will:
* 1. Writes to Cluster-wide DataStore.
* 2. Update ONOS instance In-memory Network Map.
* 3. Send-out Notification. (TBD)
- * (XXX: To update other instances In-memory Network Map,
- * notification should be triggered here.
- * But if we want to aggregate notification to minimize notification,
- * It might be better for the caller to trigger notification.)
- *
+ * (XXX: To update other instances In-memory Network Map,
+ * notification should be triggered here.
+ * But if we want to aggregate notification to minimize notification,
+ * It might be better for the caller to trigger notification.)
*/
public class NetworkGraphDatastore {
- private static final Logger log = LoggerFactory.getLogger(NetworkGraphDatastore.class);
+ private static final Logger log = LoggerFactory.getLogger(NetworkGraphDatastore.class);
- /**
- * Add a switch to the database.
- *
- * @param sw the switch to add.
- * @param portEvents the corresponding switch ports to add.
- * @return true on success, otherwise false.
- */
- public boolean addSwitch(SwitchEvent sw,
- Collection<PortEvent> portEvents) {
- log.debug("Adding switch {}", sw);
- ArrayList<WriteOp> groupOp = new ArrayList<>();
+ /**
+ * Add a switch to the database.
+ *
+ * @param sw the switch to add.
+ * @param portEvents the corresponding switch ports to add.
+ * @return true on success, otherwise false.
+ */
+ public boolean addSwitch(SwitchEvent sw,
+ Collection<PortEvent> portEvents) {
+ log.debug("Adding switch {}", sw);
+ ArrayList<WriteOp> groupOp = new ArrayList<>();
- KVSwitch rcSwitch = new KVSwitch(sw.getDpid());
- rcSwitch.setStatus(KVSwitch.STATUS.ACTIVE);
+ KVSwitch rcSwitch = new KVSwitch(sw.getDpid());
+ rcSwitch.setStatus(KVSwitch.STATUS.ACTIVE);
- IKVClient client = DataStoreClient.getClient();
+ IKVClient client = DataStoreClient.getClient();
- // XXX Is ForceCreating Switch on DB OK here?
- // If ForceCreating, who ever is calling this method needs
- // to assure that DPID is unique cluster-wide, etc.
- groupOp.add(rcSwitch.forceCreateOp(client));
+ // XXX Is ForceCreating Switch on DB OK here?
+ // If ForceCreating, who ever is calling this method needs
+ // to assure that DPID is unique cluster-wide, etc.
+ groupOp.add(rcSwitch.forceCreateOp(client));
- for (PortEvent portEvent : portEvents) {
- KVPort rcPort = new KVPort(sw.getDpid(), portEvent.getNumber());
- rcPort.setStatus(KVPort.STATUS.ACTIVE);
+ for (PortEvent portEvent : portEvents) {
+ KVPort rcPort = new KVPort(sw.getDpid(), portEvent.getNumber());
+ rcPort.setStatus(KVPort.STATUS.ACTIVE);
- groupOp.add(rcPort.forceCreateOp(client));
- }
+ groupOp.add(rcPort.forceCreateOp(client));
+ }
- boolean failed = KVObject.multiWrite(groupOp);
+ boolean failed = KVObject.multiWrite(groupOp);
- if (failed) {
- log.error("Adding Switch {} and its ports failed.", sw.getDpid());
- for (WriteOp op : groupOp) {
- log.debug("Operation:{} for {} - Result:{}", op.getOp(), op.getObject(), op.getStatus() );
+ if (failed) {
+ log.error("Adding Switch {} and its ports failed.", sw.getDpid());
+ for (WriteOp op : groupOp) {
+ log.debug("Operation:{} for {} - Result:{}", op.getOp(), op.getObject(), op.getStatus());
- // If we changed the operation from ForceCreate to
- // Conditional operation (Create/Update) then we should retry here.
- }
- }
- return !failed;
- }
+ // If we changed the operation from ForceCreate to
+ // Conditional operation (Create/Update) then we should retry here.
+ }
+ }
+ return !failed;
+ }
- /**
- * Update a switch as inactive in the database.
- *
- * @param sw the switch to update.
- * @param portEvents the corresponding switch ports to update.
- * @return true on success, otherwise false.
- */
- public boolean deactivateSwitch(SwitchEvent sw,
- Collection<PortEvent> portEvents) {
- log.debug("Deactivating switch {}", sw);
- KVSwitch rcSwitch = new KVSwitch(sw.getDpid());
+ /**
+ * Update a switch as inactive in the database.
+ *
+ * @param sw the switch to update.
+ * @param portEvents the corresponding switch ports to update.
+ * @return true on success, otherwise false.
+ */
+ public boolean deactivateSwitch(SwitchEvent sw,
+ Collection<PortEvent> portEvents) {
+ log.debug("Deactivating switch {}", sw);
+ KVSwitch rcSwitch = new KVSwitch(sw.getDpid());
- IKVClient client = DataStoreClient.getClient();
+ IKVClient client = DataStoreClient.getClient();
- List<WriteOp> groupOp = new ArrayList<>();
- rcSwitch.setStatus(KVSwitch.STATUS.INACTIVE);
+ List<WriteOp> groupOp = new ArrayList<>();
+ rcSwitch.setStatus(KVSwitch.STATUS.INACTIVE);
- groupOp.add(rcSwitch.forceCreateOp(client));
+ groupOp.add(rcSwitch.forceCreateOp(client));
- for (PortEvent portEvent : portEvents) {
- KVPort rcPort = new KVPort(sw.getDpid(), portEvent.getNumber());
- rcPort.setStatus(KVPort.STATUS.INACTIVE);
+ for (PortEvent portEvent : portEvents) {
+ KVPort rcPort = new KVPort(sw.getDpid(), portEvent.getNumber());
+ rcPort.setStatus(KVPort.STATUS.INACTIVE);
- groupOp.add(rcPort.forceCreateOp(client));
- }
+ groupOp.add(rcPort.forceCreateOp(client));
+ }
- boolean failed = KVObject.multiWrite(groupOp);
+ boolean failed = KVObject.multiWrite(groupOp);
- return !failed;
- }
+ return !failed;
+ }
- /**
- * Add a port to the database.
- *
- * @param port the port to add.
- * @return true on success, otherwise false.
- */
- public boolean addPort(PortEvent port) {
- log.debug("Adding port {}", port);
+ /**
+ * Add a port to the database.
+ *
+ * @param port the port to add.
+ * @return true on success, otherwise false.
+ */
+ public boolean addPort(PortEvent port) {
+ log.debug("Adding port {}", port);
- KVPort rcPort = new KVPort(port.getDpid(), port.getNumber());
- rcPort.setStatus(KVPort.STATUS.ACTIVE);
- rcPort.forceCreate();
- // TODO add description into KVPort
- //rcPort.setDescription(port.getDescription());
+ KVPort rcPort = new KVPort(port.getDpid(), port.getNumber());
+ rcPort.setStatus(KVPort.STATUS.ACTIVE);
+ rcPort.forceCreate();
+ // TODO add description into KVPort
+ //rcPort.setDescription(port.getDescription());
- return true;
- }
+ return true;
+ }
- /**
- * Update a port as inactive in the database.
- *
- * @param port the port to update.
- * @return true on success, otherwise false.
- */
- public boolean deactivatePort(PortEvent port) {
- log.debug("Deactivating port {}", port);
+ /**
+ * Update a port as inactive in the database.
+ *
+ * @param port the port to update.
+ * @return true on success, otherwise false.
+ */
+ public boolean deactivatePort(PortEvent port) {
+ log.debug("Deactivating port {}", port);
- KVPort rcPort = new KVPort(port.getDpid(), port.getNumber());
- rcPort.setStatus(STATUS.INACTIVE);
+ KVPort rcPort = new KVPort(port.getDpid(), port.getNumber());
+ rcPort.setStatus(STATUS.INACTIVE);
- rcPort.forceCreate();
+ rcPort.forceCreate();
- return true;
- }
+ return true;
+ }
- /**
- * Add a link to the database.
- *
- * @param link the link to add.
- * @return true on success, otherwise false.
- */
- public boolean addLink(LinkEvent link) {
- log.debug("Adding link {}", link);
+ /**
+ * Add a link to the database.
+ *
+ * @param link the link to add.
+ * @return true on success, otherwise false.
+ */
+ public boolean addLink(LinkEvent link) {
+ log.debug("Adding link {}", link);
- KVLink rcLink = new KVLink(link.getSrc().getDpid(),
- link.getSrc().getNumber(),
- link.getDst().getDpid(),
- link.getDst().getNumber());
+ KVLink rcLink = new KVLink(link.getSrc().getDpid(),
+ link.getSrc().getNumber(),
+ link.getDst().getDpid(),
+ link.getDst().getNumber());
- // XXX This method is called only by discovery,
- // which means what we are trying to write currently is the truth
- // so we can force write here
- //
- // TODO: We need to check for errors
- rcLink.setStatus(KVLink.STATUS.ACTIVE);
- rcLink.forceCreate();
+ // XXX This method is called only by discovery,
+ // which means what we are trying to write currently is the truth
+ // so we can force write here
+ //
+ // TODO: We need to check for errors
+ rcLink.setStatus(KVLink.STATUS.ACTIVE);
+ rcLink.forceCreate();
- return true; // Success
- }
+ return true; // Success
+ }
- public boolean removeLink(LinkEvent linkEvent) {
- log.debug("Removing link {}", linkEvent);
+ public boolean removeLink(LinkEvent linkEvent) {
+ log.debug("Removing link {}", linkEvent);
- KVLink rcLink = new KVLink(linkEvent.getSrc().getDpid(), linkEvent.getSrc().getNumber(),
- linkEvent.getDst().getDpid(), linkEvent.getDst().getNumber());
- rcLink.forceDelete();
+ KVLink rcLink = new KVLink(linkEvent.getSrc().getDpid(), linkEvent.getSrc().getNumber(),
+ linkEvent.getDst().getDpid(), linkEvent.getDst().getNumber());
+ rcLink.forceDelete();
- return true;
- }
+ return true;
+ }
- /**
- * Add a device to the database.
- *
- * @param device the device to add.
- * @return true on success, otherwise false.
- */
- public boolean addDevice(DeviceEvent device) {
- log.debug("Adding device into DB. mac {}", device.getMac());
+ /**
+ * Add a device to the database.
+ *
+ * @param device the device to add.
+ * @return true on success, otherwise false.
+ */
+ public boolean addDevice(DeviceEvent device) {
+ log.debug("Adding device into DB. mac {}", device.getMac());
- KVDevice rcDevice = new KVDevice(device.getMac().toBytes());
- rcDevice.setLastSeenTime(device.getLastSeenTime());
-
- for(SwitchPort sp : device.getAttachmentPoints()) {
- byte[] portId = KVPort.getPortID(sp.getDpid(), sp.getNumber());
- rcDevice.addPortId(portId);
- }
-
- for(InetAddress addr : device.getIpAddresses()) {
- //It assume only one ip on a device now.
- rcDevice.setIp(InetAddresses.coerceToInteger(addr));
- }
+ KVDevice rcDevice = new KVDevice(device.getMac().toBytes());
+ rcDevice.setLastSeenTime(device.getLastSeenTime());
- rcDevice.forceCreate();
-
- return true;
- }
+ for (SwitchPort sp : device.getAttachmentPoints()) {
+ byte[] portId = KVPort.getPortID(sp.getDpid(), sp.getNumber());
+ rcDevice.addPortId(portId);
+ }
- /**
- * Remove a device from the database.
- *
- * @param device the device to remove.
- * @return true on success, otherwise false.
- */
- public boolean removeDevice(DeviceEvent device) {
- log.debug("Removing device into DB. mac {}", device.getMac());
-
- KVDevice rcDevice = new KVDevice(device.getMac().toBytes());
- rcDevice.forceDelete();
-
- return true;
- }
+ for (InetAddress addr : device.getIpAddresses()) {
+ //It assume only one ip on a device now.
+ rcDevice.setIp(InetAddresses.coerceToInteger(addr));
+ }
+
+ rcDevice.forceCreate();
+
+ return true;
+ }
+
+ /**
+ * Remove a device from the database.
+ *
+ * @param device the device to remove.
+ * @return true on success, otherwise false.
+ */
+ public boolean removeDevice(DeviceEvent device) {
+ log.debug("Removing device into DB. mac {}", device.getMac());
+
+ KVDevice rcDevice = new KVDevice(device.getMac().toBytes());
+ rcDevice.forceDelete();
+
+ return true;
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/NetworkGraphDiscoveryInterface.java b/src/main/java/net/onrc/onos/core/topology/NetworkGraphDiscoveryInterface.java
index 14ef0ea..219417f 100644
--- a/src/main/java/net/onrc/onos/core/topology/NetworkGraphDiscoveryInterface.java
+++ b/src/main/java/net/onrc/onos/core/topology/NetworkGraphDiscoveryInterface.java
@@ -11,10 +11,10 @@
* Switch discovered event.
*
* @param switchEvent the switch event.
- * @param portEvents the corresponding port events for the switch.
+ * @param portEvents the corresponding port events for the switch.
*/
public void putSwitchDiscoveryEvent(SwitchEvent switchEvent,
- Collection<PortEvent> portEvents);
+ Collection<PortEvent> portEvents);
/**
* Switch removed event.
diff --git a/src/main/java/net/onrc/onos/core/topology/NetworkGraphImpl.java b/src/main/java/net/onrc/onos/core/topology/NetworkGraphImpl.java
index 902ffa6..a60e390 100644
--- a/src/main/java/net/onrc/onos/core/topology/NetworkGraphImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/NetworkGraphImpl.java
@@ -18,143 +18,143 @@
import org.slf4j.LoggerFactory;
public class NetworkGraphImpl implements NetworkGraph {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(NetworkGraphImpl.class);
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(NetworkGraphImpl.class);
- // DPID -> Switch
- private ConcurrentMap<Long, Switch> switches;
+ // DPID -> Switch
+ private ConcurrentMap<Long, Switch> switches;
- private ConcurrentMap<InetAddress, Set<Device>> addr2Device;
- private ConcurrentMap<MACAddress, Device> mac2Device;
+ private ConcurrentMap<InetAddress, Set<Device>> addr2Device;
+ private ConcurrentMap<MACAddress, Device> mac2Device;
- private ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
- private Lock readLock = readWriteLock.readLock();
- // TODO use the write lock after refactor
- private Lock writeLock = readWriteLock.writeLock();
+ private ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
+ private Lock readLock = readWriteLock.readLock();
+ // TODO use the write lock after refactor
+ private Lock writeLock = readWriteLock.writeLock();
- public NetworkGraphImpl() {
- // TODO: Does these object need to be stored in Concurrent Collection?
- switches = new ConcurrentHashMap<>();
- addr2Device = new ConcurrentHashMap<>();
- mac2Device = new ConcurrentHashMap<>();
- }
+ public NetworkGraphImpl() {
+ // TODO: Does these object need to be stored in Concurrent Collection?
+ switches = new ConcurrentHashMap<>();
+ addr2Device = new ConcurrentHashMap<>();
+ mac2Device = new ConcurrentHashMap<>();
+ }
- @Override
- public Switch getSwitch(Long dpid) {
- // TODO Check if it is safe to directly return this Object.
- return switches.get(dpid);
- }
+ @Override
+ public Switch getSwitch(Long dpid) {
+ // TODO Check if it is safe to directly return this Object.
+ return switches.get(dpid);
+ }
- protected void putSwitch(Switch sw) {
- switches.put(sw.getDpid(), sw);
- }
+ protected void putSwitch(Switch sw) {
+ switches.put(sw.getDpid(), sw);
+ }
- protected void removeSwitch(Long dpid) {
- switches.remove(dpid);
- }
+ protected void removeSwitch(Long dpid) {
+ switches.remove(dpid);
+ }
- @Override
- public Iterable<Switch> getSwitches() {
- // TODO Check if it is safe to directly return this Object.
- return Collections.unmodifiableCollection(switches.values());
- }
+ @Override
+ public Iterable<Switch> getSwitches() {
+ // TODO Check if it is safe to directly return this Object.
+ return Collections.unmodifiableCollection(switches.values());
+ }
- @Override
- public Port getPort(Long dpid, Long number) {
- Switch sw = getSwitch(dpid);
- if (sw != null) {
- return sw.getPort(number);
- }
- return null;
- }
+ @Override
+ public Port getPort(Long dpid, Long number) {
+ Switch sw = getSwitch(dpid);
+ if (sw != null) {
+ return sw.getPort(number);
+ }
+ return null;
+ }
- @Override
- public Link getLink(Long dpid, Long number) {
- Port srcPort = getPort(dpid, number);
- if (srcPort == null)
- return null;
- return srcPort.getOutgoingLink();
- }
+ @Override
+ public Link getLink(Long dpid, Long number) {
+ Port srcPort = getPort(dpid, number);
+ if (srcPort == null)
+ return null;
+ return srcPort.getOutgoingLink();
+ }
- @Override
- public Link getLink(Long srcDpid, Long srcNumber, Long dstDpid,
- Long dstNumber) {
- Link link = getLink(srcDpid, srcNumber);
- if (link == null)
- return null;
- if (!link.getDstSwitch().getDpid().equals(dstDpid))
- return null;
- if (!link.getDstPort().getNumber().equals(dstNumber))
- return null;
- return link;
- }
+ @Override
+ public Link getLink(Long srcDpid, Long srcNumber, Long dstDpid,
+ Long dstNumber) {
+ Link link = getLink(srcDpid, srcNumber);
+ if (link == null)
+ return null;
+ if (!link.getDstSwitch().getDpid().equals(dstDpid))
+ return null;
+ if (!link.getDstPort().getNumber().equals(dstNumber))
+ return null;
+ return link;
+ }
- @Override
- public Iterable<Link> getLinks() {
- List<Link> linklist = new LinkedList<>();
+ @Override
+ public Iterable<Link> getLinks() {
+ List<Link> linklist = new LinkedList<>();
- for (Switch sw : switches.values()) {
- Iterable<Link> links = sw.getOutgoingLinks();
- for (Link l : links) {
- linklist.add(l);
- }
- }
- return linklist;
- }
+ for (Switch sw : switches.values()) {
+ Iterable<Link> links = sw.getOutgoingLinks();
+ for (Link l : links) {
+ linklist.add(l);
+ }
+ }
+ return linklist;
+ }
- @Override
- public Iterable<Device> getDevicesByIp(InetAddress ipAddress) {
- Set<Device> devices = addr2Device.get(ipAddress);
- if (devices == null) {
- return Collections.emptySet();
- }
- return Collections.unmodifiableCollection(devices);
- }
+ @Override
+ public Iterable<Device> getDevicesByIp(InetAddress ipAddress) {
+ Set<Device> devices = addr2Device.get(ipAddress);
+ if (devices == null) {
+ return Collections.emptySet();
+ }
+ return Collections.unmodifiableCollection(devices);
+ }
- @Override
- public Device getDeviceByMac(MACAddress address) {
- return mac2Device.get(address);
- }
+ @Override
+ public Device getDeviceByMac(MACAddress address) {
+ return mac2Device.get(address);
+ }
- protected void putDevice(Device device) {
- mac2Device.put(device.getMacAddress(), device);
- for (InetAddress ipAddr : device.getIpAddress()) {
- Set<Device> devices = addr2Device.get(ipAddr);
- if (devices == null) {
- devices = new HashSet<>();
- addr2Device.put(ipAddr, devices);
- }
- devices.add(device);
- }
- }
+ protected void putDevice(Device device) {
+ mac2Device.put(device.getMacAddress(), device);
+ for (InetAddress ipAddr : device.getIpAddress()) {
+ Set<Device> devices = addr2Device.get(ipAddr);
+ if (devices == null) {
+ devices = new HashSet<>();
+ addr2Device.put(ipAddr, devices);
+ }
+ devices.add(device);
+ }
+ }
- protected void removeDevice(Device device) {
- mac2Device.remove(device.getMacAddress());
- for (InetAddress ipAddr : device.getIpAddress()) {
- Set<Device> devices = addr2Device.get(ipAddr);
- if (devices != null) {
- devices.remove(device);
- if (devices.isEmpty())
- addr2Device.remove(ipAddr);
- }
- }
- }
+ protected void removeDevice(Device device) {
+ mac2Device.remove(device.getMacAddress());
+ for (InetAddress ipAddr : device.getIpAddress()) {
+ Set<Device> devices = addr2Device.get(ipAddr);
+ if (devices != null) {
+ devices.remove(device);
+ if (devices.isEmpty())
+ addr2Device.remove(ipAddr);
+ }
+ }
+ }
- @Override
- public void acquireReadLock() {
- readLock.lock();
- }
+ @Override
+ public void acquireReadLock() {
+ readLock.lock();
+ }
- @Override
- public void releaseReadLock() {
- readLock.unlock();
- }
+ @Override
+ public void releaseReadLock() {
+ readLock.unlock();
+ }
- protected void acquireWriteLock() {
- writeLock.lock();
- }
+ protected void acquireWriteLock() {
+ writeLock.lock();
+ }
- protected void releaseWriteLock() {
- writeLock.unlock();
- }
+ protected void releaseWriteLock() {
+ writeLock.unlock();
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/NetworkGraphModule.java b/src/main/java/net/onrc/onos/core/topology/NetworkGraphModule.java
index c693df5..77981d6 100644
--- a/src/main/java/net/onrc/onos/core/topology/NetworkGraphModule.java
+++ b/src/main/java/net/onrc/onos/core/topology/NetworkGraphModule.java
@@ -18,80 +18,80 @@
public class NetworkGraphModule implements IFloodlightModule, INetworkGraphService {
- // This is initialized as a module for now
+ // This is initialized as a module for now
- private TopologyManager topologyManager;
- //private NetworkGraphDatastore southboundNetworkGraph;
- private IDatagridService datagridService;
- private IControllerRegistryService registryService;
+ private TopologyManager topologyManager;
+ //private NetworkGraphDatastore southboundNetworkGraph;
+ private IDatagridService datagridService;
+ private IControllerRegistryService registryService;
- private CopyOnWriteArrayList<INetworkGraphListener> networkGraphListeners;
+ private CopyOnWriteArrayList<INetworkGraphListener> networkGraphListeners;
- private IRestApiService restApi;
+ private IRestApiService restApi;
- @Override
- public Collection<Class<? extends IFloodlightService>> getModuleServices() {
- List<Class<? extends IFloodlightService>> services =
- new ArrayList<Class<? extends IFloodlightService>>();
- services.add(INetworkGraphService.class);
- return services;
- }
+ @Override
+ public Collection<Class<? extends IFloodlightService>> getModuleServices() {
+ List<Class<? extends IFloodlightService>> services =
+ new ArrayList<Class<? extends IFloodlightService>>();
+ services.add(INetworkGraphService.class);
+ return services;
+ }
- @Override
- public Map<Class<? extends IFloodlightService>, IFloodlightService>
- getServiceImpls() {
- Map<Class<? extends IFloodlightService>, IFloodlightService> impls =
- new HashMap<Class<? extends IFloodlightService>, IFloodlightService>();
- impls.put(INetworkGraphService.class, this);
- return impls;
- }
+ @Override
+ public Map<Class<? extends IFloodlightService>, IFloodlightService>
+ getServiceImpls() {
+ Map<Class<? extends IFloodlightService>, IFloodlightService> impls =
+ new HashMap<Class<? extends IFloodlightService>, IFloodlightService>();
+ impls.put(INetworkGraphService.class, this);
+ return impls;
+ }
- @Override
- public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
- List<Class<? extends IFloodlightService>> dependencies =
- new ArrayList<Class<? extends IFloodlightService>>();
- dependencies.add(IDatagridService.class);
- dependencies.add(IRestApiService.class);
- dependencies.add(IControllerRegistryService.class);
- return dependencies;
- }
+ @Override
+ public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
+ List<Class<? extends IFloodlightService>> dependencies =
+ new ArrayList<Class<? extends IFloodlightService>>();
+ dependencies.add(IDatagridService.class);
+ dependencies.add(IRestApiService.class);
+ dependencies.add(IControllerRegistryService.class);
+ return dependencies;
+ }
- @Override
- public void init(FloodlightModuleContext context)
- throws FloodlightModuleException {
- restApi = context.getServiceImpl(IRestApiService.class);
- datagridService = context.getServiceImpl(IDatagridService.class);
- registryService = context.getServiceImpl(IControllerRegistryService.class);
+ @Override
+ public void init(FloodlightModuleContext context)
+ throws FloodlightModuleException {
+ restApi = context.getServiceImpl(IRestApiService.class);
+ datagridService = context.getServiceImpl(IDatagridService.class);
+ registryService = context.getServiceImpl(IControllerRegistryService.class);
- networkGraphListeners = new CopyOnWriteArrayList<>();
- topologyManager = new TopologyManager(registryService, networkGraphListeners);
- //southboundNetworkGraph = new NetworkGraphDatastore(networkGraph);
- }
+ networkGraphListeners = new CopyOnWriteArrayList<>();
+ topologyManager = new TopologyManager(registryService, networkGraphListeners);
+ //southboundNetworkGraph = new NetworkGraphDatastore(networkGraph);
+ }
- @Override
- public void startUp(FloodlightModuleContext context) {
- restApi.addRestletRoutable(new NetworkGraphWebRoutable());
- topologyManager.startup(datagridService);
- }
+ @Override
+ public void startUp(FloodlightModuleContext context) {
+ restApi.addRestletRoutable(new NetworkGraphWebRoutable());
+ topologyManager.startup(datagridService);
+ }
- @Override
- public NetworkGraph getNetworkGraph() {
- return topologyManager.getNetworkGraph();
- }
+ @Override
+ public NetworkGraph getNetworkGraph() {
+ return topologyManager.getNetworkGraph();
+ }
- @Override
- public NetworkGraphDiscoveryInterface getNetworkGraphDiscoveryInterface() {
- return topologyManager;
- }
+ @Override
+ public NetworkGraphDiscoveryInterface getNetworkGraphDiscoveryInterface() {
+ return topologyManager;
+ }
- @Override
- public void registerNetworkGraphListener(INetworkGraphListener listener) {
- networkGraphListeners.addIfAbsent(listener);
- }
+ @Override
+ public void registerNetworkGraphListener(INetworkGraphListener listener) {
+ networkGraphListeners.addIfAbsent(listener);
+ }
- @Override
- public void deregisterNetworkGraphListener(INetworkGraphListener listener) {
- networkGraphListeners.remove(listener);
- }
+ @Override
+ public void deregisterNetworkGraphListener(INetworkGraphListener listener) {
+ networkGraphListeners.remove(listener);
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/NetworkGraphObject.java b/src/main/java/net/onrc/onos/core/topology/NetworkGraphObject.java
index fde4a44..bef0e11 100644
--- a/src/main/java/net/onrc/onos/core/topology/NetworkGraphObject.java
+++ b/src/main/java/net/onrc/onos/core/topology/NetworkGraphObject.java
@@ -3,10 +3,10 @@
public class NetworkGraphObject {
- protected final NetworkGraph graph;
-
- public NetworkGraphObject(NetworkGraph graph) {
- this.graph = graph;
- }
+ protected final NetworkGraph graph;
+
+ public NetworkGraphObject(NetworkGraph graph) {
+ this.graph = graph;
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/NetworkGraphPublisher.java b/src/main/java/net/onrc/onos/core/topology/NetworkGraphPublisher.java
index fef71e7..bc72e00 100644
--- a/src/main/java/net/onrc/onos/core/topology/NetworkGraphPublisher.java
+++ b/src/main/java/net/onrc/onos/core/topology/NetworkGraphPublisher.java
@@ -37,13 +37,12 @@
* The NetworkGraphPublisher subscribes to topology network events from the
* discovery modules. These events are reformatted and relayed to the topology
* part of the network graph
- *
*/
public class NetworkGraphPublisher implements /*IOFSwitchListener,*/
- IOFSwitchPortListener,
- ILinkDiscoveryListener,
- IFloodlightModule,
- IOnosDeviceListener {
+ IOFSwitchPortListener,
+ ILinkDiscoveryListener,
+ IFloodlightModule,
+ IOnosDeviceListener {
private static final Logger log =
LoggerFactory.getLogger(NetworkGraphPublisher.class);
@@ -96,7 +95,7 @@
log.trace("Checking for inactive switches");
}
// For each switch check if a controller exists in controller registry
- for (Switch sw: switches) {
+ for (Switch sw : switches) {
try {
String controller =
registryService.getControllerForSwitch(sw.getDpid());
@@ -115,7 +114,8 @@
* Second half of the switch cleanup operation. If the registry grants
* control of a switch, we can be sure no other instance is writing
* this switch to the network graph, so we can remove it now.
- * @param dpid the dpid of the switch we requested control for
+ *
+ * @param dpid the dpid of the switch we requested control for
* @param hasControl whether we got control or not
*/
@Override
@@ -139,17 +139,17 @@
(long) update.getDstPort());
switch (update.getOperation()) {
- case LINK_ADDED:
- networkGraphDiscoveryInterface.putLinkDiscoveryEvent(linkEvent);
- break;
- case LINK_UPDATED:
- // We don't use the LINK_UPDATED event (unsure what it means)
- break;
- case LINK_REMOVED:
- networkGraphDiscoveryInterface.removeLinkDiscoveryEvent(linkEvent);
- break;
- default:
- break;
+ case LINK_ADDED:
+ networkGraphDiscoveryInterface.putLinkDiscoveryEvent(linkEvent);
+ break;
+ case LINK_UPDATED:
+ // We don't use the LINK_UPDATED event (unsure what it means)
+ break;
+ case LINK_REMOVED:
+ networkGraphDiscoveryInterface.removeLinkDiscoveryEvent(linkEvent);
+ break;
+ default:
+ break;
}
}
@@ -180,7 +180,7 @@
portEvents.add(new PortEvent(sw.getId(), (long) port.getPortNumber()));
}
networkGraphDiscoveryInterface
- .putSwitchDiscoveryEvent(switchEvent, portEvents);
+ .putSwitchDiscoveryEvent(switchEvent, portEvents);
for (OFPhysicalPort port : sw.getPorts()) {
// Allow links to be discovered on this port now that it's
@@ -222,7 +222,7 @@
@Override
public Collection<Class<? extends IFloodlightService>>
- getModuleDependencies() {
+ getModuleDependencies() {
Collection<Class<? extends IFloodlightService>> l =
new ArrayList<Class<? extends IFloodlightService>>();
l.add(IFloodlightProviderService.class);
diff --git a/src/main/java/net/onrc/onos/core/topology/Path.java b/src/main/java/net/onrc/onos/core/topology/Path.java
index 1d15fc7..9c5118d 100644
--- a/src/main/java/net/onrc/onos/core/topology/Path.java
+++ b/src/main/java/net/onrc/onos/core/topology/Path.java
@@ -5,20 +5,21 @@
/**
* Base class for Path representation
+ *
* @author Toshio Koide (t-koide@onlab.us)
*/
public class Path extends LinkedList<LinkEvent> {
- private static final long serialVersionUID = 7127274096495173415L;
+ private static final long serialVersionUID = 7127274096495173415L;
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- Iterator<LinkEvent> i = this.iterator();
- while (i.hasNext()) {
- builder.append(i.next().toString());
- if (i.hasNext())
- builder.append(", ");
- }
- return builder.toString();
- }
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ Iterator<LinkEvent> i = this.iterator();
+ while (i.hasNext()) {
+ builder.append(i.next().toString());
+ if (i.hasNext())
+ builder.append(", ");
+ }
+ return builder.toString();
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/Port.java b/src/main/java/net/onrc/onos/core/topology/Port.java
index e9f6bb8..216d4b8 100644
--- a/src/main/java/net/onrc/onos/core/topology/Port.java
+++ b/src/main/java/net/onrc/onos/core/topology/Port.java
@@ -1,24 +1,26 @@
package net.onrc.onos.core.topology;
-
/**
* Interface of Port Object exposed to the "NB" read-only Topology.
- *
+ * <p/>
* Everything returned by these interfaces must be either Unmodifiable view,
* immutable object, or a copy of the original "SB" In-memory Topology.
- *
*/
public interface Port {
- public Long getDpid();
- public Long getNumber();
- public Long getHardwareAddress();
- public String getDescription();
+ public Long getDpid();
- public Switch getSwitch();
+ public Long getNumber();
- public Link getOutgoingLink();
- public Link getIncomingLink();
+ public Long getHardwareAddress();
- public Iterable<Device> getDevices();
+ public String getDescription();
+
+ public Switch getSwitch();
+
+ public Link getOutgoingLink();
+
+ public Link getIncomingLink();
+
+ public Iterable<Device> getDevices();
}
diff --git a/src/main/java/net/onrc/onos/core/topology/PortEvent.java b/src/main/java/net/onrc/onos/core/topology/PortEvent.java
index 65d0b94..2a18c08 100644
--- a/src/main/java/net/onrc/onos/core/topology/PortEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/PortEvent.java
@@ -4,23 +4,22 @@
/**
* Self-contained Port event Object
- *
+ * <p/>
* TODO: We probably want common base class/interface for Self-Contained Event Object
- *
*/
public class PortEvent {
public static class SwitchPort {
- public final Long dpid;
- public final Long number;
+ public final Long dpid;
+ public final Long number;
- /**
- * Default constructor for Serializer to use.
- */
- @Deprecated
- public SwitchPort() {
- dpid = null;
- number = null;
- }
+ /**
+ * Default constructor for Serializer to use.
+ */
+ @Deprecated
+ public SwitchPort() {
+ dpid = null;
+ number = null;
+ }
public SwitchPort(Long dpid, Long number) {
this.dpid = dpid;
@@ -46,29 +45,29 @@
int result = 1;
result = prime * result + ((dpid == null) ? 0 : dpid.hashCode());
result = prime * result
- + ((number == null) ? 0 : number.hashCode());
+ + ((number == null) ? 0 : number.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
- return true;
+ return true;
if (obj == null)
- return false;
+ return false;
if (getClass() != obj.getClass())
- return false;
+ return false;
SwitchPort other = (SwitchPort) obj;
if (dpid == null) {
- if (other.dpid != null)
- return false;
+ if (other.dpid != null)
+ return false;
} else if (!dpid.equals(other.dpid))
- return false;
+ return false;
if (number == null) {
- if (other.number != null)
- return false;
+ if (other.number != null)
+ return false;
} else if (!number.equals(other.number))
- return false;
+ return false;
return true;
}
}
@@ -82,44 +81,44 @@
*/
@Deprecated
public PortEvent() {
- id = null;
+ id = null;
}
public PortEvent(Long dpid, Long number) {
- this.id = new SwitchPort(dpid, number);
+ this.id = new SwitchPort(dpid, number);
}
public Long getDpid() {
- return id.dpid;
+ return id.dpid;
}
public Long getNumber() {
- return id.number;
+ return id.number;
}
@Override
public String toString() {
- return "[PortEvent 0x" + Long.toHexString(id.dpid) + "@" + id.number + "]";
+ return "[PortEvent 0x" + Long.toHexString(id.dpid) + "@" + id.number + "]";
}
public static final int PORTID_BYTES = SwitchEvent.SWITCHID_BYTES + 2 + 8;
public static ByteBuffer getPortID(Long dpid, Long number) {
- if (dpid == null) {
- throw new IllegalArgumentException("dpid cannot be null");
- }
- if (number == null) {
- throw new IllegalArgumentException("number cannot be null");
- }
- return (ByteBuffer) ByteBuffer.allocate(PortEvent.PORTID_BYTES).putChar('S').putLong(dpid)
- .putChar('P').putLong(number).flip();
+ if (dpid == null) {
+ throw new IllegalArgumentException("dpid cannot be null");
+ }
+ if (number == null) {
+ throw new IllegalArgumentException("number cannot be null");
+ }
+ return (ByteBuffer) ByteBuffer.allocate(PortEvent.PORTID_BYTES).putChar('S').putLong(dpid)
+ .putChar('P').putLong(number).flip();
}
public byte[] getID() {
- return getPortID(getDpid(), getNumber()).array();
+ return getPortID(getDpid(), getNumber()).array();
}
public ByteBuffer getIDasByteBuffer() {
- return getPortID(getDpid(), getNumber());
+ return getPortID(getDpid(), getNumber());
}
}
diff --git a/src/main/java/net/onrc/onos/core/topology/PortImpl.java b/src/main/java/net/onrc/onos/core/topology/PortImpl.java
index cd7d82b..32646d0 100644
--- a/src/main/java/net/onrc/onos/core/topology/PortImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/PortImpl.java
@@ -6,108 +6,106 @@
/**
* Port Object stored in In-memory Topology.
- *
+ * <p/>
* TODO REMOVE following design memo: This object itself may hold the DBObject,
* but this Object itself will not issue any read/write to the DataStore.
*/
public class PortImpl extends NetworkGraphObject implements Port {
- private Switch sw;
+ private Switch sw;
- private Long number;
- private String description;
+ private Long number;
+ private String description;
- protected Link outgoingLink;
- protected Link incomingLink;
- // These needs to be ConcurrentCollecton if allowing Graph to be accessed Concurrently
- protected Set<Device> devices;
+ protected Link outgoingLink;
+ protected Link incomingLink;
+ // These needs to be ConcurrentCollecton if allowing Graph to be accessed Concurrently
+ protected Set<Device> devices;
- public PortImpl(NetworkGraph graph, Switch parentSwitch, Long number) {
- super(graph);
- this.sw = parentSwitch;
- this.number = number;
- this.devices = new HashSet<>();
- }
+ public PortImpl(NetworkGraph graph, Switch parentSwitch, Long number) {
+ super(graph);
+ this.sw = parentSwitch;
+ this.number = number;
+ this.devices = new HashSet<>();
+ }
- @Override
- public Long getDpid() {
- return sw.getDpid();
- }
+ @Override
+ public Long getDpid() {
+ return sw.getDpid();
+ }
- @Override
- public Long getNumber() {
- return number;
- }
+ @Override
+ public Long getNumber() {
+ return number;
+ }
- @Override
- public String getDescription() {
- return description;
- }
+ @Override
+ public String getDescription() {
+ return description;
+ }
- public void setDescription(String description) {
- this.description = description;
- }
+ public void setDescription(String description) {
+ this.description = description;
+ }
- @Override
- public Long getHardwareAddress() {
- // TODO Auto-generated method stub
- return 0L;
- }
+ @Override
+ public Long getHardwareAddress() {
+ // TODO Auto-generated method stub
+ return 0L;
+ }
- @Override
- public Switch getSwitch() {
- return sw;
- }
+ @Override
+ public Switch getSwitch() {
+ return sw;
+ }
- @Override
- public Link getOutgoingLink() {
- return outgoingLink;
- }
+ @Override
+ public Link getOutgoingLink() {
+ return outgoingLink;
+ }
- @Override
- public Link getIncomingLink() {
- return incomingLink;
- }
+ @Override
+ public Link getIncomingLink() {
+ return incomingLink;
+ }
- @Override
- public Iterable<Device> getDevices() {
- return Collections.unmodifiableSet(this.devices);
- }
+ @Override
+ public Iterable<Device> getDevices() {
+ return Collections.unmodifiableSet(this.devices);
+ }
- public void setOutgoingLink(Link link) {
- outgoingLink = link;
- }
+ public void setOutgoingLink(Link link) {
+ outgoingLink = link;
+ }
- public void setIncomingLink(Link link) {
- incomingLink = link;
- }
+ public void setIncomingLink(Link link) {
+ incomingLink = link;
+ }
- /**
- *
- * @param d
- * @return true if successfully added
- */
- public boolean addDevice(Device d) {
- return this.devices.add(d);
- }
+ /**
+ * @param d
+ * @return true if successfully added
+ */
+ public boolean addDevice(Device d) {
+ return this.devices.add(d);
+ }
- /**
- *
- * @param d
- * @return true if device existed and was removed
- */
- public boolean removeDevice(Device d) {
- return this.devices.remove(d);
- }
+ /**
+ * @param d
+ * @return true if device existed and was removed
+ */
+ public boolean removeDevice(Device d) {
+ return this.devices.remove(d);
+ }
- public void removeAllDevice() {
- this.devices.clear();
- }
+ public void removeAllDevice() {
+ this.devices.clear();
+ }
- @Override
- public String toString() {
- return String.format("%d:%d",
- getSwitch().getDpid(),
- getNumber());
- }
+ @Override
+ public String toString() {
+ return String.format("%d:%d",
+ getSwitch().getDpid(),
+ getNumber());
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/Switch.java b/src/main/java/net/onrc/onos/core/topology/Switch.java
index 0b97dfa..d9796be 100644
--- a/src/main/java/net/onrc/onos/core/topology/Switch.java
+++ b/src/main/java/net/onrc/onos/core/topology/Switch.java
@@ -4,28 +4,28 @@
/**
* Interface of Switch Object exposed to the "NB" read-only Topology.
- *
+ * <p/>
* Everything returned by these interfaces must be either Unmodifiable view,
* immutable object, or a copy of the original "SB" In-memory Topology.
- *
*/
public interface Switch {
- public Long getDpid();
+ public Long getDpid();
- public Collection<Port> getPorts();
+ public Collection<Port> getPorts();
- public Port getPort(Long number);
+ public Port getPort(Long number);
- // Graph traversal API
- // XXX What is the Definition of neighbor? Link exist in both direction or one-way is sufficient to be a neighbor, etc.
- public Iterable<Switch> getNeighbors();
+ // Graph traversal API
+ // XXX What is the Definition of neighbor? Link exist in both direction or one-way is sufficient to be a neighbor, etc.
+ public Iterable<Switch> getNeighbors();
- public Iterable<Link> getOutgoingLinks();
- public Iterable<Link> getIncomingLinks();
+ public Iterable<Link> getOutgoingLinks();
- public Link getLinkToNeighbor(Long dpid);
+ public Iterable<Link> getIncomingLinks();
- // XXX Iterable or Collection?
- public Collection<Device> getDevices();
+ public Link getLinkToNeighbor(Long dpid);
+
+ // XXX Iterable or Collection?
+ public Collection<Device> getDevices();
}
diff --git a/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java b/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java
index b36eba2..7ed65d8 100644
--- a/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java
@@ -4,9 +4,8 @@
/**
* Self-contained Switch Object
- *
+ * <p/>
* TODO: We probably want common base class/interface for Self-Contained Event Object
- *
*/
public class SwitchEvent {
protected final Long dpid;
@@ -16,36 +15,36 @@
*/
@Deprecated
public SwitchEvent() {
- dpid = null;
+ dpid = null;
}
public SwitchEvent(Long dpid) {
- this.dpid = dpid;
+ this.dpid = dpid;
}
public Long getDpid() {
- return dpid;
+ return dpid;
}
@Override
public String toString() {
- return "[SwitchEvent 0x" + Long.toHexString(dpid) + "]";
+ return "[SwitchEvent 0x" + Long.toHexString(dpid) + "]";
}
public static final int SWITCHID_BYTES = 2 + 8;
public static ByteBuffer getSwitchID(Long dpid) {
- if (dpid == null) {
- throw new IllegalArgumentException("dpid cannot be null");
- }
- return (ByteBuffer) ByteBuffer.allocate(SwitchEvent.SWITCHID_BYTES).putChar('S').putLong(dpid).flip();
+ if (dpid == null) {
+ throw new IllegalArgumentException("dpid cannot be null");
+ }
+ return (ByteBuffer) ByteBuffer.allocate(SwitchEvent.SWITCHID_BYTES).putChar('S').putLong(dpid).flip();
}
public byte[] getID() {
- return getSwitchID(dpid).array();
+ return getSwitchID(dpid).array();
}
public ByteBuffer getIDasByteBuffer() {
- return getSwitchID(dpid);
+ return getSwitchID(dpid);
}
}
diff --git a/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java b/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java
index 8a45b76..3fe053c 100644
--- a/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java
@@ -12,111 +12,111 @@
/**
* Switch Object stored in In-memory Topology.
- *
+ * <p/>
* TODO REMOVE following design memo: This object itself may hold the DBObject,
* but this Object itself will not issue any read/write to the DataStore.
*/
public class SwitchImpl extends NetworkGraphObject implements Switch {
- private Long dpid;
- // These needs to be ConcurrentCollecton if allowing Graph to be accessed Concurrently
- private final Map<Long, Port> ports;
+ private Long dpid;
+ // These needs to be ConcurrentCollecton if allowing Graph to be accessed Concurrently
+ private final Map<Long, Port> ports;
- public SwitchImpl(NetworkGraph graph, Long dpid) {
- super(graph);
- this.dpid = dpid;
- ports = new HashMap<Long, Port>();
- }
+ public SwitchImpl(NetworkGraph graph, Long dpid) {
+ super(graph);
+ this.dpid = dpid;
+ ports = new HashMap<Long, Port>();
+ }
- @Override
- public Long getDpid() {
- return dpid;
- }
+ @Override
+ public Long getDpid() {
+ return dpid;
+ }
- @Override
- public Collection<Port> getPorts() {
- return Collections.unmodifiableCollection(ports.values());
- }
+ @Override
+ public Collection<Port> getPorts() {
+ return Collections.unmodifiableCollection(ports.values());
+ }
- @Override
- public Port getPort(Long number) {
- return ports.get(number);
- }
+ @Override
+ public Port getPort(Long number) {
+ return ports.get(number);
+ }
- @Override
- public Iterable<Switch> getNeighbors() {
- Set<Switch> neighbors = new HashSet<>();
- for (Link link : getOutgoingLinks()) {
- neighbors.add(link.getDstSwitch());
- }
- // XXX should incoming considered neighbor?
- for (Link link : getIncomingLinks()) {
- neighbors.add(link.getSrcSwitch());
- }
- return neighbors;
- }
+ @Override
+ public Iterable<Switch> getNeighbors() {
+ Set<Switch> neighbors = new HashSet<>();
+ for (Link link : getOutgoingLinks()) {
+ neighbors.add(link.getDstSwitch());
+ }
+ // XXX should incoming considered neighbor?
+ for (Link link : getIncomingLinks()) {
+ neighbors.add(link.getSrcSwitch());
+ }
+ return neighbors;
+ }
- @Override
- public Link getLinkToNeighbor(Long neighborDpid) {
- for (Link link : getOutgoingLinks()) {
- if (link.getDstSwitch().getDpid().equals(neighborDpid) ) {
- return link;
- }
- }
- return null;
- }
+ @Override
+ public Link getLinkToNeighbor(Long neighborDpid) {
+ for (Link link : getOutgoingLinks()) {
+ if (link.getDstSwitch().getDpid().equals(neighborDpid)) {
+ return link;
+ }
+ }
+ return null;
+ }
- @Override
- public Collection<Device> getDevices() {
- // TODO Should switch also store a list of attached devices to avoid
- // calculating this every time?
- List<Device> devices = new ArrayList<Device>();
+ @Override
+ public Collection<Device> getDevices() {
+ // TODO Should switch also store a list of attached devices to avoid
+ // calculating this every time?
+ List<Device> devices = new ArrayList<Device>();
- for (Port port : ports.values()) {
- for (Device device : port.getDevices()) {
- devices.add(device);
- }
- }
+ for (Port port : ports.values()) {
+ for (Device device : port.getDevices()) {
+ devices.add(device);
+ }
+ }
- return devices;
- }
+ return devices;
+ }
- public void addPort(Port port) {
- this.ports.put(port.getNumber(), port);
- }
+ public void addPort(Port port) {
+ this.ports.put(port.getNumber(), port);
+ }
- public Port removePort(Port port) {
- Port p = this.ports.remove(port.getNumber());
- return p;
- }
+ public Port removePort(Port port) {
+ Port p = this.ports.remove(port.getNumber());
+ return p;
+ }
- public Port addPort(Long portNumber) {
- PortImpl port = new PortImpl(graph, this, portNumber);
- ports.put(port.getNumber(), port);
- return port;
- }
+ public Port addPort(Long portNumber) {
+ PortImpl port = new PortImpl(graph, this, portNumber);
+ ports.put(port.getNumber(), port);
+ return port;
+ }
- @Override
- public Iterable<Link> getOutgoingLinks() {
- LinkedList<Link> links = new LinkedList<Link>();
- for (Port port: getPorts()) {
- Link link = port.getOutgoingLink();
- if (link != null) {
- links.add(link);
- }
- }
- return links;
- }
+ @Override
+ public Iterable<Link> getOutgoingLinks() {
+ LinkedList<Link> links = new LinkedList<Link>();
+ for (Port port : getPorts()) {
+ Link link = port.getOutgoingLink();
+ if (link != null) {
+ links.add(link);
+ }
+ }
+ return links;
+ }
- @Override
- public Iterable<Link> getIncomingLinks() {
- LinkedList<Link> links = new LinkedList<Link>();
- for (Port port: getPorts()) {
- Link link = port.getIncomingLink();
- if (link != null) {
- links.add(link);
- }
- }
- return links;
- }
+ @Override
+ public Iterable<Link> getIncomingLinks() {
+ LinkedList<Link> links = new LinkedList<Link>();
+ for (Port port : getPorts()) {
+ Link link = port.getIncomingLink();
+ if (link != null) {
+ links.add(link);
+ }
+ }
+ return links;
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java b/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java
index 84cd5cb..4f3dd20 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java
@@ -2,16 +2,16 @@
/**
* Self-contained Topology event Object
- *
+ * <p/>
* TODO: For now the topology event contains one of the following events:
* Switch, Port, Link, Device. In the future it will contain multiple events
* in a single transaction.
*/
public class TopologyEvent {
- SwitchEvent switchEvent = null; // Set for Switch event
- PortEvent portEvent = null; // Set for Port event
- LinkEvent linkEvent = null; // Set for Link event
- DeviceEvent deviceEvent = null; // Set for Device event
+ SwitchEvent switchEvent = null; // Set for Switch event
+ PortEvent portEvent = null; // Set for Port event
+ LinkEvent linkEvent = null; // Set for Link event
+ DeviceEvent deviceEvent = null; // Set for Device event
/**
* Default constructor.
@@ -25,7 +25,7 @@
* @param switchEvent the Switch event to use.
*/
TopologyEvent(SwitchEvent switchEvent) {
- this.switchEvent = switchEvent;
+ this.switchEvent = switchEvent;
}
/**
@@ -34,7 +34,7 @@
* @param portEvent the Port event to use.
*/
TopologyEvent(PortEvent portEvent) {
- this.portEvent = portEvent;
+ this.portEvent = portEvent;
}
/**
@@ -43,7 +43,7 @@
* @param linkEvent the Link event to use.
*/
TopologyEvent(LinkEvent linkEvent) {
- this.linkEvent = linkEvent;
+ this.linkEvent = linkEvent;
}
/**
@@ -52,7 +52,7 @@
* @param deviceEvent the Device event to use.
*/
TopologyEvent(DeviceEvent deviceEvent) {
- this.deviceEvent = deviceEvent;
+ this.deviceEvent = deviceEvent;
}
/**
@@ -62,15 +62,15 @@
*/
@Override
public String toString() {
- if (switchEvent != null)
- return switchEvent.toString();
- if (portEvent != null)
- return portEvent.toString();
- if (linkEvent != null)
- return linkEvent.toString();
- if (deviceEvent != null)
- return deviceEvent.toString();
- return "[Empty TopologyEvent]";
+ if (switchEvent != null)
+ return switchEvent.toString();
+ if (portEvent != null)
+ return portEvent.toString();
+ if (linkEvent != null)
+ return linkEvent.toString();
+ if (deviceEvent != null)
+ return deviceEvent.toString();
+ return "[Empty TopologyEvent]";
}
/**
@@ -79,14 +79,14 @@
* @return the Topology event ID.
*/
public byte[] getID() {
- if (switchEvent != null)
- return switchEvent.getID();
- if (portEvent != null)
- return portEvent.getID();
- if (linkEvent != null)
- return linkEvent.getID();
- if (deviceEvent != null)
- return deviceEvent.getID();
- return null;
+ if (switchEvent != null)
+ return switchEvent.getID();
+ if (portEvent != null)
+ return portEvent.getID();
+ if (linkEvent != null)
+ return linkEvent.getID();
+ if (deviceEvent != null)
+ return deviceEvent.getID();
+ return null;
}
}
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 b12eaae..4788641 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
@@ -29,22 +29,21 @@
/**
* The "NB" read-only Network Map.
- *
+ * <p/>
* - Maintain Invariant/Relationships between Topology Objects.
- *
+ * <p/>
* TODO To be synchronized based on TopologyEvent Notification.
- *
+ * <p/>
* TODO TBD: Caller is expected to maintain parent/child calling order. Parent
* Object must exist before adding sub component(Add Switch -> Port).
- *
+ * <p/>
* TODO TBD: This class may delay the requested change to handle event
* re-ordering. e.g.) Link Add came in, but Switch was not there.
- *
*/
public class TopologyManager implements NetworkGraphDiscoveryInterface {
private static final Logger log = LoggerFactory
- .getLogger(TopologyManager.class);
+ .getLogger(TopologyManager.class);
private IEventChannel<byte[], TopologyEvent> eventChannel;
public static final String EVENT_CHANNEL_NAME = "onos.topology";
@@ -60,11 +59,11 @@
// NOTE: Switch Events are not affected by the event reordering.
//
private Map<ByteBuffer, PortEvent> reorderedAddedPortEvents =
- new HashMap<ByteBuffer, PortEvent>();
+ new HashMap<ByteBuffer, PortEvent>();
private Map<ByteBuffer, LinkEvent> reorderedAddedLinkEvents =
- new HashMap<ByteBuffer, LinkEvent>();
+ new HashMap<ByteBuffer, LinkEvent>();
private Map<ByteBuffer, DeviceEvent> reorderedAddedDeviceEvents =
- new HashMap<ByteBuffer, DeviceEvent>();
+ new HashMap<ByteBuffer, DeviceEvent>();
//
// Local state for keeping track of locally discovered events so we can
@@ -77,11 +76,11 @@
// and Device events.
//
private Map<Long, Map<ByteBuffer, PortEvent>> discoveredAddedPortEvents =
- new HashMap<>();
+ new HashMap<>();
private Map<Long, Map<ByteBuffer, LinkEvent>> discoveredAddedLinkEvents =
- new HashMap<>();
+ new HashMap<>();
private Map<Long, Map<ByteBuffer, DeviceEvent>> discoveredAddedDeviceEvents =
- new HashMap<>();
+ new HashMap<>();
//
// Local state for keeping track of the application event notifications
@@ -98,15 +97,15 @@
/**
* Constructor.
*
- * @param registryService the Registry Service to use.
+ * @param registryService the Registry Service to use.
* @param networkGraphListeners the collection of Network Graph Listeners
- * to use.
+ * to use.
*/
public TopologyManager(IControllerRegistryService registryService,
- CopyOnWriteArrayList<INetworkGraphListener> networkGraphListeners) {
- datastore = new NetworkGraphDatastore();
- this.registryService = registryService;
- this.networkGraphListeners = networkGraphListeners;
+ CopyOnWriteArrayList<INetworkGraphListener> networkGraphListeners) {
+ datastore = new NetworkGraphDatastore();
+ this.registryService = registryService;
+ this.networkGraphListeners = networkGraphListeners;
}
/**
@@ -115,247 +114,246 @@
* @return the Network Graph.
*/
NetworkGraph getNetworkGraph() {
- return networkGraph;
+ return networkGraph;
}
/**
* Event handler class.
*/
private class EventHandler extends Thread implements
- IEventChannelListener<byte[], TopologyEvent> {
- private BlockingQueue<EventEntry<TopologyEvent>> topologyEvents =
- new LinkedBlockingQueue<EventEntry<TopologyEvent>>();
+ IEventChannelListener<byte[], TopologyEvent> {
+ private BlockingQueue<EventEntry<TopologyEvent>> topologyEvents =
+ new LinkedBlockingQueue<EventEntry<TopologyEvent>>();
- /**
- * Startup processing.
- */
- private void startup() {
- //
- // TODO: Read all state from the database:
- //
- // Collection<EventEntry<TopologyEvent>> collection =
- // readWholeTopologyFromDB();
- //
- // For now, as a shortcut we read it from the datagrid
- //
- Collection<TopologyEvent> topologyEvents =
- eventChannel.getAllEntries();
- Collection<EventEntry<TopologyEvent>> collection =
- new LinkedList<EventEntry<TopologyEvent>>();
+ /**
+ * Startup processing.
+ */
+ private void startup() {
+ //
+ // TODO: Read all state from the database:
+ //
+ // Collection<EventEntry<TopologyEvent>> collection =
+ // readWholeTopologyFromDB();
+ //
+ // For now, as a shortcut we read it from the datagrid
+ //
+ Collection<TopologyEvent> topologyEvents =
+ eventChannel.getAllEntries();
+ Collection<EventEntry<TopologyEvent>> collection =
+ new LinkedList<EventEntry<TopologyEvent>>();
- for (TopologyEvent topologyEvent : topologyEvents) {
- EventEntry<TopologyEvent> eventEntry =
- new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
- topologyEvent);
- collection.add(eventEntry);
- }
- processEvents(collection);
- }
+ for (TopologyEvent topologyEvent : topologyEvents) {
+ EventEntry<TopologyEvent> eventEntry =
+ new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
+ topologyEvent);
+ collection.add(eventEntry);
+ }
+ processEvents(collection);
+ }
- /**
- * Run the thread.
- */
- @Override
- public void run() {
- Collection<EventEntry<TopologyEvent>> collection =
- new LinkedList<EventEntry<TopologyEvent>>();
+ /**
+ * Run the thread.
+ */
+ @Override
+ public void run() {
+ Collection<EventEntry<TopologyEvent>> collection =
+ new LinkedList<EventEntry<TopologyEvent>>();
- this.setName("TopologyManager.EventHandler " + this.getId());
- startup();
+ this.setName("TopologyManager.EventHandler " + this.getId());
+ startup();
- //
- // The main loop
- //
- try {
- while (true) {
- EventEntry<TopologyEvent> eventEntry = topologyEvents.take();
- collection.add(eventEntry);
- topologyEvents.drainTo(collection);
+ //
+ // The main loop
+ //
+ try {
+ while (true) {
+ EventEntry<TopologyEvent> eventEntry = topologyEvents.take();
+ collection.add(eventEntry);
+ topologyEvents.drainTo(collection);
- processEvents(collection);
- collection.clear();
- }
- } catch (Exception exception) {
- log.debug("Exception processing Topology Events: ", exception);
- }
- }
+ processEvents(collection);
+ collection.clear();
+ }
+ } catch (Exception exception) {
+ log.debug("Exception processing Topology Events: ", exception);
+ }
+ }
- /**
- * Process all topology events.
- *
- * @param events the events to process.
- */
- private void processEvents(Collection<EventEntry<TopologyEvent>> events) {
- // Local state for computing the final set of events
- Map<ByteBuffer, SwitchEvent> addedSwitchEvents = new HashMap<>();
- Map<ByteBuffer, SwitchEvent> removedSwitchEvents = new HashMap<>();
- Map<ByteBuffer, PortEvent> addedPortEvents = new HashMap<>();
- Map<ByteBuffer, PortEvent> removedPortEvents = new HashMap<>();
- Map<ByteBuffer, LinkEvent> addedLinkEvents = new HashMap<>();
- Map<ByteBuffer, LinkEvent> removedLinkEvents = new HashMap<>();
- Map<ByteBuffer, DeviceEvent> addedDeviceEvents = new HashMap<>();
- Map<ByteBuffer, DeviceEvent> removedDeviceEvents = new HashMap<>();
+ /**
+ * Process all topology events.
+ *
+ * @param events the events to process.
+ */
+ private void processEvents(Collection<EventEntry<TopologyEvent>> events) {
+ // Local state for computing the final set of events
+ Map<ByteBuffer, SwitchEvent> addedSwitchEvents = new HashMap<>();
+ Map<ByteBuffer, SwitchEvent> removedSwitchEvents = new HashMap<>();
+ Map<ByteBuffer, PortEvent> addedPortEvents = new HashMap<>();
+ Map<ByteBuffer, PortEvent> removedPortEvents = new HashMap<>();
+ Map<ByteBuffer, LinkEvent> addedLinkEvents = new HashMap<>();
+ Map<ByteBuffer, LinkEvent> removedLinkEvents = new HashMap<>();
+ Map<ByteBuffer, DeviceEvent> addedDeviceEvents = new HashMap<>();
+ Map<ByteBuffer, DeviceEvent> removedDeviceEvents = new HashMap<>();
- //
- // Classify and suppress matching events
- //
- for (EventEntry<TopologyEvent> event : events) {
- TopologyEvent topologyEvent = event.eventData();
- SwitchEvent switchEvent = topologyEvent.switchEvent;
- PortEvent portEvent = topologyEvent.portEvent;
- LinkEvent linkEvent = topologyEvent.linkEvent;
- DeviceEvent deviceEvent = topologyEvent.deviceEvent;
+ //
+ // Classify and suppress matching events
+ //
+ for (EventEntry<TopologyEvent> event : events) {
+ TopologyEvent topologyEvent = event.eventData();
+ SwitchEvent switchEvent = topologyEvent.switchEvent;
+ PortEvent portEvent = topologyEvent.portEvent;
+ LinkEvent linkEvent = topologyEvent.linkEvent;
+ DeviceEvent deviceEvent = topologyEvent.deviceEvent;
- //
- // Extract the events
- //
- switch (event.eventType()) {
- case ENTRY_ADD:
- log.debug("Topology event ENTRY_ADD: {}", topologyEvent);
- if (switchEvent != null) {
- ByteBuffer id = switchEvent.getIDasByteBuffer();
- addedSwitchEvents.put(id, switchEvent);
- removedSwitchEvents.remove(id);
- // Switch Events are not affected by event reordering
- }
- if (portEvent != null) {
- ByteBuffer id = portEvent.getIDasByteBuffer();
- addedPortEvents.put(id, portEvent);
- removedPortEvents.remove(id);
- reorderedAddedPortEvents.remove(id);
- }
- if (linkEvent != null) {
- ByteBuffer id = linkEvent.getIDasByteBuffer();
- addedLinkEvents.put(id, linkEvent);
- removedLinkEvents.remove(id);
- reorderedAddedLinkEvents.remove(id);
- }
- if (deviceEvent != null) {
- ByteBuffer id = deviceEvent.getIDasByteBuffer();
- addedDeviceEvents.put(id, deviceEvent);
- removedDeviceEvents.remove(id);
- reorderedAddedDeviceEvents.remove(id);
- }
- break;
- case ENTRY_REMOVE:
- log.debug("Topology event ENTRY_REMOVE: {}", topologyEvent);
- if (switchEvent != null) {
- ByteBuffer id = switchEvent.getIDasByteBuffer();
- addedSwitchEvents.remove(id);
- removedSwitchEvents.put(id, switchEvent);
- // Switch Events are not affected by event reordering
- }
- if (portEvent != null) {
- ByteBuffer id = portEvent.getIDasByteBuffer();
- addedPortEvents.remove(id);
- removedPortEvents.put(id, portEvent);
- reorderedAddedPortEvents.remove(id);
- }
- if (linkEvent != null) {
- ByteBuffer id = linkEvent.getIDasByteBuffer();
- addedLinkEvents.remove(id);
- removedLinkEvents.put(id, linkEvent);
- reorderedAddedLinkEvents.remove(id);
- }
- if (deviceEvent != null) {
- ByteBuffer id = deviceEvent.getIDasByteBuffer();
- addedDeviceEvents.remove(id);
- removedDeviceEvents.put(id, deviceEvent);
- reorderedAddedDeviceEvents.remove(id);
- }
- break;
- }
- }
+ //
+ // Extract the events
+ //
+ switch (event.eventType()) {
+ case ENTRY_ADD:
+ log.debug("Topology event ENTRY_ADD: {}", topologyEvent);
+ if (switchEvent != null) {
+ ByteBuffer id = switchEvent.getIDasByteBuffer();
+ addedSwitchEvents.put(id, switchEvent);
+ removedSwitchEvents.remove(id);
+ // Switch Events are not affected by event reordering
+ }
+ if (portEvent != null) {
+ ByteBuffer id = portEvent.getIDasByteBuffer();
+ addedPortEvents.put(id, portEvent);
+ removedPortEvents.remove(id);
+ reorderedAddedPortEvents.remove(id);
+ }
+ if (linkEvent != null) {
+ ByteBuffer id = linkEvent.getIDasByteBuffer();
+ addedLinkEvents.put(id, linkEvent);
+ removedLinkEvents.remove(id);
+ reorderedAddedLinkEvents.remove(id);
+ }
+ if (deviceEvent != null) {
+ ByteBuffer id = deviceEvent.getIDasByteBuffer();
+ addedDeviceEvents.put(id, deviceEvent);
+ removedDeviceEvents.remove(id);
+ reorderedAddedDeviceEvents.remove(id);
+ }
+ break;
+ case ENTRY_REMOVE:
+ log.debug("Topology event ENTRY_REMOVE: {}", topologyEvent);
+ if (switchEvent != null) {
+ ByteBuffer id = switchEvent.getIDasByteBuffer();
+ addedSwitchEvents.remove(id);
+ removedSwitchEvents.put(id, switchEvent);
+ // Switch Events are not affected by event reordering
+ }
+ if (portEvent != null) {
+ ByteBuffer id = portEvent.getIDasByteBuffer();
+ addedPortEvents.remove(id);
+ removedPortEvents.put(id, portEvent);
+ reorderedAddedPortEvents.remove(id);
+ }
+ if (linkEvent != null) {
+ ByteBuffer id = linkEvent.getIDasByteBuffer();
+ addedLinkEvents.remove(id);
+ removedLinkEvents.put(id, linkEvent);
+ reorderedAddedLinkEvents.remove(id);
+ }
+ if (deviceEvent != null) {
+ ByteBuffer id = deviceEvent.getIDasByteBuffer();
+ addedDeviceEvents.remove(id);
+ removedDeviceEvents.put(id, deviceEvent);
+ reorderedAddedDeviceEvents.remove(id);
+ }
+ break;
+ }
+ }
- //
- // Lock the Network Graph while it is modified
- //
- networkGraph.acquireWriteLock();
+ //
+ // Lock the Network Graph while it is modified
+ //
+ networkGraph.acquireWriteLock();
- try {
- //
- // Apply the classified events.
- //
- // Apply the "add" events in the proper order:
- // switch, port, link, device
- //
- for (SwitchEvent switchEvent : addedSwitchEvents.values())
- addSwitch(switchEvent);
- for (PortEvent portEvent : addedPortEvents.values())
- addPort(portEvent);
- for (LinkEvent linkEvent : addedLinkEvents.values())
- addLink(linkEvent);
- for (DeviceEvent deviceEvent : addedDeviceEvents.values())
- addDevice(deviceEvent);
- //
- // Apply the "remove" events in the reverse order:
- // device, link, port, switch
- //
- for (DeviceEvent deviceEvent : removedDeviceEvents.values())
- removeDevice(deviceEvent);
- for (LinkEvent linkEvent : removedLinkEvents.values())
- removeLink(linkEvent);
- for (PortEvent portEvent : removedPortEvents.values())
- removePort(portEvent);
- for (SwitchEvent switchEvent : removedSwitchEvents.values())
- removeSwitch(switchEvent);
+ try {
+ //
+ // Apply the classified events.
+ //
+ // Apply the "add" events in the proper order:
+ // switch, port, link, device
+ //
+ for (SwitchEvent switchEvent : addedSwitchEvents.values())
+ addSwitch(switchEvent);
+ for (PortEvent portEvent : addedPortEvents.values())
+ addPort(portEvent);
+ for (LinkEvent linkEvent : addedLinkEvents.values())
+ addLink(linkEvent);
+ for (DeviceEvent deviceEvent : addedDeviceEvents.values())
+ addDevice(deviceEvent);
+ //
+ // Apply the "remove" events in the reverse order:
+ // device, link, port, switch
+ //
+ for (DeviceEvent deviceEvent : removedDeviceEvents.values())
+ removeDevice(deviceEvent);
+ for (LinkEvent linkEvent : removedLinkEvents.values())
+ removeLink(linkEvent);
+ for (PortEvent portEvent : removedPortEvents.values())
+ removePort(portEvent);
+ for (SwitchEvent switchEvent : removedSwitchEvents.values())
+ removeSwitch(switchEvent);
- //
- // Apply reordered events
- //
- applyReorderedEvents(! addedSwitchEvents.isEmpty(),
- ! addedPortEvents.isEmpty());
+ //
+ // Apply reordered events
+ //
+ applyReorderedEvents(!addedSwitchEvents.isEmpty(),
+ !addedPortEvents.isEmpty());
- }
- finally {
- //
- // Network Graph modifications completed: Release the lock
- //
- networkGraph.releaseWriteLock();
- }
+ } finally {
+ //
+ // Network Graph modifications completed: Release the lock
+ //
+ networkGraph.releaseWriteLock();
+ }
- //
- // Dispatch the Topology Notification Events to the applications
- //
- dispatchNetworkGraphEvents();
- }
+ //
+ // Dispatch the Topology Notification Events to the applications
+ //
+ dispatchNetworkGraphEvents();
+ }
- /**
- * Receive a notification that an entry is added.
- *
- * @param value the value for the entry.
- */
- @Override
- public void entryAdded(TopologyEvent value) {
- EventEntry<TopologyEvent> eventEntry =
- new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
- value);
- topologyEvents.add(eventEntry);
- }
+ /**
+ * Receive a notification that an entry is added.
+ *
+ * @param value the value for the entry.
+ */
+ @Override
+ public void entryAdded(TopologyEvent value) {
+ EventEntry<TopologyEvent> eventEntry =
+ new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
+ value);
+ topologyEvents.add(eventEntry);
+ }
- /**
- * Receive a notification that an entry is removed.
- *
- * @param value the value for the entry.
- */
- @Override
- public void entryRemoved(TopologyEvent value) {
- EventEntry<TopologyEvent> eventEntry =
- new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_REMOVE,
- value);
- topologyEvents.add(eventEntry);
- }
+ /**
+ * Receive a notification that an entry is removed.
+ *
+ * @param value the value for the entry.
+ */
+ @Override
+ public void entryRemoved(TopologyEvent value) {
+ EventEntry<TopologyEvent> eventEntry =
+ new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_REMOVE,
+ value);
+ topologyEvents.add(eventEntry);
+ }
- /**
- * Receive a notification that an entry is updated.
- *
- * @param value the value for the entry.
- */
- @Override
- public void entryUpdated(TopologyEvent value) {
- // NOTE: The ADD and UPDATE events are processed in same way
- entryAdded(value);
- }
+ /**
+ * Receive a notification that an entry is updated.
+ *
+ * @param value the value for the entry.
+ */
+ @Override
+ public void entryUpdated(TopologyEvent value) {
+ // NOTE: The ADD and UPDATE events are processed in same way
+ entryAdded(value);
+ }
}
/**
@@ -364,175 +362,175 @@
* @param datagridService the datagrid service to use.
*/
void startup(IDatagridService datagridService) {
- eventChannel = datagridService.addListener(EVENT_CHANNEL_NAME,
- eventHandler,
- byte[].class,
- TopologyEvent.class);
- eventHandler.start();
+ eventChannel = datagridService.addListener(EVENT_CHANNEL_NAME,
+ eventHandler,
+ byte[].class,
+ TopologyEvent.class);
+ eventHandler.start();
}
/**
* Dispatch Network Graph Events to the listeners.
*/
private void dispatchNetworkGraphEvents() {
- if (apiAddedSwitchEvents.isEmpty() &&
- apiRemovedSwitchEvents.isEmpty() &&
- apiAddedPortEvents.isEmpty() &&
- apiRemovedPortEvents.isEmpty() &&
- apiAddedLinkEvents.isEmpty() &&
- apiRemovedLinkEvents.isEmpty() &&
- apiAddedDeviceEvents.isEmpty() &&
- apiRemovedDeviceEvents.isEmpty()) {
- return; // No events to dispatch
- }
+ if (apiAddedSwitchEvents.isEmpty() &&
+ apiRemovedSwitchEvents.isEmpty() &&
+ apiAddedPortEvents.isEmpty() &&
+ apiRemovedPortEvents.isEmpty() &&
+ apiAddedLinkEvents.isEmpty() &&
+ apiRemovedLinkEvents.isEmpty() &&
+ apiAddedDeviceEvents.isEmpty() &&
+ apiRemovedDeviceEvents.isEmpty()) {
+ return; // No events to dispatch
+ }
- if (log.isDebugEnabled()) {
- //
- // Debug statements
- // TODO: Those statements should be removed in the future
- //
- for (SwitchEvent switchEvent : apiAddedSwitchEvents)
- log.debug("Dispatch Network Graph Event: ADDED {}", switchEvent);
- for (SwitchEvent switchEvent : apiRemovedSwitchEvents)
- log.debug("Dispatch Network Graph Event: REMOVED {}", switchEvent);
- for (PortEvent portEvent : apiAddedPortEvents)
- log.debug("Dispatch Network Graph Event: ADDED {}", portEvent);
- for (PortEvent portEvent : apiRemovedPortEvents)
- log.debug("Dispatch Network Graph Event: REMOVED {}", portEvent);
- for (LinkEvent linkEvent : apiAddedLinkEvents)
- log.debug("Dispatch Network Graph Event: ADDED {}", linkEvent);
- for (LinkEvent linkEvent : apiRemovedLinkEvents)
- log.debug("Dispatch Network Graph Event: REMOVED {}", linkEvent);
- for (DeviceEvent deviceEvent : apiAddedDeviceEvents)
- log.debug("Dispatch Network Graph Event: ADDED {}", deviceEvent);
- for (DeviceEvent deviceEvent : apiRemovedDeviceEvents)
- log.debug("Dispatch Network Graph Event: REMOVED {}", deviceEvent);
- }
+ if (log.isDebugEnabled()) {
+ //
+ // Debug statements
+ // TODO: Those statements should be removed in the future
+ //
+ for (SwitchEvent switchEvent : apiAddedSwitchEvents)
+ log.debug("Dispatch Network Graph Event: ADDED {}", switchEvent);
+ for (SwitchEvent switchEvent : apiRemovedSwitchEvents)
+ log.debug("Dispatch Network Graph Event: REMOVED {}", switchEvent);
+ for (PortEvent portEvent : apiAddedPortEvents)
+ log.debug("Dispatch Network Graph Event: ADDED {}", portEvent);
+ for (PortEvent portEvent : apiRemovedPortEvents)
+ log.debug("Dispatch Network Graph Event: REMOVED {}", portEvent);
+ for (LinkEvent linkEvent : apiAddedLinkEvents)
+ log.debug("Dispatch Network Graph Event: ADDED {}", linkEvent);
+ for (LinkEvent linkEvent : apiRemovedLinkEvents)
+ log.debug("Dispatch Network Graph Event: REMOVED {}", linkEvent);
+ for (DeviceEvent deviceEvent : apiAddedDeviceEvents)
+ log.debug("Dispatch Network Graph Event: ADDED {}", deviceEvent);
+ for (DeviceEvent deviceEvent : apiRemovedDeviceEvents)
+ log.debug("Dispatch Network Graph Event: REMOVED {}", deviceEvent);
+ }
- // Deliver the events
- for (INetworkGraphListener listener : this.networkGraphListeners) {
- // TODO: Should copy before handing them over to listener?
- listener.networkGraphEvents(apiAddedSwitchEvents,
- apiRemovedSwitchEvents,
- apiAddedPortEvents,
- apiRemovedPortEvents,
- apiAddedLinkEvents,
- apiRemovedLinkEvents,
- apiAddedDeviceEvents,
- apiRemovedDeviceEvents);
- }
+ // Deliver the events
+ for (INetworkGraphListener listener : this.networkGraphListeners) {
+ // TODO: Should copy before handing them over to listener?
+ listener.networkGraphEvents(apiAddedSwitchEvents,
+ apiRemovedSwitchEvents,
+ apiAddedPortEvents,
+ apiRemovedPortEvents,
+ apiAddedLinkEvents,
+ apiRemovedLinkEvents,
+ apiAddedDeviceEvents,
+ apiRemovedDeviceEvents);
+ }
- //
- // Cleanup
- //
- apiAddedSwitchEvents.clear();
- apiRemovedSwitchEvents.clear();
- apiAddedPortEvents.clear();
- apiRemovedPortEvents.clear();
- apiAddedLinkEvents.clear();
- apiRemovedLinkEvents.clear();
- apiAddedDeviceEvents.clear();
- apiRemovedDeviceEvents.clear();
+ //
+ // Cleanup
+ //
+ apiAddedSwitchEvents.clear();
+ apiRemovedSwitchEvents.clear();
+ apiAddedPortEvents.clear();
+ apiRemovedPortEvents.clear();
+ apiAddedLinkEvents.clear();
+ apiRemovedLinkEvents.clear();
+ apiAddedDeviceEvents.clear();
+ apiRemovedDeviceEvents.clear();
}
/**
* Apply reordered events.
*
* @param hasAddedSwitchEvents true if there were Added Switch Events.
- * @param hasAddedPortEvents true if there were Added Port Events.
+ * @param hasAddedPortEvents true if there were Added Port Events.
*/
private void applyReorderedEvents(boolean hasAddedSwitchEvents,
- boolean hasAddedPortEvents) {
- if (! (hasAddedSwitchEvents || hasAddedPortEvents))
- return; // Nothing to do
+ boolean hasAddedPortEvents) {
+ if (!(hasAddedSwitchEvents || hasAddedPortEvents))
+ return; // Nothing to do
- //
- // Try to apply the reordered events.
- //
- // NOTE: For simplicity we try to apply all events of a particular
- // type if any "parent" type event was processed:
- // - Apply reordered Port Events if Switches were added
- // - Apply reordered Link and Device Events if Switches or Ports
- // were added
- //
+ //
+ // Try to apply the reordered events.
+ //
+ // NOTE: For simplicity we try to apply all events of a particular
+ // type if any "parent" type event was processed:
+ // - Apply reordered Port Events if Switches were added
+ // - Apply reordered Link and Device Events if Switches or Ports
+ // were added
+ //
- //
- // Apply reordered Port Events if Switches were added
- //
- if (hasAddedSwitchEvents) {
- Map<ByteBuffer, PortEvent> portEvents = reorderedAddedPortEvents;
- reorderedAddedPortEvents = new HashMap<>();
- for (PortEvent portEvent : portEvents.values())
- addPort(portEvent);
- }
- //
- // Apply reordered Link and Device Events if Switches or Ports
- // were added.
- //
- Map<ByteBuffer, LinkEvent> linkEvents = reorderedAddedLinkEvents;
- reorderedAddedLinkEvents = new HashMap<>();
- for (LinkEvent linkEvent : linkEvents.values())
- addLink(linkEvent);
- //
- Map<ByteBuffer, DeviceEvent> deviceEvents = reorderedAddedDeviceEvents;
- reorderedAddedDeviceEvents = new HashMap<>();
- for (DeviceEvent deviceEvent : deviceEvents.values())
- addDevice(deviceEvent);
+ //
+ // Apply reordered Port Events if Switches were added
+ //
+ if (hasAddedSwitchEvents) {
+ Map<ByteBuffer, PortEvent> portEvents = reorderedAddedPortEvents;
+ reorderedAddedPortEvents = new HashMap<>();
+ for (PortEvent portEvent : portEvents.values())
+ addPort(portEvent);
+ }
+ //
+ // Apply reordered Link and Device Events if Switches or Ports
+ // were added.
+ //
+ Map<ByteBuffer, LinkEvent> linkEvents = reorderedAddedLinkEvents;
+ reorderedAddedLinkEvents = new HashMap<>();
+ for (LinkEvent linkEvent : linkEvents.values())
+ addLink(linkEvent);
+ //
+ Map<ByteBuffer, DeviceEvent> deviceEvents = reorderedAddedDeviceEvents;
+ reorderedAddedDeviceEvents = new HashMap<>();
+ for (DeviceEvent deviceEvent : deviceEvents.values())
+ addDevice(deviceEvent);
}
/**
* Switch discovered event.
*
* @param switchEvent the switch event.
- * @param portEvents the corresponding port events for the switch.
+ * @param portEvents the corresponding port events for the switch.
*/
@Override
public void putSwitchDiscoveryEvent(SwitchEvent switchEvent,
- Collection<PortEvent> portEvents) {
- if (datastore.addSwitch(switchEvent, portEvents)) {
- // Send out notification
- TopologyEvent topologyEvent = new TopologyEvent(switchEvent);
- eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
-
- // Send out notification for each port
- for (PortEvent portEvent : portEvents) {
- topologyEvent = new TopologyEvent(portEvent);
- eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
- }
+ Collection<PortEvent> portEvents) {
+ if (datastore.addSwitch(switchEvent, portEvents)) {
+ // Send out notification
+ TopologyEvent topologyEvent = new TopologyEvent(switchEvent);
+ eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
- //
- // Keep track of the added ports
- //
- // Get the old Port Events
- Map<ByteBuffer, PortEvent> oldPortEvents =
- discoveredAddedPortEvents.get(switchEvent.getDpid());
- if (oldPortEvents == null)
- oldPortEvents = new HashMap<>();
+ // Send out notification for each port
+ for (PortEvent portEvent : portEvents) {
+ topologyEvent = new TopologyEvent(portEvent);
+ eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
+ }
- // Store the new Port Events in the local cache
- Map<ByteBuffer, PortEvent> newPortEvents = new HashMap<>();
- for (PortEvent portEvent : portEvents) {
- ByteBuffer id = portEvent.getIDasByteBuffer();
- newPortEvents.put(id, portEvent);
- }
- discoveredAddedPortEvents.put(switchEvent.getDpid(),
- newPortEvents);
+ //
+ // Keep track of the added ports
+ //
+ // Get the old Port Events
+ Map<ByteBuffer, PortEvent> oldPortEvents =
+ discoveredAddedPortEvents.get(switchEvent.getDpid());
+ if (oldPortEvents == null)
+ oldPortEvents = new HashMap<>();
- //
- // Extract the removed ports
- //
- List<PortEvent> removedPortEvents = new LinkedList<>();
- for (Map.Entry<ByteBuffer, PortEvent> entry : oldPortEvents.entrySet()) {
- ByteBuffer key = entry.getKey();
- PortEvent portEvent = entry.getValue();
- if (! newPortEvents.containsKey(key))
- removedPortEvents.add(portEvent);
- }
+ // Store the new Port Events in the local cache
+ Map<ByteBuffer, PortEvent> newPortEvents = new HashMap<>();
+ for (PortEvent portEvent : portEvents) {
+ ByteBuffer id = portEvent.getIDasByteBuffer();
+ newPortEvents.put(id, portEvent);
+ }
+ discoveredAddedPortEvents.put(switchEvent.getDpid(),
+ newPortEvents);
- // Cleanup old removed ports
- for (PortEvent portEvent : removedPortEvents)
- removePortDiscoveryEvent(portEvent);
- }
+ //
+ // Extract the removed ports
+ //
+ List<PortEvent> removedPortEvents = new LinkedList<>();
+ for (Map.Entry<ByteBuffer, PortEvent> entry : oldPortEvents.entrySet()) {
+ ByteBuffer key = entry.getKey();
+ PortEvent portEvent = entry.getValue();
+ if (!newPortEvents.containsKey(key))
+ removedPortEvents.add(portEvent);
+ }
+
+ // Cleanup old removed ports
+ for (PortEvent portEvent : removedPortEvents)
+ removePortDiscoveryEvent(portEvent);
+ }
}
/**
@@ -542,47 +540,47 @@
*/
@Override
public void removeSwitchDiscoveryEvent(SwitchEvent switchEvent) {
- // Get the old Port Events
- Map<ByteBuffer, PortEvent> oldPortEvents =
- discoveredAddedPortEvents.get(switchEvent.getDpid());
- if (oldPortEvents == null)
- oldPortEvents = new HashMap<>();
+ // Get the old Port Events
+ Map<ByteBuffer, PortEvent> oldPortEvents =
+ discoveredAddedPortEvents.get(switchEvent.getDpid());
+ if (oldPortEvents == null)
+ oldPortEvents = new HashMap<>();
- if (datastore.deactivateSwitch(switchEvent, oldPortEvents.values())) {
- // Send out notification
- eventChannel.removeEntry(switchEvent.getID());
+ if (datastore.deactivateSwitch(switchEvent, oldPortEvents.values())) {
+ // Send out notification
+ eventChannel.removeEntry(switchEvent.getID());
- //
- // Send out notification for each port.
- //
- // NOTE: We don't use removePortDiscoveryEvent() for the cleanup,
- // because it will attempt to remove the port from the database,
- // and the deactiveSwitch() call above already removed all ports.
- //
- for (PortEvent portEvent : oldPortEvents.values())
- eventChannel.removeEntry(portEvent.getID());
- discoveredAddedPortEvents.remove(switchEvent.getDpid());
+ //
+ // Send out notification for each port.
+ //
+ // NOTE: We don't use removePortDiscoveryEvent() for the cleanup,
+ // because it will attempt to remove the port from the database,
+ // and the deactiveSwitch() call above already removed all ports.
+ //
+ for (PortEvent portEvent : oldPortEvents.values())
+ eventChannel.removeEntry(portEvent.getID());
+ discoveredAddedPortEvents.remove(switchEvent.getDpid());
- // Cleanup for each link
- Map<ByteBuffer, LinkEvent> oldLinkEvents =
- discoveredAddedLinkEvents.get(switchEvent.getDpid());
- if (oldLinkEvents != null) {
- for (LinkEvent linkEvent : new ArrayList<>(oldLinkEvents.values())) {
- removeLinkDiscoveryEvent(linkEvent);
- }
- discoveredAddedLinkEvents.remove(switchEvent.getDpid());
- }
+ // Cleanup for each link
+ Map<ByteBuffer, LinkEvent> oldLinkEvents =
+ discoveredAddedLinkEvents.get(switchEvent.getDpid());
+ if (oldLinkEvents != null) {
+ for (LinkEvent linkEvent : new ArrayList<>(oldLinkEvents.values())) {
+ removeLinkDiscoveryEvent(linkEvent);
+ }
+ discoveredAddedLinkEvents.remove(switchEvent.getDpid());
+ }
- // Cleanup for each device
- Map<ByteBuffer, DeviceEvent> oldDeviceEvents =
- discoveredAddedDeviceEvents.get(switchEvent.getDpid());
- if (oldDeviceEvents != null) {
- for (DeviceEvent deviceEvent : new ArrayList<>(oldDeviceEvents.values())) {
- removeDeviceDiscoveryEvent(deviceEvent);
- }
- discoveredAddedDeviceEvents.remove(switchEvent.getDpid());
- }
- }
+ // Cleanup for each device
+ Map<ByteBuffer, DeviceEvent> oldDeviceEvents =
+ discoveredAddedDeviceEvents.get(switchEvent.getDpid());
+ if (oldDeviceEvents != null) {
+ for (DeviceEvent deviceEvent : new ArrayList<>(oldDeviceEvents.values())) {
+ removeDeviceDiscoveryEvent(deviceEvent);
+ }
+ discoveredAddedDeviceEvents.remove(switchEvent.getDpid());
+ }
+ }
}
/**
@@ -592,22 +590,22 @@
*/
@Override
public void putPortDiscoveryEvent(PortEvent portEvent) {
- if (datastore.addPort(portEvent)) {
- // Send out notification
- TopologyEvent topologyEvent = new TopologyEvent(portEvent);
- eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
+ if (datastore.addPort(portEvent)) {
+ // Send out notification
+ TopologyEvent topologyEvent = new TopologyEvent(portEvent);
+ eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
- // Store the new Port Event in the local cache
- Map<ByteBuffer, PortEvent> oldPortEvents =
- discoveredAddedPortEvents.get(portEvent.getDpid());
- if (oldPortEvents == null) {
- oldPortEvents = new HashMap<>();
- discoveredAddedPortEvents.put(portEvent.getDpid(),
- oldPortEvents);
- }
- ByteBuffer id = portEvent.getIDasByteBuffer();
- oldPortEvents.put(id, portEvent);
- }
+ // Store the new Port Event in the local cache
+ Map<ByteBuffer, PortEvent> oldPortEvents =
+ discoveredAddedPortEvents.get(portEvent.getDpid());
+ if (oldPortEvents == null) {
+ oldPortEvents = new HashMap<>();
+ discoveredAddedPortEvents.put(portEvent.getDpid(),
+ oldPortEvents);
+ }
+ ByteBuffer id = portEvent.getIDasByteBuffer();
+ oldPortEvents.put(id, portEvent);
+ }
}
/**
@@ -617,49 +615,49 @@
*/
@Override
public void removePortDiscoveryEvent(PortEvent portEvent) {
- if (datastore.deactivatePort(portEvent)) {
- // Send out notification
- eventChannel.removeEntry(portEvent.getID());
+ if (datastore.deactivatePort(portEvent)) {
+ // Send out notification
+ eventChannel.removeEntry(portEvent.getID());
- // Cleanup the Port Event from the local cache
- Map<ByteBuffer, PortEvent> oldPortEvents =
- discoveredAddedPortEvents.get(portEvent.getDpid());
- if (oldPortEvents != null) {
- ByteBuffer id = portEvent.getIDasByteBuffer();
- oldPortEvents.remove(id);
- }
+ // Cleanup the Port Event from the local cache
+ Map<ByteBuffer, PortEvent> oldPortEvents =
+ discoveredAddedPortEvents.get(portEvent.getDpid());
+ if (oldPortEvents != null) {
+ ByteBuffer id = portEvent.getIDasByteBuffer();
+ oldPortEvents.remove(id);
+ }
- // Cleanup for the incoming link
- Map<ByteBuffer, LinkEvent> oldLinkEvents =
- discoveredAddedLinkEvents.get(portEvent.getDpid());
- if (oldLinkEvents != null) {
- for (LinkEvent linkEvent : new ArrayList<>(oldLinkEvents.values())) {
- if (linkEvent.getDst().equals(portEvent.id)) {
- removeLinkDiscoveryEvent(linkEvent);
- // XXX If we change our model to allow multiple Link on
- // a Port, this loop must be fixed to allow continuing.
- break;
- }
- }
- }
+ // Cleanup for the incoming link
+ Map<ByteBuffer, LinkEvent> oldLinkEvents =
+ discoveredAddedLinkEvents.get(portEvent.getDpid());
+ if (oldLinkEvents != null) {
+ for (LinkEvent linkEvent : new ArrayList<>(oldLinkEvents.values())) {
+ if (linkEvent.getDst().equals(portEvent.id)) {
+ removeLinkDiscoveryEvent(linkEvent);
+ // XXX If we change our model to allow multiple Link on
+ // a Port, this loop must be fixed to allow continuing.
+ break;
+ }
+ }
+ }
- // Cleanup for the connected devices
- // TODO: The implementation below is probably wrong
- List<DeviceEvent> removedDeviceEvents = new LinkedList<>();
- Map<ByteBuffer, DeviceEvent> oldDeviceEvents =
- discoveredAddedDeviceEvents.get(portEvent.getDpid());
- if (oldDeviceEvents != null) {
- for (DeviceEvent deviceEvent : new ArrayList<>(oldDeviceEvents.values())) {
- for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
- if (swp.equals(portEvent.id)) {
- removedDeviceEvents.add(deviceEvent);
- }
- }
- }
- for (DeviceEvent deviceEvent : removedDeviceEvents)
- removeDeviceDiscoveryEvent(deviceEvent);
- }
- }
+ // Cleanup for the connected devices
+ // TODO: The implementation below is probably wrong
+ List<DeviceEvent> removedDeviceEvents = new LinkedList<>();
+ Map<ByteBuffer, DeviceEvent> oldDeviceEvents =
+ discoveredAddedDeviceEvents.get(portEvent.getDpid());
+ if (oldDeviceEvents != null) {
+ for (DeviceEvent deviceEvent : new ArrayList<>(oldDeviceEvents.values())) {
+ for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
+ if (swp.equals(portEvent.id)) {
+ removedDeviceEvents.add(deviceEvent);
+ }
+ }
+ }
+ for (DeviceEvent deviceEvent : removedDeviceEvents)
+ removeDeviceDiscoveryEvent(deviceEvent);
+ }
+ }
}
/**
@@ -669,22 +667,22 @@
*/
@Override
public void putLinkDiscoveryEvent(LinkEvent linkEvent) {
- if (datastore.addLink(linkEvent)) {
- // Send out notification
- TopologyEvent topologyEvent = new TopologyEvent(linkEvent);
- eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
+ if (datastore.addLink(linkEvent)) {
+ // Send out notification
+ TopologyEvent topologyEvent = new TopologyEvent(linkEvent);
+ eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
- // Store the new Link Event in the local cache
- Map<ByteBuffer, LinkEvent> oldLinkEvents =
- discoveredAddedLinkEvents.get(linkEvent.getDst().getDpid());
- if (oldLinkEvents == null) {
- oldLinkEvents = new HashMap<>();
- discoveredAddedLinkEvents.put(linkEvent.getDst().getDpid(),
- oldLinkEvents);
- }
- ByteBuffer id = linkEvent.getIDasByteBuffer();
- oldLinkEvents.put(id, linkEvent);
- }
+ // Store the new Link Event in the local cache
+ Map<ByteBuffer, LinkEvent> oldLinkEvents =
+ discoveredAddedLinkEvents.get(linkEvent.getDst().getDpid());
+ if (oldLinkEvents == null) {
+ oldLinkEvents = new HashMap<>();
+ discoveredAddedLinkEvents.put(linkEvent.getDst().getDpid(),
+ oldLinkEvents);
+ }
+ ByteBuffer id = linkEvent.getIDasByteBuffer();
+ oldLinkEvents.put(id, linkEvent);
+ }
}
/**
@@ -694,18 +692,18 @@
*/
@Override
public void removeLinkDiscoveryEvent(LinkEvent linkEvent) {
- if (datastore.removeLink(linkEvent)) {
- // Send out notification
- eventChannel.removeEntry(linkEvent.getID());
+ if (datastore.removeLink(linkEvent)) {
+ // Send out notification
+ eventChannel.removeEntry(linkEvent.getID());
- // Cleanup the Link Event from the local cache
- Map<ByteBuffer, LinkEvent> oldLinkEvents =
- discoveredAddedLinkEvents.get(linkEvent.getDst().getDpid());
- if (oldLinkEvents != null) {
- ByteBuffer id = linkEvent.getIDasByteBuffer();
- oldLinkEvents.remove(id);
- }
- }
+ // Cleanup the Link Event from the local cache
+ Map<ByteBuffer, LinkEvent> oldLinkEvents =
+ discoveredAddedLinkEvents.get(linkEvent.getDst().getDpid());
+ if (oldLinkEvents != null) {
+ ByteBuffer id = linkEvent.getIDasByteBuffer();
+ oldLinkEvents.remove(id);
+ }
+ }
}
/**
@@ -715,26 +713,26 @@
*/
@Override
public void putDeviceDiscoveryEvent(DeviceEvent deviceEvent) {
- if (datastore.addDevice(deviceEvent)) {
- // Send out notification
- TopologyEvent topologyEvent = new TopologyEvent(deviceEvent);
- eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
- log.debug("Put the device info into the cache of the graph. mac {}", deviceEvent.getMac());
-
- // Store the new Device Event in the local cache
- // TODO: The implementation below is probably wrong
- for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
- Map<ByteBuffer, DeviceEvent> oldDeviceEvents =
- discoveredAddedDeviceEvents.get(swp.getDpid());
- if (oldDeviceEvents == null) {
- oldDeviceEvents = new HashMap<>();
- discoveredAddedDeviceEvents.put(swp.getDpid(),
- oldDeviceEvents);
- }
- ByteBuffer id = deviceEvent.getIDasByteBuffer();
- oldDeviceEvents.put(id, deviceEvent);
- }
- }
+ if (datastore.addDevice(deviceEvent)) {
+ // Send out notification
+ TopologyEvent topologyEvent = new TopologyEvent(deviceEvent);
+ eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
+ log.debug("Put the device info into the cache of the graph. mac {}", deviceEvent.getMac());
+
+ // Store the new Device Event in the local cache
+ // TODO: The implementation below is probably wrong
+ for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
+ Map<ByteBuffer, DeviceEvent> oldDeviceEvents =
+ discoveredAddedDeviceEvents.get(swp.getDpid());
+ if (oldDeviceEvents == null) {
+ oldDeviceEvents = new HashMap<>();
+ discoveredAddedDeviceEvents.put(swp.getDpid(),
+ oldDeviceEvents);
+ }
+ ByteBuffer id = deviceEvent.getIDasByteBuffer();
+ oldDeviceEvents.put(id, deviceEvent);
+ }
+ }
}
/**
@@ -744,22 +742,22 @@
*/
@Override
public void removeDeviceDiscoveryEvent(DeviceEvent deviceEvent) {
- if (datastore.removeDevice(deviceEvent)) {
- // Send out notification
- eventChannel.removeEntry(deviceEvent.getID());
- log.debug("Remove the device info into the cache of the graph. mac {}", deviceEvent.getMac());
+ if (datastore.removeDevice(deviceEvent)) {
+ // Send out notification
+ eventChannel.removeEntry(deviceEvent.getID());
+ log.debug("Remove the device info into the cache of the graph. mac {}", deviceEvent.getMac());
- // Cleanup the Device Event from the local cache
- // TODO: The implementation below is probably wrong
- ByteBuffer id = ByteBuffer.wrap(deviceEvent.getID());
- for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
- Map<ByteBuffer, DeviceEvent> oldDeviceEvents =
- discoveredAddedDeviceEvents.get(swp.getDpid());
- if (oldDeviceEvents != null) {
- oldDeviceEvents.remove(id);
- }
- }
- }
+ // Cleanup the Device Event from the local cache
+ // TODO: The implementation below is probably wrong
+ ByteBuffer id = ByteBuffer.wrap(deviceEvent.getID());
+ for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
+ Map<ByteBuffer, DeviceEvent> oldDeviceEvents =
+ discoveredAddedDeviceEvents.get(swp.getDpid());
+ if (oldDeviceEvents != null) {
+ oldDeviceEvents.remove(id);
+ }
+ }
+ }
}
/**
@@ -768,15 +766,15 @@
* @param switchEvent the Switch Event with the switch to add.
*/
private void addSwitch(SwitchEvent switchEvent) {
- Switch sw = networkGraph.getSwitch(switchEvent.getDpid());
- if (sw == null) {
- sw = new SwitchImpl(networkGraph, switchEvent.getDpid());
- networkGraph.putSwitch(sw);
- } else {
- // TODO: Update the switch attributes
- // TODO: Nothing to do for now
- }
- apiAddedSwitchEvents.add(switchEvent);
+ Switch sw = networkGraph.getSwitch(switchEvent.getDpid());
+ if (sw == null) {
+ sw = new SwitchImpl(networkGraph, switchEvent.getDpid());
+ networkGraph.putSwitch(sw);
+ } else {
+ // TODO: Update the switch attributes
+ // TODO: Nothing to do for now
+ }
+ apiAddedSwitchEvents.add(switchEvent);
}
/**
@@ -785,28 +783,28 @@
* @param switchEvent the Switch Event with the switch to remove.
*/
private void removeSwitch(SwitchEvent switchEvent) {
- Switch sw = networkGraph.getSwitch(switchEvent.getDpid());
- if (sw == null) {
- log.warn("Switch {} already removed, ignoring", switchEvent);
- return;
- }
+ Switch sw = networkGraph.getSwitch(switchEvent.getDpid());
+ if (sw == null) {
+ log.warn("Switch {} already removed, ignoring", switchEvent);
+ return;
+ }
- //
- // Remove all Ports on the Switch
- //
- ArrayList<PortEvent> portsToRemove = new ArrayList<>();
- for (Port port : sw.getPorts()) {
- log.warn("Port {} on Switch {} should be removed prior to removing Switch. Removing Port now.",
- port, switchEvent);
- PortEvent portEvent = new PortEvent(port.getDpid(),
- port.getNumber());
- portsToRemove.add(portEvent);
- }
- for (PortEvent portEvent : portsToRemove)
- removePort(portEvent);
+ //
+ // Remove all Ports on the Switch
+ //
+ ArrayList<PortEvent> portsToRemove = new ArrayList<>();
+ for (Port port : sw.getPorts()) {
+ log.warn("Port {} on Switch {} should be removed prior to removing Switch. Removing Port now.",
+ port, switchEvent);
+ PortEvent portEvent = new PortEvent(port.getDpid(),
+ port.getNumber());
+ portsToRemove.add(portEvent);
+ }
+ for (PortEvent portEvent : portsToRemove)
+ removePort(portEvent);
- networkGraph.removeSwitch(switchEvent.getDpid());
- apiRemovedSwitchEvents.add(switchEvent);
+ networkGraph.removeSwitch(switchEvent.getDpid());
+ apiRemovedSwitchEvents.add(switchEvent);
}
/**
@@ -815,23 +813,23 @@
* @param portEvent the Port Event with the port to add.
*/
private void addPort(PortEvent portEvent) {
- Switch sw = networkGraph.getSwitch(portEvent.getDpid());
- if (sw == null) {
- // Reordered event: delay the event in local cache
- ByteBuffer id = portEvent.getIDasByteBuffer();
- reorderedAddedPortEvents.put(id, portEvent);
- return;
- }
- SwitchImpl switchImpl = getSwitchImpl(sw);
+ Switch sw = networkGraph.getSwitch(portEvent.getDpid());
+ if (sw == null) {
+ // Reordered event: delay the event in local cache
+ ByteBuffer id = portEvent.getIDasByteBuffer();
+ reorderedAddedPortEvents.put(id, portEvent);
+ return;
+ }
+ SwitchImpl switchImpl = getSwitchImpl(sw);
- Port port = sw.getPort(portEvent.getNumber());
- if (port == null) {
- port = new PortImpl(networkGraph, sw, portEvent.getNumber());
- switchImpl.addPort(port);
- } else {
- // TODO: Update the port attributes
- }
- apiAddedPortEvents.add(portEvent);
+ Port port = sw.getPort(portEvent.getNumber());
+ if (port == null) {
+ port = new PortImpl(networkGraph, sw, portEvent.getNumber());
+ switchImpl.addPort(port);
+ } else {
+ // TODO: Update the port attributes
+ }
+ apiAddedPortEvents.add(portEvent);
}
/**
@@ -840,59 +838,59 @@
* @param portEvent the Port Event with the port to remove.
*/
private void removePort(PortEvent portEvent) {
- Switch sw = networkGraph.getSwitch(portEvent.getDpid());
- if (sw == null) {
- log.warn("Parent Switch for Port {} already removed, ignoring",
- portEvent);
- return;
- }
+ Switch sw = networkGraph.getSwitch(portEvent.getDpid());
+ if (sw == null) {
+ log.warn("Parent Switch for Port {} already removed, ignoring",
+ portEvent);
+ return;
+ }
- Port port = sw.getPort(portEvent.getNumber());
- if (port == null) {
- log.warn("Port {} already removed, ignoring", portEvent);
- return;
- }
+ Port port = sw.getPort(portEvent.getNumber());
+ if (port == null) {
+ log.warn("Port {} already removed, ignoring", portEvent);
+ return;
+ }
- //
- // Remove all Devices attached to the Port
- //
- ArrayList<DeviceEvent> devicesToRemove = new ArrayList<>();
- for (Device device : port.getDevices()) {
- log.debug("Removing Device {} on Port {}", device, portEvent);
- DeviceEvent deviceEvent = new DeviceEvent(device.getMacAddress());
- SwitchPort switchPort = new SwitchPort(port.getSwitch().getDpid(),
- port.getNumber());
- deviceEvent.addAttachmentPoint(switchPort);
- devicesToRemove.add(deviceEvent);
- }
- for (DeviceEvent deviceEvent : devicesToRemove)
- removeDevice(deviceEvent);
+ //
+ // Remove all Devices attached to the Port
+ //
+ ArrayList<DeviceEvent> devicesToRemove = new ArrayList<>();
+ for (Device device : port.getDevices()) {
+ log.debug("Removing Device {} on Port {}", device, portEvent);
+ DeviceEvent deviceEvent = new DeviceEvent(device.getMacAddress());
+ SwitchPort switchPort = new SwitchPort(port.getSwitch().getDpid(),
+ port.getNumber());
+ deviceEvent.addAttachmentPoint(switchPort);
+ devicesToRemove.add(deviceEvent);
+ }
+ for (DeviceEvent deviceEvent : devicesToRemove)
+ removeDevice(deviceEvent);
- //
- // Remove all Links connected to the Port
- //
- Set<Link> links = new HashSet<>();
- links.add(port.getOutgoingLink());
- links.add(port.getIncomingLink());
- ArrayList<LinkEvent> linksToRemove = new ArrayList<>();
- for (Link link : links) {
- if (link == null)
- continue;
- log.debug("Removing Link {} on Port {}", link, portEvent);
- LinkEvent linkEvent = new LinkEvent(link.getSrcSwitch().getDpid(),
- link.getSrcPort().getNumber(),
- link.getDstSwitch().getDpid(),
- link.getDstPort().getNumber());
- linksToRemove.add(linkEvent);
- }
- for (LinkEvent linkEvent : linksToRemove)
- removeLink(linkEvent);
+ //
+ // Remove all Links connected to the Port
+ //
+ Set<Link> links = new HashSet<>();
+ links.add(port.getOutgoingLink());
+ links.add(port.getIncomingLink());
+ ArrayList<LinkEvent> linksToRemove = new ArrayList<>();
+ for (Link link : links) {
+ if (link == null)
+ continue;
+ log.debug("Removing Link {} on Port {}", link, portEvent);
+ LinkEvent linkEvent = new LinkEvent(link.getSrcSwitch().getDpid(),
+ link.getSrcPort().getNumber(),
+ link.getDstSwitch().getDpid(),
+ link.getDstPort().getNumber());
+ linksToRemove.add(linkEvent);
+ }
+ for (LinkEvent linkEvent : linksToRemove)
+ removeLink(linkEvent);
- // Remove the Port from the Switch
- SwitchImpl switchImpl = getSwitchImpl(sw);
- switchImpl.removePort(port);
+ // Remove the Port from the Switch
+ SwitchImpl switchImpl = getSwitchImpl(sw);
+ switchImpl.removePort(port);
- apiRemovedPortEvents.add(portEvent);
+ apiRemovedPortEvents.add(portEvent);
}
/**
@@ -901,52 +899,52 @@
* @param linkEvent the Link Event with the link to add.
*/
private void addLink(LinkEvent linkEvent) {
- Port srcPort = networkGraph.getPort(linkEvent.getSrc().dpid,
- linkEvent.getSrc().number);
- Port dstPort = networkGraph.getPort(linkEvent.getDst().dpid,
- linkEvent.getDst().number);
- if ((srcPort == null) || (dstPort == null)) {
- // Reordered event: delay the event in local cache
- ByteBuffer id = linkEvent.getIDasByteBuffer();
- reorderedAddedLinkEvents.put(id, linkEvent);
- return;
- }
+ Port srcPort = networkGraph.getPort(linkEvent.getSrc().dpid,
+ linkEvent.getSrc().number);
+ Port dstPort = networkGraph.getPort(linkEvent.getDst().dpid,
+ linkEvent.getDst().number);
+ if ((srcPort == null) || (dstPort == null)) {
+ // Reordered event: delay the event in local cache
+ ByteBuffer id = linkEvent.getIDasByteBuffer();
+ reorderedAddedLinkEvents.put(id, linkEvent);
+ return;
+ }
- // Get the Link instance from the Destination Port Incoming Link
- Link link = dstPort.getIncomingLink();
- assert(link == srcPort.getOutgoingLink());
- if (link == null) {
- link = new LinkImpl(networkGraph, srcPort, dstPort);
- PortImpl srcPortImpl = getPortImpl(srcPort);
- PortImpl dstPortImpl = getPortImpl(dstPort);
- srcPortImpl.setOutgoingLink(link);
- dstPortImpl.setIncomingLink(link);
+ // Get the Link instance from the Destination Port Incoming Link
+ Link link = dstPort.getIncomingLink();
+ assert (link == srcPort.getOutgoingLink());
+ if (link == null) {
+ link = new LinkImpl(networkGraph, srcPort, dstPort);
+ PortImpl srcPortImpl = getPortImpl(srcPort);
+ PortImpl dstPortImpl = getPortImpl(dstPort);
+ srcPortImpl.setOutgoingLink(link);
+ dstPortImpl.setIncomingLink(link);
- // Remove all Devices attached to the Ports
- ArrayList<DeviceEvent> devicesToRemove = new ArrayList<>();
- ArrayList<Port> ports = new ArrayList<>();
- ports.add(srcPort);
- ports.add(dstPort);
- for (Port port : ports) {
- for (Device device : port.getDevices()) {
- log.error("Device {} on Port {} should have been removed prior to adding Link {}",
- device, port, linkEvent);
- DeviceEvent deviceEvent =
- new DeviceEvent(device.getMacAddress());
- SwitchPort switchPort =
- new SwitchPort(port.getSwitch().getDpid(),
- port.getNumber());
- deviceEvent.addAttachmentPoint(switchPort);
- devicesToRemove.add(deviceEvent);
- }
- }
- for (DeviceEvent deviceEvent : devicesToRemove)
- removeDevice(deviceEvent);
- } else {
- // TODO: Update the link attributes
- }
+ // Remove all Devices attached to the Ports
+ ArrayList<DeviceEvent> devicesToRemove = new ArrayList<>();
+ ArrayList<Port> ports = new ArrayList<>();
+ ports.add(srcPort);
+ ports.add(dstPort);
+ for (Port port : ports) {
+ for (Device device : port.getDevices()) {
+ log.error("Device {} on Port {} should have been removed prior to adding Link {}",
+ device, port, linkEvent);
+ DeviceEvent deviceEvent =
+ new DeviceEvent(device.getMacAddress());
+ SwitchPort switchPort =
+ new SwitchPort(port.getSwitch().getDpid(),
+ port.getNumber());
+ deviceEvent.addAttachmentPoint(switchPort);
+ devicesToRemove.add(deviceEvent);
+ }
+ }
+ for (DeviceEvent deviceEvent : devicesToRemove)
+ removeDevice(deviceEvent);
+ } else {
+ // TODO: Update the link attributes
+ }
- apiAddedLinkEvents.add(linkEvent);
+ apiAddedLinkEvents.add(linkEvent);
}
/**
@@ -955,43 +953,43 @@
* @param linkEvent the Link Event with the link to remove.
*/
private void removeLink(LinkEvent linkEvent) {
- Port srcPort = networkGraph.getPort(linkEvent.getSrc().dpid,
- linkEvent.getSrc().number);
- if (srcPort == null) {
- log.warn("Src Port for Link {} already removed, ignoring",
- linkEvent);
- return;
- }
+ Port srcPort = networkGraph.getPort(linkEvent.getSrc().dpid,
+ linkEvent.getSrc().number);
+ if (srcPort == null) {
+ log.warn("Src Port for Link {} already removed, ignoring",
+ linkEvent);
+ return;
+ }
- Port dstPort = networkGraph.getPort(linkEvent.getDst().dpid,
- linkEvent.getDst().number);
- if (dstPort == null) {
- log.warn("Dst Port for Link {} already removed, ignoring",
- linkEvent);
- return;
- }
+ Port dstPort = networkGraph.getPort(linkEvent.getDst().dpid,
+ linkEvent.getDst().number);
+ if (dstPort == null) {
+ log.warn("Dst Port for Link {} already removed, ignoring",
+ linkEvent);
+ return;
+ }
- //
- // Remove the Link instance from the Destination Port Incoming Link
- // and the Source Port Outgoing Link.
- //
- Link link = dstPort.getIncomingLink();
- if (link == null) {
- log.warn("Link {} already removed on destination Port", linkEvent);
- }
- link = srcPort.getOutgoingLink();
- if (link == null) {
- log.warn("Link {} already removed on src Port", linkEvent);
- }
- getPortImpl(dstPort).setIncomingLink(null);
- getPortImpl(srcPort).setOutgoingLink(null);
+ //
+ // Remove the Link instance from the Destination Port Incoming Link
+ // and the Source Port Outgoing Link.
+ //
+ Link link = dstPort.getIncomingLink();
+ if (link == null) {
+ log.warn("Link {} already removed on destination Port", linkEvent);
+ }
+ link = srcPort.getOutgoingLink();
+ if (link == null) {
+ log.warn("Link {} already removed on src Port", linkEvent);
+ }
+ getPortImpl(dstPort).setIncomingLink(null);
+ getPortImpl(srcPort).setOutgoingLink(null);
- apiRemovedLinkEvents.add(linkEvent);
+ apiRemovedLinkEvents.add(linkEvent);
}
/**
* Add a device to the Network Graph.
- *
+ * <p/>
* TODO: Device-related work is incomplete.
* TODO: Eventually, we might need to consider reordering
* or addLink() and addDevice() events on the same port.
@@ -999,86 +997,86 @@
* @param deviceEvent the Device Event with the device to add.
*/
private void addDevice(DeviceEvent deviceEvent) {
- Device device = networkGraph.getDeviceByMac(deviceEvent.getMac());
-
- if (device == null) {
- log.debug("Existing device was not found in networkGraph. New device. mac {}", deviceEvent.getMac());
- device = new DeviceImpl(networkGraph, deviceEvent.getMac());
- }
-
- DeviceImpl deviceImpl = getDeviceImpl(device);
+ Device device = networkGraph.getDeviceByMac(deviceEvent.getMac());
- // Update the IP addresses
- for (InetAddress ipAddr : deviceEvent.getIpAddresses())
- deviceImpl.addIpAddress(ipAddr);
+ if (device == null) {
+ log.debug("Existing device was not found in networkGraph. New device. mac {}", deviceEvent.getMac());
+ device = new DeviceImpl(networkGraph, deviceEvent.getMac());
+ }
- // Process each attachment point
- boolean attachmentFound = false;
- for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
- // Attached Ports must exist
- Port port = networkGraph.getPort(swp.dpid, swp.number);
- if (port == null) {
- // Reordered event: delay the event in local cache
- ByteBuffer id = deviceEvent.getIDasByteBuffer();
- reorderedAddedDeviceEvents.put(id, deviceEvent);
- continue;
- }
- // Attached Ports must not have Link
- if (port.getOutgoingLink() != null ||
- port.getIncomingLink() != null) {
- log.warn("Link (Out:{},In:{}) exist on the attachment point, skipping mutation.",
- port.getOutgoingLink(),
- port.getIncomingLink());
- continue;
- }
+ DeviceImpl deviceImpl = getDeviceImpl(device);
- // Add Device <-> Port attachment
- PortImpl portImpl = getPortImpl(port);
- portImpl.addDevice(device);
- deviceImpl.addAttachmentPoint(port);
- attachmentFound = true;
- }
+ // Update the IP addresses
+ for (InetAddress ipAddr : deviceEvent.getIpAddresses())
+ deviceImpl.addIpAddress(ipAddr);
- // Update the device in the Network Graph
- if (attachmentFound) {
- log.debug("Storing the info into networkGraph. mac {}", deviceEvent.getMac());
- networkGraph.putDevice(device);
- apiAddedDeviceEvents.add(deviceEvent);
- }
+ // Process each attachment point
+ boolean attachmentFound = false;
+ for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
+ // Attached Ports must exist
+ Port port = networkGraph.getPort(swp.dpid, swp.number);
+ if (port == null) {
+ // Reordered event: delay the event in local cache
+ ByteBuffer id = deviceEvent.getIDasByteBuffer();
+ reorderedAddedDeviceEvents.put(id, deviceEvent);
+ continue;
+ }
+ // Attached Ports must not have Link
+ if (port.getOutgoingLink() != null ||
+ port.getIncomingLink() != null) {
+ log.warn("Link (Out:{},In:{}) exist on the attachment point, skipping mutation.",
+ port.getOutgoingLink(),
+ port.getIncomingLink());
+ continue;
+ }
+
+ // Add Device <-> Port attachment
+ PortImpl portImpl = getPortImpl(port);
+ portImpl.addDevice(device);
+ deviceImpl.addAttachmentPoint(port);
+ attachmentFound = true;
+ }
+
+ // Update the device in the Network Graph
+ if (attachmentFound) {
+ log.debug("Storing the info into networkGraph. mac {}", deviceEvent.getMac());
+ networkGraph.putDevice(device);
+ apiAddedDeviceEvents.add(deviceEvent);
+ }
}
/**
* Remove a device from the Network Graph.
- *
+ * <p/>
* TODO: Device-related work is incomplete.
*
* @param deviceEvent the Device Event with the device to remove.
*/
private void removeDevice(DeviceEvent deviceEvent) {
- Device device = networkGraph.getDeviceByMac(deviceEvent.getMac());
- if (device == null) {
- log.warn("Device {} already removed, ignoring", deviceEvent);
- return;
- }
- DeviceImpl deviceImpl = getDeviceImpl(device);
+ Device device = networkGraph.getDeviceByMac(deviceEvent.getMac());
+ if (device == null) {
+ log.warn("Device {} already removed, ignoring", deviceEvent);
+ return;
+ }
+ DeviceImpl deviceImpl = getDeviceImpl(device);
- // Process each attachment point
- for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
- // Attached Ports must exist
- Port port = networkGraph.getPort(swp.dpid, swp.number);
- if (port == null) {
- log.warn("Port for the attachment point {} did not exist. skipping attachment point mutation", swp);
- continue;
- }
+ // Process each attachment point
+ for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
+ // Attached Ports must exist
+ Port port = networkGraph.getPort(swp.dpid, swp.number);
+ if (port == null) {
+ log.warn("Port for the attachment point {} did not exist. skipping attachment point mutation", swp);
+ continue;
+ }
- // Remove Device <-> Port attachment
- PortImpl portImpl = getPortImpl(port);
- portImpl.removeDevice(device);
- deviceImpl.removeAttachmentPoint(port);
- }
+ // Remove Device <-> Port attachment
+ PortImpl portImpl = getPortImpl(port);
+ portImpl.removeDevice(device);
+ deviceImpl.removeAttachmentPoint(port);
+ }
- networkGraph.removeDevice(device);
- apiRemovedDeviceEvents.add(deviceEvent);
+ networkGraph.removeDevice(device);
+ apiRemovedDeviceEvents.add(deviceEvent);
}
/**
@@ -1088,10 +1086,10 @@
* @return the SwitchImpl-casted switch implementation.
*/
private SwitchImpl getSwitchImpl(Switch sw) {
- if (sw instanceof SwitchImpl) {
- return (SwitchImpl)sw;
- }
- throw new ClassCastException("SwitchImpl expected, but found: " + sw);
+ if (sw instanceof SwitchImpl) {
+ return (SwitchImpl) sw;
+ }
+ throw new ClassCastException("SwitchImpl expected, but found: " + sw);
}
/**
@@ -1101,10 +1099,10 @@
* @return the PortImpl-casted port implementation.
*/
private PortImpl getPortImpl(Port port) {
- if (port instanceof PortImpl) {
- return (PortImpl)port;
- }
- throw new ClassCastException("PortImpl expected, but found: " + port);
+ if (port instanceof PortImpl) {
+ return (PortImpl) port;
+ }
+ throw new ClassCastException("PortImpl expected, but found: " + port);
}
/**
@@ -1114,10 +1112,10 @@
* @return the LinkImpl-casted link implementation.
*/
private LinkImpl getLinkImpl(Link link) {
- if (link instanceof LinkImpl) {
- return (LinkImpl)link;
- }
- throw new ClassCastException("LinkImpl expected, but found: " + link);
+ if (link instanceof LinkImpl) {
+ return (LinkImpl) link;
+ }
+ throw new ClassCastException("LinkImpl expected, but found: " + link);
}
/**
@@ -1127,10 +1125,10 @@
* @return the DeviceImpl-casted device implementation.
*/
private DeviceImpl getDeviceImpl(Device device) {
- if (device instanceof DeviceImpl) {
- return (DeviceImpl)device;
- }
- throw new ClassCastException("DeviceImpl expected, but found: " + device);
+ if (device instanceof DeviceImpl) {
+ return (DeviceImpl) device;
+ }
+ throw new ClassCastException("DeviceImpl expected, but found: " + device);
}
/**
@@ -1140,60 +1138,60 @@
* the whole topology.
*/
private Collection<EventEntry<TopologyEvent>> readWholeTopologyFromDB() {
- Collection<EventEntry<TopologyEvent>> collection =
- new LinkedList<EventEntry<TopologyEvent>>();
+ Collection<EventEntry<TopologyEvent>> collection =
+ new LinkedList<EventEntry<TopologyEvent>>();
- // XXX May need to clear whole topology first, depending on
- // how we initially subscribe to replication events
+ // XXX May need to clear whole topology first, depending on
+ // how we initially subscribe to replication events
- // Add all active switches
- for (KVSwitch sw : KVSwitch.getAllSwitches()) {
- if (sw.getStatus() != KVSwitch.STATUS.ACTIVE) {
- continue;
- }
+ // Add all active switches
+ for (KVSwitch sw : KVSwitch.getAllSwitches()) {
+ if (sw.getStatus() != KVSwitch.STATUS.ACTIVE) {
+ continue;
+ }
- SwitchEvent switchEvent = new SwitchEvent(sw.getDpid());
- TopologyEvent topologyEvent = new TopologyEvent(switchEvent);
- EventEntry<TopologyEvent> eventEntry =
- new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
- topologyEvent);
- collection.add(eventEntry);
- }
+ SwitchEvent switchEvent = new SwitchEvent(sw.getDpid());
+ TopologyEvent topologyEvent = new TopologyEvent(switchEvent);
+ EventEntry<TopologyEvent> eventEntry =
+ new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
+ topologyEvent);
+ collection.add(eventEntry);
+ }
- // Add all active ports
- for (KVPort p : KVPort.getAllPorts()) {
- if (p.getStatus() != KVPort.STATUS.ACTIVE) {
- continue;
- }
+ // Add all active ports
+ for (KVPort p : KVPort.getAllPorts()) {
+ if (p.getStatus() != KVPort.STATUS.ACTIVE) {
+ continue;
+ }
- PortEvent portEvent = new PortEvent(p.getDpid(), p.getNumber());
- TopologyEvent topologyEvent = new TopologyEvent(portEvent);
- EventEntry<TopologyEvent> eventEntry =
- new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
- topologyEvent);
- collection.add(eventEntry);
- }
+ PortEvent portEvent = new PortEvent(p.getDpid(), p.getNumber());
+ TopologyEvent topologyEvent = new TopologyEvent(portEvent);
+ EventEntry<TopologyEvent> eventEntry =
+ new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
+ topologyEvent);
+ collection.add(eventEntry);
+ }
- // TODO Is Device going to be in DB? If so, read from DB.
- // for (KVDevice d : KVDevice.getAllDevices()) {
- // DeviceEvent devEvent = new DeviceEvent( MACAddress.valueOf(d.getMac()) );
- // for (byte[] portId : d.getAllPortIds() ) {
- // devEvent.addAttachmentPoint( new SwitchPort( KVPort.getDpidFromKey(portId), KVPort.getNumberFromKey(portId) ));
- // }
- // }
+ // TODO Is Device going to be in DB? If so, read from DB.
+ // for (KVDevice d : KVDevice.getAllDevices()) {
+ // DeviceEvent devEvent = new DeviceEvent( MACAddress.valueOf(d.getMac()) );
+ // for (byte[] portId : d.getAllPortIds() ) {
+ // devEvent.addAttachmentPoint( new SwitchPort( KVPort.getDpidFromKey(portId), KVPort.getNumberFromKey(portId) ));
+ // }
+ // }
- for (KVLink l : KVLink.getAllLinks()) {
- LinkEvent linkEvent = new LinkEvent(l.getSrc().dpid,
- l.getSrc().number,
- l.getDst().dpid,
- l.getDst().number);
- TopologyEvent topologyEvent = new TopologyEvent(linkEvent);
- EventEntry<TopologyEvent> eventEntry =
- new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
- topologyEvent);
- collection.add(eventEntry);
- }
+ for (KVLink l : KVLink.getAllLinks()) {
+ LinkEvent linkEvent = new LinkEvent(l.getSrc().dpid,
+ l.getSrc().number,
+ l.getDst().dpid,
+ l.getDst().number);
+ TopologyEvent topologyEvent = new TopologyEvent(linkEvent);
+ EventEntry<TopologyEvent> eventEntry =
+ new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
+ topologyEvent);
+ collection.add(eventEntry);
+ }
- return collection;
+ return collection;
}
}
diff --git a/src/main/java/net/onrc/onos/core/topology/serializers/LinkSerializer.java b/src/main/java/net/onrc/onos/core/topology/serializers/LinkSerializer.java
index 93bce90..61a3b34 100644
--- a/src/main/java/net/onrc/onos/core/topology/serializers/LinkSerializer.java
+++ b/src/main/java/net/onrc/onos/core/topology/serializers/LinkSerializer.java
@@ -12,24 +12,24 @@
public class LinkSerializer extends SerializerBase<Link> {
- public LinkSerializer() {
- super(Link.class);
- }
+ public LinkSerializer() {
+ super(Link.class);
+ }
- @Override
- public void serialize(Link link, JsonGenerator jsonGenerator,
- SerializerProvider serializerProvider)
- throws IOException, JsonGenerationException {
- jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("src-switch",
- HexString.toHexString(link.getSrcSwitch().getDpid()));
- jsonGenerator.writeNumberField("src-port",
- link.getSrcPort().getNumber());
- jsonGenerator.writeStringField("dst-switch",
- HexString.toHexString(link.getDstSwitch().getDpid()));
- jsonGenerator.writeNumberField("dst-port",
- link.getDstPort().getNumber());
- jsonGenerator.writeEndObject();
- }
+ @Override
+ public void serialize(Link link, JsonGenerator jsonGenerator,
+ SerializerProvider serializerProvider)
+ throws IOException, JsonGenerationException {
+ jsonGenerator.writeStartObject();
+ jsonGenerator.writeStringField("src-switch",
+ HexString.toHexString(link.getSrcSwitch().getDpid()));
+ jsonGenerator.writeNumberField("src-port",
+ link.getSrcPort().getNumber());
+ jsonGenerator.writeStringField("dst-switch",
+ HexString.toHexString(link.getDstSwitch().getDpid()));
+ jsonGenerator.writeNumberField("dst-port",
+ link.getDstPort().getNumber());
+ jsonGenerator.writeEndObject();
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/serializers/PortSerializer.java b/src/main/java/net/onrc/onos/core/topology/serializers/PortSerializer.java
index 25e64d0..ae75dff 100644
--- a/src/main/java/net/onrc/onos/core/topology/serializers/PortSerializer.java
+++ b/src/main/java/net/onrc/onos/core/topology/serializers/PortSerializer.java
@@ -11,21 +11,21 @@
public class PortSerializer extends SerializerBase<Port> {
- public PortSerializer() {
- super(Port.class);
- }
+ public PortSerializer() {
+ super(Port.class);
+ }
- @Override
- public void serialize(Port port, JsonGenerator jsonGenerator,
- SerializerProvider serializerProvider)
- throws IOException, JsonProcessingException {
- jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("state", "ACTIVE");
- jsonGenerator.writeNumberField("number", port.getNumber());
- jsonGenerator.writeStringField("desc", port.getDescription());
- jsonGenerator.writeArrayFieldStart("devices");
- jsonGenerator.writeEndArray();
- jsonGenerator.writeEndObject();
- }
+ @Override
+ public void serialize(Port port, JsonGenerator jsonGenerator,
+ SerializerProvider serializerProvider)
+ throws IOException, JsonProcessingException {
+ jsonGenerator.writeStartObject();
+ jsonGenerator.writeStringField("state", "ACTIVE");
+ jsonGenerator.writeNumberField("number", port.getNumber());
+ jsonGenerator.writeStringField("desc", port.getDescription());
+ jsonGenerator.writeArrayFieldStart("devices");
+ jsonGenerator.writeEndArray();
+ jsonGenerator.writeEndObject();
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/serializers/SwitchSerializer.java b/src/main/java/net/onrc/onos/core/topology/serializers/SwitchSerializer.java
index e36d35c..00bdcad 100644
--- a/src/main/java/net/onrc/onos/core/topology/serializers/SwitchSerializer.java
+++ b/src/main/java/net/onrc/onos/core/topology/serializers/SwitchSerializer.java
@@ -13,24 +13,24 @@
public class SwitchSerializer extends SerializerBase<Switch> {
- public SwitchSerializer() {
- super(Switch.class);
- }
+ public SwitchSerializer() {
+ super(Switch.class);
+ }
- @Override
- public void serialize(Switch sw, JsonGenerator jsonGenerator,
- SerializerProvider serializerProvider) throws IOException,
- JsonProcessingException {
-
- jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("dpid", HexString.toHexString(sw.getDpid()));
- jsonGenerator.writeStringField("state", "ACTIVE");
- jsonGenerator.writeArrayFieldStart("ports");
- for (Port port : sw.getPorts()) {
- jsonGenerator.writeObject(port);
- }
- jsonGenerator.writeEndArray();
- jsonGenerator.writeEndObject();
- }
+ @Override
+ public void serialize(Switch sw, JsonGenerator jsonGenerator,
+ SerializerProvider serializerProvider) throws IOException,
+ JsonProcessingException {
+
+ jsonGenerator.writeStartObject();
+ jsonGenerator.writeStringField("dpid", HexString.toHexString(sw.getDpid()));
+ jsonGenerator.writeStringField("state", "ACTIVE");
+ jsonGenerator.writeArrayFieldStart("ports");
+ for (Port port : sw.getPorts()) {
+ jsonGenerator.writeObject(port);
+ }
+ jsonGenerator.writeEndArray();
+ jsonGenerator.writeEndObject();
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/web/DatastoreLinksResource.java b/src/main/java/net/onrc/onos/core/topology/web/DatastoreLinksResource.java
index 4837055..0f3b85c 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/DatastoreLinksResource.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/DatastoreLinksResource.java
@@ -7,8 +7,8 @@
public class DatastoreLinksResource extends ServerResource {
- @Get("json")
- public Iterable<KVLink> retrieve() {
- return KVLink.getAllLinks();
- }
+ @Get("json")
+ public Iterable<KVLink> retrieve() {
+ return KVLink.getAllLinks();
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/web/DatastorePortsResource.java b/src/main/java/net/onrc/onos/core/topology/web/DatastorePortsResource.java
index 46eaf1a..2ffb476 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/DatastorePortsResource.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/DatastorePortsResource.java
@@ -7,8 +7,8 @@
public class DatastorePortsResource extends ServerResource {
- @Get("json")
- public Iterable<KVPort> retrieve() {
- return KVPort.getAllPorts();
- }
+ @Get("json")
+ public Iterable<KVPort> retrieve() {
+ return KVPort.getAllPorts();
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/web/DatastoreSwitchesResource.java b/src/main/java/net/onrc/onos/core/topology/web/DatastoreSwitchesResource.java
index fe2cfcd..9459764 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/DatastoreSwitchesResource.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/DatastoreSwitchesResource.java
@@ -6,10 +6,10 @@
import org.restlet.resource.ServerResource;
public class DatastoreSwitchesResource extends ServerResource {
-
- @Get("json")
- public Iterable<KVSwitch> retrieve() {
- return KVSwitch.getAllSwitches();
- }
+
+ @Get("json")
+ public Iterable<KVSwitch> retrieve() {
+ return KVSwitch.getAllSwitches();
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphLinksResource.java b/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphLinksResource.java
index 5886aa5..8d4bc93 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphLinksResource.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphLinksResource.java
@@ -15,29 +15,29 @@
import org.slf4j.LoggerFactory;
public class NetworkGraphLinksResource extends ServerResource {
-
- private static final Logger log = LoggerFactory.getLogger(NetworkGraphLinksResource.class);
- @Get("json")
- public String retrieve() {
- INetworkGraphService networkGraphService = (INetworkGraphService) getContext().getAttributes().
- get(INetworkGraphService.class.getCanonicalName());
-
- NetworkGraph graph = networkGraphService.getNetworkGraph();
+ private static final Logger log = LoggerFactory.getLogger(NetworkGraphLinksResource.class);
- ObjectMapper mapper = new ObjectMapper();
- SimpleModule module = new SimpleModule("module", new Version(1, 0, 0, null));
- module.addSerializer(new LinkSerializer());
- mapper.registerModule(module);
-
- try {
- graph.acquireReadLock();
- return mapper.writeValueAsString(graph.getLinks());
- } catch (IOException e) {
- log.error("Error writing link list to JSON", e);
- return "";
- } finally {
- graph.releaseReadLock();
- }
- }
+ @Get("json")
+ public String retrieve() {
+ INetworkGraphService networkGraphService = (INetworkGraphService) getContext().getAttributes().
+ get(INetworkGraphService.class.getCanonicalName());
+
+ NetworkGraph graph = networkGraphService.getNetworkGraph();
+
+ ObjectMapper mapper = new ObjectMapper();
+ SimpleModule module = new SimpleModule("module", new Version(1, 0, 0, null));
+ module.addSerializer(new LinkSerializer());
+ mapper.registerModule(module);
+
+ try {
+ graph.acquireReadLock();
+ return mapper.writeValueAsString(graph.getLinks());
+ } catch (IOException e) {
+ log.error("Error writing link list to JSON", e);
+ return "";
+ } finally {
+ graph.releaseReadLock();
+ }
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphShortestPathResource.java b/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphShortestPathResource.java
index 1d4164b..6650efc 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphShortestPathResource.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphShortestPathResource.java
@@ -28,54 +28,54 @@
@Get("json")
public String retrieve() {
- INetworkGraphService networkGraphService =
- (INetworkGraphService)getContext().getAttributes().
- get(INetworkGraphService.class.getCanonicalName());
+ INetworkGraphService networkGraphService =
+ (INetworkGraphService) getContext().getAttributes().
+ get(INetworkGraphService.class.getCanonicalName());
- NetworkGraph graph = networkGraphService.getNetworkGraph();
+ NetworkGraph graph = networkGraphService.getNetworkGraph();
- ObjectMapper mapper = new ObjectMapper();
- SimpleModule module = new SimpleModule("module", new Version(1, 0, 0, null));
- module.addSerializer(new LinkSerializer());
- mapper.registerModule(module);
+ ObjectMapper mapper = new ObjectMapper();
+ SimpleModule module = new SimpleModule("module", new Version(1, 0, 0, null));
+ module.addSerializer(new LinkSerializer());
+ mapper.registerModule(module);
- //
- // Fetch the attributes
- //
- String srcDpidStr = (String)getRequestAttributes().get("src-dpid");
- String dstDpidStr = (String)getRequestAttributes().get("dst-dpid");
- Dpid srcDpid = new Dpid(srcDpidStr);
- Dpid dstDpid = new Dpid(dstDpidStr);
- log.debug("Getting Shortest Path {}--{}", srcDpidStr, dstDpidStr);
+ //
+ // Fetch the attributes
+ //
+ String srcDpidStr = (String) getRequestAttributes().get("src-dpid");
+ String dstDpidStr = (String) getRequestAttributes().get("dst-dpid");
+ Dpid srcDpid = new Dpid(srcDpidStr);
+ Dpid dstDpid = new Dpid(dstDpidStr);
+ log.debug("Getting Shortest Path {}--{}", srcDpidStr, dstDpidStr);
- //
- // Do the Shortest Path computation and return the result: list of
- // links.
- //
- try {
- graph.acquireReadLock();
- Switch srcSwitch = graph.getSwitch(srcDpid.value());
- Switch dstSwitch = graph.getSwitch(dstDpid.value());
- if ((srcSwitch == null) || (dstSwitch == null))
- return "";
- ConstrainedBFSTree bfsTree = new ConstrainedBFSTree(srcSwitch);
- Path path = bfsTree.getPath(dstSwitch);
- List<Link> links = new LinkedList<>();
- for (LinkEvent linkEvent : path) {
- Link link = graph.getLink(linkEvent.getSrc().getDpid(),
- linkEvent.getSrc().getNumber(),
- linkEvent.getDst().getDpid(),
- linkEvent.getDst().getNumber());
- if (link == null)
- return "";
- links.add(link);
- }
- return mapper.writeValueAsString(links);
- } catch (IOException e) {
- log.error("Error writing Shortest Path to JSON", e);
- return "";
- } finally {
- graph.releaseReadLock();
- }
+ //
+ // Do the Shortest Path computation and return the result: list of
+ // links.
+ //
+ try {
+ graph.acquireReadLock();
+ Switch srcSwitch = graph.getSwitch(srcDpid.value());
+ Switch dstSwitch = graph.getSwitch(dstDpid.value());
+ if ((srcSwitch == null) || (dstSwitch == null))
+ return "";
+ ConstrainedBFSTree bfsTree = new ConstrainedBFSTree(srcSwitch);
+ Path path = bfsTree.getPath(dstSwitch);
+ List<Link> links = new LinkedList<>();
+ for (LinkEvent linkEvent : path) {
+ Link link = graph.getLink(linkEvent.getSrc().getDpid(),
+ linkEvent.getSrc().getNumber(),
+ linkEvent.getDst().getDpid(),
+ linkEvent.getDst().getNumber());
+ if (link == null)
+ return "";
+ links.add(link);
+ }
+ return mapper.writeValueAsString(links);
+ } catch (IOException e) {
+ log.error("Error writing Shortest Path to JSON", e);
+ return "";
+ } finally {
+ graph.releaseReadLock();
+ }
}
}
diff --git a/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphSwitchesResource.java b/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphSwitchesResource.java
index 059771f..3a053e5 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphSwitchesResource.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphSwitchesResource.java
@@ -16,30 +16,30 @@
import org.slf4j.LoggerFactory;
public class NetworkGraphSwitchesResource extends ServerResource {
-
- private static final Logger log = LoggerFactory.getLogger(NetworkGraphSwitchesResource.class);
- @Get("json")
- public String retrieve() {
- INetworkGraphService networkGraphService = (INetworkGraphService) getContext().getAttributes().
- get(INetworkGraphService.class.getCanonicalName());
-
- NetworkGraph graph = networkGraphService.getNetworkGraph();
-
- ObjectMapper mapper = new ObjectMapper();
- SimpleModule module = new SimpleModule("module", new Version(1, 0, 0, null));
- module.addSerializer(new SwitchSerializer());
- module.addSerializer(new PortSerializer());
- mapper.registerModule(module);
-
- try {
- graph.acquireReadLock();
- return mapper.writeValueAsString(graph.getSwitches());
- } catch (IOException e) {
- log.error("Error writing switch list to JSON", e);
- return "";
- } finally {
- graph.releaseReadLock();
- }
- }
+ private static final Logger log = LoggerFactory.getLogger(NetworkGraphSwitchesResource.class);
+
+ @Get("json")
+ public String retrieve() {
+ INetworkGraphService networkGraphService = (INetworkGraphService) getContext().getAttributes().
+ get(INetworkGraphService.class.getCanonicalName());
+
+ NetworkGraph graph = networkGraphService.getNetworkGraph();
+
+ ObjectMapper mapper = new ObjectMapper();
+ SimpleModule module = new SimpleModule("module", new Version(1, 0, 0, null));
+ module.addSerializer(new SwitchSerializer());
+ module.addSerializer(new PortSerializer());
+ mapper.registerModule(module);
+
+ try {
+ graph.acquireReadLock();
+ return mapper.writeValueAsString(graph.getSwitches());
+ } catch (IOException e) {
+ log.error("Error writing switch list to JSON", e);
+ return "";
+ } finally {
+ graph.releaseReadLock();
+ }
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphWebRoutable.java b/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphWebRoutable.java
index c6791e5..8f32f8a 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphWebRoutable.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/NetworkGraphWebRoutable.java
@@ -8,33 +8,33 @@
public class NetworkGraphWebRoutable implements RestletRoutable {
- @Override
- public Restlet getRestlet(Context context) {
- Router router = new Router(context);
- // leaving old path there for compatibility
- router.attach("/rc/switches/json", DatastoreSwitchesResource.class);
- router.attach("/rc/links/json", DatastoreLinksResource.class);
- router.attach("/rc/ports/json", DatastorePortsResource.class);
+ @Override
+ public Restlet getRestlet(Context context) {
+ Router router = new Router(context);
+ // leaving old path there for compatibility
+ router.attach("/rc/switches/json", DatastoreSwitchesResource.class);
+ router.attach("/rc/links/json", DatastoreLinksResource.class);
+ router.attach("/rc/ports/json", DatastorePortsResource.class);
- // debug API to dump datastore content
- router.attach("/ds/switches/json", DatastoreSwitchesResource.class);
- router.attach("/ds/links/json", DatastoreLinksResource.class);
- router.attach("/ds/ports/json", DatastorePortsResource.class);
+ // debug API to dump datastore content
+ router.attach("/ds/switches/json", DatastoreSwitchesResource.class);
+ router.attach("/ds/links/json", DatastoreLinksResource.class);
+ router.attach("/ds/ports/json", DatastorePortsResource.class);
- router.attach("/ng/switches/json", NetworkGraphSwitchesResource.class);
- router.attach("/ng/links/json", NetworkGraphLinksResource.class);
- router.attach("/ng/shortest-path/{src-dpid}/{dst-dpid}/json", NetworkGraphShortestPathResource.class);
-
- // Old URLs for compatibility
- router.attach("/topology/switches/json", NetworkGraphSwitchesResource.class);
- router.attach("/topology/links/json", NetworkGraphLinksResource.class);
-
- return router;
- }
+ router.attach("/ng/switches/json", NetworkGraphSwitchesResource.class);
+ router.attach("/ng/links/json", NetworkGraphLinksResource.class);
+ router.attach("/ng/shortest-path/{src-dpid}/{dst-dpid}/json", NetworkGraphShortestPathResource.class);
- @Override
- public String basePath() {
- return "/wm/onos";
- }
+ // Old URLs for compatibility
+ router.attach("/topology/switches/json", NetworkGraphSwitchesResource.class);
+ router.attach("/topology/links/json", NetworkGraphLinksResource.class);
+
+ return router;
+ }
+
+ @Override
+ public String basePath() {
+ return "/wm/onos";
+ }
}