Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.protocol.match; |
| 2 | |
| 3 | import org.projectfloodlight.openflow.types.ArpOpcode; |
| 4 | import org.projectfloodlight.openflow.types.EthType; |
| 5 | import org.projectfloodlight.openflow.types.ICMPv4Code; |
| 6 | import org.projectfloodlight.openflow.types.ICMPv4Type; |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 7 | import org.projectfloodlight.openflow.types.IPv4Address; |
| 8 | import org.projectfloodlight.openflow.types.IPv6Address; |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 9 | import org.projectfloodlight.openflow.types.IPv6FlowLabel; |
| 10 | import org.projectfloodlight.openflow.types.IpDscp; |
| 11 | import org.projectfloodlight.openflow.types.IpEcn; |
| 12 | import org.projectfloodlight.openflow.types.IpProtocol; |
| 13 | import org.projectfloodlight.openflow.types.MacAddress; |
| 14 | import org.projectfloodlight.openflow.types.OFMetadata; |
| 15 | import org.projectfloodlight.openflow.types.OFPort; |
| 16 | import org.projectfloodlight.openflow.types.OFValueType; |
| 17 | import org.projectfloodlight.openflow.types.TransportPort; |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 18 | import org.projectfloodlight.openflow.types.U32; |
| 19 | import org.projectfloodlight.openflow.types.U8; |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 20 | import org.projectfloodlight.openflow.types.VlanPcp; |
| 21 | import org.projectfloodlight.openflow.types.VlanVid; |
| 22 | |
| 23 | @SuppressWarnings("unchecked") |
| 24 | public class MatchField<F extends OFValueType<F>> { |
| 25 | private final String name; |
| 26 | public final MatchFields id; |
| 27 | private final Prerequisite<?>[] prerequisites; |
| 28 | |
| 29 | private MatchField(final String name, final MatchFields id, Prerequisite<?>... prerequisites) { |
| 30 | this.name = name; |
| 31 | this.id = id; |
| 32 | this.prerequisites = prerequisites; |
| 33 | } |
| 34 | |
| 35 | public final static MatchField<OFPort> IN_PORT = |
| 36 | new MatchField<OFPort>("in_port", MatchFields.IN_PORT); |
| 37 | |
| 38 | public final static MatchField<OFPort> IN_PHY_PORT = |
| 39 | new MatchField<OFPort>("in_phy_port", MatchFields.IN_PHY_PORT, |
| 40 | new Prerequisite<OFPort>(MatchField.IN_PORT)); |
| 41 | |
| 42 | public final static MatchField<OFMetadata> METADATA = |
| 43 | new MatchField<OFMetadata>("metadata", MatchFields.METADATA); |
| 44 | |
| 45 | public final static MatchField<MacAddress> ETH_DST = |
| 46 | new MatchField<MacAddress>("eth_dst", MatchFields.ETH_DST); |
| 47 | |
| 48 | public final static MatchField<MacAddress> ETH_SRC = |
| 49 | new MatchField<MacAddress>("eth_src", MatchFields.ETH_SRC); |
| 50 | |
| 51 | public final static MatchField<EthType> ETH_TYPE = |
| 52 | new MatchField<EthType>("eth_type", MatchFields.ETH_TYPE); |
| 53 | |
| 54 | public final static MatchField<VlanVid> VLAN_VID = |
| 55 | new MatchField<VlanVid>("vlan_vid", MatchFields.VLAN_VID); |
| 56 | |
| 57 | public final static MatchField<VlanPcp> VLAN_PCP = |
| 58 | new MatchField<VlanPcp>("vlan_pcp", MatchFields.VLAN_PCP, |
| 59 | new Prerequisite<VlanVid>(MatchField.VLAN_VID)); |
| 60 | |
| 61 | public final static MatchField<IpDscp> IP_DSCP = |
| 62 | new MatchField<IpDscp>("ip_dscp", MatchFields.IP_DSCP, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 63 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 64 | |
| 65 | public final static MatchField<IpEcn> IP_ECN = |
| 66 | new MatchField<IpEcn>("ip_dscp", MatchFields.IP_ECN, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 67 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 68 | |
| 69 | public final static MatchField<IpProtocol> IP_PROTO = |
| 70 | new MatchField<IpProtocol>("ip_proto", MatchFields.IP_PROTO, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 71 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 72 | |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 73 | public final static MatchField<IPv4Address> IPV4_SRC = |
| 74 | new MatchField<IPv4Address>("ipv4_src", MatchFields.IPV4_SRC, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 75 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 76 | |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 77 | public final static MatchField<IPv4Address> IPV4_DST = |
| 78 | new MatchField<IPv4Address>("ipv4_dst", MatchFields.IPV4_DST, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 79 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 80 | |
| 81 | public final static MatchField<TransportPort> TCP_SRC = new MatchField<TransportPort>( |
| 82 | "tcp_src", MatchFields.TCP_SRC, |
| 83 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_TCP)); |
| 84 | |
| 85 | public final static MatchField<TransportPort> TCP_DST = new MatchField<TransportPort>( |
| 86 | "tcp_dst", MatchFields.TCP_DST, |
| 87 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_TCP)); |
| 88 | |
| 89 | public final static MatchField<TransportPort> UDP_SRC = new MatchField<TransportPort>( |
| 90 | "udp_src", MatchFields.UDP_SRC, |
| 91 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_UDP)); |
| 92 | |
| 93 | public final static MatchField<TransportPort> UDP_DST = new MatchField<TransportPort>( |
| 94 | "udp_dst", MatchFields.UDP_DST, |
| 95 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_UDP)); |
| 96 | |
| 97 | public final static MatchField<TransportPort> SCTP_SRC = new MatchField<TransportPort>( |
| 98 | "sctp_src", MatchFields.SCTP_SRC, |
| 99 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_SCTP)); |
| 100 | |
| 101 | public final static MatchField<TransportPort> SCTP_DST = new MatchField<TransportPort>( |
| 102 | "sctp_dst", MatchFields.SCTP_DST, |
| 103 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_SCTP)); |
| 104 | |
| 105 | public final static MatchField<ICMPv4Type> ICMPV4_TYPE = new MatchField<ICMPv4Type>( |
| 106 | "icmpv4_src", MatchFields.ICMPV4_TYPE, |
| 107 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_ICMP)); |
| 108 | |
| 109 | public final static MatchField<ICMPv4Code> ICMPV4_CODE = new MatchField<ICMPv4Code>( |
| 110 | "icmpv4_dst", MatchFields.ICMPV4_CODE, |
| 111 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_ICMP)); |
| 112 | |
| 113 | public final static MatchField<ArpOpcode> ARP_OP = new MatchField<ArpOpcode>( |
| 114 | "arp_op", MatchFields.ARP_OP, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 115 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 116 | |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 117 | public final static MatchField<IPv4Address> ARP_SPA = |
| 118 | new MatchField<IPv4Address>("arp_spa", MatchFields.ARP_SPA, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 119 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 120 | |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 121 | public final static MatchField<IPv4Address> ARP_TPA = |
| 122 | new MatchField<IPv4Address>("arp_tpa", MatchFields.ARP_TPA, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 123 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 124 | |
| 125 | public final static MatchField<MacAddress> ARP_SHA = |
| 126 | new MatchField<MacAddress>("arp_sha", MatchFields.ARP_SHA, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 127 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 128 | |
| 129 | public final static MatchField<MacAddress> ARP_THA = |
| 130 | new MatchField<MacAddress>("arp_tha", MatchFields.ARP_THA, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 131 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 132 | |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 133 | public final static MatchField<IPv6Address> IPV6_SRC = |
| 134 | new MatchField<IPv6Address>("ipv6_src", MatchFields.IPV6_SRC, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 135 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 136 | |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 137 | public final static MatchField<IPv6Address> IPV6_DST = |
| 138 | new MatchField<IPv6Address>("ipv6_dst", MatchFields.IPV6_DST, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 139 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 140 | |
| 141 | public final static MatchField<IPv6FlowLabel> IPV6_FLABEL = |
| 142 | new MatchField<IPv6FlowLabel>("ipv6_flabel", MatchFields.IPV6_FLABEL, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 143 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6)); |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 144 | |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 145 | public final static MatchField<U8> ICMPV6_TYPE = |
| 146 | new MatchField<U8>("icmpv6_type", MatchFields.ICMPV6_TYPE, |
| 147 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_IPv6_ICMP)); |
| 148 | |
| 149 | public final static MatchField<U8> ICMPV6_CODE = |
| 150 | new MatchField<U8>("icmpv6_code", MatchFields.ICMPV6_CODE, |
| 151 | new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_IPv6_ICMP)); |
| 152 | |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 153 | public final static MatchField<IPv6Address> IPV6_ND_TARGET = |
| 154 | new MatchField<IPv6Address>("ipv6_nd_target", MatchFields.IPV6_ND_TARGET, |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 155 | new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short)135), U8.of((short)136))); |
| 156 | |
| 157 | public final static MatchField<MacAddress> IPV6_ND_SLL = |
| 158 | new MatchField<MacAddress>("ipv6_nd_sll", MatchFields.IPV6_ND_SLL, |
| 159 | new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short)135))); |
| 160 | |
| 161 | public final static MatchField<MacAddress> IPV6_ND_TLL = |
| 162 | new MatchField<MacAddress>("ipv6_nd_tll", MatchFields.IPV6_ND_TLL, |
| 163 | new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short)136))); |
| 164 | |
| 165 | public final static MatchField<U32> MPLS_LABEL = |
| 166 | new MatchField<U32>("mpls_label", MatchFields.MPLS_LABEL, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 167 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.MPLS_UNICAST, EthType.MPLS_MULTICAST)); |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 168 | |
| 169 | public final static MatchField<U8> MPLS_TC = |
| 170 | new MatchField<U8>("mpls_tc", MatchFields.MPLS_TC, |
Andreas Wundsam | b70b044 | 2013-09-23 14:44:43 -0700 | [diff] [blame] | 171 | new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.MPLS_UNICAST, EthType.MPLS_MULTICAST)); |
Yotam Harchol | a86e425 | 2013-09-06 15:36:28 -0700 | [diff] [blame] | 172 | |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 173 | public String getName() { |
| 174 | return name; |
| 175 | } |
| 176 | |
| 177 | public boolean arePrerequisitesOK(Match match) { |
| 178 | for (Prerequisite<?> p : this.prerequisites) { |
| 179 | if (!p.isSatisfied(match)) { |
| 180 | return false; |
| 181 | } |
| 182 | } |
| 183 | return true; |
| 184 | } |
| 185 | |
| 186 | } |