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