Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 3 | * |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow.instructions; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 17 | |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 18 | import java.util.List; |
| 19 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 20 | import org.junit.Test; |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 21 | import org.onlab.packet.EthType; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 22 | import org.onlab.packet.IpAddress; |
| 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onlab.packet.MplsLabel; |
| 25 | import org.onlab.packet.TpPort; |
| 26 | import org.onlab.packet.VlanId; |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 27 | import org.onosproject.core.DefaultGroupId; |
| 28 | import org.onosproject.core.GroupId; |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 29 | import org.onosproject.net.ChannelSpacing; |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 30 | import org.onosproject.net.DeviceId; |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 31 | import org.onosproject.net.GridType; |
Ray Milkey | 85571eb | 2015-06-25 09:45:46 -0700 | [diff] [blame] | 32 | import org.onosproject.net.IndexedLambda; |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 33 | import org.onosproject.net.Lambda; |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 34 | import org.onosproject.net.OduSignalId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import org.onosproject.net.PortNumber; |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 36 | import org.onosproject.net.meter.MeterId; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 37 | |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 38 | import com.google.common.testing.EqualsTester; |
| 39 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 40 | import static org.hamcrest.MatcherAssert.assertThat; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 41 | import static org.hamcrest.Matchers.equalTo; |
| 42 | import static org.hamcrest.Matchers.instanceOf; |
| 43 | import static org.hamcrest.Matchers.is; |
| 44 | import static org.hamcrest.Matchers.not; |
| 45 | import static org.hamcrest.Matchers.notNullValue; |
| 46 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 47 | import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility; |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 48 | import static org.onosproject.net.OduSignalId.oduSignalId; |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 49 | import static org.onosproject.net.PortNumber.portNumber; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Unit tests for the Instructions class. |
| 53 | */ |
| 54 | public class InstructionsTest { |
| 55 | |
| 56 | /** |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 57 | * Checks that an Instruction object has the proper type, and then converts |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 58 | * it to the proper type. |
| 59 | * |
| 60 | * @param instruction Instruction object to convert |
| 61 | * @param type Enumerated type value for the Criterion class |
| 62 | * @param clazz Desired Criterion class |
| 63 | * @param <T> The type the caller wants returned |
| 64 | * @return converted object |
| 65 | */ |
| 66 | @SuppressWarnings("unchecked") |
| 67 | private <T> T checkAndConvert(Instruction instruction, Instruction.Type type, Class clazz) { |
| 68 | assertThat(instruction, is(notNullValue())); |
| 69 | assertThat(instruction.type(), is(equalTo(type))); |
| 70 | assertThat(instruction, instanceOf(clazz)); |
| 71 | return (T) instruction; |
| 72 | } |
| 73 | |
| 74 | /** |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 75 | * Checks the equals() and toString() methods of a Instruction class. |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 76 | * |
| 77 | * @param c1 first object to compare |
| 78 | * @param c1match object that should be equal to the first |
| 79 | * @param c2 object that should be not equal to the first |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 80 | * @param <T> type of the arguments |
| 81 | */ |
| 82 | private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 83 | T c2) { |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 84 | |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 85 | new EqualsTester() |
| 86 | .addEqualityGroup(c1, c1match) |
| 87 | .addEqualityGroup(c2) |
| 88 | .testEquals(); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Checks that Instructions is a proper utility class. |
| 93 | */ |
| 94 | @Test |
| 95 | public void testInstructionsUtilityClass() { |
| 96 | assertThatClassIsUtility(Instructions.class); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Checks that the Instruction class implementations are immutable. |
| 101 | */ |
| 102 | @Test |
| 103 | public void testImmutabilityOfInstructions() { |
| 104 | assertThatClassIsImmutable(Instructions.DropInstruction.class); |
| 105 | assertThatClassIsImmutable(Instructions.OutputInstruction.class); |
| 106 | assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class); |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 107 | assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class); |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 108 | assertThatClassIsImmutable(L1ModificationInstruction.ModOduSignalIdInstruction.class); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 109 | assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class); |
| 110 | assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class); |
| 111 | assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 112 | assertThatClassIsImmutable(L2ModificationInstruction.PopVlanInstruction.class); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 113 | assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class); |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 114 | assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class); |
Ray Milkey | d03eda0 | 2015-01-09 14:58:48 -0800 | [diff] [blame] | 115 | assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class); |
| 116 | assertThatClassIsImmutable(L2ModificationInstruction.PushHeaderInstructions.class); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 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()))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | // DropInstruction |
| 159 | |
| 160 | private final Instructions.DropInstruction drop1 = Instructions.createDrop(); |
| 161 | private final Instructions.DropInstruction drop2 = Instructions.createDrop(); |
| 162 | |
| 163 | /** |
| 164 | * Test the createDrop method. |
| 165 | */ |
| 166 | @Test |
| 167 | public void testCreateDropMethod() { |
| 168 | Instructions.DropInstruction instruction = Instructions.createDrop(); |
| 169 | checkAndConvert(instruction, |
| 170 | Instruction.Type.DROP, |
| 171 | Instructions.DropInstruction.class); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Test the equals() method of the DropInstruction class. |
| 176 | */ |
| 177 | |
| 178 | @Test |
| 179 | public void testDropInstructionEquals() throws Exception { |
| 180 | assertThat(drop1, is(equalTo(drop2))); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Test the hashCode() method of the DropInstruction class. |
| 185 | */ |
| 186 | |
| 187 | @Test |
| 188 | public void testDropInstructionHashCode() { |
| 189 | assertThat(drop1.hashCode(), is(equalTo(drop2.hashCode()))); |
| 190 | } |
| 191 | |
| 192 | // OutputInstruction |
| 193 | |
| 194 | private final PortNumber port1 = portNumber(1); |
| 195 | private final PortNumber port2 = portNumber(2); |
| 196 | private final Instructions.OutputInstruction output1 = Instructions.createOutput(port1); |
| 197 | private final Instructions.OutputInstruction sameAsOutput1 = Instructions.createOutput(port1); |
| 198 | private final Instructions.OutputInstruction output2 = Instructions.createOutput(port2); |
| 199 | |
| 200 | /** |
| 201 | * Test the createOutput method. |
| 202 | */ |
| 203 | @Test |
| 204 | public void testCreateOutputMethod() { |
| 205 | final Instruction instruction = Instructions.createOutput(port2); |
| 206 | final Instructions.OutputInstruction outputInstruction = |
| 207 | checkAndConvert(instruction, |
| 208 | Instruction.Type.OUTPUT, |
| 209 | Instructions.OutputInstruction.class); |
| 210 | assertThat(outputInstruction.port(), is(equalTo(port2))); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | /** |
| 215 | * Test the equals() method of the OutputInstruction class. |
| 216 | */ |
| 217 | |
| 218 | @Test |
| 219 | public void testOutputInstructionEquals() throws Exception { |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 220 | checkEqualsAndToString(output1, sameAsOutput1, output2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Test the hashCode() method of the OutputInstruction class. |
| 225 | */ |
| 226 | |
| 227 | @Test |
| 228 | public void testOutputInstructionHashCode() { |
| 229 | assertThat(output1.hashCode(), is(equalTo(sameAsOutput1.hashCode()))); |
| 230 | assertThat(output1.hashCode(), is(not(equalTo(output2.hashCode())))); |
| 231 | } |
| 232 | |
| 233 | // ModLambdaInstruction |
| 234 | |
Ray Milkey | 85571eb | 2015-06-25 09:45:46 -0700 | [diff] [blame] | 235 | private final IndexedLambda lambda1 = new IndexedLambda(1); |
| 236 | private final IndexedLambda lambda2 = new IndexedLambda(2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 237 | private final Instruction lambdaInstruction1 = Instructions.modL0Lambda(lambda1); |
| 238 | private final Instruction sameAsLambdaInstruction1 = Instructions.modL0Lambda(lambda1); |
| 239 | private final Instruction lambdaInstruction2 = Instructions.modL0Lambda(lambda2); |
| 240 | |
| 241 | /** |
| 242 | * Test the modL0Lambda method. |
| 243 | */ |
| 244 | @Test |
| 245 | public void testCreateLambdaMethod() { |
| 246 | final Instruction instruction = Instructions.modL0Lambda(lambda1); |
| 247 | final L0ModificationInstruction.ModLambdaInstruction lambdaInstruction = |
| 248 | checkAndConvert(instruction, |
| 249 | Instruction.Type.L0MODIFICATION, |
| 250 | L0ModificationInstruction.ModLambdaInstruction.class); |
Ray Milkey | 85571eb | 2015-06-25 09:45:46 -0700 | [diff] [blame] | 251 | assertThat(lambdaInstruction.lambda(), is(equalTo((short) lambda1.index()))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 254 | /** |
| 255 | * Test the equals() method of the ModLambdaInstruction class. |
| 256 | */ |
| 257 | |
| 258 | @Test |
| 259 | public void testModLambdaInstructionEquals() throws Exception { |
| 260 | checkEqualsAndToString(lambdaInstruction1, |
| 261 | sameAsLambdaInstruction1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 262 | lambdaInstruction2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Test the hashCode() method of the ModLambdaInstruction class. |
| 267 | */ |
| 268 | |
| 269 | @Test |
| 270 | public void testModLambdaInstructionHashCode() { |
| 271 | assertThat(lambdaInstruction1.hashCode(), |
| 272 | is(equalTo(sameAsLambdaInstruction1.hashCode()))); |
| 273 | assertThat(lambdaInstruction1.hashCode(), |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 274 | is(not(equalTo(lambdaInstruction2.hashCode())))); |
| 275 | } |
| 276 | |
| 277 | private final Lambda och1 = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8); |
| 278 | private final Lambda och2 = Lambda.ochSignal(GridType.CWDM, ChannelSpacing.CHL_100GHZ, 4, 8); |
| 279 | private final Instruction ochInstruction1 = Instructions.modL0Lambda(och1); |
| 280 | private final Instruction sameAsOchInstruction1 = Instructions.modL0Lambda(och1); |
| 281 | private final Instruction ochInstruction2 = Instructions.modL0Lambda(och2); |
| 282 | |
| 283 | /** |
| 284 | * Test the modL0Lambda(). |
| 285 | */ |
| 286 | @Test |
| 287 | public void testModL0LambdaMethod() { |
| 288 | Instruction instruction = Instructions.modL0Lambda(och1); |
| 289 | L0ModificationInstruction.ModOchSignalInstruction ochInstruction = |
| 290 | checkAndConvert(instruction, Instruction.Type.L0MODIFICATION, |
| 291 | L0ModificationInstruction.ModOchSignalInstruction.class); |
| 292 | assertThat(ochInstruction.lambda(), is(och1)); |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Test the equals() method of the ModOchSignalInstruction class. |
| 297 | */ |
| 298 | @Test |
| 299 | public void testModOchSignalInstructionEquals() { |
| 300 | checkEqualsAndToString(ochInstruction1, sameAsOchInstruction1, ochInstruction2); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Test the hashCode() method of the ModOchSignalInstruction class. |
| 305 | */ |
| 306 | @Test |
| 307 | public void testModOchSignalInstructionHashCode() { |
| 308 | assertThat(ochInstruction1.hashCode(), is(sameAsOchInstruction1.hashCode())); |
| 309 | assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode()))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 312 | // ModOduSignalIdInstruction |
| 313 | |
| 314 | private final OduSignalId odu1 = oduSignalId(1, 80, new byte[] {8, 7, 6, 5, 7, 6, 5, 7, 6, 5}); |
| 315 | private final OduSignalId odu2 = oduSignalId(2, 80, new byte[] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2}); |
| 316 | private final Instruction oduInstruction1 = Instructions.modL1OduSignalId(odu1); |
| 317 | private final Instruction sameAsOduInstruction1 = Instructions.modL1OduSignalId(odu1); |
| 318 | private final Instruction oduInstruction2 = Instructions.modL1OduSignalId(odu2); |
| 319 | |
| 320 | /** |
| 321 | * Test the modL1OduSignalId(). |
| 322 | */ |
| 323 | @Test |
| 324 | public void testModL1OduSignalIdMethod() { |
| 325 | Instruction instruction = Instructions.modL1OduSignalId(odu1); |
| 326 | L1ModificationInstruction.ModOduSignalIdInstruction oduInstruction = |
| 327 | checkAndConvert(instruction, Instruction.Type.L1MODIFICATION, |
| 328 | L1ModificationInstruction.ModOduSignalIdInstruction.class); |
| 329 | assertThat(oduInstruction.oduSignalId(), is(odu1)); |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Test the equals() method of the ModOduSignalInstruction class. |
| 334 | */ |
| 335 | @Test |
| 336 | public void testModOduSignalIdInstructionEquals() { |
| 337 | checkEqualsAndToString(oduInstruction1, sameAsOduInstruction1, oduInstruction2); |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Test the hashCode() method of the ModOduSignalInstruction class. |
| 342 | */ |
| 343 | @Test |
| 344 | public void testModOduSignalIdInstructionHashCode() { |
| 345 | assertThat(oduInstruction1.hashCode(), is(sameAsOduInstruction1.hashCode())); |
| 346 | assertThat(oduInstruction1.hashCode(), is(not(oduInstruction2.hashCode()))); |
| 347 | } |
| 348 | |
| 349 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 350 | // ModEtherInstruction |
| 351 | |
| 352 | private static final String MAC1 = "00:00:00:00:00:01"; |
| 353 | private static final String MAC2 = "00:00:00:00:00:02"; |
| 354 | private final MacAddress mac1 = MacAddress.valueOf(MAC1); |
| 355 | private final MacAddress mac2 = MacAddress.valueOf(MAC2); |
| 356 | private final Instruction modEtherInstruction1 = Instructions.modL2Src(mac1); |
| 357 | private final Instruction sameAsModEtherInstruction1 = Instructions.modL2Src(mac1); |
| 358 | private final Instruction modEtherInstruction2 = Instructions.modL2Src(mac2); |
| 359 | |
| 360 | /** |
| 361 | * Test the modL2Src method. |
| 362 | */ |
| 363 | @Test |
| 364 | public void testModL2SrcMethod() { |
| 365 | final Instruction instruction = Instructions.modL2Src(mac1); |
| 366 | final L2ModificationInstruction.ModEtherInstruction modEtherInstruction = |
| 367 | checkAndConvert(instruction, |
| 368 | Instruction.Type.L2MODIFICATION, |
| 369 | L2ModificationInstruction.ModEtherInstruction.class); |
| 370 | assertThat(modEtherInstruction.mac(), is(equalTo(mac1))); |
| 371 | assertThat(modEtherInstruction.subtype(), |
| 372 | is(equalTo(L2ModificationInstruction.L2SubType.ETH_SRC))); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Test the modL2Dst method. |
| 377 | */ |
| 378 | @Test |
| 379 | public void testModL2DstMethod() { |
| 380 | final Instruction instruction = Instructions.modL2Dst(mac1); |
| 381 | final L2ModificationInstruction.ModEtherInstruction modEtherInstruction = |
| 382 | checkAndConvert(instruction, |
| 383 | Instruction.Type.L2MODIFICATION, |
| 384 | L2ModificationInstruction.ModEtherInstruction.class); |
| 385 | assertThat(modEtherInstruction.mac(), is(equalTo(mac1))); |
| 386 | assertThat(modEtherInstruction.subtype(), |
| 387 | is(equalTo(L2ModificationInstruction.L2SubType.ETH_DST))); |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Test the equals() method of the ModEtherInstruction class. |
| 392 | */ |
| 393 | |
| 394 | @Test |
| 395 | public void testModEtherInstructionEquals() throws Exception { |
| 396 | checkEqualsAndToString(modEtherInstruction1, |
| 397 | sameAsModEtherInstruction1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 398 | modEtherInstruction2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Test the hashCode() method of the ModEtherInstruction class. |
| 403 | */ |
| 404 | |
| 405 | @Test |
| 406 | public void testModEtherInstructionHashCode() { |
| 407 | assertThat(modEtherInstruction1.hashCode(), |
| 408 | is(equalTo(sameAsModEtherInstruction1.hashCode()))); |
| 409 | assertThat(modEtherInstruction1.hashCode(), |
| 410 | is(not(equalTo(modEtherInstruction2.hashCode())))); |
| 411 | } |
| 412 | |
| 413 | |
| 414 | // ModVlanIdInstruction |
| 415 | |
| 416 | private final short vlan1 = 1; |
| 417 | private final short vlan2 = 2; |
| 418 | private final VlanId vlanId1 = VlanId.vlanId(vlan1); |
| 419 | private final VlanId vlanId2 = VlanId.vlanId(vlan2); |
| 420 | private final Instruction modVlanId1 = Instructions.modVlanId(vlanId1); |
| 421 | private final Instruction sameAsModVlanId1 = Instructions.modVlanId(vlanId1); |
| 422 | private final Instruction modVlanId2 = Instructions.modVlanId(vlanId2); |
| 423 | |
| 424 | /** |
| 425 | * Test the modVlanId method. |
| 426 | */ |
| 427 | @Test |
| 428 | public void testModVlanIdMethod() { |
| 429 | final Instruction instruction = Instructions.modVlanId(vlanId1); |
| 430 | final L2ModificationInstruction.ModVlanIdInstruction modEtherInstruction = |
| 431 | checkAndConvert(instruction, |
| 432 | Instruction.Type.L2MODIFICATION, |
| 433 | L2ModificationInstruction.ModVlanIdInstruction.class); |
| 434 | assertThat(modEtherInstruction.vlanId(), is(equalTo(vlanId1))); |
| 435 | assertThat(modEtherInstruction.subtype(), |
| 436 | is(equalTo(L2ModificationInstruction.L2SubType.VLAN_ID))); |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Test the equals() method of the ModVlanIdInstruction class. |
| 441 | */ |
| 442 | |
| 443 | @Test |
| 444 | public void testModVlanIdInstructionEquals() throws Exception { |
| 445 | checkEqualsAndToString(modVlanId1, |
| 446 | sameAsModVlanId1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 447 | modVlanId2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Test the hashCode() method of the ModEtherInstruction class. |
| 452 | */ |
| 453 | |
| 454 | @Test |
| 455 | public void testModVlanIdInstructionHashCode() { |
| 456 | assertThat(modVlanId1.hashCode(), |
| 457 | is(equalTo(sameAsModVlanId1.hashCode()))); |
| 458 | assertThat(modVlanId1.hashCode(), |
| 459 | is(not(equalTo(modVlanId2.hashCode())))); |
| 460 | } |
| 461 | |
| 462 | |
| 463 | // ModVlanPcpInstruction |
| 464 | |
| 465 | private final byte vlanPcp1 = 1; |
| 466 | private final byte vlanPcp2 = 2; |
| 467 | private final Instruction modVlanPcp1 = Instructions.modVlanPcp(vlanPcp1); |
| 468 | private final Instruction sameAsModVlanPcp1 = Instructions.modVlanPcp(vlanPcp1); |
| 469 | private final Instruction modVlanPcp2 = Instructions.modVlanPcp(vlanPcp2); |
| 470 | |
| 471 | /** |
| 472 | * Test the modVlanPcp method. |
| 473 | */ |
| 474 | @Test |
| 475 | public void testModVlanPcpMethod() { |
| 476 | final Instruction instruction = Instructions.modVlanPcp(vlanPcp1); |
| 477 | final L2ModificationInstruction.ModVlanPcpInstruction modEtherInstruction = |
| 478 | checkAndConvert(instruction, |
| 479 | Instruction.Type.L2MODIFICATION, |
| 480 | L2ModificationInstruction.ModVlanPcpInstruction.class); |
| 481 | assertThat(modEtherInstruction.vlanPcp(), is(equalTo(vlanPcp1))); |
| 482 | assertThat(modEtherInstruction.subtype(), |
| 483 | is(equalTo(L2ModificationInstruction.L2SubType.VLAN_PCP))); |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Test the equals() method of the ModVlanPcpInstruction class. |
| 488 | */ |
| 489 | |
| 490 | @Test |
| 491 | public void testModVlanPcpInstructionEquals() throws Exception { |
| 492 | checkEqualsAndToString(modVlanPcp1, |
| 493 | sameAsModVlanPcp1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 494 | modVlanPcp2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /** |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 498 | * Test the hashCode() method of the ModVlanPcp class. |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 499 | */ |
| 500 | |
| 501 | @Test |
| 502 | public void testModVlanPcpInstructionHashCode() { |
| 503 | assertThat(modVlanPcp1.hashCode(), |
| 504 | is(equalTo(sameAsModVlanPcp1.hashCode()))); |
| 505 | assertThat(modVlanPcp1.hashCode(), |
| 506 | is(not(equalTo(modVlanPcp2.hashCode())))); |
| 507 | } |
| 508 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 509 | // ModIPInstruction |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 510 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 511 | private static final String IP41 = "1.2.3.4"; |
| 512 | private static final String IP42 = "5.6.7.8"; |
| 513 | private IpAddress ip41 = IpAddress.valueOf(IP41); |
| 514 | private IpAddress ip42 = IpAddress.valueOf(IP42); |
| 515 | private final Instruction modIPInstruction1 = Instructions.modL3Src(ip41); |
| 516 | private final Instruction sameAsModIPInstruction1 = Instructions.modL3Src(ip41); |
| 517 | private final Instruction modIPInstruction2 = Instructions.modL3Src(ip42); |
| 518 | |
| 519 | private static final String IP61 = "1111::2222"; |
| 520 | private static final String IP62 = "3333::4444"; |
| 521 | private IpAddress ip61 = IpAddress.valueOf(IP61); |
| 522 | private IpAddress ip62 = IpAddress.valueOf(IP62); |
| 523 | private final Instruction modIPv6Instruction1 = |
| 524 | Instructions.modL3IPv6Src(ip61); |
| 525 | private final Instruction sameAsModIPv6Instruction1 = |
| 526 | Instructions.modL3IPv6Src(ip61); |
| 527 | private final Instruction modIPv6Instruction2 = |
| 528 | Instructions.modL3IPv6Src(ip62); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 529 | |
| 530 | /** |
| 531 | * Test the modL3Src method. |
| 532 | */ |
| 533 | @Test |
| 534 | public void testModL3SrcMethod() { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 535 | final Instruction instruction = Instructions.modL3Src(ip41); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 536 | final L3ModificationInstruction.ModIPInstruction modIPInstruction = |
| 537 | checkAndConvert(instruction, |
| 538 | Instruction.Type.L3MODIFICATION, |
| 539 | L3ModificationInstruction.ModIPInstruction.class); |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 540 | assertThat(modIPInstruction.ip(), is(equalTo(ip41))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 541 | assertThat(modIPInstruction.subtype(), |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 542 | is(equalTo(L3ModificationInstruction.L3SubType.IPV4_SRC))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /** |
| 546 | * Test the modL3Dst method. |
| 547 | */ |
| 548 | @Test |
| 549 | public void testModL3DstMethod() { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 550 | final Instruction instruction = Instructions.modL3Dst(ip41); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 551 | final L3ModificationInstruction.ModIPInstruction modIPInstruction = |
| 552 | checkAndConvert(instruction, |
| 553 | Instruction.Type.L3MODIFICATION, |
| 554 | L3ModificationInstruction.ModIPInstruction.class); |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 555 | assertThat(modIPInstruction.ip(), is(equalTo(ip41))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 556 | assertThat(modIPInstruction.subtype(), |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 557 | is(equalTo(L3ModificationInstruction.L3SubType.IPV4_DST))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 561 | * Test the modL3IPv6Src method. |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 562 | */ |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 563 | @Test |
| 564 | public void testModL3IPv6SrcMethod() { |
| 565 | final Instruction instruction = Instructions.modL3IPv6Src(ip61); |
| 566 | final L3ModificationInstruction.ModIPInstruction modIPInstruction = |
| 567 | checkAndConvert(instruction, |
| 568 | Instruction.Type.L3MODIFICATION, |
| 569 | L3ModificationInstruction.ModIPInstruction.class); |
| 570 | assertThat(modIPInstruction.ip(), is(equalTo(ip61))); |
| 571 | assertThat(modIPInstruction.subtype(), |
| 572 | is(equalTo(L3ModificationInstruction.L3SubType.IPV6_SRC))); |
| 573 | } |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 574 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 575 | /** |
| 576 | * Test the modL3IPv6Dst method. |
| 577 | */ |
| 578 | @Test |
| 579 | public void testModL3IPv6DstMethod() { |
| 580 | final Instruction instruction = Instructions.modL3IPv6Dst(ip61); |
| 581 | final L3ModificationInstruction.ModIPInstruction modIPInstruction = |
| 582 | checkAndConvert(instruction, |
| 583 | Instruction.Type.L3MODIFICATION, |
| 584 | L3ModificationInstruction.ModIPInstruction.class); |
| 585 | assertThat(modIPInstruction.ip(), is(equalTo(ip61))); |
| 586 | assertThat(modIPInstruction.subtype(), |
| 587 | is(equalTo(L3ModificationInstruction.L3SubType.IPV6_DST))); |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Test the equals() method of the ModIPInstruction class. |
| 592 | */ |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 593 | @Test |
| 594 | public void testModIPInstructionEquals() throws Exception { |
| 595 | checkEqualsAndToString(modIPInstruction1, |
| 596 | sameAsModIPInstruction1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 597 | modIPInstruction2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 601 | * Test the hashCode() method of the ModIPInstruction class. |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 602 | */ |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 603 | @Test |
| 604 | public void testModIPInstructionHashCode() { |
| 605 | assertThat(modIPInstruction1.hashCode(), |
| 606 | is(equalTo(sameAsModIPInstruction1.hashCode()))); |
| 607 | assertThat(modIPInstruction1.hashCode(), |
| 608 | is(not(equalTo(modIPInstruction2.hashCode())))); |
| 609 | } |
| 610 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 611 | private final int flowLabel1 = 0x11111; |
| 612 | private final int flowLabel2 = 0x22222; |
| 613 | private final Instruction modIPv6FlowLabelInstruction1 = |
| 614 | Instructions.modL3IPv6FlowLabel(flowLabel1); |
| 615 | private final Instruction sameAsModIPv6FlowLabelInstruction1 = |
| 616 | Instructions.modL3IPv6FlowLabel(flowLabel1); |
| 617 | private final Instruction modIPv6FlowLabelInstruction2 = |
| 618 | Instructions.modL3IPv6FlowLabel(flowLabel2); |
| 619 | |
| 620 | /** |
| 621 | * Test the modL3IPv6FlowLabel method. |
| 622 | */ |
| 623 | @Test |
| 624 | public void testModL3IPv6FlowLabelMethod() { |
| 625 | final Instruction instruction = |
| 626 | Instructions.modL3IPv6FlowLabel(flowLabel1); |
| 627 | final L3ModificationInstruction.ModIPv6FlowLabelInstruction |
| 628 | modIPv6FlowLabelInstruction = |
| 629 | checkAndConvert(instruction, |
| 630 | Instruction.Type.L3MODIFICATION, |
| 631 | L3ModificationInstruction.ModIPv6FlowLabelInstruction.class); |
| 632 | assertThat(modIPv6FlowLabelInstruction.flowLabel(), |
| 633 | is(equalTo(flowLabel1))); |
| 634 | assertThat(modIPv6FlowLabelInstruction.subtype(), |
| 635 | is(equalTo(L3ModificationInstruction.L3SubType.IPV6_FLABEL))); |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * Test the equals() method of the ModIPv6FlowLabelInstruction class. |
| 640 | */ |
| 641 | @Test |
| 642 | public void testModIPv6FlowLabelInstructionEquals() throws Exception { |
| 643 | checkEqualsAndToString(modIPv6FlowLabelInstruction1, |
| 644 | sameAsModIPv6FlowLabelInstruction1, |
| 645 | modIPv6FlowLabelInstruction2); |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * Test the hashCode() method of the ModIPv6FlowLabelInstruction class. |
| 650 | */ |
| 651 | @Test |
| 652 | public void testModIPv6FlowLabelInstructionHashCode() { |
| 653 | assertThat(modIPv6FlowLabelInstruction1.hashCode(), |
| 654 | is(equalTo(sameAsModIPv6FlowLabelInstruction1.hashCode()))); |
| 655 | assertThat(modIPv6FlowLabelInstruction1.hashCode(), |
| 656 | is(not(equalTo(modIPv6FlowLabelInstruction2.hashCode())))); |
| 657 | } |
| 658 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 659 | private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1)); |
| 660 | private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1)); |
| 661 | private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(MplsLabel.mplsLabel(2)); |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 662 | |
| 663 | /** |
| 664 | * Test the modMplsLabel method. |
| 665 | */ |
| 666 | @Test |
| 667 | public void testModMplsMethod() { |
HIGUCHI Yuta | 04b49fc | 2015-08-28 09:58:58 -0700 | [diff] [blame] | 668 | final MplsLabel mplsLabel = MplsLabel.mplsLabel(33); |
| 669 | final Instruction instruction = Instructions.modMplsLabel(mplsLabel); |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 670 | final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction = |
| 671 | checkAndConvert(instruction, |
| 672 | Instruction.Type.L2MODIFICATION, |
| 673 | L2ModificationInstruction.ModMplsLabelInstruction.class); |
HIGUCHI Yuta | 04b49fc | 2015-08-28 09:58:58 -0700 | [diff] [blame] | 674 | assertThat(modMplsLabelInstruction.mplsLabel(), is(equalTo(mplsLabel))); |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 675 | assertThat(modMplsLabelInstruction.subtype(), |
| 676 | is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL))); |
| 677 | } |
| 678 | |
| 679 | /** |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 680 | * Test the equals(), hashCode() and toString() methods of the |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 681 | * ModMplsLabelInstruction class. |
| 682 | */ |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 683 | @Test |
| 684 | public void testModMplsLabelInstructionEquals() throws Exception { |
| 685 | checkEqualsAndToString(modMplsLabelInstruction1, |
| 686 | sameAsModMplsLabelInstruction1, |
| 687 | modMplsLabelInstruction2); |
| 688 | } |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 689 | |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 690 | // ModTunnelIdInstruction |
| 691 | |
| 692 | private final long tunnelId1 = 1L; |
| 693 | private final long tunnelId2 = 2L; |
| 694 | private final Instruction modTunnelId1 = Instructions.modTunnelId(tunnelId1); |
| 695 | private final Instruction sameAsModTunnelId1 = Instructions.modTunnelId(tunnelId1); |
| 696 | private final Instruction modTunnelId2 = Instructions.modTunnelId(tunnelId2); |
| 697 | |
| 698 | /** |
| 699 | * Test the modTunnelId method. |
| 700 | */ |
| 701 | @Test |
| 702 | public void testModTunnelIdMethod() { |
| 703 | final Instruction instruction = Instructions.modTunnelId(tunnelId1); |
| 704 | final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction = |
| 705 | checkAndConvert(instruction, Instruction.Type.L2MODIFICATION, |
| 706 | L2ModificationInstruction.ModTunnelIdInstruction.class); |
| 707 | assertThat(modTunnelIdInstruction.tunnelId(), is(equalTo(tunnelId1))); |
| 708 | assertThat(modTunnelIdInstruction.subtype(), |
| 709 | is(equalTo(L2ModificationInstruction.L2SubType.TUNNEL_ID))); |
| 710 | } |
| 711 | |
| 712 | /*** |
| 713 | * Test the equals() method of the ModTunnelIdInstruction class. |
| 714 | */ |
| 715 | @Test |
| 716 | public void testModTunnelIdInstructionEquals() throws Exception { |
| 717 | checkEqualsAndToString(modTunnelId1, sameAsModTunnelId1, modTunnelId2); |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * Test the hashCode() method of the ModTunnelIdInstruction class. |
| 722 | */ |
| 723 | @Test |
| 724 | public void testModTunnelIdInstructionHashCode() { |
| 725 | assertThat(modTunnelId1.hashCode(), is(equalTo(sameAsModTunnelId1.hashCode()))); |
| 726 | assertThat(modTunnelId1.hashCode(), is(not(equalTo(modTunnelId2.hashCode())))); |
| 727 | } |
| 728 | |
| 729 | // ModTransportPortInstruction |
| 730 | |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 731 | private final TpPort tpPort1 = TpPort.tpPort(1); |
| 732 | private final TpPort tpPort2 = TpPort.tpPort(2); |
| 733 | private final Instruction modTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1); |
| 734 | private final Instruction sameAsModTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1); |
| 735 | private final Instruction modTransportPortInstruction2 = Instructions.modTcpSrc(tpPort2); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 736 | |
| 737 | /** |
| 738 | * Test the modTcpSrc() method. |
| 739 | */ |
| 740 | @Test |
| 741 | public void testModTcpSrcMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 742 | final Instruction instruction = Instructions.modTcpSrc(tpPort1); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 743 | final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = |
| 744 | checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, |
| 745 | L4ModificationInstruction.ModTransportPortInstruction.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 746 | assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1))); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 747 | assertThat(modTransportPortInstruction.subtype(), |
| 748 | is(equalTo(L4ModificationInstruction.L4SubType.TCP_SRC))); |
| 749 | } |
| 750 | |
| 751 | /** |
| 752 | * Test the modTcpDst() method. |
| 753 | */ |
| 754 | @Test |
| 755 | public void testModTcpDstMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 756 | final Instruction instruction = Instructions.modTcpDst(tpPort1); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 757 | final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = |
| 758 | checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, |
| 759 | L4ModificationInstruction.ModTransportPortInstruction.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 760 | assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1))); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 761 | assertThat(modTransportPortInstruction.subtype(), |
| 762 | is(equalTo(L4ModificationInstruction.L4SubType.TCP_DST))); |
| 763 | } |
| 764 | |
| 765 | /** |
| 766 | * Test the modUdpSrc() method. |
| 767 | */ |
| 768 | @Test |
| 769 | public void testModUdpSrcMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 770 | final Instruction instruction = Instructions.modUdpSrc(tpPort1); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 771 | final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = |
| 772 | checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, |
| 773 | L4ModificationInstruction.ModTransportPortInstruction.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 774 | assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1))); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 775 | assertThat(modTransportPortInstruction.subtype(), |
| 776 | is(equalTo(L4ModificationInstruction.L4SubType.UDP_SRC))); |
| 777 | } |
| 778 | |
| 779 | /** |
| 780 | * Test the modUdpDst() method. |
| 781 | */ |
| 782 | @Test |
| 783 | public void testModUdpDstMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 784 | final Instruction instruction = Instructions.modUdpDst(tpPort1); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 785 | final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = |
| 786 | checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, |
| 787 | L4ModificationInstruction.ModTransportPortInstruction.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 788 | assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1))); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 789 | assertThat(modTransportPortInstruction.subtype(), |
| 790 | is(equalTo(L4ModificationInstruction.L4SubType.UDP_DST))); |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * Test the equals() method of the ModTransportPortInstruction class. |
| 795 | */ |
| 796 | @Test |
| 797 | public void testModTransportPortInstructionEquals() throws Exception { |
| 798 | checkEqualsAndToString(modTransportPortInstruction1, |
| 799 | sameAsModTransportPortInstruction1, |
| 800 | modTransportPortInstruction2); |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * Test the hashCode() method of the ModTransportPortInstruction class. |
| 805 | */ |
| 806 | @Test |
| 807 | public void testModTransportPortInstructionHashCode() { |
| 808 | assertThat(modTransportPortInstruction1.hashCode(), |
| 809 | is(equalTo(sameAsModTransportPortInstruction1.hashCode()))); |
| 810 | assertThat(modTransportPortInstruction1.hashCode(), |
| 811 | is(not(equalTo(modTransportPortInstruction2.hashCode())))); |
| 812 | } |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 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 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 1392 | } |