diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-06-15 12:02:42 +0200 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-06-15 10:32:17 +0000 |
commit | d46e184662bc2ca83f721d4adb0a7a815acef0a0 (patch) | |
tree | 029ccf2d9f51fc567f3e381b3540d7b57e8acb43 /v3po/v3po2vpp/src/main/java | |
parent | 3508bc959e055c76c395e0f878d3c9f138f44114 (diff) |
Implement L2 container delete
Change-Id: I5173a892ec3e8ac695a5391e570c10f488241e07
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main/java')
4 files changed, 62 insertions, 32 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/initializers/VppInitializer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/initializers/VppInitializer.java index 4cb4a92e9..c9ecee3af 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/initializers/VppInitializer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/initializers/VppInitializer.java @@ -19,6 +19,7 @@ package io.fd.honeycomb.v3po.translate.v3po.initializers; import com.google.common.base.Function; import com.google.common.collect.Lists; import io.fd.honeycomb.v3po.vpp.data.init.AbstractDataTreeConverter; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opendaylight.controller.md.sal.binding.api.DataBroker; @@ -37,7 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Initializes vpp node in config data tree based on operational state + * Initializes vpp node in config data tree based on operational state. */ public class VppInitializer extends AbstractDataTreeConverter<VppState, Vpp> { private static final Logger LOG = LoggerFactory.getLogger(VppInitializer.class); @@ -85,14 +86,12 @@ public class VppInitializer extends AbstractDataTreeConverter<VppState, Vpp> { if (l2FibTable == null) { return; } - final L2FibTableBuilder tableBuilder = new L2FibTableBuilder(); - tableBuilder.setL2FibEntry( - Lists.transform(l2FibTable.getL2FibEntry(), - oper -> { - final L2FibEntryBuilder config = new L2FibEntryBuilder(oper); - config.setBridgedVirtualInterface(null); - return config.build(); - })); + final L2FibTableBuilder tableBuilder = new L2FibTableBuilder() + .setL2FibEntry( + l2FibTable.getL2FibEntry().stream() + // Convert operational object to config. VPP does not support setting BVI (see v3po.yang) + .map(oper -> new L2FibEntryBuilder().setBridgedVirtualInterface(null).build()) + .collect(Collectors.toList())); builder.setL2FibTable(tableBuilder.build()); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterconnectionWriteUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterconnectionWriteUtils.java index 463acc84e..b5720a427 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterconnectionWriteUtils.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterconnectionWriteUtils.java @@ -59,16 +59,15 @@ final class InterconnectionWriteUtils { } void setInterconnection(final InstanceIdentifier<? extends DataObject> id, final int swIfIndex, - final String ifcName, - final Interconnection ic, final WriteContext writeContext) + final String ifcName, final Interconnection ic, final WriteContext writeContext) throws WriteFailedException { try { if (ic == null) { // TODO in case of update we should delete interconnection LOG.trace("Interconnection is not set. Skipping"); } else if (ic instanceof XconnectBased) { - setXconnectBasedL2(swIfIndex, ifcName, (XconnectBased) ic, writeContext); + setXconnectBasedL2(swIfIndex, ifcName, (XconnectBased) ic, writeContext, (byte) 1 /*enable*/); } else if (ic instanceof BridgeBased) { - setBridgeBasedL2(swIfIndex, ifcName, (BridgeBased) ic, writeContext); + setBridgeBasedL2(swIfIndex, ifcName, (BridgeBased) ic, writeContext, (byte) 1 /*enable*/); } else { // FIXME how does choice extensibility work // FIXME it is not even possible to create a dedicated customizer for Interconnection, since it's not a DataObject @@ -84,8 +83,29 @@ final class InterconnectionWriteUtils { } } + void deleteInterconnection(final InstanceIdentifier<? extends DataObject> id, final int swIfIndex, + final String ifcName, final Interconnection ic, final WriteContext writeContext) + throws WriteFailedException { + try { + if (ic == null) { // TODO in case of update we should delete interconnection + LOG.trace("Interconnection is not set. Skipping"); + } else if (ic instanceof XconnectBased) { + setXconnectBasedL2(swIfIndex, ifcName, (XconnectBased) ic, writeContext, (byte) 0 /*disable*/); + } else if (ic instanceof BridgeBased) { + setBridgeBasedL2(swIfIndex, ifcName, (BridgeBased) ic, writeContext, (byte) 0 /*disable*/); + } else { + LOG.error("Unable to delete Interconnection of type {}", ic.getClass()); + throw new WriteFailedException(id, "Unable to delete Interconnection of type " + ic.getClass()); + } + } catch (VppBaseCallException e) { + LOG.warn("Failed to delete bridge/xconnect based interconnection flags for: {}, interconnection: {}", + ifcName, ic); + throw new WriteFailedException(id, "Unable to delete Interconnection of type " + ic.getClass(), e); + } + } + private void setBridgeBasedL2(final int swIfIndex, final String ifcName, final BridgeBased bb, - final WriteContext writeContext) + final WriteContext writeContext, final byte enabled) throws VppBaseCallException { LOG.debug("Setting bridge based interconnection(bridge-domain={}) for interface: {}", bb.getBridgeDomain(), ifcName); @@ -105,9 +125,8 @@ final class InterconnectionWriteUtils { } final CompletionStage<SwInterfaceSetL2BridgeReply> swInterfaceSetL2BridgeReplyCompletionStage = futureJvpp - .swInterfaceSetL2Bridge(getL2BridgeRequest(swIfIndex, bdId, shg, bvi, (byte) 1 /* enable */)); - final SwInterfaceSetL2BridgeReply reply = - TranslateUtils.getReply(swInterfaceSetL2BridgeReplyCompletionStage.toCompletableFuture()); + .swInterfaceSetL2Bridge(getL2BridgeRequest(swIfIndex, bdId, shg, bvi, enabled)); + TranslateUtils.getReply(swInterfaceSetL2BridgeReplyCompletionStage.toCompletableFuture()); LOG.debug("Bridge based interconnection updated successfully for: {}, interconnection: {}", ifcName, bb); } @@ -124,7 +143,7 @@ final class InterconnectionWriteUtils { } private void setXconnectBasedL2(final int swIfIndex, final String ifcName, final XconnectBased ic, - final WriteContext writeContext) + final WriteContext writeContext, final byte enabled) throws VppBaseCallException { String outSwIfName = ic.getXconnectOutgoingInterface(); LOG.debug("Setting xconnect based interconnection(outgoing ifc={}) for interface: {}", outSwIfName, ifcName); @@ -136,9 +155,8 @@ final class InterconnectionWriteUtils { final CompletionStage<SwInterfaceSetL2XconnectReply> swInterfaceSetL2XconnectReplyCompletionStage = futureJvpp - .swInterfaceSetL2Xconnect(getL2XConnectRequest(swIfIndex, outSwIfIndex, (byte) 1 /* enable */)); - final SwInterfaceSetL2XconnectReply reply = - TranslateUtils.getReply(swInterfaceSetL2XconnectReplyCompletionStage.toCompletableFuture()); + .swInterfaceSetL2Xconnect(getL2XConnectRequest(swIfIndex, outSwIfIndex, enabled)); + TranslateUtils.getReply(swInterfaceSetL2XconnectReplyCompletionStage.toCompletableFuture()); LOG.debug("Xconnect based interconnection updated successfully for: {}, interconnection: {}", ifcName, ic); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java index 099e721ab..dd40fbdd0 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java @@ -22,21 +22,16 @@ import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; +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.v3po.rev150105.VppInterfaceAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.openvpp.jvpp.VppBaseCallException; import org.openvpp.jvpp.future.FutureJVpp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; -import java.util.concurrent.CompletionStage; - -import static com.google.common.base.Preconditions.checkArgument; - public class L2Customizer extends FutureJVppCustomizer implements ChildWriterCustomizer<L2> { private static final Logger LOG = LoggerFactory.getLogger(L2Customizer.class); @@ -79,8 +74,10 @@ public class L2Customizer extends FutureJVppCustomizer implements ChildWriterCus @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataBefore, - @Nonnull final WriteContext writeContext) { - // TODO implement delete (if possible) + @Nonnull final WriteContext writeContext) throws WriteFailedException { + final String ifcName = id.firstKeyOf(Interface.class).getName(); + final int swIfc = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); + deleteL2(id, swIfc, ifcName, dataBefore, writeContext); } private void setL2(final InstanceIdentifier<L2> id, final int swIfIndex, final String ifcName, final L2 l2, @@ -90,4 +87,12 @@ public class L2Customizer extends FutureJVppCustomizer implements ChildWriterCus // Nothing besides interconnection here icWriteUtils.setInterconnection(id, swIfIndex, ifcName, l2.getInterconnection(), writeContext); } + + private void deleteL2(final InstanceIdentifier<L2> id, final int swIfIndex, final String ifcName, final L2 l2Before, + final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Deleting L2 for interface: {}", ifcName); + // Nothing besides interconnection here + icWriteUtils.deleteInterconnection(id, swIfIndex, ifcName, l2Before.getInterconnection(), writeContext); + } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceL2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceL2Customizer.java index c621612c7..8ab3e2c12 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceL2Customizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceL2Customizer.java @@ -31,7 +31,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.openvpp.jvpp.VppBaseCallException; import org.openvpp.jvpp.future.FutureJVpp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,8 +86,10 @@ public class SubInterfaceL2Customizer extends FutureJVppCustomizer implements Ch @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataBefore, - @Nonnull final WriteContext writeContext) { - // TODO implement delete (if possible) + @Nonnull final WriteContext writeContext) throws WriteFailedException { + final String subInterfaceName = getSubInterfaceName(id); + final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext()); + deleteL2(id, subInterfaceIndex, subInterfaceName, dataBefore, writeContext); } private void setL2(final InstanceIdentifier<L2> id, final int swIfIndex, final String ifcName, final L2 l2, @@ -97,4 +98,11 @@ public class SubInterfaceL2Customizer extends FutureJVppCustomizer implements Ch LOG.debug("Setting L2 for sub-interface: {}", ifcName); icWriterUtils.setInterconnection(id, swIfIndex, ifcName, l2.getInterconnection(), writeContext); } + + private void deleteL2(final InstanceIdentifier<L2> id, final int swIfIndex, final String ifcName, final L2 l2Before, + final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Deleting L2 for sub-interface: {}", ifcName); + icWriterUtils.deleteInterconnection(id, swIfIndex, ifcName, l2Before.getInterconnection(), writeContext); + } } |