blob: 65e3a2583b5dcbe70c0d783b54600580d29602f7 [file] [log] [blame]
Yi Tseng0b809722017-11-03 10:23:26 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.pipelines.fabric.pipeliner;
18
19import com.google.common.collect.ImmutableMap;
20import com.google.common.collect.ImmutableSet;
21import com.google.common.collect.Sets;
Esin Karaman971fb7f2017-12-28 13:44:52 +000022import org.onlab.packet.MacAddress;
Yi Tseng0b809722017-11-03 10:23:26 -070023import org.onosproject.net.flow.criteria.Criterion;
Esin Karaman971fb7f2017-12-28 13:44:52 +000024import org.onosproject.net.flow.criteria.EthCriterion;
Yi Tseng0b809722017-11-03 10:23:26 -070025import org.onosproject.net.flowobjective.ForwardingObjective;
26
27import java.util.Map;
28import java.util.Set;
29
30import static org.onosproject.net.flow.criteria.Criterion.Type.ETH_DST;
31import static org.onosproject.net.flow.criteria.Criterion.Type.ETH_TYPE;
32import static org.onosproject.net.flow.criteria.Criterion.Type.IPV4_DST;
33import static org.onosproject.net.flow.criteria.Criterion.Type.IPV6_DST;
34import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_BOS;
35import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL;
36import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID;
37
38public enum ForwardingFunctionType {
39 /**
40 * L2 unicast, with vlan id + mac address criterion.
41 */
42 L2_UNICAST,
43
44 /**
45 * L2 broadcast, with vlan id criterion only.
46 */
47 L2_BROADCAST,
48
49 /**
50 * IPv4 unicast, with EtherType and IPv4 unicast destination address.
51 */
Charles Chan384aea22018-08-23 22:08:02 -070052 IPV4_ROUTING,
Yi Tseng0b809722017-11-03 10:23:26 -070053
54 /**
55 * IPv6 unicast, with EtherType and IPv6 unicast destination address.
56 */
Charles Chan384aea22018-08-23 22:08:02 -070057 IPV6_ROUTING,
Yi Tseng0b809722017-11-03 10:23:26 -070058
59 /**
Yi Tseng1b154bd2017-11-20 17:48:19 -080060 * MPLS, with EtherType, MPLS label and MPLS BOS(true) criterion.
Yi Tseng0b809722017-11-03 10:23:26 -070061 */
62 MPLS,
63
64 /**
Yi Tseng1b154bd2017-11-20 17:48:19 -080065 * Pseudo-wire, with EtherType, MPLS label and MPLS BOS(false) criterion.
66 */
67 PW,
68
69 /**
Yi Tseng0b809722017-11-03 10:23:26 -070070 * Unsupported type.
71 */
72 UNSUPPORTED;
73
74 // Different criteria combinations for different FFT
75 private static final Set<Criterion.Type> L2_UNI_CRITERIA_TYPE =
76 ImmutableSet.of(VLAN_VID, ETH_DST);
77 private static final Set<Criterion.Type> L2_BRC_CRITERIA_TYPE =
78 ImmutableSet.of(VLAN_VID);
79 private static final Set<Criterion.Type> IPV4_UNI_CRITERIA_TYPE =
80 ImmutableSet.of(ETH_TYPE, IPV4_DST);
81 private static final Set<Criterion.Type> IPV4_MCAST_CRITERIA_TYPE =
82 ImmutableSet.of(ETH_TYPE, VLAN_VID, IPV4_DST);
83 private static final Set<Criterion.Type> IPV6_UNI_CRITERIA_TYPE =
84 ImmutableSet.of(ETH_TYPE, IPV6_DST);
85 private static final Set<Criterion.Type> IPV6_MCAST_CRITERIA_TYPE =
86 ImmutableSet.of(ETH_TYPE, VLAN_VID, IPV6_DST);
87 private static final Set<Criterion.Type> MPLS_UNI_CRITERIA_TYPE =
88 ImmutableSet.of(ETH_TYPE, MPLS_LABEL, MPLS_BOS);
89
90 private static final Map<Set<Criterion.Type>, ForwardingFunctionType> FFT_MAP =
91 ImmutableMap.<Set<Criterion.Type>, ForwardingFunctionType>builder()
92 .put(L2_UNI_CRITERIA_TYPE, L2_UNICAST)
93 .put(L2_BRC_CRITERIA_TYPE, L2_BROADCAST)
Charles Chan384aea22018-08-23 22:08:02 -070094 .put(IPV4_UNI_CRITERIA_TYPE, IPV4_ROUTING)
95 .put(IPV4_MCAST_CRITERIA_TYPE, IPV4_ROUTING)
96 .put(IPV6_UNI_CRITERIA_TYPE, IPV6_ROUTING)
97 .put(IPV6_MCAST_CRITERIA_TYPE, IPV6_ROUTING)
Yi Tseng0b809722017-11-03 10:23:26 -070098 .put(MPLS_UNI_CRITERIA_TYPE, MPLS)
99 .build();
100
101 /**
102 * Gets forwarding function type of the forwarding objective.
103 *
104 * @param fwd the forwarding objective
105 * @return forwarding function type of the forwarding objective
106 */
107 public static ForwardingFunctionType getForwardingFunctionType(ForwardingObjective fwd) {
108 Set<Criterion.Type> criteriaType = Sets.newHashSet();
Esin Karaman971fb7f2017-12-28 13:44:52 +0000109 //omit the criterion of ethDst type with the value of MacAddress.NONE since it indicates L2 broadcast
110 //if not, the objective is treated as L2 unicast
111 fwd.selector().criteria().stream().filter(criterion -> !ethDstIndicatesBroadcast(criterion))
112 .map(Criterion::type)
Yi Tseng0b809722017-11-03 10:23:26 -0700113 .forEach(criteriaType::add);
114
115 if (fwd.meta() != null) {
Esin Karaman971fb7f2017-12-28 13:44:52 +0000116 fwd.meta().criteria().stream().filter(criterion -> !ethDstIndicatesBroadcast(criterion))
117 .map(Criterion::type)
Yi Tseng0b809722017-11-03 10:23:26 -0700118 .forEach(criteriaType::add);
119 }
120
121 return FFT_MAP.getOrDefault(criteriaType, UNSUPPORTED);
122 }
Esin Karaman971fb7f2017-12-28 13:44:52 +0000123
124 /**
125 * Segment Routing (SR) app. sets ethDst criterion to MacAddress.NONE for broadcast rules
126 * and demands drivers to treat the flow rules containing this criterion as broadcast rule.
127 *
128 * This method checks the type and value of the criterion and detects whether it constitutes
129 * broadcast or not.
130 *
131 * For more details check RoutingRulePopulator.updateSubnetBroadcastRule method of SR app.
132 *
133 * @param criterion Criterion object
134 * @return true if the type is ETH_DST and the mac value equals to MacAddress.NONE; false otherwise.
135 */
136 private static boolean ethDstIndicatesBroadcast(Criterion criterion) {
137 return criterion.type().equals(Criterion.Type.ETH_DST) &&
138 ((EthCriterion) criterion).mac().equals(MacAddress.NONE);
139 }
Yi Tseng0b809722017-11-03 10:23:26 -0700140}