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 | |
| 18 | import org.junit.Test; |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 19 | import org.onosproject.net.ChannelSpacing; |
| 20 | import org.onosproject.net.GridType; |
| 21 | import org.onosproject.net.Lambda; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.net.PortNumber; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 23 | import org.onlab.packet.IpAddress; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 24 | import org.onlab.packet.MacAddress; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 25 | import org.onlab.packet.MplsLabel; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 26 | import org.onlab.packet.VlanId; |
| 27 | |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 28 | import com.google.common.testing.EqualsTester; |
| 29 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 30 | import static org.hamcrest.MatcherAssert.assertThat; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 31 | import static org.hamcrest.Matchers.equalTo; |
| 32 | import static org.hamcrest.Matchers.instanceOf; |
| 33 | import static org.hamcrest.Matchers.is; |
| 34 | import static org.hamcrest.Matchers.not; |
| 35 | import static org.hamcrest.Matchers.notNullValue; |
| 36 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 37 | import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 38 | import static org.onosproject.net.PortNumber.portNumber; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Unit tests for the Instructions class. |
| 42 | */ |
| 43 | public class InstructionsTest { |
| 44 | |
| 45 | /** |
| 46 | * Checks that a Criterion object has the proper type, and then converts |
| 47 | * it to the proper type. |
| 48 | * |
| 49 | * @param instruction Instruction object to convert |
| 50 | * @param type Enumerated type value for the Criterion class |
| 51 | * @param clazz Desired Criterion class |
| 52 | * @param <T> The type the caller wants returned |
| 53 | * @return converted object |
| 54 | */ |
| 55 | @SuppressWarnings("unchecked") |
| 56 | private <T> T checkAndConvert(Instruction instruction, Instruction.Type type, Class clazz) { |
| 57 | assertThat(instruction, is(notNullValue())); |
| 58 | assertThat(instruction.type(), is(equalTo(type))); |
| 59 | assertThat(instruction, instanceOf(clazz)); |
| 60 | return (T) instruction; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Checks the equals() and toString() methods of a Criterion class. |
| 65 | * |
| 66 | * @param c1 first object to compare |
| 67 | * @param c1match object that should be equal to the first |
| 68 | * @param c2 object that should be not equal to the first |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 69 | * @param <T> type of the arguments |
| 70 | */ |
| 71 | private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 72 | T c2) { |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 73 | |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 74 | new EqualsTester() |
| 75 | .addEqualityGroup(c1, c1match) |
| 76 | .addEqualityGroup(c2) |
| 77 | .testEquals(); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Checks that Instructions is a proper utility class. |
| 82 | */ |
| 83 | @Test |
| 84 | public void testInstructionsUtilityClass() { |
| 85 | assertThatClassIsUtility(Instructions.class); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Checks that the Instruction class implementations are immutable. |
| 90 | */ |
| 91 | @Test |
| 92 | public void testImmutabilityOfInstructions() { |
| 93 | assertThatClassIsImmutable(Instructions.DropInstruction.class); |
| 94 | assertThatClassIsImmutable(Instructions.OutputInstruction.class); |
| 95 | assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class); |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 96 | assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 97 | assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class); |
| 98 | assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class); |
| 99 | assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class); |
| 100 | assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class); |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 101 | assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class); |
Ray Milkey | d03eda0 | 2015-01-09 14:58:48 -0800 | [diff] [blame] | 102 | assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class); |
| 103 | assertThatClassIsImmutable(L2ModificationInstruction.PushHeaderInstructions.class); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | // DropInstruction |
| 107 | |
| 108 | private final Instructions.DropInstruction drop1 = Instructions.createDrop(); |
| 109 | private final Instructions.DropInstruction drop2 = Instructions.createDrop(); |
| 110 | |
| 111 | /** |
| 112 | * Test the createDrop method. |
| 113 | */ |
| 114 | @Test |
| 115 | public void testCreateDropMethod() { |
| 116 | Instructions.DropInstruction instruction = Instructions.createDrop(); |
| 117 | checkAndConvert(instruction, |
| 118 | Instruction.Type.DROP, |
| 119 | Instructions.DropInstruction.class); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Test the equals() method of the DropInstruction class. |
| 124 | */ |
| 125 | |
| 126 | @Test |
| 127 | public void testDropInstructionEquals() throws Exception { |
| 128 | assertThat(drop1, is(equalTo(drop2))); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Test the hashCode() method of the DropInstruction class. |
| 133 | */ |
| 134 | |
| 135 | @Test |
| 136 | public void testDropInstructionHashCode() { |
| 137 | assertThat(drop1.hashCode(), is(equalTo(drop2.hashCode()))); |
| 138 | } |
| 139 | |
| 140 | // OutputInstruction |
| 141 | |
| 142 | private final PortNumber port1 = portNumber(1); |
| 143 | private final PortNumber port2 = portNumber(2); |
| 144 | private final Instructions.OutputInstruction output1 = Instructions.createOutput(port1); |
| 145 | private final Instructions.OutputInstruction sameAsOutput1 = Instructions.createOutput(port1); |
| 146 | private final Instructions.OutputInstruction output2 = Instructions.createOutput(port2); |
| 147 | |
| 148 | /** |
| 149 | * Test the createOutput method. |
| 150 | */ |
| 151 | @Test |
| 152 | public void testCreateOutputMethod() { |
| 153 | final Instruction instruction = Instructions.createOutput(port2); |
| 154 | final Instructions.OutputInstruction outputInstruction = |
| 155 | checkAndConvert(instruction, |
| 156 | Instruction.Type.OUTPUT, |
| 157 | Instructions.OutputInstruction.class); |
| 158 | assertThat(outputInstruction.port(), is(equalTo(port2))); |
| 159 | } |
| 160 | |
| 161 | |
| 162 | /** |
| 163 | * Test the equals() method of the OutputInstruction class. |
| 164 | */ |
| 165 | |
| 166 | @Test |
| 167 | public void testOutputInstructionEquals() throws Exception { |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 168 | checkEqualsAndToString(output1, sameAsOutput1, output2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Test the hashCode() method of the OutputInstruction class. |
| 173 | */ |
| 174 | |
| 175 | @Test |
| 176 | public void testOutputInstructionHashCode() { |
| 177 | assertThat(output1.hashCode(), is(equalTo(sameAsOutput1.hashCode()))); |
| 178 | assertThat(output1.hashCode(), is(not(equalTo(output2.hashCode())))); |
| 179 | } |
| 180 | |
| 181 | // ModLambdaInstruction |
| 182 | |
| 183 | private final short lambda1 = 1; |
| 184 | private final short lambda2 = 2; |
| 185 | private final Instruction lambdaInstruction1 = Instructions.modL0Lambda(lambda1); |
| 186 | private final Instruction sameAsLambdaInstruction1 = Instructions.modL0Lambda(lambda1); |
| 187 | private final Instruction lambdaInstruction2 = Instructions.modL0Lambda(lambda2); |
| 188 | |
| 189 | /** |
| 190 | * Test the modL0Lambda method. |
| 191 | */ |
| 192 | @Test |
| 193 | public void testCreateLambdaMethod() { |
| 194 | final Instruction instruction = Instructions.modL0Lambda(lambda1); |
| 195 | final L0ModificationInstruction.ModLambdaInstruction lambdaInstruction = |
| 196 | checkAndConvert(instruction, |
| 197 | Instruction.Type.L0MODIFICATION, |
| 198 | L0ModificationInstruction.ModLambdaInstruction.class); |
| 199 | assertThat(lambdaInstruction.lambda(), is(equalTo(lambda1))); |
| 200 | } |
| 201 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 202 | /** |
| 203 | * Test the equals() method of the ModLambdaInstruction class. |
| 204 | */ |
| 205 | |
| 206 | @Test |
| 207 | public void testModLambdaInstructionEquals() throws Exception { |
| 208 | checkEqualsAndToString(lambdaInstruction1, |
| 209 | sameAsLambdaInstruction1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 210 | lambdaInstruction2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Test the hashCode() method of the ModLambdaInstruction class. |
| 215 | */ |
| 216 | |
| 217 | @Test |
| 218 | public void testModLambdaInstructionHashCode() { |
| 219 | assertThat(lambdaInstruction1.hashCode(), |
| 220 | is(equalTo(sameAsLambdaInstruction1.hashCode()))); |
| 221 | assertThat(lambdaInstruction1.hashCode(), |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 222 | is(not(equalTo(lambdaInstruction2.hashCode())))); |
| 223 | } |
| 224 | |
| 225 | private final Lambda och1 = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8); |
| 226 | private final Lambda och2 = Lambda.ochSignal(GridType.CWDM, ChannelSpacing.CHL_100GHZ, 4, 8); |
| 227 | private final Instruction ochInstruction1 = Instructions.modL0Lambda(och1); |
| 228 | private final Instruction sameAsOchInstruction1 = Instructions.modL0Lambda(och1); |
| 229 | private final Instruction ochInstruction2 = Instructions.modL0Lambda(och2); |
| 230 | |
| 231 | /** |
| 232 | * Test the modL0Lambda(). |
| 233 | */ |
| 234 | @Test |
| 235 | public void testModL0LambdaMethod() { |
| 236 | Instruction instruction = Instructions.modL0Lambda(och1); |
| 237 | L0ModificationInstruction.ModOchSignalInstruction ochInstruction = |
| 238 | checkAndConvert(instruction, Instruction.Type.L0MODIFICATION, |
| 239 | L0ModificationInstruction.ModOchSignalInstruction.class); |
| 240 | assertThat(ochInstruction.lambda(), is(och1)); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Test the equals() method of the ModOchSignalInstruction class. |
| 245 | */ |
| 246 | @Test |
| 247 | public void testModOchSignalInstructionEquals() { |
| 248 | checkEqualsAndToString(ochInstruction1, sameAsOchInstruction1, ochInstruction2); |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Test the hashCode() method of the ModOchSignalInstruction class. |
| 253 | */ |
| 254 | @Test |
| 255 | public void testModOchSignalInstructionHashCode() { |
| 256 | assertThat(ochInstruction1.hashCode(), is(sameAsOchInstruction1.hashCode())); |
| 257 | assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode()))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // ModEtherInstruction |
| 261 | |
| 262 | private static final String MAC1 = "00:00:00:00:00:01"; |
| 263 | private static final String MAC2 = "00:00:00:00:00:02"; |
| 264 | private final MacAddress mac1 = MacAddress.valueOf(MAC1); |
| 265 | private final MacAddress mac2 = MacAddress.valueOf(MAC2); |
| 266 | private final Instruction modEtherInstruction1 = Instructions.modL2Src(mac1); |
| 267 | private final Instruction sameAsModEtherInstruction1 = Instructions.modL2Src(mac1); |
| 268 | private final Instruction modEtherInstruction2 = Instructions.modL2Src(mac2); |
| 269 | |
| 270 | /** |
| 271 | * Test the modL2Src method. |
| 272 | */ |
| 273 | @Test |
| 274 | public void testModL2SrcMethod() { |
| 275 | final Instruction instruction = Instructions.modL2Src(mac1); |
| 276 | final L2ModificationInstruction.ModEtherInstruction modEtherInstruction = |
| 277 | checkAndConvert(instruction, |
| 278 | Instruction.Type.L2MODIFICATION, |
| 279 | L2ModificationInstruction.ModEtherInstruction.class); |
| 280 | assertThat(modEtherInstruction.mac(), is(equalTo(mac1))); |
| 281 | assertThat(modEtherInstruction.subtype(), |
| 282 | is(equalTo(L2ModificationInstruction.L2SubType.ETH_SRC))); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Test the modL2Dst method. |
| 287 | */ |
| 288 | @Test |
| 289 | public void testModL2DstMethod() { |
| 290 | final Instruction instruction = Instructions.modL2Dst(mac1); |
| 291 | final L2ModificationInstruction.ModEtherInstruction modEtherInstruction = |
| 292 | checkAndConvert(instruction, |
| 293 | Instruction.Type.L2MODIFICATION, |
| 294 | L2ModificationInstruction.ModEtherInstruction.class); |
| 295 | assertThat(modEtherInstruction.mac(), is(equalTo(mac1))); |
| 296 | assertThat(modEtherInstruction.subtype(), |
| 297 | is(equalTo(L2ModificationInstruction.L2SubType.ETH_DST))); |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Test the equals() method of the ModEtherInstruction class. |
| 302 | */ |
| 303 | |
| 304 | @Test |
| 305 | public void testModEtherInstructionEquals() throws Exception { |
| 306 | checkEqualsAndToString(modEtherInstruction1, |
| 307 | sameAsModEtherInstruction1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 308 | modEtherInstruction2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Test the hashCode() method of the ModEtherInstruction class. |
| 313 | */ |
| 314 | |
| 315 | @Test |
| 316 | public void testModEtherInstructionHashCode() { |
| 317 | assertThat(modEtherInstruction1.hashCode(), |
| 318 | is(equalTo(sameAsModEtherInstruction1.hashCode()))); |
| 319 | assertThat(modEtherInstruction1.hashCode(), |
| 320 | is(not(equalTo(modEtherInstruction2.hashCode())))); |
| 321 | } |
| 322 | |
| 323 | |
| 324 | // ModVlanIdInstruction |
| 325 | |
| 326 | private final short vlan1 = 1; |
| 327 | private final short vlan2 = 2; |
| 328 | private final VlanId vlanId1 = VlanId.vlanId(vlan1); |
| 329 | private final VlanId vlanId2 = VlanId.vlanId(vlan2); |
| 330 | private final Instruction modVlanId1 = Instructions.modVlanId(vlanId1); |
| 331 | private final Instruction sameAsModVlanId1 = Instructions.modVlanId(vlanId1); |
| 332 | private final Instruction modVlanId2 = Instructions.modVlanId(vlanId2); |
| 333 | |
| 334 | /** |
| 335 | * Test the modVlanId method. |
| 336 | */ |
| 337 | @Test |
| 338 | public void testModVlanIdMethod() { |
| 339 | final Instruction instruction = Instructions.modVlanId(vlanId1); |
| 340 | final L2ModificationInstruction.ModVlanIdInstruction modEtherInstruction = |
| 341 | checkAndConvert(instruction, |
| 342 | Instruction.Type.L2MODIFICATION, |
| 343 | L2ModificationInstruction.ModVlanIdInstruction.class); |
| 344 | assertThat(modEtherInstruction.vlanId(), is(equalTo(vlanId1))); |
| 345 | assertThat(modEtherInstruction.subtype(), |
| 346 | is(equalTo(L2ModificationInstruction.L2SubType.VLAN_ID))); |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Test the equals() method of the ModVlanIdInstruction class. |
| 351 | */ |
| 352 | |
| 353 | @Test |
| 354 | public void testModVlanIdInstructionEquals() throws Exception { |
| 355 | checkEqualsAndToString(modVlanId1, |
| 356 | sameAsModVlanId1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 357 | modVlanId2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Test the hashCode() method of the ModEtherInstruction class. |
| 362 | */ |
| 363 | |
| 364 | @Test |
| 365 | public void testModVlanIdInstructionHashCode() { |
| 366 | assertThat(modVlanId1.hashCode(), |
| 367 | is(equalTo(sameAsModVlanId1.hashCode()))); |
| 368 | assertThat(modVlanId1.hashCode(), |
| 369 | is(not(equalTo(modVlanId2.hashCode())))); |
| 370 | } |
| 371 | |
| 372 | |
| 373 | // ModVlanPcpInstruction |
| 374 | |
| 375 | private final byte vlanPcp1 = 1; |
| 376 | private final byte vlanPcp2 = 2; |
| 377 | private final Instruction modVlanPcp1 = Instructions.modVlanPcp(vlanPcp1); |
| 378 | private final Instruction sameAsModVlanPcp1 = Instructions.modVlanPcp(vlanPcp1); |
| 379 | private final Instruction modVlanPcp2 = Instructions.modVlanPcp(vlanPcp2); |
| 380 | |
| 381 | /** |
| 382 | * Test the modVlanPcp method. |
| 383 | */ |
| 384 | @Test |
| 385 | public void testModVlanPcpMethod() { |
| 386 | final Instruction instruction = Instructions.modVlanPcp(vlanPcp1); |
| 387 | final L2ModificationInstruction.ModVlanPcpInstruction modEtherInstruction = |
| 388 | checkAndConvert(instruction, |
| 389 | Instruction.Type.L2MODIFICATION, |
| 390 | L2ModificationInstruction.ModVlanPcpInstruction.class); |
| 391 | assertThat(modEtherInstruction.vlanPcp(), is(equalTo(vlanPcp1))); |
| 392 | assertThat(modEtherInstruction.subtype(), |
| 393 | is(equalTo(L2ModificationInstruction.L2SubType.VLAN_PCP))); |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Test the equals() method of the ModVlanPcpInstruction class. |
| 398 | */ |
| 399 | |
| 400 | @Test |
| 401 | public void testModVlanPcpInstructionEquals() throws Exception { |
| 402 | checkEqualsAndToString(modVlanPcp1, |
| 403 | sameAsModVlanPcp1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 404 | modVlanPcp2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Test the hashCode() method of the ModEtherInstruction class. |
| 409 | */ |
| 410 | |
| 411 | @Test |
| 412 | public void testModVlanPcpInstructionHashCode() { |
| 413 | assertThat(modVlanPcp1.hashCode(), |
| 414 | is(equalTo(sameAsModVlanPcp1.hashCode()))); |
| 415 | assertThat(modVlanPcp1.hashCode(), |
| 416 | is(not(equalTo(modVlanPcp2.hashCode())))); |
| 417 | } |
| 418 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 419 | // ModIPInstruction |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 420 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 421 | private static final String IP41 = "1.2.3.4"; |
| 422 | private static final String IP42 = "5.6.7.8"; |
| 423 | private IpAddress ip41 = IpAddress.valueOf(IP41); |
| 424 | private IpAddress ip42 = IpAddress.valueOf(IP42); |
| 425 | private final Instruction modIPInstruction1 = Instructions.modL3Src(ip41); |
| 426 | private final Instruction sameAsModIPInstruction1 = Instructions.modL3Src(ip41); |
| 427 | private final Instruction modIPInstruction2 = Instructions.modL3Src(ip42); |
| 428 | |
| 429 | private static final String IP61 = "1111::2222"; |
| 430 | private static final String IP62 = "3333::4444"; |
| 431 | private IpAddress ip61 = IpAddress.valueOf(IP61); |
| 432 | private IpAddress ip62 = IpAddress.valueOf(IP62); |
| 433 | private final Instruction modIPv6Instruction1 = |
| 434 | Instructions.modL3IPv6Src(ip61); |
| 435 | private final Instruction sameAsModIPv6Instruction1 = |
| 436 | Instructions.modL3IPv6Src(ip61); |
| 437 | private final Instruction modIPv6Instruction2 = |
| 438 | Instructions.modL3IPv6Src(ip62); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 439 | |
| 440 | /** |
| 441 | * Test the modL3Src method. |
| 442 | */ |
| 443 | @Test |
| 444 | public void testModL3SrcMethod() { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 445 | final Instruction instruction = Instructions.modL3Src(ip41); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 446 | final L3ModificationInstruction.ModIPInstruction modIPInstruction = |
| 447 | checkAndConvert(instruction, |
| 448 | Instruction.Type.L3MODIFICATION, |
| 449 | L3ModificationInstruction.ModIPInstruction.class); |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 450 | assertThat(modIPInstruction.ip(), is(equalTo(ip41))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 451 | assertThat(modIPInstruction.subtype(), |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 452 | is(equalTo(L3ModificationInstruction.L3SubType.IPV4_SRC))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Test the modL3Dst method. |
| 457 | */ |
| 458 | @Test |
| 459 | public void testModL3DstMethod() { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 460 | final Instruction instruction = Instructions.modL3Dst(ip41); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 461 | final L3ModificationInstruction.ModIPInstruction modIPInstruction = |
| 462 | checkAndConvert(instruction, |
| 463 | Instruction.Type.L3MODIFICATION, |
| 464 | L3ModificationInstruction.ModIPInstruction.class); |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 465 | assertThat(modIPInstruction.ip(), is(equalTo(ip41))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 466 | assertThat(modIPInstruction.subtype(), |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 467 | is(equalTo(L3ModificationInstruction.L3SubType.IPV4_DST))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 471 | * Test the modL3IPv6Src method. |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 472 | */ |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 473 | @Test |
| 474 | public void testModL3IPv6SrcMethod() { |
| 475 | final Instruction instruction = Instructions.modL3IPv6Src(ip61); |
| 476 | final L3ModificationInstruction.ModIPInstruction modIPInstruction = |
| 477 | checkAndConvert(instruction, |
| 478 | Instruction.Type.L3MODIFICATION, |
| 479 | L3ModificationInstruction.ModIPInstruction.class); |
| 480 | assertThat(modIPInstruction.ip(), is(equalTo(ip61))); |
| 481 | assertThat(modIPInstruction.subtype(), |
| 482 | is(equalTo(L3ModificationInstruction.L3SubType.IPV6_SRC))); |
| 483 | } |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 484 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 485 | /** |
| 486 | * Test the modL3IPv6Dst method. |
| 487 | */ |
| 488 | @Test |
| 489 | public void testModL3IPv6DstMethod() { |
| 490 | final Instruction instruction = Instructions.modL3IPv6Dst(ip61); |
| 491 | final L3ModificationInstruction.ModIPInstruction modIPInstruction = |
| 492 | checkAndConvert(instruction, |
| 493 | Instruction.Type.L3MODIFICATION, |
| 494 | L3ModificationInstruction.ModIPInstruction.class); |
| 495 | assertThat(modIPInstruction.ip(), is(equalTo(ip61))); |
| 496 | assertThat(modIPInstruction.subtype(), |
| 497 | is(equalTo(L3ModificationInstruction.L3SubType.IPV6_DST))); |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Test the equals() method of the ModIPInstruction class. |
| 502 | */ |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 503 | @Test |
| 504 | public void testModIPInstructionEquals() throws Exception { |
| 505 | checkEqualsAndToString(modIPInstruction1, |
| 506 | sameAsModIPInstruction1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 507 | modIPInstruction2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 511 | * Test the hashCode() method of the ModIPInstruction class. |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 512 | */ |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 513 | @Test |
| 514 | public void testModIPInstructionHashCode() { |
| 515 | assertThat(modIPInstruction1.hashCode(), |
| 516 | is(equalTo(sameAsModIPInstruction1.hashCode()))); |
| 517 | assertThat(modIPInstruction1.hashCode(), |
| 518 | is(not(equalTo(modIPInstruction2.hashCode())))); |
| 519 | } |
| 520 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 521 | private final int flowLabel1 = 0x11111; |
| 522 | private final int flowLabel2 = 0x22222; |
| 523 | private final Instruction modIPv6FlowLabelInstruction1 = |
| 524 | Instructions.modL3IPv6FlowLabel(flowLabel1); |
| 525 | private final Instruction sameAsModIPv6FlowLabelInstruction1 = |
| 526 | Instructions.modL3IPv6FlowLabel(flowLabel1); |
| 527 | private final Instruction modIPv6FlowLabelInstruction2 = |
| 528 | Instructions.modL3IPv6FlowLabel(flowLabel2); |
| 529 | |
| 530 | /** |
| 531 | * Test the modL3IPv6FlowLabel method. |
| 532 | */ |
| 533 | @Test |
| 534 | public void testModL3IPv6FlowLabelMethod() { |
| 535 | final Instruction instruction = |
| 536 | Instructions.modL3IPv6FlowLabel(flowLabel1); |
| 537 | final L3ModificationInstruction.ModIPv6FlowLabelInstruction |
| 538 | modIPv6FlowLabelInstruction = |
| 539 | checkAndConvert(instruction, |
| 540 | Instruction.Type.L3MODIFICATION, |
| 541 | L3ModificationInstruction.ModIPv6FlowLabelInstruction.class); |
| 542 | assertThat(modIPv6FlowLabelInstruction.flowLabel(), |
| 543 | is(equalTo(flowLabel1))); |
| 544 | assertThat(modIPv6FlowLabelInstruction.subtype(), |
| 545 | is(equalTo(L3ModificationInstruction.L3SubType.IPV6_FLABEL))); |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * Test the equals() method of the ModIPv6FlowLabelInstruction class. |
| 550 | */ |
| 551 | @Test |
| 552 | public void testModIPv6FlowLabelInstructionEquals() throws Exception { |
| 553 | checkEqualsAndToString(modIPv6FlowLabelInstruction1, |
| 554 | sameAsModIPv6FlowLabelInstruction1, |
| 555 | modIPv6FlowLabelInstruction2); |
| 556 | } |
| 557 | |
| 558 | /** |
| 559 | * Test the hashCode() method of the ModIPv6FlowLabelInstruction class. |
| 560 | */ |
| 561 | @Test |
| 562 | public void testModIPv6FlowLabelInstructionHashCode() { |
| 563 | assertThat(modIPv6FlowLabelInstruction1.hashCode(), |
| 564 | is(equalTo(sameAsModIPv6FlowLabelInstruction1.hashCode()))); |
| 565 | assertThat(modIPv6FlowLabelInstruction1.hashCode(), |
| 566 | is(not(equalTo(modIPv6FlowLabelInstruction2.hashCode())))); |
| 567 | } |
| 568 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 569 | private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1)); |
| 570 | private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1)); |
| 571 | private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(MplsLabel.mplsLabel(2)); |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 572 | |
| 573 | /** |
| 574 | * Test the modMplsLabel method. |
| 575 | */ |
| 576 | @Test |
| 577 | public void testModMplsMethod() { |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 578 | final Instruction instruction = Instructions.modMplsLabel(MplsLabel.mplsLabel(33)); |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 579 | final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction = |
| 580 | checkAndConvert(instruction, |
| 581 | Instruction.Type.L2MODIFICATION, |
| 582 | L2ModificationInstruction.ModMplsLabelInstruction.class); |
| 583 | assertThat(modMplsLabelInstruction.label(), is(equalTo(33))); |
| 584 | assertThat(modMplsLabelInstruction.subtype(), |
| 585 | is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL))); |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Test the equals(), hashCode and toString() methods of the |
| 590 | * ModMplsLabelInstruction class. |
| 591 | */ |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 592 | @Test |
| 593 | public void testModMplsLabelInstructionEquals() throws Exception { |
| 594 | checkEqualsAndToString(modMplsLabelInstruction1, |
| 595 | sameAsModMplsLabelInstruction1, |
| 596 | modMplsLabelInstruction2); |
| 597 | } |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 598 | |
| 599 | } |