blob: 24c49bb9ef48ea41e5b41500bbbdc1d303046c22 [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;
5import org.onlab.packet.IPAddress;
6import org.onlab.packet.MACAddress;
7import org.onlab.packet.VLANID;
8
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 *
34 * @param macValue MAC address value or wildcard mask
35 * @return match criterion
36 */
alshabib7b795492014-09-16 14:38:39 -070037 public static Criterion matchEthSrc(MACAddress mac) {
38 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 *
45 * @param macValue MAC address value or wildcard mask
46 * @return match criterion
47 */
alshabib7b795492014-09-16 14:38:39 -070048 public static Criterion matchEthDst(MACAddress mac) {
49 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 */
68 public static Criterion matchVlanId(VLANID vlanId) {
69 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 */
78 public static Criterion matchVlanId(Byte vlanPcp) {
79 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 */
98 public static Criterion matchIPSrc(IPAddress ip) {
99 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 */
108 public static Criterion matchIPDst(IPAddress ip) {
109 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 {
136 private final MACAddress mac;
137 private final Type type;
138
139 public EthCriterion(MACAddress mac, Type type) {
140 this.mac = mac;
141 this.type = type;
142 }
143
144 @Override
145 public Type type() {
146 return this.type;
147 }
148
149 public MACAddress mac() {
150 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
176 private final IPAddress ip;
177 private final Type type;
178
179 public IPCriterion(IPAddress ip, Type type) {
180 this.ip = ip;
181 this.type = type;
182 }
183
184 @Override
185 public Type type() {
186 return this.type;
187 }
188
189 public IPAddress ip() {
190 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
230 public Byte protocol() {
231 return vlanPcp;
232 }
233
234 }
235
236
237 public static final class VlanIdCriterion implements Criterion {
238
239
240 private final VLANID vlanId;
241
242 public VlanIdCriterion(VLANID vlanId) {
243 this.vlanId = vlanId;
244 }
245
246 @Override
247 public Type type() {
248 return Type.VLAN_VID;
249 }
250
251 public VLANID vlanId() {
252 return vlanId;
253 }
254
255 }
256
257
tom8bb16062014-09-12 14:47:46 -0700258}