2 * Copyright 2014-2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.net.flow.instructions;
18 import org.junit.Test;
19 import org.onlab.packet.IpAddress;
20 import org.onlab.packet.MacAddress;
21 import org.onlab.packet.MplsLabel;
22 import org.onlab.packet.TpPort;
23 import org.onlab.packet.VlanId;
24 import org.onosproject.net.ChannelSpacing;
25 import org.onosproject.net.GridType;
26 import org.onosproject.net.IndexedLambda;
27 import org.onosproject.net.Lambda;
28 import org.onosproject.net.PortNumber;
30 import com.google.common.testing.EqualsTester;
32 import static org.hamcrest.MatcherAssert.assertThat;
33 import static org.hamcrest.Matchers.equalTo;
34 import static org.hamcrest.Matchers.instanceOf;
35 import static org.hamcrest.Matchers.is;
36 import static org.hamcrest.Matchers.not;
37 import static org.hamcrest.Matchers.notNullValue;
38 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
39 import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
40 import static org.onosproject.net.PortNumber.portNumber;
43 * Unit tests for the Instructions class.
45 public class InstructionsTest {
48 * Checks that a Criterion object has the proper type, and then converts
49 * it to the proper type.
51 * @param instruction Instruction object to convert
52 * @param type Enumerated type value for the Criterion class
53 * @param clazz Desired Criterion class
54 * @param <T> The type the caller wants returned
55 * @return converted object
57 @SuppressWarnings("unchecked")
58 private <T> T checkAndConvert(Instruction instruction, Instruction.Type type, Class clazz) {
59 assertThat(instruction, is(notNullValue()));
60 assertThat(instruction.type(), is(equalTo(type)));
61 assertThat(instruction, instanceOf(clazz));
62 return (T) instruction;
66 * Checks the equals() and toString() methods of a Criterion class.
68 * @param c1 first object to compare
69 * @param c1match object that should be equal to the first
70 * @param c2 object that should be not equal to the first
71 * @param <T> type of the arguments
73 private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match,
77 .addEqualityGroup(c1, c1match)
83 * Checks that Instructions is a proper utility class.
86 public void testInstructionsUtilityClass() {
87 assertThatClassIsUtility(Instructions.class);
91 * Checks that the Instruction class implementations are immutable.
94 public void testImmutabilityOfInstructions() {
95 assertThatClassIsImmutable(Instructions.DropInstruction.class);
96 assertThatClassIsImmutable(Instructions.OutputInstruction.class);
97 assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class);
98 assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class);
99 assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class);
100 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class);
101 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class);
102 assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class);
103 assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
104 assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class);
105 assertThatClassIsImmutable(L2ModificationInstruction.PushHeaderInstructions.class);
110 private final Instructions.DropInstruction drop1 = Instructions.createDrop();
111 private final Instructions.DropInstruction drop2 = Instructions.createDrop();
114 * Test the createDrop method.
117 public void testCreateDropMethod() {
118 Instructions.DropInstruction instruction = Instructions.createDrop();
119 checkAndConvert(instruction,
120 Instruction.Type.DROP,
121 Instructions.DropInstruction.class);
125 * Test the equals() method of the DropInstruction class.
129 public void testDropInstructionEquals() throws Exception {
130 assertThat(drop1, is(equalTo(drop2)));
134 * Test the hashCode() method of the DropInstruction class.
138 public void testDropInstructionHashCode() {
139 assertThat(drop1.hashCode(), is(equalTo(drop2.hashCode())));
144 private final PortNumber port1 = portNumber(1);
145 private final PortNumber port2 = portNumber(2);
146 private final Instructions.OutputInstruction output1 = Instructions.createOutput(port1);
147 private final Instructions.OutputInstruction sameAsOutput1 = Instructions.createOutput(port1);
148 private final Instructions.OutputInstruction output2 = Instructions.createOutput(port2);
151 * Test the createOutput method.
154 public void testCreateOutputMethod() {
155 final Instruction instruction = Instructions.createOutput(port2);
156 final Instructions.OutputInstruction outputInstruction =
157 checkAndConvert(instruction,
158 Instruction.Type.OUTPUT,
159 Instructions.OutputInstruction.class);
160 assertThat(outputInstruction.port(), is(equalTo(port2)));
165 * Test the equals() method of the OutputInstruction class.
169 public void testOutputInstructionEquals() throws Exception {
170 checkEqualsAndToString(output1, sameAsOutput1, output2);
174 * Test the hashCode() method of the OutputInstruction class.
178 public void testOutputInstructionHashCode() {
179 assertThat(output1.hashCode(), is(equalTo(sameAsOutput1.hashCode())));
180 assertThat(output1.hashCode(), is(not(equalTo(output2.hashCode()))));
183 // ModLambdaInstruction
185 private final IndexedLambda lambda1 = new IndexedLambda(1);
186 private final IndexedLambda lambda2 = new IndexedLambda(2);
187 private final Instruction lambdaInstruction1 = Instructions.modL0Lambda(lambda1);
188 private final Instruction sameAsLambdaInstruction1 = Instructions.modL0Lambda(lambda1);
189 private final Instruction lambdaInstruction2 = Instructions.modL0Lambda(lambda2);
192 * Test the modL0Lambda method.
195 public void testCreateLambdaMethod() {
196 final Instruction instruction = Instructions.modL0Lambda(lambda1);
197 final L0ModificationInstruction.ModLambdaInstruction lambdaInstruction =
198 checkAndConvert(instruction,
199 Instruction.Type.L0MODIFICATION,
200 L0ModificationInstruction.ModLambdaInstruction.class);
201 assertThat(lambdaInstruction.lambda(), is(equalTo((short) lambda1.index())));
205 * Test the equals() method of the ModLambdaInstruction class.
209 public void testModLambdaInstructionEquals() throws Exception {
210 checkEqualsAndToString(lambdaInstruction1,
211 sameAsLambdaInstruction1,
216 * Test the hashCode() method of the ModLambdaInstruction class.
220 public void testModLambdaInstructionHashCode() {
221 assertThat(lambdaInstruction1.hashCode(),
222 is(equalTo(sameAsLambdaInstruction1.hashCode())));
223 assertThat(lambdaInstruction1.hashCode(),
224 is(not(equalTo(lambdaInstruction2.hashCode()))));
227 private final Lambda och1 = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
228 private final Lambda och2 = Lambda.ochSignal(GridType.CWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
229 private final Instruction ochInstruction1 = Instructions.modL0Lambda(och1);
230 private final Instruction sameAsOchInstruction1 = Instructions.modL0Lambda(och1);
231 private final Instruction ochInstruction2 = Instructions.modL0Lambda(och2);
234 * Test the modL0Lambda().
237 public void testModL0LambdaMethod() {
238 Instruction instruction = Instructions.modL0Lambda(och1);
239 L0ModificationInstruction.ModOchSignalInstruction ochInstruction =
240 checkAndConvert(instruction, Instruction.Type.L0MODIFICATION,
241 L0ModificationInstruction.ModOchSignalInstruction.class);
242 assertThat(ochInstruction.lambda(), is(och1));
246 * Test the equals() method of the ModOchSignalInstruction class.
249 public void testModOchSignalInstructionEquals() {
250 checkEqualsAndToString(ochInstruction1, sameAsOchInstruction1, ochInstruction2);
254 * Test the hashCode() method of the ModOchSignalInstruction class.
257 public void testModOchSignalInstructionHashCode() {
258 assertThat(ochInstruction1.hashCode(), is(sameAsOchInstruction1.hashCode()));
259 assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode())));
262 // ModEtherInstruction
264 private static final String MAC1 = "00:00:00:00:00:01";
265 private static final String MAC2 = "00:00:00:00:00:02";
266 private final MacAddress mac1 = MacAddress.valueOf(MAC1);
267 private final MacAddress mac2 = MacAddress.valueOf(MAC2);
268 private final Instruction modEtherInstruction1 = Instructions.modL2Src(mac1);
269 private final Instruction sameAsModEtherInstruction1 = Instructions.modL2Src(mac1);
270 private final Instruction modEtherInstruction2 = Instructions.modL2Src(mac2);
273 * Test the modL2Src method.
276 public void testModL2SrcMethod() {
277 final Instruction instruction = Instructions.modL2Src(mac1);
278 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
279 checkAndConvert(instruction,
280 Instruction.Type.L2MODIFICATION,
281 L2ModificationInstruction.ModEtherInstruction.class);
282 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
283 assertThat(modEtherInstruction.subtype(),
284 is(equalTo(L2ModificationInstruction.L2SubType.ETH_SRC)));
288 * Test the modL2Dst method.
291 public void testModL2DstMethod() {
292 final Instruction instruction = Instructions.modL2Dst(mac1);
293 final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
294 checkAndConvert(instruction,
295 Instruction.Type.L2MODIFICATION,
296 L2ModificationInstruction.ModEtherInstruction.class);
297 assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
298 assertThat(modEtherInstruction.subtype(),
299 is(equalTo(L2ModificationInstruction.L2SubType.ETH_DST)));
303 * Test the equals() method of the ModEtherInstruction class.
307 public void testModEtherInstructionEquals() throws Exception {
308 checkEqualsAndToString(modEtherInstruction1,
309 sameAsModEtherInstruction1,
310 modEtherInstruction2);
314 * Test the hashCode() method of the ModEtherInstruction class.
318 public void testModEtherInstructionHashCode() {
319 assertThat(modEtherInstruction1.hashCode(),
320 is(equalTo(sameAsModEtherInstruction1.hashCode())));
321 assertThat(modEtherInstruction1.hashCode(),
322 is(not(equalTo(modEtherInstruction2.hashCode()))));
326 // ModVlanIdInstruction
328 private final short vlan1 = 1;
329 private final short vlan2 = 2;
330 private final VlanId vlanId1 = VlanId.vlanId(vlan1);
331 private final VlanId vlanId2 = VlanId.vlanId(vlan2);
332 private final Instruction modVlanId1 = Instructions.modVlanId(vlanId1);
333 private final Instruction sameAsModVlanId1 = Instructions.modVlanId(vlanId1);
334 private final Instruction modVlanId2 = Instructions.modVlanId(vlanId2);
337 * Test the modVlanId method.
340 public void testModVlanIdMethod() {
341 final Instruction instruction = Instructions.modVlanId(vlanId1);
342 final L2ModificationInstruction.ModVlanIdInstruction modEtherInstruction =
343 checkAndConvert(instruction,
344 Instruction.Type.L2MODIFICATION,
345 L2ModificationInstruction.ModVlanIdInstruction.class);
346 assertThat(modEtherInstruction.vlanId(), is(equalTo(vlanId1)));
347 assertThat(modEtherInstruction.subtype(),
348 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_ID)));
352 * Test the equals() method of the ModVlanIdInstruction class.
356 public void testModVlanIdInstructionEquals() throws Exception {
357 checkEqualsAndToString(modVlanId1,
363 * Test the hashCode() method of the ModEtherInstruction class.
367 public void testModVlanIdInstructionHashCode() {
368 assertThat(modVlanId1.hashCode(),
369 is(equalTo(sameAsModVlanId1.hashCode())));
370 assertThat(modVlanId1.hashCode(),
371 is(not(equalTo(modVlanId2.hashCode()))));
375 // ModVlanPcpInstruction
377 private final byte vlanPcp1 = 1;
378 private final byte vlanPcp2 = 2;
379 private final Instruction modVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
380 private final Instruction sameAsModVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
381 private final Instruction modVlanPcp2 = Instructions.modVlanPcp(vlanPcp2);
384 * Test the modVlanPcp method.
387 public void testModVlanPcpMethod() {
388 final Instruction instruction = Instructions.modVlanPcp(vlanPcp1);
389 final L2ModificationInstruction.ModVlanPcpInstruction modEtherInstruction =
390 checkAndConvert(instruction,
391 Instruction.Type.L2MODIFICATION,
392 L2ModificationInstruction.ModVlanPcpInstruction.class);
393 assertThat(modEtherInstruction.vlanPcp(), is(equalTo(vlanPcp1)));
394 assertThat(modEtherInstruction.subtype(),
395 is(equalTo(L2ModificationInstruction.L2SubType.VLAN_PCP)));
399 * Test the equals() method of the ModVlanPcpInstruction class.
403 public void testModVlanPcpInstructionEquals() throws Exception {
404 checkEqualsAndToString(modVlanPcp1,
410 * Test the hashCode() method of the ModEtherInstruction class.
414 public void testModVlanPcpInstructionHashCode() {
415 assertThat(modVlanPcp1.hashCode(),
416 is(equalTo(sameAsModVlanPcp1.hashCode())));
417 assertThat(modVlanPcp1.hashCode(),
418 is(not(equalTo(modVlanPcp2.hashCode()))));
423 private static final String IP41 = "1.2.3.4";
424 private static final String IP42 = "5.6.7.8";
425 private IpAddress ip41 = IpAddress.valueOf(IP41);
426 private IpAddress ip42 = IpAddress.valueOf(IP42);
427 private final Instruction modIPInstruction1 = Instructions.modL3Src(ip41);
428 private final Instruction sameAsModIPInstruction1 = Instructions.modL3Src(ip41);
429 private final Instruction modIPInstruction2 = Instructions.modL3Src(ip42);
431 private static final String IP61 = "1111::2222";
432 private static final String IP62 = "3333::4444";
433 private IpAddress ip61 = IpAddress.valueOf(IP61);
434 private IpAddress ip62 = IpAddress.valueOf(IP62);
435 private final Instruction modIPv6Instruction1 =
436 Instructions.modL3IPv6Src(ip61);
437 private final Instruction sameAsModIPv6Instruction1 =
438 Instructions.modL3IPv6Src(ip61);
439 private final Instruction modIPv6Instruction2 =
440 Instructions.modL3IPv6Src(ip62);
443 * Test the modL3Src method.
446 public void testModL3SrcMethod() {
447 final Instruction instruction = Instructions.modL3Src(ip41);
448 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
449 checkAndConvert(instruction,
450 Instruction.Type.L3MODIFICATION,
451 L3ModificationInstruction.ModIPInstruction.class);
452 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
453 assertThat(modIPInstruction.subtype(),
454 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_SRC)));
458 * Test the modL3Dst method.
461 public void testModL3DstMethod() {
462 final Instruction instruction = Instructions.modL3Dst(ip41);
463 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
464 checkAndConvert(instruction,
465 Instruction.Type.L3MODIFICATION,
466 L3ModificationInstruction.ModIPInstruction.class);
467 assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
468 assertThat(modIPInstruction.subtype(),
469 is(equalTo(L3ModificationInstruction.L3SubType.IPV4_DST)));
473 * Test the modL3IPv6Src method.
476 public void testModL3IPv6SrcMethod() {
477 final Instruction instruction = Instructions.modL3IPv6Src(ip61);
478 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
479 checkAndConvert(instruction,
480 Instruction.Type.L3MODIFICATION,
481 L3ModificationInstruction.ModIPInstruction.class);
482 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
483 assertThat(modIPInstruction.subtype(),
484 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_SRC)));
488 * Test the modL3IPv6Dst method.
491 public void testModL3IPv6DstMethod() {
492 final Instruction instruction = Instructions.modL3IPv6Dst(ip61);
493 final L3ModificationInstruction.ModIPInstruction modIPInstruction =
494 checkAndConvert(instruction,
495 Instruction.Type.L3MODIFICATION,
496 L3ModificationInstruction.ModIPInstruction.class);
497 assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
498 assertThat(modIPInstruction.subtype(),
499 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_DST)));
503 * Test the equals() method of the ModIPInstruction class.
506 public void testModIPInstructionEquals() throws Exception {
507 checkEqualsAndToString(modIPInstruction1,
508 sameAsModIPInstruction1,
513 * Test the hashCode() method of the ModIPInstruction class.
516 public void testModIPInstructionHashCode() {
517 assertThat(modIPInstruction1.hashCode(),
518 is(equalTo(sameAsModIPInstruction1.hashCode())));
519 assertThat(modIPInstruction1.hashCode(),
520 is(not(equalTo(modIPInstruction2.hashCode()))));
523 private final int flowLabel1 = 0x11111;
524 private final int flowLabel2 = 0x22222;
525 private final Instruction modIPv6FlowLabelInstruction1 =
526 Instructions.modL3IPv6FlowLabel(flowLabel1);
527 private final Instruction sameAsModIPv6FlowLabelInstruction1 =
528 Instructions.modL3IPv6FlowLabel(flowLabel1);
529 private final Instruction modIPv6FlowLabelInstruction2 =
530 Instructions.modL3IPv6FlowLabel(flowLabel2);
533 * Test the modL3IPv6FlowLabel method.
536 public void testModL3IPv6FlowLabelMethod() {
537 final Instruction instruction =
538 Instructions.modL3IPv6FlowLabel(flowLabel1);
539 final L3ModificationInstruction.ModIPv6FlowLabelInstruction
540 modIPv6FlowLabelInstruction =
541 checkAndConvert(instruction,
542 Instruction.Type.L3MODIFICATION,
543 L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
544 assertThat(modIPv6FlowLabelInstruction.flowLabel(),
545 is(equalTo(flowLabel1)));
546 assertThat(modIPv6FlowLabelInstruction.subtype(),
547 is(equalTo(L3ModificationInstruction.L3SubType.IPV6_FLABEL)));
551 * Test the equals() method of the ModIPv6FlowLabelInstruction class.
554 public void testModIPv6FlowLabelInstructionEquals() throws Exception {
555 checkEqualsAndToString(modIPv6FlowLabelInstruction1,
556 sameAsModIPv6FlowLabelInstruction1,
557 modIPv6FlowLabelInstruction2);
561 * Test the hashCode() method of the ModIPv6FlowLabelInstruction class.
564 public void testModIPv6FlowLabelInstructionHashCode() {
565 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
566 is(equalTo(sameAsModIPv6FlowLabelInstruction1.hashCode())));
567 assertThat(modIPv6FlowLabelInstruction1.hashCode(),
568 is(not(equalTo(modIPv6FlowLabelInstruction2.hashCode()))));
571 private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
572 private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
573 private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(MplsLabel.mplsLabel(2));
576 * Test the modMplsLabel method.
579 public void testModMplsMethod() {
580 final MplsLabel mplsLabel = MplsLabel.mplsLabel(33);
581 final Instruction instruction = Instructions.modMplsLabel(mplsLabel);
582 final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction =
583 checkAndConvert(instruction,
584 Instruction.Type.L2MODIFICATION,
585 L2ModificationInstruction.ModMplsLabelInstruction.class);
586 assertThat(modMplsLabelInstruction.mplsLabel(), is(equalTo(mplsLabel)));
587 assertThat(modMplsLabelInstruction.subtype(),
588 is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL)));
592 * Test the equals(), hashCode and toString() methods of the
593 * ModMplsLabelInstruction class.
596 public void testModMplsLabelInstructionEquals() throws Exception {
597 checkEqualsAndToString(modMplsLabelInstruction1,
598 sameAsModMplsLabelInstruction1,
599 modMplsLabelInstruction2);
602 // ModTunnelIdInstruction
604 private final long tunnelId1 = 1L;
605 private final long tunnelId2 = 2L;
606 private final Instruction modTunnelId1 = Instructions.modTunnelId(tunnelId1);
607 private final Instruction sameAsModTunnelId1 = Instructions.modTunnelId(tunnelId1);
608 private final Instruction modTunnelId2 = Instructions.modTunnelId(tunnelId2);
611 * Test the modTunnelId method.
614 public void testModTunnelIdMethod() {
615 final Instruction instruction = Instructions.modTunnelId(tunnelId1);
616 final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction =
617 checkAndConvert(instruction, Instruction.Type.L2MODIFICATION,
618 L2ModificationInstruction.ModTunnelIdInstruction.class);
619 assertThat(modTunnelIdInstruction.tunnelId(), is(equalTo(tunnelId1)));
620 assertThat(modTunnelIdInstruction.subtype(),
621 is(equalTo(L2ModificationInstruction.L2SubType.TUNNEL_ID)));
625 * Test the equals() method of the ModTunnelIdInstruction class.
628 public void testModTunnelIdInstructionEquals() throws Exception {
629 checkEqualsAndToString(modTunnelId1, sameAsModTunnelId1, modTunnelId2);
633 * Test the hashCode() method of the ModTunnelIdInstruction class.
636 public void testModTunnelIdInstructionHashCode() {
637 assertThat(modTunnelId1.hashCode(), is(equalTo(sameAsModTunnelId1.hashCode())));
638 assertThat(modTunnelId1.hashCode(), is(not(equalTo(modTunnelId2.hashCode()))));
641 // ModTransportPortInstruction
643 private final TpPort tpPort1 = TpPort.tpPort(1);
644 private final TpPort tpPort2 = TpPort.tpPort(2);
645 private final Instruction modTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
646 private final Instruction sameAsModTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
647 private final Instruction modTransportPortInstruction2 = Instructions.modTcpSrc(tpPort2);
650 * Test the modTcpSrc() method.
653 public void testModTcpSrcMethod() {
654 final Instruction instruction = Instructions.modTcpSrc(tpPort1);
655 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
656 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
657 L4ModificationInstruction.ModTransportPortInstruction.class);
658 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
659 assertThat(modTransportPortInstruction.subtype(),
660 is(equalTo(L4ModificationInstruction.L4SubType.TCP_SRC)));
664 * Test the modTcpDst() method.
667 public void testModTcpDstMethod() {
668 final Instruction instruction = Instructions.modTcpDst(tpPort1);
669 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
670 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
671 L4ModificationInstruction.ModTransportPortInstruction.class);
672 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
673 assertThat(modTransportPortInstruction.subtype(),
674 is(equalTo(L4ModificationInstruction.L4SubType.TCP_DST)));
678 * Test the modUdpSrc() method.
681 public void testModUdpSrcMethod() {
682 final Instruction instruction = Instructions.modUdpSrc(tpPort1);
683 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
684 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
685 L4ModificationInstruction.ModTransportPortInstruction.class);
686 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
687 assertThat(modTransportPortInstruction.subtype(),
688 is(equalTo(L4ModificationInstruction.L4SubType.UDP_SRC)));
692 * Test the modUdpDst() method.
695 public void testModUdpDstMethod() {
696 final Instruction instruction = Instructions.modUdpDst(tpPort1);
697 final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
698 checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
699 L4ModificationInstruction.ModTransportPortInstruction.class);
700 assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
701 assertThat(modTransportPortInstruction.subtype(),
702 is(equalTo(L4ModificationInstruction.L4SubType.UDP_DST)));
706 * Test the equals() method of the ModTransportPortInstruction class.
709 public void testModTransportPortInstructionEquals() throws Exception {
710 checkEqualsAndToString(modTransportPortInstruction1,
711 sameAsModTransportPortInstruction1,
712 modTransportPortInstruction2);
716 * Test the hashCode() method of the ModTransportPortInstruction class.
719 public void testModTransportPortInstructionHashCode() {
720 assertThat(modTransportPortInstruction1.hashCode(),
721 is(equalTo(sameAsModTransportPortInstruction1.hashCode())));
722 assertThat(modTransportPortInstruction1.hashCode(),
723 is(not(equalTo(modTransportPortInstruction2.hashCode()))));