blob: e27cc4d76184fee48e10fdbacfb9a32bd3aa60c2 [file] [log] [blame]
alshabib7410fea2014-09-16 13:48:39 -07001package org.onlab.onos.net.flow.criteria;
tom8bb16062014-09-12 14:47:46 -07002
alshabib7b795492014-09-16 14:38:39 -07003import org.onlab.onos.net.PortNumber;
4import org.onlab.onos.net.flow.criteria.Criterion.Type;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -07005import org.onlab.packet.IpPrefix;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -07006import org.onlab.packet.MacAddress;
7import org.onlab.packet.VlanId;
alshabib7b795492014-09-16 14:38:39 -07008
tom8bb16062014-09-12 14:47:46 -07009/**
10 * Factory class to create various traffic selection criteria.
11 */
12public final class Criteria {
13
alshabib7b795492014-09-16 14:38:39 -070014 //TODO: incomplete type implementation. Need to implement complete list from Criterion
15
tom8bb16062014-09-12 14:47:46 -070016 // Ban construction
17 private Criteria() {
18 }
19
20 /**
alshabib7b795492014-09-16 14:38:39 -070021 * Creates a match on IN_PORT field using the specified value.
22 *
23 * @param port inport value
24 * @return match criterion
25 */
26 public static Criterion matchInPort(PortNumber port) {
27 return new PortCriterion(port);
28 }
29
30 /**
tom8bb16062014-09-12 14:47:46 -070031 * Creates a match on ETH_SRC field using the specified value. This value
32 * may be a wildcard mask.
33 *
tomc104d282014-09-19 10:57:55 -070034 * @param mac MAC address value or wildcard mask
tom8bb16062014-09-12 14:47:46 -070035 * @return match criterion
36 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070037 public static Criterion matchEthSrc(MacAddress mac) {
alshabib7b795492014-09-16 14:38:39 -070038 return new EthCriterion(mac, Type.ETH_SRC);
tom8bb16062014-09-12 14:47:46 -070039 }
40
alshabib369d2942014-09-12 17:59:35 -070041 /**
42 * Creates a match on ETH_DST field using the specified value. This value
43 * may be a wildcard mask.
44 *
tomc104d282014-09-19 10:57:55 -070045 * @param mac MAC address value or wildcard mask
alshabib369d2942014-09-12 17:59:35 -070046 * @return match criterion
47 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070048 public static Criterion matchEthDst(MacAddress mac) {
alshabib7b795492014-09-16 14:38:39 -070049 return new EthCriterion(mac, Type.ETH_DST);
50 }
51
52 /**
53 * Creates a match on ETH_TYPE field using the specified value.
54 *
55 * @param ethType eth type value
56 * @return match criterion
57 */
58 public static Criterion matchEthType(Short ethType) {
59 return new EthTypeCriterion(ethType);
60 }
61
62 /**
63 * Creates a match on VLAN ID field using the specified value.
64 *
65 * @param vlanId vlan id value
66 * @return match criterion
67 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070068 public static Criterion matchVlanId(VlanId vlanId) {
alshabib7b795492014-09-16 14:38:39 -070069 return new VlanIdCriterion(vlanId);
70 }
71
72 /**
73 * Creates a match on VLAN PCP field using the specified value.
74 *
75 * @param vlanPcp vlan pcp value
76 * @return match criterion
77 */
alshabibb45d1962014-09-18 14:25:45 -070078 public static Criterion matchVlanPcp(Byte vlanPcp) {
alshabib7b795492014-09-16 14:38:39 -070079 return new VlanPcpCriterion(vlanPcp);
80 }
81
82 /**
83 * Creates a match on IP proto field using the specified value.
84 *
85 * @param proto ip protocol value
86 * @return match criterion
87 */
88 public static Criterion matchIPProtocol(Byte proto) {
89 return new IPProtocolCriterion(proto);
90 }
91
92 /**
93 * Creates a match on IP src field using the specified value.
94 *
95 * @param ip ip src value
96 * @return match criterion
97 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070098 public static Criterion matchIPSrc(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -070099 return new IPCriterion(ip, Type.IPV4_SRC);
100 }
101
102 /**
103 * Creates a match on IP dst field using the specified value.
104 *
105 * @param ip ip src value
106 * @return match criterion
107 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700108 public static Criterion matchIPDst(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700109 return new IPCriterion(ip, Type.IPV4_DST);
alshabib369d2942014-09-12 17:59:35 -0700110 }
111
112
alshabib7b795492014-09-16 14:38:39 -0700113 /*
114 * Implementations of criteria.
115 */
116
117 public static final class PortCriterion implements Criterion {
118 private final PortNumber port;
119
120 public PortCriterion(PortNumber port) {
121 this.port = port;
122 }
123
124 @Override
125 public Type type() {
126 return Type.IN_PORT;
127 }
128
129 public PortNumber port() {
130 return this.port;
131 }
132 }
133
134
135 public static final class EthCriterion implements Criterion {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700136 private final MacAddress mac;
alshabib7b795492014-09-16 14:38:39 -0700137 private final Type type;
138
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700139 public EthCriterion(MacAddress mac, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700140 this.mac = mac;
141 this.type = type;
142 }
143
144 @Override
145 public Type type() {
146 return this.type;
147 }
148
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700149 public MacAddress mac() {
alshabib7b795492014-09-16 14:38:39 -0700150 return this.mac;
151 }
152 }
153
154 public static final class EthTypeCriterion implements Criterion {
155
156 private final Short ethType;
157
158 public EthTypeCriterion(Short ethType) {
159 this.ethType = ethType;
160 }
161
162 @Override
163 public Type type() {
164 return Type.ETH_TYPE;
165 }
166
167 public Short ethType() {
168 return ethType;
169 }
170
171 }
172
173
174 public static final class IPCriterion implements Criterion {
175
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700176 private final IpPrefix ip;
alshabib7b795492014-09-16 14:38:39 -0700177 private final Type type;
178
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700179 public IPCriterion(IpPrefix ip, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700180 this.ip = ip;
181 this.type = type;
182 }
183
184 @Override
185 public Type type() {
186 return this.type;
187 }
188
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700189 public IpPrefix ip() {
alshabib7b795492014-09-16 14:38:39 -0700190 return this.ip;
191 }
192
193
194 }
195
196
197 public static final class IPProtocolCriterion implements Criterion {
198
199 private final Byte proto;
200
201 public IPProtocolCriterion(Byte protocol) {
202 this.proto = protocol;
203 }
204
205 @Override
206 public Type type() {
207 return Type.IP_PROTO;
208 }
209
210 public Byte protocol() {
211 return proto;
212 }
213
214 }
215
216
217 public static final class VlanPcpCriterion implements Criterion {
218
219 private final Byte vlanPcp;
220
221 public VlanPcpCriterion(Byte vlanPcp) {
222 this.vlanPcp = vlanPcp;
223 }
224
225 @Override
226 public Type type() {
227 return Type.VLAN_PCP;
228 }
229
alshabib35edb1a2014-09-16 17:44:44 -0700230 public Byte priority() {
alshabib7b795492014-09-16 14:38:39 -0700231 return vlanPcp;
232 }
233
234 }
235
236
237 public static final class VlanIdCriterion implements Criterion {
238
239
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700240 private final VlanId vlanId;
alshabib7b795492014-09-16 14:38:39 -0700241
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700242 public VlanIdCriterion(VlanId vlanId) {
alshabib7b795492014-09-16 14:38:39 -0700243 this.vlanId = vlanId;
244 }
245
246 @Override
247 public Type type() {
248 return Type.VLAN_VID;
249 }
250
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700251 public VlanId vlanId() {
alshabib7b795492014-09-16 14:38:39 -0700252 return vlanId;
253 }
254
255 }
256
257
tom8bb16062014-09-12 14:47:46 -0700258}