[ONOS-6935] ActionProfile supports in P4RuntimeClient
Change-Id: I9f0ac307985c03b7ed93e14e41ba468c481a4e4f
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroup.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroup.java
index f023e05..1de4d61 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroup.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroup.java
@@ -47,11 +47,15 @@
private final PiActionGroupId id;
private final Type type;
private final ImmutableSet<PiActionGroupMember> members;
+ private final PiActionProfileId piActionProfileId;
- private PiActionGroup(PiActionGroupId id, Type type, ImmutableSet<PiActionGroupMember> members) {
+ private PiActionGroup(PiActionGroupId id, Type type,
+ ImmutableSet<PiActionGroupMember> members,
+ PiActionProfileId piActionProfileId) {
this.id = id;
this.type = type;
this.members = members;
+ this.piActionProfileId = piActionProfileId;
}
/**
@@ -81,18 +85,28 @@
return members;
}
+ /**
+ * Gets identifier of the action profile.
+ *
+ * @return action profile id
+ */
+ public PiActionProfileId actionProfileId() {
+ return piActionProfileId;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
- if (o == null || getClass() != o.getClass()) {
+ if (o == null || !(o instanceof PiActionGroup)) {
return false;
}
PiActionGroup that = (PiActionGroup) o;
- return id == that.id &&
+ return Objects.equal(id, that.id) &&
Objects.equal(type, that.type) &&
- Objects.equal(members, that.members);
+ Objects.equal(members, that.members) &&
+ Objects.equal(piActionProfileId, that.piActionProfileId);
}
@Override
@@ -106,6 +120,7 @@
.add("groupId", id)
.add("type", type)
.add("members", members)
+ .add("piActionProfileId", piActionProfileId)
.toString();
}
@@ -126,6 +141,7 @@
private PiActionGroupId id;
private Type type;
private Map<PiActionGroupMemberId, PiActionGroupMember> members = Maps.newHashMap();
+ private PiActionProfileId piActionProfileId;
private Builder() {
// hides constructor.
@@ -176,6 +192,17 @@
}
/**
+ * Sets the identifier of the action profile.
+ *
+ * @param piActionProfileId the identifier of the action profile
+ * @return this
+ */
+ public Builder withActionProfileId(PiActionProfileId piActionProfileId) {
+ this.piActionProfileId = piActionProfileId;
+ return this;
+ }
+
+ /**
* Creates a new action group.
*
* @return action group
@@ -183,8 +210,11 @@
public PiActionGroup build() {
checkNotNull(id);
checkNotNull(type);
- checkArgument(members.size() > 0, "Members cannot be empty");
- return new PiActionGroup(id, type, ImmutableSet.copyOf(members.values()));
+ checkArgument(!members.isEmpty(), "Members cannot be empty");
+ checkNotNull(piActionProfileId);
+ return new PiActionGroup(id, type,
+ ImmutableSet.copyOf(members.values()),
+ piActionProfileId);
}
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionProfileId.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionProfileId.java
new file mode 100644
index 0000000..e0158c9
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionProfileId.java
@@ -0,0 +1,41 @@
+/*
+ * 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.onlab.util.Identifier;
+
+/**
+ * Identifier of an action profile of a protocol-independent pipeline.
+ */
+@Beta
+public final class PiActionProfileId extends Identifier<String> {
+
+ private PiActionProfileId(String actionProfileName) {
+ super(actionProfileName);
+ }
+
+ /**
+ * Returns action profile id with given action profile name.
+ *
+ * @param actionProfileName action profile name
+ * @return action profile id
+ */
+ public static PiActionProfileId of(String actionProfileName) {
+ return new PiActionProfileId(actionProfileName);
+ }
+}
diff --git a/core/api/src/test/java/org/onosproject/net/pi/runtime/PiActionGroupTest.java b/core/api/src/test/java/org/onosproject/net/pi/runtime/PiActionGroupTest.java
index e9b736b..0da15e4 100644
--- a/core/api/src/test/java/org/onosproject/net/pi/runtime/PiActionGroupTest.java
+++ b/core/api/src/test/java/org/onosproject/net/pi/runtime/PiActionGroupTest.java
@@ -28,6 +28,7 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
import static org.onlab.util.ImmutableByteSequence.copyFrom;
+import static org.onosproject.net.pi.runtime.PiConstantsTest.ACTION_PROF_ID;
import static org.onosproject.net.pi.runtime.PiConstantsTest.DST_ADDR;
import static org.onosproject.net.pi.runtime.PiConstantsTest.MOD_NW_DST;
@@ -51,12 +52,14 @@
.addMember(piActionGroupMember)
.withId(piActionGroupId)
.withType(PiActionGroup.Type.SELECT)
+ .withActionProfileId(ACTION_PROF_ID)
.build();
PiActionGroup sameAsPiActionGroup1 = PiActionGroup.builder()
.addMember(piActionGroupMember)
.withId(piActionGroupId)
.withType(PiActionGroup.Type.SELECT)
+ .withActionProfileId(ACTION_PROF_ID)
.build();
PiActionGroupId piActionGroupId2 = PiActionGroupId.of(20);
@@ -64,6 +67,7 @@
.addMember(piActionGroupMember)
.withId(piActionGroupId2)
.withType(PiActionGroup.Type.SELECT)
+ .withActionProfileId(ACTION_PROF_ID)
.build();
/**
diff --git a/core/api/src/test/java/org/onosproject/net/pi/runtime/PiConstantsTest.java b/core/api/src/test/java/org/onosproject/net/pi/runtime/PiConstantsTest.java
index b2bda37..86f713d 100644
--- a/core/api/src/test/java/org/onosproject/net/pi/runtime/PiConstantsTest.java
+++ b/core/api/src/test/java/org/onosproject/net/pi/runtime/PiConstantsTest.java
@@ -38,4 +38,7 @@
public static final String EGRESS_PORT = "egress_port";
public static final String INGRESS_PORT = "ingress_port";
+
+ public static final PiActionProfileId ACTION_PROF_ID =
+ PiActionProfileId.of("Test action profile");
}
diff --git a/core/net/src/main/java/org/onosproject/net/pi/impl/PiFlowRuleTranslator.java b/core/net/src/main/java/org/onosproject/net/pi/impl/PiFlowRuleTranslator.java
index dc6d1c5..fbfd9b7 100644
--- a/core/net/src/main/java/org/onosproject/net/pi/impl/PiFlowRuleTranslator.java
+++ b/core/net/src/main/java/org/onosproject/net/pi/impl/PiFlowRuleTranslator.java
@@ -131,8 +131,8 @@
Collection<PiFieldMatch> fieldMatches = buildFieldMatches(interpreter, rule.selector(), table);
/* Translate treatment */
- PiAction piAction = buildAction(rule.treatment(), interpreter, piTableId);
- piAction = typeCheckAction(piAction, table);
+ PiTableAction piTableAction = buildAction(rule.treatment(), interpreter, piTableId);
+ piTableAction = typeCheckAction(piTableAction, table);
PiTableEntry.Builder tableEntryBuilder = PiTableEntry.builder();
@@ -154,7 +154,7 @@
.withMatchKey(PiMatchKey.builder()
.addFieldMatches(fieldMatches)
.build())
- .withAction(piAction);
+ .withAction(piTableAction);
if (!rule.isPermanent()) {
if (table.supportsAging()) {
@@ -172,7 +172,7 @@
/**
* Builds a PI action out of the given treatment, optionally using the given interpreter.
*/
- private static PiAction buildAction(TrafficTreatment treatment, PiPipelineInterpreter interpreter,
+ private static PiTableAction buildAction(TrafficTreatment treatment, PiPipelineInterpreter interpreter,
PiTableId tableId)
throws PiFlowRuleTranslationException {
@@ -208,22 +208,28 @@
+ "protocol-independent instruction were provided.");
}
- if (piTableAction.type() != PiTableAction.Type.ACTION) {
- // TODO: implement handling of other table action types, e.g. action profiles.
- throw new PiFlowRuleTranslationException(format(
- "PiTableAction type %s is not supported yet.", piTableAction.type()));
- }
-
- return (PiAction) piTableAction;
+ return piTableAction;
}
/**
- * Checks that the given PI action is suitable for the given table model and returns a new action instance with
- * parameters well-sized, according to the table model. If not suitable, throws an exception explaining why.
+ * Checks that the given PI table action is suitable for the given table
+ * model and returns a new action instance with parameters well-sized,
+ * according to the table model. If not suitable, throws an exception explaining why.
*/
- private static PiAction typeCheckAction(PiAction piAction, PiTableModel table)
+ private static PiTableAction typeCheckAction(PiTableAction piTableAction, PiTableModel table)
throws PiFlowRuleTranslationException {
+ switch (piTableAction.type()) {
+ case ACTION:
+ return checkPiAction((PiAction) piTableAction, table);
+ default:
+ // FIXME: should we check? how?
+ return piTableAction;
+ }
+ }
+
+ private static PiTableAction checkPiAction(PiAction piAction, PiTableModel table)
+ throws PiFlowRuleTranslationException {
// Table supports this action?
PiActionModel actionModel = table.action(piAction.id().name()).orElseThrow(
() -> new PiFlowRuleTranslationException(format("Not such action '%s' for table '%s'",
diff --git a/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java b/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
index 6413037..cc227ba 100644
--- a/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
+++ b/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
@@ -212,6 +212,7 @@
import org.onosproject.net.pi.runtime.PiActionParamId;
import org.onosproject.net.pi.runtime.PiExactFieldMatch;
import org.onosproject.net.pi.runtime.PiFieldMatch;
+import org.onosproject.net.pi.runtime.PiActionProfileId;
import org.onosproject.net.pi.runtime.PiHeaderFieldId;
import org.onosproject.net.pi.runtime.PiLpmFieldMatch;
import org.onosproject.net.pi.runtime.PiMatchKey;
@@ -388,7 +389,6 @@
DefaultFlowRule.class,
TableId.class,
IndexTableId.class,
- PiTableId.class,
FlowRule.FlowRemoveReason.class,
DefaultPacketRequest.class,
PacketPriority.class,
@@ -620,6 +620,7 @@
PiTableId.class,
PiTernaryFieldMatch.class,
PiValidFieldMatch.class,
+ PiActionProfileId.class,
// Other
PiCriterion.class,
PiInstruction.class