Implement L2 container delete
authorMaros Marsalek <[email protected]>
Wed, 15 Jun 2016 10:02:42 +0000 (12:02 +0200)
committerMaros Marsalek <[email protected]>
Wed, 15 Jun 2016 10:32:17 +0000 (10:32 +0000)
Change-Id: I5173a892ec3e8ac695a5391e570c10f488241e07
Signed-off-by: Maros Marsalek <[email protected]>
v3po/postman_rest_collection.json
v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/initializers/VppInitializer.java
v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterconnectionWriteUtils.java
v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java
v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceL2Customizer.java

index 5c9c83f..0a31f7b 100644 (file)
@@ -39,7 +39,8 @@
                                "99674f70-ec54-99f2-9300-545a031d5bab",
                                "f624bc96-502b-685c-1596-672ad5fcf6a9",
                                "0a1d6c0d-fe5e-1e1d-2471-96d7a4683e2f",
-                               "d752fed9-127a-9289-71f3-90ba2b459d77"
+                               "d752fed9-127a-9289-71f3-90ba2b459d77",
+                               "5c800144-cf89-7b77-1dd2-f488101ca441"
                        ],
                        "owner": "45557",
                        "collectionId": "e9ba4e80-fb4d-1eae-07e7-97b323164130"
                        "responses": [],
                        "rawModeData": "{\n    \"l2-fib-entry\": [\n        {\n            \"phys-address\": \"00:01:02:03:04:05\",\n            \"outgoing-interface\": \"local0\",\n            \"static-config\": \"true\",\n            \"action\": \"l2-fib-filter\"\n        }\n    ]\n}"
                },
+               {
+                       "id": "5c800144-cf89-7b77-1dd2-f488101ca441",
+                       "headers": "Content-Type: application/json\nAuthorization: Basic YWRtaW46YWRtaW4=\n",
+                       "url": "http://localhost:8181/restconf/config/ietf-interfaces:interfaces/interface/local0/v3po:l2",
+                       "preRequestScript": "",
+                       "pathVariables": {},
+                       "method": "DELETE",
+                       "data": [],
+                       "dataMode": "raw",
+                       "version": 2,
+                       "tests": "",
+                       "currentHelper": "normal",
+                       "helperAttributes": {},
+                       "time": 1465984375972,
+                       "name": "Remove local0 from bridge domain",
+                       "description": "Removes l2 interconnection of bridge-based type from local0 interface.\nCorresponds to the following VAT command:\n\nvat# sw_interface_set_l2_bridge sw_if_index 0 bd_id 1 disable\n\nVerification in VAT:\n\nvat# bridge_domain_dump",
+                       "collectionId": "7c35192d-9085-20f6-9fcd-3f8570aaefd7",
+                       "responses": [],
+                       "rawModeData": ""
+               },
                {
                        "id": "3f9588e4-885f-3792-bdf4-d0f10704ae4d",
                        "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
index 4cb4a92..c9ecee3 100644 (file)
@@ -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());
     }
 
index 463acc8..b5720a4 100644 (file)
@@ -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);
     }
 
index 099e721..dd40fbd 100644 (file)
@@ -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);
+    }
 }
index c621612..8ab3e2c 100644 (file)
@@ -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);
+    }
 }