@Test public void testTrafficTreatmentEncode() { Instruction output = Instructions.createOutput(PortNumber.portNumber(0)); Instruction modL2Src = Instructions.modL2Src(MacAddress.valueOf("11:22:33:44:55:66")); Instruction modL2Dst = Instructions.modL2Dst(MacAddress.valueOf("44:55:66:77:88:99")); MeterId meterId = MeterId.meterId(0); Instruction meter = Instructions.meterTraffic(meterId); Instruction transition = Instructions.transition(1); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); TrafficTreatment treatment = tBuilder .add(output) .add(modL2Src) .add(modL2Dst) .add(meter) .add(transition) .build(); ObjectNode treatmentJson = trafficTreatmentCodec.encode(treatment, context); assertThat(treatmentJson, TrafficTreatmentJsonMatcher.matchesTrafficTreatment(treatment)); }
@Override public ObjectNode encode(TrafficTreatment treatment, CodecContext context) { checkNotNull(treatment, "Traffic treatment cannot be null"); final ObjectNode result = context.mapper().createObjectNode(); final ArrayNode jsonInstructions = result.putArray(INSTRUCTIONS); final JsonCodec<Instruction> instructionCodec = context.codec(Instruction.class); for (final Instruction instruction : treatment.immediate()) { jsonInstructions.add(instructionCodec.encode(instruction, context)); } if (treatment.metered() != null) { jsonInstructions.add(instructionCodec.encode(treatment.metered(), context)); } if (treatment.tableTransition() != null) { jsonInstructions.add(instructionCodec.encode(treatment.tableTransition(), context)); } final ArrayNode jsonDeferred = result.putArray("deferred"); for (final Instruction instruction : treatment.deferred()) { jsonDeferred.add(instructionCodec.encode(instruction, context)); } return result; }
TrafficTreatmentCodec extends JsonCodec<TrafficTreatment> { @Override public ObjectNode encode(TrafficTreatment treatment, CodecContext context) { checkNotNull(treatment, "Traffic treatment cannot be null"); final ObjectNode result = context.mapper().createObjectNode(); final ArrayNode jsonInstructions = result.putArray(INSTRUCTIONS); final JsonCodec<Instruction> instructionCodec = context.codec(Instruction.class); for (final Instruction instruction : treatment.immediate()) { jsonInstructions.add(instructionCodec.encode(instruction, context)); } if (treatment.metered() != null) { jsonInstructions.add(instructionCodec.encode(treatment.metered(), context)); } if (treatment.tableTransition() != null) { jsonInstructions.add(instructionCodec.encode(treatment.tableTransition(), context)); } final ArrayNode jsonDeferred = result.putArray("deferred"); for (final Instruction instruction : treatment.deferred()) { jsonDeferred.add(instructionCodec.encode(instruction, context)); } return result; } }
TrafficTreatmentCodec extends JsonCodec<TrafficTreatment> { @Override public ObjectNode encode(TrafficTreatment treatment, CodecContext context) { checkNotNull(treatment, "Traffic treatment cannot be null"); final ObjectNode result = context.mapper().createObjectNode(); final ArrayNode jsonInstructions = result.putArray(INSTRUCTIONS); final JsonCodec<Instruction> instructionCodec = context.codec(Instruction.class); for (final Instruction instruction : treatment.immediate()) { jsonInstructions.add(instructionCodec.encode(instruction, context)); } if (treatment.metered() != null) { jsonInstructions.add(instructionCodec.encode(treatment.metered(), context)); } if (treatment.tableTransition() != null) { jsonInstructions.add(instructionCodec.encode(treatment.tableTransition(), context)); } final ArrayNode jsonDeferred = result.putArray("deferred"); for (final Instruction instruction : treatment.deferred()) { jsonDeferred.add(instructionCodec.encode(instruction, context)); } return result; }  }
TrafficTreatmentCodec extends JsonCodec<TrafficTreatment> { @Override public ObjectNode encode(TrafficTreatment treatment, CodecContext context) { checkNotNull(treatment, "Traffic treatment cannot be null"); final ObjectNode result = context.mapper().createObjectNode(); final ArrayNode jsonInstructions = result.putArray(INSTRUCTIONS); final JsonCodec<Instruction> instructionCodec = context.codec(Instruction.class); for (final Instruction instruction : treatment.immediate()) { jsonInstructions.add(instructionCodec.encode(instruction, context)); } if (treatment.metered() != null) { jsonInstructions.add(instructionCodec.encode(treatment.metered(), context)); } if (treatment.tableTransition() != null) { jsonInstructions.add(instructionCodec.encode(treatment.tableTransition(), context)); } final ArrayNode jsonDeferred = result.putArray("deferred"); for (final Instruction instruction : treatment.deferred()) { jsonDeferred.add(instructionCodec.encode(instruction, context)); } return result; }  @Override ObjectNode encode(TrafficTreatment treatment, CodecContext context); @Override TrafficTreatment decode(ObjectNode json, CodecContext context); }
TrafficTreatmentCodec extends JsonCodec<TrafficTreatment> { @Override public ObjectNode encode(TrafficTreatment treatment, CodecContext context) { checkNotNull(treatment, "Traffic treatment cannot be null"); final ObjectNode result = context.mapper().createObjectNode(); final ArrayNode jsonInstructions = result.putArray(INSTRUCTIONS); final JsonCodec<Instruction> instructionCodec = context.codec(Instruction.class); for (final Instruction instruction : treatment.immediate()) { jsonInstructions.add(instructionCodec.encode(instruction, context)); } if (treatment.metered() != null) { jsonInstructions.add(instructionCodec.encode(treatment.metered(), context)); } if (treatment.tableTransition() != null) { jsonInstructions.add(instructionCodec.encode(treatment.tableTransition(), context)); } final ArrayNode jsonDeferred = result.putArray("deferred"); for (final Instruction instruction : treatment.deferred()) { jsonDeferred.add(instructionCodec.encode(instruction, context)); } return result; }  @Override ObjectNode encode(TrafficTreatment treatment, CodecContext context); @Override TrafficTreatment decode(ObjectNode json, CodecContext context);  }