Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
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 | |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 18 | import com.google.common.testing.EqualsTester; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 19 | import org.junit.Test; |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 20 | import org.onlab.packet.EthType; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onlab.packet.MacAddress; |
| 23 | import org.onlab.packet.MplsLabel; |
| 24 | import org.onlab.packet.TpPort; |
| 25 | import org.onlab.packet.VlanId; |
Frank Wang | e33e4ed | 2017-06-28 10:01:07 +0800 | [diff] [blame] | 26 | import org.onlab.util.ImmutableByteSequence; |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 27 | import org.onosproject.core.GroupId; |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 28 | import org.onosproject.net.ChannelSpacing; |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 29 | import org.onosproject.net.DeviceId; |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 30 | import org.onosproject.net.GridType; |
| 31 | import org.onosproject.net.Lambda; |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 32 | import org.onosproject.net.OduSignalId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.net.PortNumber; |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 34 | import org.onosproject.net.meter.MeterId; |
Frank Wang | e33e4ed | 2017-06-28 10:01:07 +0800 | [diff] [blame] | 35 | import org.onosproject.net.pi.runtime.PiAction; |
| 36 | import org.onosproject.net.pi.runtime.PiActionId; |
| 37 | import org.onosproject.net.pi.runtime.PiActionParam; |
| 38 | import org.onosproject.net.pi.runtime.PiActionParamId; |
| 39 | import org.onosproject.net.pi.runtime.PiTableAction; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 40 | |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 41 | import java.util.List; |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 42 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 43 | import static org.hamcrest.MatcherAssert.assertThat; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 44 | import static org.hamcrest.Matchers.equalTo; |
| 45 | import static org.hamcrest.Matchers.instanceOf; |
| 46 | import static org.hamcrest.Matchers.is; |
| 47 | import static org.hamcrest.Matchers.not; |
| 48 | import static org.hamcrest.Matchers.notNullValue; |
| 49 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 50 | import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility; |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 51 | import static org.onosproject.net.OduSignalId.oduSignalId; |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 52 | import static org.onosproject.net.PortNumber.portNumber; |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Unit tests for the Instructions class. |
| 56 | */ |
| 57 | public class InstructionsTest { |
| 58 | |
| 59 | /** |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 60 | * Checks that an Instruction object has the proper type, and then converts |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 61 | * it to the proper type. |
| 62 | * |
| 63 | * @param instruction Instruction object to convert |
| 64 | * @param type Enumerated type value for the Criterion class |
| 65 | * @param clazz Desired Criterion class |
| 66 | * @param <T> The type the caller wants returned |
| 67 | * @return converted object |
| 68 | */ |
| 69 | @SuppressWarnings("unchecked") |
| 70 | private <T> T checkAndConvert(Instruction instruction, Instruction.Type type, Class clazz) { |
| 71 | assertThat(instruction, is(notNullValue())); |
| 72 | assertThat(instruction.type(), is(equalTo(type))); |
| 73 | assertThat(instruction, instanceOf(clazz)); |
| 74 | return (T) instruction; |
| 75 | } |
| 76 | |
| 77 | /** |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 78 | * Checks the equals() and toString() methods of a Instruction class. |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 79 | * |
| 80 | * @param c1 first object to compare |
| 81 | * @param c1match object that should be equal to the first |
| 82 | * @param c2 object that should be not equal to the first |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 83 | * @param <T> type of the arguments |
| 84 | */ |
| 85 | private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 86 | T c2) { |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 87 | |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 88 | new EqualsTester() |
| 89 | .addEqualityGroup(c1, c1match) |
| 90 | .addEqualityGroup(c2) |
| 91 | .testEquals(); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Checks that Instructions is a proper utility class. |
| 96 | */ |
| 97 | @Test |
| 98 | public void testInstructionsUtilityClass() { |
| 99 | assertThatClassIsUtility(Instructions.class); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Checks that the Instruction class implementations are immutable. |
| 104 | */ |
| 105 | @Test |
| 106 | public void testImmutabilityOfInstructions() { |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 107 | assertThatClassIsImmutable(Instructions.OutputInstruction.class); |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 108 | assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class); |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 109 | assertThatClassIsImmutable(L1ModificationInstruction.ModOduSignalIdInstruction.class); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 110 | assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class); |
| 111 | assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class); |
| 112 | assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class); |
| 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); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 116 | assertThatClassIsImmutable(L2ModificationInstruction.ModMplsHeaderInstruction.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); |
Frank Wang | e33e4ed | 2017-06-28 10:01:07 +0800 | [diff] [blame] | 120 | assertThatClassIsImmutable(PiInstruction.class); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | // NoActionInstruction |
| 124 | |
| 125 | private final Instructions.NoActionInstruction noAction1 = Instructions.createNoAction(); |
| 126 | private final Instructions.NoActionInstruction noAction2 = Instructions.createNoAction(); |
| 127 | |
| 128 | /** |
| 129 | * Test the createNoAction method. |
| 130 | */ |
| 131 | @Test |
| 132 | public void testCreateNoActionMethod() { |
| 133 | Instructions.NoActionInstruction instruction = Instructions.createNoAction(); |
| 134 | checkAndConvert(instruction, |
| 135 | Instruction.Type.NOACTION, |
| 136 | Instructions.NoActionInstruction.class); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Test the equals() method of the NoActionInstruction class. |
| 141 | */ |
| 142 | |
| 143 | @Test |
| 144 | public void testNoActionInstructionEquals() throws Exception { |
| 145 | new EqualsTester() |
| 146 | .addEqualityGroup(noAction1, noAction2) |
| 147 | .testEquals(); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Test the hashCode() method of the NoActionInstruction class. |
| 152 | */ |
| 153 | |
| 154 | @Test |
| 155 | public void testNoActionInstructionHashCode() { |
| 156 | assertThat(noAction1.hashCode(), is(equalTo(noAction2.hashCode()))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 159 | // OutputInstruction |
| 160 | |
| 161 | private final PortNumber port1 = portNumber(1); |
| 162 | private final PortNumber port2 = portNumber(2); |
| 163 | private final Instructions.OutputInstruction output1 = Instructions.createOutput(port1); |
| 164 | private final Instructions.OutputInstruction sameAsOutput1 = Instructions.createOutput(port1); |
| 165 | private final Instructions.OutputInstruction output2 = Instructions.createOutput(port2); |
| 166 | |
| 167 | /** |
| 168 | * Test the createOutput method. |
| 169 | */ |
| 170 | @Test |
| 171 | public void testCreateOutputMethod() { |
| 172 | final Instruction instruction = Instructions.createOutput(port2); |
| 173 | final Instructions.OutputInstruction outputInstruction = |
| 174 | checkAndConvert(instruction, |
| 175 | Instruction.Type.OUTPUT, |
| 176 | Instructions.OutputInstruction.class); |
| 177 | assertThat(outputInstruction.port(), is(equalTo(port2))); |
| 178 | } |
| 179 | |
| 180 | |
| 181 | /** |
| 182 | * Test the equals() method of the OutputInstruction class. |
| 183 | */ |
| 184 | |
| 185 | @Test |
| 186 | public void testOutputInstructionEquals() throws Exception { |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 187 | checkEqualsAndToString(output1, sameAsOutput1, output2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Test the hashCode() method of the OutputInstruction class. |
| 192 | */ |
| 193 | |
| 194 | @Test |
| 195 | public void testOutputInstructionHashCode() { |
| 196 | assertThat(output1.hashCode(), is(equalTo(sameAsOutput1.hashCode()))); |
| 197 | assertThat(output1.hashCode(), is(not(equalTo(output2.hashCode())))); |
| 198 | } |
| 199 | |
| 200 | // ModLambdaInstruction |
| 201 | |
Sho SHIMIZU | 5a5a734 | 2015-05-05 16:26:11 -0700 | [diff] [blame] | 202 | private final Lambda och1 = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8); |
| 203 | private final Lambda och2 = Lambda.ochSignal(GridType.CWDM, ChannelSpacing.CHL_100GHZ, 4, 8); |
| 204 | private final Instruction ochInstruction1 = Instructions.modL0Lambda(och1); |
| 205 | private final Instruction sameAsOchInstruction1 = Instructions.modL0Lambda(och1); |
| 206 | private final Instruction ochInstruction2 = Instructions.modL0Lambda(och2); |
| 207 | |
| 208 | /** |
| 209 | * Test the modL0Lambda(). |
| 210 | */ |
| 211 | @Test |
| 212 | public void testModL0LambdaMethod() { |
| 213 | Instruction instruction = Instructions.modL0Lambda(och1); |
| 214 | L0ModificationInstruction.ModOchSignalInstruction ochInstruction = |
| 215 | checkAndConvert(instruction, Instruction.Type.L0MODIFICATION, |
| 216 | L0ModificationInstruction.ModOchSignalInstruction.class); |
| 217 | assertThat(ochInstruction.lambda(), is(och1)); |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Test the equals() method of the ModOchSignalInstruction class. |
| 222 | */ |
| 223 | @Test |
| 224 | public void testModOchSignalInstructionEquals() { |
| 225 | checkEqualsAndToString(ochInstruction1, sameAsOchInstruction1, ochInstruction2); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Test the hashCode() method of the ModOchSignalInstruction class. |
| 230 | */ |
| 231 | @Test |
| 232 | public void testModOchSignalInstructionHashCode() { |
| 233 | assertThat(ochInstruction1.hashCode(), is(sameAsOchInstruction1.hashCode())); |
| 234 | assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode()))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 237 | // ModOduSignalIdInstruction |
| 238 | |
| 239 | private final OduSignalId odu1 = oduSignalId(1, 80, new byte[] {8, 7, 6, 5, 7, 6, 5, 7, 6, 5}); |
| 240 | private final OduSignalId odu2 = oduSignalId(2, 80, new byte[] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2}); |
| 241 | private final Instruction oduInstruction1 = Instructions.modL1OduSignalId(odu1); |
| 242 | private final Instruction sameAsOduInstruction1 = Instructions.modL1OduSignalId(odu1); |
| 243 | private final Instruction oduInstruction2 = Instructions.modL1OduSignalId(odu2); |
| 244 | |
| 245 | /** |
| 246 | * Test the modL1OduSignalId(). |
| 247 | */ |
| 248 | @Test |
| 249 | public void testModL1OduSignalIdMethod() { |
| 250 | Instruction instruction = Instructions.modL1OduSignalId(odu1); |
| 251 | L1ModificationInstruction.ModOduSignalIdInstruction oduInstruction = |
| 252 | checkAndConvert(instruction, Instruction.Type.L1MODIFICATION, |
| 253 | L1ModificationInstruction.ModOduSignalIdInstruction.class); |
| 254 | assertThat(oduInstruction.oduSignalId(), is(odu1)); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Test the equals() method of the ModOduSignalInstruction class. |
| 259 | */ |
| 260 | @Test |
| 261 | public void testModOduSignalIdInstructionEquals() { |
| 262 | checkEqualsAndToString(oduInstruction1, sameAsOduInstruction1, oduInstruction2); |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Test the hashCode() method of the ModOduSignalInstruction class. |
| 267 | */ |
| 268 | @Test |
| 269 | public void testModOduSignalIdInstructionHashCode() { |
| 270 | assertThat(oduInstruction1.hashCode(), is(sameAsOduInstruction1.hashCode())); |
| 271 | assertThat(oduInstruction1.hashCode(), is(not(oduInstruction2.hashCode()))); |
| 272 | } |
| 273 | |
| 274 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 275 | // ModEtherInstruction |
| 276 | |
| 277 | private static final String MAC1 = "00:00:00:00:00:01"; |
| 278 | private static final String MAC2 = "00:00:00:00:00:02"; |
| 279 | private final MacAddress mac1 = MacAddress.valueOf(MAC1); |
| 280 | private final MacAddress mac2 = MacAddress.valueOf(MAC2); |
| 281 | private final Instruction modEtherInstruction1 = Instructions.modL2Src(mac1); |
| 282 | private final Instruction sameAsModEtherInstruction1 = Instructions.modL2Src(mac1); |
| 283 | private final Instruction modEtherInstruction2 = Instructions.modL2Src(mac2); |
| 284 | |
| 285 | /** |
| 286 | * Test the modL2Src method. |
| 287 | */ |
| 288 | @Test |
| 289 | public void testModL2SrcMethod() { |
| 290 | final Instruction instruction = Instructions.modL2Src(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_SRC))); |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Test the modL2Dst method. |
| 302 | */ |
| 303 | @Test |
| 304 | public void testModL2DstMethod() { |
| 305 | final Instruction instruction = Instructions.modL2Dst(mac1); |
| 306 | final L2ModificationInstruction.ModEtherInstruction modEtherInstruction = |
| 307 | checkAndConvert(instruction, |
| 308 | Instruction.Type.L2MODIFICATION, |
| 309 | L2ModificationInstruction.ModEtherInstruction.class); |
| 310 | assertThat(modEtherInstruction.mac(), is(equalTo(mac1))); |
| 311 | assertThat(modEtherInstruction.subtype(), |
| 312 | is(equalTo(L2ModificationInstruction.L2SubType.ETH_DST))); |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Test the equals() method of the ModEtherInstruction class. |
| 317 | */ |
| 318 | |
| 319 | @Test |
| 320 | public void testModEtherInstructionEquals() throws Exception { |
| 321 | checkEqualsAndToString(modEtherInstruction1, |
| 322 | sameAsModEtherInstruction1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 323 | modEtherInstruction2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Test the hashCode() method of the ModEtherInstruction class. |
| 328 | */ |
| 329 | |
| 330 | @Test |
| 331 | public void testModEtherInstructionHashCode() { |
| 332 | assertThat(modEtherInstruction1.hashCode(), |
| 333 | is(equalTo(sameAsModEtherInstruction1.hashCode()))); |
| 334 | assertThat(modEtherInstruction1.hashCode(), |
| 335 | is(not(equalTo(modEtherInstruction2.hashCode())))); |
| 336 | } |
| 337 | |
| 338 | |
| 339 | // ModVlanIdInstruction |
| 340 | |
| 341 | private final short vlan1 = 1; |
| 342 | private final short vlan2 = 2; |
| 343 | private final VlanId vlanId1 = VlanId.vlanId(vlan1); |
| 344 | private final VlanId vlanId2 = VlanId.vlanId(vlan2); |
| 345 | private final Instruction modVlanId1 = Instructions.modVlanId(vlanId1); |
| 346 | private final Instruction sameAsModVlanId1 = Instructions.modVlanId(vlanId1); |
| 347 | private final Instruction modVlanId2 = Instructions.modVlanId(vlanId2); |
| 348 | |
| 349 | /** |
| 350 | * Test the modVlanId method. |
| 351 | */ |
| 352 | @Test |
| 353 | public void testModVlanIdMethod() { |
| 354 | final Instruction instruction = Instructions.modVlanId(vlanId1); |
| 355 | final L2ModificationInstruction.ModVlanIdInstruction modEtherInstruction = |
| 356 | checkAndConvert(instruction, |
| 357 | Instruction.Type.L2MODIFICATION, |
| 358 | L2ModificationInstruction.ModVlanIdInstruction.class); |
| 359 | assertThat(modEtherInstruction.vlanId(), is(equalTo(vlanId1))); |
| 360 | assertThat(modEtherInstruction.subtype(), |
| 361 | is(equalTo(L2ModificationInstruction.L2SubType.VLAN_ID))); |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Test the equals() method of the ModVlanIdInstruction class. |
| 366 | */ |
| 367 | |
| 368 | @Test |
| 369 | public void testModVlanIdInstructionEquals() throws Exception { |
| 370 | checkEqualsAndToString(modVlanId1, |
| 371 | sameAsModVlanId1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 372 | modVlanId2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Test the hashCode() method of the ModEtherInstruction class. |
| 377 | */ |
| 378 | |
| 379 | @Test |
| 380 | public void testModVlanIdInstructionHashCode() { |
| 381 | assertThat(modVlanId1.hashCode(), |
| 382 | is(equalTo(sameAsModVlanId1.hashCode()))); |
| 383 | assertThat(modVlanId1.hashCode(), |
| 384 | is(not(equalTo(modVlanId2.hashCode())))); |
| 385 | } |
| 386 | |
| 387 | |
| 388 | // ModVlanPcpInstruction |
| 389 | |
| 390 | private final byte vlanPcp1 = 1; |
| 391 | private final byte vlanPcp2 = 2; |
| 392 | private final Instruction modVlanPcp1 = Instructions.modVlanPcp(vlanPcp1); |
| 393 | private final Instruction sameAsModVlanPcp1 = Instructions.modVlanPcp(vlanPcp1); |
| 394 | private final Instruction modVlanPcp2 = Instructions.modVlanPcp(vlanPcp2); |
| 395 | |
| 396 | /** |
| 397 | * Test the modVlanPcp method. |
| 398 | */ |
| 399 | @Test |
| 400 | public void testModVlanPcpMethod() { |
| 401 | final Instruction instruction = Instructions.modVlanPcp(vlanPcp1); |
| 402 | final L2ModificationInstruction.ModVlanPcpInstruction modEtherInstruction = |
| 403 | checkAndConvert(instruction, |
| 404 | Instruction.Type.L2MODIFICATION, |
| 405 | L2ModificationInstruction.ModVlanPcpInstruction.class); |
| 406 | assertThat(modEtherInstruction.vlanPcp(), is(equalTo(vlanPcp1))); |
| 407 | assertThat(modEtherInstruction.subtype(), |
| 408 | is(equalTo(L2ModificationInstruction.L2SubType.VLAN_PCP))); |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * Test the equals() method of the ModVlanPcpInstruction class. |
| 413 | */ |
| 414 | |
| 415 | @Test |
| 416 | public void testModVlanPcpInstructionEquals() throws Exception { |
| 417 | checkEqualsAndToString(modVlanPcp1, |
| 418 | sameAsModVlanPcp1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 419 | modVlanPcp2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /** |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 423 | * Test the hashCode() method of the ModVlanPcp class. |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 424 | */ |
| 425 | |
| 426 | @Test |
| 427 | public void testModVlanPcpInstructionHashCode() { |
| 428 | assertThat(modVlanPcp1.hashCode(), |
| 429 | is(equalTo(sameAsModVlanPcp1.hashCode()))); |
| 430 | assertThat(modVlanPcp1.hashCode(), |
| 431 | is(not(equalTo(modVlanPcp2.hashCode())))); |
| 432 | } |
| 433 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 434 | // ModIPInstruction |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 435 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 436 | private static final String IP41 = "1.2.3.4"; |
| 437 | private static final String IP42 = "5.6.7.8"; |
| 438 | private IpAddress ip41 = IpAddress.valueOf(IP41); |
| 439 | private IpAddress ip42 = IpAddress.valueOf(IP42); |
| 440 | private final Instruction modIPInstruction1 = Instructions.modL3Src(ip41); |
| 441 | private final Instruction sameAsModIPInstruction1 = Instructions.modL3Src(ip41); |
| 442 | private final Instruction modIPInstruction2 = Instructions.modL3Src(ip42); |
| 443 | |
| 444 | private static final String IP61 = "1111::2222"; |
| 445 | private static final String IP62 = "3333::4444"; |
| 446 | private IpAddress ip61 = IpAddress.valueOf(IP61); |
| 447 | private IpAddress ip62 = IpAddress.valueOf(IP62); |
| 448 | private final Instruction modIPv6Instruction1 = |
| 449 | Instructions.modL3IPv6Src(ip61); |
| 450 | private final Instruction sameAsModIPv6Instruction1 = |
| 451 | Instructions.modL3IPv6Src(ip61); |
| 452 | private final Instruction modIPv6Instruction2 = |
| 453 | Instructions.modL3IPv6Src(ip62); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 454 | |
| 455 | /** |
| 456 | * Test the modL3Src method. |
| 457 | */ |
| 458 | @Test |
| 459 | public void testModL3SrcMethod() { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 460 | final Instruction instruction = Instructions.modL3Src(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_SRC))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Test the modL3Dst method. |
| 472 | */ |
| 473 | @Test |
| 474 | public void testModL3DstMethod() { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 475 | final Instruction instruction = Instructions.modL3Dst(ip41); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 476 | final L3ModificationInstruction.ModIPInstruction modIPInstruction = |
| 477 | checkAndConvert(instruction, |
| 478 | Instruction.Type.L3MODIFICATION, |
| 479 | L3ModificationInstruction.ModIPInstruction.class); |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 480 | assertThat(modIPInstruction.ip(), is(equalTo(ip41))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 481 | assertThat(modIPInstruction.subtype(), |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 482 | is(equalTo(L3ModificationInstruction.L3SubType.IPV4_DST))); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 486 | * Test the modL3IPv6Src method. |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 487 | */ |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 488 | @Test |
| 489 | public void testModL3IPv6SrcMethod() { |
| 490 | final Instruction instruction = Instructions.modL3IPv6Src(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_SRC))); |
| 498 | } |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 499 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 500 | /** |
| 501 | * Test the modL3IPv6Dst method. |
| 502 | */ |
| 503 | @Test |
| 504 | public void testModL3IPv6DstMethod() { |
| 505 | final Instruction instruction = Instructions.modL3IPv6Dst(ip61); |
| 506 | final L3ModificationInstruction.ModIPInstruction modIPInstruction = |
| 507 | checkAndConvert(instruction, |
| 508 | Instruction.Type.L3MODIFICATION, |
| 509 | L3ModificationInstruction.ModIPInstruction.class); |
| 510 | assertThat(modIPInstruction.ip(), is(equalTo(ip61))); |
| 511 | assertThat(modIPInstruction.subtype(), |
| 512 | is(equalTo(L3ModificationInstruction.L3SubType.IPV6_DST))); |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * Test the equals() method of the ModIPInstruction class. |
| 517 | */ |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 518 | @Test |
| 519 | public void testModIPInstructionEquals() throws Exception { |
| 520 | checkEqualsAndToString(modIPInstruction1, |
| 521 | sameAsModIPInstruction1, |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 522 | modIPInstruction2); |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 526 | * Test the hashCode() method of the ModIPInstruction class. |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 527 | */ |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 528 | @Test |
| 529 | public void testModIPInstructionHashCode() { |
| 530 | assertThat(modIPInstruction1.hashCode(), |
| 531 | is(equalTo(sameAsModIPInstruction1.hashCode()))); |
| 532 | assertThat(modIPInstruction1.hashCode(), |
| 533 | is(not(equalTo(modIPInstruction2.hashCode())))); |
| 534 | } |
| 535 | |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 536 | private final int flowLabel1 = 0x11111; |
| 537 | private final int flowLabel2 = 0x22222; |
| 538 | private final Instruction modIPv6FlowLabelInstruction1 = |
| 539 | Instructions.modL3IPv6FlowLabel(flowLabel1); |
| 540 | private final Instruction sameAsModIPv6FlowLabelInstruction1 = |
| 541 | Instructions.modL3IPv6FlowLabel(flowLabel1); |
| 542 | private final Instruction modIPv6FlowLabelInstruction2 = |
| 543 | Instructions.modL3IPv6FlowLabel(flowLabel2); |
| 544 | |
| 545 | /** |
| 546 | * Test the modL3IPv6FlowLabel method. |
| 547 | */ |
| 548 | @Test |
| 549 | public void testModL3IPv6FlowLabelMethod() { |
| 550 | final Instruction instruction = |
| 551 | Instructions.modL3IPv6FlowLabel(flowLabel1); |
| 552 | final L3ModificationInstruction.ModIPv6FlowLabelInstruction |
| 553 | modIPv6FlowLabelInstruction = |
| 554 | checkAndConvert(instruction, |
| 555 | Instruction.Type.L3MODIFICATION, |
| 556 | L3ModificationInstruction.ModIPv6FlowLabelInstruction.class); |
| 557 | assertThat(modIPv6FlowLabelInstruction.flowLabel(), |
| 558 | is(equalTo(flowLabel1))); |
| 559 | assertThat(modIPv6FlowLabelInstruction.subtype(), |
| 560 | is(equalTo(L3ModificationInstruction.L3SubType.IPV6_FLABEL))); |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * Test the equals() method of the ModIPv6FlowLabelInstruction class. |
| 565 | */ |
| 566 | @Test |
| 567 | public void testModIPv6FlowLabelInstructionEquals() throws Exception { |
| 568 | checkEqualsAndToString(modIPv6FlowLabelInstruction1, |
| 569 | sameAsModIPv6FlowLabelInstruction1, |
| 570 | modIPv6FlowLabelInstruction2); |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * Test the hashCode() method of the ModIPv6FlowLabelInstruction class. |
| 575 | */ |
| 576 | @Test |
| 577 | public void testModIPv6FlowLabelInstructionHashCode() { |
| 578 | assertThat(modIPv6FlowLabelInstruction1.hashCode(), |
| 579 | is(equalTo(sameAsModIPv6FlowLabelInstruction1.hashCode()))); |
| 580 | assertThat(modIPv6FlowLabelInstruction1.hashCode(), |
| 581 | is(not(equalTo(modIPv6FlowLabelInstruction2.hashCode())))); |
| 582 | } |
| 583 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 584 | private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1)); |
| 585 | private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1)); |
| 586 | private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(MplsLabel.mplsLabel(2)); |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 587 | |
| 588 | /** |
| 589 | * Test the modMplsLabel method. |
| 590 | */ |
| 591 | @Test |
| 592 | public void testModMplsMethod() { |
HIGUCHI Yuta | 04b49fc | 2015-08-28 09:58:58 -0700 | [diff] [blame] | 593 | final MplsLabel mplsLabel = MplsLabel.mplsLabel(33); |
| 594 | final Instruction instruction = Instructions.modMplsLabel(mplsLabel); |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 595 | final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction = |
| 596 | checkAndConvert(instruction, |
| 597 | Instruction.Type.L2MODIFICATION, |
| 598 | L2ModificationInstruction.ModMplsLabelInstruction.class); |
Ray Milkey | 125572b | 2016-02-22 16:48:17 -0800 | [diff] [blame] | 599 | assertThat(modMplsLabelInstruction.label(), is(equalTo(mplsLabel))); |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 600 | assertThat(modMplsLabelInstruction.subtype(), |
| 601 | is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL))); |
| 602 | } |
| 603 | |
| 604 | /** |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 605 | * Test the equals(), hashCode() and toString() methods of the |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 606 | * ModMplsLabelInstruction class. |
| 607 | */ |
Ray Milkey | 0d33805 | 2014-11-21 16:40:12 -0800 | [diff] [blame] | 608 | @Test |
| 609 | public void testModMplsLabelInstructionEquals() throws Exception { |
| 610 | checkEqualsAndToString(modMplsLabelInstruction1, |
| 611 | sameAsModMplsLabelInstruction1, |
| 612 | modMplsLabelInstruction2); |
| 613 | } |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 614 | |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 615 | // ModTunnelIdInstruction |
| 616 | |
| 617 | private final long tunnelId1 = 1L; |
| 618 | private final long tunnelId2 = 2L; |
| 619 | private final Instruction modTunnelId1 = Instructions.modTunnelId(tunnelId1); |
| 620 | private final Instruction sameAsModTunnelId1 = Instructions.modTunnelId(tunnelId1); |
| 621 | private final Instruction modTunnelId2 = Instructions.modTunnelId(tunnelId2); |
| 622 | |
| 623 | /** |
| 624 | * Test the modTunnelId method. |
| 625 | */ |
| 626 | @Test |
| 627 | public void testModTunnelIdMethod() { |
| 628 | final Instruction instruction = Instructions.modTunnelId(tunnelId1); |
| 629 | final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction = |
| 630 | checkAndConvert(instruction, Instruction.Type.L2MODIFICATION, |
| 631 | L2ModificationInstruction.ModTunnelIdInstruction.class); |
| 632 | assertThat(modTunnelIdInstruction.tunnelId(), is(equalTo(tunnelId1))); |
| 633 | assertThat(modTunnelIdInstruction.subtype(), |
| 634 | is(equalTo(L2ModificationInstruction.L2SubType.TUNNEL_ID))); |
| 635 | } |
| 636 | |
| 637 | /*** |
| 638 | * Test the equals() method of the ModTunnelIdInstruction class. |
| 639 | */ |
| 640 | @Test |
| 641 | public void testModTunnelIdInstructionEquals() throws Exception { |
| 642 | checkEqualsAndToString(modTunnelId1, sameAsModTunnelId1, modTunnelId2); |
| 643 | } |
| 644 | |
| 645 | /** |
| 646 | * Test the hashCode() method of the ModTunnelIdInstruction class. |
| 647 | */ |
| 648 | @Test |
| 649 | public void testModTunnelIdInstructionHashCode() { |
| 650 | assertThat(modTunnelId1.hashCode(), is(equalTo(sameAsModTunnelId1.hashCode()))); |
| 651 | assertThat(modTunnelId1.hashCode(), is(not(equalTo(modTunnelId2.hashCode())))); |
| 652 | } |
| 653 | |
| 654 | // ModTransportPortInstruction |
| 655 | |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 656 | private final TpPort tpPort1 = TpPort.tpPort(1); |
| 657 | private final TpPort tpPort2 = TpPort.tpPort(2); |
| 658 | private final Instruction modTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1); |
| 659 | private final Instruction sameAsModTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1); |
| 660 | private final Instruction modTransportPortInstruction2 = Instructions.modTcpSrc(tpPort2); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 661 | |
| 662 | /** |
| 663 | * Test the modTcpSrc() method. |
| 664 | */ |
| 665 | @Test |
| 666 | public void testModTcpSrcMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 667 | final Instruction instruction = Instructions.modTcpSrc(tpPort1); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 668 | final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = |
| 669 | checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, |
| 670 | L4ModificationInstruction.ModTransportPortInstruction.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 671 | assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1))); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 672 | assertThat(modTransportPortInstruction.subtype(), |
| 673 | is(equalTo(L4ModificationInstruction.L4SubType.TCP_SRC))); |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * Test the modTcpDst() method. |
| 678 | */ |
| 679 | @Test |
| 680 | public void testModTcpDstMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 681 | final Instruction instruction = Instructions.modTcpDst(tpPort1); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 682 | final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = |
| 683 | checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, |
| 684 | L4ModificationInstruction.ModTransportPortInstruction.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 685 | assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1))); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 686 | assertThat(modTransportPortInstruction.subtype(), |
| 687 | is(equalTo(L4ModificationInstruction.L4SubType.TCP_DST))); |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Test the modUdpSrc() method. |
| 692 | */ |
| 693 | @Test |
| 694 | public void testModUdpSrcMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 695 | final Instruction instruction = Instructions.modUdpSrc(tpPort1); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 696 | final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = |
| 697 | checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, |
| 698 | L4ModificationInstruction.ModTransportPortInstruction.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 699 | assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1))); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 700 | assertThat(modTransportPortInstruction.subtype(), |
| 701 | is(equalTo(L4ModificationInstruction.L4SubType.UDP_SRC))); |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Test the modUdpDst() method. |
| 706 | */ |
| 707 | @Test |
| 708 | public void testModUdpDstMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 709 | final Instruction instruction = Instructions.modUdpDst(tpPort1); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 710 | final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = |
| 711 | checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, |
| 712 | L4ModificationInstruction.ModTransportPortInstruction.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 713 | assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1))); |
Hyunsun Moon | d0533e5 | 2015-07-28 18:12:43 -0700 | [diff] [blame] | 714 | assertThat(modTransportPortInstruction.subtype(), |
| 715 | is(equalTo(L4ModificationInstruction.L4SubType.UDP_DST))); |
| 716 | } |
| 717 | |
| 718 | /** |
| 719 | * Test the equals() method of the ModTransportPortInstruction class. |
| 720 | */ |
| 721 | @Test |
| 722 | public void testModTransportPortInstructionEquals() throws Exception { |
| 723 | checkEqualsAndToString(modTransportPortInstruction1, |
| 724 | sameAsModTransportPortInstruction1, |
| 725 | modTransportPortInstruction2); |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * Test the hashCode() method of the ModTransportPortInstruction class. |
| 730 | */ |
| 731 | @Test |
| 732 | public void testModTransportPortInstructionHashCode() { |
| 733 | assertThat(modTransportPortInstruction1.hashCode(), |
| 734 | is(equalTo(sameAsModTransportPortInstruction1.hashCode()))); |
| 735 | assertThat(modTransportPortInstruction1.hashCode(), |
| 736 | is(not(equalTo(modTransportPortInstruction2.hashCode())))); |
| 737 | } |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 738 | |
| 739 | // GroupInstruction |
| 740 | |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 741 | private final GroupId groupId1 = new GroupId(1); |
| 742 | private final GroupId groupId2 = new GroupId(2); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 743 | private final Instruction groupInstruction1 = Instructions.createGroup(groupId1); |
| 744 | private final Instruction sameAsGroupInstruction1 = Instructions.createGroup(groupId1); |
| 745 | private final Instruction groupInstruction2 = Instructions.createGroup(groupId2); |
| 746 | |
| 747 | /** |
| 748 | * Test the create group method. |
| 749 | */ |
| 750 | @Test |
| 751 | public void testCreateGroupMethod() { |
| 752 | final Instruction instruction = Instructions.createGroup(groupId1); |
| 753 | final Instructions.GroupInstruction groupInstruction = |
| 754 | checkAndConvert(instruction, |
| 755 | Instruction.Type.GROUP, |
| 756 | Instructions.GroupInstruction.class); |
| 757 | assertThat(groupInstruction.groupId(), is(equalTo(groupId1))); |
| 758 | } |
| 759 | |
| 760 | /** |
| 761 | * Test the equals() method of the GroupInstruction class. |
| 762 | */ |
| 763 | |
| 764 | @Test |
| 765 | public void testGroupInstructionEquals() { |
| 766 | checkEqualsAndToString(groupInstruction1, |
| 767 | sameAsGroupInstruction1, |
| 768 | groupInstruction2); |
| 769 | } |
| 770 | |
| 771 | // SetQueueInstruction |
| 772 | |
| 773 | private final Instruction setQueueInstruction1 = Instructions.setQueue(1, port1); |
| 774 | private final Instruction sameAsSetQueueInstruction1 = Instructions.setQueue(1, port1); |
| 775 | private final Instruction setQueueInstruction2 = Instructions.setQueue(1, port2); |
| 776 | |
| 777 | /** |
| 778 | * Test the set queue method. |
| 779 | */ |
| 780 | @Test |
| 781 | public void testSetQueueMethod() { |
| 782 | final Instruction instruction = Instructions.setQueue(2, port2); |
| 783 | final Instructions.SetQueueInstruction setQueueInstruction = |
| 784 | checkAndConvert(instruction, |
| 785 | Instruction.Type.QUEUE, |
| 786 | Instructions.SetQueueInstruction.class); |
| 787 | assertThat(setQueueInstruction.queueId(), is(2L)); |
| 788 | assertThat(setQueueInstruction.port(), is(port2)); |
| 789 | } |
| 790 | |
| 791 | /** |
| 792 | * Test the equals() method of the SetQueueInstruction class. |
| 793 | */ |
| 794 | @Test |
| 795 | public void testSetQueueInstructionEquals() { |
| 796 | checkEqualsAndToString(setQueueInstruction1, |
| 797 | sameAsSetQueueInstruction1, |
| 798 | setQueueInstruction2); |
| 799 | } |
| 800 | |
| 801 | // MeterInstruction |
| 802 | |
| 803 | MeterId meterId1 = MeterId.meterId(1); |
| 804 | MeterId meterId2 = MeterId.meterId(2); |
| 805 | private final Instruction meterInstruction1 = Instructions.meterTraffic(meterId1); |
| 806 | private final Instruction sameAsMeterInstruction1 = Instructions.meterTraffic(meterId1); |
| 807 | private final Instruction meterInstruction2 = Instructions.meterTraffic(meterId2); |
| 808 | |
| 809 | /** |
| 810 | * Test the meter traffic method. |
| 811 | */ |
| 812 | @Test |
| 813 | public void testMeterTrafficMethod() { |
| 814 | final Instruction instruction = Instructions.meterTraffic(meterId1); |
| 815 | final Instructions.MeterInstruction meterInstruction = |
| 816 | checkAndConvert(instruction, |
| 817 | Instruction.Type.METER, |
| 818 | Instructions.MeterInstruction.class); |
| 819 | assertThat(meterInstruction.meterId(), is(meterId1)); |
| 820 | } |
| 821 | |
| 822 | /** |
| 823 | * Test the equals() method of the MeterInstruction class. |
| 824 | */ |
| 825 | @Test |
| 826 | public void testMeterTrafficInstructionEquals() { |
| 827 | checkEqualsAndToString(meterInstruction1, |
| 828 | sameAsMeterInstruction1, |
| 829 | meterInstruction2); |
| 830 | } |
| 831 | |
| 832 | // TableTypeTransition |
| 833 | |
| 834 | private final Instruction transitionInstruction1 = Instructions.transition(1); |
| 835 | private final Instruction sameAsTransitionInstruction1 = Instructions.transition(1); |
| 836 | private final Instruction transitionInstruction2 = Instructions.transition(2); |
| 837 | |
| 838 | /** |
| 839 | * Test the transition method. |
| 840 | */ |
| 841 | @Test |
| 842 | public void testTransitionMethod() { |
| 843 | final Instruction instruction = Instructions.transition(1); |
| 844 | final Instructions.TableTypeTransition tableInstruction = |
| 845 | checkAndConvert(instruction, |
| 846 | Instruction.Type.TABLE, |
| 847 | Instructions.TableTypeTransition.class); |
| 848 | assertThat(tableInstruction.tableId(), is(1)); |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * Test the equals() method of the TableTypeTransition class. |
| 853 | */ |
| 854 | @Test |
| 855 | public void testTableTypeTransitionInstructionEquals() { |
| 856 | checkEqualsAndToString(transitionInstruction1, |
| 857 | sameAsTransitionInstruction1, |
| 858 | transitionInstruction2); |
| 859 | } |
| 860 | |
| 861 | // MetadataInstruction |
| 862 | |
| 863 | long metadata1 = 111L; |
| 864 | long metadataMask1 = 222L; |
| 865 | long metadata2 = 333L; |
| 866 | long metadataMask2 = 444L; |
| 867 | |
| 868 | private final Instruction metadataInstruction1 = |
| 869 | Instructions.writeMetadata(metadata1, metadataMask1); |
| 870 | private final Instruction sameAsMetadataInstruction1 = |
| 871 | Instructions.writeMetadata(metadata1, metadataMask1); |
| 872 | private final Instruction metadataInstruction2 = |
| 873 | Instructions.writeMetadata(metadata2, metadataMask2); |
| 874 | |
| 875 | /** |
| 876 | * Test the write metadata method. |
| 877 | */ |
| 878 | @Test |
| 879 | public void testWriteMetadataMethod() { |
| 880 | final Instruction instruction = |
| 881 | Instructions.writeMetadata(metadata1, metadataMask1); |
| 882 | final Instructions.MetadataInstruction metadataInstruction = |
| 883 | checkAndConvert(instruction, |
| 884 | Instruction.Type.METADATA, |
| 885 | Instructions.MetadataInstruction.class); |
| 886 | assertThat(metadataInstruction.metadata(), is(metadata1)); |
| 887 | assertThat(metadataInstruction.metadataMask(), is(metadataMask1)); |
| 888 | } |
| 889 | |
| 890 | /** |
| 891 | * Test the equals() method of the MetadataInstruction class. |
| 892 | */ |
| 893 | @Test |
| 894 | public void testInstructionEquals() { |
| 895 | checkEqualsAndToString(metadataInstruction1, |
| 896 | sameAsMetadataInstruction1, |
| 897 | metadataInstruction2); |
| 898 | } |
| 899 | |
| 900 | // ExtensionInstructionWrapper |
| 901 | |
| 902 | class MockExtensionTreatment implements ExtensionTreatment { |
| 903 | int type; |
| 904 | |
| 905 | MockExtensionTreatment(int type) { |
| 906 | this.type = type; |
| 907 | } |
| 908 | @Override |
| 909 | public ExtensionTreatmentType type() { |
| 910 | return new ExtensionTreatmentType(type); |
| 911 | } |
| 912 | |
| 913 | @Override |
| 914 | public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException { |
| 915 | |
| 916 | } |
| 917 | |
| 918 | @Override |
| 919 | public <T> T getPropertyValue(String key) throws ExtensionPropertyException { |
| 920 | return null; |
| 921 | } |
| 922 | |
| 923 | @Override |
| 924 | public List<String> getProperties() { |
| 925 | return null; |
| 926 | } |
| 927 | |
| 928 | @Override |
| 929 | public byte[] serialize() { |
| 930 | return new byte[0]; |
| 931 | } |
| 932 | |
| 933 | @Override |
| 934 | public void deserialize(byte[] data) { |
| 935 | |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | ExtensionTreatment extensionTreatment1 = new MockExtensionTreatment(111); |
| 940 | ExtensionTreatment extensionTreatment2 = new MockExtensionTreatment(222); |
| 941 | |
| 942 | DeviceId deviceId1 = DeviceId.deviceId("of:1"); |
| 943 | DeviceId deviceId2 = DeviceId.deviceId("of:2"); |
| 944 | |
| 945 | private final Instruction extensionInstruction1 = |
| 946 | Instructions.extension(extensionTreatment1, deviceId1); |
| 947 | private final Instruction sameAsExtensionInstruction1 = |
| 948 | Instructions.extension(extensionTreatment1, deviceId1); |
| 949 | private final Instruction extensionInstruction2 = |
| 950 | Instructions.extension(extensionTreatment2, deviceId2); |
| 951 | |
| 952 | /** |
| 953 | * Test the extension method. |
| 954 | */ |
| 955 | @Test |
| 956 | public void testExtensionMethod() { |
| 957 | final Instruction instruction = |
| 958 | Instructions.extension(extensionTreatment1, deviceId1); |
| 959 | final Instructions.ExtensionInstructionWrapper extensionInstructionWrapper = |
| 960 | checkAndConvert(instruction, |
| 961 | Instruction.Type.EXTENSION, |
| 962 | Instructions.ExtensionInstructionWrapper.class); |
| 963 | assertThat(extensionInstructionWrapper.deviceId(), is(deviceId1)); |
| 964 | assertThat(extensionInstructionWrapper.extensionInstruction(), is(extensionTreatment1)); |
| 965 | } |
| 966 | |
| 967 | /** |
| 968 | * Test the equals() method of the ExtensionInstructionWrapper class. |
| 969 | */ |
| 970 | @Test |
| 971 | public void testExtensionInstructionWrapperEquals() { |
| 972 | checkEqualsAndToString(extensionInstruction1, |
| 973 | sameAsExtensionInstruction1, |
| 974 | extensionInstruction2); |
| 975 | } |
| 976 | |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 977 | // ModMplsHeaderInstructions |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 978 | |
| 979 | private final EthType ethType1 = new EthType(1); |
| 980 | private final EthType ethType2 = new EthType(2); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 981 | private final Instruction modMplsHeaderInstruction1 = Instructions.popMpls(ethType1); |
| 982 | private final Instruction sameAsModMplsHeaderInstruction1 = Instructions.popMpls(ethType1); |
| 983 | private final Instruction modMplsHeaderInstruction2 = Instructions.popMpls(ethType2); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 984 | |
| 985 | /** |
| 986 | * Test the pushMpls method. |
| 987 | */ |
| 988 | @Test |
| 989 | public void testPushMplsMethod() { |
| 990 | final Instruction instruction = Instructions.pushMpls(); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 991 | final L2ModificationInstruction.ModMplsHeaderInstruction pushHeaderInstruction = |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 992 | checkAndConvert(instruction, |
| 993 | Instruction.Type.L2MODIFICATION, |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 994 | L2ModificationInstruction.ModMplsHeaderInstruction.class); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 995 | assertThat(pushHeaderInstruction.ethernetType().toString(), |
Yi Tseng | 603d055 | 2017-04-14 14:06:44 -0700 | [diff] [blame] | 996 | is(EthType.EtherType.MPLS_UNICAST.toString())); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 997 | assertThat(pushHeaderInstruction.subtype(), |
| 998 | is(L2ModificationInstruction.L2SubType.MPLS_PUSH)); |
| 999 | } |
| 1000 | |
| 1001 | /** |
| 1002 | * Test the popMpls method. |
| 1003 | */ |
| 1004 | @Test |
| 1005 | public void testPopMplsMethod() { |
| 1006 | final Instruction instruction = Instructions.popMpls(); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1007 | final L2ModificationInstruction.ModMplsHeaderInstruction pushHeaderInstruction = |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1008 | checkAndConvert(instruction, |
| 1009 | Instruction.Type.L2MODIFICATION, |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1010 | L2ModificationInstruction.ModMplsHeaderInstruction.class); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1011 | assertThat(pushHeaderInstruction.ethernetType().toString(), |
Yi Tseng | 603d055 | 2017-04-14 14:06:44 -0700 | [diff] [blame] | 1012 | is(EthType.EtherType.MPLS_UNICAST.toString())); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1013 | assertThat(pushHeaderInstruction.subtype(), |
| 1014 | is(L2ModificationInstruction.L2SubType.MPLS_POP)); |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * Test the popMpls(EtherType) method. |
| 1019 | */ |
| 1020 | @Test |
| 1021 | public void testPopMplsEthertypeMethod() { |
| 1022 | final Instruction instruction = Instructions.popMpls(new EthType(1)); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1023 | final L2ModificationInstruction.ModMplsHeaderInstruction pushHeaderInstruction = |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1024 | checkAndConvert(instruction, |
| 1025 | Instruction.Type.L2MODIFICATION, |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1026 | L2ModificationInstruction.ModMplsHeaderInstruction.class); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1027 | assertThat(pushHeaderInstruction.ethernetType().toShort(), is((short) 1)); |
| 1028 | assertThat(pushHeaderInstruction.subtype(), |
| 1029 | is(L2ModificationInstruction.L2SubType.MPLS_POP)); |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * Test the pushVlan method. |
| 1034 | */ |
| 1035 | @Test |
| 1036 | public void testPushVlanMethod() { |
| 1037 | final Instruction instruction = Instructions.pushVlan(); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1038 | final L2ModificationInstruction.ModVlanHeaderInstruction pushHeaderInstruction = |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1039 | checkAndConvert(instruction, |
| 1040 | Instruction.Type.L2MODIFICATION, |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1041 | L2ModificationInstruction.ModVlanHeaderInstruction.class); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1042 | assertThat(pushHeaderInstruction.ethernetType().toString(), |
| 1043 | is(EthType.EtherType.VLAN.toString())); |
| 1044 | assertThat(pushHeaderInstruction.subtype(), |
| 1045 | is(L2ModificationInstruction.L2SubType.VLAN_PUSH)); |
| 1046 | } |
| 1047 | |
| 1048 | /** |
| 1049 | * Tests the equals(), hashCode() and toString() methods of the |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1050 | * ModMplsHeaderInstructions class. |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1051 | */ |
| 1052 | |
| 1053 | @Test |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1054 | public void testModMplsHeaderInstructionsEquals() { |
| 1055 | checkEqualsAndToString(modMplsHeaderInstruction1, |
| 1056 | sameAsModMplsHeaderInstruction1, |
| 1057 | modMplsHeaderInstruction2); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | // ModMplsTtlInstruction |
| 1061 | |
| 1062 | private final Instruction modMplsTtlInstruction1 = Instructions.decMplsTtl(); |
| 1063 | private final Instruction sameAsModMplsTtlInstruction1 = Instructions.decMplsTtl(); |
| 1064 | |
| 1065 | /** |
| 1066 | * Test the modMplsBos() method. |
| 1067 | */ |
| 1068 | @Test |
| 1069 | public void testDecMplsTtlMethod() { |
| 1070 | final Instruction instruction = Instructions.decMplsTtl(); |
| 1071 | final L2ModificationInstruction.ModMplsTtlInstruction modMplsTtlInstruction = |
| 1072 | checkAndConvert(instruction, |
| 1073 | Instruction.Type.L2MODIFICATION, |
| 1074 | L2ModificationInstruction.ModMplsTtlInstruction.class); |
| 1075 | assertThat(modMplsTtlInstruction.subtype(), |
| 1076 | is(L2ModificationInstruction.L2SubType.DEC_MPLS_TTL)); |
| 1077 | } |
| 1078 | |
| 1079 | /** |
| 1080 | * Tests the equals(), hashCode() and toString() methods of the |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1081 | * ModMplsTtlInstructions class. |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1082 | */ |
| 1083 | |
| 1084 | @Test |
| 1085 | public void testMplsTtlInstructionsEquals() { |
| 1086 | new EqualsTester() |
| 1087 | .addEqualityGroup(modMplsTtlInstruction1, sameAsModMplsTtlInstruction1) |
| 1088 | .testEquals(); |
| 1089 | } |
| 1090 | |
| 1091 | // ModMplsBosInstruction |
| 1092 | |
| 1093 | private final Instruction modMplsBosInstruction1 = Instructions.modMplsBos(true); |
| 1094 | private final Instruction sameAsModMplsBosInstruction1 = Instructions.modMplsBos(true); |
| 1095 | private final Instruction modMplsBosInstruction2 = Instructions.modMplsBos(false); |
| 1096 | |
| 1097 | /** |
| 1098 | * Test the modMplsBos() method. |
| 1099 | */ |
| 1100 | @Test |
| 1101 | public void testModMplsBosMethod() { |
| 1102 | final Instruction instruction = Instructions.modMplsBos(true); |
| 1103 | final L2ModificationInstruction.ModMplsBosInstruction modMplsBosInstruction = |
| 1104 | checkAndConvert(instruction, |
| 1105 | Instruction.Type.L2MODIFICATION, |
| 1106 | L2ModificationInstruction.ModMplsBosInstruction.class); |
| 1107 | assertThat(modMplsBosInstruction.subtype(), |
| 1108 | is(L2ModificationInstruction.L2SubType.MPLS_BOS)); |
| 1109 | assertThat(modMplsBosInstruction.mplsBos(), is(true)); |
| 1110 | } |
| 1111 | |
| 1112 | /** |
| 1113 | * Tests the equals(), hashCode() and toString() methods of the |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1114 | * ModMplsBosInstructions class. |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1115 | */ |
| 1116 | |
| 1117 | @Test |
| 1118 | public void testMplsBosInstructionsEquals() { |
| 1119 | checkEqualsAndToString(modMplsBosInstruction1, |
| 1120 | sameAsModMplsBosInstruction1, |
| 1121 | modMplsBosInstruction2); |
| 1122 | } |
| 1123 | |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1124 | // ModVlanHeaderInstruction |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1125 | |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1126 | private final Instruction modVlanHeaderInstruction1 = Instructions.popVlan(); |
| 1127 | private final Instruction sameAsModVlanHeaderInstruction1 = Instructions.popVlan(); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1128 | |
| 1129 | /** |
| 1130 | * Test the popVlan method. |
| 1131 | */ |
| 1132 | @Test |
| 1133 | public void testPopVlanMethod() { |
| 1134 | final Instruction instruction = Instructions.popVlan(); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1135 | final L2ModificationInstruction.ModVlanHeaderInstruction popVlanInstruction = |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1136 | checkAndConvert(instruction, |
| 1137 | Instruction.Type.L2MODIFICATION, |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1138 | L2ModificationInstruction.ModVlanHeaderInstruction.class); |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1139 | assertThat(popVlanInstruction.subtype(), |
| 1140 | is(L2ModificationInstruction.L2SubType.VLAN_POP)); |
| 1141 | } |
| 1142 | |
| 1143 | /** |
| 1144 | * Tests the equals(), hashCode() and toString() methods of the |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1145 | * ModVlanHeaderInstructions class. |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1146 | */ |
| 1147 | |
| 1148 | @Test |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1149 | public void testModVlanHeaderInstructionsEquals() { |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1150 | new EqualsTester() |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 1151 | .addEqualityGroup(modVlanHeaderInstruction1, sameAsModVlanHeaderInstruction1) |
Ray Milkey | 3564a8c | 2015-12-14 11:43:12 -0800 | [diff] [blame] | 1152 | .testEquals(); |
| 1153 | } |
| 1154 | |
| 1155 | // ModArpIPInstruction |
| 1156 | |
| 1157 | private final Instruction modArpIPInstruction1 = Instructions.modArpSpa(ip41); |
| 1158 | private final Instruction sameAsModArpIPInstruction1 = Instructions.modArpSpa(ip41); |
| 1159 | private final Instruction modArpIPInstruction2 = Instructions.modArpSpa(ip42); |
| 1160 | |
| 1161 | /** |
| 1162 | * Test the modArpSpa() method. |
| 1163 | */ |
| 1164 | @Test |
| 1165 | public void testModArpSpaMethod() { |
| 1166 | final Instruction instruction = Instructions.modArpSpa(ip41); |
| 1167 | final L3ModificationInstruction.ModArpIPInstruction modArpIPInstruction = |
| 1168 | checkAndConvert(instruction, |
| 1169 | Instruction.Type.L3MODIFICATION, |
| 1170 | L3ModificationInstruction.ModArpIPInstruction.class); |
| 1171 | assertThat(modArpIPInstruction.subtype(), |
| 1172 | is(L3ModificationInstruction.L3SubType.ARP_SPA)); |
| 1173 | assertThat(modArpIPInstruction.ip(), is(ip41)); |
| 1174 | } |
| 1175 | |
| 1176 | /** |
| 1177 | * Tests the equals(), hashCode() and toString() methods of the |
| 1178 | * ModArpIPInstruction class. |
| 1179 | */ |
| 1180 | |
| 1181 | @Test |
| 1182 | public void testModArpIPInstructionEquals() { |
| 1183 | checkEqualsAndToString(modArpIPInstruction1, |
| 1184 | sameAsModArpIPInstruction1, |
| 1185 | modArpIPInstruction2); |
| 1186 | } |
| 1187 | |
| 1188 | // ModArpEthInstruction |
| 1189 | |
| 1190 | private final Instruction modArpEthInstruction1 = Instructions.modArpSha(mac1); |
| 1191 | private final Instruction sameAsModArpEthInstruction1 = Instructions.modArpSha(mac1); |
| 1192 | private final Instruction modArpEthInstruction2 = Instructions.modArpSha(mac2); |
| 1193 | |
| 1194 | /** |
| 1195 | * Test the modArpSha() method. |
| 1196 | */ |
| 1197 | @Test |
| 1198 | public void testModArpShaMethod() { |
| 1199 | final Instruction instruction = Instructions.modArpSha(mac1); |
| 1200 | final L3ModificationInstruction.ModArpEthInstruction modArpEthInstruction = |
| 1201 | checkAndConvert(instruction, |
| 1202 | Instruction.Type.L3MODIFICATION, |
| 1203 | L3ModificationInstruction.ModArpEthInstruction.class); |
| 1204 | assertThat(modArpEthInstruction.subtype(), |
| 1205 | is(L3ModificationInstruction.L3SubType.ARP_SHA)); |
| 1206 | assertThat(modArpEthInstruction.mac(), is(mac1)); |
| 1207 | } |
| 1208 | |
| 1209 | /** |
| 1210 | * Tests the equals(), hashCode() and toString() methods of the |
| 1211 | * ModArpIPInstruction class. |
| 1212 | */ |
| 1213 | |
| 1214 | @Test |
| 1215 | public void testModArpEthInstructionEquals() { |
| 1216 | checkEqualsAndToString(modArpEthInstruction1, |
| 1217 | sameAsModArpEthInstruction1, |
| 1218 | modArpEthInstruction2); |
| 1219 | } |
| 1220 | |
| 1221 | // ModArpOpInstruction |
| 1222 | |
| 1223 | private final Instruction modArpOpInstruction1 = Instructions.modL3ArpOp((short) 1); |
| 1224 | private final Instruction sameAsModArpOpInstruction1 = Instructions.modL3ArpOp((short) 1); |
| 1225 | private final Instruction modArpOpInstruction2 = Instructions.modL3ArpOp((short) 2); |
| 1226 | |
| 1227 | /** |
| 1228 | * Test the modL3ArpOp() method. |
| 1229 | */ |
| 1230 | @Test |
| 1231 | public void testModArpModL3ArpOpMethod() { |
| 1232 | final Instruction instruction = Instructions.modL3ArpOp((short) 1); |
| 1233 | final L3ModificationInstruction.ModArpOpInstruction modArpEthInstruction = |
| 1234 | checkAndConvert(instruction, |
| 1235 | Instruction.Type.L3MODIFICATION, |
| 1236 | L3ModificationInstruction.ModArpOpInstruction.class); |
| 1237 | assertThat(modArpEthInstruction.subtype(), |
| 1238 | is(L3ModificationInstruction.L3SubType.ARP_OP)); |
| 1239 | assertThat(modArpEthInstruction.op(), is(1L)); |
| 1240 | } |
| 1241 | |
| 1242 | /** |
| 1243 | * Tests the equals(), hashCode() and toString() methods of the |
| 1244 | * ModArpIPInstruction class. |
| 1245 | */ |
| 1246 | |
| 1247 | @Test |
| 1248 | public void testModArpOpInstructionEquals() { |
| 1249 | checkEqualsAndToString(modArpOpInstruction1, |
| 1250 | sameAsModArpOpInstruction1, |
| 1251 | modArpOpInstruction2); |
| 1252 | } |
| 1253 | |
| 1254 | // ModTtlInstruction |
| 1255 | |
| 1256 | private final Instruction modArpTtlInstruction1 = Instructions.copyTtlIn(); |
| 1257 | private final Instruction sameAsModArpTtlInstruction1 = Instructions.copyTtlIn(); |
| 1258 | private final Instruction modArpTtlInstruction2 = Instructions.copyTtlOut(); |
| 1259 | private final Instruction modArpTtlInstruction3 = Instructions.decNwTtl(); |
| 1260 | |
| 1261 | /** |
| 1262 | * Test the copyTtlIn() method. |
| 1263 | */ |
| 1264 | @Test |
| 1265 | public void testCopyTtlInMethod() { |
| 1266 | final Instruction instruction = Instructions.copyTtlIn(); |
| 1267 | final L3ModificationInstruction.ModTtlInstruction modTtlInstruction = |
| 1268 | checkAndConvert(instruction, |
| 1269 | Instruction.Type.L3MODIFICATION, |
| 1270 | L3ModificationInstruction.ModTtlInstruction.class); |
| 1271 | assertThat(modTtlInstruction.subtype(), |
| 1272 | is(L3ModificationInstruction.L3SubType.TTL_IN)); |
| 1273 | } |
| 1274 | |
| 1275 | /** |
| 1276 | * Test the copyTtlOut() method. |
| 1277 | */ |
| 1278 | @Test |
| 1279 | public void testCopyTtlOutMethod() { |
| 1280 | final Instruction instruction = Instructions.copyTtlOut(); |
| 1281 | final L3ModificationInstruction.ModTtlInstruction modTtlInstruction = |
| 1282 | checkAndConvert(instruction, |
| 1283 | Instruction.Type.L3MODIFICATION, |
| 1284 | L3ModificationInstruction.ModTtlInstruction.class); |
| 1285 | assertThat(modTtlInstruction.subtype(), |
| 1286 | is(L3ModificationInstruction.L3SubType.TTL_OUT)); |
| 1287 | } |
| 1288 | |
| 1289 | /** |
| 1290 | * Test the decNwTtl() method. |
| 1291 | */ |
| 1292 | @Test |
| 1293 | public void testDecNwTtlOutMethod() { |
| 1294 | final Instruction instruction = Instructions.decNwTtl(); |
| 1295 | final L3ModificationInstruction.ModTtlInstruction modTtlInstruction = |
| 1296 | checkAndConvert(instruction, |
| 1297 | Instruction.Type.L3MODIFICATION, |
| 1298 | L3ModificationInstruction.ModTtlInstruction.class); |
| 1299 | assertThat(modTtlInstruction.subtype(), |
| 1300 | is(L3ModificationInstruction.L3SubType.DEC_TTL)); |
| 1301 | } |
| 1302 | |
| 1303 | /** |
| 1304 | * Tests the equals(), hashCode() and toString() methods of the |
| 1305 | * ModArpIPInstruction class. |
| 1306 | */ |
| 1307 | |
| 1308 | @Test |
| 1309 | public void testModTtlInstructionEquals() { |
| 1310 | new EqualsTester() |
| 1311 | .addEqualityGroup(modArpTtlInstruction1, sameAsModArpTtlInstruction1) |
| 1312 | .addEqualityGroup(modArpTtlInstruction2) |
| 1313 | .addEqualityGroup(modArpTtlInstruction3) |
| 1314 | .testEquals(); |
| 1315 | } |
| 1316 | |
Frank Wang | e33e4ed | 2017-06-28 10:01:07 +0800 | [diff] [blame] | 1317 | // PiInstruction |
| 1318 | PiTableAction piTableAction1 = PiAction.builder() |
| 1319 | .withId(PiActionId.of("set_egress_port_0")) |
| 1320 | .withParameter(new PiActionParam(PiActionParamId.of("port"), |
| 1321 | ImmutableByteSequence.copyFrom(10))).build(); |
| 1322 | PiTableAction piTableAction2 = PiAction.builder() |
| 1323 | .withId(PiActionId.of("set_egress_port_0")) |
| 1324 | .withParameter(new PiActionParam(PiActionParamId.of("port"), |
| 1325 | ImmutableByteSequence.copyFrom(20))).build(); |
| 1326 | private final Instruction piSetEgressPortInstruction1 = new PiInstruction(piTableAction1); |
| 1327 | private final Instruction sameAsPiSetEgressPortInstruction1 = new PiInstruction(piTableAction1); |
| 1328 | private final Instruction piSetEgressPortInstruction2 = new PiInstruction(piTableAction2); |
| 1329 | |
| 1330 | /** |
| 1331 | * Test the PiInstruction() method. |
| 1332 | */ |
| 1333 | @Test |
| 1334 | public void testPiMethod() { |
| 1335 | final Instruction instruction = new PiInstruction(piTableAction1); |
| 1336 | final PiInstruction piInstruction = checkAndConvert(instruction, |
| 1337 | Instruction.Type.PROTOCOL_INDEPENDENT, PiInstruction.class); |
| 1338 | |
| 1339 | assertThat(piInstruction.action(), is(piTableAction1)); |
| 1340 | assertThat(piInstruction.type(), is(Instruction.Type.PROTOCOL_INDEPENDENT)); |
| 1341 | } |
| 1342 | |
| 1343 | /** |
| 1344 | * Tests the equals(), hashCode() and toString() methods of the |
| 1345 | * PiInstruction class. |
| 1346 | */ |
| 1347 | |
| 1348 | @Test |
| 1349 | public void testPiInstructionEquals() { |
| 1350 | new EqualsTester() |
| 1351 | .addEqualityGroup(piSetEgressPortInstruction1, sameAsPiSetEgressPortInstruction1) |
| 1352 | .addEqualityGroup(piSetEgressPortInstruction2) |
| 1353 | .testEquals(); |
| 1354 | } |
| 1355 | |
Ray Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 1356 | } |