aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/extvswitchflctl.py129
-rw-r--r--tools/pkt_fwd/dummy.py62
2 files changed, 191 insertions, 0 deletions
diff --git a/tools/extvswitchflctl.py b/tools/extvswitchflctl.py
new file mode 100644
index 00000000..56eeafd0
--- /dev/null
+++ b/tools/extvswitchflctl.py
@@ -0,0 +1,129 @@
+"""
+Tool to configure flows for Kubernetes Usecases.
+"""
+
+from tools import tasks
+from conf import settings as S
+
+class ExtVswitchFlowCtl(tasks.Process):
+ """
+ Virtual Switch Flow Control
+ """
+ def __init__(self):
+ """
+ Initialization
+ """
+ super().__init__()
+ self._vpp_ctl = ['sudo', S.getValue('EXT_VSWITCH_VPP_FLOWCTL')]
+ self._ovs_ctl = ['sudo', S.getValue('EXT_VSWITCH_OVS_FLOWCTL')]
+
+ def get_vpp_interfaces(self):
+ """
+ Get VPP interfaces Names
+ """
+ ifargs = ['show', 'interface']
+ output = self.run_vppctl(ifargs)
+ ifaces = output[0].split('\n')
+ pifaces = []
+ vifaces = []
+ for iface in ifaces:
+ name = iface.split()[0]
+ if 'Name' in name or 'local' in name:
+ continue
+ if 'Ethernet' in name:
+ pifaces.append(name)
+ if 'memif' in name:
+ vifaces.append(name)
+ assert len(vifaces) == 2 or len(vifaces) == 4
+ assert len(pifaces) == 2
+ assert pifaces[0][:-1] in pifaces[1][:-1]
+ return pifaces, vifaces
+
+ def add_connections(self):
+ """
+ Add Connections of OVS or VPP
+ """
+ if 'VPP' in S.getValue('EXT_VSWITCH_TYPE'):
+ self.add_vpp_xconnect()
+ else:
+ self.add_ovs_xconnect()
+
+ def add_ovs_xconnect(self):
+ """
+ Add connections to OVS
+ """
+ entries = [['--timeout', '10', '-o', 'OpenFlow13', 'add-flow',
+ S.getValue('EXT_VSWITCH_OVS_BRIDGE'),
+ 'in_port=1,idle_timeout=0,action=output:3'],
+ ['--timeout', '10', '-o', 'OpenFlow13', 'add-flow',
+ S.getValue('EXT_VSWITCH_OVS_BRIDGE'),
+ 'in_port=3,idle_timeout=0,action=output:1'],
+ ['--timeout', '10', '-o', 'OpenFlow13', 'add-flow',
+ S.getValue('EXT_VSWITCH_OVS_BRIDGE'),
+ 'in_port=2,idle_timeout=0,action=output:4'],
+ ['--timeout', '10', '-o', 'OpenFlow13', 'add-flow',
+ S.getValue('EXT_VSWITCH_OVS_BRIDGE'),
+ 'in_port=4,idle_timeout=0,action=output:2']]
+ for entry in entries:
+ self.run_ovsfctl(entry)
+
+ def add_vpp_xconnect(self):
+ """
+ Add Connections to VPP
+ """
+ pifaces, vifaces = self.get_vpp_interfaces()
+ # Bring Physical interface up - In case it is down.
+ for piface in pifaces:
+ ifargs = ['set', 'interface', 'state', piface, 'up']
+ self.run_vppctl(ifargs)
+ if len(vifaces) == 2:
+ entries = [['test', 'l2patch', 'rx',
+ pifaces[0], 'tx', vifaces[0]],
+ ['test', 'l2patch', 'rx',
+ vifaces[0], 'tx', pifaces[0]],
+ ['test', 'l2patch', 'rx',
+ pifaces[1], 'tx', vifaces[1]],
+ ['test', 'l2patch', 'rx',
+ vifaces[1], 'tx', pifaces[1]]]
+ elif len(vifaces) == 4:
+ entries = [['test', 'l2patch', 'rx',
+ pifaces[0], 'tx', vifaces[0]],
+ ['test', 'l2patch', 'rx',
+ vifaces[0], 'tx', pifaces[0]],
+ ['test', 'l2patch', 'rx',
+ vifaces[1], 'tx', vifaces[2]],
+ ['test', 'l2patch', 'rx',
+ vifaces[2], 'tx', vifaces[1]],
+ ['test', 'l2patch', 'rx',
+ pifaces[1], 'tx', vifaces[3]],
+ ['test', 'l2patch', 'rx',
+ vifaces[3], 'tx', pifaces[1]]]
+
+ for entry in entries:
+ self.run_vppctl(entry)
+
+ def run_ovsfctl(self, args, check_error=False):
+ """Run ``ovs-ofctl`` with supplied arguments.
+
+ :param args: Arguments to pass to ``vppctl``
+ :param check_error: Throw exception on error
+
+ :return: None
+ """
+ cmd = self._ovs_ctl + args
+ return tasks.run_task(cmd, self._logger,
+ 'Running ovs-ofctl...',
+ check_error)
+
+ def run_vppctl(self, args, check_error=False):
+ """Run ``vppctl`` with supplied arguments.
+
+ :param args: Arguments to pass to ``vppctl``
+ :param check_error: Throw exception on error
+
+ :return: None
+ """
+ cmd = self._vpp_ctl + args
+ return tasks.run_task(cmd, self._logger,
+ 'Running vppctl...',
+ check_error)
diff --git a/tools/pkt_fwd/dummy.py b/tools/pkt_fwd/dummy.py
new file mode 100644
index 00000000..97ffc666
--- /dev/null
+++ b/tools/pkt_fwd/dummy.py
@@ -0,0 +1,62 @@
+# Copyright 2021 Spirent Communications
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""VSPERF Dummy Pkt-Fwd.
+"""
+
+import logging
+from conf import settings
+
+_LOGGER = logging.getLogger(__name__)
+
+class Dummy(IPktFwd):
+ """Dummy implementation
+
+ """
+
+ _logger = logging.getLogger()
+
+ def __init__(self, guest=False):
+ self._logger.info("Initializing Dummy...")
+
+ def start(self):
+ """See IPktFwd for general description
+
+ Activates testpmd.
+ """
+ self._logger.info("Starting Dummy...")
+
+ def start_for_guest(self):
+ """See IPktFwd for general description
+
+ Activates testpmd for guest config
+ """
+ self._logger.info("Starting Dummy for one guest...")
+
+ def stop(self):
+ """See IPktFwd for general description
+
+ Kills testpmd.
+ """
+ self._logger.info("Stopping Dummy ....")
+
+ # Method could be a function
+ # pylint: disable=no-self-use
+ def get_version(self):
+ """
+ Get product version
+ :return: None
+ """
+ # No way to read Dummy version
+ return []