blob: fd5c9ef5cf4afcf171b4b77535b60b96aad5066f [file] [log] [blame]
Ray Milkey78081052014-11-05 10:38:12 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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
Jian Li11260a02016-05-19 13:07:22 -070018import com.google.common.testing.EqualsTester;
Ray Milkey78081052014-11-05 10:38:12 -080019import org.junit.Test;
Ray Milkey3564a8c2015-12-14 11:43:12 -080020import org.onlab.packet.EthType;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070021import org.onlab.packet.IpAddress;
22import org.onlab.packet.MacAddress;
23import org.onlab.packet.MplsLabel;
24import org.onlab.packet.TpPort;
25import org.onlab.packet.VlanId;
Ray Milkey3564a8c2015-12-14 11:43:12 -080026import org.onosproject.core.DefaultGroupId;
27import org.onosproject.core.GroupId;
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -070028import org.onosproject.net.ChannelSpacing;
Ray Milkey3564a8c2015-12-14 11:43:12 -080029import org.onosproject.net.DeviceId;
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -070030import org.onosproject.net.GridType;
31import org.onosproject.net.Lambda;
Yafit Hadar52d81552015-10-07 12:26:52 +030032import org.onosproject.net.OduSignalId;
Brian O'Connorabafb502014-12-02 22:26:20 -080033import org.onosproject.net.PortNumber;
Ray Milkey3564a8c2015-12-14 11:43:12 -080034import org.onosproject.net.meter.MeterId;
Ray Milkey78081052014-11-05 10:38:12 -080035
Jian Li11260a02016-05-19 13:07:22 -070036import java.util.List;
Ray Milkey0d338052014-11-21 16:40:12 -080037
Ray Milkey78081052014-11-05 10:38:12 -080038import static org.hamcrest.MatcherAssert.assertThat;
Ray Milkey78081052014-11-05 10:38:12 -080039import static org.hamcrest.Matchers.equalTo;
40import static org.hamcrest.Matchers.instanceOf;
41import static org.hamcrest.Matchers.is;
42import static org.hamcrest.Matchers.not;
43import static org.hamcrest.Matchers.notNullValue;
44import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
45import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
Yafit Hadar52d81552015-10-07 12:26:52 +030046import static org.onosproject.net.OduSignalId.oduSignalId;
Ray Milkey3564a8c2015-12-14 11:43:12 -080047import static org.onosproject.net.PortNumber.portNumber;
Ray Milkey78081052014-11-05 10:38:12 -080048
49/**
50 * Unit tests for the Instructions class.
51 */
52public class InstructionsTest {
53
54 /**
Ray Milkey3564a8c2015-12-14 11:43:12 -080055 * Checks that an Instruction object has the proper type, and then converts
Ray Milkey78081052014-11-05 10:38:12 -080056 * it to the proper type.
57 *
58 * @param instruction Instruction object to convert
59 * @param type Enumerated type value for the Criterion class
60 * @param clazz Desired Criterion class
61 * @param <T> The type the caller wants returned
62 * @return converted object
63 */
64 @SuppressWarnings("unchecked")
65 private <T> T checkAndConvert(Instruction instruction, Instruction.Type type, Class clazz) {
66 assertThat(instruction, is(notNullValue()));
67 assertThat(instruction.type(), is(equalTo(type)));
68 assertThat(instruction, instanceOf(clazz));
69 return (T) instruction;
70 }
71
72 /**
Ray Milkey3564a8c2015-12-14 11:43:12 -080073 * Checks the equals() and toString() methods of a Instruction class.
Ray Milkey78081052014-11-05 10:38:12 -080074 *
75 * @param c1 first object to compare
76 * @param c1match object that should be equal to the first
77 * @param c2 object that should be not equal to the first
Ray Milkey78081052014-11-05 10:38:12 -080078 * @param <T> type of the arguments
79 */
80 private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match,
Ray Milkey0d338052014-11-21 16:40:12 -080081 T c2) {
Ray Milkey78081052014-11-05 10:38:12 -080082
Ray Milkey0d338052014-11-21 16:40:12 -080083 new EqualsTester()
84 .addEqualityGroup(c1, c1match)
85 .addEqualityGroup(c2)
86 .testEquals();
Ray Milkey78081052014-11-05 10:38:12 -080087 }
88
89 /**
90 * Checks that Instructions is a proper utility class.
91 */
92 @Test
93 public void testInstructionsUtilityClass() {
94 assertThatClassIsUtility(Instructions.class);
95 }
96
97 /**
98 * Checks that the Instruction class implementations are immutable.
99 */
100 @Test
101 public void testImmutabilityOfInstructions() {
Ray Milkey78081052014-11-05 10:38:12 -0800102 assertThatClassIsImmutable(Instructions.OutputInstruction.class);
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -0700103 assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class);
Yafit Hadar52d81552015-10-07 12:26:52 +0300104 assertThatClassIsImmutable(L1ModificationInstruction.ModOduSignalIdInstruction.class);
Ray Milkey78081052014-11-05 10:38:12 -0800105 assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class);
106 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class);
107 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class);
108 assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800109 assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
Ray Milkeyd03eda02015-01-09 14:58:48 -0800110 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class);
Jian Li11260a02016-05-19 13:07:22 -0700111 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsHeaderInstruction.class);
Ray Milkey3564a8c2015-12-14 11:43:12 -0800112 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsBosInstruction.class);
113 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsTtlInstruction.class);
114 assertThatClassIsImmutable(L2ModificationInstruction.ModTunnelIdInstruction.class);
115 }
116
117 // NoActionInstruction
118
119 private final Instructions.NoActionInstruction noAction1 = Instructions.createNoAction();
120 private final Instructions.NoActionInstruction noAction2 = Instructions.createNoAction();
121
122 /**
123 * Test the createNoAction method.
124 */
125 @Test
126 public void testCreateNoActionMethod() {
127 Instructions.NoActionInstruction instruction = Instructions.createNoAction();
128 checkAndConvert(instruction,
129 Instruction.Type.NOACTION,
130 Instructions.NoActionInstruction.class);
131 }
132
133 /**
134 * Test the equals() method of the NoActionInstruction class.
135 */
136
137 @Test
138 public void testNoActionInstructionEquals() throws Exception {
139 new EqualsTester()
140 .addEqualityGroup(noAction1, noAction2)
141 .testEquals();
142 }
143
144 /**
145 * Test the hashCode() method of the NoActionInstruction class.
146 */
147
148 @Test
149 public void testNoActionInstructionHashCode() {
150 assertThat(noAction1.hashCode(), is(equalTo(noAction2.hashCode())));
Ray Milkey78081052014-11-05 10:38:12 -0800151 }
152
Ray Milkey78081052014-11-05 10:38:12 -0800153 // OutputInstruction
154
155 private final PortNumber port1 = portNumber(1);
156 private final PortNumber port2 = portNumber(2);
157 private final Instructions.OutputInstruction output1 = Instructions.createOutput(port1);
158 private final Instructions.OutputInstruction sameAsOutput1 = Instructions.createOutput(port1);
159 private final Instructions.OutputInstruction output2 = Instructions.createOutput(port2);
160
161 /**
162 * Test the createOutput method.
163 */
164 @Test
165 public void testCreateOutputMethod() {
166 final Instruction instruction = Instructions.createOutput(port2);
167 final Instructions.OutputInstruction outputInstruction =
168 checkAndConvert(instruction,
169 Instruction.Type.OUTPUT,
170 Instructions.OutputInstruction.class);
171 assertThat(outputInstruction.port(), is(equalTo(port2)));
172 }
173
174
175 /**
176 * Test the equals() method of the OutputInstruction class.
177 */
178
179 @Test
180 public void testOutputInstructionEquals() throws Exception {
Ray Milkey0d338052014-11-21 16:40:12 -0800181 checkEqualsAndToString(output1, sameAsOutput1, output2);
Ray Milkey78081052014-11-05 10:38:12 -0800182 }
183
184 /**
185 * Test the hashCode() method of the OutputInstruction class.
186 */
187
188 @Test
189 public void testOutputInstructionHashCode() {
190 assertThat(output1.hashCode(), is(equalTo(sameAsOutput1.hashCode())));
191 assertThat(output1.hashCode(), is(not(equalTo(output2.hashCode()))));
192 }
193
194 // ModLambdaInstruction
195
Sho SHIMIZU5a5a7342015-05-05 16:26:11 -0700196 private final Lambda och1 = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
197 private final Lambda och2 = Lambda.ochSignal(GridType.CWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
198 private final Instruction ochInstruction1 = Instructions.modL0Lambda(och1);
199 private final Instruction sameAsOchInstruction1 = Instructions.modL0Lambda(och1);
200 private final Instruction ochInstruction2 = Instructions.modL0Lambda(och2);
201
202 /**
203 * Test the modL0Lambda().
204 */
205 @Test
206 public void testModL0LambdaMethod() {
207 Instruction instruction = Instructions.modL0Lambda(och1);
208 L0ModificationInstruction.ModOchSignalInstruction ochInstruction =
209 checkAndConvert(instruction, Instruction.Type.L0MODIFICATION,
210 L0ModificationInstruction.ModOchSignalInstruction.class);
211 assertThat(ochInstruction.lambda(), is(och1));
212 }
213
214 /**
215 * Test the equals() method of the ModOchSignalInstruction class.
216 */
217 @Test
218 public void testModOchSignalInstructionEquals() {
219 checkEqualsAndToString(ochInstruction1, sameAsOchInstruction1, ochInstruction2);
220 }
221
222 /**
223 * Test the hashCode() method of the ModOchSignalInstruction class.
224 */
225 @Test
226 public void testModOchSignalInstructionHashCode() {
227 assertThat(ochInstruction1.hashCode(), is(sameAsOchInstruction1.hashCode()));
228 assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode())));
Ray Milkey78081052014-11-05 10:38:12 -0800229 }
230
Yafit Hadar52d81552015-10-07 12:26:52 +0300231 // ModOduSignalIdInstruction
232
233 private final OduSignalId odu1 = oduSignalId(1, 80, new byte[] {8, 7, 6, 5, 7, 6, 5, 7, 6, 5});
234 private final OduSignalId odu2 = oduSignalId(2, 80, new byte[] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2});
235 private final Instruction oduInstruction1 = Instructions.modL1OduSignalId(odu1);
236 private final Instruction sameAsOduInstruction1 = Instructions.modL1OduSignalId(odu1);
237 private final Instruction oduInstruction2 = Instructions.modL1OduSignalId(odu2);
238
239 /**
240 * Test the modL1OduSignalId().
241 */
242 @Test
243 public void testModL1OduSignalIdMethod() {
244 Instruction instruction = Instructions.modL1OduSignalId(odu1);
245 L1ModificationInstruction.ModOduSignalIdInstruction oduInstruction =
246 checkAndConvert(instruction, Instruction.Type.L1MODIFICATION,
247 L1ModificationInstruction.ModOduSignalIdInstruction.class);
248 assertThat(oduInstruction.oduSignalId(), is(odu1));
249 }
250
251 /**
252 * Test the equals() method of the ModOduSignalInstruction class.
253 */
254 @Test
255 public void testModOduSignalIdInstructionEquals() {
256 checkEqualsAndToString(oduInstruction1, sameAsOduInstruction1, oduInstruction2);
257 }
258
259 /**
260 * Test the hashCode() method of the ModOduSignalInstruction class.
261 */
262 @Test
263 public void testModOduSignalIdInstructionHashCode() {
264 assertThat(oduInstruction1.hashCode(), is(sameAsOduInstruction1.hashCode()));
265 assertThat(oduInstruction1.hashCode(), is(not(oduInstruction2.hashCode())));
266 }
267
268
Ray Milkey78081052014-11-05 10:38:12 -0800269 // ModEtherInstruction
270
271 private static final String MAC1 = "00:00:00:00:00:01";
272 private static final String MAC2 = "00:00:00:00:00:02";
273 private final MacAddress mac1 = MacAddress.valueOf(MAC1);
274 private final MacAddress mac2 = MacAddress.valueOf(MAC2);
275 private final Instruction modEtherInstruction1 = Instructions.modL2Src(mac1);
276 private final Instruction sameAsModEtherInstruction1 = Instructions.modL2Src(mac1);
277 private final Instruction modEtherInstruction2 = Instructions.modL2Src(mac2);
278
279 /**
280 * Test the modL2Src method.
281 */
282 @Test
283 public void testModL2SrcMethod() {
284 final Instruction instruction = Instructions.modL2Src(mac1);
285 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
286 checkAndConvert(instruction,
287 Instruction.Type.L2MODIFICATION,
288 L2ModificationInstruction.ModEtherInstruction.class);
289 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
290 assertThat(modEtherInstruction.subtype(),
291 is(equalTo(L2ModificationInstruction.L2SubType.ETH_SRC)));
292 }
293
294 /**
295 * Test the modL2Dst method.
296 */
297 @Test
298 public void testModL2DstMethod() {
299 final Instruction instruction = Instructions.modL2Dst(mac1);
300 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
301 checkAndConvert(instruction,
302 Instruction.Type.L2MODIFICATION,
303 L2ModificationInstruction.ModEtherInstruction.class);
304 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
305 assertThat(modEtherInstruction.subtype(),
306 is(equalTo(L2ModificationInstruction.L2SubType.ETH_DST)));
307 }
308
309 /**
310 * Test the equals() method of the ModEtherInstruction class.
311 */
312
313 @Test
314 public void testModEtherInstructionEquals() throws Exception {
315 checkEqualsAndToString(modEtherInstruction1,
316 sameAsModEtherInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800317 modEtherInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800318 }
319
320 /**
321 * Test the hashCode() method of the ModEtherInstruction class.
322 */
323
324 @Test
325 public void testModEtherInstructionHashCode() {
326 assertThat(modEtherInstruction1.hashCode(),
327 is(equalTo(sameAsModEtherInstruction1.hashCode())));
328 assertThat(modEtherInstruction1.hashCode(),
329 is(not(equalTo(modEtherInstruction2.hashCode()))));
330 }
331
332
333 // ModVlanIdInstruction
334
335 private final short vlan1 = 1;
336 private final short vlan2 = 2;
337 private final VlanId vlanId1 = VlanId.vlanId(vlan1);
338 private final VlanId vlanId2 = VlanId.vlanId(vlan2);
339 private final Instruction modVlanId1 = Instructions.modVlanId(vlanId1);
340 private final Instruction sameAsModVlanId1 = Instructions.modVlanId(vlanId1);
341 private final Instruction modVlanId2 = Instructions.modVlanId(vlanId2);
342
343 /**
344 * Test the modVlanId method.
345 */
346 @Test
347 public void testModVlanIdMethod() {
348 final Instruction instruction = Instructions.modVlanId(vlanId1);
349 final L2ModificationInstruction.ModVlanIdInstruction modEtherInstruction =
350 checkAndConvert(instruction,
351 Instruction.Type.L2MODIFICATION,
352 L2ModificationInstruction.ModVlanIdInstruction.class);
353 assertThat(modEtherInstruction.vlanId(), is(equalTo(vlanId1)));
354 assertThat(modEtherInstruction.subtype(),
355 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_ID)));
356 }
357
358 /**
359 * Test the equals() method of the ModVlanIdInstruction class.
360 */
361
362 @Test
363 public void testModVlanIdInstructionEquals() throws Exception {
364 checkEqualsAndToString(modVlanId1,
365 sameAsModVlanId1,
Ray Milkey0d338052014-11-21 16:40:12 -0800366 modVlanId2);
Ray Milkey78081052014-11-05 10:38:12 -0800367 }
368
369 /**
370 * Test the hashCode() method of the ModEtherInstruction class.
371 */
372
373 @Test
374 public void testModVlanIdInstructionHashCode() {
375 assertThat(modVlanId1.hashCode(),
376 is(equalTo(sameAsModVlanId1.hashCode())));
377 assertThat(modVlanId1.hashCode(),
378 is(not(equalTo(modVlanId2.hashCode()))));
379 }
380
381
382 // ModVlanPcpInstruction
383
384 private final byte vlanPcp1 = 1;
385 private final byte vlanPcp2 = 2;
386 private final Instruction modVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
387 private final Instruction sameAsModVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
388 private final Instruction modVlanPcp2 = Instructions.modVlanPcp(vlanPcp2);
389
390 /**
391 * Test the modVlanPcp method.
392 */
393 @Test
394 public void testModVlanPcpMethod() {
395 final Instruction instruction = Instructions.modVlanPcp(vlanPcp1);
396 final L2ModificationInstruction.ModVlanPcpInstruction modEtherInstruction =
397 checkAndConvert(instruction,
398 Instruction.Type.L2MODIFICATION,
399 L2ModificationInstruction.ModVlanPcpInstruction.class);
400 assertThat(modEtherInstruction.vlanPcp(), is(equalTo(vlanPcp1)));
401 assertThat(modEtherInstruction.subtype(),
402 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_PCP)));
403 }
404
405 /**
406 * Test the equals() method of the ModVlanPcpInstruction class.
407 */
408
409 @Test
410 public void testModVlanPcpInstructionEquals() throws Exception {
411 checkEqualsAndToString(modVlanPcp1,
412 sameAsModVlanPcp1,
Ray Milkey0d338052014-11-21 16:40:12 -0800413 modVlanPcp2);
Ray Milkey78081052014-11-05 10:38:12 -0800414 }
415
416 /**
Ray Milkey3564a8c2015-12-14 11:43:12 -0800417 * Test the hashCode() method of the ModVlanPcp class.
Ray Milkey78081052014-11-05 10:38:12 -0800418 */
419
420 @Test
421 public void testModVlanPcpInstructionHashCode() {
422 assertThat(modVlanPcp1.hashCode(),
423 is(equalTo(sameAsModVlanPcp1.hashCode())));
424 assertThat(modVlanPcp1.hashCode(),
425 is(not(equalTo(modVlanPcp2.hashCode()))));
426 }
427
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800428 // ModIPInstruction
Ray Milkey78081052014-11-05 10:38:12 -0800429
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800430 private static final String IP41 = "1.2.3.4";
431 private static final String IP42 = "5.6.7.8";
432 private IpAddress ip41 = IpAddress.valueOf(IP41);
433 private IpAddress ip42 = IpAddress.valueOf(IP42);
434 private final Instruction modIPInstruction1 = Instructions.modL3Src(ip41);
435 private final Instruction sameAsModIPInstruction1 = Instructions.modL3Src(ip41);
436 private final Instruction modIPInstruction2 = Instructions.modL3Src(ip42);
437
438 private static final String IP61 = "1111::2222";
439 private static final String IP62 = "3333::4444";
440 private IpAddress ip61 = IpAddress.valueOf(IP61);
441 private IpAddress ip62 = IpAddress.valueOf(IP62);
442 private final Instruction modIPv6Instruction1 =
443 Instructions.modL3IPv6Src(ip61);
444 private final Instruction sameAsModIPv6Instruction1 =
445 Instructions.modL3IPv6Src(ip61);
446 private final Instruction modIPv6Instruction2 =
447 Instructions.modL3IPv6Src(ip62);
Ray Milkey78081052014-11-05 10:38:12 -0800448
449 /**
450 * Test the modL3Src method.
451 */
452 @Test
453 public void testModL3SrcMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800454 final Instruction instruction = Instructions.modL3Src(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800455 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
456 checkAndConvert(instruction,
457 Instruction.Type.L3MODIFICATION,
458 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800459 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800460 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800461 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_SRC)));
Ray Milkey78081052014-11-05 10:38:12 -0800462 }
463
464 /**
465 * Test the modL3Dst method.
466 */
467 @Test
468 public void testModL3DstMethod() {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800469 final Instruction instruction = Instructions.modL3Dst(ip41);
Ray Milkey78081052014-11-05 10:38:12 -0800470 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
471 checkAndConvert(instruction,
472 Instruction.Type.L3MODIFICATION,
473 L3ModificationInstruction.ModIPInstruction.class);
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800474 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
Ray Milkey78081052014-11-05 10:38:12 -0800475 assertThat(modIPInstruction.subtype(),
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800476 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_DST)));
Ray Milkey78081052014-11-05 10:38:12 -0800477 }
478
479 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800480 * Test the modL3IPv6Src method.
Ray Milkey78081052014-11-05 10:38:12 -0800481 */
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800482 @Test
483 public void testModL3IPv6SrcMethod() {
484 final Instruction instruction = Instructions.modL3IPv6Src(ip61);
485 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
486 checkAndConvert(instruction,
487 Instruction.Type.L3MODIFICATION,
488 L3ModificationInstruction.ModIPInstruction.class);
489 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
490 assertThat(modIPInstruction.subtype(),
491 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_SRC)));
492 }
Ray Milkey78081052014-11-05 10:38:12 -0800493
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800494 /**
495 * Test the modL3IPv6Dst method.
496 */
497 @Test
498 public void testModL3IPv6DstMethod() {
499 final Instruction instruction = Instructions.modL3IPv6Dst(ip61);
500 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
501 checkAndConvert(instruction,
502 Instruction.Type.L3MODIFICATION,
503 L3ModificationInstruction.ModIPInstruction.class);
504 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
505 assertThat(modIPInstruction.subtype(),
506 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_DST)));
507 }
508
509 /**
510 * Test the equals() method of the ModIPInstruction class.
511 */
Ray Milkey78081052014-11-05 10:38:12 -0800512 @Test
513 public void testModIPInstructionEquals() throws Exception {
514 checkEqualsAndToString(modIPInstruction1,
515 sameAsModIPInstruction1,
Ray Milkey0d338052014-11-21 16:40:12 -0800516 modIPInstruction2);
Ray Milkey78081052014-11-05 10:38:12 -0800517 }
518
519 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800520 * Test the hashCode() method of the ModIPInstruction class.
Ray Milkey78081052014-11-05 10:38:12 -0800521 */
Ray Milkey78081052014-11-05 10:38:12 -0800522 @Test
523 public void testModIPInstructionHashCode() {
524 assertThat(modIPInstruction1.hashCode(),
525 is(equalTo(sameAsModIPInstruction1.hashCode())));
526 assertThat(modIPInstruction1.hashCode(),
527 is(not(equalTo(modIPInstruction2.hashCode()))));
528 }
529
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800530 private final int flowLabel1 = 0x11111;
531 private final int flowLabel2 = 0x22222;
532 private final Instruction modIPv6FlowLabelInstruction1 =
533 Instructions.modL3IPv6FlowLabel(flowLabel1);
534 private final Instruction sameAsModIPv6FlowLabelInstruction1 =
535 Instructions.modL3IPv6FlowLabel(flowLabel1);
536 private final Instruction modIPv6FlowLabelInstruction2 =
537 Instructions.modL3IPv6FlowLabel(flowLabel2);
538
539 /**
540 * Test the modL3IPv6FlowLabel method.
541 */
542 @Test
543 public void testModL3IPv6FlowLabelMethod() {
544 final Instruction instruction =
545 Instructions.modL3IPv6FlowLabel(flowLabel1);
546 final L3ModificationInstruction.ModIPv6FlowLabelInstruction
547 modIPv6FlowLabelInstruction =
548 checkAndConvert(instruction,
549 Instruction.Type.L3MODIFICATION,
550 L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
551 assertThat(modIPv6FlowLabelInstruction.flowLabel(),
552 is(equalTo(flowLabel1)));
553 assertThat(modIPv6FlowLabelInstruction.subtype(),
554 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_FLABEL)));
555 }
556
557 /**
558 * Test the equals() method of the ModIPv6FlowLabelInstruction class.
559 */
560 @Test
561 public void testModIPv6FlowLabelInstructionEquals() throws Exception {
562 checkEqualsAndToString(modIPv6FlowLabelInstruction1,
563 sameAsModIPv6FlowLabelInstruction1,
564 modIPv6FlowLabelInstruction2);
565 }
566
567 /**
568 * Test the hashCode() method of the ModIPv6FlowLabelInstruction class.
569 */
570 @Test
571 public void testModIPv6FlowLabelInstructionHashCode() {
572 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
573 is(equalTo(sameAsModIPv6FlowLabelInstruction1.hashCode())));
574 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
575 is(not(equalTo(modIPv6FlowLabelInstruction2.hashCode()))));
576 }
577
Michele Santuari4b6019e2014-12-19 11:31:45 +0100578 private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
579 private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
580 private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(MplsLabel.mplsLabel(2));
Ray Milkey0d338052014-11-21 16:40:12 -0800581
582 /**
583 * Test the modMplsLabel method.
584 */
585 @Test
586 public void testModMplsMethod() {
HIGUCHI Yuta04b49fc2015-08-28 09:58:58 -0700587 final MplsLabel mplsLabel = MplsLabel.mplsLabel(33);
588 final Instruction instruction = Instructions.modMplsLabel(mplsLabel);
Ray Milkey0d338052014-11-21 16:40:12 -0800589 final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction =
590 checkAndConvert(instruction,
591 Instruction.Type.L2MODIFICATION,
592 L2ModificationInstruction.ModMplsLabelInstruction.class);
Ray Milkey125572b2016-02-22 16:48:17 -0800593 assertThat(modMplsLabelInstruction.label(), is(equalTo(mplsLabel)));
Ray Milkey0d338052014-11-21 16:40:12 -0800594 assertThat(modMplsLabelInstruction.subtype(),
595 is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL)));
596 }
597
598 /**
Ray Milkey3564a8c2015-12-14 11:43:12 -0800599 * Test the equals(), hashCode() and toString() methods of the
Ray Milkey0d338052014-11-21 16:40:12 -0800600 * ModMplsLabelInstruction class.
601 */
Ray Milkey0d338052014-11-21 16:40:12 -0800602 @Test
603 public void testModMplsLabelInstructionEquals() throws Exception {
604 checkEqualsAndToString(modMplsLabelInstruction1,
605 sameAsModMplsLabelInstruction1,
606 modMplsLabelInstruction2);
607 }
Ray Milkey78081052014-11-05 10:38:12 -0800608
Hyunsun Moond0533e52015-07-28 18:12:43 -0700609 // ModTunnelIdInstruction
610
611 private final long tunnelId1 = 1L;
612 private final long tunnelId2 = 2L;
613 private final Instruction modTunnelId1 = Instructions.modTunnelId(tunnelId1);
614 private final Instruction sameAsModTunnelId1 = Instructions.modTunnelId(tunnelId1);
615 private final Instruction modTunnelId2 = Instructions.modTunnelId(tunnelId2);
616
617 /**
618 * Test the modTunnelId method.
619 */
620 @Test
621 public void testModTunnelIdMethod() {
622 final Instruction instruction = Instructions.modTunnelId(tunnelId1);
623 final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction =
624 checkAndConvert(instruction, Instruction.Type.L2MODIFICATION,
625 L2ModificationInstruction.ModTunnelIdInstruction.class);
626 assertThat(modTunnelIdInstruction.tunnelId(), is(equalTo(tunnelId1)));
627 assertThat(modTunnelIdInstruction.subtype(),
628 is(equalTo(L2ModificationInstruction.L2SubType.TUNNEL_ID)));
629 }
630
631 /***
632 * Test the equals() method of the ModTunnelIdInstruction class.
633 */
634 @Test
635 public void testModTunnelIdInstructionEquals() throws Exception {
636 checkEqualsAndToString(modTunnelId1, sameAsModTunnelId1, modTunnelId2);
637 }
638
639 /**
640 * Test the hashCode() method of the ModTunnelIdInstruction class.
641 */
642 @Test
643 public void testModTunnelIdInstructionHashCode() {
644 assertThat(modTunnelId1.hashCode(), is(equalTo(sameAsModTunnelId1.hashCode())));
645 assertThat(modTunnelId1.hashCode(), is(not(equalTo(modTunnelId2.hashCode()))));
646 }
647
648 // ModTransportPortInstruction
649
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700650 private final TpPort tpPort1 = TpPort.tpPort(1);
651 private final TpPort tpPort2 = TpPort.tpPort(2);
652 private final Instruction modTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
653 private final Instruction sameAsModTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
654 private final Instruction modTransportPortInstruction2 = Instructions.modTcpSrc(tpPort2);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700655
656 /**
657 * Test the modTcpSrc() method.
658 */
659 @Test
660 public void testModTcpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700661 final Instruction instruction = Instructions.modTcpSrc(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700662 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
663 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
664 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700665 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700666 assertThat(modTransportPortInstruction.subtype(),
667 is(equalTo(L4ModificationInstruction.L4SubType.TCP_SRC)));
668 }
669
670 /**
671 * Test the modTcpDst() method.
672 */
673 @Test
674 public void testModTcpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700675 final Instruction instruction = Instructions.modTcpDst(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700676 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
677 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
678 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700679 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700680 assertThat(modTransportPortInstruction.subtype(),
681 is(equalTo(L4ModificationInstruction.L4SubType.TCP_DST)));
682 }
683
684 /**
685 * Test the modUdpSrc() method.
686 */
687 @Test
688 public void testModUdpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700689 final Instruction instruction = Instructions.modUdpSrc(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700690 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
691 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
692 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700693 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700694 assertThat(modTransportPortInstruction.subtype(),
695 is(equalTo(L4ModificationInstruction.L4SubType.UDP_SRC)));
696 }
697
698 /**
699 * Test the modUdpDst() method.
700 */
701 @Test
702 public void testModUdpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700703 final Instruction instruction = Instructions.modUdpDst(tpPort1);
Hyunsun Moond0533e52015-07-28 18:12:43 -0700704 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
705 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
706 L4ModificationInstruction.ModTransportPortInstruction.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700707 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
Hyunsun Moond0533e52015-07-28 18:12:43 -0700708 assertThat(modTransportPortInstruction.subtype(),
709 is(equalTo(L4ModificationInstruction.L4SubType.UDP_DST)));
710 }
711
712 /**
713 * Test the equals() method of the ModTransportPortInstruction class.
714 */
715 @Test
716 public void testModTransportPortInstructionEquals() throws Exception {
717 checkEqualsAndToString(modTransportPortInstruction1,
718 sameAsModTransportPortInstruction1,
719 modTransportPortInstruction2);
720 }
721
722 /**
723 * Test the hashCode() method of the ModTransportPortInstruction class.
724 */
725 @Test
726 public void testModTransportPortInstructionHashCode() {
727 assertThat(modTransportPortInstruction1.hashCode(),
728 is(equalTo(sameAsModTransportPortInstruction1.hashCode())));
729 assertThat(modTransportPortInstruction1.hashCode(),
730 is(not(equalTo(modTransportPortInstruction2.hashCode()))));
731 }
Ray Milkey3564a8c2015-12-14 11:43:12 -0800732
733 // GroupInstruction
734
735 private final GroupId groupId1 = new DefaultGroupId(1);
736 private final GroupId groupId2 = new DefaultGroupId(2);
737 private final Instruction groupInstruction1 = Instructions.createGroup(groupId1);
738 private final Instruction sameAsGroupInstruction1 = Instructions.createGroup(groupId1);
739 private final Instruction groupInstruction2 = Instructions.createGroup(groupId2);
740
741 /**
742 * Test the create group method.
743 */
744 @Test
745 public void testCreateGroupMethod() {
746 final Instruction instruction = Instructions.createGroup(groupId1);
747 final Instructions.GroupInstruction groupInstruction =
748 checkAndConvert(instruction,
749 Instruction.Type.GROUP,
750 Instructions.GroupInstruction.class);
751 assertThat(groupInstruction.groupId(), is(equalTo(groupId1)));
752 }
753
754 /**
755 * Test the equals() method of the GroupInstruction class.
756 */
757
758 @Test
759 public void testGroupInstructionEquals() {
760 checkEqualsAndToString(groupInstruction1,
761 sameAsGroupInstruction1,
762 groupInstruction2);
763 }
764
765 // SetQueueInstruction
766
767 private final Instruction setQueueInstruction1 = Instructions.setQueue(1, port1);
768 private final Instruction sameAsSetQueueInstruction1 = Instructions.setQueue(1, port1);
769 private final Instruction setQueueInstruction2 = Instructions.setQueue(1, port2);
770
771 /**
772 * Test the set queue method.
773 */
774 @Test
775 public void testSetQueueMethod() {
776 final Instruction instruction = Instructions.setQueue(2, port2);
777 final Instructions.SetQueueInstruction setQueueInstruction =
778 checkAndConvert(instruction,
779 Instruction.Type.QUEUE,
780 Instructions.SetQueueInstruction.class);
781 assertThat(setQueueInstruction.queueId(), is(2L));
782 assertThat(setQueueInstruction.port(), is(port2));
783 }
784
785 /**
786 * Test the equals() method of the SetQueueInstruction class.
787 */
788 @Test
789 public void testSetQueueInstructionEquals() {
790 checkEqualsAndToString(setQueueInstruction1,
791 sameAsSetQueueInstruction1,
792 setQueueInstruction2);
793 }
794
795 // MeterInstruction
796
797 MeterId meterId1 = MeterId.meterId(1);
798 MeterId meterId2 = MeterId.meterId(2);
799 private final Instruction meterInstruction1 = Instructions.meterTraffic(meterId1);
800 private final Instruction sameAsMeterInstruction1 = Instructions.meterTraffic(meterId1);
801 private final Instruction meterInstruction2 = Instructions.meterTraffic(meterId2);
802
803 /**
804 * Test the meter traffic method.
805 */
806 @Test
807 public void testMeterTrafficMethod() {
808 final Instruction instruction = Instructions.meterTraffic(meterId1);
809 final Instructions.MeterInstruction meterInstruction =
810 checkAndConvert(instruction,
811 Instruction.Type.METER,
812 Instructions.MeterInstruction.class);
813 assertThat(meterInstruction.meterId(), is(meterId1));
814 }
815
816 /**
817 * Test the equals() method of the MeterInstruction class.
818 */
819 @Test
820 public void testMeterTrafficInstructionEquals() {
821 checkEqualsAndToString(meterInstruction1,
822 sameAsMeterInstruction1,
823 meterInstruction2);
824 }
825
826 // TableTypeTransition
827
828 private final Instruction transitionInstruction1 = Instructions.transition(1);
829 private final Instruction sameAsTransitionInstruction1 = Instructions.transition(1);
830 private final Instruction transitionInstruction2 = Instructions.transition(2);
831
832 /**
833 * Test the transition method.
834 */
835 @Test
836 public void testTransitionMethod() {
837 final Instruction instruction = Instructions.transition(1);
838 final Instructions.TableTypeTransition tableInstruction =
839 checkAndConvert(instruction,
840 Instruction.Type.TABLE,
841 Instructions.TableTypeTransition.class);
842 assertThat(tableInstruction.tableId(), is(1));
843 }
844
845 /**
846 * Test the equals() method of the TableTypeTransition class.
847 */
848 @Test
849 public void testTableTypeTransitionInstructionEquals() {
850 checkEqualsAndToString(transitionInstruction1,
851 sameAsTransitionInstruction1,
852 transitionInstruction2);
853 }
854
855 // MetadataInstruction
856
857 long metadata1 = 111L;
858 long metadataMask1 = 222L;
859 long metadata2 = 333L;
860 long metadataMask2 = 444L;
861
862 private final Instruction metadataInstruction1 =
863 Instructions.writeMetadata(metadata1, metadataMask1);
864 private final Instruction sameAsMetadataInstruction1 =
865 Instructions.writeMetadata(metadata1, metadataMask1);
866 private final Instruction metadataInstruction2 =
867 Instructions.writeMetadata(metadata2, metadataMask2);
868
869 /**
870 * Test the write metadata method.
871 */
872 @Test
873 public void testWriteMetadataMethod() {
874 final Instruction instruction =
875 Instructions.writeMetadata(metadata1, metadataMask1);
876 final Instructions.MetadataInstruction metadataInstruction =
877 checkAndConvert(instruction,
878 Instruction.Type.METADATA,
879 Instructions.MetadataInstruction.class);
880 assertThat(metadataInstruction.metadata(), is(metadata1));
881 assertThat(metadataInstruction.metadataMask(), is(metadataMask1));
882 }
883
884 /**
885 * Test the equals() method of the MetadataInstruction class.
886 */
887 @Test
888 public void testInstructionEquals() {
889 checkEqualsAndToString(metadataInstruction1,
890 sameAsMetadataInstruction1,
891 metadataInstruction2);
892 }
893
894 // ExtensionInstructionWrapper
895
896 class MockExtensionTreatment implements ExtensionTreatment {
897 int type;
898
899 MockExtensionTreatment(int type) {
900 this.type = type;
901 }
902 @Override
903 public ExtensionTreatmentType type() {
904 return new ExtensionTreatmentType(type);
905 }
906
907 @Override
908 public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException {
909
910 }
911
912 @Override
913 public <T> T getPropertyValue(String key) throws ExtensionPropertyException {
914 return null;
915 }
916
917 @Override
918 public List<String> getProperties() {
919 return null;
920 }
921
922 @Override
923 public byte[] serialize() {
924 return new byte[0];
925 }
926
927 @Override
928 public void deserialize(byte[] data) {
929
930 }
931 }
932
933 ExtensionTreatment extensionTreatment1 = new MockExtensionTreatment(111);
934 ExtensionTreatment extensionTreatment2 = new MockExtensionTreatment(222);
935
936 DeviceId deviceId1 = DeviceId.deviceId("of:1");
937 DeviceId deviceId2 = DeviceId.deviceId("of:2");
938
939 private final Instruction extensionInstruction1 =
940 Instructions.extension(extensionTreatment1, deviceId1);
941 private final Instruction sameAsExtensionInstruction1 =
942 Instructions.extension(extensionTreatment1, deviceId1);
943 private final Instruction extensionInstruction2 =
944 Instructions.extension(extensionTreatment2, deviceId2);
945
946 /**
947 * Test the extension method.
948 */
949 @Test
950 public void testExtensionMethod() {
951 final Instruction instruction =
952 Instructions.extension(extensionTreatment1, deviceId1);
953 final Instructions.ExtensionInstructionWrapper extensionInstructionWrapper =
954 checkAndConvert(instruction,
955 Instruction.Type.EXTENSION,
956 Instructions.ExtensionInstructionWrapper.class);
957 assertThat(extensionInstructionWrapper.deviceId(), is(deviceId1));
958 assertThat(extensionInstructionWrapper.extensionInstruction(), is(extensionTreatment1));
959 }
960
961 /**
962 * Test the equals() method of the ExtensionInstructionWrapper class.
963 */
964 @Test
965 public void testExtensionInstructionWrapperEquals() {
966 checkEqualsAndToString(extensionInstruction1,
967 sameAsExtensionInstruction1,
968 extensionInstruction2);
969 }
970
Jian Li11260a02016-05-19 13:07:22 -0700971 // ModMplsHeaderInstructions
Ray Milkey3564a8c2015-12-14 11:43:12 -0800972
973 private final EthType ethType1 = new EthType(1);
974 private final EthType ethType2 = new EthType(2);
Jian Li11260a02016-05-19 13:07:22 -0700975 private final Instruction modMplsHeaderInstruction1 = Instructions.popMpls(ethType1);
976 private final Instruction sameAsModMplsHeaderInstruction1 = Instructions.popMpls(ethType1);
977 private final Instruction modMplsHeaderInstruction2 = Instructions.popMpls(ethType2);
Ray Milkey3564a8c2015-12-14 11:43:12 -0800978
979 /**
980 * Test the pushMpls method.
981 */
982 @Test
983 public void testPushMplsMethod() {
984 final Instruction instruction = Instructions.pushMpls();
Jian Li11260a02016-05-19 13:07:22 -0700985 final L2ModificationInstruction.ModMplsHeaderInstruction pushHeaderInstruction =
Ray Milkey3564a8c2015-12-14 11:43:12 -0800986 checkAndConvert(instruction,
987 Instruction.Type.L2MODIFICATION,
Jian Li11260a02016-05-19 13:07:22 -0700988 L2ModificationInstruction.ModMplsHeaderInstruction.class);
Ray Milkey3564a8c2015-12-14 11:43:12 -0800989 assertThat(pushHeaderInstruction.ethernetType().toString(),
990 is(EthType.EtherType.MPLS_MULTICAST.toString()));
991 assertThat(pushHeaderInstruction.subtype(),
992 is(L2ModificationInstruction.L2SubType.MPLS_PUSH));
993 }
994
995 /**
996 * Test the popMpls method.
997 */
998 @Test
999 public void testPopMplsMethod() {
1000 final Instruction instruction = Instructions.popMpls();
Jian Li11260a02016-05-19 13:07:22 -07001001 final L2ModificationInstruction.ModMplsHeaderInstruction pushHeaderInstruction =
Ray Milkey3564a8c2015-12-14 11:43:12 -08001002 checkAndConvert(instruction,
1003 Instruction.Type.L2MODIFICATION,
Jian Li11260a02016-05-19 13:07:22 -07001004 L2ModificationInstruction.ModMplsHeaderInstruction.class);
Ray Milkey3564a8c2015-12-14 11:43:12 -08001005 assertThat(pushHeaderInstruction.ethernetType().toString(),
1006 is(EthType.EtherType.MPLS_MULTICAST.toString()));
1007 assertThat(pushHeaderInstruction.subtype(),
1008 is(L2ModificationInstruction.L2SubType.MPLS_POP));
1009 }
1010
1011 /**
1012 * Test the popMpls(EtherType) method.
1013 */
1014 @Test
1015 public void testPopMplsEthertypeMethod() {
1016 final Instruction instruction = Instructions.popMpls(new EthType(1));
Jian Li11260a02016-05-19 13:07:22 -07001017 final L2ModificationInstruction.ModMplsHeaderInstruction pushHeaderInstruction =
Ray Milkey3564a8c2015-12-14 11:43:12 -08001018 checkAndConvert(instruction,
1019 Instruction.Type.L2MODIFICATION,
Jian Li11260a02016-05-19 13:07:22 -07001020 L2ModificationInstruction.ModMplsHeaderInstruction.class);
Ray Milkey3564a8c2015-12-14 11:43:12 -08001021 assertThat(pushHeaderInstruction.ethernetType().toShort(), is((short) 1));
1022 assertThat(pushHeaderInstruction.subtype(),
1023 is(L2ModificationInstruction.L2SubType.MPLS_POP));
1024 }
1025
1026 /**
1027 * Test the pushVlan method.
1028 */
1029 @Test
1030 public void testPushVlanMethod() {
1031 final Instruction instruction = Instructions.pushVlan();
Jian Li11260a02016-05-19 13:07:22 -07001032 final L2ModificationInstruction.ModVlanHeaderInstruction pushHeaderInstruction =
Ray Milkey3564a8c2015-12-14 11:43:12 -08001033 checkAndConvert(instruction,
1034 Instruction.Type.L2MODIFICATION,
Jian Li11260a02016-05-19 13:07:22 -07001035 L2ModificationInstruction.ModVlanHeaderInstruction.class);
Ray Milkey3564a8c2015-12-14 11:43:12 -08001036 assertThat(pushHeaderInstruction.ethernetType().toString(),
1037 is(EthType.EtherType.VLAN.toString()));
1038 assertThat(pushHeaderInstruction.subtype(),
1039 is(L2ModificationInstruction.L2SubType.VLAN_PUSH));
1040 }
1041
1042 /**
1043 * Tests the equals(), hashCode() and toString() methods of the
Jian Li11260a02016-05-19 13:07:22 -07001044 * ModMplsHeaderInstructions class.
Ray Milkey3564a8c2015-12-14 11:43:12 -08001045 */
1046
1047 @Test
Jian Li11260a02016-05-19 13:07:22 -07001048 public void testModMplsHeaderInstructionsEquals() {
1049 checkEqualsAndToString(modMplsHeaderInstruction1,
1050 sameAsModMplsHeaderInstruction1,
1051 modMplsHeaderInstruction2);
Ray Milkey3564a8c2015-12-14 11:43:12 -08001052 }
1053
1054 // ModMplsTtlInstruction
1055
1056 private final Instruction modMplsTtlInstruction1 = Instructions.decMplsTtl();
1057 private final Instruction sameAsModMplsTtlInstruction1 = Instructions.decMplsTtl();
1058
1059 /**
1060 * Test the modMplsBos() method.
1061 */
1062 @Test
1063 public void testDecMplsTtlMethod() {
1064 final Instruction instruction = Instructions.decMplsTtl();
1065 final L2ModificationInstruction.ModMplsTtlInstruction modMplsTtlInstruction =
1066 checkAndConvert(instruction,
1067 Instruction.Type.L2MODIFICATION,
1068 L2ModificationInstruction.ModMplsTtlInstruction.class);
1069 assertThat(modMplsTtlInstruction.subtype(),
1070 is(L2ModificationInstruction.L2SubType.DEC_MPLS_TTL));
1071 }
1072
1073 /**
1074 * Tests the equals(), hashCode() and toString() methods of the
Jian Li11260a02016-05-19 13:07:22 -07001075 * ModMplsTtlInstructions class.
Ray Milkey3564a8c2015-12-14 11:43:12 -08001076 */
1077
1078 @Test
1079 public void testMplsTtlInstructionsEquals() {
1080 new EqualsTester()
1081 .addEqualityGroup(modMplsTtlInstruction1, sameAsModMplsTtlInstruction1)
1082 .testEquals();
1083 }
1084
1085 // ModMplsBosInstruction
1086
1087 private final Instruction modMplsBosInstruction1 = Instructions.modMplsBos(true);
1088 private final Instruction sameAsModMplsBosInstruction1 = Instructions.modMplsBos(true);
1089 private final Instruction modMplsBosInstruction2 = Instructions.modMplsBos(false);
1090
1091 /**
1092 * Test the modMplsBos() method.
1093 */
1094 @Test
1095 public void testModMplsBosMethod() {
1096 final Instruction instruction = Instructions.modMplsBos(true);
1097 final L2ModificationInstruction.ModMplsBosInstruction modMplsBosInstruction =
1098 checkAndConvert(instruction,
1099 Instruction.Type.L2MODIFICATION,
1100 L2ModificationInstruction.ModMplsBosInstruction.class);
1101 assertThat(modMplsBosInstruction.subtype(),
1102 is(L2ModificationInstruction.L2SubType.MPLS_BOS));
1103 assertThat(modMplsBosInstruction.mplsBos(), is(true));
1104 }
1105
1106 /**
1107 * Tests the equals(), hashCode() and toString() methods of the
Jian Li11260a02016-05-19 13:07:22 -07001108 * ModMplsBosInstructions class.
Ray Milkey3564a8c2015-12-14 11:43:12 -08001109 */
1110
1111 @Test
1112 public void testMplsBosInstructionsEquals() {
1113 checkEqualsAndToString(modMplsBosInstruction1,
1114 sameAsModMplsBosInstruction1,
1115 modMplsBosInstruction2);
1116 }
1117
Jian Li11260a02016-05-19 13:07:22 -07001118 // ModVlanHeaderInstruction
Ray Milkey3564a8c2015-12-14 11:43:12 -08001119
Jian Li11260a02016-05-19 13:07:22 -07001120 private final Instruction modVlanHeaderInstruction1 = Instructions.popVlan();
1121 private final Instruction sameAsModVlanHeaderInstruction1 = Instructions.popVlan();
Ray Milkey3564a8c2015-12-14 11:43:12 -08001122
1123 /**
1124 * Test the popVlan method.
1125 */
1126 @Test
1127 public void testPopVlanMethod() {
1128 final Instruction instruction = Instructions.popVlan();
Jian Li11260a02016-05-19 13:07:22 -07001129 final L2ModificationInstruction.ModVlanHeaderInstruction popVlanInstruction =
Ray Milkey3564a8c2015-12-14 11:43:12 -08001130 checkAndConvert(instruction,
1131 Instruction.Type.L2MODIFICATION,
Jian Li11260a02016-05-19 13:07:22 -07001132 L2ModificationInstruction.ModVlanHeaderInstruction.class);
Ray Milkey3564a8c2015-12-14 11:43:12 -08001133 assertThat(popVlanInstruction.subtype(),
1134 is(L2ModificationInstruction.L2SubType.VLAN_POP));
1135 }
1136
1137 /**
1138 * Tests the equals(), hashCode() and toString() methods of the
Jian Li11260a02016-05-19 13:07:22 -07001139 * ModVlanHeaderInstructions class.
Ray Milkey3564a8c2015-12-14 11:43:12 -08001140 */
1141
1142 @Test
Jian Li11260a02016-05-19 13:07:22 -07001143 public void testModVlanHeaderInstructionsEquals() {
Ray Milkey3564a8c2015-12-14 11:43:12 -08001144 new EqualsTester()
Jian Li11260a02016-05-19 13:07:22 -07001145 .addEqualityGroup(modVlanHeaderInstruction1, sameAsModVlanHeaderInstruction1)
Ray Milkey3564a8c2015-12-14 11:43:12 -08001146 .testEquals();
1147 }
1148
1149 // ModArpIPInstruction
1150
1151 private final Instruction modArpIPInstruction1 = Instructions.modArpSpa(ip41);
1152 private final Instruction sameAsModArpIPInstruction1 = Instructions.modArpSpa(ip41);
1153 private final Instruction modArpIPInstruction2 = Instructions.modArpSpa(ip42);
1154
1155 /**
1156 * Test the modArpSpa() method.
1157 */
1158 @Test
1159 public void testModArpSpaMethod() {
1160 final Instruction instruction = Instructions.modArpSpa(ip41);
1161 final L3ModificationInstruction.ModArpIPInstruction modArpIPInstruction =
1162 checkAndConvert(instruction,
1163 Instruction.Type.L3MODIFICATION,
1164 L3ModificationInstruction.ModArpIPInstruction.class);
1165 assertThat(modArpIPInstruction.subtype(),
1166 is(L3ModificationInstruction.L3SubType.ARP_SPA));
1167 assertThat(modArpIPInstruction.ip(), is(ip41));
1168 }
1169
1170 /**
1171 * Tests the equals(), hashCode() and toString() methods of the
1172 * ModArpIPInstruction class.
1173 */
1174
1175 @Test
1176 public void testModArpIPInstructionEquals() {
1177 checkEqualsAndToString(modArpIPInstruction1,
1178 sameAsModArpIPInstruction1,
1179 modArpIPInstruction2);
1180 }
1181
1182 // ModArpEthInstruction
1183
1184 private final Instruction modArpEthInstruction1 = Instructions.modArpSha(mac1);
1185 private final Instruction sameAsModArpEthInstruction1 = Instructions.modArpSha(mac1);
1186 private final Instruction modArpEthInstruction2 = Instructions.modArpSha(mac2);
1187
1188 /**
1189 * Test the modArpSha() method.
1190 */
1191 @Test
1192 public void testModArpShaMethod() {
1193 final Instruction instruction = Instructions.modArpSha(mac1);
1194 final L3ModificationInstruction.ModArpEthInstruction modArpEthInstruction =
1195 checkAndConvert(instruction,
1196 Instruction.Type.L3MODIFICATION,
1197 L3ModificationInstruction.ModArpEthInstruction.class);
1198 assertThat(modArpEthInstruction.subtype(),
1199 is(L3ModificationInstruction.L3SubType.ARP_SHA));
1200 assertThat(modArpEthInstruction.mac(), is(mac1));
1201 }
1202
1203 /**
1204 * Tests the equals(), hashCode() and toString() methods of the
1205 * ModArpIPInstruction class.
1206 */
1207
1208 @Test
1209 public void testModArpEthInstructionEquals() {
1210 checkEqualsAndToString(modArpEthInstruction1,
1211 sameAsModArpEthInstruction1,
1212 modArpEthInstruction2);
1213 }
1214
1215 // ModArpOpInstruction
1216
1217 private final Instruction modArpOpInstruction1 = Instructions.modL3ArpOp((short) 1);
1218 private final Instruction sameAsModArpOpInstruction1 = Instructions.modL3ArpOp((short) 1);
1219 private final Instruction modArpOpInstruction2 = Instructions.modL3ArpOp((short) 2);
1220
1221 /**
1222 * Test the modL3ArpOp() method.
1223 */
1224 @Test
1225 public void testModArpModL3ArpOpMethod() {
1226 final Instruction instruction = Instructions.modL3ArpOp((short) 1);
1227 final L3ModificationInstruction.ModArpOpInstruction modArpEthInstruction =
1228 checkAndConvert(instruction,
1229 Instruction.Type.L3MODIFICATION,
1230 L3ModificationInstruction.ModArpOpInstruction.class);
1231 assertThat(modArpEthInstruction.subtype(),
1232 is(L3ModificationInstruction.L3SubType.ARP_OP));
1233 assertThat(modArpEthInstruction.op(), is(1L));
1234 }
1235
1236 /**
1237 * Tests the equals(), hashCode() and toString() methods of the
1238 * ModArpIPInstruction class.
1239 */
1240
1241 @Test
1242 public void testModArpOpInstructionEquals() {
1243 checkEqualsAndToString(modArpOpInstruction1,
1244 sameAsModArpOpInstruction1,
1245 modArpOpInstruction2);
1246 }
1247
1248 // ModTtlInstruction
1249
1250 private final Instruction modArpTtlInstruction1 = Instructions.copyTtlIn();
1251 private final Instruction sameAsModArpTtlInstruction1 = Instructions.copyTtlIn();
1252 private final Instruction modArpTtlInstruction2 = Instructions.copyTtlOut();
1253 private final Instruction modArpTtlInstruction3 = Instructions.decNwTtl();
1254
1255 /**
1256 * Test the copyTtlIn() method.
1257 */
1258 @Test
1259 public void testCopyTtlInMethod() {
1260 final Instruction instruction = Instructions.copyTtlIn();
1261 final L3ModificationInstruction.ModTtlInstruction modTtlInstruction =
1262 checkAndConvert(instruction,
1263 Instruction.Type.L3MODIFICATION,
1264 L3ModificationInstruction.ModTtlInstruction.class);
1265 assertThat(modTtlInstruction.subtype(),
1266 is(L3ModificationInstruction.L3SubType.TTL_IN));
1267 }
1268
1269 /**
1270 * Test the copyTtlOut() method.
1271 */
1272 @Test
1273 public void testCopyTtlOutMethod() {
1274 final Instruction instruction = Instructions.copyTtlOut();
1275 final L3ModificationInstruction.ModTtlInstruction modTtlInstruction =
1276 checkAndConvert(instruction,
1277 Instruction.Type.L3MODIFICATION,
1278 L3ModificationInstruction.ModTtlInstruction.class);
1279 assertThat(modTtlInstruction.subtype(),
1280 is(L3ModificationInstruction.L3SubType.TTL_OUT));
1281 }
1282
1283 /**
1284 * Test the decNwTtl() method.
1285 */
1286 @Test
1287 public void testDecNwTtlOutMethod() {
1288 final Instruction instruction = Instructions.decNwTtl();
1289 final L3ModificationInstruction.ModTtlInstruction modTtlInstruction =
1290 checkAndConvert(instruction,
1291 Instruction.Type.L3MODIFICATION,
1292 L3ModificationInstruction.ModTtlInstruction.class);
1293 assertThat(modTtlInstruction.subtype(),
1294 is(L3ModificationInstruction.L3SubType.DEC_TTL));
1295 }
1296
1297 /**
1298 * Tests the equals(), hashCode() and toString() methods of the
1299 * ModArpIPInstruction class.
1300 */
1301
1302 @Test
1303 public void testModTtlInstructionEquals() {
1304 new EqualsTester()
1305 .addEqualityGroup(modArpTtlInstruction1, sameAsModArpTtlInstruction1)
1306 .addEqualityGroup(modArpTtlInstruction2)
1307 .addEqualityGroup(modArpTtlInstruction3)
1308 .testEquals();
1309 }
1310
Ray Milkey78081052014-11-05 10:38:12 -08001311}