blob: 8f17845b050bed62d30fd3873fa591202b0a9b8f [file] [log] [blame]
Andreas Wundsam40e14f72013-05-06 14:49:08 -07001package org.openflow.protocol.match;
2
3import org.openflow.protocol.OFObject;
Yotam Harcholfb4bfb92013-08-01 14:02:04 -07004import org.openflow.types.Masked;
Yotam Harchold7b84202013-07-26 16:08:10 -07005import org.openflow.types.OFValueType;
Andreas Wundsam40e14f72013-05-06 14:49:08 -07006
Yotam Harchol6fccde62013-08-15 12:04:52 -07007/**
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 */
48public interface Match extends OFObject {
Andreas Wundsama94273b2013-08-01 22:11:33 -070049
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070050 /**
Yotam Harchol6fccde62013-08-15 12:04:52 -070051 * 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 Harchol5c9d6f42013-08-01 11:09:20 -070059 * @param field Match field to retrieve
Yotam Harchol6fccde62013-08-15 12:04:52 -070060 * @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 Harchol5c9d6f42013-08-01 11:09:20 -070062 */
63 public <F extends OFValueType<F>> F get(MatchField<F> field) throws UnsupportedOperationException;
Andreas Wundsam40e14f72013-05-06 14:49:08 -070064
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070065 /**
Yotam Harchol6fccde62013-08-15 12:04:52 -070066 * 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 Harcholfb4bfb92013-08-01 14:02:04 -070073 */
74 public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field) throws UnsupportedOperationException;
75
76 /**
Yotam Harchol6fccde62013-08-15 12:04:52 -070077 * Returns true if and only if this match object supports the given match field.
78 *
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070079 * @param field Match field
Yotam Harchol6fccde62013-08-15 12:04:52 -070080 * @return true if field is supported, false otherwise.
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070081 */
Yotam Harchold7b84202013-07-26 16:08:10 -070082 public boolean supports(MatchField<?> field);
Andreas Wundsam40e14f72013-05-06 14:49:08 -070083
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070084 /**
Yotam Harchol6fccde62013-08-15 12:04:52 -070085 * Returns true if and only if this match object supports partially bitmasking of the given field.
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070086 * (note: not all possible values of this bitmask have to be acceptable)
Yotam Harchol6fccde62013-08-15 12:04:52 -070087 *
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 Harchol5c9d6f42013-08-01 11:09:20 -070091 */
Yotam Harchol6fccde62013-08-15 12:04:52 -070092 public boolean supportsMasked(MatchField<?> field) throws UnsupportedOperationException;
Andreas Wundsam40e14f72013-05-06 14:49:08 -070093
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070094 /**
Yotam Harchol6fccde62013-08-15 12:04:52 -070095 * 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 Harchol5c9d6f42013-08-01 11:09:20 -0700101 */
Yotam Harchol6fccde62013-08-15 12:04:52 -0700102 public boolean isExact(MatchField<?> field) throws UnsupportedOperationException;
Andreas Wundsam40e14f72013-05-06 14:49:08 -0700103
Yotam Harchol5c9d6f42013-08-01 11:09:20 -0700104 /**
Yotam Harchol6fccde62013-08-15 12:04:52 -0700105 * 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 Harchol5c9d6f42013-08-01 11:09:20 -0700107 * by the match or not.
Yotam Harchol6fccde62013-08-15 12:04:52 -0700108 *
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 Harchol5c9d6f42013-08-01 11:09:20 -0700112 */
Yotam Harchol6fccde62013-08-15 12:04:52 -0700113 public boolean isFullyWildcarded(MatchField<?> field) throws UnsupportedOperationException;
Andreas Wundsam40e14f72013-05-06 14:49:08 -0700114
Yotam Harchol5c9d6f42013-08-01 11:09:20 -0700115 /**
Yotam Harchol6fccde62013-08-15 12:04:52 -0700116 * 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 Harchol5c9d6f42013-08-01 11:09:20 -0700123 */
Yotam Harchol6fccde62013-08-15 12:04:52 -0700124 public boolean isPartiallyMasked(MatchField<?> field) throws UnsupportedOperationException;
125
Yotam Harchol5c9d6f42013-08-01 11:09:20 -0700126 /**
127 * Returns a builder to build new instances of this type of match object.
128 * @return Match builder
129 */
Yotam Harchol6fccde62013-08-15 12:04:52 -0700130 public Builder createBuilder();
Andreas Wundsama94273b2013-08-01 22:11:33 -0700131
Yotam Harchol6fccde62013-08-15 12:04:52 -0700132 /**
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 Wundsama94273b2013-08-01 22:11:33 -0700192 }
Yotam Harchol6fccde62013-08-15 12:04:52 -0700193}