import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+
import org.apache.commons.lang3.ArrayUtils;
import org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.Site;
import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
import org.opendaylight.lispflowmapping.lisp.serializer.MapRequestSerializer;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.net.InetAddresses;
/**
* Contains methods for:
this.lms = lms;
}
- private Ipv4Address verifyIpv4Address(final LocatorRecord locatorRecord) {
+ private Ipv4AddressBinary verifyIpv4Address(final LocatorRecord locatorRecord) {
assertNotNull(locatorRecord);
final Rloc rloc = locatorRecord.getRloc();
assertNotNull(rloc);
final Address address = rloc.getAddress();
- assertTrue(address instanceof Ipv4);
- return ((Ipv4) address).getIpv4();
+ assertTrue(address instanceof Ipv4Binary);
+ return ((Ipv4Binary) address).getIpv4Binary();
}
private List<LocatorRecord> verifyLocatorRecordExists(final MappingRecord mappingRecord) {
}
void setCommonAuthentication() {
- Eid eid = LispAddressUtil.toEid(new Ipv4Prefix("0.0.0.0/0"), SITE_A.getVNI());
+ Eid eid = LispAddressUtil.asIpv4PrefixBinaryEid("0.0.0.0/0", SITE_A.getVNI());
mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
- eid = LispAddressUtil.toEid(new Ipv4Prefix("0.0.0.0/0"), SITE_D5.getVNI());
+ eid = LispAddressUtil.asIpv4PrefixBinaryEid("0.0.0.0/0", SITE_D5.getVNI());
mapService.addAuthenticationKey(eid, NULL_AUTH_KEY);
sleepForSeconds(1);
}
private Eid toEid(final String destSiteEidPrefix, final InstanceIdType vniValue, final int mask) {
- return LispAddressUtil.toEid(new Ipv4Prefix(destSiteEidPrefix + "/" + mask), vniValue);
+ return LispAddressUtil.asIpv4PrefixBinaryEid(destSiteEidPrefix + "/" + mask, vniValue);
}
}
void storeNorthMappingNegative(final Site dstSite, final MappingRecord.Action action) {
- final Ipv4Prefix ipv4Prefix = new Ipv4Prefix(dstSite.getEidPrefix() + "/" + DEFAULT_NETWORK_MASK);
- final Eid eidAsIpv4Prefix = LispAddressUtil.toEid(ipv4Prefix, dstSite.getVNI());
+ final Eid eidAsIpv4Prefix = LispAddressUtil.asIpv4PrefixBinaryEid(
+ dstSite.getEidPrefix() + "/" + DEFAULT_NETWORK_MASK, dstSite.getVNI());
final MappingRecordBuilder mrbNegative = prepareMappingRecord(EidType.EID_WITH_PREFIX, null, dstSite);
mrbNegative.setEid(eidAsIpv4Prefix);
}
void deleteNorthMappingNegative(final Site dstSite) {
- final Ipv4Prefix ipv4Prefix = new Ipv4Prefix(dstSite.getEidPrefix() + "/" + DEFAULT_NETWORK_MASK);
- final Eid eidAsIpv4Prefix = LispAddressUtil.toEid(ipv4Prefix, dstSite.getVNI());
+ final Eid eidAsIpv4Prefix = LispAddressUtil.asIpv4PrefixBinaryEid(
+ dstSite.getEidPrefix() + "/" + DEFAULT_NETWORK_MASK, dstSite.getVNI());
mapService.removeMapping(MappingOrigin.Northbound, eidAsIpv4Prefix);
}
if (!dstSites[0].isForDeletion) {
for (Site dstSite : dstSites) {
if (dstSite.getRloc() != null) {
- locatorRecords.add(provideLocatorRecord(LispAddressUtil.toRloc(new Ipv4Address(dstSite.getRloc())),
+ locatorRecords.add(provideLocatorRecord(LispAddressUtil.asIpv4Rloc(dstSite.getRloc()),
dstSite.getRloc(), dstSite.getWeight(), dstSite.getPriority()));
}
}
boolean expectedTargetFound = false;
for (LocatorRecord locatorRecord : locatorRecords) {
if (expectedTargetSite.getRloc().equals(rlocToString(locatorRecord))) {
- final Ipv4Address ipv4AddressSrcDst = verifyIpv4Address(locatorRecord);
- final boolean isRlocSrcDstEqual = ipv4AddressSrcDst.getValue().equals(expectedTargetSite.getRloc());
+ final byte[] ipv4AddressSrcDst = verifyIpv4Address(locatorRecord).getValue();
+ final byte[] rloc = InetAddresses.forString((expectedTargetSite.getRloc())).getAddress();
+ final boolean isRlocSrcDstEqual = Arrays.equals(ipv4AddressSrcDst, rloc);
if (isPossibleAssertPingResultImmediately(expectedPingWorks, isRlocSrcDstEqual, "Unexpected RLOC." +
- "Expected value " + dstSite.getRloc() + ". Real value " + ipv4AddressSrcDst.getValue() +
+ "Expected value " + rloc + ". Real value " + ipv4AddressSrcDst +
".")) {
return true;
}
boolean expectedPingWorks, final Site ... additionalSitesFromMapping) {
final MapReply mapReplyFromSrcToDst = emitMapRequestMessage(srcSite.getHost(srcHostIndex), dstSite.getHost
(dstHostIndex), dstSite.getVNI());
- if (checkActionAndRloc(dstSite, expectedPingWorks, mapReplyFromSrcToDst,
- additionalSitesFromMapping)) {
+ if (checkActionAndRloc(dstSite, expectedPingWorks, mapReplyFromSrcToDst, additionalSitesFromMapping)) {
return;
}
// mapping will be pushed to dst as well (see sendSMRs in MapServer)
if (mapEid.getAddressType().equals(SourceDestKeyLcaf.class)
&& !reqEid.getAddressType().equals(SourceDestKeyLcaf.class)) {
- subscribedEid = SourceDestKeyHelper.getDst(mapEid);
+ subscribedEid = SourceDestKeyHelper.getDstBinary(mapEid);
}
Set<SubscriberRLOC> subscribers = getSubscribers(subscribedEid);
if (mapping.getEid().getAddress() instanceof SourceDestKey
&& !(dstEid.getAddress() instanceof SourceDestKey)) {
return new MappingRecordBuilder(mapping).setEid(
- SourceDestKeyHelper.getDst(mapping.getEid())).build();
+ SourceDestKeyHelper.getDstBinary(mapping.getEid())).build();
}
return mapping;
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingChanged;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.OdlMappingserviceListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
boolean authFailed = false;
boolean mappingUpdated = false;
boolean merge = ConfigIni.getInstance().mappingMergeIsSet() && mapRegister.isMergeEnabled();
- MappingAuthkey authkey = null;
Set<SubscriberRLOC> subscribers = null;
MappingRecord oldMapping;
// For SrcDst LCAF also send SMRs to Dst prefix
if (eid.getAddress() instanceof SourceDestKey) {
- Eid dstAddr = SourceDestKeyHelper.getDst(eid);
+ Eid dstAddr = SourceDestKeyHelper.getDstBinary(eid);
Set<SubscriberRLOC> dstSubs = getSubscribers(dstAddr);
MappingRecord newRecord = new MappingRecordBuilder(record).setEid(dstAddr).build();
handleSmr(newRecord.getEid(), dstSubs, notifyHandler);
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
private static AuthenticationKey convertToBinaryIfNecessary(AuthenticationKey authKey) {
Eid originalEid = authKey.getEid();
- if (originalEid.getAddress() instanceof Ipv4Prefix || originalEid.getAddress() instanceof Ipv6Prefix ||
- originalEid.getAddress() instanceof Ipv4 || originalEid.getAddress() instanceof Ipv6) {
+ if (LispAddressUtil.addressNeedsConversionToBinary(originalEid.getAddress())) {
AuthenticationKeyBuilder akb = new AuthenticationKeyBuilder(authKey);
akb.setEid(LispAddressUtil.convertToBinary(originalEid));
return akb.build();
*/
package org.opendaylight.lispflowmapping.implementation.mdsal;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.lispflowmapping.implementation.util.MSNotificationInputUtil;
import org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingChange;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.MappingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.database.VirtualNetworkIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
LOG.trace("Value: {}", mapping);
- mapSystem.removeMapping(mapping.getOrigin(), mapping.getMappingRecord().getEid());
+ final Mapping convertedMapping = convertToBinaryIfNecessary(mapping);
+
+ mapSystem.removeMapping(convertedMapping.getOrigin(), convertedMapping.getMappingRecord().getEid());
try {
notificationPublishService.putNotification(MSNotificationInputUtil.toMappingChanged(
- mapping, MappingChange.Removed));
+ convertedMapping, MappingChange.Removed));
} catch (InterruptedException e) {
LOG.warn("Notification publication interrupted!");
}
LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
LOG.trace("Value: {}", mapping);
- mapSystem.addMapping(mapping.getOrigin(), mapping.getMappingRecord().getEid(),
- mapping.getMappingRecord(), false);
+ final Mapping convertedMapping = convertToBinaryIfNecessary(mapping);
+
+ mapSystem.addMapping(convertedMapping.getOrigin(), convertedMapping.getMappingRecord().getEid(),
+ convertedMapping.getMappingRecord(), false);
try {
// The notifications are used for sending SMR.
- notificationPublishService.putNotification(MSNotificationInputUtil.toMappingChanged(mapping,
- mappingChange));
+ notificationPublishService.putNotification(MSNotificationInputUtil.toMappingChanged(
+ convertedMapping, mappingChange));
} catch (InterruptedException e) {
LOG.warn("Notification publication interrupted!");
}
}
}
}
+
+ private static Mapping convertToBinaryIfNecessary(Mapping mapping) {
+ MappingRecord originalRecord = mapping.getMappingRecord();
+ List<LocatorRecord> originalLocators = originalRecord.getLocatorRecord();
+
+ List<LocatorRecord> convertedLocators = null;
+ if (originalLocators != null) {
+ // If convertedLocators is non-null, while originalLocators is also non-null, conversion has been made
+ convertedLocators = convertToBinaryIfNecessary(originalLocators);
+ }
+
+ if (LispAddressUtil.addressNeedsConversionToBinary(originalRecord.getEid().getAddress()) ||
+ (originalLocators != null && convertedLocators != null)) {
+ MappingRecordBuilder mrb = new MappingRecordBuilder(originalRecord);
+ mrb.setEid(LispAddressUtil.convertToBinary(originalRecord.getEid()));
+ if (convertedLocators != null) {
+ mrb.setLocatorRecord(convertedLocators);
+ }
+ return new MappingBuilder(mapping).setMappingRecord(mrb.build()).build();
+ }
+ return mapping;
+ }
+
+ private static List<LocatorRecord> convertToBinaryIfNecessary(List<LocatorRecord> locators) {
+ List<LocatorRecord> convertedLocators = null;
+ for (LocatorRecord record : locators) {
+ if (LispAddressUtil.addressNeedsConversionToBinary(record.getRloc().getAddress())) {
+ LocatorRecordBuilder lrb = new LocatorRecordBuilder(record);
+ lrb.setRloc(LispAddressUtil.convertToBinary(record.getRloc()));
+ if (convertedLocators == null) {
+ convertedLocators = new ArrayList<LocatorRecord>();
+ }
+ convertedLocators.add(lrb.build());
+ }
+ }
+ return convertedLocators;
+ }
}
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(mapServiceMock).getData(MappingOrigin.Southbound,
- SourceDestKeyHelper.getDst(SOURCE_DEST_KEY_EID), SubKeys.SUBSCRIBERS);
+ SourceDestKeyHelper.getDstBinary(SOURCE_DEST_KEY_EID), SubKeys.SUBSCRIBERS);
}
/**
.thenReturn(subscriberSetMock_1);
// return a subscriberSet for SrcDestKeyEid destination MappingRecord
- Mockito.when(mapService.getData(MappingOrigin.Southbound, SourceDestKeyHelper.getDst(SOURCE_DEST_KEY_EID),
+ Mockito.when(mapService.getData(MappingOrigin.Southbound, SourceDestKeyHelper.getDstBinary(SOURCE_DEST_KEY_EID),
SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock_2);
// ----------------- Stubbing for Ipv4 type Eid mapping ------------------------
// for SrcDst destination mapping
final ArgumentCaptor<MapRequest> captor_2 = ArgumentCaptor.forClass(MapRequest.class);
Mockito.verify(notifyHandler, Mockito.times(1)).handleSMR(captor_2.capture(), Mockito.eq(RLOC_4));
- Mockito.verify(mapService).addData(MappingOrigin.Southbound, SourceDestKeyHelper.getDst(SOURCE_DEST_KEY_EID),
+ Mockito.verify(mapService).addData(MappingOrigin.Southbound,
+ SourceDestKeyHelper.getDstBinary(SOURCE_DEST_KEY_EID),
SubKeys.SUBSCRIBERS, subscriberSetMock_2);
final Eid resultEid_2 = captor_2.getValue().getEidItem().iterator().next().getEid();
assertEquals(IPV4_SOURCE_EID_4, resultEid_2);
import java.util.List;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
return null;
}
+ public static Class<? extends LispAddressFamily> binaryAddressTypeFromInet(InetAddress address) {
+ if (address instanceof Inet4Address) {
+ return Ipv4BinaryAfi.class;
+ } else if (address instanceof Inet6Address) {
+ return Ipv6BinaryAfi.class;
+ }
+ return null;
+ }
+
+ public static Address binaryAddressFromInet(InetAddress address) {
+ if (address instanceof Inet4Address) {
+ return (Address) new Ipv4BinaryBuilder().setIpv4Binary(new Ipv4AddressBinary(address.getAddress())).build();
+ } else if (address instanceof Inet6Address) {
+ return (Address) new Ipv6BinaryBuilder().setIpv6Binary(new Ipv6AddressBinary(address.getAddress())).build();
+ }
+ return null;
+ }
+
public static Class<? extends LispAddressFamily> addressTypeFromIpAddress(IpAddress address) {
if (address == null) {
return null;
public static Rloc toRloc(InetAddress address) {
RlocBuilder builder = new RlocBuilder();
- builder.setAddressType(addressTypeFromInet(address));
+ builder.setAddressType(binaryAddressTypeFromInet(address));
builder.setVirtualNetworkId(null);
- builder.setAddress(addressFromInet(address));
+ builder.setAddress(binaryAddressFromInet(address));
return builder.build();
}
return toEid(new Ipv4AddressBinary(InetAddresses.forString(address).getAddress()), new InstanceIdType(vni));
}
+ public static Eid asBinaryEid(SimpleAddress address, InstanceIdType iid) {
+ if (address.getIpPrefix() != null) {
+ if (address.getIpPrefix().getIpv4Prefix() != null) {
+ return LispAddressUtil.asIpv4PrefixBinaryEid(address.getIpPrefix().getIpv4Prefix().getValue(), iid);
+ } else if (address.getIpPrefix().getIpv6Prefix() != null) {
+ return LispAddressUtil.asIpv6PrefixBinaryEid(address.getIpPrefix().getIpv6Prefix().getValue(), iid);
+ }
+ } else if (address.getIpAddress() != null) {
+ if (address.getIpAddress().getIpv4Address() != null) {
+ LispAddressUtil.toEid(new Ipv4AddressBinary(InetAddresses.forString(
+ address.getIpPrefix().getIpv4Prefix().getValue()).getAddress()), iid);
+ } else if (address.getIpAddress().getIpv6Address() != null) {
+ LispAddressUtil.toEid(new Ipv6AddressBinary(InetAddresses.forString(
+ address.getIpPrefix().getIpv6Prefix().getValue()).getAddress()), iid);
+ }
+ }
+ return LispAddressUtil.asEid(address, iid);
+ }
+
public static int ipVersionFromString(String ip) {
if (IP4_PATTERN.matcher(ip).matches()) {
return 4;
return new Ipv6BinaryBuilder().setIpv6Binary(new Ipv6AddressBinary(addr)).build();
}
- public static Eid convertToBinary(Eid eid) {
- EidBuilder eb = new EidBuilder(eid);
- Address addr = eid.getAddress();
+ private static Pair<Class<? extends LispAddressFamily>, Address> convertToBinary(Address addr) {
Address convAddr = null;
+ Class<? extends LispAddressFamily> convType = null;
if (addr instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix) {
convAddr = convertToBinary((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix) addr);
+ convType = Ipv4PrefixBinaryAfi.class;
} else if (addr instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix) {
convAddr = convertToBinary((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix) addr);
+ convType = Ipv6PrefixBinaryAfi.class;
} else if (addr instanceof Ipv4) {
convAddr = convertToBinary((Ipv4) addr);
+ convType = Ipv4BinaryAfi.class;
} else if (addr instanceof Ipv6) {
convAddr = convertToBinary((Ipv6) addr);
- } else {
+ convType = Ipv6BinaryAfi.class;
+ }
+ return new ImmutablePair<Class<? extends LispAddressFamily>, Address>(convType, convAddr);
+ }
+
+ public static Eid convertToBinary(Eid eid) {
+ Pair<Class<? extends LispAddressFamily>, Address> converted = convertToBinary(eid.getAddress());
+ if (converted.getRight() == null) {
return eid;
}
- eb.setAddress(convAddr);
+ EidBuilder eb = new EidBuilder(eid);
+ eb.setAddressType(converted.getLeft());
+ eb.setAddress(converted.getRight());
return eb.build();
}
+ public static Rloc convertToBinary(Rloc rloc) {
+ Pair<Class<? extends LispAddressFamily>, Address> converted = convertToBinary(rloc.getAddress());
+ if (converted.getRight() == null) {
+ return rloc;
+ }
+ RlocBuilder rb = new RlocBuilder(rloc);
+ rb.setAddressType(converted.getLeft());
+ rb.setAddress(converted.getRight());
+ return rb.build();
+ }
+
+ public static boolean addressNeedsConversionToBinary(Address address) {
+ if (address instanceof Ipv4 || address instanceof Ipv6 ||
+ address instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
+ .lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix ||
+ address instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
+ .lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix) {
+ return true;
+ }
+ return false;
+ }
+
public static int compareIpAddressByteArrays(byte[] a, byte[] b) {
int i;
if (a.length < b.length) {
}
}
+ public static Eid getSrcBinary(Eid eid) {
+ if (eid.getAddress() instanceof SourceDestKey) {
+ return LispAddressUtil.asBinaryEid(((SourceDestKey) eid.getAddress()).getSourceDestKey().getSource(),
+ eid.getVirtualNetworkId());
+ }
+ return eid;
+ }
+
+ public static Eid getDstBinary(Eid eid) {
+ if (eid.getAddress() instanceof SourceDestKey) {
+ return LispAddressUtil.asBinaryEid(((SourceDestKey) eid.getAddress()).getSourceDestKey().getDest(),
+ eid.getVirtualNetworkId());
+ }
+ return eid;
+ }
+
public static short getSrcMask(Eid eid) {
Address addr = eid.getAddress();
if (!isSrcDst(addr)) {
public void toRloc() throws UnknownHostException {
InetAddress ipv4AddressInet = Inet4Address.getByAddress(IPV4_ADDRESS_BYTES_A_TEST);
final Rloc rlocFromInetAddress = LispAddressUtil.toRloc(ipv4AddressInet);
- assertEquals(Ipv4Afi.class, rlocFromInetAddress.getAddressType());
- assertEquals(IPV4_ADDRESS_VALUE_TEST, ((Ipv4)rlocFromInetAddress.getAddress()).getIpv4().getValue());
+ assertEquals(Ipv4BinaryAfi.class, rlocFromInetAddress.getAddressType());
+ assertEquals(IPV4_ADDRESS_BINARY_TEST, ((Ipv4Binary) rlocFromInetAddress.getAddress()).getIpv4Binary());
final Rloc rlocFromIpv4Address = LispAddressUtil.toRloc(IPV4_ADDRESS_TEST);
assertEquals(Ipv4Afi.class, rlocFromIpv4Address.getAddressType());
ILispDAO table = getOrInstantiateVniTable(key);
if (eid.getAddress() instanceof SourceDestKey) {
- Eid srcKey = SourceDestKeyHelper.getSrc(eid);
+ Eid srcKey = SourceDestKeyHelper.getSrcBinary(eid);
ILispDAO srcDstDao = getOrInstantiateSDInnerDao(eid, table);
srcDstDao.put(srcKey, new MappingEntry<>(SubKeys.REGDATE, new Date(System.currentTimeMillis())));
srcDstDao.put(srcKey, new MappingEntry<>(SubKeys.RECORD, value));
// a map-request for an actual SrcDst LCAF, ignore src eid
if (dstEid.getAddress() instanceof SourceDestKey) {
- Eid srcAddr = SourceDestKeyHelper.getSrc(dstEid);
- Eid dstAddr = SourceDestKeyHelper.getDst(dstEid);
+ Eid srcAddr = SourceDestKeyHelper.getSrcBinary(dstEid);
+ Eid dstAddr = SourceDestKeyHelper.getDstBinary(dstEid);
return getMappingLpmSD(srcAddr, dstAddr, table);
}
if (key.getAddress() instanceof SourceDestKey) {
ILispDAO db = getSDInnerDao(key, table);
if (db != null) {
- db.removeSpecific(SourceDestKeyHelper.getSrc(key),
+ db.removeSpecific(SourceDestKeyHelper.getSrcBinary(key),
SubKeys.RECORD);
}
} else {
if (key.getAddress() instanceof SourceDestKey) {
ILispDAO srcDstDao = getOrInstantiateSDInnerDao(key, table);
- srcDstDao.put(SourceDestKeyHelper.getSrc(key), new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
+ srcDstDao.put(SourceDestKeyHelper.getSrcBinary(key), new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
} else {
table.put(key, new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
}
// NOTE: this is an exact match, not a longest prefix match
ILispDAO srcDstDao = getSDInnerDao(eid, table);
if (srcDstDao != null) {
- return getAuthKeyLpm(SourceDestKeyHelper.getSrc(eid), srcDstDao);
+ return getAuthKeyLpm(SourceDestKeyHelper.getSrcBinary(eid), srcDstDao);
}
return null;
} else {
// SrcDst LCAFs are stored in a 2-tier DAO with dst having priority over src.
// This method returns the DAO associated to a dst or creates it if it doesn't exist.
private ILispDAO getOrInstantiateSDInnerDao(Eid address, ILispDAO dao) {
- Eid dstKey = SourceDestKeyHelper.getDst(address);
+ Eid dstKey = SourceDestKeyHelper.getDstBinary(address);
ILispDAO srcDstDao = (ILispDAO) dao.getSpecific(dstKey, SubKeys.LCAF_SRCDST);
if (srcDstDao == null) {
// inserts nested table for source
// SrcDst LCAFs are stored in a 2-tier DAO with dst having priority over src.
// This method returns the DAO associated to dst or null if it doesn't exist.
private ILispDAO getSDInnerDao(Eid address, ILispDAO dao) {
- return (ILispDAO) dao.getSpecific(SourceDestKeyHelper.getDst(address), SubKeys.LCAF_SRCDST);
+ return (ILispDAO) dao.getSpecific(SourceDestKeyHelper.getDstBinary(address), SubKeys.LCAF_SRCDST);
}
public String printMappings() {
if (key.getAddress() instanceof SourceDestKey) {
ILispDAO srcDstDao = getOrInstantiateSDInnerDao(key, table);
- srcDstDao.put(SourceDestKeyHelper.getSrc(key), new MappingEntry<Object>(subKey, data));
+ srcDstDao.put(SourceDestKeyHelper.getSrcBinary(key), new MappingEntry<Object>(subKey, data));
} else {
table.put(key, new MappingEntry<Object>(subKey, data));
}
if (key.getAddress() instanceof SourceDestKey) {
ILispDAO srcDstDao = getSDInnerDao(key, table);
- return srcDstDao.getSpecific(SourceDestKeyHelper.getSrc(key), subKey);
+ return srcDstDao.getSpecific(SourceDestKeyHelper.getSrcBinary(key), subKey);
} else {
return table.getSpecific(key, subKey);
}
if (key.getAddress() instanceof SourceDestKey) {
ILispDAO db = getSDInnerDao(key, table);
if (db != null) {
- db.removeSpecific(SourceDestKeyHelper.getSrc(key), subKey);
+ db.removeSpecific(SourceDestKeyHelper.getSrcBinary(key), subKey);
}
} else {
table.removeSpecific(key, subKey);
public void addMappingTest_withSourceDestKey() {
final Eid normalized_Eid = MaskUtil.normalize(EID_SOURCE_DEST_KEY_TYPE);
- final Eid dstKey = SourceDestKeyHelper.getDst(normalized_Eid);
- final Eid srcKey = SourceDestKeyHelper.getSrc(normalized_Eid);
+ final Eid dstKey = SourceDestKeyHelper.getDstBinary(normalized_Eid);
+ final Eid srcKey = SourceDestKeyHelper.getSrcBinary(normalized_Eid);
when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
when(tableDaoMock.getSpecific(dstKey, SubKeys.LCAF_SRCDST)).thenReturn(srcDstDaoMock);
public void getMappingTest_withSourceDestKey() {
when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
- final Eid dstAddr = SourceDestKeyHelper.getDst(EID_SOURCE_DEST_KEY_TYPE);
+ final Eid dstAddr = SourceDestKeyHelper.getDstBinary(EID_SOURCE_DEST_KEY_TYPE);
final Eid normalizedDstAddr = MaskUtil.normalize(dstAddr);
- final Eid srcAddr = SourceDestKeyHelper.getSrc(EID_SOURCE_DEST_KEY_TYPE);
+ final Eid srcAddr = SourceDestKeyHelper.getSrcBinary(EID_SOURCE_DEST_KEY_TYPE);
final Eid normalizedSrcAddr = MaskUtil.normalize(srcAddr);
final Map<String, Object> entry = getEntry1();
when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
when(tableDaoMock.getSpecific(SourceDestKeyHelper
- .getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST)).thenReturn(dbMock);
+ .getDstBinary(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST)).thenReturn(dbMock);
multiTableMapCache.removeMapping(EID_SOURCE_DEST_KEY_TYPE, true);
- verify(dbMock).removeSpecific(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID),
+ verify(dbMock).removeSpecific(SourceDestKeyHelper.getSrcBinary(NORMALIZED_SRCDST_EID),
SubKeys.RECORD);
}
@Test
public void addAuthenticationKeyTest() {
when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
- when(tableDaoMock.putNestedTable(SourceDestKeyHelper.getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
+ when(tableDaoMock.putNestedTable(SourceDestKeyHelper.getDstBinary(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
.thenReturn(srcDstDaoMock);
multiTableMapCache.addAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE, MAPPING_AUTHKEY);
- verify(srcDstDaoMock).put(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID),
+ verify(srcDstDaoMock).put(SourceDestKeyHelper.getSrcBinary(NORMALIZED_SRCDST_EID),
new MappingEntry<>(SubKeys.AUTH_KEY, MAPPING_AUTHKEY));
multiTableMapCache.addAuthenticationKey(EID_TEST, MAPPING_AUTHKEY);
*/
@Test
public void getAuthenticationKeyTest_withSourceDestKey() {
- final Eid eidSrc = SourceDestKeyHelper.getSrc(EID_SOURCE_DEST_KEY_TYPE);
- final Eid eidDst = SourceDestKeyHelper.getDst(EID_SOURCE_DEST_KEY_TYPE);
+ final Eid eidSrc = SourceDestKeyHelper.getSrcBinary(EID_SOURCE_DEST_KEY_TYPE);
+ final Eid eidDst = SourceDestKeyHelper.getDstBinary(EID_SOURCE_DEST_KEY_TYPE);
final short maskLength = MaskUtil.getMaskForAddress(eidSrc.getAddress());
final Eid key = MaskUtil.normalize(eidSrc, maskLength);
*/
@Test
public void getAuthenticationKeyTest_withSourceDestKey_nullDao() {
- final Eid eidDst = SourceDestKeyHelper.getDst(EID_SOURCE_DEST_KEY_TYPE);
+ final Eid eidDst = SourceDestKeyHelper.getDstBinary(EID_SOURCE_DEST_KEY_TYPE);
when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
when(tableDaoMock.getSpecific(eidDst, SubKeys.LCAF_SRCDST))
@Test
public void removeAuthenticationKeyTest_withSourceDestKey() {
when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
- when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
+ when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDstBinary(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
.thenReturn(srcDstDaoMock);
multiTableMapCache.removeAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE);
@Test
public void addDataTest_withSourceDestKey() {
when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
- when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
+ when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDstBinary(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
.thenReturn(srcDstDaoMock);
multiTableMapCache.addData(EID_SOURCE_DEST_KEY_TYPE, SubKeys.RECORD, DUMMY_OBJECT);
- verify(srcDstDaoMock).put(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID),
+ verify(srcDstDaoMock).put(SourceDestKeyHelper.getSrcBinary(NORMALIZED_SRCDST_EID),
new MappingEntry<>(SubKeys.RECORD, DUMMY_OBJECT));
}
@Test
public void getDataTest_withSourceDestKey() {
when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
- when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
+ when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDstBinary(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
.thenReturn(srcDstDaoMock);
- when(srcDstDaoMock.getSpecific(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID), SubKeys.RECORD))
+ when(srcDstDaoMock.getSpecific(SourceDestKeyHelper.getSrcBinary(NORMALIZED_SRCDST_EID), SubKeys.RECORD))
.thenReturn(DUMMY_OBJECT);
assertEquals(DUMMY_OBJECT, multiTableMapCache.getData(EID_SOURCE_DEST_KEY_TYPE, SubKeys.RECORD));
@Test
public void removeDataTest_withSourceDestKey() {
when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
- when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
+ when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDstBinary(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
.thenReturn(srcDstDaoMock);
multiTableMapCache.removeData(EID_SOURCE_DEST_KEY_TYPE, SubKeys.RECORD);
- verify(srcDstDaoMock).removeSpecific(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID), SubKeys.RECORD);
+ verify(srcDstDaoMock).removeSpecific(SourceDestKeyHelper.getSrcBinary(NORMALIZED_SRCDST_EID), SubKeys.RECORD);
}
/**
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
import org.opendaylight.lispflowmapping.mapcache.SimpleMapCache;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
private static AuthenticationKey convertToBinaryIfNecessary(AuthenticationKey authKey) {
Eid originalEid = authKey.getEid();
- if (originalEid.getAddress() instanceof Ipv4Prefix || originalEid.getAddress() instanceof Ipv6Prefix ||
- originalEid.getAddress() instanceof Ipv4 || originalEid.getAddress() instanceof Ipv6) {
+ if (LispAddressUtil.addressNeedsConversionToBinary(originalEid.getAddress())) {
AuthenticationKeyBuilder akb = new AuthenticationKeyBuilder(authKey);
akb.setEid(LispAddressUtil.convertToBinary(originalEid));
return akb.build();