andrea
Committed by Gerrit Code Review

[ONOS-3405] Change EthType Json encoding to Hex and extend decoding with Hex support alongside int

Change-Id: I629f52016256d6c5cc258ab9e1c5a7b916991d5b
...@@ -15,11 +15,8 @@ ...@@ -15,11 +15,8 @@
15 */ 15 */
16 package org.onosproject.codec.impl; 16 package org.onosproject.codec.impl;
17 17
18 -import static org.onlab.util.Tools.nullIsIllegal; 18 +import com.fasterxml.jackson.databind.JsonNode;
19 - 19 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 -import java.util.HashMap;
21 -import java.util.Map;
22 -
23 import org.onlab.packet.Ip6Address; 20 import org.onlab.packet.Ip6Address;
24 import org.onlab.packet.IpPrefix; 21 import org.onlab.packet.IpPrefix;
25 import org.onlab.packet.MacAddress; 22 import org.onlab.packet.MacAddress;
...@@ -37,8 +34,10 @@ import org.onosproject.net.PortNumber; ...@@ -37,8 +34,10 @@ import org.onosproject.net.PortNumber;
37 import org.onosproject.net.flow.criteria.Criteria; 34 import org.onosproject.net.flow.criteria.Criteria;
38 import org.onosproject.net.flow.criteria.Criterion; 35 import org.onosproject.net.flow.criteria.Criterion;
39 36
40 -import com.fasterxml.jackson.databind.JsonNode; 37 +import java.util.HashMap;
41 -import com.fasterxml.jackson.databind.node.ObjectNode; 38 +import java.util.Map;
39 +
40 +import static org.onlab.util.Tools.nullIsIllegal;
42 41
43 /** 42 /**
44 * Decode portion of the criterion codec. 43 * Decode portion of the criterion codec.
...@@ -106,12 +105,16 @@ public final class DecodeCriterionCodecHelper { ...@@ -106,12 +105,16 @@ public final class DecodeCriterionCodecHelper {
106 private class EthTypeDecoder implements CriterionDecoder { 105 private class EthTypeDecoder implements CriterionDecoder {
107 @Override 106 @Override
108 public Criterion decodeCriterion(ObjectNode json) { 107 public Criterion decodeCriterion(ObjectNode json) {
109 - int ethType = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE), 108 + int ethType;
110 - CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE).asInt(); 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 + }
111 return Criteria.matchEthType(ethType); 115 return Criteria.matchEthType(ethType);
112 } 116 }
113 } 117 }
114 -
115 private class EthDstDecoder implements CriterionDecoder { 118 private class EthDstDecoder implements CriterionDecoder {
116 @Override 119 @Override
117 public Criterion decodeCriterion(ObjectNode json) { 120 public Criterion decodeCriterion(ObjectNode json) {
......
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
15 */ 15 */
16 package org.onosproject.codec.impl; 16 package org.onosproject.codec.impl;
17 17
18 -import java.util.EnumMap; 18 +import com.fasterxml.jackson.databind.node.ObjectNode;
19 -
20 import org.onlab.util.HexString; 19 import org.onlab.util.HexString;
21 import org.onosproject.codec.CodecContext; 20 import org.onosproject.codec.CodecContext;
22 import org.onosproject.net.OchSignal; 21 import org.onosproject.net.OchSignal;
...@@ -50,7 +49,7 @@ import org.onosproject.net.flow.criteria.UdpPortCriterion; ...@@ -50,7 +49,7 @@ import org.onosproject.net.flow.criteria.UdpPortCriterion;
50 import org.onosproject.net.flow.criteria.VlanIdCriterion; 49 import org.onosproject.net.flow.criteria.VlanIdCriterion;
51 import org.onosproject.net.flow.criteria.VlanPcpCriterion; 50 import org.onosproject.net.flow.criteria.VlanPcpCriterion;
52 51
53 -import com.fasterxml.jackson.databind.node.ObjectNode; 52 +import java.util.EnumMap;
54 53
55 import static com.google.common.base.Preconditions.checkNotNull; 54 import static com.google.common.base.Preconditions.checkNotNull;
56 55
...@@ -69,7 +68,7 @@ public final class EncodeCriterionCodecHelper { ...@@ -69,7 +68,7 @@ public final class EncodeCriterionCodecHelper {
69 * Initializes the formatter lookup map for the criterion subclasses. 68 * Initializes the formatter lookup map for the criterion subclasses.
70 * 69 *
71 * @param criterion Criterion to encode 70 * @param criterion Criterion to encode
72 - * @param context context of the JSON encoding 71 + * @param context context of the JSON encoding
73 */ 72 */
74 public EncodeCriterionCodecHelper(Criterion criterion, CodecContext context) { 73 public EncodeCriterionCodecHelper(Criterion criterion, CodecContext context) {
75 this.criterion = criterion; 74 this.criterion = criterion;
...@@ -171,7 +170,8 @@ public final class EncodeCriterionCodecHelper { ...@@ -171,7 +170,8 @@ public final class EncodeCriterionCodecHelper {
171 public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { 170 public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
172 final EthTypeCriterion ethTypeCriterion = 171 final EthTypeCriterion ethTypeCriterion =
173 (EthTypeCriterion) criterion; 172 (EthTypeCriterion) criterion;
174 - return root.put(CriterionCodec.ETH_TYPE, ethTypeCriterion.ethType().toShort()); 173 + return root.put(CriterionCodec.ETH_TYPE, "0x"
174 + + Integer.toHexString(ethTypeCriterion.ethType().toShort() & 0xffff));
175 } 175 }
176 } 176 }
177 177
......
...@@ -138,8 +138,8 @@ public final class CriterionJsonMatcher extends ...@@ -138,8 +138,8 @@ public final class CriterionJsonMatcher extends
138 * @return true if the JSON matches the criterion, false otherwise. 138 * @return true if the JSON matches the criterion, false otherwise.
139 */ 139 */
140 private boolean matchCriterion(EthTypeCriterion criterion) { 140 private boolean matchCriterion(EthTypeCriterion criterion) {
141 - final int ethType = criterion.ethType().toShort(); 141 + final int ethType = criterion.ethType().toShort() & 0xffff;
142 - final int jsonEthType = jsonCriterion.get("ethType").intValue(); 142 + final int jsonEthType = Integer.decode(jsonCriterion.get("ethType").textValue()) & 0xffff;
143 if (ethType != jsonEthType) { 143 if (ethType != jsonEthType) {
144 description.appendText("ethType was " 144 description.appendText("ethType was "
145 + Integer.toString(jsonEthType)); 145 + Integer.toString(jsonEthType));
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
9 {"type":"IN_PORT", "port":23}, 9 {"type":"IN_PORT", "port":23},
10 {"type":"IN_PHY_PORT", "port":44}, 10 {"type":"IN_PHY_PORT", "port":44},
11 {"type":"METADATA", "metadata":123456}, 11 {"type":"METADATA", "metadata":123456},
12 - {"type":"ETH_TYPE","ethType":2054}, 12 + {"type":"ETH_TYPE","ethType":"0x806"},
13 {"type":"ETH_SRC","mac":"00:11:22:33:44:55"}, 13 {"type":"ETH_SRC","mac":"00:11:22:33:44:55"},
14 {"type":"ETH_DST","mac":"00:11:22:33:44:55"}, 14 {"type":"ETH_DST","mac":"00:11:22:33:44:55"},
15 {"type":"VLAN_VID","vlanId":777}, 15 {"type":"VLAN_VID","vlanId":777},
......
...@@ -35,5 +35,5 @@ ...@@ -35,5 +35,5 @@
35 ], 35 ],
36 "deferred":[] 36 "deferred":[]
37 }, 37 },
38 - "selector": {"criteria":[{"type":"ETH_TYPE","ethType":2054}]} 38 + "selector": {"criteria":[{"type":"ETH_TYPE","ethType":"0x806"}]}
39 } 39 }
......
...@@ -262,7 +262,6 @@ public class OnosSwaggerMojo extends AbstractMojo { ...@@ -262,7 +262,6 @@ public class OnosSwaggerMojo extends AbstractMojo {
262 262
263 addSummaryDescriptions(methodNode, comment); 263 addSummaryDescriptions(methodNode, comment);
264 addJsonSchemaDefinition(definitions, tag); 264 addJsonSchemaDefinition(definitions, tag);
265 - addJsonSchemaDefinition(definitions, tag);
266 265
267 processParameters(javaMethod, methodNode, method, tag); 266 processParameters(javaMethod, methodNode, method, tag);
268 267
......
...@@ -168,7 +168,7 @@ ...@@ -168,7 +168,7 @@
168 "ethType": { 168 "ethType": {
169 "type": "integer", 169 "type": "integer",
170 "format": "int64", 170 "format": "int64",
171 - "example": -30516 171 + "example": "0x88cc"
172 } 172 }
173 } 173 }
174 } 174 }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
24 }, 24 },
25 "deviceId": { 25 "deviceId": {
26 "type": "string", 26 "type": "string",
27 - "example": "of:0000000000000003" 27 + "example": "of:0000000000000001"
28 }, 28 },
29 "treatment": { 29 "treatment": {
30 "type": "object", 30 "type": "object",
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
91 "ethType": { 91 "ethType": {
92 "type": "integer", 92 "type": "integer",
93 "format": "int64", 93 "format": "int64",
94 - "example": -30516 94 + "example": "0x88cc"
95 } 95 }
96 } 96 }
97 } 97 }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 "criteria": [ 13 "criteria": [
14 { 14 {
15 "type": "ETH_TYPE", 15 "type": "ETH_TYPE",
16 - "ethType": 2054 16 + "ethType": "0x806"
17 } 17 }
18 ] 18 ]
19 } 19 }
......