Added Port.Type and plumbed it throughout.
diff --git a/core/api/src/main/java/org/onlab/onos/net/DefaultPort.java b/core/api/src/main/java/org/onlab/onos/net/DefaultPort.java
index 9d4f8a8..d9cd764 100644
--- a/core/api/src/main/java/org/onlab/onos/net/DefaultPort.java
+++ b/core/api/src/main/java/org/onlab/onos/net/DefaultPort.java
@@ -24,9 +24,14 @@
*/
public class DefaultPort extends AbstractAnnotated implements Port {
+ /** Default port speed in Mbps. */
+ public static final long DEFAULT_SPEED = 1_000;
+
private final Element element;
private final PortNumber number;
private final boolean isEnabled;
+ private final Type type;
+ private final long portSpeed;
/**
* Creates a network element attributed to the specified provider.
@@ -36,40 +41,35 @@
* @param isEnabled indicator whether the port is up and active
* @param annotations optional key/value annotations
*/
- public DefaultPort(Element element, PortNumber number,
- boolean isEnabled, Annotations... annotations) {
+ public DefaultPort(Element element, PortNumber number, boolean isEnabled,
+ Annotations... annotations) {
+ this(element, number, isEnabled, Type.COPPER, DEFAULT_SPEED, annotations);
+ }
+
+ /**
+ * 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
+ * @param type port type
+ * @param portSpeed port speed in Mbs
+ * @param annotations optional key/value annotations
+ */
+ public DefaultPort(Element element, PortNumber number, boolean isEnabled,
+ Type type, long portSpeed, Annotations... annotations) {
super(annotations);
this.element = element;
this.number = number;
this.isEnabled = isEnabled;
+ this.type = type;
+ this.portSpeed = portSpeed;
+
}
@Override
- public int hashCode() {
- return Objects.hash(number, isEnabled);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- 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();
+ public Element element() {
+ return element;
}
@Override
@@ -83,8 +83,45 @@
}
@Override
- public Element element() {
- return element;
+ public Type type() {
+ return type;
+ }
+
+ @Override
+ public long portSpeed() {
+ return portSpeed;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(number, isEnabled, type, portSpeed);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ 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) &&
+ Objects.equals(this.type, other.type) &&
+ Objects.equals(this.portSpeed, other.portSpeed);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("element", element.id())
+ .add("number", number)
+ .add("isEnabled", isEnabled)
+ .add("type", type)
+ .add("portSpeed", portSpeed)
+ .toString();
}
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/Port.java b/core/api/src/main/java/org/onlab/onos/net/Port.java
index 7bf6af3..2153593 100644
--- a/core/api/src/main/java/org/onlab/onos/net/Port.java
+++ b/core/api/src/main/java/org/onlab/onos/net/Port.java
@@ -21,6 +21,26 @@
*/
public interface Port extends Annotated {
+ /** Represents coarse port type classification. */
+ public enum Type {
+ /**
+ * Signifies copper-based connectivity.
+ */
+ COPPER,
+
+ /**
+ * Signifies optical fiber-based connectivity.
+ */
+ FIBER
+ }
+
+ /**
+ * Returns the parent network element to which this port belongs.
+ *
+ * @return parent network element
+ */
+ Element element();
+
/**
* Returns the port number.
*
@@ -36,12 +56,18 @@
boolean isEnabled();
/**
- * Returns the parent network element to which this port belongs.
+ * Returns the port type.
*
- * @return parent network element
+ * @return port type
*/
- Element element();
+ Type type();
- // set of port attributes
+ /**
+ * Returns the current port speed in Mbps.
+ *
+ * @return current port speed
+ */
+ long portSpeed();
+ // TODO: more attributes?
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DefaultPortDescription.java b/core/api/src/main/java/org/onlab/onos/net/device/DefaultPortDescription.java
index 47e3280..9688827 100644
--- a/core/api/src/main/java/org/onlab/onos/net/device/DefaultPortDescription.java
+++ b/core/api/src/main/java/org/onlab/onos/net/device/DefaultPortDescription.java
@@ -15,11 +15,12 @@
*/
package org.onlab.onos.net.device;
+import com.google.common.base.MoreObjects;
import org.onlab.onos.net.AbstractDescription;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.SparseAnnotations;
-import com.google.common.base.MoreObjects;
+import static org.onlab.onos.net.Port.Type;
/**
* Default implementation of immutable port description.
@@ -27,32 +28,62 @@
public class DefaultPortDescription extends AbstractDescription
implements PortDescription {
+ private static final long DEFAULT_SPEED = 1_000;
+
private final PortNumber number;
private final boolean isEnabled;
+ private final Type type;
+ private final long portSpeed;
/**
* Creates a port description using the supplied information.
*
- * @param number port number
- * @param isEnabled port enabled state
- * @param annotations optional key/value annotations map
+ * @param number port number
+ * @param isEnabled port enabled state
+ * @param annotations optional key/value annotations map
*/
public DefaultPortDescription(PortNumber number, boolean isEnabled,
- SparseAnnotations... annotations) {
- super(annotations);
- this.number = number;
- this.isEnabled = isEnabled;
+ SparseAnnotations... annotations) {
+ this(number, isEnabled, Type.COPPER, DEFAULT_SPEED, annotations);
}
/**
* Creates a port description using the supplied information.
*
- * @param base PortDescription to get basic information from
- * @param annotations optional key/value annotations map
+ * @param number port number
+ * @param isEnabled port enabled state
+ * @param type port type
+ * @param portSpeed port speed in Mbps
+ * @param annotations optional key/value annotations map
+ */
+ public DefaultPortDescription(PortNumber number, boolean isEnabled,
+ Type type, long portSpeed,
+ SparseAnnotations...annotations) {
+ super(annotations);
+ this.number = number;
+ this.isEnabled = isEnabled;
+ this.type = type;
+ this.portSpeed = portSpeed;
+ }
+
+ // Default constructor for serialization
+ private DefaultPortDescription() {
+ this.number = null;
+ this.isEnabled = false;
+ this.portSpeed = DEFAULT_SPEED;
+ this.type = Type.COPPER;
+ }
+
+ /**
+ * Creates a port description using the supplied information.
+ *
+ * @param base PortDescription to get basic information from
+ * @param annotations optional key/value annotations map
*/
public DefaultPortDescription(PortDescription base,
- SparseAnnotations annotations) {
- this(base.portNumber(), base.isEnabled(), annotations);
+ SparseAnnotations annotations) {
+ this(base.portNumber(), base.isEnabled(), base.type(), base.portSpeed(),
+ annotations);
}
@Override
@@ -66,17 +97,24 @@
}
@Override
+ public Type type() {
+ return type;
+ }
+
+ @Override
+ public long portSpeed() {
+ return portSpeed;
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("number", number)
.add("isEnabled", isEnabled)
+ .add("type", type)
+ .add("portSpeed", portSpeed)
.add("annotations", annotations())
.toString();
}
- // default constructor for serialization
- private DefaultPortDescription() {
- this.number = null;
- this.isEnabled = false;
- }
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/PortDescription.java b/core/api/src/main/java/org/onlab/onos/net/device/PortDescription.java
index cdee005..b134d83 100644
--- a/core/api/src/main/java/org/onlab/onos/net/device/PortDescription.java
+++ b/core/api/src/main/java/org/onlab/onos/net/device/PortDescription.java
@@ -18,13 +18,13 @@
import org.onlab.onos.net.Description;
import org.onlab.onos.net.PortNumber;
+import static org.onlab.onos.net.Port.Type;
+
/**
* Information about a port.
*/
public interface PortDescription extends Description {
- // TODO: possibly relocate this to a common ground so that this can also used by host tracking if required
-
/**
* Returns the port number.
*
@@ -39,4 +39,18 @@
*/
boolean isEnabled();
+ /**
+ * Returns the port type.
+ *
+ * @return port type
+ */
+ Type type();
+
+ /**
+ * Returns the current port speed in Mbps.
+ *
+ * @return current port speed
+ */
+ long portSpeed();
+
}