blob: 5913658e3703271c5af3888b7da7a3317287335b [file] [log] [blame]
Andreas Wundsam40e14f72013-05-06 14:49:08 -07001package org.openflow.protocol.match;
2
Yotam Harchold7b84202013-07-26 16:08:10 -07003import org.openflow.types.ArpOpcode;
Andreas Wundsam40e14f72013-05-06 14:49:08 -07004import org.openflow.types.EthType;
Yotam Harchold7b84202013-07-26 16:08:10 -07005import org.openflow.types.ICMPv4Code;
6import org.openflow.types.ICMPv4Type;
Yotam Harchol5c9d6f42013-08-01 11:09:20 -07007import org.openflow.types.IPv4;
8import org.openflow.types.IPv6;
Yotam Harchold7b84202013-07-26 16:08:10 -07009import org.openflow.types.IPv6FlowLabel;
Yotam Harchold7b84202013-07-26 16:08:10 -070010import org.openflow.types.IpDscp;
11import org.openflow.types.IpEcn;
Andreas Wundsam40e14f72013-05-06 14:49:08 -070012import org.openflow.types.IpProtocol;
13import org.openflow.types.MacAddress;
Yotam Harchol6fccde62013-08-15 12:04:52 -070014import org.openflow.types.OFMetadata;
Andreas Wundsam40e14f72013-05-06 14:49:08 -070015import org.openflow.types.OFPort;
Yotam Harchold7b84202013-07-26 16:08:10 -070016import org.openflow.types.OFValueType;
17import org.openflow.types.TransportPort;
Andreas Wundsam40e14f72013-05-06 14:49:08 -070018import org.openflow.types.VlanPcp;
19import org.openflow.types.VlanVid;
Andreas Wundsam40e14f72013-05-06 14:49:08 -070020
Yotam Harchol6fccde62013-08-15 12:04:52 -070021@SuppressWarnings("unchecked")
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070022public class MatchField<F extends OFValueType<F>> {
Andreas Wundsam40e14f72013-05-06 14:49:08 -070023 private final String name;
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070024 public final MatchFields id;
Yotam Harchol6fccde62013-08-15 12:04:52 -070025 private final Prerequisite<?>[] prerequisites;
Andreas Wundsam40e14f72013-05-06 14:49:08 -070026
Yotam Harchol6fccde62013-08-15 12:04:52 -070027 private MatchField(final String name, final MatchFields id, Prerequisite<?>... prerequisites) {
Andreas Wundsam40e14f72013-05-06 14:49:08 -070028 this.name = name;
29 this.id = id;
Yotam Harchol6fccde62013-08-15 12:04:52 -070030 this.prerequisites = prerequisites;
Andreas Wundsam40e14f72013-05-06 14:49:08 -070031 }
32
Yotam Harchold7b84202013-07-26 16:08:10 -070033 public final static MatchField<OFPort> IN_PORT =
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070034 new MatchField<OFPort>("in_port", MatchFields.IN_PORT);
Yotam Harchol6fccde62013-08-15 12:04:52 -070035
Yotam Harchold7b84202013-07-26 16:08:10 -070036 public final static MatchField<OFPort> IN_PHY_PORT =
Yotam Harchol6fccde62013-08-15 12:04:52 -070037 new MatchField<OFPort>("in_phy_port", MatchFields.PHYSICAL_PORT,
38 new Prerequisite<OFPort>(MatchField.IN_PORT));
39
40 public final static MatchField<OFMetadata> METADATA =
41 new MatchField<OFMetadata>("metadata", MatchFields.METADATA);
Andreas Wundsam40e14f72013-05-06 14:49:08 -070042
Yotam Harcholfb4bfb92013-08-01 14:02:04 -070043 public final static MatchField<MacAddress> ETH_DST =
44 new MatchField<MacAddress>("eth_dst", MatchFields.ETH_DST);
Yotam Harchol6fccde62013-08-15 12:04:52 -070045
Yotam Harcholfb4bfb92013-08-01 14:02:04 -070046 public final static MatchField<MacAddress> ETH_SRC =
47 new MatchField<MacAddress>("eth_src", MatchFields.ETH_SRC);
Andreas Wundsam40e14f72013-05-06 14:49:08 -070048
Yotam Harchold7b84202013-07-26 16:08:10 -070049 public final static MatchField<EthType> ETH_TYPE =
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070050 new MatchField<EthType>("eth_type", MatchFields.ETH_TYPE);
Yotam Harchol161a5d52013-07-25 17:17:48 -070051
Yotam Harcholfb4bfb92013-08-01 14:02:04 -070052 public final static MatchField<VlanVid> VLAN_VID =
53 new MatchField<VlanVid>("vlan_vid", MatchFields.VLAN_VID);
Yotam Harchol161a5d52013-07-25 17:17:48 -070054
Yotam Harchol6fccde62013-08-15 12:04:52 -070055 public final static MatchField<VlanPcp> VLAN_PCP =
56 new MatchField<VlanPcp>("vlan_pcp", MatchFields.VLAN_PCP,
57 new Prerequisite<VlanVid>(MatchField.VLAN_VID));
Yotam Harchol161a5d52013-07-25 17:17:48 -070058
Yotam Harchold7b84202013-07-26 16:08:10 -070059 public final static MatchField<IpDscp> IP_DSCP =
Yotam Harchol6fccde62013-08-15 12:04:52 -070060 new MatchField<IpDscp>("ip_dscp", MatchFields.IP_DSCP,
61 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv4, EthType.ETH_TYPE_IPv6));
62
Yotam Harchold7b84202013-07-26 16:08:10 -070063 public final static MatchField<IpEcn> IP_ECN =
Yotam Harchol6fccde62013-08-15 12:04:52 -070064 new MatchField<IpEcn>("ip_dscp", MatchFields.IP_ECN,
65 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv4, EthType.ETH_TYPE_IPv6));
66
Yotam Harchold7b84202013-07-26 16:08:10 -070067 public final static MatchField<IpProtocol> IP_PROTO =
Yotam Harchol6fccde62013-08-15 12:04:52 -070068 new MatchField<IpProtocol>("ip_proto", MatchFields.IP_PROTO,
69 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv4, EthType.ETH_TYPE_IPv6));
Andreas Wundsam40e14f72013-05-06 14:49:08 -070070
Yotam Harcholfb4bfb92013-08-01 14:02:04 -070071 public final static MatchField<IPv4> IPV4_SRC =
Yotam Harchol6fccde62013-08-15 12:04:52 -070072 new MatchField<IPv4>("ipv4_src", MatchFields.IPV4_SRC,
73 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv4));
74
Yotam Harcholfb4bfb92013-08-01 14:02:04 -070075 public final static MatchField<IPv4> IPV4_DST =
Yotam Harchol6fccde62013-08-15 12:04:52 -070076 new MatchField<IPv4>("ipv4_dst", MatchFields.IPV4_DST,
77 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv4));
Andreas Wundsam40e14f72013-05-06 14:49:08 -070078
Yotam Harchold7b84202013-07-26 16:08:10 -070079 public final static MatchField<TransportPort> TCP_SRC = new MatchField<TransportPort>(
Yotam Harchol6fccde62013-08-15 12:04:52 -070080 "tcp_src", MatchFields.TCP_SRC,
81 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_TCP));
82
Yotam Harchold7b84202013-07-26 16:08:10 -070083 public final static MatchField<TransportPort> TCP_DST = new MatchField<TransportPort>(
Yotam Harchol6fccde62013-08-15 12:04:52 -070084 "tcp_dst", MatchFields.TCP_DST,
85 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_TCP));
Andreas Wundsam40e14f72013-05-06 14:49:08 -070086
Yotam Harchold7b84202013-07-26 16:08:10 -070087 public final static MatchField<TransportPort> UDP_SRC = new MatchField<TransportPort>(
Yotam Harchol6fccde62013-08-15 12:04:52 -070088 "udp_src", MatchFields.UDP_SRC,
89 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_UDP));
90
Yotam Harchold7b84202013-07-26 16:08:10 -070091 public final static MatchField<TransportPort> UDP_DST = new MatchField<TransportPort>(
Yotam Harchol6fccde62013-08-15 12:04:52 -070092 "udp_dst", MatchFields.UDP_DST,
93 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_UDP));
Andreas Wundsam40e14f72013-05-06 14:49:08 -070094
Yotam Harchold7b84202013-07-26 16:08:10 -070095 public final static MatchField<TransportPort> SCTP_SRC = new MatchField<TransportPort>(
Yotam Harchol6fccde62013-08-15 12:04:52 -070096 "sctp_src", MatchFields.SCTP_SRC,
97 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_SCTP));
98
Yotam Harchold7b84202013-07-26 16:08:10 -070099 public final static MatchField<TransportPort> SCTP_DST = new MatchField<TransportPort>(
Yotam Harchol6fccde62013-08-15 12:04:52 -0700100 "sctp_dst", MatchFields.SCTP_DST,
101 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_SCTP));
Andreas Wundsam40e14f72013-05-06 14:49:08 -0700102
Yotam Harchold7b84202013-07-26 16:08:10 -0700103 public final static MatchField<ICMPv4Type> ICMPV4_TYPE = new MatchField<ICMPv4Type>(
Yotam Harchol6fccde62013-08-15 12:04:52 -0700104 "icmpv4_src", MatchFields.ICMPV4_TYPE,
105 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_ICMP));
106
Yotam Harchold7b84202013-07-26 16:08:10 -0700107 public final static MatchField<ICMPv4Code> ICMPV4_CODE = new MatchField<ICMPv4Code>(
Yotam Harchol6fccde62013-08-15 12:04:52 -0700108 "icmpv4_dst", MatchFields.ICMPV4_CODE,
109 new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_ICMP));
Andreas Wundsam40e14f72013-05-06 14:49:08 -0700110
Yotam Harchold7b84202013-07-26 16:08:10 -0700111 public final static MatchField<ArpOpcode> ARP_OP = new MatchField<ArpOpcode>(
Yotam Harchol6fccde62013-08-15 12:04:52 -0700112 "arp_op", MatchFields.ARP_OP,
113 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_ARP));
114
Yotam Harcholfb4bfb92013-08-01 14:02:04 -0700115 public final static MatchField<IPv4> ARP_SPA =
Yotam Harchol6fccde62013-08-15 12:04:52 -0700116 new MatchField<IPv4>("arp_spa", MatchFields.ARP_SPA,
117 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_ARP));
118
Yotam Harcholfb4bfb92013-08-01 14:02:04 -0700119 public final static MatchField<IPv4> ARP_TPA =
Yotam Harchol6fccde62013-08-15 12:04:52 -0700120 new MatchField<IPv4>("arp_tpa", MatchFields.ARP_TPA,
121 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_ARP));
122
Yotam Harcholfb4bfb92013-08-01 14:02:04 -0700123 public final static MatchField<MacAddress> ARP_SHA =
Yotam Harchol6fccde62013-08-15 12:04:52 -0700124 new MatchField<MacAddress>("arp_sha", MatchFields.ARP_SHA,
125 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_ARP));
126
Yotam Harcholfb4bfb92013-08-01 14:02:04 -0700127 public final static MatchField<MacAddress> ARP_THA =
Yotam Harchol6fccde62013-08-15 12:04:52 -0700128 new MatchField<MacAddress>("arp_tha", MatchFields.ARP_THA,
129 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_ARP));
Andreas Wundsam40e14f72013-05-06 14:49:08 -0700130
Yotam Harcholfb4bfb92013-08-01 14:02:04 -0700131 public final static MatchField<IPv6> IPV6_SRC =
Yotam Harchol6fccde62013-08-15 12:04:52 -0700132 new MatchField<IPv6>("ipv6_src", MatchFields.IPV6_SRC,
133 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv6));
134
Yotam Harcholfb4bfb92013-08-01 14:02:04 -0700135 public final static MatchField<IPv6> IPV6_DST =
Yotam Harchol6fccde62013-08-15 12:04:52 -0700136 new MatchField<IPv6>("ipv6_dst", MatchFields.IPV6_DST,
137 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv6));
Andreas Wundsam40e14f72013-05-06 14:49:08 -0700138
Yotam Harcholfb4bfb92013-08-01 14:02:04 -0700139 public final static MatchField<IPv6FlowLabel> IPV6_FLABEL =
Yotam Harchol6fccde62013-08-15 12:04:52 -0700140 new MatchField<IPv6FlowLabel>("ipv6_flabel", MatchFields.IPV6_FLOWLABEL,
141 new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv6));
Andreas Wundsam40e14f72013-05-06 14:49:08 -0700142
143 public String getName() {
144 return name;
145 }
Yotam Harchol6fccde62013-08-15 12:04:52 -0700146
147 public boolean arePrerequisitesOK(Match match) {
148 for (Prerequisite<?> p : this.prerequisites) {
149 if (!p.isStaisfied(match)) {
150 return false;
151 }
152 }
153 return true;
154 }
Andreas Wundsam40e14f72013-05-06 14:49:08 -0700155
156}