useStaleLinkAge for VanishStaleLink
Change-Id: Ifd8079172a096bef0edf89daca97395c2d35a5ce
diff --git a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
index 87ca7d7..b752478 100644
--- a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
+++ b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
@@ -101,7 +101,7 @@
private static final String FORMAT =
"Settings: enabled={}, useBDDP={}, probeRate={}, " +
- "staleLinkAge={}";
+ "staleLinkAge={}, useStaleLinkAge={}";
// When a Device/Port has this annotation, do not send out LLDP/BDDP
public static final String NO_LLDP = "no-lldp";
@@ -174,6 +174,12 @@
label = "Number of millis beyond which links will be considered stale")
private int staleLinkAge = DEFAULT_STALE_LINK_AGE;
+ public static final String PROP_USE_STALE_LINK_AGE = "useStaleLinkAge";
+ public static final boolean DEFAULT_USE_STALE_LINK_AGE = true;
+ @Property(name = PROP_USE_STALE_LINK_AGE, boolValue = DEFAULT_USE_STALE_LINK_AGE,
+ label = "If false, StaleLinkAge cpability is disabled")
+ private boolean useStaleLinkAge = DEFAULT_USE_STALE_LINK_AGE;
+
private final LinkDiscoveryContext context = new InternalDiscoveryContext();
private final InternalRoleListener roleListener = new InternalRoleListener();
private final InternalDeviceListener deviceListener = new InternalDeviceListener();
@@ -296,7 +302,7 @@
public void modified(ComponentContext context) {
Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
- boolean newEnabled, newUseBddp;
+ boolean newEnabled, newUseBddp, newUseStaleLinkAge;
int newProbeRate, newStaleLinkAge;
try {
String s = get(properties, PROP_ENABLED);
@@ -311,12 +317,16 @@
s = get(properties, PROP_STALE_LINK_AGE);
newStaleLinkAge = isNullOrEmpty(s) ? staleLinkAge : Integer.parseInt(s.trim());
+ s = get(properties, PROP_USE_STALE_LINK_AGE);
+ newUseStaleLinkAge = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim());
+
} catch (NumberFormatException e) {
log.warn("Component configuration had invalid values", e);
newEnabled = enabled;
newUseBddp = useBddp;
newProbeRate = probeRate;
newStaleLinkAge = staleLinkAge;
+ newUseStaleLinkAge = useStaleLinkAge;
}
boolean wasEnabled = enabled;
@@ -325,6 +335,7 @@
useBddp = newUseBddp;
probeRate = newProbeRate;
staleLinkAge = newStaleLinkAge;
+ useStaleLinkAge = newUseStaleLinkAge;
if (!wasEnabled && enabled) {
enable();
@@ -337,7 +348,7 @@
}
}
- log.info(FORMAT, enabled, useBddp, probeRate, staleLinkAge);
+ log.info(FORMAT, enabled, useBddp, probeRate, staleLinkAge, useStaleLinkAge);
}
/**
@@ -727,10 +738,15 @@
return true;
}
if (isStale(e.getValue())) {
- providerService.linkVanished(new DefaultLinkDescription(e.getKey().src(),
+ if (useStaleLinkAge) {
+ providerService.linkVanished(new DefaultLinkDescription(e.getKey().src(),
e.getKey().dst(),
DIRECT));
- return true;
+ return true;
+ }
+ log.warn("VanishStaleLinkAge feature is disabled, " +
+ "not bringing down link src {} dst {} with expired StaleLinkAge",
+ e.getKey().src(), e.getKey().dst());
}
return false;
}).clear();
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java
index 3c74d94..713f690 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java
@@ -23,7 +23,9 @@
import org.onosproject.rest.AbstractWebResource;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@@ -31,6 +33,13 @@
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.PortNumber.portNumber;
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.cfg.ConfigProperty;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.IOException;
+import java.io.InputStream;
+
/**
* Manage inventory of infrastructure links.
@@ -97,4 +106,55 @@
}
}
+ /**
+ * Get useStaleLinkAge active status.
+ * Returns current status of the VanishedStaleLink.
+ *
+ * @onos.rsModel VanishedLink
+ * @return 200 ok with the VanishedStaleLink status.
+ */
+ @GET
+ @Path("{usestalelinkage}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getVanishStaleLink() {
+ ObjectNode root = mapper().createObjectNode();
+ ComponentConfigService useStaleLink = get(ComponentConfigService.class);
+
+ for (ConfigProperty prop : useStaleLink.getProperties("org.onosproject.provider.lldp.impl.LldpLinkProvider")) {
+ if (prop.name().equals("useStaleLinkAge")) {
+ root.put("active", Boolean.valueOf(prop.value()));
+ break;
+ }
+ }
+ return ok(root).build();
+ }
+
+ /**
+ * Set useStaleLinkAge status.
+ *
+ * @onos.rsModel VanishedLink
+ * @param stream input JSON
+ * @return 200 ok.
+ * BAD_REQUEST if the JSON is invalid
+ */
+ @POST
+ @Path("{usestalelinkage}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response setVanishStaleLink(InputStream stream) {
+ try {
+ // Parse the input stream
+ ObjectNode root = (ObjectNode) mapper().readTree(stream);
+ if (root.has("active")) {
+ ComponentConfigService useStaleLink = get(ComponentConfigService.class);
+ useStaleLink.setProperty("org.onosproject.provider.lldp.impl.LldpLinkProvider",
+ "useStaleLinkAge", String.valueOf(root.get("active")));
+ }
+ } catch (IOException ex) {
+ throw new IllegalArgumentException(ex);
+ }
+ return Response
+ .ok()
+ .build();
+ }
}
diff --git a/web/api/src/main/resources/definitions/VanishedLink.json b/web/api/src/main/resources/definitions/VanishedLink.json
new file mode 100644
index 0000000..7bee04b
--- /dev/null
+++ b/web/api/src/main/resources/definitions/VanishedLink.json
@@ -0,0 +1,12 @@
+{
+ "type" : "object",
+ "required": [
+ "active"
+ ],
+ "properties": {
+ "active": {
+ "type": "boolean",
+ "example": true
+ }
+ }
+}