Committed by
Ray Milkey
Support to encode and decode group id in InstructionCodec
Change-Id: Icd0947f494f572831e8b5c8d82d47c85eb074824
Showing
4 changed files
with
45 additions
and
4 deletions
... | @@ -22,6 +22,8 @@ import org.onlab.packet.MplsLabel; | ... | @@ -22,6 +22,8 @@ import org.onlab.packet.MplsLabel; |
22 | import org.onlab.packet.TpPort; | 22 | import org.onlab.packet.TpPort; |
23 | import org.onlab.packet.VlanId; | 23 | import org.onlab.packet.VlanId; |
24 | import org.onlab.util.HexString; | 24 | import org.onlab.util.HexString; |
25 | +import org.onosproject.core.DefaultGroupId; | ||
26 | +import org.onosproject.core.GroupId; | ||
25 | import org.onosproject.net.ChannelSpacing; | 27 | import org.onosproject.net.ChannelSpacing; |
26 | import org.onosproject.net.GridType; | 28 | import org.onosproject.net.GridType; |
27 | import org.onosproject.net.Lambda; | 29 | import org.onosproject.net.Lambda; |
... | @@ -261,6 +263,10 @@ public final class DecodeInstructionCodecHelper { | ... | @@ -261,6 +263,10 @@ public final class DecodeInstructionCodecHelper { |
261 | } else if (type.equals(Instruction.Type.TABLE.name())) { | 263 | } else if (type.equals(Instruction.Type.TABLE.name())) { |
262 | return Instructions.transition(nullIsIllegal(json.get(InstructionCodec.TABLE_ID) | 264 | return Instructions.transition(nullIsIllegal(json.get(InstructionCodec.TABLE_ID) |
263 | .asInt(), InstructionCodec.TABLE_ID + InstructionCodec.MISSING_MEMBER_MESSAGE)); | 265 | .asInt(), InstructionCodec.TABLE_ID + InstructionCodec.MISSING_MEMBER_MESSAGE)); |
266 | + } else if (type.equals(Instruction.Type.GROUP.name())) { | ||
267 | + GroupId groupId = new DefaultGroupId(nullIsIllegal(json.get(InstructionCodec.GROUP_ID) | ||
268 | + .asInt(), InstructionCodec.GROUP_ID + InstructionCodec.MISSING_MEMBER_MESSAGE)); | ||
269 | + return Instructions.createGroup(groupId); | ||
264 | } else if (type.equals(Instruction.Type.L0MODIFICATION.name())) { | 270 | } else if (type.equals(Instruction.Type.L0MODIFICATION.name())) { |
265 | return decodeL0(); | 271 | return decodeL0(); |
266 | } else if (type.equals(Instruction.Type.L1MODIFICATION.name())) { | 272 | } else if (type.equals(Instruction.Type.L1MODIFICATION.name())) { | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.codec.impl; | 16 | package org.onosproject.codec.impl; |
17 | 17 | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
18 | import org.onlab.util.HexString; | 19 | import org.onlab.util.HexString; |
19 | import org.onosproject.codec.CodecContext; | 20 | import org.onosproject.codec.CodecContext; |
20 | import org.onosproject.net.OchSignal; | 21 | import org.onosproject.net.OchSignal; |
... | @@ -29,8 +30,6 @@ import org.onosproject.net.flow.instructions.L4ModificationInstruction; | ... | @@ -29,8 +30,6 @@ import org.onosproject.net.flow.instructions.L4ModificationInstruction; |
29 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
30 | import org.slf4j.LoggerFactory; | 31 | import org.slf4j.LoggerFactory; |
31 | 32 | ||
32 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
33 | - | ||
34 | /** | 33 | /** |
35 | * JSON encoding of Instructions. | 34 | * JSON encoding of Instructions. |
36 | */ | 35 | */ |
... | @@ -249,6 +248,12 @@ public final class EncodeInstructionCodecHelper { | ... | @@ -249,6 +248,12 @@ public final class EncodeInstructionCodecHelper { |
249 | case NOACTION: | 248 | case NOACTION: |
250 | break; | 249 | break; |
251 | 250 | ||
251 | + case GROUP: | ||
252 | + final Instructions.GroupInstruction groupInstruction = | ||
253 | + (Instructions.GroupInstruction) instruction; | ||
254 | + result.put(InstructionCodec.GROUP_ID, groupInstruction.groupId().toString()); | ||
255 | + break; | ||
256 | + | ||
252 | case L0MODIFICATION: | 257 | case L0MODIFICATION: |
253 | encodeL0(result); | 258 | encodeL0(result); |
254 | break; | 259 | break; | ... | ... |
... | @@ -50,6 +50,7 @@ public final class InstructionCodec extends JsonCodec<Instruction> { | ... | @@ -50,6 +50,7 @@ public final class InstructionCodec extends JsonCodec<Instruction> { |
50 | protected static final String TCP_PORT = "tcpPort"; | 50 | protected static final String TCP_PORT = "tcpPort"; |
51 | protected static final String UDP_PORT = "udpPort"; | 51 | protected static final String UDP_PORT = "udpPort"; |
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 TRIBUTARY_PORT_NUMBER = "tributaryPortNumber"; | 54 | protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber"; |
54 | protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength"; | 55 | protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength"; |
55 | protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap"; | 56 | protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap"; | ... | ... |
... | @@ -15,11 +15,13 @@ | ... | @@ -15,11 +15,13 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.codec.impl; | 16 | package org.onosproject.codec.impl; |
17 | 17 | ||
18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
18 | import org.hamcrest.Description; | 19 | import org.hamcrest.Description; |
19 | import org.hamcrest.TypeSafeDiagnosingMatcher; | 20 | import org.hamcrest.TypeSafeDiagnosingMatcher; |
20 | import org.onlab.util.HexString; | 21 | import org.onlab.util.HexString; |
21 | import org.onosproject.net.OduSignalId; | 22 | import org.onosproject.net.OduSignalId; |
22 | import org.onosproject.net.flow.instructions.Instruction; | 23 | import org.onosproject.net.flow.instructions.Instruction; |
24 | +import org.onosproject.net.flow.instructions.Instructions.GroupInstruction; | ||
23 | import org.onosproject.net.flow.instructions.Instructions.NoActionInstruction; | 25 | import org.onosproject.net.flow.instructions.Instructions.NoActionInstruction; |
24 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; | 26 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
25 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; | 27 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; |
... | @@ -33,8 +35,6 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeade | ... | @@ -33,8 +35,6 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeade |
33 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; | 35 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; |
34 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; | 36 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; |
35 | 37 | ||
36 | -import com.fasterxml.jackson.databind.JsonNode; | ||
37 | - | ||
38 | /** | 38 | /** |
39 | * Hamcrest matcher for instructions. | 39 | * Hamcrest matcher for instructions. |
40 | */ | 40 | */ |
... | @@ -123,6 +123,33 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json | ... | @@ -123,6 +123,33 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json |
123 | } | 123 | } |
124 | 124 | ||
125 | /** | 125 | /** |
126 | + * Matches the contents of a group instruction. | ||
127 | + * | ||
128 | + * @param instructionJson JSON instruction to match | ||
129 | + * @param description Description object used for recording errors | ||
130 | + * @return true if contents match, false otherwise | ||
131 | + */ | ||
132 | + private boolean matchGroupInstruction(JsonNode instructionJson, | ||
133 | + Description description) { | ||
134 | + final String jsonType = instructionJson.get("type").textValue(); | ||
135 | + GroupInstruction instructionToMatch = (GroupInstruction) instruction; | ||
136 | + if (!instructionToMatch.type().name().equals(jsonType)) { | ||
137 | + description.appendText("type was " + jsonType); | ||
138 | + return false; | ||
139 | + } | ||
140 | + | ||
141 | + if (instructionJson.get("groupId").isInt()) { | ||
142 | + final int jsonGroupId = instructionJson.get("groupId").asInt(); | ||
143 | + if (instructionToMatch.groupId().id() != jsonGroupId) { | ||
144 | + description.appendText("groupId was " + jsonGroupId); | ||
145 | + return false; | ||
146 | + } | ||
147 | + } | ||
148 | + | ||
149 | + return true; | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
126 | * Matches the contents of a mod lambda instruction. | 153 | * Matches the contents of a mod lambda instruction. |
127 | * | 154 | * |
128 | * @param instructionJson JSON instruction to match | 155 | * @param instructionJson JSON instruction to match |
... | @@ -453,6 +480,8 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json | ... | @@ -453,6 +480,8 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json |
453 | return matchPushHeaderInstruction(jsonInstruction, description); | 480 | return matchPushHeaderInstruction(jsonInstruction, description); |
454 | } else if (instruction instanceof OutputInstruction) { | 481 | } else if (instruction instanceof OutputInstruction) { |
455 | return matchOutputInstruction(jsonInstruction, description); | 482 | return matchOutputInstruction(jsonInstruction, description); |
483 | + } else if (instruction instanceof GroupInstruction) { | ||
484 | + return matchGroupInstruction(jsonInstruction, description); | ||
456 | } else if (instruction instanceof ModLambdaInstruction) { | 485 | } else if (instruction instanceof ModLambdaInstruction) { |
457 | return matchModLambdaInstruction(jsonInstruction, description); | 486 | return matchModLambdaInstruction(jsonInstruction, description); |
458 | } else if (instruction instanceof ModOchSignalInstruction) { | 487 | } else if (instruction instanceof ModOchSignalInstruction) { | ... | ... |
-
Please register or login to post a comment