From 8e0c7007906730fe4547b0265a895ad8a322a7dc Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Thu, 10 Nov 2016 12:22:28 +0100 Subject: Remove hc2vpp codebase Moved to a dedicated hc2vpp project in fd.io Change-Id: I03dc3b3029f21b127a00c69a86bcd8e467896241 Signed-off-by: Maros Marsalek --- .../ip/Ipv4AddressCustomizerTest.java | 284 --------------------- .../interfacesstate/ip/Ipv4CustomizerTest.java | 44 ---- .../ip/SubInterfaceIpv4AddressCustomizerTest.java | 247 ------------------ 3 files changed, 575 deletions(-) delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4CustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java (limited to 'v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip') 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 deleted file mode 100644 index efe6c6afe..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (c) 2016 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.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.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -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.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; -import org.hamcrest.Matchers; -import org.junit.Test; -import org.mockito.Mockito; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -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.interfaces.rev140508.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; -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; - -public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest implements - Ipv4Translator { - - private static final String IFACE_NAME = "eth0"; - private static final String IFACE_2_NAME = "eth1"; - private static final int IFACE_ID = 1; - private static final int IFACE_2_ID = 2; - private static final String IFC_CTX_NAME = "ifc-test-instance"; - - private NamingContext interfacesContext; - private InstanceIdentifier
ifaceOneAddressOneIdentifier; - private InstanceIdentifier
ifaceTwoAddressOneIdentifier; - private CacheKeyFactory cacheKeyFactory; - - public Ipv4AddressCustomizerTest() { - super(Address.class, Ipv4Builder.class); - } - - @Override - public void setUp() { - interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - defineMapping(mappingContext, IFACE_2_NAME, IFACE_2_ID, IFC_CTX_NAME); - - ifaceOneAddressOneIdentifier = - InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(Interface2.class) - .child(Ipv4.class) - .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))); - ifaceTwoAddressOneIdentifier = - InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_2_NAME)) - .augmentation(Interface2.class) - .child(Ipv4.class) - .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))); - - // to simulate complex key - cacheKeyFactory = new IdentifierCacheKeyFactory(ImmutableSet.of(Interface.class)); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new Ipv4AddressCustomizer(api, interfacesContext); - } - - private static InstanceIdentifier
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) - - IpAddressDetails detail1 = new IpAddressDetails(); - IpAddressDetails detail2 = new IpAddressDetails(); - - detail1.ip = reverseBytes( - ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")))); - detail2.ip = reverseBytes( - ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2")))); - - IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump(); - reply.ipAddressDetails = ImmutableList.of(detail1); - IpAddressDetailsReplyDump reply2 = new IpAddressDetailsReplyDump(); - reply2.ipAddressDetails = ImmutableList.of(detail2); - - CompletableFuture future = new CompletableFuture<>(); - future.complete(reply); - CompletableFuture future2 = new CompletableFuture<>(); - future2.complete(reply2); - - when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future).thenReturn(future2) - .thenReturn(future).thenReturn(future2); - when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future(reply)).thenReturn(future(reply2)) - .thenReturn(future(reply)).thenReturn(future(reply2)); - when(ctx.getModificationCache()).thenReturn(cache); - - - final InstanceIdentifier
id = getId("192.168.2.1", IFACE_NAME); - final InstanceIdentifier
id2 = getId("192.168.2.2", IFACE_2_NAME); - - final List ifc1Ids = getCustomizer().getAllIds(id, ctx); - assertThat(ifc1Ids.size(), is(1)); - assertThat(ifc1Ids, Matchers.hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.1")))); - final List ifc2Ids = getCustomizer().getAllIds(id2, ctx); - assertThat(ifc2Ids.size(), is(1)); - assertThat(ifc2Ids, Matchers.hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.2")))); - - AddressBuilder builder = new AddressBuilder(); - getCustomizer().readCurrentAttributes(id, builder, ctx); - assertEquals(builder.getIp().getValue(), "192.168.2.1"); - builder = new AddressBuilder(); - getCustomizer().readCurrentAttributes(id2, builder, ctx); - assertEquals(builder.getIp().getValue(), "192.168.2.2"); - } - - @Test - public void testReadCurrentAttributesSuccessfull() throws ReadFailedException { - IpAddressDetails detail1 = new IpAddressDetails(); - IpAddressDetails detail2 = new IpAddressDetails(); - IpAddressDetails detail3 = new IpAddressDetails(); - - detail1.ip = reverseBytes( - ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")))); - detail2.ip = reverseBytes( - ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2")))); - detail3.ip = reverseBytes( - ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3")))); - - IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump(); - reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3); - when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future(reply)); - when(ctx.getModificationCache()).thenReturn(cache); - - final AddressBuilder builder = new AddressBuilder(); - final InstanceIdentifier
id = getId("192.168.2.1", IFACE_NAME); - - getCustomizer().readCurrentAttributes(id, builder, ctx); - - assertEquals("192.168.2.1", builder.getIp().getValue()); - } - - @Test - public void testGetAllIdsFromSuccessfull() throws ReadFailedException { - IpAddressDetails detail1 = new IpAddressDetails(); - IpAddressDetails detail2 = new IpAddressDetails(); - IpAddressDetails detail3 = new IpAddressDetails(); - - detail1.ip = reverseBytes( - ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")))); - detail2.ip = reverseBytes( - ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2")))); - detail3.ip = reverseBytes( - ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3")))); - - IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump(); - reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3); - when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future(reply)); - when(ctx.getModificationCache()).thenReturn(cache); - - final InstanceIdentifier
id = getId("192.168.2.1", IFACE_NAME); - - List ids = getCustomizer().getAllIds(id, ctx).stream() - .map(key -> key.getIp()) - .collect(Collectors.toList()); - - assertEquals(3, ids.size()); - assertEquals(true, "192.168.2.1".equals(ids.get(0).getValue())); - assertEquals(true, "192.168.2.2".equals(ids.get(1).getValue())); - assertEquals(true, "192.168.2.3".equals(ids.get(2).getValue())); - } - - @Test - public void testCachingScopeSpecificRequest() throws ReadFailedException { - fillCacheForTwoIfaces(); - final AddressBuilder ifaceOneAddressBuilder = new AddressBuilder(); - final AddressBuilder ifaceTwoAddressBuilder = new AddressBuilder(); - - getCustomizer().readCurrentAttributes(ifaceOneAddressOneIdentifier, ifaceOneAddressBuilder, ctx); - getCustomizer().readCurrentAttributes(ifaceTwoAddressOneIdentifier, ifaceTwoAddressBuilder, ctx); - - // addresses have caching scope of parent interface, so returned address should have respective prefix lengths - assertEquals("192.168.2.1", ifaceOneAddressBuilder.getIp().getValue()); - assertTrue(ifaceOneAddressBuilder.getSubnet() instanceof PrefixLength); - assertEquals(22, PrefixLength.class.cast(ifaceOneAddressBuilder.getSubnet()).getPrefixLength().intValue()); - - assertEquals("192.168.2.1", ifaceTwoAddressBuilder.getIp().getValue()); - assertTrue(ifaceTwoAddressBuilder.getSubnet() instanceof PrefixLength); - assertEquals(23, PrefixLength.class.cast(ifaceTwoAddressBuilder.getSubnet()).getPrefixLength().intValue()); - } - - @Test - public void testCachingScopeGetAll() throws ReadFailedException { - fillCacheForFirstIfaceSecondEmpty(); - - final List 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(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne); - cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), 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(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne); - cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), new IpAddressDetailsReplyDump()); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4CustomizerTest.java deleted file mode 100644 index f536a37eb..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4CustomizerTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2016 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.honeycomb.translate.v3po.interfacesstate.ip; - -import static org.mockito.Mockito.verifyZeroInteractions; - -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; - -public class Ipv4CustomizerTest extends ReaderCustomizerTest { - - public Ipv4CustomizerTest() { - super(Ipv4.class, Interface2Builder.class); - } - - @Test - public void testReadCurrentAttributes() throws Exception { - customizer.readCurrentAttributes(null, null, ctx); - verifyZeroInteractions(api); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new Ipv4Customizer(api); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java deleted file mode 100644 index 9a9346a5a..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (c) 2016 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.honeycomb.translate.v3po.interfacesstate.ip; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -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.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.common.collect.ImmutableSet; -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.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 java.util.Arrays; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -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.interfaces.rev140508.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.AddressKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLength; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLengthBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceIpv4AddressCustomizerTest extends ListReaderCustomizerTest - implements Ipv4Translator { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "local0"; - private static final int IF_INDEX = 1; - private static final String SUB_IF_NAME = "local0.1"; - private static final String SUB_IF_2_NAME = "local0.2"; - private static final long SUB_IF_ID = 1; - private static final int SUB_IF_INDEX = 11; - private static final int SUB_IF_2_INDEX = 12; - private static final InstanceIdentifier IP4_IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)) - .child(Ipv4.class); - private InstanceIdentifier
ifaceOneAddressOneIdentifier; - private InstanceIdentifier
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 NamingContext interfaceContext; - - public SubInterfaceIpv4AddressCustomizerTest() { - super(Address.class, Ipv4Builder.class); - } - - @Override - protected void setUp() throws Exception { - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - - ifaceOneAddressOneIdentifier = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(1L)) - .child(Ipv4.class) - .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))); - ifaceTwoAddressOneIdentifier = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(2L)) - .child(Ipv4.class) - .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))); - - // to simulate complex key - cacheKeyFactory = new IdentifierCacheKeyFactory(ImmutableSet.of(SubInterface.class)); - - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME); - defineMapping(mappingContext, SUB_IF_2_NAME, SUB_IF_2_INDEX, IFC_CTX_NAME); - } - - @Override - protected ListReaderCustomizer initCustomizer() { - return new SubInterfaceIpv4AddressCustomizer(api, interfaceContext); - } - - private static InstanceIdentifier
getId() { - return IP4_IID.child(Address.class); - } - - private static InstanceIdentifier
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); - when(api.ipAddressDump(any())).thenReturn(future(dump())); - getCustomizer().readCurrentAttributes(getId(IP2), builder, ctx); - verify(builder).setIp(IP2); - verify(builder).setSubnet(new PrefixLengthBuilder().setPrefixLength(PREFIX_LENGTH).build()); - } - - @Test(expected = ReadFailedException.class) - public void testReadFailed() throws ReadFailedException { - when(api.ipAddressDump(any())).thenReturn(failedFuture()); - getCustomizer().readCurrentAttributes(getId(IP1), mock(AddressBuilder.class), ctx); - } - - @Test - public void testGetAllIds() throws ReadFailedException { - when(api.ipAddressDump(any())).thenReturn(future(dump())); - final List allIds = getCustomizer().getAllIds(getId(), ctx); - assertThat(allIds, hasSize(2)); - assertThat(allIds, containsInAnyOrder(new AddressKey(IP1), new AddressKey(IP2))); - } - - @Test(expected = ReadFailedException.class) - public void testGetAllIdsFailed() throws ReadFailedException { - when(api.ipAddressDump(any())).thenReturn(failedFuture()); - getCustomizer().getAllIds(getId(), ctx); - } - - @Test - public void testCacheScope() { - - } - - @Test - public void testCachingScopeSpecificRequest() throws ReadFailedException { - fillCacheForTwoIfaces(); - final AddressBuilder ifaceOneAddressBuilder = new AddressBuilder(); - final AddressBuilder ifaceTwoAddressBuilder = new AddressBuilder(); - - getCustomizer().readCurrentAttributes(ifaceOneAddressOneIdentifier, ifaceOneAddressBuilder, ctx); - getCustomizer().readCurrentAttributes(ifaceTwoAddressOneIdentifier, ifaceTwoAddressBuilder, ctx); - - // addresses have caching scope of parent interface, so returned address should have respective prefix lengths - assertEquals("192.168.2.1", ifaceOneAddressBuilder.getIp().getValue()); - assertTrue(ifaceOneAddressBuilder.getSubnet() instanceof PrefixLength); - assertEquals(22, PrefixLength.class.cast(ifaceOneAddressBuilder.getSubnet()).getPrefixLength().intValue()); - - assertEquals("192.168.2.1", ifaceTwoAddressBuilder.getIp().getValue()); - assertTrue(ifaceTwoAddressBuilder.getSubnet() instanceof PrefixLength); - assertEquals(23, PrefixLength.class.cast(ifaceTwoAddressBuilder.getSubnet()).getPrefixLength().intValue()); - } - - @Test - public void testCachingScopeGetAll() throws ReadFailedException { - fillCacheForFirstIfaceSecondEmpty(); - - final List keysForIfaceOne = getCustomizer().getAllIds(ifaceOneAddressOneIdentifier, ctx); - Assert.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); - Assert.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(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne); - cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), 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(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne); - cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), new IpAddressDetailsReplyDump()); - } - - private IpAddressDetailsReplyDump dump() { - final IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump(); - - final IpAddressDetails details1 = new IpAddressDetails(); - details1.ip = new byte[]{1, 1, 1, 10}; - details1.prefixLength = (byte) PREFIX_LENGTH; - reply.ipAddressDetails.add(details1); - - final IpAddressDetails details2 = new IpAddressDetails(); - details2.ip = new byte[]{2, 1, 1, 10}; - details2.prefixLength = (byte) PREFIX_LENGTH; - reply.ipAddressDetails.add(details2); - - return reply; - } -} \ No newline at end of file -- cgit 1.2.3-korg