Search in sources :

Example 1 with LispTeAddress

use of org.onosproject.drivers.lisp.extensions.LispTeAddress in project onos by opennetworkinglab.

the class LispTeAddressCodec method decode.

@Override
public LispTeAddress decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    final JsonCodec<LispTeAddress.TeRecord> recordCodec = context.codec(LispTeAddress.TeRecord.class);
    JsonNode recordsJson = nullIsIllegal(json.get(TE_RECORDS), TE_RECORDS + MISSING_MEMBER_MESSAGE);
    List<LispTeAddress.TeRecord> records = Lists.newArrayList();
    if (recordsJson != null) {
        IntStream.range(0, recordsJson.size()).forEach(i -> records.add(recordCodec.decode(get(recordsJson, i), context)));
    }
    return new LispTeAddress.Builder().withTeRecords(records).build();
}
Also used : LispTeAddress(org.onosproject.drivers.lisp.extensions.LispTeAddress) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with LispTeAddress

use of org.onosproject.drivers.lisp.extensions.LispTeAddress in project onos by opennetworkinglab.

the class LispTeAddressCodec method encode.

@Override
public ObjectNode encode(LispTeAddress address, CodecContext context) {
    checkNotNull(address, "LispTeAddress cannot be null");
    final ObjectNode result = context.mapper().createObjectNode();
    final ArrayNode jsonRecords = result.putArray(TE_RECORDS);
    final JsonCodec<LispTeAddress.TeRecord> recordCodec = context.codec(LispTeAddress.TeRecord.class);
    for (final LispTeAddress.TeRecord record : address.getTeRecords()) {
        jsonRecords.add(recordCodec.encode(record, context));
    }
    return result;
}
Also used : LispTeAddress(org.onosproject.drivers.lisp.extensions.LispTeAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 3 with LispTeAddress

use of org.onosproject.drivers.lisp.extensions.LispTeAddress in project onos by opennetworkinglab.

the class LispTeAddressCodecTest method getLispTeAddress.

/**
 * Reads in a LispTeAddress from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded LispTeAddress
 * @throws IOException if processing the resource fails
 */
private LispTeAddress getLispTeAddress(String resourceName) throws IOException {
    InputStream jsonStream = LispTeAddressCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    assertThat("JSON string should not be null", json, notNullValue());
    LispTeAddress teAddress = teAddressCodec.decode((ObjectNode) json, context);
    assertThat("decoded address should not be null", teAddress, notNullValue());
    return teAddress;
}
Also used : LispTeAddress(org.onosproject.drivers.lisp.extensions.LispTeAddress) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 4 with LispTeAddress

use of org.onosproject.drivers.lisp.extensions.LispTeAddress in project onos by opennetworkinglab.

the class LispTeAddressCodecTest method setUp.

/**
 * Sets up for each test.
 * Creates a context and fetches the LispTeAddress codec.
 */
@Before
public void setUp() {
    CodecManager manager = new CodecManager();
    registrator = new LispMappingExtensionCodecRegistrator();
    registrator.codecService = manager;
    registrator.activate();
    context = new LispMappingExtensionCodecContextAdapter(registrator.codecService);
    teAddressCodec = context.codec(LispTeAddress.class);
    assertThat("Traffic Engineering address codec should not be null", teAddressCodec, notNullValue());
    record1 = new LispTeAddress.TeRecord.Builder().withIsLookup(LOOKUP_1).withIsRlocProbe(RLOC_PROBE_1).withIsStrict(STRICT_1).withRtrRlocAddress(MappingAddresses.ipv4MappingAddress(IPV4_ADDRESS_1)).build();
    record2 = new LispTeAddress.TeRecord.Builder().withIsLookup(LOOKUP_2).withIsRlocProbe(RLOC_PROBE_2).withIsStrict(STRICT_2).withRtrRlocAddress(MappingAddresses.ipv4MappingAddress(IPV4_ADDRESS_2)).build();
}
Also used : LispTeAddress(org.onosproject.drivers.lisp.extensions.LispTeAddress) CodecManager(org.onosproject.codec.impl.CodecManager) LispMappingExtensionCodecRegistrator(org.onosproject.drivers.lisp.extensions.LispMappingExtensionCodecRegistrator) Before(org.junit.Before)

Example 5 with LispTeAddress

use of org.onosproject.drivers.lisp.extensions.LispTeAddress in project onos by opennetworkinglab.

the class LispTeAddressCodecTest method testLispTeAddressDecode.

/**
 * Tests decoding of a LispTeAddress JSON object.
 */
@Test
public void testLispTeAddressDecode() throws IOException {
    LispTeAddress address = getLispTeAddress("LispTeAddress.json");
    new EqualsTester().addEqualityGroup(address.getTeRecords().get(0), record1).addEqualityGroup(address.getTeRecords().get(1), record2).testEquals();
}
Also used : LispTeAddress(org.onosproject.drivers.lisp.extensions.LispTeAddress) EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Aggregations

LispTeAddress (org.onosproject.drivers.lisp.extensions.LispTeAddress)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Test (org.junit.Test)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 EqualsTester (com.google.common.testing.EqualsTester)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 CodecManager (org.onosproject.codec.impl.CodecManager)1 LispMappingExtensionCodecRegistrator (org.onosproject.drivers.lisp.extensions.LispMappingExtensionCodecRegistrator)1