Committed by
Gerrit Code Review
[ONOS-3405] Change EthType Json encoding to Hex and extend decoding with Hex support alongside int
Change-Id: I629f52016256d6c5cc258ab9e1c5a7b916991d5b
Showing
9 changed files
with
24 additions
and
22 deletions
... | @@ -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; |
109 | + if (json.get(CriterionCodec.ETH_TYPE).isInt()) { | ||
110 | + ethType = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE), | ||
110 | CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE).asInt(); | 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 | ||
... | @@ -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}, | ... | ... |
... | @@ -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 | ... | ... |
... | @@ -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 | } | ... | ... |
-
Please register or login to post a comment