blob: dc3c49721fab6ca89afe15a4fc15e362fa8603b5 [file] [log] [blame]
Ray Milkeyd03eda02015-01-09 14:58:48 -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
Jian Lice8c5602016-03-03 21:43:24 -080018import com.fasterxml.jackson.databind.JsonNode;
Ray Milkeyd03eda02015-01-09 14:58:48 -080019import org.hamcrest.Description;
Ray Milkeyd03eda02015-01-09 14:58:48 -080020import org.hamcrest.TypeSafeDiagnosingMatcher;
Yafit Hadar5796d972015-10-15 13:16:11 +030021import org.onlab.util.HexString;
22import org.onosproject.net.OduSignalId;
Ray Milkeyd03eda02015-01-09 14:58:48 -080023import org.onosproject.net.flow.instructions.Instruction;
Jian Lice8c5602016-03-03 21:43:24 -080024import org.onosproject.net.flow.instructions.Instructions.GroupInstruction;
Jian Li47b26232016-03-07 09:59:59 -080025import org.onosproject.net.flow.instructions.Instructions.MeterInstruction;
Yafit Hadar5796d972015-10-15 13:16:11 +030026import org.onosproject.net.flow.instructions.Instructions.NoActionInstruction;
27import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
Jian Li70dffe42016-03-08 22:23:02 -080028import org.onosproject.net.flow.instructions.Instructions.SetQueueInstruction;
Yafit Hadar5796d972015-10-15 13:16:11 +030029import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
30import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction;
31import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction;
32import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
33import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction;
34import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
35import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
36import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeaderInstructions;
37import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
38import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
Ray Milkeyd03eda02015-01-09 14:58:48 -080039
Ray Milkeyd03eda02015-01-09 14:58:48 -080040/**
41 * Hamcrest matcher for instructions.
42 */
Ray Milkeydb358082015-01-13 16:34:38 -080043public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
Ray Milkeyd03eda02015-01-09 14:58:48 -080044
45 private final Instruction instruction;
46
Ray Milkeydb358082015-01-13 16:34:38 -080047 private InstructionJsonMatcher(Instruction instructionValue) {
Ray Milkeyd03eda02015-01-09 14:58:48 -080048 instruction = instructionValue;
49 }
50
51 /**
52 * Matches the contents of a push header instruction.
53 *
54 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080055 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -080056 * @return true if contents match, false otherwise
57 */
58 private boolean matchPushHeaderInstruction(JsonNode instructionJson,
59 Description description) {
60 PushHeaderInstructions instructionToMatch =
61 (PushHeaderInstructions) instruction;
62 final String jsonSubtype = instructionJson.get("subtype").textValue();
63 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
64 description.appendText("subtype was " + jsonSubtype);
65 return false;
66 }
67
68 final String jsonType = instructionJson.get("type").textValue();
69 if (!instructionToMatch.type().name().equals(jsonType)) {
70 description.appendText("type was " + jsonType);
71 return false;
72 }
73
74 final JsonNode ethJson = instructionJson.get("ethernetType");
75 if (ethJson == null) {
76 description.appendText("ethernetType was not null");
77 return false;
78 }
79
alshabib7b808c52015-06-26 14:22:24 -070080 if (instructionToMatch.ethernetType().toShort() != ethJson.asInt()) {
Yuta HIGUCHI32a53c52015-02-08 01:25:40 -080081 description.appendText("ethernetType was " + ethJson);
Ray Milkeyd03eda02015-01-09 14:58:48 -080082 return false;
83 }
Yuta HIGUCHI32a53c52015-02-08 01:25:40 -080084
Ray Milkeyd03eda02015-01-09 14:58:48 -080085 return true;
86 }
87
88 /**
89 * Matches the contents of an output instruction.
90 *
91 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080092 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -080093 * @return true if contents match, false otherwise
94 */
95 private boolean matchOutputInstruction(JsonNode instructionJson,
96 Description description) {
Ray Milkeyd03eda02015-01-09 14:58:48 -080097 final String jsonType = instructionJson.get("type").textValue();
Andrea Campanella5df35952015-12-08 15:46:49 -080098 OutputInstruction instructionToMatch = (OutputInstruction) instruction;
Ray Milkeyd03eda02015-01-09 14:58:48 -080099 if (!instructionToMatch.type().name().equals(jsonType)) {
100 description.appendText("type was " + jsonType);
101 return false;
102 }
103
Andrea Campanella5df35952015-12-08 15:46:49 -0800104 if (instructionJson.get("port").isLong() ||
105 instructionJson.get("port").isInt()) {
106 final long jsonPort = instructionJson.get("port").asLong();
107 if (instructionToMatch.port().toLong() != (jsonPort)) {
108 description.appendText("port was " + jsonPort);
109 return false;
110 }
111 } else if (instructionJson.get("port").isTextual()) {
112 final String jsonPort = instructionJson.get("port").textValue();
113 if (!instructionToMatch.port().toString().equals(jsonPort)) {
114 description.appendText("port was " + jsonPort);
115 return false;
116 }
117 } else {
118 final String jsonPort = instructionJson.get("port").toString();
Jian Li70dffe42016-03-08 22:23:02 -0800119 description.appendText("Unmatching types ");
Andrea Campanella5df35952015-12-08 15:46:49 -0800120 description.appendText("instructionToMatch " + instructionToMatch.port().toString());
121 description.appendText("jsonPort " + jsonPort);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800122 }
123
124 return true;
125 }
126
127 /**
Jian Lice8c5602016-03-03 21:43:24 -0800128 * Matches the contents of a group instruction.
129 *
130 * @param instructionJson JSON instruction to match
131 * @param description Description object used for recording errors
132 * @return true if contents match, false otherwise
133 */
134 private boolean matchGroupInstruction(JsonNode instructionJson,
135 Description description) {
136 final String jsonType = instructionJson.get("type").textValue();
137 GroupInstruction instructionToMatch = (GroupInstruction) instruction;
138 if (!instructionToMatch.type().name().equals(jsonType)) {
139 description.appendText("type was " + jsonType);
140 return false;
141 }
142
Jian Li47b26232016-03-07 09:59:59 -0800143 final int jsonGroupId = instructionJson.get("groupId").intValue();
144 if (instructionToMatch.groupId().id() != jsonGroupId) {
145 description.appendText("groupId was " + jsonGroupId);
146 return false;
147 }
148
149 return true;
150 }
151
152 /**
153 * Matches the contents of a meter instruction.
154 *
155 * @param instructionJson JSON instruction to match
156 * @param description Description object used for recording errors
157 * @return true if contents match, false otherwise
158 */
159 private boolean matchMeterInstruction(JsonNode instructionJson,
160 Description description) {
161 final String jsonType = instructionJson.get("type").textValue();
162 MeterInstruction instructionToMatch = (MeterInstruction) instruction;
163 if (!instructionToMatch.type().name().equals(jsonType)) {
164 description.appendText("type was " + jsonType);
165 return false;
166 }
167
168 final long jsonMeterId = instructionJson.get("meterId").longValue();
169 if (instructionToMatch.meterId().id() != jsonMeterId) {
170 description.appendText("meterId was " + jsonMeterId);
171 return false;
Jian Lice8c5602016-03-03 21:43:24 -0800172 }
173
174 return true;
175 }
176
177 /**
Jian Li70dffe42016-03-08 22:23:02 -0800178 * Matches the contents of a set queue instruction.
179 *
180 * @param instructionJson JSON instruction to match
181 * @param description Description object used for recording errors
182 * @return true if contents match, false otherwise
183 */
184 private boolean matchSetQueueInstruction(JsonNode instructionJson,
185 Description description) {
186 final String jsonType = instructionJson.get("type").textValue();
187 SetQueueInstruction instructionToMatch = (SetQueueInstruction) instruction;
188 if (!instructionToMatch.type().name().equals(jsonType)) {
189 description.appendText("type was " + jsonType);
190 return false;
191 }
192
193 final long jsonQueueId = instructionJson.get("queueId").longValue();
194 if (instructionToMatch.queueId() != jsonQueueId) {
195 description.appendText("queueId was " + jsonQueueId);
196 return false;
197 }
198
199 if (instructionJson.get("port").isLong() ||
200 instructionJson.get("port").isInt()) {
201 final long jsonPort = instructionJson.get("port").asLong();
202 if (instructionToMatch.port().toLong() != (jsonPort)) {
203 description.appendText("port was " + jsonPort);
204 return false;
205 }
206 } else if (instructionJson.get("port").isTextual()) {
207 final String jsonPort = instructionJson.get("port").textValue();
208 if (!instructionToMatch.port().toString().equals(jsonPort)) {
209 description.appendText("port was " + jsonPort);
210 return false;
211 }
212 } else {
213 final String jsonPort = instructionJson.get("port").toString();
214 description.appendText("Unmatching types ");
215 description.appendText("instructionToMatch " + instructionToMatch.port().toString());
216 description.appendText("jsonPort " + jsonPort);
217 }
218
219 return true;
220 }
221
222 /**
Ray Milkeyd03eda02015-01-09 14:58:48 -0800223 * Matches the contents of a mod lambda instruction.
224 *
225 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800226 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800227 * @return true if contents match, false otherwise
228 */
229 private boolean matchModLambdaInstruction(JsonNode instructionJson,
230 Description description) {
231 ModLambdaInstruction instructionToMatch =
232 (ModLambdaInstruction) instruction;
233 final String jsonSubtype = instructionJson.get("subtype").textValue();
234 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
235 description.appendText("subtype was " + jsonSubtype);
236 return false;
237 }
238
239 final String jsonType = instructionJson.get("type").textValue();
240 if (!instructionToMatch.type().name().equals(jsonType)) {
241 description.appendText("type was " + jsonType);
242 return false;
243 }
244
245 final long jsonLambda = instructionJson.get("lambda").shortValue();
246 if (instructionToMatch.lambda() != jsonLambda) {
247 description.appendText("lambda was " + jsonLambda);
248 return false;
249 }
250
251 return true;
252 }
253
254 /**
Yafit Hadar5796d972015-10-15 13:16:11 +0300255 * Matches the contents of a mod OCh singal instruction.
Sho SHIMIZUed7af542015-05-05 19:10:45 -0700256 *
257 * @param instructionJson JSON instruction to match
258 * @param description Description object used for recording errors
259 * @return true if contents matches, false otherwise
260 */
261 private boolean matchModOchSingalInstruction(JsonNode instructionJson,
262 Description description) {
263 ModOchSignalInstruction instructionToMatch =
264 (ModOchSignalInstruction) instruction;
265
266 String jsonSubType = instructionJson.get("subtype").textValue();
267 if (!instructionToMatch.subtype().name().equals(jsonSubType)) {
268 description.appendText("subtype was " + jsonSubType);
269 return false;
270 }
271
272 String jsonType = instructionJson.get("type").textValue();
273 if (!instructionToMatch.type().name().equals(jsonType)) {
274 description.appendText("type was " + jsonType);
275 return false;
276 }
277
278 String jsonGridType = instructionJson.get("gridType").textValue();
279 if (!instructionToMatch.lambda().gridType().name().equals(jsonGridType)) {
280 description.appendText("gridType was " + jsonGridType);
281 return false;
282 }
283
284 String jsonChannelSpacing = instructionJson.get("channelSpacing").textValue();
285 if (!instructionToMatch.lambda().channelSpacing().name().equals(jsonChannelSpacing)) {
286 description.appendText("channelSpacing was " + jsonChannelSpacing);
287 return false;
288 }
289
290 int jsonSpacingMultiplier = instructionJson.get("spacingMultiplier").intValue();
291 if (instructionToMatch.lambda().spacingMultiplier() != jsonSpacingMultiplier) {
292 description.appendText("spacingMultiplier was " + jsonSpacingMultiplier);
293 return false;
294 }
295
296 int jsonSlotGranularity = instructionJson.get("slotGranularity").intValue();
297 if (instructionToMatch.lambda().slotGranularity() != jsonSlotGranularity) {
298 description.appendText("slotGranularity was " + jsonSlotGranularity);
299 return false;
300 }
301
302 return true;
303 }
304
305 /**
Yafit Hadar5796d972015-10-15 13:16:11 +0300306 * Matches the contents of a mod ODU singal Id instruction.
307 *
308 * @param instructionJson JSON instruction to match
309 * @param description Description object used for recording errors
310 * @return true if contents matches, false otherwise
311 */
312 private boolean matchModOduSingalIdInstruction(JsonNode instructionJson,
313 Description description) {
314 ModOduSignalIdInstruction instructionToMatch =
315 (ModOduSignalIdInstruction) instruction;
316 String jsonSubType = instructionJson.get("subtype").textValue();
317 if (!instructionToMatch.subtype().name().equals(jsonSubType)) {
318 description.appendText("subtype was " + jsonSubType);
319 return false;
320 }
321 String jsonType = instructionJson.get("type").textValue();
322 if (!instructionToMatch.type().name().equals(jsonType)) {
323 description.appendText("type was " + jsonType);
324 return false;
325 }
326 final JsonNode jsonOduSignal = instructionJson.get("oduSignalId");
327 int jsonTpn = jsonOduSignal.get("tributaryPortNumber").intValue();
328 int jsonTsLen = jsonOduSignal.get("tributarySlotLength").intValue();
Jian Li68c4fc42016-01-11 16:07:03 -0800329 byte[] tributaryBitMap = HexString.fromHexString(jsonOduSignal.get("tributarySlotBitmap").asText());
Yafit Hadar5796d972015-10-15 13:16:11 +0300330 OduSignalId jsonOduSignalId = OduSignalId.oduSignalId(jsonTpn, jsonTsLen, tributaryBitMap);
331 if (!instructionToMatch.oduSignalId().equals(jsonOduSignalId)) {
332 description.appendText("oduSignalId was " + instructionToMatch);
333 return false;
334 }
335 return true;
336 }
337
338
339 /**
Ray Milkeydb358082015-01-13 16:34:38 -0800340 * Matches the contents of a mod Ethernet instruction.
Ray Milkeyd03eda02015-01-09 14:58:48 -0800341 *
342 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800343 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800344 * @return true if contents match, false otherwise
345 */
346 private boolean matchModEtherInstruction(JsonNode instructionJson,
347 Description description) {
348 ModEtherInstruction instructionToMatch =
349 (ModEtherInstruction) instruction;
350 final String jsonSubtype = instructionJson.get("subtype").textValue();
351 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
352 description.appendText("subtype was " + jsonSubtype);
353 return false;
354 }
355
356 final String jsonType = instructionJson.get("type").textValue();
357 if (!instructionToMatch.type().name().equals(jsonType)) {
358 description.appendText("type was " + jsonType);
359 return false;
360 }
361
362 final String jsonMac = instructionJson.get("mac").textValue();
363 final String mac = instructionToMatch.mac().toString();
364 if (!mac.equals(jsonMac)) {
365 description.appendText("mac was " + jsonMac);
366 return false;
367 }
368
369 return true;
370 }
371
372 /**
373 * Matches the contents of a mod vlan id instruction.
374 *
375 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800376 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800377 * @return true if contents match, false otherwise
378 */
379 private boolean matchModVlanIdInstruction(JsonNode instructionJson,
380 Description description) {
381 ModVlanIdInstruction instructionToMatch =
382 (ModVlanIdInstruction) instruction;
383 final String jsonSubtype = instructionJson.get("subtype").textValue();
384 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
385 description.appendText("subtype was " + jsonSubtype);
386 return false;
387 }
388
389 final String jsonType = instructionJson.get("type").textValue();
390 if (!instructionToMatch.type().name().equals(jsonType)) {
391 description.appendText("type was " + jsonType);
392 return false;
393 }
394
395 final short jsonVlanId = instructionJson.get("vlanId").shortValue();
396 final short vlanId = instructionToMatch.vlanId().toShort();
397 if (jsonVlanId != vlanId) {
398 description.appendText("vlan id was " + jsonVlanId);
399 return false;
400 }
401
402 return true;
403 }
404
405 /**
406 * Matches the contents of a mod vlan pcp instruction.
407 *
408 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800409 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800410 * @return true if contents match, false otherwise
411 */
412 private boolean matchModVlanPcpInstruction(JsonNode instructionJson,
413 Description description) {
414 ModVlanPcpInstruction instructionToMatch =
415 (ModVlanPcpInstruction) instruction;
416 final String jsonSubtype = instructionJson.get("subtype").textValue();
417 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
418 description.appendText("subtype was " + jsonSubtype);
419 return false;
420 }
421
422 final String jsonType = instructionJson.get("type").textValue();
423 if (!instructionToMatch.type().name().equals(jsonType)) {
424 description.appendText("type was " + jsonType);
425 return false;
426 }
427
428 final short jsonVlanPcp = instructionJson.get("vlanPcp").shortValue();
429 final short vlanId = instructionToMatch.vlanPcp();
430 if (jsonVlanPcp != vlanId) {
431 description.appendText("vlan pcp was " + jsonVlanPcp);
432 return false;
433 }
434
435 return true;
436 }
437
438 /**
439 * Matches the contents of a mod ip instruction.
440 *
441 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800442 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800443 * @return true if contents match, false otherwise
444 */
445 private boolean matchModIpInstruction(JsonNode instructionJson,
446 Description description) {
447 ModIPInstruction instructionToMatch =
448 (ModIPInstruction) instruction;
449 final String jsonSubtype = instructionJson.get("subtype").textValue();
450 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
451 description.appendText("subtype was " + jsonSubtype);
452 return false;
453 }
454
455 final String jsonType = instructionJson.get("type").textValue();
456 if (!instructionToMatch.type().name().equals(jsonType)) {
457 description.appendText("type was " + jsonType);
458 return false;
459 }
460
461 final String jsonIp = instructionJson.get("ip").textValue();
462 final String ip = instructionToMatch.ip().toString();
463 if (!ip.equals(jsonIp)) {
464 description.appendText("ip was " + jsonIp);
465 return false;
466 }
467
468 return true;
469 }
470
471 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800472 * Matches the contents of a mod IPv6 Flow Label instruction.
473 *
474 * @param instructionJson JSON instruction to match
475 * @param description Description object used for recording errors
476 * @return true if contents match, false otherwise
477 */
478 private boolean matchModIPv6FlowLabelInstruction(JsonNode instructionJson,
479 Description description) {
480 ModIPv6FlowLabelInstruction instructionToMatch =
481 (ModIPv6FlowLabelInstruction) instruction;
482 final String jsonSubtype = instructionJson.get("subtype").textValue();
483 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
484 description.appendText("subtype was " + jsonSubtype);
485 return false;
486 }
487
488 final String jsonType = instructionJson.get("type").textValue();
489 if (!instructionToMatch.type().name().equals(jsonType)) {
490 description.appendText("type was " + jsonType);
491 return false;
492 }
493
494 final int jsonFlowLabel = instructionJson.get("flowLabel").intValue();
495 final int flowLabel = instructionToMatch.flowLabel();
496 if (flowLabel != jsonFlowLabel) {
497 description.appendText("IPv6 flow label was " + jsonFlowLabel);
498 return false;
499 }
500
501 return true;
502 }
503
504 /**
Ray Milkeydb358082015-01-13 16:34:38 -0800505 * Matches the contents of a mod MPLS label instruction.
Ray Milkeyd03eda02015-01-09 14:58:48 -0800506 *
507 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800508 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800509 * @return true if contents match, false otherwise
510 */
511 private boolean matchModMplsLabelInstruction(JsonNode instructionJson,
512 Description description) {
513 ModMplsLabelInstruction instructionToMatch =
514 (ModMplsLabelInstruction) instruction;
515 final String jsonSubtype = instructionJson.get("subtype").textValue();
516 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
517 description.appendText("subtype was " + jsonSubtype);
518 return false;
519 }
520
521 final String jsonType = instructionJson.get("type").textValue();
522 if (!instructionToMatch.type().name().equals(jsonType)) {
523 description.appendText("type was " + jsonType);
524 return false;
525 }
526
527 final int jsonLabel = instructionJson.get("label").intValue();
Ray Milkey125572b2016-02-22 16:48:17 -0800528 final int label = instructionToMatch.label().toInt();
Ray Milkeyd03eda02015-01-09 14:58:48 -0800529 if (label != jsonLabel) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800530 description.appendText("MPLS label was " + jsonLabel);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800531 return false;
532 }
533
534 return true;
535 }
536
537 @Override
538 public boolean matchesSafely(JsonNode jsonInstruction, Description description) {
539
540 // check type
541 final JsonNode jsonTypeNode = jsonInstruction.get("type");
542 final String jsonType = jsonTypeNode.textValue();
543 final String type = instruction.type().name();
544 if (!jsonType.equals(type)) {
545 description.appendText("type was " + type);
546 return false;
547 }
548
549 if (instruction instanceof PushHeaderInstructions) {
550 return matchPushHeaderInstruction(jsonInstruction, description);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800551 } else if (instruction instanceof OutputInstruction) {
552 return matchOutputInstruction(jsonInstruction, description);
Jian Lice8c5602016-03-03 21:43:24 -0800553 } else if (instruction instanceof GroupInstruction) {
554 return matchGroupInstruction(jsonInstruction, description);
Jian Li47b26232016-03-07 09:59:59 -0800555 } else if (instruction instanceof MeterInstruction) {
556 return matchMeterInstruction(jsonInstruction, description);
Jian Li70dffe42016-03-08 22:23:02 -0800557 } else if (instruction instanceof SetQueueInstruction) {
558 return matchSetQueueInstruction(jsonInstruction, description);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800559 } else if (instruction instanceof ModLambdaInstruction) {
560 return matchModLambdaInstruction(jsonInstruction, description);
Sho SHIMIZUed7af542015-05-05 19:10:45 -0700561 } else if (instruction instanceof ModOchSignalInstruction) {
562 return matchModOchSingalInstruction(jsonInstruction, description);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800563 } else if (instruction instanceof ModEtherInstruction) {
564 return matchModEtherInstruction(jsonInstruction, description);
565 } else if (instruction instanceof ModVlanIdInstruction) {
566 return matchModVlanIdInstruction(jsonInstruction, description);
567 } else if (instruction instanceof ModVlanPcpInstruction) {
568 return matchModVlanPcpInstruction(jsonInstruction, description);
569 } else if (instruction instanceof ModIPInstruction) {
570 return matchModIpInstruction(jsonInstruction, description);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800571 } else if (instruction instanceof ModIPv6FlowLabelInstruction) {
Jian Li70dffe42016-03-08 22:23:02 -0800572 return matchModIPv6FlowLabelInstruction(jsonInstruction, description);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800573 } else if (instruction instanceof ModMplsLabelInstruction) {
574 return matchModMplsLabelInstruction(jsonInstruction, description);
Yafit Hadar5796d972015-10-15 13:16:11 +0300575 } else if (instruction instanceof ModOduSignalIdInstruction) {
576 return matchModOduSingalIdInstruction(jsonInstruction, description);
Brian O'Connorb75a67a2015-10-07 14:34:06 -0700577 } else if (instruction instanceof NoActionInstruction) {
578 return true;
Ray Milkeyd03eda02015-01-09 14:58:48 -0800579 }
580
581 return false;
582 }
583
584 @Override
585 public void describeTo(Description description) {
586 description.appendText(instruction.toString());
587 }
588
589 /**
590 * Factory to allocate an instruction matcher.
591 *
592 * @param instruction instruction object we are looking for
593 * @return matcher
594 */
595 public static InstructionJsonMatcher matchesInstruction(Instruction instruction) {
596 return new InstructionJsonMatcher(instruction);
597 }
598}