From c54ae4ac74d6b8ab71c7e166f10ca6b080ffa558 Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Thu, 13 Oct 2016 16:58:22 +0200 Subject: Caching for Ipv4 addresses fixed also for readCurrentAttributes Caching scope fixed also in specific request logic Added test Change-Id: Ib70a3069cf7620132ae5921ddb21b56fa2f4108b Signed-off-by: Jan Srnicek --- .../interfacesstate/ip/Ipv4AddressCustomizer.java | 4 +- .../ip/Ipv4AddressCustomizerTest.java | 99 +++++++++++++++++++--- 2 files changed, 92 insertions(+), 11 deletions(-) (limited to 'v3po') diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java index 0cd9032b6..8b1fb86e9 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java @@ -78,8 +78,10 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer final String interfaceName = id.firstKeyOf(Interface.class).getName(); final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext()); + // Key needs to contain interface ID to distinguish dumps between interfaces + final String cacheKey = CACHE_KEY + interfaceName; final Optional dumpOptional = dumpManager - .getDump(id, CACHE_KEY, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false)); + .getDump(id, cacheKey, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false)); if (!dumpOptional.isPresent() || dumpOptional.get().ipAddressDetails.isEmpty()) { return; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java index 1a137f3e3..42fae44a3 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java @@ -17,19 +17,24 @@ package io.fd.honeycomb.translate.v3po.interfacesstate.ip; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; -import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.vpp.util.Ipv4Translator; import io.fd.honeycomb.translate.vpp.util.NamingContext; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; +import io.fd.vpp.jvpp.core.dto.IpAddressDetails; +import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.IpAddressDump; +import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -47,10 +52,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev14061 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.IpAddressDetails; -import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.IpAddressDump; public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest implements Ipv4Translator { @@ -62,6 +65,8 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest ifaceOneAddressOneIdentifier; + private InstanceIdentifier
ifaceTwoAddressOneIdentifier; public Ipv4AddressCustomizerTest() { super(Address.class, Ipv4Builder.class); @@ -72,6 +77,19 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest keysForIfaceOne = getCustomizer().getAllIds(ifaceOneAddressOneIdentifier, ctx); + assertThat(keysForIfaceOne, hasSize(1)); + final AddressKey keyIfaceOne = keysForIfaceOne.get(0); + assertEquals("192.168.2.1", keyIfaceOne.getIp().getValue()); + + final List keysForIfaceTwo = getCustomizer().getAllIds(ifaceTwoAddressOneIdentifier, ctx); + assertThat(keysForIfaceTwo, is(empty())); + } + + private void fillCacheForTwoIfaces() { + IpAddressDetails detailIfaceOneAddressOne = new IpAddressDetails(); + IpAddressDetails detailIfaceTwoAddressOne = new IpAddressDetails(); + IpAddressDetailsReplyDump replyIfaceOne = new IpAddressDetailsReplyDump(); + IpAddressDetailsReplyDump replyIfaceTwo = new IpAddressDetailsReplyDump(); + + replyIfaceOne.ipAddressDetails = Arrays.asList(detailIfaceOneAddressOne); + replyIfaceTwo.ipAddressDetails = Arrays.asList(detailIfaceTwoAddressOne); + + detailIfaceOneAddressOne.ip = reverseBytes( + ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")))); + detailIfaceOneAddressOne.prefixLength = 22; + + detailIfaceTwoAddressOne.ip = reverseBytes( + ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")))); + detailIfaceTwoAddressOne.prefixLength = 23; + + cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_NAME, replyIfaceOne); + cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_2_NAME, replyIfaceTwo); + } + + private void fillCacheForFirstIfaceSecondEmpty() { + IpAddressDetails detailIfaceOneAddressOne = new IpAddressDetails(); + IpAddressDetailsReplyDump replyIfaceOne = new IpAddressDetailsReplyDump(); + replyIfaceOne.ipAddressDetails = Arrays.asList(detailIfaceOneAddressOne); + + detailIfaceOneAddressOne.ip = reverseBytes( + ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")))); + detailIfaceOneAddressOne.prefixLength = 22; + + cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_NAME, replyIfaceOne); + cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_2_NAME, new IpAddressDetailsReplyDump()); + } } -- cgit 1.2.3-korg