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();
}
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)));
}
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));
}
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;
}
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());
}
Aggregations