Committed by
Gerrit Code Review
Improve test coverage for Instructions APIs
Change-Id: I3b7018c51227c789832616c5d6ac8f2420d99744
Showing
1 changed file
with
631 additions
and
5 deletions
... | @@ -15,18 +15,25 @@ | ... | @@ -15,18 +15,25 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.flow.instructions; | 16 | package org.onosproject.net.flow.instructions; |
17 | 17 | ||
18 | +import java.util.List; | ||
19 | + | ||
18 | import org.junit.Test; | 20 | import org.junit.Test; |
21 | +import org.onlab.packet.EthType; | ||
19 | import org.onlab.packet.IpAddress; | 22 | import org.onlab.packet.IpAddress; |
20 | import org.onlab.packet.MacAddress; | 23 | import org.onlab.packet.MacAddress; |
21 | import org.onlab.packet.MplsLabel; | 24 | import org.onlab.packet.MplsLabel; |
22 | import org.onlab.packet.TpPort; | 25 | import org.onlab.packet.TpPort; |
23 | import org.onlab.packet.VlanId; | 26 | import org.onlab.packet.VlanId; |
27 | +import org.onosproject.core.DefaultGroupId; | ||
28 | +import org.onosproject.core.GroupId; | ||
24 | import org.onosproject.net.ChannelSpacing; | 29 | import org.onosproject.net.ChannelSpacing; |
30 | +import org.onosproject.net.DeviceId; | ||
25 | import org.onosproject.net.GridType; | 31 | import org.onosproject.net.GridType; |
26 | import org.onosproject.net.IndexedLambda; | 32 | import org.onosproject.net.IndexedLambda; |
27 | import org.onosproject.net.Lambda; | 33 | import org.onosproject.net.Lambda; |
28 | import org.onosproject.net.OduSignalId; | 34 | import org.onosproject.net.OduSignalId; |
29 | import org.onosproject.net.PortNumber; | 35 | import org.onosproject.net.PortNumber; |
36 | +import org.onosproject.net.meter.MeterId; | ||
30 | 37 | ||
31 | import com.google.common.testing.EqualsTester; | 38 | import com.google.common.testing.EqualsTester; |
32 | 39 | ||
... | @@ -38,8 +45,8 @@ import static org.hamcrest.Matchers.not; | ... | @@ -38,8 +45,8 @@ import static org.hamcrest.Matchers.not; |
38 | import static org.hamcrest.Matchers.notNullValue; | 45 | import static org.hamcrest.Matchers.notNullValue; |
39 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | 46 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
40 | import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility; | 47 | import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility; |
41 | -import static org.onosproject.net.PortNumber.portNumber; | ||
42 | import static org.onosproject.net.OduSignalId.oduSignalId; | 48 | import static org.onosproject.net.OduSignalId.oduSignalId; |
49 | +import static org.onosproject.net.PortNumber.portNumber; | ||
43 | 50 | ||
44 | /** | 51 | /** |
45 | * Unit tests for the Instructions class. | 52 | * Unit tests for the Instructions class. |
... | @@ -47,7 +54,7 @@ import static org.onosproject.net.OduSignalId.oduSignalId; | ... | @@ -47,7 +54,7 @@ import static org.onosproject.net.OduSignalId.oduSignalId; |
47 | public class InstructionsTest { | 54 | public class InstructionsTest { |
48 | 55 | ||
49 | /** | 56 | /** |
50 | - * Checks that a Criterion object has the proper type, and then converts | 57 | + * Checks that an Instruction object has the proper type, and then converts |
51 | * it to the proper type. | 58 | * it to the proper type. |
52 | * | 59 | * |
53 | * @param instruction Instruction object to convert | 60 | * @param instruction Instruction object to convert |
... | @@ -65,7 +72,7 @@ public class InstructionsTest { | ... | @@ -65,7 +72,7 @@ public class InstructionsTest { |
65 | } | 72 | } |
66 | 73 | ||
67 | /** | 74 | /** |
68 | - * Checks the equals() and toString() methods of a Criterion class. | 75 | + * Checks the equals() and toString() methods of a Instruction class. |
69 | * | 76 | * |
70 | * @param c1 first object to compare | 77 | * @param c1 first object to compare |
71 | * @param c1match object that should be equal to the first | 78 | * @param c1match object that should be equal to the first |
... | @@ -102,10 +109,50 @@ public class InstructionsTest { | ... | @@ -102,10 +109,50 @@ public class InstructionsTest { |
102 | assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class); | 109 | assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class); |
103 | assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class); | 110 | assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class); |
104 | assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class); | 111 | assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class); |
112 | + assertThatClassIsImmutable(L2ModificationInstruction.PopVlanInstruction.class); | ||
105 | assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class); | 113 | assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class); |
106 | assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class); | 114 | assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class); |
107 | assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class); | 115 | assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class); |
108 | assertThatClassIsImmutable(L2ModificationInstruction.PushHeaderInstructions.class); | 116 | assertThatClassIsImmutable(L2ModificationInstruction.PushHeaderInstructions.class); |
117 | + assertThatClassIsImmutable(L2ModificationInstruction.ModMplsBosInstruction.class); | ||
118 | + assertThatClassIsImmutable(L2ModificationInstruction.ModMplsTtlInstruction.class); | ||
119 | + assertThatClassIsImmutable(L2ModificationInstruction.ModTunnelIdInstruction.class); | ||
120 | + } | ||
121 | + | ||
122 | + // NoActionInstruction | ||
123 | + | ||
124 | + private final Instructions.NoActionInstruction noAction1 = Instructions.createNoAction(); | ||
125 | + private final Instructions.NoActionInstruction noAction2 = Instructions.createNoAction(); | ||
126 | + | ||
127 | + /** | ||
128 | + * Test the createNoAction method. | ||
129 | + */ | ||
130 | + @Test | ||
131 | + public void testCreateNoActionMethod() { | ||
132 | + Instructions.NoActionInstruction instruction = Instructions.createNoAction(); | ||
133 | + checkAndConvert(instruction, | ||
134 | + Instruction.Type.NOACTION, | ||
135 | + Instructions.NoActionInstruction.class); | ||
136 | + } | ||
137 | + | ||
138 | + /** | ||
139 | + * Test the equals() method of the NoActionInstruction class. | ||
140 | + */ | ||
141 | + | ||
142 | + @Test | ||
143 | + public void testNoActionInstructionEquals() throws Exception { | ||
144 | + new EqualsTester() | ||
145 | + .addEqualityGroup(noAction1, noAction2) | ||
146 | + .testEquals(); | ||
147 | + } | ||
148 | + | ||
149 | + /** | ||
150 | + * Test the hashCode() method of the NoActionInstruction class. | ||
151 | + */ | ||
152 | + | ||
153 | + @Test | ||
154 | + public void testNoActionInstructionHashCode() { | ||
155 | + assertThat(noAction1.hashCode(), is(equalTo(noAction2.hashCode()))); | ||
109 | } | 156 | } |
110 | 157 | ||
111 | // DropInstruction | 158 | // DropInstruction |
... | @@ -448,7 +495,7 @@ public class InstructionsTest { | ... | @@ -448,7 +495,7 @@ public class InstructionsTest { |
448 | } | 495 | } |
449 | 496 | ||
450 | /** | 497 | /** |
451 | - * Test the hashCode() method of the ModEtherInstruction class. | 498 | + * Test the hashCode() method of the ModVlanPcp class. |
452 | */ | 499 | */ |
453 | 500 | ||
454 | @Test | 501 | @Test |
... | @@ -630,7 +677,7 @@ public class InstructionsTest { | ... | @@ -630,7 +677,7 @@ public class InstructionsTest { |
630 | } | 677 | } |
631 | 678 | ||
632 | /** | 679 | /** |
633 | - * Test the equals(), hashCode and toString() methods of the | 680 | + * Test the equals(), hashCode() and toString() methods of the |
634 | * ModMplsLabelInstruction class. | 681 | * ModMplsLabelInstruction class. |
635 | */ | 682 | */ |
636 | @Test | 683 | @Test |
... | @@ -763,4 +810,583 @@ public class InstructionsTest { | ... | @@ -763,4 +810,583 @@ public class InstructionsTest { |
763 | assertThat(modTransportPortInstruction1.hashCode(), | 810 | assertThat(modTransportPortInstruction1.hashCode(), |
764 | is(not(equalTo(modTransportPortInstruction2.hashCode())))); | 811 | is(not(equalTo(modTransportPortInstruction2.hashCode())))); |
765 | } | 812 | } |
813 | + | ||
814 | + // GroupInstruction | ||
815 | + | ||
816 | + private final GroupId groupId1 = new DefaultGroupId(1); | ||
817 | + private final GroupId groupId2 = new DefaultGroupId(2); | ||
818 | + private final Instruction groupInstruction1 = Instructions.createGroup(groupId1); | ||
819 | + private final Instruction sameAsGroupInstruction1 = Instructions.createGroup(groupId1); | ||
820 | + private final Instruction groupInstruction2 = Instructions.createGroup(groupId2); | ||
821 | + | ||
822 | + /** | ||
823 | + * Test the create group method. | ||
824 | + */ | ||
825 | + @Test | ||
826 | + public void testCreateGroupMethod() { | ||
827 | + final Instruction instruction = Instructions.createGroup(groupId1); | ||
828 | + final Instructions.GroupInstruction groupInstruction = | ||
829 | + checkAndConvert(instruction, | ||
830 | + Instruction.Type.GROUP, | ||
831 | + Instructions.GroupInstruction.class); | ||
832 | + assertThat(groupInstruction.groupId(), is(equalTo(groupId1))); | ||
833 | + } | ||
834 | + | ||
835 | + /** | ||
836 | + * Test the equals() method of the GroupInstruction class. | ||
837 | + */ | ||
838 | + | ||
839 | + @Test | ||
840 | + public void testGroupInstructionEquals() { | ||
841 | + checkEqualsAndToString(groupInstruction1, | ||
842 | + sameAsGroupInstruction1, | ||
843 | + groupInstruction2); | ||
844 | + } | ||
845 | + | ||
846 | + // SetQueueInstruction | ||
847 | + | ||
848 | + private final Instruction setQueueInstruction1 = Instructions.setQueue(1, port1); | ||
849 | + private final Instruction sameAsSetQueueInstruction1 = Instructions.setQueue(1, port1); | ||
850 | + private final Instruction setQueueInstruction2 = Instructions.setQueue(1, port2); | ||
851 | + | ||
852 | + /** | ||
853 | + * Test the set queue method. | ||
854 | + */ | ||
855 | + @Test | ||
856 | + public void testSetQueueMethod() { | ||
857 | + final Instruction instruction = Instructions.setQueue(2, port2); | ||
858 | + final Instructions.SetQueueInstruction setQueueInstruction = | ||
859 | + checkAndConvert(instruction, | ||
860 | + Instruction.Type.QUEUE, | ||
861 | + Instructions.SetQueueInstruction.class); | ||
862 | + assertThat(setQueueInstruction.queueId(), is(2L)); | ||
863 | + assertThat(setQueueInstruction.port(), is(port2)); | ||
864 | + } | ||
865 | + | ||
866 | + /** | ||
867 | + * Test the equals() method of the SetQueueInstruction class. | ||
868 | + */ | ||
869 | + @Test | ||
870 | + public void testSetQueueInstructionEquals() { | ||
871 | + checkEqualsAndToString(setQueueInstruction1, | ||
872 | + sameAsSetQueueInstruction1, | ||
873 | + setQueueInstruction2); | ||
874 | + } | ||
875 | + | ||
876 | + // MeterInstruction | ||
877 | + | ||
878 | + MeterId meterId1 = MeterId.meterId(1); | ||
879 | + MeterId meterId2 = MeterId.meterId(2); | ||
880 | + private final Instruction meterInstruction1 = Instructions.meterTraffic(meterId1); | ||
881 | + private final Instruction sameAsMeterInstruction1 = Instructions.meterTraffic(meterId1); | ||
882 | + private final Instruction meterInstruction2 = Instructions.meterTraffic(meterId2); | ||
883 | + | ||
884 | + /** | ||
885 | + * Test the meter traffic method. | ||
886 | + */ | ||
887 | + @Test | ||
888 | + public void testMeterTrafficMethod() { | ||
889 | + final Instruction instruction = Instructions.meterTraffic(meterId1); | ||
890 | + final Instructions.MeterInstruction meterInstruction = | ||
891 | + checkAndConvert(instruction, | ||
892 | + Instruction.Type.METER, | ||
893 | + Instructions.MeterInstruction.class); | ||
894 | + assertThat(meterInstruction.meterId(), is(meterId1)); | ||
895 | + } | ||
896 | + | ||
897 | + /** | ||
898 | + * Test the equals() method of the MeterInstruction class. | ||
899 | + */ | ||
900 | + @Test | ||
901 | + public void testMeterTrafficInstructionEquals() { | ||
902 | + checkEqualsAndToString(meterInstruction1, | ||
903 | + sameAsMeterInstruction1, | ||
904 | + meterInstruction2); | ||
905 | + } | ||
906 | + | ||
907 | + // TableTypeTransition | ||
908 | + | ||
909 | + private final Instruction transitionInstruction1 = Instructions.transition(1); | ||
910 | + private final Instruction sameAsTransitionInstruction1 = Instructions.transition(1); | ||
911 | + private final Instruction transitionInstruction2 = Instructions.transition(2); | ||
912 | + | ||
913 | + /** | ||
914 | + * Test the transition method. | ||
915 | + */ | ||
916 | + @Test | ||
917 | + public void testTransitionMethod() { | ||
918 | + final Instruction instruction = Instructions.transition(1); | ||
919 | + final Instructions.TableTypeTransition tableInstruction = | ||
920 | + checkAndConvert(instruction, | ||
921 | + Instruction.Type.TABLE, | ||
922 | + Instructions.TableTypeTransition.class); | ||
923 | + assertThat(tableInstruction.tableId(), is(1)); | ||
924 | + } | ||
925 | + | ||
926 | + /** | ||
927 | + * Test the equals() method of the TableTypeTransition class. | ||
928 | + */ | ||
929 | + @Test | ||
930 | + public void testTableTypeTransitionInstructionEquals() { | ||
931 | + checkEqualsAndToString(transitionInstruction1, | ||
932 | + sameAsTransitionInstruction1, | ||
933 | + transitionInstruction2); | ||
934 | + } | ||
935 | + | ||
936 | + // MetadataInstruction | ||
937 | + | ||
938 | + long metadata1 = 111L; | ||
939 | + long metadataMask1 = 222L; | ||
940 | + long metadata2 = 333L; | ||
941 | + long metadataMask2 = 444L; | ||
942 | + | ||
943 | + private final Instruction metadataInstruction1 = | ||
944 | + Instructions.writeMetadata(metadata1, metadataMask1); | ||
945 | + private final Instruction sameAsMetadataInstruction1 = | ||
946 | + Instructions.writeMetadata(metadata1, metadataMask1); | ||
947 | + private final Instruction metadataInstruction2 = | ||
948 | + Instructions.writeMetadata(metadata2, metadataMask2); | ||
949 | + | ||
950 | + /** | ||
951 | + * Test the write metadata method. | ||
952 | + */ | ||
953 | + @Test | ||
954 | + public void testWriteMetadataMethod() { | ||
955 | + final Instruction instruction = | ||
956 | + Instructions.writeMetadata(metadata1, metadataMask1); | ||
957 | + final Instructions.MetadataInstruction metadataInstruction = | ||
958 | + checkAndConvert(instruction, | ||
959 | + Instruction.Type.METADATA, | ||
960 | + Instructions.MetadataInstruction.class); | ||
961 | + assertThat(metadataInstruction.metadata(), is(metadata1)); | ||
962 | + assertThat(metadataInstruction.metadataMask(), is(metadataMask1)); | ||
963 | + } | ||
964 | + | ||
965 | + /** | ||
966 | + * Test the equals() method of the MetadataInstruction class. | ||
967 | + */ | ||
968 | + @Test | ||
969 | + public void testInstructionEquals() { | ||
970 | + checkEqualsAndToString(metadataInstruction1, | ||
971 | + sameAsMetadataInstruction1, | ||
972 | + metadataInstruction2); | ||
973 | + } | ||
974 | + | ||
975 | + // ExtensionInstructionWrapper | ||
976 | + | ||
977 | + class MockExtensionTreatment implements ExtensionTreatment { | ||
978 | + int type; | ||
979 | + | ||
980 | + MockExtensionTreatment(int type) { | ||
981 | + this.type = type; | ||
982 | + } | ||
983 | + @Override | ||
984 | + public ExtensionTreatmentType type() { | ||
985 | + return new ExtensionTreatmentType(type); | ||
986 | + } | ||
987 | + | ||
988 | + @Override | ||
989 | + public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException { | ||
990 | + | ||
991 | + } | ||
992 | + | ||
993 | + @Override | ||
994 | + public <T> T getPropertyValue(String key) throws ExtensionPropertyException { | ||
995 | + return null; | ||
996 | + } | ||
997 | + | ||
998 | + @Override | ||
999 | + public List<String> getProperties() { | ||
1000 | + return null; | ||
1001 | + } | ||
1002 | + | ||
1003 | + @Override | ||
1004 | + public byte[] serialize() { | ||
1005 | + return new byte[0]; | ||
1006 | + } | ||
1007 | + | ||
1008 | + @Override | ||
1009 | + public void deserialize(byte[] data) { | ||
1010 | + | ||
1011 | + } | ||
1012 | + } | ||
1013 | + | ||
1014 | + ExtensionTreatment extensionTreatment1 = new MockExtensionTreatment(111); | ||
1015 | + ExtensionTreatment extensionTreatment2 = new MockExtensionTreatment(222); | ||
1016 | + | ||
1017 | + DeviceId deviceId1 = DeviceId.deviceId("of:1"); | ||
1018 | + DeviceId deviceId2 = DeviceId.deviceId("of:2"); | ||
1019 | + | ||
1020 | + private final Instruction extensionInstruction1 = | ||
1021 | + Instructions.extension(extensionTreatment1, deviceId1); | ||
1022 | + private final Instruction sameAsExtensionInstruction1 = | ||
1023 | + Instructions.extension(extensionTreatment1, deviceId1); | ||
1024 | + private final Instruction extensionInstruction2 = | ||
1025 | + Instructions.extension(extensionTreatment2, deviceId2); | ||
1026 | + | ||
1027 | + /** | ||
1028 | + * Test the extension method. | ||
1029 | + */ | ||
1030 | + @Test | ||
1031 | + public void testExtensionMethod() { | ||
1032 | + final Instruction instruction = | ||
1033 | + Instructions.extension(extensionTreatment1, deviceId1); | ||
1034 | + final Instructions.ExtensionInstructionWrapper extensionInstructionWrapper = | ||
1035 | + checkAndConvert(instruction, | ||
1036 | + Instruction.Type.EXTENSION, | ||
1037 | + Instructions.ExtensionInstructionWrapper.class); | ||
1038 | + assertThat(extensionInstructionWrapper.deviceId(), is(deviceId1)); | ||
1039 | + assertThat(extensionInstructionWrapper.extensionInstruction(), is(extensionTreatment1)); | ||
1040 | + } | ||
1041 | + | ||
1042 | + /** | ||
1043 | + * Test the equals() method of the ExtensionInstructionWrapper class. | ||
1044 | + */ | ||
1045 | + @Test | ||
1046 | + public void testExtensionInstructionWrapperEquals() { | ||
1047 | + checkEqualsAndToString(extensionInstruction1, | ||
1048 | + sameAsExtensionInstruction1, | ||
1049 | + extensionInstruction2); | ||
1050 | + } | ||
1051 | + | ||
1052 | + // PushHeaderInstructions | ||
1053 | + | ||
1054 | + private final EthType ethType1 = new EthType(1); | ||
1055 | + private final EthType ethType2 = new EthType(2); | ||
1056 | + private final Instruction pushHeaderInstruction1 = Instructions.popMpls(ethType1); | ||
1057 | + private final Instruction sameAsPushHeaderInstruction1 = Instructions.popMpls(ethType1); | ||
1058 | + private final Instruction pushHeaderInstruction2 = Instructions.popMpls(ethType2); | ||
1059 | + | ||
1060 | + /** | ||
1061 | + * Test the pushMpls method. | ||
1062 | + */ | ||
1063 | + @Test | ||
1064 | + public void testPushMplsMethod() { | ||
1065 | + final Instruction instruction = Instructions.pushMpls(); | ||
1066 | + final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstruction = | ||
1067 | + checkAndConvert(instruction, | ||
1068 | + Instruction.Type.L2MODIFICATION, | ||
1069 | + L2ModificationInstruction.PushHeaderInstructions.class); | ||
1070 | + assertThat(pushHeaderInstruction.ethernetType().toString(), | ||
1071 | + is(EthType.EtherType.MPLS_MULTICAST.toString())); | ||
1072 | + assertThat(pushHeaderInstruction.subtype(), | ||
1073 | + is(L2ModificationInstruction.L2SubType.MPLS_PUSH)); | ||
1074 | + } | ||
1075 | + | ||
1076 | + /** | ||
1077 | + * Test the popMpls method. | ||
1078 | + */ | ||
1079 | + @Test | ||
1080 | + public void testPopMplsMethod() { | ||
1081 | + final Instruction instruction = Instructions.popMpls(); | ||
1082 | + final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstruction = | ||
1083 | + checkAndConvert(instruction, | ||
1084 | + Instruction.Type.L2MODIFICATION, | ||
1085 | + L2ModificationInstruction.PushHeaderInstructions.class); | ||
1086 | + assertThat(pushHeaderInstruction.ethernetType().toString(), | ||
1087 | + is(EthType.EtherType.MPLS_MULTICAST.toString())); | ||
1088 | + assertThat(pushHeaderInstruction.subtype(), | ||
1089 | + is(L2ModificationInstruction.L2SubType.MPLS_POP)); | ||
1090 | + } | ||
1091 | + | ||
1092 | + /** | ||
1093 | + * Test the popMpls(EtherType) method. | ||
1094 | + */ | ||
1095 | + @Test | ||
1096 | + public void testPopMplsEthertypeMethod() { | ||
1097 | + final Instruction instruction = Instructions.popMpls(new EthType(1)); | ||
1098 | + final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstruction = | ||
1099 | + checkAndConvert(instruction, | ||
1100 | + Instruction.Type.L2MODIFICATION, | ||
1101 | + L2ModificationInstruction.PushHeaderInstructions.class); | ||
1102 | + assertThat(pushHeaderInstruction.ethernetType().toShort(), is((short) 1)); | ||
1103 | + assertThat(pushHeaderInstruction.subtype(), | ||
1104 | + is(L2ModificationInstruction.L2SubType.MPLS_POP)); | ||
1105 | + } | ||
1106 | + | ||
1107 | + /** | ||
1108 | + * Test the pushVlan method. | ||
1109 | + */ | ||
1110 | + @Test | ||
1111 | + public void testPushVlanMethod() { | ||
1112 | + final Instruction instruction = Instructions.pushVlan(); | ||
1113 | + final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstruction = | ||
1114 | + checkAndConvert(instruction, | ||
1115 | + Instruction.Type.L2MODIFICATION, | ||
1116 | + L2ModificationInstruction.PushHeaderInstructions.class); | ||
1117 | + assertThat(pushHeaderInstruction.ethernetType().toString(), | ||
1118 | + is(EthType.EtherType.VLAN.toString())); | ||
1119 | + assertThat(pushHeaderInstruction.subtype(), | ||
1120 | + is(L2ModificationInstruction.L2SubType.VLAN_PUSH)); | ||
1121 | + } | ||
1122 | + | ||
1123 | + /** | ||
1124 | + * Tests the equals(), hashCode() and toString() methods of the | ||
1125 | + * PushHeaderInstructions class. | ||
1126 | + */ | ||
1127 | + | ||
1128 | + @Test | ||
1129 | + public void testPushHeaderInstructionsEquals() { | ||
1130 | + checkEqualsAndToString(pushHeaderInstruction1, | ||
1131 | + sameAsPushHeaderInstruction1, | ||
1132 | + pushHeaderInstruction2); | ||
1133 | + } | ||
1134 | + | ||
1135 | + // ModMplsTtlInstruction | ||
1136 | + | ||
1137 | + private final Instruction modMplsTtlInstruction1 = Instructions.decMplsTtl(); | ||
1138 | + private final Instruction sameAsModMplsTtlInstruction1 = Instructions.decMplsTtl(); | ||
1139 | + | ||
1140 | + /** | ||
1141 | + * Test the modMplsBos() method. | ||
1142 | + */ | ||
1143 | + @Test | ||
1144 | + public void testDecMplsTtlMethod() { | ||
1145 | + final Instruction instruction = Instructions.decMplsTtl(); | ||
1146 | + final L2ModificationInstruction.ModMplsTtlInstruction modMplsTtlInstruction = | ||
1147 | + checkAndConvert(instruction, | ||
1148 | + Instruction.Type.L2MODIFICATION, | ||
1149 | + L2ModificationInstruction.ModMplsTtlInstruction.class); | ||
1150 | + assertThat(modMplsTtlInstruction.subtype(), | ||
1151 | + is(L2ModificationInstruction.L2SubType.DEC_MPLS_TTL)); | ||
1152 | + } | ||
1153 | + | ||
1154 | + /** | ||
1155 | + * Tests the equals(), hashCode() and toString() methods of the | ||
1156 | + * PushHeaderInstructions class. | ||
1157 | + */ | ||
1158 | + | ||
1159 | + @Test | ||
1160 | + public void testMplsTtlInstructionsEquals() { | ||
1161 | + new EqualsTester() | ||
1162 | + .addEqualityGroup(modMplsTtlInstruction1, sameAsModMplsTtlInstruction1) | ||
1163 | + .testEquals(); | ||
1164 | + } | ||
1165 | + | ||
1166 | + // ModMplsBosInstruction | ||
1167 | + | ||
1168 | + private final Instruction modMplsBosInstruction1 = Instructions.modMplsBos(true); | ||
1169 | + private final Instruction sameAsModMplsBosInstruction1 = Instructions.modMplsBos(true); | ||
1170 | + private final Instruction modMplsBosInstruction2 = Instructions.modMplsBos(false); | ||
1171 | + | ||
1172 | + /** | ||
1173 | + * Test the modMplsBos() method. | ||
1174 | + */ | ||
1175 | + @Test | ||
1176 | + public void testModMplsBosMethod() { | ||
1177 | + final Instruction instruction = Instructions.modMplsBos(true); | ||
1178 | + final L2ModificationInstruction.ModMplsBosInstruction modMplsBosInstruction = | ||
1179 | + checkAndConvert(instruction, | ||
1180 | + Instruction.Type.L2MODIFICATION, | ||
1181 | + L2ModificationInstruction.ModMplsBosInstruction.class); | ||
1182 | + assertThat(modMplsBosInstruction.subtype(), | ||
1183 | + is(L2ModificationInstruction.L2SubType.MPLS_BOS)); | ||
1184 | + assertThat(modMplsBosInstruction.mplsBos(), is(true)); | ||
1185 | + } | ||
1186 | + | ||
1187 | + /** | ||
1188 | + * Tests the equals(), hashCode() and toString() methods of the | ||
1189 | + * PushHeaderInstructions class. | ||
1190 | + */ | ||
1191 | + | ||
1192 | + @Test | ||
1193 | + public void testMplsBosInstructionsEquals() { | ||
1194 | + checkEqualsAndToString(modMplsBosInstruction1, | ||
1195 | + sameAsModMplsBosInstruction1, | ||
1196 | + modMplsBosInstruction2); | ||
1197 | + } | ||
1198 | + | ||
1199 | + // PopVlanInstruction | ||
1200 | + | ||
1201 | + private final Instruction popVlanInstruction1 = Instructions.popVlan(); | ||
1202 | + private final Instruction sameAsPopVlanInstruction1 = Instructions.popVlan(); | ||
1203 | + | ||
1204 | + /** | ||
1205 | + * Test the popVlan method. | ||
1206 | + */ | ||
1207 | + @Test | ||
1208 | + public void testPopVlanMethod() { | ||
1209 | + final Instruction instruction = Instructions.popVlan(); | ||
1210 | + final L2ModificationInstruction.PopVlanInstruction popVlanInstruction = | ||
1211 | + checkAndConvert(instruction, | ||
1212 | + Instruction.Type.L2MODIFICATION, | ||
1213 | + L2ModificationInstruction.PopVlanInstruction.class); | ||
1214 | + assertThat(popVlanInstruction.subtype(), | ||
1215 | + is(L2ModificationInstruction.L2SubType.VLAN_POP)); | ||
1216 | + } | ||
1217 | + | ||
1218 | + /** | ||
1219 | + * Tests the equals(), hashCode() and toString() methods of the | ||
1220 | + * PushHeaderInstructions class. | ||
1221 | + */ | ||
1222 | + | ||
1223 | + @Test | ||
1224 | + public void testPopVlanInstructionsEquals() { | ||
1225 | + new EqualsTester() | ||
1226 | + .addEqualityGroup(popVlanInstruction1, sameAsPopVlanInstruction1) | ||
1227 | + .testEquals(); | ||
1228 | + } | ||
1229 | + | ||
1230 | + // ModArpIPInstruction | ||
1231 | + | ||
1232 | + private final Instruction modArpIPInstruction1 = Instructions.modArpSpa(ip41); | ||
1233 | + private final Instruction sameAsModArpIPInstruction1 = Instructions.modArpSpa(ip41); | ||
1234 | + private final Instruction modArpIPInstruction2 = Instructions.modArpSpa(ip42); | ||
1235 | + | ||
1236 | + /** | ||
1237 | + * Test the modArpSpa() method. | ||
1238 | + */ | ||
1239 | + @Test | ||
1240 | + public void testModArpSpaMethod() { | ||
1241 | + final Instruction instruction = Instructions.modArpSpa(ip41); | ||
1242 | + final L3ModificationInstruction.ModArpIPInstruction modArpIPInstruction = | ||
1243 | + checkAndConvert(instruction, | ||
1244 | + Instruction.Type.L3MODIFICATION, | ||
1245 | + L3ModificationInstruction.ModArpIPInstruction.class); | ||
1246 | + assertThat(modArpIPInstruction.subtype(), | ||
1247 | + is(L3ModificationInstruction.L3SubType.ARP_SPA)); | ||
1248 | + assertThat(modArpIPInstruction.ip(), is(ip41)); | ||
1249 | + } | ||
1250 | + | ||
1251 | + /** | ||
1252 | + * Tests the equals(), hashCode() and toString() methods of the | ||
1253 | + * ModArpIPInstruction class. | ||
1254 | + */ | ||
1255 | + | ||
1256 | + @Test | ||
1257 | + public void testModArpIPInstructionEquals() { | ||
1258 | + checkEqualsAndToString(modArpIPInstruction1, | ||
1259 | + sameAsModArpIPInstruction1, | ||
1260 | + modArpIPInstruction2); | ||
1261 | + } | ||
1262 | + | ||
1263 | + // ModArpEthInstruction | ||
1264 | + | ||
1265 | + private final Instruction modArpEthInstruction1 = Instructions.modArpSha(mac1); | ||
1266 | + private final Instruction sameAsModArpEthInstruction1 = Instructions.modArpSha(mac1); | ||
1267 | + private final Instruction modArpEthInstruction2 = Instructions.modArpSha(mac2); | ||
1268 | + | ||
1269 | + /** | ||
1270 | + * Test the modArpSha() method. | ||
1271 | + */ | ||
1272 | + @Test | ||
1273 | + public void testModArpShaMethod() { | ||
1274 | + final Instruction instruction = Instructions.modArpSha(mac1); | ||
1275 | + final L3ModificationInstruction.ModArpEthInstruction modArpEthInstruction = | ||
1276 | + checkAndConvert(instruction, | ||
1277 | + Instruction.Type.L3MODIFICATION, | ||
1278 | + L3ModificationInstruction.ModArpEthInstruction.class); | ||
1279 | + assertThat(modArpEthInstruction.subtype(), | ||
1280 | + is(L3ModificationInstruction.L3SubType.ARP_SHA)); | ||
1281 | + assertThat(modArpEthInstruction.mac(), is(mac1)); | ||
1282 | + } | ||
1283 | + | ||
1284 | + /** | ||
1285 | + * Tests the equals(), hashCode() and toString() methods of the | ||
1286 | + * ModArpIPInstruction class. | ||
1287 | + */ | ||
1288 | + | ||
1289 | + @Test | ||
1290 | + public void testModArpEthInstructionEquals() { | ||
1291 | + checkEqualsAndToString(modArpEthInstruction1, | ||
1292 | + sameAsModArpEthInstruction1, | ||
1293 | + modArpEthInstruction2); | ||
1294 | + } | ||
1295 | + | ||
1296 | + // ModArpOpInstruction | ||
1297 | + | ||
1298 | + private final Instruction modArpOpInstruction1 = Instructions.modL3ArpOp((short) 1); | ||
1299 | + private final Instruction sameAsModArpOpInstruction1 = Instructions.modL3ArpOp((short) 1); | ||
1300 | + private final Instruction modArpOpInstruction2 = Instructions.modL3ArpOp((short) 2); | ||
1301 | + | ||
1302 | + /** | ||
1303 | + * Test the modL3ArpOp() method. | ||
1304 | + */ | ||
1305 | + @Test | ||
1306 | + public void testModArpModL3ArpOpMethod() { | ||
1307 | + final Instruction instruction = Instructions.modL3ArpOp((short) 1); | ||
1308 | + final L3ModificationInstruction.ModArpOpInstruction modArpEthInstruction = | ||
1309 | + checkAndConvert(instruction, | ||
1310 | + Instruction.Type.L3MODIFICATION, | ||
1311 | + L3ModificationInstruction.ModArpOpInstruction.class); | ||
1312 | + assertThat(modArpEthInstruction.subtype(), | ||
1313 | + is(L3ModificationInstruction.L3SubType.ARP_OP)); | ||
1314 | + assertThat(modArpEthInstruction.op(), is(1L)); | ||
1315 | + } | ||
1316 | + | ||
1317 | + /** | ||
1318 | + * Tests the equals(), hashCode() and toString() methods of the | ||
1319 | + * ModArpIPInstruction class. | ||
1320 | + */ | ||
1321 | + | ||
1322 | + @Test | ||
1323 | + public void testModArpOpInstructionEquals() { | ||
1324 | + checkEqualsAndToString(modArpOpInstruction1, | ||
1325 | + sameAsModArpOpInstruction1, | ||
1326 | + modArpOpInstruction2); | ||
1327 | + } | ||
1328 | + | ||
1329 | + // ModTtlInstruction | ||
1330 | + | ||
1331 | + private final Instruction modArpTtlInstruction1 = Instructions.copyTtlIn(); | ||
1332 | + private final Instruction sameAsModArpTtlInstruction1 = Instructions.copyTtlIn(); | ||
1333 | + private final Instruction modArpTtlInstruction2 = Instructions.copyTtlOut(); | ||
1334 | + private final Instruction modArpTtlInstruction3 = Instructions.decNwTtl(); | ||
1335 | + | ||
1336 | + /** | ||
1337 | + * Test the copyTtlIn() method. | ||
1338 | + */ | ||
1339 | + @Test | ||
1340 | + public void testCopyTtlInMethod() { | ||
1341 | + final Instruction instruction = Instructions.copyTtlIn(); | ||
1342 | + final L3ModificationInstruction.ModTtlInstruction modTtlInstruction = | ||
1343 | + checkAndConvert(instruction, | ||
1344 | + Instruction.Type.L3MODIFICATION, | ||
1345 | + L3ModificationInstruction.ModTtlInstruction.class); | ||
1346 | + assertThat(modTtlInstruction.subtype(), | ||
1347 | + is(L3ModificationInstruction.L3SubType.TTL_IN)); | ||
1348 | + } | ||
1349 | + | ||
1350 | + /** | ||
1351 | + * Test the copyTtlOut() method. | ||
1352 | + */ | ||
1353 | + @Test | ||
1354 | + public void testCopyTtlOutMethod() { | ||
1355 | + final Instruction instruction = Instructions.copyTtlOut(); | ||
1356 | + final L3ModificationInstruction.ModTtlInstruction modTtlInstruction = | ||
1357 | + checkAndConvert(instruction, | ||
1358 | + Instruction.Type.L3MODIFICATION, | ||
1359 | + L3ModificationInstruction.ModTtlInstruction.class); | ||
1360 | + assertThat(modTtlInstruction.subtype(), | ||
1361 | + is(L3ModificationInstruction.L3SubType.TTL_OUT)); | ||
1362 | + } | ||
1363 | + | ||
1364 | + /** | ||
1365 | + * Test the decNwTtl() method. | ||
1366 | + */ | ||
1367 | + @Test | ||
1368 | + public void testDecNwTtlOutMethod() { | ||
1369 | + final Instruction instruction = Instructions.decNwTtl(); | ||
1370 | + final L3ModificationInstruction.ModTtlInstruction modTtlInstruction = | ||
1371 | + checkAndConvert(instruction, | ||
1372 | + Instruction.Type.L3MODIFICATION, | ||
1373 | + L3ModificationInstruction.ModTtlInstruction.class); | ||
1374 | + assertThat(modTtlInstruction.subtype(), | ||
1375 | + is(L3ModificationInstruction.L3SubType.DEC_TTL)); | ||
1376 | + } | ||
1377 | + | ||
1378 | + /** | ||
1379 | + * Tests the equals(), hashCode() and toString() methods of the | ||
1380 | + * ModArpIPInstruction class. | ||
1381 | + */ | ||
1382 | + | ||
1383 | + @Test | ||
1384 | + public void testModTtlInstructionEquals() { | ||
1385 | + new EqualsTester() | ||
1386 | + .addEqualityGroup(modArpTtlInstruction1, sameAsModArpTtlInstruction1) | ||
1387 | + .addEqualityGroup(modArpTtlInstruction2) | ||
1388 | + .addEqualityGroup(modArpTtlInstruction3) | ||
1389 | + .testEquals(); | ||
1390 | + } | ||
1391 | + | ||
766 | } | 1392 | } | ... | ... |
-
Please register or login to post a comment