X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FL2Util.py;h=0d34ce3e41adfab0028d9a5365ea8231d9d633bf;hp=b39515dceeddba03f7c9a2ffc98506698e985730;hb=476ea70ea42ccd6f0486fa799058d47647bc0942;hpb=1254d80a0b64985de2816eff5ef79e3e22cde972 diff --git a/resources/libraries/python/L2Util.py b/resources/libraries/python/L2Util.py index b39515dcee..0d34ce3e41 100644 --- a/resources/libraries/python/L2Util.py +++ b/resources/libraries/python/L2Util.py @@ -15,8 +15,8 @@ from robot.api.deco import keyword from resources.libraries.python.topology import Topology -from resources.libraries.python.VatExecutor import VatExecutor - +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) @@ -153,3 +156,65 @@ class L2Util(object): sw_if_id2=sw_if_index2, bd_id=bd_id, learn=int(learn)) + + @staticmethod + def vpp_setup_bidirectional_cross_connect(node, interface1, interface2): + """Create bidirectional cross-connect between 2 interfaces on vpp node. + + :param node: Node to add bidirectional cross-connect + :param interface1: first interface name or sw_if_index + :param interface2: second interface name or sw_if_index + :type node: dict + :type interface1: str or int + :type interface2: str or int + """ + + if isinstance(interface1, basestring): + sw_iface1 = Topology().get_interface_sw_index(node, interface1) + else: + sw_iface1 = interface1 + + if isinstance(interface2, basestring): + sw_iface2 = Topology().get_interface_sw_index(node, interface2) + else: + sw_iface2 = interface2 + + with VatTerminal(node) as vat: + vat.vat_terminal_exec_cmd_from_template('l2_xconnect.vat', + interface1=sw_iface1, + interface2=sw_iface2) + 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)