blob: 9c5e3fda44fc04f96a6ea9a8772dd4937a5559de [file] [log] [blame]
Ray Milkeyd43fe452015-05-29 09:35:12 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeyd43fe452015-05-29 09:35:12 -07003 *
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
Sho SHIMIZUcc137a92016-03-11 15:10:54 -0800217 assertThat(rule.treatment().allInstructions().size(), is(23));
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,
Ray Milkeyd43fe452015-05-29 09:35:12 -0700323 L0ModificationInstruction.L0SubType.OCH.name());
324 assertThat(instruction.type(), is(Instruction.Type.L0MODIFICATION));
325 L0ModificationInstruction.ModOchSignalInstruction och =
326 (L0ModificationInstruction.ModOchSignalInstruction) instruction;
327 assertThat(och.lambda().spacingMultiplier(), is(4));
328 assertThat(och.lambda().slotGranularity(), is(8));
329 assertThat(och.lambda().gridType(), is(GridType.DWDM));
330 assertThat(och.lambda().channelSpacing(), is(ChannelSpacing.CHL_100GHZ));
Hyunsun Moonfab29502015-08-25 13:39:16 -0700331
332 instruction = getInstruction(Instruction.Type.L4MODIFICATION,
333 L4ModificationInstruction.L4SubType.TCP_DST.name());
334 assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
335 assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction)
336 .port().toInt(), is(40001));
337
338 instruction = getInstruction(Instruction.Type.L4MODIFICATION,
339 L4ModificationInstruction.L4SubType.TCP_SRC.name());
340 assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
341 assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction)
342 .port().toInt(), is(40002));
343
344 instruction = getInstruction(Instruction.Type.L4MODIFICATION,
345 L4ModificationInstruction.L4SubType.UDP_DST.name());
346 assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
347 assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction)
348 .port().toInt(), is(40003));
349
350 instruction = getInstruction(Instruction.Type.L4MODIFICATION,
351 L4ModificationInstruction.L4SubType.UDP_SRC.name());
352 assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
353 assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction)
354 .port().toInt(), is(40004));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700355 }
356
357 SortedMap<String, Criterion> criteria = new TreeMap<>();
358
359 /**
360 * Looks up a criterion in the instruction map based on type and subtype.
361 *
362 * @param type type string
363 * @return criterion that matches
364 */
365 private Criterion getCriterion(Criterion.Type type) {
366 Criterion criterion = criteria.get(type.name());
367 assertThat(criterion.type(), is(type));
368 return criterion;
369 }
370
371 /**
372 * Checks that a rule with one of each kind of criterion decodes properly.
373 *
374 * @throws IOException if the resource cannot be processed
375 */
376 @Test
377 public void codecCriteriaFlowTest() throws Exception {
378 FlowRule rule = getRule("criteria-flow.json");
379
380 checkCommonData(rule);
381
Sho SHIMIZU06810162016-02-24 12:52:32 -0800382 assertThat(rule.selector().criteria().size(), is(35));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700383
384 rule.selector().criteria()
385 .stream()
386 .forEach(criterion ->
387 criteria.put(criterion.type().name(), criterion));
388
389 Criterion criterion;
390
391 criterion = getCriterion(Criterion.Type.ETH_TYPE);
alshabibcaf1ca22015-06-25 15:18:16 -0700392 assertThat(((EthTypeCriterion) criterion).ethType(), is(new EthType(2054)));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700393
394 criterion = getCriterion(Criterion.Type.ETH_DST);
395 assertThat(((EthCriterion) criterion).mac(),
396 is(MacAddress.valueOf("00:11:22:33:44:55")));
397
398 criterion = getCriterion(Criterion.Type.ETH_SRC);
399 assertThat(((EthCriterion) criterion).mac(),
400 is(MacAddress.valueOf("00:11:22:33:44:55")));
401
402 criterion = getCriterion(Criterion.Type.IN_PORT);
403 assertThat(((PortCriterion) criterion).port(),
404 is(PortNumber.portNumber(23)));
405
406 criterion = getCriterion(Criterion.Type.IN_PHY_PORT);
407 assertThat(((PortCriterion) criterion).port(),
408 is(PortNumber.portNumber(44)));
409
410 criterion = getCriterion(Criterion.Type.VLAN_VID);
411 assertThat(((VlanIdCriterion) criterion).vlanId(),
412 is(VlanId.vlanId((short) 777)));
413
414 criterion = getCriterion(Criterion.Type.VLAN_PCP);
415 assertThat(((VlanPcpCriterion) criterion).priority(),
416 is(((byte) 3)));
417
418 criterion = getCriterion(Criterion.Type.IP_DSCP);
419 assertThat(((IPDscpCriterion) criterion).ipDscp(),
420 is(((byte) 2)));
421
422 criterion = getCriterion(Criterion.Type.IP_ECN);
423 assertThat(((IPEcnCriterion) criterion).ipEcn(),
424 is(((byte) 1)));
425
426 criterion = getCriterion(Criterion.Type.IP_PROTO);
427 assertThat(((IPProtocolCriterion) criterion).protocol(),
428 is(((short) 4)));
429
430 criterion = getCriterion(Criterion.Type.IPV4_SRC);
431 assertThat(((IPCriterion) criterion).ip(),
432 is((IpPrefix.valueOf("1.2.0.0/32"))));
433
434 criterion = getCriterion(Criterion.Type.IPV4_DST);
435 assertThat(((IPCriterion) criterion).ip(),
436 is((IpPrefix.valueOf("2.2.0.0/32"))));
437
438 criterion = getCriterion(Criterion.Type.IPV6_SRC);
439 assertThat(((IPCriterion) criterion).ip(),
440 is((IpPrefix.valueOf("3.2.0.0/32"))));
441
442 criterion = getCriterion(Criterion.Type.IPV6_DST);
443 assertThat(((IPCriterion) criterion).ip(),
444 is((IpPrefix.valueOf("4.2.0.0/32"))));
445
446 criterion = getCriterion(Criterion.Type.TCP_SRC);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700447 assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700448 is(80));
449
450 criterion = getCriterion(Criterion.Type.TCP_DST);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700451 assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700452 is(443));
453
454 criterion = getCriterion(Criterion.Type.UDP_SRC);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700455 assertThat(((UdpPortCriterion) criterion).udpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700456 is(180));
457
458 criterion = getCriterion(Criterion.Type.UDP_DST);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700459 assertThat(((UdpPortCriterion) criterion).udpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700460 is(1443));
461
462 criterion = getCriterion(Criterion.Type.SCTP_SRC);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700463 assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700464 is(280));
465
466 criterion = getCriterion(Criterion.Type.SCTP_DST);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700467 assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(),
Ray Milkeyd43fe452015-05-29 09:35:12 -0700468 is(2443));
469
470 criterion = getCriterion(Criterion.Type.ICMPV4_TYPE);
471 assertThat(((IcmpTypeCriterion) criterion).icmpType(),
472 is((short) 24));
473
474 criterion = getCriterion(Criterion.Type.ICMPV4_CODE);
475 assertThat(((IcmpCodeCriterion) criterion).icmpCode(),
476 is((short) 16));
477
478 criterion = getCriterion(Criterion.Type.ICMPV6_TYPE);
479 assertThat(((Icmpv6TypeCriterion) criterion).icmpv6Type(),
480 is((short) 14));
481
482 criterion = getCriterion(Criterion.Type.ICMPV6_CODE);
483 assertThat(((Icmpv6CodeCriterion) criterion).icmpv6Code(),
484 is((short) 6));
485
486 criterion = getCriterion(Criterion.Type.IPV6_FLABEL);
487 assertThat(((IPv6FlowLabelCriterion) criterion).flowLabel(),
488 is(8));
489
490 criterion = getCriterion(Criterion.Type.IPV6_ND_TARGET);
491 assertThat(((IPv6NDTargetAddressCriterion) criterion)
492 .targetAddress().toString(),
493 is("1111:2222:3333:4444:5555:6666:7777:8888"));
494
495 criterion = getCriterion(Criterion.Type.IPV6_ND_SLL);
496 assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(),
497 is(MacAddress.valueOf("00:11:22:33:44:56")));
498
499 criterion = getCriterion(Criterion.Type.IPV6_ND_TLL);
500 assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(),
501 is(MacAddress.valueOf("00:11:22:33:44:57")));
502
503 criterion = getCriterion(Criterion.Type.MPLS_LABEL);
504 assertThat(((MplsCriterion) criterion).label(),
505 is(MplsLabel.mplsLabel(123)));
506
507 criterion = getCriterion(Criterion.Type.IPV6_EXTHDR);
508 assertThat(((IPv6ExthdrFlagsCriterion) criterion).exthdrFlags(),
509 is(99));
510
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700511 criterion = getCriterion(Criterion.Type.TUNNEL_ID);
512 assertThat(((TunnelIdCriterion) criterion).tunnelId(),
513 is(100L));
Yafit Hadar5796d972015-10-15 13:16:11 +0300514
515 criterion = getCriterion(Criterion.Type.OCH_SIGTYPE);
516 assertThat(((OchSignalTypeCriterion) criterion).signalType(),
517 is(OchSignalType.FIXED_GRID));
518
519 criterion = getCriterion(Criterion.Type.ODU_SIGTYPE);
520 assertThat(((OduSignalTypeCriterion) criterion).signalType(),
521 is(OduSignalType.ODU4));
522
523
524 criterion = getCriterion(Criterion.Type.ODU_SIGID);
525 assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributaryPortNumber(),
526 is(1));
527
528 assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotLength(),
529 is(80));
530
531 assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotBitmap(),
Jian Li68c4fc42016-01-11 16:07:03 -0800532 is(new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700533 }
534
535 /**
536 * Checks that a rule with a SigId criterion decodes properly.
537 *
538 * @throws IOException if the resource cannot be processed
539 */
540 @Test
541 public void codecSigIdCriteriaFlowTest() throws Exception {
542 FlowRule rule = getRule("sigid-flow.json");
543
544 checkCommonData(rule);
545
546 assertThat(rule.selector().criteria().size(), is(1));
547 Criterion criterion = rule.selector().criteria().iterator().next();
548 assertThat(criterion.type(), is(Criterion.Type.OCH_SIGID));
549 Lambda lambda = ((OchSignalCriterion) criterion).lambda();
550 assertThat(lambda, instanceOf(OchSignal.class));
551 OchSignal ochSignal = (OchSignal) lambda;
552 assertThat(ochSignal.spacingMultiplier(), is(3));
553 assertThat(ochSignal.slotGranularity(), is(4));
554 assertThat(ochSignal.gridType(), is(GridType.CWDM));
555 assertThat(ochSignal.channelSpacing(), is(ChannelSpacing.CHL_25GHZ));
556 }
557
558}