Search in sources :

Example 1 with LispSrcDstAddress

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

the class LispSrcDstAddressCodec method decode.

@Override
public LispSrcDstAddress decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    byte srcMaskLength = (byte) nullIsIllegal(json.get(SRC_MASK_LENGTH), SRC_MASK_LENGTH + MISSING_MEMBER_MESSAGE).asInt();
    byte dstMaskLength = (byte) nullIsIllegal(json.get(DST_MASK_LENGTH), DST_MASK_LENGTH + MISSING_MEMBER_MESSAGE).asInt();
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    ObjectNode srcPrefixJson = get(json, SRC_PREFIX);
    MappingAddress srcPrefix = null;
    ObjectNode dstPrefixJson = get(json, DST_PREFIX);
    MappingAddress dstPrefix = null;
    if (srcPrefixJson != null) {
        srcPrefix = addressCodec.decode(srcPrefixJson, context);
    }
    if (dstPrefixJson != null) {
        dstPrefix = addressCodec.decode(dstPrefixJson, context);
    }
    return new LispSrcDstAddress.Builder().withSrcMaskLength(srcMaskLength).withDstMaskLength(dstMaskLength).withSrcPrefix(srcPrefix).withDstPrefix(dstPrefix).build();
}
Also used : LispSrcDstAddress(org.onosproject.drivers.lisp.extensions.LispSrcDstAddress) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 2 with LispSrcDstAddress

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

the class LispSrcDstAddressCodecTest method setUp.

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

Example 3 with LispSrcDstAddress

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

the class LispSrcDstAddressCodecTest method getLispSrcDstAddress.

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

Example 4 with LispSrcDstAddress

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

the class LispSrcDstAddressCodecTest method testLispSrcDstAddressDecode.

/**
 * Tests decoding of a LispSrcDstAddress JSON object.
 */
@Test
public void testLispSrcDstAddressDecode() throws IOException {
    LispSrcDstAddress address = getLispSrcDstAddress("LispSrcDstAddress.json");
    assertThat("incorrect srcMaskLength", address.getSrcMaskLength(), is(SRC_MASK_LENGTH));
    assertThat("incorrect dstMaskLength", address.getDstMaskLength(), is(DST_MASK_LENGTH));
    assertThat("incorrect srcPrefix", address.getSrcPrefix(), is(MappingAddresses.ipv4MappingAddress(IPV4_SRC_PREFIX)));
    assertThat("incorrect dstPrefix", address.getDstPrefix(), is(MappingAddresses.ipv4MappingAddress(IPV4_DST_PREFIX)));
}
Also used : LispSrcDstAddress(org.onosproject.drivers.lisp.extensions.LispSrcDstAddress) Test(org.junit.Test)

Example 5 with LispSrcDstAddress

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

the class LispSrcDstAddressCodecTest method testLispSrcDstAddressEncode.

/**
 * Tests encoding of a LispSrcDstAddress object.
 */
@Test
public void testLispSrcDstAddressEncode() {
    LispSrcDstAddress address = new LispSrcDstAddress.Builder().withSrcMaskLength(SRC_MASK_LENGTH).withDstMaskLength(DST_MASK_LENGTH).withSrcPrefix(MappingAddresses.ipv4MappingAddress(IPV4_SRC_PREFIX)).withDstPrefix(MappingAddresses.ipv4MappingAddress(IPV4_DST_PREFIX)).build();
    ObjectNode addressJson = srcDstAddressCodec.encode(address, context);
    assertThat("errors in encoding Source and Destination address JSON", addressJson, LispSrcDstAddressJsonMatcher.matchesSrcDstAddress(address));
}
Also used : LispSrcDstAddress(org.onosproject.drivers.lisp.extensions.LispSrcDstAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Test(org.junit.Test)

Aggregations

LispSrcDstAddress (org.onosproject.drivers.lisp.extensions.LispSrcDstAddress)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