Introduce driver property to suppress meter feature
Piggybacked in this commit:
- Fix CLI output of driver properties
- Fix mfr matching pattern in onos-drivers.xml
- Add driver support for Accton OFDPA 3
Change-Id: Ia350bd52f4e88e53565ff491d68bce5e4894bbb9
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriver.java b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriver.java
index 6ffdbee..89cec03 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriver.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriver.java
@@ -22,9 +22,11 @@
import org.slf4j.Logger;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Queue;
import java.util.Set;
import static com.google.common.base.MoreObjects.toStringHelper;
@@ -238,6 +240,22 @@
}
@Override
+ public String getProperty(String name) {
+ Queue<Driver> queue = new LinkedList<>();
+ queue.add(this);
+ while (!queue.isEmpty()) {
+ Driver driver = queue.remove();
+ String property = driver.properties().get(name);
+ if (property != null) {
+ return property;
+ } else if (driver.parents() != null) {
+ queue.addAll(driver.parents());
+ }
+ }
+ return null;
+ }
+
+ @Override
public String toString() {
return toStringHelper(this)
.add("name", name)
diff --git a/core/api/src/main/java/org/onosproject/net/driver/Driver.java b/core/api/src/main/java/org/onosproject/net/driver/Driver.java
index d8f6f3c..ce7cc03 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/Driver.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/Driver.java
@@ -132,6 +132,16 @@
Map<String, String> properties();
/**
+ * Gets the value of given property name.
+ * If the driver does not define the property, a BFS will be performed to search its ancestors.
+ *
+ * @param name property name
+ * @return the value of the property,
+ * or null if the property is not defined in this driver nor in any of its ancestors
+ */
+ String getProperty(String name);
+
+ /**
* Merges the specified driver behaviours and properties into this one,
* giving preference to the other driver when dealing with conflicts.
*
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterProvider.java b/core/api/src/main/java/org/onosproject/net/meter/MeterProvider.java
index 3d14d06..2688dc0 100644
--- a/core/api/src/main/java/org/onosproject/net/meter/MeterProvider.java
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterProvider.java
@@ -22,6 +22,11 @@
* Abstraction of a Meter provider.
*/
public interface MeterProvider extends Provider {
+ /**
+ * Meter capable property name.
+ * A driver is assumed to be meter capable if this property is undefined.
+ */
+ String METER_CAPABLE = "meterCapable";
/**
* Performs a batch of meter operation on the specified device with the
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
index 2062951..2774194 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
@@ -17,15 +17,25 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
import org.junit.Test;
import java.util.ArrayList;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.onosproject.net.driver.DefaultDriverDataTest.DEVICE_ID;
public class DefaultDriverTest {
+ private static final String MFR = "mfr";
+ private static final String HW = "hw";
+ private static final String SW = "sw";
+ private static final String KEY = "key";
+ private static final String VALUE = "value";
+ private static final String ROOT = "rootDriver";
+ private static final String CHILD = "childDriver";
+ private static final String GRAND_CHILD = "grandChilDriver";
@Test
public void basics() {
@@ -90,4 +100,20 @@
assertTrue("incorrect toString", ddc.toString().contains("Circus"));
}
+
+ @Test
+ public void testGetProperty() throws Exception {
+ DefaultDriver root = new DefaultDriver(ROOT, Lists.newArrayList(), MFR, HW, SW,
+ ImmutableMap.of(), ImmutableMap.of());
+
+ DefaultDriver child = new DefaultDriver(CHILD, Lists.newArrayList(root), MFR, HW, SW,
+ ImmutableMap.of(), ImmutableMap.of(KEY, VALUE));
+
+ DefaultDriver grandChild = new DefaultDriver(GRAND_CHILD, Lists.newArrayList(child),
+ MFR, HW, SW, ImmutableMap.of(), ImmutableMap.of());
+
+ assertNull(root.getProperty(KEY));
+ assertEquals(VALUE, child.getProperty(KEY));
+ assertEquals(VALUE, grandChild.getProperty(KEY));
+ }
}
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DriverAdapter.java b/core/api/src/test/java/org/onosproject/net/driver/DriverAdapter.java
index a989e758..25b3aca 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DriverAdapter.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DriverAdapter.java
@@ -84,6 +84,11 @@
}
@Override
+ public String getProperty(String name) {
+ return null;
+ }
+
+ @Override
public Driver merge(Driver other) {
return null;
}