blob: a25783f9651bba90b218eb66ec93c33fd26232bd [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;
Yafit Hadar52d81552015-10-07 12:26:52 +030028import org.onosproject.net.OduSignalId;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.PortNumber;
Ray Milkey78081052014-11-05 10:38:12 -080030
Ray Milkey0d338052014-11-21 16:40:12 -080031import com.google.common.testing.EqualsTester;
32
Ray Milkey78081052014-11-05 10:38:12 -080033import static org.hamcrest.MatcherAssert.assertThat;
Ray Milkey78081052014-11-05 10:38:12 -080034import static org.hamcrest.Matchers.equalTo;
35import static org.hamcrest.Matchers.instanceOf;
36import static org.hamcrest.Matchers.is;
37import static org.hamcrest.Matchers.not;
38import static org.hamcrest.Matchers.notNullValue;
39import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
40import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
Brian O'Connorabafb502014-12-02 22:26:20 -080041import static org.onosproject.net.PortNumber.portNumber;
Yafit Hadar52d81552015-10-07 12:26:52 +030042import static org.onosproject.net.OduSignalId.oduSignalId;
Ray Milkey78081052014-11-05 10:38:12 -080043
44/**
45 * Unit tests for the Instructions class.
46 */
47public class InstructionsTest {
48
49 /**
50 * Checks that a Criterion object has the proper type, and then converts
51 * it to the proper type.
52 *
53 * @param instruction Instruction object to convert
54 * @param type Enumerated type value for the Criterion class
55 * @param clazz Desired Criterion class
56 * @param <T> The type the caller wants returned
57 * @return converted object
58 */
59 @SuppressWarnings("unchecked")
60 private <T> T checkAndConvert(Instruction instruction, Instruction.Type type, Class clazz) {
61 assertThat(instruction, is(notNullValue()));
62 assertThat(instruction.type(), is(equalTo(type)));
63 assertThat(instruction, instanceOf(clazz));
64 return (T) instruction;
65 }
66
67 /**
68 * Checks the equals() and toString() methods of a Criterion class.
69 *
70 * @param c1 first object to compare
71 * @param c1match object that should be equal to the first
72 * @param c2 object that should be not equal to the first
Ray Milkey78081052014-11-05 10:38:12 -080073 * @param <T> type of the arguments
74 */
75 private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match,
Ray Milkey0d338052014-11-21 16:40:12 -080076 T c2) {
Ray Milkey78081052014-11-05 10:38:12 -080077
Ray Milkey0d338052014-11-21 16:40:12 -080078 new EqualsTester()
79 .addEqualityGroup(c1, c1match)
80 .addEqualityGroup(c2)
81 .testEquals();
Ray Milkey78081052014-11-05 10:38:12 -080082 }
83
84 /**
85 * Checks that Instructions is a proper utility class.
86 */
87 @Test
88 public void testInstructionsUtilityClass() {
89 assertThatClassIsUtility(Instructions.class);
90 }
91
92 /**
93 * Checks that the Instruction class implementations are immutable.
94 */
95 @Test
96 public void testImmutabilityOfInstructions() {
97 assertThatClassIsImmutable(Instructions.DropInstruction.class);
98 assertThatClassIsImmutable(Instructions.OutputInstruction.class);
99 assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class);
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -0700100 assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class);
Yafit Hadar52d81552015-10-07 12:26:52 +0300101 assertThatClassIsImmutable(L1ModificationInstruction.ModOduSignalIdInstruction.class);
Ray Milkey78081052014-11-05 10:38:12 -0800102 assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class);
103 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class);
104 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class);
105 assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800106 assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800107 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class);
108 assertThatClassIsImmutable(L2ModificationInstruction.PushHeaderInstructions.class);
Ray Milkey78081052014-11-05 10:38:12 -0800109 }
110
111 // DropInstruction
112
113 private final Instructions.DropInstruction drop1 = Instructions.createDrop();
114 private final Instructions.DropInstruction drop2 = Instructions.createDrop();
115
116 /**
117 * Test the createDrop method.
118 */
119 @Test
120 public void testCreateDropMethod() {
121 Instructions.DropInstruction instruction = Instructions.createDrop();
122 checkAndConvert(instruction,
123 Instruction.Type.DROP,
124 Instructions.DropInstruction.class);
125 }
126
127 /**
128 * Test the equals() method of the DropInstruction class.
129 */
130
131 @Test
132 public void testDropInstructionEquals() throws Exception {
133 assertThat(drop1, is(equalTo(drop2)));
134 }
135
136 /**
137 * Test the hashCode() method of the DropInstruction class.
138 */
139
140 @Test
141 public void testDropInstructionHashCode() {
142 assertThat(drop1.hashCode(), is(equalTo(drop2.hashCode())));
143 }
144
145 // OutputInstruction
146
147 private final PortNumber port1 = portNumber(1);
148 private final PortNumber port2 = portNumber(2);
149 private final Instructions.OutputInstruction output1 = Instructions.createOutput(port1);
150 private final Instructions.OutputInstruction sameAsOutput1 = Instructions.createOutput(port1);
151 private final Instructions.OutputInstruction output2 = Instructions.createOutput(port2);
152
153 /**
154 * Test the createOutput method.
155 */
156 @Test
157 public void testCreateOutputMethod() {
158 final Instruction instruction = Instructions.createOutput(port2);
159 final Instructions.OutputInstruction outputInstruction =
160 checkAndConvert(instruction,
161 Instruction.Type.OUTPUT,
162 Instructions.OutputInstruction.class);
163 assertThat(outputInstruction.port(), is(equalTo(port2)));
164 }
165
166
167 /**
168 * Test the equals() method of the OutputInstruction class.
169 */
170
171 @Test
172 public void testOutputInstructionEquals() throws Exception {
Ray Milkey0d338052014-11-21 16:40:12 -0800173 checkEqualsAndToString(output1, sameAsOutput1, output2);
Ray Milkey78081052014-11-05 10:38:12 -0800174 }
175
176 /**
177 * Test the hashCode() method of the OutputInstruction class.
178 */
179
180 @Test
181 public void testOutputInstructionHashCode() {
182 assertThat(output1.hashCode(), is(equalTo(sameAsOutput1.hashCode())));
183 assertThat(output1.hashCode(), is(not(equalTo(output2.hashCode()))));
184 }
185
186 // ModLambdaInstruction
187
Ray Milkey85571eb2015-06-25 09:45:46 -0700188 private final IndexedLambda lambda1 = new IndexedLambda(1);
189 private final IndexedLambda lambda2 = new IndexedLambda(2);
Ray Milkey78081052014-11-05 10:38:12 -0800190 private final Instruction lambdaInstruction1 = Instructions.modL0Lambda(lambda1);
191 private final Instruction sameAsLambdaInstruction1 = Instructions.modL0Lambda(lambda1);
192 private final Instruction lambdaInstruction2 = Instructions.modL0Lambda(lambda2);
193
194 /**
195 * Test the modL0Lambda method.
196 */
197 @Test
198 public void testCreateLambdaMethod() {
199 final Instruction instruction = Instructions.modL0Lambda(lambda1);
200 final L0ModificationInstruction.ModLambdaInstruction lambdaInstruction =
201 checkAndConvert(instruction,
202 Instruction.Type.L0MODIFICATION,
203 L0ModificationInstruction.ModLambdaInstruction.class);
Ray Milkey85571eb2015-06-25 09:45:46 -0700204 assertThat(lambdaInstruction.lambda(), is(equalTo((short) lambda1.index())));
Ray Milkey78081052014-11-05 10:38:12 -0800205 }
206
Ray Milkey78081052014-11-05 10:38:12 -0800207 /**
208 * Test the equals() method of the ModLambdaInstruction class.
209 */
210
211 @Test
212 public void testModLambdaInstructionEquals() throws Exception {
213 checkEqualsAndToString(lambdaInstruction1,
214 sameAsLambdaInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800215 lambdaInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800216 }
217
218 /**
219 * Test the hashCode() method of the ModLambdaInstruction class.
220 */
221
222 @Test
223 public void testModLambdaInstructionHashCode() {
224 assertThat(lambdaInstruction1.hashCode(),
225 is(equalTo(sameAsLambdaInstruction1.hashCode())));
226 assertThat(lambdaInstruction1.hashCode(),
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -0700227 is(not(equalTo(lambdaInstruction2.hashCode()))));
228 }
229
230 private final Lambda och1 = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
231 private final Lambda och2 = Lambda.ochSignal(GridType.CWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
232 private final Instruction ochInstruction1 = Instructions.modL0Lambda(och1);
233 private final Instruction sameAsOchInstruction1 = Instructions.modL0Lambda(och1);
234 private final Instruction ochInstruction2 = Instructions.modL0Lambda(och2);
235
236 /**
237 * Test the modL0Lambda().
238 */
239 @Test
240 public void testModL0LambdaMethod() {
241 Instruction instruction = Instructions.modL0Lambda(och1);
242 L0ModificationInstruction.ModOchSignalInstruction ochInstruction =
243 checkAndConvert(instruction, Instruction.Type.L0MODIFICATION,
244 L0ModificationInstruction.ModOchSignalInstruction.class);
245 assertThat(ochInstruction.lambda(), is(och1));
246 }
247
248 /**
249 * Test the equals() method of the ModOchSignalInstruction class.
250 */
251 @Test
252 public void testModOchSignalInstructionEquals() {
253 checkEqualsAndToString(ochInstruction1, sameAsOchInstruction1, ochInstruction2);
254 }
255
256 /**
257 * Test the hashCode() method of the ModOchSignalInstruction class.
258 */
259 @Test
260 public void testModOchSignalInstructionHashCode() {
261 assertThat(ochInstruction1.hashCode(), is(sameAsOchInstruction1.hashCode()));
262 assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode())));
Ray Milkey78081052014-11-05 10:38:12 -0800263 }
264
Yafit Hadar52d81552015-10-07 12:26:52 +0300265 // ModOduSignalIdInstruction
266
267 private final OduSignalId odu1 = oduSignalId(1, 80, new byte[] {8, 7, 6, 5, 7, 6, 5, 7, 6, 5});
268 private final OduSignalId odu2 = oduSignalId(2, 80, new byte[] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2});
269 private final Instruction oduInstruction1 = Instructions.modL1OduSignalId(odu1);
270 private final Instruction sameAsOduInstruction1 = Instructions.modL1OduSignalId(odu1);
271 private final Instruction oduInstruction2 = Instructions.modL1OduSignalId(odu2);
272
273 /**
274 * Test the modL1OduSignalId().
275 */
276 @Test
277 public void testModL1OduSignalIdMethod() {
278 Instruction instruction = Instructions.modL1OduSignalId(odu1);
279 L1ModificationInstruction.ModOduSignalIdInstruction oduInstruction =
280 checkAndConvert(instruction, Instruction.Type.L1MODIFICATION,
281 L1ModificationInstruction.ModOduSignalIdInstruction.class);
282 assertThat(oduInstruction.oduSignalId(), is(odu1));
283 }
284
285 /**
286 * Test the equals() method of the ModOduSignalInstruction class.
287 */
288 @Test
289 public void testModOduSignalIdInstructionEquals() {
290 checkEqualsAndToString(oduInstruction1, sameAsOduInstruction1, oduInstruction2);
291 }
292
293 /**
294 * Test the hashCode() method of the ModOduSignalInstruction class.
295 */
296 @Test
297 public void testModOduSignalIdInstructionHashCode() {
298 assertThat(oduInstruction1.hashCode(), is(sameAsOduInstruction1.hashCode()));
299 assertThat(oduInstruction1.hashCode(), is(not(oduInstruction2.hashCode())));
300 }
301
302
Ray Milkey78081052014-11-05 10:38:12 -0800303 // ModEtherInstruction
304
305 private static final String MAC1 = "00:00:00:00:00:01";
306 private static final String MAC2 = "00:00:00:00:00:02";
307 private final MacAddress mac1 = MacAddress.valueOf(MAC1);
308 private final MacAddress mac2 = MacAddress.valueOf(MAC2);
309 private final Instruction modEtherInstruction1 = Instructions.modL2Src(mac1);
310 private final Instruction sameAsModEtherInstruction1 = Instructions.modL2Src(mac1);
311 private final Instruction modEtherInstruction2 = Instructions.modL2Src(mac2);
312
313 /**
314 * Test the modL2Src method.
315 */
316 @Test
317 public void testModL2SrcMethod() {
318 final Instruction instruction = Instructions.modL2Src(mac1);
319 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
320 checkAndConvert(instruction,
321 Instruction.Type.L2MODIFICATION,
322 L2ModificationInstruction.ModEtherInstruction.class);
323 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
324 assertThat(modEtherInstruction.subtype(),
325 is(equalTo(L2ModificationInstruction.L2SubType.ETH_SRC)));
326 }
327
328 /**
329 * Test the modL2Dst method.
330 */
331 @Test
332 public void testModL2DstMethod() {
333 final Instruction instruction = Instructions.modL2Dst(mac1);
334 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
335 checkAndConvert(instruction,
336 Instruction.Type.L2MODIFICATION,
337 L2ModificationInstruction.ModEtherInstruction.class);
338 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
339 assertThat(modEtherInstruction.subtype(),
340 is(equalTo(L2ModificationInstruction.L2SubType.ETH_DST)));
341 }
342
343 /**
344 * Test the equals() method of the ModEtherInstruction class.
345 */
346
347 @Test
348 public void testModEtherInstructionEquals() throws Exception {
349 checkEqualsAndToString(modEtherInstruction1,
350 sameAsModEtherInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800351 modEtherInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800352 }
353
354 /**
355 * Test the hashCode() method of the ModEtherInstruction class.
356 */
357
358 @Test
359 public void testModEtherInstructionHashCode() {
360 assertThat(modEtherInstruction1.hashCode(),
361 is(equalTo(sameAsModEtherInstruction1.hashCode())));
362 assertThat(modEtherInstruction1.hashCode(),
363 is(not(equalTo(modEtherInstruction2.hashCode()))));
364 }
365
366
367 // ModVlanIdInstruction
368
369 private final short vlan1 = 1;
370 private final short vlan2 = 2;
371 private final VlanId vlanId1 = VlanId.vlanId(vlan1);
372 private final VlanId vlanId2 = VlanId.vlanId(vlan2);
373 private final Instruction modVlanId1 = Instructions.modVlanId(vlanId1);
374 private final Instruction sameAsModVlanId1 = Instructions.modVlanId(vlanId1);
375 private final Instruction modVlanId2 = Instructions.modVlanId(vlanId2);
376
377 /**
378 * Test the modVlanId method.
379 */
380 @Test
381 public void testModVlanIdMethod() {
382 final Instruction instruction = Instructions.modVlanId(vlanId1);
383 final L2ModificationInstruction.ModVlanIdInstruction modEtherInstruction =
384 checkAndConvert(instruction,
385 Instruction.Type.L2MODIFICATION,
386 L2ModificationInstruction.ModVlanIdInstruction.class);
387 assertThat(modEtherInstruction.vlanId(), is(equalTo(vlanId1)));
388 assertThat(modEtherInstruction.subtype(),
389 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_ID)));
390 }
391
392 /**
393 * Test the equals() method of the ModVlanIdInstruction class.
394 */
395
396 @Test
397 public void testModVlanIdInstructionEquals() throws Exception {
398 checkEqualsAndToString(modVlanId1,
399 sameAsModVlanId1,
Ray Milkey0d338052014-11-21 16:40:12 -0800400 modVlanId2);
Ray Milkey78081052014-11-05 10:38:12 -0800401 }
402
403 /**
404 * Test the hashCode() method of the ModEtherInstruction class.
405 */
406
407 @Test
408 public void testModVlanIdInstructionHashCode() {
409 assertThat(modVlanId1.hashCode(),
410 is(equalTo(sameAsModVlanId1.hashCode())));
411 assertThat(modVlanId1.hashCode(),
412 is(not(equalTo(modVlanId2.hashCode()))));
413 }
414
415
416 // ModVlanPcpInstruction
417
418 private final byte vlanPcp1 = 1;
419 private final byte vlanPcp2 = 2;
420 private final Instruction modVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
421 private final Instruction sameAsModVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
422 private final Instruction modVlanPcp2 = Instructions.modVlanPcp(vlanPcp2);
423
424 /**
425 * Test the modVlanPcp method.
426 */
427 @Test
428 public void testModVlanPcpMethod() {
429 final Instruction instruction = Instructions.modVlanPcp(vlanPcp1);
430 final L2ModificationInstruction.ModVlanPcpInstruction modEtherInstruction =
431 checkAndConvert(instruction,
432 Instruction.Type.L2MODIFICATION,
433 L2ModificationInstruction.ModVlanPcpInstruction.class);
434 assertThat(modEtherInstruction.vlanPcp(), is(equalTo(vlanPcp1)));
435 assertThat(modEtherInstruction.subtype(),
436 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_PCP)));
437 }
438
439 /**
440 * Test the equals() method of the ModVlanPcpInstruction class.
441 */
442
443 @Test
444 public void testModVlanPcpInstructionEquals() throws Exception {
445 checkEqualsAndToString(modVlanPcp1,
446 sameAsModVlanPcp1,
Ray Milkey0d338052014-11-21 16:40:12 -0800447 modVlanPcp2);
Ray Milkey78081052014-11-05 10:38:12 -0800448 }
449
450 /**
451 * Test the hashCode() method of the ModEtherInstruction class.
452 */
453
454 @Test
455 public void testModVlanPcpInstructionHashCode() {
456 assertThat(modVlanPcp1.hashCode(),
457 is(equalTo(sameAsModVlanPcp1.hashCode())));
458 assertThat(modVlanPcp1.hashCode(),
459 is(not(equalTo(modVlanPcp2.hashCode()))));
460 }
461
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800462 // ModIPInstruction
Ray Milkey78081052014-11-05 10:38:12 -0800463
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800464 private static final String IP41 = "1.2.3.4";
465 private static final String IP42 = "5.6.7.8";
466 private IpAddress ip41 = IpAddress.valueOf(IP41);
467 private IpAddress ip42 = IpAddress.valueOf(IP42);
468 private final Instruction modIPInstruction1 = Instructions.modL3Src(ip41);
469 private final Instruction sameAsModIPInstruction1 = Instructions.modL3Src(ip41);
470 private final Instruction modIPInstruction2 = Instructions.modL3Src(ip42);
471
472 private static final String IP61 = "1111::2222";
473 private static final String IP62 = "3333::4444";
474 private IpAddress ip61 = IpAddress.valueOf(IP61);
475 private IpAddress ip62 = IpAddress.valueOf(IP62);
476 private final Instruction modIPv6Instruction1 =
477 Instructions.modL3IPv6Src(ip61);
478 private final Instruction sameAsModIPv6Instruction1 =
479 Instructions.modL3IPv6Src(ip61);
480 private final Instruction modIPv6Instruction2 =
481 Instructions.modL3IPv6Src(ip62);
Ray Milkey78081052014-11-05 10:38:12 -0800482
483 /**
484 * Test the modL3Src method.
485 */
486 @Test
487 public void testModL3SrcMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800488 final Instruction instruction = Instructions.modL3Src(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800489 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
490 checkAndConvert(instruction,
491 Instruction.Type.L3MODIFICATION,
492 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800493 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800494 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800495 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_SRC)));
Ray Milkey78081052014-11-05 10:38:12 -0800496 }
497
498 /**
499 * Test the modL3Dst method.
500 */
501 @Test
502 public void testModL3DstMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800503 final Instruction instruction = Instructions.modL3Dst(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800504 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
505 checkAndConvert(instruction,
506 Instruction.Type.L3MODIFICATION,
507 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800508 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800509 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800510 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_DST)));
Ray Milkey78081052014-11-05 10:38:12 -0800511 }
512
513 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800514 * Test the modL3IPv6Src method.
Ray Milkey78081052014-11-05 10:38:12 -0800515 */
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800516 @Test
517 public void testModL3IPv6SrcMethod() {
518 final Instruction instruction = Instructions.modL3IPv6Src(ip61);
519 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
520 checkAndConvert(instruction,
521 Instruction.Type.L3MODIFICATION,
522 L3ModificationInstruction.ModIPInstruction.class);
523 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
524 assertThat(modIPInstruction.subtype(),
525 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_SRC)));
526 }
Ray Milkey78081052014-11-05 10:38:12 -0800527
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800528 /**
529 * Test the modL3IPv6Dst method.
530 */
531 @Test
532 public void testModL3IPv6DstMethod() {
533 final Instruction instruction = Instructions.modL3IPv6Dst(ip61);
534 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
535 checkAndConvert(instruction,
536 Instruction.Type.L3MODIFICATION,
537 L3ModificationInstruction.ModIPInstruction.class);
538 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
539 assertThat(modIPInstruction.subtype(),
540 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_DST)));
541 }
542
543 /**
544 * Test the equals() method of the ModIPInstruction class.
545 */
Ray Milkey78081052014-11-05 10:38:12 -0800546 @Test
547 public void testModIPInstructionEquals() throws Exception {
548 checkEqualsAndToString(modIPInstruction1,
549 sameAsModIPInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800550 modIPInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800551 }
552
553 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800554 * Test the hashCode() method of the ModIPInstruction class.
Ray Milkey78081052014-11-05 10:38:12 -0800555 */
Ray Milkey78081052014-11-05 10:38:12 -0800556 @Test
557 public void testModIPInstructionHashCode() {
558 assertThat(modIPInstruction1.hashCode(),
559 is(equalTo(sameAsModIPInstruction1.hashCode())));
560 assertThat(modIPInstruction1.hashCode(),
561 is(not(equalTo(modIPInstruction2.hashCode()))));
562 }
563
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800564 private final int flowLabel1 = 0x11111;
565 private final int flowLabel2 = 0x22222;
566 private final Instruction modIPv6FlowLabelInstruction1 =
567 Instructions.modL3IPv6FlowLabel(flowLabel1);
568 private final Instruction sameAsModIPv6FlowLabelInstruction1 =
569 Instructions.modL3IPv6FlowLabel(flowLabel1);
570 private final Instruction modIPv6FlowLabelInstruction2 =
571 Instructions.modL3IPv6FlowLabel(flowLabel2);
572
573 /**
574 * Test the modL3IPv6FlowLabel method.
575 */
576 @Test
577 public void testModL3IPv6FlowLabelMethod() {
578 final Instruction instruction =
579 Instructions.modL3IPv6FlowLabel(flowLabel1);
580 final L3ModificationInstruction.ModIPv6FlowLabelInstruction
581 modIPv6FlowLabelInstruction =
582 checkAndConvert(instruction,
583 Instruction.Type.L3MODIFICATION,
584 L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
585 assertThat(modIPv6FlowLabelInstruction.flowLabel(),
586 is(equalTo(flowLabel1)));
587 assertThat(modIPv6FlowLabelInstruction.subtype(),
588 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_FLABEL)));
589 }
590
591 /**
592 * Test the equals() method of the ModIPv6FlowLabelInstruction class.
593 */
594 @Test
595 public void testModIPv6FlowLabelInstructionEquals() throws Exception {
596 checkEqualsAndToString(modIPv6FlowLabelInstruction1,
597 sameAsModIPv6FlowLabelInstruction1,
598 modIPv6FlowLabelInstruction2);
599 }
600
601 /**
602 * Test the hashCode() method of the ModIPv6FlowLabelInstruction class.
603 */
604 @Test
605 public void testModIPv6FlowLabelInstructionHashCode() {
606 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
607 is(equalTo(sameAsModIPv6FlowLabelInstruction1.hashCode())));
608 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
609 is(not(equalTo(modIPv6FlowLabelInstruction2.hashCode()))));
610 }
611
Michele Santuari4b6019e2014-12-19 11:31:45 +0100612 private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
613 private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
614 private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(MplsLabel.mplsLabel(2));
Ray Milkey0d338052014-11-21 16:40:12 -0800615
616 /**
617 * Test the modMplsLabel method.
618 */
619 @Test
620 public void testModMplsMethod() {
HIGUCHI Yuta04b49fc2015-08-28 09:58:58 -0700621 final MplsLabel mplsLabel = MplsLabel.mplsLabel(33);
622 final Instruction instruction = Instructions.modMplsLabel(mplsLabel);
Ray Milkey0d338052014-11-21 16:40:12 -0800623 final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction =
624 checkAndConvert(instruction,
625 Instruction.Type.L2MODIFICATION,
626 L2ModificationInstruction.ModMplsLabelInstruction.class);
HIGUCHI Yuta04b49fc2015-08-28 09:58:58 -0700627 assertThat(modMplsLabelInstruction.mplsLabel(), is(equalTo(mplsLabel)));
Ray Milkey0d338052014-11-21 16:40:12 -0800628 assertThat(modMplsLabelInstruction.subtype(),
629 is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL)));
630 }
631
632 /**
633 * Test the equals(), hashCode and toString() methods of the
634 * ModMplsLabelInstruction class.
635 */
Ray Milkey0d338052014-11-21 16:40:12 -0800636 @Test
637 public void testModMplsLabelInstructionEquals() throws Exception {
638 checkEqualsAndToString(modMplsLabelInstruction1,
639 sameAsModMplsLabelInstruction1,
640 modMplsLabelInstruction2);
641 }
Ray Milkey78081052014-11-05 10:38:12 -0800642
Hyunsun Moond0533e52015-07-28 18:12:43 -0700643 // ModTunnelIdInstruction
644
645 private final long tunnelId1 = 1L;
646 private final long tunnelId2 = 2L;
647 private final Instruction modTunnelId1 = Instructions.modTunnelId(tunnelId1);
648 private final Instruction sameAsModTunnelId1 = Instructions.modTunnelId(tunnelId1);
649 private final Instruction modTunnelId2 = Instructions.modTunnelId(tunnelId2);
650
651 /**
652 * Test the modTunnelId method.
653 */
654 @Test
655 public void testModTunnelIdMethod() {
656 final Instruction instruction = Instructions.modTunnelId(tunnelId1);
657 final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction =
658 checkAndConvert(instruction, Instruction.Type.L2MODIFICATION,
659 L2ModificationInstruction.ModTunnelIdInstruction.class);
660 assertThat(modTunnelIdInstruction.tunnelId(), is(equalTo(tunnelId1)));
661 assertThat(modTunnelIdInstruction.subtype(),
662 is(equalTo(L2ModificationInstruction.L2SubType.TUNNEL_ID)));
663 }
664
665 /***
666 * Test the equals() method of the ModTunnelIdInstruction class.
667 */
668 @Test
669 public void testModTunnelIdInstructionEquals() throws Exception {
670 checkEqualsAndToString(modTunnelId1, sameAsModTunnelId1, modTunnelId2);
671 }
672
673 /**
674 * Test the hashCode() method of the ModTunnelIdInstruction class.
675 */
676 @Test
677 public void testModTunnelIdInstructionHashCode() {
678 assertThat(modTunnelId1.hashCode(), is(equalTo(sameAsModTunnelId1.hashCode())));
679 assertThat(modTunnelId1.hashCode(), is(not(equalTo(modTunnelId2.hashCode()))));
680 }
681
682 // ModTransportPortInstruction
683
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700684 private final TpPort tpPort1 = TpPort.tpPort(1);
685 private final TpPort tpPort2 = TpPort.tpPort(2);
686 private final Instruction modTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
687 private final Instruction sameAsModTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
688 private final Instruction modTransportPortInstruction2 = Instructions.modTcpSrc(tpPort2);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700689
690 /**
691 * Test the modTcpSrc() method.
692 */
693 @Test
694 public void testModTcpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700695 final Instruction instruction = Instructions.modTcpSrc(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700696 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
697 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
698 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700699 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700700 assertThat(modTransportPortInstruction.subtype(),
701 is(equalTo(L4ModificationInstruction.L4SubType.TCP_SRC)));
702 }
703
704 /**
705 * Test the modTcpDst() method.
706 */
707 @Test
708 public void testModTcpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700709 final Instruction instruction = Instructions.modTcpDst(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700710 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
711 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
712 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700713 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700714 assertThat(modTransportPortInstruction.subtype(),
715 is(equalTo(L4ModificationInstruction.L4SubType.TCP_DST)));
716 }
717
718 /**
719 * Test the modUdpSrc() method.
720 */
721 @Test
722 public void testModUdpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700723 final Instruction instruction = Instructions.modUdpSrc(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700724 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
725 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
726 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700727 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700728 assertThat(modTransportPortInstruction.subtype(),
729 is(equalTo(L4ModificationInstruction.L4SubType.UDP_SRC)));
730 }
731
732 /**
733 * Test the modUdpDst() method.
734 */
735 @Test
736 public void testModUdpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700737 final Instruction instruction = Instructions.modUdpDst(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700738 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
739 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
740 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700741 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700742 assertThat(modTransportPortInstruction.subtype(),
743 is(equalTo(L4ModificationInstruction.L4SubType.UDP_DST)));
744 }
745
746 /**
747 * Test the equals() method of the ModTransportPortInstruction class.
748 */
749 @Test
750 public void testModTransportPortInstructionEquals() throws Exception {
751 checkEqualsAndToString(modTransportPortInstruction1,
752 sameAsModTransportPortInstruction1,
753 modTransportPortInstruction2);
754 }
755
756 /**
757 * Test the hashCode() method of the ModTransportPortInstruction class.
758 */
759 @Test
760 public void testModTransportPortInstructionHashCode() {
761 assertThat(modTransportPortInstruction1.hashCode(),
762 is(equalTo(sameAsModTransportPortInstruction1.hashCode())));
763 assertThat(modTransportPortInstruction1.hashCode(),
764 is(not(equalTo(modTransportPortInstruction2.hashCode()))));
765 }
Ray Milkey78081052014-11-05 10:38:12 -0800766}