blob: 2bc611c65351e4d4e0f445ac88151a68c236bec7 [file] [log] [blame]
Ray Milkeydb358082015-01-13 16:34:38 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.codec.impl;
17
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -070018import com.google.common.base.Joiner;
Ray Milkeydb358082015-01-13 16:34:38 -080019import org.hamcrest.Description;
20import org.hamcrest.TypeSafeDiagnosingMatcher;
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -070021import org.onosproject.net.OchSignal;
Ray Milkeydb358082015-01-13 16:34:38 -080022import org.onosproject.net.flow.criteria.Criterion;
23
24import com.fasterxml.jackson.databind.JsonNode;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070025import org.onosproject.net.flow.criteria.EthCriterion;
26import org.onosproject.net.flow.criteria.EthTypeCriterion;
27import org.onosproject.net.flow.criteria.IPCriterion;
28import org.onosproject.net.flow.criteria.IPDscpCriterion;
29import org.onosproject.net.flow.criteria.IPEcnCriterion;
30import org.onosproject.net.flow.criteria.IPProtocolCriterion;
31import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion;
32import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion;
33import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion;
34import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion;
35import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
36import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
37import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
38import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070039import org.onosproject.net.flow.criteria.MetadataCriterion;
40import org.onosproject.net.flow.criteria.MplsCriterion;
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -070041import org.onosproject.net.flow.criteria.OchSignalCriterion;
Sho SHIMIZU6c70f642015-05-29 17:27:22 -070042import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070043import org.onosproject.net.flow.criteria.PortCriterion;
44import org.onosproject.net.flow.criteria.SctpPortCriterion;
45import org.onosproject.net.flow.criteria.TcpPortCriterion;
46import org.onosproject.net.flow.criteria.UdpPortCriterion;
47import org.onosproject.net.flow.criteria.VlanIdCriterion;
48import org.onosproject.net.flow.criteria.VlanPcpCriterion;
Ray Milkeydb358082015-01-13 16:34:38 -080049
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -070050import java.util.Objects;
51
Ray Milkeydb358082015-01-13 16:34:38 -080052/**
53 * Hamcrest matcher for criterion objects.
54 */
Ray Milkey46670a82015-02-08 17:57:17 -080055public final class CriterionJsonMatcher extends
56 TypeSafeDiagnosingMatcher<JsonNode> {
Ray Milkeydb358082015-01-13 16:34:38 -080057
58 final Criterion criterion;
Ray Milkey46670a82015-02-08 17:57:17 -080059 Description description;
60 JsonNode jsonCriterion;
Ray Milkeydb358082015-01-13 16:34:38 -080061
Ray Milkey46670a82015-02-08 17:57:17 -080062 /**
63 * Constructs a matcher object.
64 *
65 * @param criterionValue criterion to match
66 */
Ray Milkeydb358082015-01-13 16:34:38 -080067 private CriterionJsonMatcher(Criterion criterionValue) {
68 criterion = criterionValue;
69 }
70
Ray Milkey46670a82015-02-08 17:57:17 -080071 /**
72 * Factory to allocate an criterion matcher.
73 *
74 * @param criterion criterion object we are looking for
75 * @return matcher
76 */
77 public static CriterionJsonMatcher matchesCriterion(Criterion criterion) {
78 return new CriterionJsonMatcher(criterion);
79 }
80
81 /**
82 * Matches a port criterion object.
83 *
84 * @param criterion criterion to match
85 * @return true if the JSON matches the criterion, false otherwise.
86 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070087 private boolean matchCriterion(PortCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -080088 final long port = criterion.port().toLong();
89 final long jsonPort = jsonCriterion.get("port").asLong();
90 if (port != jsonPort) {
91 description.appendText("port was " + Long.toString(jsonPort));
92 return false;
93 }
94 return true;
95 }
96
97 /**
98 * Matches a metadata criterion object.
99 *
100 * @param criterion criterion to match
101 * @return true if the JSON matches the criterion, false otherwise.
102 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700103 private boolean matchCriterion(MetadataCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800104 final long metadata = criterion.metadata();
105 final long jsonMetadata = jsonCriterion.get("metadata").asLong();
106 if (metadata != jsonMetadata) {
107 description.appendText("metadata was "
108 + Long.toString(jsonMetadata));
109 return false;
110 }
111 return true;
112 }
113
114 /**
115 * Matches an eth criterion object.
116 *
117 * @param criterion criterion to match
118 * @return true if the JSON matches the criterion, false otherwise.
119 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700120 private boolean matchCriterion(EthCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800121 final String mac = criterion.mac().toString();
122 final String jsonMac = jsonCriterion.get("mac").textValue();
123 if (!mac.equals(jsonMac)) {
124 description.appendText("mac was " + jsonMac);
125 return false;
126 }
127 return true;
128 }
129
130 /**
131 * Matches an eth type criterion object.
132 *
133 * @param criterion criterion to match
134 * @return true if the JSON matches the criterion, false otherwise.
135 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700136 private boolean matchCriterion(EthTypeCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800137 final int ethType = criterion.ethType();
138 final int jsonEthType = jsonCriterion.get("ethType").intValue();
139 if (ethType != jsonEthType) {
140 description.appendText("ethType was "
141 + Integer.toString(jsonEthType));
142 return false;
143 }
144 return true;
145 }
146
147 /**
148 * Matches a VLAN ID criterion object.
149 *
150 * @param criterion criterion to match
151 * @return true if the JSON matches the criterion, false otherwise.
152 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700153 private boolean matchCriterion(VlanIdCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800154 final short vlanId = criterion.vlanId().toShort();
155 final short jsonVlanId = jsonCriterion.get("vlanId").shortValue();
156 if (vlanId != jsonVlanId) {
157 description.appendText("vlanId was " + Short.toString(jsonVlanId));
158 return false;
159 }
160 return true;
161 }
162
163 /**
164 * Matches a VLAN PCP criterion object.
165 *
166 * @param criterion criterion to match
167 * @return true if the JSON matches the criterion, false otherwise.
168 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700169 private boolean matchCriterion(VlanPcpCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800170 final byte priority = criterion.priority();
171 final byte jsonPriority =
172 (byte) jsonCriterion.get("priority").shortValue();
173 if (priority != jsonPriority) {
174 description.appendText("priority was " + Byte.toString(jsonPriority));
175 return false;
176 }
177 return true;
178 }
179
180 /**
181 * Matches an IP DSCP criterion object.
182 *
183 * @param criterion criterion to match
184 * @return true if the JSON matches the criterion, false otherwise.
185 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700186 private boolean matchCriterion(IPDscpCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800187 final byte ipDscp = criterion.ipDscp();
188 final byte jsonIpDscp = (byte) jsonCriterion.get("ipDscp").shortValue();
189 if (ipDscp != jsonIpDscp) {
190 description.appendText("IP DSCP was " + Byte.toString(jsonIpDscp));
191 return false;
192 }
193 return true;
194 }
195
196 /**
197 * Matches an IP ECN criterion object.
198 *
199 * @param criterion criterion to match
200 * @return true if the JSON matches the criterion, false otherwise.
201 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700202 private boolean matchCriterion(IPEcnCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800203 final byte ipEcn = criterion.ipEcn();
204 final byte jsonIpEcn = (byte) jsonCriterion.get("ipEcn").shortValue();
205 if (ipEcn != jsonIpEcn) {
206 description.appendText("IP ECN was " + Byte.toString(jsonIpEcn));
207 return false;
208 }
209 return true;
210 }
211
212 /**
213 * Matches an IP protocol criterion object.
214 *
215 * @param criterion criterion to match
216 * @return true if the JSON matches the criterion, false otherwise.
217 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700218 private boolean matchCriterion(IPProtocolCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800219 final short protocol = criterion.protocol();
220 final short jsonProtocol = jsonCriterion.get("protocol").shortValue();
221 if (protocol != jsonProtocol) {
222 description.appendText("protocol was "
223 + Short.toString(jsonProtocol));
224 return false;
225 }
226 return true;
227 }
228
229 /**
230 * Matches an IP address criterion object.
231 *
232 * @param criterion criterion to match
233 * @return true if the JSON matches the criterion, false otherwise.
234 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700235 private boolean matchCriterion(IPCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800236 final String ip = criterion.ip().toString();
237 final String jsonIp = jsonCriterion.get("ip").textValue();
238 if (!ip.equals(jsonIp)) {
239 description.appendText("ip was " + jsonIp);
240 return false;
241 }
242 return true;
243 }
244
245 /**
246 * Matches a TCP port criterion object.
247 *
248 * @param criterion criterion to match
249 * @return true if the JSON matches the criterion, false otherwise.
250 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700251 private boolean matchCriterion(TcpPortCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800252 final int tcpPort = criterion.tcpPort();
253 final int jsonTcpPort = jsonCriterion.get("tcpPort").intValue();
254 if (tcpPort != jsonTcpPort) {
255 description.appendText("tcp port was "
256 + Integer.toString(jsonTcpPort));
257 return false;
258 }
259 return true;
260 }
261
262 /**
263 * Matches a UDP port criterion object.
264 *
265 * @param criterion criterion to match
266 * @return true if the JSON matches the criterion, false otherwise.
267 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700268 private boolean matchCriterion(UdpPortCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800269 final int udpPort = criterion.udpPort();
270 final int jsonUdpPort = jsonCriterion.get("udpPort").intValue();
271 if (udpPort != jsonUdpPort) {
272 description.appendText("udp port was "
273 + Integer.toString(jsonUdpPort));
274 return false;
275 }
276 return true;
277 }
278
279 /**
280 * Matches an SCTP port criterion object.
281 *
282 * @param criterion criterion to match
283 * @return true if the JSON matches the criterion, false otherwise.
284 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700285 private boolean matchCriterion(SctpPortCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800286 final int sctpPort = criterion.sctpPort();
287 final int jsonSctpPort = jsonCriterion.get("sctpPort").intValue();
288 if (sctpPort != jsonSctpPort) {
289 description.appendText("sctp port was "
290 + Integer.toString(jsonSctpPort));
291 return false;
292 }
293 return true;
294 }
295
296 /**
297 * Matches an ICMP type criterion object.
298 *
299 * @param criterion criterion to match
300 * @return true if the JSON matches the criterion, false otherwise.
301 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700302 private boolean matchCriterion(IcmpTypeCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800303 final short icmpType = criterion.icmpType();
304 final short jsonIcmpType = jsonCriterion.get("icmpType").shortValue();
305 if (icmpType != jsonIcmpType) {
306 description.appendText("icmp type was "
307 + Short.toString(jsonIcmpType));
308 return false;
309 }
310 return true;
311 }
312
313 /**
314 * Matches an ICMP code criterion object.
315 *
316 * @param criterion criterion to match
317 * @return true if the JSON matches the criterion, false otherwise.
318 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700319 private boolean matchCriterion(IcmpCodeCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800320 final short icmpCode = criterion.icmpCode();
321 final short jsonIcmpCode = jsonCriterion.get("icmpCode").shortValue();
322 if (icmpCode != jsonIcmpCode) {
323 description.appendText("icmp code was "
324 + Short.toString(jsonIcmpCode));
325 return false;
326 }
327 return true;
328 }
329
330 /**
331 * Matches an IPV6 flow label criterion object.
332 *
333 * @param criterion criterion to match
334 * @return true if the JSON matches the criterion, false otherwise.
335 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700336 private boolean matchCriterion(IPv6FlowLabelCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800337 final int flowLabel = criterion.flowLabel();
338 final int jsonFlowLabel = jsonCriterion.get("flowLabel").intValue();
339 if (flowLabel != jsonFlowLabel) {
340 description.appendText("IPv6 flow label was "
341 + Integer.toString(jsonFlowLabel));
342 return false;
343 }
344 return true;
345 }
346
347 /**
348 * Matches an ICMP V6 type criterion object.
349 *
350 * @param criterion criterion to match
351 * @return true if the JSON matches the criterion, false otherwise.
352 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700353 private boolean matchCriterion(Icmpv6TypeCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800354 final short icmpv6Type = criterion.icmpv6Type();
355 final short jsonIcmpv6Type =
356 jsonCriterion.get("icmpv6Type").shortValue();
357 if (icmpv6Type != jsonIcmpv6Type) {
358 description.appendText("icmpv6 type was "
359 + Short.toString(jsonIcmpv6Type));
360 return false;
361 }
362 return true;
363 }
364
365 /**
366 * Matches an IPV6 code criterion object.
367 *
368 * @param criterion criterion to match
369 * @return true if the JSON matches the criterion, false otherwise.
370 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700371 private boolean matchCriterion(Icmpv6CodeCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800372 final short icmpv6Code = criterion.icmpv6Code();
373 final short jsonIcmpv6Code =
374 jsonCriterion.get("icmpv6Code").shortValue();
375 if (icmpv6Code != jsonIcmpv6Code) {
376 description.appendText("icmpv6 code was "
377 + Short.toString(jsonIcmpv6Code));
378 return false;
379 }
380 return true;
381 }
382
383 /**
384 * Matches an IPV6 ND target criterion object.
385 *
386 * @param criterion criterion to match
387 * @return true if the JSON matches the criterion, false otherwise.
388 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700389 private boolean matchCriterion(IPv6NDTargetAddressCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800390 final String targetAddress =
391 criterion.targetAddress().toString();
392 final String jsonTargetAddress =
393 jsonCriterion.get("targetAddress").textValue();
394 if (!targetAddress.equals(jsonTargetAddress)) {
395 description.appendText("target address was " +
396 jsonTargetAddress);
397 return false;
398 }
399 return true;
400 }
401
402 /**
403 * Matches an IPV6 ND link layer criterion object.
404 *
405 * @param criterion criterion to match
406 * @return true if the JSON matches the criterion, false otherwise.
407 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700408 private boolean matchCriterion(IPv6NDLinkLayerAddressCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800409 final String llAddress =
410 criterion.mac().toString();
411 final String jsonLlAddress =
412 jsonCriterion.get("mac").textValue();
413 if (!llAddress.equals(jsonLlAddress)) {
414 description.appendText("mac was " + jsonLlAddress);
415 return false;
416 }
417 return true;
418 }
419
420 /**
421 * Matches an MPLS label criterion object.
422 *
423 * @param criterion criterion to match
424 * @return true if the JSON matches the criterion, false otherwise.
425 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700426 private boolean matchCriterion(MplsCriterion criterion) {
Michele Santuari4b6019e2014-12-19 11:31:45 +0100427 final int label = criterion.label().toInt();
Ray Milkey46670a82015-02-08 17:57:17 -0800428 final int jsonLabel = jsonCriterion.get("label").intValue();
429 if (label != jsonLabel) {
430 description.appendText("label was " + Integer.toString(jsonLabel));
431 return false;
432 }
433 return true;
434 }
435
436 /**
437 * Matches an IPV6 exthdr criterion object.
438 *
439 * @param criterion criterion to match
440 * @return true if the JSON matches the criterion, false otherwise.
441 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700442 private boolean matchCriterion(IPv6ExthdrFlagsCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800443 final int exthdrFlags = criterion.exthdrFlags();
444 final int jsonExthdrFlags =
445 jsonCriterion.get("exthdrFlags").intValue();
446 if (exthdrFlags != jsonExthdrFlags) {
447 description.appendText("exthdrFlags was "
448 + Long.toHexString(jsonExthdrFlags));
449 return false;
450 }
451 return true;
452 }
453
454 /**
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -0700455 * Matches an Och signal criterion object.
Ray Milkey46670a82015-02-08 17:57:17 -0800456 *
457 * @param criterion criterion to match
458 * @return true if the JSON matches the criterion, false otherwise.
459 */
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -0700460 private boolean matchCriterion(OchSignalCriterion criterion) {
461 final OchSignal ochSignal = criterion.lambda();
462 final JsonNode jsonOchSignal = jsonCriterion.get("ochSignalId");
463 String jsonGridType = jsonOchSignal.get("gridType").textValue();
464 String jsonChannelSpacing = jsonOchSignal.get("channelSpacing").textValue();
465 int jsonSpacingMultiplier = jsonOchSignal.get("spacingMultiplier").intValue();
466 int jsonSlotGranularity = jsonOchSignal.get("slotGranularity").intValue();
467
468 boolean equality = Objects.equals(ochSignal.gridType().name(), jsonGridType)
469 && Objects.equals(ochSignal.channelSpacing().name(), jsonChannelSpacing)
470 && Objects.equals(ochSignal.spacingMultiplier(), jsonSpacingMultiplier)
471 && Objects.equals(ochSignal.slotGranularity(), jsonSlotGranularity);
472
473 if (!equality) {
474 String joined = Joiner.on(", ")
475 .join(jsonGridType, jsonChannelSpacing, jsonSpacingMultiplier, jsonSlotGranularity);
476
477 description.appendText("och signal id was " + joined);
Ray Milkey46670a82015-02-08 17:57:17 -0800478 return false;
479 }
480 return true;
481 }
482
483 /**
Sho SHIMIZU68b8c1f2015-05-29 18:42:26 -0700484 * Matches an Och signal type criterion object.
Ray Milkey46670a82015-02-08 17:57:17 -0800485 *
486 * @param criterion criterion to match
487 * @return true if the JSON matches the criterion, false otherwise.
488 */
Sho SHIMIZU6c70f642015-05-29 17:27:22 -0700489 private boolean matchCriterion(OchSignalTypeCriterion criterion) {
490 final String signalType = criterion.signalType().name();
491 final String jsonSignalType = jsonCriterion.get("ochSignalType").textValue();
492 if (!signalType.equals(jsonSignalType)) {
Sho SHIMIZUc06966e2015-06-01 12:14:37 -0700493 description.appendText("signal type was " + jsonSignalType);
Ray Milkey46670a82015-02-08 17:57:17 -0800494 return false;
495 }
496 return true;
497 }
498
Ray Milkeydb358082015-01-13 16:34:38 -0800499 @Override
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800500 public boolean matchesSafely(JsonNode jsonCriterion,
501 Description description) {
Ray Milkey46670a82015-02-08 17:57:17 -0800502 this.description = description;
503 this.jsonCriterion = jsonCriterion;
Ray Milkeydb358082015-01-13 16:34:38 -0800504 final String type = criterion.type().name();
505 final String jsonType = jsonCriterion.get("type").asText();
506 if (!type.equals(jsonType)) {
507 description.appendText("type was " + type);
508 return false;
509 }
510
511 switch (criterion.type()) {
512
513 case IN_PORT:
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800514 case IN_PHY_PORT:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700515 return matchCriterion((PortCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800516
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800517 case METADATA:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700518 return matchCriterion((MetadataCriterion) criterion);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800519
Ray Milkeydb358082015-01-13 16:34:38 -0800520 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800521 case ETH_SRC:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700522 return matchCriterion((EthCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800523
524 case ETH_TYPE:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700525 return matchCriterion((EthTypeCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800526
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800527 case VLAN_VID:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700528 return matchCriterion((VlanIdCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800529
530 case VLAN_PCP:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700531 return matchCriterion((VlanPcpCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800532
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800533 case IP_DSCP:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700534 return matchCriterion((IPDscpCriterion) criterion);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800535
536 case IP_ECN:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700537 return matchCriterion((IPEcnCriterion) criterion);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800538
Ray Milkeydb358082015-01-13 16:34:38 -0800539 case IP_PROTO:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700540 return matchCriterion((IPProtocolCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800541
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800542 case IPV4_SRC:
543 case IPV4_DST:
544 case IPV6_SRC:
545 case IPV6_DST:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700546 return matchCriterion((IPCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800547
548 case TCP_SRC:
549 case TCP_DST:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700550 return matchCriterion((TcpPortCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800551
552 case UDP_SRC:
553 case UDP_DST:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700554 return matchCriterion((UdpPortCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800555
556 case SCTP_SRC:
557 case SCTP_DST:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700558 return matchCriterion((SctpPortCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800559
560 case ICMPV4_TYPE:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700561 return matchCriterion((IcmpTypeCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800562
563 case ICMPV4_CODE:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700564 return matchCriterion((IcmpCodeCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800565
566 case IPV6_FLABEL:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700567 return matchCriterion((IPv6FlowLabelCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800568
569 case ICMPV6_TYPE:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700570 return matchCriterion((Icmpv6TypeCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800571
572 case ICMPV6_CODE:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700573 return matchCriterion((Icmpv6CodeCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800574
575 case IPV6_ND_TARGET:
Ray Milkey46670a82015-02-08 17:57:17 -0800576 return matchCriterion(
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700577 (IPv6NDTargetAddressCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800578
579 case IPV6_ND_SLL:
580 case IPV6_ND_TLL:
Ray Milkey46670a82015-02-08 17:57:17 -0800581 return matchCriterion(
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700582 (IPv6NDLinkLayerAddressCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800583
584 case MPLS_LABEL:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700585 return matchCriterion((MplsCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800586
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800587 case IPV6_EXTHDR:
Ray Milkey46670a82015-02-08 17:57:17 -0800588 return matchCriterion(
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700589 (IPv6ExthdrFlagsCriterion) criterion);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800590
Ray Milkeydb358082015-01-13 16:34:38 -0800591 case OCH_SIGID:
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -0700592 return matchCriterion((OchSignalCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800593
594 case OCH_SIGTYPE:
Sho SHIMIZU6c70f642015-05-29 17:27:22 -0700595 return matchCriterion((OchSignalTypeCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800596
597 default:
598 // Don't know how to format this type
599 description.appendText("unknown criterion type " +
600 criterion.type());
601 return false;
602 }
Ray Milkeydb358082015-01-13 16:34:38 -0800603 }
604
605 @Override
606 public void describeTo(Description description) {
607 description.appendText(criterion.toString());
608 }
Ray Milkeydb358082015-01-13 16:34:38 -0800609}