diff options
author | 2017-06-06 12:51:42 +0200 | |
---|---|---|
committer | 2017-06-06 12:52:41 +0200 | |
commit | ca6cda948df343f56164ce38e258735ead68dc6e (patch) | |
tree | 2fec067c86aaab49f69da09d1506261c801ea802 /lisp/lisp2vpp/src/test/java/io/fd | |
parent | c9052815f89fff314d8f6b67fcd62b707d827611 (diff) |
HC2VPP-165 - Optional Local Eid support
- Support for optional local eid's for gpe entries
- Fixes equality issues for mapping identificators
- Fixed write request ordering of locator pairs
HC2VPP-160 - Use standard index to name mapping for gpe entries
- Uses indexes returned from dump/write calls to bind context mapping
Change-Id: Ib69240044206dec21307a47981a63f415a16bbdd
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/test/java/io/fd')
3 files changed, 216 insertions, 83 deletions
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/GpeModuleTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/GpeModuleTest.java new file mode 100644 index 000000000..794ec29c6 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/GpeModuleTest.java @@ -0,0 +1,79 @@ +/* + * 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; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.testing.fieldbinder.Bind; +import com.google.inject.testing.fieldbinder.BoundFieldModule; +import io.fd.hc2vpp.lisp.gpe.GpeModule; +import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; +import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.HashSet; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; + +public class GpeModuleTest { + + @Bind + @Mock + private FutureJVppCore futureJVppCore; + + @Inject + private Set<ReaderFactory> readerFactories = new HashSet<>(); + + @Inject + private Set<WriterFactory> writerFactories = new HashSet<>(); + + @Before + public void setUp() throws Exception { + initMocks(this); + Guice.createInjector(new GpeModule(), BoundFieldModule.of(this)).injectMembers(this); + } + + @Test + public void testReaderFactories() throws Exception { + assertThat(readerFactories, is(not(empty()))); + + // Test registration process (all dependencies present, topological order of readers does exist, etc.) + final CompositeReaderRegistryBuilder registryBuilder = new CompositeReaderRegistryBuilder(); + readerFactories.stream().forEach(factory -> factory.init(registryBuilder)); + assertNotNull(registryBuilder.build()); + } + + @Test + public void testWriterFactories() throws Exception { + assertThat(writerFactories, is(not(empty()))); + + // Test registration process (all dependencies present, topological order of writers does exist, etc.) + final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder(); + writerFactories.stream().forEach(factory -> factory.init(registryBuilder)); + assertNotNull(registryBuilder.build()); + } +} 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 index 9e1958224..475fe2d3e 100644 --- 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 @@ -18,14 +18,14 @@ package io.fd.hc2vpp.lisp.gpe.translate.read; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; 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.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; @@ -83,6 +83,7 @@ public class GpeForwardEntryCustomizerTest implements AddressTranslator, EidTranslator { private static final String V4_ENTRY_ID = "v4-entry"; + private static final String V4_ENTRY_NO_LEID_ID = "v4-entry-no-leid-id"; 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; @@ -90,6 +91,9 @@ public class GpeForwardEntryCustomizerTest private static final KeyedInstanceIdentifier<GpeEntry, GpeEntryKey> V4_IDENTIFIER = InstanceIdentifier.create(GpeEntryTable.class) .child(GpeEntry.class, new GpeEntryKey(V4_ENTRY_ID)); + private static final KeyedInstanceIdentifier<GpeEntry, GpeEntryKey> V4_NO_LEID_IDENTIFIER = + InstanceIdentifier.create(GpeEntryTable.class) + .child(GpeEntry.class, new GpeEntryKey(V4_ENTRY_NO_LEID_ID)); private static final Ipv4Prefix V4_ENTRY_LOCAL_ADDRESS = new Ipv4Prefix("192.168.2.0/24"); private static final Ipv4Prefix @@ -132,13 +136,14 @@ public class GpeForwardEntryCustomizerTest 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; + private static final int V6_LOCATOR_LOCAL_WEIGHT = 3; + private static final int MAC_LOCATOR_LOCAL_WEIGHT = 7; + private static final int V4_LOCATOR_LOCAL_WEIGHT = 2; + private static final int V4_ENTRY_NO_LEID_FWD_INDEX = 12; + private static final String GPE_ENTRY_CTX = "gpe-entry-ctx"; - @Mock - private GpeEntryMappingContext gpeEntryMappingContext; + private NamingContext gpeEntryMappingContext; @Mock private GpeLocatorPairMappingContext gpeLocatorPairMappingContext; @@ -158,6 +163,7 @@ public class GpeForwardEntryCustomizerTest @Override protected void setUp() throws Exception { + gpeEntryMappingContext = new NamingContext("gpe-entry-", GPE_ENTRY_CTX); when(gpeStateCheckService.isGpeEnabled(ctx)).thenReturn(true); when(api.gpeFwdEntriesGet(entryRequest(V4_ENTRY_VNI))) .thenReturn(future(getGpeEntryDumpReply(getV4GpeEntry()))); @@ -166,7 +172,7 @@ public class GpeForwardEntryCustomizerTest when(api.gpeFwdEntriesGet(entryRequest(MAC_ENTRY_VNI))) .thenReturn(future(getGpeEntryDumpReply(getMacGpeEntry()))); when(api.gpeFwdEntryVnisGet(any())).thenReturn(future(activeVnisDump())); - mockMappingsForGpeEntries(); + defineMappingsForGpeEntries(); mockMappingsForLocators(); } @@ -210,6 +216,34 @@ public class GpeForwardEntryCustomizerTest } @Test + public void testReadCurrentV4EntryNoLeid() throws ReadFailedException { + when(api.gpeFwdEntriesGet(entryRequest(V4_ENTRY_VNI))) + .thenReturn(future(getGpeEntryDumpReply(getV4GpeNoLeidEntry()))); + mockLocatorDump(); + final GpeEntryBuilder builder = new GpeEntryBuilder(); + getCustomizer().readCurrentAttributes(V4_NO_LEID_IDENTIFIER, builder, ctx); + + assertEquals(V4_ENTRY_NO_LEID_ID, builder.getId()); + assertEquals(10, builder.getDpTable().intValue()); + assertNull(builder.getLocalEid()); + 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(); @@ -313,6 +347,7 @@ public class GpeForwardEntryCustomizerTest private void mockLocatorDump() { when(api.gpeFwdEntryPathDump(pathRequest(V4_ENTRY_FWD_INDEX))).thenReturn(future(locatorDumpForV4EntryReply())); + when(api.gpeFwdEntryPathDump(pathRequest(V4_ENTRY_NO_LEID_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())); @@ -324,25 +359,11 @@ public class GpeForwardEntryCustomizerTest 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 defineMappingsForGpeEntries() { + defineMapping(mappingContext, V4_ENTRY_ID, V4_ENTRY_FWD_INDEX, GPE_ENTRY_CTX); + defineMapping(mappingContext, V4_ENTRY_NO_LEID_ID, V4_ENTRY_NO_LEID_FWD_INDEX, GPE_ENTRY_CTX); + defineMapping(mappingContext, V6_ENTRY_ID, V6_ENTRY_FWD_INDEX, GPE_ENTRY_CTX); + defineMapping(mappingContext, MAC_ENTRY_ID, MAC_ENTRY_FWD_INDEX, GPE_ENTRY_CTX); } private void mockMappingsForLocators() { @@ -357,6 +378,8 @@ public class GpeForwardEntryCustomizerTest final GpeLocatorPair v4LocatorPairOne = GpeLocatorPair.fromDumpDetail(v4LocatorOne); when(gpeLocatorPairMappingContext.getMapping(V4_ENTRY_ID, v4LocatorPairOne, mappingContext)) .thenReturn(fromDump(V4_ENTRY_LOCATOR, v4LocatorOne)); + when(gpeLocatorPairMappingContext.getMapping(V4_ENTRY_NO_LEID_ID, v4LocatorPairOne, mappingContext)) + .thenReturn(fromDump(V4_ENTRY_LOCATOR, v4LocatorOne)); } private void mockV6LocatorMapping() { @@ -387,25 +410,6 @@ public class GpeForwardEntryCustomizerTest .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}; @@ -517,4 +521,16 @@ public class GpeForwardEntryCustomizerTest entryOne.reidPrefixLen = 24; return entryOne; } + + private GpeFwdEntry getV4GpeNoLeidEntry() { + 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_NO_LEID_FWD_INDEX; + 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/GpeForwardEntryCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/gpe/translate/write/GpeForwardEntryCustomizerTest.java index 74c9bdeba..476c8a070 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 @@ -17,6 +17,7 @@ package io.fd.hc2vpp.lisp.gpe.translate.write; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; @@ -27,8 +28,7 @@ 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.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; @@ -68,14 +68,15 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest 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; + public static final String GPE_ENTRY_CTX = "gpe-entry-ctx"; + public static final int GPE_FWD_ENTRY_INDEX = 4; + + private NamingContext gpeEntryMappingContext; @Captor private ArgumentCaptor<GpeAddDelFwdEntry> requestCaptor; @Mock - private GpeEntryMappingContext gpeEntryMappingContext; - - @Mock private GpeLocatorPairMappingContext gpeLocatorPairMappingContext; @Mock @@ -86,6 +87,7 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest @Override protected void setUpTest() throws Exception { + 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, @@ -104,13 +106,13 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest @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())); + when(api.gpeAddDelFwdEntry(any())).thenReturn(future(entryReply())); 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); + 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); @@ -122,17 +124,23 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest GpeLocatorPair.fromLocatorPair(locatorPairSecond), mappingContext); } + private static GpeAddDelFwdEntryReply entryReply() { + final GpeAddDelFwdEntryReply reply = new GpeAddDelFwdEntryReply(); + reply.fwdEntryIndex = GPE_FWD_ENTRY_INDEX; + return reply; + } + @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())); + when(api.gpeAddDelFwdEntry(any())).thenReturn(future(entryReply())); 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); + verify(mappingContext, times(1)) + .put(mappingIid(entry.getId(), GPE_ENTRY_CTX), mapping(entry.getId(), GPE_FWD_ENTRY_INDEX).get()); verifyZeroInteractions(gpeLocatorPairMappingContext); } @@ -140,27 +148,39 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest 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())); + when(api.gpeAddDelFwdEntry(any())).thenReturn(future(entryReply())); 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); + 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 testWriteCurrentAttributesFailNoLocalEid( + public void testWriteCurrentAttributesNoLocalEid( @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"); + when(api.gpeAddDelFwdEntry(any())).thenReturn(future(entryReply())); + final GpeEntry entry = entryTable.getGpeEntry().get(0); + customizer.writeCurrentAttributes(id, entry, writeContext); + verify(api, times(1)).gpeAddDelFwdEntry(requestCaptor.capture()); + assertEquals(expectedActionLessNoLeidRequest(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 @@ -184,8 +204,7 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest 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(mappingContext, times(1)).delete(mappingIid(entry.getId(), GPE_ENTRY_CTX)); verify(gpeLocatorPairMappingContext, times(1)) .removeMapping(entry.getId(), mappingContext); } @@ -199,8 +218,7 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest 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(mappingContext, times(1)).delete(mappingIid(entry.getId(), GPE_ENTRY_CTX)); verify(gpeLocatorPairMappingContext, times(1)) .removeMapping(entry.getId(), mappingContext); } @@ -214,23 +232,23 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest 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(mappingContext, times(1)).delete(mappingIid(entry.getId(), GPE_ENTRY_CTX)); verify(gpeLocatorPairMappingContext, times(1)) .removeMapping(entry.getId(), mappingContext); } @Test - public void testDeleteCurrentAttributesFailNoLocalEid( + public void testDeleteCurrentAttributesNoLocalEid( @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"); + 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(expectedActionLessNoLeidRequest(false), requestCaptor.getValue()); + verify(mappingContext, times(1)).delete(mappingIid(entry.getId(), GPE_ENTRY_CTX)); + verify(gpeLocatorPairMappingContext, times(1)) + .removeMapping(entry.getId(), mappingContext); } @Test @@ -246,6 +264,26 @@ 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 GpeAddDelFwdEntry expectedActionLessRequest(final boolean add) { final GpeAddDelFwdEntry request = new GpeAddDelFwdEntry(); @@ -293,8 +331,8 @@ public class GpeForwardEntryCustomizerTest extends WriterCustomizerTest 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_2_LOCAL_ADDRESS, 1, 2), gpeLocator(PAIR_1_REMOTE_ADDRESS, 1, 0), gpeLocator(PAIR_2_REMOTE_ADDRESS, 1, 0) }; |