blob: ec1b061c3c1c24c4dfb4ece15aa9f04f3e73be39 [file] [log] [blame]
Ray Milkeyc95bb9d2015-01-06 10:28:24 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Ray Milkeyc95bb9d2015-01-06 10:28:24 -08003 *
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
18import org.onosproject.codec.CodecContext;
19import org.onosproject.codec.JsonCodec;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080020import org.onosproject.net.flow.criteria.Criterion;
21import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
23
24import com.fasterxml.jackson.databind.node.ObjectNode;
25
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080026/**
27 * Criterion codec.
28 */
Ray Milkey540b2ce2015-02-04 17:50:20 -080029public final class CriterionCodec extends JsonCodec<Criterion> {
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080030
Ray Milkey9c9cde42018-01-12 14:22:06 -080031 private static final Logger log =
Ray Milkey73ba84a2015-02-04 17:08:41 -080032 LoggerFactory.getLogger(CriterionCodec.class);
33
Ray Milkey9c9cde42018-01-12 14:22:06 -080034 static final String TYPE = "type";
35 static final String ETH_TYPE = "ethType";
36 static final String MAC = "mac";
37 static final String PORT = "port";
38 static final String METADATA = "metadata";
Ray Milkey73ba84a2015-02-04 17:08:41 -080039
Ray Milkey9c9cde42018-01-12 14:22:06 -080040 static final String VLAN_ID = "vlanId";
41 static final String INNER_VLAN_ID = "innerVlanId";
42 static final String INNER_PRIORITY = "innerPriority";
43 static final String PRIORITY = "priority";
44 static final String IP_DSCP = "ipDscp";
45 static final String IP_ECN = "ipEcn";
46 static final String PROTOCOL = "protocol";
47 static final String IP = "ip";
48 static final String TCP_PORT = "tcpPort";
49 static final String TCP_MASK = "tcpMask";
50 static final String UDP_PORT = "udpPort";
51 static final String UDP_MASK = "udpMask";
52 static final String SCTP_PORT = "sctpPort";
53 static final String SCTP_MASK = "sctpMask";
54 static final String ICMP_TYPE = "icmpType";
55 static final String ICMP_CODE = "icmpCode";
56 static final String FLOW_LABEL = "flowLabel";
57 static final String ICMPV6_TYPE = "icmpv6Type";
58 static final String ICMPV6_CODE = "icmpv6Code";
59 static final String TARGET_ADDRESS = "targetAddress";
60 static final String LABEL = "label";
61 static final String BOS = "bos";
62 static final String EXT_HDR_FLAGS = "exthdrFlags";
63 static final String LAMBDA = "lambda";
64 static final String GRID_TYPE = "gridType";
65 static final String CHANNEL_SPACING = "channelSpacing";
66 static final String SPACING_MULIPLIER = "spacingMultiplier";
67 static final String SLOT_GRANULARITY = "slotGranularity";
68 static final String OCH_SIGNAL_ID = "ochSignalId";
69 static final String TUNNEL_ID = "tunnelId";
70 static final String OCH_SIGNAL_TYPE = "ochSignalType";
71 static final String ODU_SIGNAL_ID = "oduSignalId";
72 static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber";
73 static final String TRIBUTARY_SLOT_LEN = "tributarySlotLen";
74 static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap";
75 static final String ODU_SIGNAL_TYPE = "oduSignalType";
alshabiba3a476d2015-04-10 14:35:38 -070076
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080077 @Override
78 public ObjectNode encode(Criterion criterion, CodecContext context) {
Ray Milkey6d7968e2015-07-06 14:30:02 -070079 EncodeCriterionCodecHelper encoder = new EncodeCriterionCodecHelper(criterion, context);
Ray Milkeyd43fe452015-05-29 09:35:12 -070080 return encoder.encode();
81 }
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080082
Ray Milkeyd43fe452015-05-29 09:35:12 -070083 @Override
84 public Criterion decode(ObjectNode json, CodecContext context) {
Ray Milkey6d7968e2015-07-06 14:30:02 -070085 DecodeCriterionCodecHelper decoder = new DecodeCriterionCodecHelper(json);
Ray Milkeyd43fe452015-05-29 09:35:12 -070086 return decoder.decode();
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080087 }
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080088}