[ONOS-7128] Initial commit of fabric.p4
Change-Id: I5224c411a1eccdbee84b1fc0b1824c5fa922f689
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
new file mode 100644
index 0000000..333964a
--- /dev/null
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
@@ -0,0 +1,158 @@
+/*
+ * 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.fabric;
+
+import org.onosproject.net.pi.model.PiActionId;
+import org.onosproject.net.pi.model.PiActionParamId;
+import org.onosproject.net.pi.model.PiActionProfileId;
+import org.onosproject.net.pi.model.PiControlMetadataId;
+import org.onosproject.net.pi.model.PiCounterId;
+import org.onosproject.net.pi.model.PiMatchFieldId;
+import org.onosproject.net.pi.model.PiTableId;
+/**
+ * Constants for fabric pipeline.
+ */
+public final class FabricConstants {
+
+ // hide default constructor
+ private FabricConstants() {
+ }
+
+ public static final String DOT = ".";
+ // Header IDs
+ public static final String HDR = "hdr";
+ public static final String UDP = "udp";
+ public static final String STANDARD_METADATA = "standard_metadata";
+ public static final String MPLS = "mpls";
+ public static final String TCP = "tcp";
+ public static final String FABRIC_METADATA = "fabric_metadata";
+ public static final String IPV4 = "ipv4";
+ public static final String IPV6 = "ipv6";
+ public static final String ETHERNET = "ethernet";
+ public static final String VLAN_TAG = "vlan_tag";
+ public static final String ICMP = "icmp";
+
+ // Header field IDs
+ public static final PiMatchFieldId HF_VLAN_TAG_VLAN_ID_ID = buildPiMatchField(VLAN_TAG, "vlan_id", true);
+ public static final PiMatchFieldId HF_MPLS_LABEL_ID = buildPiMatchField(MPLS, "label", true);
+ public static final PiMatchFieldId HF_STANDARD_METADATA_INGRESS_PORT_ID =
+ buildPiMatchField(STANDARD_METADATA, "ingress_port", false);
+ public static final PiMatchFieldId HF_UDP_SRC_PORT_ID = buildPiMatchField(UDP, "src_port", true);
+ public static final PiMatchFieldId HF_VLAN_TAG_IS_VALID_ID = buildPiMatchField(VLAN_TAG, "is_valid", true);
+ public static final PiMatchFieldId HF_IPV6_NEXT_HDR_ID = buildPiMatchField(IPV6, "next_hdr", true);
+ public static final PiMatchFieldId HF_ETHERNET_SRC_ADDR_ID = buildPiMatchField(ETHERNET, "src_addr", true);
+ public static final PiMatchFieldId HF_ICMP_ICMP_TYPE_ID = buildPiMatchField(ICMP, "icmp_type", true);
+ public static final PiMatchFieldId HF_MPLS_TC_ID = buildPiMatchField(MPLS, "tc", true);
+ public static final PiMatchFieldId HF_IPV4_DST_ADDR_ID = buildPiMatchField(IPV4, "dst_addr", true);
+ public static final PiMatchFieldId HF_VLAN_TAG_PRI_ID = buildPiMatchField(VLAN_TAG, "pri", true);
+ public static final PiMatchFieldId HF_TCP_SRC_PORT_ID = buildPiMatchField(TCP, "src_port", true);
+ public static final PiMatchFieldId HF_ETHERNET_ETHER_TYPE_ID = buildPiMatchField(ETHERNET, "ether_type", true);
+ public static final PiMatchFieldId HF_ICMP_ICMP_CODE_ID = buildPiMatchField(ICMP, "icmp_code", true);
+ public static final PiMatchFieldId HF_MPLS_BOS_ID = buildPiMatchField(MPLS, "bos", true);
+ public static final PiMatchFieldId HF_FABRIC_METADATA_IP_PROTO_ID =
+ buildPiMatchField(FABRIC_METADATA, "ip_proto", false);
+ public static final PiMatchFieldId HF_FABRIC_METADATA_NEXT_ID_ID =
+ buildPiMatchField(FABRIC_METADATA, "next_id", false);
+ public static final PiMatchFieldId HF_UDP_DST_PORT_ID = buildPiMatchField(UDP, "dst_port", true);
+ public static final PiMatchFieldId HF_IPV4_PROTOCOL_ID = buildPiMatchField(IPV4, "protocol", true);
+ public static final PiMatchFieldId HF_IPV4_SRC_ADDR_ID = buildPiMatchField(IPV4, "src_addr", true);
+ public static final PiMatchFieldId HF_IPV6_SRC_ADDR_ID = buildPiMatchField(IPV6, "src_addr", true);
+ public static final PiMatchFieldId HF_IPV6_DST_ADDR_ID = buildPiMatchField(IPV6, "dst_addr", true);
+ public static final PiMatchFieldId HF_TCP_DST_PORT_ID = buildPiMatchField(TCP, "dst_port", true);
+ public static final PiMatchFieldId HF_ETHERNET_DST_ADDR_ID = buildPiMatchField(ETHERNET, "dst_addr", true);
+
+ private static PiMatchFieldId buildPiMatchField(String header, String field, boolean withHdrPrefix) {
+ if (withHdrPrefix) {
+ return PiMatchFieldId.of(HDR + DOT + header + DOT + field);
+ } else {
+ return PiMatchFieldId.of(header + DOT + field);
+ }
+ }
+
+ // Table IDs
+ public static final PiTableId TBL_MULTICAST_V4_ID = PiTableId.of("forwarding.multicast_v4");
+ public static final PiTableId TBL_MULTICAST_V6_ID = PiTableId.of("forwarding.multicast_v6");
+ public static final PiTableId TBL_ACL_ID = PiTableId.of("forwarding.acl");
+ public static final PiTableId TBL_BROADCAST_ID = PiTableId.of("next.broadcast");
+ public static final PiTableId TBL_HASHED_ID = PiTableId.of("next.hashed");
+ public static final PiTableId TBL_INGRESS_PORT_VLAN_ID = PiTableId.of("filtering.ingress_port_vlan");
+ public static final PiTableId TBL_FWD_CLASSIFIER_ID = PiTableId.of("filtering.fwd_classifier");
+ public static final PiTableId TBL_NEXT_ID_MAPPING_ID = PiTableId.of("next.next_id_mapping");
+ public static final PiTableId TBL_UNICAST_V6_ID = PiTableId.of("forwarding.unicast_v6");
+ public static final PiTableId TBL_SIMPLE_ID = PiTableId.of("next.simple");
+ public static final PiTableId TBL_BRIDGING_ID = PiTableId.of("forwarding.bridging");
+ public static final PiTableId TBL_UNICAST_V4_ID = PiTableId.of("forwarding.unicast_v4");
+ public static final PiTableId TBL_MPLS_ID = PiTableId.of("forwarding.mpls");
+
+ // Indirect Counter IDs
+ public static final PiCounterId CNT_EGRESS_PORT_COUNTER_ID =
+ PiCounterId.of("port_counters_control.egress_port_counter");
+ public static final PiCounterId CNT_INGRESS_PORT_COUNTER_ID =
+ PiCounterId.of("port_counters_control.ingress_port_counter");
+
+ // Direct Counter IDs
+ public static final PiCounterId CNT_MULTICAST_V6_COUNTER_ID = PiCounterId.of("forwarding.multicast_v6_counter");
+ public static final PiCounterId CNT_ACL_COUNTER_ID = PiCounterId.of("forwarding.acl_counter");
+ public static final PiCounterId CNT_UNICAST_V4_COUNTER_ID = PiCounterId.of("forwarding.unicast_v4_counter");
+ public static final PiCounterId CNT_INGRESS_PORT_VLAN_COUNTER_ID =
+ PiCounterId.of("filtering.ingress_port_vlan_counter");
+ public static final PiCounterId CNT_FWD_CLASSIFIER_COUNTER_ID = PiCounterId.of("filtering.fwd_classifier_counter");
+ public static final PiCounterId CNT_UNICAST_V6_COUNTER_ID = PiCounterId.of("forwarding.unicast_v6_counter");
+ public static final PiCounterId CNT_BRIDGING_COUNTER_ID = PiCounterId.of("forwarding.bridging_counter");
+ public static final PiCounterId CNT_NEXT_ID_MAPPING_COUNTER_ID = PiCounterId.of("next.next_id_mapping_counter");
+ public static final PiCounterId CNT_SIMPLE_COUNTER_ID = PiCounterId.of("next.simple_counter");
+ public static final PiCounterId CNT_HASHED_COUNTER_ID = PiCounterId.of("next.hashed_counter");
+ public static final PiCounterId CNT_BROADCAST_COUNTER_ID = PiCounterId.of("next.broadcast_counter");
+ public static final PiCounterId CNT_MULTICAST_V4_COUNTER_ID = PiCounterId.of("forwarding.multicast_v4_counter");
+ public static final PiCounterId CNT_MPLS_COUNTER_ID = PiCounterId.of("forwarding.mpls_counter");
+
+ // Action IDs
+ public static final PiActionId ACT_SET_MCAST_GROUP_ID = PiActionId.of("next.set_mcast_group");
+ public static final PiActionId ACT_DROP_ID = PiActionId.of("drop");
+ public static final PiActionId ACT_PUSH_INTERNAL_VLAN_ID = PiActionId.of("filtering.push_internal_vlan");
+ public static final PiActionId ACT_SET_VLAN_OUTPUT_ID = PiActionId.of("next.set_vlan_output");
+ public static final PiActionId ACT_NOACTION_ID = PiActionId.of("NoAction");
+ public static final PiActionId ACT_PUSH_MPLS_AND_NEXT_V6_ID = PiActionId.of("forwarding.push_mpls_and_next_v6");
+ public static final PiActionId ACT_PUSH_MPLS_AND_NEXT_V4_ID = PiActionId.of("forwarding.push_mpls_and_next_v4");
+ public static final PiActionId ACT_SET_FORWARDING_TYPE_ID = PiActionId.of("filtering.set_forwarding_type");
+ public static final PiActionId ACT_POP_MPLS_AND_NEXT_ID = PiActionId.of("forwarding.pop_mpls_and_next");
+ public static final PiActionId ACT_SET_NEXT_TYPE_ID = PiActionId.of("next.set_next_type");
+ public static final PiActionId ACT_L3_ROUTING_ID = PiActionId.of("next.l3_routing");
+ public static final PiActionId ACT_OUTPUT_ID = PiActionId.of("next.output");
+ public static final PiActionId ACT_NOP_ID = PiActionId.of("nop");
+ public static final PiActionId ACT_SET_NEXT_ID_ID = PiActionId.of("forwarding.set_next_id");
+ public static final PiActionId ACT_SET_VLAN_ID = PiActionId.of("filtering.set_vlan");
+ public static final PiActionId ACT_DUPLICATE_TO_CONTROLLER_ID = PiActionId.of("forwarding.duplicate_to_controller");
+
+ // Action Param IDs
+ public static final PiActionParamId ACT_PRM_DMAC_ID = PiActionParamId.of("dmac");
+ public static final PiActionParamId ACT_PRM_PORT_NUM_ID = PiActionParamId.of("port_num");
+ public static final PiActionParamId ACT_PRM_LABEL_ID = PiActionParamId.of("label");
+ public static final PiActionParamId ACT_PRM_SMAC_ID = PiActionParamId.of("smac");
+ public static final PiActionParamId ACT_PRM_GID_ID = PiActionParamId.of("gid");
+ public static final PiActionParamId ACT_PRM_NEW_VLAN_ID_ID = PiActionParamId.of("new_vlan_id");
+ public static final PiActionParamId ACT_PRM_FWD_TYPE_ID = PiActionParamId.of("fwd_type");
+ public static final PiActionParamId ACT_PRM_NEXT_TYPE_ID = PiActionParamId.of("next_type");
+ public static final PiActionParamId ACT_PRM_NEXT_ID_ID = PiActionParamId.of("next_id");
+
+ // Action Profile IDs
+ public static final PiActionProfileId ACT_PRF_ECMP_SELECTOR_ID = PiActionProfileId.of("ecmp_selector");
+
+ // Packet Metadata IDs
+ public static final PiControlMetadataId CTRL_META_EGRESS_PORT_ID = PiControlMetadataId.of("egress_port");
+ public static final PiControlMetadataId CTRL_META_INGRESS_PORT_ID = PiControlMetadataId.of("ingress_port");
+}
\ No newline at end of file
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricPortStatisticsDiscovery.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricPortStatisticsDiscovery.java
new file mode 100644
index 0000000..a9e3f3b
--- /dev/null
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricPortStatisticsDiscovery.java
@@ -0,0 +1,47 @@
+/*
+ * 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.fabric;
+
+
+import org.onosproject.net.pi.model.PiCounterId;
+import org.onosproject.pipelines.basic.PortStatisticsDiscoveryImpl;
+
+/**
+ * Implementation of the PortStatisticsBehaviour for fabric.p4.
+ */
+public class FabricPortStatisticsDiscovery extends PortStatisticsDiscoveryImpl {
+
+ /**
+ * Returns the ID of the ingress port counter.
+ *
+ * @return counter ID
+ */
+ @Override
+ public PiCounterId ingressCounterId() {
+ return FabricConstants.CNT_INGRESS_PORT_COUNTER_ID;
+ }
+
+ /**
+ * Returns the ID of the egress port counter.
+ *
+ * @return counter ID
+ */
+ @Override
+ public PiCounterId egressCounterId() {
+ return FabricConstants.CNT_EGRESS_PORT_COUNTER_ID;
+ }
+}
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/PipeconfLoader.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/PipeconfLoader.java
new file mode 100644
index 0000000..f7fc45f
--- /dev/null
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/PipeconfLoader.java
@@ -0,0 +1,94 @@
+/*
+ * 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.fabric;
+
+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.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.PiPipelineModel;
+import org.onosproject.net.pi.service.PiPipeconfService;
+import org.onosproject.p4runtime.model.P4InfoParser;
+import org.onosproject.p4runtime.model.P4InfoParserException;
+
+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;
+
+/**
+ * Pipeline config loader for fabric pipeline.
+ */
+@Component(immediate = true)
+public class PipeconfLoader {
+
+ private static final PiPipeconfId FABRIC_PIPECONF_ID =
+ new PiPipeconfId("org.onosproject.pipelines.fabric");
+ private static final String FABRIC_JSON_PATH = "/p4c-out/bmv2/fabric.json";
+ private static final String FABRIC_P4INFO_PATH = "/p4c-out/bmv2/fabric.p4info";
+
+ public static final PiPipeconf FABRIC_PIPECONF = buildFabricPipeconf();
+
+ // XXX: Use a collection to hold only one pipeconf because we might separate
+ // fabric pipeconf to leaf/spine pipeconf in the future.
+ private static final Collection<PiPipeconf> ALL_PIPECONFS =
+ ImmutableList.of(FABRIC_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 buildFabricPipeconf() {
+ final URL jsonUrl = PipeconfLoader.class.getResource(FABRIC_JSON_PATH);
+ final URL p4InfoUrl = PipeconfLoader.class.getResource(FABRIC_P4INFO_PATH);
+ final PiPipelineModel model = parseP4Info(p4InfoUrl);
+ return DefaultPiPipeconf.builder()
+ .withId(FABRIC_PIPECONF_ID)
+ .withPipelineModel(model)
+ .addBehaviour(PortStatisticsDiscovery.class, FabricPortStatisticsDiscovery.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 PiPipelineModel parseP4Info(URL p4InfoUrl) {
+ try {
+ return P4InfoParser.parse(p4InfoUrl);
+ } catch (P4InfoParserException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/package-info.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/package-info.java
new file mode 100644
index 0000000..1cd2d1f
--- /dev/null
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * CORD underlay fabric pipeline.
+ */
+package org.onosproject.pipelines.fabric;