Registering BMv2 default/base pipeconf at driver loading
Change-Id: Ib46bf202213a741c4a73732e20cd1638424f8a0a
diff --git a/core/net/src/main/java/org/onosproject/net/pi/impl/PiPipeconfManager.java b/core/net/src/main/java/org/onosproject/net/pi/impl/PiPipeconfManager.java
index 85d3fc3..000ded3 100644
--- a/core/net/src/main/java/org/onosproject/net/pi/impl/PiPipeconfManager.java
+++ b/core/net/src/main/java/org/onosproject/net/pi/impl/PiPipeconfManager.java
@@ -56,6 +56,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import static java.lang.String.format;
import static org.onlab.util.Tools.groupedThreads;
import static org.slf4j.LoggerFactory.getLogger;
@@ -89,7 +90,7 @@
protected ExecutorService executor =
Executors.newFixedThreadPool(5, groupedThreads("onos/pipipeconfservice",
- "pipeline-to-device-%d", log));
+ "pipeline-to-device-%d", log));
protected final ConfigFactory factory =
new ConfigFactory<DeviceId, PiPipeconfConfig>(
@@ -129,7 +130,11 @@
@Override
public void register(PiPipeconf pipeconf) throws IllegalStateException {
log.warn("Currently using local maps, needs to be moved to a distributed store");
+ if (piPipeconfs.containsKey(pipeconf.id())) {
+ throw new IllegalStateException(format("Pipeconf %s is already registered", pipeconf.id()));
+ }
piPipeconfs.put(pipeconf.id(), pipeconf);
+ log.info("New pipeconf registered: {}", pipeconf.id());
}
@Override
@@ -165,7 +170,7 @@
} catch (ItemNotFoundException e) {
log.debug("First time pipeconf {} is used with base driver {}, merging the two",
- pipeconfId, baseDriver);
+ pipeconfId, baseDriver);
//extract the behaviours from the pipipeconf.
Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>();
piPipeconf.behaviours().forEach(b -> {
@@ -173,8 +178,8 @@
});
Driver piPipeconfDriver = new DefaultDriver(completeDriverName, baseDriver.parents(),
- baseDriver.manufacturer(), baseDriver.hwVersion(), baseDriver.swVersion(),
- behaviours, new HashMap<>());
+ baseDriver.manufacturer(), baseDriver.hwVersion(),
+ baseDriver.swVersion(), behaviours, new HashMap<>());
//we take the base driver created with the behaviours of the PiPeconf and
// merge it with the base driver that was assigned to the device
Driver completeDriver = piPipeconfDriver.merge(baseDriver);
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DefaultPipeconfFactory.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DefaultPipeconfFactory.java
index 3004627..1dbab42 100644
--- a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DefaultPipeconfFactory.java
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DefaultPipeconfFactory.java
@@ -38,11 +38,17 @@
private static final String JSON_PATH = "/default.json";
private static final String P4INFO_PATH = "/default.p4info";
+ private static final PiPipeconf PIPECONF = buildPipeconf();
+
private Bmv2DefaultPipeconfFactory() {
// Hides constructor.
}
static PiPipeconf get() {
+ return PIPECONF;
+ }
+
+ private static PiPipeconf buildPipeconf() {
final URL jsonUrl = Bmv2DefaultPipeconfFactory.class.getResource(JSON_PATH);
final URL p4InfoUrl = Bmv2DefaultPipeconfFactory.class.getResource(P4INFO_PATH);
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DriversLoader.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DriversLoader.java
index 45fb749..046e93b 100644
--- a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DriversLoader.java
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DriversLoader.java
@@ -17,7 +17,10 @@
package org.onosproject.drivers.bmv2;
import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.net.driver.AbstractDriverLoader;
+import org.onosproject.net.pi.runtime.PiPipeconfService;
/**
* Loader for P4Runtime device drivers.
@@ -25,7 +28,16 @@
@Component(immediate = true)
public class Bmv2DriversLoader extends AbstractDriverLoader {
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected PiPipeconfService pipeconfService;
+
public Bmv2DriversLoader() {
super("/bmv2-drivers.xml");
}
+
+ @Override
+ public void activate() {
+ pipeconfService.register(Bmv2DefaultPipeconfFactory.get());
+ super.activate();
+ }
}
diff --git a/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java b/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java
index ad48e1e..c6df99d 100644
--- a/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java
+++ b/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java
@@ -391,11 +391,6 @@
if (pipelineProg.getDefaultPipeconf().isPresent()) {
PiPipeconf defaultPipeconf = pipelineProg.getDefaultPipeconf().get();
log.info("Using default pipeconf {} for {}", defaultPipeconf.id(), deviceId);
- // Register default one if it is not.
- // TODO: this should be performed at driver loading.
- if (!piPipeconfService.getPipeconf(defaultPipeconf.id()).isPresent()) {
- piPipeconfService.register(defaultPipeconf);
- }
return defaultPipeconf.id();
} else {
return null;