blob: acd7dab12e6061b31676d7427c77767bc6e061b0 [file] [log] [blame]
Ray Milkeydb358082015-01-13 16:34:38 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeydb358082015-01-13 16:34:38 -08003 *
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
Yafit Hadar5796d972015-10-15 13:16:11 +030018import java.util.Objects;
19
Ray Milkeydb358082015-01-13 16:34:38 -080020import org.hamcrest.Description;
21import org.hamcrest.TypeSafeDiagnosingMatcher;
Yafit Hadar5796d972015-10-15 13:16:11 +030022import org.onlab.util.HexString;
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -070023import org.onosproject.net.OchSignal;
Yafit Hadar5796d972015-10-15 13:16:11 +030024import org.onosproject.net.OduSignalId;
Ray Milkeydb358082015-01-13 16:34:38 -080025import org.onosproject.net.flow.criteria.Criterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070026import org.onosproject.net.flow.criteria.EthCriterion;
27import org.onosproject.net.flow.criteria.EthTypeCriterion;
28import org.onosproject.net.flow.criteria.IPCriterion;
29import org.onosproject.net.flow.criteria.IPDscpCriterion;
30import org.onosproject.net.flow.criteria.IPEcnCriterion;
31import org.onosproject.net.flow.criteria.IPProtocolCriterion;
32import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion;
33import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion;
34import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion;
35import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion;
36import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
37import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
38import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
39import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070040import org.onosproject.net.flow.criteria.MetadataCriterion;
41import org.onosproject.net.flow.criteria.MplsCriterion;
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -070042import org.onosproject.net.flow.criteria.OchSignalCriterion;
Sho SHIMIZU6c70f642015-05-29 17:27:22 -070043import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
Yafit Hadar5796d972015-10-15 13:16:11 +030044import org.onosproject.net.flow.criteria.OduSignalIdCriterion;
45import org.onosproject.net.flow.criteria.OduSignalTypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070046import org.onosproject.net.flow.criteria.PortCriterion;
47import org.onosproject.net.flow.criteria.SctpPortCriterion;
48import org.onosproject.net.flow.criteria.TcpPortCriterion;
49import org.onosproject.net.flow.criteria.UdpPortCriterion;
50import org.onosproject.net.flow.criteria.VlanIdCriterion;
51import org.onosproject.net.flow.criteria.VlanPcpCriterion;
Ray Milkeydb358082015-01-13 16:34:38 -080052
Yafit Hadar5796d972015-10-15 13:16:11 +030053import com.fasterxml.jackson.databind.JsonNode;
54import com.google.common.base.Joiner;
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -070055
Ray Milkeydb358082015-01-13 16:34:38 -080056/**
57 * Hamcrest matcher for criterion objects.
58 */
Ray Milkey46670a82015-02-08 17:57:17 -080059public final class CriterionJsonMatcher extends
60 TypeSafeDiagnosingMatcher<JsonNode> {
Ray Milkeydb358082015-01-13 16:34:38 -080061
62 final Criterion criterion;
Ray Milkey46670a82015-02-08 17:57:17 -080063 Description description;
64 JsonNode jsonCriterion;
Ray Milkeydb358082015-01-13 16:34:38 -080065
Ray Milkey46670a82015-02-08 17:57:17 -080066 /**
67 * Constructs a matcher object.
68 *
69 * @param criterionValue criterion to match
70 */
Ray Milkeydb358082015-01-13 16:34:38 -080071 private CriterionJsonMatcher(Criterion criterionValue) {
72 criterion = criterionValue;
73 }
74
Ray Milkey46670a82015-02-08 17:57:17 -080075 /**
76 * Factory to allocate an criterion matcher.
77 *
78 * @param criterion criterion object we are looking for
79 * @return matcher
80 */
81 public static CriterionJsonMatcher matchesCriterion(Criterion criterion) {
82 return new CriterionJsonMatcher(criterion);
83 }
84
85 /**
86 * Matches a port criterion object.
87 *
88 * @param criterion criterion to match
89 * @return true if the JSON matches the criterion, false otherwise.
90 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070091 private boolean matchCriterion(PortCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -080092 final long port = criterion.port().toLong();
93 final long jsonPort = jsonCriterion.get("port").asLong();
94 if (port != jsonPort) {
95 description.appendText("port was " + Long.toString(jsonPort));
96 return false;
97 }
98 return true;
99 }
100
101 /**
102 * Matches a metadata criterion object.
103 *
104 * @param criterion criterion to match
105 * @return true if the JSON matches the criterion, false otherwise.
106 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700107 private boolean matchCriterion(MetadataCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800108 final long metadata = criterion.metadata();
109 final long jsonMetadata = jsonCriterion.get("metadata").asLong();
110 if (metadata != jsonMetadata) {
111 description.appendText("metadata was "
112 + Long.toString(jsonMetadata));
113 return false;
114 }
115 return true;
116 }
117
118 /**
119 * Matches an eth criterion object.
120 *
121 * @param criterion criterion to match
122 * @return true if the JSON matches the criterion, false otherwise.
123 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700124 private boolean matchCriterion(EthCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800125 final String mac = criterion.mac().toString();
126 final String jsonMac = jsonCriterion.get("mac").textValue();
127 if (!mac.equals(jsonMac)) {
128 description.appendText("mac was " + jsonMac);
129 return false;
130 }
131 return true;
132 }
133
134 /**
135 * Matches an eth type criterion object.
136 *
137 * @param criterion criterion to match
138 * @return true if the JSON matches the criterion, false otherwise.
139 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700140 private boolean matchCriterion(EthTypeCriterion criterion) {
andread35f89c2015-11-23 10:02:07 -0800141 final int ethType = criterion.ethType().toShort() & 0xffff;
142 final int jsonEthType = Integer.decode(jsonCriterion.get("ethType").textValue()) & 0xffff;
Ray Milkey46670a82015-02-08 17:57:17 -0800143 if (ethType != jsonEthType) {
144 description.appendText("ethType was "
145 + Integer.toString(jsonEthType));
146 return false;
147 }
148 return true;
149 }
150
151 /**
152 * Matches a VLAN ID criterion object.
153 *
154 * @param criterion criterion to match
155 * @return true if the JSON matches the criterion, false otherwise.
156 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700157 private boolean matchCriterion(VlanIdCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800158 final short vlanId = criterion.vlanId().toShort();
159 final short jsonVlanId = jsonCriterion.get("vlanId").shortValue();
160 if (vlanId != jsonVlanId) {
161 description.appendText("vlanId was " + Short.toString(jsonVlanId));
162 return false;
163 }
164 return true;
165 }
166
167 /**
168 * Matches a VLAN PCP criterion object.
169 *
170 * @param criterion criterion to match
171 * @return true if the JSON matches the criterion, false otherwise.
172 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700173 private boolean matchCriterion(VlanPcpCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800174 final byte priority = criterion.priority();
175 final byte jsonPriority =
176 (byte) jsonCriterion.get("priority").shortValue();
177 if (priority != jsonPriority) {
178 description.appendText("priority was " + Byte.toString(jsonPriority));
179 return false;
180 }
181 return true;
182 }
183
184 /**
185 * Matches an IP DSCP criterion object.
186 *
187 * @param criterion criterion to match
188 * @return true if the JSON matches the criterion, false otherwise.
189 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700190 private boolean matchCriterion(IPDscpCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800191 final byte ipDscp = criterion.ipDscp();
192 final byte jsonIpDscp = (byte) jsonCriterion.get("ipDscp").shortValue();
193 if (ipDscp != jsonIpDscp) {
194 description.appendText("IP DSCP was " + Byte.toString(jsonIpDscp));
195 return false;
196 }
197 return true;
198 }
199
200 /**
201 * Matches an IP ECN criterion object.
202 *
203 * @param criterion criterion to match
204 * @return true if the JSON matches the criterion, false otherwise.
205 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700206 private boolean matchCriterion(IPEcnCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800207 final byte ipEcn = criterion.ipEcn();
208 final byte jsonIpEcn = (byte) jsonCriterion.get("ipEcn").shortValue();
209 if (ipEcn != jsonIpEcn) {
210 description.appendText("IP ECN was " + Byte.toString(jsonIpEcn));
211 return false;
212 }
213 return true;
214 }
215
216 /**
217 * Matches an IP protocol criterion object.
218 *
219 * @param criterion criterion to match
220 * @return true if the JSON matches the criterion, false otherwise.
221 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700222 private boolean matchCriterion(IPProtocolCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800223 final short protocol = criterion.protocol();
224 final short jsonProtocol = jsonCriterion.get("protocol").shortValue();
225 if (protocol != jsonProtocol) {
226 description.appendText("protocol was "
227 + Short.toString(jsonProtocol));
228 return false;
229 }
230 return true;
231 }
232
233 /**
234 * Matches an IP address criterion object.
235 *
236 * @param criterion criterion to match
237 * @return true if the JSON matches the criterion, false otherwise.
238 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700239 private boolean matchCriterion(IPCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800240 final String ip = criterion.ip().toString();
241 final String jsonIp = jsonCriterion.get("ip").textValue();
242 if (!ip.equals(jsonIp)) {
243 description.appendText("ip was " + jsonIp);
244 return false;
245 }
246 return true;
247 }
248
249 /**
250 * Matches a TCP port criterion object.
251 *
252 * @param criterion criterion to match
253 * @return true if the JSON matches the criterion, false otherwise.
254 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700255 private boolean matchCriterion(TcpPortCriterion criterion) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700256 final int tcpPort = criterion.tcpPort().toInt();
Ray Milkey46670a82015-02-08 17:57:17 -0800257 final int jsonTcpPort = jsonCriterion.get("tcpPort").intValue();
258 if (tcpPort != jsonTcpPort) {
259 description.appendText("tcp port was "
260 + Integer.toString(jsonTcpPort));
261 return false;
262 }
263 return true;
264 }
265
266 /**
267 * Matches a UDP port criterion object.
268 *
269 * @param criterion criterion to match
270 * @return true if the JSON matches the criterion, false otherwise.
271 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700272 private boolean matchCriterion(UdpPortCriterion criterion) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700273 final int udpPort = criterion.udpPort().toInt();
Ray Milkey46670a82015-02-08 17:57:17 -0800274 final int jsonUdpPort = jsonCriterion.get("udpPort").intValue();
275 if (udpPort != jsonUdpPort) {
276 description.appendText("udp port was "
277 + Integer.toString(jsonUdpPort));
278 return false;
279 }
280 return true;
281 }
282
283 /**
284 * Matches an SCTP port criterion object.
285 *
286 * @param criterion criterion to match
287 * @return true if the JSON matches the criterion, false otherwise.
288 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700289 private boolean matchCriterion(SctpPortCriterion criterion) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700290 final int sctpPort = criterion.sctpPort().toInt();
Ray Milkey46670a82015-02-08 17:57:17 -0800291 final int jsonSctpPort = jsonCriterion.get("sctpPort").intValue();
292 if (sctpPort != jsonSctpPort) {
293 description.appendText("sctp port was "
294 + Integer.toString(jsonSctpPort));
295 return false;
296 }
297 return true;
298 }
299
300 /**
301 * Matches an ICMP type criterion object.
302 *
303 * @param criterion criterion to match
304 * @return true if the JSON matches the criterion, false otherwise.
305 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700306 private boolean matchCriterion(IcmpTypeCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800307 final short icmpType = criterion.icmpType();
308 final short jsonIcmpType = jsonCriterion.get("icmpType").shortValue();
309 if (icmpType != jsonIcmpType) {
310 description.appendText("icmp type was "
311 + Short.toString(jsonIcmpType));
312 return false;
313 }
314 return true;
315 }
316
317 /**
318 * Matches an ICMP code criterion object.
319 *
320 * @param criterion criterion to match
321 * @return true if the JSON matches the criterion, false otherwise.
322 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700323 private boolean matchCriterion(IcmpCodeCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800324 final short icmpCode = criterion.icmpCode();
325 final short jsonIcmpCode = jsonCriterion.get("icmpCode").shortValue();
326 if (icmpCode != jsonIcmpCode) {
327 description.appendText("icmp code was "
328 + Short.toString(jsonIcmpCode));
329 return false;
330 }
331 return true;
332 }
333
334 /**
335 * Matches an IPV6 flow label criterion object.
336 *
337 * @param criterion criterion to match
338 * @return true if the JSON matches the criterion, false otherwise.
339 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700340 private boolean matchCriterion(IPv6FlowLabelCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800341 final int flowLabel = criterion.flowLabel();
342 final int jsonFlowLabel = jsonCriterion.get("flowLabel").intValue();
343 if (flowLabel != jsonFlowLabel) {
344 description.appendText("IPv6 flow label was "
345 + Integer.toString(jsonFlowLabel));
346 return false;
347 }
348 return true;
349 }
350
351 /**
352 * Matches an ICMP V6 type criterion object.
353 *
354 * @param criterion criterion to match
355 * @return true if the JSON matches the criterion, false otherwise.
356 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700357 private boolean matchCriterion(Icmpv6TypeCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800358 final short icmpv6Type = criterion.icmpv6Type();
359 final short jsonIcmpv6Type =
360 jsonCriterion.get("icmpv6Type").shortValue();
361 if (icmpv6Type != jsonIcmpv6Type) {
362 description.appendText("icmpv6 type was "
363 + Short.toString(jsonIcmpv6Type));
364 return false;
365 }
366 return true;
367 }
368
369 /**
370 * Matches an IPV6 code criterion object.
371 *
372 * @param criterion criterion to match
373 * @return true if the JSON matches the criterion, false otherwise.
374 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700375 private boolean matchCriterion(Icmpv6CodeCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800376 final short icmpv6Code = criterion.icmpv6Code();
377 final short jsonIcmpv6Code =
378 jsonCriterion.get("icmpv6Code").shortValue();
379 if (icmpv6Code != jsonIcmpv6Code) {
380 description.appendText("icmpv6 code was "
381 + Short.toString(jsonIcmpv6Code));
382 return false;
383 }
384 return true;
385 }
386
387 /**
388 * Matches an IPV6 ND target criterion object.
389 *
390 * @param criterion criterion to match
391 * @return true if the JSON matches the criterion, false otherwise.
392 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700393 private boolean matchCriterion(IPv6NDTargetAddressCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800394 final String targetAddress =
395 criterion.targetAddress().toString();
396 final String jsonTargetAddress =
397 jsonCriterion.get("targetAddress").textValue();
398 if (!targetAddress.equals(jsonTargetAddress)) {
399 description.appendText("target address was " +
400 jsonTargetAddress);
401 return false;
402 }
403 return true;
404 }
405
406 /**
407 * Matches an IPV6 ND link layer criterion object.
408 *
409 * @param criterion criterion to match
410 * @return true if the JSON matches the criterion, false otherwise.
411 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700412 private boolean matchCriterion(IPv6NDLinkLayerAddressCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800413 final String llAddress =
414 criterion.mac().toString();
415 final String jsonLlAddress =
416 jsonCriterion.get("mac").textValue();
417 if (!llAddress.equals(jsonLlAddress)) {
418 description.appendText("mac was " + jsonLlAddress);
419 return false;
420 }
421 return true;
422 }
423
424 /**
425 * Matches an MPLS label criterion object.
426 *
427 * @param criterion criterion to match
428 * @return true if the JSON matches the criterion, false otherwise.
429 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700430 private boolean matchCriterion(MplsCriterion criterion) {
Michele Santuari4b6019e2014-12-19 11:31:45 +0100431 final int label = criterion.label().toInt();
Ray Milkey46670a82015-02-08 17:57:17 -0800432 final int jsonLabel = jsonCriterion.get("label").intValue();
433 if (label != jsonLabel) {
434 description.appendText("label was " + Integer.toString(jsonLabel));
435 return false;
436 }
437 return true;
438 }
439
440 /**
441 * Matches an IPV6 exthdr criterion object.
442 *
443 * @param criterion criterion to match
444 * @return true if the JSON matches the criterion, false otherwise.
445 */
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700446 private boolean matchCriterion(IPv6ExthdrFlagsCriterion criterion) {
Ray Milkey46670a82015-02-08 17:57:17 -0800447 final int exthdrFlags = criterion.exthdrFlags();
448 final int jsonExthdrFlags =
449 jsonCriterion.get("exthdrFlags").intValue();
450 if (exthdrFlags != jsonExthdrFlags) {
451 description.appendText("exthdrFlags was "
452 + Long.toHexString(jsonExthdrFlags));
453 return false;
454 }
455 return true;
456 }
457
458 /**
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -0700459 * Matches an Och signal criterion object.
Ray Milkey46670a82015-02-08 17:57:17 -0800460 *
461 * @param criterion criterion to match
462 * @return true if the JSON matches the criterion, false otherwise.
463 */
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -0700464 private boolean matchCriterion(OchSignalCriterion criterion) {
465 final OchSignal ochSignal = criterion.lambda();
466 final JsonNode jsonOchSignal = jsonCriterion.get("ochSignalId");
467 String jsonGridType = jsonOchSignal.get("gridType").textValue();
468 String jsonChannelSpacing = jsonOchSignal.get("channelSpacing").textValue();
469 int jsonSpacingMultiplier = jsonOchSignal.get("spacingMultiplier").intValue();
470 int jsonSlotGranularity = jsonOchSignal.get("slotGranularity").intValue();
471
472 boolean equality = Objects.equals(ochSignal.gridType().name(), jsonGridType)
473 && Objects.equals(ochSignal.channelSpacing().name(), jsonChannelSpacing)
474 && Objects.equals(ochSignal.spacingMultiplier(), jsonSpacingMultiplier)
475 && Objects.equals(ochSignal.slotGranularity(), jsonSlotGranularity);
476
477 if (!equality) {
478 String joined = Joiner.on(", ")
479 .join(jsonGridType, jsonChannelSpacing, jsonSpacingMultiplier, jsonSlotGranularity);
480
481 description.appendText("och signal id was " + joined);
Ray Milkey46670a82015-02-08 17:57:17 -0800482 return false;
483 }
484 return true;
485 }
486
487 /**
Sho SHIMIZU68b8c1f2015-05-29 18:42:26 -0700488 * Matches an Och signal type criterion object.
Ray Milkey46670a82015-02-08 17:57:17 -0800489 *
490 * @param criterion criterion to match
491 * @return true if the JSON matches the criterion, false otherwise.
492 */
Sho SHIMIZU6c70f642015-05-29 17:27:22 -0700493 private boolean matchCriterion(OchSignalTypeCriterion criterion) {
494 final String signalType = criterion.signalType().name();
495 final String jsonSignalType = jsonCriterion.get("ochSignalType").textValue();
496 if (!signalType.equals(jsonSignalType)) {
Sho SHIMIZUc06966e2015-06-01 12:14:37 -0700497 description.appendText("signal type was " + jsonSignalType);
Ray Milkey46670a82015-02-08 17:57:17 -0800498 return false;
499 }
500 return true;
501 }
502
Yafit Hadar5796d972015-10-15 13:16:11 +0300503 /**
504 * Matches an ODU signal ID criterion object.
505 *
506 * @param criterion criterion to match
507 * @return true if the JSON matches the criterion, false otherwise.
508 */
509 private boolean matchCriterion(OduSignalIdCriterion criterion) {
510 final OduSignalId oduSignal = criterion.oduSignalId();
511 final JsonNode jsonOduSignal = jsonCriterion.get(CriterionCodec.ODU_SIGNAL_ID);
512 int jsonTpn = jsonOduSignal.get(CriterionCodec.TRIBUTARY_PORT_NUMBER).intValue();
513 int jsonTsLen = jsonOduSignal.get(CriterionCodec.TRIBUTARY_SLOT_LEN).intValue();
514 byte[] jsonTributaryBitMap = HexString.fromHexString(
515 jsonOduSignal.get(CriterionCodec.TRIBUTARY_SLOT_BITMAP).asText());
516 OduSignalId jsonOduSignalId = OduSignalId.oduSignalId(jsonTpn, jsonTsLen, jsonTributaryBitMap);
517 if (!oduSignal.equals(jsonOduSignalId)) {
518 description.appendText("oduSignalId was " + criterion);
519 return false;
520 }
521 return true;
522 }
523
524 /**
525 * Matches an ODU signal Type criterion object.
526 *
527 * @param criterion criterion to match
528 * @return true if the JSON matches the criterion, false otherwise.
529 */
530 private boolean matchCriterion(OduSignalTypeCriterion criterion) {
531 final String signalType = criterion.signalType().name();
532 final String jsonOduSignalType = jsonCriterion.get("oduSignalType").textValue();
533 if (!signalType.equals(jsonOduSignalType)) {
534 description.appendText("signalType was " + signalType);
535 return false;
536 }
537 return true;
538 }
539
540
Ray Milkeydb358082015-01-13 16:34:38 -0800541 @Override
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800542 public boolean matchesSafely(JsonNode jsonCriterion,
543 Description description) {
Ray Milkey46670a82015-02-08 17:57:17 -0800544 this.description = description;
545 this.jsonCriterion = jsonCriterion;
Ray Milkeydb358082015-01-13 16:34:38 -0800546 final String type = criterion.type().name();
547 final String jsonType = jsonCriterion.get("type").asText();
548 if (!type.equals(jsonType)) {
549 description.appendText("type was " + type);
550 return false;
551 }
552
553 switch (criterion.type()) {
554
555 case IN_PORT:
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800556 case IN_PHY_PORT:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700557 return matchCriterion((PortCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800558
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800559 case METADATA:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700560 return matchCriterion((MetadataCriterion) criterion);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800561
Ray Milkeydb358082015-01-13 16:34:38 -0800562 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800563 case ETH_SRC:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700564 return matchCriterion((EthCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800565
566 case ETH_TYPE:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700567 return matchCriterion((EthTypeCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800568
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800569 case VLAN_VID:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700570 return matchCriterion((VlanIdCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800571
572 case VLAN_PCP:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700573 return matchCriterion((VlanPcpCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800574
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800575 case IP_DSCP:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700576 return matchCriterion((IPDscpCriterion) criterion);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800577
578 case IP_ECN:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700579 return matchCriterion((IPEcnCriterion) criterion);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800580
Ray Milkeydb358082015-01-13 16:34:38 -0800581 case IP_PROTO:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700582 return matchCriterion((IPProtocolCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800583
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800584 case IPV4_SRC:
585 case IPV4_DST:
586 case IPV6_SRC:
587 case IPV6_DST:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700588 return matchCriterion((IPCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800589
590 case TCP_SRC:
591 case TCP_DST:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700592 return matchCriterion((TcpPortCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800593
594 case UDP_SRC:
595 case UDP_DST:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700596 return matchCriterion((UdpPortCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800597
598 case SCTP_SRC:
599 case SCTP_DST:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700600 return matchCriterion((SctpPortCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800601
602 case ICMPV4_TYPE:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700603 return matchCriterion((IcmpTypeCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800604
605 case ICMPV4_CODE:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700606 return matchCriterion((IcmpCodeCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800607
608 case IPV6_FLABEL:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700609 return matchCriterion((IPv6FlowLabelCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800610
611 case ICMPV6_TYPE:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700612 return matchCriterion((Icmpv6TypeCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800613
614 case ICMPV6_CODE:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700615 return matchCriterion((Icmpv6CodeCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800616
617 case IPV6_ND_TARGET:
Ray Milkey46670a82015-02-08 17:57:17 -0800618 return matchCriterion(
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700619 (IPv6NDTargetAddressCriterion) criterion);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800620
621 case IPV6_ND_SLL:
622 case IPV6_ND_TLL:
Ray Milkey46670a82015-02-08 17:57:17 -0800623 return matchCriterion(
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700624 (IPv6NDLinkLayerAddressCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800625
626 case MPLS_LABEL:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700627 return matchCriterion((MplsCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800628
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800629 case IPV6_EXTHDR:
Ray Milkey46670a82015-02-08 17:57:17 -0800630 return matchCriterion(
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700631 (IPv6ExthdrFlagsCriterion) criterion);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800632
Ray Milkeydb358082015-01-13 16:34:38 -0800633 case OCH_SIGID:
Sho SHIMIZUc44c0c32015-06-01 11:40:48 -0700634 return matchCriterion((OchSignalCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800635
636 case OCH_SIGTYPE:
Sho SHIMIZU6c70f642015-05-29 17:27:22 -0700637 return matchCriterion((OchSignalTypeCriterion) criterion);
Ray Milkeydb358082015-01-13 16:34:38 -0800638
Yafit Hadar5796d972015-10-15 13:16:11 +0300639 case ODU_SIGID:
640 return matchCriterion((OduSignalIdCriterion) criterion);
641
642 case ODU_SIGTYPE:
643 return matchCriterion((OduSignalTypeCriterion) criterion);
644
Ray Milkeydb358082015-01-13 16:34:38 -0800645 default:
646 // Don't know how to format this type
647 description.appendText("unknown criterion type " +
648 criterion.type());
649 return false;
650 }
Ray Milkeydb358082015-01-13 16:34:38 -0800651 }
652
653 @Override
654 public void describeTo(Description description) {
655 description.appendText(criterion.toString());
656 }
Ray Milkeydb358082015-01-13 16:34:38 -0800657}