blob: 410349b55fc2149b2caac9effe6cb5d5df880594 [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;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070019import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
21import org.onlab.packet.MplsLabel;
22import org.onlab.packet.TpPort;
23import org.onlab.packet.VlanId;
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -070024import org.onosproject.net.ChannelSpacing;
25import org.onosproject.net.GridType;
Ray Milkey85571eb2015-06-25 09:45:46 -070026import org.onosproject.net.IndexedLambda;
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -070027import org.onosproject.net.Lambda;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.PortNumber;
Ray Milkey78081052014-11-05 10:38:12 -080029
Ray Milkey0d338052014-11-21 16:40:12 -080030import com.google.common.testing.EqualsTester;
31
Ray Milkey78081052014-11-05 10:38:12 -080032import static org.hamcrest.MatcherAssert.assertThat;
Ray Milkey78081052014-11-05 10:38:12 -080033import static org.hamcrest.Matchers.equalTo;
34import static org.hamcrest.Matchers.instanceOf;
35import static org.hamcrest.Matchers.is;
36import static org.hamcrest.Matchers.not;
37import static org.hamcrest.Matchers.notNullValue;
38import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
39import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
Brian O'Connorabafb502014-12-02 22:26:20 -080040import static org.onosproject.net.PortNumber.portNumber;
Ray Milkey78081052014-11-05 10:38:12 -080041
42/**
43 * Unit tests for the Instructions class.
44 */
45public class InstructionsTest {
46
47 /**
48 * Checks that a Criterion object has the proper type, and then converts
49 * it to the proper type.
50 *
51 * @param instruction Instruction object to convert
52 * @param type Enumerated type value for the Criterion class
53 * @param clazz Desired Criterion class
54 * @param <T> The type the caller wants returned
55 * @return converted object
56 */
57 @SuppressWarnings("unchecked")
58 private <T> T checkAndConvert(Instruction instruction, Instruction.Type type, Class clazz) {
59 assertThat(instruction, is(notNullValue()));
60 assertThat(instruction.type(), is(equalTo(type)));
61 assertThat(instruction, instanceOf(clazz));
62 return (T) instruction;
63 }
64
65 /**
66 * Checks the equals() and toString() methods of a Criterion class.
67 *
68 * @param c1 first object to compare
69 * @param c1match object that should be equal to the first
70 * @param c2 object that should be not equal to the first
Ray Milkey78081052014-11-05 10:38:12 -080071 * @param <T> type of the arguments
72 */
73 private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match,
Ray Milkey0d338052014-11-21 16:40:12 -080074 T c2) {
Ray Milkey78081052014-11-05 10:38:12 -080075
Ray Milkey0d338052014-11-21 16:40:12 -080076 new EqualsTester()
77 .addEqualityGroup(c1, c1match)
78 .addEqualityGroup(c2)
79 .testEquals();
Ray Milkey78081052014-11-05 10:38:12 -080080 }
81
82 /**
83 * Checks that Instructions is a proper utility class.
84 */
85 @Test
86 public void testInstructionsUtilityClass() {
87 assertThatClassIsUtility(Instructions.class);
88 }
89
90 /**
91 * Checks that the Instruction class implementations are immutable.
92 */
93 @Test
94 public void testImmutabilityOfInstructions() {
95 assertThatClassIsImmutable(Instructions.DropInstruction.class);
96 assertThatClassIsImmutable(Instructions.OutputInstruction.class);
97 assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class);
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -070098 assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class);
Ray Milkey78081052014-11-05 10:38:12 -080099 assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class);
100 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class);
101 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class);
102 assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800103 assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800104 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class);
105 assertThatClassIsImmutable(L2ModificationInstruction.PushHeaderInstructions.class);
Ray Milkey78081052014-11-05 10:38:12 -0800106 }
107
108 // DropInstruction
109
110 private final Instructions.DropInstruction drop1 = Instructions.createDrop();
111 private final Instructions.DropInstruction drop2 = Instructions.createDrop();
112
113 /**
114 * Test the createDrop method.
115 */
116 @Test
117 public void testCreateDropMethod() {
118 Instructions.DropInstruction instruction = Instructions.createDrop();
119 checkAndConvert(instruction,
120 Instruction.Type.DROP,
121 Instructions.DropInstruction.class);
122 }
123
124 /**
125 * Test the equals() method of the DropInstruction class.
126 */
127
128 @Test
129 public void testDropInstructionEquals() throws Exception {
130 assertThat(drop1, is(equalTo(drop2)));
131 }
132
133 /**
134 * Test the hashCode() method of the DropInstruction class.
135 */
136
137 @Test
138 public void testDropInstructionHashCode() {
139 assertThat(drop1.hashCode(), is(equalTo(drop2.hashCode())));
140 }
141
142 // OutputInstruction
143
144 private final PortNumber port1 = portNumber(1);
145 private final PortNumber port2 = portNumber(2);
146 private final Instructions.OutputInstruction output1 = Instructions.createOutput(port1);
147 private final Instructions.OutputInstruction sameAsOutput1 = Instructions.createOutput(port1);
148 private final Instructions.OutputInstruction output2 = Instructions.createOutput(port2);
149
150 /**
151 * Test the createOutput method.
152 */
153 @Test
154 public void testCreateOutputMethod() {
155 final Instruction instruction = Instructions.createOutput(port2);
156 final Instructions.OutputInstruction outputInstruction =
157 checkAndConvert(instruction,
158 Instruction.Type.OUTPUT,
159 Instructions.OutputInstruction.class);
160 assertThat(outputInstruction.port(), is(equalTo(port2)));
161 }
162
163
164 /**
165 * Test the equals() method of the OutputInstruction class.
166 */
167
168 @Test
169 public void testOutputInstructionEquals() throws Exception {
Ray Milkey0d338052014-11-21 16:40:12 -0800170 checkEqualsAndToString(output1, sameAsOutput1, output2);
Ray Milkey78081052014-11-05 10:38:12 -0800171 }
172
173 /**
174 * Test the hashCode() method of the OutputInstruction class.
175 */
176
177 @Test
178 public void testOutputInstructionHashCode() {
179 assertThat(output1.hashCode(), is(equalTo(sameAsOutput1.hashCode())));
180 assertThat(output1.hashCode(), is(not(equalTo(output2.hashCode()))));
181 }
182
183 // ModLambdaInstruction
184
Ray Milkey85571eb2015-06-25 09:45:46 -0700185 private final IndexedLambda lambda1 = new IndexedLambda(1);
186 private final IndexedLambda lambda2 = new IndexedLambda(2);
Ray Milkey78081052014-11-05 10:38:12 -0800187 private final Instruction lambdaInstruction1 = Instructions.modL0Lambda(lambda1);
188 private final Instruction sameAsLambdaInstruction1 = Instructions.modL0Lambda(lambda1);
189 private final Instruction lambdaInstruction2 = Instructions.modL0Lambda(lambda2);
190
191 /**
192 * Test the modL0Lambda method.
193 */
194 @Test
195 public void testCreateLambdaMethod() {
196 final Instruction instruction = Instructions.modL0Lambda(lambda1);
197 final L0ModificationInstruction.ModLambdaInstruction lambdaInstruction =
198 checkAndConvert(instruction,
199 Instruction.Type.L0MODIFICATION,
200 L0ModificationInstruction.ModLambdaInstruction.class);
Ray Milkey85571eb2015-06-25 09:45:46 -0700201 assertThat(lambdaInstruction.lambda(), is(equalTo((short) lambda1.index())));
Ray Milkey78081052014-11-05 10:38:12 -0800202 }
203
Ray Milkey78081052014-11-05 10:38:12 -0800204 /**
205 * Test the equals() method of the ModLambdaInstruction class.
206 */
207
208 @Test
209 public void testModLambdaInstructionEquals() throws Exception {
210 checkEqualsAndToString(lambdaInstruction1,
211 sameAsLambdaInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800212 lambdaInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800213 }
214
215 /**
216 * Test the hashCode() method of the ModLambdaInstruction class.
217 */
218
219 @Test
220 public void testModLambdaInstructionHashCode() {
221 assertThat(lambdaInstruction1.hashCode(),
222 is(equalTo(sameAsLambdaInstruction1.hashCode())));
223 assertThat(lambdaInstruction1.hashCode(),
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -0700224 is(not(equalTo(lambdaInstruction2.hashCode()))));
225 }
226
227 private final Lambda och1 = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
228 private final Lambda och2 = Lambda.ochSignal(GridType.CWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
229 private final Instruction ochInstruction1 = Instructions.modL0Lambda(och1);
230 private final Instruction sameAsOchInstruction1 = Instructions.modL0Lambda(och1);
231 private final Instruction ochInstruction2 = Instructions.modL0Lambda(och2);
232
233 /**
234 * Test the modL0Lambda().
235 */
236 @Test
237 public void testModL0LambdaMethod() {
238 Instruction instruction = Instructions.modL0Lambda(och1);
239 L0ModificationInstruction.ModOchSignalInstruction ochInstruction =
240 checkAndConvert(instruction, Instruction.Type.L0MODIFICATION,
241 L0ModificationInstruction.ModOchSignalInstruction.class);
242 assertThat(ochInstruction.lambda(), is(och1));
243 }
244
245 /**
246 * Test the equals() method of the ModOchSignalInstruction class.
247 */
248 @Test
249 public void testModOchSignalInstructionEquals() {
250 checkEqualsAndToString(ochInstruction1, sameAsOchInstruction1, ochInstruction2);
251 }
252
253 /**
254 * Test the hashCode() method of the ModOchSignalInstruction class.
255 */
256 @Test
257 public void testModOchSignalInstructionHashCode() {
258 assertThat(ochInstruction1.hashCode(), is(sameAsOchInstruction1.hashCode()));
259 assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode())));
Ray Milkey78081052014-11-05 10:38:12 -0800260 }
261
262 // ModEtherInstruction
263
264 private static final String MAC1 = "00:00:00:00:00:01";
265 private static final String MAC2 = "00:00:00:00:00:02";
266 private final MacAddress mac1 = MacAddress.valueOf(MAC1);
267 private final MacAddress mac2 = MacAddress.valueOf(MAC2);
268 private final Instruction modEtherInstruction1 = Instructions.modL2Src(mac1);
269 private final Instruction sameAsModEtherInstruction1 = Instructions.modL2Src(mac1);
270 private final Instruction modEtherInstruction2 = Instructions.modL2Src(mac2);
271
272 /**
273 * Test the modL2Src method.
274 */
275 @Test
276 public void testModL2SrcMethod() {
277 final Instruction instruction = Instructions.modL2Src(mac1);
278 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
279 checkAndConvert(instruction,
280 Instruction.Type.L2MODIFICATION,
281 L2ModificationInstruction.ModEtherInstruction.class);
282 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
283 assertThat(modEtherInstruction.subtype(),
284 is(equalTo(L2ModificationInstruction.L2SubType.ETH_SRC)));
285 }
286
287 /**
288 * Test the modL2Dst method.
289 */
290 @Test
291 public void testModL2DstMethod() {
292 final Instruction instruction = Instructions.modL2Dst(mac1);
293 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
294 checkAndConvert(instruction,
295 Instruction.Type.L2MODIFICATION,
296 L2ModificationInstruction.ModEtherInstruction.class);
297 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
298 assertThat(modEtherInstruction.subtype(),
299 is(equalTo(L2ModificationInstruction.L2SubType.ETH_DST)));
300 }
301
302 /**
303 * Test the equals() method of the ModEtherInstruction class.
304 */
305
306 @Test
307 public void testModEtherInstructionEquals() throws Exception {
308 checkEqualsAndToString(modEtherInstruction1,
309 sameAsModEtherInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800310 modEtherInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800311 }
312
313 /**
314 * Test the hashCode() method of the ModEtherInstruction class.
315 */
316
317 @Test
318 public void testModEtherInstructionHashCode() {
319 assertThat(modEtherInstruction1.hashCode(),
320 is(equalTo(sameAsModEtherInstruction1.hashCode())));
321 assertThat(modEtherInstruction1.hashCode(),
322 is(not(equalTo(modEtherInstruction2.hashCode()))));
323 }
324
325
326 // ModVlanIdInstruction
327
328 private final short vlan1 = 1;
329 private final short vlan2 = 2;
330 private final VlanId vlanId1 = VlanId.vlanId(vlan1);
331 private final VlanId vlanId2 = VlanId.vlanId(vlan2);
332 private final Instruction modVlanId1 = Instructions.modVlanId(vlanId1);
333 private final Instruction sameAsModVlanId1 = Instructions.modVlanId(vlanId1);
334 private final Instruction modVlanId2 = Instructions.modVlanId(vlanId2);
335
336 /**
337 * Test the modVlanId method.
338 */
339 @Test
340 public void testModVlanIdMethod() {
341 final Instruction instruction = Instructions.modVlanId(vlanId1);
342 final L2ModificationInstruction.ModVlanIdInstruction modEtherInstruction =
343 checkAndConvert(instruction,
344 Instruction.Type.L2MODIFICATION,
345 L2ModificationInstruction.ModVlanIdInstruction.class);
346 assertThat(modEtherInstruction.vlanId(), is(equalTo(vlanId1)));
347 assertThat(modEtherInstruction.subtype(),
348 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_ID)));
349 }
350
351 /**
352 * Test the equals() method of the ModVlanIdInstruction class.
353 */
354
355 @Test
356 public void testModVlanIdInstructionEquals() throws Exception {
357 checkEqualsAndToString(modVlanId1,
358 sameAsModVlanId1,
Ray Milkey0d338052014-11-21 16:40:12 -0800359 modVlanId2);
Ray Milkey78081052014-11-05 10:38:12 -0800360 }
361
362 /**
363 * Test the hashCode() method of the ModEtherInstruction class.
364 */
365
366 @Test
367 public void testModVlanIdInstructionHashCode() {
368 assertThat(modVlanId1.hashCode(),
369 is(equalTo(sameAsModVlanId1.hashCode())));
370 assertThat(modVlanId1.hashCode(),
371 is(not(equalTo(modVlanId2.hashCode()))));
372 }
373
374
375 // ModVlanPcpInstruction
376
377 private final byte vlanPcp1 = 1;
378 private final byte vlanPcp2 = 2;
379 private final Instruction modVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
380 private final Instruction sameAsModVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
381 private final Instruction modVlanPcp2 = Instructions.modVlanPcp(vlanPcp2);
382
383 /**
384 * Test the modVlanPcp method.
385 */
386 @Test
387 public void testModVlanPcpMethod() {
388 final Instruction instruction = Instructions.modVlanPcp(vlanPcp1);
389 final L2ModificationInstruction.ModVlanPcpInstruction modEtherInstruction =
390 checkAndConvert(instruction,
391 Instruction.Type.L2MODIFICATION,
392 L2ModificationInstruction.ModVlanPcpInstruction.class);
393 assertThat(modEtherInstruction.vlanPcp(), is(equalTo(vlanPcp1)));
394 assertThat(modEtherInstruction.subtype(),
395 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_PCP)));
396 }
397
398 /**
399 * Test the equals() method of the ModVlanPcpInstruction class.
400 */
401
402 @Test
403 public void testModVlanPcpInstructionEquals() throws Exception {
404 checkEqualsAndToString(modVlanPcp1,
405 sameAsModVlanPcp1,
Ray Milkey0d338052014-11-21 16:40:12 -0800406 modVlanPcp2);
Ray Milkey78081052014-11-05 10:38:12 -0800407 }
408
409 /**
410 * Test the hashCode() method of the ModEtherInstruction class.
411 */
412
413 @Test
414 public void testModVlanPcpInstructionHashCode() {
415 assertThat(modVlanPcp1.hashCode(),
416 is(equalTo(sameAsModVlanPcp1.hashCode())));
417 assertThat(modVlanPcp1.hashCode(),
418 is(not(equalTo(modVlanPcp2.hashCode()))));
419 }
420
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800421 // ModIPInstruction
Ray Milkey78081052014-11-05 10:38:12 -0800422
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800423 private static final String IP41 = "1.2.3.4";
424 private static final String IP42 = "5.6.7.8";
425 private IpAddress ip41 = IpAddress.valueOf(IP41);
426 private IpAddress ip42 = IpAddress.valueOf(IP42);
427 private final Instruction modIPInstruction1 = Instructions.modL3Src(ip41);
428 private final Instruction sameAsModIPInstruction1 = Instructions.modL3Src(ip41);
429 private final Instruction modIPInstruction2 = Instructions.modL3Src(ip42);
430
431 private static final String IP61 = "1111::2222";
432 private static final String IP62 = "3333::4444";
433 private IpAddress ip61 = IpAddress.valueOf(IP61);
434 private IpAddress ip62 = IpAddress.valueOf(IP62);
435 private final Instruction modIPv6Instruction1 =
436 Instructions.modL3IPv6Src(ip61);
437 private final Instruction sameAsModIPv6Instruction1 =
438 Instructions.modL3IPv6Src(ip61);
439 private final Instruction modIPv6Instruction2 =
440 Instructions.modL3IPv6Src(ip62);
Ray Milkey78081052014-11-05 10:38:12 -0800441
442 /**
443 * Test the modL3Src method.
444 */
445 @Test
446 public void testModL3SrcMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800447 final Instruction instruction = Instructions.modL3Src(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800448 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
449 checkAndConvert(instruction,
450 Instruction.Type.L3MODIFICATION,
451 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800452 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800453 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800454 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_SRC)));
Ray Milkey78081052014-11-05 10:38:12 -0800455 }
456
457 /**
458 * Test the modL3Dst method.
459 */
460 @Test
461 public void testModL3DstMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800462 final Instruction instruction = Instructions.modL3Dst(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800463 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
464 checkAndConvert(instruction,
465 Instruction.Type.L3MODIFICATION,
466 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800467 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800468 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800469 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_DST)));
Ray Milkey78081052014-11-05 10:38:12 -0800470 }
471
472 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800473 * Test the modL3IPv6Src method.
Ray Milkey78081052014-11-05 10:38:12 -0800474 */
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800475 @Test
476 public void testModL3IPv6SrcMethod() {
477 final Instruction instruction = Instructions.modL3IPv6Src(ip61);
478 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
479 checkAndConvert(instruction,
480 Instruction.Type.L3MODIFICATION,
481 L3ModificationInstruction.ModIPInstruction.class);
482 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
483 assertThat(modIPInstruction.subtype(),
484 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_SRC)));
485 }
Ray Milkey78081052014-11-05 10:38:12 -0800486
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800487 /**
488 * Test the modL3IPv6Dst method.
489 */
490 @Test
491 public void testModL3IPv6DstMethod() {
492 final Instruction instruction = Instructions.modL3IPv6Dst(ip61);
493 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
494 checkAndConvert(instruction,
495 Instruction.Type.L3MODIFICATION,
496 L3ModificationInstruction.ModIPInstruction.class);
497 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
498 assertThat(modIPInstruction.subtype(),
499 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_DST)));
500 }
501
502 /**
503 * Test the equals() method of the ModIPInstruction class.
504 */
Ray Milkey78081052014-11-05 10:38:12 -0800505 @Test
506 public void testModIPInstructionEquals() throws Exception {
507 checkEqualsAndToString(modIPInstruction1,
508 sameAsModIPInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800509 modIPInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800510 }
511
512 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800513 * Test the hashCode() method of the ModIPInstruction class.
Ray Milkey78081052014-11-05 10:38:12 -0800514 */
Ray Milkey78081052014-11-05 10:38:12 -0800515 @Test
516 public void testModIPInstructionHashCode() {
517 assertThat(modIPInstruction1.hashCode(),
518 is(equalTo(sameAsModIPInstruction1.hashCode())));
519 assertThat(modIPInstruction1.hashCode(),
520 is(not(equalTo(modIPInstruction2.hashCode()))));
521 }
522
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800523 private final int flowLabel1 = 0x11111;
524 private final int flowLabel2 = 0x22222;
525 private final Instruction modIPv6FlowLabelInstruction1 =
526 Instructions.modL3IPv6FlowLabel(flowLabel1);
527 private final Instruction sameAsModIPv6FlowLabelInstruction1 =
528 Instructions.modL3IPv6FlowLabel(flowLabel1);
529 private final Instruction modIPv6FlowLabelInstruction2 =
530 Instructions.modL3IPv6FlowLabel(flowLabel2);
531
532 /**
533 * Test the modL3IPv6FlowLabel method.
534 */
535 @Test
536 public void testModL3IPv6FlowLabelMethod() {
537 final Instruction instruction =
538 Instructions.modL3IPv6FlowLabel(flowLabel1);
539 final L3ModificationInstruction.ModIPv6FlowLabelInstruction
540 modIPv6FlowLabelInstruction =
541 checkAndConvert(instruction,
542 Instruction.Type.L3MODIFICATION,
543 L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
544 assertThat(modIPv6FlowLabelInstruction.flowLabel(),
545 is(equalTo(flowLabel1)));
546 assertThat(modIPv6FlowLabelInstruction.subtype(),
547 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_FLABEL)));
548 }
549
550 /**
551 * Test the equals() method of the ModIPv6FlowLabelInstruction class.
552 */
553 @Test
554 public void testModIPv6FlowLabelInstructionEquals() throws Exception {
555 checkEqualsAndToString(modIPv6FlowLabelInstruction1,
556 sameAsModIPv6FlowLabelInstruction1,
557 modIPv6FlowLabelInstruction2);
558 }
559
560 /**
561 * Test the hashCode() method of the ModIPv6FlowLabelInstruction class.
562 */
563 @Test
564 public void testModIPv6FlowLabelInstructionHashCode() {
565 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
566 is(equalTo(sameAsModIPv6FlowLabelInstruction1.hashCode())));
567 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
568 is(not(equalTo(modIPv6FlowLabelInstruction2.hashCode()))));
569 }
570
Michele Santuari4b6019e2014-12-19 11:31:45 +0100571 private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
572 private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
573 private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(MplsLabel.mplsLabel(2));
Ray Milkey0d338052014-11-21 16:40:12 -0800574
575 /**
576 * Test the modMplsLabel method.
577 */
578 @Test
579 public void testModMplsMethod() {
HIGUCHI Yuta04b49fc2015-08-28 09:58:58 -0700580 final MplsLabel mplsLabel = MplsLabel.mplsLabel(33);
581 final Instruction instruction = Instructions.modMplsLabel(mplsLabel);
Ray Milkey0d338052014-11-21 16:40:12 -0800582 final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction =
583 checkAndConvert(instruction,
584 Instruction.Type.L2MODIFICATION,
585 L2ModificationInstruction.ModMplsLabelInstruction.class);
HIGUCHI Yuta04b49fc2015-08-28 09:58:58 -0700586 assertThat(modMplsLabelInstruction.mplsLabel(), is(equalTo(mplsLabel)));
Ray Milkey0d338052014-11-21 16:40:12 -0800587 assertThat(modMplsLabelInstruction.subtype(),
588 is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL)));
589 }
590
591 /**
592 * Test the equals(), hashCode and toString() methods of the
593 * ModMplsLabelInstruction class.
594 */
Ray Milkey0d338052014-11-21 16:40:12 -0800595 @Test
596 public void testModMplsLabelInstructionEquals() throws Exception {
597 checkEqualsAndToString(modMplsLabelInstruction1,
598 sameAsModMplsLabelInstruction1,
599 modMplsLabelInstruction2);
600 }
Ray Milkey78081052014-11-05 10:38:12 -0800601
Hyunsun Moond0533e52015-07-28 18:12:43 -0700602 // ModTunnelIdInstruction
603
604 private final long tunnelId1 = 1L;
605 private final long tunnelId2 = 2L;
606 private final Instruction modTunnelId1 = Instructions.modTunnelId(tunnelId1);
607 private final Instruction sameAsModTunnelId1 = Instructions.modTunnelId(tunnelId1);
608 private final Instruction modTunnelId2 = Instructions.modTunnelId(tunnelId2);
609
610 /**
611 * Test the modTunnelId method.
612 */
613 @Test
614 public void testModTunnelIdMethod() {
615 final Instruction instruction = Instructions.modTunnelId(tunnelId1);
616 final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction =
617 checkAndConvert(instruction, Instruction.Type.L2MODIFICATION,
618 L2ModificationInstruction.ModTunnelIdInstruction.class);
619 assertThat(modTunnelIdInstruction.tunnelId(), is(equalTo(tunnelId1)));
620 assertThat(modTunnelIdInstruction.subtype(),
621 is(equalTo(L2ModificationInstruction.L2SubType.TUNNEL_ID)));
622 }
623
624 /***
625 * Test the equals() method of the ModTunnelIdInstruction class.
626 */
627 @Test
628 public void testModTunnelIdInstructionEquals() throws Exception {
629 checkEqualsAndToString(modTunnelId1, sameAsModTunnelId1, modTunnelId2);
630 }
631
632 /**
633 * Test the hashCode() method of the ModTunnelIdInstruction class.
634 */
635 @Test
636 public void testModTunnelIdInstructionHashCode() {
637 assertThat(modTunnelId1.hashCode(), is(equalTo(sameAsModTunnelId1.hashCode())));
638 assertThat(modTunnelId1.hashCode(), is(not(equalTo(modTunnelId2.hashCode()))));
639 }
640
641 // ModTransportPortInstruction
642
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700643 private final TpPort tpPort1 = TpPort.tpPort(1);
644 private final TpPort tpPort2 = TpPort.tpPort(2);
645 private final Instruction modTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
646 private final Instruction sameAsModTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
647 private final Instruction modTransportPortInstruction2 = Instructions.modTcpSrc(tpPort2);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700648
649 /**
650 * Test the modTcpSrc() method.
651 */
652 @Test
653 public void testModTcpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700654 final Instruction instruction = Instructions.modTcpSrc(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700655 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
656 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
657 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700658 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700659 assertThat(modTransportPortInstruction.subtype(),
660 is(equalTo(L4ModificationInstruction.L4SubType.TCP_SRC)));
661 }
662
663 /**
664 * Test the modTcpDst() method.
665 */
666 @Test
667 public void testModTcpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700668 final Instruction instruction = Instructions.modTcpDst(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700669 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
670 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
671 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700672 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700673 assertThat(modTransportPortInstruction.subtype(),
674 is(equalTo(L4ModificationInstruction.L4SubType.TCP_DST)));
675 }
676
677 /**
678 * Test the modUdpSrc() method.
679 */
680 @Test
681 public void testModUdpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700682 final Instruction instruction = Instructions.modUdpSrc(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700683 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
684 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
685 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700686 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700687 assertThat(modTransportPortInstruction.subtype(),
688 is(equalTo(L4ModificationInstruction.L4SubType.UDP_SRC)));
689 }
690
691 /**
692 * Test the modUdpDst() method.
693 */
694 @Test
695 public void testModUdpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700696 final Instruction instruction = Instructions.modUdpDst(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700697 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
698 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
699 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700700 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700701 assertThat(modTransportPortInstruction.subtype(),
702 is(equalTo(L4ModificationInstruction.L4SubType.UDP_DST)));
703 }
704
705 /**
706 * Test the equals() method of the ModTransportPortInstruction class.
707 */
708 @Test
709 public void testModTransportPortInstructionEquals() throws Exception {
710 checkEqualsAndToString(modTransportPortInstruction1,
711 sameAsModTransportPortInstruction1,
712 modTransportPortInstruction2);
713 }
714
715 /**
716 * Test the hashCode() method of the ModTransportPortInstruction class.
717 */
718 @Test
719 public void testModTransportPortInstructionHashCode() {
720 assertThat(modTransportPortInstruction1.hashCode(),
721 is(equalTo(sameAsModTransportPortInstruction1.hashCode())));
722 assertThat(modTransportPortInstruction1.hashCode(),
723 is(not(equalTo(modTransportPortInstruction2.hashCode()))));
724 }
Ray Milkey78081052014-11-05 10:38:12 -0800725}