summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/test/java
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-05-24 08:45:19 +0200
committerJan Srnicek <jsrnicek@cisco.com>2017-05-24 08:45:19 +0200
commit7ca39aa6d228dc552097857afc697ddf52bd3ad3 (patch)
treee1af2f7bd22ffc83a2958168f2b313dd765dda47 /lisp/lisp2vpp/src/test/java
parentb5d9c75265a5779ed7404b426f3f91a6b1e07e49 (diff)
HC2VPP-147 - Gpe entry implementation
Change-Id: Ie7887c8e8f10678410ad677c425bfed1690bf440 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/test/java')
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/read/GpeFeatureCustomizerTest.java67
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/read/GpeForwardEntryCustomizerTest.java520
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeFeatureCustomizerTest.java80
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeForwardEntryCustomizerTest.java313
4 files changed, 980 insertions, 0 deletions
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/read/GpeFeatureCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/read/GpeFeatureCustomizerTest.java
new file mode 100644
index 000000000..965906abd
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/read/GpeFeatureCustomizerTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.lisp.gpe.translate.read;
+
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.vpp.jvpp.core.dto.ShowLispStatusReply;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.Gpe;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.GpeState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.GpeStateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.feature.data.grouping.GpeFeatureData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.feature.data.grouping.GpeFeatureDataBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class GpeFeatureCustomizerTest extends InitializingReaderCustomizerTest<GpeFeatureData, GpeFeatureDataBuilder> {
+ public GpeFeatureCustomizerTest() {
+ super(GpeFeatureData.class, GpeStateBuilder.class);
+ }
+
+ @Override
+ protected GpeFeatureCustomizer initCustomizer() {
+ return new GpeFeatureCustomizer(api);
+ }
+
+ @Test
+ public void testReadCurrent() throws ReadFailedException {
+ final ShowLispStatusReply result = new ShowLispStatusReply();
+ result.gpeStatus = 1;
+ when(api.showLispStatus(any())).thenReturn(future(result));
+
+ final GpeFeatureDataBuilder builder = new GpeFeatureDataBuilder();
+ getCustomizer().readCurrentAttributes(InstanceIdentifier.create(GpeFeatureData.class), builder, ctx);
+ assertTrue(builder.isEnable());
+ }
+
+ @Test
+ public void testInit() {
+ final InstanceIdentifier<GpeFeatureData> CONFIG_ID =
+ InstanceIdentifier.create(Gpe.class).child(GpeFeatureData.class);
+
+ final InstanceIdentifier<GpeFeatureData> STATE_ID =
+ InstanceIdentifier.create(GpeState.class).child(GpeFeatureData.class);
+
+ final GpeFeatureData data = new GpeFeatureDataBuilder().build();
+ invokeInitTest(STATE_ID, data, CONFIG_ID, data);
+ }
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/read/GpeForwardEntryCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/read/GpeForwardEntryCustomizerTest.java
new file mode 100644
index 000000000..9e1958224
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/read/GpeForwardEntryCustomizerTest.java
@@ -0,0 +1,520 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.lisp.gpe.translate.read;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.read.InitializingListReaderCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.AddressTranslator;
+import io.fd.hc2vpp.lisp.gpe.translate.ctx.GpeEntryIdentifier;
+import io.fd.hc2vpp.lisp.gpe.translate.ctx.GpeEntryMappingContext;
+import io.fd.hc2vpp.lisp.gpe.translate.ctx.GpeLocatorPair;
+import io.fd.hc2vpp.lisp.gpe.translate.ctx.GpeLocatorPairMappingContext;
+import io.fd.hc2vpp.lisp.gpe.translate.service.GpeStateCheckService;
+import io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType;
+import io.fd.hc2vpp.lisp.translate.util.EidTranslator;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.vpp.jvpp.core.dto.GpeFwdEntriesGet;
+import io.fd.vpp.jvpp.core.dto.GpeFwdEntriesGetReply;
+import io.fd.vpp.jvpp.core.dto.GpeFwdEntryPathDetails;
+import io.fd.vpp.jvpp.core.dto.GpeFwdEntryPathDetailsReplyDump;
+import io.fd.vpp.jvpp.core.dto.GpeFwdEntryPathDump;
+import io.fd.vpp.jvpp.core.dto.GpeFwdEntryVnisGetReply;
+import io.fd.vpp.jvpp.core.types.GpeFwdEntry;
+import io.fd.vpp.jvpp.core.types.GpeLocator;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.gpe.entry.identification.context.rev170517.gpe.entry.identification.context.attributes.gpe.entry.identification.contexts.gpe.entry.identification.mappings.mapping.GpeEntryIdentificator;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.gpe.entry.identification.context.rev170517.gpe.entry.identification.context.attributes.gpe.entry.identification.contexts.gpe.entry.identification.mappings.mapping.GpeEntryIdentificatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.gpe.entry.identification.context.rev170517.gpe.entry.identification.context.attributes.gpe.entry.identification.contexts.gpe.entry.identification.mappings.mapping.gpe.entry.identificator.LocalEidBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.gpe.entry.identification.context.rev170517.gpe.entry.identification.context.attributes.gpe.entry.identification.contexts.gpe.entry.identification.mappings.mapping.gpe.entry.identificator.RemoteEidBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.gpe.locator.pair.identification.context.rev170517.gpe.locator.pair.identification.context.attributes.gpe.locator.pair.identification.contexts.gpe.locator.pair.identification.mappings.mapping.LocatorPairMapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.gpe.locator.pair.identification.context.rev170517.gpe.locator.pair.identification.context.attributes.gpe.locator.pair.identification.contexts.gpe.locator.pair.identification.mappings.mapping.LocatorPairMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.gpe.locator.pair.identification.context.rev170517.gpe.locator.pair.identification.context.attributes.gpe.locator.pair.identification.contexts.gpe.locator.pair.identification.mappings.mapping.locator.pair.mapping.PairBuilder;
+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.Ipv4Prefix;
+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.inet.types.rev130715.Ipv6Prefix;
+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.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.Ipv4PrefixBuilder;
+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.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.gpe.rev170518.Gpe;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.GpeState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.entry.table.grouping.GpeEntryTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.entry.table.grouping.GpeEntryTableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.entry.table.grouping.gpe.entry.table.GpeEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.entry.table.grouping.gpe.entry.table.GpeEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.entry.table.grouping.gpe.entry.table.GpeEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.entry.table.grouping.gpe.entry.table.gpe.entry.LocatorPairs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.feature.data.grouping.GpeFeatureData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.locator.pair.LocatorPair;
+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.dp.subtable.grouping.local.mappings.local.mapping.Eid;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+public class GpeForwardEntryCustomizerTest
+ extends InitializingListReaderCustomizerTest<GpeEntry, GpeEntryKey, GpeEntryBuilder>
+ implements AddressTranslator, EidTranslator {
+
+ private static final String V4_ENTRY_ID = "v4-entry";
+ private static final String V4_ENTRY_LOCATOR = "v4-entry-locator";
+ private static final int V4_ENTRY_DP_TABLE = 10;
+ private static final int V4_ENTRY_FWD_INDEX = 4;
+ private static final int V4_ENTRY_VNI = 45;
+ private static final KeyedInstanceIdentifier<GpeEntry, GpeEntryKey> V4_IDENTIFIER =
+ InstanceIdentifier.create(GpeEntryTable.class)
+ .child(GpeEntry.class, new GpeEntryKey(V4_ENTRY_ID));
+ private static final Ipv4Prefix
+ V4_ENTRY_LOCAL_ADDRESS = new Ipv4Prefix("192.168.2.0/24");
+ private static final Ipv4Prefix
+ V4_ENTRY_REMOTE_ADDRESS = new Ipv4Prefix("192.168.3.0/24");
+ private static final Ipv4AddressNoZone
+ V4_LOCATOR_LOCAL_ADDRESS = new Ipv4AddressNoZone("192.168.5.4");
+ private static final Ipv4AddressNoZone
+ V4_LOCATOR_REMOTE_ADDRESS = new Ipv4AddressNoZone("192.168.7.4");
+
+
+ private static final String V6_ENTRY_ID = "v6-entry";
+ private static final String V6_ENTRY_LOCATOR = "v6-entry-locator";
+ private static final int V6_ENTRY_DP_TABLE = 11;
+ private static final int V6_ENTRY_VNI = 22;
+ private static final int V6_ENTRY_FWD_INDEX = 5;
+ private static final Ipv6Prefix
+ V6_ENTRY_LOCAL_ADDRESS = new Ipv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64");
+ private static final Ipv6Prefix
+ V6_ENTRY_REMOTE_ADDRESS = new Ipv6Prefix("2001:0db8:85a7:0000:0000:8a2e:0370:7334/64");
+ private static final KeyedInstanceIdentifier<GpeEntry, GpeEntryKey> V6_IDENTIFIER =
+ InstanceIdentifier.create(GpeEntryTable.class)
+ .child(GpeEntry.class, new GpeEntryKey(V6_ENTRY_ID));
+ private static final Ipv6AddressNoZone
+ V6_LOCATOR_LOCAL_ADDRESS = new Ipv6AddressNoZone("2001:db8:85a3::8a2e:370:7334");
+ private static final Ipv6AddressNoZone
+ V6_LOCATOR_REMOTE_ADDRESS = new Ipv6AddressNoZone("2001:db8:85a3::8a2e:222:7334");
+
+ private static final String MAC_ENTRY_ID = "mac-entry";
+ private static final int MAC_ENTRY_FWD_INDEX = 7;
+ private static final int MAC_ENTRY_VNI = 18;
+ private static final String MAC_ENTRY_LOCATOR = "mac-entry-locator";
+ private static final int MAC_ENTRY_DP_TABLE = 12;
+ private static final KeyedInstanceIdentifier<GpeEntry, GpeEntryKey> MAC_IDENTIFIER =
+ InstanceIdentifier.create(GpeEntryTable.class)
+ .child(GpeEntry.class, new GpeEntryKey(MAC_ENTRY_ID));
+ private static final String MAC_ENTRY_LOCAL_ADDRESS_VALUE = "aa:bb:cc:dd:ee:ff";
+ private static final String MAC_ENTRY_REMOTE_ADDRESS_VALUE = "bb:cc:bb:cc:bb:cc";
+
+ private static final Ipv4AddressNoZone
+ MAC_LOCATOR_LOCAL_ADDRESS = new Ipv4AddressNoZone("192.168.7.4");
+ private static final Ipv4AddressNoZone
+ MAC_LOCATOR_REMOTE_ADDRESS = new Ipv4AddressNoZone("192.168.2.4");
+ public static final int V6_LOCATOR_LOCAL_WEIGHT = 3;
+ public static final int MAC_LOCATOR_LOCAL_WEIGHT = 7;
+ public static final int V4_LOCATOR_LOCAL_WEIGHT = 2;
+
+
+ @Mock
+ private GpeEntryMappingContext gpeEntryMappingContext;
+
+ @Mock
+ private GpeLocatorPairMappingContext gpeLocatorPairMappingContext;
+
+ @Mock
+ private GpeStateCheckService gpeStateCheckService;
+
+ public GpeForwardEntryCustomizerTest() {
+ super(GpeEntry.class, GpeEntryTableBuilder.class);
+ }
+
+ @Override
+ protected GpeForwardEntryCustomizer initCustomizer() {
+ return new GpeForwardEntryCustomizer(api, gpeStateCheckService, gpeEntryMappingContext,
+ gpeLocatorPairMappingContext);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ when(gpeStateCheckService.isGpeEnabled(ctx)).thenReturn(true);
+ when(api.gpeFwdEntriesGet(entryRequest(V4_ENTRY_VNI)))
+ .thenReturn(future(getGpeEntryDumpReply(getV4GpeEntry())));
+ when(api.gpeFwdEntriesGet(entryRequest(V6_ENTRY_VNI)))
+ .thenReturn(future(getGpeEntryDumpReply(getV6GpeEntry())));
+ when(api.gpeFwdEntriesGet(entryRequest(MAC_ENTRY_VNI)))
+ .thenReturn(future(getGpeEntryDumpReply(getMacGpeEntry())));
+ when(api.gpeFwdEntryVnisGet(any())).thenReturn(future(activeVnisDump()));
+ mockMappingsForGpeEntries();
+ mockMappingsForLocators();
+ }
+
+ @Test
+ public void testGetAll() throws ReadFailedException {
+ final List<GpeEntryKey> allIds = getCustomizer().getAllIds(V4_IDENTIFIER, ctx);
+
+ assertTrue(allIds.containsAll(Arrays.asList(new GpeEntryKey(V4_ENTRY_ID),
+ new GpeEntryKey(V6_ENTRY_ID),
+ new GpeEntryKey(MAC_ENTRY_ID))));
+ }
+
+ @Test
+ public void testReadCurrentV4Entry() throws ReadFailedException {
+ mockLocatorDump();
+ final GpeEntryBuilder builder = new GpeEntryBuilder();
+ getCustomizer().readCurrentAttributes(V4_IDENTIFIER, builder, ctx);
+
+ assertEquals(V4_ENTRY_ID, builder.getId());
+ assertEquals(10, builder.getDpTable().intValue());
+ assertTrue(compareAddresses(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(V4_ENTRY_LOCAL_ADDRESS)
+ .build(), builder.getLocalEid().getAddress()));
+ assertEquals(Ipv4PrefixAfi.class, builder.getLocalEid().getAddressType());
+ assertEquals(V4_ENTRY_VNI, builder.getLocalEid().getVirtualNetworkId().getValue().intValue());
+ assertTrue(compareAddresses(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(V4_ENTRY_REMOTE_ADDRESS)
+ .build(), builder.getRemoteEid().getAddress()));
+ assertEquals(Ipv4PrefixAfi.class, builder.getRemoteEid().getAddressType());
+ assertEquals(V4_ENTRY_VNI, builder.getRemoteEid().getVirtualNetworkId().getValue().intValue());
+ assertTrue(V4_ENTRY_VNI == builder.getVni());
+ assertEquals(1, builder.getLocatorPairs().size());
+
+ final LocatorPairs locatorPair = builder.getLocatorPairs().get(0);
+ assertEquals(V4_ENTRY_LOCATOR, locatorPair.getId());
+
+ final LocatorPair pair = locatorPair.getLocatorPair();
+ assertEquals(V4_LOCATOR_LOCAL_ADDRESS, pair.getLocalLocator().getIpv4Address());
+ assertEquals(V4_LOCATOR_REMOTE_ADDRESS, pair.getRemoteLocator().getIpv4Address());
+ assertEquals(V4_LOCATOR_LOCAL_WEIGHT, pair.getWeight().byteValue());
+ }
+
+ @Test
+ public void testReadCurrentV6Entry() throws ReadFailedException {
+ mockLocatorDump();
+ final GpeEntryBuilder builder = new GpeEntryBuilder();
+ getCustomizer().readCurrentAttributes(V6_IDENTIFIER, builder, ctx);
+
+ assertEquals(V6_ENTRY_ID, builder.getId());
+ assertEquals(V6_ENTRY_DP_TABLE, builder.getDpTable().intValue());
+ assertTrue(compareAddresses(new Ipv6PrefixBuilder()
+ .setIpv6Prefix(V6_ENTRY_LOCAL_ADDRESS)
+ .build(), builder.getLocalEid().getAddress()));
+ assertEquals(Ipv6PrefixAfi.class, builder.getLocalEid().getAddressType());
+ assertEquals(V6_ENTRY_VNI, builder.getLocalEid().getVirtualNetworkId().getValue().intValue());
+ assertTrue(compareAddresses(new Ipv6PrefixBuilder()
+ .setIpv6Prefix(V6_ENTRY_REMOTE_ADDRESS)
+ .build(), builder.getRemoteEid().getAddress()));
+ assertEquals(Ipv6PrefixAfi.class, builder.getRemoteEid().getAddressType());
+ assertEquals(V6_ENTRY_VNI, builder.getRemoteEid().getVirtualNetworkId().getValue().intValue());
+ assertTrue(V6_ENTRY_VNI == builder.getVni());
+
+ assertEquals(1, builder.getLocatorPairs().size());
+
+ final LocatorPairs locatorPair = builder.getLocatorPairs().get(0);
+ assertEquals(V6_ENTRY_LOCATOR, locatorPair.getId());
+
+ final LocatorPair pair = locatorPair.getLocatorPair();
+ assertEquals(V6_LOCATOR_LOCAL_ADDRESS, pair.getLocalLocator().getIpv6Address());
+ assertEquals(V6_LOCATOR_REMOTE_ADDRESS, pair.getRemoteLocator().getIpv6Address());
+ assertEquals(V6_LOCATOR_LOCAL_WEIGHT, pair.getWeight().byteValue());
+ }
+
+ @Test
+ public void testReadCurrentMacEntry() throws ReadFailedException {
+ mockLocatorDump();
+ final GpeEntryBuilder builder = new GpeEntryBuilder();
+ getCustomizer().readCurrentAttributes(MAC_IDENTIFIER, builder, ctx);
+
+ assertEquals(MAC_ENTRY_ID, builder.getId());
+ assertEquals(MAC_ENTRY_DP_TABLE, builder.getDpTable().intValue());
+ assertTrue(compareAddresses(new MacBuilder()
+ .setMac(new MacAddress(MAC_ENTRY_LOCAL_ADDRESS_VALUE))
+ .build(), builder.getLocalEid().getAddress()));
+ assertEquals(MAC_ENTRY_VNI, builder.getLocalEid().getVirtualNetworkId().getValue().intValue());
+ assertEquals(MacAfi.class, builder.getLocalEid().getAddressType());
+ assertTrue(compareAddresses(new MacBuilder()
+ .setMac(new MacAddress(MAC_ENTRY_REMOTE_ADDRESS_VALUE))
+ .build(), builder.getRemoteEid().getAddress()));
+ assertEquals(MacAfi.class, builder.getRemoteEid().getAddressType());
+ assertEquals(MAC_ENTRY_VNI, builder.getRemoteEid().getVirtualNetworkId().getValue().intValue());
+ assertTrue(MAC_ENTRY_VNI == builder.getVni());
+
+ assertEquals(1, builder.getLocatorPairs().size());
+
+ final LocatorPairs locatorPair = builder.getLocatorPairs().get(0);
+ assertEquals(MAC_ENTRY_LOCATOR, locatorPair.getId());
+
+ final LocatorPair pair = locatorPair.getLocatorPair();
+ assertEquals(MAC_LOCATOR_LOCAL_ADDRESS, pair.getLocalLocator().getIpv4Address());
+ assertEquals(MAC_LOCATOR_REMOTE_ADDRESS, pair.getRemoteLocator().getIpv4Address());
+ assertEquals(MAC_LOCATOR_LOCAL_WEIGHT, pair.getWeight().byteValue());
+ }
+
+ @Test
+ public void testReadCurrentNegativeMapping() throws ReadFailedException {
+ when(api.gpeFwdEntryPathDump(any())).thenReturn(future(new GpeFwdEntryPathDetailsReplyDump()));
+ final GpeEntryBuilder builder = new GpeEntryBuilder();
+ getCustomizer().readCurrentAttributes(V4_IDENTIFIER, builder, ctx);
+
+ assertEquals(V4_ENTRY_ID, builder.getId());
+ assertEquals(V4_ENTRY_DP_TABLE, builder.getDpTable().intValue());
+ assertTrue(compareAddresses(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(V4_ENTRY_LOCAL_ADDRESS)
+ .build(), builder.getLocalEid().getAddress()));
+ assertEquals(Ipv4PrefixAfi.class, builder.getLocalEid().getAddressType());
+ assertTrue(compareAddresses(new Ipv4PrefixBuilder()
+ .setIpv4Prefix(V4_ENTRY_REMOTE_ADDRESS)
+ .build(), builder.getRemoteEid().getAddress()));
+ assertEquals(Ipv4PrefixAfi.class, builder.getRemoteEid().getAddressType());
+ assertEquals(MapReplyAction.Drop, builder.getAction());
+ }
+
+ @Test
+ public void testInit() {
+ final InstanceIdentifier<GpeEntry> CONFIG_ID =
+ InstanceIdentifier.create(Gpe.class).child(GpeFeatureData.class).child(GpeEntryTable.class)
+ .child(GpeEntry.class, new GpeEntryKey(V4_ENTRY_ID));
+
+ final InstanceIdentifier<GpeEntry> STATE_ID =
+ InstanceIdentifier.create(GpeState.class).child(GpeFeatureData.class).child(GpeEntryTable.class)
+ .child(GpeEntry.class, new GpeEntryKey(V4_ENTRY_ID));
+
+ final GpeEntry entry = new GpeEntryBuilder().build();
+
+ invokeInitTest(STATE_ID, entry, CONFIG_ID, entry);
+ }
+
+ private GpeFwdEntriesGet entryRequest(final int vni) {
+ GpeFwdEntriesGet request = new GpeFwdEntriesGet();
+ request.vni = vni;
+ return request;
+ }
+
+ private void mockLocatorDump() {
+ when(api.gpeFwdEntryPathDump(pathRequest(V4_ENTRY_FWD_INDEX))).thenReturn(future(locatorDumpForV4EntryReply()));
+ when(api.gpeFwdEntryPathDump(pathRequest(V6_ENTRY_FWD_INDEX))).thenReturn(future(locatorDumpForV6EntryReply()));
+ when(api.gpeFwdEntryPathDump(pathRequest(MAC_ENTRY_FWD_INDEX)))
+ .thenReturn(future(locatorDumpForMacEntryReply()));
+ }
+
+ private GpeFwdEntryPathDump pathRequest(final int fwdIndex) {
+ GpeFwdEntryPathDump request = new GpeFwdEntryPathDump();
+ request.fwdEntryIndex = fwdIndex;
+ return request;
+ }
+
+ private void mockMappingsForGpeEntries() {
+ when(gpeEntryMappingContext
+ .getIdByEntryIdentifier(GpeEntryIdentifier.fromDumpDetail(getV4GpeEntry()), mappingContext))
+ .thenReturn(V4_ENTRY_ID);
+ when(gpeEntryMappingContext
+ .getIdentificatorById(V4_ENTRY_ID, mappingContext))
+ .thenReturn(fromDumpDetail(getV4GpeEntry()));
+ when(gpeEntryMappingContext
+ .getIdByEntryIdentifier(GpeEntryIdentifier.fromDumpDetail(getV6GpeEntry()), mappingContext))
+ .thenReturn(V6_ENTRY_ID);
+ when(gpeEntryMappingContext
+ .getIdentificatorById(V6_ENTRY_ID, mappingContext))
+ .thenReturn(fromDumpDetail(getV6GpeEntry()));
+ when(gpeEntryMappingContext
+ .getIdByEntryIdentifier(GpeEntryIdentifier.fromDumpDetail(getMacGpeEntry()), mappingContext))
+ .thenReturn(MAC_ENTRY_ID);
+ when(gpeEntryMappingContext
+ .getIdentificatorById(MAC_ENTRY_ID, mappingContext))
+ .thenReturn(fromDumpDetail(getMacGpeEntry()));
+ }
+
+ private void mockMappingsForLocators() {
+ mockV4LocatorMapping();
+ mockV6LocatorMapping();
+ mockMacLocatorMapping();
+ }
+
+ private void mockV4LocatorMapping() {
+ final GpeFwdEntryPathDetailsReplyDump forV4EntryReply = locatorDumpForV4EntryReply();
+ final GpeFwdEntryPathDetails v4LocatorOne = forV4EntryReply.gpeFwdEntryPathDetails.get(0);
+ final GpeLocatorPair v4LocatorPairOne = GpeLocatorPair.fromDumpDetail(v4LocatorOne);
+ when(gpeLocatorPairMappingContext.getMapping(V4_ENTRY_ID, v4LocatorPairOne, mappingContext))
+ .thenReturn(fromDump(V4_ENTRY_LOCATOR, v4LocatorOne));
+ }
+
+ private void mockV6LocatorMapping() {
+ final GpeFwdEntryPathDetailsReplyDump forV6EntryReply = locatorDumpForV6EntryReply();
+ final GpeFwdEntryPathDetails v6LocatorOne = forV6EntryReply.gpeFwdEntryPathDetails.get(0);
+ final GpeLocatorPair v6LocatorPairOne = GpeLocatorPair.fromDumpDetail(v6LocatorOne);
+ when(gpeLocatorPairMappingContext.getMapping(V6_ENTRY_ID, v6LocatorPairOne, mappingContext))
+ .thenReturn(fromDump(V6_ENTRY_LOCATOR, v6LocatorOne));
+ }
+
+ private void mockMacLocatorMapping() {
+ final GpeFwdEntryPathDetails macLocator = locatorDumpForMacEntryReply().gpeFwdEntryPathDetails.get(0);
+ final GpeLocatorPair macLocatorPair = GpeLocatorPair.fromDumpDetail(macLocator);
+ when(gpeLocatorPairMappingContext.getMapping(MAC_ENTRY_ID, macLocatorPair, mappingContext))
+ .thenReturn(fromDump(MAC_ENTRY_LOCATOR, macLocator));
+ }
+
+ private LocatorPairMapping fromDump(final String id, final GpeFwdEntryPathDetails dump) {
+
+ final boolean localV4 = byteToBoolean(dump.lclLoc.isIp4);
+ final boolean remoteV4 = byteToBoolean(dump.rmtLoc.isIp4);
+ return new LocatorPairMappingBuilder()
+ .setId(id)
+ .setPair(new PairBuilder()
+ .setLocalAddress(arrayToIpAddress(!localV4, dump.lclLoc.addr))
+ .setRemoteAddress(arrayToIpAddress(!remoteV4, dump.rmtLoc.addr))
+ .build())
+ .build();
+ }
+
+ private GpeEntryIdentificator fromDumpDetail(final GpeFwdEntry entry) {
+ final EidType eidType = EidType.valueOf(entry.eidType);
+ final Eid localEid = getArrayAsEidLocal(eidType, entry.leid, entry.leidPrefixLen, entry.vni);
+ final Eid remoteEid = getArrayAsEidLocal(eidType, entry.reid, entry.reidPrefixLen, entry.vni);
+ return new GpeEntryIdentificatorBuilder()
+ .setLocalEid(new LocalEidBuilder()
+ .setAddress(localEid.getAddress())
+ .setAddressType(localEid.getAddressType())
+ .setVirtualNetworkId(localEid.getVirtualNetworkId())
+ .build())
+ .setRemoteEid(new RemoteEidBuilder()
+ .setAddress(remoteEid.getAddress())
+ .setAddressType(remoteEid.getAddressType())
+ .setVirtualNetworkId(remoteEid.getVirtualNetworkId())
+ .build())
+ .setVni((long) entry.vni)
+ .build();
+ }
+
+ private GpeFwdEntriesGetReply getGpeEntryDumpReply(final GpeFwdEntry entry) {
+ GpeFwdEntriesGetReply reply = new GpeFwdEntriesGetReply();
+ reply.entries = new GpeFwdEntry[]{entry};
+ reply.count = reply.entries.length;
+ return reply;
+ }
+
+ private GpeFwdEntryVnisGetReply activeVnisDump() {
+ GpeFwdEntryVnisGetReply reply = new GpeFwdEntryVnisGetReply();
+ reply.vnis = new int[]{V4_ENTRY_VNI, V6_ENTRY_VNI, MAC_ENTRY_VNI};
+ return reply;
+ }
+
+ private GpeFwdEntryPathDetailsReplyDump locatorDumpForV4EntryReply() {
+ GpeFwdEntryPathDetailsReplyDump reply = new GpeFwdEntryPathDetailsReplyDump();
+
+ GpeFwdEntryPathDetails entry = new GpeFwdEntryPathDetails();
+ GpeLocator localLocator = new GpeLocator();
+ localLocator.addr = ipv4AddressNoZoneToArray(V4_LOCATOR_LOCAL_ADDRESS);
+ localLocator.isIp4 = 1;
+ localLocator.weight = V4_LOCATOR_LOCAL_WEIGHT;
+ GpeLocator remoteLocator = new GpeLocator();
+ remoteLocator.addr = ipv4AddressNoZoneToArray(V4_LOCATOR_REMOTE_ADDRESS);
+ remoteLocator.isIp4 = 1;
+
+ entry.lclLoc = localLocator;
+ entry.rmtLoc = remoteLocator;
+
+ reply.gpeFwdEntryPathDetails = Collections.singletonList(entry);
+
+ return reply;
+ }
+
+ private GpeFwdEntryPathDetailsReplyDump locatorDumpForMacEntryReply() {
+ GpeFwdEntryPathDetailsReplyDump reply = new GpeFwdEntryPathDetailsReplyDump();
+
+ GpeFwdEntryPathDetails entry = new GpeFwdEntryPathDetails();
+ GpeLocator localLocator = new GpeLocator();
+ localLocator.addr = ipv4AddressNoZoneToArray(MAC_LOCATOR_LOCAL_ADDRESS);
+ localLocator.isIp4 = 1;
+ localLocator.weight = MAC_LOCATOR_LOCAL_WEIGHT;
+ GpeLocator remoteLocator = new GpeLocator();
+ remoteLocator.addr = ipv4AddressNoZoneToArray(MAC_LOCATOR_REMOTE_ADDRESS);
+ remoteLocator.isIp4 = 1;
+
+ entry.lclLoc = localLocator;
+ entry.rmtLoc = remoteLocator;
+
+ reply.gpeFwdEntryPathDetails = Collections.singletonList(entry);
+
+ return reply;
+ }
+
+ private GpeFwdEntryPathDetailsReplyDump locatorDumpForV6EntryReply() {
+ GpeFwdEntryPathDetailsReplyDump reply = new GpeFwdEntryPathDetailsReplyDump();
+
+ GpeFwdEntryPathDetails entry = new GpeFwdEntryPathDetails();
+ GpeLocator localLocator = new GpeLocator();
+ localLocator.addr = ipv6AddressNoZoneToArray(V6_LOCATOR_LOCAL_ADDRESS);
+ localLocator.isIp4 = 0;
+ localLocator.weight = V6_LOCATOR_LOCAL_WEIGHT;
+ GpeLocator remoteLocator = new GpeLocator();
+ remoteLocator.addr = ipv6AddressNoZoneToArray(V6_LOCATOR_REMOTE_ADDRESS);
+ remoteLocator.isIp4 = 0;
+
+ entry.lclLoc = localLocator;
+ entry.rmtLoc = remoteLocator;
+
+ reply.gpeFwdEntryPathDetails = Collections.singletonList(entry);
+
+ return reply;
+ }
+
+ private GpeFwdEntry getMacGpeEntry() {
+ GpeFwdEntry entryThree = new GpeFwdEntry();
+ entryThree.dpTable = MAC_ENTRY_DP_TABLE;
+ entryThree.vni = MAC_ENTRY_VNI;
+ entryThree.eidType = 2;
+ entryThree.fwdEntryIndex = MAC_ENTRY_FWD_INDEX;
+ entryThree.leid = parseMac(MAC_ENTRY_LOCAL_ADDRESS_VALUE);
+ entryThree.reid = parseMac(MAC_ENTRY_REMOTE_ADDRESS_VALUE);
+
+ return entryThree;
+ }
+
+ private GpeFwdEntry getV6GpeEntry() {
+ GpeFwdEntry entryTwo = new GpeFwdEntry();
+ entryTwo.dpTable = V6_ENTRY_DP_TABLE;
+ entryTwo.vni = V6_ENTRY_VNI;
+ entryTwo.eidType = 1;
+ entryTwo.fwdEntryIndex = V6_ENTRY_FWD_INDEX;
+ entryTwo.leid = ipv6AddressPrefixToArray(V6_ENTRY_LOCAL_ADDRESS);
+ entryTwo.leidPrefixLen = 64;
+ entryTwo.reid = ipv6AddressPrefixToArray(V6_ENTRY_REMOTE_ADDRESS);
+ entryTwo.reidPrefixLen = 64;
+ return entryTwo;
+ }
+
+ private GpeFwdEntry getV4GpeEntry() {
+ GpeFwdEntry entryOne = new GpeFwdEntry();
+ entryOne.dpTable = V4_ENTRY_DP_TABLE;
+ entryOne.vni = V4_ENTRY_VNI;
+ entryOne.eidType = 0;
+ entryOne.action = 3;
+ entryOne.fwdEntryIndex = V4_ENTRY_FWD_INDEX;
+ entryOne.leid = ipv4AddressPrefixToArray(V4_ENTRY_LOCAL_ADDRESS);
+ entryOne.leidPrefixLen = 24;
+ entryOne.reid = ipv4AddressPrefixToArray(V4_ENTRY_REMOTE_ADDRESS);
+ entryOne.reidPrefixLen = 24;
+ return entryOne;
+ }
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeFeatureCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeFeatureCustomizerTest.java
new file mode 100644
index 000000000..c7f0ae816
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeFeatureCustomizerTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.lisp.gpe.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.GpeEnableDisable;
+import io.fd.vpp.jvpp.core.dto.GpeEnableDisableReply;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.feature.data.grouping.GpeFeatureData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.feature.data.grouping.GpeFeatureDataBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class GpeFeatureCustomizerTest extends WriterCustomizerTest {
+
+ private GpeFeatureCustomizer customizer;
+
+ @Captor
+ private ArgumentCaptor<GpeEnableDisable> requestCaptor;
+
+ @Override
+ protected void setUpTest() throws Exception {
+ customizer = new GpeFeatureCustomizer(api);
+ }
+
+ @Test
+ public void testWrite() throws WriteFailedException {
+ when(api.gpeEnableDisable(any())).thenReturn(future(new GpeEnableDisableReply()));
+
+ customizer.writeCurrentAttributes(InstanceIdentifier.create(GpeFeatureData.class),
+ new GpeFeatureDataBuilder().setEnable(true).build(), writeContext);
+ verify(api, times(1)).gpeEnableDisable(requestCaptor.capture());
+ final GpeEnableDisable request = requestCaptor.getValue();
+ assertEquals(1, request.isEn);
+ }
+
+ @Test
+ public void testDelete() throws WriteFailedException {
+ when(api.gpeEnableDisable(any())).thenReturn(future(new GpeEnableDisableReply()));
+
+ customizer.deleteCurrentAttributes(InstanceIdentifier.create(GpeFeatureData.class),
+ new GpeFeatureDataBuilder().setEnable(true).build(), writeContext);
+ verify(api, times(1)).gpeEnableDisable(requestCaptor.capture());
+ final GpeEnableDisable request = requestCaptor.getValue();
+ assertEquals(0, request.isEn);
+ }
+
+ @Test
+ public void testUpdate() throws WriteFailedException {
+ when(api.gpeEnableDisable(any())).thenReturn(future(new GpeEnableDisableReply()));
+
+ customizer.writeCurrentAttributes(InstanceIdentifier.create(GpeFeatureData.class),
+ new GpeFeatureDataBuilder().setEnable(false).build(), writeContext);
+ verify(api, times(1)).gpeEnableDisable(requestCaptor.capture());
+ final GpeEnableDisable request = requestCaptor.getValue();
+ assertEquals(0, request.isEn);
+ }
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeForwardEntryCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeForwardEntryCustomizerTest.java
new file mode 100644
index 000000000..74c9bdeba
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeForwardEntryCustomizerTest.java
@@ -0,0 +1,313 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.lisp.gpe.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.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 com.google.common.collect.ImmutableSet;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.hc2vpp.lisp.gpe.translate.ctx.GpeEntryIdentifier;
+import io.fd.hc2vpp.lisp.gpe.translate.ctx.GpeEntryMappingContext;
+import io.fd.hc2vpp.lisp.gpe.translate.ctx.GpeLocatorPair;
+import io.fd.hc2vpp.lisp.gpe.translate.ctx.GpeLocatorPairMappingContext;
+import io.fd.hc2vpp.lisp.gpe.translate.service.GpeStateCheckService;
+import io.fd.honeycomb.test.tools.HoneycombTestRunner;
+import io.fd.honeycomb.test.tools.annotations.InjectTestData;
+import io.fd.honeycomb.test.tools.annotations.InjectablesProcessor;
+import io.fd.honeycomb.test.tools.annotations.SchemaContextProvider;
+import io.fd.vpp.jvpp.core.dto.GpeAddDelFwdEntry;
+import io.fd.vpp.jvpp.core.dto.GpeAddDelFwdEntryReply;
+import io.fd.vpp.jvpp.core.types.GpeLocator;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.entry.table.grouping.GpeEntryTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.entry.table.grouping.gpe.entry.table.GpeEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.entry.table.grouping.gpe.entry.table.GpeEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.entry.table.grouping.gpe.entry.table.gpe.entry.LocatorPairs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.$YangModuleInfoImpl;
+import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+@RunWith(HoneycombTestRunner.class)
+public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
+ implements InjectablesProcessor, ByteDataTranslator {
+
+ private static final String GPE_ENTRY_ID = "gpe-fwd-entry-1";
+ private static final String GPE_ENTRY_PATH = "/gpe:gpe" +
+ "/gpe:gpe-feature-data" +
+ "/gpe:gpe-entry-table";
+ private static final byte[] LOCAL_EID_ADDRESS = {-64, -88, 2, 0};
+ private static final byte[] REMOTE_EID_ADDRESS = {-64, -88, 3, 0};
+ private static final byte[] PAIR_2_LOCAL_ADDRESS = {-64, -88, 5, 1};
+ private static final byte[] PAIR_1_LOCAL_ADDRESS = {-64, -88, 4, 1};
+ private static final byte[] PAIR_2_REMOTE_ADDRESS = {-64, -88, 5, 2};
+ private static final byte[] PAIR_1_REMOTE_ADDRESS = {-64, -88, 4, 2};
+ private static final int LOCAL_EID_PREFIX = 24;
+ private static final int REMOTE_EID_PREFIX = 16;
+
+ @Captor
+ private ArgumentCaptor<GpeAddDelFwdEntry> requestCaptor;
+
+ @Mock
+ private GpeEntryMappingContext gpeEntryMappingContext;
+
+ @Mock
+ private GpeLocatorPairMappingContext gpeLocatorPairMappingContext;
+
+ @Mock
+ private GpeStateCheckService gpeStateCheckService;
+
+ private InstanceIdentifier<GpeEntry> id;
+ private GpeForwardEntryCustomizer customizer;
+
+ @Override
+ protected void setUpTest() throws Exception {
+ id = InstanceIdentifier.create(GpeEntryTable.class)
+ .child(GpeEntry.class, new GpeEntryKey(GPE_ENTRY_ID));
+ customizer = new GpeForwardEntryCustomizer(api, gpeStateCheckService, gpeEntryMappingContext,
+ gpeLocatorPairMappingContext);
+ }
+
+ @SchemaContextProvider
+ public ModuleInfoBackedContext schemaContext() {
+ return provideSchemaContextFor(ImmutableSet.of($YangModuleInfoImpl.getInstance(),
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.$YangModuleInfoImpl
+ .getInstance(),
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.$YangModuleInfoImpl
+ .getInstance()));
+ }
+
+ @Test
+ public void testWriteCurrentAttributesFull(@InjectTestData(resourcePath = "/gpe/gpe-fwd-entry-full.json",
+ id = GPE_ENTRY_PATH) GpeEntryTable entryTable) throws Exception {
+ when(api.gpeAddDelFwdEntry(any())).thenReturn(future(new GpeAddDelFwdEntryReply()));
+ final GpeEntry entry = entryTable.getGpeEntry().get(0);
+ customizer.writeCurrentAttributes(id, entry, writeContext);
+ verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
+ assertEquals(expectedFullRequest(true), requestCaptor.getValue());
+ verify(gpeEntryMappingContext, times(1))
+ .addMapping(entry.getId(), GpeEntryIdentifier.fromEntry(entry), mappingContext);
+
+ final LocatorPairs locatorPairFirst = entry.getLocatorPairs().get(0);
+ final LocatorPairs locatorPairSecond = entry.getLocatorPairs().get(1);
+ verify(gpeLocatorPairMappingContext, times(1))
+ .addMapping(entry.getId(), locatorPairFirst.getId(),
+ GpeLocatorPair.fromLocatorPair(locatorPairFirst), mappingContext);
+ verify(gpeLocatorPairMappingContext, times(1))
+ .addMapping(entry.getId(), locatorPairSecond.getId(),
+ GpeLocatorPair.fromLocatorPair(locatorPairSecond), mappingContext);
+ }
+
+ @Test
+ public void testWriteCurrentAttributesWithoutLocators(
+ @InjectTestData(resourcePath = "/gpe/gpe-fwd-entry-without-locators.json",
+ id = GPE_ENTRY_PATH) GpeEntryTable entryTable) throws Exception {
+ when(api.gpeAddDelFwdEntry(any())).thenReturn(future(new GpeAddDelFwdEntryReply()));
+ final GpeEntry entry = entryTable.getGpeEntry().get(0);
+ customizer.writeCurrentAttributes(id, entry, writeContext);
+ verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
+ assertEquals(expectedLocatorLessRequest(true), requestCaptor.getValue());
+ verify(gpeEntryMappingContext, times(1))
+ .addMapping(entry.getId(), GpeEntryIdentifier.fromEntry(entry), mappingContext);
+ verifyZeroInteractions(gpeLocatorPairMappingContext);
+ }
+
+ @Test
+ public void testWriteCurrentAttributesWithoutAction(
+ @InjectTestData(resourcePath = "/gpe/gpe-fwd-entry-without-action.json",
+ id = GPE_ENTRY_PATH) GpeEntryTable entryTable) throws Exception {
+ when(api.gpeAddDelFwdEntry(any())).thenReturn(future(new GpeAddDelFwdEntryReply()));
+ final GpeEntry entry = entryTable.getGpeEntry().get(0);
+ customizer.writeCurrentAttributes(id, entry, writeContext);
+ verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
+ assertEquals(expectedActionLessRequest(true), requestCaptor.getValue());
+ verify(gpeEntryMappingContext, times(1))
+ .addMapping(entry.getId(), GpeEntryIdentifier.fromEntry(entry), mappingContext);
+ verifyZeroInteractions(gpeLocatorPairMappingContext);
+ }
+
+ @Test
+ public void testWriteCurrentAttributesFailNoLocalEid(
+ @InjectTestData(resourcePath = "/gpe/invalid/invalid-gpe-fwd-entry-no-local-eid.json",
+ id = GPE_ENTRY_PATH) GpeEntryTable entryTable) throws Exception {
+ try {
+ customizer.writeCurrentAttributes(id, entryTable.getGpeEntry().get(0), writeContext);
+ } catch (IllegalArgumentException e) {
+ verifyZeroInteractions(api);
+ return;
+ }
+ fail("Test should have failed");
+ }
+
+ @Test
+ public void testWriteCurrentAttributesFailNoRemoteEid(
+ @InjectTestData(resourcePath = "/gpe/invalid/invalid-gpe-fwd-entry-no-remote-eid.json",
+ id = GPE_ENTRY_PATH) GpeEntryTable entryTable) throws Exception {
+ try {
+ customizer.writeCurrentAttributes(id, entryTable.getGpeEntry().get(0), writeContext);
+ } catch (IllegalArgumentException e) {
+ verifyZeroInteractions(api);
+ return;
+ }
+ fail("Test should have failed");
+ }
+
+ @Test
+ public void testDeleteCurrentAttributesFull(@InjectTestData(resourcePath = "/gpe/gpe-fwd-entry-full.json",
+ id = GPE_ENTRY_PATH) GpeEntryTable entryTable) throws Exception {
+ when(api.gpeAddDelFwdEntry(any())).thenReturn(future(new GpeAddDelFwdEntryReply()));
+ final GpeEntry entry = entryTable.getGpeEntry().get(0);
+ customizer.deleteCurrentAttributes(id, entry, writeContext);
+ verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
+ assertEquals(expectedFullRequest(false), requestCaptor.getValue());
+ verify(gpeEntryMappingContext, times(1))
+ .removeMapping(entry.getId(), mappingContext);
+ verify(gpeLocatorPairMappingContext, times(1))
+ .removeMapping(entry.getId(), mappingContext);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributesWithoutLocators(
+ @InjectTestData(resourcePath = "/gpe/gpe-fwd-entry-without-locators.json",
+ id = GPE_ENTRY_PATH) GpeEntryTable entryTable) throws Exception {
+ when(api.gpeAddDelFwdEntry(any())).thenReturn(future(new GpeAddDelFwdEntryReply()));
+ final GpeEntry entry = entryTable.getGpeEntry().get(0);
+ customizer.deleteCurrentAttributes(id, entry, writeContext);
+ verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
+ assertEquals(expectedLocatorLessRequest(false), requestCaptor.getValue());
+ verify(gpeEntryMappingContext, times(1))
+ .removeMapping(entry.getId(), mappingContext);
+ verify(gpeLocatorPairMappingContext, times(1))
+ .removeMapping(entry.getId(), mappingContext);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributesWithoutAction(
+ @InjectTestData(resourcePath = "/gpe/gpe-fwd-entry-without-action.json",
+ id = GPE_ENTRY_PATH) GpeEntryTable entryTable) throws Exception {
+ when(api.gpeAddDelFwdEntry(any())).thenReturn(future(new GpeAddDelFwdEntryReply()));
+ final GpeEntry entry = entryTable.getGpeEntry().get(0);
+ customizer.deleteCurrentAttributes(id, entry, writeContext);
+ verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
+ assertEquals(expectedActionLessRequest(false), requestCaptor.getValue());
+ verify(gpeEntryMappingContext, times(1))
+ .removeMapping(entry.getId(), mappingContext);
+ verify(gpeLocatorPairMappingContext, times(1))
+ .removeMapping(entry.getId(), mappingContext);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributesFailNoLocalEid(
+ @InjectTestData(resourcePath = "/gpe/invalid/invalid-gpe-fwd-entry-no-local-eid.json",
+ id = GPE_ENTRY_PATH) GpeEntryTable entryTable) throws Exception {
+ try {
+ customizer.deleteCurrentAttributes(id, entryTable.getGpeEntry().get(0), writeContext);
+ } catch (IllegalArgumentException e) {
+ verifyZeroInteractions(api);
+ return;
+ }
+ fail("Test should have failed");
+ }
+
+ @Test
+ public void testDeleteCurrentAttributesFailNoRemoteEid(
+ @InjectTestData(resourcePath = "/gpe/invalid/invalid-gpe-fwd-entry-no-remote-eid.json",
+ id = GPE_ENTRY_PATH) GpeEntryTable entryTable) throws Exception {
+ try {
+ customizer.deleteCurrentAttributes(id, entryTable.getGpeEntry().get(0), writeContext);
+ } catch (IllegalArgumentException e) {
+ verifyZeroInteractions(api);
+ return;
+ }
+ fail("Test should have failed");
+ }
+
+ private GpeAddDelFwdEntry expectedActionLessRequest(final boolean add) {
+ final GpeAddDelFwdEntry request = new GpeAddDelFwdEntry();
+
+ request.isAdd = booleanToByte(add);
+ request.dpTable = 10;
+ request.vni = 12;
+ request.eidType = 0;
+ request.action = 0;
+ request.lclEid = LOCAL_EID_ADDRESS;
+ request.lclLen = LOCAL_EID_PREFIX;
+ request.rmtEid = REMOTE_EID_ADDRESS;
+ request.rmtLen = REMOTE_EID_PREFIX;
+ request.locNum = 0;
+ return request;
+ }
+
+ private GpeAddDelFwdEntry expectedLocatorLessRequest(final boolean add) {
+ final GpeAddDelFwdEntry request = new GpeAddDelFwdEntry();
+
+ request.isAdd = booleanToByte(add);
+ request.dpTable = 10;
+ request.vni = 12;
+ request.eidType = 0;
+ request.action = 1;
+ request.lclEid = LOCAL_EID_ADDRESS;
+ request.lclLen = LOCAL_EID_PREFIX;
+ request.rmtEid = REMOTE_EID_ADDRESS;
+ request.rmtLen = REMOTE_EID_PREFIX;
+ request.locNum = 0;
+ return request;
+ }
+
+
+ private GpeAddDelFwdEntry expectedFullRequest(final boolean add) {
+ final GpeAddDelFwdEntry request = new GpeAddDelFwdEntry();
+
+ request.isAdd = booleanToByte(add);
+ request.dpTable = 10;
+ request.vni = 12;
+ request.eidType = 0;
+ request.action = 1;
+ request.lclEid = LOCAL_EID_ADDRESS;
+ request.lclLen = LOCAL_EID_PREFIX;
+ request.rmtEid = REMOTE_EID_ADDRESS;
+ request.rmtLen = REMOTE_EID_PREFIX;
+ request.locNum = 4;
+ request.locs = new GpeLocator[]{
+ gpeLocator(PAIR_2_LOCAL_ADDRESS, 1, 2),
+ gpeLocator(PAIR_1_LOCAL_ADDRESS, 1, 3),
+ gpeLocator(PAIR_1_REMOTE_ADDRESS, 1, 0),
+ gpeLocator(PAIR_2_REMOTE_ADDRESS, 1, 0)
+ };
+
+ return request;
+ }
+
+ private GpeLocator gpeLocator(final byte[] address, final int isIpv4, final int weight) {
+ GpeLocator locator = new GpeLocator();
+ locator.isIp4 = (byte) isIpv4;
+ locator.weight = (byte) weight;
+ locator.addr = address;
+
+ return locator;
+ }
+} \ No newline at end of file