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/cli/src/main/java/org/onosproject/cli/net/DriversListCommand.java b/cli/src/main/java/org/onosproject/cli/net/DriversListCommand.java
index 589cb06..3cafc0f 100644
--- a/cli/src/main/java/org/onosproject/cli/net/DriversListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/DriversListCommand.java
@@ -88,9 +88,10 @@
}
driver.behaviours().forEach(b -> printBehaviour(b, driver));
+ driver.properties().forEach((k, v) -> print(FMT_P, k, v));
+
//recursion call to print each parent
parents.stream().forEach(parent -> printDriver(parent, false));
- driver.properties().forEach((k, v) -> print(FMT_P, k, v));
}
}
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;
}
diff --git a/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java b/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java
index 9850004..17100e3 100644
--- a/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java
@@ -279,6 +279,11 @@
}
@Override
+ public String getProperty(String name) {
+ return null;
+ }
+
+ @Override
public Set<Class<? extends Behaviour>> behaviours() {
return ImmutableSet.of(DeviceDescriptionDiscovery.class);
}
diff --git a/drivers/default/src/main/resources/onos-drivers.xml b/drivers/default/src/main/resources/onos-drivers.xml
index fa32015..61602ee 100644
--- a/drivers/default/src/main/resources/onos-drivers.xml
+++ b/drivers/default/src/main/resources/onos-drivers.xml
@@ -59,7 +59,7 @@
~ TODO: version number in i12_1.7 is 2.0. Change it back when we can distinguish 3.0.
-->
<driver name="ofdpa" extends="default"
- manufacturer="Broadcom Corp." hwVersion="OF-DPA i12_1.7" swVersion="OF-DPA i12_1.7">
+ manufacturer="Broadcom Corp\." hwVersion="OF-DPA i12_1.7" swVersion="OF-DPA i12_1.7">
<behaviour api="org.onosproject.net.behaviour.Pipeliner"
impl="org.onosproject.driver.pipeline.ofdpa.Ofdpa2Pipeline"/>
<behaviour api="org.onosproject.openflow.controller.ExtensionTreatmentInterpreter"
@@ -70,13 +70,14 @@
impl="org.onosproject.driver.extensions.OfdpaExtensionSelectorInterpreter" />
<behaviour api="org.onosproject.net.behaviour.ExtensionSelectorResolver"
impl="org.onosproject.driver.extensions.OfdpaExtensionSelectorInterpreter" />
+ <property name="meterCapable">false</property>
</driver>
<!-- Driver for OFDPA 3.0 EA*.
~ TODO: version number from switch is still 2.0. Update when 3.0 is GA.
-->
- <driver name="ofdpa3" extends="default"
- manufacturer="Broadcom Corp." hwVersion="OF-DPA 2.0" swVersion="OF-DPA 2.0">
+ <driver name="ofdpa3" extends="ofdpa"
+ manufacturer="Broadcom Corp\." hwVersion="OF-DPA 2.0" swVersion="OF-DPA 2.0">
<behaviour api="org.onosproject.net.behaviour.Pipeliner"
impl="org.onosproject.driver.pipeline.ofdpa.Ofdpa3Pipeline"/>
<behaviour api="org.onosproject.openflow.controller.ExtensionTreatmentInterpreter"
@@ -93,12 +94,16 @@
~ Note: driver needs to be configured using onos-netcfg.
-->
<driver name="qmx-ofdpa3" extends="ofdpa3"
- manufacturer="Broadcom Corp." hwVersion="Qmx" swVersion="Qmx">
- <behaviour api="org.onosproject.net.behaviour.Pipeliner"
- impl="org.onosproject.driver.pipeline.ofdpa.Ofdpa3QmxPipeline"/>
+ manufacturer="Broadcom Corp\." hwVersion="Qmx" swVersion="Qmx">
+ <behaviour api="org.onosproject.net.behaviour.Pipeliner"
+ impl="org.onosproject.driver.pipeline.ofdpa.Ofdpa3QmxPipeline"/>
</driver>
- <driver name="znyx-ofdpa" extends="default"
+ <driver name="accton-ofdpa3" extends="ofdpa3"
+ manufacturer="Accton Corp\." hwVersion=".*" swVersion="ofdpa 3.*">
+ </driver>
+
+ <driver name="znyx-ofdpa" extends="ofdpa3"
manufacturer="ZNYX Networks" hwVersion=".*" swVersion=".*OF-DPA.*">
<behaviour api="org.onosproject.net.behaviour.Pipeliner"
impl="org.onosproject.driver.pipeline.ofdpa.Ofdpa3Pipeline"/>
diff --git a/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java b/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java
index 9c4ccab..5f1a543 100644
--- a/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java
+++ b/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java
@@ -29,6 +29,8 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.core.CoreService;
+import org.onosproject.net.driver.Driver;
+import org.onosproject.net.driver.DriverService;
import org.onosproject.net.meter.Band;
import org.onosproject.net.meter.DefaultBand;
import org.onosproject.net.meter.DefaultMeter;
@@ -87,7 +89,6 @@
@Component(immediate = true, enabled = true)
public class OpenFlowMeterProvider extends AbstractProvider implements MeterProvider {
-
private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -99,6 +100,9 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DriverService driverService;
+
private MeterProviderService providerService;
private static final AtomicLong XID_COUNTER = new AtomicLong(1);
@@ -251,13 +255,25 @@
sw.factory().getVersion() == OFVersion.OF_11 ||
sw.factory().getVersion() == OFVersion.OF_12 ||
NO_METER_SUPPORT.contains(sw.deviceType()) ||
- sw.softwareDescription().equals("OF-DPA 2.0")) {
+ !isMeterCapable(sw)) {
return false;
}
return true;
}
+ /**
+ * Determine whether the given switch is meter-capable.
+ *
+ * @param sw switch
+ * @return the boolean value of meterCapable property, or true if it is not configured.
+ */
+ private boolean isMeterCapable(OpenFlowSwitch sw) {
+ Driver driver = driverService.getDriver(DeviceId.deviceId(Dpid.uri(sw.getDpid())));
+ String isMeterCapable = driver.getProperty(METER_CAPABLE);
+ return isMeterCapable == null || Boolean.parseBoolean(isMeterCapable);
+ }
+
private void pushMeterStats(Dpid dpid, OFStatsReply msg) {
DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));