import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer;
import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
+import io.fd.vpp.jvpp.snat.dto.Nat64InterfaceDetailsReplyDump;
+import io.fd.vpp.jvpp.snat.dto.Nat64InterfaceDump;
import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump;
import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDump;
import io.fd.vpp.jvpp.snat.dto.SnatInterfaceOutputFeatureDetailsReplyDump;
abstract class AbstractInterfaceNatCustomizer<C extends DataObject, B extends Builder<C>>
implements InitializingReaderCustomizer<C, B>, JvppReplyConsumer {
- private final FutureJVppSnatFacade jvppSnat;
- private final DumpCacheManager<SnatInterfaceDetailsReplyDump, Void> preRoutingDumpMgr;
- private final DumpCacheManager<SnatInterfaceOutputFeatureDetailsReplyDump, Void> postRoutingDumpMgr;
+ private final DumpCacheManager<SnatInterfaceDetailsReplyDump, Void> preRoutingNat44DumpMgr;
+ private final DumpCacheManager<Nat64InterfaceDetailsReplyDump, Void> preRoutingNat64DumpMgr;
+ private final DumpCacheManager<SnatInterfaceOutputFeatureDetailsReplyDump, Void> postRoutingNat44DumpMgr;
private final NamingContext ifcContext;
+ private final VppAttributesBuilder vppAttributesBuilder;
AbstractInterfaceNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat,
- @Nonnull final NamingContext ifcContext) {
- this.jvppSnat = requireNonNull(jvppSnat, "jvppSnat should not be null");
+ @Nonnull final NamingContext ifcContext,
+ @Nonnull final VppAttributesBuilder vppAttributesBuilder) {
+ requireNonNull(jvppSnat, "jvppSnat should not be null");
this.ifcContext = requireNonNull(ifcContext, "ifcContext should not be null");
- this.preRoutingDumpMgr = new DumpCacheManager.DumpCacheManagerBuilder<SnatInterfaceDetailsReplyDump, Void>()
- .withExecutor((id, params) -> getReplyForRead(
- jvppSnat.snatInterfaceDump(new SnatInterfaceDump()).toCompletableFuture(), id))
- .acceptOnly(SnatInterfaceDetailsReplyDump.class)
- .build();
- this.postRoutingDumpMgr =
+ this.vppAttributesBuilder = requireNonNull(vppAttributesBuilder, "ifcContext should not be null");
+ this.preRoutingNat44DumpMgr =
+ new DumpCacheManager.DumpCacheManagerBuilder<SnatInterfaceDetailsReplyDump, Void>()
+ .withExecutor((id, params) -> getReplyForRead(
+ jvppSnat.snatInterfaceDump(new SnatInterfaceDump()).toCompletableFuture(), id))
+ .acceptOnly(SnatInterfaceDetailsReplyDump.class)
+ .build();
+ this.preRoutingNat64DumpMgr =
+ new DumpCacheManager.DumpCacheManagerBuilder<Nat64InterfaceDetailsReplyDump, Void>()
+ .withExecutor((id, params) -> getReplyForRead(
+ jvppSnat.nat64InterfaceDump(new Nat64InterfaceDump()).toCompletableFuture(), id))
+ .acceptOnly(Nat64InterfaceDetailsReplyDump.class)
+ .build();
+ this.postRoutingNat44DumpMgr =
new DumpCacheManager.DumpCacheManagerBuilder<SnatInterfaceOutputFeatureDetailsReplyDump, Void>()
.withExecutor((id, params) -> getReplyForRead(
jvppSnat.snatInterfaceOutputFeatureDump(new SnatInterfaceOutputFeatureDump())
getLog().debug("Reading NAT features on interface: {}", ifcName);
final int index = ifcContext.getIndex(ifcName, ctx.getMappingContext());
- // There are no additional attributes for pre routing NAT, so it is enough to read post routing ifc mapping:
- final Optional<SnatInterfaceOutputFeatureDetailsReplyDump> postRoutingDump =
- postRoutingDumpMgr.getDump(id, ctx.getModificationCache(), null);
+ // Each of the following cases uses different VPP API, but we store them under single node.
+ // Not all combinations are possible, but we don't validate on read and rely on VPP.
+ readPreRoutingNat44(id, index, builder, ctx);
+ readPreRoutingNat64(id, index, builder, ctx);
+ readPostRoutingNat44(id, index, builder, ctx);
+ }
+
+ private void readPreRoutingNat44(final InstanceIdentifier<C> id, final int index, final B builder,
+ final ReadContext ctx) throws ReadFailedException {
+ final Optional<SnatInterfaceDetailsReplyDump> dump =
+ preRoutingNat44DumpMgr.getDump(id, ctx.getModificationCache(), null);
- postRoutingDump.or(new SnatInterfaceOutputFeatureDetailsReplyDump()).snatInterfaceOutputFeatureDetails.stream()
+ dump.or(new SnatInterfaceDetailsReplyDump()).snatInterfaceDetails.stream()
.filter(snatIfcDetail -> snatIfcDetail.swIfIndex == index)
.filter(snatIfcDetail -> isExpectedNatType(snatIfcDetail.isInside))
- .findFirst()
- .ifPresent(snatIfcDetail -> setPostRouting(builder));
+ .findAny()
+ .ifPresent(snatIfcDetail -> vppAttributesBuilder.enableNat44(builder));
+ // do not modify builder is feature is absent (inbound/outbound are presence containers)
}
- @Override
- public boolean isPresent(final InstanceIdentifier<C> id, final C built, final ReadContext ctx)
- throws ReadFailedException {
- // In the post routing case, we can reuse default implementation:
- if (InitializingReaderCustomizer.super.isPresent(id, built, ctx)) {
- // post routing was set
- return true;
- }
- // In the pre routing case, we need to inspect pre routing dump:
- final String ifcName = getName(id);
- getLog().debug("Checking NAT presence for interface: {}", ifcName);
- final int index = ifcContext.getIndex(ifcName, ctx.getMappingContext());
+ private void readPreRoutingNat64(final InstanceIdentifier<C> id, final int index, final B builder,
+ final ReadContext ctx) throws ReadFailedException {
+ final Optional<Nat64InterfaceDetailsReplyDump> dump =
+ preRoutingNat64DumpMgr.getDump(id, ctx.getModificationCache(), null);
- // Cache dump for each interface under the same key since this is all ifc dump:
- final Optional<SnatInterfaceDetailsReplyDump> preRoutingDump =
- preRoutingDumpMgr.getDump(id, ctx.getModificationCache(), null);
+ dump.or(new Nat64InterfaceDetailsReplyDump()).nat64InterfaceDetails.stream()
+ .filter(snatIfcDetail -> snatIfcDetail.swIfIndex == index)
+ .filter(snatIfcDetail -> isExpectedNatType(snatIfcDetail.isInside))
+ .findAny()
+ .ifPresent(snatIfcDetail -> vppAttributesBuilder.enableNat64(builder));
+ // do not modify builder is feature is absent (inbound/outbound are presence containers)
+ }
- // Find entries for current ifc and if is marked as inside set the builder to return presence container:
- return preRoutingDump.or(new SnatInterfaceDetailsReplyDump()).snatInterfaceDetails.stream()
+ private void readPostRoutingNat44(final InstanceIdentifier<C> id, final int index, final B builder,
+ final ReadContext ctx) throws ReadFailedException {
+ final Optional<SnatInterfaceOutputFeatureDetailsReplyDump> dump =
+ postRoutingNat44DumpMgr.getDump(id, ctx.getModificationCache(), null);
+
+ dump.or(new SnatInterfaceOutputFeatureDetailsReplyDump()).snatInterfaceOutputFeatureDetails
+ .stream()
.filter(snatIfcDetail -> snatIfcDetail.swIfIndex == index)
- .anyMatch(snatIfcDetail -> isExpectedNatType(snatIfcDetail.isInside));
- // Not setting data, just marking the builder to propagate empty container to indicate presence.
+ .filter(snatIfcDetail -> isExpectedNatType(snatIfcDetail.isInside))
+ .findAny()
+ .ifPresent(snatIfcDetail -> vppAttributesBuilder.enablePostRouting(builder));
+ // do not modify builder is feature is absent (inbound/outbound are presence containers)
}
protected String getName(final InstanceIdentifier<C> id) {
abstract Logger getLog();
abstract boolean isExpectedNatType(final int isInside);
-
- abstract void setPostRouting(final B builder);
}
abstract class AbstractSubInterfaceNatCustomizer<C extends DataObject, B extends Builder<C>>
extends AbstractInterfaceNatCustomizer<C, B> {
AbstractSubInterfaceNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat,
- @Nonnull final NamingContext ifcContext) {
- super(jvppSnat, ifcContext);
+ @Nonnull final NamingContext ifcContext,
+ @Nonnull final VppAttributesBuilder vppAttributesBuilder) {
+ super(jvppSnat, ifcContext, vppAttributesBuilder);
}
@Override
package io.fd.hc2vpp.nat.read.ifc;
-
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.fd.hc2vpp.common.translate.util.NamingContext;
--- /dev/null
+/*
+ * Copyright (c) 2017 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.hc2vpp.nat.read.ifc;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.nat.InboundBuilder;
+
+final class InboundAttributesBuilder implements VppAttributesBuilder<InboundBuilder> {
+ @Override
+ public void enableNat44(final InboundBuilder builder) {
+ builder.setNat44Support(true);
+ }
+
+ @Override
+ public void enableNat64(final InboundBuilder builder) {
+ builder.setNat64Support(true);
+ }
+
+ @Override
+ public void enablePostRouting(final InboundBuilder builder) {
+ builder.setPostRouting(true);
+ }
+}
InterfaceInboundNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat,
@Nonnull final NamingContext ifcContext) {
- super(jvppSnat, ifcContext);
+ super(jvppSnat, ifcContext, new InboundAttributesBuilder());
}
@Override
return isInside == 1;
}
- @Override
- void setPostRouting(final InboundBuilder builder) {
- builder.setPostRouting(true);
- }
-
@Nonnull
@Override
public InboundBuilder getBuilder(@Nonnull final InstanceIdentifier<Inbound> id) {
InterfaceOutboundNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat,
@Nonnull final NamingContext ifcContext) {
- super(jvppSnat, ifcContext);
+ super(jvppSnat, ifcContext, new OutboundAttributesReader());
}
@Override
return isInside == 0;
}
- @Override
- void setPostRouting(final OutboundBuilder builder) {
- builder.setPostRouting(true);
- }
-
@Nonnull
@Override
public OutboundBuilder getBuilder(@Nonnull final InstanceIdentifier<Outbound> id) {
--- /dev/null
+/*
+ * Copyright (c) 2017 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.hc2vpp.nat.read.ifc;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.nat.OutboundBuilder;
+
+final class OutboundAttributesReader implements VppAttributesBuilder<OutboundBuilder> {
+ @Override
+ public void enableNat44(final OutboundBuilder builder) {
+ builder.setNat44Support(true);
+ }
+
+ @Override
+ public void enableNat64(final OutboundBuilder builder) {
+ builder.setNat64Support(true);
+ }
+
+ @Override
+ public void enablePostRouting(final OutboundBuilder builder) {
+ builder.setPostRouting(true);
+ }
+}
SubInterfaceInboundNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat,
@Nonnull final NamingContext ifcContext) {
- super(jvppSnat, ifcContext);
+ super(jvppSnat, ifcContext, new InboundAttributesBuilder());
}
@Override
return isInside == 1;
}
- @Override
- void setPostRouting(final InboundBuilder builder) {
- builder.setPostRouting(true);
- }
-
@Nonnull
@Override
public InboundBuilder getBuilder(@Nonnull final InstanceIdentifier<Inbound> id) {
SubInterfaceOutboundNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat,
@Nonnull final NamingContext ifcContext) {
- super(jvppSnat, ifcContext);
+ super(jvppSnat, ifcContext, new OutboundAttributesReader());
}
@Override
return isInside == 0;
}
- @Override
- void setPostRouting(final OutboundBuilder builder) {
- builder.setPostRouting(true);
- }
-
@Nonnull
@Override
public OutboundBuilder getBuilder(@Nonnull final InstanceIdentifier<Outbound> id) {
--- /dev/null
+/*
+ * Copyright (c) 2017 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.hc2vpp.nat.read.ifc;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.InterfaceNatVppFeatureAttributes;
+import org.opendaylight.yangtools.concepts.Builder;
+
+interface VppAttributesBuilder<B extends Builder<? extends InterfaceNatVppFeatureAttributes>> {
+ void enableNat44(final B builder);
+
+ void enableNat64(final B builder);
+
+ void enablePostRouting(final B builder);
+}
package io.fd.hc2vpp.nat.write.ifc;
+import static com.google.common.base.Preconditions.checkArgument;
+
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.vpp.jvpp.dto.JVppReply;
+import io.fd.vpp.jvpp.snat.dto.Nat64AddDelInterface;
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 java.util.concurrent.CompletionStage;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.InterfaceNatVppFeatureAttributes;
getLog().debug("Enabling {} NAT: {}", dataAfter, id);
final int ifcIndex = ifcContext.getIndex(ifcName, writeContext.getMappingContext());
- final JVppReply reply;
if (dataAfter.isPostRouting()) {
- reply = postRoutingNat(id, ifcIndex, true);
+ postRoutingNat(id, dataAfter, ifcIndex, true);
} else {
- reply = preRoutingNat(id, ifcIndex, true);
+ preRoutingNat(id, dataAfter, ifcIndex, true);
}
- getLog().debug("NAT {} enabled successfully on: {}, reply: {}", dataAfter, ifcName, reply);
+ getLog().debug("NAT {} enabled successfully on: {}", dataAfter, ifcName);
}
@Override
getLog().debug("Disabling {} NAT: {}", dataBefore, id);
final int ifcIndex = ifcContext.getIndex(ifcName, writeContext.getMappingContext());
- final JVppReply reply;
if (dataBefore.isPostRouting()) {
- reply = postRoutingNat(id, ifcIndex, false);
+ postRoutingNat(id, dataBefore, ifcIndex, false);
} else {
- reply = preRoutingNat(id, ifcIndex, false);
+ preRoutingNat(id, dataBefore, ifcIndex, false);
}
- getLog().debug("NAT {} disabled successfully on: {}, reply: {}", dataBefore, ifcName, reply);
+ getLog().debug("NAT {} disabled successfully on: {}", dataBefore, ifcName);
}
protected String getName(final InstanceIdentifier<D> id) {
return id.firstKeyOf(Interface.class).getName();
}
- private JVppReply postRoutingNat(@Nonnull final InstanceIdentifier<D> id, final int ifcIndex, final boolean enable)
+ private void postRoutingNat(@Nonnull final InstanceIdentifier<D> id, final D natAttributes, final int ifcIndex,
+ final boolean enable)
throws WriteFailedException {
+ checkArgument(!isNat64Supported(natAttributes), "Post routing Nat64 is not supported by VPP");
final SnatInterfaceAddDelOutputFeature request = new SnatInterfaceAddDelOutputFeature();
request.isAdd = booleanToByte(enable);
request.isInside = getType().isInside;
request.swIfIndex = ifcIndex;
+ getReplyForWrite(jvppSnat.snatInterfaceAddDelOutputFeature(request).toCompletableFuture(), id);
+ }
+
+ private void preRoutingNat(@Nonnull final InstanceIdentifier<D> id, final D natAttributes, final int ifcIndex,
+ final boolean enable)
+ throws WriteFailedException {
+ if (natAttributes.isNat44Support()) {
+ // default value is defined for nat44-support, so no need for null check
+ preRoutingNat44(id, ifcIndex, enable);
+ }
+ if (isNat64Supported(natAttributes)) {
+ preRoutingNat64(id, ifcIndex, enable);
+ }
+ }
- final CompletionStage<SnatInterfaceAddDelOutputFeatureReply> future =
- jvppSnat.snatInterfaceAddDelOutputFeature(request);
- return getReplyForWrite(future.toCompletableFuture(), id);
+ private boolean isNat64Supported(final D natAttributes) {
+ return natAttributes.isNat64Support() != null && natAttributes.isNat64Support();
}
- private JVppReply preRoutingNat(@Nonnull final InstanceIdentifier<D> id, final int ifcIndex, final boolean enable)
+ private void preRoutingNat44(@Nonnull final InstanceIdentifier<D> id, final int ifcIndex, final boolean enable)
throws WriteFailedException {
final SnatInterfaceAddDelFeature request = new SnatInterfaceAddDelFeature();
request.isAdd = booleanToByte(enable);
request.isInside = getType().isInside;
request.swIfIndex = ifcIndex;
+ getReplyForWrite(jvppSnat.snatInterfaceAddDelFeature(request).toCompletableFuture(), id);
+ }
- final CompletionStage<SnatInterfaceAddDelFeatureReply> future = jvppSnat.snatInterfaceAddDelFeature(request);
- return getReplyForWrite(future.toCompletableFuture(), id);
+ private void preRoutingNat64(@Nonnull final InstanceIdentifier<D> id, final int ifcIndex, final boolean enable)
+ throws WriteFailedException {
+ final Nat64AddDelInterface request = new Nat64AddDelInterface();
+ request.isAdd = booleanToByte(enable);
+ request.isInside = getType().isInside;
+ request.swIfIndex = ifcIndex;
+ getReplyForWrite(jvppSnat.nat64AddDelInterface(request).toCompletableFuture(), id);
}
enum NatType {
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 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;
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();
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 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;
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();
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;
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
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)
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
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;
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;
@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
@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