summaryrefslogtreecommitdiffstats
path: root/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc
diff options
context:
space:
mode:
Diffstat (limited to 'nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc')
-rw-r--r--nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/AbstractNatCustomizerTest.java72
-rw-r--r--nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/InterfaceInboundNatCustomizerTest.java19
-rw-r--r--nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/InterfaceOutboundNatCustomizerTest.java19
3 files changed, 81 insertions, 29 deletions
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<D extends DataObject, T extends AbstractInterfaceNatCustomizer<D>>
- extends WriterCustomizerTest implements ByteDataTranslator {
+abstract class AbstractNatCustomizerTest<D extends InterfaceNatVppFeatureAttributes & DataObject, T extends AbstractInterfaceNatCustomizer<D>>
+ 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<D extends DataObject, T extends Abstrac
@Override
public void setUpTest() {
customizer = getCustomizer(snatApi, ifcNamingCtx);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ when(snatApi.snatInterfaceAddDelFeature(any())).thenReturn(future(new SnatInterfaceAddDelFeatureReply()));
+ when(snatApi.snatInterfaceAddDelOutputFeature(any()))
+ .thenReturn(future(new SnatInterfaceAddDelOutputFeatureReply()));
}
@Test
- public void testWrite() throws Exception {
- defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
- when(snatApi.snatInterfaceAddDelFeature(any())).thenReturn(future(new SnatInterfaceAddDelFeatureReply()));
- final D data = getData();
+ public void testWritePreRouting() throws Exception {
+ final D data = getPreRoutingConfig();
+ customizer.writeCurrentAttributes(getIId(IFACE_NAME), data, writeContext);
+ verify(snatApi).snatInterfaceAddDelFeature(expectedPreRoutingRequest(data, true));
+ }
+
+ @Test
+ public void testWritePostRouting() throws Exception {
+ final D data = getPostRoutingConfig();
customizer.writeCurrentAttributes(getIId(IFACE_NAME), data, writeContext);
- verify(snatApi).snatInterfaceAddDelFeature(expectedRequest(data, true));
+ verify(snatApi).snatInterfaceAddDelOutputFeature(expectedPostRoutingRequest(data, true));
+ }
+
+ @Test(expected = WriteFailedException.UpdateFailedException.class)
+ public void testUpdatePreRouting() throws Exception {
+ customizer.updateCurrentAttributes(getIId(IFACE_NAME), getPreRoutingConfig(), getPreRoutingConfig(),
+ writeContext);
}
@Test(expected = WriteFailedException.UpdateFailedException.class)
- public void testUpdate() throws Exception {
- customizer.updateCurrentAttributes(getIId(IFACE_NAME), getData(), getData(), writeContext);
+ public void testUpdatePostRouting() throws Exception {
+ customizer.updateCurrentAttributes(getIId(IFACE_NAME), getPostRoutingConfig(), getPostRoutingConfig(),
+ writeContext);
}
@Test
- public void testDelete() throws Exception {
- defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
- when(snatApi.snatInterfaceAddDelFeature(any())).thenReturn(future(new SnatInterfaceAddDelFeatureReply()));
- final D data = getData();
+ public void testDeletePreRouting() throws Exception {
+ final D data = getPreRoutingConfig();
+ customizer.deleteCurrentAttributes(getIId(IFACE_NAME), data, writeContext);
+ verify(snatApi).snatInterfaceAddDelFeature(expectedPreRoutingRequest(data, false));
+ }
+
+ @Test
+ public void testDeletePostRouting() throws Exception {
+ final D data = getPostRoutingConfig();
customizer.deleteCurrentAttributes(getIId(IFACE_NAME), data, writeContext);
- verify(snatApi).snatInterfaceAddDelFeature(expectedRequest(data, false));
+ verify(snatApi).snatInterfaceAddDelOutputFeature(expectedPostRoutingRequest(data, false));
}
- private SnatInterfaceAddDelFeature expectedRequest(final D data, boolean isAdd) {
+ private SnatInterfaceAddDelFeature expectedPreRoutingRequest(final D data, boolean isAdd) {
SnatInterfaceAddDelFeature request = new SnatInterfaceAddDelFeature();
- request.isInside = (byte) ((data instanceof Inbound) ? 1 : 0);
+ request.isInside = (byte) ((data instanceof Inbound)
+ ? 1
+ : 0);
request.swIfIndex = IFACE_ID;
request.isAdd = booleanToByte(isAdd);
return request;
}
- protected abstract D getData();
+ private SnatInterfaceAddDelOutputFeature expectedPostRoutingRequest(final D data, boolean isAdd) {
+ SnatInterfaceAddDelOutputFeature request = new SnatInterfaceAddDelOutputFeature();
+ request.isInside = (byte) ((data instanceof Inbound)
+ ? 1
+ : 0);
+ request.swIfIndex = IFACE_ID;
+ request.isAdd = booleanToByte(isAdd);
+ return request;
+ }
+
+ protected abstract D getPreRoutingConfig();
+
+ protected abstract D getPostRoutingConfig();
protected abstract InstanceIdentifier<D> 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<Inbound, InterfaceInboundNatCustomizer> {
+public class InterfaceInboundNatCustomizerTest
+ extends AbstractNatCustomizerTest<Inbound, InterfaceInboundNatCustomizer> {
@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<Inbound> 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<Outbound, InterfaceOutboundNatCustomizer> {
+public class InterfaceOutboundNatCustomizerTest
+ extends AbstractNatCustomizerTest<Outbound, InterfaceOutboundNatCustomizer> {
@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<Outbound> 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