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