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