Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 1 | package org.openflow.protocol.match; |
| 2 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 3 | import org.openflow.types.ArpOpcode; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 4 | import org.openflow.types.EthType; |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 5 | import org.openflow.types.ICMPv4Code; |
| 6 | import org.openflow.types.ICMPv4Type; |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 7 | import org.openflow.types.IPv4; |
| 8 | import org.openflow.types.IPv6; |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 9 | import org.openflow.types.IPv6FlowLabel; |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 10 | import org.openflow.types.IpDscp; |
| 11 | import org.openflow.types.IpEcn; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 12 | import org.openflow.types.IpProtocol; |
| 13 | import org.openflow.types.MacAddress; |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 14 | import org.openflow.types.OFMetadata; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 15 | import org.openflow.types.OFPort; |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 16 | import org.openflow.types.OFValueType; |
| 17 | import org.openflow.types.TransportPort; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 18 | import org.openflow.types.VlanPcp; |
| 19 | import org.openflow.types.VlanVid; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 20 | |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 21 | @SuppressWarnings("unchecked") |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 22 | public class MatchField<F extends OFValueType<F>> { |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 23 | private final String name; |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 24 | public final MatchFields id; |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 25 | private final Prerequisite<?>[] prerequisites; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 26 | |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 27 | private MatchField(final String name, final MatchFields id, Prerequisite<?>... prerequisites) { |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 28 | this.name = name; |
| 29 | this.id = id; |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 30 | this.prerequisites = prerequisites; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 33 | public final static MatchField<OFPort> IN_PORT = |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 34 | new MatchField<OFPort>("in_port", MatchFields.IN_PORT); |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 35 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 36 | public final static MatchField<OFPort> IN_PHY_PORT = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 37 | 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 Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 42 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 43 | public final static MatchField<MacAddress> ETH_DST = |
| 44 | new MatchField<MacAddress>("eth_dst", MatchFields.ETH_DST); |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 45 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 46 | public final static MatchField<MacAddress> ETH_SRC = |
| 47 | new MatchField<MacAddress>("eth_src", MatchFields.ETH_SRC); |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 48 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 49 | public final static MatchField<EthType> ETH_TYPE = |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 50 | new MatchField<EthType>("eth_type", MatchFields.ETH_TYPE); |
Yotam Harchol | 161a5d5 | 2013-07-25 17:17:48 -0700 | [diff] [blame] | 51 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 52 | public final static MatchField<VlanVid> VLAN_VID = |
| 53 | new MatchField<VlanVid>("vlan_vid", MatchFields.VLAN_VID); |
Yotam Harchol | 161a5d5 | 2013-07-25 17:17:48 -0700 | [diff] [blame] | 54 | |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 55 | public final static MatchField<VlanPcp> VLAN_PCP = |
| 56 | new MatchField<VlanPcp>("vlan_pcp", MatchFields.VLAN_PCP, |
| 57 | new Prerequisite<VlanVid>(MatchField.VLAN_VID)); |
Yotam Harchol | 161a5d5 | 2013-07-25 17:17:48 -0700 | [diff] [blame] | 58 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 59 | public final static MatchField<IpDscp> IP_DSCP = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 60 | 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 Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 63 | public final static MatchField<IpEcn> IP_ECN = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 64 | 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 Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 67 | public final static MatchField<IpProtocol> IP_PROTO = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 68 | new MatchField<IpProtocol>("ip_proto", MatchFields.IP_PROTO, |
| 69 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv4, EthType.ETH_TYPE_IPv6)); |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 70 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 71 | public final static MatchField<IPv4> IPV4_SRC = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 72 | new MatchField<IPv4>("ipv4_src", MatchFields.IPV4_SRC, |
| 73 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv4)); |
| 74 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 75 | public final static MatchField<IPv4> IPV4_DST = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 76 | new MatchField<IPv4>("ipv4_dst", MatchFields.IPV4_DST, |
| 77 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv4)); |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 78 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 79 | public final static MatchField<TransportPort> TCP_SRC = new MatchField<TransportPort>( |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 80 | "tcp_src", MatchFields.TCP_SRC, |
| 81 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_TCP)); |
| 82 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 83 | public final static MatchField<TransportPort> TCP_DST = new MatchField<TransportPort>( |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 84 | "tcp_dst", MatchFields.TCP_DST, |
| 85 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_TCP)); |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 86 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 87 | public final static MatchField<TransportPort> UDP_SRC = new MatchField<TransportPort>( |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 88 | "udp_src", MatchFields.UDP_SRC, |
| 89 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_UDP)); |
| 90 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 91 | public final static MatchField<TransportPort> UDP_DST = new MatchField<TransportPort>( |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 92 | "udp_dst", MatchFields.UDP_DST, |
| 93 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_UDP)); |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 94 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 95 | public final static MatchField<TransportPort> SCTP_SRC = new MatchField<TransportPort>( |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 96 | "sctp_src", MatchFields.SCTP_SRC, |
| 97 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_SCTP)); |
| 98 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 99 | public final static MatchField<TransportPort> SCTP_DST = new MatchField<TransportPort>( |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 100 | "sctp_dst", MatchFields.SCTP_DST, |
| 101 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_SCTP)); |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 102 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 103 | public final static MatchField<ICMPv4Type> ICMPV4_TYPE = new MatchField<ICMPv4Type>( |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 104 | "icmpv4_src", MatchFields.ICMPV4_TYPE, |
| 105 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_ICMP)); |
| 106 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 107 | public final static MatchField<ICMPv4Code> ICMPV4_CODE = new MatchField<ICMPv4Code>( |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 108 | "icmpv4_dst", MatchFields.ICMPV4_CODE, |
| 109 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_ICMP)); |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 110 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 111 | public final static MatchField<ArpOpcode> ARP_OP = new MatchField<ArpOpcode>( |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 112 | "arp_op", MatchFields.ARP_OP, |
| 113 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_ARP)); |
| 114 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 115 | public final static MatchField<IPv4> ARP_SPA = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 116 | new MatchField<IPv4>("arp_spa", MatchFields.ARP_SPA, |
| 117 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_ARP)); |
| 118 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 119 | public final static MatchField<IPv4> ARP_TPA = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 120 | new MatchField<IPv4>("arp_tpa", MatchFields.ARP_TPA, |
| 121 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_ARP)); |
| 122 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 123 | public final static MatchField<MacAddress> ARP_SHA = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 124 | new MatchField<MacAddress>("arp_sha", MatchFields.ARP_SHA, |
| 125 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_ARP)); |
| 126 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 127 | public final static MatchField<MacAddress> ARP_THA = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 128 | new MatchField<MacAddress>("arp_tha", MatchFields.ARP_THA, |
| 129 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_ARP)); |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 130 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 131 | public final static MatchField<IPv6> IPV6_SRC = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 132 | new MatchField<IPv6>("ipv6_src", MatchFields.IPV6_SRC, |
| 133 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv6)); |
| 134 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 135 | public final static MatchField<IPv6> IPV6_DST = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 136 | new MatchField<IPv6>("ipv6_dst", MatchFields.IPV6_DST, |
| 137 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv6)); |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 138 | |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 139 | public final static MatchField<IPv6FlowLabel> IPV6_FLABEL = |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 140 | new MatchField<IPv6FlowLabel>("ipv6_flabel", MatchFields.IPV6_FLOWLABEL, |
| 141 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ETH_TYPE_IPv6)); |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 142 | |
| 143 | public String getName() { |
| 144 | return name; |
| 145 | } |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 146 | |
| 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 Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 155 | |
| 156 | } |