ONOS-7058 Refactored default pipeconfs in new pipelines directory
- Minimal refactoring of P4 programs
- Removed symlinks to BMv2 JSON/P4Info
- Bumped p4c commit (which fixes known parser bug)
- Renamed "default" pipeconf to "basic" (ONOS-6818)
Change-Id: I319f8b142ab22dba9b15457e28cd62d17f78a423
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
deleted file mode 100644
index a9178ca..0000000
--- a/core/net/src/test/java/org/onosproject/net/pi/impl/MockInterpreter.java
+++ /dev/null
@@ -1,150 +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.impl;
-
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableList;
-import org.onlab.util.ImmutableByteSequence;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.driver.AbstractHandlerBehaviour;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.flow.criteria.Criterion;
-import org.onosproject.net.flow.instructions.Instruction;
-import org.onosproject.net.packet.InboundPacket;
-import org.onosproject.net.packet.OutboundPacket;
-import org.onosproject.net.pi.model.PiPipelineInterpreter;
-import org.onosproject.net.pi.runtime.PiAction;
-import org.onosproject.net.pi.runtime.PiActionId;
-import org.onosproject.net.pi.runtime.PiActionParam;
-import org.onosproject.net.pi.runtime.PiActionParamId;
-import org.onosproject.net.pi.runtime.PiCounterId;
-import org.onosproject.net.pi.runtime.PiHeaderFieldId;
-import org.onosproject.net.pi.runtime.PiPacketOperation;
-import org.onosproject.net.pi.runtime.PiTableId;
-
-import java.util.Collection;
-import java.util.Optional;
-
-import static org.onosproject.net.PortNumber.CONTROLLER;
-import static org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
-
-/**
- * Mock interpreter implementation.
- */
-public class MockInterpreter extends AbstractHandlerBehaviour implements PiPipelineInterpreter {
-
- static final String TABLE0 = "table0";
- static final String SEND_TO_CPU = "send_to_cpu";
- static final String PORT = "port";
- static final String DROP = "_drop";
- static final String SET_EGRESS_PORT = "set_egress_port";
-
- static final PiHeaderFieldId IN_PORT_ID = PiHeaderFieldId.of("standard_metadata", "ingress_port");
- static final PiHeaderFieldId ETH_DST_ID = PiHeaderFieldId.of("ethernet", "dstAddr");
- static final PiHeaderFieldId ETH_SRC_ID = PiHeaderFieldId.of("ethernet", "srcAddr");
- static final PiHeaderFieldId ETH_TYPE_ID = PiHeaderFieldId.of("ethernet", "etherType");
-
- private static final ImmutableBiMap<Criterion.Type, PiHeaderFieldId> CRITERION_MAP = ImmutableBiMap.of(
- Criterion.Type.IN_PORT, IN_PORT_ID,
- Criterion.Type.ETH_DST, ETH_DST_ID,
- Criterion.Type.ETH_SRC, ETH_SRC_ID,
- Criterion.Type.ETH_TYPE, ETH_TYPE_ID);
-
- private static final ImmutableBiMap<Integer, PiTableId> TABLE_MAP = ImmutableBiMap.of(
- 0, PiTableId.of(TABLE0));
-
- @Override
- public PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId) throws PiInterpreterException {
-
- if (treatment.allInstructions().size() == 0) {
- // No instructions means drop for us.
- return actionWithName(DROP);
- } else if (treatment.allInstructions().size() > 1) {
- // Otherwise, we understand treatments with only 1 instruction.
- throw new PiPipelineInterpreter.PiInterpreterException("Treatment has multiple instructions");
- }
-
- Instruction instruction = treatment.allInstructions().get(0);
-
- switch (instruction.type()) {
- case OUTPUT:
- OutputInstruction outInstruction = (OutputInstruction) instruction;
- PortNumber port = outInstruction.port();
- if (!port.isLogical()) {
- PiAction.builder()
- .withId(PiActionId.of(SET_EGRESS_PORT))
- .withParameter(new PiActionParam(PiActionParamId.of(PORT),
- ImmutableByteSequence.copyFrom(port.toLong())))
- .build();
- } else if (port.equals(CONTROLLER)) {
- return actionWithName(SEND_TO_CPU);
- } else {
- throw new PiInterpreterException("Egress on logical port not supported: " + port);
- }
- case NOACTION:
- return actionWithName(DROP);
- default:
- throw new PiInterpreterException("Instruction type not supported: " + instruction.type().name());
- }
- }
-
- @Override
- public Optional<PiCounterId> mapTableCounter(PiTableId piTableId) {
- return Optional.empty();
- }
-
- @Override
- public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
- throws PiInterpreterException {
- return ImmutableList.of();
- }
-
- @Override
- public InboundPacket mapInboundPacket(DeviceId deviceId, PiPacketOperation packetInOperation)
- throws PiInterpreterException {
- return null;
- }
-
- /**
- * Returns an action instance with no runtime parameters.
- */
- private PiAction actionWithName(String name) {
- return PiAction.builder().withId(PiActionId.of(name)).build();
- }
-
- @Override
- public Optional<PiHeaderFieldId> mapCriterionType(Criterion.Type type) {
- return Optional.ofNullable(CRITERION_MAP.get(type));
- }
-
- @Override
- public Optional<Criterion.Type> mapPiHeaderFieldId(PiHeaderFieldId headerFieldId) {
- return Optional.ofNullable(CRITERION_MAP.inverse().get(headerFieldId));
- }
-
- @Override
- public Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId) {
- return Optional.ofNullable(TABLE_MAP.get(flowRuleTableId));
- }
-
- @Override
- public Optional<Integer> mapPiTableId(PiTableId piTableId) {
- return Optional.ofNullable(TABLE_MAP.inverse().get(piTableId));
- }
-
-}
diff --git a/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java b/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java
index 1982d7f..2630cdd 100644
--- a/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java
@@ -23,10 +23,8 @@
import org.junit.Before;
import org.junit.Test;
import org.onlab.util.ItemNotFoundException;
-import org.onosproject.bmv2.model.Bmv2PipelineModelParser;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.Pipeliner;
-import org.onosproject.net.behaviour.PipelinerAdapter;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.ConfigApplyDelegate;
import org.onosproject.net.config.ConfigFactory;
@@ -46,22 +44,23 @@
import org.onosproject.net.driver.DriverProvider;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.driver.DriverServiceAdapter;
-import org.onosproject.net.pi.model.DefaultPiPipeconf;
import org.onosproject.net.pi.model.PiPipeconf;
import org.onosproject.net.pi.model.PiPipeconfId;
import org.onosproject.net.pi.model.PiPipelineInterpreter;
import org.onosproject.net.pi.runtime.PiPipeconfConfig;
+import org.onosproject.pipelines.basic.PipeconfLoader;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
@@ -69,11 +68,6 @@
*/
public class PiPipeconfManagerTest {
- private static final String PIPECONF_ID = "org.project.pipeconf.default";
- private static final String BMV2_JSON_PATH = "/org/onosproject/net/pi/impl/default.json";
-
- private final URL bmv2JsonConfigUrl = this.getClass().getResource(BMV2_JSON_PATH);
-
private static final DeviceId DEVICE_ID = DeviceId.deviceId("test:test");
private static final String BASE_DRIVER = "baseDriver";
private static final Set<Class<? extends Behaviour>> EXPECTED_BEHAVIOURS =
@@ -105,11 +99,7 @@
@Before
public void setUp() throws IOException {
piPipeconfService = new PiPipeconfManager();
- piPipeconf = DefaultPiPipeconf.builder()
- .withId(new PiPipeconfId(PIPECONF_ID))
- .withPipelineModel(Bmv2PipelineModelParser.parse(bmv2JsonConfigUrl))
- .addBehaviour(Pipeliner.class, PipelinerAdapter.class)
- .build();
+ piPipeconf = PipeconfLoader.BASIC_PIPECONF;
completeDriverName = BASE_DRIVER + ":" + piPipeconf.id();
piPipeconfService.cfgService = cfgService;
piPipeconfService.driverService = driverService;
diff --git a/core/net/src/test/java/org/onosproject/net/pi/impl/PiTranslatorServiceTest.java b/core/net/src/test/java/org/onosproject/net/pi/impl/PiTranslatorServiceTest.java
index 2e6fa5f..e7e3e23 100644
--- a/core/net/src/test/java/org/onosproject/net/pi/impl/PiTranslatorServiceTest.java
+++ b/core/net/src/test/java/org/onosproject/net/pi/impl/PiTranslatorServiceTest.java
@@ -24,7 +24,6 @@
import org.onlab.packet.MacAddress;
import org.onlab.util.ImmutableByteSequence;
import org.onosproject.TestApplicationId;
-import org.onosproject.bmv2.model.Bmv2PipelineModelParser;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.DefaultApplicationId;
import org.onosproject.core.GroupId;
@@ -44,23 +43,17 @@
import org.onosproject.net.group.GroupBucket;
import org.onosproject.net.group.GroupBuckets;
import org.onosproject.net.group.GroupDescription;
-import org.onosproject.net.pi.model.DefaultPiPipeconf;
import org.onosproject.net.pi.model.PiPipeconf;
-import org.onosproject.net.pi.model.PiPipeconfId;
-import org.onosproject.net.pi.model.PiPipelineInterpreter;
import org.onosproject.net.pi.runtime.PiAction;
import org.onosproject.net.pi.runtime.PiActionGroup;
import org.onosproject.net.pi.runtime.PiActionGroupMember;
import org.onosproject.net.pi.runtime.PiActionGroupMemberId;
-import org.onosproject.net.pi.runtime.PiActionId;
import org.onosproject.net.pi.runtime.PiActionParam;
-import org.onosproject.net.pi.runtime.PiActionParamId;
-import org.onosproject.net.pi.runtime.PiActionProfileId;
import org.onosproject.net.pi.runtime.PiGroupKey;
import org.onosproject.net.pi.runtime.PiTableAction;
import org.onosproject.net.pi.runtime.PiTableEntry;
-import org.onosproject.net.pi.runtime.PiTableId;
import org.onosproject.net.pi.runtime.PiTernaryFieldMatch;
+import org.onosproject.pipelines.basic.PipeconfLoader;
import java.util.Collection;
import java.util.List;
@@ -73,8 +66,17 @@
import static org.onlab.util.ImmutableByteSequence.copyFrom;
import static org.onlab.util.ImmutableByteSequence.fit;
import static org.onosproject.net.group.GroupDescription.Type.SELECT;
-import static org.onosproject.net.pi.impl.MockInterpreter.*;
import static org.onosproject.net.pi.impl.PiFlowRuleTranslator.MAX_PI_PRIORITY;
+import static org.onosproject.pipelines.basic.BasicConstants.ACT_PRF_WCMP_SELECTOR_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.ACT_PRM_PORT_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.ACT_SET_EGRESS_PORT_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.HDR_ETH_DST_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.HDR_ETH_SRC_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.HDR_ETH_TYPE_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.HDR_IN_PORT_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.PORT_BITWIDTH;
+import static org.onosproject.pipelines.basic.BasicConstants.TBL_TABLE0_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.TBL_WCMP_TABLE_ID;
/**
* Tests for {@link PiFlowRuleTranslator}.
@@ -82,22 +84,17 @@
@SuppressWarnings("ConstantConditions")
public class PiTranslatorServiceTest {
- private static final String BMV2_JSON_PATH = "/org/onosproject/net/pi/impl/default.json";
private static final short IN_PORT_MASK = 0x01ff; // 9-bit mask
private static final short ETH_TYPE_MASK = (short) 0xffff;
private static final DeviceId DEVICE_ID = DeviceId.deviceId("device:dummy:1");
private static final ApplicationId APP_ID = TestApplicationId.create("dummy");
- private static final PiTableId ECMP_TABLE_ID = PiTableId.of("ecmp");
- private static final PiActionProfileId ACT_PROF_ID = PiActionProfileId.of("ecmp_selector");
private static final GroupId GROUP_ID = GroupId.valueOf(1);
- private static final PiActionId EGRESS_PORT_ACTION_ID = PiActionId.of("set_egress_port");
- private static final int PORT_BITWIDTH = 9;
- private static final PiActionParamId PORT_PARAM_ID = PiActionParamId.of("port");
private static final List<GroupBucket> BUCKET_LIST = ImmutableList.of(outputBucket(1),
outputBucket(2),
outputBucket(3)
);
- private static final PiGroupKey GROUP_KEY = new PiGroupKey(ECMP_TABLE_ID, ACT_PROF_ID, GROUP_ID.id());
+ private static final PiGroupKey GROUP_KEY = new PiGroupKey(TBL_WCMP_TABLE_ID, ACT_PRF_WCMP_SELECTOR_ID,
+ GROUP_ID.id());
private static final GroupBuckets BUCKETS = new GroupBuckets(BUCKET_LIST);
private static final GroupDescription GROUP_DESC =
new DefaultGroupDescription(DEVICE_ID, SELECT, BUCKETS, GROUP_KEY, GROUP_ID.id(), APP_ID);
@@ -111,12 +108,7 @@
@Before
public void setUp() throws Exception {
- pipeconf = DefaultPiPipeconf.builder()
- .withId(new PiPipeconfId("mock-pipeconf"))
- .withPipelineModel(Bmv2PipelineModelParser.parse(this.getClass().getResource(BMV2_JSON_PATH)))
- .addBehaviour(PiPipelineInterpreter.class, MockInterpreter.class)
- .build();
-
+ pipeconf = PipeconfLoader.BASIC_PIPECONF;
expectedMembers = ImmutableSet.of(outputMember(1),
outputMember(2),
outputMember(3));
@@ -177,13 +169,13 @@
.addEqualityGroup(entry1, entry2)
.testEquals();
- int numMatchParams = pipeconf.pipelineModel().table(TABLE0).get().matchFields().size();
+ int numMatchParams = pipeconf.pipelineModel().table(TBL_TABLE0_ID.id()).get().matchFields().size();
// parse values stored in entry1
- PiTernaryFieldMatch inPortParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(IN_PORT_ID).get();
- PiTernaryFieldMatch ethDstParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(ETH_DST_ID).get();
- PiTernaryFieldMatch ethSrcParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(ETH_SRC_ID).get();
- PiTernaryFieldMatch ethTypeParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(ETH_TYPE_ID).get();
- Optional<Double> expectedTimeout = pipeconf.pipelineModel().table(TABLE0).get().supportsAging()
+ PiTernaryFieldMatch inPortParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_IN_PORT_ID).get();
+ PiTernaryFieldMatch ethDstParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_ETH_DST_ID).get();
+ PiTernaryFieldMatch ethSrcParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_ETH_SRC_ID).get();
+ PiTernaryFieldMatch ethTypeParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_ETH_TYPE_ID).get();
+ Optional<Double> expectedTimeout = pipeconf.pipelineModel().table(TBL_TABLE0_ID.id()).get().supportsAging()
? Optional.of((double) rule1.timeout()) : Optional.empty();
// check that the number of parameters in the entry is the same as the number of table keys
@@ -216,8 +208,8 @@
private static GroupBucket outputBucket(int portNum) {
ImmutableByteSequence paramVal = copyFrom(portNum);
- PiActionParam param = new PiActionParam(PiActionParamId.of(PORT_PARAM_ID.name()), paramVal);
- PiTableAction action = PiAction.builder().withId(EGRESS_PORT_ACTION_ID).withParameter(param).build();
+ PiActionParam param = new PiActionParam(ACT_PRM_PORT_ID, paramVal);
+ PiTableAction action = PiAction.builder().withId(ACT_SET_EGRESS_PORT_ID).withParameter(param).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.add(Instructions.piTableAction(action))
.build();
@@ -226,9 +218,9 @@
private static PiActionGroupMember outputMember(int portNum)
throws ImmutableByteSequence.ByteSequenceTrimException {
- PiActionParam param = new PiActionParam(PORT_PARAM_ID, fit(copyFrom(portNum), PORT_BITWIDTH));
+ PiActionParam param = new PiActionParam(ACT_PRM_PORT_ID, fit(copyFrom(portNum), PORT_BITWIDTH));
PiAction piAction = PiAction.builder()
- .withId(EGRESS_PORT_ACTION_ID)
+ .withId(ACT_SET_EGRESS_PORT_ID)
.withParameter(param).build();
return PiActionGroupMember.builder()
.withAction(piAction)
@@ -255,7 +247,7 @@
assertThat("Group type must be SELECT",
piGroup1.type(), is(equalTo(PiActionGroup.Type.SELECT)));
assertThat("Action profile ID must be equal",
- piGroup1.actionProfileId(), is(equalTo(ACT_PROF_ID)));
+ piGroup1.actionProfileId(), is(equalTo(ACT_PRF_WCMP_SELECTOR_ID)));
// members installed
Collection<PiActionGroupMember> members = piGroup1.members();