[ONOS-4681] Enables device registration in GossipDeviceStore,
exposes availability, and polls NETCONF device reachability.
Change-Id: I5492c7b6109c3431d71555a9104c7e97fc6e75be
diff --git a/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java b/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java
index 72ec4ab..91ce5af 100644
--- a/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java
@@ -38,6 +38,7 @@
private final String swVersion;
private final String serialNumber;
private final ChassisId chassisId;
+ private final boolean defaultAvailable;
/**
* Creates a device description using the supplied information.
@@ -55,6 +56,28 @@
String hwVersion, String swVersion,
String serialNumber, ChassisId chassis,
SparseAnnotations... annotations) {
+ this(uri, type, manufacturer, hwVersion, swVersion, serialNumber,
+ chassis, true, annotations);
+ }
+
+ /**
+ * Creates a device description using the supplied information.
+ *
+ * @param uri device URI
+ * @param type device type
+ * @param manufacturer device manufacturer
+ * @param hwVersion device HW version
+ * @param swVersion device SW version
+ * @param serialNumber device serial number
+ * @param chassis chassis id
+ * @param defaultAvailable optional whether device is by default available
+ * @param annotations optional key/value annotations map
+ */
+ public DefaultDeviceDescription(URI uri, Type type, String manufacturer,
+ String hwVersion, String swVersion,
+ String serialNumber, ChassisId chassis,
+ boolean defaultAvailable,
+ SparseAnnotations... annotations) {
super(annotations);
this.uri = checkNotNull(uri, "Device URI cannot be null");
this.type = checkNotNull(type, "Device type cannot be null");
@@ -63,6 +86,7 @@
this.swVersion = swVersion;
this.serialNumber = serialNumber;
this.chassisId = chassis;
+ this.defaultAvailable = defaultAvailable;
}
/**
@@ -74,7 +98,7 @@
SparseAnnotations... annotations) {
this(base.deviceUri(), base.type(), base.manufacturer(),
base.hwVersion(), base.swVersion(), base.serialNumber(),
- base.chassisId(), annotations);
+ base.chassisId(), base.isDefaultAvailable(), annotations);
}
/**
@@ -83,10 +107,26 @@
* @param type device type
* @param annotations Annotations to use.
*/
- public DefaultDeviceDescription(DeviceDescription base, Type type, SparseAnnotations... annotations) {
+ public DefaultDeviceDescription(DeviceDescription base, Type type,
+ SparseAnnotations... annotations) {
this(base.deviceUri(), type, base.manufacturer(),
base.hwVersion(), base.swVersion(), base.serialNumber(),
- base.chassisId(), annotations);
+ base.chassisId(), base.isDefaultAvailable(), annotations);
+ }
+
+ /**
+ * Creates a device description using the supplied information.
+ *
+ * @param base DeviceDescription to basic information (except for defaultAvailable)
+ * @param defaultAvailable whether device should be made available by default
+ * @param annotations Annotations to use.
+ */
+ public DefaultDeviceDescription(DeviceDescription base,
+ boolean defaultAvailable,
+ SparseAnnotations... annotations) {
+ this(base.deviceUri(), base.type(), base.manufacturer(),
+ base.hwVersion(), base.swVersion(), base.serialNumber(),
+ base.chassisId(), defaultAvailable, annotations);
}
@Override
@@ -125,6 +165,11 @@
}
@Override
+ public boolean isDefaultAvailable() {
+ return defaultAvailable;
+ }
+
+ @Override
public String toString() {
return toStringHelper(this)
.add("uri", uri).add("type", type).add("mfr", manufacturer)
@@ -137,7 +182,8 @@
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), uri, type, manufacturer,
- hwVersion, swVersion, serialNumber, chassisId);
+ hwVersion, swVersion, serialNumber, chassisId,
+ defaultAvailable);
}
@Override
@@ -153,7 +199,8 @@
&& Objects.equal(this.hwVersion, that.hwVersion)
&& Objects.equal(this.swVersion, that.swVersion)
&& Objects.equal(this.serialNumber, that.serialNumber)
- && Objects.equal(this.chassisId, that.chassisId);
+ && Objects.equal(this.chassisId, that.chassisId)
+ && Objects.equal(this.defaultAvailable, that.defaultAvailable);
}
return false;
}
@@ -167,5 +214,6 @@
this.swVersion = null;
this.serialNumber = null;
this.chassisId = null;
+ this.defaultAvailable = true;
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java b/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java
index b796f29..848fc6d 100644
--- a/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java
@@ -77,4 +77,11 @@
*/
ChassisId chassisId();
+ /**
+ * Return whether device should be made available by default.
+ *
+ * @return default availability
+ */
+ boolean isDefaultAvailable();
+
}
diff --git a/core/api/src/main/java/org/onosproject/net/device/DeviceStore.java b/core/api/src/main/java/org/onosproject/net/device/DeviceStore.java
index cfc9626..e010202 100644
--- a/core/api/src/main/java/org/onosproject/net/device/DeviceStore.java
+++ b/core/api/src/main/java/org/onosproject/net/device/DeviceStore.java
@@ -52,8 +52,6 @@
*/
Iterable<Device> getAvailableDevices();
-
-
/**
* Returns the device with the specified identifier.
*
@@ -74,6 +72,7 @@
DeviceEvent createOrUpdateDevice(ProviderId providerId, DeviceId deviceId,
DeviceDescription deviceDescription);
+
// TODO: We may need to enforce that ancillary cannot interfere this state
/**
* Removes the specified infrastructure device.
@@ -84,6 +83,14 @@
DeviceEvent markOffline(DeviceId deviceId);
/**
+ * Marks the device as available.
+ *
+ * @param deviceId device identifier
+ * @return true if availability change request was accepted and changed the state
+ */
+ boolean markOnline(DeviceId deviceId);
+
+ /**
* Updates the ports of the specified infrastructure device using the given
* list of port descriptions. The list is assumed to be comprehensive.
*