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