Search in sources :

Example 1 with LispSegmentAddress

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

the class LispSegmentAddressCodec method decode.

@Override
public LispSegmentAddress decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    int instanceId = nullIsIllegal(json.get(INSTANCE_ID), INSTANCE_ID + MISSING_MEMBER_MESSAGE).asInt();
    ObjectNode addressJson = get(json, ADDRESS);
    MappingAddress mappingAddress = null;
    if (addressJson != null) {
        final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
        mappingAddress = addressCodec.decode(addressJson, context);
    }
    return new LispSegmentAddress.Builder().withInstanceId(instanceId).withAddress(mappingAddress).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) LispSegmentAddress(org.onosproject.drivers.lisp.extensions.LispSegmentAddress)

Example 2 with LispSegmentAddress

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

the class LispSegmentAddressCodecTest method setUp.

/**
 * Sets up for each test.
 * Creates a context and fetches the LispSegmentAddress codec.
 */
@Before
public void setUp() {
    CodecManager manager = new CodecManager();
    registrator = new LispMappingExtensionCodecRegistrator();
    registrator.codecService = manager;
    registrator.activate();
    context = new LispMappingExtensionCodecContextAdapter(registrator.codecService);
    segmentAddressCodec = context.codec(LispSegmentAddress.class);
    assertThat("segment address codec should not be null", segmentAddressCodec, notNullValue());
}
Also used : LispSegmentAddress(org.onosproject.drivers.lisp.extensions.LispSegmentAddress) CodecManager(org.onosproject.codec.impl.CodecManager) LispMappingExtensionCodecRegistrator(org.onosproject.drivers.lisp.extensions.LispMappingExtensionCodecRegistrator) Before(org.junit.Before)

Example 3 with LispSegmentAddress

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

the class LispSegmentAddressCodecTest method testLispSegmentAddressDecode.

/**
 * Tests decoding of a LispSegmentAddress JSON object.
 */
@Test
public void testLispSegmentAddressDecode() throws IOException {
    LispSegmentAddress address = getLispSegmentAddress("LispSegmentAddress.json");
    assertThat("incorrect instance ID", address.getInstanceId(), is(INSTANCE_ID));
    assertThat("incorrect mapping address", address.getAddress(), is(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX)));
}
Also used : LispSegmentAddress(org.onosproject.drivers.lisp.extensions.LispSegmentAddress) Test(org.junit.Test)

Example 4 with LispSegmentAddress

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

the class LispSegmentAddressCodecTest method getLispSegmentAddress.

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

Example 5 with LispSegmentAddress

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

the class LispSegmentAddressCodecTest method testLispSegmentAddressEncode.

/**
 * Tests encoding of a LispSegmentAddress object.
 */
@Test
public void testLispSegmentAddressEncode() {
    LispSegmentAddress address = new LispSegmentAddress.Builder().withInstanceId(INSTANCE_ID).withAddress(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX)).build();
    ObjectNode addressJson = segmentAddressCodec.encode(address, context);
    assertThat("errors in encoding segment address JSON", addressJson, LispSegmentAddressJsonMatcher.matchesSegmentAddress(address));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LispSegmentAddress(org.onosproject.drivers.lisp.extensions.LispSegmentAddress) Test(org.junit.Test)

Aggregations

LispSegmentAddress (org.onosproject.drivers.lisp.extensions.LispSegmentAddress)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)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 MappingAddress (org.onosproject.mapping.addresses.MappingAddress)1