rstp-stp: Add basic functions for stp/rstp enable on ovs 37/16137/3
authorChristian Trautman <ctrautma@redhat.com>
Wed, 29 Jun 2016 20:58:36 +0000 (16:58 -0400)
committerChristian Trautman <ctrautma@redhat.com>
Thu, 7 Jul 2016 17:39:11 +0000 (13:39 -0400)
Add basic functions to enable/disable spanning tree
protocols on the bridge.

Also adds bridge info function to retrieve other bridge
information.

JIRA: VSPERF-314

Change-Id: Ic72c5a2a9d16aab1b95428ce37042a5b536481aa
Signed-off-by: Christian Trautman <ctrautma@redhat.com>
src/ovs/ofctl.py
vswitches/ovs.py

index 1ee4813..d7a2b32 100644 (file)
@@ -349,6 +349,37 @@ class OFBridge(OFBase):
         self.logger.debug('dump flows')
         self.run_ofctl(['dump-flows', self.br_name], timeout=120)
 
+    def set_stp(self, enable=True):
+        """
+        Set stp status
+        :param enable: Boolean to enable or disable stp
+        :return: None
+        """
+        self.logger.debug(
+            'Setting stp on bridge to %s', 'on' if enable else 'off')
+        self.run_vsctl(
+            ['set', 'Bridge', self.br_name, 'stp_enable={}'.format(
+                'true' if enable else 'false')])
+
+    def set_rstp(self, enable=True):
+        """
+        Set rstp status
+        :param enable: Boolean to enable or disable rstp
+        :return: None
+        """
+        self.logger.debug(
+            'Setting rstp on bridge to %s', 'on' if enable else 'off')
+        self.run_vsctl(
+            ['set', 'Bridge', self.br_name, 'rstp_enable={}'.format(
+                'true' if enable else 'false')])
+
+    def bridge_info(self):
+        """
+        Get bridge info
+        :return: Returns bridge info from list bridge command
+        """
+        return self.run_vsctl(['list', 'bridge', self.br_name])
+
 #
 # helper functions
 #
index 555d7de..115ab19 100644 (file)
 """
 
 import logging
-import re
 import os
-import time
 import pexpect
+import re
+import time
+
 from conf import settings
-from vswitches.vswitch import IVSwitch
 from src.ovs import OFBridge, flow_key, flow_match
 from tools import tasks
+from vswitches.vswitch import IVSwitch
 
 _OVS_VAR_DIR = settings.getValue('OVS_VAR_DIR')
 _OVS_ETC_DIR = settings.getValue('OVS_ETC_DIR')
 
+
 class IVSwitchOvs(IVSwitch, tasks.Process):
     """Open vSwitch base class implementation
 
@@ -193,6 +195,50 @@ class IVSwitchOvs(IVSwitch, tasks.Process):
             cnt = 0
         return cnt
 
+    def disable_stp(self, switch_name):
+        """
+        Disable stp protocol on the bridge
+        :param switch_name: bridge to disable stp
+        :return: None
+        """
+        bridge = self._bridges[switch_name]
+        bridge.set_stp(False)
+        self._logger.info('Sleeping for 50 secs to allow stp to stop.')
+        time.sleep(50)  # needs time to disable
+
+    def enable_stp(self, switch_name):
+        """
+        Enable stp protocol on the bridge
+        :param switch_name: bridge to enable stp
+        :return: None
+        """
+        bridge = self._bridges[switch_name]
+        bridge.set_stp(True)
+        self._logger.info('Sleeping for 50 secs to allow stp to start.')
+        time.sleep(50)  # needs time to enable
+
+    def disable_rstp(self, switch_name):
+        """
+        Disable rstp on the bridge
+        :param switch_name: bridge to disable rstp
+        :return: None
+        """
+        bridge = self._bridges[switch_name]
+        bridge.set_rstp(False)
+        self._logger.info('Sleeping for 15 secs to allow rstp to stop.')
+        time.sleep(15)  # needs time to disable
+
+    def enable_rstp(self, switch_name):
+        """
+        Enable rstp on the bridge
+        :param switch_name: bridge to enable rstp
+        :return: None
+        """
+        bridge = self._bridges[switch_name]
+        bridge.set_rstp(True)
+        self._logger.info('Sleeping for 15 secs to allow rstp to start.')
+        time.sleep(15)  # needs time to enable
+
     def kill(self, signal='-15', sleep=10):
         """Kill ``ovs-vswitchd`` and ``ovs-ovsdb`` instances if they are alive.
 
@@ -354,3 +400,27 @@ class IVSwitchOvs(IVSwitch, tasks.Process):
         """ Validate call of flow dump
         """
         return True
+
+    def validate_disable_rstp(self, result, switch_name):
+        """ Validate rstp disable
+        """
+        bridge = self._bridges[switch_name]
+        return 'rstp_enable         : false' in ''.join(bridge.bridge_info())
+
+    def validate_enable_rstp(self, result, switch_name):
+        """ Validate rstp enable
+        """
+        bridge = self._bridges[switch_name]
+        return 'rstp_enable         : true' in ''.join(bridge.bridge_info())
+
+    def validate_disable_stp(self, result, switch_name):
+        """ Validate stp disable
+        """
+        bridge = self._bridges[switch_name]
+        return 'stp_enable          : false' in ''.join(bridge.bridge_info())
+
+    def validate_enable_stp(self, result, switch_name):
+        """ Validate stp enable
+        """
+        bridge = self._bridges[switch_name]
+        return 'stp_enable          : true' in ''.join(bridge.bridge_info())