Allow links to be configured as unidirectional.
Change-Id: I25eedc96aab9316c2210952b6ce8cb7ee468412e
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java
index cd05e14..6a5e026 100644
--- a/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java
@@ -33,12 +33,14 @@
public static final String LATENCY = "latency";
public static final String BANDWIDTH = "bandwidth";
public static final String IS_DURABLE = "durable";
+ public static final String IS_BIDIRECTIONAL = "bidirectional";
@Override
public boolean isValid() {
- return hasOnlyFields(ALLOWED, TYPE, METRIC, LATENCY, BANDWIDTH, IS_DURABLE) &&
+ return hasOnlyFields(ALLOWED, TYPE, METRIC, LATENCY, BANDWIDTH, IS_DURABLE, IS_BIDIRECTIONAL) &&
isBoolean(ALLOWED, OPTIONAL) && isNumber(METRIC, OPTIONAL) &&
- isNumber(LATENCY, OPTIONAL) && isNumber(BANDWIDTH, OPTIONAL);
+ isNumber(LATENCY, OPTIONAL) && isNumber(BANDWIDTH, OPTIONAL) &&
+ isBoolean(IS_BIDIRECTIONAL, OPTIONAL);
}
/**
@@ -142,4 +144,27 @@
public BasicLinkConfig isDurable(Boolean isDurable) {
return (BasicLinkConfig) setOrClear(IS_DURABLE, isDurable);
}
+
+ /**
+ * Returns if link is bidirectional in the network model or not.
+ *
+ * @return true for bidirectional, false otherwise
+ */
+ public Boolean isBidirectional() {
+ JsonNode res = object.path(IS_BIDIRECTIONAL);
+ if (res.isMissingNode()) {
+ return true;
+ }
+ return res.asBoolean();
+ }
+
+ /**
+ * Sets durability for this link.
+ *
+ * @param isBidirectional true for directional, false otherwise
+ * @return this BasicLinkConfig
+ */
+ public BasicLinkConfig isBidirectional(Boolean isBidirectional) {
+ return (BasicLinkConfig) setOrClear(IS_BIDIRECTIONAL, isBidirectional);
+ }
}
diff --git a/core/api/src/test/java/org/onosproject/net/config/basics/BasicLinkConfigTest.java b/core/api/src/test/java/org/onosproject/net/config/basics/BasicLinkConfigTest.java
index 9ace865..feb5b22 100644
--- a/core/api/src/test/java/org/onosproject/net/config/basics/BasicLinkConfigTest.java
+++ b/core/api/src/test/java/org/onosproject/net/config/basics/BasicLinkConfigTest.java
@@ -15,16 +15,15 @@
*/
package org.onosproject.net.config.basics;
-import java.time.Duration;
-
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.junit.Test;
import org.onosproject.net.Link;
import org.onosproject.net.LinkKey;
import org.onosproject.net.NetTestTools;
import org.onosproject.net.config.ConfigApplyDelegate;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import java.time.Duration;
import static java.lang.Boolean.FALSE;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -55,16 +54,18 @@
config.bandwidth(BANDWIDTH)
- .isDurable(FALSE)
- .metric(METRIC)
- .type(Link.Type.DIRECT)
- .latency(LATENCY);
+ .isDurable(FALSE)
+ .metric(METRIC)
+ .type(Link.Type.DIRECT)
+ .latency(LATENCY)
+ .isBidirectional(FALSE);
assertThat(config.bandwidth(), is(BANDWIDTH));
assertThat(config.isDurable(), is(FALSE));
assertThat(config.metric(), is(METRIC));
assertThat(config.type(), is(Link.Type.DIRECT));
assertThat(config.latency(), is(LATENCY));
+ assertThat(config.isBidirectional(), is(FALSE));
assertThat(config.isValid(), is(true));
}
}