Bharat saraswal
Committed by Gerrit Code Review

[ONOS-3108] flow classifier codec changes

Change-Id: I4de3fbf506caeb50e4df730fff2e0a2caaa53584
...@@ -74,8 +74,10 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { ...@@ -74,8 +74,10 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> {
74 String etherType = nullIsIllegal(json.get(ETHER_TYPE), ETHER_TYPE + MISSING_MEMBER_MESSAGE).asText(); 74 String etherType = nullIsIllegal(json.get(ETHER_TYPE), ETHER_TYPE + MISSING_MEMBER_MESSAGE).asText();
75 resultBuilder.setEtherType(etherType); 75 resultBuilder.setEtherType(etherType);
76 76
77 + if (json.get(PROTOCOL) != null && !(json.get(PROTOCOL)).asText().equals("null")) {
77 String protocol = (json.get(PROTOCOL)).asText(); 78 String protocol = (json.get(PROTOCOL)).asText();
78 resultBuilder.setProtocol(protocol); 79 resultBuilder.setProtocol(protocol);
80 + }
79 81
80 int minSrcPortRange = (json.get(MIN_SRC_PORT_RANGE)).asInt(); 82 int minSrcPortRange = (json.get(MIN_SRC_PORT_RANGE)).asInt();
81 resultBuilder.setMinSrcPortRange(minSrcPortRange); 83 resultBuilder.setMinSrcPortRange(minSrcPortRange);
...@@ -89,23 +91,23 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { ...@@ -89,23 +91,23 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> {
89 int maxDstPortRange = (json.get(MAX_DST_PORT_RANGE)).asInt(); 91 int maxDstPortRange = (json.get(MAX_DST_PORT_RANGE)).asInt();
90 resultBuilder.setMaxDstPortRange(maxDstPortRange); 92 resultBuilder.setMaxDstPortRange(maxDstPortRange);
91 93
94 + if (json.get(SRC_IP_PREFIX) != null && !(json.get(SRC_IP_PREFIX)).asText().equals("null")) {
92 String srcIpPrefix = (json.get(SRC_IP_PREFIX)).asText(); 95 String srcIpPrefix = (json.get(SRC_IP_PREFIX)).asText();
93 - if (!srcIpPrefix.isEmpty()) {
94 resultBuilder.setSrcIpPrefix(IpPrefix.valueOf(srcIpPrefix)); 96 resultBuilder.setSrcIpPrefix(IpPrefix.valueOf(srcIpPrefix));
95 } 97 }
96 98
99 + if (json.get(DST_IP_PREFIX) != null && !(json.get(DST_IP_PREFIX)).asText().equals("null")) {
97 String dstIpPrefix = (json.get(DST_IP_PREFIX)).asText(); 100 String dstIpPrefix = (json.get(DST_IP_PREFIX)).asText();
98 - if (!dstIpPrefix.isEmpty()) {
99 resultBuilder.setDstIpPrefix(IpPrefix.valueOf(dstIpPrefix)); 101 resultBuilder.setDstIpPrefix(IpPrefix.valueOf(dstIpPrefix));
100 } 102 }
101 103
102 - String srcPort = json.get(SRC_PORT) != null ? (json.get(SRC_PORT)).asText() : ""; 104 + if (json.get(SRC_PORT) != null && !(json.get(SRC_PORT)).asText().equals("null")) {
103 - if (!srcPort.isEmpty()) { 105 + String srcPort = (json.get(SRC_PORT)).asText();
104 resultBuilder.setSrcPort(VirtualPortId.portId(srcPort)); 106 resultBuilder.setSrcPort(VirtualPortId.portId(srcPort));
105 } 107 }
106 108
107 - String dstPort = json.get(DST_PORT) != null ? (json.get(DST_PORT)).asText() : ""; 109 + if (json.get(DST_PORT) != null && !(json.get(DST_PORT)).asText().equals("null")) {
108 - if (!dstPort.isEmpty()) { 110 + String dstPort = (json.get(DST_PORT)).asText();
109 resultBuilder.setDstPort(VirtualPortId.portId(dstPort)); 111 resultBuilder.setDstPort(VirtualPortId.portId(dstPort));
110 } 112 }
111 return resultBuilder.build(); 113 return resultBuilder.build();
...@@ -114,8 +116,8 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { ...@@ -114,8 +116,8 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> {
114 @Override 116 @Override
115 public ObjectNode encode(FlowClassifier flowClassifier, CodecContext context) { 117 public ObjectNode encode(FlowClassifier flowClassifier, CodecContext context) {
116 checkNotNull(flowClassifier, "flowClassifier cannot be null"); 118 checkNotNull(flowClassifier, "flowClassifier cannot be null");
117 - ObjectNode result = context.mapper().createObjectNode() 119 + ObjectNode result = context.mapper().createObjectNode();
118 - .put(FLOW_CLASSIFIER_ID, flowClassifier.flowClassifierId().toString()) 120 + result.put(FLOW_CLASSIFIER_ID, flowClassifier.flowClassifierId().toString())
119 .put(TENANT_ID, flowClassifier.tenantId().toString()) 121 .put(TENANT_ID, flowClassifier.tenantId().toString())
120 .put(NAME, flowClassifier.name()) 122 .put(NAME, flowClassifier.name())
121 .put(DESCRIPTION, flowClassifier.description()) 123 .put(DESCRIPTION, flowClassifier.description())
...@@ -124,11 +126,29 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { ...@@ -124,11 +126,29 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> {
124 .put(MIN_SRC_PORT_RANGE, flowClassifier.minSrcPortRange()) 126 .put(MIN_SRC_PORT_RANGE, flowClassifier.minSrcPortRange())
125 .put(MAX_SRC_PORT_RANGE, flowClassifier.maxSrcPortRange()) 127 .put(MAX_SRC_PORT_RANGE, flowClassifier.maxSrcPortRange())
126 .put(MIN_DST_PORT_RANGE, flowClassifier.minDstPortRange()) 128 .put(MIN_DST_PORT_RANGE, flowClassifier.minDstPortRange())
127 - .put(MAX_DST_PORT_RANGE, flowClassifier.maxDstPortRange()) 129 + .put(MAX_DST_PORT_RANGE, flowClassifier.maxDstPortRange());
128 - .put(SRC_IP_PREFIX, flowClassifier.srcIpPrefix().toString()) 130 +
129 - .put(DST_IP_PREFIX, flowClassifier.dstIpPrefix().toString()) 131 + if (flowClassifier.srcIpPrefix() != null) {
130 - .put(SRC_PORT, flowClassifier.srcPort().toString()) 132 + result.put(SRC_IP_PREFIX, flowClassifier.srcIpPrefix().toString());
131 - .put(DST_PORT, flowClassifier.dstPort().toString()); 133 + } else {
134 + result.put(SRC_IP_PREFIX, "null");
135 + }
136 + if (flowClassifier.dstIpPrefix() != null) {
137 + result.put(DST_IP_PREFIX, flowClassifier.dstIpPrefix().toString());
138 + } else {
139 + result.put(DST_IP_PREFIX, "null");
140 + }
141 +
142 + if (flowClassifier.srcPort() != null) {
143 + result.put(SRC_PORT, flowClassifier.srcPort().toString());
144 + } else {
145 + result.put(SRC_PORT, "null");
146 + }
147 + if (flowClassifier.dstPort() != null) {
148 + result.put(DST_PORT, flowClassifier.dstPort().toString());
149 + } else {
150 + result.put(DST_PORT, "null");
151 + }
132 return result; 152 return result;
133 } 153 }
134 } 154 }
......