Skip to content

Commit 5a2de71

Browse files
daniele-moroccascone
authored andcommitted
eth_type moved outside ethernet header in fabric.p4
Change-Id: I3ae0813c5e8aba48767d5bb235fbbcfb75954010 (cherry picked from commit 693d76f)
1 parent 71ba99f commit 5a2de71

File tree

27 files changed

+5589
-8290
lines changed

27 files changed

+5589
-8290
lines changed

pipelines/fabric/impl/src/main/java/org/onosproject/pipelines/fabric/impl/behaviour/FabricConstants.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import org.onosproject.net.pi.model.PiActionId;
2020
import org.onosproject.net.pi.model.PiActionParamId;
2121
import org.onosproject.net.pi.model.PiActionProfileId;
22-
import org.onosproject.net.pi.model.PiCounterId;
23-
import org.onosproject.net.pi.model.PiMatchFieldId;
2422
import org.onosproject.net.pi.model.PiMeterId;
2523
import org.onosproject.net.pi.model.PiPacketMetadataId;
24+
import org.onosproject.net.pi.model.PiCounterId;
25+
import org.onosproject.net.pi.model.PiMatchFieldId;
2626
import org.onosproject.net.pi.model.PiTableId;
2727
/**
2828
* Constants for fabric pipeline.
@@ -38,17 +38,13 @@ private FabricConstants() {
3838
PiMatchFieldId.of("ig_port");
3939
public static final PiMatchFieldId HDR_VLAN_IS_VALID =
4040
PiMatchFieldId.of("vlan_is_valid");
41-
public static final PiMatchFieldId HDR_EG_PORT =
42-
PiMatchFieldId.of("eg_port");
4341
public static final PiMatchFieldId HDR_IPV6_SRC_NET_ID =
4442
PiMatchFieldId.of("ipv6_src_net_id");
4543
public static final PiMatchFieldId HDR_C_TAG = PiMatchFieldId.of("c_tag");
4644
public static final PiMatchFieldId HDR_IPV4_SRC =
4745
PiMatchFieldId.of("ipv4_src");
4846
public static final PiMatchFieldId HDR_IPV6_DST =
4947
PiMatchFieldId.of("ipv6_dst");
50-
public static final PiMatchFieldId HDR_IS_MPLS =
51-
PiMatchFieldId.of("is_mpls");
5248
public static final PiMatchFieldId HDR_L4_DPORT =
5349
PiMatchFieldId.of("l4_dport");
5450
public static final PiMatchFieldId HDR_PPPOE_CODE =
@@ -72,6 +68,8 @@ private FabricConstants() {
7268
PiMatchFieldId.of("eth_type");
7369
public static final PiMatchFieldId HDR_NEXT_ID =
7470
PiMatchFieldId.of("next_id");
71+
public static final PiMatchFieldId HDR_IP_ETH_TYPE =
72+
PiMatchFieldId.of("ip_eth_type");
7573
public static final PiMatchFieldId HDR_L4_SPORT =
7674
PiMatchFieldId.of("l4_sport");
7775
public static final PiMatchFieldId HDR_ICMP_CODE =
@@ -88,10 +86,8 @@ private FabricConstants() {
8886
PiMatchFieldId.of("line_id");
8987
public static final PiMatchFieldId HDR_IPV4_DSCP =
9088
PiMatchFieldId.of("ipv4_dscp");
91-
public static final PiMatchFieldId HDR_IS_IPV4 =
92-
PiMatchFieldId.of("is_ipv4");
93-
public static final PiMatchFieldId HDR_IS_IPV6 =
94-
PiMatchFieldId.of("is_ipv6");
89+
public static final PiMatchFieldId HDR_EG_PORT =
90+
PiMatchFieldId.of("eg_port");
9591
public static final PiMatchFieldId HDR_GTP_IPV4_DST =
9692
PiMatchFieldId.of("gtp_ipv4_dst");
9793
public static final PiMatchFieldId HDR_INT_IS_VALID =
@@ -181,8 +177,8 @@ private FabricConstants() {
181177
PiCounterId.of("FabricIngress.filtering.fwd_classifier_counter");
182178
public static final PiCounterId FABRIC_INGRESS_FORWARDING_BRIDGING_COUNTER =
183179
PiCounterId.of("FabricIngress.forwarding.bridging_counter");
184-
public static final PiCounterId FABRIC_INGRESS_FORWARDING_ROUTING_V4_COUNTER =
185-
PiCounterId.of("FabricIngress.forwarding.routing_v4_counter");
180+
public static final PiCounterId FABRIC_INGRESS_NEXT_HASHED_COUNTER =
181+
PiCounterId.of("FabricIngress.next.hashed_counter");
186182
public static final PiCounterId FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_COUNTER_SET_SOURCE =
187183
PiCounterId.of("FabricIngress.process_set_source_sink.counter_set_source");
188184
public static final PiCounterId FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_COUNTER_INT_SOURCE =
@@ -205,8 +201,6 @@ private FabricConstants() {
205201
PiCounterId.of("FabricIngress.filtering.ingress_port_vlan_counter");
206202
public static final PiCounterId FABRIC_INGRESS_FORWARDING_MPLS_COUNTER =
207203
PiCounterId.of("FabricIngress.forwarding.mpls_counter");
208-
public static final PiCounterId FABRIC_INGRESS_NEXT_HASHED_COUNTER =
209-
PiCounterId.of("FabricIngress.next.hashed_counter");
210204
// Action IDs
211205
public static final PiActionId FABRIC_INGRESS_NEXT_SET_NEXT_ID_XCONNECT =
212206
PiActionId.of("FabricIngress.next.set_next_id_xconnect");

pipelines/fabric/impl/src/main/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/AbstractObjectiveTranslator.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,18 @@ public abstract ObjectiveTranslation doTranslate(T obj)
7070
public FlowRule flowRule(T obj, PiTableId tableId, TrafficSelector selector,
7171
TrafficTreatment treatment)
7272
throws FabricPipelinerException {
73+
return flowRule(obj, tableId, selector, treatment, obj.priority());
74+
}
75+
76+
public FlowRule flowRule(T obj, PiTableId tableId, TrafficSelector selector,
77+
TrafficTreatment treatment, Integer priority)
78+
throws FabricPipelinerException {
7379
return DefaultFlowRule.builder()
7480
.withSelector(selector)
7581
.withTreatment(mapTreatmentToPiIfNeeded(treatment, tableId))
7682
.forTable(tableId)
7783
.makePermanent()
78-
.withPriority(obj.priority())
84+
.withPriority(priority)
7985
.forDevice(deviceId)
8086
.fromApp(obj.appId())
8187
.build();

pipelines/fabric/impl/src/main/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/FilteringObjectiveTranslator.java

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.onosproject.pipelines.fabric.impl.behaviour.pipeliner;
1818

1919
import com.google.common.collect.Lists;
20-
import org.onlab.packet.EthType;
2120
import org.onlab.packet.Ethernet;
2221
import org.onlab.packet.MacAddress;
2322
import org.onlab.packet.VlanId;
@@ -60,6 +59,8 @@ class FilteringObjectiveTranslator
6059
private static final byte[] ONE = new byte[]{1};
6160
private static final byte[] ZERO = new byte[]{0};
6261

62+
private static final short ETH_TYPE_EXACT_MASK = (short) 0xFFFF;
63+
6364
private static final PiAction DENY = PiAction.builder()
6465
.withId(FabricConstants.FABRIC_INGRESS_FILTERING_DENY)
6566
.build();
@@ -163,7 +164,7 @@ private void fwdClassifierRules(
163164
} else {
164165
final MacAddress dstMac = ethDstCriterion.mac();
165166
flowRules.addAll(ipFwdClassifierRules(inPort, dstMac, obj));
166-
flowRules.add(mplsFwdClassifierRule(inPort, dstMac, obj));
167+
flowRules.addAll(mplsFwdClassifierRules(inPort, dstMac, obj));
167168
}
168169

169170
for (FlowRule f : flowRules) {
@@ -207,21 +208,58 @@ private Collection<FlowRule> ipFwdClassifierRules(
207208
return flowRules;
208209
}
209210

210-
private FlowRule mplsFwdClassifierRule(
211+
private Collection<FlowRule> mplsFwdClassifierRules(
211212
PortNumber inPort, MacAddress dstMac, FilteringObjective obj)
212213
throws FabricPipelinerException {
213-
return fwdClassifierRule(
214-
inPort, Ethernet.MPLS_UNICAST, dstMac, null,
215-
fwdClassifierTreatment(FWD_MPLS), obj);
214+
// Forwarding classifier for MPLS is composed of 2 rules
215+
// with higher priority wrt standard forwarding classifier rules,
216+
// this is due to overlap on ternary matching.
217+
TrafficTreatment treatment = fwdClassifierTreatment(FWD_MPLS);
218+
final PiCriterion ethTypeMplsIpv4 = PiCriterion.builder()
219+
.matchTernary(FabricConstants.HDR_ETH_TYPE,
220+
Ethernet.MPLS_UNICAST, ETH_TYPE_EXACT_MASK)
221+
.matchExact(FabricConstants.HDR_IP_ETH_TYPE,
222+
Ethernet.TYPE_IPV4)
223+
.build();
224+
final TrafficSelector selectorMplsIpv4 = DefaultTrafficSelector.builder()
225+
.matchInPort(inPort)
226+
.matchPi(ethTypeMplsIpv4)
227+
.matchEthDstMasked(dstMac, MacAddress.EXACT_MASK)
228+
.build();
229+
230+
final PiCriterion ethTypeMplsIpv6 = PiCriterion.builder()
231+
.matchTernary(FabricConstants.HDR_ETH_TYPE,
232+
Ethernet.MPLS_UNICAST, ETH_TYPE_EXACT_MASK)
233+
.matchExact(FabricConstants.HDR_IP_ETH_TYPE,
234+
Ethernet.TYPE_IPV6)
235+
.build();
236+
final TrafficSelector selectorMplsIpv6 = DefaultTrafficSelector.builder()
237+
.matchInPort(inPort)
238+
.matchPi(ethTypeMplsIpv6)
239+
.matchEthDstMasked(dstMac, MacAddress.EXACT_MASK)
240+
.build();
241+
242+
return List.of(
243+
flowRule(obj, FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER,
244+
selectorMplsIpv4, treatment, obj.priority() + 1),
245+
flowRule(obj, FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER,
246+
selectorMplsIpv6, treatment, obj.priority() + 1)
247+
);
216248
}
217249

218250
private FlowRule fwdClassifierRule(
219251
PortNumber inPort, short ethType, MacAddress dstMac, MacAddress dstMacMask,
220252
TrafficTreatment treatment, FilteringObjective obj)
221253
throws FabricPipelinerException {
254+
// Match on ip_eth_type that is the eth_type of the L3 protocol.
255+
// i.e., if the packet has an IP header, ip_eth_type should
256+
// contain the corresponding eth_type (for IPv4 or IPv6)
257+
final PiCriterion ethTypeCriterion = PiCriterion.builder()
258+
.matchExact(FabricConstants.HDR_IP_ETH_TYPE, ethType)
259+
.build();
222260
final TrafficSelector selector = DefaultTrafficSelector.builder()
223261
.matchInPort(inPort)
224-
.matchPi(mapEthTypeFwdClassifier(ethType))
262+
.matchPi(ethTypeCriterion)
225263
.matchEthDstMasked(dstMac, dstMacMask == null
226264
? MacAddress.EXACT_MASK : dstMacMask)
227265
.build();
@@ -241,38 +279,4 @@ private TrafficTreatment fwdClassifierTreatment(byte fwdType) {
241279
.build();
242280

243281
}
244-
245-
static PiCriterion mapEthTypeFwdClassifier(short ethType) {
246-
// Map the Ethernet type to the validity bits of the fabric pipeline
247-
switch (EthType.EtherType.lookup(ethType)) {
248-
case IPV4: {
249-
return PiCriterion.builder()
250-
.matchExact(FabricConstants.HDR_IS_IPV4, ONE)
251-
.matchExact(FabricConstants.HDR_IS_IPV6, ZERO)
252-
.matchExact(FabricConstants.HDR_IS_MPLS, ZERO)
253-
.build();
254-
}
255-
case IPV6: {
256-
return PiCriterion.builder()
257-
.matchExact(FabricConstants.HDR_IS_IPV4, ZERO)
258-
.matchExact(FabricConstants.HDR_IS_IPV6, ONE)
259-
.matchExact(FabricConstants.HDR_IS_MPLS, ZERO)
260-
.build();
261-
}
262-
case MPLS_UNICAST: {
263-
return PiCriterion.builder()
264-
.matchExact(FabricConstants.HDR_IS_IPV4, ZERO)
265-
.matchExact(FabricConstants.HDR_IS_IPV6, ZERO)
266-
.matchExact(FabricConstants.HDR_IS_MPLS, ONE)
267-
.build();
268-
}
269-
default: {
270-
return PiCriterion.builder()
271-
.matchExact(FabricConstants.HDR_IS_IPV4, ZERO)
272-
.matchExact(FabricConstants.HDR_IS_IPV6, ZERO)
273-
.matchExact(FabricConstants.HDR_IS_MPLS, ZERO)
274-
.build();
275-
}
276-
}
277-
}
278282
}

pipelines/fabric/impl/src/main/resources/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fabric-spgw:
77
@./bmv2-compile.sh "fabric-spgw" "-DWITH_SPGW"
88

99
fabric-bng:
10-
@./bmv2-compile.sh "fabric-bng" "-DWITH_BNG -DWITH_DOUBLE_VLAN_TERMINATION -DWITHOUT_XCONNECT"
10+
@./bmv2-compile.sh "fabric-bng" "-DWITH_BNG -DWITHOUT_XCONNECT"
1111

1212
fabric-int:
1313
@./bmv2-compile.sh "fabric-int" "-DWITH_INT_SOURCE -DWITH_INT_TRANSIT"
@@ -18,7 +18,7 @@ fabric-spgw-int:
1818
fabric-full:
1919
@./bmv2-compile.sh "fabric-full" " -DWITH_MULTICAST -DWITH_IPV6 \
2020
-DWITH_SIMPLE_NEXT -DWITH_HASHED_NEXT -DWITH_BNG -DWITH_SPGW \
21-
-DWITH_INT_SOURCE -DWITH_INT_TRANSIT -DWITH_INT_SINK -DWITH_DOUBLE_VLAN_TERMINATION"
21+
-DWITH_INT_SOURCE -DWITH_INT_TRANSIT -DWITH_INT_SINK"
2222

2323
constants:
2424
docker run -v $(ONOS_ROOT):/onos -w /onos/tools/dev/bin \

pipelines/fabric/impl/src/main/resources/bmv2-compile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
BMV2_CPU_PORT="255"
6-
BMV2_PP_FLAGS="-DTARGET_BMV2 -DCPU_PORT=${BMV2_CPU_PORT} -DWITH_PORT_COUNTER"
6+
BMV2_PP_FLAGS="-DTARGET_BMV2 -DCPU_PORT=${BMV2_CPU_PORT} -DWITH_PORT_COUNTER -DWITH_DEBUG"
77

88
PROFILE=$1
99
OTHER_PP_FLAGS=$2

pipelines/fabric/impl/src/main/resources/include/bng.p4

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ control bng_ingress_upstream(
6464

6565
@hidden
6666
action term_enabled(bit<16> eth_type) {
67-
hdr.inner_vlan_tag.eth_type = eth_type;
68-
fmeta.last_eth_type = eth_type;
67+
hdr.eth_type.value = eth_type;
6968
hdr.pppoe.setInvalid();
7069
c_terminated.count(fmeta.bng.line_id);
7170
}
@@ -266,8 +265,8 @@ control bng_egress_downstream(
266265

267266
@hidden
268267
action encap() {
269-
// Here we add PPPoE and modify the inner_vlan_tag Ethernet Type.
270-
hdr.inner_vlan_tag.eth_type = ETHERTYPE_PPPOES;
268+
// Here we add PPPoE and modify the Ethernet Type.
269+
hdr.eth_type.value = ETHERTYPE_PPPOES;
271270
hdr.pppoe.setValid();
272271
hdr.pppoe.version = 4w1;
273272
hdr.pppoe.type_id = 4w1;
@@ -327,11 +326,11 @@ control bng_ingress(
327326
c_tag : exact @name("c_tag");
328327
}
329328
actions = {
330-
@defaultonly nop;
331329
set_line;
332330
}
333331
size = BNG_MAX_SUBSC;
334-
const default_action = nop;
332+
// By default set the line ID to 0
333+
const default_action = set_line(0);
335334
}
336335

337336
apply {

pipelines/fabric/impl/src/main/resources/include/control/acl.p4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ control Acl (inout parsed_headers_t hdr,
6666
hdr.ethernet.dst_addr: ternary @name("eth_src"); // 48
6767
hdr.ethernet.src_addr: ternary @name("eth_dst"); // 48
6868
hdr.vlan_tag.vlan_id: ternary @name("vlan_id"); // 12
69-
fabric_metadata.last_eth_type: ternary @name("eth_type"); //16
69+
hdr.eth_type.value: ternary @name("eth_type"); //16
7070
hdr.ipv4.src_addr: ternary @name("ipv4_src"); // 32
7171
hdr.ipv4.dst_addr: ternary @name("ipv4_dst"); // 32
7272
hdr.icmp.icmp_type: ternary @name("icmp_type"); // 8

pipelines/fabric/impl/src/main/resources/include/control/filtering.p4

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ control Filtering (inout parsed_headers_t hdr,
9191
key = {
9292
standard_metadata.ingress_port : exact @name("ig_port");
9393
hdr.ethernet.dst_addr : ternary @name("eth_dst");
94-
fabric_metadata.is_ipv4 : exact @name("is_ipv4");
95-
fabric_metadata.is_ipv6 : exact @name("is_ipv6");
96-
fabric_metadata.is_mpls : exact @name("is_mpls");
94+
hdr.eth_type.value : ternary @name("eth_type");
95+
fabric_metadata.ip_eth_type : exact @name("ip_eth_type");
9796
}
9897
actions = {
9998
set_forwarding_type;
@@ -126,22 +125,6 @@ control Filtering (inout parsed_headers_t hdr,
126125
fabric_metadata.mpls_ttl = DEFAULT_MPLS_TTL + 1;
127126
}
128127

129-
// Set last_eth_type checking the validity of the L2.5 headers
130-
if (hdr.mpls.isValid()) {
131-
fabric_metadata.last_eth_type = ETHERTYPE_MPLS;
132-
} else {
133-
if (hdr.vlan_tag.isValid()) {
134-
#if defined(WITH_XCONNECT) || defined(WITH_BNG) || defined(WITH_DOUBLE_VLAN_TERMINATION)
135-
if(hdr.inner_vlan_tag.isValid()) {
136-
fabric_metadata.last_eth_type = hdr.inner_vlan_tag.eth_type;
137-
} else
138-
#endif // WITH_XCONNECT || WITH_BNG || WITH_DOUBLE_VLAN_TERMINATION
139-
fabric_metadata.last_eth_type = hdr.vlan_tag.eth_type;
140-
} else {
141-
fabric_metadata.last_eth_type = hdr.ethernet.eth_type;
142-
}
143-
}
144-
145128
ingress_port_vlan.apply();
146129
fwd_classifier.apply();
147130
}

pipelines/fabric/impl/src/main/resources/include/control/forwarding.p4

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,22 @@ control Forwarding (inout parsed_headers_t hdr,
8484
/*
8585
* IPv4 Routing Table.
8686
*/
87+
#ifdef WTIH_DEBUG
8788
direct_counter(CounterType.packets_and_bytes) routing_v4_counter;
89+
#endif // WITH_DEBUG
8890

8991
action set_next_id_routing_v4(next_id_t next_id) {
9092
set_next_id(next_id);
93+
#ifdef WTIH_DEBUG
9194
routing_v4_counter.count();
95+
#endif // WITH_DEBUG
9296
}
9397

9498
action nop_routing_v4() {
99+
// no-op
100+
#ifdef WTIH_DEBUG
95101
routing_v4_counter.count();
102+
#endif // WITH_DEBUG
96103
}
97104

98105
#ifdef _ROUTING_V4_TABLE_ANNOT
@@ -108,7 +115,9 @@ control Forwarding (inout parsed_headers_t hdr,
108115
@defaultonly nop;
109116
}
110117
const default_action = nop();
118+
#ifdef WTIH_DEBUG
111119
counters = routing_v4_counter;
120+
#endif // WITH_DEBUG
112121
size = ROUTING_V4_TABLE_SIZE;
113122
}
114123

0 commit comments

Comments
 (0)