summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-05-16 12:48:47 +0200
committerMarek Gradzki <mgradzki@cisco.com>2017-05-18 09:32:02 +0000
commitf1189488bce92471d6e5e5a666befa2340bd20ae (patch)
tree020200cab38d98cec1dd6f45db018b6bca44efe0 /lisp/lisp2vpp/src
parentb4b8fba02e15dd061f0bc05fb87f121980893ca1 (diff)
HC2VPP-90 - Ipv4/Ipv6 prefix based eid's support
- adds full support for prefix based eid's ,both in non-normalized and normalized form Change-Id: I22451d20e0f9b540da447c8f120b917e0b30a6b7 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src')
-rw-r--r--lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/context/util/EidMappingContext.java4
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizer.java12
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizer.java7
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizer.java7
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/dump/executor/params/MappingsDumpParams.java34
-rw-r--r--lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/trait/MappingProducer.java16
-rw-r--r--lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/trait/MappingReader.java6
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/EidTranslator.java295
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizer.java10
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizer.java17
-rwxr-xr-xlisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizer.java9
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java64
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/AdjacencyData.java27
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java69
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizerTest.java73
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizerTest.java70
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/util/EidTranslatorTest.java172
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java90
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java44
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java41
20 files changed, 926 insertions, 141 deletions
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/context/util/EidMappingContext.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/context/util/EidMappingContext.java
index 5288a609d..9cb489940 100644
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/context/util/EidMappingContext.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/context/util/EidMappingContext.java
@@ -188,13 +188,13 @@ public class EidMappingContext implements EidTranslator {
private Eid copyEid(
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.Eid eid) {
- return new EidBuilder().setAddress(eid.getAddress()).setAddressType(eid.getAddressType())
+ return new EidBuilder().setAddress(normalizeIfPrefixBased(eid.getAddress())).setAddressType(eid.getAddressType())
.setVirtualNetworkId(eid.getVirtualNetworkId()).build();
}
private Eid copyEid(
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.remote.mappings.remote.mapping.Eid eid) {
- return new EidBuilder().setAddress(eid.getAddress()).setAddressType(eid.getAddressType())
+ return new EidBuilder().setAddress(normalizeIfPrefixBased(eid.getAddress())).setAddressType(eid.getAddressType())
.setVirtualNetworkId(eid.getVirtualNetworkId()).build();
}
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizer.java
index 72ed941f5..afbe2f3bf 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizer.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizer.java
@@ -145,9 +145,11 @@ public class AdjacencyCustomizer extends FutureJVppCustomizer
builder.setId(currentAdjacencyId)
.setKey(new AdjacencyKey(currentAdjacencyId))
.setLocalEid(getArrayAsLocalEid(
- MappingsDumpParams.EidType.valueOf(currentAdjacency.eidType), currentAdjacency.leid, vni))
+ MappingsDumpParams.EidType.valueOf(currentAdjacency.eidType), currentAdjacency.leid,
+ currentAdjacency.leidPrefixLen, vni))
.setRemoteEid(getArrayAsRemoteEid(
- MappingsDumpParams.EidType.valueOf(currentAdjacency.eidType), currentAdjacency.reid, vni));
+ MappingsDumpParams.EidType.valueOf(currentAdjacency.eidType), currentAdjacency.reid,
+ currentAdjacency.reidPrefixLen, vni));
}
private EntityDumpExecutor<OneAdjacenciesGetReply, AdjacencyDumpParams> createExecutor() {
@@ -199,9 +201,11 @@ public class AdjacencyCustomizer extends FutureJVppCustomizer
final MappingContext mappingContext) {
return new EidIdentificatorPairBuilder()
.setLocalEidId(new MappingId(localMappingContext.getId(getArrayAsEidLocal(
- MappingsDumpParams.EidType.valueOf(data.eidType), data.leid, vni), mappingContext)))
+ MappingsDumpParams.EidType.valueOf(data.eidType), data.leid, data.leidPrefixLen, vni),
+ mappingContext)))
.setRemoteEidId(new MappingId(remoteMappingContext.getId(getArrayAsEidLocal(
- MappingsDumpParams.EidType.valueOf(data.eidType), data.reid, vni), mappingContext)))
+ MappingsDumpParams.EidType.valueOf(data.eidType), data.reid, data.reidPrefixLen, vni),
+ mappingContext)))
.build();
}
}
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizer.java
index ff71d9c00..81409296d 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizer.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizer.java
@@ -105,7 +105,6 @@ public class LocalMappingCustomizer
final long vni = id.firstKeyOf(VniTable.class).getVirtualNetworkIdentifier();
- final String localMappingId = id.firstKeyOf(LocalMapping.class).getId().getValue();
final Eid eid = localMappingContext.getEid(mappingId, ctx.getMappingContext());
//Requesting for specific mapping dump,only from local mappings with specified eid/vni/eid type
@@ -135,7 +134,7 @@ public class LocalMappingCustomizer
"No Locator Set name found for index %s", details.locatorSetIndex);
builder.setLocatorSet(locatorSetContext.getName(details.locatorSetIndex, ctx.getMappingContext()));
builder.setKey(new LocalMappingKey(new MappingId(id.firstKeyOf(LocalMapping.class).getId())));
- builder.setEid(getArrayAsEidLocal(valueOf(details.eidType), details.eid, details.vni));
+ builder.setEid(getArrayAsEidLocal(valueOf(details.eidType), details.eid, details.eidPrefixLen, details.vni));
if (details.key != null) {
builder.setHmacKey(
@@ -149,7 +148,7 @@ public class LocalMappingCustomizer
}
private Address getAddressFromDumpDetail(final OneEidTableDetails detail) {
- return getArrayAsEidLocal(valueOf(detail.eidType), detail.eid, detail.vni).getAddress();
+ return getArrayAsEidLocal(valueOf(detail.eidType), detail.eid, detail.eidPrefixLen, detail.vni).getAddress();
}
@Override
@@ -184,7 +183,7 @@ public class LocalMappingCustomizer
return replyOptional.get().oneEidTableDetails.stream()
.filter(a -> a.vni == vni)
.filter(subtableFilterForLocalMappings(id))
- .map(detail -> getArrayAsEidLocal(valueOf(detail.eidType), detail.eid, detail.vni))
+ .map(detail -> getArrayAsEidLocal(valueOf(detail.eidType), detail.eid, detail.eidPrefixLen, detail.vni))
.map(localEid -> localMappingContext.getId(localEid, context.getMappingContext()))
.map(MappingId::new)
.map(LocalMappingKey::new)
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizer.java
index 2ba9eb831..04b89a59f 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizer.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizer.java
@@ -148,7 +148,6 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer
"No mapping stored for id %s", mappingId);
final long vni = id.firstKeyOf(VniTable.class).getVirtualNetworkIdentifier();
- final String remoteMappingId = id.firstKeyOf(RemoteMapping.class).getId().getValue();
final Eid eid = copyEid(remoteMappingContext.getEid(mappingId, ctx.getMappingContext()));
final MappingsDumpParams dumpParams = new MappingsDumpParamsBuilder()
.setVni(Long.valueOf(vni).intValue())
@@ -172,11 +171,11 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer
OneEidTableDetails details = replyOptional.get().oneEidTableDetails.stream()
.filter(subtableFilterForRemoteMappings(id))
.filter(a -> compareAddresses(eid.getAddress(),
- getArrayAsEidLocal(valueOf(a.eidType), a.eid, a.vni).getAddress()))
+ getArrayAsEidLocal(valueOf(a.eidType), a.eid, a.eidPrefixLen, a.vni).getAddress()))
.collect(
RWUtils.singleItemCollector());
- builder.setEid(getArrayAsEidRemote(valueOf(details.eidType), details.eid, details.vni));
+ builder.setEid(getArrayAsEidRemote(valueOf(details.eidType), details.eid, details.eidPrefixLen, details.vni));
builder.setKey(new RemoteMappingKey(new MappingId(id.firstKeyOf(RemoteMapping.class).getId())));
builder.setTtl(resolveTtl(details.ttl));
builder.setAuthoritative(
@@ -217,7 +216,7 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer
.stream()
.filter(a -> a.vni == vni)
.filter(subtableFilterForRemoteMappings(id))
- .map(detail -> getArrayAsEidRemote(valueOf(detail.eidType), detail.eid, detail.vni))
+ .map(detail -> getArrayAsEidRemote(valueOf(detail.eidType), detail.eid, detail.eidPrefixLen, detail.vni))
.map(remoteEid -> remoteMappingContext.getId(remoteEid, context.getMappingContext()))
.map(MappingId::new)
.map(RemoteMappingKey::new)
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/dump/executor/params/MappingsDumpParams.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/dump/executor/params/MappingsDumpParams.java
index 6b422f503..3c440668d 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/dump/executor/params/MappingsDumpParams.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/dump/executor/params/MappingsDumpParams.java
@@ -16,7 +16,9 @@
package io.fd.hc2vpp.lisp.translate.read.dump.executor.params;
+import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
+import java.util.Map;
/**
* Parameters for executing dump of mappings
@@ -82,15 +84,27 @@ public final class MappingsDumpParams {
public enum EidType {
IPV4(0),
IPV6(1),
- MAC(2);
-
+ MAC(2),
+ IPV4_PREFIX(3),
+ IPV6_PREFIX(4);
+
+ /**
+ * From vpp api perspective, ipv4 is the same as ipv4-prefix, it differs just in prefix value.
+ * Respectively for ipv6/ipv6-prefix
+ */
+ private static final Map<EidType, Integer> VPP_EID_TYPE_REGISTER = ImmutableMap.of(
+ IPV4, 0, IPV6, 1, MAC, 2, IPV4_PREFIX, 0, IPV6_PREFIX, 1);
+
+ /**
+ * This value should be use just for our logic, do not use it to bind vpp requests
+ */
private final int value;
private EidType(final int value) {
this.value = value;
}
- public static final EidType valueOf(int value) {
+ public static EidType valueOf(int value) {
switch (value) {
case 0:
return IPV4;
@@ -98,13 +112,17 @@ public final class MappingsDumpParams {
return IPV6;
case 2:
return MAC;
+ case 3:
+ return IPV4_PREFIX;
+ case 4:
+ return IPV6_PREFIX;
default:
throw new IllegalArgumentException("Illegal value");
}
}
- public final int getValue() {
- return this.value;
+ public final int getVppTypeBinding() {
+ return VPP_EID_TYPE_REGISTER.get(this);
}
}
@@ -150,10 +168,6 @@ public final class MappingsDumpParams {
private byte[] eid;
private byte filter;
- public static final MappingsDumpParamsBuilder newInstance() {
- return new MappingsDumpParamsBuilder();
- }
-
public MappingsDumpParamsBuilder setEidSet(final QuantityType quantityType) {
this.eidSet = (byte) quantityType.getValue();
return this;
@@ -170,7 +184,7 @@ public final class MappingsDumpParams {
}
public MappingsDumpParamsBuilder setEidType(final EidType eidType) {
- this.eidType = (byte) eidType.getValue();
+ this.eidType = (byte) eidType.getVppTypeBinding();
return this;
}
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/trait/MappingProducer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/trait/MappingProducer.java
index c9694c7a6..bceae832e 100644
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/trait/MappingProducer.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/trait/MappingProducer.java
@@ -16,10 +16,14 @@
package io.fd.hc2vpp.lisp.translate.read.trait;
+import com.google.common.collect.ImmutableSet;
import io.fd.honeycomb.translate.write.WriteFailedException;
+import java.util.Set;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4PrefixAfi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6PrefixAfi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.LocalMapping;
@@ -33,15 +37,21 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
*/
public interface MappingProducer {
+ Set<Class<? extends LispAddressFamily>> VRF_ALLOWED_ADDRESS_TYPES = ImmutableSet.of(
+ Ipv4Afi.class,
+ Ipv6Afi.class,
+ Ipv4PrefixAfi.class,
+ Ipv6PrefixAfi.class);
+
/**
- * Checks whether provided {@link LocalMapping} can be written under subtree idenfied by {@link InstanceIdentifier}
+ * Checks whether provided {@link LocalMapping} can be written under subtree identified by {@link InstanceIdentifier}
*/
default void checkAllowedCombination(@Nonnull final InstanceIdentifier<LocalMapping> identifier,
@Nonnull final LocalMapping data) throws WriteFailedException {
final Class<? extends LispAddressFamily> eidAddressType = data.getEid().getAddressType();
if (identifier.firstIdentifierOf(VrfSubtable.class) != null) {
- if (Ipv4Afi.class != eidAddressType && Ipv6Afi.class != eidAddressType) {
+ if (!VRF_ALLOWED_ADDRESS_TYPES.contains(eidAddressType)) {
throw new WriteFailedException.CreateFailedException(identifier, data,
new IllegalArgumentException("Only Ipv4/Ipv6 eid's are allowed for Vrf Subtable"));
}
@@ -58,7 +68,7 @@ public interface MappingProducer {
final Class<? extends LispAddressFamily> eidAddressType = data.getEid().getAddressType();
if (identifier.firstIdentifierOf(VrfSubtable.class) != null) {
- if (Ipv4Afi.class != eidAddressType && Ipv6Afi.class != eidAddressType) {
+ if (!VRF_ALLOWED_ADDRESS_TYPES.contains(eidAddressType)) {
throw new WriteFailedException.CreateFailedException(identifier, data,
new IllegalArgumentException("Only Ipv4/Ipv6 eid's are allowed for Vrf Subtable"));
}
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/trait/MappingReader.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/trait/MappingReader.java
index bad719d01..993a6451c 100644
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/trait/MappingReader.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/trait/MappingReader.java
@@ -37,15 +37,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
- * Trait providing predicates to filter mappings to respective subtables
+ * Trait providing predicates to filter mappings to respective sub-tables
*/
public interface MappingReader extends JvppReplyConsumer {
Predicate<OneEidTableDetails> BRIDGE_DOMAIN_MAPPINGS_ONLY =
- (OneEidTableDetails detail) -> detail.eidType == MAC.getValue();
+ (OneEidTableDetails detail) -> detail.eidType == MAC.getVppTypeBinding();
Predicate<OneEidTableDetails> VRF_MAPPINGS_ONLY =
- (OneEidTableDetails detail) -> detail.eidType == IPV4.getValue() || detail.eidType == IPV6.getValue();
+ (OneEidTableDetails detail) -> detail.eidType == IPV4.getVppTypeBinding() || detail.eidType == IPV6.getVppTypeBinding();
default Predicate<OneEidTableDetails> subtableFilterForLocalMappings(
@Nonnull final InstanceIdentifier<LocalMapping> identifier) {
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/EidTranslator.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/EidTranslator.java
index 2c65c0c8f..deae3f5f6 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/EidTranslator.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/util/EidTranslator.java
@@ -16,40 +16,59 @@
package io.fd.hc2vpp.lisp.translate.util;
+import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType;
import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4;
+import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4_PREFIX;
import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV6;
+import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV6_PREFIX;
import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.MAC;
+import static java.lang.Integer.parseInt;
+import static java.lang.String.format;
+import inet.ipaddr.IPAddress;
import io.fd.hc2vpp.common.translate.util.AddressTranslator;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Arrays;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4PrefixAfi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6PrefixAfi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
+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.Ipv4PrefixBuilder;
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.Ipv6Builder;
+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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6PrefixBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.adjacencies.adjacency.LocalEid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.adjacencies.adjacency.RemoteEid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.Eid;
+import org.slf4j.Logger;
/**
* Trait providing converting logic for eid's
*/
+// TODO - HC2VPP-149 - restructuralize code
public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
+ byte DEFAULT_V4_PREFIX = 32;
+ byte DEFAULT_V6_PREFIX = (byte) 128;
+
default byte getPrefixLength(LocalEid address) {
return resolverPrefixLength(address.getAddress());
}
@@ -77,57 +96,103 @@ public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
switch (resolveType(address)) {
case IPV4:
- return 32;
+ return DEFAULT_V4_PREFIX;
case IPV6:
- return (byte) 128;
+ return DEFAULT_V6_PREFIX;
case MAC:
return 0;
+ case IPV4_PREFIX:
+ return extractPrefix(Ipv4Prefix.class.cast(address).getIpv4Prefix().getValue());
+ case IPV6_PREFIX:
+ return extractPrefix(Ipv6Prefix.class.cast(address).getIpv6Prefix().getValue());
default:
throw new IllegalArgumentException("Illegal type");
}
}
- default Eid getArrayAsEidLocal(@Nonnull final EidType type, final byte[] address, final int vni) {
+ static byte extractPrefix(final String data) {
+ return Byte.valueOf(data.substring(data.indexOf('/') + 1));
+ }
+
+ default Eid getArrayAsEidLocal(@Nonnull final EidType type, final byte[] address, final byte prefix,
+ final int vni) {
switch (type) {
case IPV4: {
- return newLocalEidBuilder(Ipv4Afi.class, vni).setAddress(
- new Ipv4Builder().setIpv4(arrayToIpv4AddressNoZone(address)).build())
- .build();
+ // vpp does no have separate constant for prefix based ,so if prefix is different than
+ // default, map it to prefix type. Same in any other logic switched by eid type
+ return prefix != DEFAULT_V4_PREFIX
+ ? newLocalEidBuilder(Ipv4PrefixAfi.class, vni).setAddress(
+ new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix(address, prefix)).build()).build()
+ : newLocalEidBuilder(Ipv4Afi.class, vni).setAddress(
+ new Ipv4Builder().setIpv4(arrayToIpv4AddressNoZone(address)).build())
+ .build();
}
case IPV6: {
- return newLocalEidBuilder(Ipv6Afi.class, vni).setAddress(
- new Ipv6Builder().setIpv6(arrayToIpv6AddressNoZone(address)).build())
- .build();
+ return prefix != DEFAULT_V6_PREFIX
+ ? newLocalEidBuilder(Ipv6PrefixAfi.class, vni).setAddress(
+ new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix(address, prefix)).build()).build()
+ : newLocalEidBuilder(Ipv6Afi.class, vni).setAddress(
+ new Ipv6Builder().setIpv6(arrayToIpv6AddressNoZone(address)).build())
+ .build();
}
case MAC: {
return newLocalEidBuilder(MacAfi.class, vni).setAddress(
new MacBuilder().setMac(new MacAddress(byteArrayToMacSeparated(address)))
.build()).build();
}
+ case IPV4_PREFIX: {
+ return newLocalEidBuilder(Ipv4PrefixAfi.class, vni).setAddress(
+ new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix(address, prefix)).build()).build();
+ }
+ case IPV6_PREFIX: {
+ return newLocalEidBuilder(Ipv6PrefixAfi.class, vni).setAddress(
+ new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix(address, prefix)).build()).build();
+ }
default: {
throw new IllegalStateException("Unknown type detected");
}
}
}
+ static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix v4Prefix(
+ final byte[] address, final byte prefix) {
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix(
+ prefixValue(INSTANCE.arrayToIpv4AddressNoZone(address).getValue(), String.valueOf(prefix)));
+ }
+
+ static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix v6Prefix(
+ final byte[] address, final byte prefix) {
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix(
+ prefixValue(INSTANCE.arrayToIpv6AddressNoZone(address).getValue(), String.valueOf(prefix)));
+ }
+
+ static String prefixValue(final String prefix, final String suffix) {
+ // normalize prefix based address to prevent duplicates
+ IPAddress normalizedForm = IPAddress.from(getAddress(prefix)).toSubnet(parseInt(suffix));
+
+ return normalizedForm.toCompressedString();
+ }
+
default org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.remote.mappings.remote.mapping.Eid getArrayAsEidRemote(
- @Nonnull final EidType type, final byte[] address, final int vni) {
+ @Nonnull final EidType type, final byte[] address, final byte prefix, final int vni) {
switch (type) {
case IPV4: {
- return newRemoteEidBuilder(Ipv4Afi.class, vni)
- .setAddress(
- new Ipv4Builder().setIpv4(arrayToIpv4AddressNoZone(address))
- .build())
- .build();
+ return prefix != DEFAULT_V4_PREFIX
+ ? newRemoteEidBuilder(Ipv4PrefixAfi.class, vni).setAddress(
+ new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix(address, prefix)).build()).build()
+ : newRemoteEidBuilder(Ipv4Afi.class, vni)
+ .setAddress(new Ipv4Builder().setIpv4(arrayToIpv4AddressNoZone(address)).build())
+ .build();
}
case IPV6: {
- return newRemoteEidBuilder(Ipv6Afi.class, vni)
- .setAddress(
- new Ipv6Builder().setIpv6(arrayToIpv6AddressNoZone(address))
- .build())
- .build();
+ return prefix != DEFAULT_V6_PREFIX
+ ? newRemoteEidBuilder(Ipv6PrefixAfi.class, vni).setAddress(
+ new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix(address, prefix)).build()).build()
+ : newRemoteEidBuilder(Ipv6Afi.class, vni)
+ .setAddress(new Ipv6Builder().setIpv6(arrayToIpv6AddressNoZone(address)).build())
+ .build();
}
case MAC: {
return newRemoteEidBuilder(MacAfi.class, vni)
@@ -135,15 +200,28 @@ public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
new MacBuilder().setMac(new MacAddress(byteArrayToMacSeparated(address)))
.build()).build();
}
+ case IPV4_PREFIX: {
+ return newRemoteEidBuilder(Ipv4PrefixAfi.class, vni).setAddress(
+ new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix(address, prefix)).build()).build();
+ }
+ case IPV6_PREFIX: {
+ return newRemoteEidBuilder(Ipv6PrefixAfi.class, vni).setAddress(
+ new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix(address, prefix)).build()).build();
+ }
default: {
throw new IllegalStateException("Unknown type detected");
}
}
}
- default LocalEid getArrayAsLocalEid(@Nonnull final EidType type, final byte[] address, final int vni) {
+ default LocalEid getArrayAsLocalEid(@Nonnull final EidType type, final byte[] address, final byte prefix,
+ final int vni) {
switch (type) {
case IPV4: {
+ if (prefix != DEFAULT_V4_PREFIX) {
+ return newEidBuilderLocal(Ipv4PrefixAfi.class, vni).setAddress(
+ new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix(address, prefix)).build()).build();
+ }
return newEidBuilderLocal(Ipv4Afi.class, vni)
.setAddress(
new Ipv4Builder().setIpv4(arrayToIpv4AddressNoZone(address))
@@ -151,6 +229,10 @@ public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
.build();
}
case IPV6: {
+ if (prefix != DEFAULT_V6_PREFIX) {
+ return newEidBuilderLocal(Ipv6PrefixAfi.class, vni).setAddress(
+ new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix(address, prefix)).build()).build();
+ }
return newEidBuilderLocal(Ipv6Afi.class, vni)
.setAddress(
new Ipv6Builder().setIpv6(arrayToIpv6AddressNoZone(address))
@@ -163,27 +245,38 @@ public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
new MacBuilder().setMac(new MacAddress(byteArrayToMacSeparated(address)))
.build()).build();
}
+ case IPV4_PREFIX: {
+ return newEidBuilderLocal(Ipv4PrefixAfi.class, vni).setAddress(
+ new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix(address, prefix)).build()).build();
+ }
+ case IPV6_PREFIX: {
+ return newEidBuilderLocal(Ipv6PrefixAfi.class, vni).setAddress(
+ new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix(address, prefix)).build()).build();
+ }
default: {
throw new IllegalStateException("Unknown type detected");
}
}
}
- default RemoteEid getArrayAsRemoteEid(@Nonnull final EidType type, final byte[] address, final int vni) {
+ default RemoteEid getArrayAsRemoteEid(@Nonnull final EidType type, final byte[] address, final byte prefix,
+ final int vni) {
switch (type) {
case IPV4: {
- return newEidBuilderRemote(Ipv4Afi.class, vni)
- .setAddress(
- new Ipv4Builder().setIpv4(arrayToIpv4AddressNoZone(address))
- .build())
- .build();
+ return (prefix != DEFAULT_V4_PREFIX)
+ ? newEidBuilderRemote(Ipv4PrefixAfi.class, vni).setAddress(
+ new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix(address, prefix)).build()).build()
+ : newEidBuilderRemote(Ipv4Afi.class, vni)
+ .setAddress(new Ipv4Builder().setIpv4(arrayToIpv4AddressNoZone(address)).build())
+ .build();
}
case IPV6: {
- return newEidBuilderRemote(Ipv6Afi.class, vni)
- .setAddress(
- new Ipv6Builder().setIpv6(arrayToIpv6AddressNoZone(address))
- .build())
- .build();
+ return prefix != DEFAULT_V6_PREFIX
+ ? newEidBuilderRemote(Ipv6PrefixAfi.class, vni)
+ .setAddress(new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix(address, prefix)).build()).build()
+ : newEidBuilderRemote(Ipv6Afi.class, vni)
+ .setAddress(new Ipv6Builder().setIpv6(arrayToIpv6AddressNoZone(address)).build())
+ .build();
}
case MAC: {
return newEidBuilderRemote(MacAfi.class, vni)
@@ -191,25 +284,42 @@ public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
new MacBuilder().setMac(new MacAddress(byteArrayToMacSeparated(address)))
.build()).build();
}
+ case IPV4_PREFIX: {
+ return newEidBuilderRemote(Ipv4PrefixAfi.class, vni).setAddress(
+ new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix(address, prefix)).build()).build();
+ }
+ case IPV6_PREFIX: {
+ return newEidBuilderRemote(Ipv6PrefixAfi.class, vni).setAddress(
+ new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix(address, prefix)).build()).build();
+ }
default: {
throw new IllegalStateException("Unknown type detected");
}
}
}
- default String getArrayAsEidString(
- EidType type, byte[] address) {
+ default String getArrayAsEidString(final EidType type, final byte[] address, final byte prefix) {
switch (type) {
case IPV4: {
- return arrayToIpv4AddressNoZone(address).getValue();
+ return prefix != DEFAULT_V4_PREFIX
+ ? v4Prefix(address, prefix).getValue()
+ : arrayToIpv4AddressNoZone(address).getValue();
}
case IPV6: {
- return arrayToIpv6AddressNoZone(address).getValue();
+ return prefix != DEFAULT_V6_PREFIX
+ ? v6Prefix(address, prefix).getValue()
+ : arrayToIpv6AddressNoZone(address).getValue();
}
case MAC: {
//as wrong as it looks ,its right(second param is not end index,but count)
return byteArrayToMacSeparated(Arrays.copyOfRange(address, 0, 6));
}
+ case IPV4_PREFIX: {
+ return v4Prefix(address, prefix).getValue();
+ }
+ case IPV6_PREFIX: {
+ return v6Prefix(address, prefix).getValue();
+ }
default: {
throw new IllegalStateException("Unknown type detected");
}
@@ -261,6 +371,10 @@ public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
return IPV6;
} else if (address instanceof Mac) {
return MAC;
+ } else if (address instanceof Ipv4Prefix) {
+ return IPV4_PREFIX;
+ } else if (address instanceof Ipv6Prefix) {
+ return IPV6_PREFIX;
} else {
throw new IllegalStateException("Unknown type detected");
}
@@ -308,11 +422,49 @@ public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
return ipv6AddressNoZoneToArray(new Ipv6AddressNoZone(((Ipv6) address).getIpv6()));
case MAC:
return parseMac(((Mac) address).getMac().getValue());
+ case IPV4_PREFIX:
+ return ipv4AddressPrefixToArray(v4LispPrefixToInetPrefix(Ipv4Prefix.class.cast(address)));
+ case IPV6_PREFIX:
+ return ipv6AddressPrefixToArray(v6LispPrefixToInetPrefix(Ipv6Prefix.class.cast(address)));
default:
throw new IllegalArgumentException("Unsupported type");
}
}
+ default Address normalizeIfPrefixBased(Address address){
+ if(address instanceof Ipv4Prefix){
+ final String[] parts = ((Ipv4Prefix) address).getIpv4Prefix().getValue().split("/");
+
+ return new Ipv4PrefixBuilder().setIpv4Prefix(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix(
+ prefixValue(parts[0], parts[1])))
+ .build();
+ }
+
+ if (address instanceof Ipv6Prefix){
+ final String[] parts = ((Ipv6Prefix) address).getIpv6Prefix().getValue().split("/");
+
+ return new Ipv6PrefixBuilder().setIpv6Prefix(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix(
+ prefixValue(parts[0], parts[1]))).build();
+ }
+
+ // if not prefix based, does nothing
+ return address;
+ }
+
+ static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix v4LispPrefixToInetPrefix(
+ final Ipv4Prefix prefix) {
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix(
+ prefix.getIpv4Prefix().getValue());
+ }
+
+ static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix v6LispPrefixToInetPrefix(
+ final Ipv6Prefix prefix) {
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix(
+ prefix.getIpv6Prefix().getValue());
+ }
+
default boolean compareEids(
LispAddress first,
LispAddress second) {
@@ -338,6 +490,77 @@ public interface EidTranslator extends AddressTranslator, EidMetadataProvider {
return ((Mac) firstAddress).getMac().getValue().equals(((Mac) secondAddress).getMac().getValue());
}
+ if (firstAddress instanceof Ipv4Prefix && secondAddress instanceof Ipv4Prefix) {
+
+ final String firstPrefix = ((Ipv4Prefix) firstAddress).getIpv4Prefix().getValue();
+ final String secondPrefix = ((Ipv4Prefix) secondAddress).getIpv4Prefix().getValue();
+
+ // for ex. 192.168.2.1/24 and 192.168.2.2/24 will be optimized to
+ // 192.168.2.0/24
+ return isSameSubnet(firstPrefix, secondPrefix);
+ }
+
+ if (firstAddress instanceof Ipv6Prefix && secondAddress instanceof Ipv6Prefix) {
+ final String firstPrefix = ((Ipv6Prefix) firstAddress).getIpv6Prefix().getValue();
+ final String secondPrefix = ((Ipv6Prefix) secondAddress).getIpv6Prefix().getValue();
+
+ // same here
+ return isSameSubnet(firstPrefix, secondPrefix);
+ }
+
return false;
}
+
+ /**
+ * Configuration data store whatever value is put, so it can be non-normalized, but
+ * vpp optimize all eid prefix based values, returns true if such case
+ */
+ default void checkIgnoredSubnetUpdate(@Nonnull final Address dataBefore,
+ @Nonnull final Address dataAfter,
+ @Nonnull Logger logger) {
+ boolean isSameSubnet = false;
+ if (dataBefore instanceof Ipv4Prefix && dataAfter instanceof Ipv4Prefix) {
+ isSameSubnet = isSameSubnet(((Ipv4Prefix) dataBefore).getIpv4Prefix().getValue(),
+ ((Ipv4Prefix) dataAfter).getIpv4Prefix().getValue());
+ }
+
+ if (dataBefore instanceof Ipv6Prefix && dataAfter instanceof Ipv6Prefix) {
+ isSameSubnet = isSameSubnet(((Ipv6Prefix) dataBefore).getIpv6Prefix().getValue(),
+ ((Ipv6Prefix) dataAfter).getIpv6Prefix().getValue());
+ }
+
+ if (isSameSubnet) {
+ logger.warn("Attempt to update address within same subnet detected, ignoring[{} vs {}]", dataBefore,
+ dataAfter);
+ return;
+ }
+
+ throw new UnsupportedOperationException("Operation not supported");
+ }
+
+ static boolean isSameSubnet(final String firstPrefix, final String secondPrefix) {
+ final String[] firstPrefixParts = getPrefixParts(firstPrefix);
+ final String[] secondPrefixParts = getPrefixParts(secondPrefix);
+
+ IPAddress firstAddress =
+ IPAddress.from(getAddress(firstPrefixParts[0])).toSubnet(parseInt(firstPrefixParts[1]));
+ IPAddress secondAddress =
+ IPAddress.from(getAddress(secondPrefixParts[0])).toSubnet(parseInt(secondPrefixParts[1]));
+
+ return firstAddress.compareTo(secondAddress) == 0;
+ }
+
+ static String[] getPrefixParts(final String prefixString) {
+ final String[] split = prefixString.split("/");
+ checkArgument(split.length == 2, "%s is not a valid ip prefix", prefixString);
+ return split;
+ }
+
+ static InetAddress getAddress(final String value) {
+ try {
+ return InetAddress.getByName(value);
+ } catch (UnknownHostException e) {
+ throw new IllegalArgumentException(format("Unable to convert %s", value), e);
+ }
+ }
}
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizer.java
index df5f431be..fc6de8653 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizer.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizer.java
@@ -41,11 +41,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.adjacencies.adjacency.RemoteEid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.eid.table.grouping.eid.table.VniTable;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class AdjacencyCustomizer extends FutureJVppCustomizer
implements ListWriterCustomizer<Adjacency, AdjacencyKey>, ByteDataTranslator, EidTranslator,
JvppReplyConsumer {
+ private static final Logger LOG = LoggerFactory.getLogger(AdjacencyCustomizer.class);
+
private final EidMappingContext localEidsMappingContext;
private final EidMappingContext remoteEidsMappingContext;
private final AdjacenciesMappingContext adjacenciesMappingContext;
@@ -97,7 +101,9 @@ public class AdjacencyCustomizer extends FutureJVppCustomizer
public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Adjacency> id,
@Nonnull final Adjacency dataBefore, @Nonnull final Adjacency dataAfter,
@Nonnull final WriteContext writeContext) throws WriteFailedException {
- throw new UnsupportedOperationException("Operation not supported");
+ // case that happens during initialization
+ checkIgnoredSubnetUpdate(dataBefore.getLocalEid().getAddress(), dataAfter.getLocalEid().getAddress(), LOG);
+ checkIgnoredSubnetUpdate(dataBefore.getRemoteEid().getAddress(), dataAfter.getRemoteEid().getAddress(), LOG);
}
@Override
@@ -145,7 +151,7 @@ public class AdjacencyCustomizer extends FutureJVppCustomizer
request.leidLen = getPrefixLength(localEid);
request.reid = getEidAsByteArray(remoteEid);
request.reidLen = getPrefixLength(remoteEid);
- request.eidType = (byte) localEidType.getValue();
+ request.eidType = (byte) localEidType.getVppTypeBinding();
request.vni = vni;
getReply(getFutureJVpp().oneAddDelAdjacency(request).toCompletableFuture());
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizer.java
index 582a37756..d3a03b298 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizer.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizer.java
@@ -18,8 +18,6 @@ package io.fd.hc2vpp.lisp.translate.write;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
-import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4;
-import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV6;
import static java.nio.charset.StandardCharsets.UTF_8;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
@@ -44,6 +42,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.eid.table.grouping.eid.table.VniTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.hmac.key.grouping.HmacKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -53,6 +53,8 @@ public class LocalMappingCustomizer extends FutureJVppCustomizer
implements ListWriterCustomizer<LocalMapping, LocalMappingKey>, ByteDataTranslator, EidTranslator,
JvppReplyConsumer, MappingProducer {
+ private static final Logger LOG = LoggerFactory.getLogger(LocalMappingCustomizer.class);
+
private final EidMappingContext localMappingsContext;
public LocalMappingCustomizer(@Nonnull FutureJVppCore futureJvpp, @Nonnull EidMappingContext localMappingsContext) {
@@ -85,7 +87,8 @@ public class LocalMappingCustomizer extends FutureJVppCustomizer
public void updateCurrentAttributes(InstanceIdentifier<LocalMapping> id, LocalMapping dataBefore,
LocalMapping dataAfter, WriteContext writeContext)
throws WriteFailedException {
- throw new UnsupportedOperationException("Operation not supported");
+ // case that happens during initialization
+ checkIgnoredSubnetUpdate(dataBefore.getEid().getAddress(), dataAfter.getEid().getAddress(), LOG);
}
@Override
@@ -120,16 +123,12 @@ public class LocalMappingCustomizer extends FutureJVppCustomizer
request.isAdd = booleanToByte(add);
request.eid = getEidAsByteArray(data.getEid());
- request.eidType = (byte) getEidType(data.getEid()).getValue();
+ request.eidType = (byte) getEidType(data.getEid()).getVppTypeBinding();
request.locatorSetName = data.getLocatorSet().getBytes(UTF_8);
request.vni = vni;
//default prefixes
- if (request.eidType == IPV4.getValue()) {
- request.prefixLen = 32;
- } else if (request.eidType == IPV6.getValue()) {
- request.prefixLen = (byte) 128;
- }
+ request.prefixLen = getPrefixLength(data.getEid());
final HmacKey hmacKey = data.getHmacKey();
if (hmacKey != null) {
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizer.java
index 056dcde1d..f6774890b 100755
--- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizer.java
+++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizer.java
@@ -51,6 +51,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.Rlocs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.eid.table.grouping.eid.table.VniTable;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -60,6 +62,8 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer
implements ListWriterCustomizer<RemoteMapping, RemoteMappingKey>, EidTranslator,
AddressTranslator, JvppReplyConsumer, MappingProducer {
+ private static final Logger LOG = LoggerFactory.getLogger(RemoteMappingCustomizer.class);
+
private final EidMappingContext remoteMappingContext;
public RemoteMappingCustomizer(@Nonnull final FutureJVppCore futureJvpp,
@@ -92,7 +96,8 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer
public void updateCurrentAttributes(InstanceIdentifier<RemoteMapping> id, RemoteMapping dataBefore,
RemoteMapping dataAfter, WriteContext writeContext)
throws WriteFailedException {
- throw new UnsupportedOperationException("Operation not supported");
+ // case that happens during initialization
+ checkIgnoredSubnetUpdate(dataBefore.getEid().getAddress(), dataAfter.getEid().getAddress(), LOG);
}
@Override
@@ -124,7 +129,7 @@ public class RemoteMappingCustomizer extends FutureJVppCustomizer
request.isAdd = booleanToByte(add);
request.vni = vni;
- request.eidType = (byte) getEidType(data.getEid()).getValue();
+ request.eidType = (byte) getEidType(data.getEid()).getVppTypeBinding();
request.eid = getEidAsByteArray(data.getEid());
//this is not length of eid array,but prefix length(bad naming by vpp)
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java
index f4325b00c..4dafb2176 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java
@@ -29,6 +29,8 @@ import org.mockito.MockitoAnnotations;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
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.Ipv4Builder;
+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.Ipv4PrefixBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.Eid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder;
@@ -42,11 +44,20 @@ public class EidMappingContextTest implements EidMappingContextHelper {
private EidMappingContext eidMappingContext;
private Eid localEid;
+ private Eid localPrefixBasedEid;
+ private Eid localPrefixBasedEidNormalized;
private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.remote.mappings.remote.mapping.Eid
remoteEid;
+ private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.remote.mappings.remote.mapping.Eid
+ remoteEidPrefixBased;
+ private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.remote.mappings.remote.mapping.Eid
+ remoteEidPrefixBasedNormalized;
private org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid
mappingEid;
+ private org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid
+ mappingEidPrefixBased;
private MappingId mappingId;
+ private MappingId mappingIdPrefixBased;
@Before
public void init() {
@@ -55,11 +66,24 @@ public class EidMappingContextTest implements EidMappingContextHelper {
localEid =
new EidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()).build();
+
+ localPrefixBasedEid = new EidBuilder().setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.2/24"))
+ .build()).build();
+
+ localPrefixBasedEidNormalized = new EidBuilder().setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.0/24"))
+ .build()).build();
+
remoteEid = fromLocalToRemoteEid(localEid);
+ remoteEidPrefixBased = fromLocalToRemoteEid(localPrefixBasedEid);
+ remoteEidPrefixBasedNormalized = fromLocalToRemoteEid(localPrefixBasedEidNormalized);
+ mappingEidPrefixBased = fromLocalToMappingEid(localPrefixBasedEidNormalized);
mappingEid = fromLocalToMappingEid(localEid);
mappingId = new MappingId("mapping");
-
+ mappingIdPrefixBased = new MappingId("mappingIdPrefixBased");
defineEidMapping(mappingContext, mappingEid, mappingId, EID_MAPPING_CONTEXT_NAME);
+ defineEidMapping(mappingContext, mappingEidPrefixBased, mappingIdPrefixBased, EID_MAPPING_CONTEXT_NAME);
}
@Test
@@ -72,20 +96,36 @@ public class EidMappingContextTest implements EidMappingContextHelper {
}
@Test
+ public void testContainsEidPrefixBased() {
+ assertTrue(eidMappingContext.containsEid(mappingIdPrefixBased, mappingContext));
+ org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid
+ loadedEid = eidMappingContext.getEid(mappingIdPrefixBased, mappingContext);
+
+ assertEquals("192.168.2.0/24", ((Ipv4Prefix) (loadedEid.getAddress())).getIpv4Prefix().getValue());
+ }
+
+ @Test
public void testContainsId() {
assertTrue(eidMappingContext.containsId(localEid, mappingContext));
assertTrue(eidMappingContext.containsId(remoteEid, mappingContext));
+ // detects both normalized and non-normalized form
+ assertTrue(eidMappingContext.containsId(localPrefixBasedEid, mappingContext));
+ assertTrue(eidMappingContext.containsId(localPrefixBasedEidNormalized, mappingContext));
}
@Test
public void testGetEid() {
assertEquals(mappingEid, eidMappingContext.getEid(mappingId, mappingContext));
+ assertEquals(mappingEidPrefixBased, eidMappingContext.getEid(mappingIdPrefixBased, mappingContext));
}
@Test
public void testGetId() {
assertEquals(mappingId, eidMappingContext.getId(localEid, mappingContext));
assertEquals(mappingId, eidMappingContext.getId(remoteEid, mappingContext));
+ // detects both normalized and non-normalized form
+ assertEquals(mappingIdPrefixBased, eidMappingContext.getId(localPrefixBasedEid, mappingContext));
+ assertEquals(mappingIdPrefixBased, eidMappingContext.getId(localPrefixBasedEidNormalized, mappingContext));
}
@Test
@@ -98,6 +138,17 @@ public class EidMappingContextTest implements EidMappingContextHelper {
}
@Test
+ public void testAddEidLocalPrefixBased() {
+ eidMappingContext.addEid(mappingIdPrefixBased, localPrefixBasedEid, mappingContext);
+ final org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid eid = eidMappingContext.getEid(mappingIdPrefixBased, mappingContext);
+
+ // verify if normalized
+ assertEquals(localPrefixBasedEidNormalized.getAddress(), eid.getAddress());
+ assertEquals(localEid.getAddressType(), eid.getAddressType());
+ assertEquals(localEid.getVirtualNetworkId(), eid.getVirtualNetworkId());
+ }
+
+ @Test
public void testAddEidRemote() {
eidMappingContext.addEid(mappingId, remoteEid, mappingContext);
final org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid eid = eidMappingContext.getEid(mappingId, mappingContext);
@@ -106,6 +157,17 @@ public class EidMappingContextTest implements EidMappingContextHelper {
assertEquals(remoteEid.getVirtualNetworkId(), eid.getVirtualNetworkId());
}
+ @Test
+ public void testAddEidRemotePrefixBased() {
+ eidMappingContext.addEid(mappingIdPrefixBased, remoteEidPrefixBased, mappingContext);
+ final org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid eid = eidMappingContext.getEid(mappingIdPrefixBased, mappingContext);
+
+ // verify if normalized
+ assertEquals(remoteEidPrefixBasedNormalized.getAddress(), eid.getAddress());
+ assertEquals(remoteEid.getAddressType(), eid.getAddressType());
+ assertEquals(remoteEid.getVirtualNetworkId(), eid.getVirtualNetworkId());
+ }
+
private org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid fromLocalToMappingEid(
Eid eid) {
return new org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.EidBuilder()
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/AdjacencyData.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/AdjacencyData.java
index cc3581ae4..6e011fd48 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/AdjacencyData.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/AdjacencyData.java
@@ -22,6 +22,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
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.Ipv4Afi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder;
public class AdjacencyData {
@@ -32,6 +33,11 @@ public class AdjacencyData {
public static final Ipv4Address ADDRESS_THREE = new Ipv4Address("192.168.2.3");
public static final Ipv4Address ADDRESS_FOUR = new Ipv4Address("192.168.2.4");
+ public static final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix PREFIX_ADDRESS_ONE = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.1/24");
+ public static final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix PREFIX_ADDRESS_TWO = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.2/28");
+ public static final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix PREFIX_ADDRESS_THREE = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.3/16");
+ public static final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix PREFIX_ADDRESS_FOUR = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.4/8");
+
public static final Eid LOCAL_EID_ONE = new EidBuilder()
.setAddressType(Ipv4Afi.class)
.setVirtualNetworkId(new InstanceIdType(VNI))
@@ -55,5 +61,26 @@ public class AdjacencyData {
.setAddress(new Ipv4Builder().setIpv4(ADDRESS_FOUR).build())
.build();
+ public static final Eid LOCAL_EID_PREFIX_ONE = new EidBuilder()
+ .setAddressType(Ipv4Afi.class)
+ .setVirtualNetworkId(new InstanceIdType(VNI))
+ .setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(PREFIX_ADDRESS_ONE).build())
+ .build();
+
+ public static final Eid LOCAL_EID_PREFIX_TWO = new EidBuilder()
+ .setAddressType(Ipv4Afi.class)
+ .setVirtualNetworkId(new InstanceIdType(VNI))
+ .setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(PREFIX_ADDRESS_TWO).build())
+ .build();
+ public static final Eid REMOTE_EID_PREFIX_ONE = new EidBuilder()
+ .setAddressType(Ipv4Afi.class)
+ .setVirtualNetworkId(new InstanceIdType(VNI))
+ .setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(PREFIX_ADDRESS_THREE).build())
+ .build();
+ public static final Eid REMOTE_EID_PREFIX_TWO = new EidBuilder()
+ .setAddressType(Ipv4Afi.class)
+ .setVirtualNetworkId(new InstanceIdType(VNI))
+ .setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(PREFIX_ADDRESS_FOUR).build())
+ .build();
}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java
index ad65a7604..92c5abcfe 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java
@@ -19,8 +19,12 @@ package io.fd.hc2vpp.lisp.translate.read;
import static io.fd.hc2vpp.lisp.translate.AdjacencyData.ADDRESS_ONE;
import static io.fd.hc2vpp.lisp.translate.AdjacencyData.ADDRESS_THREE;
import static io.fd.hc2vpp.lisp.translate.AdjacencyData.LOCAL_EID_ONE;
+import static io.fd.hc2vpp.lisp.translate.AdjacencyData.LOCAL_EID_PREFIX_ONE;
+import static io.fd.hc2vpp.lisp.translate.AdjacencyData.LOCAL_EID_PREFIX_TWO;
import static io.fd.hc2vpp.lisp.translate.AdjacencyData.LOCAL_EID_TWO;
import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_ONE;
+import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_PREFIX_ONE;
+import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_PREFIX_TWO;
import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_TWO;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
@@ -43,6 +47,7 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
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.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.Adjacencies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.AdjacenciesBuilder;
@@ -63,6 +68,8 @@ public class AdjacencyCustomizerTest
extends ListReaderCustomizerTest<Adjacency, AdjacencyKey, AdjacencyBuilder>
implements ByteDataTranslator, EidMetadataProvider, EidMappingContextHelper, AdjacencyMappingContextTestHelper {
+ public static final String NORMALIZED_PREFIX_ONE = "192.168.2.0/24";
+ public static final String NORMALIZED_PREFIX_THREE = "192.168.0.0/16";
private InstanceIdentifier<Adjacency> identifier;
public AdjacencyCustomizerTest() {
@@ -78,23 +85,30 @@ public class AdjacencyCustomizerTest
.child(RemoteMapping.class, new RemoteMappingKey(new MappingId("remote-mapping")))
.child(Adjacencies.class)
.child(Adjacency.class, new AdjacencyKey("adj-one"));
+ defineAdjacencyMapping(mappingContext, "local-eid-one", "remote-eid-one", "adj-one",
+ "adjacencies-mapping-context");
+ defineAdjacencyMapping(mappingContext, "local-eid-two", "remote-eid-two", "adj-two",
+ "adjacencies-mapping-context");
+ }
-
- mockApi();
+ private void defineEidAddressMapping() {
defineEidMapping(mappingContext, LOCAL_EID_ONE, new MappingId("local-eid-one"), "local-mapping-context");
defineEidMapping(mappingContext, LOCAL_EID_TWO, new MappingId("local-eid-two"), "local-mapping-context");
defineEidMapping(mappingContext, REMOTE_EID_ONE, new MappingId("remote-eid-one"), "remote-mapping-context");
defineEidMapping(mappingContext, REMOTE_EID_TWO, new MappingId("remote-eid-two"), "remote-mapping-context");
+ }
- defineAdjacencyMapping(mappingContext, "local-eid-one", "remote-eid-one", "adj-one",
- "adjacencies-mapping-context");
- defineAdjacencyMapping(mappingContext, "local-eid-two", "remote-eid-two", "adj-two",
- "adjacencies-mapping-context");
- mockApi();
+ private void defineEidPrefixMapping() {
+ defineEidMapping(mappingContext, LOCAL_EID_PREFIX_ONE, new MappingId("local-eid-one"), "local-mapping-context");
+ defineEidMapping(mappingContext, LOCAL_EID_PREFIX_TWO, new MappingId("local-eid-two"), "local-mapping-context");
+ defineEidMapping(mappingContext, REMOTE_EID_PREFIX_ONE, new MappingId("remote-eid-one"), "remote-mapping-context");
+ defineEidMapping(mappingContext, REMOTE_EID_PREFIX_TWO, new MappingId("remote-eid-two"), "remote-mapping-context");
}
@Test
public void getAllIds() throws Exception {
+ mockAddressDump();
+ defineEidAddressMapping();
final List<AdjacencyKey> keys = getCustomizer().getAllIds(identifier, ctx);
assertThat(keys, hasSize(2));
@@ -103,6 +117,8 @@ public class AdjacencyCustomizerTest
@Test
public void readCurrentAttributes() throws Exception {
+ mockAddressDump();
+ defineEidAddressMapping();
final AdjacencyBuilder builder = new AdjacencyBuilder();
getCustomizer().readCurrentAttributes(identifier, builder, ctx);
@@ -113,6 +129,21 @@ public class AdjacencyCustomizerTest
Ipv4.class.cast(builder.getRemoteEid().getAddress()).getIpv4().getValue());
}
+ @Test
+ public void readCurrentAttributesPrefixBased() throws Exception {
+ mockPrefixDump();
+ defineEidPrefixMapping();
+ final AdjacencyBuilder builder = new AdjacencyBuilder();
+ getCustomizer().readCurrentAttributes(identifier, builder, ctx);
+
+ assertEquals("adj-one", builder.getId());
+ assertEquals(new AdjacencyKey("adj-one"), builder.getKey());
+ assertEquals(NORMALIZED_PREFIX_ONE,
+ Ipv4Prefix.class.cast(builder.getLocalEid().getAddress()).getIpv4Prefix().getValue());
+ assertEquals(NORMALIZED_PREFIX_THREE,
+ Ipv4Prefix.class.cast(builder.getRemoteEid().getAddress()).getIpv4Prefix().getValue());
+ }
+
@Override
protected ReaderCustomizer<Adjacency, AdjacencyBuilder> initCustomizer() {
return new AdjacencyCustomizer(api, new EidMappingContext("local-mapping-context", "local-mapping-"),
@@ -121,7 +152,7 @@ public class AdjacencyCustomizerTest
}
- private void mockApi() {
+ private void mockAddressDump() {
OneAdjacency adjacencyOne = new OneAdjacency();
adjacencyOne.eidType = 0;
adjacencyOne.leid = new byte[]{-64, -88, 2, 1};
@@ -142,4 +173,26 @@ public class AdjacencyCustomizerTest
when(api.oneAdjacenciesGet(any())).thenReturn(future(reply));
}
+
+ private void mockPrefixDump() {
+ OneAdjacency adjacencyOne = new OneAdjacency();
+ adjacencyOne.eidType = 0;
+ adjacencyOne.leid = new byte[]{-64, -88, 2, 1};
+ adjacencyOne.leidPrefixLen = 24;
+ adjacencyOne.reid = new byte[]{-64, -88, 2, 3};
+ adjacencyOne.reidPrefixLen = 16;
+
+
+ OneAdjacency adjacencyTwo = new OneAdjacency();
+ adjacencyTwo.eidType = 0;
+ adjacencyTwo.leid = new byte[]{-64, -88, 2, 2};
+ adjacencyTwo.leidPrefixLen = 28;
+ adjacencyTwo.reid = new byte[]{-64, -88, 2, 4};
+ adjacencyTwo.reidPrefixLen = 8;
+
+ OneAdjacenciesGetReply reply = new OneAdjacenciesGetReply();
+ reply.adjacencies = new OneAdjacency[]{adjacencyOne, adjacencyTwo};
+
+ when(api.oneAdjacenciesGet(any())).thenReturn(future(reply));
+ }
} \ No newline at end of file
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizerTest.java
index 53fbc568b..11fe30dc5 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizerTest.java
@@ -17,6 +17,7 @@
package io.fd.hc2vpp.lisp.translate.read;
import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4;
+import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4_PREFIX;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
@@ -40,6 +41,8 @@ import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
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.Ipv4Builder;
+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.Ipv4PrefixBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.HmacKeyType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.LocalMappings;
@@ -61,6 +64,9 @@ public class LocalMappingCustomizerTest extends
private static final Ipv4
EID_ADDRESS = new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build();
+ private static final Ipv4Prefix
+ EID_V4_PREFIX_ADDRESS = new Ipv4PrefixBuilder().setIpv4Prefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.1/28")).build();
+
@Mock
private EidMappingContext localMappingContext;
@@ -84,11 +90,9 @@ public class LocalMappingCustomizerTest extends
.child(VrfSubtable.class)
.child(LocalMappings.class)
.child(LocalMapping.class, new LocalMappingKey(new MappingId("local-mapping")));
-
- defineMappings();
}
- private void defineDumpData() {
+ private void defineV4AddressDumpData() {
OneEidTableDetailsReplyDump replyDump = new OneEidTableDetailsReplyDump();
OneEidTableDetails detail = new OneEidTableDetails();
detail.action = 0;
@@ -96,7 +100,27 @@ public class LocalMappingCustomizerTest extends
detail.context = 4;
detail.eid = new byte[]{-64, -88, 2, 1};
detail.eidPrefixLen = 32;
- detail.eidType = (byte) IPV4.getValue();
+ detail.eidType = (byte) IPV4.getVppTypeBinding();
+ detail.isLocal = 1;
+ detail.locatorSetIndex = 1;
+ detail.ttl = 7;
+ detail.vni = 12;
+ detail.key = "abcdefgh".getBytes(StandardCharsets.UTF_8);
+ detail.keyId = 1;
+
+ replyDump.oneEidTableDetails = ImmutableList.of(detail);
+ when(api.oneEidTableDump(any())).thenReturn(future(replyDump));
+ }
+
+ private void defineV4PrefixDumpData() {
+ OneEidTableDetailsReplyDump replyDump = new OneEidTableDetailsReplyDump();
+ OneEidTableDetails detail = new OneEidTableDetails();
+ detail.action = 0;
+ detail.authoritative = 1;
+ detail.context = 4;
+ detail.eid = new byte[]{-64, -88, 2, 1};
+ detail.eidPrefixLen = 28;
+ detail.eidType = (byte) IPV4_PREFIX.getVppTypeBinding();
detail.isLocal = 1;
detail.locatorSetIndex = 1;
detail.ttl = 7;
@@ -116,7 +140,7 @@ public class LocalMappingCustomizerTest extends
detail.context = 4;
detail.eid = new byte[]{-64, -88, 2, 1};
detail.eidPrefixLen = 32;
- detail.eidType = (byte) IPV4.getValue();
+ detail.eidType = (byte) IPV4.getVppTypeBinding();
detail.isLocal = 1;
detail.locatorSetIndex = 1;
detail.ttl = 7;
@@ -126,7 +150,7 @@ public class LocalMappingCustomizerTest extends
when(api.oneEidTableDump(any())).thenReturn(future(replyDump));
}
- private void defineMappings() {
+ private void defineAddressMappings() {
//eid mapping
when(localMappingContext.getId(any(Eid.class), any(MappingContext.class)))
@@ -138,8 +162,21 @@ public class LocalMappingCustomizerTest extends
defineMapping(mappingContext, "loc-set", 1, "locator-set-context");
}
+ private void definePrefixMappings() {
+ //eid mapping
+
+ when(localMappingContext.getId(any(Eid.class), any(MappingContext.class)))
+ .thenReturn(new MappingId("local-mapping"));
+ when(localMappingContext.containsEid(new MappingId("local-mapping"), mappingContext)).thenReturn(true);
+ when(localMappingContext.getEid(new MappingId("local-mapping"), mappingContext)).thenReturn(new EidBuilder()
+ .setAddress(EID_V4_PREFIX_ADDRESS).build());
+ //naming context for locator
+ defineMapping(mappingContext, "loc-set", 1, "locator-set-context");
+ }
+
@Test
public void readCurrentAttributesNoHmacKey() throws ReadFailedException {
+ defineAddressMappings();
defineDumpDataNoHmacKey();
LocalMappingBuilder builder = new LocalMappingBuilder();
@@ -155,7 +192,8 @@ public class LocalMappingCustomizerTest extends
@Test
public void readCurrentAttributes() throws Exception {
- defineDumpData();
+ defineAddressMappings();
+ defineV4AddressDumpData();
LocalMappingBuilder builder = new LocalMappingBuilder();
getCustomizer().readCurrentAttributes(validIdentifier, builder, ctx);
@@ -171,8 +209,27 @@ public class LocalMappingCustomizerTest extends
}
@Test
+ public void readCurrentAttributesPrefixBased() throws Exception {
+ definePrefixMappings();
+ defineV4PrefixDumpData();
+ LocalMappingBuilder builder = new LocalMappingBuilder();
+ getCustomizer().readCurrentAttributes(validIdentifier, builder, ctx);
+
+ final LocalMapping mapping = builder.build();
+
+ assertNotNull(mapping);
+ assertEquals(true, compareAddresses(EID_V4_PREFIX_ADDRESS, mapping.getEid().getAddress()));
+ assertEquals("loc-set", mapping.getLocatorSet());
+
+ final HmacKey hmacKey = mapping.getHmacKey();
+ assertEquals("abcdefgh", hmacKey.getKey());
+ assertEquals(HmacKeyType.Sha196Key, hmacKey.getKeyType());
+ }
+
+ @Test
public void getAllIds() throws Exception {
- defineDumpData();
+ defineAddressMappings();
+ defineV4AddressDumpData();
final List<LocalMappingKey> keys = getCustomizer().getAllIds(emptyIdentifier, ctx);
assertEquals(1, keys.size());
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizerTest.java
index 59caeb03a..d239f379b 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizerTest.java
@@ -42,6 +42,8 @@ import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
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.Ipv4Builder;
+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.Ipv4PrefixBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MapReplyAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.RemoteMappings;
@@ -66,6 +68,9 @@ public class RemoteMappingCustomizerTest
private static final Ipv4
EID_ADDRESS = new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build();
+ private static final Ipv4Prefix
+ EID_V4_PREFIX_ADDRESS = new Ipv4PrefixBuilder().setIpv4Prefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.1/24")).build();
+
@Mock
private EidMappingContext eidMappingContext;
@@ -83,12 +88,11 @@ public class RemoteMappingCustomizerTest
.child(VrfSubtable.class)
.child(RemoteMappings.class)
.child(RemoteMapping.class, new RemoteMappingKey(new MappingId("remote-mapping")));
- mockMappings();
defineMapping(mappingContext,"loc-set",1,"loc-set-context");
}
- private void mockDumpDataActionZero() {
+ private void mockDumpDataAddressActionZero() {
OneEidTableDetailsReplyDump replyDump = new OneEidTableDetailsReplyDump();
OneEidTableDetails detail = new OneEidTableDetails();
detail.action = 0;
@@ -110,7 +114,29 @@ public class RemoteMappingCustomizerTest
when(api.oneLocatorDump(any())).thenReturn(future(rlocs));
}
- private void mockDumpDataActionOne() {
+ private void mockDumpDataPrefixActionZero() {
+ OneEidTableDetailsReplyDump replyDump = new OneEidTableDetailsReplyDump();
+ OneEidTableDetails detail = new OneEidTableDetails();
+ detail.action = 0;
+ detail.authoritative = 1;
+ detail.context = 4;
+ detail.eid = new byte[]{-64, -88, 2, 1};
+ detail.eidPrefixLen = 24;
+ detail.isLocal = 0;
+ detail.locatorSetIndex = -1;
+ detail.ttl = 7;
+ detail.vni = 12;
+
+ replyDump.oneEidTableDetails = ImmutableList.of(detail);
+
+ when(api.oneEidTableDump(any())).thenReturn(future(replyDump));
+
+ OneLocatorDetailsReplyDump rlocs = new OneLocatorDetailsReplyDump();
+ rlocs.oneLocatorDetails = Collections.emptyList();
+ when(api.oneLocatorDump(any())).thenReturn(future(rlocs));
+ }
+
+ private void mockDumpDataAddressActionOne() {
OneEidTableDetailsReplyDump replyDump = new OneEidTableDetailsReplyDump();
OneEidTableDetails detail = new OneEidTableDetails();
detail.action = 1;
@@ -158,19 +184,28 @@ public class RemoteMappingCustomizerTest
}
- private void mockMappings() {
+ private void mockAddressMappings() {
when(eidMappingContext.getId(any(Eid.class), any(MappingContext.class)))
.thenReturn(new MappingId("remote-mapping"));
when(eidMappingContext.containsEid(new MappingId("remote-mapping"), mappingContext)).thenReturn(true);
when(eidMappingContext.getEid(new MappingId("remote-mapping"), mappingContext))
.thenReturn(new EidBuilder().setAddress(EID_ADDRESS).build());
+ }
+
+ private void mockPrefixMappings() {
+ when(eidMappingContext.getId(any(Eid.class), any(MappingContext.class)))
+ .thenReturn(new MappingId("remote-mapping"));
+ when(eidMappingContext.containsEid(new MappingId("remote-mapping"), mappingContext)).thenReturn(true);
+ when(eidMappingContext.getEid(new MappingId("remote-mapping"), mappingContext))
+ .thenReturn(new EidBuilder().setAddress(EID_V4_PREFIX_ADDRESS).build());
}
@Test
public void readCurrentAttributesNegativeMappingOne() throws Exception {
- mockDumpDataActionOne();
+ mockAddressMappings();
+ mockDumpDataAddressActionOne();
RemoteMappingBuilder builder = new RemoteMappingBuilder();
getCustomizer().readCurrentAttributes(validId, builder, ctx);
@@ -187,7 +222,8 @@ public class RemoteMappingCustomizerTest
@Test
public void readCurrentAttributesNegativeMappingZero() throws Exception {
- mockDumpDataActionZero();
+ mockAddressMappings();
+ mockDumpDataAddressActionZero();
RemoteMappingBuilder builder = new RemoteMappingBuilder();
getCustomizer().readCurrentAttributes(validId, builder, ctx);
@@ -202,7 +238,25 @@ public class RemoteMappingCustomizerTest
}
@Test
+ public void readCurrentAttributesPrefixBasedNegativeMappingZero() throws Exception {
+ mockPrefixMappings();
+ mockDumpDataPrefixActionZero();
+ RemoteMappingBuilder builder = new RemoteMappingBuilder();
+ getCustomizer().readCurrentAttributes(validId, builder, ctx);
+
+ RemoteMapping mapping = builder.build();
+
+ assertNotNull(mapping);
+ assertEquals(true, compareAddresses(EID_V4_PREFIX_ADDRESS, mapping.getEid().getAddress()));
+ assertEquals(true, mapping.getAuthoritative().isA());
+ assertEquals(7L, mapping.getTtl().longValue());
+ assertEquals(MapReplyAction.NoAction,
+ ((NegativeMapping) mapping.getLocatorList()).getMapReply().getMapReplyAction());
+ }
+
+ @Test
public void readCurrentAttributesPositiveMapping() throws Exception {
+ mockAddressMappings();
mockDumpDataActionZeroWithRemotes();
RemoteMappingBuilder builder = new RemoteMappingBuilder();
getCustomizer().readCurrentAttributes(validId, builder, ctx);
@@ -223,10 +277,10 @@ public class RemoteMappingCustomizerTest
assertEquals(2, locator.getWeight().shortValue());
}
-
@Test
public void getAllIds() throws Exception {
- mockDumpDataActionOne();
+ mockAddressMappings();
+ mockDumpDataAddressActionOne();
final List<RemoteMappingKey> keys = getCustomizer().getAllIds(validId, ctx);
assertNotNull(keys);
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/util/EidTranslatorTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/util/EidTranslatorTest.java
index 096eca7fd..6e09f2faa 100755
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/util/EidTranslatorTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/util/EidTranslatorTest.java
@@ -16,23 +16,39 @@
package io.fd.hc2vpp.lisp.translate.util;
+import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4;
+import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4_PREFIX;
+import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV6;
+import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV6_PREFIX;
+import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.MAC;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4PrefixAfi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6PrefixAfi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
-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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
+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.Ipv4PrefixBuilder;
+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.Ipv6Builder;
+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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6PrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.adjacencies.adjacency.LocalEid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.adjacencies.adjacency.RemoteEid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.remote.mappings.remote.mapping.Eid;
-import java.util.Arrays;
-
-import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.*;
-import static org.junit.Assert.*;
-
public class EidTranslatorTest implements EidTranslator {
private static final String MAC_STRING = "bf:bf:bf:bf:bf:bf";
@@ -50,6 +66,8 @@ public class EidTranslatorTest implements EidTranslator {
new Ipv4Address(IPV4_STRING))
.build();
private static final byte[] IPV_ADDRESS_BYTES = {-64, -88, 2, 1};
+ private static final String NORMALIZED_V6_PREFIX = "2001:db8:a0b:12f0::/64";
+ private static final String NORMALIZED_V4_PREFIX = "192.168.2.0/24";
@Test
public void testGetEidType() {
@@ -68,33 +86,53 @@ public class EidTranslatorTest implements EidTranslator {
@Test
public void testGetPrefixLength() {
- assertEquals(32, getPrefixLength(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder()
- .setAddress(IPV4_ADDRESS).build()));
- assertEquals(-128, getPrefixLength(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder()
- .setAddress(IPV6_ADDRESS).build()));
- assertEquals(0, getPrefixLength(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder()
- .setAddress(MAC_ADDRES).build()));
+ assertEquals(32, getPrefixLength(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder()
+ .setAddress(IPV4_ADDRESS).build()));
+ assertEquals(-128, getPrefixLength(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder()
+ .setAddress(IPV6_ADDRESS).build()));
+ assertEquals(0, getPrefixLength(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder()
+ .setAddress(MAC_ADDRES).build()));
}
@Test
public void testGetArrayAsEidRemoteIpv4() {
- final Eid eid = getArrayAsEidRemote(IPV4, IPV_ADDRESS_BYTES, 10);
+ final Eid eid = getArrayAsEidRemote(IPV4, IPV_ADDRESS_BYTES, DEFAULT_V4_PREFIX, 10);
assertEquals(IPV4_STRING, ((Ipv4) eid.getAddress()).getIpv4().getValue());
assertEquals(10, eid.getVirtualNetworkId().getValue().intValue());
assertEquals(Ipv4Afi.class, eid.getAddressType());
}
@Test
+ public void testGetArrayAsEidRemoteIpv4Prefix() {
+ final Eid eid = getArrayAsEidRemote(IPV4_PREFIX, IPV_ADDRESS_BYTES, (byte) 24, 10);
+ assertEquals(NORMALIZED_V4_PREFIX, ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue());
+ assertEquals(10, eid.getVirtualNetworkId().getValue().intValue());
+ assertEquals(Ipv4PrefixAfi.class, eid.getAddressType());
+ }
+
+ @Test
public void testGetArrayAsEidRemoteIpv6() {
- final Eid eid = getArrayAsEidRemote(IPV6, IPV6_ADDRESS_BYTES, 12);
+ final Eid eid = getArrayAsEidRemote(IPV6, IPV6_ADDRESS_BYTES, DEFAULT_V6_PREFIX, 12);
assertEquals(IPV6_STRING, ((Ipv6) eid.getAddress()).getIpv6().getValue());
assertEquals(12, eid.getVirtualNetworkId().getValue().intValue());
assertEquals(Ipv6Afi.class, eid.getAddressType());
}
@Test
+ public void testGetArrayAsEidRemoteIpv6Prefix() {
+ final Eid eid = getArrayAsEidRemote(IPV6_PREFIX, IPV6_ADDRESS_BYTES, (byte) 64, 12);
+ assertEquals(NORMALIZED_V6_PREFIX, ((Ipv6Prefix) eid.getAddress()).getIpv6Prefix().getValue());
+ assertEquals(12, eid.getVirtualNetworkId().getValue().intValue());
+ assertEquals(Ipv6PrefixAfi.class, eid.getAddressType());
+ }
+
+
+ @Test
public void testGetArrayAsEidRemoteMac() {
- final Eid eid = getArrayAsEidRemote(MAC, MAC_ADDRESS_BYTES, 13);
+ final Eid eid = getArrayAsEidRemote(MAC, MAC_ADDRESS_BYTES, (byte) 0, 13);
assertEquals(MAC_STRING, ((Mac) eid.getAddress()).getMac().getValue());
assertEquals(13, eid.getVirtualNetworkId().getValue().intValue());
assertEquals(MacAfi.class, eid.getAddressType());
@@ -102,23 +140,39 @@ public class EidTranslatorTest implements EidTranslator {
@Test
public void testGetArrayAsLocalEidIpv4() {
- final LocalEid eid = getArrayAsLocalEid(IPV4, IPV_ADDRESS_BYTES, 10);
+ final LocalEid eid = getArrayAsLocalEid(IPV4, IPV_ADDRESS_BYTES, DEFAULT_V4_PREFIX, 10);
assertEquals(IPV4_STRING, ((Ipv4) eid.getAddress()).getIpv4().getValue());
assertEquals(10, eid.getVirtualNetworkId().getValue().intValue());
assertEquals(Ipv4Afi.class, eid.getAddressType());
}
@Test
+ public void testGetArrayAsLocalEidIpv4Prefix() {
+ final LocalEid eid = getArrayAsLocalEid(IPV4_PREFIX, IPV_ADDRESS_BYTES, (byte) 24, 10);
+ assertEquals(NORMALIZED_V4_PREFIX, ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue());
+ assertEquals(10, eid.getVirtualNetworkId().getValue().intValue());
+ assertEquals(Ipv4PrefixAfi.class, eid.getAddressType());
+ }
+
+ @Test
public void testGetArrayAsLocalEidIpv6() {
- final LocalEid eid = getArrayAsLocalEid(IPV6, IPV6_ADDRESS_BYTES, 12);
+ final LocalEid eid = getArrayAsLocalEid(IPV6, IPV6_ADDRESS_BYTES, DEFAULT_V6_PREFIX, 12);
assertEquals(IPV6_STRING, ((Ipv6) eid.getAddress()).getIpv6().getValue());
assertEquals(12, eid.getVirtualNetworkId().getValue().intValue());
assertEquals(Ipv6Afi.class, eid.getAddressType());
}
@Test
+ public void testGetArrayAsLocalEidIpv6Prefix() {
+ final LocalEid eid = getArrayAsLocalEid(IPV6_PREFIX, IPV6_ADDRESS_BYTES, (byte) 64, 12);
+ assertEquals(NORMALIZED_V6_PREFIX, ((Ipv6Prefix) eid.getAddress()).getIpv6Prefix().getValue());
+ assertEquals(12, eid.getVirtualNetworkId().getValue().intValue());
+ assertEquals(Ipv6PrefixAfi.class, eid.getAddressType());
+ }
+
+ @Test
public void testGetArrayAsLocalEidMac() {
- final LocalEid eid = getArrayAsLocalEid(MAC, MAC_ADDRESS_BYTES, 13);
+ final LocalEid eid = getArrayAsLocalEid(MAC, MAC_ADDRESS_BYTES, (byte) 0, 13);
assertEquals(MAC_STRING, ((Mac) eid.getAddress()).getMac().getValue());
assertEquals(13, eid.getVirtualNetworkId().getValue().intValue());
assertEquals(MacAfi.class, eid.getAddressType());
@@ -126,23 +180,39 @@ public class EidTranslatorTest implements EidTranslator {
@Test
public void testGetArrayAsRemoteEidIpv4() {
- final RemoteEid eid = getArrayAsRemoteEid(IPV4, IPV_ADDRESS_BYTES, 10);
+ final RemoteEid eid = getArrayAsRemoteEid(IPV4, IPV_ADDRESS_BYTES, DEFAULT_V4_PREFIX, 10);
assertEquals(IPV4_STRING, ((Ipv4) eid.getAddress()).getIpv4().getValue());
assertEquals(10, eid.getVirtualNetworkId().getValue().intValue());
assertEquals(Ipv4Afi.class, eid.getAddressType());
}
@Test
+ public void testGetArrayAsRemoteEidIpv4Prefix() {
+ final RemoteEid eid = getArrayAsRemoteEid(IPV4_PREFIX, IPV_ADDRESS_BYTES, (byte) 24, 10);
+ assertEquals(NORMALIZED_V4_PREFIX, ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue());
+ assertEquals(10, eid.getVirtualNetworkId().getValue().intValue());
+ assertEquals(Ipv4PrefixAfi.class, eid.getAddressType());
+ }
+
+ @Test
public void testGetArrayAsRemoteEidIpv6() {
- final RemoteEid eid = getArrayAsRemoteEid(IPV6, IPV6_ADDRESS_BYTES, 12);
+ final RemoteEid eid = getArrayAsRemoteEid(IPV6, IPV6_ADDRESS_BYTES, DEFAULT_V6_PREFIX, 12);
assertEquals(IPV6_STRING, ((Ipv6) eid.getAddress()).getIpv6().getValue());
assertEquals(12, eid.getVirtualNetworkId().getValue().intValue());
assertEquals(Ipv6Afi.class, eid.getAddressType());
}
@Test
+ public void testGetArrayAsRemoteEidIpv6Prefix() {
+ final RemoteEid eid = getArrayAsRemoteEid(IPV6_PREFIX, IPV6_ADDRESS_BYTES, (byte) 64, 12);
+ assertEquals(NORMALIZED_V6_PREFIX, ((Ipv6Prefix) eid.getAddress()).getIpv6Prefix().getValue());
+ assertEquals(12, eid.getVirtualNetworkId().getValue().intValue());
+ assertEquals(Ipv6PrefixAfi.class, eid.getAddressType());
+ }
+
+ @Test
public void testGetArrayAsRemoteEidMac() {
- final RemoteEid eid = getArrayAsRemoteEid(MAC, MAC_ADDRESS_BYTES, 13);
+ final RemoteEid eid = getArrayAsRemoteEid(MAC, MAC_ADDRESS_BYTES, (byte) 0, 13);
assertEquals(MAC_STRING, ((Mac) eid.getAddress()).getMac().getValue());
assertEquals(13, eid.getVirtualNetworkId().getValue().intValue());
assertEquals(MacAfi.class, eid.getAddressType());
@@ -150,17 +220,27 @@ public class EidTranslatorTest implements EidTranslator {
@Test
public void testGetArrayAsEidStringIpv4() {
- assertEquals(IPV4_STRING, getArrayAsEidString(IPV4, IPV_ADDRESS_BYTES));
+ assertEquals(IPV4_STRING, getArrayAsEidString(IPV4, IPV_ADDRESS_BYTES, DEFAULT_V4_PREFIX));
+ }
+
+ @Test
+ public void testGetArrayAsEidStringIpv4Prefix() {
+ assertEquals(NORMALIZED_V4_PREFIX, getArrayAsEidString(IPV4, IPV_ADDRESS_BYTES, (byte) 24));
}
@Test
public void testGetArrayAsEidStringIpv6() {
- assertEquals(IPV6_STRING, getArrayAsEidString(IPV6, IPV6_ADDRESS_BYTES));
+ assertEquals(IPV6_STRING, getArrayAsEidString(IPV6, IPV6_ADDRESS_BYTES, DEFAULT_V6_PREFIX));
+ }
+
+ @Test
+ public void testGetArrayAsEidStringIpv6Prefix() {
+ assertEquals(NORMALIZED_V6_PREFIX, getArrayAsEidString(IPV6, IPV6_ADDRESS_BYTES, (byte) 64));
}
@Test
public void testGetArrayAsEidStringMac() {
- assertEquals(MAC_STRING, getArrayAsEidString(MAC, MAC_ADDRESS_BYTES));
+ assertEquals(MAC_STRING, getArrayAsEidString(MAC, MAC_ADDRESS_BYTES, (byte) 0));
}
@Test
@@ -191,4 +271,48 @@ public class EidTranslatorTest implements EidTranslator {
assertFalse(compareAddresses(IPV4_ADDRESS, IPV6_ADDRESS));
assertFalse(compareAddresses(IPV4_ADDRESS, MAC_ADDRES));
}
+
+ @Test
+ public void testCompareV4AddressFromSameSubnetPositive() {
+ final Ipv4Prefix firstV4 = new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix("192.168.2.1/24")).build();
+ final Ipv4Prefix secondV4 = new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix("192.168.2.2/24")).build();
+
+ assertTrue(compareAddresses(firstV4, secondV4));
+ }
+
+ @Test
+ public void testCompareV4AddressFromSameSubnetNegative() {
+ final Ipv4Prefix firstV4 = new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix("192.168.2.1/24")).build();
+ final Ipv4Prefix secondV4 = new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix("192.168.2.1/16")).build();
+
+ assertFalse(compareAddresses(firstV4, secondV4));
+ }
+
+ @Test
+ public void testCompareV6AddressesFromSameSubnetPositive() {
+ final Ipv6Prefix firstV6 = new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix("2001:db8:a0b:12f0::1/64")).build();
+ final Ipv6Prefix secondV6 = new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix("2001:db8:a0b:12f0::4/64")).build();
+
+ assertTrue(compareAddresses(firstV6, secondV6));
+ }
+
+ @Test
+ public void testCompareV6AddressesFromSameSubnetNegative() {
+ final Ipv6Prefix firstV6 = new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64")).build();
+ final Ipv6Prefix secondV6 = new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/48")).build();
+
+ assertFalse(compareAddresses(firstV6, secondV6));
+ }
+
+ private static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix v6Prefix(
+ String v6Prefix) {
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix(
+ v6Prefix);
+ }
+
+ private static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix v4Prefix(
+ String v4Prefix) {
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix(
+ v4Prefix);
+ }
}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java
index bf19ae581..1c487e3ae 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java
@@ -19,7 +19,9 @@ package io.fd.hc2vpp.lisp.translate.write;
import static io.fd.hc2vpp.lisp.translate.AdjacencyData.ADDRESS_ONE;
import static io.fd.hc2vpp.lisp.translate.AdjacencyData.ADDRESS_THREE;
import static io.fd.hc2vpp.lisp.translate.AdjacencyData.LOCAL_EID_ONE;
+import static io.fd.hc2vpp.lisp.translate.AdjacencyData.LOCAL_EID_PREFIX_ONE;
import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_ONE;
+import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_PREFIX_ONE;
import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -28,6 +30,7 @@ import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
@@ -42,10 +45,12 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.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.Ipv4Afi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId;
@@ -81,9 +86,13 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid
private InstanceIdentifier<Adjacency> emptyId;
private InstanceIdentifier<Adjacency> validId;
- private Adjacency emptyData;
+ private Adjacency failDataBefore;
+ private Adjacency failDataAfter;
+ private Adjacency ignoreDataBefore;
+ private Adjacency ignoreDataAfter;
private Adjacency invalidData;
private Adjacency validData;
+ private Adjacency validDataPrefixBased;
@Before
public void init() {
@@ -100,7 +109,41 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid
.child(Adjacencies.class)
.child(Adjacency.class, new AdjacencyKey("adj-one"));
- emptyData = new AdjacencyBuilder().build();
+ failDataBefore = new AdjacencyBuilder().setLocalEid(new LocalEidBuilder()
+ .setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/24"))
+ .build())
+ .build()).build();
+
+ failDataAfter = new AdjacencyBuilder().setLocalEid(new LocalEidBuilder()
+ .setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/16"))
+ .build())
+ .build()).build();
+
+ ignoreDataBefore = new AdjacencyBuilder().setLocalEid(new LocalEidBuilder()
+ .setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/24"))
+ .build())
+ .build())
+ .setRemoteEid(new RemoteEidBuilder()
+ .setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new Ipv4Prefix("192.168.3.1/24"))
+ .build())
+ .build())
+ .build();
+
+ ignoreDataAfter = new AdjacencyBuilder().setLocalEid(new LocalEidBuilder()
+ .setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new Ipv4Prefix("192.168.2.0/24"))
+ .build())
+ .build())
+ .setRemoteEid(new RemoteEidBuilder()
+ .setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new Ipv4Prefix("192.168.3.4/24"))
+ .build())
+ .build())
+ .build();
invalidData = new AdjacencyBuilder().setId("ID").setLocalEid(
new LocalEidBuilder()
@@ -126,13 +169,25 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid
.setAddressType(Ipv4Afi.class)
.setAddress(new Ipv4Builder().setIpv4(ADDRESS_THREE).build()).build()).build();
+ validDataPrefixBased = new AdjacencyBuilder()
+ .setLocalEid(new LocalEidBuilder()
+ .setAddressType(LOCAL_EID_PREFIX_ONE.getAddressType())
+ .setVirtualNetworkId(LOCAL_EID_PREFIX_ONE.getVirtualNetworkId())
+ .setAddress(LOCAL_EID_PREFIX_ONE.getAddress()).build())
+ .setRemoteEid(new RemoteEidBuilder()
+ .setVirtualNetworkId(REMOTE_EID_PREFIX_ONE.getVirtualNetworkId())
+ .setAddressType(REMOTE_EID_PREFIX_ONE.getAddressType())
+ .setAddress(REMOTE_EID_PREFIX_ONE.getAddress())
+ .build())
+ .build();
+
when(api.oneAddDelAdjacency(any())).thenReturn(future(new OneAddDelAdjacencyReply()));
}
@Test
public void writeCurrentAttributesNoKey() throws Exception {
try {
- customizer.writeCurrentAttributes(emptyId, emptyData, writeContext);
+ customizer.writeCurrentAttributes(emptyId, failDataBefore, writeContext);
} catch (NullPointerException e) {
verify(api, times(0)).oneAddDelAdjacency(any());
return;
@@ -161,7 +216,19 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid
customizer.writeCurrentAttributes(validId, validData, writeContext);
verify(api, times(1)).oneAddDelAdjacency(requestCaptor.capture());
verifyRequest(requestCaptor.getValue(), 1, new byte[]{-64, -88, 2, 1}, 32, new byte[]{-64, -88, 2, 3},
- 32, IPV4.getValue(), 2);
+ 32, IPV4.getVppTypeBinding(), 2);
+ verify(adjacenciesMappingContext, times(1))
+ .addEidPair("adj-one", "local-eid-one", "remote-eid-one", mappingContext);
+ }
+
+ @Test
+ public void writeCurrentAttributesPrefixBased() throws Exception {
+ defineEidMapping(mappingContext, LOCAL_EID_PREFIX_ONE, new MappingId("local-eid-one"), "local-mapping-context");
+ defineEidMapping(mappingContext, REMOTE_EID_PREFIX_ONE, new MappingId("remote-eid-one"), "remote-mapping-context");
+ customizer.writeCurrentAttributes(validId, validDataPrefixBased, writeContext);
+ verify(api, times(1)).oneAddDelAdjacency(requestCaptor.capture());
+ verifyRequest(requestCaptor.getValue(), 1, new byte[]{-64, -88, 2, 1}, 24, new byte[]{-64, -88, 2, 3},
+ 16, IPV4.getVppTypeBinding(), 2);
verify(adjacenciesMappingContext, times(1))
.addEidPair("adj-one", "local-eid-one", "remote-eid-one", mappingContext);
}
@@ -196,14 +263,21 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid
}
@Test(expected = UnsupportedOperationException.class)
- public void updateCurrentAttributes() throws Exception {
- customizer.updateCurrentAttributes(emptyId, emptyData, emptyData, writeContext);
+ public void updateCurrentAttributesFail() throws Exception {
+ customizer.updateCurrentAttributes(emptyId, failDataBefore, failDataAfter, writeContext);
+ }
+
+ @Test
+ public void updateCurrentAttributesIgnore() throws Exception {
+ // should not throw in this case
+ customizer.updateCurrentAttributes(emptyId, ignoreDataBefore, ignoreDataAfter, writeContext);
+ verifyZeroInteractions(api);
}
@Test
public void deleteCurrentAttributesNoKey() throws Exception {
try {
- customizer.deleteCurrentAttributes(emptyId, emptyData, writeContext);
+ customizer.deleteCurrentAttributes(emptyId, failDataBefore, writeContext);
} catch (NullPointerException e) {
verify(api, times(0)).oneAddDelAdjacency(any());
return;
@@ -222,7 +296,7 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid
customizer.deleteCurrentAttributes(validId, validData, writeContext);
verify(api, times(1)).oneAddDelAdjacency(requestCaptor.capture());
verifyRequest(requestCaptor.getValue(), 0, new byte[]{-64, -88, 2, 1}, 32, new byte[]{-64, -88, 2, 3},
- 32, IPV4.getValue(), 2);
+ 32, IPV4.getVppTypeBinding(), 2);
verify(adjacenciesMappingContext, times(1)).removeForIndex("adj-one", mappingContext);
}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java
index f945415a1..c49823f7a 100755
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java
@@ -24,6 +24,7 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
@@ -41,8 +42,10 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.HmacKeyType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.Lisp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId;
@@ -70,6 +73,12 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements
private InstanceIdentifier<LocalMapping> id;
private LocalMapping mapping;
private LocalMapping mappingWithHmacKey;
+
+ private LocalMapping failUpdateBefore;
+ private LocalMapping failUpdateAfter;
+ private LocalMapping ignoreUpdateBefore;
+ private LocalMapping ignoreUpdateAfter;
+
private LocalMappingCustomizer customizer;
@Override
@@ -95,6 +104,28 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements
.build())
.build();
+ failUpdateBefore = new LocalMappingBuilder()
+ .setEid(new EidBuilder().setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/24"))
+ .build()).build())
+ .build();
+ failUpdateAfter = new LocalMappingBuilder()
+ .setEid(new EidBuilder().setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/16"))
+ .build()).build())
+ .build();
+
+ ignoreUpdateBefore = new LocalMappingBuilder()
+ .setEid(new EidBuilder().setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/24"))
+ .build()).build())
+ .build();
+ ignoreUpdateAfter = new LocalMappingBuilder()
+ .setEid(new EidBuilder().setAddress(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(new Ipv4Prefix("192.168.2.4/24"))
+ .build()).build())
+ .build();
+
id = InstanceIdentifier.builder(Lisp.class)
.child(LispFeatureData.class)
.child(EidTable.class)
@@ -171,8 +202,14 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements
}
@Test(expected = UnsupportedOperationException.class)
- public void testUpdateCurrentAttributes() throws WriteFailedException {
- customizer.updateCurrentAttributes(null, null, null, writeContext);
+ public void testUpdateCurrentAttributesFail() throws WriteFailedException {
+ customizer.updateCurrentAttributes(null, failUpdateBefore, failUpdateAfter, writeContext);
+ }
+
+ @Test
+ public void testUpdateCurrentAttributesIgnore() throws WriteFailedException {
+ customizer.updateCurrentAttributes(null, ignoreUpdateBefore, ignoreUpdateAfter, writeContext);
+ verifyZeroInteractions(api);
}
@Test
@@ -194,7 +231,8 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements
}
@Test
- public void testDeleteCurrentAttributesWithHmacKey() throws WriteFailedException, InterruptedException, ExecutionException {
+ public void testDeleteCurrentAttributesWithHmacKey()
+ throws WriteFailedException, InterruptedException, ExecutionException {
when(eidMappingContext.containsEid(any(), eq(mappingContext))).thenReturn(true);
customizer.deleteCurrentAttributes(id, mappingWithHmacKey, writeContext);
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java
index 35cc87689..62823df73 100755
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java
@@ -26,6 +26,7 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
@@ -44,8 +45,10 @@ import org.mockito.Captor;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6PrefixBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.Lisp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MapReplyAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId;
@@ -77,6 +80,12 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements
private RemoteMapping negativeMapping;
private RemoteMapping positiveMappingNoPrioNoWeight;
private RemoteMapping positiveMappingPrioWeight;
+
+ private RemoteMapping failUpdateBefore;
+ private RemoteMapping failUpdateAfter;
+ private RemoteMapping ignoreUpdateBefore;
+ private RemoteMapping ignoreUpdateAfter;
+
private InstanceIdentifier<RemoteMapping> id;
@Mock
@@ -95,6 +104,28 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements
mappingId = new MappingId("REMOTE");
final RemoteMappingKey key = new RemoteMappingKey(mappingId);
+ failUpdateBefore = new RemoteMappingBuilder()
+ .setEid(new EidBuilder().setAddress(new Ipv6PrefixBuilder()
+ .setIpv6Prefix(new Ipv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))
+ .build()).build())
+ .build();
+ failUpdateAfter = new RemoteMappingBuilder()
+ .setEid(new EidBuilder().setAddress(new Ipv6PrefixBuilder()
+ .setIpv6Prefix(new Ipv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/48"))
+ .build()).build())
+ .build();
+
+ ignoreUpdateBefore = new RemoteMappingBuilder()
+ .setEid(new EidBuilder().setAddress(new Ipv6PrefixBuilder()
+ .setIpv6Prefix(new Ipv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))
+ .build()).build())
+ .build();
+ ignoreUpdateAfter = new RemoteMappingBuilder()
+ .setEid(new EidBuilder().setAddress(new Ipv6PrefixBuilder()
+ .setIpv6Prefix(new Ipv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7348/64"))
+ .build()).build())
+ .build();
+
negativeMapping = new RemoteMappingBuilder()
.setEid(eid)
.setLocatorList(new NegativeMappingBuilder()
@@ -205,8 +236,14 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements
}
@Test(expected = UnsupportedOperationException.class)
- public void testUpdateCurrentAttributes() throws WriteFailedException {
- customizer.updateCurrentAttributes(null, null, null, writeContext);
+ public void testUpdateCurrentAttributesFail() throws WriteFailedException {
+ customizer.updateCurrentAttributes(null, failUpdateBefore, failUpdateAfter, writeContext);
+ }
+
+ @Test
+ public void testUpdateCurrentAttributesIgnore() throws WriteFailedException {
+ customizer.updateCurrentAttributes(null, ignoreUpdateBefore, ignoreUpdateAfter, writeContext);
+ verifyZeroInteractions(api);
}
@Test(expected = NullPointerException.class)