blob: bfb84096c8d170fac5b94825292f65c627552232 [file] [log] [blame]
Ray Milkey78081052014-11-05 10:38:12 -08001/*
2 * Copyright 2014 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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow.instructions;
Ray Milkey78081052014-11-05 10:38:12 -080017
18import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.net.PortNumber;
Ray Milkey78081052014-11-05 10:38:12 -080020import org.onlab.packet.IpAddress;
Ray Milkey78081052014-11-05 10:38:12 -080021import org.onlab.packet.MacAddress;
22import org.onlab.packet.VlanId;
23
Ray Milkey0d338052014-11-21 16:40:12 -080024import com.google.common.testing.EqualsTester;
25
Ray Milkey78081052014-11-05 10:38:12 -080026import static org.hamcrest.MatcherAssert.assertThat;
Ray Milkey78081052014-11-05 10:38:12 -080027import static org.hamcrest.Matchers.equalTo;
28import static org.hamcrest.Matchers.instanceOf;
29import static org.hamcrest.Matchers.is;
30import static org.hamcrest.Matchers.not;
31import static org.hamcrest.Matchers.notNullValue;
32import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
33import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
Brian O'Connorabafb502014-12-02 22:26:20 -080034import static org.onosproject.net.PortNumber.portNumber;
Ray Milkey78081052014-11-05 10:38:12 -080035
36/**
37 * Unit tests for the Instructions class.
38 */
39public class InstructionsTest {
40
41 /**
42 * Checks that a Criterion object has the proper type, and then converts
43 * it to the proper type.
44 *
45 * @param instruction Instruction object to convert
46 * @param type Enumerated type value for the Criterion class
47 * @param clazz Desired Criterion class
48 * @param <T> The type the caller wants returned
49 * @return converted object
50 */
51 @SuppressWarnings("unchecked")
52 private <T> T checkAndConvert(Instruction instruction, Instruction.Type type, Class clazz) {
53 assertThat(instruction, is(notNullValue()));
54 assertThat(instruction.type(), is(equalTo(type)));
55 assertThat(instruction, instanceOf(clazz));
56 return (T) instruction;
57 }
58
59 /**
60 * Checks the equals() and toString() methods of a Criterion class.
61 *
62 * @param c1 first object to compare
63 * @param c1match object that should be equal to the first
64 * @param c2 object that should be not equal to the first
Ray Milkey78081052014-11-05 10:38:12 -080065 * @param <T> type of the arguments
66 */
67 private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match,
Ray Milkey0d338052014-11-21 16:40:12 -080068 T c2) {
Ray Milkey78081052014-11-05 10:38:12 -080069
Ray Milkey0d338052014-11-21 16:40:12 -080070 new EqualsTester()
71 .addEqualityGroup(c1, c1match)
72 .addEqualityGroup(c2)
73 .testEquals();
Ray Milkey78081052014-11-05 10:38:12 -080074 }
75
76 /**
77 * Checks that Instructions is a proper utility class.
78 */
79 @Test
80 public void testInstructionsUtilityClass() {
81 assertThatClassIsUtility(Instructions.class);
82 }
83
84 /**
85 * Checks that the Instruction class implementations are immutable.
86 */
87 @Test
88 public void testImmutabilityOfInstructions() {
89 assertThatClassIsImmutable(Instructions.DropInstruction.class);
90 assertThatClassIsImmutable(Instructions.OutputInstruction.class);
91 assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class);
92 assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class);
93 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class);
94 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class);
95 assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080096 assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
Ray Milkeyd03eda02015-01-09 14:58:48 -080097 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class);
98 assertThatClassIsImmutable(L2ModificationInstruction.PushHeaderInstructions.class);
Ray Milkey78081052014-11-05 10:38:12 -080099 }
100
101 // DropInstruction
102
103 private final Instructions.DropInstruction drop1 = Instructions.createDrop();
104 private final Instructions.DropInstruction drop2 = Instructions.createDrop();
105
106 /**
107 * Test the createDrop method.
108 */
109 @Test
110 public void testCreateDropMethod() {
111 Instructions.DropInstruction instruction = Instructions.createDrop();
112 checkAndConvert(instruction,
113 Instruction.Type.DROP,
114 Instructions.DropInstruction.class);
115 }
116
117 /**
118 * Test the equals() method of the DropInstruction class.
119 */
120
121 @Test
122 public void testDropInstructionEquals() throws Exception {
123 assertThat(drop1, is(equalTo(drop2)));
124 }
125
126 /**
127 * Test the hashCode() method of the DropInstruction class.
128 */
129
130 @Test
131 public void testDropInstructionHashCode() {
132 assertThat(drop1.hashCode(), is(equalTo(drop2.hashCode())));
133 }
134
135 // OutputInstruction
136
137 private final PortNumber port1 = portNumber(1);
138 private final PortNumber port2 = portNumber(2);
139 private final Instructions.OutputInstruction output1 = Instructions.createOutput(port1);
140 private final Instructions.OutputInstruction sameAsOutput1 = Instructions.createOutput(port1);
141 private final Instructions.OutputInstruction output2 = Instructions.createOutput(port2);
142
143 /**
144 * Test the createOutput method.
145 */
146 @Test
147 public void testCreateOutputMethod() {
148 final Instruction instruction = Instructions.createOutput(port2);
149 final Instructions.OutputInstruction outputInstruction =
150 checkAndConvert(instruction,
151 Instruction.Type.OUTPUT,
152 Instructions.OutputInstruction.class);
153 assertThat(outputInstruction.port(), is(equalTo(port2)));
154 }
155
156
157 /**
158 * Test the equals() method of the OutputInstruction class.
159 */
160
161 @Test
162 public void testOutputInstructionEquals() throws Exception {
Ray Milkey0d338052014-11-21 16:40:12 -0800163 checkEqualsAndToString(output1, sameAsOutput1, output2);
Ray Milkey78081052014-11-05 10:38:12 -0800164 }
165
166 /**
167 * Test the hashCode() method of the OutputInstruction class.
168 */
169
170 @Test
171 public void testOutputInstructionHashCode() {
172 assertThat(output1.hashCode(), is(equalTo(sameAsOutput1.hashCode())));
173 assertThat(output1.hashCode(), is(not(equalTo(output2.hashCode()))));
174 }
175
176 // ModLambdaInstruction
177
178 private final short lambda1 = 1;
179 private final short lambda2 = 2;
180 private final Instruction lambdaInstruction1 = Instructions.modL0Lambda(lambda1);
181 private final Instruction sameAsLambdaInstruction1 = Instructions.modL0Lambda(lambda1);
182 private final Instruction lambdaInstruction2 = Instructions.modL0Lambda(lambda2);
183
184 /**
185 * Test the modL0Lambda method.
186 */
187 @Test
188 public void testCreateLambdaMethod() {
189 final Instruction instruction = Instructions.modL0Lambda(lambda1);
190 final L0ModificationInstruction.ModLambdaInstruction lambdaInstruction =
191 checkAndConvert(instruction,
192 Instruction.Type.L0MODIFICATION,
193 L0ModificationInstruction.ModLambdaInstruction.class);
194 assertThat(lambdaInstruction.lambda(), is(equalTo(lambda1)));
195 }
196
197
198 /**
199 * Test the equals() method of the ModLambdaInstruction class.
200 */
201
202 @Test
203 public void testModLambdaInstructionEquals() throws Exception {
204 checkEqualsAndToString(lambdaInstruction1,
205 sameAsLambdaInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800206 lambdaInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800207 }
208
209 /**
210 * Test the hashCode() method of the ModLambdaInstruction class.
211 */
212
213 @Test
214 public void testModLambdaInstructionHashCode() {
215 assertThat(lambdaInstruction1.hashCode(),
216 is(equalTo(sameAsLambdaInstruction1.hashCode())));
217 assertThat(lambdaInstruction1.hashCode(),
218 is(not(equalTo(lambdaInstruction2.hashCode()))));
219 }
220
221 // ModEtherInstruction
222
223 private static final String MAC1 = "00:00:00:00:00:01";
224 private static final String MAC2 = "00:00:00:00:00:02";
225 private final MacAddress mac1 = MacAddress.valueOf(MAC1);
226 private final MacAddress mac2 = MacAddress.valueOf(MAC2);
227 private final Instruction modEtherInstruction1 = Instructions.modL2Src(mac1);
228 private final Instruction sameAsModEtherInstruction1 = Instructions.modL2Src(mac1);
229 private final Instruction modEtherInstruction2 = Instructions.modL2Src(mac2);
230
231 /**
232 * Test the modL2Src method.
233 */
234 @Test
235 public void testModL2SrcMethod() {
236 final Instruction instruction = Instructions.modL2Src(mac1);
237 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
238 checkAndConvert(instruction,
239 Instruction.Type.L2MODIFICATION,
240 L2ModificationInstruction.ModEtherInstruction.class);
241 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
242 assertThat(modEtherInstruction.subtype(),
243 is(equalTo(L2ModificationInstruction.L2SubType.ETH_SRC)));
244 }
245
246 /**
247 * Test the modL2Dst method.
248 */
249 @Test
250 public void testModL2DstMethod() {
251 final Instruction instruction = Instructions.modL2Dst(mac1);
252 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
253 checkAndConvert(instruction,
254 Instruction.Type.L2MODIFICATION,
255 L2ModificationInstruction.ModEtherInstruction.class);
256 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
257 assertThat(modEtherInstruction.subtype(),
258 is(equalTo(L2ModificationInstruction.L2SubType.ETH_DST)));
259 }
260
261 /**
262 * Test the equals() method of the ModEtherInstruction class.
263 */
264
265 @Test
266 public void testModEtherInstructionEquals() throws Exception {
267 checkEqualsAndToString(modEtherInstruction1,
268 sameAsModEtherInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800269 modEtherInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800270 }
271
272 /**
273 * Test the hashCode() method of the ModEtherInstruction class.
274 */
275
276 @Test
277 public void testModEtherInstructionHashCode() {
278 assertThat(modEtherInstruction1.hashCode(),
279 is(equalTo(sameAsModEtherInstruction1.hashCode())));
280 assertThat(modEtherInstruction1.hashCode(),
281 is(not(equalTo(modEtherInstruction2.hashCode()))));
282 }
283
284
285 // ModVlanIdInstruction
286
287 private final short vlan1 = 1;
288 private final short vlan2 = 2;
289 private final VlanId vlanId1 = VlanId.vlanId(vlan1);
290 private final VlanId vlanId2 = VlanId.vlanId(vlan2);
291 private final Instruction modVlanId1 = Instructions.modVlanId(vlanId1);
292 private final Instruction sameAsModVlanId1 = Instructions.modVlanId(vlanId1);
293 private final Instruction modVlanId2 = Instructions.modVlanId(vlanId2);
294
295 /**
296 * Test the modVlanId method.
297 */
298 @Test
299 public void testModVlanIdMethod() {
300 final Instruction instruction = Instructions.modVlanId(vlanId1);
301 final L2ModificationInstruction.ModVlanIdInstruction modEtherInstruction =
302 checkAndConvert(instruction,
303 Instruction.Type.L2MODIFICATION,
304 L2ModificationInstruction.ModVlanIdInstruction.class);
305 assertThat(modEtherInstruction.vlanId(), is(equalTo(vlanId1)));
306 assertThat(modEtherInstruction.subtype(),
307 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_ID)));
308 }
309
310 /**
311 * Test the equals() method of the ModVlanIdInstruction class.
312 */
313
314 @Test
315 public void testModVlanIdInstructionEquals() throws Exception {
316 checkEqualsAndToString(modVlanId1,
317 sameAsModVlanId1,
Ray Milkey0d338052014-11-21 16:40:12 -0800318 modVlanId2);
Ray Milkey78081052014-11-05 10:38:12 -0800319 }
320
321 /**
322 * Test the hashCode() method of the ModEtherInstruction class.
323 */
324
325 @Test
326 public void testModVlanIdInstructionHashCode() {
327 assertThat(modVlanId1.hashCode(),
328 is(equalTo(sameAsModVlanId1.hashCode())));
329 assertThat(modVlanId1.hashCode(),
330 is(not(equalTo(modVlanId2.hashCode()))));
331 }
332
333
334 // ModVlanPcpInstruction
335
336 private final byte vlanPcp1 = 1;
337 private final byte vlanPcp2 = 2;
338 private final Instruction modVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
339 private final Instruction sameAsModVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
340 private final Instruction modVlanPcp2 = Instructions.modVlanPcp(vlanPcp2);
341
342 /**
343 * Test the modVlanPcp method.
344 */
345 @Test
346 public void testModVlanPcpMethod() {
347 final Instruction instruction = Instructions.modVlanPcp(vlanPcp1);
348 final L2ModificationInstruction.ModVlanPcpInstruction modEtherInstruction =
349 checkAndConvert(instruction,
350 Instruction.Type.L2MODIFICATION,
351 L2ModificationInstruction.ModVlanPcpInstruction.class);
352 assertThat(modEtherInstruction.vlanPcp(), is(equalTo(vlanPcp1)));
353 assertThat(modEtherInstruction.subtype(),
354 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_PCP)));
355 }
356
357 /**
358 * Test the equals() method of the ModVlanPcpInstruction class.
359 */
360
361 @Test
362 public void testModVlanPcpInstructionEquals() throws Exception {
363 checkEqualsAndToString(modVlanPcp1,
364 sameAsModVlanPcp1,
Ray Milkey0d338052014-11-21 16:40:12 -0800365 modVlanPcp2);
Ray Milkey78081052014-11-05 10:38:12 -0800366 }
367
368 /**
369 * Test the hashCode() method of the ModEtherInstruction class.
370 */
371
372 @Test
373 public void testModVlanPcpInstructionHashCode() {
374 assertThat(modVlanPcp1.hashCode(),
375 is(equalTo(sameAsModVlanPcp1.hashCode())));
376 assertThat(modVlanPcp1.hashCode(),
377 is(not(equalTo(modVlanPcp2.hashCode()))));
378 }
379
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800380 // ModIPInstruction
Ray Milkey78081052014-11-05 10:38:12 -0800381
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800382 private static final String IP41 = "1.2.3.4";
383 private static final String IP42 = "5.6.7.8";
384 private IpAddress ip41 = IpAddress.valueOf(IP41);
385 private IpAddress ip42 = IpAddress.valueOf(IP42);
386 private final Instruction modIPInstruction1 = Instructions.modL3Src(ip41);
387 private final Instruction sameAsModIPInstruction1 = Instructions.modL3Src(ip41);
388 private final Instruction modIPInstruction2 = Instructions.modL3Src(ip42);
389
390 private static final String IP61 = "1111::2222";
391 private static final String IP62 = "3333::4444";
392 private IpAddress ip61 = IpAddress.valueOf(IP61);
393 private IpAddress ip62 = IpAddress.valueOf(IP62);
394 private final Instruction modIPv6Instruction1 =
395 Instructions.modL3IPv6Src(ip61);
396 private final Instruction sameAsModIPv6Instruction1 =
397 Instructions.modL3IPv6Src(ip61);
398 private final Instruction modIPv6Instruction2 =
399 Instructions.modL3IPv6Src(ip62);
Ray Milkey78081052014-11-05 10:38:12 -0800400
401 /**
402 * Test the modL3Src method.
403 */
404 @Test
405 public void testModL3SrcMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800406 final Instruction instruction = Instructions.modL3Src(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800407 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
408 checkAndConvert(instruction,
409 Instruction.Type.L3MODIFICATION,
410 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800411 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800412 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800413 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_SRC)));
Ray Milkey78081052014-11-05 10:38:12 -0800414 }
415
416 /**
417 * Test the modL3Dst method.
418 */
419 @Test
420 public void testModL3DstMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800421 final Instruction instruction = Instructions.modL3Dst(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800422 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
423 checkAndConvert(instruction,
424 Instruction.Type.L3MODIFICATION,
425 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800426 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800427 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800428 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_DST)));
Ray Milkey78081052014-11-05 10:38:12 -0800429 }
430
431 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800432 * Test the modL3IPv6Src method.
Ray Milkey78081052014-11-05 10:38:12 -0800433 */
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800434 @Test
435 public void testModL3IPv6SrcMethod() {
436 final Instruction instruction = Instructions.modL3IPv6Src(ip61);
437 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
438 checkAndConvert(instruction,
439 Instruction.Type.L3MODIFICATION,
440 L3ModificationInstruction.ModIPInstruction.class);
441 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
442 assertThat(modIPInstruction.subtype(),
443 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_SRC)));
444 }
Ray Milkey78081052014-11-05 10:38:12 -0800445
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800446 /**
447 * Test the modL3IPv6Dst method.
448 */
449 @Test
450 public void testModL3IPv6DstMethod() {
451 final Instruction instruction = Instructions.modL3IPv6Dst(ip61);
452 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
453 checkAndConvert(instruction,
454 Instruction.Type.L3MODIFICATION,
455 L3ModificationInstruction.ModIPInstruction.class);
456 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
457 assertThat(modIPInstruction.subtype(),
458 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_DST)));
459 }
460
461 /**
462 * Test the equals() method of the ModIPInstruction class.
463 */
Ray Milkey78081052014-11-05 10:38:12 -0800464 @Test
465 public void testModIPInstructionEquals() throws Exception {
466 checkEqualsAndToString(modIPInstruction1,
467 sameAsModIPInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800468 modIPInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800469 }
470
471 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800472 * Test the hashCode() method of the ModIPInstruction class.
Ray Milkey78081052014-11-05 10:38:12 -0800473 */
Ray Milkey78081052014-11-05 10:38:12 -0800474 @Test
475 public void testModIPInstructionHashCode() {
476 assertThat(modIPInstruction1.hashCode(),
477 is(equalTo(sameAsModIPInstruction1.hashCode())));
478 assertThat(modIPInstruction1.hashCode(),
479 is(not(equalTo(modIPInstruction2.hashCode()))));
480 }
481
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800482 private final int flowLabel1 = 0x11111;
483 private final int flowLabel2 = 0x22222;
484 private final Instruction modIPv6FlowLabelInstruction1 =
485 Instructions.modL3IPv6FlowLabel(flowLabel1);
486 private final Instruction sameAsModIPv6FlowLabelInstruction1 =
487 Instructions.modL3IPv6FlowLabel(flowLabel1);
488 private final Instruction modIPv6FlowLabelInstruction2 =
489 Instructions.modL3IPv6FlowLabel(flowLabel2);
490
491 /**
492 * Test the modL3IPv6FlowLabel method.
493 */
494 @Test
495 public void testModL3IPv6FlowLabelMethod() {
496 final Instruction instruction =
497 Instructions.modL3IPv6FlowLabel(flowLabel1);
498 final L3ModificationInstruction.ModIPv6FlowLabelInstruction
499 modIPv6FlowLabelInstruction =
500 checkAndConvert(instruction,
501 Instruction.Type.L3MODIFICATION,
502 L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
503 assertThat(modIPv6FlowLabelInstruction.flowLabel(),
504 is(equalTo(flowLabel1)));
505 assertThat(modIPv6FlowLabelInstruction.subtype(),
506 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_FLABEL)));
507 }
508
509 /**
510 * Test the equals() method of the ModIPv6FlowLabelInstruction class.
511 */
512 @Test
513 public void testModIPv6FlowLabelInstructionEquals() throws Exception {
514 checkEqualsAndToString(modIPv6FlowLabelInstruction1,
515 sameAsModIPv6FlowLabelInstruction1,
516 modIPv6FlowLabelInstruction2);
517 }
518
519 /**
520 * Test the hashCode() method of the ModIPv6FlowLabelInstruction class.
521 */
522 @Test
523 public void testModIPv6FlowLabelInstructionHashCode() {
524 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
525 is(equalTo(sameAsModIPv6FlowLabelInstruction1.hashCode())));
526 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
527 is(not(equalTo(modIPv6FlowLabelInstruction2.hashCode()))));
528 }
529
Ray Milkey0d338052014-11-21 16:40:12 -0800530 private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(1);
531 private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(1);
532 private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(2);
533
534 /**
535 * Test the modMplsLabel method.
536 */
537 @Test
538 public void testModMplsMethod() {
539 final Instruction instruction = Instructions.modMplsLabel(33);
540 final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction =
541 checkAndConvert(instruction,
542 Instruction.Type.L2MODIFICATION,
543 L2ModificationInstruction.ModMplsLabelInstruction.class);
544 assertThat(modMplsLabelInstruction.label(), is(equalTo(33)));
545 assertThat(modMplsLabelInstruction.subtype(),
546 is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL)));
547 }
548
549 /**
550 * Test the equals(), hashCode and toString() methods of the
551 * ModMplsLabelInstruction class.
552 */
Ray Milkey0d338052014-11-21 16:40:12 -0800553 @Test
554 public void testModMplsLabelInstructionEquals() throws Exception {
555 checkEqualsAndToString(modMplsLabelInstruction1,
556 sameAsModMplsLabelInstruction1,
557 modMplsLabelInstruction2);
558 }
Ray Milkey78081052014-11-05 10:38:12 -0800559
560}