Search in sources :

Example 1 with UnicastMappingInstruction

use of org.onosproject.mapping.instructions.UnicastMappingInstruction in project onos by opennetworkinglab.

the class MappingInstructionCodecTest method testMappingInstructionDecode.

/**
 * Tests the decoding of mapping instruction from JSON object.
 *
 * @throws IOException if processing the resource fails
 */
@Test
public void testMappingInstructionDecode() throws IOException {
    UnicastMappingInstruction instruction = (UnicastMappingInstruction) getInstruction("MappingInstruction.json");
    assertThat(instruction.type().toString(), is(UNICAST_TYPE_STRING));
    assertThat(instruction.subtype().toString(), is(WEIGHT_SUBTYPE_STRING));
}
Also used : UnicastMappingInstruction(org.onosproject.mapping.instructions.UnicastMappingInstruction) Test(org.junit.Test)

Example 2 with UnicastMappingInstruction

use of org.onosproject.mapping.instructions.UnicastMappingInstruction in project onos by opennetworkinglab.

the class EncodeMappingInstructionCodecHelper method encodeUnicast.

/**
 * Encodes an unicast mapping instruction.
 *
 * @param result json node that the mapping instruction
 *               attributes are added to
 */
private void encodeUnicast(ObjectNode result) {
    UnicastMappingInstruction unicastInstruction = (UnicastMappingInstruction) instruction;
    result.put(MappingInstructionCodec.SUBTYPE, unicastInstruction.subtype().name());
    switch(unicastInstruction.subtype()) {
        case WEIGHT:
            UnicastMappingInstruction.WeightMappingInstruction wmi = (UnicastMappingInstruction.WeightMappingInstruction) unicastInstruction;
            result.put(MappingInstructionCodec.UNICAST_WEIGHT, wmi.weight());
            break;
        case PRIORITY:
            UnicastMappingInstruction.PriorityMappingInstruction pmi = (UnicastMappingInstruction.PriorityMappingInstruction) unicastInstruction;
            result.put(MappingInstructionCodec.UNICAST_PRIORITY, pmi.priority());
            break;
        default:
            log.info("Cannot convert unicast subtype of {}", unicastInstruction.subtype());
    }
}
Also used : UnicastMappingInstruction(org.onosproject.mapping.instructions.UnicastMappingInstruction)

Aggregations

UnicastMappingInstruction (org.onosproject.mapping.instructions.UnicastMappingInstruction)2 Test (org.junit.Test)1