From 33ecedc83c01e4d33e8304d9759100dcd95cb244 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Tue, 1 Aug 2017 13:43:14 +0200 Subject: HC2VPP-197: translation layert for post routing NAT Change-Id: Icef6682fbc7a18a1e52953270ad26f6b3b7676eb Signed-off-by: Marek Gradzki --- .../ifc/InterfaceInboundNatCustomizerTest.java | 56 ++++++++++++----- .../ifc/InterfaceOutboundNatCustomizerTest.java | 55 ++++++++++++----- .../nat/write/ifc/AbstractNatCustomizerTest.java | 72 +++++++++++++++++----- .../ifc/InterfaceInboundNatCustomizerTest.java | 19 ++++-- .../ifc/InterfaceOutboundNatCustomizerTest.java | 19 ++++-- 5 files changed, 160 insertions(+), 61 deletions(-) (limited to 'nat/nat2vpp/src/test/java/io/fd') diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java index 859d78fb3..a71461f4a 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java @@ -18,6 +18,10 @@ package io.fd.hc2vpp.nat.read.ifc; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.common.collect.Lists; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; @@ -25,13 +29,13 @@ import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.impl.read.GenericReader; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetails; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump; +import io.fd.vpp.jvpp.snat.dto.SnatInterfaceOutputFeatureDetails; +import io.fd.vpp.jvpp.snat.dto.SnatInterfaceOutputFeatureDetailsReplyDump; +import io.fd.vpp.jvpp.snat.future.FutureJVppSnatFacade; import org.junit.Test; import org.mockito.Mock; -import org.mockito.Mockito; 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; @@ -51,8 +55,8 @@ public class InterfaceInboundNatCustomizerTest private static final String CTX_NAME = "ifc"; @Mock - private EntityDumpExecutor natExecutor; - private DumpCacheManager dumpMgr; + private FutureJVppSnatFacade jvppSnat; + private NamingContext ifcContext = new NamingContext(CTX_NAME, CTX_NAME); private InstanceIdentifier id; @@ -72,12 +76,13 @@ public class InterfaceInboundNatCustomizerTest protected void setUp() throws Exception { id = getId(Inbound.class); defineMapping(mappingContext, IFC_NAME, IFC_IDX, CTX_NAME); - // empty dump - Mockito.doReturn(new SnatInterfaceDetailsReplyDump()).when(natExecutor).executeDump(id, null); - dumpMgr = new DumpCacheManager.DumpCacheManagerBuilder() - .withExecutor(natExecutor) - .acceptOnly(SnatInterfaceDetailsReplyDump.class) - .build(); + when(jvppSnat.snatInterfaceDump(any())).thenReturn(future(new SnatInterfaceDetailsReplyDump())); + when(jvppSnat.snatInterfaceOutputFeatureDump(any())) + .thenReturn(future(new SnatInterfaceOutputFeatureDetailsReplyDump())); + } + + private GenericReader getReader() { + return new GenericReader<>(RWUtils.makeIidWildcarded(id), customizer); } @Test @@ -85,24 +90,43 @@ public class InterfaceInboundNatCustomizerTest assertFalse(getReader().read(id, ctx).isPresent()); } - private GenericReader getReader() { - return new GenericReader<>(RWUtils.makeIidWildcarded(id), customizer); + private void mockPostRoutingDump() { + final SnatInterfaceOutputFeatureDetailsReplyDump details = new SnatInterfaceOutputFeatureDetailsReplyDump(); + final SnatInterfaceOutputFeatureDetails detail = new SnatInterfaceOutputFeatureDetails(); + detail.isInside = 1; + detail.swIfIndex = IFC_IDX; + details.snatInterfaceOutputFeatureDetails = Lists.newArrayList(detail); + when(jvppSnat.snatInterfaceOutputFeatureDump(any())).thenReturn(future(details)); } @Test - public void testPresence() throws Exception { + public void testPresencePreRouting() throws Exception { final SnatInterfaceDetailsReplyDump details = new SnatInterfaceDetailsReplyDump(); final SnatInterfaceDetails detail = new SnatInterfaceDetails(); detail.isInside = 1; detail.swIfIndex = IFC_IDX; details.snatInterfaceDetails = Lists.newArrayList(detail); - Mockito.doReturn(details).when(natExecutor).executeDump(id, null); + when(jvppSnat.snatInterfaceDump(any())).thenReturn(future(details)); + + assertTrue(getReader().read(id, ctx).isPresent()); + } + @Test + public void testPresencePostRouting() throws Exception { + mockPostRoutingDump(); assertTrue(getReader().read(id, ctx).isPresent()); } + @Test + public void testReadPostRouting() throws Exception { + mockPostRoutingDump(); + final InboundBuilder builder = mock(InboundBuilder.class); + customizer.readCurrentAttributes(id, builder, ctx); + verify(builder).setPostRouting(true); + } + @Override protected ReaderCustomizer initCustomizer() { - return new InterfaceInboundNatCustomizer(dumpMgr, ifcContext); + return new InterfaceInboundNatCustomizer(jvppSnat, ifcContext); } } \ No newline at end of file diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java index b19878be8..833a4fa74 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java @@ -19,6 +19,10 @@ package io.fd.hc2vpp.nat.read.ifc; import static io.fd.hc2vpp.nat.read.ifc.InterfaceInboundNatCustomizerTest.getId; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.common.collect.Lists; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; @@ -26,13 +30,13 @@ import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.impl.read.GenericReader; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetails; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump; +import io.fd.vpp.jvpp.snat.dto.SnatInterfaceOutputFeatureDetails; +import io.fd.vpp.jvpp.snat.dto.SnatInterfaceOutputFeatureDetailsReplyDump; +import io.fd.vpp.jvpp.snat.future.FutureJVppSnatFacade; import org.junit.Test; import org.mockito.Mock; -import org.mockito.Mockito; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170801._interface.nat.attributes.NatBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170801._interface.nat.attributes.nat.Outbound; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170801._interface.nat.attributes.nat.OutboundBuilder; @@ -46,8 +50,7 @@ public class InterfaceOutboundNatCustomizerTest private static final String CTX_NAME = "ifc"; @Mock - private EntityDumpExecutor abc; - private DumpCacheManager dumpMgr; + private FutureJVppSnatFacade jvppSnat; private NamingContext ifcContext = new NamingContext(CTX_NAME, CTX_NAME); private InstanceIdentifier id; @@ -59,12 +62,13 @@ public class InterfaceOutboundNatCustomizerTest protected void setUp() throws Exception { id = getId(Outbound.class); defineMapping(mappingContext, IFC_NAME, IFC_IDX, CTX_NAME); - // empty dump - Mockito.doReturn(new SnatInterfaceDetailsReplyDump()).when(abc).executeDump(id, null); - dumpMgr = new DumpCacheManager.DumpCacheManagerBuilder() - .withExecutor(abc) - .acceptOnly(SnatInterfaceDetailsReplyDump.class) - .build(); + when(jvppSnat.snatInterfaceDump(any())).thenReturn(future(new SnatInterfaceDetailsReplyDump())); + when(jvppSnat.snatInterfaceOutputFeatureDump(any())) + .thenReturn(future(new SnatInterfaceOutputFeatureDetailsReplyDump())); + } + + private GenericReader getReader() { + return new GenericReader<>(RWUtils.makeIidWildcarded(id), customizer); } @Test @@ -72,24 +76,43 @@ public class InterfaceOutboundNatCustomizerTest assertFalse(getReader().read(id, ctx).isPresent()); } - private GenericReader getReader() { - return new GenericReader<>(RWUtils.makeIidWildcarded(id), customizer); + private void mockPostRoutingDump() { + final SnatInterfaceOutputFeatureDetailsReplyDump details = new SnatInterfaceOutputFeatureDetailsReplyDump(); + final SnatInterfaceOutputFeatureDetails detail = new SnatInterfaceOutputFeatureDetails(); + detail.isInside = 0; + detail.swIfIndex = IFC_IDX; + details.snatInterfaceOutputFeatureDetails = Lists.newArrayList(detail); + when(jvppSnat.snatInterfaceOutputFeatureDump(any())).thenReturn(future(details)); } @Test - public void testPresence() throws Exception { + public void testPresencePreRouting() throws Exception { final SnatInterfaceDetailsReplyDump details = new SnatInterfaceDetailsReplyDump(); final SnatInterfaceDetails detail = new SnatInterfaceDetails(); detail.isInside = 0; detail.swIfIndex = IFC_IDX; details.snatInterfaceDetails = Lists.newArrayList(detail); - Mockito.doReturn(details).when(abc).executeDump(id, null); + when(jvppSnat.snatInterfaceDump(any())).thenReturn(future(details)); assertTrue(getReader().read(id, ctx).isPresent()); } + @Test + public void testPresencePostRouting() throws Exception { + mockPostRoutingDump(); + assertTrue(getReader().read(id, ctx).isPresent()); + } + + @Test + public void testReadPostRouting() throws Exception { + mockPostRoutingDump(); + final OutboundBuilder builder = mock(OutboundBuilder.class); + customizer.readCurrentAttributes(id, builder, ctx); + verify(builder).setPostRouting(true); + } + @Override protected ReaderCustomizer initCustomizer() { - return new InterfaceOutboundNatCustomizer(dumpMgr, ifcContext); + return new InterfaceOutboundNatCustomizer(jvppSnat, ifcContext); } } \ No newline at end of file diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/AbstractNatCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/AbstractNatCustomizerTest.java index c4886a43f..273d376cd 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/AbstractNatCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/AbstractNatCustomizerTest.java @@ -26,15 +26,18 @@ import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelFeature; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelFeatureReply; +import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelOutputFeature; +import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelOutputFeatureReply; import io.fd.vpp.jvpp.snat.future.FutureJVppSnatFacade; import org.junit.Test; import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170801.InterfaceNatVppFeatureAttributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170801._interface.nat.attributes.nat.Inbound; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -abstract class AbstractNatCustomizerTest> - extends WriterCustomizerTest implements ByteDataTranslator { +abstract class AbstractNatCustomizerTest> + extends WriterCustomizerTest implements ByteDataTranslator { private static final String IFC_CTX_NAME = "ifc-test-instance"; private static final String IFACE_NAME = "eth0"; @@ -48,40 +51,75 @@ abstract class AbstractNatCustomizerTest getIId(final String ifaceName); diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/InterfaceInboundNatCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/InterfaceInboundNatCustomizerTest.java index 8c16b1c98..17efc4095 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/InterfaceInboundNatCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/InterfaceInboundNatCustomizerTest.java @@ -27,22 +27,29 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interfa import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170801._interface.nat.attributes.nat.InboundBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -public class InterfaceInboundNatCustomizerTest extends AbstractNatCustomizerTest { +public class InterfaceInboundNatCustomizerTest + extends AbstractNatCustomizerTest { @Override - protected Inbound getData() { - return new InboundBuilder().build(); + protected Inbound getPreRoutingConfig() { + return new InboundBuilder().setPostRouting(false).build(); + } + + @Override + protected Inbound getPostRoutingConfig() { + return new InboundBuilder().setPostRouting(true).build(); } @Override protected InstanceIdentifier getIId(final String ifaceName) { return InstanceIdentifier.create(Interfaces.class) - .child(Interface.class, new InterfaceKey(ifaceName)).augmentation(NatInterfaceAugmentation.class) - .child(Nat.class).child(Inbound.class); + .child(Interface.class, new InterfaceKey(ifaceName)).augmentation(NatInterfaceAugmentation.class) + .child(Nat.class).child(Inbound.class); } @Override - protected InterfaceInboundNatCustomizer getCustomizer(final FutureJVppSnatFacade snatApi, final NamingContext ifcNamingCtx) { + protected InterfaceInboundNatCustomizer getCustomizer(final FutureJVppSnatFacade snatApi, + final NamingContext ifcNamingCtx) { return new InterfaceInboundNatCustomizer(snatApi, ifcNamingCtx); } } \ No newline at end of file diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/InterfaceOutboundNatCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/InterfaceOutboundNatCustomizerTest.java index 1daa0530a..fcc9d376a 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/InterfaceOutboundNatCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/InterfaceOutboundNatCustomizerTest.java @@ -27,22 +27,29 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interfa import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170801._interface.nat.attributes.nat.OutboundBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -public class InterfaceOutboundNatCustomizerTest extends AbstractNatCustomizerTest { +public class InterfaceOutboundNatCustomizerTest + extends AbstractNatCustomizerTest { @Override - protected Outbound getData() { - return new OutboundBuilder().build(); + protected Outbound getPreRoutingConfig() { + return new OutboundBuilder().setPostRouting(false).build(); + } + + @Override + protected Outbound getPostRoutingConfig() { + return new OutboundBuilder().setPostRouting(true).build(); } @Override protected InstanceIdentifier getIId(final String ifaceName) { return InstanceIdentifier.create(Interfaces.class) - .child(Interface.class, new InterfaceKey(ifaceName)).augmentation(NatInterfaceAugmentation.class) - .child(Nat.class).child(Outbound.class); + .child(Interface.class, new InterfaceKey(ifaceName)).augmentation(NatInterfaceAugmentation.class) + .child(Nat.class).child(Outbound.class); } @Override - protected InterfaceOutboundNatCustomizer getCustomizer(final FutureJVppSnatFacade snatApi, final NamingContext ifcNamingCtx) { + protected InterfaceOutboundNatCustomizer getCustomizer(final FutureJVppSnatFacade snatApi, + final NamingContext ifcNamingCtx) { return new InterfaceOutboundNatCustomizer(snatApi, ifcNamingCtx); } } \ No newline at end of file -- cgit 1.2.3-korg