blob: 591a73b83da0fe83c975119e483a329884bf2f93 [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
Ray Milkey3564a8c2015-12-14 11:43:12 -080018import java.util.List;
19
Ray Milkey78081052014-11-05 10:38:12 -080020import org.junit.Test;
Ray Milkey3564a8c2015-12-14 11:43:12 -080021import org.onlab.packet.EthType;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070022import org.onlab.packet.IpAddress;
23import org.onlab.packet.MacAddress;
24import org.onlab.packet.MplsLabel;
25import org.onlab.packet.TpPort;
26import org.onlab.packet.VlanId;
Ray Milkey3564a8c2015-12-14 11:43:12 -080027import org.onosproject.core.DefaultGroupId;
28import org.onosproject.core.GroupId;
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -070029import org.onosproject.net.ChannelSpacing;
Ray Milkey3564a8c2015-12-14 11:43:12 -080030import org.onosproject.net.DeviceId;
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -070031import org.onosproject.net.GridType;
Ray Milkey85571eb2015-06-25 09:45:46 -070032import org.onosproject.net.IndexedLambda;
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -070033import org.onosproject.net.Lambda;
Yafit Hadar52d81552015-10-07 12:26:52 +030034import org.onosproject.net.OduSignalId;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.PortNumber;
Ray Milkey3564a8c2015-12-14 11:43:12 -080036import org.onosproject.net.meter.MeterId;
Ray Milkey78081052014-11-05 10:38:12 -080037
Ray Milkey0d338052014-11-21 16:40:12 -080038import com.google.common.testing.EqualsTester;
39
Ray Milkey78081052014-11-05 10:38:12 -080040import static org.hamcrest.MatcherAssert.assertThat;
Ray Milkey78081052014-11-05 10:38:12 -080041import static org.hamcrest.Matchers.equalTo;
42import static org.hamcrest.Matchers.instanceOf;
43import static org.hamcrest.Matchers.is;
44import static org.hamcrest.Matchers.not;
45import static org.hamcrest.Matchers.notNullValue;
46import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
47import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
Yafit Hadar52d81552015-10-07 12:26:52 +030048import static org.onosproject.net.OduSignalId.oduSignalId;
Ray Milkey3564a8c2015-12-14 11:43:12 -080049import static org.onosproject.net.PortNumber.portNumber;
Ray Milkey78081052014-11-05 10:38:12 -080050
51/**
52 * Unit tests for the Instructions class.
53 */
54public class InstructionsTest {
55
56 /**
Ray Milkey3564a8c2015-12-14 11:43:12 -080057 * Checks that an Instruction object has the proper type, and then converts
Ray Milkey78081052014-11-05 10:38:12 -080058 * it to the proper type.
59 *
60 * @param instruction Instruction object to convert
61 * @param type Enumerated type value for the Criterion class
62 * @param clazz Desired Criterion class
63 * @param <T> The type the caller wants returned
64 * @return converted object
65 */
66 @SuppressWarnings("unchecked")
67 private <T> T checkAndConvert(Instruction instruction, Instruction.Type type, Class clazz) {
68 assertThat(instruction, is(notNullValue()));
69 assertThat(instruction.type(), is(equalTo(type)));
70 assertThat(instruction, instanceOf(clazz));
71 return (T) instruction;
72 }
73
74 /**
Ray Milkey3564a8c2015-12-14 11:43:12 -080075 * Checks the equals() and toString() methods of a Instruction class.
Ray Milkey78081052014-11-05 10:38:12 -080076 *
77 * @param c1 first object to compare
78 * @param c1match object that should be equal to the first
79 * @param c2 object that should be not equal to the first
Ray Milkey78081052014-11-05 10:38:12 -080080 * @param <T> type of the arguments
81 */
82 private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match,
Ray Milkey0d338052014-11-21 16:40:12 -080083 T c2) {
Ray Milkey78081052014-11-05 10:38:12 -080084
Ray Milkey0d338052014-11-21 16:40:12 -080085 new EqualsTester()
86 .addEqualityGroup(c1, c1match)
87 .addEqualityGroup(c2)
88 .testEquals();
Ray Milkey78081052014-11-05 10:38:12 -080089 }
90
91 /**
92 * Checks that Instructions is a proper utility class.
93 */
94 @Test
95 public void testInstructionsUtilityClass() {
96 assertThatClassIsUtility(Instructions.class);
97 }
98
99 /**
100 * Checks that the Instruction class implementations are immutable.
101 */
102 @Test
103 public void testImmutabilityOfInstructions() {
Ray Milkey78081052014-11-05 10:38:12 -0800104 assertThatClassIsImmutable(Instructions.OutputInstruction.class);
105 assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class);
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -0700106 assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class);
Yafit Hadar52d81552015-10-07 12:26:52 +0300107 assertThatClassIsImmutable(L1ModificationInstruction.ModOduSignalIdInstruction.class);
Ray Milkey78081052014-11-05 10:38:12 -0800108 assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class);
109 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class);
110 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class);
Ray Milkey3564a8c2015-12-14 11:43:12 -0800111 assertThatClassIsImmutable(L2ModificationInstruction.PopVlanInstruction.class);
Ray Milkey78081052014-11-05 10:38:12 -0800112 assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800113 assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800114 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class);
115 assertThatClassIsImmutable(L2ModificationInstruction.PushHeaderInstructions.class);
Ray Milkey3564a8c2015-12-14 11:43:12 -0800116 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsBosInstruction.class);
117 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsTtlInstruction.class);
118 assertThatClassIsImmutable(L2ModificationInstruction.ModTunnelIdInstruction.class);
119 }
120
121 // NoActionInstruction
122
123 private final Instructions.NoActionInstruction noAction1 = Instructions.createNoAction();
124 private final Instructions.NoActionInstruction noAction2 = Instructions.createNoAction();
125
126 /**
127 * Test the createNoAction method.
128 */
129 @Test
130 public void testCreateNoActionMethod() {
131 Instructions.NoActionInstruction instruction = Instructions.createNoAction();
132 checkAndConvert(instruction,
133 Instruction.Type.NOACTION,
134 Instructions.NoActionInstruction.class);
135 }
136
137 /**
138 * Test the equals() method of the NoActionInstruction class.
139 */
140
141 @Test
142 public void testNoActionInstructionEquals() throws Exception {
143 new EqualsTester()
144 .addEqualityGroup(noAction1, noAction2)
145 .testEquals();
146 }
147
148 /**
149 * Test the hashCode() method of the NoActionInstruction class.
150 */
151
152 @Test
153 public void testNoActionInstructionHashCode() {
154 assertThat(noAction1.hashCode(), is(equalTo(noAction2.hashCode())));
Ray Milkey78081052014-11-05 10:38:12 -0800155 }
156
Ray Milkey78081052014-11-05 10:38:12 -0800157 // OutputInstruction
158
159 private final PortNumber port1 = portNumber(1);
160 private final PortNumber port2 = portNumber(2);
161 private final Instructions.OutputInstruction output1 = Instructions.createOutput(port1);
162 private final Instructions.OutputInstruction sameAsOutput1 = Instructions.createOutput(port1);
163 private final Instructions.OutputInstruction output2 = Instructions.createOutput(port2);
164
165 /**
166 * Test the createOutput method.
167 */
168 @Test
169 public void testCreateOutputMethod() {
170 final Instruction instruction = Instructions.createOutput(port2);
171 final Instructions.OutputInstruction outputInstruction =
172 checkAndConvert(instruction,
173 Instruction.Type.OUTPUT,
174 Instructions.OutputInstruction.class);
175 assertThat(outputInstruction.port(), is(equalTo(port2)));
176 }
177
178
179 /**
180 * Test the equals() method of the OutputInstruction class.
181 */
182
183 @Test
184 public void testOutputInstructionEquals() throws Exception {
Ray Milkey0d338052014-11-21 16:40:12 -0800185 checkEqualsAndToString(output1, sameAsOutput1, output2);
Ray Milkey78081052014-11-05 10:38:12 -0800186 }
187
188 /**
189 * Test the hashCode() method of the OutputInstruction class.
190 */
191
192 @Test
193 public void testOutputInstructionHashCode() {
194 assertThat(output1.hashCode(), is(equalTo(sameAsOutput1.hashCode())));
195 assertThat(output1.hashCode(), is(not(equalTo(output2.hashCode()))));
196 }
197
198 // ModLambdaInstruction
199
Ray Milkey85571eb2015-06-25 09:45:46 -0700200 private final IndexedLambda lambda1 = new IndexedLambda(1);
201 private final IndexedLambda lambda2 = new IndexedLambda(2);
Ray Milkey78081052014-11-05 10:38:12 -0800202 private final Instruction lambdaInstruction1 = Instructions.modL0Lambda(lambda1);
203 private final Instruction sameAsLambdaInstruction1 = Instructions.modL0Lambda(lambda1);
204 private final Instruction lambdaInstruction2 = Instructions.modL0Lambda(lambda2);
205
206 /**
207 * Test the modL0Lambda method.
208 */
209 @Test
210 public void testCreateLambdaMethod() {
211 final Instruction instruction = Instructions.modL0Lambda(lambda1);
212 final L0ModificationInstruction.ModLambdaInstruction lambdaInstruction =
213 checkAndConvert(instruction,
214 Instruction.Type.L0MODIFICATION,
215 L0ModificationInstruction.ModLambdaInstruction.class);
Ray Milkey85571eb2015-06-25 09:45:46 -0700216 assertThat(lambdaInstruction.lambda(), is(equalTo((short) lambda1.index())));
Ray Milkey78081052014-11-05 10:38:12 -0800217 }
218
Ray Milkey78081052014-11-05 10:38:12 -0800219 /**
220 * Test the equals() method of the ModLambdaInstruction class.
221 */
222
223 @Test
224 public void testModLambdaInstructionEquals() throws Exception {
225 checkEqualsAndToString(lambdaInstruction1,
226 sameAsLambdaInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800227 lambdaInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800228 }
229
230 /**
231 * Test the hashCode() method of the ModLambdaInstruction class.
232 */
233
234 @Test
235 public void testModLambdaInstructionHashCode() {
236 assertThat(lambdaInstruction1.hashCode(),
237 is(equalTo(sameAsLambdaInstruction1.hashCode())));
238 assertThat(lambdaInstruction1.hashCode(),
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -0700239 is(not(equalTo(lambdaInstruction2.hashCode()))));
240 }
241
242 private final Lambda och1 = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
243 private final Lambda och2 = Lambda.ochSignal(GridType.CWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
244 private final Instruction ochInstruction1 = Instructions.modL0Lambda(och1);
245 private final Instruction sameAsOchInstruction1 = Instructions.modL0Lambda(och1);
246 private final Instruction ochInstruction2 = Instructions.modL0Lambda(och2);
247
248 /**
249 * Test the modL0Lambda().
250 */
251 @Test
252 public void testModL0LambdaMethod() {
253 Instruction instruction = Instructions.modL0Lambda(och1);
254 L0ModificationInstruction.ModOchSignalInstruction ochInstruction =
255 checkAndConvert(instruction, Instruction.Type.L0MODIFICATION,
256 L0ModificationInstruction.ModOchSignalInstruction.class);
257 assertThat(ochInstruction.lambda(), is(och1));
258 }
259
260 /**
261 * Test the equals() method of the ModOchSignalInstruction class.
262 */
263 @Test
264 public void testModOchSignalInstructionEquals() {
265 checkEqualsAndToString(ochInstruction1, sameAsOchInstruction1, ochInstruction2);
266 }
267
268 /**
269 * Test the hashCode() method of the ModOchSignalInstruction class.
270 */
271 @Test
272 public void testModOchSignalInstructionHashCode() {
273 assertThat(ochInstruction1.hashCode(), is(sameAsOchInstruction1.hashCode()));
274 assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode())));
Ray Milkey78081052014-11-05 10:38:12 -0800275 }
276
Yafit Hadar52d81552015-10-07 12:26:52 +0300277 // ModOduSignalIdInstruction
278
279 private final OduSignalId odu1 = oduSignalId(1, 80, new byte[] {8, 7, 6, 5, 7, 6, 5, 7, 6, 5});
280 private final OduSignalId odu2 = oduSignalId(2, 80, new byte[] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2});
281 private final Instruction oduInstruction1 = Instructions.modL1OduSignalId(odu1);
282 private final Instruction sameAsOduInstruction1 = Instructions.modL1OduSignalId(odu1);
283 private final Instruction oduInstruction2 = Instructions.modL1OduSignalId(odu2);
284
285 /**
286 * Test the modL1OduSignalId().
287 */
288 @Test
289 public void testModL1OduSignalIdMethod() {
290 Instruction instruction = Instructions.modL1OduSignalId(odu1);
291 L1ModificationInstruction.ModOduSignalIdInstruction oduInstruction =
292 checkAndConvert(instruction, Instruction.Type.L1MODIFICATION,
293 L1ModificationInstruction.ModOduSignalIdInstruction.class);
294 assertThat(oduInstruction.oduSignalId(), is(odu1));
295 }
296
297 /**
298 * Test the equals() method of the ModOduSignalInstruction class.
299 */
300 @Test
301 public void testModOduSignalIdInstructionEquals() {
302 checkEqualsAndToString(oduInstruction1, sameAsOduInstruction1, oduInstruction2);
303 }
304
305 /**
306 * Test the hashCode() method of the ModOduSignalInstruction class.
307 */
308 @Test
309 public void testModOduSignalIdInstructionHashCode() {
310 assertThat(oduInstruction1.hashCode(), is(sameAsOduInstruction1.hashCode()));
311 assertThat(oduInstruction1.hashCode(), is(not(oduInstruction2.hashCode())));
312 }
313
314
Ray Milkey78081052014-11-05 10:38:12 -0800315 // ModEtherInstruction
316
317 private static final String MAC1 = "00:00:00:00:00:01";
318 private static final String MAC2 = "00:00:00:00:00:02";
319 private final MacAddress mac1 = MacAddress.valueOf(MAC1);
320 private final MacAddress mac2 = MacAddress.valueOf(MAC2);
321 private final Instruction modEtherInstruction1 = Instructions.modL2Src(mac1);
322 private final Instruction sameAsModEtherInstruction1 = Instructions.modL2Src(mac1);
323 private final Instruction modEtherInstruction2 = Instructions.modL2Src(mac2);
324
325 /**
326 * Test the modL2Src method.
327 */
328 @Test
329 public void testModL2SrcMethod() {
330 final Instruction instruction = Instructions.modL2Src(mac1);
331 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
332 checkAndConvert(instruction,
333 Instruction.Type.L2MODIFICATION,
334 L2ModificationInstruction.ModEtherInstruction.class);
335 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
336 assertThat(modEtherInstruction.subtype(),
337 is(equalTo(L2ModificationInstruction.L2SubType.ETH_SRC)));
338 }
339
340 /**
341 * Test the modL2Dst method.
342 */
343 @Test
344 public void testModL2DstMethod() {
345 final Instruction instruction = Instructions.modL2Dst(mac1);
346 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
347 checkAndConvert(instruction,
348 Instruction.Type.L2MODIFICATION,
349 L2ModificationInstruction.ModEtherInstruction.class);
350 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
351 assertThat(modEtherInstruction.subtype(),
352 is(equalTo(L2ModificationInstruction.L2SubType.ETH_DST)));
353 }
354
355 /**
356 * Test the equals() method of the ModEtherInstruction class.
357 */
358
359 @Test
360 public void testModEtherInstructionEquals() throws Exception {
361 checkEqualsAndToString(modEtherInstruction1,
362 sameAsModEtherInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800363 modEtherInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800364 }
365
366 /**
367 * Test the hashCode() method of the ModEtherInstruction class.
368 */
369
370 @Test
371 public void testModEtherInstructionHashCode() {
372 assertThat(modEtherInstruction1.hashCode(),
373 is(equalTo(sameAsModEtherInstruction1.hashCode())));
374 assertThat(modEtherInstruction1.hashCode(),
375 is(not(equalTo(modEtherInstruction2.hashCode()))));
376 }
377
378
379 // ModVlanIdInstruction
380
381 private final short vlan1 = 1;
382 private final short vlan2 = 2;
383 private final VlanId vlanId1 = VlanId.vlanId(vlan1);
384 private final VlanId vlanId2 = VlanId.vlanId(vlan2);
385 private final Instruction modVlanId1 = Instructions.modVlanId(vlanId1);
386 private final Instruction sameAsModVlanId1 = Instructions.modVlanId(vlanId1);
387 private final Instruction modVlanId2 = Instructions.modVlanId(vlanId2);
388
389 /**
390 * Test the modVlanId method.
391 */
392 @Test
393 public void testModVlanIdMethod() {
394 final Instruction instruction = Instructions.modVlanId(vlanId1);
395 final L2ModificationInstruction.ModVlanIdInstruction modEtherInstruction =
396 checkAndConvert(instruction,
397 Instruction.Type.L2MODIFICATION,
398 L2ModificationInstruction.ModVlanIdInstruction.class);
399 assertThat(modEtherInstruction.vlanId(), is(equalTo(vlanId1)));
400 assertThat(modEtherInstruction.subtype(),
401 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_ID)));
402 }
403
404 /**
405 * Test the equals() method of the ModVlanIdInstruction class.
406 */
407
408 @Test
409 public void testModVlanIdInstructionEquals() throws Exception {
410 checkEqualsAndToString(modVlanId1,
411 sameAsModVlanId1,
Ray Milkey0d338052014-11-21 16:40:12 -0800412 modVlanId2);
Ray Milkey78081052014-11-05 10:38:12 -0800413 }
414
415 /**
416 * Test the hashCode() method of the ModEtherInstruction class.
417 */
418
419 @Test
420 public void testModVlanIdInstructionHashCode() {
421 assertThat(modVlanId1.hashCode(),
422 is(equalTo(sameAsModVlanId1.hashCode())));
423 assertThat(modVlanId1.hashCode(),
424 is(not(equalTo(modVlanId2.hashCode()))));
425 }
426
427
428 // ModVlanPcpInstruction
429
430 private final byte vlanPcp1 = 1;
431 private final byte vlanPcp2 = 2;
432 private final Instruction modVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
433 private final Instruction sameAsModVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
434 private final Instruction modVlanPcp2 = Instructions.modVlanPcp(vlanPcp2);
435
436 /**
437 * Test the modVlanPcp method.
438 */
439 @Test
440 public void testModVlanPcpMethod() {
441 final Instruction instruction = Instructions.modVlanPcp(vlanPcp1);
442 final L2ModificationInstruction.ModVlanPcpInstruction modEtherInstruction =
443 checkAndConvert(instruction,
444 Instruction.Type.L2MODIFICATION,
445 L2ModificationInstruction.ModVlanPcpInstruction.class);
446 assertThat(modEtherInstruction.vlanPcp(), is(equalTo(vlanPcp1)));
447 assertThat(modEtherInstruction.subtype(),
448 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_PCP)));
449 }
450
451 /**
452 * Test the equals() method of the ModVlanPcpInstruction class.
453 */
454
455 @Test
456 public void testModVlanPcpInstructionEquals() throws Exception {
457 checkEqualsAndToString(modVlanPcp1,
458 sameAsModVlanPcp1,
Ray Milkey0d338052014-11-21 16:40:12 -0800459 modVlanPcp2);
Ray Milkey78081052014-11-05 10:38:12 -0800460 }
461
462 /**
Ray Milkey3564a8c2015-12-14 11:43:12 -0800463 * Test the hashCode() method of the ModVlanPcp class.
Ray Milkey78081052014-11-05 10:38:12 -0800464 */
465
466 @Test
467 public void testModVlanPcpInstructionHashCode() {
468 assertThat(modVlanPcp1.hashCode(),
469 is(equalTo(sameAsModVlanPcp1.hashCode())));
470 assertThat(modVlanPcp1.hashCode(),
471 is(not(equalTo(modVlanPcp2.hashCode()))));
472 }
473
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800474 // ModIPInstruction
Ray Milkey78081052014-11-05 10:38:12 -0800475
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800476 private static final String IP41 = "1.2.3.4";
477 private static final String IP42 = "5.6.7.8";
478 private IpAddress ip41 = IpAddress.valueOf(IP41);
479 private IpAddress ip42 = IpAddress.valueOf(IP42);
480 private final Instruction modIPInstruction1 = Instructions.modL3Src(ip41);
481 private final Instruction sameAsModIPInstruction1 = Instructions.modL3Src(ip41);
482 private final Instruction modIPInstruction2 = Instructions.modL3Src(ip42);
483
484 private static final String IP61 = "1111::2222";
485 private static final String IP62 = "3333::4444";
486 private IpAddress ip61 = IpAddress.valueOf(IP61);
487 private IpAddress ip62 = IpAddress.valueOf(IP62);
488 private final Instruction modIPv6Instruction1 =
489 Instructions.modL3IPv6Src(ip61);
490 private final Instruction sameAsModIPv6Instruction1 =
491 Instructions.modL3IPv6Src(ip61);
492 private final Instruction modIPv6Instruction2 =
493 Instructions.modL3IPv6Src(ip62);
Ray Milkey78081052014-11-05 10:38:12 -0800494
495 /**
496 * Test the modL3Src method.
497 */
498 @Test
499 public void testModL3SrcMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800500 final Instruction instruction = Instructions.modL3Src(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800501 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
502 checkAndConvert(instruction,
503 Instruction.Type.L3MODIFICATION,
504 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800505 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800506 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800507 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_SRC)));
Ray Milkey78081052014-11-05 10:38:12 -0800508 }
509
510 /**
511 * Test the modL3Dst method.
512 */
513 @Test
514 public void testModL3DstMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800515 final Instruction instruction = Instructions.modL3Dst(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800516 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
517 checkAndConvert(instruction,
518 Instruction.Type.L3MODIFICATION,
519 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800520 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800521 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800522 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_DST)));
Ray Milkey78081052014-11-05 10:38:12 -0800523 }
524
525 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800526 * Test the modL3IPv6Src method.
Ray Milkey78081052014-11-05 10:38:12 -0800527 */
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800528 @Test
529 public void testModL3IPv6SrcMethod() {
530 final Instruction instruction = Instructions.modL3IPv6Src(ip61);
531 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
532 checkAndConvert(instruction,
533 Instruction.Type.L3MODIFICATION,
534 L3ModificationInstruction.ModIPInstruction.class);
535 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
536 assertThat(modIPInstruction.subtype(),
537 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_SRC)));
538 }
Ray Milkey78081052014-11-05 10:38:12 -0800539
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800540 /**
541 * Test the modL3IPv6Dst method.
542 */
543 @Test
544 public void testModL3IPv6DstMethod() {
545 final Instruction instruction = Instructions.modL3IPv6Dst(ip61);
546 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
547 checkAndConvert(instruction,
548 Instruction.Type.L3MODIFICATION,
549 L3ModificationInstruction.ModIPInstruction.class);
550 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
551 assertThat(modIPInstruction.subtype(),
552 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_DST)));
553 }
554
555 /**
556 * Test the equals() method of the ModIPInstruction class.
557 */
Ray Milkey78081052014-11-05 10:38:12 -0800558 @Test
559 public void testModIPInstructionEquals() throws Exception {
560 checkEqualsAndToString(modIPInstruction1,
561 sameAsModIPInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800562 modIPInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800563 }
564
565 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800566 * Test the hashCode() method of the ModIPInstruction class.
Ray Milkey78081052014-11-05 10:38:12 -0800567 */
Ray Milkey78081052014-11-05 10:38:12 -0800568 @Test
569 public void testModIPInstructionHashCode() {
570 assertThat(modIPInstruction1.hashCode(),
571 is(equalTo(sameAsModIPInstruction1.hashCode())));
572 assertThat(modIPInstruction1.hashCode(),
573 is(not(equalTo(modIPInstruction2.hashCode()))));
574 }
575
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800576 private final int flowLabel1 = 0x11111;
577 private final int flowLabel2 = 0x22222;
578 private final Instruction modIPv6FlowLabelInstruction1 =
579 Instructions.modL3IPv6FlowLabel(flowLabel1);
580 private final Instruction sameAsModIPv6FlowLabelInstruction1 =
581 Instructions.modL3IPv6FlowLabel(flowLabel1);
582 private final Instruction modIPv6FlowLabelInstruction2 =
583 Instructions.modL3IPv6FlowLabel(flowLabel2);
584
585 /**
586 * Test the modL3IPv6FlowLabel method.
587 */
588 @Test
589 public void testModL3IPv6FlowLabelMethod() {
590 final Instruction instruction =
591 Instructions.modL3IPv6FlowLabel(flowLabel1);
592 final L3ModificationInstruction.ModIPv6FlowLabelInstruction
593 modIPv6FlowLabelInstruction =
594 checkAndConvert(instruction,
595 Instruction.Type.L3MODIFICATION,
596 L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
597 assertThat(modIPv6FlowLabelInstruction.flowLabel(),
598 is(equalTo(flowLabel1)));
599 assertThat(modIPv6FlowLabelInstruction.subtype(),
600 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_FLABEL)));
601 }
602
603 /**
604 * Test the equals() method of the ModIPv6FlowLabelInstruction class.
605 */
606 @Test
607 public void testModIPv6FlowLabelInstructionEquals() throws Exception {
608 checkEqualsAndToString(modIPv6FlowLabelInstruction1,
609 sameAsModIPv6FlowLabelInstruction1,
610 modIPv6FlowLabelInstruction2);
611 }
612
613 /**
614 * Test the hashCode() method of the ModIPv6FlowLabelInstruction class.
615 */
616 @Test
617 public void testModIPv6FlowLabelInstructionHashCode() {
618 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
619 is(equalTo(sameAsModIPv6FlowLabelInstruction1.hashCode())));
620 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
621 is(not(equalTo(modIPv6FlowLabelInstruction2.hashCode()))));
622 }
623
Michele Santuari4b6019e2014-12-19 11:31:45 +0100624 private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
625 private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
626 private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(MplsLabel.mplsLabel(2));
Ray Milkey0d338052014-11-21 16:40:12 -0800627
628 /**
629 * Test the modMplsLabel method.
630 */
631 @Test
632 public void testModMplsMethod() {
HIGUCHI Yuta04b49fc2015-08-28 09:58:58 -0700633 final MplsLabel mplsLabel = MplsLabel.mplsLabel(33);
634 final Instruction instruction = Instructions.modMplsLabel(mplsLabel);
Ray Milkey0d338052014-11-21 16:40:12 -0800635 final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction =
636 checkAndConvert(instruction,
637 Instruction.Type.L2MODIFICATION,
638 L2ModificationInstruction.ModMplsLabelInstruction.class);
Ray Milkey125572b2016-02-22 16:48:17 -0800639 assertThat(modMplsLabelInstruction.label(), is(equalTo(mplsLabel)));
Ray Milkey0d338052014-11-21 16:40:12 -0800640 assertThat(modMplsLabelInstruction.subtype(),
641 is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL)));
642 }
643
644 /**
Ray Milkey3564a8c2015-12-14 11:43:12 -0800645 * Test the equals(), hashCode() and toString() methods of the
Ray Milkey0d338052014-11-21 16:40:12 -0800646 * ModMplsLabelInstruction class.
647 */
Ray Milkey0d338052014-11-21 16:40:12 -0800648 @Test
649 public void testModMplsLabelInstructionEquals() throws Exception {
650 checkEqualsAndToString(modMplsLabelInstruction1,
651 sameAsModMplsLabelInstruction1,
652 modMplsLabelInstruction2);
653 }
Ray Milkey78081052014-11-05 10:38:12 -0800654
Hyunsun Moond0533e52015-07-28 18:12:43 -0700655 // ModTunnelIdInstruction
656
657 private final long tunnelId1 = 1L;
658 private final long tunnelId2 = 2L;
659 private final Instruction modTunnelId1 = Instructions.modTunnelId(tunnelId1);
660 private final Instruction sameAsModTunnelId1 = Instructions.modTunnelId(tunnelId1);
661 private final Instruction modTunnelId2 = Instructions.modTunnelId(tunnelId2);
662
663 /**
664 * Test the modTunnelId method.
665 */
666 @Test
667 public void testModTunnelIdMethod() {
668 final Instruction instruction = Instructions.modTunnelId(tunnelId1);
669 final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction =
670 checkAndConvert(instruction, Instruction.Type.L2MODIFICATION,
671 L2ModificationInstruction.ModTunnelIdInstruction.class);
672 assertThat(modTunnelIdInstruction.tunnelId(), is(equalTo(tunnelId1)));
673 assertThat(modTunnelIdInstruction.subtype(),
674 is(equalTo(L2ModificationInstruction.L2SubType.TUNNEL_ID)));
675 }
676
677 /***
678 * Test the equals() method of the ModTunnelIdInstruction class.
679 */
680 @Test
681 public void testModTunnelIdInstructionEquals() throws Exception {
682 checkEqualsAndToString(modTunnelId1, sameAsModTunnelId1, modTunnelId2);
683 }
684
685 /**
686 * Test the hashCode() method of the ModTunnelIdInstruction class.
687 */
688 @Test
689 public void testModTunnelIdInstructionHashCode() {
690 assertThat(modTunnelId1.hashCode(), is(equalTo(sameAsModTunnelId1.hashCode())));
691 assertThat(modTunnelId1.hashCode(), is(not(equalTo(modTunnelId2.hashCode()))));
692 }
693
694 // ModTransportPortInstruction
695
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700696 private final TpPort tpPort1 = TpPort.tpPort(1);
697 private final TpPort tpPort2 = TpPort.tpPort(2);
698 private final Instruction modTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
699 private final Instruction sameAsModTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
700 private final Instruction modTransportPortInstruction2 = Instructions.modTcpSrc(tpPort2);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700701
702 /**
703 * Test the modTcpSrc() method.
704 */
705 @Test
706 public void testModTcpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700707 final Instruction instruction = Instructions.modTcpSrc(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700708 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
709 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
710 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700711 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700712 assertThat(modTransportPortInstruction.subtype(),
713 is(equalTo(L4ModificationInstruction.L4SubType.TCP_SRC)));
714 }
715
716 /**
717 * Test the modTcpDst() method.
718 */
719 @Test
720 public void testModTcpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700721 final Instruction instruction = Instructions.modTcpDst(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700722 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
723 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
724 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700725 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700726 assertThat(modTransportPortInstruction.subtype(),
727 is(equalTo(L4ModificationInstruction.L4SubType.TCP_DST)));
728 }
729
730 /**
731 * Test the modUdpSrc() method.
732 */
733 @Test
734 public void testModUdpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700735 final Instruction instruction = Instructions.modUdpSrc(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700736 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
737 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
738 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700739 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700740 assertThat(modTransportPortInstruction.subtype(),
741 is(equalTo(L4ModificationInstruction.L4SubType.UDP_SRC)));
742 }
743
744 /**
745 * Test the modUdpDst() method.
746 */
747 @Test
748 public void testModUdpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700749 final Instruction instruction = Instructions.modUdpDst(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700750 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
751 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
752 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700753 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700754 assertThat(modTransportPortInstruction.subtype(),
755 is(equalTo(L4ModificationInstruction.L4SubType.UDP_DST)));
756 }
757
758 /**
759 * Test the equals() method of the ModTransportPortInstruction class.
760 */
761 @Test
762 public void testModTransportPortInstructionEquals() throws Exception {
763 checkEqualsAndToString(modTransportPortInstruction1,
764 sameAsModTransportPortInstruction1,
765 modTransportPortInstruction2);
766 }
767
768 /**
769 * Test the hashCode() method of the ModTransportPortInstruction class.
770 */
771 @Test
772 public void testModTransportPortInstructionHashCode() {
773 assertThat(modTransportPortInstruction1.hashCode(),
774 is(equalTo(sameAsModTransportPortInstruction1.hashCode())));
775 assertThat(modTransportPortInstruction1.hashCode(),
776 is(not(equalTo(modTransportPortInstruction2.hashCode()))));
777 }
Ray Milkey3564a8c2015-12-14 11:43:12 -0800778
779 // GroupInstruction
780
781 private final GroupId groupId1 = new DefaultGroupId(1);
782 private final GroupId groupId2 = new DefaultGroupId(2);
783 private final Instruction groupInstruction1 = Instructions.createGroup(groupId1);
784 private final Instruction sameAsGroupInstruction1 = Instructions.createGroup(groupId1);
785 private final Instruction groupInstruction2 = Instructions.createGroup(groupId2);
786
787 /**
788 * Test the create group method.
789 */
790 @Test
791 public void testCreateGroupMethod() {
792 final Instruction instruction = Instructions.createGroup(groupId1);
793 final Instructions.GroupInstruction groupInstruction =
794 checkAndConvert(instruction,
795 Instruction.Type.GROUP,
796 Instructions.GroupInstruction.class);
797 assertThat(groupInstruction.groupId(), is(equalTo(groupId1)));
798 }
799
800 /**
801 * Test the equals() method of the GroupInstruction class.
802 */
803
804 @Test
805 public void testGroupInstructionEquals() {
806 checkEqualsAndToString(groupInstruction1,
807 sameAsGroupInstruction1,
808 groupInstruction2);
809 }
810
811 // SetQueueInstruction
812
813 private final Instruction setQueueInstruction1 = Instructions.setQueue(1, port1);
814 private final Instruction sameAsSetQueueInstruction1 = Instructions.setQueue(1, port1);
815 private final Instruction setQueueInstruction2 = Instructions.setQueue(1, port2);
816
817 /**
818 * Test the set queue method.
819 */
820 @Test
821 public void testSetQueueMethod() {
822 final Instruction instruction = Instructions.setQueue(2, port2);
823 final Instructions.SetQueueInstruction setQueueInstruction =
824 checkAndConvert(instruction,
825 Instruction.Type.QUEUE,
826 Instructions.SetQueueInstruction.class);
827 assertThat(setQueueInstruction.queueId(), is(2L));
828 assertThat(setQueueInstruction.port(), is(port2));
829 }
830
831 /**
832 * Test the equals() method of the SetQueueInstruction class.
833 */
834 @Test
835 public void testSetQueueInstructionEquals() {
836 checkEqualsAndToString(setQueueInstruction1,
837 sameAsSetQueueInstruction1,
838 setQueueInstruction2);
839 }
840
841 // MeterInstruction
842
843 MeterId meterId1 = MeterId.meterId(1);
844 MeterId meterId2 = MeterId.meterId(2);
845 private final Instruction meterInstruction1 = Instructions.meterTraffic(meterId1);
846 private final Instruction sameAsMeterInstruction1 = Instructions.meterTraffic(meterId1);
847 private final Instruction meterInstruction2 = Instructions.meterTraffic(meterId2);
848
849 /**
850 * Test the meter traffic method.
851 */
852 @Test
853 public void testMeterTrafficMethod() {
854 final Instruction instruction = Instructions.meterTraffic(meterId1);
855 final Instructions.MeterInstruction meterInstruction =
856 checkAndConvert(instruction,
857 Instruction.Type.METER,
858 Instructions.MeterInstruction.class);
859 assertThat(meterInstruction.meterId(), is(meterId1));
860 }
861
862 /**
863 * Test the equals() method of the MeterInstruction class.
864 */
865 @Test
866 public void testMeterTrafficInstructionEquals() {
867 checkEqualsAndToString(meterInstruction1,
868 sameAsMeterInstruction1,
869 meterInstruction2);
870 }
871
872 // TableTypeTransition
873
874 private final Instruction transitionInstruction1 = Instructions.transition(1);
875 private final Instruction sameAsTransitionInstruction1 = Instructions.transition(1);
876 private final Instruction transitionInstruction2 = Instructions.transition(2);
877
878 /**
879 * Test the transition method.
880 */
881 @Test
882 public void testTransitionMethod() {
883 final Instruction instruction = Instructions.transition(1);
884 final Instructions.TableTypeTransition tableInstruction =
885 checkAndConvert(instruction,
886 Instruction.Type.TABLE,
887 Instructions.TableTypeTransition.class);
888 assertThat(tableInstruction.tableId(), is(1));
889 }
890
891 /**
892 * Test the equals() method of the TableTypeTransition class.
893 */
894 @Test
895 public void testTableTypeTransitionInstructionEquals() {
896 checkEqualsAndToString(transitionInstruction1,
897 sameAsTransitionInstruction1,
898 transitionInstruction2);
899 }
900
901 // MetadataInstruction
902
903 long metadata1 = 111L;
904 long metadataMask1 = 222L;
905 long metadata2 = 333L;
906 long metadataMask2 = 444L;
907
908 private final Instruction metadataInstruction1 =
909 Instructions.writeMetadata(metadata1, metadataMask1);
910 private final Instruction sameAsMetadataInstruction1 =
911 Instructions.writeMetadata(metadata1, metadataMask1);
912 private final Instruction metadataInstruction2 =
913 Instructions.writeMetadata(metadata2, metadataMask2);
914
915 /**
916 * Test the write metadata method.
917 */
918 @Test
919 public void testWriteMetadataMethod() {
920 final Instruction instruction =
921 Instructions.writeMetadata(metadata1, metadataMask1);
922 final Instructions.MetadataInstruction metadataInstruction =
923 checkAndConvert(instruction,
924 Instruction.Type.METADATA,
925 Instructions.MetadataInstruction.class);
926 assertThat(metadataInstruction.metadata(), is(metadata1));
927 assertThat(metadataInstruction.metadataMask(), is(metadataMask1));
928 }
929
930 /**
931 * Test the equals() method of the MetadataInstruction class.
932 */
933 @Test
934 public void testInstructionEquals() {
935 checkEqualsAndToString(metadataInstruction1,
936 sameAsMetadataInstruction1,
937 metadataInstruction2);
938 }
939
940 // ExtensionInstructionWrapper
941
942 class MockExtensionTreatment implements ExtensionTreatment {
943 int type;
944
945 MockExtensionTreatment(int type) {
946 this.type = type;
947 }
948 @Override
949 public ExtensionTreatmentType type() {
950 return new ExtensionTreatmentType(type);
951 }
952
953 @Override
954 public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException {
955
956 }
957
958 @Override
959 public <T> T getPropertyValue(String key) throws ExtensionPropertyException {
960 return null;
961 }
962
963 @Override
964 public List<String> getProperties() {
965 return null;
966 }
967
968 @Override
969 public byte[] serialize() {
970 return new byte[0];
971 }
972
973 @Override
974 public void deserialize(byte[] data) {
975
976 }
977 }
978
979 ExtensionTreatment extensionTreatment1 = new MockExtensionTreatment(111);
980 ExtensionTreatment extensionTreatment2 = new MockExtensionTreatment(222);
981
982 DeviceId deviceId1 = DeviceId.deviceId("of:1");
983 DeviceId deviceId2 = DeviceId.deviceId("of:2");
984
985 private final Instruction extensionInstruction1 =
986 Instructions.extension(extensionTreatment1, deviceId1);
987 private final Instruction sameAsExtensionInstruction1 =
988 Instructions.extension(extensionTreatment1, deviceId1);
989 private final Instruction extensionInstruction2 =
990 Instructions.extension(extensionTreatment2, deviceId2);
991
992 /**
993 * Test the extension method.
994 */
995 @Test
996 public void testExtensionMethod() {
997 final Instruction instruction =
998 Instructions.extension(extensionTreatment1, deviceId1);
999 final Instructions.ExtensionInstructionWrapper extensionInstructionWrapper =
1000 checkAndConvert(instruction,
1001 Instruction.Type.EXTENSION,
1002 Instructions.ExtensionInstructionWrapper.class);
1003 assertThat(extensionInstructionWrapper.deviceId(), is(deviceId1));
1004 assertThat(extensionInstructionWrapper.extensionInstruction(), is(extensionTreatment1));
1005 }
1006
1007 /**
1008 * Test the equals() method of the ExtensionInstructionWrapper class.
1009 */
1010 @Test
1011 public void testExtensionInstructionWrapperEquals() {
1012 checkEqualsAndToString(extensionInstruction1,
1013 sameAsExtensionInstruction1,
1014 extensionInstruction2);
1015 }
1016
1017 // PushHeaderInstructions
1018
1019 private final EthType ethType1 = new EthType(1);
1020 private final EthType ethType2 = new EthType(2);
1021 private final Instruction pushHeaderInstruction1 = Instructions.popMpls(ethType1);
1022 private final Instruction sameAsPushHeaderInstruction1 = Instructions.popMpls(ethType1);
1023 private final Instruction pushHeaderInstruction2 = Instructions.popMpls(ethType2);
1024
1025 /**
1026 * Test the pushMpls method.
1027 */
1028 @Test
1029 public void testPushMplsMethod() {
1030 final Instruction instruction = Instructions.pushMpls();
1031 final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstruction =
1032 checkAndConvert(instruction,
1033 Instruction.Type.L2MODIFICATION,
1034 L2ModificationInstruction.PushHeaderInstructions.class);
1035 assertThat(pushHeaderInstruction.ethernetType().toString(),
1036 is(EthType.EtherType.MPLS_MULTICAST.toString()));
1037 assertThat(pushHeaderInstruction.subtype(),
1038 is(L2ModificationInstruction.L2SubType.MPLS_PUSH));
1039 }
1040
1041 /**
1042 * Test the popMpls method.
1043 */
1044 @Test
1045 public void testPopMplsMethod() {
1046 final Instruction instruction = Instructions.popMpls();
1047 final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstruction =
1048 checkAndConvert(instruction,
1049 Instruction.Type.L2MODIFICATION,
1050 L2ModificationInstruction.PushHeaderInstructions.class);
1051 assertThat(pushHeaderInstruction.ethernetType().toString(),
1052 is(EthType.EtherType.MPLS_MULTICAST.toString()));
1053 assertThat(pushHeaderInstruction.subtype(),
1054 is(L2ModificationInstruction.L2SubType.MPLS_POP));
1055 }
1056
1057 /**
1058 * Test the popMpls(EtherType) method.
1059 */
1060 @Test
1061 public void testPopMplsEthertypeMethod() {
1062 final Instruction instruction = Instructions.popMpls(new EthType(1));
1063 final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstruction =
1064 checkAndConvert(instruction,
1065 Instruction.Type.L2MODIFICATION,
1066 L2ModificationInstruction.PushHeaderInstructions.class);
1067 assertThat(pushHeaderInstruction.ethernetType().toShort(), is((short) 1));
1068 assertThat(pushHeaderInstruction.subtype(),
1069 is(L2ModificationInstruction.L2SubType.MPLS_POP));
1070 }
1071
1072 /**
1073 * Test the pushVlan method.
1074 */
1075 @Test
1076 public void testPushVlanMethod() {
1077 final Instruction instruction = Instructions.pushVlan();
1078 final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstruction =
1079 checkAndConvert(instruction,
1080 Instruction.Type.L2MODIFICATION,
1081 L2ModificationInstruction.PushHeaderInstructions.class);
1082 assertThat(pushHeaderInstruction.ethernetType().toString(),
1083 is(EthType.EtherType.VLAN.toString()));
1084 assertThat(pushHeaderInstruction.subtype(),
1085 is(L2ModificationInstruction.L2SubType.VLAN_PUSH));
1086 }
1087
1088 /**
1089 * Tests the equals(), hashCode() and toString() methods of the
1090 * PushHeaderInstructions class.
1091 */
1092
1093 @Test
1094 public void testPushHeaderInstructionsEquals() {
1095 checkEqualsAndToString(pushHeaderInstruction1,
1096 sameAsPushHeaderInstruction1,
1097 pushHeaderInstruction2);
1098 }
1099
1100 // ModMplsTtlInstruction
1101
1102 private final Instruction modMplsTtlInstruction1 = Instructions.decMplsTtl();
1103 private final Instruction sameAsModMplsTtlInstruction1 = Instructions.decMplsTtl();
1104
1105 /**
1106 * Test the modMplsBos() method.
1107 */
1108 @Test
1109 public void testDecMplsTtlMethod() {
1110 final Instruction instruction = Instructions.decMplsTtl();
1111 final L2ModificationInstruction.ModMplsTtlInstruction modMplsTtlInstruction =
1112 checkAndConvert(instruction,
1113 Instruction.Type.L2MODIFICATION,
1114 L2ModificationInstruction.ModMplsTtlInstruction.class);
1115 assertThat(modMplsTtlInstruction.subtype(),
1116 is(L2ModificationInstruction.L2SubType.DEC_MPLS_TTL));
1117 }
1118
1119 /**
1120 * Tests the equals(), hashCode() and toString() methods of the
1121 * PushHeaderInstructions class.
1122 */
1123
1124 @Test
1125 public void testMplsTtlInstructionsEquals() {
1126 new EqualsTester()
1127 .addEqualityGroup(modMplsTtlInstruction1, sameAsModMplsTtlInstruction1)
1128 .testEquals();
1129 }
1130
1131 // ModMplsBosInstruction
1132
1133 private final Instruction modMplsBosInstruction1 = Instructions.modMplsBos(true);
1134 private final Instruction sameAsModMplsBosInstruction1 = Instructions.modMplsBos(true);
1135 private final Instruction modMplsBosInstruction2 = Instructions.modMplsBos(false);
1136
1137 /**
1138 * Test the modMplsBos() method.
1139 */
1140 @Test
1141 public void testModMplsBosMethod() {
1142 final Instruction instruction = Instructions.modMplsBos(true);
1143 final L2ModificationInstruction.ModMplsBosInstruction modMplsBosInstruction =
1144 checkAndConvert(instruction,
1145 Instruction.Type.L2MODIFICATION,
1146 L2ModificationInstruction.ModMplsBosInstruction.class);
1147 assertThat(modMplsBosInstruction.subtype(),
1148 is(L2ModificationInstruction.L2SubType.MPLS_BOS));
1149 assertThat(modMplsBosInstruction.mplsBos(), is(true));
1150 }
1151
1152 /**
1153 * Tests the equals(), hashCode() and toString() methods of the
1154 * PushHeaderInstructions class.
1155 */
1156
1157 @Test
1158 public void testMplsBosInstructionsEquals() {
1159 checkEqualsAndToString(modMplsBosInstruction1,
1160 sameAsModMplsBosInstruction1,
1161 modMplsBosInstruction2);
1162 }
1163
1164 // PopVlanInstruction
1165
1166 private final Instruction popVlanInstruction1 = Instructions.popVlan();
1167 private final Instruction sameAsPopVlanInstruction1 = Instructions.popVlan();
1168
1169 /**
1170 * Test the popVlan method.
1171 */
1172 @Test
1173 public void testPopVlanMethod() {
1174 final Instruction instruction = Instructions.popVlan();
1175 final L2ModificationInstruction.PopVlanInstruction popVlanInstruction =
1176 checkAndConvert(instruction,
1177 Instruction.Type.L2MODIFICATION,
1178 L2ModificationInstruction.PopVlanInstruction.class);
1179 assertThat(popVlanInstruction.subtype(),
1180 is(L2ModificationInstruction.L2SubType.VLAN_POP));
1181 }
1182
1183 /**
1184 * Tests the equals(), hashCode() and toString() methods of the
1185 * PushHeaderInstructions class.
1186 */
1187
1188 @Test
1189 public void testPopVlanInstructionsEquals() {
1190 new EqualsTester()
1191 .addEqualityGroup(popVlanInstruction1, sameAsPopVlanInstruction1)
1192 .testEquals();
1193 }
1194
1195 // ModArpIPInstruction
1196
1197 private final Instruction modArpIPInstruction1 = Instructions.modArpSpa(ip41);
1198 private final Instruction sameAsModArpIPInstruction1 = Instructions.modArpSpa(ip41);
1199 private final Instruction modArpIPInstruction2 = Instructions.modArpSpa(ip42);
1200
1201 /**
1202 * Test the modArpSpa() method.
1203 */
1204 @Test
1205 public void testModArpSpaMethod() {
1206 final Instruction instruction = Instructions.modArpSpa(ip41);
1207 final L3ModificationInstruction.ModArpIPInstruction modArpIPInstruction =
1208 checkAndConvert(instruction,
1209 Instruction.Type.L3MODIFICATION,
1210 L3ModificationInstruction.ModArpIPInstruction.class);
1211 assertThat(modArpIPInstruction.subtype(),
1212 is(L3ModificationInstruction.L3SubType.ARP_SPA));
1213 assertThat(modArpIPInstruction.ip(), is(ip41));
1214 }
1215
1216 /**
1217 * Tests the equals(), hashCode() and toString() methods of the
1218 * ModArpIPInstruction class.
1219 */
1220
1221 @Test
1222 public void testModArpIPInstructionEquals() {
1223 checkEqualsAndToString(modArpIPInstruction1,
1224 sameAsModArpIPInstruction1,
1225 modArpIPInstruction2);
1226 }
1227
1228 // ModArpEthInstruction
1229
1230 private final Instruction modArpEthInstruction1 = Instructions.modArpSha(mac1);
1231 private final Instruction sameAsModArpEthInstruction1 = Instructions.modArpSha(mac1);
1232 private final Instruction modArpEthInstruction2 = Instructions.modArpSha(mac2);
1233
1234 /**
1235 * Test the modArpSha() method.
1236 */
1237 @Test
1238 public void testModArpShaMethod() {
1239 final Instruction instruction = Instructions.modArpSha(mac1);
1240 final L3ModificationInstruction.ModArpEthInstruction modArpEthInstruction =
1241 checkAndConvert(instruction,
1242 Instruction.Type.L3MODIFICATION,
1243 L3ModificationInstruction.ModArpEthInstruction.class);
1244 assertThat(modArpEthInstruction.subtype(),
1245 is(L3ModificationInstruction.L3SubType.ARP_SHA));
1246 assertThat(modArpEthInstruction.mac(), is(mac1));
1247 }
1248
1249 /**
1250 * Tests the equals(), hashCode() and toString() methods of the
1251 * ModArpIPInstruction class.
1252 */
1253
1254 @Test
1255 public void testModArpEthInstructionEquals() {
1256 checkEqualsAndToString(modArpEthInstruction1,
1257 sameAsModArpEthInstruction1,
1258 modArpEthInstruction2);
1259 }
1260
1261 // ModArpOpInstruction
1262
1263 private final Instruction modArpOpInstruction1 = Instructions.modL3ArpOp((short) 1);
1264 private final Instruction sameAsModArpOpInstruction1 = Instructions.modL3ArpOp((short) 1);
1265 private final Instruction modArpOpInstruction2 = Instructions.modL3ArpOp((short) 2);
1266
1267 /**
1268 * Test the modL3ArpOp() method.
1269 */
1270 @Test
1271 public void testModArpModL3ArpOpMethod() {
1272 final Instruction instruction = Instructions.modL3ArpOp((short) 1);
1273 final L3ModificationInstruction.ModArpOpInstruction modArpEthInstruction =
1274 checkAndConvert(instruction,
1275 Instruction.Type.L3MODIFICATION,
1276 L3ModificationInstruction.ModArpOpInstruction.class);
1277 assertThat(modArpEthInstruction.subtype(),
1278 is(L3ModificationInstruction.L3SubType.ARP_OP));
1279 assertThat(modArpEthInstruction.op(), is(1L));
1280 }
1281
1282 /**
1283 * Tests the equals(), hashCode() and toString() methods of the
1284 * ModArpIPInstruction class.
1285 */
1286
1287 @Test
1288 public void testModArpOpInstructionEquals() {
1289 checkEqualsAndToString(modArpOpInstruction1,
1290 sameAsModArpOpInstruction1,
1291 modArpOpInstruction2);
1292 }
1293
1294 // ModTtlInstruction
1295
1296 private final Instruction modArpTtlInstruction1 = Instructions.copyTtlIn();
1297 private final Instruction sameAsModArpTtlInstruction1 = Instructions.copyTtlIn();
1298 private final Instruction modArpTtlInstruction2 = Instructions.copyTtlOut();
1299 private final Instruction modArpTtlInstruction3 = Instructions.decNwTtl();
1300
1301 /**
1302 * Test the copyTtlIn() method.
1303 */
1304 @Test
1305 public void testCopyTtlInMethod() {
1306 final Instruction instruction = Instructions.copyTtlIn();
1307 final L3ModificationInstruction.ModTtlInstruction modTtlInstruction =
1308 checkAndConvert(instruction,
1309 Instruction.Type.L3MODIFICATION,
1310 L3ModificationInstruction.ModTtlInstruction.class);
1311 assertThat(modTtlInstruction.subtype(),
1312 is(L3ModificationInstruction.L3SubType.TTL_IN));
1313 }
1314
1315 /**
1316 * Test the copyTtlOut() method.
1317 */
1318 @Test
1319 public void testCopyTtlOutMethod() {
1320 final Instruction instruction = Instructions.copyTtlOut();
1321 final L3ModificationInstruction.ModTtlInstruction modTtlInstruction =
1322 checkAndConvert(instruction,
1323 Instruction.Type.L3MODIFICATION,
1324 L3ModificationInstruction.ModTtlInstruction.class);
1325 assertThat(modTtlInstruction.subtype(),
1326 is(L3ModificationInstruction.L3SubType.TTL_OUT));
1327 }
1328
1329 /**
1330 * Test the decNwTtl() method.
1331 */
1332 @Test
1333 public void testDecNwTtlOutMethod() {
1334 final Instruction instruction = Instructions.decNwTtl();
1335 final L3ModificationInstruction.ModTtlInstruction modTtlInstruction =
1336 checkAndConvert(instruction,
1337 Instruction.Type.L3MODIFICATION,
1338 L3ModificationInstruction.ModTtlInstruction.class);
1339 assertThat(modTtlInstruction.subtype(),
1340 is(L3ModificationInstruction.L3SubType.DEC_TTL));
1341 }
1342
1343 /**
1344 * Tests the equals(), hashCode() and toString() methods of the
1345 * ModArpIPInstruction class.
1346 */
1347
1348 @Test
1349 public void testModTtlInstructionEquals() {
1350 new EqualsTester()
1351 .addEqualityGroup(modArpTtlInstruction1, sameAsModArpTtlInstruction1)
1352 .addEqualityGroup(modArpTtlInstruction2)
1353 .addEqualityGroup(modArpTtlInstruction3)
1354 .testEquals();
1355 }
1356
Ray Milkey78081052014-11-05 10:38:12 -08001357}