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