@Test public void testForwardingObjectiveEncode() { Criterion criterion1 = Criteria.matchVlanId(VlanId.ANY); Criterion criterion2 = Criteria.matchEthType((short) 0x8844); TrafficSelector selector = DefaultTrafficSelector.builder() .add(criterion1) .add(criterion2) .build(); ForwardingObjective forwardingObj = DefaultForwardingObjective.builder() .makePermanent() .fromApp(APP_ID) .withPriority(60) .withFlag(ForwardingObjective.Flag.SPECIFIC) .nextStep(1) .withSelector(selector) .add(); ObjectNode forwardingObjJson = forwardingObjectiveCodec.encode(forwardingObj, context); assertThat(forwardingObjJson, matchesForwardingObjective(forwardingObj)); }
@Override public ObjectNode encode(ForwardingObjective forwardingObjective, CodecContext context) { checkNotNull(forwardingObjective, NOT_NULL_MESSAGE); final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class); final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class); ObjectiveCodecHelper och = new ObjectiveCodecHelper(); ObjectNode result = och.encode(forwardingObjective, context); result.put(ID, forwardingObjective.id()); result.put(FLAG, forwardingObjective.flag().toString()); result.put(OPERATION, forwardingObjective.op().toString()); ObjectNode trafficSelectorNode = trafficSelectorCodec.encode(forwardingObjective.selector(), context); result.set(SELECTOR, trafficSelectorNode); if (forwardingObjective.nextId() != null) { result.put(NEXT_ID, forwardingObjective.nextId()); } if (forwardingObjective.treatment() != null) { ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(forwardingObjective.treatment(), context); result.set(TREATMENT, trafficTreatmentNode); } return result; }
ForwardingObjectiveCodec extends JsonCodec<ForwardingObjective> { @Override public ObjectNode encode(ForwardingObjective forwardingObjective, CodecContext context) { checkNotNull(forwardingObjective, NOT_NULL_MESSAGE); final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class); final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class); ObjectiveCodecHelper och = new ObjectiveCodecHelper(); ObjectNode result = och.encode(forwardingObjective, context); result.put(ID, forwardingObjective.id()); result.put(FLAG, forwardingObjective.flag().toString()); result.put(OPERATION, forwardingObjective.op().toString()); ObjectNode trafficSelectorNode = trafficSelectorCodec.encode(forwardingObjective.selector(), context); result.set(SELECTOR, trafficSelectorNode); if (forwardingObjective.nextId() != null) { result.put(NEXT_ID, forwardingObjective.nextId()); } if (forwardingObjective.treatment() != null) { ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(forwardingObjective.treatment(), context); result.set(TREATMENT, trafficTreatmentNode); } return result; } }
ForwardingObjectiveCodec extends JsonCodec<ForwardingObjective> { @Override public ObjectNode encode(ForwardingObjective forwardingObjective, CodecContext context) { checkNotNull(forwardingObjective, NOT_NULL_MESSAGE); final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class); final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class); ObjectiveCodecHelper och = new ObjectiveCodecHelper(); ObjectNode result = och.encode(forwardingObjective, context); result.put(ID, forwardingObjective.id()); result.put(FLAG, forwardingObjective.flag().toString()); result.put(OPERATION, forwardingObjective.op().toString()); ObjectNode trafficSelectorNode = trafficSelectorCodec.encode(forwardingObjective.selector(), context); result.set(SELECTOR, trafficSelectorNode); if (forwardingObjective.nextId() != null) { result.put(NEXT_ID, forwardingObjective.nextId()); } if (forwardingObjective.treatment() != null) { ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(forwardingObjective.treatment(), context); result.set(TREATMENT, trafficTreatmentNode); } return result; }  }
ForwardingObjectiveCodec extends JsonCodec<ForwardingObjective> { @Override public ObjectNode encode(ForwardingObjective forwardingObjective, CodecContext context) { checkNotNull(forwardingObjective, NOT_NULL_MESSAGE); final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class); final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class); ObjectiveCodecHelper och = new ObjectiveCodecHelper(); ObjectNode result = och.encode(forwardingObjective, context); result.put(ID, forwardingObjective.id()); result.put(FLAG, forwardingObjective.flag().toString()); result.put(OPERATION, forwardingObjective.op().toString()); ObjectNode trafficSelectorNode = trafficSelectorCodec.encode(forwardingObjective.selector(), context); result.set(SELECTOR, trafficSelectorNode); if (forwardingObjective.nextId() != null) { result.put(NEXT_ID, forwardingObjective.nextId()); } if (forwardingObjective.treatment() != null) { ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(forwardingObjective.treatment(), context); result.set(TREATMENT, trafficTreatmentNode); } return result; }  @Override ObjectNode encode(ForwardingObjective forwardingObjective, CodecContext context); @Override ForwardingObjective decode(ObjectNode json, CodecContext context); }
ForwardingObjectiveCodec extends JsonCodec<ForwardingObjective> { @Override public ObjectNode encode(ForwardingObjective forwardingObjective, CodecContext context) { checkNotNull(forwardingObjective, NOT_NULL_MESSAGE); final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class); final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class); ObjectiveCodecHelper och = new ObjectiveCodecHelper(); ObjectNode result = och.encode(forwardingObjective, context); result.put(ID, forwardingObjective.id()); result.put(FLAG, forwardingObjective.flag().toString()); result.put(OPERATION, forwardingObjective.op().toString()); ObjectNode trafficSelectorNode = trafficSelectorCodec.encode(forwardingObjective.selector(), context); result.set(SELECTOR, trafficSelectorNode); if (forwardingObjective.nextId() != null) { result.put(NEXT_ID, forwardingObjective.nextId()); } if (forwardingObjective.treatment() != null) { ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(forwardingObjective.treatment(), context); result.set(TREATMENT, trafficTreatmentNode); } return result; }  @Override ObjectNode encode(ForwardingObjective forwardingObjective, CodecContext context); @Override ForwardingObjective decode(ObjectNode json, CodecContext context); static final String REST_APP_ID; }