blob: 8d8de5409ac6a489bbc59907f88672a8d0dd33a6 [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 /**
68 * MPLS, with EtherType, MPLS label and MPLS BOS criterion.
69 */
70 MPLS,
71
72 /**
73 * Unsupported type.
74 */
75 UNSUPPORTED;
76
77 // Different criteria combinations for different FFT
78 private static final Set<Criterion.Type> L2_UNI_CRITERIA_TYPE =
79 ImmutableSet.of(VLAN_VID, ETH_DST);
80 private static final Set<Criterion.Type> L2_BRC_CRITERIA_TYPE =
81 ImmutableSet.of(VLAN_VID);
82 private static final Set<Criterion.Type> IPV4_UNI_CRITERIA_TYPE =
83 ImmutableSet.of(ETH_TYPE, IPV4_DST);
84 private static final Set<Criterion.Type> IPV4_MCAST_CRITERIA_TYPE =
85 ImmutableSet.of(ETH_TYPE, VLAN_VID, IPV4_DST);
86 private static final Set<Criterion.Type> IPV6_UNI_CRITERIA_TYPE =
87 ImmutableSet.of(ETH_TYPE, IPV6_DST);
88 private static final Set<Criterion.Type> IPV6_MCAST_CRITERIA_TYPE =
89 ImmutableSet.of(ETH_TYPE, VLAN_VID, IPV6_DST);
90 private static final Set<Criterion.Type> MPLS_UNI_CRITERIA_TYPE =
91 ImmutableSet.of(ETH_TYPE, MPLS_LABEL, MPLS_BOS);
92
93 private static final Map<Set<Criterion.Type>, ForwardingFunctionType> FFT_MAP =
94 ImmutableMap.<Set<Criterion.Type>, ForwardingFunctionType>builder()
95 .put(L2_UNI_CRITERIA_TYPE, L2_UNICAST)
96 .put(L2_BRC_CRITERIA_TYPE, L2_BROADCAST)
97 .put(IPV4_UNI_CRITERIA_TYPE, IPV4_UNICAST)
98 .put(IPV4_MCAST_CRITERIA_TYPE, IPV4_MULTICAST)
99 .put(IPV6_UNI_CRITERIA_TYPE, IPV6_UNICAST)
100 .put(IPV6_MCAST_CRITERIA_TYPE, IPV6_MULTICAST)
101 .put(MPLS_UNI_CRITERIA_TYPE, MPLS)
102 .build();
103
104 /**
105 * Gets forwarding function type of the forwarding objective.
106 *
107 * @param fwd the forwarding objective
108 * @return forwarding function type of the forwarding objective
109 */
110 public static ForwardingFunctionType getForwardingFunctionType(ForwardingObjective fwd) {
111 Set<Criterion.Type> criteriaType = Sets.newHashSet();
112 fwd.selector().criteria().stream().map(Criterion::type)
113 .forEach(criteriaType::add);
114
115 if (fwd.meta() != null) {
116 fwd.meta().criteria().stream().map(Criterion::type)
117 .forEach(criteriaType::add);
118 }
119
120 return FFT_MAP.getOrDefault(criteriaType, UNSUPPORTED);
121 }
122}