From 80804f713cdd8d3c30c7e2dd19cbc2a61a1a70c0 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Mon, 31 Oct 2016 15:46:41 +0100 Subject: Add support for ipv6 vrf Change-Id: I3372d4156a19157ca431cb29c23de33161f6cfc0 Signed-off-by: Marek Gradzki --- v3po/api/src/main/yang/v3po.yang | 9 ++++-- .../v3po/interfaces/RoutingCustomizer.java | 35 ++++++++++++++-------- .../v3po/interfaces/RoutingCustomizerTest.java | 10 +------ 3 files changed, 30 insertions(+), 24 deletions(-) (limited to 'v3po') diff --git a/v3po/api/src/main/yang/v3po.yang b/v3po/api/src/main/yang/v3po.yang index d3869abaf..f272a489a 100644 --- a/v3po/api/src/main/yang/v3po.yang +++ b/v3po/api/src/main/yang/v3po.yang @@ -442,10 +442,15 @@ module v3po { } container routing { - leaf vrf-id { // todo no routing info for oper, is it possible to get it from the vpp? + // TODO (HONEYCOMB-127): add routing info for oper + leaf ipv4-vrf-id { + type uint32; + } + leaf ipv6-vrf-id { type uint32; - default 0; } + description + "Defines VRF tables used for ipv4 and ipv6 traffic"; } container vhost-user { diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizer.java index 4b1e2dba4..05ecf3648 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizer.java @@ -16,7 +16,10 @@ package io.fd.honeycomb.translate.v3po.interfaces; +import static com.google.common.base.Preconditions.checkArgument; + import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer; import io.fd.honeycomb.translate.vpp.util.NamingContext; @@ -33,7 +36,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCustomizer, JvppReplyConsumer { +public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCustomizer, JvppReplyConsumer, + ByteDataTranslator { private static final Logger LOG = LoggerFactory.getLogger(RoutingCustomizer.class); private final NamingContext interfaceContext; @@ -70,22 +74,27 @@ public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCus disableRouting(id, ifName, writeContext); } - private void setRouting(final InstanceIdentifier id, final String name, final Routing rt, - final WriteContext writeContext) throws WriteFailedException { + private void setRouting(@Nonnull final InstanceIdentifier id, @Nonnull final String name, + @Nonnull final Routing rt, + @Nonnull final WriteContext writeContext) throws WriteFailedException { final int swIfc = interfaceContext.getIndex(name, writeContext.getMappingContext()); LOG.debug("Setting routing for interface: {}, {}. Routing: {}", name, swIfc, rt); + checkArgument(rt.getIpv4VrfId() != null || rt.getIpv6VrfId() != null, "No vrf-id given"); + + setVrfId(id, swIfc, rt.getIpv4VrfId(), false); + setVrfId(id, swIfc, rt.getIpv6VrfId(), true); - int vrfId = (rt != null) - ? rt.getVrfId().intValue() - : 0; + LOG.debug("Routing set successfully for interface: {}, {}, routing: {}", name, swIfc, rt); + } - if (vrfId != 0) { - final CompletionStage swInterfaceSetTableReplyCompletionStage = - getFutureJVpp() - .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, (byte) 0, /* isIpv6 */ vrfId)); - getReplyForWrite(swInterfaceSetTableReplyCompletionStage.toCompletableFuture(), id); - LOG.debug("Routing set successfully for interface: {}, {}, routing: {}", name, swIfc, rt); + private void setVrfId(final InstanceIdentifier id, final int swIfc, final Long vrfId, boolean isIp6) + throws WriteFailedException { + if (vrfId == null) { + return; } + final CompletionStage cs = getFutureJVpp() + .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, booleanToByte(isIp6), vrfId.intValue())); + getReplyForWrite(cs.toCompletableFuture(), id); } /** @@ -98,7 +107,7 @@ public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCus LOG.debug("Disabling routing for interface: {}, {}.", name, swIfc); getReplyForDelete(getFutureJVpp() - .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, (byte) 0, 0)).toCompletableFuture(), id); + .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, (byte) 0, 0)).toCompletableFuture(), id); LOG.debug("Routing for interface: {}, {} successfully disabled", name, swIfc); } diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizerTest.java index 0fbe7e83c..a6a0b48f0 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizerTest.java @@ -18,7 +18,6 @@ package io.fd.honeycomb.translate.v3po.interfaces; import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import io.fd.honeycomb.translate.vpp.util.NamingContext; @@ -65,13 +64,6 @@ public class RoutingCustomizerTest extends WriterCustomizerTest { customizer.writeCurrentAttributes(IID, routing(213), writeContext); } - @Test - public void testUpdate() throws WriteFailedException { - when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply())); - customizer.updateCurrentAttributes(IID, routing(123L), null, writeContext); - verifyZeroInteractions(api); - } - @Test(expected = WriteFailedException.class) public void testUpdateFailed() throws WriteFailedException { when(api.swInterfaceSetTable(any())).thenReturn(failedFuture()); @@ -92,7 +84,7 @@ public class RoutingCustomizerTest extends WriterCustomizerTest { } private Routing routing(final long vrfId) { - return new RoutingBuilder().setVrfId(vrfId).build(); + return new RoutingBuilder().setIpv4VrfId(vrfId).build(); } private SwInterfaceSetTable expectedRequest(final int vrfId) { -- cgit 1.2.3-korg