use of org.onosproject.mapping.instructions.MappingInstruction in project onos by opennetworkinglab.
the class MappingInstructionCodecTest method getInstruction.
/**
* Reads in a mapping instruction from the given resource and decodes it.
*
* @param resourceName resource to use to read the JSON for the rule
* @return decoded mappingInstruction
* @throws IOException if processing the resource fails
*/
private MappingInstruction getInstruction(String resourceName) throws IOException {
InputStream jsonStream = MappingInstructionCodecTest.class.getResourceAsStream(resourceName);
JsonNode json = context.mapper().readTree(jsonStream);
assertThat(json, notNullValue());
MappingInstruction instruction = instructionCodec.decode((ObjectNode) json, context);
assertThat(instruction, notNullValue());
return instruction;
}
use of org.onosproject.mapping.instructions.MappingInstruction in project onos by opennetworkinglab.
the class MappingTreatmentCodec method decode.
@Override
public MappingTreatment decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
final JsonCodec<MappingInstruction> instructionCodec = context.codec(MappingInstruction.class);
JsonNode instructionJson = json.get(INSTRUCTIONS);
MappingTreatment.Builder builder = DefaultMappingTreatment.builder();
if (instructionJson != null) {
IntStream.range(0, instructionJson.size()).forEach(i -> builder.add(instructionCodec.decode(get(instructionJson, i), context)));
}
ObjectNode addressJson = get(json, ADDRESS);
if (addressJson != null) {
final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
builder.withAddress(addressCodec.decode(addressJson, context));
}
return builder.build();
}
use of org.onosproject.mapping.instructions.MappingInstruction in project onos by opennetworkinglab.
the class MappingTreatmentCodec method encode.
@Override
public ObjectNode encode(MappingTreatment treatment, CodecContext context) {
checkNotNull(treatment, "Mapping treatment cannot be null");
final ObjectNode result = context.mapper().createObjectNode();
final ArrayNode jsonInstructions = result.putArray(INSTRUCTIONS);
final JsonCodec<MappingInstruction> instructionCodec = context.codec(MappingInstruction.class);
final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
for (final MappingInstruction instruction : treatment.instructions()) {
jsonInstructions.add(instructionCodec.encode(instruction, context));
}
result.set(ADDRESS, addressCodec.encode(treatment.address(), context));
return result;
}
Aggregations