blob: 574cb55aced37f90afb9cda2672207268b286630 [file] [log] [blame]
Yotam Harcholf3f11152013-09-05 16:47:16 -07001package org.projectfloodlight.openflow.protocol.match;
2
3import org.projectfloodlight.openflow.types.ArpOpcode;
4import org.projectfloodlight.openflow.types.EthType;
5import org.projectfloodlight.openflow.types.ICMPv4Code;
6import org.projectfloodlight.openflow.types.ICMPv4Type;
Yotam Harchola289d552013-09-16 10:10:40 -07007import org.projectfloodlight.openflow.types.IPv4Address;
8import org.projectfloodlight.openflow.types.IPv6Address;
Yotam Harcholf3f11152013-09-05 16:47:16 -07009import org.projectfloodlight.openflow.types.IPv6FlowLabel;
10import org.projectfloodlight.openflow.types.IpDscp;
11import org.projectfloodlight.openflow.types.IpEcn;
12import org.projectfloodlight.openflow.types.IpProtocol;
Rich Lane376cafe2013-10-27 21:49:14 -070013import org.projectfloodlight.openflow.types.LagId;
Yotam Harcholf3f11152013-09-05 16:47:16 -070014import org.projectfloodlight.openflow.types.MacAddress;
Andreas Wundsam520c8802013-10-08 22:05:23 -070015import org.projectfloodlight.openflow.types.OFBitMask128;
Yotam Harcholf3f11152013-09-05 16:47:16 -070016import org.projectfloodlight.openflow.types.OFMetadata;
17import org.projectfloodlight.openflow.types.OFPort;
18import org.projectfloodlight.openflow.types.OFValueType;
19import org.projectfloodlight.openflow.types.TransportPort;
Yotam Harchola86e4252013-09-06 15:36:28 -070020import org.projectfloodlight.openflow.types.U32;
21import org.projectfloodlight.openflow.types.U8;
Yotam Harcholf3f11152013-09-05 16:47:16 -070022import org.projectfloodlight.openflow.types.VlanPcp;
23import org.projectfloodlight.openflow.types.VlanVid;
24
25@SuppressWarnings("unchecked")
26public class MatchField<F extends OFValueType<F>> {
27 private final String name;
28 public final MatchFields id;
29 private final Prerequisite<?>[] prerequisites;
30
31 private MatchField(final String name, final MatchFields id, Prerequisite<?>... prerequisites) {
32 this.name = name;
33 this.id = id;
34 this.prerequisites = prerequisites;
35 }
36
37 public final static MatchField<OFPort> IN_PORT =
38 new MatchField<OFPort>("in_port", MatchFields.IN_PORT);
39
40 public final static MatchField<OFPort> IN_PHY_PORT =
41 new MatchField<OFPort>("in_phy_port", MatchFields.IN_PHY_PORT,
42 new Prerequisite<OFPort>(MatchField.IN_PORT));
43
44 public final static MatchField<OFMetadata> METADATA =
45 new MatchField<OFMetadata>("metadata", MatchFields.METADATA);
46
47 public final static MatchField<MacAddress> ETH_DST =
48 new MatchField<MacAddress>("eth_dst", MatchFields.ETH_DST);
49
50 public final static MatchField<MacAddress> ETH_SRC =
51 new MatchField<MacAddress>("eth_src", MatchFields.ETH_SRC);
52
53 public final static MatchField<EthType> ETH_TYPE =
54 new MatchField<EthType>("eth_type", MatchFields.ETH_TYPE);
55
56 public final static MatchField<VlanVid> VLAN_VID =
57 new MatchField<VlanVid>("vlan_vid", MatchFields.VLAN_VID);
58
59 public final static MatchField<VlanPcp> VLAN_PCP =
60 new MatchField<VlanPcp>("vlan_pcp", MatchFields.VLAN_PCP,
61 new Prerequisite<VlanVid>(MatchField.VLAN_VID));
62
63 public final static MatchField<IpDscp> IP_DSCP =
64 new MatchField<IpDscp>("ip_dscp", MatchFields.IP_DSCP,
Andreas Wundsamb70b0442013-09-23 14:44:43 -070065 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -070066
67 public final static MatchField<IpEcn> IP_ECN =
68 new MatchField<IpEcn>("ip_dscp", MatchFields.IP_ECN,
Andreas Wundsamb70b0442013-09-23 14:44:43 -070069 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -070070
71 public final static MatchField<IpProtocol> IP_PROTO =
72 new MatchField<IpProtocol>("ip_proto", MatchFields.IP_PROTO,
Andreas Wundsamb70b0442013-09-23 14:44:43 -070073 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -070074
Yotam Harchola289d552013-09-16 10:10:40 -070075 public final static MatchField<IPv4Address> IPV4_SRC =
76 new MatchField<IPv4Address>("ipv4_src", MatchFields.IPV4_SRC,
Andreas Wundsamb70b0442013-09-23 14:44:43 -070077 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4));
Yotam Harcholf3f11152013-09-05 16:47:16 -070078
Yotam Harchola289d552013-09-16 10:10:40 -070079 public final static MatchField<IPv4Address> IPV4_DST =
80 new MatchField<IPv4Address>("ipv4_dst", MatchFields.IPV4_DST,
Andreas Wundsamb70b0442013-09-23 14:44:43 -070081 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4));
Yotam Harcholf3f11152013-09-05 16:47:16 -070082
83 public final static MatchField<TransportPort> TCP_SRC = new MatchField<TransportPort>(
84 "tcp_src", MatchFields.TCP_SRC,
Andreas Wundsam520c8802013-10-08 22:05:23 -070085 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.TCP));
Yotam Harcholf3f11152013-09-05 16:47:16 -070086
87 public final static MatchField<TransportPort> TCP_DST = new MatchField<TransportPort>(
88 "tcp_dst", MatchFields.TCP_DST,
Andreas Wundsam520c8802013-10-08 22:05:23 -070089 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.TCP));
Yotam Harcholf3f11152013-09-05 16:47:16 -070090
91 public final static MatchField<TransportPort> UDP_SRC = new MatchField<TransportPort>(
92 "udp_src", MatchFields.UDP_SRC,
Andreas Wundsam520c8802013-10-08 22:05:23 -070093 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.UDP));
Yotam Harcholf3f11152013-09-05 16:47:16 -070094
95 public final static MatchField<TransportPort> UDP_DST = new MatchField<TransportPort>(
96 "udp_dst", MatchFields.UDP_DST,
Andreas Wundsam520c8802013-10-08 22:05:23 -070097 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.UDP));
Yotam Harcholf3f11152013-09-05 16:47:16 -070098
99 public final static MatchField<TransportPort> SCTP_SRC = new MatchField<TransportPort>(
100 "sctp_src", MatchFields.SCTP_SRC,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700101 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.SCTP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700102
103 public final static MatchField<TransportPort> SCTP_DST = new MatchField<TransportPort>(
104 "sctp_dst", MatchFields.SCTP_DST,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700105 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.SCTP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700106
107 public final static MatchField<ICMPv4Type> ICMPV4_TYPE = new MatchField<ICMPv4Type>(
108 "icmpv4_src", MatchFields.ICMPV4_TYPE,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700109 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.ICMP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700110
111 public final static MatchField<ICMPv4Code> ICMPV4_CODE = new MatchField<ICMPv4Code>(
112 "icmpv4_dst", MatchFields.ICMPV4_CODE,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700113 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.ICMP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700114
115 public final static MatchField<ArpOpcode> ARP_OP = new MatchField<ArpOpcode>(
116 "arp_op", MatchFields.ARP_OP,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700117 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700118
Yotam Harchola289d552013-09-16 10:10:40 -0700119 public final static MatchField<IPv4Address> ARP_SPA =
120 new MatchField<IPv4Address>("arp_spa", MatchFields.ARP_SPA,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700121 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700122
Yotam Harchola289d552013-09-16 10:10:40 -0700123 public final static MatchField<IPv4Address> ARP_TPA =
124 new MatchField<IPv4Address>("arp_tpa", MatchFields.ARP_TPA,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700125 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700126
127 public final static MatchField<MacAddress> ARP_SHA =
128 new MatchField<MacAddress>("arp_sha", MatchFields.ARP_SHA,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700129 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700130
131 public final static MatchField<MacAddress> ARP_THA =
132 new MatchField<MacAddress>("arp_tha", MatchFields.ARP_THA,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700133 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700134
Yotam Harchola289d552013-09-16 10:10:40 -0700135 public final static MatchField<IPv6Address> IPV6_SRC =
136 new MatchField<IPv6Address>("ipv6_src", MatchFields.IPV6_SRC,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700137 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700138
Yotam Harchola289d552013-09-16 10:10:40 -0700139 public final static MatchField<IPv6Address> IPV6_DST =
140 new MatchField<IPv6Address>("ipv6_dst", MatchFields.IPV6_DST,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700141 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700142
143 public final static MatchField<IPv6FlowLabel> IPV6_FLABEL =
144 new MatchField<IPv6FlowLabel>("ipv6_flabel", MatchFields.IPV6_FLABEL,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700145 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700146
Yotam Harchola86e4252013-09-06 15:36:28 -0700147 public final static MatchField<U8> ICMPV6_TYPE =
148 new MatchField<U8>("icmpv6_type", MatchFields.ICMPV6_TYPE,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700149 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IPv6_ICMP));
Yotam Harchola86e4252013-09-06 15:36:28 -0700150
151 public final static MatchField<U8> ICMPV6_CODE =
152 new MatchField<U8>("icmpv6_code", MatchFields.ICMPV6_CODE,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700153 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IPv6_ICMP));
Yotam Harchola86e4252013-09-06 15:36:28 -0700154
Yotam Harchola289d552013-09-16 10:10:40 -0700155 public final static MatchField<IPv6Address> IPV6_ND_TARGET =
156 new MatchField<IPv6Address>("ipv6_nd_target", MatchFields.IPV6_ND_TARGET,
Yotam Harchola86e4252013-09-06 15:36:28 -0700157 new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short)135), U8.of((short)136)));
158
159 public final static MatchField<MacAddress> IPV6_ND_SLL =
160 new MatchField<MacAddress>("ipv6_nd_sll", MatchFields.IPV6_ND_SLL,
161 new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short)135)));
162
163 public final static MatchField<MacAddress> IPV6_ND_TLL =
164 new MatchField<MacAddress>("ipv6_nd_tll", MatchFields.IPV6_ND_TLL,
165 new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short)136)));
166
167 public final static MatchField<U32> MPLS_LABEL =
168 new MatchField<U32>("mpls_label", MatchFields.MPLS_LABEL,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700169 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.MPLS_UNICAST, EthType.MPLS_MULTICAST));
Yotam Harchola86e4252013-09-06 15:36:28 -0700170
171 public final static MatchField<U8> MPLS_TC =
172 new MatchField<U8>("mpls_tc", MatchFields.MPLS_TC,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700173 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.MPLS_UNICAST, EthType.MPLS_MULTICAST));
Yotam Harchola86e4252013-09-06 15:36:28 -0700174
Yotam Harchol2c535582013-10-01 15:50:20 -0700175 public final static MatchField<OFBitMask128> BSN_IN_PORTS_128 =
176 new MatchField<OFBitMask128>("bsn_in_port_masked_128", MatchFields.BSN_IN_PORTS_128);
Yotam Harchola11f38b2013-09-26 15:38:17 -0700177
Rich Lane376cafe2013-10-27 21:49:14 -0700178 public final static MatchField<LagId> BSN_LAG_ID =
179 new MatchField<LagId>("bsn_lag_id", MatchFields.BSN_LAG_ID);
Rich Lane1424d0b2013-10-24 17:16:24 -0700180
Yotam Harcholf3f11152013-09-05 16:47:16 -0700181 public String getName() {
182 return name;
183 }
184
185 public boolean arePrerequisitesOK(Match match) {
186 for (Prerequisite<?> p : this.prerequisites) {
187 if (!p.isSatisfied(match)) {
188 return false;
189 }
190 }
191 return true;
192 }
193
194}