blob: f2786b6ffa402ab2ce3195945c5f7e2ece7c2835 [file] [log] [blame]
Ray Milkeyd43fe452015-05-29 09:35:12 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.codec.impl;
17
18import java.io.IOException;
19import java.io.InputStream;
20import java.util.SortedMap;
21import java.util.TreeMap;
22
23import org.junit.Before;
24import org.junit.Test;
alshabibcaf1ca22015-06-25 15:18:16 -070025import org.onlab.packet.EthType;
Ray Milkeyd43fe452015-05-29 09:35:12 -070026import org.onlab.packet.Ethernet;
27import org.onlab.packet.IpAddress;
28import org.onlab.packet.IpPrefix;
29import org.onlab.packet.MacAddress;
30import org.onlab.packet.MplsLabel;
31import org.onlab.packet.VlanId;
32import org.onosproject.codec.JsonCodec;
33import org.onosproject.core.CoreService;
34import org.onosproject.net.ChannelSpacing;
35import org.onosproject.net.GridType;
36import org.onosproject.net.Lambda;
37import org.onosproject.net.OchSignal;
38import org.onosproject.net.PortNumber;
39import org.onosproject.net.flow.FlowRule;
40import org.onosproject.net.flow.criteria.Criterion;
41import org.onosproject.net.flow.criteria.EthCriterion;
42import org.onosproject.net.flow.criteria.EthTypeCriterion;
43import org.onosproject.net.flow.criteria.IPCriterion;
44import org.onosproject.net.flow.criteria.IPDscpCriterion;
45import org.onosproject.net.flow.criteria.IPEcnCriterion;
46import org.onosproject.net.flow.criteria.IPProtocolCriterion;
47import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion;
48import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion;
49import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion;
50import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion;
51import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
52import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
53import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
54import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
55import org.onosproject.net.flow.criteria.IndexedLambdaCriterion;
56import org.onosproject.net.flow.criteria.MplsCriterion;
57import org.onosproject.net.flow.criteria.OchSignalCriterion;
58import org.onosproject.net.flow.criteria.PortCriterion;
59import org.onosproject.net.flow.criteria.SctpPortCriterion;
60import org.onosproject.net.flow.criteria.TcpPortCriterion;
Hyunsun Moon7080a0d2015-08-14 19:18:48 -070061import org.onosproject.net.flow.criteria.TunnelIdCriterion;
Ray Milkeyd43fe452015-05-29 09:35:12 -070062import org.onosproject.net.flow.criteria.UdpPortCriterion;
63import org.onosproject.net.flow.criteria.VlanIdCriterion;
64import org.onosproject.net.flow.criteria.VlanPcpCriterion;
65import org.onosproject.net.flow.instructions.Instruction;
66import org.onosproject.net.flow.instructions.Instructions;
67import org.onosproject.net.flow.instructions.L0ModificationInstruction;
68import org.onosproject.net.flow.instructions.L2ModificationInstruction;
69import org.onosproject.net.flow.instructions.L3ModificationInstruction;
70
71import com.fasterxml.jackson.databind.JsonNode;
72import com.fasterxml.jackson.databind.node.ObjectNode;
73
74import static org.easymock.EasyMock.createMock;
75import static org.easymock.EasyMock.expect;
76import static org.easymock.EasyMock.replay;
77import static org.hamcrest.MatcherAssert.assertThat;
78import static org.hamcrest.Matchers.instanceOf;
79import static org.hamcrest.Matchers.is;
80import static org.hamcrest.Matchers.notNullValue;
81import static org.onosproject.net.NetTestTools.APP_ID;
82
83/**
84 * Flow rule codec unit tests.
85 */
86public class FlowRuleCodecTest {
87
88 MockCodecContext context;
89 JsonCodec<FlowRule> flowRuleCodec;
90 final CoreService mockCoreService = createMock(CoreService.class);
91
92 /**
93 * Sets up for each test. Creates a context and fetches the flow rule
94 * codec.
95 */
96 @Before
97 public void setUp() {
98 context = new MockCodecContext();
99 flowRuleCodec = context.codec(FlowRule.class);
100 assertThat(flowRuleCodec, notNullValue());
101
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700102 expect(mockCoreService.registerApplication(FlowRuleCodec.REST_APP_ID))
Ray Milkeyd43fe452015-05-29 09:35:12 -0700103 .andReturn(APP_ID).anyTimes();
104 replay(mockCoreService);
105 context.registerService(CoreService.class, mockCoreService);
106 }
107
108 /**
109 * Reads in a rule from the given resource and decodes it.
110 *
111 * @param resourceName resource to use to read the JSON for the rule
112 * @return decoded flow rule
113 * @throws IOException if processing the resource fails
114 */
115 private FlowRule getRule(String resourceName) throws IOException {
116 InputStream jsonStream = FlowRuleCodecTest.class
117 .getResourceAsStream(resourceName);
118 JsonNode json = context.mapper().readTree(jsonStream);
119 assertThat(json, notNullValue());
120 FlowRule rule = flowRuleCodec.decode((ObjectNode) json, context);
121 assertThat(rule, notNullValue());
122 return rule;
123 }
124
125 /**
126 * Checks that the data shared by all the resources is correct for a
127 * given rule.
128 *
129 * @param rule rule to check
130 */
131 private void checkCommonData(FlowRule rule) {
132 assertThat(rule.appId(), is(APP_ID.id()));
133 assertThat(rule.isPermanent(), is(false));
134 assertThat(rule.timeout(), is(1));
135 assertThat(rule.priority(), is(1));
136 assertThat(rule.deviceId().toString(), is("of:0000000000000001"));
137 }
138
139 /**
140 * Checks that a simple rule decodes properly.
141 *
142 * @throws IOException if the resource cannot be processed
143 */
144 @Test
145 public void codecSimpleFlowTest() throws IOException {
146 FlowRule rule = getRule("simple-flow.json");
147
148 checkCommonData(rule);
149
150 assertThat(rule.selector().criteria().size(), is(1));
151 Criterion criterion1 = rule.selector().criteria().iterator().next();
152 assertThat(criterion1.type(), is(Criterion.Type.ETH_TYPE));
alshabibcaf1ca22015-06-25 15:18:16 -0700153 assertThat(((EthTypeCriterion) criterion1).ethType(), is(new EthType(2054)));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700154
155 assertThat(rule.treatment().allInstructions().size(), is(1));
156 Instruction instruction1 = rule.treatment().allInstructions().get(0);
157 assertThat(instruction1.type(), is(Instruction.Type.OUTPUT));
158 assertThat(((Instructions.OutputInstruction) instruction1).port(), is(PortNumber.CONTROLLER));
159 }
160
161 SortedMap<String, Instruction> instructions = new TreeMap<>();
162
163 /**
164 * Looks up an instruction in the instruction map based on type and subtype.
165 *
166 * @param type type string
167 * @param subType subtype string
168 * @return instruction that matches
169 */
170 private Instruction getInstruction(Instruction.Type type, String subType) {
171 Instruction instruction = instructions.get(type.name() + "/" + subType);
172 assertThat(instruction, notNullValue());
173 assertThat(instruction.type(), is(type));
174 return instruction;
175 }
176
177 /**
178 * Checks that a rule with one of each instruction type decodes properly.
179 *
180 * @throws IOException if the resource cannot be processed
181 */
182 @Test
183 public void decodeInstructionsFlowTest() throws Exception {
184 FlowRule rule = getRule("instructions-flow.json");
185
186 checkCommonData(rule);
187
188 rule.treatment().allInstructions()
189 .stream()
190 .forEach(instruction ->
191 {
192 String subType;
193 if (instruction.type() == Instruction.Type.L0MODIFICATION) {
194 subType = ((L0ModificationInstruction) instruction)
195 .subtype().name();
196 } else if (instruction.type() == Instruction.Type.L2MODIFICATION) {
197 subType = ((L2ModificationInstruction) instruction)
198 .subtype().name();
199 } else if (instruction.type() == Instruction.Type.L3MODIFICATION) {
200 subType = ((L3ModificationInstruction) instruction)
201 .subtype().name();
202 } else {
203 subType = "";
204 }
205 instructions.put(
206 instruction.type().name() + "/" + subType, instruction);
207 });
208
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700209 assertThat(rule.treatment().allInstructions().size(), is(20));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700210
211 Instruction instruction;
212
213 instruction = getInstruction(Instruction.Type.OUTPUT, "");
214 assertThat(instruction.type(), is(Instruction.Type.OUTPUT));
215 assertThat(((Instructions.OutputInstruction) instruction).port(), is(PortNumber.CONTROLLER));
216
217 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
218 L2ModificationInstruction.L2SubType.ETH_SRC.name());
219 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
220 assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(),
221 is(MacAddress.valueOf("12:34:56:78:90:12")));
222
223 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
224 L2ModificationInstruction.L2SubType.ETH_DST.name());
225 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
226 assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(),
227 is(MacAddress.valueOf("98:76:54:32:01:00")));
228
229 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
230 L2ModificationInstruction.L2SubType.VLAN_ID.name());
231 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
232 assertThat(((L2ModificationInstruction.ModVlanIdInstruction) instruction).vlanId().toShort(),
233 is((short) 22));
234
235 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
236 L2ModificationInstruction.L2SubType.VLAN_PCP.name());
237 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
238 assertThat(((L2ModificationInstruction.ModVlanPcpInstruction) instruction).vlanPcp(),
239 is((byte) 1));
240
241 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
242 L2ModificationInstruction.L2SubType.MPLS_LABEL.name());
243 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
244 assertThat(((L2ModificationInstruction.ModMplsLabelInstruction) instruction)
245 .label().shortValue(),
246 is((short) 777));
247
248 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
249 L2ModificationInstruction.L2SubType.MPLS_PUSH.name());
250 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
alshabib7b808c52015-06-26 14:22:24 -0700251 assertThat(((L2ModificationInstruction.PushHeaderInstructions) instruction)
252 .ethernetType().toShort(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700253 is(Ethernet.MPLS_UNICAST));
254
255 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
256 L2ModificationInstruction.L2SubType.MPLS_POP.name());
257 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
alshabib7b808c52015-06-26 14:22:24 -0700258 assertThat(((L2ModificationInstruction.PushHeaderInstructions) instruction)
259 .ethernetType().toShort(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700260 is(Ethernet.MPLS_UNICAST));
261
262 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
263 L2ModificationInstruction.L2SubType.DEC_MPLS_TTL.name());
264 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
265 assertThat(instruction, instanceOf(L2ModificationInstruction.ModMplsTtlInstruction.class));
266
267 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
268 L2ModificationInstruction.L2SubType.VLAN_POP.name());
269 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
270 assertThat(instruction, instanceOf(L2ModificationInstruction.PopVlanInstruction.class));
271
272 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
273 L2ModificationInstruction.L2SubType.VLAN_PUSH.name());
274 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
275 assertThat(instruction, instanceOf(L2ModificationInstruction.PushHeaderInstructions.class));
276
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700277 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
278 L2ModificationInstruction.L2SubType.TUNNEL_ID.name());
279 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
280 assertThat(((L2ModificationInstruction.ModTunnelIdInstruction) instruction)
281 .tunnelId(), is(100L));
282
Ray Milkeyd43fe452015-05-29 09:35:12 -0700283 instruction = getInstruction(Instruction.Type.L3MODIFICATION,
284 L3ModificationInstruction.L3SubType.IPV4_SRC.name());
285 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
286 assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(),
287 is(IpAddress.valueOf("1.2.3.4")));
288
289 instruction = getInstruction(Instruction.Type.L3MODIFICATION,
290 L3ModificationInstruction.L3SubType.IPV4_DST.name());
291 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
292 assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(),
293 is(IpAddress.valueOf("1.2.3.3")));
294
295 instruction = getInstruction(Instruction.Type.L3MODIFICATION,
296 L3ModificationInstruction.L3SubType.IPV6_SRC.name());
297 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
298 assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(),
299 is(IpAddress.valueOf("1.2.3.2")));
300
301 instruction = getInstruction(Instruction.Type.L3MODIFICATION,
302 L3ModificationInstruction.L3SubType.IPV6_DST.name());
303 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
304 assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(),
305 is(IpAddress.valueOf("1.2.3.1")));
306
307 instruction = getInstruction(Instruction.Type.L3MODIFICATION,
308 L3ModificationInstruction.L3SubType.IPV6_FLABEL.name());
309 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
310 assertThat(((L3ModificationInstruction.ModIPv6FlowLabelInstruction) instruction)
311 .flowLabel(),
312 is(8));
313
314 instruction = getInstruction(Instruction.Type.L0MODIFICATION,
315 L0ModificationInstruction.L0SubType.LAMBDA.name());
316 assertThat(instruction.type(), is(Instruction.Type.L0MODIFICATION));
317 assertThat(((L0ModificationInstruction.ModLambdaInstruction) instruction)
318 .lambda(),
319 is((short) 7));
320
321 instruction = getInstruction(Instruction.Type.L0MODIFICATION,
322 L0ModificationInstruction.L0SubType.OCH.name());
323 assertThat(instruction.type(), is(Instruction.Type.L0MODIFICATION));
324 L0ModificationInstruction.ModOchSignalInstruction och =
325 (L0ModificationInstruction.ModOchSignalInstruction) instruction;
326 assertThat(och.lambda().spacingMultiplier(), is(4));
327 assertThat(och.lambda().slotGranularity(), is(8));
328 assertThat(och.lambda().gridType(), is(GridType.DWDM));
329 assertThat(och.lambda().channelSpacing(), is(ChannelSpacing.CHL_100GHZ));
330 }
331
332 SortedMap<String, Criterion> criteria = new TreeMap<>();
333
334 /**
335 * Looks up a criterion in the instruction map based on type and subtype.
336 *
337 * @param type type string
338 * @return criterion that matches
339 */
340 private Criterion getCriterion(Criterion.Type type) {
341 Criterion criterion = criteria.get(type.name());
342 assertThat(criterion.type(), is(type));
343 return criterion;
344 }
345
346 /**
347 * Checks that a rule with one of each kind of criterion decodes properly.
348 *
349 * @throws IOException if the resource cannot be processed
350 */
351 @Test
352 public void codecCriteriaFlowTest() throws Exception {
353 FlowRule rule = getRule("criteria-flow.json");
354
355 checkCommonData(rule);
356
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700357 assertThat(rule.selector().criteria().size(), is(33));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700358
359 rule.selector().criteria()
360 .stream()
361 .forEach(criterion ->
362 criteria.put(criterion.type().name(), criterion));
363
364 Criterion criterion;
365
366 criterion = getCriterion(Criterion.Type.ETH_TYPE);
alshabibcaf1ca22015-06-25 15:18:16 -0700367 assertThat(((EthTypeCriterion) criterion).ethType(), is(new EthType(2054)));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700368
369 criterion = getCriterion(Criterion.Type.ETH_DST);
370 assertThat(((EthCriterion) criterion).mac(),
371 is(MacAddress.valueOf("00:11:22:33:44:55")));
372
373 criterion = getCriterion(Criterion.Type.ETH_SRC);
374 assertThat(((EthCriterion) criterion).mac(),
375 is(MacAddress.valueOf("00:11:22:33:44:55")));
376
377 criterion = getCriterion(Criterion.Type.IN_PORT);
378 assertThat(((PortCriterion) criterion).port(),
379 is(PortNumber.portNumber(23)));
380
381 criterion = getCriterion(Criterion.Type.IN_PHY_PORT);
382 assertThat(((PortCriterion) criterion).port(),
383 is(PortNumber.portNumber(44)));
384
385 criterion = getCriterion(Criterion.Type.VLAN_VID);
386 assertThat(((VlanIdCriterion) criterion).vlanId(),
387 is(VlanId.vlanId((short) 777)));
388
389 criterion = getCriterion(Criterion.Type.VLAN_PCP);
390 assertThat(((VlanPcpCriterion) criterion).priority(),
391 is(((byte) 3)));
392
393 criterion = getCriterion(Criterion.Type.IP_DSCP);
394 assertThat(((IPDscpCriterion) criterion).ipDscp(),
395 is(((byte) 2)));
396
397 criterion = getCriterion(Criterion.Type.IP_ECN);
398 assertThat(((IPEcnCriterion) criterion).ipEcn(),
399 is(((byte) 1)));
400
401 criterion = getCriterion(Criterion.Type.IP_PROTO);
402 assertThat(((IPProtocolCriterion) criterion).protocol(),
403 is(((short) 4)));
404
405 criterion = getCriterion(Criterion.Type.IPV4_SRC);
406 assertThat(((IPCriterion) criterion).ip(),
407 is((IpPrefix.valueOf("1.2.0.0/32"))));
408
409 criterion = getCriterion(Criterion.Type.IPV4_DST);
410 assertThat(((IPCriterion) criterion).ip(),
411 is((IpPrefix.valueOf("2.2.0.0/32"))));
412
413 criterion = getCriterion(Criterion.Type.IPV6_SRC);
414 assertThat(((IPCriterion) criterion).ip(),
415 is((IpPrefix.valueOf("3.2.0.0/32"))));
416
417 criterion = getCriterion(Criterion.Type.IPV6_DST);
418 assertThat(((IPCriterion) criterion).ip(),
419 is((IpPrefix.valueOf("4.2.0.0/32"))));
420
421 criterion = getCriterion(Criterion.Type.TCP_SRC);
422 assertThat(((TcpPortCriterion) criterion).tcpPort(),
423 is(80));
424
425 criterion = getCriterion(Criterion.Type.TCP_DST);
426 assertThat(((TcpPortCriterion) criterion).tcpPort(),
427 is(443));
428
429 criterion = getCriterion(Criterion.Type.UDP_SRC);
430 assertThat(((UdpPortCriterion) criterion).udpPort(),
431 is(180));
432
433 criterion = getCriterion(Criterion.Type.UDP_DST);
434 assertThat(((UdpPortCriterion) criterion).udpPort(),
435 is(1443));
436
437 criterion = getCriterion(Criterion.Type.SCTP_SRC);
438 assertThat(((SctpPortCriterion) criterion).sctpPort(),
439 is(280));
440
441 criterion = getCriterion(Criterion.Type.SCTP_DST);
442 assertThat(((SctpPortCriterion) criterion).sctpPort(),
443 is(2443));
444
445 criterion = getCriterion(Criterion.Type.ICMPV4_TYPE);
446 assertThat(((IcmpTypeCriterion) criterion).icmpType(),
447 is((short) 24));
448
449 criterion = getCriterion(Criterion.Type.ICMPV4_CODE);
450 assertThat(((IcmpCodeCriterion) criterion).icmpCode(),
451 is((short) 16));
452
453 criterion = getCriterion(Criterion.Type.ICMPV6_TYPE);
454 assertThat(((Icmpv6TypeCriterion) criterion).icmpv6Type(),
455 is((short) 14));
456
457 criterion = getCriterion(Criterion.Type.ICMPV6_CODE);
458 assertThat(((Icmpv6CodeCriterion) criterion).icmpv6Code(),
459 is((short) 6));
460
461 criterion = getCriterion(Criterion.Type.IPV6_FLABEL);
462 assertThat(((IPv6FlowLabelCriterion) criterion).flowLabel(),
463 is(8));
464
465 criterion = getCriterion(Criterion.Type.IPV6_ND_TARGET);
466 assertThat(((IPv6NDTargetAddressCriterion) criterion)
467 .targetAddress().toString(),
468 is("1111:2222:3333:4444:5555:6666:7777:8888"));
469
470 criterion = getCriterion(Criterion.Type.IPV6_ND_SLL);
471 assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(),
472 is(MacAddress.valueOf("00:11:22:33:44:56")));
473
474 criterion = getCriterion(Criterion.Type.IPV6_ND_TLL);
475 assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(),
476 is(MacAddress.valueOf("00:11:22:33:44:57")));
477
478 criterion = getCriterion(Criterion.Type.MPLS_LABEL);
479 assertThat(((MplsCriterion) criterion).label(),
480 is(MplsLabel.mplsLabel(123)));
481
482 criterion = getCriterion(Criterion.Type.IPV6_EXTHDR);
483 assertThat(((IPv6ExthdrFlagsCriterion) criterion).exthdrFlags(),
484 is(99));
485
486 criterion = getCriterion(Criterion.Type.OCH_SIGID);
487 assertThat(((IndexedLambdaCriterion) criterion).lambda(),
488 is(Lambda.indexedLambda(122)));
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700489
490 criterion = getCriterion(Criterion.Type.TUNNEL_ID);
491 assertThat(((TunnelIdCriterion) criterion).tunnelId(),
492 is(100L));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700493 }
494
495 /**
496 * Checks that a rule with a SigId criterion decodes properly.
497 *
498 * @throws IOException if the resource cannot be processed
499 */
500 @Test
501 public void codecSigIdCriteriaFlowTest() throws Exception {
502 FlowRule rule = getRule("sigid-flow.json");
503
504 checkCommonData(rule);
505
506 assertThat(rule.selector().criteria().size(), is(1));
507 Criterion criterion = rule.selector().criteria().iterator().next();
508 assertThat(criterion.type(), is(Criterion.Type.OCH_SIGID));
509 Lambda lambda = ((OchSignalCriterion) criterion).lambda();
510 assertThat(lambda, instanceOf(OchSignal.class));
511 OchSignal ochSignal = (OchSignal) lambda;
512 assertThat(ochSignal.spacingMultiplier(), is(3));
513 assertThat(ochSignal.slotGranularity(), is(4));
514 assertThat(ochSignal.gridType(), is(GridType.CWDM));
515 assertThat(ochSignal.channelSpacing(), is(ChannelSpacing.CHL_25GHZ));
516 }
517
518}