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