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/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/BasicConstants.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/BasicConstants.java
new file mode 100644
index 0000000..df0923a
--- /dev/null
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/BasicConstants.java
@@ -0,0 +1,73 @@
+/*
+ * 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.pipelines.basic;
+
+import org.onosproject.net.pi.runtime.PiActionId;
+import org.onosproject.net.pi.runtime.PiActionParamId;
+import org.onosproject.net.pi.runtime.PiActionProfileId;
+import org.onosproject.net.pi.runtime.PiCounterId;
+import org.onosproject.net.pi.runtime.PiCounterType;
+import org.onosproject.net.pi.runtime.PiHeaderFieldId;
+import org.onosproject.net.pi.runtime.PiPacketMetadataId;
+import org.onosproject.net.pi.runtime.PiTableId;
+
+/**
+ * Constants for the basic.p4 program.
+ */
+public final class BasicConstants {
+
+    // TODO: constants could be auto-generated starting from the P4info.
+
+    // Header field IDs
+    public static final String ETHERNET = "ethernet";
+    public static final String LOCAL_METADATA = "local_metadata";
+    public static final String STANDARD_METADATA = "standard_metadata";
+    public static final PiHeaderFieldId HDR_IN_PORT_ID = PiHeaderFieldId.of(STANDARD_METADATA, "ingress_port");
+    public static final PiHeaderFieldId HDR_ETH_DST_ID = PiHeaderFieldId.of(ETHERNET, "dst_addr");
+    public static final PiHeaderFieldId HDR_ETH_SRC_ID = PiHeaderFieldId.of(ETHERNET, "src_addr");
+    public static final PiHeaderFieldId HDR_ETH_TYPE_ID = PiHeaderFieldId.of(ETHERNET, "ether_type");
+    public static final PiHeaderFieldId HDR_NEXT_HOP_ID = PiHeaderFieldId.of(LOCAL_METADATA, "next_hop_id");
+    public static final PiHeaderFieldId HDR_SELECTOR_ID = PiHeaderFieldId.of(LOCAL_METADATA, "selector");
+    // Table IDs
+    public static final PiTableId TBL_TABLE0_ID = PiTableId.of("table0_control.table0");
+    public static final PiTableId TBL_WCMP_TABLE_ID = PiTableId.of("wcmp_control.wcmp_table");
+    // Counter IDs
+    public static final PiCounterId CNT_TABLE0_ID = PiCounterId.of("table0_control.table0_counter",
+                                                                   PiCounterType.DIRECT);
+    public static final PiCounterId CNT_WCMP_TABLE_ID = PiCounterId.of("wcmp_control.wcmp_table_counter",
+                                                                       PiCounterType.DIRECT);
+    // Action IDs
+    public static final PiActionId ACT_NOACTION_ID = PiActionId.of("NoAction");
+    public static final PiActionId ACT_DROP_ID = PiActionId.of("_drop");
+    public static final PiActionId ACT_SET_EGRESS_PORT_ID = PiActionId.of("set_egress_port");
+    public static final PiActionId ACT_SET_NEXT_HOP_ID = PiActionId.of("table0_control.set_next_hop_id");
+    public static final PiActionId ACT_SEND_TO_CPU_ID = PiActionId.of("send_to_cpu");
+    // Action Param IDs
+    public static final PiActionParamId ACT_PRM_PORT_ID = PiActionParamId.of("port");
+    public static final PiActionParamId ACT_PRM_NEXT_HOP_ID = PiActionParamId.of("next_hop_id");
+    // Action Profile IDs
+    public static final PiActionProfileId ACT_PRF_WCMP_SELECTOR_ID = PiActionProfileId.of("wcmp_selector");
+    // Packet Metadata IDs
+    public static final PiPacketMetadataId PKT_META_EGRESS_PORT_ID = PiPacketMetadataId.of("egress_port");
+    public static final PiPacketMetadataId PKT_META_INGRESS_PORT_ID = PiPacketMetadataId.of("ingress_port");
+    // Bitwidths
+    public static final int PORT_BITWIDTH = 9;
+
+    private BasicConstants() {
+        // Hides constructor.
+    }
+}
diff --git a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/BasicInterpreterImpl.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/BasicInterpreterImpl.java
new file mode 100644
index 0000000..f9ff527
--- /dev/null
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/BasicInterpreterImpl.java
@@ -0,0 +1,257 @@
+/*
+ * 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.pipelines.basic;
+
+import com.google.common.collect.ImmutableBiMap;
+import com.google.common.collect.ImmutableList;
+import org.onlab.packet.DeserializationException;
+import org.onlab.packet.Ethernet;
+import org.onlab.util.ImmutableByteSequence;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceService;
+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.DefaultInboundPacket;
+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.PiActionParam;
+import org.onosproject.net.pi.runtime.PiCounterId;
+import org.onosproject.net.pi.runtime.PiHeaderFieldId;
+import org.onosproject.net.pi.runtime.PiPacketMetadata;
+import org.onosproject.net.pi.runtime.PiPacketOperation;
+import org.onosproject.net.pi.runtime.PiTableId;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+
+import static java.lang.String.format;
+import static java.util.stream.Collectors.toList;
+import static org.onlab.util.ImmutableByteSequence.copyFrom;
+import static org.onlab.util.ImmutableByteSequence.fit;
+import static org.onosproject.net.PortNumber.CONTROLLER;
+import static org.onosproject.net.PortNumber.FLOOD;
+import static org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT;
+import static org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
+import static org.onosproject.net.pi.runtime.PiPacketOperation.Type.PACKET_OUT;
+import static org.onosproject.pipelines.basic.BasicConstants.ACT_DROP_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.ACT_NOACTION_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.ACT_PRM_PORT_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.ACT_SEND_TO_CPU_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.ACT_SET_EGRESS_PORT_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.CNT_TABLE0_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.CNT_WCMP_TABLE_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.PKT_META_EGRESS_PORT_ID;
+import static org.onosproject.pipelines.basic.BasicConstants.PKT_META_INGRESS_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;
+
+/**
+ * Interpreter implementation for basic.p4.
+ */
+public class BasicInterpreterImpl extends AbstractHandlerBehaviour
+        implements PiPipelineInterpreter {
+
+    private static final ImmutableBiMap<Integer, PiTableId> TABLE_MAP =
+            new ImmutableBiMap.Builder<Integer, PiTableId>()
+                    .put(0, TBL_TABLE0_ID)
+                    .build();
+    private static final ImmutableBiMap<PiTableId, PiCounterId> TABLE_COUNTER_MAP =
+            new ImmutableBiMap.Builder<PiTableId, PiCounterId>()
+                    .put(TBL_TABLE0_ID, CNT_TABLE0_ID)
+                    .put(TBL_WCMP_TABLE_ID, CNT_WCMP_TABLE_ID)
+                    .build();
+    private static final ImmutableBiMap<Criterion.Type, PiHeaderFieldId> CRITERION_MAP =
+            new ImmutableBiMap.Builder<Criterion.Type, PiHeaderFieldId>()
+                    .put(Criterion.Type.IN_PORT, HDR_IN_PORT_ID)
+                    .put(Criterion.Type.ETH_DST, HDR_ETH_DST_ID)
+                    .put(Criterion.Type.ETH_SRC, HDR_ETH_SRC_ID)
+                    .put(Criterion.Type.ETH_TYPE, HDR_ETH_TYPE_ID)
+                    .build();
+
+    @Override
+    public PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId)
+            throws PiInterpreterException {
+        if (treatment.allInstructions().size() == 0) {
+            // No actions means drop.
+            return PiAction.builder().withId(ACT_DROP_ID).build();
+        } else if (treatment.allInstructions().size() > 1) {
+            // We understand treatments with only 1 instruction.
+            throw new PiInterpreterException("Treatment has multiple instructions");
+        }
+
+        Instruction instruction = treatment.allInstructions().get(0);
+        switch (instruction.type()) {
+            case OUTPUT:
+                return outputPiAction((OutputInstruction) instruction);
+            case NOACTION:
+                return PiAction.builder().withId(ACT_NOACTION_ID).build();
+            default:
+                throw new PiInterpreterException(format(
+                        "Instruction type '%s' not supported", instruction.type()));
+        }
+    }
+
+    private PiAction outputPiAction(OutputInstruction outInstruction)
+            throws PiInterpreterException {
+        PortNumber port = outInstruction.port();
+        if (!port.isLogical()) {
+            try {
+                return PiAction.builder()
+                        .withId(ACT_SET_EGRESS_PORT_ID)
+                        .withParameter(new PiActionParam(ACT_PRM_PORT_ID,
+                                                         fit(copyFrom(port.toLong()), PORT_BITWIDTH)))
+                        .build();
+            } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
+                throw new PiInterpreterException(e.getMessage());
+            }
+        } else if (port.equals(CONTROLLER)) {
+            return PiAction.builder().withId(ACT_SEND_TO_CPU_ID).build();
+        } else {
+            throw new PiInterpreterException(format(
+                    "Egress on logical port '%s' not supported", port));
+        }
+    }
+
+    @Override
+    public Optional<PiCounterId> mapTableCounter(PiTableId piTableId) {
+        return Optional.ofNullable(TABLE_COUNTER_MAP.get(piTableId));
+    }
+
+    @Override
+    public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
+            throws PiInterpreterException {
+        TrafficTreatment treatment = packet.treatment();
+
+        // basic.p4 supports only OUTPUT instructions.
+        List<OutputInstruction> outInstructions = treatment
+                .allInstructions()
+                .stream()
+                .filter(i -> i.type().equals(OUTPUT))
+                .map(i -> (OutputInstruction) i)
+                .collect(toList());
+
+        if (treatment.allInstructions().size() != outInstructions.size()) {
+            // There are other instructions that are not of type OUTPUT.
+            throw new PiInterpreterException("Treatment not supported: " + treatment);
+        }
+
+        ImmutableList.Builder<PiPacketOperation> builder = ImmutableList.builder();
+        for (OutputInstruction outInst : outInstructions) {
+            if (outInst.port().isLogical() && !outInst.port().equals(FLOOD)) {
+                throw new PiInterpreterException(format(
+                        "Output on logical port '%s' not supported", outInst.port()));
+            } else if (outInst.port().equals(FLOOD)) {
+                // Since basic.p4 does not support flooding, we create a packet
+                // operation for each switch port.
+                final DeviceService deviceService = handler().get(DeviceService.class);
+                for (Port port : deviceService.getPorts(packet.sendThrough())) {
+                    builder.add(createPiPacketOperation(packet.data(), port.number().toLong()));
+                }
+            } else {
+                builder.add(createPiPacketOperation(packet.data(), outInst.port().toLong()));
+            }
+        }
+        return builder.build();
+    }
+
+    @Override
+    public InboundPacket mapInboundPacket(DeviceId deviceId, PiPacketOperation packetIn)
+            throws PiInterpreterException {
+        // Assuming that the packet is ethernet, which is fine since basic.p4
+        // can deparse only ethernet packets.
+        Ethernet ethPkt;
+        try {
+            ethPkt = Ethernet.deserializer().deserialize(packetIn.data().asArray(), 0,
+                                                         packetIn.data().size());
+        } catch (DeserializationException dex) {
+            throw new PiInterpreterException(dex.getMessage());
+        }
+
+        // Returns the ingress port packet metadata.
+        Optional<PiPacketMetadata> packetMetadata = packetIn.metadatas()
+                .stream().filter(m -> m.id().equals(PKT_META_INGRESS_PORT_ID))
+                .findFirst();
+
+        if (packetMetadata.isPresent()) {
+            ImmutableByteSequence portByteSequence = packetMetadata.get().value();
+            short s = portByteSequence.asReadOnlyBuffer().getShort();
+            ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(s));
+            ByteBuffer rawData = ByteBuffer.wrap(packetIn.data().asArray());
+            return new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
+        } else {
+            throw new PiInterpreterException(format(
+                    "Missing metadata '%s' in packet-in received from '%s': %s",
+                    PKT_META_INGRESS_PORT_ID, deviceId, packetIn));
+        }
+    }
+
+    private PiPacketOperation createPiPacketOperation(ByteBuffer data, long portNumber)
+            throws PiInterpreterException {
+        PiPacketMetadata metadata = createPacketMetadata(portNumber);
+        return PiPacketOperation.builder()
+                .withType(PACKET_OUT)
+                .withData(copyFrom(data))
+                .withMetadatas(ImmutableList.of(metadata))
+                .build();
+    }
+
+    private PiPacketMetadata createPacketMetadata(long portNumber) throws PiInterpreterException {
+        try {
+            return PiPacketMetadata.builder()
+                    .withId(PKT_META_EGRESS_PORT_ID)
+                    .withValue(fit(copyFrom(portNumber), PORT_BITWIDTH))
+                    .build();
+        } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
+            throw new PiInterpreterException(format(
+                    "Port number %d too big, %s", portNumber, e.getMessage()));
+        }
+    }
+
+    @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/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/EcmpConstants.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/EcmpConstants.java
new file mode 100644
index 0000000..284d5cd
--- /dev/null
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/EcmpConstants.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.pipelines.basic;
+
+import org.onosproject.net.pi.runtime.PiTableId;
+
+/**
+ * Constants for the ecmp.p4 program.
+ */
+public final class EcmpConstants {
+
+    public static final PiTableId TBL_ECMP_TABLE_ID = PiTableId.of("ecmp_table");
+
+    private EcmpConstants() {
+        // Hides constructor.
+    }
+}
diff --git a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/EcmpInterpreterImpl.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/EcmpInterpreterImpl.java
new file mode 100644
index 0000000..2596ee9
--- /dev/null
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/EcmpInterpreterImpl.java
@@ -0,0 +1,46 @@
+/*
+ * 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.pipelines.basic;
+
+import com.google.common.collect.ImmutableBiMap;
+import org.onosproject.net.pi.runtime.PiTableId;
+
+import java.util.Optional;
+
+import static org.onosproject.pipelines.basic.BasicConstants.TBL_TABLE0_ID;
+import static org.onosproject.pipelines.basic.EcmpConstants.TBL_ECMP_TABLE_ID;
+
+/**
+ * Interpreter implementation for ecmp.p4.
+ */
+public class EcmpInterpreterImpl extends BasicInterpreterImpl {
+
+    private static final ImmutableBiMap<Integer, PiTableId> TABLE_MAP = new ImmutableBiMap.Builder<Integer, PiTableId>()
+            .put(0, TBL_TABLE0_ID)
+            .put(1, TBL_ECMP_TABLE_ID)
+            .build();
+
+    @Override
+    public Optional<Integer> mapPiTableId(PiTableId piTableId) {
+        return Optional.ofNullable(TABLE_MAP.inverse().get(piTableId));
+    }
+
+    @Override
+    public Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId) {
+        return Optional.ofNullable(TABLE_MAP.get(flowRuleTableId));
+    }
+}
diff --git a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/PipeconfLoader.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/PipeconfLoader.java
new file mode 100644
index 0000000..bcfb7d0
--- /dev/null
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/PipeconfLoader.java
@@ -0,0 +1,106 @@
+/*
+ * 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.pipelines.basic;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onosproject.bmv2.model.Bmv2PipelineModelParser;
+import org.onosproject.driver.pipeline.DefaultSingleTablePipeline;
+import org.onosproject.net.behaviour.Pipeliner;
+import org.onosproject.net.device.PortStatisticsDiscovery;
+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.model.PiPipelineModel;
+import org.onosproject.net.pi.runtime.PiPipeconfService;
+
+import java.net.URL;
+import java.util.Collection;
+
+import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON;
+import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.P4_INFO_TEXT;
+
+/**
+ * Component that produces and registers the basic pipeconfs when loaded.
+ */
+@Component(immediate = true)
+public final class PipeconfLoader {
+
+    private static final PiPipeconfId BASIC_PIPECONF_ID = new PiPipeconfId("org.onosproject.pipelines.basic");
+    private static final String BASIC_JSON_PATH = "/p4c-out/bmv2/basic.json";
+    private static final String BASIC_P4INFO = "/p4c-out/bmv2/basic.p4info";
+
+    private static final PiPipeconfId ECMP_PIPECONF_ID = new PiPipeconfId("org.onosproject.pipelines.ecmp");
+    private static final String ECMP_JSON_PATH = "/p4c-out/bmv2/ecmp.json";
+    private static final String ECMP_P4INFO = "/p4c-out/bmv2/ecmp.p4info";
+
+    public static final PiPipeconf BASIC_PIPECONF = buildBasicPipeconf();
+    public static final PiPipeconf ECMP_PIPECONF = buildEcmpPipeconf();
+
+    private static final Collection<PiPipeconf> ALL_PIPECONFS = ImmutableList.of(BASIC_PIPECONF, ECMP_PIPECONF);
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private PiPipeconfService piPipeconfService;
+
+    @Activate
+    public void activate() {
+        // Registers all pipeconf at component activation.
+        ALL_PIPECONFS.forEach(piPipeconfService::register);
+    }
+
+    @Deactivate
+    public void deactivate() {
+        ALL_PIPECONFS.stream().map(PiPipeconf::id).forEach(piPipeconfService::remove);
+    }
+
+    private static PiPipeconf buildBasicPipeconf() {
+        final URL jsonUrl = PipeconfLoader.class.getResource(BASIC_JSON_PATH);
+        final URL p4InfoUrl = PipeconfLoader.class.getResource(BASIC_P4INFO);
+        final PiPipelineModel model = Bmv2PipelineModelParser.parse(jsonUrl);
+        return DefaultPiPipeconf.builder()
+                .withId(BASIC_PIPECONF_ID)
+                .withPipelineModel(model)
+                .addBehaviour(PiPipelineInterpreter.class, BasicInterpreterImpl.class)
+                .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class)
+                .addBehaviour(PortStatisticsDiscovery.class, PortStatisticsDiscoveryImpl.class)
+                .addExtension(P4_INFO_TEXT, p4InfoUrl)
+                .addExtension(BMV2_JSON, jsonUrl)
+                // Put here other target-specific extensions,
+                // e.g. Tofino's bin and context.json.
+                .build();
+    }
+
+    private static PiPipeconf buildEcmpPipeconf() {
+        final URL jsonUrl = PipeconfLoader.class.getResource(ECMP_JSON_PATH);
+        final URL p4InfoUrl = PipeconfLoader.class.getResource(ECMP_P4INFO);
+        final PiPipelineModel model = Bmv2PipelineModelParser.parse(jsonUrl);
+        return DefaultPiPipeconf.builder()
+                .withId(ECMP_PIPECONF_ID)
+                .withPipelineModel(model)
+                .addBehaviour(PiPipelineInterpreter.class, EcmpInterpreterImpl.class)
+                .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class)
+                .addBehaviour(PortStatisticsDiscovery.class, PortStatisticsDiscoveryImpl.class)
+                .addExtension(P4_INFO_TEXT, p4InfoUrl)
+                .addExtension(BMV2_JSON, jsonUrl)
+                .build();
+    }
+}
diff --git a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/PortStatisticsDiscoveryImpl.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/PortStatisticsDiscoveryImpl.java
new file mode 100644
index 0000000..425f8fe
--- /dev/null
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/PortStatisticsDiscoveryImpl.java
@@ -0,0 +1,150 @@
+/*
+ * 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.pipelines.basic;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DefaultPortStatistics;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.PortStatistics;
+import org.onosproject.net.device.PortStatisticsDiscovery;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.pi.model.PiPipeconf;
+import org.onosproject.net.pi.runtime.PiCounterCellData;
+import org.onosproject.net.pi.runtime.PiCounterCellId;
+import org.onosproject.net.pi.runtime.PiCounterId;
+import org.onosproject.net.pi.runtime.PiIndirectCounterCellId;
+import org.onosproject.net.pi.runtime.PiPipeconfService;
+import org.onosproject.p4runtime.api.P4RuntimeClient;
+import org.onosproject.p4runtime.api.P4RuntimeController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import static org.onosproject.net.pi.runtime.PiCounterType.INDIRECT;
+
+/**
+ * Implementation of the PortStatisticsBehaviour for basic.p4.
+ */
+public class PortStatisticsDiscoveryImpl extends AbstractHandlerBehaviour implements PortStatisticsDiscovery {
+
+    protected final Logger log = LoggerFactory.getLogger(getClass());
+
+    private static final String SCOPE = "port_counters_control";
+    private static final PiCounterId INGRESS_COUNTER_ID = PiCounterId.of("port_counters_ingress",
+                                                                         "ingress_port_counter", INDIRECT);
+    private static final PiCounterId EGRESS_COUNTER_ID = PiCounterId.of("port_counters_egress",
+                                                                        "egress_port_counter", INDIRECT);
+
+    /**
+     * Returns the ID of the ingress port counter.
+     *
+     * @return counter ID
+     */
+    public PiCounterId ingressCounterId() {
+        return INGRESS_COUNTER_ID;
+    }
+
+    /**
+     * Returns the ID of the egress port counter.
+     *
+     * @return counter ID
+     */
+    public PiCounterId egressCounterId() {
+        return EGRESS_COUNTER_ID;
+    }
+
+    @Override
+    public Collection<PortStatistics> discoverPortStatistics() {
+
+        DeviceService deviceService = this.handler().get(DeviceService.class);
+        DeviceId deviceId = this.data().deviceId();
+
+        PiPipeconfService piPipeconfService = handler().get(PiPipeconfService.class);
+        if (!piPipeconfService.ofDevice(deviceId).isPresent() ||
+                !piPipeconfService.getPipeconf(piPipeconfService.ofDevice(deviceId).get()).isPresent()) {
+            log.warn("Unable to get the pipeconf of {}, aborting operation", deviceId);
+            return Collections.emptyList();
+        }
+        PiPipeconf pipeconf = piPipeconfService.getPipeconf(piPipeconfService.ofDevice(deviceId).get()).get();
+
+        P4RuntimeController controller = handler().get(P4RuntimeController.class);
+        if (!controller.hasClient(deviceId)) {
+            log.warn("Unable to find client for {}, aborting operation", deviceId);
+            return Collections.emptyList();
+        }
+        P4RuntimeClient client = controller.getClient(deviceId);
+
+        Map<Long, DefaultPortStatistics.Builder> portStatBuilders = Maps.newHashMap();
+        deviceService.getPorts(deviceId)
+                .forEach(p -> portStatBuilders.put(p.number().toLong(),
+                                                   DefaultPortStatistics.builder()
+                                                           .setPort(p.number())
+                                                           .setDeviceId(deviceId)));
+
+        Set<PiCounterCellId> counterCellIds = Sets.newHashSet();
+        portStatBuilders.keySet().forEach(p -> {
+            // Counter cell/index = port number.
+            counterCellIds.add(PiIndirectCounterCellId.of(ingressCounterId(), p));
+            counterCellIds.add(PiIndirectCounterCellId.of(egressCounterId(), p));
+        });
+
+        Collection<PiCounterCellData> counterEntryResponse;
+        try {
+            counterEntryResponse = client.readCounterCells(counterCellIds, pipeconf).get();
+        } catch (InterruptedException | ExecutionException e) {
+            log.warn("Exception while reading port counters from {}: {}", deviceId, e.toString());
+            log.debug("", e);
+            return Collections.emptyList();
+        }
+
+        counterEntryResponse.forEach(counterData -> {
+            if (counterData.cellId().type() != INDIRECT) {
+                log.warn("Invalid counter data type {}, skipping", counterData.cellId().type());
+                return;
+            }
+            PiIndirectCounterCellId indCellId = (PiIndirectCounterCellId) counterData.cellId();
+            if (!portStatBuilders.containsKey(indCellId.index())) {
+                log.warn("Unrecognized counter index {}, skipping", counterData);
+                return;
+            }
+            DefaultPortStatistics.Builder statsBuilder = portStatBuilders.get(indCellId.index());
+            if (counterData.cellId().counterId().equals(ingressCounterId())) {
+                statsBuilder.setPacketsReceived(counterData.packets());
+                statsBuilder.setBytesReceived(counterData.bytes());
+            } else if (counterData.cellId().counterId().equals(egressCounterId())) {
+                statsBuilder.setPacketsSent(counterData.packets());
+                statsBuilder.setBytesSent(counterData.bytes());
+            } else {
+                log.warn("Unrecognized counter ID {}, skipping", counterData);
+            }
+        });
+
+        return portStatBuilders
+                .values()
+                .stream()
+                .map(DefaultPortStatistics.Builder::build)
+                .collect(Collectors.toList());
+    }
+}
diff --git a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/package-info.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/package-info.java
new file mode 100644
index 0000000..1fb8767
--- /dev/null
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * ONOS default pipelines that provide basic L2/L3 forwarding capabilities
+ * and packet-in/out support.
+ */
+package org.onosproject.pipelines.basic;
\ No newline at end of file