diff options
Diffstat (limited to 'v3po/v3po2vpp/src')
4 files changed, 75 insertions, 71 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java index a71c0061e..43d82ec5e 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java @@ -19,19 +19,19 @@ package io.fd.hc2vpp.v3po.interfacesstate.ip; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Optional; -import com.google.common.collect.ImmutableSet; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.AddressDumpParams; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.AddressDumpParams; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; import io.fd.vpp.jvpp.core.dto.IpAddressDetails; import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; import io.fd.vpp.jvpp.core.future.FutureJVppCore; @@ -72,10 +72,35 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, AddressDumpParams>() .withExecutor(createExecutor(futureJVppCore)) // Key needs to contain interface ID to distinguish dumps between interfaces - .withCacheKeyFactory(new IdentifierCacheKeyFactory(ImmutableSet.of(Interface.class))) + .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, + ImmutableSet.of(Interface.class))) .build(); } + private static Subnet getSubnet(final Address address) { + final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.Subnet + subnet = address.getSubnet(); + + // Only prefix length supported + Preconditions.checkArgument( + subnet instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength); + + return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder() + .setPrefixLength( + ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength) subnet) + .getPrefixLength()).build(); + } + + static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address> getCfgId( + final InstanceIdentifier<Address> id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(Interface1.class) + .child(Ipv4.class) + .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address.class, + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressKey( + id.firstKeyOf(Address.class).getIp())); + } + @Override @Nonnull public AddressBuilder getBuilder(@Nonnull InstanceIdentifier<Address> id) { @@ -140,27 +165,4 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer .setSubnet(getSubnet(readValue)) .build()); } - - private static Subnet getSubnet(final Address address) { - final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.Subnet - subnet = address.getSubnet(); - - // Only prefix length supported - Preconditions.checkArgument( - subnet instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength); - - return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder() - .setPrefixLength( - ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength) subnet) - .getPrefixLength()).build(); - } - - static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address> getCfgId( - final InstanceIdentifier<Address> id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(Interface1.class) - .child(Ipv4.class) - .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address.class, - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressKey(id.firstKeyOf(Address.class).getIp())); - } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java index 3288e0c35..cb239dc9f 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java @@ -20,18 +20,18 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.AddressDumpParams; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; import io.fd.vpp.jvpp.core.dto.IpAddressDetails; import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; import io.fd.vpp.jvpp.core.future.FutureJVppCore; @@ -69,10 +69,16 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, AddressDumpParams>() .withExecutor(createExecutor(futureJVppCore)) //same as with ipv4 addresses for interfaces, these must have cache scope of their parent sub-interface - .withCacheKeyFactory(new IdentifierCacheKeyFactory(ImmutableSet.of(SubInterface.class))) + .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, + ImmutableSet.of(SubInterface.class))) .build(); } + private static String getSubInterfaceName(@Nonnull final InstanceIdentifier<Address> id) { + return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), + Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier())); + } + @Override @Nonnull public AddressBuilder getBuilder(@Nonnull InstanceIdentifier<Address> id) { @@ -123,11 +129,6 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer ((Ipv4Builder) builder).setAddress(readData); } - private static String getSubInterfaceName(@Nonnull final InstanceIdentifier<Address> id) { - return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), - Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier())); - } - @Override public Initialized<Address> init( @Nonnull final InstanceIdentifier<Address> id, @Nonnull final Address readValue, diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java index bac21c88f..0ab64b21e 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java @@ -27,13 +27,13 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory; -import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; import io.fd.vpp.jvpp.core.dto.IpAddressDetails; import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; import io.fd.vpp.jvpp.core.dto.IpAddressDump; @@ -76,6 +76,15 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, super(Address.class, Ipv4Builder.class); } + private static InstanceIdentifier<Address> getId(final String address, final String ifaceName) { + return InstanceIdentifier.builder(InterfacesState.class) + .child(Interface.class, new InterfaceKey(ifaceName)) + .augmentation(Interface2.class) + .child(Ipv4.class) + .child(Address.class, new AddressKey(new Ipv4AddressNoZone(new Ipv4Address(address)))) + .build(); + } + @Override public void setUp() { interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); @@ -96,7 +105,8 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))); // to simulate complex key - cacheKeyFactory = new IdentifierCacheKeyFactory(ImmutableSet.of(Interface.class)); + cacheKeyFactory = new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, + ImmutableSet.of(Interface.class)); } @Override @@ -104,15 +114,6 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, return new Ipv4AddressCustomizer(api, interfacesContext); } - private static InstanceIdentifier<Address> getId(final String address, final String ifaceName) { - return InstanceIdentifier.builder(InterfacesState.class) - .child(Interface.class, new InterfaceKey(ifaceName)) - .augmentation(Interface2.class) - .child(Ipv4.class) - .child(Address.class, new AddressKey(new Ipv4AddressNoZone(new Ipv4Address(address)))) - .build(); - } - @Test public void testReadCurrentAttributesFor2Ifcs() throws ReadFailedException { //changed to mock to not store first dumped data(otherwise that double thenReturn on line 118 is not gonna work) diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java index 4842f5de4..8c67735aa 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java @@ -29,13 +29,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory; -import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; import io.fd.vpp.jvpp.core.dto.IpAddressDetails; import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; import java.util.Arrays; @@ -76,19 +76,26 @@ public class SubInterfaceIpv4AddressCustomizerTest extends ListReaderCustomizerT .augmentation(SubinterfaceStateAugmentation.class) .child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)) .child(Ipv4.class); - private InstanceIdentifier<Address> ifaceOneAddressOneIdentifier; - private InstanceIdentifier<Address> ifaceTwoAddressOneIdentifier; - private CacheKeyFactory cacheKeyFactory; private static final Ipv4AddressNoZone IP1 = new Ipv4AddressNoZone("10.1.1.1"); private static final Ipv4AddressNoZone IP2 = new Ipv4AddressNoZone("10.1.1.2"); private static final short PREFIX_LENGTH = 16; - + private InstanceIdentifier<Address> ifaceOneAddressOneIdentifier; + private InstanceIdentifier<Address> ifaceTwoAddressOneIdentifier; + private CacheKeyFactory cacheKeyFactory; private NamingContext interfaceContext; public SubInterfaceIpv4AddressCustomizerTest() { super(Address.class, Ipv4Builder.class); } + private static InstanceIdentifier<Address> getId() { + return IP4_IID.child(Address.class); + } + + private static InstanceIdentifier<Address> getId(final Ipv4AddressNoZone ip) { + return IP4_IID.child(Address.class, new AddressKey(ip)); + } + @Override protected void setUp() throws Exception { interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); @@ -109,7 +116,8 @@ public class SubInterfaceIpv4AddressCustomizerTest extends ListReaderCustomizerT .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))); // to simulate complex key - cacheKeyFactory = new IdentifierCacheKeyFactory(ImmutableSet.of(SubInterface.class)); + cacheKeyFactory = new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, + ImmutableSet.of(SubInterface.class)); defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME); @@ -121,14 +129,6 @@ public class SubInterfaceIpv4AddressCustomizerTest extends ListReaderCustomizerT return new SubInterfaceIpv4AddressCustomizer(api, interfaceContext); } - private static InstanceIdentifier<Address> getId() { - return IP4_IID.child(Address.class); - } - - private static InstanceIdentifier<Address> getId(final Ipv4AddressNoZone ip) { - return IP4_IID.child(Address.class, new AddressKey(ip)); - } - @Test public void testRead() throws ReadFailedException { final AddressBuilder builder = mock(AddressBuilder.class); |