Search in sources :

Example 1 with LispNatAddress

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

the class LispNatAddressCodec method decode.

@Override
public LispNatAddress decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    short msUdpPortNumber = (short) json.get(MS_UDP_PORT_NUMBER).asInt();
    short etrUdpPortNumber = (short) json.get(ETR_UDP_PORT_NUMBER).asInt();
    ObjectNode globalEtrRlocJson = get(json, GLOBAL_ETR_RLOC_ADDRESS);
    ObjectNode msRlocJson = get(json, MS_RLOC_ADDRESS);
    ObjectNode privateEtrRlocJson = get(json, PRIVATE_ETR_RLOC_ADDRESS);
    JsonNode rtrRlocJson = json.get(RTR_RLOC_ADDRESSES);
    MappingAddress globalEtrRlocAddress = null;
    MappingAddress msRlocAddress = null;
    MappingAddress privateEtrRlocAddress = null;
    List<MappingAddress> rtrRlocAddresses = Lists.newArrayList();
    if (globalEtrRlocJson != null) {
        globalEtrRlocAddress = addressCodec.decode(globalEtrRlocJson, context);
    }
    if (msRlocJson != null) {
        msRlocAddress = addressCodec.decode(msRlocJson, context);
    }
    if (privateEtrRlocJson != null) {
        privateEtrRlocAddress = addressCodec.decode(privateEtrRlocJson, context);
    }
    if (rtrRlocJson != null) {
        IntStream.range(0, rtrRlocJson.size()).forEach(i -> rtrRlocAddresses.add(addressCodec.decode(get(rtrRlocJson, i), context)));
    }
    return new LispNatAddress.Builder().withMsUdpPortNumber(msUdpPortNumber).withEtrUdpPortNumber(etrUdpPortNumber).withGlobalEtrRlocAddress(globalEtrRlocAddress).withMsRlocAddress(msRlocAddress).withPrivateEtrRlocAddress(privateEtrRlocAddress).withRtrRlocAddresses(rtrRlocAddresses).build();
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LispNatAddress(org.onosproject.drivers.lisp.extensions.LispNatAddress) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with LispNatAddress

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

the class LispNatAddressCodecTest method testLispNatAddressDecode.

/**
 * Tests decoding of a LispNatAddress JSON object.
 */
@Test
public void testLispNatAddressDecode() throws IOException {
    LispNatAddress address = getLispNatAddress("LispNatAddress.json");
    assertThat("incorrect MS UDP port number", address.getMsUdpPortNumber(), is(MS_UDP_PORT_NUMBER));
    assertThat("incorrect ETR UDP port number", address.getEtrUdpPortNumber(), is(ETR_UDP_PORT_NUMBER));
    assertThat("incorrect global ETR RLOC address", address.getGlobalEtrRlocAddress(), is(MappingAddresses.ipv4MappingAddress(GLOBAL_ETR_RLOC_ADDRESS)));
    assertThat("incorrect MS RLOC address", address.getMsRlocAddress(), is(MappingAddresses.ipv4MappingAddress(MS_RLOC_ADDRESS)));
    assertThat("incorrect private ETR RLOC address", address.getPrivateEtrRlocAddress(), is(MappingAddresses.ipv4MappingAddress(PRIVATE_ETR_RLOC_ADDRESS)));
}
Also used : LispNatAddress(org.onosproject.drivers.lisp.extensions.LispNatAddress) Test(org.junit.Test)

Example 3 with LispNatAddress

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

the class LispNatAddressCodecTest method testLispNatAddressEncode.

/**
 * Tests encoding of a LispNatAddress object.
 */
@Test
public void testLispNatAddressEncode() {
    List<MappingAddress> rtrRlocs = ImmutableList.of(MappingAddresses.ipv4MappingAddress(GLOBAL_ETR_RLOC_ADDRESS), MappingAddresses.ipv4MappingAddress(MS_RLOC_ADDRESS), MappingAddresses.ipv4MappingAddress(PRIVATE_ETR_RLOC_ADDRESS));
    LispNatAddress address = new LispNatAddress.Builder().withMsUdpPortNumber(MS_UDP_PORT_NUMBER).withEtrUdpPortNumber(ETR_UDP_PORT_NUMBER).withGlobalEtrRlocAddress(MappingAddresses.ipv4MappingAddress(GLOBAL_ETR_RLOC_ADDRESS)).withMsRlocAddress(MappingAddresses.ipv4MappingAddress(MS_RLOC_ADDRESS)).withPrivateEtrRlocAddress(MappingAddresses.ipv4MappingAddress(PRIVATE_ETR_RLOC_ADDRESS)).withRtrRlocAddresses(rtrRlocs).build();
    ObjectNode addressJson = natAddressCodec.encode(address, context);
    assertThat("errors in encoding NAT address JSON", addressJson, LispNatAddressJsonMatcher.matchesNatAddress(address));
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LispNatAddress(org.onosproject.drivers.lisp.extensions.LispNatAddress) Test(org.junit.Test)

Example 4 with LispNatAddress

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

the class LispNatAddressCodecTest method getLispNatAddress.

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

Example 5 with LispNatAddress

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

the class LispNatAddressCodecTest method setUp.

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

Aggregations

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