use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary in project lispflowmapping by opendaylight.
the class MapResolver method resolveRloc.
private Rloc resolveRloc(List<ItrRloc> itrRlocList, IpAddressBinary srcRloc) {
if (srcRloc == null) {
return itrRlocList.get(0).getRloc();
}
byte[] srcRlocByte;
if (srcRloc.getIpv4AddressBinary() != null) {
srcRlocByte = srcRloc.getIpv4AddressBinary().getValue();
} else {
srcRlocByte = srcRloc.getIpv6AddressBinary().getValue();
}
Rloc equalIpvRloc = null;
for (ItrRloc itrRloc : itrRlocList) {
final Rloc rloc = itrRloc.getRloc();
final byte[] itrRlocByte = LispAddressUtil.ipAddressToByteArray(rloc.getAddress());
// return an Rloc equal to the source Rloc
if (itrRlocByte != null && LispAddressUtil.compareIpAddressByteArrays(srcRlocByte, itrRlocByte) == 0) {
return rloc;
}
// else lookup the first Rloc with identical Ip version
if (equalIpvRloc == null && isEqualIpVersion(srcRloc, rloc)) {
equalIpvRloc = rloc;
}
}
if (equalIpvRloc != null) {
return equalIpvRloc;
} else {
// if none of the above, return the first Rloc
return itrRlocList.get(0).getRloc();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary in project lispflowmapping by opendaylight.
the class LispAddressUtilTest method addressBinaryFromInet_Inet4Address.
/**
* Tests {@link LispAddressUtil#addressBinaryFromInet(InetAddress)} method with Inet4Address.
*/
@Test
public void addressBinaryFromInet_Inet4Address() throws UnknownHostException {
final InetAddress inet4Address = InetAddress.getByName(IPV4_ADDRESS_VALUE_TEST);
assertEquals(new IpAddressBinary(IPV4_ADDRESS_BINARY_TEST), LispAddressUtil.addressBinaryFromInet(inet4Address));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary in project lispflowmapping by opendaylight.
the class LispSouthboundPlugin method getInetAddress.
private InetAddress getInetAddress(TransportAddress address) {
Preconditions.checkNotNull(address, "TransportAddress must not be null");
IpAddressBinary ip = address.getIpAddress();
try {
if (ip.getIpv4AddressBinary() != null) {
return InetAddress.getByAddress(ip.getIpv4AddressBinary().getValue());
} else if (ip.getIpv6AddressBinary() != null) {
return InetAddress.getByAddress(ip.getIpv6AddressBinary().getValue());
}
} catch (UnknownHostException e) {
LOG.debug("Could not convert TransportAddress {} to InetAddress", address, e);
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary in project lispflowmapping by opendaylight.
the class MappingSystem method handleMergedMapping.
private MappingData handleMergedMapping(Eid key) {
LOG.trace("Merging mappings for EID {}", LispAddressStringifier.getString(key));
List<MappingData> expiredMappingDataList = new ArrayList<>();
Set<IpAddressBinary> sourceRlocs = new HashSet<>();
MappingData mergedMappingData = MappingMergeUtil.mergeXtrIdMappings(smc.getAllXtrIdMappings(key), expiredMappingDataList, sourceRlocs);
for (MappingData mappingData : expiredMappingDataList) {
removeSbXtrIdSpecificMapping(key, mappingData.getXtrId(), mappingData);
}
if (mergedMappingData != null) {
smc.addMapping(key, mergedMappingData, sourceRlocs);
dsbe.addMapping(DSBEInputUtil.toMapping(MappingOrigin.Southbound, key, mergedMappingData));
addOrRefreshMappingInTimeoutService(key, mergedMappingData);
} else {
removeSbMapping(key, mergedMappingData);
}
return mergedMappingData;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary in project lispflowmapping by opendaylight.
the class MapResolver method handleMapRequest.
public void handleMapRequest(MapRequest request) {
LOG.trace("Map-Request received: {}", request);
// SMRs and RLOC probes are directed towards xTRs and we're a Map-Resolver here, so ignore them
if (request.isSmr() != null && request.isSmr()) {
LOG.debug("Map-Resolver ignoring incoming SMR control message.");
return;
}
if (request.isProbe() != null && request.isProbe()) {
LOG.debug("Map-Resolver ignoring incoming RLOC probe control message.");
return;
}
if (request.isSmrInvoked()) {
LOG.debug("SMR-invoked request received.");
LOG.trace("Map-Request object: {}", request);
for (EidItem eidItem : request.getEidItem()) {
final SmrEvent event = new SmrEvent(subscriberListFromItrRlocs(request.getItrRloc(), request.getSourceEid().getEid()), eidItem.getEid(), request.getNonce());
smrNotificationListener.onSmrInvokedReceived(event);
}
}
Eid srcEid = null;
if (request.getSourceEid() != null) {
srcEid = request.getSourceEid().getEid();
}
MapReplyBuilder replyBuilder = new MapReplyBuilder();
replyBuilder.setEchoNonceEnabled(false);
replyBuilder.setProbe(false);
replyBuilder.setSecurityEnabled(false);
replyBuilder.setNonce(request.getNonce());
replyBuilder.setMappingRecordItem(new ArrayList<>());
List<ItrRloc> itrRlocs = request.getItrRloc();
final IpAddressBinary sourceRloc = request.getSourceRloc();
for (EidItem eidRecord : request.getEidItem()) {
MappingData mappingData = mapService.getMapping(srcEid, eidRecord.getEid());
MappingRecord mapping;
if (mappingData == null) {
mapping = mapService.addNegativeMapping(eidRecord.getEid()).getRecord();
} else {
mapping = mappingData.getRecord();
}
if (itrRlocs != null && itrRlocs.size() != 0) {
if (subscriptionService && isValidSourceEidForSubscriber(srcEid)) {
final Rloc resolvedRloc = resolveRloc(itrRlocs, sourceRloc);
updateSubscribers(resolvedRloc, eidRecord.getEid(), mapping.getEid(), srcEid, mapping.getRecordTtl());
}
mapping = updateLocators(mapping, itrRlocs);
}
mapping = fixIfNotSDRequest(mapping, eidRecord.getEid());
mapping = fixTtlIfSmrInvoked(request, mapping);
replyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mapping).build());
}
requestHandler.handleMapReply(replyBuilder.build());
}
Aggregations