Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.codec.impl; |
| 17 | |
andrea | d35f89c | 2015-11-23 10:02:07 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 20 | import org.onlab.packet.Ip6Address; |
| 21 | import org.onlab.packet.IpPrefix; |
| 22 | import org.onlab.packet.MacAddress; |
| 23 | import org.onlab.packet.MplsLabel; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 24 | import org.onlab.packet.TpPort; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 25 | import org.onlab.packet.VlanId; |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 26 | import org.onlab.util.HexString; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 27 | import org.onosproject.net.ChannelSpacing; |
| 28 | import org.onosproject.net.GridType; |
| 29 | import org.onosproject.net.Lambda; |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 30 | import org.onosproject.net.OchSignalType; |
| 31 | import org.onosproject.net.OduSignalId; |
| 32 | import org.onosproject.net.OduSignalType; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 33 | import org.onosproject.net.PortNumber; |
| 34 | import org.onosproject.net.flow.criteria.Criteria; |
| 35 | import org.onosproject.net.flow.criteria.Criterion; |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 36 | import org.onosproject.net.flow.criteria.PiCriterion; |
| 37 | import org.onosproject.net.pi.model.PiMatchFieldId; |
| 38 | import org.onosproject.net.pi.model.PiMatchType; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 39 | |
andrea | d35f89c | 2015-11-23 10:02:07 -0800 | [diff] [blame] | 40 | import java.util.HashMap; |
| 41 | import java.util.Map; |
| 42 | |
| 43 | import static org.onlab.util.Tools.nullIsIllegal; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 44 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 45 | /** |
| 46 | * Decode portion of the criterion codec. |
| 47 | */ |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 48 | public final class DecodeCriterionCodecHelper { |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 49 | |
| 50 | private final ObjectNode json; |
| 51 | |
| 52 | protected static final String MISSING_MEMBER_MESSAGE = |
| 53 | " member is required in Criterion"; |
| 54 | |
| 55 | private interface CriterionDecoder { |
| 56 | Criterion decodeCriterion(ObjectNode json); |
| 57 | } |
| 58 | private final Map<String, CriterionDecoder> decoderMap; |
| 59 | |
| 60 | /** |
| 61 | * Creates a decode criterion codec object. |
| 62 | * Initializes the lookup map for criterion subclass decoders. |
| 63 | * |
| 64 | * @param json JSON object to decode |
| 65 | */ |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 66 | public DecodeCriterionCodecHelper(ObjectNode json) { |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 67 | this.json = json; |
| 68 | decoderMap = new HashMap<>(); |
| 69 | |
| 70 | decoderMap.put(Criterion.Type.IN_PORT.name(), new InPortDecoder()); |
| 71 | decoderMap.put(Criterion.Type.IN_PHY_PORT.name(), new InPhyPortDecoder()); |
| 72 | decoderMap.put(Criterion.Type.METADATA.name(), new MetadataDecoder()); |
| 73 | decoderMap.put(Criterion.Type.ETH_DST.name(), new EthDstDecoder()); |
| 74 | decoderMap.put(Criterion.Type.ETH_SRC.name(), new EthSrcDecoder()); |
| 75 | decoderMap.put(Criterion.Type.ETH_TYPE.name(), new EthTypeDecoder()); |
| 76 | decoderMap.put(Criterion.Type.VLAN_VID.name(), new VlanVidDecoder()); |
| 77 | decoderMap.put(Criterion.Type.VLAN_PCP.name(), new VlanPcpDecoder()); |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 78 | decoderMap.put(Criterion.Type.INNER_VLAN_VID.name(), new InnerVlanVidDecoder()); |
| 79 | decoderMap.put(Criterion.Type.INNER_VLAN_PCP.name(), new InnerVlanPcpDecoder()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 80 | decoderMap.put(Criterion.Type.IP_DSCP.name(), new IpDscpDecoder()); |
| 81 | decoderMap.put(Criterion.Type.IP_ECN.name(), new IpEcnDecoder()); |
| 82 | decoderMap.put(Criterion.Type.IP_PROTO.name(), new IpProtoDecoder()); |
| 83 | decoderMap.put(Criterion.Type.IPV4_SRC.name(), new IpV4SrcDecoder()); |
| 84 | decoderMap.put(Criterion.Type.IPV4_DST.name(), new IpV4DstDecoder()); |
| 85 | decoderMap.put(Criterion.Type.TCP_SRC.name(), new TcpSrcDecoder()); |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 86 | decoderMap.put(Criterion.Type.TCP_SRC_MASKED.name(), new TcpSrcMaskDecoder()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 87 | decoderMap.put(Criterion.Type.TCP_DST.name(), new TcpDstDecoder()); |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 88 | decoderMap.put(Criterion.Type.TCP_DST_MASKED.name(), new TcpDstMaskDecoder()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 89 | decoderMap.put(Criterion.Type.UDP_SRC.name(), new UdpSrcDecoder()); |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 90 | decoderMap.put(Criterion.Type.UDP_SRC_MASKED.name(), new UdpSrcMaskDecoder()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 91 | decoderMap.put(Criterion.Type.UDP_DST.name(), new UdpDstDecoder()); |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 92 | decoderMap.put(Criterion.Type.UDP_DST_MASKED.name(), new UdpDstMaskDecoder()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 93 | decoderMap.put(Criterion.Type.SCTP_SRC.name(), new SctpSrcDecoder()); |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 94 | decoderMap.put(Criterion.Type.SCTP_SRC_MASKED.name(), new SctpSrcMaskDecoder()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 95 | decoderMap.put(Criterion.Type.SCTP_DST.name(), new SctpDstDecoder()); |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 96 | decoderMap.put(Criterion.Type.SCTP_DST_MASKED.name(), new SctpDstMaskDecoder()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 97 | decoderMap.put(Criterion.Type.ICMPV4_TYPE.name(), new IcmpV4TypeDecoder()); |
| 98 | decoderMap.put(Criterion.Type.ICMPV4_CODE.name(), new IcmpV4CodeDecoder()); |
| 99 | decoderMap.put(Criterion.Type.IPV6_SRC.name(), new IpV6SrcDecoder()); |
| 100 | decoderMap.put(Criterion.Type.IPV6_DST.name(), new IpV6DstDecoder()); |
| 101 | decoderMap.put(Criterion.Type.IPV6_FLABEL.name(), new IpV6FLabelDecoder()); |
| 102 | decoderMap.put(Criterion.Type.ICMPV6_TYPE.name(), new IcmpV6TypeDecoder()); |
| 103 | decoderMap.put(Criterion.Type.ICMPV6_CODE.name(), new IcmpV6CodeDecoder()); |
| 104 | decoderMap.put(Criterion.Type.IPV6_ND_TARGET.name(), new V6NDTargetDecoder()); |
| 105 | decoderMap.put(Criterion.Type.IPV6_ND_SLL.name(), new V6NDSllDecoder()); |
| 106 | decoderMap.put(Criterion.Type.IPV6_ND_TLL.name(), new V6NDTllDecoder()); |
| 107 | decoderMap.put(Criterion.Type.MPLS_LABEL.name(), new MplsLabelDecoder()); |
Jonathan Hart | cc962d8 | 2016-08-09 16:52:22 -0700 | [diff] [blame] | 108 | decoderMap.put(Criterion.Type.MPLS_BOS.name(), new MplsBosDecoder()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 109 | decoderMap.put(Criterion.Type.IPV6_EXTHDR.name(), new IpV6ExthdrDecoder()); |
| 110 | decoderMap.put(Criterion.Type.OCH_SIGID.name(), new OchSigIdDecoder()); |
| 111 | decoderMap.put(Criterion.Type.OCH_SIGTYPE.name(), new OchSigTypeDecoder()); |
Hyunsun Moon | 7080a0d | 2015-08-14 19:18:48 -0700 | [diff] [blame] | 112 | decoderMap.put(Criterion.Type.TUNNEL_ID.name(), new TunnelIdDecoder()); |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 113 | decoderMap.put(Criterion.Type.ODU_SIGID.name(), new OduSigIdDecoder()); |
| 114 | decoderMap.put(Criterion.Type.ODU_SIGTYPE.name(), new OduSigTypeDecoder()); |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 115 | decoderMap.put(Criterion.Type.PROTOCOL_INDEPENDENT.name(), new PiDecoder()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | private class EthTypeDecoder implements CriterionDecoder { |
| 119 | @Override |
| 120 | public Criterion decodeCriterion(ObjectNode json) { |
Ray Milkey | fe447c5 | 2016-02-24 14:17:54 -0800 | [diff] [blame] | 121 | JsonNode ethTypeNode = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE), |
| 122 | CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE); |
andrea | d35f89c | 2015-11-23 10:02:07 -0800 | [diff] [blame] | 123 | int ethType; |
Ray Milkey | fe447c5 | 2016-02-24 14:17:54 -0800 | [diff] [blame] | 124 | if (ethTypeNode.isInt()) { |
| 125 | ethType = ethTypeNode.asInt(); |
andrea | d35f89c | 2015-11-23 10:02:07 -0800 | [diff] [blame] | 126 | } else { |
Ray Milkey | fe447c5 | 2016-02-24 14:17:54 -0800 | [diff] [blame] | 127 | ethType = Integer.decode(ethTypeNode.textValue()); |
andrea | d35f89c | 2015-11-23 10:02:07 -0800 | [diff] [blame] | 128 | } |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 129 | return Criteria.matchEthType(ethType); |
| 130 | } |
| 131 | } |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 132 | private class EthDstDecoder 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.matchEthDst(mac); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | private class EthSrcDecoder implements CriterionDecoder { |
| 143 | @Override |
| 144 | public Criterion decodeCriterion(ObjectNode json) { |
| 145 | MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC), |
| 146 | CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText()); |
| 147 | |
| 148 | return Criteria.matchEthSrc(mac); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | private class InPortDecoder implements CriterionDecoder { |
| 153 | @Override |
| 154 | public Criterion decodeCriterion(ObjectNode json) { |
| 155 | PortNumber port = PortNumber.portNumber(nullIsIllegal(json.get(CriterionCodec.PORT), |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 156 | CriterionCodec.PORT + |
| 157 | MISSING_MEMBER_MESSAGE).asLong()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 158 | |
| 159 | return Criteria.matchInPort(port); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | private class InPhyPortDecoder implements CriterionDecoder { |
| 164 | @Override |
| 165 | public Criterion decodeCriterion(ObjectNode json) { |
| 166 | PortNumber port = PortNumber.portNumber(nullIsIllegal(json.get(CriterionCodec.PORT), |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 167 | CriterionCodec.PORT + |
| 168 | MISSING_MEMBER_MESSAGE).asLong()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 169 | |
| 170 | return Criteria.matchInPhyPort(port); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | private class MetadataDecoder implements CriterionDecoder { |
| 175 | @Override |
| 176 | public Criterion decodeCriterion(ObjectNode json) { |
| 177 | long metadata = nullIsIllegal(json.get(CriterionCodec.METADATA), |
| 178 | CriterionCodec.METADATA + MISSING_MEMBER_MESSAGE).asLong(); |
| 179 | |
| 180 | return Criteria.matchMetadata(metadata); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | private class VlanVidDecoder implements CriterionDecoder { |
| 185 | @Override |
| 186 | public Criterion decodeCriterion(ObjectNode json) { |
| 187 | short vlanId = (short) nullIsIllegal(json.get(CriterionCodec.VLAN_ID), |
| 188 | CriterionCodec.VLAN_ID + MISSING_MEMBER_MESSAGE).asInt(); |
| 189 | |
| 190 | return Criteria.matchVlanId(VlanId.vlanId(vlanId)); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | private class VlanPcpDecoder implements CriterionDecoder { |
| 195 | @Override |
| 196 | public Criterion decodeCriterion(ObjectNode json) { |
| 197 | byte priority = (byte) nullIsIllegal(json.get(CriterionCodec.PRIORITY), |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 198 | CriterionCodec.PRIORITY + MISSING_MEMBER_MESSAGE).asInt(); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 199 | |
| 200 | return Criteria.matchVlanPcp(priority); |
| 201 | } |
| 202 | } |
| 203 | |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 204 | private class InnerVlanVidDecoder implements CriterionDecoder { |
| 205 | @Override |
| 206 | public Criterion decodeCriterion(ObjectNode json) { |
| 207 | short vlanId = (short) nullIsIllegal(json.get(CriterionCodec.INNER_VLAN_ID), |
| 208 | CriterionCodec.INNER_VLAN_ID + |
| 209 | MISSING_MEMBER_MESSAGE).asInt(); |
| 210 | |
| 211 | return Criteria.matchInnerVlanId(VlanId.vlanId(vlanId)); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | private class InnerVlanPcpDecoder implements CriterionDecoder { |
| 216 | @Override |
| 217 | public Criterion decodeCriterion(ObjectNode json) { |
| 218 | byte priority = (byte) nullIsIllegal(json.get(CriterionCodec.INNER_PRIORITY), |
| 219 | CriterionCodec.INNER_PRIORITY + |
| 220 | MISSING_MEMBER_MESSAGE).asInt(); |
| 221 | |
| 222 | return Criteria.matchInnerVlanPcp(priority); |
| 223 | } |
| 224 | } |
| 225 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 226 | private class IpDscpDecoder implements CriterionDecoder { |
| 227 | @Override |
| 228 | public Criterion decodeCriterion(ObjectNode json) { |
| 229 | byte ipDscp = (byte) nullIsIllegal(json.get(CriterionCodec.IP_DSCP), |
| 230 | CriterionCodec.IP_DSCP + MISSING_MEMBER_MESSAGE).asInt(); |
| 231 | return Criteria.matchIPDscp(ipDscp); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | private class IpEcnDecoder implements CriterionDecoder { |
| 236 | @Override |
| 237 | public Criterion decodeCriterion(ObjectNode json) { |
| 238 | byte ipEcn = (byte) nullIsIllegal(json.get(CriterionCodec.IP_ECN), |
| 239 | CriterionCodec.IP_ECN + MISSING_MEMBER_MESSAGE).asInt(); |
| 240 | return Criteria.matchIPEcn(ipEcn); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | private class IpProtoDecoder implements CriterionDecoder { |
| 245 | @Override |
| 246 | public Criterion decodeCriterion(ObjectNode json) { |
| 247 | short proto = (short) nullIsIllegal(json.get(CriterionCodec.PROTOCOL), |
| 248 | CriterionCodec.PROTOCOL + MISSING_MEMBER_MESSAGE).asInt(); |
| 249 | return Criteria.matchIPProtocol(proto); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | private class IpV4SrcDecoder implements CriterionDecoder { |
| 254 | @Override |
| 255 | public Criterion decodeCriterion(ObjectNode json) { |
| 256 | String ip = nullIsIllegal(json.get(CriterionCodec.IP), |
| 257 | CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText(); |
| 258 | return Criteria.matchIPSrc(IpPrefix.valueOf(ip)); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | private class IpV4DstDecoder implements CriterionDecoder { |
| 263 | @Override |
| 264 | public Criterion decodeCriterion(ObjectNode json) { |
| 265 | String ip = nullIsIllegal(json.get(CriterionCodec.IP), |
| 266 | CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText(); |
| 267 | return Criteria.matchIPDst(IpPrefix.valueOf(ip)); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | private class IpV6SrcDecoder implements CriterionDecoder { |
| 272 | @Override |
| 273 | public Criterion decodeCriterion(ObjectNode json) { |
| 274 | String ip = nullIsIllegal(json.get(CriterionCodec.IP), |
| 275 | CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText(); |
| 276 | return Criteria.matchIPv6Src(IpPrefix.valueOf(ip)); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | private class IpV6DstDecoder implements CriterionDecoder { |
| 281 | @Override |
| 282 | public Criterion decodeCriterion(ObjectNode json) { |
| 283 | String ip = nullIsIllegal(json.get(CriterionCodec.IP), |
| 284 | CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText(); |
| 285 | return Criteria.matchIPv6Dst(IpPrefix.valueOf(ip)); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | private class TcpSrcDecoder implements CriterionDecoder { |
| 290 | @Override |
| 291 | public Criterion decodeCriterion(ObjectNode json) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 292 | TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT), |
| 293 | CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 294 | return Criteria.matchTcpSrc(tcpPort); |
| 295 | } |
| 296 | } |
| 297 | |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 298 | private class TcpSrcMaskDecoder implements CriterionDecoder { |
| 299 | @Override |
| 300 | public Criterion decodeCriterion(ObjectNode json) { |
| 301 | TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT), |
| 302 | CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
| 303 | |
| 304 | TpPort tcpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_MASK), |
| 305 | CriterionCodec.TCP_MASK + MISSING_MEMBER_MESSAGE).asInt()); |
| 306 | |
| 307 | return Criteria.matchTcpSrcMasked(tcpPort, tcpMask); |
| 308 | } |
| 309 | } |
| 310 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 311 | private class TcpDstDecoder implements CriterionDecoder { |
| 312 | @Override |
| 313 | public Criterion decodeCriterion(ObjectNode json) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 314 | TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT), |
| 315 | CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 316 | return Criteria.matchTcpDst(tcpPort); |
| 317 | } |
| 318 | } |
| 319 | |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 320 | private class TcpDstMaskDecoder implements CriterionDecoder { |
| 321 | @Override |
| 322 | public Criterion decodeCriterion(ObjectNode json) { |
| 323 | TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT), |
| 324 | CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
| 325 | |
| 326 | TpPort tcpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_MASK), |
| 327 | CriterionCodec.TCP_MASK + MISSING_MEMBER_MESSAGE).asInt()); |
| 328 | |
| 329 | return Criteria.matchTcpDstMasked(tcpPort, tcpMask); |
| 330 | } |
| 331 | } |
| 332 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 333 | private class UdpSrcDecoder implements CriterionDecoder { |
| 334 | @Override |
| 335 | public Criterion decodeCriterion(ObjectNode json) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 336 | TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT), |
| 337 | CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 338 | return Criteria.matchUdpSrc(udpPort); |
| 339 | } |
| 340 | } |
| 341 | |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 342 | private class UdpSrcMaskDecoder implements CriterionDecoder { |
| 343 | @Override |
| 344 | public Criterion decodeCriterion(ObjectNode json) { |
| 345 | TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT), |
| 346 | CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
| 347 | |
| 348 | TpPort udpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_MASK), |
| 349 | CriterionCodec.UDP_MASK + MISSING_MEMBER_MESSAGE).asInt()); |
| 350 | |
| 351 | return Criteria.matchUdpSrcMasked(udpPort, udpMask); |
| 352 | } |
| 353 | } |
| 354 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 355 | private class UdpDstDecoder implements CriterionDecoder { |
| 356 | @Override |
| 357 | public Criterion decodeCriterion(ObjectNode json) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 358 | TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT), |
| 359 | CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 360 | return Criteria.matchUdpDst(udpPort); |
| 361 | } |
| 362 | } |
| 363 | |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 364 | private class UdpDstMaskDecoder implements CriterionDecoder { |
| 365 | @Override |
| 366 | public Criterion decodeCriterion(ObjectNode json) { |
| 367 | TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT), |
| 368 | CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
| 369 | |
| 370 | TpPort udpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_MASK), |
| 371 | CriterionCodec.UDP_MASK + MISSING_MEMBER_MESSAGE).asInt()); |
| 372 | |
| 373 | return Criteria.matchUdpDstMasked(udpPort, udpMask); |
| 374 | } |
| 375 | } |
| 376 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 377 | private class SctpSrcDecoder implements CriterionDecoder { |
| 378 | @Override |
| 379 | public Criterion decodeCriterion(ObjectNode json) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 380 | TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT), |
| 381 | CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 382 | return Criteria.matchSctpSrc(sctpPort); |
| 383 | } |
| 384 | } |
| 385 | |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 386 | private class SctpSrcMaskDecoder implements CriterionDecoder { |
| 387 | @Override |
| 388 | public Criterion decodeCriterion(ObjectNode json) { |
| 389 | TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT), |
| 390 | CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
| 391 | |
| 392 | TpPort sctpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_MASK), |
| 393 | CriterionCodec.SCTP_MASK + MISSING_MEMBER_MESSAGE).asInt()); |
| 394 | |
| 395 | return Criteria.matchSctpSrcMasked(sctpPort, sctpMask); |
| 396 | } |
| 397 | } |
| 398 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 399 | private class SctpDstDecoder implements CriterionDecoder { |
| 400 | @Override |
| 401 | public Criterion decodeCriterion(ObjectNode json) { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 402 | TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT), |
| 403 | CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 404 | return Criteria.matchSctpDst(sctpPort); |
| 405 | } |
| 406 | } |
| 407 | |
Andreas Gilbert | 5e95961 | 2017-12-20 10:30:18 +0100 | [diff] [blame] | 408 | private class SctpDstMaskDecoder implements CriterionDecoder { |
| 409 | @Override |
| 410 | public Criterion decodeCriterion(ObjectNode json) { |
| 411 | TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT), |
| 412 | CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt()); |
| 413 | |
| 414 | TpPort sctpMask = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_MASK), |
| 415 | CriterionCodec.SCTP_MASK + MISSING_MEMBER_MESSAGE).asInt()); |
| 416 | |
| 417 | return Criteria.matchSctpDstMasked(sctpPort, sctpMask); |
| 418 | } |
| 419 | } |
| 420 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 421 | private class IcmpV4TypeDecoder implements CriterionDecoder { |
| 422 | @Override |
| 423 | public Criterion decodeCriterion(ObjectNode json) { |
| 424 | short type = (short) nullIsIllegal(json.get(CriterionCodec.ICMP_TYPE), |
| 425 | CriterionCodec.ICMP_TYPE + MISSING_MEMBER_MESSAGE).asInt(); |
| 426 | return Criteria.matchIcmpType(type); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | private class IcmpV4CodeDecoder implements CriterionDecoder { |
| 431 | @Override |
| 432 | public Criterion decodeCriterion(ObjectNode json) { |
| 433 | short code = (short) nullIsIllegal(json.get(CriterionCodec.ICMP_CODE), |
| 434 | CriterionCodec.ICMP_CODE + MISSING_MEMBER_MESSAGE).asInt(); |
| 435 | return Criteria.matchIcmpCode(code); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | private class IpV6FLabelDecoder implements CriterionDecoder { |
| 440 | @Override |
| 441 | public Criterion decodeCriterion(ObjectNode json) { |
| 442 | int flowLabel = nullIsIllegal(json.get(CriterionCodec.FLOW_LABEL), |
| 443 | CriterionCodec.FLOW_LABEL + MISSING_MEMBER_MESSAGE).asInt(); |
| 444 | return Criteria.matchIPv6FlowLabel(flowLabel); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | private class IcmpV6TypeDecoder implements CriterionDecoder { |
| 449 | @Override |
| 450 | public Criterion decodeCriterion(ObjectNode json) { |
| 451 | short type = (short) nullIsIllegal(json.get(CriterionCodec.ICMPV6_TYPE), |
| 452 | CriterionCodec.ICMPV6_TYPE + MISSING_MEMBER_MESSAGE).asInt(); |
| 453 | return Criteria.matchIcmpv6Type(type); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | private class IcmpV6CodeDecoder implements CriterionDecoder { |
| 458 | @Override |
| 459 | public Criterion decodeCriterion(ObjectNode json) { |
| 460 | short code = (short) nullIsIllegal(json.get(CriterionCodec.ICMPV6_CODE), |
| 461 | CriterionCodec.ICMPV6_CODE + MISSING_MEMBER_MESSAGE).asInt(); |
| 462 | return Criteria.matchIcmpv6Code(code); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | private class V6NDTargetDecoder implements CriterionDecoder { |
| 467 | @Override |
| 468 | public Criterion decodeCriterion(ObjectNode json) { |
| 469 | Ip6Address target = Ip6Address.valueOf(nullIsIllegal(json.get(CriterionCodec.TARGET_ADDRESS), |
| 470 | CriterionCodec.TARGET_ADDRESS + MISSING_MEMBER_MESSAGE).asText()); |
| 471 | return Criteria.matchIPv6NDTargetAddress(target); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | private class V6NDSllDecoder implements CriterionDecoder { |
| 476 | @Override |
| 477 | public Criterion decodeCriterion(ObjectNode json) { |
| 478 | MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC), |
| 479 | CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText()); |
| 480 | return Criteria.matchIPv6NDSourceLinkLayerAddress(mac); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | private class V6NDTllDecoder implements CriterionDecoder { |
| 485 | @Override |
| 486 | public Criterion decodeCriterion(ObjectNode json) { |
| 487 | MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC), |
| 488 | CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText()); |
| 489 | return Criteria.matchIPv6NDTargetLinkLayerAddress(mac); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | private class MplsLabelDecoder implements CriterionDecoder { |
| 494 | @Override |
| 495 | public Criterion decodeCriterion(ObjectNode json) { |
| 496 | int label = nullIsIllegal(json.get(CriterionCodec.LABEL), |
| 497 | CriterionCodec.LABEL + MISSING_MEMBER_MESSAGE).asInt(); |
| 498 | return Criteria.matchMplsLabel(MplsLabel.mplsLabel(label)); |
| 499 | } |
| 500 | } |
| 501 | |
Jonathan Hart | cc962d8 | 2016-08-09 16:52:22 -0700 | [diff] [blame] | 502 | private class MplsBosDecoder implements CriterionDecoder { |
| 503 | @Override |
| 504 | public Criterion decodeCriterion(ObjectNode json) { |
| 505 | boolean bos = nullIsIllegal(json.get(CriterionCodec.BOS), |
| 506 | CriterionCodec.BOS + MISSING_MEMBER_MESSAGE).asBoolean(); |
| 507 | return Criteria.matchMplsBos(bos); |
| 508 | } |
| 509 | } |
| 510 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 511 | private class IpV6ExthdrDecoder implements CriterionDecoder { |
| 512 | @Override |
| 513 | public Criterion decodeCriterion(ObjectNode json) { |
| 514 | int exthdrFlags = nullIsIllegal(json.get(CriterionCodec.EXT_HDR_FLAGS), |
| 515 | CriterionCodec.EXT_HDR_FLAGS + MISSING_MEMBER_MESSAGE).asInt(); |
| 516 | return Criteria.matchIPv6ExthdrFlags(exthdrFlags); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | private class OchSigIdDecoder implements CriterionDecoder { |
| 521 | @Override |
| 522 | public Criterion decodeCriterion(ObjectNode json) { |
Sho SHIMIZU | cc137a9 | 2016-03-11 15:10:54 -0800 | [diff] [blame] | 523 | JsonNode ochSignalId = nullIsIllegal(json.get(CriterionCodec.OCH_SIGNAL_ID), |
| 524 | CriterionCodec.GRID_TYPE + MISSING_MEMBER_MESSAGE); |
| 525 | GridType gridType = |
| 526 | GridType.valueOf( |
| 527 | nullIsIllegal(ochSignalId.get(CriterionCodec.GRID_TYPE), |
| 528 | CriterionCodec.GRID_TYPE + MISSING_MEMBER_MESSAGE).asText()); |
| 529 | ChannelSpacing channelSpacing = |
| 530 | ChannelSpacing.valueOf( |
| 531 | nullIsIllegal(ochSignalId.get(CriterionCodec.CHANNEL_SPACING), |
| 532 | CriterionCodec.CHANNEL_SPACING + MISSING_MEMBER_MESSAGE).asText()); |
| 533 | int spacingMultiplier = nullIsIllegal(ochSignalId.get(CriterionCodec.SPACING_MULIPLIER), |
| 534 | CriterionCodec.SPACING_MULIPLIER + MISSING_MEMBER_MESSAGE).asInt(); |
| 535 | int slotGranularity = nullIsIllegal(ochSignalId.get(CriterionCodec.SLOT_GRANULARITY), |
| 536 | CriterionCodec.SLOT_GRANULARITY + MISSING_MEMBER_MESSAGE).asInt(); |
| 537 | return Criteria.matchLambda( |
| 538 | Lambda.ochSignal(gridType, channelSpacing, |
| 539 | spacingMultiplier, slotGranularity)); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | |
| 543 | private class OchSigTypeDecoder implements CriterionDecoder { |
| 544 | @Override |
| 545 | public Criterion decodeCriterion(ObjectNode json) { |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 546 | OchSignalType ochSignalType = OchSignalType.valueOf(nullIsIllegal(json.get(CriterionCodec.OCH_SIGNAL_TYPE), |
| 547 | CriterionCodec.OCH_SIGNAL_TYPE + MISSING_MEMBER_MESSAGE).asText()); |
| 548 | return Criteria.matchOchSignalType(ochSignalType); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
Hyunsun Moon | 7080a0d | 2015-08-14 19:18:48 -0700 | [diff] [blame] | 552 | private class TunnelIdDecoder implements CriterionDecoder { |
| 553 | @Override |
| 554 | public Criterion decodeCriterion(ObjectNode json) { |
| 555 | long tunnelId = nullIsIllegal(json.get(CriterionCodec.TUNNEL_ID), |
| 556 | CriterionCodec.TUNNEL_ID + MISSING_MEMBER_MESSAGE).asLong(); |
| 557 | return Criteria.matchTunnelId(tunnelId); |
| 558 | } |
| 559 | } |
| 560 | |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 561 | private class OduSigIdDecoder implements CriterionDecoder { |
| 562 | @Override |
| 563 | public Criterion decodeCriterion(ObjectNode json) { |
| 564 | JsonNode oduSignalId = nullIsIllegal(json.get(CriterionCodec.ODU_SIGNAL_ID), |
| 565 | CriterionCodec.TRIBUTARY_PORT_NUMBER + MISSING_MEMBER_MESSAGE); |
| 566 | |
| 567 | int tributaryPortNumber = nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_PORT_NUMBER), |
| 568 | CriterionCodec.TRIBUTARY_PORT_NUMBER + MISSING_MEMBER_MESSAGE).asInt(); |
| 569 | int tributarySlotLen = nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_SLOT_LEN), |
| 570 | CriterionCodec.TRIBUTARY_SLOT_LEN + MISSING_MEMBER_MESSAGE).asInt(); |
| 571 | byte[] tributarySlotBitmap = HexString.fromHexString( |
| 572 | nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_SLOT_BITMAP), |
| 573 | CriterionCodec.TRIBUTARY_SLOT_BITMAP + MISSING_MEMBER_MESSAGE).asText()); |
| 574 | |
| 575 | return Criteria.matchOduSignalId( |
| 576 | OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap)); |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | private class OduSigTypeDecoder implements CriterionDecoder { |
| 581 | @Override |
| 582 | public Criterion decodeCriterion(ObjectNode json) { |
| 583 | OduSignalType oduSignalType = OduSignalType.valueOf(nullIsIllegal(json.get(CriterionCodec.ODU_SIGNAL_TYPE), |
| 584 | CriterionCodec.ODU_SIGNAL_TYPE + MISSING_MEMBER_MESSAGE).asText()); |
| 585 | return Criteria.matchOduSignalType(oduSignalType); |
| 586 | } |
| 587 | } |
| 588 | |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 589 | private class PiDecoder implements CriterionDecoder { |
| 590 | @Override |
| 591 | public Criterion decodeCriterion(ObjectNode json) { |
| 592 | PiCriterion.Builder builder = PiCriterion.builder(); |
| 593 | JsonNode matchesNode = nullIsIllegal(json.get(CriterionCodec.PI_MATCHES), |
| 594 | CriterionCodec.PI_MATCHES + MISSING_MEMBER_MESSAGE); |
| 595 | if (matchesNode.isArray()) { |
| 596 | for (JsonNode node : matchesNode) { |
| 597 | String type = nullIsIllegal(node.get(CriterionCodec.PI_MATCH_TYPE), |
| 598 | CriterionCodec.PI_MATCH_TYPE + MISSING_MEMBER_MESSAGE).asText(); |
| 599 | switch (PiMatchType.valueOf(type.toUpperCase())) { |
| 600 | case EXACT: |
| 601 | builder.matchExact( |
| 602 | PiMatchFieldId.of( |
| 603 | nullIsIllegal(node.get(CriterionCodec.PI_MATCH_FIELD_ID), |
| 604 | CriterionCodec.PI_MATCH_FIELD_ID + |
| 605 | MISSING_MEMBER_MESSAGE).asText()), |
| 606 | HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_VALUE), |
| 607 | CriterionCodec.PI_MATCH_VALUE + |
| 608 | MISSING_MEMBER_MESSAGE).asText(), null)); |
| 609 | break; |
| 610 | case LPM: |
| 611 | builder.matchLpm( |
| 612 | PiMatchFieldId.of( |
| 613 | nullIsIllegal(node.get(CriterionCodec.PI_MATCH_FIELD_ID), |
| 614 | CriterionCodec.PI_MATCH_FIELD_ID + |
| 615 | MISSING_MEMBER_MESSAGE).asText()), |
| 616 | HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_VALUE), |
| 617 | CriterionCodec.PI_MATCH_VALUE + |
| 618 | MISSING_MEMBER_MESSAGE).asText(), null), |
| 619 | nullIsIllegal(node.get(CriterionCodec.PI_MATCH_PREFIX), |
| 620 | CriterionCodec.PI_MATCH_PREFIX + |
| 621 | MISSING_MEMBER_MESSAGE).asInt()); |
| 622 | break; |
| 623 | case TERNARY: |
| 624 | builder.matchTernary( |
| 625 | PiMatchFieldId.of( |
| 626 | nullIsIllegal(node.get(CriterionCodec.PI_MATCH_FIELD_ID), |
| 627 | CriterionCodec.PI_MATCH_FIELD_ID + |
| 628 | MISSING_MEMBER_MESSAGE).asText()), |
| 629 | HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_VALUE), |
| 630 | CriterionCodec.PI_MATCH_VALUE + |
| 631 | MISSING_MEMBER_MESSAGE).asText(), null), |
| 632 | HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_MASK), |
| 633 | CriterionCodec.PI_MATCH_MASK + |
| 634 | MISSING_MEMBER_MESSAGE).asText(), null)); |
| 635 | break; |
| 636 | case RANGE: |
| 637 | builder.matchRange( |
| 638 | PiMatchFieldId.of( |
| 639 | nullIsIllegal(node.get(CriterionCodec.PI_MATCH_FIELD_ID), |
| 640 | CriterionCodec.PI_MATCH_FIELD_ID + |
| 641 | MISSING_MEMBER_MESSAGE).asText()), |
| 642 | HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_LOW_VALUE), |
| 643 | CriterionCodec.PI_MATCH_LOW_VALUE + |
| 644 | MISSING_MEMBER_MESSAGE).asText(), null), |
| 645 | HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_HIGH_VALUE), |
| 646 | CriterionCodec.PI_MATCH_HIGH_VALUE + |
| 647 | MISSING_MEMBER_MESSAGE).asText(), null) |
| 648 | ); |
| 649 | break; |
| 650 | case VALID: |
| 651 | builder.matchValid( |
| 652 | PiMatchFieldId.of( |
| 653 | nullIsIllegal(node.get(CriterionCodec.PI_MATCH_FIELD_ID), |
| 654 | CriterionCodec.PI_MATCH_FIELD_ID + |
| 655 | MISSING_MEMBER_MESSAGE).asText()), |
| 656 | nullIsIllegal(node.get(CriterionCodec.PI_MATCH_VALUE), |
| 657 | CriterionCodec.PI_MATCH_VALUE + |
| 658 | MISSING_MEMBER_MESSAGE).asBoolean()); |
| 659 | break; |
| 660 | default: |
| 661 | throw new IllegalArgumentException("Type " + type + " is unsupported"); |
| 662 | } |
| 663 | } |
| 664 | } else { |
| 665 | throw new IllegalArgumentException("Protocol-independent matches must be in an array."); |
| 666 | } |
| 667 | |
| 668 | return builder.build(); |
| 669 | } |
| 670 | } |
| 671 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 672 | /** |
| 673 | * Decodes the JSON into a criterion object. |
| 674 | * |
| 675 | * @return Criterion object |
| 676 | * @throws IllegalArgumentException if the JSON is invalid |
| 677 | */ |
| 678 | public Criterion decode() { |
Ray Milkey | 5207506 | 2016-02-03 17:36:48 -0800 | [diff] [blame] | 679 | String type = |
| 680 | nullIsIllegal(json.get(CriterionCodec.TYPE), "Type not specified") |
| 681 | .asText(); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 682 | |
| 683 | CriterionDecoder decoder = decoderMap.get(type); |
| 684 | if (decoder != null) { |
| 685 | return decoder.decodeCriterion(json); |
| 686 | } |
| 687 | |
| 688 | throw new IllegalArgumentException("Type " + type + " is unknown"); |
| 689 | } |
| 690 | |
| 691 | |
| 692 | } |