diff options
Diffstat (limited to 'nat/nat2vpp/src/test/java')
5 files changed, 43 insertions, 25 deletions
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 2d31e3b6a..a2d92b4d0 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 @@ -16,7 +16,6 @@ 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; @@ -29,6 +28,7 @@ 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.vpp.jvpp.snat.dto.Nat64InterfaceDetailsReplyDump; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetails; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceOutputFeatureDetails; @@ -79,17 +79,14 @@ public class InterfaceInboundNatCustomizerTest when(jvppSnat.snatInterfaceDump(any())).thenReturn(future(new SnatInterfaceDetailsReplyDump())); when(jvppSnat.snatInterfaceOutputFeatureDump(any())) .thenReturn(future(new SnatInterfaceOutputFeatureDetailsReplyDump())); + when(jvppSnat.nat64InterfaceDump(any())) + .thenReturn(future(new Nat64InterfaceDetailsReplyDump())); } private GenericReader<Inbound, InboundBuilder> getReader() { return new GenericReader<>(RWUtils.makeIidWildcarded(id), customizer); } - @Test - public void testNoPresence() throws Exception { - assertFalse(getReader().read(id, ctx).isPresent()); - } - private void mockPostRoutingDump() { final SnatInterfaceOutputFeatureDetailsReplyDump details = new SnatInterfaceOutputFeatureDetailsReplyDump(); final SnatInterfaceOutputFeatureDetails detail = new SnatInterfaceOutputFeatureDetails(); 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 92dfff161..4640944a5 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 @@ -17,7 +17,6 @@ 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; @@ -30,6 +29,7 @@ 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.vpp.jvpp.snat.dto.Nat64InterfaceDetailsReplyDump; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetails; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceOutputFeatureDetails; @@ -65,17 +65,14 @@ public class InterfaceOutboundNatCustomizerTest when(jvppSnat.snatInterfaceDump(any())).thenReturn(future(new SnatInterfaceDetailsReplyDump())); when(jvppSnat.snatInterfaceOutputFeatureDump(any())) .thenReturn(future(new SnatInterfaceOutputFeatureDetailsReplyDump())); + when(jvppSnat.nat64InterfaceDump(any())) + .thenReturn(future(new Nat64InterfaceDetailsReplyDump())); } private GenericReader<Outbound, OutboundBuilder> getReader() { return new GenericReader<>(RWUtils.makeIidWildcarded(id), customizer); } - @Test - public void testNoPresence() throws Exception { - assertFalse(getReader().read(id, ctx).isPresent()); - } - private void mockPostRoutingDump() { final SnatInterfaceOutputFeatureDetailsReplyDump details = new SnatInterfaceOutputFeatureDetailsReplyDump(); final SnatInterfaceOutputFeatureDetails detail = new SnatInterfaceOutputFeatureDetails(); 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 5e37d165d..c70999907 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 @@ -17,12 +17,15 @@ package io.fd.hc2vpp.nat.write.ifc; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.vpp.jvpp.snat.dto.Nat64AddDelInterface; +import io.fd.vpp.jvpp.snat.dto.Nat64AddDelInterfaceReply; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelFeature; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelFeatureReply; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelOutputFeature; @@ -54,13 +57,14 @@ abstract class AbstractNatCustomizerTest<D extends InterfaceNatVppFeatureAttribu when(snatApi.snatInterfaceAddDelFeature(any())).thenReturn(future(new SnatInterfaceAddDelFeatureReply())); when(snatApi.snatInterfaceAddDelOutputFeature(any())) .thenReturn(future(new SnatInterfaceAddDelOutputFeatureReply())); + when(snatApi.nat64AddDelInterface(any())).thenReturn(future(new Nat64AddDelInterfaceReply())); } @Test public void testWritePreRouting() throws Exception { final D data = getPreRoutingConfig(); customizer.writeCurrentAttributes(getIId(IFACE_NAME), data, writeContext); - verify(snatApi).snatInterfaceAddDelFeature(expectedPreRoutingRequest(data, true)); + verifyPreRouting(data, true); } @Test @@ -68,6 +72,7 @@ abstract class AbstractNatCustomizerTest<D extends InterfaceNatVppFeatureAttribu final D data = getPostRoutingConfig(); customizer.writeCurrentAttributes(getIId(IFACE_NAME), data, writeContext); verify(snatApi).snatInterfaceAddDelOutputFeature(expectedPostRoutingRequest(data, true)); + verify(snatApi, never()).nat64AddDelInterface(any()); // VPP does not support it currently } @Test(expected = UnsupportedOperationException.class) @@ -86,7 +91,7 @@ abstract class AbstractNatCustomizerTest<D extends InterfaceNatVppFeatureAttribu public void testDeletePreRouting() throws Exception { final D data = getPreRoutingConfig(); customizer.deleteCurrentAttributes(getIId(IFACE_NAME), data, writeContext); - verify(snatApi).snatInterfaceAddDelFeature(expectedPreRoutingRequest(data, false)); + verifyPreRouting(data, false); } @Test @@ -94,13 +99,34 @@ abstract class AbstractNatCustomizerTest<D extends InterfaceNatVppFeatureAttribu final D data = getPostRoutingConfig(); customizer.deleteCurrentAttributes(getIId(IFACE_NAME), data, writeContext); verify(snatApi).snatInterfaceAddDelOutputFeature(expectedPostRoutingRequest(data, false)); + verify(snatApi, never()).nat64AddDelInterface(any()); // VPP does not support it currently } - private SnatInterfaceAddDelFeature expectedPreRoutingRequest(final D data, boolean isAdd) { + private void verifyPreRouting(final D data, final boolean isAdd) { + if (data.isNat44Support()) { + verify(snatApi).snatInterfaceAddDelFeature(expectedPreRoutingNat44Request(data, isAdd)); + } else { + verify(snatApi, never()).snatInterfaceAddDelFeature(any()); + } + if (data.isNat64Support() != null && data.isNat64Support()) { + verify(snatApi).nat64AddDelInterface(expectedPreRoutingNat64Request(data, isAdd)); + } else { + verify(snatApi, never()).nat64AddDelInterface(any()); + } + + } + + private SnatInterfaceAddDelFeature expectedPreRoutingNat44Request(final D data, boolean isAdd) { SnatInterfaceAddDelFeature request = new SnatInterfaceAddDelFeature(); - request.isInside = (byte) ((data instanceof Inbound) - ? 1 - : 0); + request.isInside = booleanToByte(data instanceof Inbound); + request.swIfIndex = IFACE_ID; + request.isAdd = booleanToByte(isAdd); + return request; + } + + private Nat64AddDelInterface expectedPreRoutingNat64Request(final D data, boolean isAdd) { + Nat64AddDelInterface request = new Nat64AddDelInterface(); + request.isInside = booleanToByte(data instanceof Inbound); request.swIfIndex = IFACE_ID; request.isAdd = booleanToByte(isAdd); return request; @@ -108,9 +134,7 @@ abstract class AbstractNatCustomizerTest<D extends InterfaceNatVppFeatureAttribu private SnatInterfaceAddDelOutputFeature expectedPostRoutingRequest(final D data, boolean isAdd) { SnatInterfaceAddDelOutputFeature request = new SnatInterfaceAddDelOutputFeature(); - request.isInside = (byte) ((data instanceof Inbound) - ? 1 - : 0); + request.isInside = booleanToByte(data instanceof Inbound); request.swIfIndex = IFACE_ID; request.isAdd = booleanToByte(isAdd); return request; 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 f7d9777e3..74dd59938 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 @@ -32,12 +32,12 @@ public class InterfaceInboundNatCustomizerTest @Override protected Inbound getPreRoutingConfig() { - return new InboundBuilder().setPostRouting(false).build(); + return new InboundBuilder().setPostRouting(false).setNat44Support(true).build(); } @Override protected Inbound getPostRoutingConfig() { - return new InboundBuilder().setPostRouting(true).build(); + return new InboundBuilder().setPostRouting(true).setNat44Support(true).build(); } @Override 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 ba48d914e..ddd589472 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 @@ -32,12 +32,12 @@ public class InterfaceOutboundNatCustomizerTest @Override protected Outbound getPreRoutingConfig() { - return new OutboundBuilder().setPostRouting(false).build(); + return new OutboundBuilder().setPostRouting(false).setNat44Support(true).setNat64Support(true).build(); } @Override protected Outbound getPostRoutingConfig() { - return new OutboundBuilder().setPostRouting(true).build(); + return new OutboundBuilder().setPostRouting(true).setNat44Support(true).setNat64Support(false).build(); } @Override |