Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.pipelines.fabric.pipeliner; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableMap; |
| 20 | import com.google.common.collect.ImmutableSet; |
| 21 | import com.google.common.collect.Sets; |
Esin Karaman | 971fb7f | 2017-12-28 13:44:52 +0000 | [diff] [blame] | 22 | import org.onlab.packet.MacAddress; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 23 | import org.onosproject.net.flow.criteria.Criterion; |
Esin Karaman | 971fb7f | 2017-12-28 13:44:52 +0000 | [diff] [blame] | 24 | import org.onosproject.net.flow.criteria.EthCriterion; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 25 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 26 | |
| 27 | import java.util.Map; |
| 28 | import java.util.Set; |
| 29 | |
| 30 | import static org.onosproject.net.flow.criteria.Criterion.Type.ETH_DST; |
| 31 | import static org.onosproject.net.flow.criteria.Criterion.Type.ETH_TYPE; |
| 32 | import static org.onosproject.net.flow.criteria.Criterion.Type.IPV4_DST; |
| 33 | import static org.onosproject.net.flow.criteria.Criterion.Type.IPV6_DST; |
| 34 | import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_BOS; |
| 35 | import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL; |
| 36 | import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID; |
| 37 | |
| 38 | public 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 | */ |
| 52 | IPV4_UNICAST, |
| 53 | |
| 54 | /** |
| 55 | * IPv4 multicast, with EtherType and IPv4 multicast destination address. |
| 56 | */ |
| 57 | IPV4_MULTICAST, |
| 58 | |
| 59 | /** |
| 60 | * IPv6 unicast, with EtherType and IPv6 unicast destination address. |
| 61 | */ |
| 62 | IPV6_UNICAST, |
| 63 | |
| 64 | /** |
| 65 | * IPv6 multicast, with EtherType and IPv6 multicast destination address. |
| 66 | */ |
| 67 | IPV6_MULTICAST, |
| 68 | |
| 69 | /** |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 70 | * MPLS, with EtherType, MPLS label and MPLS BOS(true) criterion. |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 71 | */ |
| 72 | MPLS, |
| 73 | |
| 74 | /** |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 75 | * Pseudo-wire, with EtherType, MPLS label and MPLS BOS(false) criterion. |
| 76 | */ |
| 77 | PW, |
| 78 | |
| 79 | /** |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 80 | * Unsupported type. |
| 81 | */ |
| 82 | UNSUPPORTED; |
| 83 | |
| 84 | // Different criteria combinations for different FFT |
| 85 | private static final Set<Criterion.Type> L2_UNI_CRITERIA_TYPE = |
| 86 | ImmutableSet.of(VLAN_VID, ETH_DST); |
| 87 | private static final Set<Criterion.Type> L2_BRC_CRITERIA_TYPE = |
| 88 | ImmutableSet.of(VLAN_VID); |
| 89 | private static final Set<Criterion.Type> IPV4_UNI_CRITERIA_TYPE = |
| 90 | ImmutableSet.of(ETH_TYPE, IPV4_DST); |
| 91 | private static final Set<Criterion.Type> IPV4_MCAST_CRITERIA_TYPE = |
| 92 | ImmutableSet.of(ETH_TYPE, VLAN_VID, IPV4_DST); |
| 93 | private static final Set<Criterion.Type> IPV6_UNI_CRITERIA_TYPE = |
| 94 | ImmutableSet.of(ETH_TYPE, IPV6_DST); |
| 95 | private static final Set<Criterion.Type> IPV6_MCAST_CRITERIA_TYPE = |
| 96 | ImmutableSet.of(ETH_TYPE, VLAN_VID, IPV6_DST); |
| 97 | private static final Set<Criterion.Type> MPLS_UNI_CRITERIA_TYPE = |
| 98 | ImmutableSet.of(ETH_TYPE, MPLS_LABEL, MPLS_BOS); |
| 99 | |
| 100 | private static final Map<Set<Criterion.Type>, ForwardingFunctionType> FFT_MAP = |
| 101 | ImmutableMap.<Set<Criterion.Type>, ForwardingFunctionType>builder() |
| 102 | .put(L2_UNI_CRITERIA_TYPE, L2_UNICAST) |
| 103 | .put(L2_BRC_CRITERIA_TYPE, L2_BROADCAST) |
| 104 | .put(IPV4_UNI_CRITERIA_TYPE, IPV4_UNICAST) |
| 105 | .put(IPV4_MCAST_CRITERIA_TYPE, IPV4_MULTICAST) |
| 106 | .put(IPV6_UNI_CRITERIA_TYPE, IPV6_UNICAST) |
| 107 | .put(IPV6_MCAST_CRITERIA_TYPE, IPV6_MULTICAST) |
| 108 | .put(MPLS_UNI_CRITERIA_TYPE, MPLS) |
| 109 | .build(); |
| 110 | |
| 111 | /** |
| 112 | * Gets forwarding function type of the forwarding objective. |
| 113 | * |
| 114 | * @param fwd the forwarding objective |
| 115 | * @return forwarding function type of the forwarding objective |
| 116 | */ |
| 117 | public static ForwardingFunctionType getForwardingFunctionType(ForwardingObjective fwd) { |
| 118 | Set<Criterion.Type> criteriaType = Sets.newHashSet(); |
Esin Karaman | 971fb7f | 2017-12-28 13:44:52 +0000 | [diff] [blame] | 119 | //omit the criterion of ethDst type with the value of MacAddress.NONE since it indicates L2 broadcast |
| 120 | //if not, the objective is treated as L2 unicast |
| 121 | fwd.selector().criteria().stream().filter(criterion -> !ethDstIndicatesBroadcast(criterion)) |
| 122 | .map(Criterion::type) |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 123 | .forEach(criteriaType::add); |
| 124 | |
| 125 | if (fwd.meta() != null) { |
Esin Karaman | 971fb7f | 2017-12-28 13:44:52 +0000 | [diff] [blame] | 126 | fwd.meta().criteria().stream().filter(criterion -> !ethDstIndicatesBroadcast(criterion)) |
| 127 | .map(Criterion::type) |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 128 | .forEach(criteriaType::add); |
| 129 | } |
| 130 | |
| 131 | return FFT_MAP.getOrDefault(criteriaType, UNSUPPORTED); |
| 132 | } |
Esin Karaman | 971fb7f | 2017-12-28 13:44:52 +0000 | [diff] [blame] | 133 | |
| 134 | /** |
| 135 | * Segment Routing (SR) app. sets ethDst criterion to MacAddress.NONE for broadcast rules |
| 136 | * and demands drivers to treat the flow rules containing this criterion as broadcast rule. |
| 137 | * |
| 138 | * This method checks the type and value of the criterion and detects whether it constitutes |
| 139 | * broadcast or not. |
| 140 | * |
| 141 | * For more details check RoutingRulePopulator.updateSubnetBroadcastRule method of SR app. |
| 142 | * |
| 143 | * @param criterion Criterion object |
| 144 | * @return true if the type is ETH_DST and the mac value equals to MacAddress.NONE; false otherwise. |
| 145 | */ |
| 146 | private static boolean ethDstIndicatesBroadcast(Criterion criterion) { |
| 147 | return criterion.type().equals(Criterion.Type.ETH_DST) && |
| 148 | ((EthCriterion) criterion).mac().equals(MacAddress.NONE); |
| 149 | } |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 150 | } |