blob: d53b022c94c1af7e751460ac808bdc489dfa4b0f [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
andread35f89c2015-11-23 10:02:07 -080018import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.node.ObjectNode;
Ray Milkeyd43fe452015-05-29 09:35:12 -070020import org.onlab.packet.Ip6Address;
21import org.onlab.packet.IpPrefix;
22import org.onlab.packet.MacAddress;
23import org.onlab.packet.MplsLabel;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070024import org.onlab.packet.TpPort;
Ray Milkeyd43fe452015-05-29 09:35:12 -070025import org.onlab.packet.VlanId;
Yafit Hadar5796d972015-10-15 13:16:11 +030026import org.onlab.util.HexString;
Ray Milkeyd43fe452015-05-29 09:35:12 -070027import org.onosproject.net.ChannelSpacing;
28import org.onosproject.net.GridType;
29import org.onosproject.net.Lambda;
Yafit Hadar5796d972015-10-15 13:16:11 +030030import org.onosproject.net.OchSignalType;
31import org.onosproject.net.OduSignalId;
32import org.onosproject.net.OduSignalType;
Ray Milkeyd43fe452015-05-29 09:35:12 -070033import org.onosproject.net.PortNumber;
34import org.onosproject.net.flow.criteria.Criteria;
35import org.onosproject.net.flow.criteria.Criterion;
36
andread35f89c2015-11-23 10:02:07 -080037import java.util.HashMap;
38import java.util.Map;
39
40import static org.onlab.util.Tools.nullIsIllegal;
Ray Milkeyd43fe452015-05-29 09:35:12 -070041
Ray Milkeyd43fe452015-05-29 09:35:12 -070042/**
43 * Decode portion of the criterion codec.
44 */
Ray Milkey6d7968e2015-07-06 14:30:02 -070045public final class DecodeCriterionCodecHelper {
Ray Milkeyd43fe452015-05-29 09:35:12 -070046
47 private final ObjectNode json;
48
49 protected static final String MISSING_MEMBER_MESSAGE =
50 " member is required in Criterion";
51
52 private interface CriterionDecoder {
53 Criterion decodeCriterion(ObjectNode json);
54 }
55 private final Map<String, CriterionDecoder> decoderMap;
56
57 /**
58 * Creates a decode criterion codec object.
59 * Initializes the lookup map for criterion subclass decoders.
60 *
61 * @param json JSON object to decode
62 */
Ray Milkey6d7968e2015-07-06 14:30:02 -070063 public DecodeCriterionCodecHelper(ObjectNode json) {
Ray Milkeyd43fe452015-05-29 09:35:12 -070064 this.json = json;
65 decoderMap = new HashMap<>();
66
67 decoderMap.put(Criterion.Type.IN_PORT.name(), new InPortDecoder());
68 decoderMap.put(Criterion.Type.IN_PHY_PORT.name(), new InPhyPortDecoder());
69 decoderMap.put(Criterion.Type.METADATA.name(), new MetadataDecoder());
70 decoderMap.put(Criterion.Type.ETH_DST.name(), new EthDstDecoder());
71 decoderMap.put(Criterion.Type.ETH_SRC.name(), new EthSrcDecoder());
72 decoderMap.put(Criterion.Type.ETH_TYPE.name(), new EthTypeDecoder());
73 decoderMap.put(Criterion.Type.VLAN_VID.name(), new VlanVidDecoder());
74 decoderMap.put(Criterion.Type.VLAN_PCP.name(), new VlanPcpDecoder());
alshabibfa0dc662016-01-13 11:23:53 -080075 decoderMap.put(Criterion.Type.INNER_VLAN_VID.name(), new InnerVlanVidDecoder());
76 decoderMap.put(Criterion.Type.INNER_VLAN_PCP.name(), new InnerVlanPcpDecoder());
Ray Milkeyd43fe452015-05-29 09:35:12 -070077 decoderMap.put(Criterion.Type.IP_DSCP.name(), new IpDscpDecoder());
78 decoderMap.put(Criterion.Type.IP_ECN.name(), new IpEcnDecoder());
79 decoderMap.put(Criterion.Type.IP_PROTO.name(), new IpProtoDecoder());
80 decoderMap.put(Criterion.Type.IPV4_SRC.name(), new IpV4SrcDecoder());
81 decoderMap.put(Criterion.Type.IPV4_DST.name(), new IpV4DstDecoder());
82 decoderMap.put(Criterion.Type.TCP_SRC.name(), new TcpSrcDecoder());
83 decoderMap.put(Criterion.Type.TCP_DST.name(), new TcpDstDecoder());
84 decoderMap.put(Criterion.Type.UDP_SRC.name(), new UdpSrcDecoder());
85 decoderMap.put(Criterion.Type.UDP_DST.name(), new UdpDstDecoder());
86 decoderMap.put(Criterion.Type.SCTP_SRC.name(), new SctpSrcDecoder());
87 decoderMap.put(Criterion.Type.SCTP_DST.name(), new SctpDstDecoder());
88 decoderMap.put(Criterion.Type.ICMPV4_TYPE.name(), new IcmpV4TypeDecoder());
89 decoderMap.put(Criterion.Type.ICMPV4_CODE.name(), new IcmpV4CodeDecoder());
90 decoderMap.put(Criterion.Type.IPV6_SRC.name(), new IpV6SrcDecoder());
91 decoderMap.put(Criterion.Type.IPV6_DST.name(), new IpV6DstDecoder());
92 decoderMap.put(Criterion.Type.IPV6_FLABEL.name(), new IpV6FLabelDecoder());
93 decoderMap.put(Criterion.Type.ICMPV6_TYPE.name(), new IcmpV6TypeDecoder());
94 decoderMap.put(Criterion.Type.ICMPV6_CODE.name(), new IcmpV6CodeDecoder());
95 decoderMap.put(Criterion.Type.IPV6_ND_TARGET.name(), new V6NDTargetDecoder());
96 decoderMap.put(Criterion.Type.IPV6_ND_SLL.name(), new V6NDSllDecoder());
97 decoderMap.put(Criterion.Type.IPV6_ND_TLL.name(), new V6NDTllDecoder());
98 decoderMap.put(Criterion.Type.MPLS_LABEL.name(), new MplsLabelDecoder());
Jonathan Hartcc962d82016-08-09 16:52:22 -070099 decoderMap.put(Criterion.Type.MPLS_BOS.name(), new MplsBosDecoder());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700100 decoderMap.put(Criterion.Type.IPV6_EXTHDR.name(), new IpV6ExthdrDecoder());
101 decoderMap.put(Criterion.Type.OCH_SIGID.name(), new OchSigIdDecoder());
102 decoderMap.put(Criterion.Type.OCH_SIGTYPE.name(), new OchSigTypeDecoder());
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700103 decoderMap.put(Criterion.Type.TUNNEL_ID.name(), new TunnelIdDecoder());
Yafit Hadar5796d972015-10-15 13:16:11 +0300104 decoderMap.put(Criterion.Type.ODU_SIGID.name(), new OduSigIdDecoder());
105 decoderMap.put(Criterion.Type.ODU_SIGTYPE.name(), new OduSigTypeDecoder());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700106 }
107
108 private class EthTypeDecoder implements CriterionDecoder {
109 @Override
110 public Criterion decodeCriterion(ObjectNode json) {
Ray Milkeyfe447c52016-02-24 14:17:54 -0800111 JsonNode ethTypeNode = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE),
112 CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE);
andread35f89c2015-11-23 10:02:07 -0800113 int ethType;
Ray Milkeyfe447c52016-02-24 14:17:54 -0800114 if (ethTypeNode.isInt()) {
115 ethType = ethTypeNode.asInt();
andread35f89c2015-11-23 10:02:07 -0800116 } else {
Ray Milkeyfe447c52016-02-24 14:17:54 -0800117 ethType = Integer.decode(ethTypeNode.textValue());
andread35f89c2015-11-23 10:02:07 -0800118 }
Ray Milkeyd43fe452015-05-29 09:35:12 -0700119 return Criteria.matchEthType(ethType);
120 }
121 }
Ray Milkeyd43fe452015-05-29 09:35:12 -0700122 private class EthDstDecoder implements CriterionDecoder {
123 @Override
124 public Criterion decodeCriterion(ObjectNode json) {
125 MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC),
126 CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText());
127
128 return Criteria.matchEthDst(mac);
129 }
130 }
131
132 private class EthSrcDecoder implements CriterionDecoder {
133 @Override
134 public Criterion decodeCriterion(ObjectNode json) {
135 MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC),
136 CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText());
137
138 return Criteria.matchEthSrc(mac);
139 }
140 }
141
142 private class InPortDecoder implements CriterionDecoder {
143 @Override
144 public Criterion decodeCriterion(ObjectNode json) {
145 PortNumber port = PortNumber.portNumber(nullIsIllegal(json.get(CriterionCodec.PORT),
alshabibfa0dc662016-01-13 11:23:53 -0800146 CriterionCodec.PORT +
147 MISSING_MEMBER_MESSAGE).asLong());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700148
149 return Criteria.matchInPort(port);
150 }
151 }
152
153 private class InPhyPortDecoder implements CriterionDecoder {
154 @Override
155 public Criterion decodeCriterion(ObjectNode json) {
156 PortNumber port = PortNumber.portNumber(nullIsIllegal(json.get(CriterionCodec.PORT),
alshabibfa0dc662016-01-13 11:23:53 -0800157 CriterionCodec.PORT +
158 MISSING_MEMBER_MESSAGE).asLong());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700159
160 return Criteria.matchInPhyPort(port);
161 }
162 }
163
164 private class MetadataDecoder implements CriterionDecoder {
165 @Override
166 public Criterion decodeCriterion(ObjectNode json) {
167 long metadata = nullIsIllegal(json.get(CriterionCodec.METADATA),
168 CriterionCodec.METADATA + MISSING_MEMBER_MESSAGE).asLong();
169
170 return Criteria.matchMetadata(metadata);
171 }
172 }
173
174 private class VlanVidDecoder implements CriterionDecoder {
175 @Override
176 public Criterion decodeCriterion(ObjectNode json) {
177 short vlanId = (short) nullIsIllegal(json.get(CriterionCodec.VLAN_ID),
178 CriterionCodec.VLAN_ID + MISSING_MEMBER_MESSAGE).asInt();
179
180 return Criteria.matchVlanId(VlanId.vlanId(vlanId));
181 }
182 }
183
184 private class VlanPcpDecoder implements CriterionDecoder {
185 @Override
186 public Criterion decodeCriterion(ObjectNode json) {
187 byte priority = (byte) nullIsIllegal(json.get(CriterionCodec.PRIORITY),
alshabibfa0dc662016-01-13 11:23:53 -0800188 CriterionCodec.PRIORITY + MISSING_MEMBER_MESSAGE).asInt();
Ray Milkeyd43fe452015-05-29 09:35:12 -0700189
190 return Criteria.matchVlanPcp(priority);
191 }
192 }
193
alshabibfa0dc662016-01-13 11:23:53 -0800194 private class InnerVlanVidDecoder implements CriterionDecoder {
195 @Override
196 public Criterion decodeCriterion(ObjectNode json) {
197 short vlanId = (short) nullIsIllegal(json.get(CriterionCodec.INNER_VLAN_ID),
198 CriterionCodec.INNER_VLAN_ID +
199 MISSING_MEMBER_MESSAGE).asInt();
200
201 return Criteria.matchInnerVlanId(VlanId.vlanId(vlanId));
202 }
203 }
204
205 private class InnerVlanPcpDecoder implements CriterionDecoder {
206 @Override
207 public Criterion decodeCriterion(ObjectNode json) {
208 byte priority = (byte) nullIsIllegal(json.get(CriterionCodec.INNER_PRIORITY),
209 CriterionCodec.INNER_PRIORITY +
210 MISSING_MEMBER_MESSAGE).asInt();
211
212 return Criteria.matchInnerVlanPcp(priority);
213 }
214 }
215
Ray Milkeyd43fe452015-05-29 09:35:12 -0700216 private class IpDscpDecoder implements CriterionDecoder {
217 @Override
218 public Criterion decodeCriterion(ObjectNode json) {
219 byte ipDscp = (byte) nullIsIllegal(json.get(CriterionCodec.IP_DSCP),
220 CriterionCodec.IP_DSCP + MISSING_MEMBER_MESSAGE).asInt();
221 return Criteria.matchIPDscp(ipDscp);
222 }
223 }
224
225 private class IpEcnDecoder implements CriterionDecoder {
226 @Override
227 public Criterion decodeCriterion(ObjectNode json) {
228 byte ipEcn = (byte) nullIsIllegal(json.get(CriterionCodec.IP_ECN),
229 CriterionCodec.IP_ECN + MISSING_MEMBER_MESSAGE).asInt();
230 return Criteria.matchIPEcn(ipEcn);
231 }
232 }
233
234 private class IpProtoDecoder implements CriterionDecoder {
235 @Override
236 public Criterion decodeCriterion(ObjectNode json) {
237 short proto = (short) nullIsIllegal(json.get(CriterionCodec.PROTOCOL),
238 CriterionCodec.PROTOCOL + MISSING_MEMBER_MESSAGE).asInt();
239 return Criteria.matchIPProtocol(proto);
240 }
241 }
242
243 private class IpV4SrcDecoder implements CriterionDecoder {
244 @Override
245 public Criterion decodeCriterion(ObjectNode json) {
246 String ip = nullIsIllegal(json.get(CriterionCodec.IP),
247 CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText();
248 return Criteria.matchIPSrc(IpPrefix.valueOf(ip));
249 }
250 }
251
252 private class IpV4DstDecoder implements CriterionDecoder {
253 @Override
254 public Criterion decodeCriterion(ObjectNode json) {
255 String ip = nullIsIllegal(json.get(CriterionCodec.IP),
256 CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText();
257 return Criteria.matchIPDst(IpPrefix.valueOf(ip));
258 }
259 }
260
261 private class IpV6SrcDecoder implements CriterionDecoder {
262 @Override
263 public Criterion decodeCriterion(ObjectNode json) {
264 String ip = nullIsIllegal(json.get(CriterionCodec.IP),
265 CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText();
266 return Criteria.matchIPv6Src(IpPrefix.valueOf(ip));
267 }
268 }
269
270 private class IpV6DstDecoder implements CriterionDecoder {
271 @Override
272 public Criterion decodeCriterion(ObjectNode json) {
273 String ip = nullIsIllegal(json.get(CriterionCodec.IP),
274 CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText();
275 return Criteria.matchIPv6Dst(IpPrefix.valueOf(ip));
276 }
277 }
278
279 private class TcpSrcDecoder implements CriterionDecoder {
280 @Override
281 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700282 TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT),
283 CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700284 return Criteria.matchTcpSrc(tcpPort);
285 }
286 }
287
288 private class TcpDstDecoder implements CriterionDecoder {
289 @Override
290 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700291 TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT),
292 CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700293 return Criteria.matchTcpDst(tcpPort);
294 }
295 }
296
297 private class UdpSrcDecoder implements CriterionDecoder {
298 @Override
299 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700300 TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT),
301 CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700302 return Criteria.matchUdpSrc(udpPort);
303 }
304 }
305
306 private class UdpDstDecoder implements CriterionDecoder {
307 @Override
308 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700309 TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT),
310 CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700311 return Criteria.matchUdpDst(udpPort);
312 }
313 }
314
315 private class SctpSrcDecoder implements CriterionDecoder {
316 @Override
317 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700318 TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT),
319 CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700320 return Criteria.matchSctpSrc(sctpPort);
321 }
322 }
323
324 private class SctpDstDecoder implements CriterionDecoder {
325 @Override
326 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700327 TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT),
328 CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700329 return Criteria.matchSctpDst(sctpPort);
330 }
331 }
332
333 private class IcmpV4TypeDecoder implements CriterionDecoder {
334 @Override
335 public Criterion decodeCriterion(ObjectNode json) {
336 short type = (short) nullIsIllegal(json.get(CriterionCodec.ICMP_TYPE),
337 CriterionCodec.ICMP_TYPE + MISSING_MEMBER_MESSAGE).asInt();
338 return Criteria.matchIcmpType(type);
339 }
340 }
341
342 private class IcmpV4CodeDecoder implements CriterionDecoder {
343 @Override
344 public Criterion decodeCriterion(ObjectNode json) {
345 short code = (short) nullIsIllegal(json.get(CriterionCodec.ICMP_CODE),
346 CriterionCodec.ICMP_CODE + MISSING_MEMBER_MESSAGE).asInt();
347 return Criteria.matchIcmpCode(code);
348 }
349 }
350
351 private class IpV6FLabelDecoder implements CriterionDecoder {
352 @Override
353 public Criterion decodeCriterion(ObjectNode json) {
354 int flowLabel = nullIsIllegal(json.get(CriterionCodec.FLOW_LABEL),
355 CriterionCodec.FLOW_LABEL + MISSING_MEMBER_MESSAGE).asInt();
356 return Criteria.matchIPv6FlowLabel(flowLabel);
357 }
358 }
359
360 private class IcmpV6TypeDecoder implements CriterionDecoder {
361 @Override
362 public Criterion decodeCriterion(ObjectNode json) {
363 short type = (short) nullIsIllegal(json.get(CriterionCodec.ICMPV6_TYPE),
364 CriterionCodec.ICMPV6_TYPE + MISSING_MEMBER_MESSAGE).asInt();
365 return Criteria.matchIcmpv6Type(type);
366 }
367 }
368
369 private class IcmpV6CodeDecoder implements CriterionDecoder {
370 @Override
371 public Criterion decodeCriterion(ObjectNode json) {
372 short code = (short) nullIsIllegal(json.get(CriterionCodec.ICMPV6_CODE),
373 CriterionCodec.ICMPV6_CODE + MISSING_MEMBER_MESSAGE).asInt();
374 return Criteria.matchIcmpv6Code(code);
375 }
376 }
377
378 private class V6NDTargetDecoder implements CriterionDecoder {
379 @Override
380 public Criterion decodeCriterion(ObjectNode json) {
381 Ip6Address target = Ip6Address.valueOf(nullIsIllegal(json.get(CriterionCodec.TARGET_ADDRESS),
382 CriterionCodec.TARGET_ADDRESS + MISSING_MEMBER_MESSAGE).asText());
383 return Criteria.matchIPv6NDTargetAddress(target);
384 }
385 }
386
387 private class V6NDSllDecoder implements CriterionDecoder {
388 @Override
389 public Criterion decodeCriterion(ObjectNode json) {
390 MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC),
391 CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText());
392 return Criteria.matchIPv6NDSourceLinkLayerAddress(mac);
393 }
394 }
395
396 private class V6NDTllDecoder implements CriterionDecoder {
397 @Override
398 public Criterion decodeCriterion(ObjectNode json) {
399 MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC),
400 CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText());
401 return Criteria.matchIPv6NDTargetLinkLayerAddress(mac);
402 }
403 }
404
405 private class MplsLabelDecoder implements CriterionDecoder {
406 @Override
407 public Criterion decodeCriterion(ObjectNode json) {
408 int label = nullIsIllegal(json.get(CriterionCodec.LABEL),
409 CriterionCodec.LABEL + MISSING_MEMBER_MESSAGE).asInt();
410 return Criteria.matchMplsLabel(MplsLabel.mplsLabel(label));
411 }
412 }
413
Jonathan Hartcc962d82016-08-09 16:52:22 -0700414 private class MplsBosDecoder implements CriterionDecoder {
415 @Override
416 public Criterion decodeCriterion(ObjectNode json) {
417 boolean bos = nullIsIllegal(json.get(CriterionCodec.BOS),
418 CriterionCodec.BOS + MISSING_MEMBER_MESSAGE).asBoolean();
419 return Criteria.matchMplsBos(bos);
420 }
421 }
422
Ray Milkeyd43fe452015-05-29 09:35:12 -0700423 private class IpV6ExthdrDecoder implements CriterionDecoder {
424 @Override
425 public Criterion decodeCriterion(ObjectNode json) {
426 int exthdrFlags = nullIsIllegal(json.get(CriterionCodec.EXT_HDR_FLAGS),
427 CriterionCodec.EXT_HDR_FLAGS + MISSING_MEMBER_MESSAGE).asInt();
428 return Criteria.matchIPv6ExthdrFlags(exthdrFlags);
429 }
430 }
431
432 private class OchSigIdDecoder implements CriterionDecoder {
433 @Override
434 public Criterion decodeCriterion(ObjectNode json) {
Sho SHIMIZUcc137a92016-03-11 15:10:54 -0800435 JsonNode ochSignalId = nullIsIllegal(json.get(CriterionCodec.OCH_SIGNAL_ID),
436 CriterionCodec.GRID_TYPE + MISSING_MEMBER_MESSAGE);
437 GridType gridType =
438 GridType.valueOf(
439 nullIsIllegal(ochSignalId.get(CriterionCodec.GRID_TYPE),
440 CriterionCodec.GRID_TYPE + MISSING_MEMBER_MESSAGE).asText());
441 ChannelSpacing channelSpacing =
442 ChannelSpacing.valueOf(
443 nullIsIllegal(ochSignalId.get(CriterionCodec.CHANNEL_SPACING),
444 CriterionCodec.CHANNEL_SPACING + MISSING_MEMBER_MESSAGE).asText());
445 int spacingMultiplier = nullIsIllegal(ochSignalId.get(CriterionCodec.SPACING_MULIPLIER),
446 CriterionCodec.SPACING_MULIPLIER + MISSING_MEMBER_MESSAGE).asInt();
447 int slotGranularity = nullIsIllegal(ochSignalId.get(CriterionCodec.SLOT_GRANULARITY),
448 CriterionCodec.SLOT_GRANULARITY + MISSING_MEMBER_MESSAGE).asInt();
449 return Criteria.matchLambda(
450 Lambda.ochSignal(gridType, channelSpacing,
451 spacingMultiplier, slotGranularity));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700452 }
453 }
454
455 private class OchSigTypeDecoder implements CriterionDecoder {
456 @Override
457 public Criterion decodeCriterion(ObjectNode json) {
Yafit Hadar5796d972015-10-15 13:16:11 +0300458 OchSignalType ochSignalType = OchSignalType.valueOf(nullIsIllegal(json.get(CriterionCodec.OCH_SIGNAL_TYPE),
459 CriterionCodec.OCH_SIGNAL_TYPE + MISSING_MEMBER_MESSAGE).asText());
460 return Criteria.matchOchSignalType(ochSignalType);
Ray Milkeyd43fe452015-05-29 09:35:12 -0700461 }
462 }
463
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700464 private class TunnelIdDecoder implements CriterionDecoder {
465 @Override
466 public Criterion decodeCriterion(ObjectNode json) {
467 long tunnelId = nullIsIllegal(json.get(CriterionCodec.TUNNEL_ID),
468 CriterionCodec.TUNNEL_ID + MISSING_MEMBER_MESSAGE).asLong();
469 return Criteria.matchTunnelId(tunnelId);
470 }
471 }
472
Yafit Hadar5796d972015-10-15 13:16:11 +0300473 private class OduSigIdDecoder implements CriterionDecoder {
474 @Override
475 public Criterion decodeCriterion(ObjectNode json) {
476 JsonNode oduSignalId = nullIsIllegal(json.get(CriterionCodec.ODU_SIGNAL_ID),
477 CriterionCodec.TRIBUTARY_PORT_NUMBER + MISSING_MEMBER_MESSAGE);
478
479 int tributaryPortNumber = nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_PORT_NUMBER),
480 CriterionCodec.TRIBUTARY_PORT_NUMBER + MISSING_MEMBER_MESSAGE).asInt();
481 int tributarySlotLen = nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_SLOT_LEN),
482 CriterionCodec.TRIBUTARY_SLOT_LEN + MISSING_MEMBER_MESSAGE).asInt();
483 byte[] tributarySlotBitmap = HexString.fromHexString(
484 nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_SLOT_BITMAP),
485 CriterionCodec.TRIBUTARY_SLOT_BITMAP + MISSING_MEMBER_MESSAGE).asText());
486
487 return Criteria.matchOduSignalId(
488 OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap));
489 }
490 }
491
492 private class OduSigTypeDecoder implements CriterionDecoder {
493 @Override
494 public Criterion decodeCriterion(ObjectNode json) {
495 OduSignalType oduSignalType = OduSignalType.valueOf(nullIsIllegal(json.get(CriterionCodec.ODU_SIGNAL_TYPE),
496 CriterionCodec.ODU_SIGNAL_TYPE + MISSING_MEMBER_MESSAGE).asText());
497 return Criteria.matchOduSignalType(oduSignalType);
498 }
499 }
500
Ray Milkeyd43fe452015-05-29 09:35:12 -0700501 /**
502 * Decodes the JSON into a criterion object.
503 *
504 * @return Criterion object
505 * @throws IllegalArgumentException if the JSON is invalid
506 */
507 public Criterion decode() {
Ray Milkey52075062016-02-03 17:36:48 -0800508 String type =
509 nullIsIllegal(json.get(CriterionCodec.TYPE), "Type not specified")
510 .asText();
Ray Milkeyd43fe452015-05-29 09:35:12 -0700511
512 CriterionDecoder decoder = decoderMap.get(type);
513 if (decoder != null) {
514 return decoder.decodeCriterion(json);
515 }
516
517 throw new IllegalArgumentException("Type " + type + " is unknown");
518 }
519
520
521}