Added unit tests for the event abstractions.
Added Element as the notion of common ancestry between Device and Host.
diff --git a/net/api/src/main/java/org/onlab/onos/event/AbstractListenerManager.java b/net/api/src/main/java/org/onlab/onos/event/AbstractListenerManager.java
index 7d4836f..d063b59 100644
--- a/net/api/src/main/java/org/onlab/onos/event/AbstractListenerManager.java
+++ b/net/api/src/main/java/org/onlab/onos/event/AbstractListenerManager.java
@@ -51,8 +51,13 @@
}
}
- @Override
- public void reportProblem(E event, Throwable error) {
+ /**
+ * Reports a problem encountered while processing an event.
+ *
+ * @param event event being processed
+ * @param error error encountered while processing
+ */
+ protected void reportProblem(E event, Throwable error) {
log.warn("Exception encountered while processing event " + event, error);
}
diff --git a/net/api/src/main/java/org/onlab/onos/event/AbstractEventSinkBroker.java b/net/api/src/main/java/org/onlab/onos/event/DefaultEventSinkBroker.java
similarity index 91%
rename from net/api/src/main/java/org/onlab/onos/event/AbstractEventSinkBroker.java
rename to net/api/src/main/java/org/onlab/onos/event/DefaultEventSinkBroker.java
index 4ca3c3c..c791544 100644
--- a/net/api/src/main/java/org/onlab/onos/event/AbstractEventSinkBroker.java
+++ b/net/api/src/main/java/org/onlab/onos/event/DefaultEventSinkBroker.java
@@ -12,7 +12,7 @@
/**
* Base implementation of event sink broker.
*/
-public class AbstractEventSinkBroker implements EventSinkBroker {
+public class DefaultEventSinkBroker implements EventSinkBroker {
private final Map<Class<? extends Event>, EventSink<? extends Event>> sinks =
new ConcurrentHashMap<>();
@@ -36,6 +36,7 @@
@Override
@SuppressWarnings("unchecked")
public <E extends Event> EventSink<E> getSink(Class<E> eventClass) {
+ // TODO: add implicit registration of descendant classes
return (EventSink<E>) sinks.get(eventClass);
}
diff --git a/net/api/src/main/java/org/onlab/onos/event/EventSink.java b/net/api/src/main/java/org/onlab/onos/event/EventSink.java
index f46458c..45ad408 100644
--- a/net/api/src/main/java/org/onlab/onos/event/EventSink.java
+++ b/net/api/src/main/java/org/onlab/onos/event/EventSink.java
@@ -12,12 +12,4 @@
*/
void process(E event);
- /**
- * Reports a problem encountered while processing an event.
- *
- * @param event event being processed
- * @param error error encountered while processing
- */
- void reportProblem(E event, Throwable error);
-
}
diff --git a/net/api/src/main/java/org/onlab/onos/net/Device.java b/net/api/src/main/java/org/onlab/onos/net/Device.java
index 700654f..9e6018e 100644
--- a/net/api/src/main/java/org/onlab/onos/net/Device.java
+++ b/net/api/src/main/java/org/onlab/onos/net/Device.java
@@ -1,11 +1,9 @@
package org.onlab.onos.net;
-import org.onlab.onos.net.provider.Provided;
-
/**
* Representation of a network infrastructure device.
*/
-public interface Device extends Provided {
+public interface Device extends Element {
/**
* Coarse classification of the type of the infrastructure device.
diff --git a/net/api/src/main/java/org/onlab/onos/net/DeviceId.java b/net/api/src/main/java/org/onlab/onos/net/DeviceId.java
index 45528a4..124fa96 100644
--- a/net/api/src/main/java/org/onlab/onos/net/DeviceId.java
+++ b/net/api/src/main/java/org/onlab/onos/net/DeviceId.java
@@ -1,49 +1,19 @@
package org.onlab.onos.net;
import java.net.URI;
-import java.util.Objects;
-
-import static com.google.common.base.Objects.toStringHelper;
/**
* Immutable representation of a device identity.
*/
-public class DeviceId {
-
- private final URI uri;
-
- public DeviceId(URI uri) {
- this.uri = uri;
- }
+public class DeviceId extends ElementId {
/**
- * Returns the backing URI.
+ * Creates a device id using the supplied URI.
*
- * @return backing device URI
+ * @param uri backing device URI
*/
- public URI uri() {
- return uri;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(uri);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null || getClass() != obj.getClass()) {
- return false;
- }
- final DeviceId other = (DeviceId) obj;
- return Objects.equals(this.uri, other.uri);
- }
- @Override
- public String toString() {
- return toStringHelper(this).add("uri", uri).toString();
+ public DeviceId(URI uri) {
+ super(uri);
}
}
diff --git a/net/api/src/main/java/org/onlab/onos/net/Element.java b/net/api/src/main/java/org/onlab/onos/net/Element.java
new file mode 100644
index 0000000..c11d103
--- /dev/null
+++ b/net/api/src/main/java/org/onlab/onos/net/Element.java
@@ -0,0 +1,17 @@
+package org.onlab.onos.net;
+
+import org.onlab.onos.net.provider.Provided;
+
+/**
+ * Base abstraction of a network element, i.e. an infrastructure device or an end-station host.
+ */
+public interface Element extends Provided {
+
+ /**
+ * Returns the network element identifier.
+ *
+ * @return element identifier
+ */
+ ElementId id();
+
+}
diff --git a/net/api/src/main/java/org/onlab/onos/net/ElementId.java b/net/api/src/main/java/org/onlab/onos/net/ElementId.java
new file mode 100644
index 0000000..e0f3add
--- /dev/null
+++ b/net/api/src/main/java/org/onlab/onos/net/ElementId.java
@@ -0,0 +1,55 @@
+package org.onlab.onos.net;
+
+import java.net.URI;
+import java.util.Objects;
+
+import static com.google.common.base.Objects.toStringHelper;
+
+/**
+ * Immutable representation of a network element identity.
+ */
+public class ElementId {
+
+ private final URI uri;
+
+ /**
+ * Creates an element identifier using the supplied URI.
+ *
+ * @param uri backing URI
+ */
+ public ElementId(URI uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Returns the backing URI.
+ *
+ * @return backing URI
+ */
+ public URI uri() {
+ return uri;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(uri);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final ElementId other = (ElementId) obj;
+ return Objects.equals(this.uri, other.uri);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this).add("uri", uri).toString();
+ }
+
+}
diff --git a/net/api/src/main/java/org/onlab/onos/net/Host.java b/net/api/src/main/java/org/onlab/onos/net/Host.java
index f8e2e31..17eaf22 100644
--- a/net/api/src/main/java/org/onlab/onos/net/Host.java
+++ b/net/api/src/main/java/org/onlab/onos/net/Host.java
@@ -1,14 +1,21 @@
package org.onlab.onos.net;
-import org.onlab.onos.net.provider.Provided;
-
/**
* Abstraction of an end-station host on the network, essentially a NIC.
*/
-public interface Host extends Provided {
+public interface Host extends Element {
// MAC, IP(s), optional VLAN ID
- // Location (current, recent locations?
+
+ /**
+ * Returns the most recent host location where the host attaches to the
+ * network edge.
+ *
+ * @return host location
+ */
+ HostLocation location();
+
+ // list of recent locations?
}
diff --git a/net/api/src/main/java/org/onlab/onos/net/HostLocation.java b/net/api/src/main/java/org/onlab/onos/net/HostLocation.java
new file mode 100644
index 0000000..5c124db
--- /dev/null
+++ b/net/api/src/main/java/org/onlab/onos/net/HostLocation.java
@@ -0,0 +1,17 @@
+package org.onlab.onos.net;
+
+/**
+ * Representation of a network edge location where an end-station host is
+ * connected.
+ */
+public interface HostLocation extends ConnectPoint {
+
+ /**
+ * Returns the timestamp when the location was established, given in
+ * milliseconds since start of epoch.
+ *
+ * @return timestamp in milliseconds since start of epoch
+ */
+ long timestamp();
+
+}
diff --git a/net/api/src/main/java/org/onlab/onos/net/Port.java b/net/api/src/main/java/org/onlab/onos/net/Port.java
new file mode 100644
index 0000000..3135b77
--- /dev/null
+++ b/net/api/src/main/java/org/onlab/onos/net/Port.java
@@ -0,0 +1,26 @@
+package org.onlab.onos.net;
+
+/**
+ * Abstraction of a network port.
+ */
+public interface Port {
+
+ // Notion of port state: enabled, disabled, blocked
+
+ /**
+ * Returns the port number.
+ *
+ * @return port number
+ */
+ PortNumber number();
+
+ /**
+ * Returns the identifier of the network element to which this port belongs.
+ *
+ * @return parent network element
+ */
+ Element parent();
+
+ // set of port attributes
+
+}
diff --git a/net/api/src/main/java/org/onlab/onos/net/device/DeviceService.java b/net/api/src/main/java/org/onlab/onos/net/device/DeviceService.java
index 4048fbb..ac2f4a4 100644
--- a/net/api/src/main/java/org/onlab/onos/net/device/DeviceService.java
+++ b/net/api/src/main/java/org/onlab/onos/net/device/DeviceService.java
@@ -3,6 +3,10 @@
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
+import org.onlab.onos.net.Port;
+import org.onlab.onos.net.PortNumber;
+
+import java.util.List;
/**
* Service for interacting with the inventory of infrastructure devices.
@@ -34,7 +38,21 @@
Device getDevice(DeviceId deviceId);
-// List<Port> getPorts(DeviceId deviceId);
+ /**
+ * Returns the list of ports associated with the device.
+ *
+ * @param deviceId device identifier
+ * @return list of ports
+ */
+ List<Port> getPorts(DeviceId deviceId);
+
+ /**
+ * Returns the port with the specified number and hosted by the given device.
+ * @param deviceId device identifier
+ * @param portNumber port number
+ * @return device port
+ */
+ Port getPort(DeviceId deviceId, PortNumber portNumber);
/**
* Adds the specified device listener.
@@ -49,4 +67,5 @@
* @param listener device listener
*/
void removeListener(DeviceListener listener);
+
}