Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [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 | */ |
| 16 | package org.onosproject.codec.impl; |
| 17 | |
Jian Li | 7c322f4 | 2016-03-04 11:00:59 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Jian Li | 2907ad2 | 2016-05-12 23:08:54 -0700 | [diff] [blame] | 20 | import org.hamcrest.Description; |
| 21 | import org.hamcrest.TypeSafeDiagnosingMatcher; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 24 | import org.onlab.packet.EthType; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 25 | import org.onlab.packet.Ethernet; |
| 26 | import org.onlab.packet.IpAddress; |
| 27 | import org.onlab.packet.IpPrefix; |
| 28 | import org.onlab.packet.MacAddress; |
| 29 | import org.onlab.packet.MplsLabel; |
| 30 | import org.onlab.packet.VlanId; |
| 31 | import org.onosproject.codec.JsonCodec; |
| 32 | import org.onosproject.core.CoreService; |
| 33 | import org.onosproject.net.ChannelSpacing; |
Jian Li | 2907ad2 | 2016-05-12 23:08:54 -0700 | [diff] [blame] | 34 | import org.onosproject.net.DeviceId; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 35 | import org.onosproject.net.GridType; |
| 36 | import org.onosproject.net.Lambda; |
| 37 | import org.onosproject.net.OchSignal; |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 38 | import org.onosproject.net.OchSignalType; |
| 39 | import org.onosproject.net.OduSignalType; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 40 | import org.onosproject.net.PortNumber; |
Jian Li | 2907ad2 | 2016-05-12 23:08:54 -0700 | [diff] [blame] | 41 | import org.onosproject.net.flow.DefaultFlowRule; |
Jian Li | e2a59f4 | 2016-05-18 15:15:53 -0700 | [diff] [blame] | 42 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 43 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 44 | import org.onosproject.net.flow.FlowRule; |
Jian Li | e2a59f4 | 2016-05-18 15:15:53 -0700 | [diff] [blame] | 45 | import org.onosproject.net.flow.TrafficSelector; |
| 46 | import org.onosproject.net.flow.TrafficTreatment; |
| 47 | import org.onosproject.net.flow.criteria.Criteria; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 48 | import org.onosproject.net.flow.criteria.Criterion; |
| 49 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 50 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 51 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 52 | import org.onosproject.net.flow.criteria.IPDscpCriterion; |
| 53 | import org.onosproject.net.flow.criteria.IPEcnCriterion; |
| 54 | import org.onosproject.net.flow.criteria.IPProtocolCriterion; |
| 55 | import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion; |
| 56 | import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion; |
| 57 | import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion; |
| 58 | import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion; |
| 59 | import org.onosproject.net.flow.criteria.IcmpCodeCriterion; |
| 60 | import org.onosproject.net.flow.criteria.IcmpTypeCriterion; |
| 61 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 62 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 63 | import org.onosproject.net.flow.criteria.MplsCriterion; |
| 64 | import org.onosproject.net.flow.criteria.OchSignalCriterion; |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 65 | import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; |
| 66 | import org.onosproject.net.flow.criteria.OduSignalIdCriterion; |
| 67 | import org.onosproject.net.flow.criteria.OduSignalTypeCriterion; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 68 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 69 | import org.onosproject.net.flow.criteria.SctpPortCriterion; |
| 70 | import org.onosproject.net.flow.criteria.TcpPortCriterion; |
Hyunsun Moon | 7080a0d | 2015-08-14 19:18:48 -0700 | [diff] [blame] | 71 | import org.onosproject.net.flow.criteria.TunnelIdCriterion; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 72 | import org.onosproject.net.flow.criteria.UdpPortCriterion; |
| 73 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 74 | import org.onosproject.net.flow.criteria.VlanPcpCriterion; |
| 75 | import org.onosproject.net.flow.instructions.Instruction; |
| 76 | import org.onosproject.net.flow.instructions.Instructions; |
| 77 | import org.onosproject.net.flow.instructions.L0ModificationInstruction; |
| 78 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
| 79 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
Hyunsun Moon | fab2950 | 2015-08-25 13:39:16 -0700 | [diff] [blame] | 80 | import org.onosproject.net.flow.instructions.L4ModificationInstruction; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 81 | |
Jian Li | 7c322f4 | 2016-03-04 11:00:59 -0800 | [diff] [blame] | 82 | import java.io.IOException; |
| 83 | import java.io.InputStream; |
| 84 | import java.util.SortedMap; |
| 85 | import java.util.TreeMap; |
| 86 | |
Jian Li | 2907ad2 | 2016-05-12 23:08:54 -0700 | [diff] [blame] | 87 | import static org.easymock.EasyMock.anyShort; |
Jian Li | 7c322f4 | 2016-03-04 11:00:59 -0800 | [diff] [blame] | 88 | import static org.easymock.EasyMock.createMock; |
| 89 | import static org.easymock.EasyMock.expect; |
| 90 | import static org.easymock.EasyMock.replay; |
| 91 | import static org.hamcrest.MatcherAssert.assertThat; |
| 92 | import static org.hamcrest.Matchers.instanceOf; |
| 93 | import static org.hamcrest.Matchers.is; |
| 94 | import static org.hamcrest.Matchers.notNullValue; |
| 95 | import static org.onosproject.net.NetTestTools.APP_ID; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * Flow rule codec unit tests. |
| 99 | */ |
| 100 | public class FlowRuleCodecTest { |
| 101 | |
| 102 | MockCodecContext context; |
| 103 | JsonCodec<FlowRule> flowRuleCodec; |
| 104 | final CoreService mockCoreService = createMock(CoreService.class); |
| 105 | |
| 106 | /** |
| 107 | * Sets up for each test. Creates a context and fetches the flow rule |
| 108 | * codec. |
| 109 | */ |
| 110 | @Before |
| 111 | public void setUp() { |
| 112 | context = new MockCodecContext(); |
| 113 | flowRuleCodec = context.codec(FlowRule.class); |
| 114 | assertThat(flowRuleCodec, notNullValue()); |
| 115 | |
Ray Milkey | eb5c717 | 2015-06-23 14:59:27 -0700 | [diff] [blame] | 116 | expect(mockCoreService.registerApplication(FlowRuleCodec.REST_APP_ID)) |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 117 | .andReturn(APP_ID).anyTimes(); |
Jian Li | 2907ad2 | 2016-05-12 23:08:54 -0700 | [diff] [blame] | 118 | expect(mockCoreService.getAppId(anyShort())).andReturn(APP_ID).anyTimes(); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 119 | replay(mockCoreService); |
| 120 | context.registerService(CoreService.class, mockCoreService); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Reads in a rule from the given resource and decodes it. |
| 125 | * |
| 126 | * @param resourceName resource to use to read the JSON for the rule |
| 127 | * @return decoded flow rule |
| 128 | * @throws IOException if processing the resource fails |
| 129 | */ |
| 130 | private FlowRule getRule(String resourceName) throws IOException { |
| 131 | InputStream jsonStream = FlowRuleCodecTest.class |
| 132 | .getResourceAsStream(resourceName); |
| 133 | JsonNode json = context.mapper().readTree(jsonStream); |
| 134 | assertThat(json, notNullValue()); |
| 135 | FlowRule rule = flowRuleCodec.decode((ObjectNode) json, context); |
| 136 | assertThat(rule, notNullValue()); |
| 137 | return rule; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Checks that the data shared by all the resources is correct for a |
| 142 | * given rule. |
| 143 | * |
| 144 | * @param rule rule to check |
| 145 | */ |
| 146 | private void checkCommonData(FlowRule rule) { |
| 147 | assertThat(rule.appId(), is(APP_ID.id())); |
| 148 | assertThat(rule.isPermanent(), is(false)); |
| 149 | assertThat(rule.timeout(), is(1)); |
| 150 | assertThat(rule.priority(), is(1)); |
Jian Li | 7c322f4 | 2016-03-04 11:00:59 -0800 | [diff] [blame] | 151 | assertThat(rule.tableId(), is(1)); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 152 | assertThat(rule.deviceId().toString(), is("of:0000000000000001")); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Checks that a simple rule decodes properly. |
| 157 | * |
| 158 | * @throws IOException if the resource cannot be processed |
| 159 | */ |
| 160 | @Test |
| 161 | public void codecSimpleFlowTest() throws IOException { |
| 162 | FlowRule rule = getRule("simple-flow.json"); |
| 163 | |
| 164 | checkCommonData(rule); |
| 165 | |
| 166 | assertThat(rule.selector().criteria().size(), is(1)); |
| 167 | Criterion criterion1 = rule.selector().criteria().iterator().next(); |
| 168 | assertThat(criterion1.type(), is(Criterion.Type.ETH_TYPE)); |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 169 | assertThat(((EthTypeCriterion) criterion1).ethType(), is(new EthType(2054))); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 170 | |
| 171 | assertThat(rule.treatment().allInstructions().size(), is(1)); |
| 172 | Instruction instruction1 = rule.treatment().allInstructions().get(0); |
| 173 | assertThat(instruction1.type(), is(Instruction.Type.OUTPUT)); |
| 174 | assertThat(((Instructions.OutputInstruction) instruction1).port(), is(PortNumber.CONTROLLER)); |
| 175 | } |
| 176 | |
| 177 | SortedMap<String, Instruction> instructions = new TreeMap<>(); |
| 178 | |
| 179 | /** |
Jian Li | 2907ad2 | 2016-05-12 23:08:54 -0700 | [diff] [blame] | 180 | * Checks that a simple rule encodes properly. |
| 181 | */ |
| 182 | @Test |
| 183 | public void testFlowRuleEncode() { |
| 184 | |
| 185 | DeviceId deviceId = DeviceId.deviceId("of:000000000000000a"); |
Jian Li | e2a59f4 | 2016-05-18 15:15:53 -0700 | [diff] [blame] | 186 | |
| 187 | Instruction output = Instructions.createOutput(PortNumber.portNumber(0)); |
| 188 | Instruction modL2Src = Instructions.modL2Src(MacAddress.valueOf("11:22:33:44:55:66")); |
| 189 | Instruction modL2Dst = Instructions.modL2Dst(MacAddress.valueOf("44:55:66:77:88:99")); |
| 190 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 191 | TrafficTreatment treatment = tBuilder |
| 192 | .add(output) |
| 193 | .add(modL2Src) |
| 194 | .add(modL2Dst) |
| 195 | .build(); |
| 196 | |
| 197 | Criterion inPort = Criteria.matchInPort(PortNumber.portNumber(0)); |
| 198 | Criterion ethSrc = Criteria.matchEthSrc(MacAddress.valueOf("11:22:33:44:55:66")); |
| 199 | Criterion ethDst = Criteria.matchEthDst(MacAddress.valueOf("44:55:66:77:88:99")); |
| 200 | Criterion ethType = Criteria.matchEthType(Ethernet.TYPE_IPV4); |
| 201 | |
| 202 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 203 | TrafficSelector selector = sBuilder |
| 204 | .add(inPort) |
| 205 | .add(ethSrc) |
| 206 | .add(ethDst) |
| 207 | .add(ethType) |
| 208 | .build(); |
| 209 | |
Jian Li | 2907ad2 | 2016-05-12 23:08:54 -0700 | [diff] [blame] | 210 | FlowRule permFlowRule = DefaultFlowRule.builder() |
| 211 | .withCookie(1) |
| 212 | .forTable(1) |
| 213 | .withPriority(1) |
| 214 | .makePermanent() |
Jian Li | e2a59f4 | 2016-05-18 15:15:53 -0700 | [diff] [blame] | 215 | .withTreatment(treatment) |
| 216 | .withSelector(selector) |
Jian Li | 2907ad2 | 2016-05-12 23:08:54 -0700 | [diff] [blame] | 217 | .forDevice(deviceId).build(); |
| 218 | |
| 219 | FlowRule tempFlowRule = DefaultFlowRule.builder() |
| 220 | .withCookie(1) |
| 221 | .forTable(1) |
| 222 | .withPriority(1) |
| 223 | .makeTemporary(1000) |
Jian Li | e2a59f4 | 2016-05-18 15:15:53 -0700 | [diff] [blame] | 224 | .withTreatment(treatment) |
| 225 | .withSelector(selector) |
Jian Li | 2907ad2 | 2016-05-12 23:08:54 -0700 | [diff] [blame] | 226 | .forDevice(deviceId).build(); |
| 227 | |
| 228 | ObjectNode permFlowRuleJson = flowRuleCodec.encode(permFlowRule, context); |
| 229 | ObjectNode tempFlowRuleJson = flowRuleCodec.encode(tempFlowRule, context); |
| 230 | |
| 231 | assertThat(permFlowRuleJson, FlowRuleJsonMatcher.matchesFlowRule(permFlowRule)); |
| 232 | assertThat(tempFlowRuleJson, FlowRuleJsonMatcher.matchesFlowRule(tempFlowRule)); |
| 233 | } |
| 234 | |
| 235 | private static final class FlowRuleJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> { |
| 236 | |
| 237 | private final FlowRule flowRule; |
| 238 | |
| 239 | private FlowRuleJsonMatcher(FlowRule flowRule) { |
| 240 | this.flowRule = flowRule; |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | protected boolean matchesSafely(JsonNode jsonNode, Description description) { |
| 245 | |
| 246 | // check id |
| 247 | long jsonId = jsonNode.get("id").asLong(); |
| 248 | long id = flowRule.id().id(); |
| 249 | if (jsonId != id) { |
| 250 | description.appendText("flow rule id was " + jsonId); |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | // TODO: need to check application ID |
| 255 | |
| 256 | // check tableId |
| 257 | int jsonTableId = jsonNode.get("tableId").asInt(); |
| 258 | int tableId = flowRule.tableId(); |
| 259 | if (jsonTableId != tableId) { |
| 260 | description.appendText("table id was " + jsonId); |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | // check priority |
| 265 | int jsonPriority = jsonNode.get("priority").asInt(); |
| 266 | int priority = flowRule.priority(); |
| 267 | if (jsonPriority != priority) { |
| 268 | description.appendText("priority was " + jsonPriority); |
| 269 | return false; |
| 270 | } |
| 271 | |
| 272 | // check timeout |
| 273 | int jsonTimeout = jsonNode.get("timeout").asInt(); |
| 274 | int timeout = flowRule.timeout(); |
| 275 | if (jsonTimeout != timeout) { |
| 276 | description.appendText("timeout was " + jsonTimeout); |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | // check isPermanent |
| 281 | boolean jsonIsPermanent = jsonNode.get("isPermanent").asBoolean(); |
| 282 | boolean isPermanent = flowRule.isPermanent(); |
| 283 | if (jsonIsPermanent != isPermanent) { |
| 284 | description.appendText("isPermanent was " + jsonIsPermanent); |
| 285 | return false; |
| 286 | } |
| 287 | |
| 288 | // check deviceId |
| 289 | String jsonDeviceId = jsonNode.get("deviceId").asText(); |
| 290 | String deviceId = flowRule.deviceId().toString(); |
| 291 | if (!jsonDeviceId.equals(deviceId)) { |
| 292 | description.appendText("deviceId was " + jsonDeviceId); |
| 293 | return false; |
| 294 | } |
| 295 | |
Jian Li | e2a59f4 | 2016-05-18 15:15:53 -0700 | [diff] [blame] | 296 | // check traffic treatment |
| 297 | JsonNode jsonTreatment = jsonNode.get("treatment"); |
| 298 | TrafficTreatmentCodecTest.TrafficTreatmentJsonMatcher treatmentMatcher = |
| 299 | TrafficTreatmentCodecTest.TrafficTreatmentJsonMatcher |
| 300 | .matchesTrafficTreatment(flowRule.treatment()); |
Jian Li | 2907ad2 | 2016-05-12 23:08:54 -0700 | [diff] [blame] | 301 | |
Jian Li | e2a59f4 | 2016-05-18 15:15:53 -0700 | [diff] [blame] | 302 | if (!treatmentMatcher.matches(jsonTreatment)) { |
| 303 | description.appendText("treatment is not matched"); |
| 304 | return false; |
| 305 | } |
| 306 | |
| 307 | // check traffic selector |
| 308 | JsonNode jsonSelector = jsonNode.get("selector"); |
| 309 | TrafficSelectorCodecTest.TrafficSelectorJsonMatcher selectorMatcher = |
| 310 | TrafficSelectorCodecTest.TrafficSelectorJsonMatcher |
| 311 | .matchesTrafficSelector(flowRule.selector()); |
| 312 | |
| 313 | if (!selectorMatcher.matches(jsonSelector)) { |
| 314 | description.appendText("selector is not matched"); |
| 315 | return false; |
| 316 | } |
Jian Li | 2907ad2 | 2016-05-12 23:08:54 -0700 | [diff] [blame] | 317 | |
| 318 | return true; |
| 319 | } |
| 320 | |
| 321 | @Override |
| 322 | public void describeTo(Description description) { |
| 323 | description.appendText(flowRule.toString()); |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Factory to allocate a flow rule matcher. |
| 328 | * |
| 329 | * @param flowRule flow rule object we are looking for |
| 330 | * @return matcher |
| 331 | */ |
| 332 | public static FlowRuleJsonMatcher matchesFlowRule(FlowRule flowRule) { |
| 333 | return new FlowRuleJsonMatcher(flowRule); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | /** |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 338 | * Looks up an instruction in the instruction map based on type and subtype. |
| 339 | * |
| 340 | * @param type type string |
| 341 | * @param subType subtype string |
| 342 | * @return instruction that matches |
| 343 | */ |
| 344 | private Instruction getInstruction(Instruction.Type type, String subType) { |
| 345 | Instruction instruction = instructions.get(type.name() + "/" + subType); |
| 346 | assertThat(instruction, notNullValue()); |
| 347 | assertThat(instruction.type(), is(type)); |
| 348 | return instruction; |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Checks that a rule with one of each instruction type decodes properly. |
| 353 | * |
| 354 | * @throws IOException if the resource cannot be processed |
| 355 | */ |
| 356 | @Test |
| 357 | public void decodeInstructionsFlowTest() throws Exception { |
| 358 | FlowRule rule = getRule("instructions-flow.json"); |
| 359 | |
| 360 | checkCommonData(rule); |
| 361 | |
| 362 | rule.treatment().allInstructions() |
Ray Milkey | 88cc343 | 2017-03-30 17:19:08 -0700 | [diff] [blame] | 363 | .forEach(instruction -> { |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 364 | String subType; |
| 365 | if (instruction.type() == Instruction.Type.L0MODIFICATION) { |
| 366 | subType = ((L0ModificationInstruction) instruction) |
| 367 | .subtype().name(); |
| 368 | } else if (instruction.type() == Instruction.Type.L2MODIFICATION) { |
| 369 | subType = ((L2ModificationInstruction) instruction) |
| 370 | .subtype().name(); |
| 371 | } else if (instruction.type() == Instruction.Type.L3MODIFICATION) { |
| 372 | subType = ((L3ModificationInstruction) instruction) |
| 373 | .subtype().name(); |
Hyunsun Moon | fab2950 | 2015-08-25 13:39:16 -0700 | [diff] [blame] | 374 | } else if (instruction.type() == Instruction.Type.L4MODIFICATION) { |
| 375 | subType = ((L4ModificationInstruction) instruction) |
| 376 | .subtype().name(); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 377 | } else { |
| 378 | subType = ""; |
| 379 | } |
| 380 | instructions.put( |
| 381 | instruction.type().name() + "/" + subType, instruction); |
| 382 | }); |
| 383 | |
Sho SHIMIZU | cc137a9 | 2016-03-11 15:10:54 -0800 | [diff] [blame] | 384 | assertThat(rule.treatment().allInstructions().size(), is(23)); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 385 | |
| 386 | Instruction instruction; |
| 387 | |
| 388 | instruction = getInstruction(Instruction.Type.OUTPUT, ""); |
| 389 | assertThat(instruction.type(), is(Instruction.Type.OUTPUT)); |
| 390 | assertThat(((Instructions.OutputInstruction) instruction).port(), is(PortNumber.CONTROLLER)); |
| 391 | |
| 392 | instruction = getInstruction(Instruction.Type.L2MODIFICATION, |
| 393 | L2ModificationInstruction.L2SubType.ETH_SRC.name()); |
| 394 | assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); |
| 395 | assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(), |
| 396 | is(MacAddress.valueOf("12:34:56:78:90:12"))); |
| 397 | |
| 398 | instruction = getInstruction(Instruction.Type.L2MODIFICATION, |
| 399 | L2ModificationInstruction.L2SubType.ETH_DST.name()); |
| 400 | assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); |
| 401 | assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(), |
| 402 | is(MacAddress.valueOf("98:76:54:32:01:00"))); |
| 403 | |
| 404 | instruction = getInstruction(Instruction.Type.L2MODIFICATION, |
| 405 | L2ModificationInstruction.L2SubType.VLAN_ID.name()); |
| 406 | assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); |
| 407 | assertThat(((L2ModificationInstruction.ModVlanIdInstruction) instruction).vlanId().toShort(), |
| 408 | is((short) 22)); |
| 409 | |
| 410 | instruction = getInstruction(Instruction.Type.L2MODIFICATION, |
| 411 | L2ModificationInstruction.L2SubType.VLAN_PCP.name()); |
| 412 | assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); |
| 413 | assertThat(((L2ModificationInstruction.ModVlanPcpInstruction) instruction).vlanPcp(), |
| 414 | is((byte) 1)); |
| 415 | |
| 416 | instruction = getInstruction(Instruction.Type.L2MODIFICATION, |
| 417 | L2ModificationInstruction.L2SubType.MPLS_LABEL.name()); |
| 418 | assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); |
| 419 | assertThat(((L2ModificationInstruction.ModMplsLabelInstruction) instruction) |
Ray Milkey | 125572b | 2016-02-22 16:48:17 -0800 | [diff] [blame] | 420 | .label().toInt(), |
HIGUCHI Yuta | 04b49fc | 2015-08-28 09:58:58 -0700 | [diff] [blame] | 421 | is(MplsLabel.MAX_MPLS)); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 422 | |
| 423 | instruction = getInstruction(Instruction.Type.L2MODIFICATION, |
| 424 | L2ModificationInstruction.L2SubType.MPLS_PUSH.name()); |
| 425 | assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 426 | assertThat(((L2ModificationInstruction.ModMplsHeaderInstruction) instruction) |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 427 | .ethernetType().toShort(), |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 428 | is(Ethernet.MPLS_UNICAST)); |
| 429 | |
| 430 | instruction = getInstruction(Instruction.Type.L2MODIFICATION, |
| 431 | L2ModificationInstruction.L2SubType.MPLS_POP.name()); |
| 432 | assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 433 | assertThat(((L2ModificationInstruction.ModMplsHeaderInstruction) instruction) |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 434 | .ethernetType().toShort(), |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 435 | is(Ethernet.MPLS_UNICAST)); |
| 436 | |
| 437 | instruction = getInstruction(Instruction.Type.L2MODIFICATION, |
| 438 | L2ModificationInstruction.L2SubType.DEC_MPLS_TTL.name()); |
| 439 | assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); |
| 440 | assertThat(instruction, instanceOf(L2ModificationInstruction.ModMplsTtlInstruction.class)); |
| 441 | |
| 442 | instruction = getInstruction(Instruction.Type.L2MODIFICATION, |
| 443 | L2ModificationInstruction.L2SubType.VLAN_POP.name()); |
| 444 | assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 445 | assertThat(instruction, instanceOf(L2ModificationInstruction.ModVlanHeaderInstruction.class)); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 446 | |
| 447 | instruction = getInstruction(Instruction.Type.L2MODIFICATION, |
| 448 | L2ModificationInstruction.L2SubType.VLAN_PUSH.name()); |
| 449 | assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); |
Jian Li | 11260a0 | 2016-05-19 13:07:22 -0700 | [diff] [blame] | 450 | assertThat(instruction, instanceOf(L2ModificationInstruction.ModVlanHeaderInstruction.class)); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 451 | |
Hyunsun Moon | 7080a0d | 2015-08-14 19:18:48 -0700 | [diff] [blame] | 452 | instruction = getInstruction(Instruction.Type.L2MODIFICATION, |
| 453 | L2ModificationInstruction.L2SubType.TUNNEL_ID.name()); |
| 454 | assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); |
| 455 | assertThat(((L2ModificationInstruction.ModTunnelIdInstruction) instruction) |
| 456 | .tunnelId(), is(100L)); |
| 457 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 458 | instruction = getInstruction(Instruction.Type.L3MODIFICATION, |
| 459 | L3ModificationInstruction.L3SubType.IPV4_SRC.name()); |
| 460 | assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION)); |
| 461 | assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), |
| 462 | is(IpAddress.valueOf("1.2.3.4"))); |
| 463 | |
| 464 | instruction = getInstruction(Instruction.Type.L3MODIFICATION, |
| 465 | L3ModificationInstruction.L3SubType.IPV4_DST.name()); |
| 466 | assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION)); |
| 467 | assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), |
| 468 | is(IpAddress.valueOf("1.2.3.3"))); |
| 469 | |
| 470 | instruction = getInstruction(Instruction.Type.L3MODIFICATION, |
| 471 | L3ModificationInstruction.L3SubType.IPV6_SRC.name()); |
| 472 | assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION)); |
| 473 | assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), |
| 474 | is(IpAddress.valueOf("1.2.3.2"))); |
| 475 | |
| 476 | instruction = getInstruction(Instruction.Type.L3MODIFICATION, |
| 477 | L3ModificationInstruction.L3SubType.IPV6_DST.name()); |
| 478 | assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION)); |
| 479 | assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), |
| 480 | is(IpAddress.valueOf("1.2.3.1"))); |
| 481 | |
| 482 | instruction = getInstruction(Instruction.Type.L3MODIFICATION, |
| 483 | L3ModificationInstruction.L3SubType.IPV6_FLABEL.name()); |
| 484 | assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION)); |
| 485 | assertThat(((L3ModificationInstruction.ModIPv6FlowLabelInstruction) instruction) |
| 486 | .flowLabel(), |
| 487 | is(8)); |
| 488 | |
| 489 | instruction = getInstruction(Instruction.Type.L0MODIFICATION, |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 490 | L0ModificationInstruction.L0SubType.OCH.name()); |
| 491 | assertThat(instruction.type(), is(Instruction.Type.L0MODIFICATION)); |
| 492 | L0ModificationInstruction.ModOchSignalInstruction och = |
| 493 | (L0ModificationInstruction.ModOchSignalInstruction) instruction; |
| 494 | assertThat(och.lambda().spacingMultiplier(), is(4)); |
| 495 | assertThat(och.lambda().slotGranularity(), is(8)); |
| 496 | assertThat(och.lambda().gridType(), is(GridType.DWDM)); |
| 497 | assertThat(och.lambda().channelSpacing(), is(ChannelSpacing.CHL_100GHZ)); |
Hyunsun Moon | fab2950 | 2015-08-25 13:39:16 -0700 | [diff] [blame] | 498 | |
| 499 | instruction = getInstruction(Instruction.Type.L4MODIFICATION, |
| 500 | L4ModificationInstruction.L4SubType.TCP_DST.name()); |
| 501 | assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION)); |
| 502 | assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction) |
| 503 | .port().toInt(), is(40001)); |
| 504 | |
| 505 | instruction = getInstruction(Instruction.Type.L4MODIFICATION, |
| 506 | L4ModificationInstruction.L4SubType.TCP_SRC.name()); |
| 507 | assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION)); |
| 508 | assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction) |
| 509 | .port().toInt(), is(40002)); |
| 510 | |
| 511 | instruction = getInstruction(Instruction.Type.L4MODIFICATION, |
| 512 | L4ModificationInstruction.L4SubType.UDP_DST.name()); |
| 513 | assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION)); |
| 514 | assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction) |
| 515 | .port().toInt(), is(40003)); |
| 516 | |
| 517 | instruction = getInstruction(Instruction.Type.L4MODIFICATION, |
| 518 | L4ModificationInstruction.L4SubType.UDP_SRC.name()); |
| 519 | assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION)); |
| 520 | assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction) |
| 521 | .port().toInt(), is(40004)); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | SortedMap<String, Criterion> criteria = new TreeMap<>(); |
| 525 | |
| 526 | /** |
| 527 | * Looks up a criterion in the instruction map based on type and subtype. |
| 528 | * |
| 529 | * @param type type string |
| 530 | * @return criterion that matches |
| 531 | */ |
| 532 | private Criterion getCriterion(Criterion.Type type) { |
| 533 | Criterion criterion = criteria.get(type.name()); |
| 534 | assertThat(criterion.type(), is(type)); |
| 535 | return criterion; |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * Checks that a rule with one of each kind of criterion decodes properly. |
| 540 | * |
| 541 | * @throws IOException if the resource cannot be processed |
| 542 | */ |
| 543 | @Test |
| 544 | public void codecCriteriaFlowTest() throws Exception { |
| 545 | FlowRule rule = getRule("criteria-flow.json"); |
| 546 | |
| 547 | checkCommonData(rule); |
| 548 | |
Sho SHIMIZU | 0681016 | 2016-02-24 12:52:32 -0800 | [diff] [blame] | 549 | assertThat(rule.selector().criteria().size(), is(35)); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 550 | |
| 551 | rule.selector().criteria() |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 552 | .forEach(criterion -> |
| 553 | criteria.put(criterion.type().name(), criterion)); |
| 554 | |
| 555 | Criterion criterion; |
| 556 | |
| 557 | criterion = getCriterion(Criterion.Type.ETH_TYPE); |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 558 | assertThat(((EthTypeCriterion) criterion).ethType(), is(new EthType(2054))); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 559 | |
| 560 | criterion = getCriterion(Criterion.Type.ETH_DST); |
| 561 | assertThat(((EthCriterion) criterion).mac(), |
| 562 | is(MacAddress.valueOf("00:11:22:33:44:55"))); |
| 563 | |
| 564 | criterion = getCriterion(Criterion.Type.ETH_SRC); |
| 565 | assertThat(((EthCriterion) criterion).mac(), |
| 566 | is(MacAddress.valueOf("00:11:22:33:44:55"))); |
| 567 | |
| 568 | criterion = getCriterion(Criterion.Type.IN_PORT); |
| 569 | assertThat(((PortCriterion) criterion).port(), |
| 570 | is(PortNumber.portNumber(23))); |
| 571 | |
| 572 | criterion = getCriterion(Criterion.Type.IN_PHY_PORT); |
| 573 | assertThat(((PortCriterion) criterion).port(), |
| 574 | is(PortNumber.portNumber(44))); |
| 575 | |
| 576 | criterion = getCriterion(Criterion.Type.VLAN_VID); |
| 577 | assertThat(((VlanIdCriterion) criterion).vlanId(), |
| 578 | is(VlanId.vlanId((short) 777))); |
| 579 | |
| 580 | criterion = getCriterion(Criterion.Type.VLAN_PCP); |
| 581 | assertThat(((VlanPcpCriterion) criterion).priority(), |
| 582 | is(((byte) 3))); |
| 583 | |
| 584 | criterion = getCriterion(Criterion.Type.IP_DSCP); |
| 585 | assertThat(((IPDscpCriterion) criterion).ipDscp(), |
| 586 | is(((byte) 2))); |
| 587 | |
| 588 | criterion = getCriterion(Criterion.Type.IP_ECN); |
| 589 | assertThat(((IPEcnCriterion) criterion).ipEcn(), |
| 590 | is(((byte) 1))); |
| 591 | |
| 592 | criterion = getCriterion(Criterion.Type.IP_PROTO); |
| 593 | assertThat(((IPProtocolCriterion) criterion).protocol(), |
| 594 | is(((short) 4))); |
| 595 | |
| 596 | criterion = getCriterion(Criterion.Type.IPV4_SRC); |
| 597 | assertThat(((IPCriterion) criterion).ip(), |
| 598 | is((IpPrefix.valueOf("1.2.0.0/32")))); |
| 599 | |
| 600 | criterion = getCriterion(Criterion.Type.IPV4_DST); |
| 601 | assertThat(((IPCriterion) criterion).ip(), |
| 602 | is((IpPrefix.valueOf("2.2.0.0/32")))); |
| 603 | |
| 604 | criterion = getCriterion(Criterion.Type.IPV6_SRC); |
| 605 | assertThat(((IPCriterion) criterion).ip(), |
| 606 | is((IpPrefix.valueOf("3.2.0.0/32")))); |
| 607 | |
| 608 | criterion = getCriterion(Criterion.Type.IPV6_DST); |
| 609 | assertThat(((IPCriterion) criterion).ip(), |
| 610 | is((IpPrefix.valueOf("4.2.0.0/32")))); |
| 611 | |
| 612 | criterion = getCriterion(Criterion.Type.TCP_SRC); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 613 | assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(), |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 614 | is(80)); |
| 615 | |
| 616 | criterion = getCriterion(Criterion.Type.TCP_DST); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 617 | assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(), |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 618 | is(443)); |
| 619 | |
| 620 | criterion = getCriterion(Criterion.Type.UDP_SRC); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 621 | assertThat(((UdpPortCriterion) criterion).udpPort().toInt(), |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 622 | is(180)); |
| 623 | |
| 624 | criterion = getCriterion(Criterion.Type.UDP_DST); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 625 | assertThat(((UdpPortCriterion) criterion).udpPort().toInt(), |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 626 | is(1443)); |
| 627 | |
| 628 | criterion = getCriterion(Criterion.Type.SCTP_SRC); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 629 | assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(), |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 630 | is(280)); |
| 631 | |
| 632 | criterion = getCriterion(Criterion.Type.SCTP_DST); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 633 | assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(), |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 634 | is(2443)); |
| 635 | |
| 636 | criterion = getCriterion(Criterion.Type.ICMPV4_TYPE); |
| 637 | assertThat(((IcmpTypeCriterion) criterion).icmpType(), |
| 638 | is((short) 24)); |
| 639 | |
| 640 | criterion = getCriterion(Criterion.Type.ICMPV4_CODE); |
| 641 | assertThat(((IcmpCodeCriterion) criterion).icmpCode(), |
| 642 | is((short) 16)); |
| 643 | |
| 644 | criterion = getCriterion(Criterion.Type.ICMPV6_TYPE); |
| 645 | assertThat(((Icmpv6TypeCriterion) criterion).icmpv6Type(), |
| 646 | is((short) 14)); |
| 647 | |
| 648 | criterion = getCriterion(Criterion.Type.ICMPV6_CODE); |
| 649 | assertThat(((Icmpv6CodeCriterion) criterion).icmpv6Code(), |
| 650 | is((short) 6)); |
| 651 | |
| 652 | criterion = getCriterion(Criterion.Type.IPV6_FLABEL); |
| 653 | assertThat(((IPv6FlowLabelCriterion) criterion).flowLabel(), |
| 654 | is(8)); |
| 655 | |
| 656 | criterion = getCriterion(Criterion.Type.IPV6_ND_TARGET); |
| 657 | assertThat(((IPv6NDTargetAddressCriterion) criterion) |
| 658 | .targetAddress().toString(), |
| 659 | is("1111:2222:3333:4444:5555:6666:7777:8888")); |
| 660 | |
| 661 | criterion = getCriterion(Criterion.Type.IPV6_ND_SLL); |
| 662 | assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(), |
| 663 | is(MacAddress.valueOf("00:11:22:33:44:56"))); |
| 664 | |
| 665 | criterion = getCriterion(Criterion.Type.IPV6_ND_TLL); |
| 666 | assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(), |
| 667 | is(MacAddress.valueOf("00:11:22:33:44:57"))); |
| 668 | |
| 669 | criterion = getCriterion(Criterion.Type.MPLS_LABEL); |
| 670 | assertThat(((MplsCriterion) criterion).label(), |
| 671 | is(MplsLabel.mplsLabel(123))); |
| 672 | |
| 673 | criterion = getCriterion(Criterion.Type.IPV6_EXTHDR); |
| 674 | assertThat(((IPv6ExthdrFlagsCriterion) criterion).exthdrFlags(), |
| 675 | is(99)); |
| 676 | |
Hyunsun Moon | 7080a0d | 2015-08-14 19:18:48 -0700 | [diff] [blame] | 677 | criterion = getCriterion(Criterion.Type.TUNNEL_ID); |
| 678 | assertThat(((TunnelIdCriterion) criterion).tunnelId(), |
| 679 | is(100L)); |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 680 | |
| 681 | criterion = getCriterion(Criterion.Type.OCH_SIGTYPE); |
| 682 | assertThat(((OchSignalTypeCriterion) criterion).signalType(), |
| 683 | is(OchSignalType.FIXED_GRID)); |
| 684 | |
| 685 | criterion = getCriterion(Criterion.Type.ODU_SIGTYPE); |
| 686 | assertThat(((OduSignalTypeCriterion) criterion).signalType(), |
| 687 | is(OduSignalType.ODU4)); |
| 688 | |
| 689 | |
| 690 | criterion = getCriterion(Criterion.Type.ODU_SIGID); |
| 691 | assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributaryPortNumber(), |
| 692 | is(1)); |
| 693 | |
| 694 | assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotLength(), |
| 695 | is(80)); |
| 696 | |
| 697 | assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotBitmap(), |
Jian Li | 68c4fc4 | 2016-01-11 16:07:03 -0800 | [diff] [blame] | 698 | is(new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1})); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /** |
| 702 | * Checks that a rule with a SigId criterion decodes properly. |
| 703 | * |
| 704 | * @throws IOException if the resource cannot be processed |
| 705 | */ |
| 706 | @Test |
| 707 | public void codecSigIdCriteriaFlowTest() throws Exception { |
| 708 | FlowRule rule = getRule("sigid-flow.json"); |
| 709 | |
| 710 | checkCommonData(rule); |
| 711 | |
| 712 | assertThat(rule.selector().criteria().size(), is(1)); |
| 713 | Criterion criterion = rule.selector().criteria().iterator().next(); |
| 714 | assertThat(criterion.type(), is(Criterion.Type.OCH_SIGID)); |
| 715 | Lambda lambda = ((OchSignalCriterion) criterion).lambda(); |
| 716 | assertThat(lambda, instanceOf(OchSignal.class)); |
| 717 | OchSignal ochSignal = (OchSignal) lambda; |
| 718 | assertThat(ochSignal.spacingMultiplier(), is(3)); |
| 719 | assertThat(ochSignal.slotGranularity(), is(4)); |
| 720 | assertThat(ochSignal.gridType(), is(GridType.CWDM)); |
| 721 | assertThat(ochSignal.channelSpacing(), is(ChannelSpacing.CHL_25GHZ)); |
| 722 | } |
| 723 | |
| 724 | } |