use of org.onosproject.mapping.addresses.ExtensionMappingAddress in project onos by opennetworkinglab.
the class LispExtensionMappingAddressInterpreterTest method getExtMappingAddress.
private ExtensionMappingAddress getExtMappingAddress(ExtensionMappingAddressType type) {
ExtensionMappingAddress address = null;
MappingAddress ipv4Addr = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX);
MappingAddress ipv6Addr = MappingAddresses.ipv6MappingAddress(IPV6_PREFIX);
if (type.equals(LIST_ADDRESS.type())) {
address = new LispListAddress.Builder().withIpv4(ipv4Addr).withIpv6(ipv6Addr).build();
}
if (type.equals(SEGMENT_ADDRESS.type())) {
address = new LispSegmentAddress.Builder().withInstanceId(UNIQUE_INT).withAddress(ipv4Addr).build();
}
if (type.equals(AS_ADDRESS.type())) {
address = new LispAsAddress.Builder().withAsNumber(UNIQUE_INT).withAddress(ipv4Addr).build();
}
if (type.equals(APPLICATION_DATA_ADDRESS.type())) {
address = new LispAppDataAddress.Builder().withProtocol(UNIQUE_BYTE).withIpTos(UNIQUE_INT).withLocalPortLow(UNIQUE_SHORT).withLocalPortHigh(UNIQUE_SHORT).withRemotePortLow(UNIQUE_SHORT).withRemotePortHigh(UNIQUE_SHORT).withAddress(ipv4Addr).build();
}
if (type.equals(GEO_COORDINATE_ADDRESS.type())) {
address = new LispGcAddress.Builder().withIsNorth(UNIQUE_BOOLEAN).withLatitudeDegree(UNIQUE_SHORT).withLatitudeMinute(UNIQUE_BYTE).withLatitudeSecond(UNIQUE_BYTE).withIsEast(UNIQUE_BOOLEAN).withLongitudeDegree(UNIQUE_SHORT).withLongitudeMinute(UNIQUE_BYTE).withLongitudeSecond(UNIQUE_BYTE).withAltitude(UNIQUE_INT).withAddress(ipv4Addr).build();
}
if (type.equals(NAT_ADDRESS.type())) {
address = new LispNatAddress.Builder().withMsUdpPortNumber(UNIQUE_SHORT).withEtrUdpPortNumber(UNIQUE_SHORT).withGlobalEtrRlocAddress(ipv4Addr).withMsRlocAddress(ipv4Addr).withPrivateEtrRlocAddress(ipv4Addr).withRtrRlocAddresses(ImmutableList.of(ipv4Addr, ipv6Addr)).build();
}
if (type.equals(NONCE_ADDRESS.type())) {
address = new LispNonceAddress.Builder().withNonce(UNIQUE_INT).withAddress(ipv4Addr).build();
}
if (type.equals(MULTICAST_ADDRESS.type())) {
address = new LispMulticastAddress.Builder().withInstanceId(UNIQUE_INT).withSrcMaskLength(UNIQUE_BYTE).withSrcAddress(ipv4Addr).withGrpMaskLength(UNIQUE_BYTE).withGrpAddress(ipv4Addr).build();
}
if (type.equals(TRAFFIC_ENGINEERING_ADDRESS.type())) {
LispTeAddress.TeRecord tr = new LispTeAddress.TeRecord.Builder().withIsLookup(UNIQUE_BOOLEAN).withIsRlocProbe(UNIQUE_BOOLEAN).withIsStrict(UNIQUE_BOOLEAN).withRtrRlocAddress(ipv4Addr).build();
address = new LispTeAddress.Builder().withTeRecords(ImmutableList.of(tr)).build();
}
if (type.equals(SOURCE_DEST_ADDRESS.type())) {
address = new LispSrcDstAddress.Builder().withSrcMaskLength(UNIQUE_BYTE).withSrcPrefix(ipv4Addr).withDstMaskLength(UNIQUE_BYTE).withDstPrefix(ipv4Addr).build();
}
return address;
}
use of org.onosproject.mapping.addresses.ExtensionMappingAddress in project onos by opennetworkinglab.
the class LispExtensionMappingAddressInterpreterTest method testAddressDecode.
/**
* Tests decoding of an ExtensionMappingAddress JSON object.
*/
@Test
public void testAddressDecode() throws IOException {
List<ExtensionMappingAddress> addresses = getLispExtensionMappingAddresses("LispExtensionMappingAddress.json");
new EqualsTester().addEqualityGroup(addresses.get(0), listExtAddress).addEqualityGroup(addresses.get(1), segmentExtAddress).addEqualityGroup(addresses.get(2), asExtAddress).addEqualityGroup(addresses.get(3), appDataExtAddress).addEqualityGroup(addresses.get(4), gcExtAddress).addEqualityGroup(addresses.get(5), natExtAddress).addEqualityGroup(addresses.get(6), nonceExtAddress).addEqualityGroup(addresses.get(7), multicastExtAddress).addEqualityGroup(addresses.get(8), teExtAddress).addEqualityGroup(addresses.get(9), srcDstExtAddress).testEquals();
}
use of org.onosproject.mapping.addresses.ExtensionMappingAddress in project onos by opennetworkinglab.
the class LispExtensionMappingAddressInterpreterTest method getLispExtensionMappingAddresses.
/**
* Reads in a collection of LispExtensionMappingAddresses from the given resource and decodes it.
*
* @param resourceName resource to use to read the JSON for the rule
* @return decoded LispExtensionMappingAddresses
* @throws IOException if processing the resource fails
*/
private List<ExtensionMappingAddress> getLispExtensionMappingAddresses(String resourceName) throws IOException {
InputStream jsonStream = LispExtensionMappingAddressInterpreterTest.class.getResourceAsStream(resourceName);
JsonNode json = context.mapper().readTree(jsonStream);
assertThat("JSON string should not be null", json, notNullValue());
final List<ExtensionMappingAddress> addresses = Lists.newArrayList();
for (int addrIndex = 0; addrIndex < json.size(); addrIndex++) {
ExtensionMappingAddress address = interpreter.decode(json.get(addrIndex).deepCopy(), context);
assertThat("decoded address should not be null", address, notNullValue());
addresses.add(address);
}
return addresses;
}
use of org.onosproject.mapping.addresses.ExtensionMappingAddress in project onos by opennetworkinglab.
the class LispExtensionMappingAddressInterpreter method mapLcafAddress.
@Override
public ExtensionMappingAddress mapLcafAddress(LispLcafAddress lcafAddress) {
switch(lcafAddress.getType()) {
case LIST:
LispListLcafAddress lcafListAddress = (LispListLcafAddress) lcafAddress;
MappingAddress ipv4Ma = afi2mapping(lcafListAddress.getAddresses().get(0));
MappingAddress ipv6Ma = afi2mapping(lcafListAddress.getAddresses().get(1));
return new LispListAddress.Builder().withIpv4(ipv4Ma).withIpv6(ipv6Ma).build();
case SEGMENT:
LispSegmentLcafAddress segmentLcafAddress = (LispSegmentLcafAddress) lcafAddress;
return new LispSegmentAddress.Builder().withInstanceId(segmentLcafAddress.getInstanceId()).withAddress(getMappingAddress(segmentLcafAddress.getAddress())).build();
case AS:
LispAsLcafAddress asLcafAddress = (LispAsLcafAddress) lcafAddress;
return new org.onosproject.drivers.lisp.extensions.LispAsAddress.Builder().withAsNumber(asLcafAddress.getAsNumber()).withAddress(getMappingAddress(asLcafAddress.getAddress())).build();
case APPLICATION_DATA:
LispAppDataLcafAddress appLcafAddress = (LispAppDataLcafAddress) lcafAddress;
return new LispAppDataAddress.Builder().withProtocol(appLcafAddress.getProtocol()).withIpTos(appLcafAddress.getIpTos()).withLocalPortLow(appLcafAddress.getLocalPortLow()).withLocalPortHigh(appLcafAddress.getLocalPortHigh()).withRemotePortLow(appLcafAddress.getRemotePortLow()).withRemotePortHigh(appLcafAddress.getRemotePortHigh()).withAddress(getMappingAddress(appLcafAddress.getAddress())).build();
case GEO_COORDINATE:
LispGeoCoordinateLcafAddress gcLcafAddress = (LispGeoCoordinateLcafAddress) lcafAddress;
return new LispGcAddress.Builder().withIsNorth(gcLcafAddress.isNorth()).withLatitudeDegree(gcLcafAddress.getLatitudeDegree()).withLatitudeMinute(gcLcafAddress.getLatitudeMinute()).withLatitudeSecond(gcLcafAddress.getLatitudeSecond()).withIsEast(gcLcafAddress.isEast()).withLongitudeDegree(gcLcafAddress.getLongitudeDegree()).withLongitudeMinute(gcLcafAddress.getLongitudeMinute()).withLongitudeSecond(gcLcafAddress.getLongitudeSecond()).withAltitude(gcLcafAddress.getAltitude()).withAddress(getMappingAddress(gcLcafAddress.getAddress())).build();
case NAT:
LispNatLcafAddress natLcafAddress = (LispNatLcafAddress) lcafAddress;
List<MappingAddress> mas = Lists.newArrayList();
natLcafAddress.getRtrRlocAddresses().forEach(rtr -> mas.add(getMappingAddress(rtr)));
return new LispNatAddress.Builder().withMsUdpPortNumber(natLcafAddress.getMsUdpPortNumber()).withEtrUdpPortNumber(natLcafAddress.getEtrUdpPortNumber()).withMsRlocAddress(getMappingAddress(natLcafAddress.getMsRlocAddress())).withGlobalEtrRlocAddress(getMappingAddress(natLcafAddress.getGlobalEtrRlocAddress())).withPrivateEtrRlocAddress(getMappingAddress(natLcafAddress.getPrivateEtrRlocAddress())).withRtrRlocAddresses(mas).build();
case NONCE:
LispNonceLcafAddress nonceLcafAddress = (LispNonceLcafAddress) lcafAddress;
return new LispNonceAddress.Builder().withNonce(nonceLcafAddress.getNonce()).withAddress(getMappingAddress(nonceLcafAddress.getAddress())).build();
case MULTICAST:
LispMulticastLcafAddress multiLcafAddress = (LispMulticastLcafAddress) lcafAddress;
return new LispMulticastAddress.Builder().withInstanceId(multiLcafAddress.getInstanceId()).withSrcAddress(getMappingAddress(multiLcafAddress.getSrcAddress())).withSrcMaskLength(multiLcafAddress.getSrcMaskLength()).withGrpAddress(getMappingAddress(multiLcafAddress.getGrpAddress())).withGrpMaskLength(multiLcafAddress.getGrpMaskLength()).build();
case TRAFFIC_ENGINEERING:
LispTeLcafAddress teLcafAddress = (LispTeLcafAddress) lcafAddress;
List<LispTeAddress.TeRecord> records = Lists.newArrayList();
teLcafAddress.getTeRecords().forEach(record -> {
LispTeAddress.TeRecord teRecord = new LispTeAddress.TeRecord.Builder().withIsLookup(record.isLookup()).withIsRlocProbe(record.isRlocProbe()).withIsStrict(record.isStrict()).withRtrRlocAddress(getMappingAddress(record.getRtrRlocAddress())).build();
records.add(teRecord);
});
return new LispTeAddress.Builder().withTeRecords(records).build();
case SECURITY:
// TODO: need to implement security type later
log.warn("security type will be implemented later");
return null;
case SOURCE_DEST:
LispSourceDestLcafAddress srcDstLcafAddress = (LispSourceDestLcafAddress) lcafAddress;
return new LispSrcDstAddress.Builder().withSrcPrefix(getMappingAddress(srcDstLcafAddress.getSrcPrefix())).withSrcMaskLength(srcDstLcafAddress.getSrcMaskLength()).withDstPrefix(getMappingAddress(srcDstLcafAddress.getDstPrefix())).withDstMaskLength(srcDstLcafAddress.getDstMaskLength()).build();
case UNSPECIFIED:
case UNKNOWN:
default:
log.error("Unsupported LCAF type {}", lcafAddress.getType());
return null;
}
}
use of org.onosproject.mapping.addresses.ExtensionMappingAddress in project onos by opennetworkinglab.
the class MappingAddressBuilder method lcaf2extension.
/**
* Converts LCAF address to extension mapping address.
*
* @param deviceService device service
* @param deviceId device identifier
* @param lcaf LCAF address
* @return extension mapping address
*/
private static MappingAddress lcaf2extension(DeviceService deviceService, DeviceId deviceId, LispLcafAddress lcaf) {
Device device = deviceService.getDevice(deviceId);
ExtensionMappingAddressInterpreter addressInterpreter;
ExtensionMappingAddress mappingAddress = null;
if (device.is(ExtensionMappingAddressInterpreter.class)) {
addressInterpreter = device.as(ExtensionMappingAddressInterpreter.class);
} else {
addressInterpreter = null;
}
switch(lcaf.getType()) {
case LIST:
if (addressInterpreter != null && addressInterpreter.supported(LIST_ADDRESS.type())) {
mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
}
break;
case SEGMENT:
if (addressInterpreter != null && addressInterpreter.supported(SEGMENT_ADDRESS.type())) {
mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
}
break;
case AS:
if (addressInterpreter != null && addressInterpreter.supported(AS_ADDRESS.type())) {
mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
}
break;
case APPLICATION_DATA:
if (addressInterpreter != null && addressInterpreter.supported(APPLICATION_DATA_ADDRESS.type())) {
mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
}
break;
case GEO_COORDINATE:
if (addressInterpreter != null && addressInterpreter.supported(GEO_COORDINATE_ADDRESS.type())) {
mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
}
break;
case NAT:
if (addressInterpreter != null && addressInterpreter.supported(NAT_ADDRESS.type())) {
mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
}
break;
case NONCE:
if (addressInterpreter != null && addressInterpreter.supported(NONCE_ADDRESS.type())) {
mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
}
break;
case MULTICAST:
if (addressInterpreter != null && addressInterpreter.supported(MULTICAST_ADDRESS.type())) {
mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
}
break;
case TRAFFIC_ENGINEERING:
if (addressInterpreter != null && addressInterpreter.supported(TRAFFIC_ENGINEERING_ADDRESS.type())) {
mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
}
break;
case SOURCE_DEST:
if (addressInterpreter != null && addressInterpreter.supported(SOURCE_DEST_ADDRESS.type())) {
mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
}
break;
default:
log.warn("Unsupported extension mapping address type {}", lcaf.getType());
break;
}
return mappingAddress != null ? MappingAddresses.extensionMappingAddressWrapper(mappingAddress, deviceId) : null;
}
Aggregations