diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2017-02-21 08:42:28 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-02-21 17:23:31 +0100 |
commit | f93fc373a265382b88673a3b8636714924e71a9e (patch) | |
tree | 3d9e7945b4a8da917c3e2c032b1b92836339a9f4 | |
parent | f674354dbb4ee89aea8f748aa21e8c43602db9f2 (diff) |
HC2VPP-81: add support for ARP proxy enable/disable
Change-Id: Ib0cd5ce9175161a3e9bc83076931fb75e6d82a09
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
3 files changed, 52 insertions, 8 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java index 62fbe822a..b321930d6 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java @@ -153,7 +153,7 @@ public final class InterfacesWriterFactory implements WriterFactory { SubinterfaceAugmentationWriterFactory.SUB_IFC_ID); // Proxy Arp (execute after specific interface customizers) registry.addAfter( - new GenericWriter<>(VPP_IFC_AUG_ID.child(ProxyArp.class), new ProxyArpCustomizer(jvpp)), + new GenericWriter<>(VPP_IFC_AUG_ID.child(ProxyArp.class), new ProxyArpCustomizer(jvpp, ifcNamingContext)), specificIfcTypes); // Ingress (execute after classify table and session writers) // also handles L2Acl, Ip4Acl and Ip6Acl: diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ProxyArpCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ProxyArpCustomizer.java index 66f2e3e81..9f5c4ac66 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ProxyArpCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ProxyArpCustomizer.java @@ -17,13 +17,15 @@ 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; @@ -38,16 +40,20 @@ import org.slf4j.LoggerFactory; 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 @@ -63,7 +69,9 @@ public class ProxyArpCustomizer extends FutureJVppCustomizer implements WriterCu @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, @@ -86,7 +94,7 @@ public class ProxyArpCustomizer extends FutureJVppCustomizer implements WriterCu } 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); } @@ -105,4 +113,24 @@ public class ProxyArpCustomizer extends FutureJVppCustomizer implements WriterCu 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); + } } diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ProxyArpCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ProxyArpCustomizerTest.java index 87e8e6422..f1451fd9d 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ProxyArpCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ProxyArpCustomizerTest.java @@ -22,9 +22,12 @@ 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.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; @@ -37,19 +40,24 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; 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) @@ -67,7 +75,8 @@ public class ProxyArpCustomizerTest extends WriterCustomizerTest implements Byte 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) @@ -81,7 +90,7 @@ public class ProxyArpCustomizerTest extends WriterCustomizerTest implements Byte .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; @@ -90,6 +99,13 @@ public class ProxyArpCustomizerTest extends WriterCustomizerTest implements Byte 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); |