Implementing port update in trivial core.
diff --git a/net/api/src/main/java/org/onlab/onos/net/DefaultPort.java b/net/api/src/main/java/org/onlab/onos/net/DefaultPort.java
new file mode 100644
index 0000000..56a2979
--- /dev/null
+++ b/net/api/src/main/java/org/onlab/onos/net/DefaultPort.java
@@ -0,0 +1,70 @@
+package org.onlab.onos.net;
+
+import java.util.Objects;
+
+import static com.google.common.base.Objects.toStringHelper;
+
+/**
+ * Default port implementation.
+ */
+public class DefaultPort implements Port {
+
+ private final Element element;
+ private final PortNumber number;
+ private final boolean isEnabled;
+
+ /**
+ * Creates a network element attributed to the specified provider.
+ *
+ * @param element parent network element
+ * @param number port number
+ * @param isEnabled indicator whether the port is up and active
+ */
+ public DefaultPort(Element element, PortNumber number,
+ boolean isEnabled) {
+ this.element = element;
+ this.number = number;
+ this.isEnabled = isEnabled;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(number, isEnabled);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof DefaultPort) {
+ final DefaultPort other = (DefaultPort) obj;
+ return Objects.equals(this.element.id(), other.element.id()) &&
+ Objects.equals(this.number, other.number) &&
+ Objects.equals(this.isEnabled, other.isEnabled);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("element", element.id())
+ .add("number", number)
+ .add("isEnabled", isEnabled)
+ .toString();
+ }
+
+ @Override
+ public PortNumber number() {
+ return number;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return isEnabled;
+ }
+
+ @Override
+ public Element element() {
+ return element;
+ }
+
+}
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
index cf9a2ce..e98278b 100644
--- a/net/api/src/main/java/org/onlab/onos/net/Port.java
+++ b/net/api/src/main/java/org/onlab/onos/net/Port.java
@@ -20,11 +20,11 @@
boolean isEnabled();
/**
- * Returns the identifier of the network element to which this port belongs.
+ * Returns the parent network element to which this port belongs.
*
* @return parent network element
*/
- Element parent();
+ Element element();
// set of port attributes
diff --git a/net/api/src/main/java/org/onlab/onos/net/device/DeviceEvent.java b/net/api/src/main/java/org/onlab/onos/net/device/DeviceEvent.java
index 984f575..10b3b19 100644
--- a/net/api/src/main/java/org/onlab/onos/net/device/DeviceEvent.java
+++ b/net/api/src/main/java/org/onlab/onos/net/device/DeviceEvent.java
@@ -2,12 +2,15 @@
import org.onlab.onos.event.AbstractEvent;
import org.onlab.onos.net.Device;
+import org.onlab.onos.net.Port;
/**
* Describes infrastructure device event.
*/
public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> {
+ private final Port port;
+
/**
* Type of device events.
*/
@@ -42,7 +45,22 @@
* Signifies that the current controller instance relationship has
* changed with respect to a device.
*/
- DEVICE_MASTERSHIP_CHANGED
+ DEVICE_MASTERSHIP_CHANGED,
+
+ /**
+ * Signifies that a port has been added.
+ */
+ PORT_ADDED,
+
+ /**
+ * Signifies that a port has been updated.
+ */
+ PORT_UPDATED,
+
+ /**
+ * Signifies that a port has been removed.
+ */
+ PORT_REMOVED
}
/**
@@ -53,7 +71,20 @@
* @param device event device subject
*/
public DeviceEvent(Type type, Device device) {
+ this(type, device, null);
+ }
+
+ /**
+ * Creates an event of a given type and for the specified device, port
+ * and the current time.
+ *
+ * @param type device event type
+ * @param device event device subject
+ * @param port optional port subject
+ */
+ public DeviceEvent(Type type, Device device, Port port) {
super(type, device);
+ this.port = port;
}
/**
@@ -61,10 +92,21 @@
*
* @param type device event type
* @param device event device subject
+ * @param port optional port subject
* @param time occurrence time
*/
- public DeviceEvent(Type type, Device device, long time) {
+ public DeviceEvent(Type type, Device device, Port port, long time) {
super(type, device, time);
+ this.port = port;
+ }
+
+ /**
+ * Returns the port subject.
+ *
+ * @return port subject or null if the event is not port specific.
+ */
+ Port port() {
+ return port;
}
}