aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/L2Util.py
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2016-03-22 09:04:07 +0100
committerGerrit Code Review <gerrit@fd.io>2016-03-30 10:08:19 +0000
commit476ea70ea42ccd6f0486fa799058d47647bc0942 (patch)
tree6c1b69b6b4aa382a337ac5b501273c6848bbf3d0 /resources/libraries/python/L2Util.py
parent20f5ad2f804e810789838126b909f1866bec6334 (diff)
Add linux_add/del_bridge and modify vpp_add_l2fib_entry
linux_add_bridge - bridge two interfaces on linux node linux_del_bridge - delete bridge from linux node vpp_add_l2fib_entry - param interface should be interface name or sw_if_index Change-Id: Ia8030e24a0afe088df0dcb6c65a85ed341224206 Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'resources/libraries/python/L2Util.py')
-rw-r--r--resources/libraries/python/L2Util.py43
1 files changed, 39 insertions, 4 deletions
diff --git a/resources/libraries/python/L2Util.py b/resources/libraries/python/L2Util.py
index 4dc230cf16..0d34ce3e41 100644
--- a/resources/libraries/python/L2Util.py
+++ b/resources/libraries/python/L2Util.py
@@ -16,7 +16,7 @@
from robot.api.deco import keyword
from resources.libraries.python.topology import Topology
from resources.libraries.python.VatExecutor import VatExecutor, VatTerminal
-
+from resources.libraries.python.ssh import exec_cmd_no_error
class L2Util(object):
"""Utilities for l2 configuration"""
@@ -27,14 +27,17 @@ class L2Util(object):
:param node: Node to add L2FIB entry on.
:param mac: Destination mac address.
- :param interface: Interface name.
+ :param interface: Interface name or sw_if_index.
:param bd_id: Bridge domain id.
:type node: dict
:type mac: str
- :type interface: str
+ :type interface: str or int
:type bd_id: int
"""
- sw_if_index = Topology.get_interface_sw_index(node, interface)
+ if isinstance(interface, basestring):
+ sw_if_index = Topology.get_interface_sw_index(node, interface)
+ else:
+ sw_if_index = interface
VatExecutor.cmd_from_template(node, "add_l2_fib_entry.vat",
mac=mac, bd=bd_id,
interface=sw_if_index)
@@ -183,3 +186,35 @@ class L2Util(object):
vat.vat_terminal_exec_cmd_from_template('l2_xconnect.vat',
interface1=sw_iface2,
interface2=sw_iface1)
+
+ @staticmethod
+ def linux_add_bridge(node, br_name, if_1, if_2):
+ """Bridge two interfaces on linux node.
+
+ :param node: Node to add bridge on.
+ :param br_name: Bridge name.
+ :param if_1: First interface to be added to the bridge.
+ :param if_2: Second interface to be added to the bridge.
+ :type node: dict
+ :type br_name: str
+ :type if_1: str
+ :type if_2: str
+ """
+ cmd = 'brctl addbr {0}'.format(br_name)
+ exec_cmd_no_error(node, cmd, sudo=True)
+ cmd = 'brctl addif {0} {1}'.format(br_name, if_1)
+ exec_cmd_no_error(node, cmd, sudo=True)
+ cmd = 'brctl addif {0} {1}'.format(br_name, if_2)
+ exec_cmd_no_error(node, cmd, sudo=True)
+
+ @staticmethod
+ def linux_del_bridge(node, br_name):
+ """Delete bridge from linux node.
+
+ :param node: Node to delete bridge from.
+ :param br_name: Bridge name.
+ .. note:: The network interface corresponding to the bridge must be
+ down before it can be deleted!
+ """
+ cmd = 'brctl delbr {0}'.format(br_name)
+ exec_cmd_no_error(node, cmd, sudo=True)