Bug 7563: Add an ability to configure inactivity_probe for OVS 43/50643/1
authorVishal Thapar <vishal.thapar@ericsson.com>
Wed, 18 Jan 2017 21:37:45 +0000 (03:07 +0530)
committerVishal Thapar <vishal.thapar@ericsson.com>
Wed, 18 Jan 2017 21:41:56 +0000 (03:11 +0530)
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: Ib7fbb1f6ac70b745264ca6fa191b3f382f3580d0
Signed-off-by: Vishal Thapar <vishal.thapar@ericsson.com>
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-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 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..c89b1e590ec356fb2b84bf056777b6169ad39916 100644 (file)
@@ -331,14 +331,23 @@ 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());
-
-            controllerEntries.add(new ControllerEntryBuilder()
+            ControllerEntryBuilder builder = new ControllerEntryBuilder();
+            if (controller.getMaxBackoffColumn() != null && controller.getMaxBackoffColumn().getData() != null) {
+                builder.setMaxBackoff(controller.getMaxBackoffColumn().getData());
+            }
+            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 +450,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..e57fc1d20ab0b56b386ff983fee161b102e284be 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(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 db4c6ab0cc4fdca5a583789f590d38982bbc9efd..51db6e88b1253208e24adf28d76185eea6fca32e 100644 (file)
@@ -131,7 +131,6 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
@@ -166,6 +165,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;
@@ -251,10 +252,10 @@ public class SouthboundIT extends AbstractMdsalTestBase {
             synchronized (this) {
                 long _start = System.currentTimeMillis();
                 LOG.info("Waiting for {} DataChanged creation on {}", type, iid);
-                while (!isCreated(iid) && (System.currentTimeMillis() - _start) < timeout) {
+                while (!isCreated(iid) && System.currentTimeMillis() - _start < timeout) {
                     wait(RETRY_WAIT);
                 }
-                LOG.info("Woke up, waited {}ms for creation of {}", (System.currentTimeMillis() - _start), iid);
+                LOG.info("Woke up, waited {}ms for creation of {}", System.currentTimeMillis() - _start, iid);
             }
         }
 
@@ -262,10 +263,10 @@ public class SouthboundIT extends AbstractMdsalTestBase {
             synchronized (this) {
                 long _start = System.currentTimeMillis();
                 LOG.info("Waiting for {} DataChanged deletion on {}", type, iid);
-                while (!isRemoved(iid) && (System.currentTimeMillis() - _start) < timeout) {
+                while (!isRemoved(iid) && System.currentTimeMillis() - _start < timeout) {
                     wait(RETRY_WAIT);
                 }
-                LOG.info("Woke up, waited {}ms for deletion of {}", (System.currentTimeMillis() - _start), iid);
+                LOG.info("Woke up, waited {}ms for deletion of {}", System.currentTimeMillis() - _start, iid);
             }
         }
 
@@ -273,15 +274,16 @@ public class SouthboundIT extends AbstractMdsalTestBase {
             synchronized (this) {
                 long _start = System.currentTimeMillis();
                 LOG.info("Waiting for {} DataChanged update on {}", type, iid);
-                while (!isUpdated(iid) && (System.currentTimeMillis() - _start) < timeout) {
+                while (!isUpdated(iid) && System.currentTimeMillis() - _start < timeout) {
                     wait(RETRY_WAIT);
                 }
-                LOG.info("Woke up, waited {}ms for update of {}", (System.currentTimeMillis() - _start), iid);
+                LOG.info("Woke up, waited {}ms for update of {}", System.currentTimeMillis() - _start, iid);
             }
         }
 
     }
 
+    @Override
     @Configuration
     public Option[] config() {
         Option[] options = super.config();
@@ -555,10 +557,10 @@ public class SouthboundIT extends AbstractMdsalTestBase {
             long _start = System.currentTimeMillis();
             LOG.info("Waiting for OPERATIONAL DataChanged creation on {}", iid);
             while (!OPERATIONAL_LISTENER.isCreated(
-                    iid) && (System.currentTimeMillis() - _start) < OVSDB_ROUNDTRIP_TIMEOUT) {
+                    iid) && System.currentTimeMillis() - _start < OVSDB_ROUNDTRIP_TIMEOUT) {
                 OPERATIONAL_LISTENER.wait(OVSDB_UPDATE_TIMEOUT);
             }
-            LOG.info("Woke up, waited {} for creation of {}", (System.currentTimeMillis() - _start), iid);
+            LOG.info("Woke up, waited {} for creation of {}", System.currentTimeMillis() - _start, iid);
         }
     }
 
@@ -567,10 +569,10 @@ public class SouthboundIT extends AbstractMdsalTestBase {
             long _start = System.currentTimeMillis();
             LOG.info("Waiting for OPERATIONAL DataChanged deletion on {}", iid);
             while (!OPERATIONAL_LISTENER.isRemoved(
-                    iid) && (System.currentTimeMillis() - _start) < OVSDB_ROUNDTRIP_TIMEOUT) {
+                    iid) && System.currentTimeMillis() - _start < OVSDB_ROUNDTRIP_TIMEOUT) {
                 OPERATIONAL_LISTENER.wait(OVSDB_UPDATE_TIMEOUT);
             }
-            LOG.info("Woke up, waited {} for deletion of {}", (System.currentTimeMillis() - _start), iid);
+            LOG.info("Woke up, waited {} for deletion of {}", System.currentTimeMillis() - _start, iid);
         }
     }
 
@@ -579,10 +581,10 @@ public class SouthboundIT extends AbstractMdsalTestBase {
             long _start = System.currentTimeMillis();
             LOG.info("Waiting for OPERATIONAL DataChanged update on {}", iid);
             while (!OPERATIONAL_LISTENER.isUpdated(
-                    iid) && (System.currentTimeMillis() - _start) < OVSDB_ROUNDTRIP_TIMEOUT) {
+                    iid) && System.currentTimeMillis() - _start < OVSDB_ROUNDTRIP_TIMEOUT) {
                 OPERATIONAL_LISTENER.wait(OVSDB_UPDATE_TIMEOUT);
             }
-            LOG.info("Woke up, waited {} for update of {}", (System.currentTimeMillis() - _start), iid);
+            LOG.info("Woke up, waited {} for update of {}", System.currentTimeMillis() - _start, iid);
         }
     }
 
@@ -629,7 +631,7 @@ public class SouthboundIT extends AbstractMdsalTestBase {
                         Assert.assertEquals(dpType, bridge.getDatapathType());
 
                         // Add port for all dpdk interface types (dpdkvhost not supported in existing dpdk ovs)
-                        List<String> dpdkTypes = new ArrayList<String>();
+                        List<String> dpdkTypes = new ArrayList<>();
                         dpdkTypes.add("dpdk");
                         dpdkTypes.add("dpdkr");
                         dpdkTypes.add("dpdkvhostuser");
@@ -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;
     }
@@ -2109,7 +2119,7 @@ public class SouthboundIT extends AbstractMdsalTestBase {
         ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
         OvsdbNodeAugmentation ovsdbNodeAugmentation;
         Uri qosUri = new Uri("QOS-ROW");
-        List<String> typeList = new ArrayList<String>();
+        List<String> typeList = new ArrayList<>();
         typeList.add(SouthboundConstants.QOS_LINUX_HTB);
         typeList.add(SouthboundConstants.QOS_LINUX_HFSC);
 
@@ -2175,8 +2185,9 @@ public class SouthboundIT extends AbstractMdsalTestBase {
 
     private Queues getQueue(Uri queueId, OvsdbNodeAugmentation node) {
         for (Queues queue : node.getQueues()) {
-            if (queue.getKey().getQueueId().getValue().equals(queueId.getValue()))
+            if (queue.getKey().getQueueId().getValue().equals(queueId.getValue())) {
                 return queue;
+            }
         }
         return null;
     }
@@ -2212,8 +2223,9 @@ public class SouthboundIT extends AbstractMdsalTestBase {
 
     private QosEntries getQos(Uri qosId, OvsdbNodeAugmentation node) {
         for (QosEntries qos : node.getQosEntries()) {
-            if (qos.getKey().getQosId().equals(qosId))
+            if (qos.getKey().getQosId().equals(qosId)) {
                 return qos;
+            }
         }
         return null;
     }
@@ -2835,7 +2847,7 @@ public class SouthboundIT extends AbstractMdsalTestBase {
 
         @Override
         protected void setKey(Builder<InterfaceLldp> builder, String key) {
-            ((InterfaceLldpBuilder) builder).setLldpKey((key));
+            ((InterfaceLldpBuilder) builder).setLldpKey(key);
         }
 
         @Override
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());
             }
         }