Added P4Runtime-based Barefoot Tofino driver
Change-Id: I09ba8dd4468fa5a792ca481921e8a51dad49702e
diff --git a/apps/p4runtime-test/src/test/java/org/onosproject/p4runtime/test/P4RuntimeTest.java b/apps/p4runtime-test/src/test/java/org/onosproject/p4runtime/test/P4RuntimeTest.java
index ab55468..7b4c668 100644
--- a/apps/p4runtime-test/src/test/java/org/onosproject/p4runtime/test/P4RuntimeTest.java
+++ b/apps/p4runtime-test/src/test/java/org/onosproject/p4runtime/test/P4RuntimeTest.java
@@ -148,8 +148,8 @@
private void setPipelineConfig(PiPipeconf pipeconf, PiPipeconf.ExtensionType extensionType)
throws ExecutionException, InterruptedException, PiPipelineInterpreter.PiInterpreterException,
IllegalAccessException, InstantiationException {
-
- assert (client.setPipelineConfig(pipeconf, extensionType).get());
+ // FIXME: setPipelineConfig now takes a byte buffer, not extension type
+ // assert (client.setPipelineConfig(pipeconf, extensionType).get());
assert (client.initStreamChannel().get());
}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/model/PiPipeconf.java b/core/api/src/main/java/org/onosproject/net/pi/model/PiPipeconf.java
index f56fef3..0185e9b 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/model/PiPipeconf.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/model/PiPipeconf.java
@@ -95,6 +95,11 @@
/**
* Barefoot's Tofino configuration binary.
*/
- TOFINO_BIN
+ TOFINO_BIN,
+
+ /**
+ * Barefoot's Tofino context JSON.
+ */
+ TOFINO_CONTEXT_JSON
}
}
diff --git a/drivers/barefoot/BUCK b/drivers/barefoot/BUCK
new file mode 100644
index 0000000..f38ad9f
--- /dev/null
+++ b/drivers/barefoot/BUCK
@@ -0,0 +1,32 @@
+GRPC_VER = '1.3.0'
+
+COMPILE_DEPS = [
+ '//lib:CORE_DEPS',
+ '//lib:minimal-json',
+ '//incubator/bmv2/model:onos-incubator-bmv2-model',
+ '//protocols/p4runtime/api:onos-protocols-p4runtime-api',
+ '//drivers/p4runtime:onos-drivers-p4runtime',
+ '//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
+ '//lib:grpc-netty-' + GRPC_VER,
+]
+
+BUNDLES = [
+ ':onos-drivers-barefoot',
+ '//incubator/bmv2/model:onos-incubator-bmv2-model',
+]
+
+osgi_jar(
+ deps = COMPILE_DEPS,
+)
+
+onos_app (
+ app_name = 'org.onosproject.drivers.barefoot',
+ title = 'Barefoot Drivers',
+ category = 'Drivers',
+ url = 'http://onosproject.org',
+ description = 'Adds support for Barefoot-based devices',
+ included_bundles = BUNDLES,
+ required_apps = [
+ 'org.onosproject.drivers.p4runtime',
+ ],
+)
diff --git a/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/BarefootDriversLoader.java b/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/BarefootDriversLoader.java
new file mode 100644
index 0000000..41ab063
--- /dev/null
+++ b/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/BarefootDriversLoader.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.drivers.barefoot;
+
+import org.apache.felix.scr.annotations.Component;
+import org.onosproject.net.driver.AbstractDriverLoader;
+
+/**
+ * Loader for the Barefoot device drivers.
+ */
+@Component(immediate = true)
+public class BarefootDriversLoader extends AbstractDriverLoader {
+
+ public BarefootDriversLoader() {
+ super("/barefoot-drivers.xml");
+ }
+}
diff --git a/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/TofinoPipelineProgrammable.java b/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/TofinoPipelineProgrammable.java
new file mode 100644
index 0000000..197b681
--- /dev/null
+++ b/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/TofinoPipelineProgrammable.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.drivers.barefoot;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.io.IOUtils;
+import org.onosproject.drivers.p4runtime.AbstractP4RuntimePipelineProgrammable;
+import org.onosproject.net.pi.model.PiPipeconf;
+import org.onosproject.net.pi.model.PiPipeconf.ExtensionType;
+
+import java.io.IOException;
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Optional;
+
+import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.TOFINO_BIN;
+import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.TOFINO_CONTEXT_JSON;
+
+/**
+ * Implementation of the PiPipelineProgrammable behaviour for a Tofino-based switch.
+ */
+public class TofinoPipelineProgrammable extends AbstractP4RuntimePipelineProgrammable {
+
+ @Override
+ public Optional<PiPipeconf> getDefaultPipeconf() {
+ return Optional.empty();
+ }
+
+ @Override
+ public ByteBuffer createDeviceDataBuffer(PiPipeconf pipeconf) {
+
+ List<ByteBuffer> buffers = Lists.newLinkedList();
+ try {
+ buffers.add(nameBuffer(pipeconf));
+ buffers.add(extensionBuffer(pipeconf, TOFINO_BIN));
+ buffers.add(extensionBuffer(pipeconf, TOFINO_CONTEXT_JSON));
+ } catch (ExtensionException e) {
+ return null;
+ }
+
+ // Concatenate buffers (flip so they can be read).
+ int len = buffers.stream().mapToInt(Buffer::limit).sum();
+ ByteBuffer deviceData = ByteBuffer.allocate(len);
+ buffers.forEach(b -> deviceData.put((ByteBuffer) b.flip()));
+ deviceData.flip();
+
+ return deviceData.asReadOnlyBuffer();
+ }
+
+ private ByteBuffer nameBuffer(PiPipeconf pipeconf) {
+ // Length of the name + name.
+ String name = pipeconf.id().toString();
+ return ByteBuffer.allocate(Integer.BYTES + name.length())
+ .order(ByteOrder.LITTLE_ENDIAN)
+ .putInt(name.length())
+ .put(name.getBytes(StandardCharsets.UTF_8));
+ }
+
+ private ByteBuffer extensionBuffer(PiPipeconf pipeconf, ExtensionType extType) {
+ if (!pipeconf.extension(extType).isPresent()) {
+ log.warn("Missing extension {} in pipeconf {}", extType, pipeconf.id());
+ throw new ExtensionException();
+ }
+ try {
+ byte[] bytes = IOUtils.toByteArray(pipeconf.extension(extType).get());
+ // Length of the extension + bytes.
+ return ByteBuffer.allocate(Integer.BYTES + bytes.length)
+ .order(ByteOrder.LITTLE_ENDIAN)
+ .putInt(bytes.length)
+ .put(bytes);
+ } catch (IOException ex) {
+ log.warn("Unable to read extension {} from pipeconf {}: {}",
+ extType, pipeconf.id(), ex.getMessage());
+ throw new ExtensionException();
+ }
+ }
+
+ private static class ExtensionException extends IllegalArgumentException {
+ }
+}
diff --git a/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/package-info.java b/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/package-info.java
new file mode 100644
index 0000000..649731e
--- /dev/null
+++ b/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Package for Barefoot device drivers.
+ */
+package org.onosproject.drivers.barefoot;
\ No newline at end of file
diff --git a/drivers/barefoot/src/main/resources/barefoot-drivers.xml b/drivers/barefoot/src/main/resources/barefoot-drivers.xml
new file mode 100644
index 0000000..ee56455
--- /dev/null
+++ b/drivers/barefoot/src/main/resources/barefoot-drivers.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2017-present Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<drivers>
+ <driver name="tofino" manufacturer="Barefoot Networks" hwVersion="1.0" swVersion="1.0" extends="p4runtime">
+ <behaviour api="org.onosproject.net.pi.model.PiPipelineProgrammable"
+ impl="org.onosproject.drivers.barefoot.TofinoPipelineProgrammable"/>
+ </driver>
+</drivers>
+
diff --git a/drivers/bmv2/BUCK b/drivers/bmv2/BUCK
index c8224f5..ed32104 100644
--- a/drivers/bmv2/BUCK
+++ b/drivers/bmv2/BUCK
@@ -5,7 +5,6 @@
'//lib:minimal-json',
'//protocols/p4runtime/api:onos-protocols-p4runtime-api',
'//incubator/bmv2/model:onos-incubator-bmv2-model',
- '//drivers/default:onos-drivers-default',
'//drivers/p4runtime:onos-drivers-p4runtime',
'//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
'//lib:grpc-netty-' + GRPC_VER,
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2PipelineProgrammable.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2PipelineProgrammable.java
index bf88238..bf7061f 100644
--- a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2PipelineProgrammable.java
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2PipelineProgrammable.java
@@ -16,72 +16,34 @@
package org.onosproject.drivers.bmv2;
-import org.onlab.util.SharedExecutors;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.apache.commons.io.IOUtils;
+import org.onosproject.drivers.p4runtime.AbstractP4RuntimePipelineProgrammable;
import org.onosproject.net.pi.model.PiPipeconf;
-import org.onosproject.net.pi.model.PiPipelineProgrammable;
-import org.onosproject.p4runtime.api.P4RuntimeClient;
-import org.onosproject.p4runtime.api.P4RuntimeController;
import org.onosproject.pipelines.basic.PipeconfLoader;
-import org.slf4j.Logger;
+import java.io.IOException;
+import java.nio.ByteBuffer;
import java.util.Optional;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON;
-import static org.slf4j.LoggerFactory.getLogger;
/**
- * Implementation of the PiPipelineProgrammable for BMv2.
+ * Implementation of the PiPipelineProgrammable behavior for BMv2.
*/
-public class Bmv2PipelineProgrammable extends AbstractHandlerBehaviour implements PiPipelineProgrammable {
-
- private final Logger log = getLogger(getClass());
+public class Bmv2PipelineProgrammable extends AbstractP4RuntimePipelineProgrammable {
@Override
- public CompletableFuture<Boolean> deployPipeconf(PiPipeconf pipeconf) {
-
- CompletableFuture<Boolean> result = new CompletableFuture<>();
-
- SharedExecutors.getPoolThreadExecutor().submit(() -> result.complete(doDeployConfig(pipeconf)));
-
- return result;
- }
-
- private boolean doDeployConfig(PiPipeconf pipeconf) {
-
- P4RuntimeController controller = handler().get(P4RuntimeController.class);
-
- DeviceId deviceId = handler().data().deviceId();
-
- if (!controller.hasClient(deviceId)) {
- log.warn("Unable to find client for {}, aborting pipeconf deploy", deviceId);
- return false;
-
+ public ByteBuffer createDeviceDataBuffer(PiPipeconf pipeconf) {
+ if (!pipeconf.extension(BMV2_JSON).isPresent()) {
+ log.warn("Missing extension {} in pipeconf {}", BMV2_JSON, pipeconf.id());
+ return null;
}
-
- P4RuntimeClient client = controller.getClient(deviceId);
-
try {
- if (!client.setPipelineConfig(pipeconf, BMV2_JSON).get()) {
- log.warn("Unable to deploy pipeconf {} to {}", pipeconf.id(), deviceId);
- return false;
- }
-
- // It would be more logical to have this performed at device handshake, but P4runtime would reject any
- // command if a P4info has not been set first.
- if (!client.initStreamChannel().get()) {
- log.warn("Unable to init stream channel to {}.", deviceId);
- return false;
- }
-
- } catch (InterruptedException | ExecutionException e) {
- throw new RuntimeException(e);
+ return ByteBuffer.wrap(IOUtils.toByteArray(pipeconf.extension(BMV2_JSON).get()));
+ } catch (IOException e) {
+ log.warn("Unable to read {} from pipeconf {}", BMV2_JSON, pipeconf.id());
+ return null;
}
-
- return true;
}
@Override
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/AbstractP4RuntimePipelineProgrammable.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/AbstractP4RuntimePipelineProgrammable.java
new file mode 100644
index 0000000..1272305
--- /dev/null
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/AbstractP4RuntimePipelineProgrammable.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.drivers.p4runtime;
+
+import org.onlab.util.SharedExecutors;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.pi.model.PiPipeconf;
+import org.onosproject.net.pi.model.PiPipelineProgrammable;
+import org.onosproject.p4runtime.api.P4RuntimeClient;
+import org.onosproject.p4runtime.api.P4RuntimeController;
+import org.slf4j.Logger;
+
+import java.nio.ByteBuffer;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Abstract implementation of the PiPipelineProgrammable behaviours for a P4Runtime device.
+ */
+public abstract class AbstractP4RuntimePipelineProgrammable extends AbstractHandlerBehaviour
+ implements PiPipelineProgrammable {
+
+ protected final Logger log = getLogger(getClass());
+
+ /**
+ * Returns a byte buffer representing the target-specific device data to be used in the SetPipelineConfig message.
+ *
+ * @param pipeconf pipeconf
+ * @return byte buffer
+ */
+ public abstract ByteBuffer createDeviceDataBuffer(PiPipeconf pipeconf);
+
+ @Override
+ public CompletableFuture<Boolean> deployPipeconf(PiPipeconf pipeconf) {
+ return CompletableFuture.supplyAsync(
+ () -> doDeployConfig(pipeconf),
+ SharedExecutors.getPoolThreadExecutor());
+ }
+
+ private boolean doDeployConfig(PiPipeconf pipeconf) {
+
+ DeviceId deviceId = handler().data().deviceId();
+ P4RuntimeController controller = handler().get(P4RuntimeController.class);
+
+ if (!controller.hasClient(deviceId)) {
+ log.warn("Unable to find client for {}, aborting pipeconf deploy", deviceId);
+ return false;
+ }
+ P4RuntimeClient client = controller.getClient(deviceId);
+
+ ByteBuffer deviceDataBuffer = createDeviceDataBuffer(pipeconf);
+ if (deviceDataBuffer == null) {
+ // Hopefully the child class logged the problem.
+ return false;
+ }
+
+ try {
+ if (!client.setPipelineConfig(pipeconf, deviceDataBuffer).get()) {
+ log.warn("Unable to deploy pipeconf {} to {}", pipeconf.id(), deviceId);
+ return false;
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ log.error("Exception while deploying pipeconf to {}", deviceId, e);
+ return false;
+ }
+
+ try {
+ // It would make more sense to init the stream channel once the client
+ // is created, but P4runtime would reject any command if a P4info has
+ // not been set first.
+ if (!client.initStreamChannel().get()) {
+ log.warn("Unable to init stream channel to {}.", deviceId);
+ return false;
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ log.error("Exception while initializing stream channel on {}", deviceId, e);
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public abstract Optional<PiPipeconf> getDefaultPipeconf();
+}
diff --git a/modules.defs b/modules.defs
index b6c61e9..63afd14 100644
--- a/modules.defs
+++ b/modules.defs
@@ -105,6 +105,7 @@
'//drivers/microsemi:onos-drivers-microsemi-oar',
'//drivers/oplink:onos-drivers-oplink-oar',
'//drivers/bmv2:onos-drivers-bmv2-oar',
+ '//drivers/barefoot:onos-drivers-barefoot-oar',
'//drivers/hp:onos-drivers-hp-oar',
'//drivers/p4runtime:onos-drivers-p4runtime-oar',
'//drivers/polatis/netconf:onos-drivers-polatis-netconf-oar',
diff --git a/protocols/p4runtime/api/src/main/java/org/onosproject/p4runtime/api/P4RuntimeClient.java b/protocols/p4runtime/api/src/main/java/org/onosproject/p4runtime/api/P4RuntimeClient.java
index b2743ac..7c75c91 100644
--- a/protocols/p4runtime/api/src/main/java/org/onosproject/p4runtime/api/P4RuntimeClient.java
+++ b/protocols/p4runtime/api/src/main/java/org/onosproject/p4runtime/api/P4RuntimeClient.java
@@ -27,6 +27,7 @@
import org.onosproject.net.pi.runtime.PiTableEntry;
import org.onosproject.net.pi.runtime.PiTableId;
+import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
@@ -48,15 +49,15 @@
}
/**
- * Sets the pipeline configuration defined by the given pipeconf for the given target-specific configuration
- * extension type (e.g. {@link PiPipeconf.ExtensionType#BMV2_JSON}, or {@link PiPipeconf.ExtensionType#TOFINO_BIN}).
- * This method should be called before any other method of this client.
+ * Sets the device pipeline according to the given pipeconf, and for the given byte buffer representing the
+ * target-specific data to be used in the P4Runtime's SetPipelineConfig message. This method should be called
+ * before any other method of this client.
*
- * @param pipeconf pipeconf
- * @param targetConfigExtType extension type of the target-specific configuration
+ * @param pipeconf pipeconf
+ * @param deviceData target-specific data
* @return a completable future of a boolean, true if the operations was successful, false otherwise.
*/
- CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, PiPipeconf.ExtensionType targetConfigExtType);
+ CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, ByteBuffer deviceData);
/**
* Initializes the stream channel, after which all messages received from the device will be notified using the
@@ -109,8 +110,8 @@
* Returns a collection of counter data corresponding to the given set of counter cell identifiers, for the given
* pipeconf.
*
- * @param cellIds set of counter cell identifiers
- * @param pipeconf pipeconf
+ * @param cellIds set of counter cell identifiers
+ * @param pipeconf pipeconf
* @return collection of counter data
*/
CompletableFuture<Collection<PiCounterCellData>> readCounterCells(Set<PiCounterCellId> cellIds,
@@ -119,8 +120,8 @@
/**
* Performs the given write operation for the given action group members and pipeconf.
*
- * @param group action group
- * @param opType write operation type
+ * @param group action group
+ * @param opType write operation type
* @param pipeconf the pipeconf currently deployed on the device
* @return true if the operation was successful, false otherwise
*/
@@ -131,8 +132,8 @@
/**
* Performs the given write operation for the given action group and pipeconf.
*
- * @param group the action group
- * @param opType write operation type
+ * @param group the action group
+ * @param opType write operation type
* @param pipeconf the pipeconf currently deployed on the device
* @return true if the operation was successful, false otherwise
*/
@@ -144,7 +145,7 @@
* Dumps all groups currently installed for the given action profile.
*
* @param actionProfileId the action profile id
- * @param pipeconf the pipeconf currently deployed on the device
+ * @param pipeconf the pipeconf currently deployed on the device
* @return completable future of a collection of groups
*/
CompletableFuture<Collection<PiActionGroup>> dumpGroups(PiActionProfileId actionProfileId,
diff --git a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java
index 3dd5fcd..21bd31b 100644
--- a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java
@@ -65,8 +65,7 @@
import p4.config.P4InfoOuterClass.P4Info;
import p4.tmp.P4Config;
-import java.io.IOException;
-import java.io.InputStream;
+import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -85,10 +84,12 @@
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
+import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.groupedThreads;
-import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType;
import static org.slf4j.LoggerFactory.getLogger;
-import static p4.P4RuntimeOuterClass.Entity.EntityCase.*;
+import static p4.P4RuntimeOuterClass.Entity.EntityCase.ACTION_PROFILE_GROUP;
+import static p4.P4RuntimeOuterClass.Entity.EntityCase.ACTION_PROFILE_MEMBER;
+import static p4.P4RuntimeOuterClass.Entity.EntityCase.TABLE_ENTRY;
import static p4.P4RuntimeOuterClass.PacketOut;
import static p4.P4RuntimeOuterClass.SetForwardingPipelineConfigRequest.Action.VERIFY_AND_COMMIT;
@@ -172,8 +173,8 @@
}
@Override
- public CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, ExtensionType targetConfigExtType) {
- return supplyInContext(() -> doSetPipelineConfig(pipeconf, targetConfigExtType), "setPipelineConfig");
+ public CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, ByteBuffer deviceData) {
+ return supplyInContext(() -> doSetPipelineConfig(pipeconf, deviceData), "setPipelineConfig");
}
@Override
@@ -286,9 +287,11 @@
}
}
- private boolean doSetPipelineConfig(PiPipeconf pipeconf, ExtensionType targetConfigExtType) {
+ private boolean doSetPipelineConfig(PiPipeconf pipeconf, ByteBuffer deviceData) {
- log.info("Setting pipeline config for {} to {} using {}...", deviceId, pipeconf.id(), targetConfigExtType);
+ log.info("Setting pipeline config for {} to {}...", deviceId, pipeconf.id());
+
+ checkNotNull(deviceData, "deviceData cannot be null");
P4Info p4Info = PipeconfHelper.getP4Info(pipeconf);
if (p4Info == null) {
@@ -296,51 +299,33 @@
return false;
}
+ P4Config.P4DeviceConfig p4DeviceConfigMsg = P4Config.P4DeviceConfig
+ .newBuilder()
+ .setExtras(P4Config.P4DeviceConfig.Extras.getDefaultInstance())
+ .setReassign(true)
+ .setDeviceData(ByteString.copyFrom(deviceData))
+ .build();
- ForwardingPipelineConfig.Builder pipelineConfigBuilder = ForwardingPipelineConfig
+ ForwardingPipelineConfig pipelineConfig = ForwardingPipelineConfig
.newBuilder()
.setDeviceId(p4DeviceId)
- .setP4Info(p4Info);
-
- //if the target config extension is null we don't want to add the config.
- if (targetConfigExtType != null) {
- if (!pipeconf.extension(targetConfigExtType).isPresent()) {
- log.warn("Missing extension {} in pipeconf {}", targetConfigExtType, pipeconf.id());
- return false;
- }
- InputStream targetConfig = pipeconf.extension(targetConfigExtType).get();
- P4Config.P4DeviceConfig p4DeviceConfigMsg;
- try {
- p4DeviceConfigMsg = P4Config.P4DeviceConfig
- .newBuilder()
- .setExtras(P4Config.P4DeviceConfig.Extras.getDefaultInstance())
- .setReassign(true)
- .setDeviceData(ByteString.readFrom(targetConfig))
- .build();
-
- pipelineConfigBuilder.setP4DeviceConfig(p4DeviceConfigMsg.toByteString());
-
- } catch (IOException ex) {
- log.warn("Unable to load target-specific config for {}: {}", deviceId, ex.getMessage());
- return false;
- }
- }
+ .setP4Info(p4Info)
+ .setP4DeviceConfig(p4DeviceConfigMsg.toByteString())
+ .build();
SetForwardingPipelineConfigRequest request = SetForwardingPipelineConfigRequest
.newBuilder()
.setAction(VERIFY_AND_COMMIT)
- .addConfigs(pipelineConfigBuilder.build())
+ .addConfigs(pipelineConfig)
.build();
try {
this.blockingStub.setForwardingPipelineConfig(request);
-
+ return true;
} catch (StatusRuntimeException ex) {
log.warn("Unable to set pipeline config for {}: {}", deviceId, ex.getMessage());
return false;
}
-
- return true;
}
private boolean doWriteTableEntries(Collection<PiTableEntry> piTableEntries, WriteOperationType opType,