Search in sources :

Example 6 with MappingInstruction

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;
}
Also used : InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) MulticastMappingInstruction(org.onosproject.mapping.instructions.MulticastMappingInstruction) MappingInstruction(org.onosproject.mapping.instructions.MappingInstruction) UnicastMappingInstruction(org.onosproject.mapping.instructions.UnicastMappingInstruction)

Example 7 with MappingInstruction

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultMappingTreatment(org.onosproject.mapping.DefaultMappingTreatment) MappingTreatment(org.onosproject.mapping.MappingTreatment) MappingInstruction(org.onosproject.mapping.instructions.MappingInstruction)

Example 8 with MappingInstruction

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MappingInstruction(org.onosproject.mapping.instructions.MappingInstruction)

Aggregations

MappingInstruction (org.onosproject.mapping.instructions.MappingInstruction)8 DefaultMappingTreatment (org.onosproject.mapping.DefaultMappingTreatment)6 MappingTreatment (org.onosproject.mapping.MappingTreatment)6 MappingAddress (org.onosproject.mapping.addresses.MappingAddress)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 Test (org.junit.Test)4 DefaultMappingValue (org.onosproject.mapping.DefaultMappingValue)3 MappingValue (org.onosproject.mapping.MappingValue)3 MappingAction (org.onosproject.mapping.actions.MappingAction)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 DefaultMappingKey (org.onosproject.mapping.DefaultMappingKey)2 MappingEntry (org.onosproject.mapping.MappingEntry)2 MappingKey (org.onosproject.mapping.MappingKey)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 InputStream (java.io.InputStream)1 DefaultMapping (org.onosproject.mapping.DefaultMapping)1 DefaultMappingEntry (org.onosproject.mapping.DefaultMappingEntry)1 Mapping (org.onosproject.mapping.Mapping)1 MulticastMappingInstruction (org.onosproject.mapping.instructions.MulticastMappingInstruction)1 UnicastMappingInstruction (org.onosproject.mapping.instructions.UnicastMappingInstruction)1