Removed pipeconf dependency from PiPipelineInterpreter
If needed, an interpreter implementation should know which pipeconf it
supports. Instead, mapping of treatments now depends on a table ID,
since table in P4 can potentially support different actions with similar
semantics.
Change-Id: Iffbc84457f08e5dba84a8e949931849006f82535
diff --git a/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineInterpreter.java b/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineInterpreter.java
index 25962ca..394b787 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineInterpreter.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineInterpreter.java
@@ -18,13 +18,12 @@
import com.google.common.annotations.Beta;
import org.onosproject.net.driver.HandlerBehaviour;
-import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.packet.OutboundPacket;
+import org.onosproject.net.pi.runtime.PiAction;
import org.onosproject.net.pi.runtime.PiHeaderFieldId;
import org.onosproject.net.pi.runtime.PiPacketOperation;
-import org.onosproject.net.pi.runtime.PiTableAction;
import org.onosproject.net.pi.runtime.PiTableId;
import java.util.Collection;
@@ -37,9 +36,8 @@
public interface PiPipelineInterpreter extends HandlerBehaviour {
/**
- * Returns the protocol-independent header field identifier that is equivalent to the given
- * criterion type, if present. If not present, it means that the given criterion type is not
- * supported by this interpreter.
+ * Returns the protocol-independent header field identifier that is equivalent to the given criterion type, if
+ * present. If not present, it means that the given criterion type is not supported by this interpreter.
*
* @param type criterion type
* @return optional header field identifier
@@ -47,9 +45,8 @@
Optional<PiHeaderFieldId> mapCriterionType(Criterion.Type type);
/**
- * Returns the criterion type that is equivalent to the given protocol-independent header field
- * identifier, if present. If not present, it means that the given field identifier is not
- * supported by this interpreter.
+ * Returns the criterion type that is equivalent to the given protocol-independent header field identifier, if
+ * present. If not present, it means that the given field identifier is not supported by this interpreter.
*
* @param headerFieldId header field identifier
* @return optional criterion type
@@ -57,9 +54,9 @@
Optional<Criterion.Type> mapPiHeaderFieldId(PiHeaderFieldId headerFieldId);
/**
- * Returns a protocol-independent table id equivalent to the given numeric table id (as in
- * {@link FlowRule#tableId()}). If not present, it means that the given numeric table id cannot
- * be mapped to any table of the pipeline model.
+ * Returns a protocol-independent table id equivalent to the given numeric table id (as in {@link
+ * org.onosproject.net.flow.FlowRule#tableId()}). If not present, it means that the given numeric table id cannot be
+ * mapped to any table of the pipeline model.
*
* @param flowRuleTableId a numeric table id
* @return a protocol-independent table id
@@ -67,27 +64,25 @@
Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId);
/**
- * Returns a table action of a protocol-independent pipeline that is functionally equivalent to
- * the given ONOS traffic treatment for the given pipeline configuration.
+ * Returns an action of a protocol-independent pipeline that is functionally equivalent to the given ONOS traffic
+ * treatment for the given table.
*
* @param treatment a ONOS traffic treatment
- * @param pipeconf a pipeline configuration
- * @return a table action object
+ * @param piTableId PI table identifier
+ * @return an action object
* @throws PiInterpreterException if the treatment cannot be mapped to any table action
*/
- PiTableAction mapTreatment(TrafficTreatment treatment, PiPipeconf pipeconf)
+ PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId)
throws PiInterpreterException;
/**
- * Returns a collection of packet operations equivalent to the given OutboundPacket, for the given
- * pipeline configuration.
+ * Returns a collection of packet operations equivalent to the given OutboundPacket.
*
- * @param packet a ONOS outbound packet
- * @param pipeconf a pipeline configuration
+ * @param packet a ONOS outbound packet
* @return a collection of packet operations
* @throws PiInterpreterException if the packet treatments cannot be mapped to any metadata
*/
- Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet, PiPipeconf pipeconf)
+ Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
throws PiInterpreterException;
/**
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 14f15a5..8b28b5e 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
@@ -123,7 +123,7 @@
Collection<PiFieldMatch> fieldMatches = buildFieldMatches(interpreter, rule.selector(), table);
/* Translate treatment */
- PiAction piAction = buildAction(rule.treatment(), interpreter, pipeconf);
+ PiAction piAction = buildAction(rule.treatment(), interpreter, piTableId);
piAction = typeCheckAction(piAction, table);
PiTableEntry.Builder tableEntryBuilder = PiTableEntry.builder();
@@ -155,7 +155,7 @@
* Builds a PI action out of the given treatment, optionally using the given interpreter.
*/
private static PiAction buildAction(TrafficTreatment treatment, PiPipelineInterpreter interpreter,
- PiPipeconf pipeconf)
+ PiTableId tableId)
throws PiFlowRuleTranslationException {
PiTableAction piTableAction = null;
@@ -176,7 +176,7 @@
if (piTableAction == null && interpreter != null) {
// No PiInstruction, use interpreter to build action.
try {
- piTableAction = interpreter.mapTreatment(treatment, pipeconf);
+ piTableAction = interpreter.mapTreatment(treatment, tableId);
} catch (PiPipelineInterpreter.PiInterpreterException e) {
throw new PiFlowRuleTranslationException(
"Interpreter was unable to translate treatment. " + e.getMessage());
diff --git a/core/net/src/test/java/org/onosproject/net/pi/impl/MockInterpreter.java b/core/net/src/test/java/org/onosproject/net/pi/impl/MockInterpreter.java
index 14e698d..04535aa 100644
--- a/core/net/src/test/java/org/onosproject/net/pi/impl/MockInterpreter.java
+++ b/core/net/src/test/java/org/onosproject/net/pi/impl/MockInterpreter.java
@@ -25,7 +25,6 @@
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.packet.OutboundPacket;
-import org.onosproject.net.pi.model.PiPipeconf;
import org.onosproject.net.pi.model.PiPipelineInterpreter;
import org.onosproject.net.pi.runtime.PiAction;
import org.onosproject.net.pi.runtime.PiActionId;
@@ -33,7 +32,6 @@
import org.onosproject.net.pi.runtime.PiActionParamId;
import org.onosproject.net.pi.runtime.PiHeaderFieldId;
import org.onosproject.net.pi.runtime.PiPacketOperation;
-import org.onosproject.net.pi.runtime.PiTableAction;
import org.onosproject.net.pi.runtime.PiTableId;
import java.util.Collection;
@@ -68,7 +66,7 @@
0, PiTableId.of(TABLE0));
@Override
- public PiTableAction mapTreatment(TrafficTreatment treatment, PiPipeconf pipeconf) throws PiInterpreterException {
+ public PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId) throws PiInterpreterException {
if (treatment.allInstructions().size() == 0) {
// No instructions means drop for us.
@@ -103,7 +101,7 @@
}
@Override
- public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet, PiPipeconf pipeconf)
+ public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
throws PiInterpreterException {
return ImmutableList.of();
}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DefaultInterpreter.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DefaultInterpreter.java
index a2e7812..6b057cc 100644
--- a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DefaultInterpreter.java
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DefaultInterpreter.java
@@ -28,7 +28,6 @@
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.packet.OutboundPacket;
-import org.onosproject.net.pi.model.PiPipeconf;
import org.onosproject.net.pi.model.PiPipelineInterpreter;
import org.onosproject.net.pi.runtime.PiAction;
import org.onosproject.net.pi.runtime.PiActionId;
@@ -38,7 +37,6 @@
import org.onosproject.net.pi.runtime.PiPacketMetadata;
import org.onosproject.net.pi.runtime.PiPacketMetadataId;
import org.onosproject.net.pi.runtime.PiPacketOperation;
-import org.onosproject.net.pi.runtime.PiTableAction;
import org.onosproject.net.pi.runtime.PiTableId;
import java.nio.ByteBuffer;
@@ -82,7 +80,7 @@
@Override
- public PiTableAction mapTreatment(TrafficTreatment treatment, PiPipeconf pipeconf) throws PiInterpreterException {
+ public PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId) throws PiInterpreterException {
if (treatment.allInstructions().size() == 0) {
// No instructions means drop for us.
@@ -117,7 +115,7 @@
}
@Override
- public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet, PiPipeconf pipeconf)
+ public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
throws PiInterpreterException {
TrafficTreatment treatment = packet.treatment();
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2PacketProgrammable.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2PacketProgrammable.java
index cbf032b..49f0f4b 100644
--- a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2PacketProgrammable.java
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2PacketProgrammable.java
@@ -71,7 +71,7 @@
}
try {
- Collection<PiPacketOperation> operations = interpreter.mapOutboundPacket(packet, pipeconf);
+ Collection<PiPacketOperation> operations = interpreter.mapOutboundPacket(packet);
operations.forEach(piPacketOperation -> {
client.packetOut(piPacketOperation, pipeconf);
});