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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCustomizer<Routing>, JvppReplyConsumer {
+public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCustomizer<Routing>, JvppReplyConsumer,
+ ByteDataTranslator {
private static final Logger LOG = LoggerFactory.getLogger(RoutingCustomizer.class);
private final NamingContext interfaceContext;
disableRouting(id, ifName, writeContext);
}
- private void setRouting(final InstanceIdentifier<Routing> id, final String name, final Routing rt,
- final WriteContext writeContext) throws WriteFailedException {
+ private void setRouting(@Nonnull final InstanceIdentifier<Routing> 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<SwInterfaceSetTableReply> 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<Routing> id, final int swIfc, final Long vrfId, boolean isIp6)
+ throws WriteFailedException {
+ if (vrfId == null) {
+ return;
}
+ final CompletionStage<SwInterfaceSetTableReply> cs = getFutureJVpp()
+ .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, booleanToByte(isIp6), vrfId.intValue()));
+ getReplyForWrite(cs.toCompletableFuture(), id);
}
/**
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);
}
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;
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());
}
private Routing routing(final long vrfId) {
- return new RoutingBuilder().setVrfId(vrfId).build();
+ return new RoutingBuilder().setIpv4VrfId(vrfId).build();
}
private SwInterfaceSetTable expectedRequest(final int vrfId) {