Skip to content

Commit

Permalink
eth_type moved outside ethernet header in fabric.p4
Browse files Browse the repository at this point in the history
Change-Id: I3ae0813c5e8aba48767d5bb235fbbcfb75954010
(cherry picked from commit 693d76f)
  • Loading branch information
daniele-moro authored and ccascone committed Nov 1, 2019
1 parent 71ba99f commit 5a2de71
Show file tree
Hide file tree
Showing 27 changed files with 5,589 additions and 8,290 deletions.
Expand Up @@ -19,10 +19,10 @@
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.PiCounterId;
import org.onosproject.net.pi.model.PiMatchFieldId;
import org.onosproject.net.pi.model.PiMeterId;
import org.onosproject.net.pi.model.PiPacketMetadataId;
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.
Expand All @@ -38,17 +38,13 @@ private FabricConstants() {
PiMatchFieldId.of("ig_port");
public static final PiMatchFieldId HDR_VLAN_IS_VALID =
PiMatchFieldId.of("vlan_is_valid");
public static final PiMatchFieldId HDR_EG_PORT =
PiMatchFieldId.of("eg_port");
public static final PiMatchFieldId HDR_IPV6_SRC_NET_ID =
PiMatchFieldId.of("ipv6_src_net_id");
public static final PiMatchFieldId HDR_C_TAG = PiMatchFieldId.of("c_tag");
public static final PiMatchFieldId HDR_IPV4_SRC =
PiMatchFieldId.of("ipv4_src");
public static final PiMatchFieldId HDR_IPV6_DST =
PiMatchFieldId.of("ipv6_dst");
public static final PiMatchFieldId HDR_IS_MPLS =
PiMatchFieldId.of("is_mpls");
public static final PiMatchFieldId HDR_L4_DPORT =
PiMatchFieldId.of("l4_dport");
public static final PiMatchFieldId HDR_PPPOE_CODE =
Expand All @@ -72,6 +68,8 @@ private FabricConstants() {
PiMatchFieldId.of("eth_type");
public static final PiMatchFieldId HDR_NEXT_ID =
PiMatchFieldId.of("next_id");
public static final PiMatchFieldId HDR_IP_ETH_TYPE =
PiMatchFieldId.of("ip_eth_type");
public static final PiMatchFieldId HDR_L4_SPORT =
PiMatchFieldId.of("l4_sport");
public static final PiMatchFieldId HDR_ICMP_CODE =
Expand All @@ -88,10 +86,8 @@ private FabricConstants() {
PiMatchFieldId.of("line_id");
public static final PiMatchFieldId HDR_IPV4_DSCP =
PiMatchFieldId.of("ipv4_dscp");
public static final PiMatchFieldId HDR_IS_IPV4 =
PiMatchFieldId.of("is_ipv4");
public static final PiMatchFieldId HDR_IS_IPV6 =
PiMatchFieldId.of("is_ipv6");
public static final PiMatchFieldId HDR_EG_PORT =
PiMatchFieldId.of("eg_port");
public static final PiMatchFieldId HDR_GTP_IPV4_DST =
PiMatchFieldId.of("gtp_ipv4_dst");
public static final PiMatchFieldId HDR_INT_IS_VALID =
Expand Down Expand Up @@ -181,8 +177,8 @@ private FabricConstants() {
PiCounterId.of("FabricIngress.filtering.fwd_classifier_counter");
public static final PiCounterId FABRIC_INGRESS_FORWARDING_BRIDGING_COUNTER =
PiCounterId.of("FabricIngress.forwarding.bridging_counter");
public static final PiCounterId FABRIC_INGRESS_FORWARDING_ROUTING_V4_COUNTER =
PiCounterId.of("FabricIngress.forwarding.routing_v4_counter");
public static final PiCounterId FABRIC_INGRESS_NEXT_HASHED_COUNTER =
PiCounterId.of("FabricIngress.next.hashed_counter");
public static final PiCounterId FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_COUNTER_SET_SOURCE =
PiCounterId.of("FabricIngress.process_set_source_sink.counter_set_source");
public static final PiCounterId FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_COUNTER_INT_SOURCE =
Expand All @@ -205,8 +201,6 @@ private FabricConstants() {
PiCounterId.of("FabricIngress.filtering.ingress_port_vlan_counter");
public static final PiCounterId FABRIC_INGRESS_FORWARDING_MPLS_COUNTER =
PiCounterId.of("FabricIngress.forwarding.mpls_counter");
public static final PiCounterId FABRIC_INGRESS_NEXT_HASHED_COUNTER =
PiCounterId.of("FabricIngress.next.hashed_counter");
// Action IDs
public static final PiActionId FABRIC_INGRESS_NEXT_SET_NEXT_ID_XCONNECT =
PiActionId.of("FabricIngress.next.set_next_id_xconnect");
Expand Down
Expand Up @@ -70,12 +70,18 @@ public abstract ObjectiveTranslation doTranslate(T obj)
public FlowRule flowRule(T obj, PiTableId tableId, TrafficSelector selector,
TrafficTreatment treatment)
throws FabricPipelinerException {
return flowRule(obj, tableId, selector, treatment, obj.priority());
}

public FlowRule flowRule(T obj, PiTableId tableId, TrafficSelector selector,
TrafficTreatment treatment, Integer priority)
throws FabricPipelinerException {
return DefaultFlowRule.builder()
.withSelector(selector)
.withTreatment(mapTreatmentToPiIfNeeded(treatment, tableId))
.forTable(tableId)
.makePermanent()
.withPriority(obj.priority())
.withPriority(priority)
.forDevice(deviceId)
.fromApp(obj.appId())
.build();
Expand Down
Expand Up @@ -17,7 +17,6 @@
package org.onosproject.pipelines.fabric.impl.behaviour.pipeliner;

import com.google.common.collect.Lists;
import org.onlab.packet.EthType;
import org.onlab.packet.Ethernet;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
Expand Down Expand Up @@ -60,6 +59,8 @@ class FilteringObjectiveTranslator
private static final byte[] ONE = new byte[]{1};
private static final byte[] ZERO = new byte[]{0};

private static final short ETH_TYPE_EXACT_MASK = (short) 0xFFFF;

private static final PiAction DENY = PiAction.builder()
.withId(FabricConstants.FABRIC_INGRESS_FILTERING_DENY)
.build();
Expand Down Expand Up @@ -163,7 +164,7 @@ private void fwdClassifierRules(
} else {
final MacAddress dstMac = ethDstCriterion.mac();
flowRules.addAll(ipFwdClassifierRules(inPort, dstMac, obj));
flowRules.add(mplsFwdClassifierRule(inPort, dstMac, obj));
flowRules.addAll(mplsFwdClassifierRules(inPort, dstMac, obj));
}

for (FlowRule f : flowRules) {
Expand Down Expand Up @@ -207,21 +208,58 @@ private Collection<FlowRule> ipFwdClassifierRules(
return flowRules;
}

private FlowRule mplsFwdClassifierRule(
private Collection<FlowRule> mplsFwdClassifierRules(
PortNumber inPort, MacAddress dstMac, FilteringObjective obj)
throws FabricPipelinerException {
return fwdClassifierRule(
inPort, Ethernet.MPLS_UNICAST, dstMac, null,
fwdClassifierTreatment(FWD_MPLS), obj);
// Forwarding classifier for MPLS is composed of 2 rules
// with higher priority wrt standard forwarding classifier rules,
// this is due to overlap on ternary matching.
TrafficTreatment treatment = fwdClassifierTreatment(FWD_MPLS);
final PiCriterion ethTypeMplsIpv4 = PiCriterion.builder()
.matchTernary(FabricConstants.HDR_ETH_TYPE,
Ethernet.MPLS_UNICAST, ETH_TYPE_EXACT_MASK)
.matchExact(FabricConstants.HDR_IP_ETH_TYPE,
Ethernet.TYPE_IPV4)
.build();
final TrafficSelector selectorMplsIpv4 = DefaultTrafficSelector.builder()
.matchInPort(inPort)
.matchPi(ethTypeMplsIpv4)
.matchEthDstMasked(dstMac, MacAddress.EXACT_MASK)
.build();

final PiCriterion ethTypeMplsIpv6 = PiCriterion.builder()
.matchTernary(FabricConstants.HDR_ETH_TYPE,
Ethernet.MPLS_UNICAST, ETH_TYPE_EXACT_MASK)
.matchExact(FabricConstants.HDR_IP_ETH_TYPE,
Ethernet.TYPE_IPV6)
.build();
final TrafficSelector selectorMplsIpv6 = DefaultTrafficSelector.builder()
.matchInPort(inPort)
.matchPi(ethTypeMplsIpv6)
.matchEthDstMasked(dstMac, MacAddress.EXACT_MASK)
.build();

return List.of(
flowRule(obj, FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER,
selectorMplsIpv4, treatment, obj.priority() + 1),
flowRule(obj, FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER,
selectorMplsIpv6, treatment, obj.priority() + 1)
);
}

private FlowRule fwdClassifierRule(
PortNumber inPort, short ethType, MacAddress dstMac, MacAddress dstMacMask,
TrafficTreatment treatment, FilteringObjective obj)
throws FabricPipelinerException {
// Match on ip_eth_type that is the eth_type of the L3 protocol.
// i.e., if the packet has an IP header, ip_eth_type should
// contain the corresponding eth_type (for IPv4 or IPv6)
final PiCriterion ethTypeCriterion = PiCriterion.builder()
.matchExact(FabricConstants.HDR_IP_ETH_TYPE, ethType)
.build();
final TrafficSelector selector = DefaultTrafficSelector.builder()
.matchInPort(inPort)
.matchPi(mapEthTypeFwdClassifier(ethType))
.matchPi(ethTypeCriterion)
.matchEthDstMasked(dstMac, dstMacMask == null
? MacAddress.EXACT_MASK : dstMacMask)
.build();
Expand All @@ -241,38 +279,4 @@ private TrafficTreatment fwdClassifierTreatment(byte fwdType) {
.build();

}

static PiCriterion mapEthTypeFwdClassifier(short ethType) {
// Map the Ethernet type to the validity bits of the fabric pipeline
switch (EthType.EtherType.lookup(ethType)) {
case IPV4: {
return PiCriterion.builder()
.matchExact(FabricConstants.HDR_IS_IPV4, ONE)
.matchExact(FabricConstants.HDR_IS_IPV6, ZERO)
.matchExact(FabricConstants.HDR_IS_MPLS, ZERO)
.build();
}
case IPV6: {
return PiCriterion.builder()
.matchExact(FabricConstants.HDR_IS_IPV4, ZERO)
.matchExact(FabricConstants.HDR_IS_IPV6, ONE)
.matchExact(FabricConstants.HDR_IS_MPLS, ZERO)
.build();
}
case MPLS_UNICAST: {
return PiCriterion.builder()
.matchExact(FabricConstants.HDR_IS_IPV4, ZERO)
.matchExact(FabricConstants.HDR_IS_IPV6, ZERO)
.matchExact(FabricConstants.HDR_IS_MPLS, ONE)
.build();
}
default: {
return PiCriterion.builder()
.matchExact(FabricConstants.HDR_IS_IPV4, ZERO)
.matchExact(FabricConstants.HDR_IS_IPV6, ZERO)
.matchExact(FabricConstants.HDR_IS_MPLS, ZERO)
.build();
}
}
}
}
4 changes: 2 additions & 2 deletions pipelines/fabric/impl/src/main/resources/Makefile
Expand Up @@ -7,7 +7,7 @@ fabric-spgw:
@./bmv2-compile.sh "fabric-spgw" "-DWITH_SPGW"

fabric-bng:
@./bmv2-compile.sh "fabric-bng" "-DWITH_BNG -DWITH_DOUBLE_VLAN_TERMINATION -DWITHOUT_XCONNECT"
@./bmv2-compile.sh "fabric-bng" "-DWITH_BNG -DWITHOUT_XCONNECT"

fabric-int:
@./bmv2-compile.sh "fabric-int" "-DWITH_INT_SOURCE -DWITH_INT_TRANSIT"
Expand All @@ -18,7 +18,7 @@ fabric-spgw-int:
fabric-full:
@./bmv2-compile.sh "fabric-full" " -DWITH_MULTICAST -DWITH_IPV6 \
-DWITH_SIMPLE_NEXT -DWITH_HASHED_NEXT -DWITH_BNG -DWITH_SPGW \
-DWITH_INT_SOURCE -DWITH_INT_TRANSIT -DWITH_INT_SINK -DWITH_DOUBLE_VLAN_TERMINATION"
-DWITH_INT_SOURCE -DWITH_INT_TRANSIT -DWITH_INT_SINK"

constants:
docker run -v $(ONOS_ROOT):/onos -w /onos/tools/dev/bin \
Expand Down
2 changes: 1 addition & 1 deletion pipelines/fabric/impl/src/main/resources/bmv2-compile.sh
Expand Up @@ -3,7 +3,7 @@
set -e

BMV2_CPU_PORT="255"
BMV2_PP_FLAGS="-DTARGET_BMV2 -DCPU_PORT=${BMV2_CPU_PORT} -DWITH_PORT_COUNTER"
BMV2_PP_FLAGS="-DTARGET_BMV2 -DCPU_PORT=${BMV2_CPU_PORT} -DWITH_PORT_COUNTER -DWITH_DEBUG"

PROFILE=$1
OTHER_PP_FLAGS=$2
Expand Down
11 changes: 5 additions & 6 deletions pipelines/fabric/impl/src/main/resources/include/bng.p4
Expand Up @@ -64,8 +64,7 @@ control bng_ingress_upstream(

@hidden
action term_enabled(bit<16> eth_type) {
hdr.inner_vlan_tag.eth_type = eth_type;
fmeta.last_eth_type = eth_type;
hdr.eth_type.value = eth_type;
hdr.pppoe.setInvalid();
c_terminated.count(fmeta.bng.line_id);
}
Expand Down Expand Up @@ -266,8 +265,8 @@ control bng_egress_downstream(

@hidden
action encap() {
// Here we add PPPoE and modify the inner_vlan_tag Ethernet Type.
hdr.inner_vlan_tag.eth_type = ETHERTYPE_PPPOES;
// Here we add PPPoE and modify the Ethernet Type.
hdr.eth_type.value = ETHERTYPE_PPPOES;
hdr.pppoe.setValid();
hdr.pppoe.version = 4w1;
hdr.pppoe.type_id = 4w1;
Expand Down Expand Up @@ -327,11 +326,11 @@ control bng_ingress(
c_tag : exact @name("c_tag");
}
actions = {
@defaultonly nop;
set_line;
}
size = BNG_MAX_SUBSC;
const default_action = nop;
// By default set the line ID to 0
const default_action = set_line(0);
}

apply {
Expand Down
Expand Up @@ -66,7 +66,7 @@ control Acl (inout parsed_headers_t hdr,
hdr.ethernet.dst_addr: ternary @name("eth_src"); // 48
hdr.ethernet.src_addr: ternary @name("eth_dst"); // 48
hdr.vlan_tag.vlan_id: ternary @name("vlan_id"); // 12
fabric_metadata.last_eth_type: ternary @name("eth_type"); //16
hdr.eth_type.value: ternary @name("eth_type"); //16
hdr.ipv4.src_addr: ternary @name("ipv4_src"); // 32
hdr.ipv4.dst_addr: ternary @name("ipv4_dst"); // 32
hdr.icmp.icmp_type: ternary @name("icmp_type"); // 8
Expand Down
Expand Up @@ -91,9 +91,8 @@ control Filtering (inout parsed_headers_t hdr,
key = {
standard_metadata.ingress_port : exact @name("ig_port");
hdr.ethernet.dst_addr : ternary @name("eth_dst");
fabric_metadata.is_ipv4 : exact @name("is_ipv4");
fabric_metadata.is_ipv6 : exact @name("is_ipv6");
fabric_metadata.is_mpls : exact @name("is_mpls");
hdr.eth_type.value : ternary @name("eth_type");
fabric_metadata.ip_eth_type : exact @name("ip_eth_type");
}
actions = {
set_forwarding_type;
Expand Down Expand Up @@ -126,22 +125,6 @@ control Filtering (inout parsed_headers_t hdr,
fabric_metadata.mpls_ttl = DEFAULT_MPLS_TTL + 1;
}

// Set last_eth_type checking the validity of the L2.5 headers
if (hdr.mpls.isValid()) {
fabric_metadata.last_eth_type = ETHERTYPE_MPLS;
} else {
if (hdr.vlan_tag.isValid()) {
#if defined(WITH_XCONNECT) || defined(WITH_BNG) || defined(WITH_DOUBLE_VLAN_TERMINATION)
if(hdr.inner_vlan_tag.isValid()) {
fabric_metadata.last_eth_type = hdr.inner_vlan_tag.eth_type;
} else
#endif // WITH_XCONNECT || WITH_BNG || WITH_DOUBLE_VLAN_TERMINATION
fabric_metadata.last_eth_type = hdr.vlan_tag.eth_type;
} else {
fabric_metadata.last_eth_type = hdr.ethernet.eth_type;
}
}

ingress_port_vlan.apply();
fwd_classifier.apply();
}
Expand Down
Expand Up @@ -84,15 +84,22 @@ control Forwarding (inout parsed_headers_t hdr,
/*
* IPv4 Routing Table.
*/
#ifdef WTIH_DEBUG
direct_counter(CounterType.packets_and_bytes) routing_v4_counter;
#endif // WITH_DEBUG

action set_next_id_routing_v4(next_id_t next_id) {
set_next_id(next_id);
#ifdef WTIH_DEBUG
routing_v4_counter.count();
#endif // WITH_DEBUG
}

action nop_routing_v4() {
// no-op
#ifdef WTIH_DEBUG
routing_v4_counter.count();
#endif // WITH_DEBUG
}

#ifdef _ROUTING_V4_TABLE_ANNOT
Expand All @@ -108,7 +115,9 @@ control Forwarding (inout parsed_headers_t hdr,
@defaultonly nop;
}
const default_action = nop();
#ifdef WTIH_DEBUG
counters = routing_v4_counter;
#endif // WITH_DEBUG
size = ROUTING_V4_TABLE_SIZE;
}

Expand Down

0 comments on commit 5a2de71

Please sign in to comment.