blob: 3cf015db2fdfbadc960632f8d2b7f5aec9a06927 [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;
22import org.onosproject.net.flow.criteria.Criterion;
23import org.onosproject.net.flowobjective.ForwardingObjective;
24
25import java.util.Map;
26import java.util.Set;
27
28import static org.onosproject.net.flow.criteria.Criterion.Type.ETH_DST;
29import static org.onosproject.net.flow.criteria.Criterion.Type.ETH_TYPE;
30import static org.onosproject.net.flow.criteria.Criterion.Type.IPV4_DST;
31import static org.onosproject.net.flow.criteria.Criterion.Type.IPV6_DST;
32import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_BOS;
33import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL;
34import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID;
35
36public enum ForwardingFunctionType {
37 /**
38 * L2 unicast, with vlan id + mac address criterion.
39 */
40 L2_UNICAST,
41
42 /**
43 * L2 broadcast, with vlan id criterion only.
44 */
45 L2_BROADCAST,
46
47 /**
48 * IPv4 unicast, with EtherType and IPv4 unicast destination address.
49 */
50 IPV4_UNICAST,
51
52 /**
53 * IPv4 multicast, with EtherType and IPv4 multicast destination address.
54 */
55 IPV4_MULTICAST,
56
57 /**
58 * IPv6 unicast, with EtherType and IPv6 unicast destination address.
59 */
60 IPV6_UNICAST,
61
62 /**
63 * IPv6 multicast, with EtherType and IPv6 multicast destination address.
64 */
65 IPV6_MULTICAST,
66
67 /**
Yi Tseng1b154bd2017-11-20 17:48:19 -080068 * MPLS, with EtherType, MPLS label and MPLS BOS(true) criterion.
Yi Tseng0b809722017-11-03 10:23:26 -070069 */
70 MPLS,
71
72 /**
Yi Tseng1b154bd2017-11-20 17:48:19 -080073 * Pseudo-wire, with EtherType, MPLS label and MPLS BOS(false) criterion.
74 */
75 PW,
76
77 /**
Yi Tseng0b809722017-11-03 10:23:26 -070078 * Unsupported type.
79 */
80 UNSUPPORTED;
81
82 // Different criteria combinations for different FFT
83 private static final Set<Criterion.Type> L2_UNI_CRITERIA_TYPE =
84 ImmutableSet.of(VLAN_VID, ETH_DST);
85 private static final Set<Criterion.Type> L2_BRC_CRITERIA_TYPE =
86 ImmutableSet.of(VLAN_VID);
87 private static final Set<Criterion.Type> IPV4_UNI_CRITERIA_TYPE =
88 ImmutableSet.of(ETH_TYPE, IPV4_DST);
89 private static final Set<Criterion.Type> IPV4_MCAST_CRITERIA_TYPE =
90 ImmutableSet.of(ETH_TYPE, VLAN_VID, IPV4_DST);
91 private static final Set<Criterion.Type> IPV6_UNI_CRITERIA_TYPE =
92 ImmutableSet.of(ETH_TYPE, IPV6_DST);
93 private static final Set<Criterion.Type> IPV6_MCAST_CRITERIA_TYPE =
94 ImmutableSet.of(ETH_TYPE, VLAN_VID, IPV6_DST);
95 private static final Set<Criterion.Type> MPLS_UNI_CRITERIA_TYPE =
96 ImmutableSet.of(ETH_TYPE, MPLS_LABEL, MPLS_BOS);
97
98 private static final Map<Set<Criterion.Type>, ForwardingFunctionType> FFT_MAP =
99 ImmutableMap.<Set<Criterion.Type>, ForwardingFunctionType>builder()
100 .put(L2_UNI_CRITERIA_TYPE, L2_UNICAST)
101 .put(L2_BRC_CRITERIA_TYPE, L2_BROADCAST)
102 .put(IPV4_UNI_CRITERIA_TYPE, IPV4_UNICAST)
103 .put(IPV4_MCAST_CRITERIA_TYPE, IPV4_MULTICAST)
104 .put(IPV6_UNI_CRITERIA_TYPE, IPV6_UNICAST)
105 .put(IPV6_MCAST_CRITERIA_TYPE, IPV6_MULTICAST)
106 .put(MPLS_UNI_CRITERIA_TYPE, MPLS)
107 .build();
108
109 /**
110 * Gets forwarding function type of the forwarding objective.
111 *
112 * @param fwd the forwarding objective
113 * @return forwarding function type of the forwarding objective
114 */
115 public static ForwardingFunctionType getForwardingFunctionType(ForwardingObjective fwd) {
116 Set<Criterion.Type> criteriaType = Sets.newHashSet();
117 fwd.selector().criteria().stream().map(Criterion::type)
118 .forEach(criteriaType::add);
119
120 if (fwd.meta() != null) {
121 fwd.meta().criteria().stream().map(Criterion::type)
122 .forEach(criteriaType::add);
123 }
124
125 return FFT_MAP.getOrDefault(criteriaType, UNSUPPORTED);
126 }
127}