blob: 344f9b7e68838e21c69c7a8f2aa19a79440c201e [file] [log] [blame]
Ray Milkey78081052014-11-05 10:38:12 -08001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Ray Milkey78081052014-11-05 10:38:12 -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 */
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;
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -070019import org.onosproject.net.ChannelSpacing;
20import org.onosproject.net.GridType;
21import org.onosproject.net.Lambda;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.PortNumber;
Ray Milkey78081052014-11-05 10:38:12 -080023import org.onlab.packet.IpAddress;
Ray Milkey78081052014-11-05 10:38:12 -080024import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010025import org.onlab.packet.MplsLabel;
Ray Milkey78081052014-11-05 10:38:12 -080026import org.onlab.packet.VlanId;
27
Ray Milkey0d338052014-11-21 16:40:12 -080028import com.google.common.testing.EqualsTester;
29
Ray Milkey78081052014-11-05 10:38:12 -080030import static org.hamcrest.MatcherAssert.assertThat;
Ray Milkey78081052014-11-05 10:38:12 -080031import static org.hamcrest.Matchers.equalTo;
32import static org.hamcrest.Matchers.instanceOf;
33import static org.hamcrest.Matchers.is;
34import static org.hamcrest.Matchers.not;
35import static org.hamcrest.Matchers.notNullValue;
36import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
37import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
Brian O'Connorabafb502014-12-02 22:26:20 -080038import static org.onosproject.net.PortNumber.portNumber;
Ray Milkey78081052014-11-05 10:38:12 -080039
40/**
41 * Unit tests for the Instructions class.
42 */
43public class InstructionsTest {
44
45 /**
46 * Checks that a Criterion object has the proper type, and then converts
47 * it to the proper type.
48 *
49 * @param instruction Instruction object to convert
50 * @param type Enumerated type value for the Criterion class
51 * @param clazz Desired Criterion class
52 * @param <T> The type the caller wants returned
53 * @return converted object
54 */
55 @SuppressWarnings("unchecked")
56 private <T> T checkAndConvert(Instruction instruction, Instruction.Type type, Class clazz) {
57 assertThat(instruction, is(notNullValue()));
58 assertThat(instruction.type(), is(equalTo(type)));
59 assertThat(instruction, instanceOf(clazz));
60 return (T) instruction;
61 }
62
63 /**
64 * Checks the equals() and toString() methods of a Criterion class.
65 *
66 * @param c1 first object to compare
67 * @param c1match object that should be equal to the first
68 * @param c2 object that should be not equal to the first
Ray Milkey78081052014-11-05 10:38:12 -080069 * @param <T> type of the arguments
70 */
71 private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match,
Ray Milkey0d338052014-11-21 16:40:12 -080072 T c2) {
Ray Milkey78081052014-11-05 10:38:12 -080073
Ray Milkey0d338052014-11-21 16:40:12 -080074 new EqualsTester()
75 .addEqualityGroup(c1, c1match)
76 .addEqualityGroup(c2)
77 .testEquals();
Ray Milkey78081052014-11-05 10:38:12 -080078 }
79
80 /**
81 * Checks that Instructions is a proper utility class.
82 */
83 @Test
84 public void testInstructionsUtilityClass() {
85 assertThatClassIsUtility(Instructions.class);
86 }
87
88 /**
89 * Checks that the Instruction class implementations are immutable.
90 */
91 @Test
92 public void testImmutabilityOfInstructions() {
93 assertThatClassIsImmutable(Instructions.DropInstruction.class);
94 assertThatClassIsImmutable(Instructions.OutputInstruction.class);
95 assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class);
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -070096 assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class);
Ray Milkey78081052014-11-05 10:38:12 -080097 assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class);
98 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class);
99 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class);
100 assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800101 assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800102 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class);
103 assertThatClassIsImmutable(L2ModificationInstruction.PushHeaderInstructions.class);
Ray Milkey78081052014-11-05 10:38:12 -0800104 }
105
106 // DropInstruction
107
108 private final Instructions.DropInstruction drop1 = Instructions.createDrop();
109 private final Instructions.DropInstruction drop2 = Instructions.createDrop();
110
111 /**
112 * Test the createDrop method.
113 */
114 @Test
115 public void testCreateDropMethod() {
116 Instructions.DropInstruction instruction = Instructions.createDrop();
117 checkAndConvert(instruction,
118 Instruction.Type.DROP,
119 Instructions.DropInstruction.class);
120 }
121
122 /**
123 * Test the equals() method of the DropInstruction class.
124 */
125
126 @Test
127 public void testDropInstructionEquals() throws Exception {
128 assertThat(drop1, is(equalTo(drop2)));
129 }
130
131 /**
132 * Test the hashCode() method of the DropInstruction class.
133 */
134
135 @Test
136 public void testDropInstructionHashCode() {
137 assertThat(drop1.hashCode(), is(equalTo(drop2.hashCode())));
138 }
139
140 // OutputInstruction
141
142 private final PortNumber port1 = portNumber(1);
143 private final PortNumber port2 = portNumber(2);
144 private final Instructions.OutputInstruction output1 = Instructions.createOutput(port1);
145 private final Instructions.OutputInstruction sameAsOutput1 = Instructions.createOutput(port1);
146 private final Instructions.OutputInstruction output2 = Instructions.createOutput(port2);
147
148 /**
149 * Test the createOutput method.
150 */
151 @Test
152 public void testCreateOutputMethod() {
153 final Instruction instruction = Instructions.createOutput(port2);
154 final Instructions.OutputInstruction outputInstruction =
155 checkAndConvert(instruction,
156 Instruction.Type.OUTPUT,
157 Instructions.OutputInstruction.class);
158 assertThat(outputInstruction.port(), is(equalTo(port2)));
159 }
160
161
162 /**
163 * Test the equals() method of the OutputInstruction class.
164 */
165
166 @Test
167 public void testOutputInstructionEquals() throws Exception {
Ray Milkey0d338052014-11-21 16:40:12 -0800168 checkEqualsAndToString(output1, sameAsOutput1, output2);
Ray Milkey78081052014-11-05 10:38:12 -0800169 }
170
171 /**
172 * Test the hashCode() method of the OutputInstruction class.
173 */
174
175 @Test
176 public void testOutputInstructionHashCode() {
177 assertThat(output1.hashCode(), is(equalTo(sameAsOutput1.hashCode())));
178 assertThat(output1.hashCode(), is(not(equalTo(output2.hashCode()))));
179 }
180
181 // ModLambdaInstruction
182
183 private final short lambda1 = 1;
184 private final short lambda2 = 2;
185 private final Instruction lambdaInstruction1 = Instructions.modL0Lambda(lambda1);
186 private final Instruction sameAsLambdaInstruction1 = Instructions.modL0Lambda(lambda1);
187 private final Instruction lambdaInstruction2 = Instructions.modL0Lambda(lambda2);
188
189 /**
190 * Test the modL0Lambda method.
191 */
192 @Test
193 public void testCreateLambdaMethod() {
194 final Instruction instruction = Instructions.modL0Lambda(lambda1);
195 final L0ModificationInstruction.ModLambdaInstruction lambdaInstruction =
196 checkAndConvert(instruction,
197 Instruction.Type.L0MODIFICATION,
198 L0ModificationInstruction.ModLambdaInstruction.class);
199 assertThat(lambdaInstruction.lambda(), is(equalTo(lambda1)));
200 }
201
Ray Milkey78081052014-11-05 10:38:12 -0800202 /**
203 * Test the equals() method of the ModLambdaInstruction class.
204 */
205
206 @Test
207 public void testModLambdaInstructionEquals() throws Exception {
208 checkEqualsAndToString(lambdaInstruction1,
209 sameAsLambdaInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800210 lambdaInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800211 }
212
213 /**
214 * Test the hashCode() method of the ModLambdaInstruction class.
215 */
216
217 @Test
218 public void testModLambdaInstructionHashCode() {
219 assertThat(lambdaInstruction1.hashCode(),
220 is(equalTo(sameAsLambdaInstruction1.hashCode())));
221 assertThat(lambdaInstruction1.hashCode(),
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -0700222 is(not(equalTo(lambdaInstruction2.hashCode()))));
223 }
224
225 private final Lambda och1 = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
226 private final Lambda och2 = Lambda.ochSignal(GridType.CWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
227 private final Instruction ochInstruction1 = Instructions.modL0Lambda(och1);
228 private final Instruction sameAsOchInstruction1 = Instructions.modL0Lambda(och1);
229 private final Instruction ochInstruction2 = Instructions.modL0Lambda(och2);
230
231 /**
232 * Test the modL0Lambda().
233 */
234 @Test
235 public void testModL0LambdaMethod() {
236 Instruction instruction = Instructions.modL0Lambda(och1);
237 L0ModificationInstruction.ModOchSignalInstruction ochInstruction =
238 checkAndConvert(instruction, Instruction.Type.L0MODIFICATION,
239 L0ModificationInstruction.ModOchSignalInstruction.class);
240 assertThat(ochInstruction.lambda(), is(och1));
241 }
242
243 /**
244 * Test the equals() method of the ModOchSignalInstruction class.
245 */
246 @Test
247 public void testModOchSignalInstructionEquals() {
248 checkEqualsAndToString(ochInstruction1, sameAsOchInstruction1, ochInstruction2);
249 }
250
251 /**
252 * Test the hashCode() method of the ModOchSignalInstruction class.
253 */
254 @Test
255 public void testModOchSignalInstructionHashCode() {
256 assertThat(ochInstruction1.hashCode(), is(sameAsOchInstruction1.hashCode()));
257 assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode())));
Ray Milkey78081052014-11-05 10:38:12 -0800258 }
259
260 // ModEtherInstruction
261
262 private static final String MAC1 = "00:00:00:00:00:01";
263 private static final String MAC2 = "00:00:00:00:00:02";
264 private final MacAddress mac1 = MacAddress.valueOf(MAC1);
265 private final MacAddress mac2 = MacAddress.valueOf(MAC2);
266 private final Instruction modEtherInstruction1 = Instructions.modL2Src(mac1);
267 private final Instruction sameAsModEtherInstruction1 = Instructions.modL2Src(mac1);
268 private final Instruction modEtherInstruction2 = Instructions.modL2Src(mac2);
269
270 /**
271 * Test the modL2Src method.
272 */
273 @Test
274 public void testModL2SrcMethod() {
275 final Instruction instruction = Instructions.modL2Src(mac1);
276 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
277 checkAndConvert(instruction,
278 Instruction.Type.L2MODIFICATION,
279 L2ModificationInstruction.ModEtherInstruction.class);
280 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
281 assertThat(modEtherInstruction.subtype(),
282 is(equalTo(L2ModificationInstruction.L2SubType.ETH_SRC)));
283 }
284
285 /**
286 * Test the modL2Dst method.
287 */
288 @Test
289 public void testModL2DstMethod() {
290 final Instruction instruction = Instructions.modL2Dst(mac1);
291 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
292 checkAndConvert(instruction,
293 Instruction.Type.L2MODIFICATION,
294 L2ModificationInstruction.ModEtherInstruction.class);
295 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
296 assertThat(modEtherInstruction.subtype(),
297 is(equalTo(L2ModificationInstruction.L2SubType.ETH_DST)));
298 }
299
300 /**
301 * Test the equals() method of the ModEtherInstruction class.
302 */
303
304 @Test
305 public void testModEtherInstructionEquals() throws Exception {
306 checkEqualsAndToString(modEtherInstruction1,
307 sameAsModEtherInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800308 modEtherInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800309 }
310
311 /**
312 * Test the hashCode() method of the ModEtherInstruction class.
313 */
314
315 @Test
316 public void testModEtherInstructionHashCode() {
317 assertThat(modEtherInstruction1.hashCode(),
318 is(equalTo(sameAsModEtherInstruction1.hashCode())));
319 assertThat(modEtherInstruction1.hashCode(),
320 is(not(equalTo(modEtherInstruction2.hashCode()))));
321 }
322
323
324 // ModVlanIdInstruction
325
326 private final short vlan1 = 1;
327 private final short vlan2 = 2;
328 private final VlanId vlanId1 = VlanId.vlanId(vlan1);
329 private final VlanId vlanId2 = VlanId.vlanId(vlan2);
330 private final Instruction modVlanId1 = Instructions.modVlanId(vlanId1);
331 private final Instruction sameAsModVlanId1 = Instructions.modVlanId(vlanId1);
332 private final Instruction modVlanId2 = Instructions.modVlanId(vlanId2);
333
334 /**
335 * Test the modVlanId method.
336 */
337 @Test
338 public void testModVlanIdMethod() {
339 final Instruction instruction = Instructions.modVlanId(vlanId1);
340 final L2ModificationInstruction.ModVlanIdInstruction modEtherInstruction =
341 checkAndConvert(instruction,
342 Instruction.Type.L2MODIFICATION,
343 L2ModificationInstruction.ModVlanIdInstruction.class);
344 assertThat(modEtherInstruction.vlanId(), is(equalTo(vlanId1)));
345 assertThat(modEtherInstruction.subtype(),
346 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_ID)));
347 }
348
349 /**
350 * Test the equals() method of the ModVlanIdInstruction class.
351 */
352
353 @Test
354 public void testModVlanIdInstructionEquals() throws Exception {
355 checkEqualsAndToString(modVlanId1,
356 sameAsModVlanId1,
Ray Milkey0d338052014-11-21 16:40:12 -0800357 modVlanId2);
Ray Milkey78081052014-11-05 10:38:12 -0800358 }
359
360 /**
361 * Test the hashCode() method of the ModEtherInstruction class.
362 */
363
364 @Test
365 public void testModVlanIdInstructionHashCode() {
366 assertThat(modVlanId1.hashCode(),
367 is(equalTo(sameAsModVlanId1.hashCode())));
368 assertThat(modVlanId1.hashCode(),
369 is(not(equalTo(modVlanId2.hashCode()))));
370 }
371
372
373 // ModVlanPcpInstruction
374
375 private final byte vlanPcp1 = 1;
376 private final byte vlanPcp2 = 2;
377 private final Instruction modVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
378 private final Instruction sameAsModVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
379 private final Instruction modVlanPcp2 = Instructions.modVlanPcp(vlanPcp2);
380
381 /**
382 * Test the modVlanPcp method.
383 */
384 @Test
385 public void testModVlanPcpMethod() {
386 final Instruction instruction = Instructions.modVlanPcp(vlanPcp1);
387 final L2ModificationInstruction.ModVlanPcpInstruction modEtherInstruction =
388 checkAndConvert(instruction,
389 Instruction.Type.L2MODIFICATION,
390 L2ModificationInstruction.ModVlanPcpInstruction.class);
391 assertThat(modEtherInstruction.vlanPcp(), is(equalTo(vlanPcp1)));
392 assertThat(modEtherInstruction.subtype(),
393 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_PCP)));
394 }
395
396 /**
397 * Test the equals() method of the ModVlanPcpInstruction class.
398 */
399
400 @Test
401 public void testModVlanPcpInstructionEquals() throws Exception {
402 checkEqualsAndToString(modVlanPcp1,
403 sameAsModVlanPcp1,
Ray Milkey0d338052014-11-21 16:40:12 -0800404 modVlanPcp2);
Ray Milkey78081052014-11-05 10:38:12 -0800405 }
406
407 /**
408 * Test the hashCode() method of the ModEtherInstruction class.
409 */
410
411 @Test
412 public void testModVlanPcpInstructionHashCode() {
413 assertThat(modVlanPcp1.hashCode(),
414 is(equalTo(sameAsModVlanPcp1.hashCode())));
415 assertThat(modVlanPcp1.hashCode(),
416 is(not(equalTo(modVlanPcp2.hashCode()))));
417 }
418
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800419 // ModIPInstruction
Ray Milkey78081052014-11-05 10:38:12 -0800420
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800421 private static final String IP41 = "1.2.3.4";
422 private static final String IP42 = "5.6.7.8";
423 private IpAddress ip41 = IpAddress.valueOf(IP41);
424 private IpAddress ip42 = IpAddress.valueOf(IP42);
425 private final Instruction modIPInstruction1 = Instructions.modL3Src(ip41);
426 private final Instruction sameAsModIPInstruction1 = Instructions.modL3Src(ip41);
427 private final Instruction modIPInstruction2 = Instructions.modL3Src(ip42);
428
429 private static final String IP61 = "1111::2222";
430 private static final String IP62 = "3333::4444";
431 private IpAddress ip61 = IpAddress.valueOf(IP61);
432 private IpAddress ip62 = IpAddress.valueOf(IP62);
433 private final Instruction modIPv6Instruction1 =
434 Instructions.modL3IPv6Src(ip61);
435 private final Instruction sameAsModIPv6Instruction1 =
436 Instructions.modL3IPv6Src(ip61);
437 private final Instruction modIPv6Instruction2 =
438 Instructions.modL3IPv6Src(ip62);
Ray Milkey78081052014-11-05 10:38:12 -0800439
440 /**
441 * Test the modL3Src method.
442 */
443 @Test
444 public void testModL3SrcMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800445 final Instruction instruction = Instructions.modL3Src(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800446 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
447 checkAndConvert(instruction,
448 Instruction.Type.L3MODIFICATION,
449 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800450 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800451 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800452 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_SRC)));
Ray Milkey78081052014-11-05 10:38:12 -0800453 }
454
455 /**
456 * Test the modL3Dst method.
457 */
458 @Test
459 public void testModL3DstMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800460 final Instruction instruction = Instructions.modL3Dst(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800461 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
462 checkAndConvert(instruction,
463 Instruction.Type.L3MODIFICATION,
464 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800465 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800466 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800467 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_DST)));
Ray Milkey78081052014-11-05 10:38:12 -0800468 }
469
470 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800471 * Test the modL3IPv6Src method.
Ray Milkey78081052014-11-05 10:38:12 -0800472 */
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800473 @Test
474 public void testModL3IPv6SrcMethod() {
475 final Instruction instruction = Instructions.modL3IPv6Src(ip61);
476 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
477 checkAndConvert(instruction,
478 Instruction.Type.L3MODIFICATION,
479 L3ModificationInstruction.ModIPInstruction.class);
480 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
481 assertThat(modIPInstruction.subtype(),
482 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_SRC)));
483 }
Ray Milkey78081052014-11-05 10:38:12 -0800484
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800485 /**
486 * Test the modL3IPv6Dst method.
487 */
488 @Test
489 public void testModL3IPv6DstMethod() {
490 final Instruction instruction = Instructions.modL3IPv6Dst(ip61);
491 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
492 checkAndConvert(instruction,
493 Instruction.Type.L3MODIFICATION,
494 L3ModificationInstruction.ModIPInstruction.class);
495 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
496 assertThat(modIPInstruction.subtype(),
497 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_DST)));
498 }
499
500 /**
501 * Test the equals() method of the ModIPInstruction class.
502 */
Ray Milkey78081052014-11-05 10:38:12 -0800503 @Test
504 public void testModIPInstructionEquals() throws Exception {
505 checkEqualsAndToString(modIPInstruction1,
506 sameAsModIPInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800507 modIPInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800508 }
509
510 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800511 * Test the hashCode() method of the ModIPInstruction class.
Ray Milkey78081052014-11-05 10:38:12 -0800512 */
Ray Milkey78081052014-11-05 10:38:12 -0800513 @Test
514 public void testModIPInstructionHashCode() {
515 assertThat(modIPInstruction1.hashCode(),
516 is(equalTo(sameAsModIPInstruction1.hashCode())));
517 assertThat(modIPInstruction1.hashCode(),
518 is(not(equalTo(modIPInstruction2.hashCode()))));
519 }
520
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800521 private final int flowLabel1 = 0x11111;
522 private final int flowLabel2 = 0x22222;
523 private final Instruction modIPv6FlowLabelInstruction1 =
524 Instructions.modL3IPv6FlowLabel(flowLabel1);
525 private final Instruction sameAsModIPv6FlowLabelInstruction1 =
526 Instructions.modL3IPv6FlowLabel(flowLabel1);
527 private final Instruction modIPv6FlowLabelInstruction2 =
528 Instructions.modL3IPv6FlowLabel(flowLabel2);
529
530 /**
531 * Test the modL3IPv6FlowLabel method.
532 */
533 @Test
534 public void testModL3IPv6FlowLabelMethod() {
535 final Instruction instruction =
536 Instructions.modL3IPv6FlowLabel(flowLabel1);
537 final L3ModificationInstruction.ModIPv6FlowLabelInstruction
538 modIPv6FlowLabelInstruction =
539 checkAndConvert(instruction,
540 Instruction.Type.L3MODIFICATION,
541 L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
542 assertThat(modIPv6FlowLabelInstruction.flowLabel(),
543 is(equalTo(flowLabel1)));
544 assertThat(modIPv6FlowLabelInstruction.subtype(),
545 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_FLABEL)));
546 }
547
548 /**
549 * Test the equals() method of the ModIPv6FlowLabelInstruction class.
550 */
551 @Test
552 public void testModIPv6FlowLabelInstructionEquals() throws Exception {
553 checkEqualsAndToString(modIPv6FlowLabelInstruction1,
554 sameAsModIPv6FlowLabelInstruction1,
555 modIPv6FlowLabelInstruction2);
556 }
557
558 /**
559 * Test the hashCode() method of the ModIPv6FlowLabelInstruction class.
560 */
561 @Test
562 public void testModIPv6FlowLabelInstructionHashCode() {
563 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
564 is(equalTo(sameAsModIPv6FlowLabelInstruction1.hashCode())));
565 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
566 is(not(equalTo(modIPv6FlowLabelInstruction2.hashCode()))));
567 }
568
Michele Santuari4b6019e2014-12-19 11:31:45 +0100569 private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
570 private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
571 private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(MplsLabel.mplsLabel(2));
Ray Milkey0d338052014-11-21 16:40:12 -0800572
573 /**
574 * Test the modMplsLabel method.
575 */
576 @Test
577 public void testModMplsMethod() {
Michele Santuari4b6019e2014-12-19 11:31:45 +0100578 final Instruction instruction = Instructions.modMplsLabel(MplsLabel.mplsLabel(33));
Ray Milkey0d338052014-11-21 16:40:12 -0800579 final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction =
580 checkAndConvert(instruction,
581 Instruction.Type.L2MODIFICATION,
582 L2ModificationInstruction.ModMplsLabelInstruction.class);
583 assertThat(modMplsLabelInstruction.label(), is(equalTo(33)));
584 assertThat(modMplsLabelInstruction.subtype(),
585 is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL)));
586 }
587
588 /**
589 * Test the equals(), hashCode and toString() methods of the
590 * ModMplsLabelInstruction class.
591 */
Ray Milkey0d338052014-11-21 16:40:12 -0800592 @Test
593 public void testModMplsLabelInstructionEquals() throws Exception {
594 checkEqualsAndToString(modMplsLabelInstruction1,
595 sameAsModMplsLabelInstruction1,
596 modMplsLabelInstruction2);
597 }
Ray Milkey78081052014-11-05 10:38:12 -0800598
599}