summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeForwardEntryCustomizerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeForwardEntryCustomizerTest.java')
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeForwardEntryCustomizerTest.java189
1 files changed, 70 insertions, 119 deletions
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
index c54206270..fe5c09b6b 100644
--- 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
@@ -29,8 +29,6 @@ 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.common.translate.util.NamingContext;
-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;
@@ -39,15 +37,15 @@ 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 java.util.Arrays;
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.gpe.rev170801.gpe.entry.table.grouping.GpeEntryTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170801.gpe.entry.table.grouping.gpe.entry.table.GpeEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170801.gpe.entry.table.grouping.gpe.entry.table.GpeEntryKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.$YangModuleInfoImpl;
import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -66,10 +64,20 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
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 GpeLocator[] ABAB_LOCATORS = {
+ gpeLocator(PAIR_1_LOCAL_ADDRESS, 1, 3),
+ gpeLocator(PAIR_2_LOCAL_ADDRESS, 1, 2),
+ gpeLocator(PAIR_1_REMOTE_ADDRESS, 1, 0),
+ gpeLocator(PAIR_2_REMOTE_ADDRESS, 1, 0)};
+
+ private static final GpeLocator[] BABA_LOCATORS = {
+ ABAB_LOCATORS[1], ABAB_LOCATORS[0], ABAB_LOCATORS[3], ABAB_LOCATORS[2]};
+
private static final int LOCAL_EID_PREFIX = 24;
private static final int REMOTE_EID_PREFIX = 16;
- public static final String GPE_ENTRY_CTX = "gpe-entry-ctx";
- public static final int GPE_FWD_ENTRY_INDEX = 4;
+ private static final String GPE_ENTRY_CTX = "gpe-entry-ctx";
+ private static final int GPE_FWD_ENTRY_INDEX = 4;
private NamingContext gpeEntryMappingContext;
@@ -77,9 +85,6 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
private ArgumentCaptor<GpeAddDelFwdEntry> requestCaptor;
@Mock
- private GpeLocatorPairMappingContext gpeLocatorPairMappingContext;
-
- @Mock
private GpeStateCheckService gpeStateCheckService;
private InstanceIdentifier<GpeEntry> id;
@@ -90,8 +95,7 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
gpeEntryMappingContext = new NamingContext("gpe-entry-", GPE_ENTRY_CTX);
id = InstanceIdentifier.create(GpeEntryTable.class)
.child(GpeEntry.class, new GpeEntryKey(GPE_ENTRY_ID));
- customizer = new GpeForwardEntryCustomizer(api, gpeStateCheckService, gpeEntryMappingContext,
- gpeLocatorPairMappingContext);
+ customizer = new GpeForwardEntryCustomizer(api, gpeStateCheckService, gpeEntryMappingContext);
}
@SchemaContextProvider
@@ -99,7 +103,7 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
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
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170801.$YangModuleInfoImpl
.getInstance()));
}
@@ -110,18 +114,9 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
final GpeEntry entry = entryTable.getGpeEntry().get(0);
customizer.writeCurrentAttributes(id, entry, writeContext);
verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
- assertEquals(expectedFullRequest(true), requestCaptor.getValue());
+ assertFullRequest(true, requestCaptor.getValue());
verify(mappingContext, times(1))
.put(mappingIid(entry.getId(), GPE_ENTRY_CTX), mapping(entry.getId(), GPE_FWD_ENTRY_INDEX).get());
-
- 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);
}
private static GpeAddDelFwdEntryReply entryReply() {
@@ -138,10 +133,9 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
final GpeEntry entry = entryTable.getGpeEntry().get(0);
customizer.writeCurrentAttributes(id, entry, writeContext);
verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
- assertEquals(expectedLocatorLessRequest(true), requestCaptor.getValue());
+ assertLocatorLessRequest(true, requestCaptor.getValue());
verify(mappingContext, times(1))
.put(mappingIid(entry.getId(), GPE_ENTRY_CTX), mapping(entry.getId(), GPE_FWD_ENTRY_INDEX).get());
- verifyZeroInteractions(gpeLocatorPairMappingContext);
}
@Test
@@ -152,15 +146,14 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
final GpeEntry entry = entryTable.getGpeEntry().get(0);
customizer.writeCurrentAttributes(id, entry, writeContext);
verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
- assertEquals(expectedActionLessRequest(true), requestCaptor.getValue());
+ assertActionLessRequest(true, requestCaptor.getValue());
verify(mappingContext, times(1))
.put(mappingIid(entry.getId(), GPE_ENTRY_CTX), mapping(entry.getId(), GPE_FWD_ENTRY_INDEX).get());
- verifyZeroInteractions(gpeLocatorPairMappingContext);
}
/**
* Gpe entry allows no local eid
- * */
+ */
@Test
public void testWriteCurrentAttributesNoLocalEid(
@InjectTestData(resourcePath = "/gpe/invalid/invalid-gpe-fwd-entry-no-local-eid.json",
@@ -169,18 +162,9 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
final GpeEntry entry = entryTable.getGpeEntry().get(0);
customizer.writeCurrentAttributes(id, entry, writeContext);
verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
- assertEquals(expectedActionLessNoLeidRequest(true), requestCaptor.getValue());
+ assertActionLessNoLeidRequest(true, requestCaptor.getValue());
verify(mappingContext, times(1))
.put(mappingIid(entry.getId(), GPE_ENTRY_CTX), mapping(entry.getId(), GPE_FWD_ENTRY_INDEX).get());
-
- 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
@@ -203,10 +187,8 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
final GpeEntry entry = entryTable.getGpeEntry().get(0);
customizer.deleteCurrentAttributes(id, entry, writeContext);
verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
- assertEquals(expectedFullRequest(false), requestCaptor.getValue());
+ assertFullRequest(false, requestCaptor.getValue());
verify(mappingContext, times(1)).delete(mappingIid(entry.getId(), GPE_ENTRY_CTX));
- verify(gpeLocatorPairMappingContext, times(1))
- .removeMapping(entry.getId(), mappingContext);
}
@Test
@@ -217,10 +199,8 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
final GpeEntry entry = entryTable.getGpeEntry().get(0);
customizer.deleteCurrentAttributes(id, entry, writeContext);
verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
- assertEquals(expectedLocatorLessRequest(false), requestCaptor.getValue());
+ assertLocatorLessRequest(false, requestCaptor.getValue());
verify(mappingContext, times(1)).delete(mappingIid(entry.getId(), GPE_ENTRY_CTX));
- verify(gpeLocatorPairMappingContext, times(1))
- .removeMapping(entry.getId(), mappingContext);
}
@Test
@@ -231,10 +211,8 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
final GpeEntry entry = entryTable.getGpeEntry().get(0);
customizer.deleteCurrentAttributes(id, entry, writeContext);
verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
- assertEquals(expectedActionLessRequest(false), requestCaptor.getValue());
+ assertActionLessRequest(false, requestCaptor.getValue());
verify(mappingContext, times(1)).delete(mappingIid(entry.getId(), GPE_ENTRY_CTX));
- verify(gpeLocatorPairMappingContext, times(1))
- .removeMapping(entry.getId(), mappingContext);
}
@Test
@@ -245,10 +223,8 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
final GpeEntry entry = entryTable.getGpeEntry().get(0);
customizer.deleteCurrentAttributes(id, entry, writeContext);
verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture());
- assertEquals(expectedActionLessNoLeidRequest(false), requestCaptor.getValue());
+ assertActionLessNoLeidRequest(false, requestCaptor.getValue());
verify(mappingContext, times(1)).delete(mappingIid(entry.getId(), GPE_ENTRY_CTX));
- verify(gpeLocatorPairMappingContext, times(1))
- .removeMapping(entry.getId(), mappingContext);
}
@Test
@@ -264,83 +240,58 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest
fail("Test should have failed");
}
- private GpeAddDelFwdEntry expectedActionLessNoLeidRequest(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.rmtEid = REMOTE_EID_ADDRESS;
- request.rmtLen = REMOTE_EID_PREFIX;
- request.locNum = 4;
- request.locs = new GpeLocator[]{
- gpeLocator(PAIR_1_LOCAL_ADDRESS, 1, 3),
- gpeLocator(PAIR_2_LOCAL_ADDRESS, 1, 2),
- gpeLocator(PAIR_1_REMOTE_ADDRESS, 1, 0),
- gpeLocator(PAIR_2_REMOTE_ADDRESS, 1, 0)
- };
- return request;
+ private void assertActionLessNoLeidRequest(final boolean add, final GpeAddDelFwdEntry actual) {
+
+ assertEquals(booleanToByte(add), actual.isAdd);
+ assertEquals(10, actual.dpTable);
+ assertEquals(12, actual.vni);
+ assertEquals(0, actual.eidType);
+ assertEquals(4, actual.locNum);
+ assertTrue(Arrays.equals(REMOTE_EID_ADDRESS, actual.rmtEid));
+ assertEquals(REMOTE_EID_PREFIX, actual.rmtLen);
+ assertTrue(Arrays.equals(ABAB_LOCATORS, actual.locs) || Arrays.equals(BABA_LOCATORS, actual.locs));
}
- 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 void assertActionLessRequest(final boolean add, final GpeAddDelFwdEntry actual) {
+
+ assertEquals(booleanToByte(add), actual.isAdd);
+ assertEquals(10, actual.dpTable);
+ assertEquals(12, actual.vni);
+ assertEquals(0, actual.eidType);
+ assertEquals(0, actual.action);
+ assertEquals(0, actual.locNum);
}
- 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 void assertLocatorLessRequest(final boolean add, final GpeAddDelFwdEntry actual) {
+
+ assertEquals(booleanToByte(add), actual.isAdd);
+ assertEquals(10, actual.dpTable);
+ assertEquals(12, actual.vni);
+ assertEquals(0, actual.eidType);
+ assertEquals(1, actual.action);
+ assertEquals(0, actual.locNum);
+ assertTrue(Arrays.equals(LOCAL_EID_ADDRESS, actual.lclEid));
+ assertEquals(LOCAL_EID_PREFIX, actual.lclLen);
+ assertTrue(Arrays.equals(REMOTE_EID_ADDRESS, actual.rmtEid));
+ assertEquals(REMOTE_EID_PREFIX, actual.rmtLen);
}
- 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_1_LOCAL_ADDRESS, 1, 3),
- gpeLocator(PAIR_2_LOCAL_ADDRESS, 1, 2),
- gpeLocator(PAIR_1_REMOTE_ADDRESS, 1, 0),
- gpeLocator(PAIR_2_REMOTE_ADDRESS, 1, 0)
- };
-
- return request;
+ private void assertFullRequest(final boolean add, final GpeAddDelFwdEntry actual) {
+
+ assertEquals(booleanToByte(add), actual.isAdd);
+ assertEquals(10, actual.dpTable);
+ assertEquals(12, actual.vni);
+ assertEquals(0, actual.eidType);
+ assertEquals(4, actual.locNum);
+ assertTrue(Arrays.equals(LOCAL_EID_ADDRESS, actual.lclEid));
+ assertEquals(LOCAL_EID_PREFIX, actual.lclLen);
+ assertTrue(Arrays.equals(REMOTE_EID_ADDRESS, actual.rmtEid));
+ assertEquals(REMOTE_EID_PREFIX, actual.rmtLen);
+ assertTrue(Arrays.equals(ABAB_LOCATORS, actual.locs) || Arrays.equals(BABA_LOCATORS, actual.locs));
}
- private GpeLocator gpeLocator(final byte[] address, final int isIpv4, final int weight) {
+ private static GpeLocator gpeLocator(final byte[] address, final int isIpv4, final int weight) {
GpeLocator locator = new GpeLocator();
locator.isIp4 = (byte) isIpv4;
locator.weight = (byte) weight;