package io.fd.hc2vpp.v3po.interfaces;
import com.google.common.net.InetAddresses;
-import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
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.core.dto.ProxyArpAddDel;
import io.fd.vpp.jvpp.core.dto.ProxyArpAddDelReply;
+import io.fd.vpp.jvpp.core.dto.ProxyArpIntfcEnableDisable;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
import java.net.InetAddress;
import java.util.concurrent.Future;
public class ProxyArpCustomizer extends FutureJVppCustomizer implements WriterCustomizer<ProxyArp>, JvppReplyConsumer {
private static final Logger LOG = LoggerFactory.getLogger(ProxyArpCustomizer.class);
+ private final NamingContext interfaceContext;
- public ProxyArpCustomizer(final FutureJVppCore vppApi) {
+ public ProxyArpCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) {
super(vppApi);
+ this.interfaceContext = interfaceContext;
}
@Override
public void writeCurrentAttributes(@Nonnull InstanceIdentifier<ProxyArp> id, @Nonnull ProxyArp dataAfter,
@Nonnull WriteContext writeContext) throws WriteFailedException {
final String swIfName = id.firstKeyOf(Interface.class).getName();
+ final int swIfIndex = interfaceContext.getIndex(swIfName, writeContext.getMappingContext());
createProxyArp(getProxyArpRequestFuture(id, swIfName, dataAfter, (byte) 1 /* 1 is add */), id, dataAfter);
+ enableProxyArp(swIfName, swIfIndex, id);
}
@Override
@Nonnull WriteContext writeContext) throws WriteFailedException {
final String swIfName = id.firstKeyOf(Interface.class).getName();
+ final int swIfIndex = interfaceContext.getIndex(swIfName, writeContext.getMappingContext());
deleteProxyArp(getProxyArpRequestFuture(id, swIfName, dataBefore, (byte) 0 /* 0 is delete */), id);
+ disableProxyArp(swIfName, swIfIndex, id);
}
private Future<ProxyArpAddDelReply> getProxyArpRequestFuture(InstanceIdentifier<ProxyArp> id, String swIfName,
}
private void deleteProxyArp(final Future<ProxyArpAddDelReply> future, final InstanceIdentifier<ProxyArp> identifier)
- throws WriteFailedException {
+ throws WriteFailedException {
final ProxyArpAddDelReply reply = getReplyForDelete(future, identifier);
LOG.debug("Proxy ARP setting delete successful, with reply context:", reply.context);
}
private String getv4AddressString(@Nonnull final Ipv4Address addr) {
return addr.getValue();
}
+
+ private void enableProxyArp(final String swIfName, final int swIfIndex,
+ final InstanceIdentifier<ProxyArp> identifier)
+ throws WriteFailedException {
+ final ProxyArpIntfcEnableDisable request = new ProxyArpIntfcEnableDisable();
+ request.swIfIndex = swIfIndex;
+ request.enableDisable = 1;
+ getReplyForWrite(getFutureJVpp().proxyArpIntfcEnableDisable(request).toCompletableFuture(), identifier);
+ LOG.debug("Proxy ARP was successfully enabled on interface {} (id={})", swIfName, swIfIndex);
+ }
+
+ private void disableProxyArp(final String swIfName, final int swIfIndex,
+ final InstanceIdentifier<ProxyArp> identifier)
+ throws WriteFailedException {
+ final ProxyArpIntfcEnableDisable request = new ProxyArpIntfcEnableDisable();
+ request.swIfIndex = swIfIndex;
+ request.enableDisable = 0;
+ getReplyForDelete(getFutureJVpp().proxyArpIntfcEnableDisable(request).toCompletableFuture(), identifier);
+ LOG.debug("Proxy ARP was successfully disabled on interface {} (id={})", swIfName, swIfIndex);
+ }
}
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.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.ProxyArpAddDel;
import io.fd.vpp.jvpp.core.dto.ProxyArpAddDelReply;
+import io.fd.vpp.jvpp.core.dto.ProxyArpIntfcEnableDisable;
+import io.fd.vpp.jvpp.core.dto.ProxyArpIntfcEnableDisableReply;
import org.junit.Test;
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.Interfaces;
public class ProxyArpCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
private static final String IF_NAME = "eth1";
+ private static final int IF_INDEX = 42;
+ private static final String IFACE_CTX_NAME = "ifc-test-instance";
private ProxyArpCustomizer customizer;
@Override
public void setUpTest() throws Exception {
- customizer = new ProxyArpCustomizer(api);
+ customizer = new ProxyArpCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME));
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME);
+ when(api.proxyArpIntfcEnableDisable(any())).thenReturn(future(new ProxyArpIntfcEnableDisableReply()));
}
@Test
public void testWrite() throws WriteFailedException {
when(api.proxyArpAddDel(any())).thenReturn(future(new ProxyArpAddDelReply()));
customizer.writeCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), writeContext);
- verify(api).proxyArpAddDel(expectedRequest(true));
+ verify(api).proxyArpAddDel(expectedAddDelRequest(true));
+ verify(api).proxyArpIntfcEnableDisable(expectedEnableRequest(true));
}
@Test(expected = WriteFailedException.class)
public void testDelete() throws WriteFailedException {
when(api.proxyArpAddDel(any())).thenReturn(future(new ProxyArpAddDelReply()));
customizer.deleteCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), writeContext);
- verify(api).proxyArpAddDel(expectedRequest(false));
+ verify(api).proxyArpAddDel(expectedAddDelRequest(false));
+ verify(api).proxyArpIntfcEnableDisable(expectedEnableRequest(false));
}
@Test(expected = WriteFailedException.DeleteFailedException.class)
.setLowAddr(new Ipv4AddressNoZone("10.1.1.1")).build();
}
- private ProxyArpAddDel expectedRequest(final boolean isAdd) {
+ private ProxyArpAddDel expectedAddDelRequest(final boolean isAdd) {
final ProxyArpAddDel request = new ProxyArpAddDel();
request.isAdd = booleanToByte(isAdd);
request.vrfId = 123;
return request;
}
+ private ProxyArpIntfcEnableDisable expectedEnableRequest(final boolean enable) {
+ final ProxyArpIntfcEnableDisable request = new ProxyArpIntfcEnableDisable();
+ request.swIfIndex = IF_INDEX;
+ request.enableDisable = booleanToByte(enable);
+ return request;
+ }
+
private InstanceIdentifier<ProxyArp> getProxyArpId(final String eth0) {
return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(eth0)).augmentation(
VppInterfaceAugmentation.class).child(ProxyArp.class);