Bug 7563: Add config for inactivity_probe and max_backoff 93/50993/3
authorVishal Thapar <vishal.thapar@ericsson.com>
Wed, 25 Jan 2017 07:29:16 +0000 (12:59 +0530)
committerVishal Thapar <vishal.thapar@ericsson.com>
Wed, 25 Jan 2017 14:43:39 +0000 (20:13 +0530)
Fix v2.: Fixes wrong schema definition for MaxBackoff column in Controller
table. Adds two more exceptions to catch in
OvsdbOperationalCommandAggregator.

This adds support for inactivity_probe and max_backoff fields in
Controller entry. Changes to Util method for addBridge and setControllers
is done in a backward compatible way. Once Netvirt changes to new API,
older one will be removed.

Change-Id: Ia41afa0e6de9be28a50f0a408270ef854b3e1bbe
Signed-off-by: Vishal Thapar <vishal.thapar@ericsson.com>
schemas/openvswitch/src/main/java/org/opendaylight/ovsdb/schema/openvswitch/Controller.java
southbound/southbound-api/src/main/yang/ovsdb.yang
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundMapper.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/ControllerUpdateCommand.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbOperationalCommandAggregator.java
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java
utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java

index 4ebcf829d45d3e99acd73987bc3b633f2686a72b..bce5d75a04eab476108dfe361d1ffb1c9e2da55d 100644 (file)
@@ -104,10 +104,10 @@ public interface Controller extends TypedBaseTable<GenericTableSchema> {
     void setOtherConfig(Map<String, String> otherConfig);
 
     @TypedColumn (name = "max_backoff", method = MethodType.GETCOLUMN, fromVersion = "1.0.0")
-    Column<GenericTableSchema, Long> getMaxBackoffColumn();
+    Column<GenericTableSchema, Set<Long>> getMaxBackoffColumn();
 
     @TypedColumn (name = "max_backoff", method = MethodType.SETDATA, fromVersion = "1.0.0")
-    void setMaxBackoff(Long maxBackoff);
+    void setMaxBackoff(Set<Long> maxBackoff);
 
     @TypedColumn (name = "local_ip", method = MethodType.GETCOLUMN, fromVersion = "1.0.0")
     Column<GenericTableSchema, Set<String>> getLocalIpColumn();
index 2e1694c94810e1f83b389c9ca7fe87726e7bd4cc..a66129a540cd9aaa9ad05681c6d872352869f7a6 100755 (executable)
@@ -167,6 +167,21 @@ module ovsdb {
             leaf is-connected {
                 type boolean;
             }
+            leaf max_backoff {
+                description
+                    "Maximum  number  of  milliseconds  to  wait between
+                connection attempts";
+                type uint32 {
+                    range "1000..max";
+                }
+            }
+            leaf inactivity_probe {
+                description
+                    "Maximum number of milliseconds of idle time on connection
+                to controller before sending an inactivity probe message.
+                A value of 0 disables inactivity probes.";
+                type uint32;
+            }
 
         }
 
index 1dde7ac1d9562266f2945ecef9f4ff4ab418c22f..bfc9d3d2e1705f6cc60a1356846cb028d323c409 100644 (file)
@@ -331,14 +331,24 @@ public class SouthboundMapper {
             final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid uuid =
                     new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
                             .ietf.yang.types.rev130715.Uuid(controller.getUuid().toString());
+            ControllerEntryBuilder builder = new ControllerEntryBuilder();
 
-            controllerEntries.add(new ControllerEntryBuilder()
+            if (controller.getMaxBackoffColumn() != null && controller.getMaxBackoffColumn().getData() != null
+                    && !controller.getMaxBackoffColumn().getData().isEmpty()) {
+                builder.setMaxBackoff(controller.getMaxBackoffColumn().getData().iterator().next());
+            }
+            if (controller.getInactivityProbeColumn() != null && controller.getInactivityProbeColumn().getData() != null
+                    && !controller.getInactivityProbeColumn().getData().isEmpty()) {
+                builder.setInactivityProbe(controller.getInactivityProbeColumn().getData().iterator().next());
+            }
+            controllerEntries.add(builder
                     .setTarget(new Uri(targetString))
                     .setIsConnected(controller.getIsConnectedColumn().getData())
                     .setControllerUuid(uuid).build());
         }
     }
 
+    // This is not called from anywhere but test. Do we need this?
     public static Map<UUID, Controller> createOvsdbController(OvsdbBridgeAugmentation omn,DatabaseSchema dbSchema) {
         List<ControllerEntry> controllerEntries = omn.getControllerEntry();
         Map<UUID,Controller> controllerMap = new HashMap<>();
@@ -441,8 +451,8 @@ public class SouthboundMapper {
             final String targetString = manager.getTargetColumn().getData();
 
             final Map<String, String> statusAttributeMap =
-                            (manager.getStatusColumn() == null) ? null : manager.getStatusColumn().getData();
-            if ((statusAttributeMap != null) && statusAttributeMap.containsKey(N_CONNECTIONS_STR)) {
+                            manager.getStatusColumn() == null ? null : manager.getStatusColumn().getData();
+            if (statusAttributeMap != null && statusAttributeMap.containsKey(N_CONNECTIONS_STR)) {
                 String numberOfConnectionValueStr = statusAttributeMap.get(N_CONNECTIONS_STR);
                 numberOfConnections = Integer.parseInt(numberOfConnectionValueStr);
             } else {
index c2db5e42c9687c7537b97b2ae9a0ab42b4272a6d..416a1be71a651e8dcbc51368076bdfc2ee97c497 100644 (file)
@@ -68,9 +68,16 @@ public class ControllerUpdateCommand implements TransactCommand {
                         && ovsdbBridge.getBridgeName() != null
                         && entry.getValue() != null
                         && entry.getValue().getTarget() != null) {
+                    ControllerEntry controllerEntry = entry.getValue();
                     Controller controller =
                             TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Controller.class);
-                    controller.setTarget(entry.getValue().getTarget().getValue());
+                    controller.setTarget(controllerEntry.getTarget().getValue());
+                    if (controllerEntry.getMaxBackoff() != null) {
+                        controller.setMaxBackoff(Sets.newHashSet(controllerEntry.getMaxBackoff()));
+                    }
+                    if (controllerEntry.getInactivityProbe() != null) {
+                        controller.setInactivityProbe(Sets.newHashSet(controllerEntry.getInactivityProbe()));
+                    }
                     String controllerNamedUuidString = SouthboundMapper.getRandomUuid();
                     UUID controllerNamedUuid = new UUID(controllerNamedUuidString);
                     transaction.add(op.insert(controller).withId(controllerNamedUuidString));
index 8ceadfc1eb8201e9419f5f0e97d0cf00a1f2fbe1..1843b6faf87cb7c81e92e6676a5477b476267096 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.ovsdb.southbound.transactions.md;
 
 import java.util.ArrayList;
 import java.util.List;
-
+import java.util.NoSuchElementException;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.ovsdb.lib.message.TableUpdates;
 import org.opendaylight.ovsdb.lib.notation.Version;
@@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
 public class OvsdbOperationalCommandAggregator implements TransactionCommand {
 
     private static final Logger LOG = LoggerFactory.getLogger(OvsdbOperationalCommandAggregator.class);
-    private List<TransactionCommand> commands = new ArrayList<>();
+    private final List<TransactionCommand> commands = new ArrayList<>();
 
     public OvsdbOperationalCommandAggregator(InstanceIdentifierCodec instanceIdentifierCodec,
             OvsdbConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
@@ -57,7 +57,7 @@ public class OvsdbOperationalCommandAggregator implements TransactionCommand {
         for (TransactionCommand command: commands) {
             try {
                 command.execute(transaction);
-            } catch (NullPointerException e) {
+            } catch (NullPointerException | NoSuchElementException | ClassCastException e) {
                 LOG.warn("Exception trying to execute {}", command, e);
             }
         }
index db4c6ab0cc4fdca5a583789f590d38982bbc9efd..9e3b328ea8e25f15bc2fa0107d9f49bba92ac7b5 100644 (file)
@@ -166,6 +166,8 @@ public class SouthboundIT extends AbstractMdsalTestBase {
     private static final String FORMAT_STR = "%s_%s_%d";
     private static final Version AUTOATTACH_FROM_VERSION = Version.fromString("7.11.2");
     private static final Version IF_INDEX_FROM_VERSION = Version.fromString("7.2.1");
+    private static final Long MAX_BACKOFF = 10000L;
+    private static final Long INACTIVITY_PROBE = 30000L;
     private static String addressStr;
     private static int portNumber;
     private static String connectionType;
@@ -728,6 +730,12 @@ public class SouthboundIT extends AbstractMdsalTestBase {
                 if (entry.getTarget() != null) {
                     Assert.assertEquals(setUri.toString(), entry.getTarget().toString());
                 }
+                if (entry.getMaxBackoff() != null) {
+                    Assert.assertEquals(entry.getMaxBackoff(), MAX_BACKOFF);
+                }
+                if (entry.getInactivityProbe() != null) {
+                    Assert.assertEquals(entry.getInactivityProbe(),INACTIVITY_PROBE);
+                }
             }
         }
     }
@@ -736,6 +744,8 @@ public class SouthboundIT extends AbstractMdsalTestBase {
         List<ControllerEntry> controllerEntriesList = new ArrayList<>();
         controllerEntriesList.add(new ControllerEntryBuilder()
                 .setTarget(new Uri(controllerTarget))
+                .setMaxBackoff(MAX_BACKOFF)
+                .setInactivityProbe(INACTIVITY_PROBE)
                 .build());
         return controllerEntriesList;
     }
index 6e9e1df83453de97006176a8cacf2de5abedd5d2..8ddc65cf51811c5282b6534a9909a98783cd5a26 100644 (file)
@@ -589,6 +589,19 @@ public class SouthboundUtils {
      * @return success if the write to md-sal was successful
      */
     public boolean setBridgeController(Node ovsdbNode, String bridgeName, List<String> controllers) {
+        return setBridgeController(ovsdbNode, bridgeName, controllers, null, null);
+    }
+    /**
+     * Set the controllers of an existing bridge node
+     * @param ovsdbNode where the bridge is
+     * @param bridgeName Name of the bridge
+     * @param controllers controller strings
+     * @param maxBackoff Max backoff in milliseconds
+     * @param inactivityProbe inactivity probe in milliseconds
+     * @return success if the write to md-sal was successful
+     */
+    public boolean setBridgeController(Node ovsdbNode, String bridgeName, List<String> controllers,
+            Long maxBackoff, Long inactivityProbe) {
         LOG.debug("setBridgeController: ovsdbNode: {}, bridgeNode: {}, controller(s): {}",
                 ovsdbNode, bridgeName, controllers);
 
@@ -606,7 +619,7 @@ public class SouthboundUtils {
         List<ControllerEntry> newControllerEntries = new ArrayList<>();
         if(existingControllerEntries != null) {
             NEW_ENTRY_LOOP:
-            for (ControllerEntry newEntry : createControllerEntries(controllers)) {
+            for (ControllerEntry newEntry : createControllerEntries(controllers, maxBackoff, inactivityProbe)) {
                 for (ControllerEntry existingEntry : existingControllerEntries) {
                     if (newEntry.getTarget().equals(existingEntry.getTarget())) {
                         continue NEW_ENTRY_LOOP;
@@ -615,7 +628,7 @@ public class SouthboundUtils {
                 newControllerEntries.add(newEntry);
             }
         } else {
-            newControllerEntries = createControllerEntries(controllers);
+            newControllerEntries = createControllerEntries(controllers,maxBackoff, inactivityProbe);
         }
 
         if(newControllerEntries.isEmpty()) {
@@ -632,7 +645,13 @@ public class SouthboundUtils {
     }
 
     public boolean addBridge(Node ovsdbNode, String bridgeName, List<String> controllersStr,
-                             final Class<? extends DatapathTypeBase> dpType, String mac) {
+            final Class<? extends DatapathTypeBase> dpType, String mac) {
+        return addBridge(ovsdbNode, bridgeName, controllersStr, dpType, mac, null, null);
+    }
+
+    public boolean addBridge(Node ovsdbNode, String bridgeName, List<String> controllersStr,
+                             final Class<? extends DatapathTypeBase> dpType, String mac,
+                             Long maxBackoff, Long inactivityProbe) {
         boolean result;
 
         LOG.info("addBridge: node: {}, bridgeName: {}, controller(s): {}", ovsdbNode, bridgeName, controllersStr);
@@ -643,7 +662,8 @@ public class SouthboundUtils {
             NodeId bridgeNodeId = createManagedNodeId(bridgeIid);
             bridgeNodeBuilder.setNodeId(bridgeNodeId);
             OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
-            ovsdbBridgeAugmentationBuilder.setControllerEntry(createControllerEntries(controllersStr));
+            ovsdbBridgeAugmentationBuilder.setControllerEntry(createControllerEntries(
+                    controllersStr, maxBackoff, inactivityProbe));
             ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName));
             ovsdbBridgeAugmentationBuilder.setProtocolEntry(createMdsalProtocols());
             ovsdbBridgeAugmentationBuilder.setFailMode( OVSDB_FAIL_MODE_MAP.inverse().get("secure"));
@@ -1001,12 +1021,19 @@ public class SouthboundUtils {
         return found;
     }
 
-    private List<ControllerEntry> createControllerEntries(List<String> controllersStr) {
+    private List<ControllerEntry> createControllerEntries(List<String> controllersStr,
+            Long maxBackoff, Long inactivityProbe) {
         List<ControllerEntry> controllerEntries = new ArrayList<>();
         if (controllersStr != null) {
             for (String controllerStr : controllersStr) {
                 ControllerEntryBuilder controllerEntryBuilder = new ControllerEntryBuilder();
                 controllerEntryBuilder.setTarget(new Uri(controllerStr));
+                if (maxBackoff != null) {
+                    controllerEntryBuilder.setMaxBackoff(maxBackoff);
+                }
+                if (inactivityProbe != null) {
+                    controllerEntryBuilder.setInactivityProbe(inactivityProbe);
+                }
                 controllerEntries.add(controllerEntryBuilder.build());
             }
         }