blob: 88cc3328ddc7a4fc357d54ae1195e5b9a7a5129b [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
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());
75 decoderMap.put(Criterion.Type.IP_DSCP.name(), new IpDscpDecoder());
76 decoderMap.put(Criterion.Type.IP_ECN.name(), new IpEcnDecoder());
77 decoderMap.put(Criterion.Type.IP_PROTO.name(), new IpProtoDecoder());
78 decoderMap.put(Criterion.Type.IPV4_SRC.name(), new IpV4SrcDecoder());
79 decoderMap.put(Criterion.Type.IPV4_DST.name(), new IpV4DstDecoder());
80 decoderMap.put(Criterion.Type.TCP_SRC.name(), new TcpSrcDecoder());
81 decoderMap.put(Criterion.Type.TCP_DST.name(), new TcpDstDecoder());
82 decoderMap.put(Criterion.Type.UDP_SRC.name(), new UdpSrcDecoder());
83 decoderMap.put(Criterion.Type.UDP_DST.name(), new UdpDstDecoder());
84 decoderMap.put(Criterion.Type.SCTP_SRC.name(), new SctpSrcDecoder());
85 decoderMap.put(Criterion.Type.SCTP_DST.name(), new SctpDstDecoder());
86 decoderMap.put(Criterion.Type.ICMPV4_TYPE.name(), new IcmpV4TypeDecoder());
87 decoderMap.put(Criterion.Type.ICMPV4_CODE.name(), new IcmpV4CodeDecoder());
88 decoderMap.put(Criterion.Type.IPV6_SRC.name(), new IpV6SrcDecoder());
89 decoderMap.put(Criterion.Type.IPV6_DST.name(), new IpV6DstDecoder());
90 decoderMap.put(Criterion.Type.IPV6_FLABEL.name(), new IpV6FLabelDecoder());
91 decoderMap.put(Criterion.Type.ICMPV6_TYPE.name(), new IcmpV6TypeDecoder());
92 decoderMap.put(Criterion.Type.ICMPV6_CODE.name(), new IcmpV6CodeDecoder());
93 decoderMap.put(Criterion.Type.IPV6_ND_TARGET.name(), new V6NDTargetDecoder());
94 decoderMap.put(Criterion.Type.IPV6_ND_SLL.name(), new V6NDSllDecoder());
95 decoderMap.put(Criterion.Type.IPV6_ND_TLL.name(), new V6NDTllDecoder());
96 decoderMap.put(Criterion.Type.MPLS_LABEL.name(), new MplsLabelDecoder());
97 decoderMap.put(Criterion.Type.IPV6_EXTHDR.name(), new IpV6ExthdrDecoder());
98 decoderMap.put(Criterion.Type.OCH_SIGID.name(), new OchSigIdDecoder());
99 decoderMap.put(Criterion.Type.OCH_SIGTYPE.name(), new OchSigTypeDecoder());
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700100 decoderMap.put(Criterion.Type.TUNNEL_ID.name(), new TunnelIdDecoder());
Yafit Hadar5796d972015-10-15 13:16:11 +0300101 decoderMap.put(Criterion.Type.ODU_SIGID.name(), new OduSigIdDecoder());
102 decoderMap.put(Criterion.Type.ODU_SIGTYPE.name(), new OduSigTypeDecoder());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700103 }
104
105 private class EthTypeDecoder implements CriterionDecoder {
106 @Override
107 public Criterion decodeCriterion(ObjectNode json) {
andread35f89c2015-11-23 10:02:07 -0800108 int ethType;
109 if (json.get(CriterionCodec.ETH_TYPE).isInt()) {
110 ethType = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE),
111 CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE).asInt();
112 } else {
113 ethType = Integer.decode(json.get(CriterionCodec.ETH_TYPE).textValue());
114 }
Ray Milkeyd43fe452015-05-29 09:35:12 -0700115 return Criteria.matchEthType(ethType);
116 }
117 }
Ray Milkeyd43fe452015-05-29 09:35:12 -0700118 private class EthDstDecoder implements CriterionDecoder {
119 @Override
120 public Criterion decodeCriterion(ObjectNode json) {
121 MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC),
122 CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText());
123
124 return Criteria.matchEthDst(mac);
125 }
126 }
127
128 private class EthSrcDecoder implements CriterionDecoder {
129 @Override
130 public Criterion decodeCriterion(ObjectNode json) {
131 MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC),
132 CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText());
133
134 return Criteria.matchEthSrc(mac);
135 }
136 }
137
138 private class InPortDecoder implements CriterionDecoder {
139 @Override
140 public Criterion decodeCriterion(ObjectNode json) {
141 PortNumber port = PortNumber.portNumber(nullIsIllegal(json.get(CriterionCodec.PORT),
142 CriterionCodec.PORT + MISSING_MEMBER_MESSAGE).asLong());
143
144 return Criteria.matchInPort(port);
145 }
146 }
147
148 private class InPhyPortDecoder implements CriterionDecoder {
149 @Override
150 public Criterion decodeCriterion(ObjectNode json) {
151 PortNumber port = PortNumber.portNumber(nullIsIllegal(json.get(CriterionCodec.PORT),
152 CriterionCodec.PORT + MISSING_MEMBER_MESSAGE).asLong());
153
154 return Criteria.matchInPhyPort(port);
155 }
156 }
157
158 private class MetadataDecoder implements CriterionDecoder {
159 @Override
160 public Criterion decodeCriterion(ObjectNode json) {
161 long metadata = nullIsIllegal(json.get(CriterionCodec.METADATA),
162 CriterionCodec.METADATA + MISSING_MEMBER_MESSAGE).asLong();
163
164 return Criteria.matchMetadata(metadata);
165 }
166 }
167
168 private class VlanVidDecoder implements CriterionDecoder {
169 @Override
170 public Criterion decodeCriterion(ObjectNode json) {
171 short vlanId = (short) nullIsIllegal(json.get(CriterionCodec.VLAN_ID),
172 CriterionCodec.VLAN_ID + MISSING_MEMBER_MESSAGE).asInt();
173
174 return Criteria.matchVlanId(VlanId.vlanId(vlanId));
175 }
176 }
177
178 private class VlanPcpDecoder implements CriterionDecoder {
179 @Override
180 public Criterion decodeCriterion(ObjectNode json) {
181 byte priority = (byte) nullIsIllegal(json.get(CriterionCodec.PRIORITY),
182 CriterionCodec.VLAN_ID + MISSING_MEMBER_MESSAGE).asInt();
183
184 return Criteria.matchVlanPcp(priority);
185 }
186 }
187
188 private class IpDscpDecoder implements CriterionDecoder {
189 @Override
190 public Criterion decodeCriterion(ObjectNode json) {
191 byte ipDscp = (byte) nullIsIllegal(json.get(CriterionCodec.IP_DSCP),
192 CriterionCodec.IP_DSCP + MISSING_MEMBER_MESSAGE).asInt();
193 return Criteria.matchIPDscp(ipDscp);
194 }
195 }
196
197 private class IpEcnDecoder implements CriterionDecoder {
198 @Override
199 public Criterion decodeCriterion(ObjectNode json) {
200 byte ipEcn = (byte) nullIsIllegal(json.get(CriterionCodec.IP_ECN),
201 CriterionCodec.IP_ECN + MISSING_MEMBER_MESSAGE).asInt();
202 return Criteria.matchIPEcn(ipEcn);
203 }
204 }
205
206 private class IpProtoDecoder implements CriterionDecoder {
207 @Override
208 public Criterion decodeCriterion(ObjectNode json) {
209 short proto = (short) nullIsIllegal(json.get(CriterionCodec.PROTOCOL),
210 CriterionCodec.PROTOCOL + MISSING_MEMBER_MESSAGE).asInt();
211 return Criteria.matchIPProtocol(proto);
212 }
213 }
214
215 private class IpV4SrcDecoder implements CriterionDecoder {
216 @Override
217 public Criterion decodeCriterion(ObjectNode json) {
218 String ip = nullIsIllegal(json.get(CriterionCodec.IP),
219 CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText();
220 return Criteria.matchIPSrc(IpPrefix.valueOf(ip));
221 }
222 }
223
224 private class IpV4DstDecoder implements CriterionDecoder {
225 @Override
226 public Criterion decodeCriterion(ObjectNode json) {
227 String ip = nullIsIllegal(json.get(CriterionCodec.IP),
228 CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText();
229 return Criteria.matchIPDst(IpPrefix.valueOf(ip));
230 }
231 }
232
233 private class IpV6SrcDecoder implements CriterionDecoder {
234 @Override
235 public Criterion decodeCriterion(ObjectNode json) {
236 String ip = nullIsIllegal(json.get(CriterionCodec.IP),
237 CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText();
238 return Criteria.matchIPv6Src(IpPrefix.valueOf(ip));
239 }
240 }
241
242 private class IpV6DstDecoder implements CriterionDecoder {
243 @Override
244 public Criterion decodeCriterion(ObjectNode json) {
245 String ip = nullIsIllegal(json.get(CriterionCodec.IP),
246 CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText();
247 return Criteria.matchIPv6Dst(IpPrefix.valueOf(ip));
248 }
249 }
250
251 private class TcpSrcDecoder implements CriterionDecoder {
252 @Override
253 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700254 TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT),
255 CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700256 return Criteria.matchTcpSrc(tcpPort);
257 }
258 }
259
260 private class TcpDstDecoder implements CriterionDecoder {
261 @Override
262 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700263 TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT),
264 CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700265 return Criteria.matchTcpDst(tcpPort);
266 }
267 }
268
269 private class UdpSrcDecoder implements CriterionDecoder {
270 @Override
271 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700272 TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT),
273 CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700274 return Criteria.matchUdpSrc(udpPort);
275 }
276 }
277
278 private class UdpDstDecoder implements CriterionDecoder {
279 @Override
280 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700281 TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT),
282 CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700283 return Criteria.matchUdpDst(udpPort);
284 }
285 }
286
287 private class SctpSrcDecoder implements CriterionDecoder {
288 @Override
289 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700290 TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT),
291 CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700292 return Criteria.matchSctpSrc(sctpPort);
293 }
294 }
295
296 private class SctpDstDecoder implements CriterionDecoder {
297 @Override
298 public Criterion decodeCriterion(ObjectNode json) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700299 TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT),
300 CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700301 return Criteria.matchSctpDst(sctpPort);
302 }
303 }
304
305 private class IcmpV4TypeDecoder implements CriterionDecoder {
306 @Override
307 public Criterion decodeCriterion(ObjectNode json) {
308 short type = (short) nullIsIllegal(json.get(CriterionCodec.ICMP_TYPE),
309 CriterionCodec.ICMP_TYPE + MISSING_MEMBER_MESSAGE).asInt();
310 return Criteria.matchIcmpType(type);
311 }
312 }
313
314 private class IcmpV4CodeDecoder implements CriterionDecoder {
315 @Override
316 public Criterion decodeCriterion(ObjectNode json) {
317 short code = (short) nullIsIllegal(json.get(CriterionCodec.ICMP_CODE),
318 CriterionCodec.ICMP_CODE + MISSING_MEMBER_MESSAGE).asInt();
319 return Criteria.matchIcmpCode(code);
320 }
321 }
322
323 private class IpV6FLabelDecoder implements CriterionDecoder {
324 @Override
325 public Criterion decodeCriterion(ObjectNode json) {
326 int flowLabel = nullIsIllegal(json.get(CriterionCodec.FLOW_LABEL),
327 CriterionCodec.FLOW_LABEL + MISSING_MEMBER_MESSAGE).asInt();
328 return Criteria.matchIPv6FlowLabel(flowLabel);
329 }
330 }
331
332 private class IcmpV6TypeDecoder implements CriterionDecoder {
333 @Override
334 public Criterion decodeCriterion(ObjectNode json) {
335 short type = (short) nullIsIllegal(json.get(CriterionCodec.ICMPV6_TYPE),
336 CriterionCodec.ICMPV6_TYPE + MISSING_MEMBER_MESSAGE).asInt();
337 return Criteria.matchIcmpv6Type(type);
338 }
339 }
340
341 private class IcmpV6CodeDecoder implements CriterionDecoder {
342 @Override
343 public Criterion decodeCriterion(ObjectNode json) {
344 short code = (short) nullIsIllegal(json.get(CriterionCodec.ICMPV6_CODE),
345 CriterionCodec.ICMPV6_CODE + MISSING_MEMBER_MESSAGE).asInt();
346 return Criteria.matchIcmpv6Code(code);
347 }
348 }
349
350 private class V6NDTargetDecoder implements CriterionDecoder {
351 @Override
352 public Criterion decodeCriterion(ObjectNode json) {
353 Ip6Address target = Ip6Address.valueOf(nullIsIllegal(json.get(CriterionCodec.TARGET_ADDRESS),
354 CriterionCodec.TARGET_ADDRESS + MISSING_MEMBER_MESSAGE).asText());
355 return Criteria.matchIPv6NDTargetAddress(target);
356 }
357 }
358
359 private class V6NDSllDecoder implements CriterionDecoder {
360 @Override
361 public Criterion decodeCriterion(ObjectNode json) {
362 MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC),
363 CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText());
364 return Criteria.matchIPv6NDSourceLinkLayerAddress(mac);
365 }
366 }
367
368 private class V6NDTllDecoder implements CriterionDecoder {
369 @Override
370 public Criterion decodeCriterion(ObjectNode json) {
371 MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC),
372 CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText());
373 return Criteria.matchIPv6NDTargetLinkLayerAddress(mac);
374 }
375 }
376
377 private class MplsLabelDecoder implements CriterionDecoder {
378 @Override
379 public Criterion decodeCriterion(ObjectNode json) {
380 int label = nullIsIllegal(json.get(CriterionCodec.LABEL),
381 CriterionCodec.LABEL + MISSING_MEMBER_MESSAGE).asInt();
382 return Criteria.matchMplsLabel(MplsLabel.mplsLabel(label));
383 }
384 }
385
386 private class IpV6ExthdrDecoder implements CriterionDecoder {
387 @Override
388 public Criterion decodeCriterion(ObjectNode json) {
389 int exthdrFlags = nullIsIllegal(json.get(CriterionCodec.EXT_HDR_FLAGS),
390 CriterionCodec.EXT_HDR_FLAGS + MISSING_MEMBER_MESSAGE).asInt();
391 return Criteria.matchIPv6ExthdrFlags(exthdrFlags);
392 }
393 }
394
395 private class OchSigIdDecoder implements CriterionDecoder {
396 @Override
397 public Criterion decodeCriterion(ObjectNode json) {
398 if (json.get(CriterionCodec.LAMBDA) != null) {
399 Lambda lambda = Lambda.indexedLambda(nullIsIllegal(json.get(CriterionCodec.LAMBDA),
400 CriterionCodec.LAMBDA + MISSING_MEMBER_MESSAGE).asInt());
401 return Criteria.matchLambda(lambda);
402 } else {
403 JsonNode ochSignalId = nullIsIllegal(json.get(CriterionCodec.OCH_SIGNAL_ID),
404 CriterionCodec.GRID_TYPE + MISSING_MEMBER_MESSAGE);
405 GridType gridType =
406 GridType.valueOf(
407 nullIsIllegal(ochSignalId.get(CriterionCodec.GRID_TYPE),
408 CriterionCodec.GRID_TYPE + MISSING_MEMBER_MESSAGE).asText());
409 ChannelSpacing channelSpacing =
410 ChannelSpacing.valueOf(
411 nullIsIllegal(ochSignalId.get(CriterionCodec.CHANNEL_SPACING),
412 CriterionCodec.CHANNEL_SPACING + MISSING_MEMBER_MESSAGE).asText());
413 int spacingMultiplier = nullIsIllegal(ochSignalId.get(CriterionCodec.SPACING_MULIPLIER),
414 CriterionCodec.SPACING_MULIPLIER + MISSING_MEMBER_MESSAGE).asInt();
415 int slotGranularity = nullIsIllegal(ochSignalId.get(CriterionCodec.SLOT_GRANULARITY),
416 CriterionCodec.SLOT_GRANULARITY + MISSING_MEMBER_MESSAGE).asInt();
417 return Criteria.matchLambda(
418 Lambda.ochSignal(gridType, channelSpacing,
419 spacingMultiplier, slotGranularity));
420 }
421 }
422 }
423
424 private class OchSigTypeDecoder implements CriterionDecoder {
425 @Override
426 public Criterion decodeCriterion(ObjectNode json) {
Yafit Hadar5796d972015-10-15 13:16:11 +0300427 OchSignalType ochSignalType = OchSignalType.valueOf(nullIsIllegal(json.get(CriterionCodec.OCH_SIGNAL_TYPE),
428 CriterionCodec.OCH_SIGNAL_TYPE + MISSING_MEMBER_MESSAGE).asText());
429 return Criteria.matchOchSignalType(ochSignalType);
Ray Milkeyd43fe452015-05-29 09:35:12 -0700430 }
431 }
432
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700433 private class TunnelIdDecoder implements CriterionDecoder {
434 @Override
435 public Criterion decodeCriterion(ObjectNode json) {
436 long tunnelId = nullIsIllegal(json.get(CriterionCodec.TUNNEL_ID),
437 CriterionCodec.TUNNEL_ID + MISSING_MEMBER_MESSAGE).asLong();
438 return Criteria.matchTunnelId(tunnelId);
439 }
440 }
441
Yafit Hadar5796d972015-10-15 13:16:11 +0300442 private class OduSigIdDecoder implements CriterionDecoder {
443 @Override
444 public Criterion decodeCriterion(ObjectNode json) {
445 JsonNode oduSignalId = nullIsIllegal(json.get(CriterionCodec.ODU_SIGNAL_ID),
446 CriterionCodec.TRIBUTARY_PORT_NUMBER + MISSING_MEMBER_MESSAGE);
447
448 int tributaryPortNumber = nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_PORT_NUMBER),
449 CriterionCodec.TRIBUTARY_PORT_NUMBER + MISSING_MEMBER_MESSAGE).asInt();
450 int tributarySlotLen = nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_SLOT_LEN),
451 CriterionCodec.TRIBUTARY_SLOT_LEN + MISSING_MEMBER_MESSAGE).asInt();
452 byte[] tributarySlotBitmap = HexString.fromHexString(
453 nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_SLOT_BITMAP),
454 CriterionCodec.TRIBUTARY_SLOT_BITMAP + MISSING_MEMBER_MESSAGE).asText());
455
456 return Criteria.matchOduSignalId(
457 OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap));
458 }
459 }
460
461 private class OduSigTypeDecoder implements CriterionDecoder {
462 @Override
463 public Criterion decodeCriterion(ObjectNode json) {
464 OduSignalType oduSignalType = OduSignalType.valueOf(nullIsIllegal(json.get(CriterionCodec.ODU_SIGNAL_TYPE),
465 CriterionCodec.ODU_SIGNAL_TYPE + MISSING_MEMBER_MESSAGE).asText());
466 return Criteria.matchOduSignalType(oduSignalType);
467 }
468 }
469
Ray Milkeyd43fe452015-05-29 09:35:12 -0700470 /**
471 * Decodes the JSON into a criterion object.
472 *
473 * @return Criterion object
474 * @throws IllegalArgumentException if the JSON is invalid
475 */
476 public Criterion decode() {
477 String type = json.get(CriterionCodec.TYPE).asText();
478
479 CriterionDecoder decoder = decoderMap.get(type);
480 if (decoder != null) {
481 return decoder.decodeCriterion(json);
482 }
483
484 throw new IllegalArgumentException("Type " + type + " is unknown");
485 }
486
487
488}