Various improvements to PI group handling
- Moved group translation logic to core service
- Removed dependency on KRYO
- Fixed bug where tratments with PI instructions where not supported if
an interpreter was present
- Fixed bug where action profile name was not found during protobuf
encoding (always perform P4Info lookup by name and alias)
- Improved reading of members by issuing one big request for all
groups
Change-Id: Ifcf8380b09293e70be15cf4999bd2845caf5d01e
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiFlowRuleTranslationService.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiFlowRuleTranslationService.java
deleted file mode 100644
index 4948ebb..0000000
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiFlowRuleTranslationService.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.net.pi.runtime;
-
-import com.google.common.annotations.Beta;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.pi.model.PiPipeconf;
-
-/**
- * A service to translate ONOS flow rules to table entries of a protocol-independent pipeline.
- */
-@Beta
-public interface PiFlowRuleTranslationService {
-
- /**
- * Returns a table entry equivalent to the given flow rule for the given protocol-independent
- * pipeline configuration.
- *
- * @param rule a flow rule
- * @param pipeconf a pipeline configuration
- * @return a table entry
- * @throws PiFlowRuleTranslationException if the flow rule cannot be translated
- */
- PiTableEntry translate(FlowRule rule, PiPipeconf pipeconf)
- throws PiFlowRuleTranslationException;
-
- /**
- * Signals that an error was encountered while translating flow rule.
- */
- class PiFlowRuleTranslationException extends Exception {
-
- /**
- * Creates a new exception with the given message.
- *
- * @param message a message
- */
- public PiFlowRuleTranslationException(String message) {
- super(message);
- }
- }
-}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiGroupKey.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiGroupKey.java
new file mode 100644
index 0000000..598f3e7
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiGroupKey.java
@@ -0,0 +1,101 @@
+/*
+ * 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.net.pi.runtime;
+
+import com.google.common.base.Objects;
+import org.onosproject.net.group.GroupKey;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Implementation of GroupKey for the case of a protocol-independent pipeline.
+ */
+public final class PiGroupKey implements GroupKey {
+
+ private final PiTableId tableId;
+ private final PiActionProfileId piActionProfileId;
+ private final int groupId;
+
+ /**
+ * Returns a new group key for the given table ID, action profile ID, and group ID.
+ *
+ * @param tableId table ID
+ * @param piActionProfileId action profile ID
+ * @param groupId group ID
+ */
+ public PiGroupKey(PiTableId tableId, PiActionProfileId piActionProfileId, int groupId) {
+ this.tableId = checkNotNull(tableId);
+ this.piActionProfileId = checkNotNull(piActionProfileId);
+ this.groupId = groupId;
+ }
+
+ /**
+ * Returns the table ID defined by this key.
+ *
+ * @return table ID
+ */
+ public PiTableId tableId() {
+ return tableId;
+ }
+
+ /**
+ * Returns the group ID defined by this key.
+ *
+ * @return group ID
+ */
+ public int groupId() {
+ return groupId;
+ }
+
+ /**
+ * Returns the action profile ID defined by this key.
+ *
+ * @return action profile ID
+ */
+ public PiActionProfileId actionProfileId() {
+ return piActionProfileId;
+ }
+
+ @Override
+ public byte[] key() {
+ return toString().getBytes();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof PiGroupKey)) {
+ return false;
+ }
+ PiGroupKey that = (PiGroupKey) o;
+ return groupId == that.groupId &&
+ Objects.equal(tableId, that.tableId) &&
+ Objects.equal(piActionProfileId, that.piActionProfileId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(tableId, piActionProfileId, groupId);
+ }
+
+ @Override
+ public String toString() {
+ return tableId.id() + "-" + piActionProfileId.id() + "-" + String.valueOf(groupId);
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTranslationService.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTranslationService.java
new file mode 100644
index 0000000..a0c1101
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTranslationService.java
@@ -0,0 +1,68 @@
+/*
+ * 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.net.pi.runtime;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.group.Group;
+import org.onosproject.net.pi.model.PiPipeconf;
+
+/**
+ * A service to translate ONOS entities to protocol-independent ones.
+ */
+@Beta
+public interface PiTranslationService {
+
+ /**
+ * Returns a PI table entry equivalent to the given flow rule for the given protocol-independent pipeline
+ * configuration.
+ *
+ * @param rule a flow rule
+ * @param pipeconf a pipeline configuration
+ * @return a table entry
+ * @throws PiTranslationException if the flow rule cannot be translated
+ */
+ PiTableEntry translateFlowRule(FlowRule rule, PiPipeconf pipeconf)
+ throws PiTranslationException;
+
+ /**
+ * Returns a PI action group equivalent to the given group for the given protocol-independent pipeline
+ * configuration.
+ *
+ * @param group a group
+ * @param pipeconf a pipeline configuration
+ * @return a PI action group
+ * @throws PiTranslationException if the group cannot be translated
+ */
+ PiActionGroup translateGroup(Group group, PiPipeconf pipeconf)
+ throws PiTranslationException;
+
+ /**
+ * Signals that an error was encountered while translating an entity.
+ */
+ class PiTranslationException extends Exception {
+
+ /**
+ * Creates a new exception with the given message.
+ *
+ * @param message a message
+ */
+ public PiTranslationException(String message) {
+ super(message);
+ }
+ }
+}