blob: 51a97591e125a0c9c2f7214ae758a145373dbdb1 [file] [log] [blame]
Ray Milkeyd03eda02015-01-09 14:58:48 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeyd03eda02015-01-09 14:58:48 -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
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.ModOchSignalInstruction;
30import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction;
31import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
Jian Li11260a02016-05-19 13:07:22 -070032import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction;
Yafit Hadar5796d972015-10-15 13:16:11 +030033import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction;
34import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
35import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
Yafit Hadar5796d972015-10-15 13:16:11 +030036import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
37import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
Ray Milkeyd03eda02015-01-09 14:58:48 -080038
Ray Milkeyd03eda02015-01-09 14:58:48 -080039/**
40 * Hamcrest matcher for instructions.
41 */
Ray Milkeydb358082015-01-13 16:34:38 -080042public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
Ray Milkeyd03eda02015-01-09 14:58:48 -080043
44 private final Instruction instruction;
45
Ray Milkeydb358082015-01-13 16:34:38 -080046 private InstructionJsonMatcher(Instruction instructionValue) {
Ray Milkeyd03eda02015-01-09 14:58:48 -080047 instruction = instructionValue;
48 }
49
50 /**
51 * Matches the contents of a push header instruction.
52 *
53 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080054 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -080055 * @return true if contents match, false otherwise
56 */
Jian Li11260a02016-05-19 13:07:22 -070057 private boolean matchModMplsHeaderInstruction(JsonNode instructionJson,
58 Description description) {
59 ModMplsHeaderInstruction instructionToMatch =
60 (ModMplsHeaderInstruction) instruction;
Ray Milkeyd03eda02015-01-09 14:58:48 -080061 final String jsonSubtype = instructionJson.get("subtype").textValue();
62 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
63 description.appendText("subtype was " + jsonSubtype);
64 return false;
65 }
66
67 final String jsonType = instructionJson.get("type").textValue();
68 if (!instructionToMatch.type().name().equals(jsonType)) {
69 description.appendText("type was " + jsonType);
70 return false;
71 }
72
73 final JsonNode ethJson = instructionJson.get("ethernetType");
74 if (ethJson == null) {
75 description.appendText("ethernetType was not null");
76 return false;
77 }
78
alshabib7b808c52015-06-26 14:22:24 -070079 if (instructionToMatch.ethernetType().toShort() != ethJson.asInt()) {
Yuta HIGUCHI32a53c52015-02-08 01:25:40 -080080 description.appendText("ethernetType was " + ethJson);
Ray Milkeyd03eda02015-01-09 14:58:48 -080081 return false;
82 }
Yuta HIGUCHI32a53c52015-02-08 01:25:40 -080083
Ray Milkeyd03eda02015-01-09 14:58:48 -080084 return true;
85 }
86
Jian Li11260a02016-05-19 13:07:22 -070087 // TODO: need to add matchModVlanHeaderInstruction
88
Ray Milkeyd03eda02015-01-09 14:58:48 -080089 /**
90 * Matches the contents of an output instruction.
91 *
92 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080093 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -080094 * @return true if contents match, false otherwise
95 */
96 private boolean matchOutputInstruction(JsonNode instructionJson,
97 Description description) {
Ray Milkeyd03eda02015-01-09 14:58:48 -080098 final String jsonType = instructionJson.get("type").textValue();
Andrea Campanella5df35952015-12-08 15:46:49 -080099 OutputInstruction instructionToMatch = (OutputInstruction) instruction;
Ray Milkeyd03eda02015-01-09 14:58:48 -0800100 if (!instructionToMatch.type().name().equals(jsonType)) {
101 description.appendText("type was " + jsonType);
102 return false;
103 }
104
Andrea Campanella5df35952015-12-08 15:46:49 -0800105 if (instructionJson.get("port").isLong() ||
106 instructionJson.get("port").isInt()) {
107 final long jsonPort = instructionJson.get("port").asLong();
108 if (instructionToMatch.port().toLong() != (jsonPort)) {
109 description.appendText("port was " + jsonPort);
110 return false;
111 }
112 } else if (instructionJson.get("port").isTextual()) {
113 final String jsonPort = instructionJson.get("port").textValue();
114 if (!instructionToMatch.port().toString().equals(jsonPort)) {
115 description.appendText("port was " + jsonPort);
116 return false;
117 }
118 } else {
119 final String jsonPort = instructionJson.get("port").toString();
Jian Li70dffe42016-03-08 22:23:02 -0800120 description.appendText("Unmatching types ");
Andrea Campanella5df35952015-12-08 15:46:49 -0800121 description.appendText("instructionToMatch " + instructionToMatch.port().toString());
122 description.appendText("jsonPort " + jsonPort);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800123 }
124
125 return true;
126 }
127
128 /**
Jian Lice8c5602016-03-03 21:43:24 -0800129 * Matches the contents of a group instruction.
130 *
131 * @param instructionJson JSON instruction to match
132 * @param description Description object used for recording errors
133 * @return true if contents match, false otherwise
134 */
135 private boolean matchGroupInstruction(JsonNode instructionJson,
136 Description description) {
137 final String jsonType = instructionJson.get("type").textValue();
138 GroupInstruction instructionToMatch = (GroupInstruction) instruction;
139 if (!instructionToMatch.type().name().equals(jsonType)) {
140 description.appendText("type was " + jsonType);
141 return false;
142 }
143
Jian Li47b26232016-03-07 09:59:59 -0800144 final int jsonGroupId = instructionJson.get("groupId").intValue();
145 if (instructionToMatch.groupId().id() != jsonGroupId) {
146 description.appendText("groupId was " + jsonGroupId);
147 return false;
148 }
149
150 return true;
151 }
152
153 /**
154 * Matches the contents of a meter instruction.
155 *
156 * @param instructionJson JSON instruction to match
157 * @param description Description object used for recording errors
158 * @return true if contents match, false otherwise
159 */
160 private boolean matchMeterInstruction(JsonNode instructionJson,
161 Description description) {
162 final String jsonType = instructionJson.get("type").textValue();
163 MeterInstruction instructionToMatch = (MeterInstruction) instruction;
164 if (!instructionToMatch.type().name().equals(jsonType)) {
165 description.appendText("type was " + jsonType);
166 return false;
167 }
168
169 final long jsonMeterId = instructionJson.get("meterId").longValue();
170 if (instructionToMatch.meterId().id() != jsonMeterId) {
171 description.appendText("meterId was " + jsonMeterId);
172 return false;
Jian Lice8c5602016-03-03 21:43:24 -0800173 }
174
175 return true;
176 }
177
178 /**
Jian Li70dffe42016-03-08 22:23:02 -0800179 * Matches the contents of a set queue instruction.
180 *
181 * @param instructionJson JSON instruction to match
182 * @param description Description object used for recording errors
183 * @return true if contents match, false otherwise
184 */
185 private boolean matchSetQueueInstruction(JsonNode instructionJson,
186 Description description) {
187 final String jsonType = instructionJson.get("type").textValue();
188 SetQueueInstruction instructionToMatch = (SetQueueInstruction) instruction;
189 if (!instructionToMatch.type().name().equals(jsonType)) {
190 description.appendText("type was " + jsonType);
191 return false;
192 }
193
194 final long jsonQueueId = instructionJson.get("queueId").longValue();
195 if (instructionToMatch.queueId() != jsonQueueId) {
196 description.appendText("queueId was " + jsonQueueId);
197 return false;
198 }
199
200 if (instructionJson.get("port").isLong() ||
201 instructionJson.get("port").isInt()) {
202 final long jsonPort = instructionJson.get("port").asLong();
203 if (instructionToMatch.port().toLong() != (jsonPort)) {
204 description.appendText("port was " + jsonPort);
205 return false;
206 }
207 } else if (instructionJson.get("port").isTextual()) {
208 final String jsonPort = instructionJson.get("port").textValue();
209 if (!instructionToMatch.port().toString().equals(jsonPort)) {
210 description.appendText("port was " + jsonPort);
211 return false;
212 }
213 } else {
214 final String jsonPort = instructionJson.get("port").toString();
215 description.appendText("Unmatching types ");
216 description.appendText("instructionToMatch " + instructionToMatch.port().toString());
217 description.appendText("jsonPort " + jsonPort);
218 }
219
220 return true;
221 }
222
223 /**
Yafit Hadar5796d972015-10-15 13:16:11 +0300224 * Matches the contents of a mod OCh singal instruction.
Sho SHIMIZUed7af542015-05-05 19:10:45 -0700225 *
226 * @param instructionJson JSON instruction to match
227 * @param description Description object used for recording errors
228 * @return true if contents matches, false otherwise
229 */
230 private boolean matchModOchSingalInstruction(JsonNode instructionJson,
231 Description description) {
232 ModOchSignalInstruction instructionToMatch =
233 (ModOchSignalInstruction) instruction;
234
235 String jsonSubType = instructionJson.get("subtype").textValue();
236 if (!instructionToMatch.subtype().name().equals(jsonSubType)) {
237 description.appendText("subtype was " + jsonSubType);
238 return false;
239 }
240
241 String jsonType = instructionJson.get("type").textValue();
242 if (!instructionToMatch.type().name().equals(jsonType)) {
243 description.appendText("type was " + jsonType);
244 return false;
245 }
246
247 String jsonGridType = instructionJson.get("gridType").textValue();
248 if (!instructionToMatch.lambda().gridType().name().equals(jsonGridType)) {
249 description.appendText("gridType was " + jsonGridType);
250 return false;
251 }
252
253 String jsonChannelSpacing = instructionJson.get("channelSpacing").textValue();
254 if (!instructionToMatch.lambda().channelSpacing().name().equals(jsonChannelSpacing)) {
255 description.appendText("channelSpacing was " + jsonChannelSpacing);
256 return false;
257 }
258
259 int jsonSpacingMultiplier = instructionJson.get("spacingMultiplier").intValue();
260 if (instructionToMatch.lambda().spacingMultiplier() != jsonSpacingMultiplier) {
261 description.appendText("spacingMultiplier was " + jsonSpacingMultiplier);
262 return false;
263 }
264
265 int jsonSlotGranularity = instructionJson.get("slotGranularity").intValue();
266 if (instructionToMatch.lambda().slotGranularity() != jsonSlotGranularity) {
267 description.appendText("slotGranularity was " + jsonSlotGranularity);
268 return false;
269 }
270
271 return true;
272 }
273
274 /**
Yafit Hadar5796d972015-10-15 13:16:11 +0300275 * Matches the contents of a mod ODU singal Id instruction.
276 *
277 * @param instructionJson JSON instruction to match
278 * @param description Description object used for recording errors
279 * @return true if contents matches, false otherwise
280 */
281 private boolean matchModOduSingalIdInstruction(JsonNode instructionJson,
282 Description description) {
283 ModOduSignalIdInstruction instructionToMatch =
284 (ModOduSignalIdInstruction) instruction;
285 String jsonSubType = instructionJson.get("subtype").textValue();
286 if (!instructionToMatch.subtype().name().equals(jsonSubType)) {
287 description.appendText("subtype was " + jsonSubType);
288 return false;
289 }
290 String jsonType = instructionJson.get("type").textValue();
291 if (!instructionToMatch.type().name().equals(jsonType)) {
292 description.appendText("type was " + jsonType);
293 return false;
294 }
295 final JsonNode jsonOduSignal = instructionJson.get("oduSignalId");
296 int jsonTpn = jsonOduSignal.get("tributaryPortNumber").intValue();
297 int jsonTsLen = jsonOduSignal.get("tributarySlotLength").intValue();
Jian Li68c4fc42016-01-11 16:07:03 -0800298 byte[] tributaryBitMap = HexString.fromHexString(jsonOduSignal.get("tributarySlotBitmap").asText());
Yafit Hadar5796d972015-10-15 13:16:11 +0300299 OduSignalId jsonOduSignalId = OduSignalId.oduSignalId(jsonTpn, jsonTsLen, tributaryBitMap);
300 if (!instructionToMatch.oduSignalId().equals(jsonOduSignalId)) {
301 description.appendText("oduSignalId was " + instructionToMatch);
302 return false;
303 }
304 return true;
305 }
306
307
308 /**
Ray Milkeydb358082015-01-13 16:34:38 -0800309 * Matches the contents of a mod Ethernet instruction.
Ray Milkeyd03eda02015-01-09 14:58:48 -0800310 *
311 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800312 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800313 * @return true if contents match, false otherwise
314 */
315 private boolean matchModEtherInstruction(JsonNode instructionJson,
316 Description description) {
317 ModEtherInstruction instructionToMatch =
318 (ModEtherInstruction) instruction;
319 final String jsonSubtype = instructionJson.get("subtype").textValue();
320 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
321 description.appendText("subtype was " + jsonSubtype);
322 return false;
323 }
324
325 final String jsonType = instructionJson.get("type").textValue();
326 if (!instructionToMatch.type().name().equals(jsonType)) {
327 description.appendText("type was " + jsonType);
328 return false;
329 }
330
331 final String jsonMac = instructionJson.get("mac").textValue();
332 final String mac = instructionToMatch.mac().toString();
333 if (!mac.equals(jsonMac)) {
334 description.appendText("mac was " + jsonMac);
335 return false;
336 }
337
338 return true;
339 }
340
341 /**
342 * Matches the contents of a mod vlan id instruction.
343 *
344 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800345 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800346 * @return true if contents match, false otherwise
347 */
348 private boolean matchModVlanIdInstruction(JsonNode instructionJson,
349 Description description) {
350 ModVlanIdInstruction instructionToMatch =
351 (ModVlanIdInstruction) instruction;
352 final String jsonSubtype = instructionJson.get("subtype").textValue();
353 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
354 description.appendText("subtype was " + jsonSubtype);
355 return false;
356 }
357
358 final String jsonType = instructionJson.get("type").textValue();
359 if (!instructionToMatch.type().name().equals(jsonType)) {
360 description.appendText("type was " + jsonType);
361 return false;
362 }
363
364 final short jsonVlanId = instructionJson.get("vlanId").shortValue();
365 final short vlanId = instructionToMatch.vlanId().toShort();
366 if (jsonVlanId != vlanId) {
367 description.appendText("vlan id was " + jsonVlanId);
368 return false;
369 }
370
371 return true;
372 }
373
374 /**
375 * Matches the contents of a mod vlan pcp instruction.
376 *
377 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800378 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800379 * @return true if contents match, false otherwise
380 */
381 private boolean matchModVlanPcpInstruction(JsonNode instructionJson,
382 Description description) {
383 ModVlanPcpInstruction instructionToMatch =
384 (ModVlanPcpInstruction) instruction;
385 final String jsonSubtype = instructionJson.get("subtype").textValue();
386 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
387 description.appendText("subtype was " + jsonSubtype);
388 return false;
389 }
390
391 final String jsonType = instructionJson.get("type").textValue();
392 if (!instructionToMatch.type().name().equals(jsonType)) {
393 description.appendText("type was " + jsonType);
394 return false;
395 }
396
397 final short jsonVlanPcp = instructionJson.get("vlanPcp").shortValue();
398 final short vlanId = instructionToMatch.vlanPcp();
399 if (jsonVlanPcp != vlanId) {
400 description.appendText("vlan pcp was " + jsonVlanPcp);
401 return false;
402 }
403
404 return true;
405 }
406
407 /**
408 * Matches the contents of a mod ip instruction.
409 *
410 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800411 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800412 * @return true if contents match, false otherwise
413 */
414 private boolean matchModIpInstruction(JsonNode instructionJson,
415 Description description) {
416 ModIPInstruction instructionToMatch =
417 (ModIPInstruction) instruction;
418 final String jsonSubtype = instructionJson.get("subtype").textValue();
419 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
420 description.appendText("subtype was " + jsonSubtype);
421 return false;
422 }
423
424 final String jsonType = instructionJson.get("type").textValue();
425 if (!instructionToMatch.type().name().equals(jsonType)) {
426 description.appendText("type was " + jsonType);
427 return false;
428 }
429
430 final String jsonIp = instructionJson.get("ip").textValue();
431 final String ip = instructionToMatch.ip().toString();
432 if (!ip.equals(jsonIp)) {
433 description.appendText("ip was " + jsonIp);
434 return false;
435 }
436
437 return true;
438 }
439
440 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800441 * Matches the contents of a mod IPv6 Flow Label instruction.
442 *
443 * @param instructionJson JSON instruction to match
444 * @param description Description object used for recording errors
445 * @return true if contents match, false otherwise
446 */
447 private boolean matchModIPv6FlowLabelInstruction(JsonNode instructionJson,
448 Description description) {
449 ModIPv6FlowLabelInstruction instructionToMatch =
450 (ModIPv6FlowLabelInstruction) instruction;
451 final String jsonSubtype = instructionJson.get("subtype").textValue();
452 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
453 description.appendText("subtype was " + jsonSubtype);
454 return false;
455 }
456
457 final String jsonType = instructionJson.get("type").textValue();
458 if (!instructionToMatch.type().name().equals(jsonType)) {
459 description.appendText("type was " + jsonType);
460 return false;
461 }
462
463 final int jsonFlowLabel = instructionJson.get("flowLabel").intValue();
464 final int flowLabel = instructionToMatch.flowLabel();
465 if (flowLabel != jsonFlowLabel) {
466 description.appendText("IPv6 flow label was " + jsonFlowLabel);
467 return false;
468 }
469
470 return true;
471 }
472
473 /**
Ray Milkeydb358082015-01-13 16:34:38 -0800474 * Matches the contents of a mod MPLS label instruction.
Ray Milkeyd03eda02015-01-09 14:58:48 -0800475 *
476 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800477 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800478 * @return true if contents match, false otherwise
479 */
480 private boolean matchModMplsLabelInstruction(JsonNode instructionJson,
481 Description description) {
482 ModMplsLabelInstruction instructionToMatch =
483 (ModMplsLabelInstruction) instruction;
484 final String jsonSubtype = instructionJson.get("subtype").textValue();
485 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
486 description.appendText("subtype was " + jsonSubtype);
487 return false;
488 }
489
490 final String jsonType = instructionJson.get("type").textValue();
491 if (!instructionToMatch.type().name().equals(jsonType)) {
492 description.appendText("type was " + jsonType);
493 return false;
494 }
495
496 final int jsonLabel = instructionJson.get("label").intValue();
Ray Milkey125572b2016-02-22 16:48:17 -0800497 final int label = instructionToMatch.label().toInt();
Ray Milkeyd03eda02015-01-09 14:58:48 -0800498 if (label != jsonLabel) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800499 description.appendText("MPLS label was " + jsonLabel);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800500 return false;
501 }
502
503 return true;
504 }
505
506 @Override
507 public boolean matchesSafely(JsonNode jsonInstruction, Description description) {
508
509 // check type
510 final JsonNode jsonTypeNode = jsonInstruction.get("type");
511 final String jsonType = jsonTypeNode.textValue();
512 final String type = instruction.type().name();
513 if (!jsonType.equals(type)) {
514 description.appendText("type was " + type);
515 return false;
516 }
517
Jian Li11260a02016-05-19 13:07:22 -0700518 if (instruction instanceof ModMplsHeaderInstruction) {
519 return matchModMplsHeaderInstruction(jsonInstruction, description);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800520 } else if (instruction instanceof OutputInstruction) {
521 return matchOutputInstruction(jsonInstruction, description);
Jian Lice8c5602016-03-03 21:43:24 -0800522 } else if (instruction instanceof GroupInstruction) {
523 return matchGroupInstruction(jsonInstruction, description);
Jian Li47b26232016-03-07 09:59:59 -0800524 } else if (instruction instanceof MeterInstruction) {
525 return matchMeterInstruction(jsonInstruction, description);
Jian Li70dffe42016-03-08 22:23:02 -0800526 } else if (instruction instanceof SetQueueInstruction) {
527 return matchSetQueueInstruction(jsonInstruction, description);
Sho SHIMIZUed7af542015-05-05 19:10:45 -0700528 } else if (instruction instanceof ModOchSignalInstruction) {
529 return matchModOchSingalInstruction(jsonInstruction, description);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800530 } else if (instruction instanceof ModEtherInstruction) {
531 return matchModEtherInstruction(jsonInstruction, description);
532 } else if (instruction instanceof ModVlanIdInstruction) {
533 return matchModVlanIdInstruction(jsonInstruction, description);
534 } else if (instruction instanceof ModVlanPcpInstruction) {
535 return matchModVlanPcpInstruction(jsonInstruction, description);
536 } else if (instruction instanceof ModIPInstruction) {
537 return matchModIpInstruction(jsonInstruction, description);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800538 } else if (instruction instanceof ModIPv6FlowLabelInstruction) {
Jian Li70dffe42016-03-08 22:23:02 -0800539 return matchModIPv6FlowLabelInstruction(jsonInstruction, description);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800540 } else if (instruction instanceof ModMplsLabelInstruction) {
541 return matchModMplsLabelInstruction(jsonInstruction, description);
Yafit Hadar5796d972015-10-15 13:16:11 +0300542 } else if (instruction instanceof ModOduSignalIdInstruction) {
543 return matchModOduSingalIdInstruction(jsonInstruction, description);
Brian O'Connorb75a67a2015-10-07 14:34:06 -0700544 } else if (instruction instanceof NoActionInstruction) {
545 return true;
Ray Milkeyd03eda02015-01-09 14:58:48 -0800546 }
547
548 return false;
549 }
550
551 @Override
552 public void describeTo(Description description) {
553 description.appendText(instruction.toString());
554 }
555
556 /**
557 * Factory to allocate an instruction matcher.
558 *
559 * @param instruction instruction object we are looking for
560 * @return matcher
561 */
562 public static InstructionJsonMatcher matchesInstruction(Instruction instruction) {
563 return new InstructionJsonMatcher(instruction);
564 }
565}