Committed by
Gerrit Code Review
Support to encode and decode meter id in InstructionCodec
Change-Id: Icdac264b81a9f6edf93198cc5e729521601cbe49
Showing
4 changed files
with
61 additions
and
22 deletions
... | @@ -37,6 +37,7 @@ import org.onosproject.net.flow.instructions.L1ModificationInstruction; | ... | @@ -37,6 +37,7 @@ import org.onosproject.net.flow.instructions.L1ModificationInstruction; |
37 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; | 37 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
38 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; | 38 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
39 | import org.onosproject.net.flow.instructions.L4ModificationInstruction; | 39 | import org.onosproject.net.flow.instructions.L4ModificationInstruction; |
40 | +import org.onosproject.net.meter.MeterId; | ||
40 | 41 | ||
41 | import static org.onlab.util.Tools.nullIsIllegal; | 42 | import static org.onlab.util.Tools.nullIsIllegal; |
42 | 43 | ||
... | @@ -267,6 +268,10 @@ public final class DecodeInstructionCodecHelper { | ... | @@ -267,6 +268,10 @@ public final class DecodeInstructionCodecHelper { |
267 | GroupId groupId = new DefaultGroupId(nullIsIllegal(json.get(InstructionCodec.GROUP_ID) | 268 | GroupId groupId = new DefaultGroupId(nullIsIllegal(json.get(InstructionCodec.GROUP_ID) |
268 | .asInt(), InstructionCodec.GROUP_ID + InstructionCodec.MISSING_MEMBER_MESSAGE)); | 269 | .asInt(), InstructionCodec.GROUP_ID + InstructionCodec.MISSING_MEMBER_MESSAGE)); |
269 | return Instructions.createGroup(groupId); | 270 | return Instructions.createGroup(groupId); |
271 | + } else if (type.equals(Instruction.Type.METER.name())) { | ||
272 | + MeterId meterId = MeterId.meterId(nullIsIllegal(json.get(InstructionCodec.METER_ID) | ||
273 | + .asLong(), InstructionCodec.METER_ID + InstructionCodec.MISSING_MEMBER_MESSAGE)); | ||
274 | + return Instructions.meterTraffic(meterId); | ||
270 | } else if (type.equals(Instruction.Type.L0MODIFICATION.name())) { | 275 | } else if (type.equals(Instruction.Type.L0MODIFICATION.name())) { |
271 | return decodeL0(); | 276 | return decodeL0(); |
272 | } else if (type.equals(Instruction.Type.L1MODIFICATION.name())) { | 277 | } else if (type.equals(Instruction.Type.L1MODIFICATION.name())) { | ... | ... |
... | @@ -42,7 +42,7 @@ public final class EncodeInstructionCodecHelper { | ... | @@ -42,7 +42,7 @@ public final class EncodeInstructionCodecHelper { |
42 | * Creates an instruction object encoder. | 42 | * Creates an instruction object encoder. |
43 | * | 43 | * |
44 | * @param instruction instruction to encode | 44 | * @param instruction instruction to encode |
45 | - * @param context codec context for the encoding | 45 | + * @param context codec context for the encoding |
46 | */ | 46 | */ |
47 | public EncodeInstructionCodecHelper(Instruction instruction, CodecContext context) { | 47 | public EncodeInstructionCodecHelper(Instruction instruction, CodecContext context) { |
48 | this.instruction = instruction; | 48 | this.instruction = instruction; |
... | @@ -93,20 +93,21 @@ public final class EncodeInstructionCodecHelper { | ... | @@ -93,20 +93,21 @@ public final class EncodeInstructionCodecHelper { |
93 | result.put(InstructionCodec.SUBTYPE, instruction.subtype().name()); | 93 | result.put(InstructionCodec.SUBTYPE, instruction.subtype().name()); |
94 | 94 | ||
95 | switch (instruction.subtype()) { | 95 | switch (instruction.subtype()) { |
96 | - case ODU_SIGID: | 96 | + case ODU_SIGID: |
97 | - final L1ModificationInstruction.ModOduSignalIdInstruction oduSignalIdInstruction = | 97 | + final L1ModificationInstruction.ModOduSignalIdInstruction oduSignalIdInstruction = |
98 | - (L1ModificationInstruction.ModOduSignalIdInstruction) instruction; | 98 | + (L1ModificationInstruction.ModOduSignalIdInstruction) instruction; |
99 | - OduSignalId oduSignalId = oduSignalIdInstruction.oduSignalId(); | 99 | + OduSignalId oduSignalId = oduSignalIdInstruction.oduSignalId(); |
100 | - | 100 | + |
101 | - ObjectNode child = result.putObject("oduSignalId"); | 101 | + ObjectNode child = result.putObject("oduSignalId"); |
102 | - | 102 | + |
103 | - child.put(InstructionCodec.TRIBUTARY_PORT_NUMBER, oduSignalId.tributaryPortNumber()); | 103 | + child.put(InstructionCodec.TRIBUTARY_PORT_NUMBER, oduSignalId.tributaryPortNumber()); |
104 | - child.put(InstructionCodec.TRIBUTARY_SLOT_LEN, oduSignalId.tributarySlotLength()); | 104 | + child.put(InstructionCodec.TRIBUTARY_SLOT_LEN, oduSignalId.tributarySlotLength()); |
105 | - child.put(InstructionCodec.TRIBUTARY_SLOT_BITMAP, HexString.toHexString(oduSignalId.tributarySlotBitmap())); | 105 | + child.put(InstructionCodec.TRIBUTARY_SLOT_BITMAP, |
106 | - break; | 106 | + HexString.toHexString(oduSignalId.tributarySlotBitmap())); |
107 | - default: | 107 | + break; |
108 | - log.info("Cannot convert L1 subtype of {}", instruction.subtype()); | 108 | + default: |
109 | - break; | 109 | + log.info("Cannot convert L1 subtype of {}", instruction.subtype()); |
110 | + break; | ||
110 | } | 111 | } |
111 | } | 112 | } |
112 | 113 | ||
... | @@ -151,7 +152,7 @@ public final class EncodeInstructionCodecHelper { | ... | @@ -151,7 +152,7 @@ public final class EncodeInstructionCodecHelper { |
151 | (L2ModificationInstruction.PushHeaderInstructions) instruction; | 152 | (L2ModificationInstruction.PushHeaderInstructions) instruction; |
152 | 153 | ||
153 | result.put(InstructionCodec.ETHERNET_TYPE, | 154 | result.put(InstructionCodec.ETHERNET_TYPE, |
154 | - pushHeaderInstructions.ethernetType().toShort()); | 155 | + pushHeaderInstructions.ethernetType().toShort()); |
155 | break; | 156 | break; |
156 | 157 | ||
157 | case TUNNEL_ID: | 158 | case TUNNEL_ID: |
... | @@ -254,6 +255,12 @@ public final class EncodeInstructionCodecHelper { | ... | @@ -254,6 +255,12 @@ public final class EncodeInstructionCodecHelper { |
254 | result.put(InstructionCodec.GROUP_ID, groupInstruction.groupId().toString()); | 255 | result.put(InstructionCodec.GROUP_ID, groupInstruction.groupId().toString()); |
255 | break; | 256 | break; |
256 | 257 | ||
258 | + case METER: | ||
259 | + final Instructions.MeterInstruction meterInstruction = | ||
260 | + (Instructions.MeterInstruction) instruction; | ||
261 | + result.put(InstructionCodec.METER_ID, meterInstruction.meterId().toString()); | ||
262 | + break; | ||
263 | + | ||
257 | case L0MODIFICATION: | 264 | case L0MODIFICATION: |
258 | encodeL0(result); | 265 | encodeL0(result); |
259 | break; | 266 | break; | ... | ... |
... | @@ -51,6 +51,7 @@ public final class InstructionCodec extends JsonCodec<Instruction> { | ... | @@ -51,6 +51,7 @@ public final class InstructionCodec extends JsonCodec<Instruction> { |
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 GROUP_ID = "groupId"; |
54 | + protected static final String METER_ID = "meterId"; | ||
54 | protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber"; | 55 | protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber"; |
55 | protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength"; | 56 | protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength"; |
56 | protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap"; | 57 | protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap"; | ... | ... |
... | @@ -22,6 +22,7 @@ import org.onlab.util.HexString; | ... | @@ -22,6 +22,7 @@ import org.onlab.util.HexString; |
22 | import org.onosproject.net.OduSignalId; | 22 | import org.onosproject.net.OduSignalId; |
23 | import org.onosproject.net.flow.instructions.Instruction; | 23 | import org.onosproject.net.flow.instructions.Instruction; |
24 | import org.onosproject.net.flow.instructions.Instructions.GroupInstruction; | 24 | 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.NoActionInstruction; | 26 | import org.onosproject.net.flow.instructions.Instructions.NoActionInstruction; |
26 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; | 27 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
27 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; | 28 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; |
... | @@ -138,12 +139,35 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json | ... | @@ -138,12 +139,35 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json |
138 | return false; | 139 | return false; |
139 | } | 140 | } |
140 | 141 | ||
141 | - if (instructionJson.get("groupId").isInt()) { | 142 | + final int jsonGroupId = instructionJson.get("groupId").intValue(); |
142 | - final int jsonGroupId = instructionJson.get("groupId").asInt(); | 143 | + if (instructionToMatch.groupId().id() != jsonGroupId) { |
143 | - if (instructionToMatch.groupId().id() != jsonGroupId) { | 144 | + description.appendText("groupId was " + jsonGroupId); |
144 | - description.appendText("groupId was " + jsonGroupId); | 145 | + return false; |
145 | - return false; | 146 | + } |
146 | - } | 147 | + |
148 | + return true; | ||
149 | + } | ||
150 | + | ||
151 | + /** | ||
152 | + * Matches the contents of a meter instruction. | ||
153 | + * | ||
154 | + * @param instructionJson JSON instruction to match | ||
155 | + * @param description Description object used for recording errors | ||
156 | + * @return true if contents match, false otherwise | ||
157 | + */ | ||
158 | + private boolean matchMeterInstruction(JsonNode instructionJson, | ||
159 | + Description description) { | ||
160 | + final String jsonType = instructionJson.get("type").textValue(); | ||
161 | + MeterInstruction instructionToMatch = (MeterInstruction) instruction; | ||
162 | + if (!instructionToMatch.type().name().equals(jsonType)) { | ||
163 | + description.appendText("type was " + jsonType); | ||
164 | + return false; | ||
165 | + } | ||
166 | + | ||
167 | + final long jsonMeterId = instructionJson.get("meterId").longValue(); | ||
168 | + if (instructionToMatch.meterId().id() != jsonMeterId) { | ||
169 | + description.appendText("meterId was " + jsonMeterId); | ||
170 | + return false; | ||
147 | } | 171 | } |
148 | 172 | ||
149 | return true; | 173 | return true; |
... | @@ -482,6 +506,8 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json | ... | @@ -482,6 +506,8 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json |
482 | return matchOutputInstruction(jsonInstruction, description); | 506 | return matchOutputInstruction(jsonInstruction, description); |
483 | } else if (instruction instanceof GroupInstruction) { | 507 | } else if (instruction instanceof GroupInstruction) { |
484 | return matchGroupInstruction(jsonInstruction, description); | 508 | return matchGroupInstruction(jsonInstruction, description); |
509 | + } else if (instruction instanceof MeterInstruction) { | ||
510 | + return matchMeterInstruction(jsonInstruction, description); | ||
485 | } else if (instruction instanceof ModLambdaInstruction) { | 511 | } else if (instruction instanceof ModLambdaInstruction) { |
486 | return matchModLambdaInstruction(jsonInstruction, description); | 512 | return matchModLambdaInstruction(jsonInstruction, description); |
487 | } else if (instruction instanceof ModOchSignalInstruction) { | 513 | } else if (instruction instanceof ModOchSignalInstruction) { | ... | ... |
-
Please register or login to post a comment