Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 1 | package org.openflow.protocol.match; |
| 2 | |
| 3 | import org.openflow.protocol.OFObject; |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 4 | import org.openflow.types.Masked; |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 5 | import org.openflow.types.OFValueType; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 6 | |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 7 | /** |
| 8 | * Generic interface for version-agnostic immutable Match structure. |
| 9 | * The Match structure is defined in the OpenFlow protocol, and it contains information on |
| 10 | * the fields to be matched in a specific flow record. |
| 11 | * This interface does not assume anything on the fields in the Match structure. If in |
| 12 | * some version, the match structure cannot handle a certain field, it may return <code>false</code> |
| 13 | * for <code>supports(...)</code> calls, and throw <code>UnsupportedOperationException</code> from all |
| 14 | * other methods in such cases. |
| 15 | * <br><br> |
| 16 | * On wildcards and masks:<br> |
| 17 | * This interface defines the following masking notations for fields: |
| 18 | * <ul> |
| 19 | * <li><b>Exact</b>: field is matched exactly against a single, fixed value (no mask, or mask is all ones). |
| 20 | * <li><b>Wildcarded</b>: field is not being matched. It is fully masked (mask=0) and any value of it |
| 21 | * will match the flow record having this match. |
| 22 | * <li><b>Partially masked</b>: field is matched using a specified mask which is neither 0 nor all ones. Mask can |
| 23 | * be either arbitrary or require some specific structure. |
| 24 | * </ul> |
| 25 | * Implementing classes may or may not support all types of these masking types. They may also support |
| 26 | * them in part. For example, OF1.0 supports exact match and (full) wildcarding for all fields, but it |
| 27 | * does only supports partial masking for IP source/destination fields, and this partial masking must be |
| 28 | * in the CIDR prefix format. Thus, OF1.0 implementation may throw <code>UnsupportedOperationException</code> if given |
| 29 | * in <code>setMaksed</code> an IP mask of, for example, 255.0.255.0, or if <code>setMasked</code> is called for any field |
| 30 | * which is not IP source/destination address. |
| 31 | * <br><br> |
| 32 | * On prerequisites:<br> |
| 33 | * From the OF1.1 spec, page 28, the OF1.0 spec failed to explicitly specify this, but it |
| 34 | * is the behavior of OF1.0 switches: |
| 35 | * "Protocol-specific fields within ofp_match will be ignored within a single table when |
| 36 | * the corresponding protocol is not specified in the match. The MPLS match fields will |
| 37 | * be ignored unless the Ethertype is specified as MPLS. Likewise, the IP header and |
| 38 | * transport header fields will be ignored unless the Ethertype is specified as either |
| 39 | * IPv4 or ARP. The tp_src and tp_dst fields will be ignored unless the network protocol |
| 40 | * specified is as TCP, UDP or SCTP. Fields that are ignored donÕt need to be wildcarded |
| 41 | * and should be set to 0." |
| 42 | * <br><br> |
| 43 | * This interface uses generics to assure type safety in users code. However, implementing classes may have to suppress |
| 44 | * 'unchecked cast' warnings while making sure they correctly cast base on their implementation details. |
| 45 | * |
| 46 | * @author Yotam Harchol (yotam.harchol@bigswitch.com) |
| 47 | */ |
| 48 | public interface Match extends OFObject { |
Andreas Wundsam | a94273b | 2013-08-01 22:11:33 -0700 | [diff] [blame] | 49 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 50 | /** |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 51 | * Returns a value for the given field if: |
| 52 | * <ul> |
| 53 | * <li>Field is supported |
| 54 | * <li>Field is not fully wildcarded |
| 55 | * <li>Prerequisites are ok |
| 56 | * </ul> |
| 57 | * If one of the above conditions does not hold, returns null. Value is returned masked if partially wildcarded. |
| 58 | * |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 59 | * @param field Match field to retrieve |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 60 | * @return Value of match field (may be masked), or <code>null</code> if field is one of the conditions above does not hold. |
| 61 | * @throws UnsupportedOperationException If field is not supported. |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 62 | */ |
| 63 | public <F extends OFValueType<F>> F get(MatchField<F> field) throws UnsupportedOperationException; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 64 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 65 | /** |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 66 | * Returns the masked value for the given field from this match, along with the mask itself. |
| 67 | * Prerequisite: field is partially masked. |
| 68 | * If prerequisite is not met, a <code>null</code> is returned. |
| 69 | * |
| 70 | * @param field Match field to retrieve. |
| 71 | * @return Masked value of match field or null if no mask is set. |
| 72 | * @throws UnsupportedOperationException If field is not supported. |
Yotam Harchol | fb4bfb9 | 2013-08-01 14:02:04 -0700 | [diff] [blame] | 73 | */ |
| 74 | public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field) throws UnsupportedOperationException; |
| 75 | |
| 76 | /** |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 77 | * Returns true if and only if this match object supports the given match field. |
| 78 | * |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 79 | * @param field Match field |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 80 | * @return true if field is supported, false otherwise. |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 81 | */ |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 82 | public boolean supports(MatchField<?> field); |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 83 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 84 | /** |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 85 | * Returns true if and only if this match object supports partially bitmasking of the given field. |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 86 | * (note: not all possible values of this bitmask have to be acceptable) |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 87 | * |
| 88 | * @param field Match field. |
| 89 | * @return true if field can be partially masked, false otherwise. |
| 90 | * @throws UnsupportedOperationException If field is not supported. |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 91 | */ |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 92 | public boolean supportsMasked(MatchField<?> field) throws UnsupportedOperationException; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 93 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 94 | /** |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 95 | * Returns true if and only if this field is currently specified in the match with an exact value and |
| 96 | * no mask. I.e., the specified match will only select packets that match the exact value of getValue(field). |
| 97 | * |
| 98 | * @param field Match field. |
| 99 | * @return true if field has a specific exact value, false if not. |
| 100 | * @throws UnsupportedOperationException If field is not supported. |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 101 | */ |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 102 | public boolean isExact(MatchField<?> field) throws UnsupportedOperationException; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 103 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 104 | /** |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 105 | * True if and only if this field is currently logically unspecified in the match, i.e, the |
| 106 | * value returned by getValue(f) has no impact on whether a packet will be selected |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 107 | * by the match or not. |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 108 | * |
| 109 | * @param field Match field. |
| 110 | * @return true if field is fully wildcarded, false if not. |
| 111 | * @throws UnsupportedOperationException If field is not supported. |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 112 | */ |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 113 | public boolean isFullyWildcarded(MatchField<?> field) throws UnsupportedOperationException; |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 114 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 115 | /** |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 116 | * True if and only if this field is currently partially specified in the match, i.e, the |
| 117 | * match will only select packets that match (p.value & getMask(field)) == getValue(field), |
| 118 | * and getMask(field) != 0. |
| 119 | * |
| 120 | * @param field Match field. |
| 121 | * @return true if field is partially masked, false if not. |
| 122 | * @throws UnsupportedOperationException If field is not supported. |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 123 | */ |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 124 | public boolean isPartiallyMasked(MatchField<?> field) throws UnsupportedOperationException; |
| 125 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 126 | /** |
| 127 | * Returns a builder to build new instances of this type of match object. |
| 128 | * @return Match builder |
| 129 | */ |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 130 | public Builder createBuilder(); |
Andreas Wundsam | a94273b | 2013-08-01 22:11:33 -0700 | [diff] [blame] | 131 | |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 132 | /** |
| 133 | * Builder interface for Match objects. |
| 134 | * Builder is used to create new Match objects and it creates the match according to the version it |
| 135 | * corresponds to. The builder uses the same notation of wildcards and masks, and can also throw |
| 136 | * <code>UnsupportedOperationException</code> if it is asked to create some matching that is not supported in |
| 137 | * the version it represents. |
| 138 | * |
| 139 | * While used, MatchBuilder may not be consistent in terms of field prerequisites. However, user must |
| 140 | * solve these before using the generated Match object as these prerequisites should be enforced in the |
| 141 | * getters. |
| 142 | * |
| 143 | * @author Yotam Harchol (yotam.harchol@bigswitch.com) |
| 144 | */ |
| 145 | interface Builder extends Match { |
| 146 | /** |
| 147 | * Sets a specific exact value for a field. |
| 148 | * |
| 149 | * @param field Match field to set. |
| 150 | * @param value Value of match field. |
| 151 | * @return the Builder instance used. |
| 152 | * @throws UnsupportedOperationException If field is not supported. |
| 153 | */ |
| 154 | public <F extends OFValueType<F>> Builder setExact(MatchField<F> field, F value) throws UnsupportedOperationException; |
| 155 | |
| 156 | /** |
| 157 | * Sets a masked value for a field. |
| 158 | * |
| 159 | * @param field Match field to set. |
| 160 | * @param value Value of field. |
| 161 | * @param mask Mask value. |
| 162 | * @return the Builder instance used. |
| 163 | * @throws UnsupportedOperationException If field is not supported, if field is supported but does not support masking, or if mask structure is not supported. |
| 164 | */ |
| 165 | public <F extends OFValueType<F>> Builder setMasked(MatchField<F> field, F value, F mask) throws UnsupportedOperationException; |
| 166 | |
| 167 | /** |
| 168 | * Sets a masked value for a field. |
| 169 | * |
| 170 | * @param field Match field to set. |
| 171 | * @param valueWithMask Compound Masked object contains the value and the mask. |
| 172 | * @return the Builder instance used. |
| 173 | * @throws UnsupportedOperationException If field is not supported, if field is supported but does not support masking, or if mask structure is not supported. |
| 174 | */ |
| 175 | public <F extends OFValueType<F>> Builder setMasked(MatchField<F> field, Masked<F> valueWithMask) throws UnsupportedOperationException; |
| 176 | |
| 177 | /** |
| 178 | * Unsets any value given for the field and wildcards it so that it matches any value. |
| 179 | * |
| 180 | * @param field Match field to unset. |
| 181 | * @return the Builder instance used. |
| 182 | * @throws UnsupportedOperationException If field is not supported. |
| 183 | */ |
| 184 | public <F extends OFValueType<F>> Builder wildcard(MatchField<F> field) throws UnsupportedOperationException; |
| 185 | |
| 186 | /** |
| 187 | * Returns the match created by this builder. |
| 188 | * |
| 189 | * @return a Match object. |
| 190 | */ |
| 191 | public Match getMatch(); |
Andreas Wundsam | a94273b | 2013-08-01 22:11:33 -0700 | [diff] [blame] | 192 | } |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame^] | 193 | } |