Search in sources :

Example 11 with MappingTreatment

use of org.onosproject.mapping.MappingTreatment 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 12 with MappingTreatment

use of org.onosproject.mapping.MappingTreatment in project onos by opennetworkinglab.

the class MappingValueCodec method encode.

@Override
public ObjectNode encode(MappingValue value, CodecContext context) {
    checkNotNull(value, "Mapping value cannot be null");
    final ObjectNode result = context.mapper().createObjectNode();
    final ArrayNode jsonTreatments = result.putArray(TREATMENTS);
    final JsonCodec<MappingTreatment> treatmentCodec = context.codec(MappingTreatment.class);
    final JsonCodec<MappingAction> actionCodec = context.codec(MappingAction.class);
    for (final MappingTreatment treatment : value.treatments()) {
        jsonTreatments.add(treatmentCodec.encode(treatment, context));
    }
    result.set(ACTION, actionCodec.encode(value.action(), context));
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAction(org.onosproject.mapping.actions.MappingAction) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MappingTreatment(org.onosproject.mapping.MappingTreatment)

Aggregations

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