Bug 5149: Support LLDP on ovsdb interface 00/33800/8
authorRashmi Pujar <rpujar@inocybe.com>
Fri, 29 Jan 2016 22:22:50 +0000 (17:22 -0500)
committerSam Hague <shague@redhat.com>
Sun, 31 Jan 2016 17:14:29 +0000 (17:14 +0000)
Change-Id: I9b61d2e149479ae95f6978ae04e4f4e3e2a6df53
Signed-off-by: Rashmi Pujar <rpujar@inocybe.com>
schemas/openvswitch/src/main/java/org/opendaylight/ovsdb/schema/openvswitch/Interface.java
southbound/southbound-api/src/main/yang/ovsdb.yang
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointCreateCommand.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointUpdateCommand.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortUpdateCommand.java
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortUpdateCommandTest.java
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java

index 934245bcc476fe70221b506fab7d1c613a5257e6..e0bd8a20a7662ac64ea8e7feea668805cf93cbe9 100644 (file)
@@ -191,4 +191,9 @@ public interface Interface extends TypedBaseTable<GenericTableSchema> {
     @TypedColumn(name="error", method=MethodType.SETDATA, fromVersion="7.7.0")
     void setError(Set<String> error);
 
+    @TypedColumn(name="lldp", method=MethodType.GETCOLUMN, fromVersion="7.11.2")
+    Column<GenericTableSchema, Map<String, String>> getLldpColumn();
+    @TypedColumn(name="lldp", method=MethodType.SETDATA, fromVersion="7.11.2")
+    void setLldp(Map<String, String> lldp);
+
 }
index b32c0f0ddcd043edbdcd5cb88d9c86a38cb8402e..9d8b8a2ed5efb7534761cacc3093c6ff69a7653f 100755 (executable)
@@ -1011,6 +1011,26 @@ module ovsdb {
             }
         }
 
+        list interface-lldp {
+            description "Auto Attach configuration for a particular interface.
+                If LLDP is enabled on an interface, the interface processes received
+                LLDP packets and never passes them to OpenFlow or forwards them.
+
+                lldp : enable: optional string, either true or false
+                       True to enable LLDP on this Interface. If not specified, LLDP
+                       will be disabled by default.";
+
+            key "lldp-key";
+            leaf lldp-key {
+                description "lldp name/key";
+                type string;
+            }
+            leaf lldp-value {
+                description "lldp value";
+                type string;
+            }
+        }
+
         leaf qos {
             description "The unique identifier of the QoS entry for this port.";
             type yang:uuid;
index 4548fd87db88fb53784dfe2d58dd00e7d0f2e9b7..8159178d0d9c6faa5dd0d76247e3e5c76bef36ce 100644 (file)
@@ -38,6 +38,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbPortInterfaceAttributes.VlanMode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceLldp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceOtherConfigs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortExternalIds;
@@ -121,6 +122,7 @@ public class TerminationPointCreateCommand extends AbstractTransactCommand {
         createInterfaceOptions(terminationPoint, ovsInterface);
         createInterfaceOtherConfig(terminationPoint, ovsInterface);
         createInterfaceExternalIds(terminationPoint, ovsInterface);
+        createInterfaceLldp(terminationPoint, ovsInterface);
     }
 
     private void createInterfaceType(final OvsdbTerminationPointAugmentation terminationPoint,
@@ -222,6 +224,25 @@ public class TerminationPointCreateCommand extends AbstractTransactCommand {
         }
     }
 
+    private void createInterfaceLldp(
+            final OvsdbTerminationPointAugmentation terminationPoint,
+            final Interface ovsInterface) {
+
+        List<InterfaceLldp> interfaceLldpList =
+                terminationPoint.getInterfaceLldp();
+        if (interfaceLldpList != null && !interfaceLldpList.isEmpty()) {
+            Map<String, String> interfaceLldpMap = new HashMap<>();
+            for (InterfaceLldp interfaceLldp : interfaceLldpList) {
+                interfaceLldpMap.put(interfaceLldp.getLldpKey(), interfaceLldp.getLldpValue());
+            }
+            try {
+                ovsInterface.setLldp(ImmutableMap.copyOf(interfaceLldpMap));
+            } catch (NullPointerException e) {
+                LOG.warn("Incomplete OVSDB interface lldp");
+            }
+        }
+    }
+
     private void createPortExternalIds(
             final OvsdbTerminationPointAugmentation terminationPoint,
             final Port port) {
index 2023374db99b4eb270cbdd1052516f7185c8c6e1..18b16006988bdf707f5a11f9be99d62566ddb7bb 100644 (file)
@@ -27,6 +27,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbPortInterfaceAttributes.VlanMode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceLldp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceOtherConfigs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortExternalIds;
@@ -110,6 +111,7 @@ public class TerminationPointUpdateCommand extends AbstractTransactCommand {
         updateInterfaceOptions(terminationPoint, ovsInterface);
         updateInterfaceOtherConfig(terminationPoint, ovsInterface);
         updateInterfaceExternalIds(terminationPoint, ovsInterface);
+        updateInterfaceLldp(terminationPoint, ovsInterface);
     }
 
     private void updatePort(
@@ -194,6 +196,25 @@ public class TerminationPointUpdateCommand extends AbstractTransactCommand {
         }
     }
 
+    private void updateInterfaceLldp(
+            final OvsdbTerminationPointAugmentation terminationPoint,
+            final Interface ovsInterface) {
+
+        List<InterfaceLldp> interfaceLldpList =
+                terminationPoint.getInterfaceLldp();
+        if (interfaceLldpList != null && !interfaceLldpList.isEmpty()) {
+            Map<String, String> interfaceLldpMap = new HashMap<>();
+            for (InterfaceLldp interfaceLldp : interfaceLldpList) {
+                interfaceLldpMap.put(interfaceLldp.getLldpKey(), interfaceLldp.getLldpValue());
+            }
+            try {
+                ovsInterface.setLldp(ImmutableMap.copyOf(interfaceLldpMap));
+            } catch (NullPointerException e) {
+                LOG.warn("Incomplete OVSDB interface lldp");
+            }
+        }
+    }
+
     private void updateInterfaceOtherConfig(
             final OvsdbTerminationPointAugmentation terminationPoint,
             final Interface ovsInterface) {
index 597caa4eedea2e8ccdc7e00b570649729076e9bb..5dd16c64cd3b8c4df6b9e732bd474d43e53587d7 100644 (file)
@@ -43,6 +43,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIdsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceLldp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceLldpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceLldpKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceOtherConfigs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceOtherConfigsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
@@ -254,6 +257,7 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand {
         updateInterfaceExternalIds(interf, ovsdbTerminationPointBuilder);
         updateOptions(interf, ovsdbTerminationPointBuilder);
         updateInterfaceOtherConfig(interf, ovsdbTerminationPointBuilder);
+        updateInterfaceLldp(interf, ovsdbTerminationPointBuilder);
     }
 
     private void updateVlan(final Port port,
@@ -443,6 +447,26 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand {
         }
     }
 
+    private void updateInterfaceLldp(final Interface interf,
+            final OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointBuilder) {
+
+        Map<String, String> interfaceLldpMap = interf.getLldpColumn().getData();
+        if (interfaceLldpMap != null && !interfaceLldpMap.isEmpty()) {
+            List<InterfaceLldp> interfaceLldpList = new ArrayList<>();
+            for (String interfaceLldpKeyString : interfaceLldpMap.keySet()) {
+                String interfaceLldpValueString = interfaceLldpMap.get(interfaceLldpKeyString);
+                if (interfaceLldpKeyString != null && interfaceLldpValueString!=null) {
+                    interfaceLldpList.add(new InterfaceLldpBuilder()
+                            .setKey(new InterfaceLldpKey(interfaceLldpKeyString))
+                            .setLldpKey(interfaceLldpKeyString)
+                            .setLldpValue(interfaceLldpValueString)
+                            .build());
+                }
+            }
+            ovsdbTerminationPointBuilder.setInterfaceLldp(interfaceLldpList);
+        }
+    }
+
     private void updateInterfaceOtherConfig(final Interface interf,
             final OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointBuilder) {
 
index 52cb756e36b0e27d76431c4389975618eedee1d6..f85fd02df53509c0ff788d7cc26bf8ed9fa45390 100644 (file)
@@ -385,6 +385,7 @@ import com.google.common.util.concurrent.CheckedFuture;
         MemberModifier.suppress(MemberMatcher.method(OvsdbPortUpdateCommand.class, "updateInterfaceExternalIds", Interface.class, OvsdbTerminationPointAugmentationBuilder.class));
         MemberModifier.suppress(MemberMatcher.method(OvsdbPortUpdateCommand.class, "updateOptions", Interface.class, OvsdbTerminationPointAugmentationBuilder.class));
         MemberModifier.suppress(MemberMatcher.method(OvsdbPortUpdateCommand.class, "updateInterfaceOtherConfig", Interface.class, OvsdbTerminationPointAugmentationBuilder.class));
+        MemberModifier.suppress(MemberMatcher.method(OvsdbPortUpdateCommand.class, "updateInterfaceLldp", Interface.class, OvsdbTerminationPointAugmentationBuilder.class));
 
         Whitebox.invokeMethod(ovsdbPortUpdateCommand, "updateInterface", interf, OVSDB_INTERFACE_TYPE, ovsdbTerminationPointBuilder);
         verify(ovsdbTerminationPointBuilder).setInterfaceUuid(any(Uuid.class));
index 96dd3c4a5e75418572658d48aa9d41db2f4ecd59..ae980bb8236c51ab4d314a1ce2446deb71ae9d50 100644 (file)
@@ -83,6 +83,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIdsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceLldp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceLldpBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceOtherConfigs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceOtherConfigsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
@@ -1092,6 +1094,17 @@ public class SouthboundIT extends AbstractMdsalTestBase {
                 new InterfaceExternalIdsSouthboundHelper());
     }
 
+    /*
+     * Tests the CRUD operations for <code>Interface</code> <code>lldp</code>.
+     *
+     * @see <code>SouthboundIT.generateInterfaceLldpTestCases()</code> for specific test case information
+     */
+    @Test
+    public void testCRUDTerminationPointInterfaceLldp() throws InterruptedException {
+        testCRUDTerminationPoint(new SouthboundInterfaceLldpBuilder(), "TPInterfaceLldp",
+                new InterfaceLldpSouthboundHelper());
+    }
+
     /*
      * Tests the CRUD operations for <code>TerminationPoint</code> <code>options</code>.
      *
@@ -1657,6 +1670,28 @@ public class SouthboundIT extends AbstractMdsalTestBase {
         }
     }
 
+    private static final class SouthboundInterfaceLldpBuilder extends KeyValueBuilder<InterfaceLldp> {
+        @Override
+        protected Builder<InterfaceLldp> builder() {
+            return new InterfaceLldpBuilder();
+        }
+
+        @Override
+        protected void setKey(Builder<InterfaceLldp> builder, String key) {
+            ((InterfaceLldpBuilder) builder).setLldpKey((key));
+        }
+
+        @Override
+        protected void setValue(Builder<InterfaceLldp> builder, String value) {
+            ((InterfaceLldpBuilder) builder).setLldpValue(value);
+        }
+
+        @Override
+        protected boolean isValueMandatory() {
+            return true;
+        }
+    }
+
     private static final class SouthboundOptionsBuilder extends KeyValueBuilder<Options> {
         @Override
         protected Builder<Options> builder() {
@@ -1864,6 +1899,20 @@ public class SouthboundIT extends AbstractMdsalTestBase {
         }
     }
 
+    private static class InterfaceLldpSouthboundHelper implements
+    SouthboundTerminationPointHelper<InterfaceLldp> {
+        @Override
+        public void writeValues(
+                OvsdbTerminationPointAugmentationBuilder builder, List<InterfaceLldp> values) {
+            builder.setInterfaceLldp(values);
+        }
+
+        @Override
+        public List<InterfaceLldp> readValues(OvsdbTerminationPointAugmentation augmentation) {
+            return augmentation.getInterfaceLldp();
+        }
+    }
+
     private static class OptionsSouthboundHelper implements SouthboundTerminationPointHelper<Options> {
         @Override
         public void writeValues(