blob: 515a69ea16912df5429b7e812a35c5ad32945fbb [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
Jian Li7c322f42016-03-04 11:00:59 -080018import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.node.ObjectNode;
Ray Milkeyd43fe452015-05-29 09:35:12 -070020import org.junit.Before;
21import org.junit.Test;
alshabibcaf1ca22015-06-25 15:18:16 -070022import org.onlab.packet.EthType;
Ray Milkeyd43fe452015-05-29 09:35:12 -070023import org.onlab.packet.Ethernet;
24import org.onlab.packet.IpAddress;
25import org.onlab.packet.IpPrefix;
26import org.onlab.packet.MacAddress;
27import org.onlab.packet.MplsLabel;
28import org.onlab.packet.VlanId;
29import org.onosproject.codec.JsonCodec;
30import org.onosproject.core.CoreService;
31import org.onosproject.net.ChannelSpacing;
32import org.onosproject.net.GridType;
33import org.onosproject.net.Lambda;
34import org.onosproject.net.OchSignal;
Yafit Hadar5796d972015-10-15 13:16:11 +030035import org.onosproject.net.OchSignalType;
36import org.onosproject.net.OduSignalType;
Ray Milkeyd43fe452015-05-29 09:35:12 -070037import org.onosproject.net.PortNumber;
38import org.onosproject.net.flow.FlowRule;
39import org.onosproject.net.flow.criteria.Criterion;
40import org.onosproject.net.flow.criteria.EthCriterion;
41import org.onosproject.net.flow.criteria.EthTypeCriterion;
42import org.onosproject.net.flow.criteria.IPCriterion;
43import org.onosproject.net.flow.criteria.IPDscpCriterion;
44import org.onosproject.net.flow.criteria.IPEcnCriterion;
45import org.onosproject.net.flow.criteria.IPProtocolCriterion;
46import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion;
47import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion;
48import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion;
49import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion;
50import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
51import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
52import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
53import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
Ray Milkeyd43fe452015-05-29 09:35:12 -070054import org.onosproject.net.flow.criteria.MplsCriterion;
55import org.onosproject.net.flow.criteria.OchSignalCriterion;
Yafit Hadar5796d972015-10-15 13:16:11 +030056import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
57import org.onosproject.net.flow.criteria.OduSignalIdCriterion;
58import org.onosproject.net.flow.criteria.OduSignalTypeCriterion;
Ray Milkeyd43fe452015-05-29 09:35:12 -070059import org.onosproject.net.flow.criteria.PortCriterion;
60import org.onosproject.net.flow.criteria.SctpPortCriterion;
61import org.onosproject.net.flow.criteria.TcpPortCriterion;
Hyunsun Moon7080a0d2015-08-14 19:18:48 -070062import org.onosproject.net.flow.criteria.TunnelIdCriterion;
Ray Milkeyd43fe452015-05-29 09:35:12 -070063import org.onosproject.net.flow.criteria.UdpPortCriterion;
64import org.onosproject.net.flow.criteria.VlanIdCriterion;
65import org.onosproject.net.flow.criteria.VlanPcpCriterion;
66import org.onosproject.net.flow.instructions.Instruction;
67import org.onosproject.net.flow.instructions.Instructions;
68import org.onosproject.net.flow.instructions.L0ModificationInstruction;
69import org.onosproject.net.flow.instructions.L2ModificationInstruction;
70import org.onosproject.net.flow.instructions.L3ModificationInstruction;
Hyunsun Moonfab29502015-08-25 13:39:16 -070071import org.onosproject.net.flow.instructions.L4ModificationInstruction;
Ray Milkeyd43fe452015-05-29 09:35:12 -070072
Jian Li7c322f42016-03-04 11:00:59 -080073import java.io.IOException;
74import java.io.InputStream;
75import java.util.SortedMap;
76import java.util.TreeMap;
77
78import static org.easymock.EasyMock.createMock;
79import static org.easymock.EasyMock.expect;
80import static org.easymock.EasyMock.replay;
81import static org.hamcrest.MatcherAssert.assertThat;
82import static org.hamcrest.Matchers.instanceOf;
83import static org.hamcrest.Matchers.is;
84import static org.hamcrest.Matchers.notNullValue;
85import static org.onosproject.net.NetTestTools.APP_ID;
Ray Milkeyd43fe452015-05-29 09:35:12 -070086
87/**
88 * Flow rule codec unit tests.
89 */
90public class FlowRuleCodecTest {
91
92 MockCodecContext context;
93 JsonCodec<FlowRule> flowRuleCodec;
94 final CoreService mockCoreService = createMock(CoreService.class);
95
96 /**
97 * Sets up for each test. Creates a context and fetches the flow rule
98 * codec.
99 */
100 @Before
101 public void setUp() {
102 context = new MockCodecContext();
103 flowRuleCodec = context.codec(FlowRule.class);
104 assertThat(flowRuleCodec, notNullValue());
105
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700106 expect(mockCoreService.registerApplication(FlowRuleCodec.REST_APP_ID))
Ray Milkeyd43fe452015-05-29 09:35:12 -0700107 .andReturn(APP_ID).anyTimes();
108 replay(mockCoreService);
109 context.registerService(CoreService.class, mockCoreService);
110 }
111
112 /**
113 * Reads in a rule from the given resource and decodes it.
114 *
115 * @param resourceName resource to use to read the JSON for the rule
116 * @return decoded flow rule
117 * @throws IOException if processing the resource fails
118 */
119 private FlowRule getRule(String resourceName) throws IOException {
120 InputStream jsonStream = FlowRuleCodecTest.class
121 .getResourceAsStream(resourceName);
122 JsonNode json = context.mapper().readTree(jsonStream);
123 assertThat(json, notNullValue());
124 FlowRule rule = flowRuleCodec.decode((ObjectNode) json, context);
125 assertThat(rule, notNullValue());
126 return rule;
127 }
128
129 /**
130 * Checks that the data shared by all the resources is correct for a
131 * given rule.
132 *
133 * @param rule rule to check
134 */
135 private void checkCommonData(FlowRule rule) {
136 assertThat(rule.appId(), is(APP_ID.id()));
137 assertThat(rule.isPermanent(), is(false));
138 assertThat(rule.timeout(), is(1));
139 assertThat(rule.priority(), is(1));
Jian Li7c322f42016-03-04 11:00:59 -0800140 assertThat(rule.tableId(), is(1));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700141 assertThat(rule.deviceId().toString(), is("of:0000000000000001"));
142 }
143
144 /**
145 * Checks that a simple rule decodes properly.
146 *
147 * @throws IOException if the resource cannot be processed
148 */
149 @Test
150 public void codecSimpleFlowTest() throws IOException {
151 FlowRule rule = getRule("simple-flow.json");
152
153 checkCommonData(rule);
154
155 assertThat(rule.selector().criteria().size(), is(1));
156 Criterion criterion1 = rule.selector().criteria().iterator().next();
157 assertThat(criterion1.type(), is(Criterion.Type.ETH_TYPE));
alshabibcaf1ca22015-06-25 15:18:16 -0700158 assertThat(((EthTypeCriterion) criterion1).ethType(), is(new EthType(2054)));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700159
160 assertThat(rule.treatment().allInstructions().size(), is(1));
161 Instruction instruction1 = rule.treatment().allInstructions().get(0);
162 assertThat(instruction1.type(), is(Instruction.Type.OUTPUT));
163 assertThat(((Instructions.OutputInstruction) instruction1).port(), is(PortNumber.CONTROLLER));
164 }
165
166 SortedMap<String, Instruction> instructions = new TreeMap<>();
167
168 /**
169 * Looks up an instruction in the instruction map based on type and subtype.
170 *
171 * @param type type string
172 * @param subType subtype string
173 * @return instruction that matches
174 */
175 private Instruction getInstruction(Instruction.Type type, String subType) {
176 Instruction instruction = instructions.get(type.name() + "/" + subType);
177 assertThat(instruction, notNullValue());
178 assertThat(instruction.type(), is(type));
179 return instruction;
180 }
181
182 /**
183 * Checks that a rule with one of each instruction type decodes properly.
184 *
185 * @throws IOException if the resource cannot be processed
186 */
187 @Test
188 public void decodeInstructionsFlowTest() throws Exception {
189 FlowRule rule = getRule("instructions-flow.json");
190
191 checkCommonData(rule);
192
193 rule.treatment().allInstructions()
194 .stream()
195 .forEach(instruction ->
196 {
197 String subType;
198 if (instruction.type() == Instruction.Type.L0MODIFICATION) {
199 subType = ((L0ModificationInstruction) instruction)
200 .subtype().name();
201 } else if (instruction.type() == Instruction.Type.L2MODIFICATION) {
202 subType = ((L2ModificationInstruction) instruction)
203 .subtype().name();
204 } else if (instruction.type() == Instruction.Type.L3MODIFICATION) {
205 subType = ((L3ModificationInstruction) instruction)
206 .subtype().name();
Hyunsun Moonfab29502015-08-25 13:39:16 -0700207 } else if (instruction.type() == Instruction.Type.L4MODIFICATION) {
208 subType = ((L4ModificationInstruction) instruction)
209 .subtype().name();
Ray Milkeyd43fe452015-05-29 09:35:12 -0700210 } else {
211 subType = "";
212 }
213 instructions.put(
214 instruction.type().name() + "/" + subType, instruction);
215 });
216
Hyunsun Moonfab29502015-08-25 13:39:16 -0700217 assertThat(rule.treatment().allInstructions().size(), is(24));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700218
219 Instruction instruction;
220
221 instruction = getInstruction(Instruction.Type.OUTPUT, "");
222 assertThat(instruction.type(), is(Instruction.Type.OUTPUT));
223 assertThat(((Instructions.OutputInstruction) instruction).port(), is(PortNumber.CONTROLLER));
224
225 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
226 L2ModificationInstruction.L2SubType.ETH_SRC.name());
227 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
228 assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(),
229 is(MacAddress.valueOf("12:34:56:78:90:12")));
230
231 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
232 L2ModificationInstruction.L2SubType.ETH_DST.name());
233 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
234 assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(),
235 is(MacAddress.valueOf("98:76:54:32:01:00")));
236
237 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
238 L2ModificationInstruction.L2SubType.VLAN_ID.name());
239 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
240 assertThat(((L2ModificationInstruction.ModVlanIdInstruction) instruction).vlanId().toShort(),
241 is((short) 22));
242
243 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
244 L2ModificationInstruction.L2SubType.VLAN_PCP.name());
245 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
246 assertThat(((L2ModificationInstruction.ModVlanPcpInstruction) instruction).vlanPcp(),
247 is((byte) 1));
248
249 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
250 L2ModificationInstruction.L2SubType.MPLS_LABEL.name());
251 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
252 assertThat(((L2ModificationInstruction.ModMplsLabelInstruction) instruction)
Ray Milkey125572b2016-02-22 16:48:17 -0800253 .label().toInt(),
HIGUCHI Yuta04b49fc2015-08-28 09:58:58 -0700254 is(MplsLabel.MAX_MPLS));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700255
256 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
257 L2ModificationInstruction.L2SubType.MPLS_PUSH.name());
258 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
alshabib7b808c52015-06-26 14:22:24 -0700259 assertThat(((L2ModificationInstruction.PushHeaderInstructions) instruction)
260 .ethernetType().toShort(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700261 is(Ethernet.MPLS_UNICAST));
262
263 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
264 L2ModificationInstruction.L2SubType.MPLS_POP.name());
265 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
alshabib7b808c52015-06-26 14:22:24 -0700266 assertThat(((L2ModificationInstruction.PushHeaderInstructions) instruction)
267 .ethernetType().toShort(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700268 is(Ethernet.MPLS_UNICAST));
269
270 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
271 L2ModificationInstruction.L2SubType.DEC_MPLS_TTL.name());
272 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
273 assertThat(instruction, instanceOf(L2ModificationInstruction.ModMplsTtlInstruction.class));
274
275 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
276 L2ModificationInstruction.L2SubType.VLAN_POP.name());
277 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
278 assertThat(instruction, instanceOf(L2ModificationInstruction.PopVlanInstruction.class));
279
280 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
281 L2ModificationInstruction.L2SubType.VLAN_PUSH.name());
282 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
283 assertThat(instruction, instanceOf(L2ModificationInstruction.PushHeaderInstructions.class));
284
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700285 instruction = getInstruction(Instruction.Type.L2MODIFICATION,
286 L2ModificationInstruction.L2SubType.TUNNEL_ID.name());
287 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
288 assertThat(((L2ModificationInstruction.ModTunnelIdInstruction) instruction)
289 .tunnelId(), is(100L));
290
Ray Milkeyd43fe452015-05-29 09:35:12 -0700291 instruction = getInstruction(Instruction.Type.L3MODIFICATION,
292 L3ModificationInstruction.L3SubType.IPV4_SRC.name());
293 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
294 assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(),
295 is(IpAddress.valueOf("1.2.3.4")));
296
297 instruction = getInstruction(Instruction.Type.L3MODIFICATION,
298 L3ModificationInstruction.L3SubType.IPV4_DST.name());
299 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
300 assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(),
301 is(IpAddress.valueOf("1.2.3.3")));
302
303 instruction = getInstruction(Instruction.Type.L3MODIFICATION,
304 L3ModificationInstruction.L3SubType.IPV6_SRC.name());
305 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
306 assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(),
307 is(IpAddress.valueOf("1.2.3.2")));
308
309 instruction = getInstruction(Instruction.Type.L3MODIFICATION,
310 L3ModificationInstruction.L3SubType.IPV6_DST.name());
311 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
312 assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(),
313 is(IpAddress.valueOf("1.2.3.1")));
314
315 instruction = getInstruction(Instruction.Type.L3MODIFICATION,
316 L3ModificationInstruction.L3SubType.IPV6_FLABEL.name());
317 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
318 assertThat(((L3ModificationInstruction.ModIPv6FlowLabelInstruction) instruction)
319 .flowLabel(),
320 is(8));
321
322 instruction = getInstruction(Instruction.Type.L0MODIFICATION,
323 L0ModificationInstruction.L0SubType.LAMBDA.name());
324 assertThat(instruction.type(), is(Instruction.Type.L0MODIFICATION));
325 assertThat(((L0ModificationInstruction.ModLambdaInstruction) instruction)
326 .lambda(),
327 is((short) 7));
328
329 instruction = getInstruction(Instruction.Type.L0MODIFICATION,
330 L0ModificationInstruction.L0SubType.OCH.name());
331 assertThat(instruction.type(), is(Instruction.Type.L0MODIFICATION));
332 L0ModificationInstruction.ModOchSignalInstruction och =
333 (L0ModificationInstruction.ModOchSignalInstruction) instruction;
334 assertThat(och.lambda().spacingMultiplier(), is(4));
335 assertThat(och.lambda().slotGranularity(), is(8));
336 assertThat(och.lambda().gridType(), is(GridType.DWDM));
337 assertThat(och.lambda().channelSpacing(), is(ChannelSpacing.CHL_100GHZ));
Hyunsun Moonfab29502015-08-25 13:39:16 -0700338
339 instruction = getInstruction(Instruction.Type.L4MODIFICATION,
340 L4ModificationInstruction.L4SubType.TCP_DST.name());
341 assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
342 assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction)
343 .port().toInt(), is(40001));
344
345 instruction = getInstruction(Instruction.Type.L4MODIFICATION,
346 L4ModificationInstruction.L4SubType.TCP_SRC.name());
347 assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
348 assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction)
349 .port().toInt(), is(40002));
350
351 instruction = getInstruction(Instruction.Type.L4MODIFICATION,
352 L4ModificationInstruction.L4SubType.UDP_DST.name());
353 assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
354 assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction)
355 .port().toInt(), is(40003));
356
357 instruction = getInstruction(Instruction.Type.L4MODIFICATION,
358 L4ModificationInstruction.L4SubType.UDP_SRC.name());
359 assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
360 assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction)
361 .port().toInt(), is(40004));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700362 }
363
364 SortedMap<String, Criterion> criteria = new TreeMap<>();
365
366 /**
367 * Looks up a criterion in the instruction map based on type and subtype.
368 *
369 * @param type type string
370 * @return criterion that matches
371 */
372 private Criterion getCriterion(Criterion.Type type) {
373 Criterion criterion = criteria.get(type.name());
374 assertThat(criterion.type(), is(type));
375 return criterion;
376 }
377
378 /**
379 * Checks that a rule with one of each kind of criterion decodes properly.
380 *
381 * @throws IOException if the resource cannot be processed
382 */
383 @Test
384 public void codecCriteriaFlowTest() throws Exception {
385 FlowRule rule = getRule("criteria-flow.json");
386
387 checkCommonData(rule);
388
Sho SHIMIZU06810162016-02-24 12:52:32 -0800389 assertThat(rule.selector().criteria().size(), is(35));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700390
391 rule.selector().criteria()
392 .stream()
393 .forEach(criterion ->
394 criteria.put(criterion.type().name(), criterion));
395
396 Criterion criterion;
397
398 criterion = getCriterion(Criterion.Type.ETH_TYPE);
alshabibcaf1ca22015-06-25 15:18:16 -0700399 assertThat(((EthTypeCriterion) criterion).ethType(), is(new EthType(2054)));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700400
401 criterion = getCriterion(Criterion.Type.ETH_DST);
402 assertThat(((EthCriterion) criterion).mac(),
403 is(MacAddress.valueOf("00:11:22:33:44:55")));
404
405 criterion = getCriterion(Criterion.Type.ETH_SRC);
406 assertThat(((EthCriterion) criterion).mac(),
407 is(MacAddress.valueOf("00:11:22:33:44:55")));
408
409 criterion = getCriterion(Criterion.Type.IN_PORT);
410 assertThat(((PortCriterion) criterion).port(),
411 is(PortNumber.portNumber(23)));
412
413 criterion = getCriterion(Criterion.Type.IN_PHY_PORT);
414 assertThat(((PortCriterion) criterion).port(),
415 is(PortNumber.portNumber(44)));
416
417 criterion = getCriterion(Criterion.Type.VLAN_VID);
418 assertThat(((VlanIdCriterion) criterion).vlanId(),
419 is(VlanId.vlanId((short) 777)));
420
421 criterion = getCriterion(Criterion.Type.VLAN_PCP);
422 assertThat(((VlanPcpCriterion) criterion).priority(),
423 is(((byte) 3)));
424
425 criterion = getCriterion(Criterion.Type.IP_DSCP);
426 assertThat(((IPDscpCriterion) criterion).ipDscp(),
427 is(((byte) 2)));
428
429 criterion = getCriterion(Criterion.Type.IP_ECN);
430 assertThat(((IPEcnCriterion) criterion).ipEcn(),
431 is(((byte) 1)));
432
433 criterion = getCriterion(Criterion.Type.IP_PROTO);
434 assertThat(((IPProtocolCriterion) criterion).protocol(),
435 is(((short) 4)));
436
437 criterion = getCriterion(Criterion.Type.IPV4_SRC);
438 assertThat(((IPCriterion) criterion).ip(),
439 is((IpPrefix.valueOf("1.2.0.0/32"))));
440
441 criterion = getCriterion(Criterion.Type.IPV4_DST);
442 assertThat(((IPCriterion) criterion).ip(),
443 is((IpPrefix.valueOf("2.2.0.0/32"))));
444
445 criterion = getCriterion(Criterion.Type.IPV6_SRC);
446 assertThat(((IPCriterion) criterion).ip(),
447 is((IpPrefix.valueOf("3.2.0.0/32"))));
448
449 criterion = getCriterion(Criterion.Type.IPV6_DST);
450 assertThat(((IPCriterion) criterion).ip(),
451 is((IpPrefix.valueOf("4.2.0.0/32"))));
452
453 criterion = getCriterion(Criterion.Type.TCP_SRC);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700454 assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700455 is(80));
456
457 criterion = getCriterion(Criterion.Type.TCP_DST);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700458 assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700459 is(443));
460
461 criterion = getCriterion(Criterion.Type.UDP_SRC);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700462 assertThat(((UdpPortCriterion) criterion).udpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700463 is(180));
464
465 criterion = getCriterion(Criterion.Type.UDP_DST);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700466 assertThat(((UdpPortCriterion) criterion).udpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700467 is(1443));
468
469 criterion = getCriterion(Criterion.Type.SCTP_SRC);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700470 assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700471 is(280));
472
473 criterion = getCriterion(Criterion.Type.SCTP_DST);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700474 assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700475 is(2443));
476
477 criterion = getCriterion(Criterion.Type.ICMPV4_TYPE);
478 assertThat(((IcmpTypeCriterion) criterion).icmpType(),
479 is((short) 24));
480
481 criterion = getCriterion(Criterion.Type.ICMPV4_CODE);
482 assertThat(((IcmpCodeCriterion) criterion).icmpCode(),
483 is((short) 16));
484
485 criterion = getCriterion(Criterion.Type.ICMPV6_TYPE);
486 assertThat(((Icmpv6TypeCriterion) criterion).icmpv6Type(),
487 is((short) 14));
488
489 criterion = getCriterion(Criterion.Type.ICMPV6_CODE);
490 assertThat(((Icmpv6CodeCriterion) criterion).icmpv6Code(),
491 is((short) 6));
492
493 criterion = getCriterion(Criterion.Type.IPV6_FLABEL);
494 assertThat(((IPv6FlowLabelCriterion) criterion).flowLabel(),
495 is(8));
496
497 criterion = getCriterion(Criterion.Type.IPV6_ND_TARGET);
498 assertThat(((IPv6NDTargetAddressCriterion) criterion)
499 .targetAddress().toString(),
500 is("1111:2222:3333:4444:5555:6666:7777:8888"));
501
502 criterion = getCriterion(Criterion.Type.IPV6_ND_SLL);
503 assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(),
504 is(MacAddress.valueOf("00:11:22:33:44:56")));
505
506 criterion = getCriterion(Criterion.Type.IPV6_ND_TLL);
507 assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(),
508 is(MacAddress.valueOf("00:11:22:33:44:57")));
509
510 criterion = getCriterion(Criterion.Type.MPLS_LABEL);
511 assertThat(((MplsCriterion) criterion).label(),
512 is(MplsLabel.mplsLabel(123)));
513
514 criterion = getCriterion(Criterion.Type.IPV6_EXTHDR);
515 assertThat(((IPv6ExthdrFlagsCriterion) criterion).exthdrFlags(),
516 is(99));
517
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700518 criterion = getCriterion(Criterion.Type.TUNNEL_ID);
519 assertThat(((TunnelIdCriterion) criterion).tunnelId(),
520 is(100L));
Yafit Hadar5796d972015-10-15 13:16:11 +0300521
522 criterion = getCriterion(Criterion.Type.OCH_SIGTYPE);
523 assertThat(((OchSignalTypeCriterion) criterion).signalType(),
524 is(OchSignalType.FIXED_GRID));
525
526 criterion = getCriterion(Criterion.Type.ODU_SIGTYPE);
527 assertThat(((OduSignalTypeCriterion) criterion).signalType(),
528 is(OduSignalType.ODU4));
529
530
531 criterion = getCriterion(Criterion.Type.ODU_SIGID);
532 assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributaryPortNumber(),
533 is(1));
534
535 assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotLength(),
536 is(80));
537
538 assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotBitmap(),
Jian Li68c4fc42016-01-11 16:07:03 -0800539 is(new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700540 }
541
542 /**
543 * Checks that a rule with a SigId criterion decodes properly.
544 *
545 * @throws IOException if the resource cannot be processed
546 */
547 @Test
548 public void codecSigIdCriteriaFlowTest() throws Exception {
549 FlowRule rule = getRule("sigid-flow.json");
550
551 checkCommonData(rule);
552
553 assertThat(rule.selector().criteria().size(), is(1));
554 Criterion criterion = rule.selector().criteria().iterator().next();
555 assertThat(criterion.type(), is(Criterion.Type.OCH_SIGID));
556 Lambda lambda = ((OchSignalCriterion) criterion).lambda();
557 assertThat(lambda, instanceOf(OchSignal.class));
558 OchSignal ochSignal = (OchSignal) lambda;
559 assertThat(ochSignal.spacingMultiplier(), is(3));
560 assertThat(ochSignal.slotGranularity(), is(4));
561 assertThat(ochSignal.gridType(), is(GridType.CWDM));
562 assertThat(ochSignal.channelSpacing(), is(ChannelSpacing.CHL_25GHZ));
563 }
564
565}