Committed by
Gerrit Code Review
Support to encode and decode setqueue id in InstructionCodec
Change-Id: I911e14b750d5264755687a9eff322502ba9ed118
Showing
4 changed files
with
89 additions
and
20 deletions
| ... | @@ -233,6 +233,32 @@ public final class DecodeInstructionCodecHelper { | ... | @@ -233,6 +233,32 @@ public final class DecodeInstructionCodecHelper { |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | /** | 235 | /** |
| 236 | + * Extracts port number of the given json node. | ||
| 237 | + * | ||
| 238 | + * @param jsonNode json node | ||
| 239 | + * @return port number | ||
| 240 | + */ | ||
| 241 | + private PortNumber getPortNumber(ObjectNode jsonNode) { | ||
| 242 | + PortNumber portNumber; | ||
| 243 | + if (jsonNode.get(InstructionCodec.PORT).isLong() || jsonNode.get(InstructionCodec.PORT).isInt()) { | ||
| 244 | + portNumber = PortNumber | ||
| 245 | + .portNumber(nullIsIllegal(jsonNode.get(InstructionCodec.PORT) | ||
| 246 | + .asLong(), InstructionCodec.PORT | ||
| 247 | + + InstructionCodec.MISSING_MEMBER_MESSAGE)); | ||
| 248 | + } else if (jsonNode.get(InstructionCodec.PORT).isTextual()) { | ||
| 249 | + portNumber = PortNumber | ||
| 250 | + .fromString(nullIsIllegal(jsonNode.get(InstructionCodec.PORT) | ||
| 251 | + .textValue(), InstructionCodec.PORT | ||
| 252 | + + InstructionCodec.MISSING_MEMBER_MESSAGE)); | ||
| 253 | + } else { | ||
| 254 | + throw new IllegalArgumentException("Port value " | ||
| 255 | + + jsonNode.get(InstructionCodec.PORT).toString() | ||
| 256 | + + " is not supported"); | ||
| 257 | + } | ||
| 258 | + return portNumber; | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + /** | ||
| 236 | * Decodes the JSON into an instruction object. | 262 | * Decodes the JSON into an instruction object. |
| 237 | * | 263 | * |
| 238 | * @return Criterion object | 264 | * @return Criterion object |
| ... | @@ -242,23 +268,7 @@ public final class DecodeInstructionCodecHelper { | ... | @@ -242,23 +268,7 @@ public final class DecodeInstructionCodecHelper { |
| 242 | String type = json.get(InstructionCodec.TYPE).asText(); | 268 | String type = json.get(InstructionCodec.TYPE).asText(); |
| 243 | 269 | ||
| 244 | if (type.equals(Instruction.Type.OUTPUT.name())) { | 270 | if (type.equals(Instruction.Type.OUTPUT.name())) { |
| 245 | - PortNumber portNumber; | 271 | + return Instructions.createOutput(getPortNumber(json)); |
| 246 | - if (json.get(InstructionCodec.PORT).isLong() || json.get(InstructionCodec.PORT).isInt()) { | ||
| 247 | - portNumber = PortNumber | ||
| 248 | - .portNumber(nullIsIllegal(json.get(InstructionCodec.PORT) | ||
| 249 | - .asLong(), InstructionCodec.PORT | ||
| 250 | - + InstructionCodec.MISSING_MEMBER_MESSAGE)); | ||
| 251 | - } else if (json.get(InstructionCodec.PORT).isTextual()) { | ||
| 252 | - portNumber = PortNumber | ||
| 253 | - .fromString(nullIsIllegal(json.get(InstructionCodec.PORT) | ||
| 254 | - .textValue(), InstructionCodec.PORT | ||
| 255 | - + InstructionCodec.MISSING_MEMBER_MESSAGE)); | ||
| 256 | - } else { | ||
| 257 | - throw new IllegalArgumentException("Port value " | ||
| 258 | - + json.get(InstructionCodec.PORT).toString() | ||
| 259 | - + " is not supported"); | ||
| 260 | - } | ||
| 261 | - return Instructions.createOutput(portNumber); | ||
| 262 | } else if (type.equals(Instruction.Type.NOACTION.name())) { | 272 | } else if (type.equals(Instruction.Type.NOACTION.name())) { |
| 263 | return Instructions.createNoAction(); | 273 | return Instructions.createNoAction(); |
| 264 | } else if (type.equals(Instruction.Type.TABLE.name())) { | 274 | } else if (type.equals(Instruction.Type.TABLE.name())) { |
| ... | @@ -272,6 +282,10 @@ public final class DecodeInstructionCodecHelper { | ... | @@ -272,6 +282,10 @@ public final class DecodeInstructionCodecHelper { |
| 272 | MeterId meterId = MeterId.meterId(nullIsIllegal(json.get(InstructionCodec.METER_ID) | 282 | MeterId meterId = MeterId.meterId(nullIsIllegal(json.get(InstructionCodec.METER_ID) |
| 273 | .asLong(), InstructionCodec.METER_ID + InstructionCodec.MISSING_MEMBER_MESSAGE)); | 283 | .asLong(), InstructionCodec.METER_ID + InstructionCodec.MISSING_MEMBER_MESSAGE)); |
| 274 | return Instructions.meterTraffic(meterId); | 284 | return Instructions.meterTraffic(meterId); |
| 285 | + } else if (type.equals(Instruction.Type.QUEUE.name())) { | ||
| 286 | + long queueId = nullIsIllegal(json.get(InstructionCodec.QUEUE_ID) | ||
| 287 | + .asLong(), InstructionCodec.QUEUE_ID + InstructionCodec.MISSING_MEMBER_MESSAGE); | ||
| 288 | + return Instructions.setQueue(queueId, getPortNumber(json)); | ||
| 275 | } else if (type.equals(Instruction.Type.L0MODIFICATION.name())) { | 289 | } else if (type.equals(Instruction.Type.L0MODIFICATION.name())) { |
| 276 | return decodeL0(); | 290 | return decodeL0(); |
| 277 | } else if (type.equals(Instruction.Type.L1MODIFICATION.name())) { | 291 | } else if (type.equals(Instruction.Type.L1MODIFICATION.name())) { | ... | ... |
| ... | @@ -256,6 +256,13 @@ public final class EncodeInstructionCodecHelper { | ... | @@ -256,6 +256,13 @@ public final class EncodeInstructionCodecHelper { |
| 256 | result.put(InstructionCodec.METER_ID, meterInstruction.meterId().toString()); | 256 | result.put(InstructionCodec.METER_ID, meterInstruction.meterId().toString()); |
| 257 | break; | 257 | break; |
| 258 | 258 | ||
| 259 | + case QUEUE: | ||
| 260 | + final Instructions.SetQueueInstruction setQueueInstruction = | ||
| 261 | + (Instructions.SetQueueInstruction) instruction; | ||
| 262 | + result.put(InstructionCodec.QUEUE_ID, setQueueInstruction.queueId()); | ||
| 263 | + result.put(InstructionCodec.PORT, setQueueInstruction.port().toString()); | ||
| 264 | + break; | ||
| 265 | + | ||
| 259 | case L0MODIFICATION: | 266 | case L0MODIFICATION: |
| 260 | encodeL0(result); | 267 | encodeL0(result); |
| 261 | break; | 268 | break; | ... | ... |
| ... | @@ -52,6 +52,7 @@ public final class InstructionCodec extends JsonCodec<Instruction> { | ... | @@ -52,6 +52,7 @@ public final class InstructionCodec extends JsonCodec<Instruction> { |
| 52 | protected static final String TABLE_ID = "tableId"; | 52 | protected static final String TABLE_ID = "tableId"; |
| 53 | protected static final String GROUP_ID = "groupId"; | 53 | protected static final String GROUP_ID = "groupId"; |
| 54 | protected static final String METER_ID = "meterId"; | 54 | protected static final String METER_ID = "meterId"; |
| 55 | + protected static final String QUEUE_ID = "queueId"; | ||
| 55 | protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber"; | 56 | protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber"; |
| 56 | protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength"; | 57 | protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength"; |
| 57 | protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap"; | 58 | protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap"; | ... | ... |
| ... | @@ -25,6 +25,7 @@ import org.onosproject.net.flow.instructions.Instructions.GroupInstruction; | ... | @@ -25,6 +25,7 @@ import org.onosproject.net.flow.instructions.Instructions.GroupInstruction; |
| 25 | import org.onosproject.net.flow.instructions.Instructions.MeterInstruction; | 25 | import org.onosproject.net.flow.instructions.Instructions.MeterInstruction; |
| 26 | import org.onosproject.net.flow.instructions.Instructions.NoActionInstruction; | 26 | import org.onosproject.net.flow.instructions.Instructions.NoActionInstruction; |
| 27 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; | 27 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 28 | +import org.onosproject.net.flow.instructions.Instructions.SetQueueInstruction; | ||
| 28 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; | 29 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; |
| 29 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction; | 30 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction; |
| 30 | import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction; | 31 | import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction; |
| ... | @@ -115,7 +116,7 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json | ... | @@ -115,7 +116,7 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json |
| 115 | } | 116 | } |
| 116 | } else { | 117 | } else { |
| 117 | final String jsonPort = instructionJson.get("port").toString(); | 118 | final String jsonPort = instructionJson.get("port").toString(); |
| 118 | - description.appendText("Unmathcing types "); | 119 | + description.appendText("Unmatching types "); |
| 119 | description.appendText("instructionToMatch " + instructionToMatch.port().toString()); | 120 | description.appendText("instructionToMatch " + instructionToMatch.port().toString()); |
| 120 | description.appendText("jsonPort " + jsonPort); | 121 | description.appendText("jsonPort " + jsonPort); |
| 121 | } | 122 | } |
| ... | @@ -174,6 +175,51 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json | ... | @@ -174,6 +175,51 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json |
| 174 | } | 175 | } |
| 175 | 176 | ||
| 176 | /** | 177 | /** |
| 178 | + * Matches the contents of a set queue instruction. | ||
| 179 | + * | ||
| 180 | + * @param instructionJson JSON instruction to match | ||
| 181 | + * @param description Description object used for recording errors | ||
| 182 | + * @return true if contents match, false otherwise | ||
| 183 | + */ | ||
| 184 | + private boolean matchSetQueueInstruction(JsonNode instructionJson, | ||
| 185 | + Description description) { | ||
| 186 | + final String jsonType = instructionJson.get("type").textValue(); | ||
| 187 | + SetQueueInstruction instructionToMatch = (SetQueueInstruction) instruction; | ||
| 188 | + if (!instructionToMatch.type().name().equals(jsonType)) { | ||
| 189 | + description.appendText("type was " + jsonType); | ||
| 190 | + return false; | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + final long jsonQueueId = instructionJson.get("queueId").longValue(); | ||
| 194 | + if (instructionToMatch.queueId() != jsonQueueId) { | ||
| 195 | + description.appendText("queueId was " + jsonQueueId); | ||
| 196 | + return false; | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + if (instructionJson.get("port").isLong() || | ||
| 200 | + instructionJson.get("port").isInt()) { | ||
| 201 | + final long jsonPort = instructionJson.get("port").asLong(); | ||
| 202 | + if (instructionToMatch.port().toLong() != (jsonPort)) { | ||
| 203 | + description.appendText("port was " + jsonPort); | ||
| 204 | + return false; | ||
| 205 | + } | ||
| 206 | + } else if (instructionJson.get("port").isTextual()) { | ||
| 207 | + final String jsonPort = instructionJson.get("port").textValue(); | ||
| 208 | + if (!instructionToMatch.port().toString().equals(jsonPort)) { | ||
| 209 | + description.appendText("port was " + jsonPort); | ||
| 210 | + return false; | ||
| 211 | + } | ||
| 212 | + } else { | ||
| 213 | + final String jsonPort = instructionJson.get("port").toString(); | ||
| 214 | + description.appendText("Unmatching types "); | ||
| 215 | + description.appendText("instructionToMatch " + instructionToMatch.port().toString()); | ||
| 216 | + description.appendText("jsonPort " + jsonPort); | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | + return true; | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | + /** | ||
| 177 | * Matches the contents of a mod lambda instruction. | 223 | * Matches the contents of a mod lambda instruction. |
| 178 | * | 224 | * |
| 179 | * @param instructionJson JSON instruction to match | 225 | * @param instructionJson JSON instruction to match |
| ... | @@ -508,6 +554,8 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json | ... | @@ -508,6 +554,8 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json |
| 508 | return matchGroupInstruction(jsonInstruction, description); | 554 | return matchGroupInstruction(jsonInstruction, description); |
| 509 | } else if (instruction instanceof MeterInstruction) { | 555 | } else if (instruction instanceof MeterInstruction) { |
| 510 | return matchMeterInstruction(jsonInstruction, description); | 556 | return matchMeterInstruction(jsonInstruction, description); |
| 557 | + } else if (instruction instanceof SetQueueInstruction) { | ||
| 558 | + return matchSetQueueInstruction(jsonInstruction, description); | ||
| 511 | } else if (instruction instanceof ModLambdaInstruction) { | 559 | } else if (instruction instanceof ModLambdaInstruction) { |
| 512 | return matchModLambdaInstruction(jsonInstruction, description); | 560 | return matchModLambdaInstruction(jsonInstruction, description); |
| 513 | } else if (instruction instanceof ModOchSignalInstruction) { | 561 | } else if (instruction instanceof ModOchSignalInstruction) { |
| ... | @@ -521,8 +569,7 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json | ... | @@ -521,8 +569,7 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json |
| 521 | } else if (instruction instanceof ModIPInstruction) { | 569 | } else if (instruction instanceof ModIPInstruction) { |
| 522 | return matchModIpInstruction(jsonInstruction, description); | 570 | return matchModIpInstruction(jsonInstruction, description); |
| 523 | } else if (instruction instanceof ModIPv6FlowLabelInstruction) { | 571 | } else if (instruction instanceof ModIPv6FlowLabelInstruction) { |
| 524 | - return matchModIPv6FlowLabelInstruction(jsonInstruction, | 572 | + return matchModIPv6FlowLabelInstruction(jsonInstruction, description); |
| 525 | - description); | ||
| 526 | } else if (instruction instanceof ModMplsLabelInstruction) { | 573 | } else if (instruction instanceof ModMplsLabelInstruction) { |
| 527 | return matchModMplsLabelInstruction(jsonInstruction, description); | 574 | return matchModMplsLabelInstruction(jsonInstruction, description); |
| 528 | } else if (instruction instanceof ModOduSignalIdInstruction) { | 575 | } else if (instruction instanceof ModOduSignalIdInstruction) { | ... | ... |
-
Please register or login to post a comment