blob: 774336bf3e5cc37d6f0fea5246674803629778fc [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;
13import org.projectfloodlight.openflow.types.MacAddress;
Andreas Wundsam520c8802013-10-08 22:05:23 -070014import org.projectfloodlight.openflow.types.OFBitMask128;
Yotam Harcholf3f11152013-09-05 16:47:16 -070015import org.projectfloodlight.openflow.types.OFMetadata;
16import org.projectfloodlight.openflow.types.OFPort;
17import org.projectfloodlight.openflow.types.OFValueType;
18import org.projectfloodlight.openflow.types.TransportPort;
Yotam Harchola86e4252013-09-06 15:36:28 -070019import org.projectfloodlight.openflow.types.U32;
20import org.projectfloodlight.openflow.types.U8;
Yotam Harcholf3f11152013-09-05 16:47:16 -070021import org.projectfloodlight.openflow.types.VlanPcp;
22import org.projectfloodlight.openflow.types.VlanVid;
23
24@SuppressWarnings("unchecked")
25public class MatchField<F extends OFValueType<F>> {
26 private final String name;
27 public final MatchFields id;
28 private final Prerequisite<?>[] prerequisites;
29
30 private MatchField(final String name, final MatchFields id, Prerequisite<?>... prerequisites) {
31 this.name = name;
32 this.id = id;
33 this.prerequisites = prerequisites;
34 }
35
36 public final static MatchField<OFPort> IN_PORT =
37 new MatchField<OFPort>("in_port", MatchFields.IN_PORT);
38
39 public final static MatchField<OFPort> IN_PHY_PORT =
40 new MatchField<OFPort>("in_phy_port", MatchFields.IN_PHY_PORT,
41 new Prerequisite<OFPort>(MatchField.IN_PORT));
42
43 public final static MatchField<OFMetadata> METADATA =
44 new MatchField<OFMetadata>("metadata", MatchFields.METADATA);
45
46 public final static MatchField<MacAddress> ETH_DST =
47 new MatchField<MacAddress>("eth_dst", MatchFields.ETH_DST);
48
49 public final static MatchField<MacAddress> ETH_SRC =
50 new MatchField<MacAddress>("eth_src", MatchFields.ETH_SRC);
51
52 public final static MatchField<EthType> ETH_TYPE =
53 new MatchField<EthType>("eth_type", MatchFields.ETH_TYPE);
54
55 public final static MatchField<VlanVid> VLAN_VID =
56 new MatchField<VlanVid>("vlan_vid", MatchFields.VLAN_VID);
57
58 public final static MatchField<VlanPcp> VLAN_PCP =
59 new MatchField<VlanPcp>("vlan_pcp", MatchFields.VLAN_PCP,
60 new Prerequisite<VlanVid>(MatchField.VLAN_VID));
61
62 public final static MatchField<IpDscp> IP_DSCP =
63 new MatchField<IpDscp>("ip_dscp", MatchFields.IP_DSCP,
Andreas Wundsamb70b0442013-09-23 14:44:43 -070064 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -070065
66 public final static MatchField<IpEcn> IP_ECN =
67 new MatchField<IpEcn>("ip_dscp", MatchFields.IP_ECN,
Andreas Wundsamb70b0442013-09-23 14:44:43 -070068 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -070069
70 public final static MatchField<IpProtocol> IP_PROTO =
71 new MatchField<IpProtocol>("ip_proto", MatchFields.IP_PROTO,
Andreas Wundsamb70b0442013-09-23 14:44:43 -070072 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -070073
Yotam Harchola289d552013-09-16 10:10:40 -070074 public final static MatchField<IPv4Address> IPV4_SRC =
75 new MatchField<IPv4Address>("ipv4_src", MatchFields.IPV4_SRC,
Andreas Wundsamb70b0442013-09-23 14:44:43 -070076 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4));
Yotam Harcholf3f11152013-09-05 16:47:16 -070077
Yotam Harchola289d552013-09-16 10:10:40 -070078 public final static MatchField<IPv4Address> IPV4_DST =
79 new MatchField<IPv4Address>("ipv4_dst", MatchFields.IPV4_DST,
Andreas Wundsamb70b0442013-09-23 14:44:43 -070080 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4));
Yotam Harcholf3f11152013-09-05 16:47:16 -070081
82 public final static MatchField<TransportPort> TCP_SRC = new MatchField<TransportPort>(
83 "tcp_src", MatchFields.TCP_SRC,
Andreas Wundsam520c8802013-10-08 22:05:23 -070084 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.TCP));
Yotam Harcholf3f11152013-09-05 16:47:16 -070085
86 public final static MatchField<TransportPort> TCP_DST = new MatchField<TransportPort>(
87 "tcp_dst", MatchFields.TCP_DST,
Andreas Wundsam520c8802013-10-08 22:05:23 -070088 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.TCP));
Yotam Harcholf3f11152013-09-05 16:47:16 -070089
90 public final static MatchField<TransportPort> UDP_SRC = new MatchField<TransportPort>(
91 "udp_src", MatchFields.UDP_SRC,
Andreas Wundsam520c8802013-10-08 22:05:23 -070092 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.UDP));
Yotam Harcholf3f11152013-09-05 16:47:16 -070093
94 public final static MatchField<TransportPort> UDP_DST = new MatchField<TransportPort>(
95 "udp_dst", MatchFields.UDP_DST,
Andreas Wundsam520c8802013-10-08 22:05:23 -070096 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.UDP));
Yotam Harcholf3f11152013-09-05 16:47:16 -070097
98 public final static MatchField<TransportPort> SCTP_SRC = new MatchField<TransportPort>(
99 "sctp_src", MatchFields.SCTP_SRC,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700100 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.SCTP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700101
102 public final static MatchField<TransportPort> SCTP_DST = new MatchField<TransportPort>(
103 "sctp_dst", MatchFields.SCTP_DST,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700104 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.SCTP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700105
106 public final static MatchField<ICMPv4Type> ICMPV4_TYPE = new MatchField<ICMPv4Type>(
107 "icmpv4_src", MatchFields.ICMPV4_TYPE,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700108 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.ICMP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700109
110 public final static MatchField<ICMPv4Code> ICMPV4_CODE = new MatchField<ICMPv4Code>(
111 "icmpv4_dst", MatchFields.ICMPV4_CODE,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700112 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.ICMP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700113
114 public final static MatchField<ArpOpcode> ARP_OP = new MatchField<ArpOpcode>(
115 "arp_op", MatchFields.ARP_OP,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700116 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700117
Yotam Harchola289d552013-09-16 10:10:40 -0700118 public final static MatchField<IPv4Address> ARP_SPA =
119 new MatchField<IPv4Address>("arp_spa", MatchFields.ARP_SPA,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700120 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700121
Yotam Harchola289d552013-09-16 10:10:40 -0700122 public final static MatchField<IPv4Address> ARP_TPA =
123 new MatchField<IPv4Address>("arp_tpa", MatchFields.ARP_TPA,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700124 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700125
126 public final static MatchField<MacAddress> ARP_SHA =
127 new MatchField<MacAddress>("arp_sha", MatchFields.ARP_SHA,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700128 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700129
130 public final static MatchField<MacAddress> ARP_THA =
131 new MatchField<MacAddress>("arp_tha", MatchFields.ARP_THA,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700132 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700133
Yotam Harchola289d552013-09-16 10:10:40 -0700134 public final static MatchField<IPv6Address> IPV6_SRC =
135 new MatchField<IPv6Address>("ipv6_src", MatchFields.IPV6_SRC,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700136 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700137
Yotam Harchola289d552013-09-16 10:10:40 -0700138 public final static MatchField<IPv6Address> IPV6_DST =
139 new MatchField<IPv6Address>("ipv6_dst", MatchFields.IPV6_DST,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700140 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700141
142 public final static MatchField<IPv6FlowLabel> IPV6_FLABEL =
143 new MatchField<IPv6FlowLabel>("ipv6_flabel", MatchFields.IPV6_FLABEL,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700144 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6));
Yotam Harcholf3f11152013-09-05 16:47:16 -0700145
Yotam Harchola86e4252013-09-06 15:36:28 -0700146 public final static MatchField<U8> ICMPV6_TYPE =
147 new MatchField<U8>("icmpv6_type", MatchFields.ICMPV6_TYPE,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700148 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IPv6_ICMP));
Yotam Harchola86e4252013-09-06 15:36:28 -0700149
150 public final static MatchField<U8> ICMPV6_CODE =
151 new MatchField<U8>("icmpv6_code", MatchFields.ICMPV6_CODE,
Andreas Wundsam520c8802013-10-08 22:05:23 -0700152 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IPv6_ICMP));
Yotam Harchola86e4252013-09-06 15:36:28 -0700153
Yotam Harchola289d552013-09-16 10:10:40 -0700154 public final static MatchField<IPv6Address> IPV6_ND_TARGET =
155 new MatchField<IPv6Address>("ipv6_nd_target", MatchFields.IPV6_ND_TARGET,
Yotam Harchola86e4252013-09-06 15:36:28 -0700156 new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short)135), U8.of((short)136)));
157
158 public final static MatchField<MacAddress> IPV6_ND_SLL =
159 new MatchField<MacAddress>("ipv6_nd_sll", MatchFields.IPV6_ND_SLL,
160 new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short)135)));
161
162 public final static MatchField<MacAddress> IPV6_ND_TLL =
163 new MatchField<MacAddress>("ipv6_nd_tll", MatchFields.IPV6_ND_TLL,
164 new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short)136)));
165
166 public final static MatchField<U32> MPLS_LABEL =
167 new MatchField<U32>("mpls_label", MatchFields.MPLS_LABEL,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700168 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.MPLS_UNICAST, EthType.MPLS_MULTICAST));
Yotam Harchola86e4252013-09-06 15:36:28 -0700169
170 public final static MatchField<U8> MPLS_TC =
171 new MatchField<U8>("mpls_tc", MatchFields.MPLS_TC,
Andreas Wundsamb70b0442013-09-23 14:44:43 -0700172 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.MPLS_UNICAST, EthType.MPLS_MULTICAST));
Yotam Harchola86e4252013-09-06 15:36:28 -0700173
Yotam Harchol2c535582013-10-01 15:50:20 -0700174 public final static MatchField<OFBitMask128> BSN_IN_PORTS_128 =
175 new MatchField<OFBitMask128>("bsn_in_port_masked_128", MatchFields.BSN_IN_PORTS_128);
Yotam Harchola11f38b2013-09-26 15:38:17 -0700176
Rich Lane1424d0b2013-10-24 17:16:24 -0700177 public final static MatchField<U32> BSN_LAG_ID =
178 new MatchField<U32>("bsn_lag_id", MatchFields.BSN_LAG_ID);
179
Yotam Harcholf3f11152013-09-05 16:47:16 -0700180 public String getName() {
181 return name;
182 }
183
184 public boolean arePrerequisitesOK(Match match) {
185 for (Prerequisite<?> p : this.prerequisites) {
186 if (!p.isSatisfied(match)) {
187 return false;
188 }
189 }
190 return true;
191 }
192
193}