use of org.onosproject.mapping.MappingTreatment in project onos by opennetworkinglab.
the class MappingValueCodec method decode.
@Override
public MappingValue decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
final JsonCodec<MappingTreatment> treatmentCodec = context.codec(MappingTreatment.class);
JsonNode treatmentJson = json.get(TREATMENTS);
MappingValue.Builder builder = DefaultMappingValue.builder();
if (treatmentJson != null) {
IntStream.range(0, treatmentJson.size()).forEach(i -> builder.add(treatmentCodec.decode(get(treatmentJson, i), context)));
}
ObjectNode actionJson = get(json, ACTION);
if (actionJson != null) {
final JsonCodec<MappingAction> actionCodec = context.codec(MappingAction.class);
builder.withAction(actionCodec.decode(actionJson, context));
}
return builder.build();
}
use of org.onosproject.mapping.MappingTreatment in project onos by opennetworkinglab.
the class MappingValueCodecTest method testMappingValueEncode.
/**
* Tests encoding of a mapping value object.
*/
@Test
public void testMappingValueEncode() {
MappingInstruction unicastWeight = MappingInstructions.unicastWeight(UNICAST_WEIGHT);
MappingInstruction unicastPriority = MappingInstructions.unicastPriority(UNICAST_PRIORITY);
MappingInstruction multicastWeight = MappingInstructions.multicastWeight(MULTICAST_WEIGHT);
MappingInstruction multicastPriority = MappingInstructions.multicastPriority(MULTICAST_PRIORITY);
MappingAddress address = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX);
MappingTreatment treatment = DefaultMappingTreatment.builder().add(unicastWeight).add(unicastPriority).add(multicastWeight).add(multicastPriority).withAddress(address).build();
MappingAction action = MappingActions.noAction();
MappingValue value = DefaultMappingValue.builder().add(treatment).withAction(action).build();
ObjectNode valueJson = valueCodec.encode(value, context);
assertThat(valueJson, MappingValueJsonMatcher.matchesMappingValue(value));
}
use of org.onosproject.mapping.MappingTreatment in project onos by opennetworkinglab.
the class MappingTreatmentCodecTest method testMappingTreatmentEncode.
/**
* Tests encoding of a mapping treatment object.
*/
@Test
public void testMappingTreatmentEncode() {
MappingInstruction unicastWeight = MappingInstructions.unicastWeight(UNICAST_WEIGHT);
MappingInstruction unicastPriority = MappingInstructions.unicastPriority(UNICAST_PRIORITY);
MappingInstruction multicastWeight = MappingInstructions.multicastWeight(MULTICAST_WEIGHT);
MappingInstruction multicastPriority = MappingInstructions.multicastPriority(MULTICAST_PRIORITY);
MappingAddress address = MappingAddresses.asMappingAddress(ASN_NUMBER);
MappingTreatment treatment = DefaultMappingTreatment.builder().add(unicastWeight).add(unicastPriority).add(multicastWeight).add(multicastPriority).withAddress(address).build();
ObjectNode treatmentJson = treatmentCodec.encode(treatment, context);
assertThat(treatmentJson, MappingTreatmentJsonMatcher.matchesMappingTreatment(treatment));
}
use of org.onosproject.mapping.MappingTreatment in project onos by opennetworkinglab.
the class MappingTreatmentCodecTest method testMappingTreatmentDecode.
/**
* Tests decoding of a mapping treatment JSON object.
*/
@Test
public void testMappingTreatmentDecode() throws IOException {
MappingTreatment treatment = getTreatment("MappingTreatment.json");
List<MappingInstruction> insts = treatment.instructions();
assertThat(insts.size(), is(2));
ImmutableSet<String> types = ImmutableSet.of("UNICAST", "MULTICAST");
assertThat(types.contains(insts.get(0).type().name()), is(true));
assertThat(types.contains(insts.get(1).type().name()), is(true));
}
use of org.onosproject.mapping.MappingTreatment in project onos by opennetworkinglab.
the class MappingsWebResourceTest method setupMockMappings.
/**
* Populates some mappings used as testing data.
*/
private void setupMockMappings() {
MappingAddress address1 = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX_1);
MappingAddress address2 = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX_2);
MappingInstruction unicastWeight1 = unicastWeight(UNICAST_WEIGHT);
MappingInstruction unicastPriority1 = unicastPriority(UNICAST_PRIORITY);
MappingInstruction multicastWeight1 = multicastWeight(MULTICAST_WEIGHT);
MappingInstruction multicastPriority1 = multicastPriority(MULTICAST_PRIORITY);
MappingInstruction unicastWeight2 = unicastWeight(UNICAST_WEIGHT + DIFF_VALUE);
MappingInstruction unicastPriority2 = unicastPriority(UNICAST_PRIORITY + DIFF_VALUE);
MappingInstruction multicastWeight2 = multicastWeight(MULTICAST_WEIGHT + DIFF_VALUE);
MappingInstruction multicastPriority2 = multicastPriority(MULTICAST_PRIORITY + DIFF_VALUE);
MappingKey key1 = DefaultMappingKey.builder().withAddress(address1).build();
MappingTreatment treatment1 = DefaultMappingTreatment.builder().add(unicastWeight1).add(unicastPriority1).add(multicastWeight1).add(multicastPriority1).withAddress(address1).build();
MappingAction action1 = MappingActions.noAction();
MappingValue value1 = DefaultMappingValue.builder().add(treatment1).withAction(action1).build();
MappingKey key2 = DefaultMappingKey.builder().withAddress(address2).build();
MappingTreatment treatment2 = DefaultMappingTreatment.builder().add(unicastWeight2).add(unicastPriority2).add(multicastWeight2).add(multicastPriority2).withAddress(address2).build();
MappingAction action2 = MappingActions.forward();
MappingValue value2 = DefaultMappingValue.builder().add(treatment2).withAction(action2).build();
mapping1.key = key1;
mapping2.key = key2;
mapping3.key = key1;
mapping4.key = key2;
mapping1.value = value1;
mapping2.value = value2;
mapping3.value = value1;
mapping4.value = value2;
final Set<MappingEntry> mappings1 = Sets.newHashSet();
mappings1.add(mapping1);
mappings1.add(mapping2);
final Set<MappingEntry> mappings2 = Sets.newHashSet();
mappings2.add(mapping3);
mappings2.add(mapping4);
mappings.put(deviceId1, mappings1);
mappings.put(deviceId2, mappings2);
}
Aggregations