blob: d501522af8833dfaa035ca5daed15873a07e57eb [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;
32import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction;
33import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
34import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
35import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeaderInstructions;
36import 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 */
57 private boolean matchPushHeaderInstruction(JsonNode instructionJson,
58 Description description) {
59 PushHeaderInstructions instructionToMatch =
60 (PushHeaderInstructions) instruction;
61 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
87 /**
88 * Matches the contents of an output instruction.
89 *
90 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080091 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -080092 * @return true if contents match, false otherwise
93 */
94 private boolean matchOutputInstruction(JsonNode instructionJson,
95 Description description) {
Ray Milkeyd03eda02015-01-09 14:58:48 -080096 final String jsonType = instructionJson.get("type").textValue();
Andrea Campanella5df35952015-12-08 15:46:49 -080097 OutputInstruction instructionToMatch = (OutputInstruction) instruction;
Ray Milkeyd03eda02015-01-09 14:58:48 -080098 if (!instructionToMatch.type().name().equals(jsonType)) {
99 description.appendText("type was " + jsonType);
100 return false;
101 }
102
Andrea Campanella5df35952015-12-08 15:46:49 -0800103 if (instructionJson.get("port").isLong() ||
104 instructionJson.get("port").isInt()) {
105 final long jsonPort = instructionJson.get("port").asLong();
106 if (instructionToMatch.port().toLong() != (jsonPort)) {
107 description.appendText("port was " + jsonPort);
108 return false;
109 }
110 } else if (instructionJson.get("port").isTextual()) {
111 final String jsonPort = instructionJson.get("port").textValue();
112 if (!instructionToMatch.port().toString().equals(jsonPort)) {
113 description.appendText("port was " + jsonPort);
114 return false;
115 }
116 } else {
117 final String jsonPort = instructionJson.get("port").toString();
Jian Li70dffe42016-03-08 22:23:02 -0800118 description.appendText("Unmatching types ");
Andrea Campanella5df35952015-12-08 15:46:49 -0800119 description.appendText("instructionToMatch " + instructionToMatch.port().toString());
120 description.appendText("jsonPort " + jsonPort);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800121 }
122
123 return true;
124 }
125
126 /**
Jian Lice8c5602016-03-03 21:43:24 -0800127 * Matches the contents of a group instruction.
128 *
129 * @param instructionJson JSON instruction to match
130 * @param description Description object used for recording errors
131 * @return true if contents match, false otherwise
132 */
133 private boolean matchGroupInstruction(JsonNode instructionJson,
134 Description description) {
135 final String jsonType = instructionJson.get("type").textValue();
136 GroupInstruction instructionToMatch = (GroupInstruction) instruction;
137 if (!instructionToMatch.type().name().equals(jsonType)) {
138 description.appendText("type was " + jsonType);
139 return false;
140 }
141
Jian Li47b26232016-03-07 09:59:59 -0800142 final int jsonGroupId = instructionJson.get("groupId").intValue();
143 if (instructionToMatch.groupId().id() != jsonGroupId) {
144 description.appendText("groupId was " + jsonGroupId);
145 return false;
146 }
147
148 return true;
149 }
150
151 /**
152 * Matches the contents of a meter instruction.
153 *
154 * @param instructionJson JSON instruction to match
155 * @param description Description object used for recording errors
156 * @return true if contents match, false otherwise
157 */
158 private boolean matchMeterInstruction(JsonNode instructionJson,
159 Description description) {
160 final String jsonType = instructionJson.get("type").textValue();
161 MeterInstruction instructionToMatch = (MeterInstruction) instruction;
162 if (!instructionToMatch.type().name().equals(jsonType)) {
163 description.appendText("type was " + jsonType);
164 return false;
165 }
166
167 final long jsonMeterId = instructionJson.get("meterId").longValue();
168 if (instructionToMatch.meterId().id() != jsonMeterId) {
169 description.appendText("meterId was " + jsonMeterId);
170 return false;
Jian Lice8c5602016-03-03 21:43:24 -0800171 }
172
173 return true;
174 }
175
176 /**
Jian Li70dffe42016-03-08 22:23:02 -0800177 * Matches the contents of a set queue instruction.
178 *
179 * @param instructionJson JSON instruction to match
180 * @param description Description object used for recording errors
181 * @return true if contents match, false otherwise
182 */
183 private boolean matchSetQueueInstruction(JsonNode instructionJson,
184 Description description) {
185 final String jsonType = instructionJson.get("type").textValue();
186 SetQueueInstruction instructionToMatch = (SetQueueInstruction) instruction;
187 if (!instructionToMatch.type().name().equals(jsonType)) {
188 description.appendText("type was " + jsonType);
189 return false;
190 }
191
192 final long jsonQueueId = instructionJson.get("queueId").longValue();
193 if (instructionToMatch.queueId() != jsonQueueId) {
194 description.appendText("queueId was " + jsonQueueId);
195 return false;
196 }
197
198 if (instructionJson.get("port").isLong() ||
199 instructionJson.get("port").isInt()) {
200 final long jsonPort = instructionJson.get("port").asLong();
201 if (instructionToMatch.port().toLong() != (jsonPort)) {
202 description.appendText("port was " + jsonPort);
203 return false;
204 }
205 } else if (instructionJson.get("port").isTextual()) {
206 final String jsonPort = instructionJson.get("port").textValue();
207 if (!instructionToMatch.port().toString().equals(jsonPort)) {
208 description.appendText("port was " + jsonPort);
209 return false;
210 }
211 } else {
212 final String jsonPort = instructionJson.get("port").toString();
213 description.appendText("Unmatching types ");
214 description.appendText("instructionToMatch " + instructionToMatch.port().toString());
215 description.appendText("jsonPort " + jsonPort);
216 }
217
218 return true;
219 }
220
221 /**
Yafit Hadar5796d972015-10-15 13:16:11 +0300222 * Matches the contents of a mod OCh singal instruction.
Sho SHIMIZUed7af542015-05-05 19:10:45 -0700223 *
224 * @param instructionJson JSON instruction to match
225 * @param description Description object used for recording errors
226 * @return true if contents matches, false otherwise
227 */
228 private boolean matchModOchSingalInstruction(JsonNode instructionJson,
229 Description description) {
230 ModOchSignalInstruction instructionToMatch =
231 (ModOchSignalInstruction) instruction;
232
233 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 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 String jsonGridType = instructionJson.get("gridType").textValue();
246 if (!instructionToMatch.lambda().gridType().name().equals(jsonGridType)) {
247 description.appendText("gridType was " + jsonGridType);
248 return false;
249 }
250
251 String jsonChannelSpacing = instructionJson.get("channelSpacing").textValue();
252 if (!instructionToMatch.lambda().channelSpacing().name().equals(jsonChannelSpacing)) {
253 description.appendText("channelSpacing was " + jsonChannelSpacing);
254 return false;
255 }
256
257 int jsonSpacingMultiplier = instructionJson.get("spacingMultiplier").intValue();
258 if (instructionToMatch.lambda().spacingMultiplier() != jsonSpacingMultiplier) {
259 description.appendText("spacingMultiplier was " + jsonSpacingMultiplier);
260 return false;
261 }
262
263 int jsonSlotGranularity = instructionJson.get("slotGranularity").intValue();
264 if (instructionToMatch.lambda().slotGranularity() != jsonSlotGranularity) {
265 description.appendText("slotGranularity was " + jsonSlotGranularity);
266 return false;
267 }
268
269 return true;
270 }
271
272 /**
Yafit Hadar5796d972015-10-15 13:16:11 +0300273 * Matches the contents of a mod ODU singal Id instruction.
274 *
275 * @param instructionJson JSON instruction to match
276 * @param description Description object used for recording errors
277 * @return true if contents matches, false otherwise
278 */
279 private boolean matchModOduSingalIdInstruction(JsonNode instructionJson,
280 Description description) {
281 ModOduSignalIdInstruction instructionToMatch =
282 (ModOduSignalIdInstruction) instruction;
283 String jsonSubType = instructionJson.get("subtype").textValue();
284 if (!instructionToMatch.subtype().name().equals(jsonSubType)) {
285 description.appendText("subtype was " + jsonSubType);
286 return false;
287 }
288 String jsonType = instructionJson.get("type").textValue();
289 if (!instructionToMatch.type().name().equals(jsonType)) {
290 description.appendText("type was " + jsonType);
291 return false;
292 }
293 final JsonNode jsonOduSignal = instructionJson.get("oduSignalId");
294 int jsonTpn = jsonOduSignal.get("tributaryPortNumber").intValue();
295 int jsonTsLen = jsonOduSignal.get("tributarySlotLength").intValue();
Jian Li68c4fc42016-01-11 16:07:03 -0800296 byte[] tributaryBitMap = HexString.fromHexString(jsonOduSignal.get("tributarySlotBitmap").asText());
Yafit Hadar5796d972015-10-15 13:16:11 +0300297 OduSignalId jsonOduSignalId = OduSignalId.oduSignalId(jsonTpn, jsonTsLen, tributaryBitMap);
298 if (!instructionToMatch.oduSignalId().equals(jsonOduSignalId)) {
299 description.appendText("oduSignalId was " + instructionToMatch);
300 return false;
301 }
302 return true;
303 }
304
305
306 /**
Ray Milkeydb358082015-01-13 16:34:38 -0800307 * Matches the contents of a mod Ethernet instruction.
Ray Milkeyd03eda02015-01-09 14:58:48 -0800308 *
309 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800310 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800311 * @return true if contents match, false otherwise
312 */
313 private boolean matchModEtherInstruction(JsonNode instructionJson,
314 Description description) {
315 ModEtherInstruction instructionToMatch =
316 (ModEtherInstruction) instruction;
317 final String jsonSubtype = instructionJson.get("subtype").textValue();
318 if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
319 description.appendText("subtype was " + jsonSubtype);
320 return false;
321 }
322
323 final String jsonType = instructionJson.get("type").textValue();
324 if (!instructionToMatch.type().name().equals(jsonType)) {
325 description.appendText("type was " + jsonType);
326 return false;
327 }
328
329 final String jsonMac = instructionJson.get("mac").textValue();
330 final String mac = instructionToMatch.mac().toString();
331 if (!mac.equals(jsonMac)) {
332 description.appendText("mac was " + jsonMac);
333 return false;
334 }
335
336 return true;
337 }
338
339 /**
340 * Matches the contents of a mod vlan id instruction.
341 *
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 matchModVlanIdInstruction(JsonNode instructionJson,
347 Description description) {
348 ModVlanIdInstruction instructionToMatch =
349 (ModVlanIdInstruction) 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 short jsonVlanId = instructionJson.get("vlanId").shortValue();
363 final short vlanId = instructionToMatch.vlanId().toShort();
364 if (jsonVlanId != vlanId) {
365 description.appendText("vlan id was " + jsonVlanId);
366 return false;
367 }
368
369 return true;
370 }
371
372 /**
373 * Matches the contents of a mod vlan pcp 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 matchModVlanPcpInstruction(JsonNode instructionJson,
380 Description description) {
381 ModVlanPcpInstruction instructionToMatch =
382 (ModVlanPcpInstruction) 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 jsonVlanPcp = instructionJson.get("vlanPcp").shortValue();
396 final short vlanId = instructionToMatch.vlanPcp();
397 if (jsonVlanPcp != vlanId) {
398 description.appendText("vlan pcp was " + jsonVlanPcp);
399 return false;
400 }
401
402 return true;
403 }
404
405 /**
406 * Matches the contents of a mod ip 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 matchModIpInstruction(JsonNode instructionJson,
413 Description description) {
414 ModIPInstruction instructionToMatch =
415 (ModIPInstruction) 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 String jsonIp = instructionJson.get("ip").textValue();
429 final String ip = instructionToMatch.ip().toString();
430 if (!ip.equals(jsonIp)) {
431 description.appendText("ip was " + jsonIp);
432 return false;
433 }
434
435 return true;
436 }
437
438 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800439 * Matches the contents of a mod IPv6 Flow Label instruction.
440 *
441 * @param instructionJson JSON instruction to match
442 * @param description Description object used for recording errors
443 * @return true if contents match, false otherwise
444 */
445 private boolean matchModIPv6FlowLabelInstruction(JsonNode instructionJson,
446 Description description) {
447 ModIPv6FlowLabelInstruction instructionToMatch =
448 (ModIPv6FlowLabelInstruction) 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 int jsonFlowLabel = instructionJson.get("flowLabel").intValue();
462 final int flowLabel = instructionToMatch.flowLabel();
463 if (flowLabel != jsonFlowLabel) {
464 description.appendText("IPv6 flow label was " + jsonFlowLabel);
465 return false;
466 }
467
468 return true;
469 }
470
471 /**
Ray Milkeydb358082015-01-13 16:34:38 -0800472 * Matches the contents of a mod MPLS label instruction.
Ray Milkeyd03eda02015-01-09 14:58:48 -0800473 *
474 * @param instructionJson JSON instruction to match
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800475 * @param description Description object used for recording errors
Ray Milkeyd03eda02015-01-09 14:58:48 -0800476 * @return true if contents match, false otherwise
477 */
478 private boolean matchModMplsLabelInstruction(JsonNode instructionJson,
479 Description description) {
480 ModMplsLabelInstruction instructionToMatch =
481 (ModMplsLabelInstruction) 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 jsonLabel = instructionJson.get("label").intValue();
Ray Milkey125572b2016-02-22 16:48:17 -0800495 final int label = instructionToMatch.label().toInt();
Ray Milkeyd03eda02015-01-09 14:58:48 -0800496 if (label != jsonLabel) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800497 description.appendText("MPLS label was " + jsonLabel);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800498 return false;
499 }
500
501 return true;
502 }
503
504 @Override
505 public boolean matchesSafely(JsonNode jsonInstruction, Description description) {
506
507 // check type
508 final JsonNode jsonTypeNode = jsonInstruction.get("type");
509 final String jsonType = jsonTypeNode.textValue();
510 final String type = instruction.type().name();
511 if (!jsonType.equals(type)) {
512 description.appendText("type was " + type);
513 return false;
514 }
515
516 if (instruction instanceof PushHeaderInstructions) {
517 return matchPushHeaderInstruction(jsonInstruction, description);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800518 } else if (instruction instanceof OutputInstruction) {
519 return matchOutputInstruction(jsonInstruction, description);
Jian Lice8c5602016-03-03 21:43:24 -0800520 } else if (instruction instanceof GroupInstruction) {
521 return matchGroupInstruction(jsonInstruction, description);
Jian Li47b26232016-03-07 09:59:59 -0800522 } else if (instruction instanceof MeterInstruction) {
523 return matchMeterInstruction(jsonInstruction, description);
Jian Li70dffe42016-03-08 22:23:02 -0800524 } else if (instruction instanceof SetQueueInstruction) {
525 return matchSetQueueInstruction(jsonInstruction, description);
Sho SHIMIZUed7af542015-05-05 19:10:45 -0700526 } else if (instruction instanceof ModOchSignalInstruction) {
527 return matchModOchSingalInstruction(jsonInstruction, description);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800528 } else if (instruction instanceof ModEtherInstruction) {
529 return matchModEtherInstruction(jsonInstruction, description);
530 } else if (instruction instanceof ModVlanIdInstruction) {
531 return matchModVlanIdInstruction(jsonInstruction, description);
532 } else if (instruction instanceof ModVlanPcpInstruction) {
533 return matchModVlanPcpInstruction(jsonInstruction, description);
534 } else if (instruction instanceof ModIPInstruction) {
535 return matchModIpInstruction(jsonInstruction, description);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800536 } else if (instruction instanceof ModIPv6FlowLabelInstruction) {
Jian Li70dffe42016-03-08 22:23:02 -0800537 return matchModIPv6FlowLabelInstruction(jsonInstruction, description);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800538 } else if (instruction instanceof ModMplsLabelInstruction) {
539 return matchModMplsLabelInstruction(jsonInstruction, description);
Yafit Hadar5796d972015-10-15 13:16:11 +0300540 } else if (instruction instanceof ModOduSignalIdInstruction) {
541 return matchModOduSingalIdInstruction(jsonInstruction, description);
Brian O'Connorb75a67a2015-10-07 14:34:06 -0700542 } else if (instruction instanceof NoActionInstruction) {
543 return true;
Ray Milkeyd03eda02015-01-09 14:58:48 -0800544 }
545
546 return false;
547 }
548
549 @Override
550 public void describeTo(Description description) {
551 description.appendText(instruction.toString());
552 }
553
554 /**
555 * Factory to allocate an instruction matcher.
556 *
557 * @param instruction instruction object we are looking for
558 * @return matcher
559 */
560 public static InstructionJsonMatcher matchesInstruction(Instruction instruction) {
561 return new InstructionJsonMatcher(instruction);
562 }
563}