From: Jiri Pirko jiri@mellanox.com
Kernel exposes an interface primary used by bridge to work with internal VLAN implementation. However, other devices (for example SR-IOV drivers) implement this as well making this not bridge-specific.
Allow task to work with the bridge VLAN settings. This is implemented simply by calling "bridge" utility. This may be later on changed to pyroute2 implementation, alas it does not implement PF_BRIDGE Netlink at the moment.
Signed-off-by: Jiri Pirko jiri@mellanox.com --- lnst/Controller/Machine.py | 8 ++++++++ lnst/Controller/Task.py | 12 ++++++++++++ lnst/Slave/BridgeTool.py | 36 ++++++++++++++++++++++++++++++++++++ lnst/Slave/NetTestSlave.py | 19 +++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 lnst/Slave/BridgeTool.py
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py index 8cfe5bf..b457c3c 100644 --- a/lnst/Controller/Machine.py +++ b/lnst/Controller/Machine.py @@ -764,6 +764,14 @@ class Interface(object): "return_if_netns", self.get_id()) self._configured = False
+ def add_br_vlan(self, br_vlan_info): + self._machine._rpc_call_x(self._netns, "add_br_vlan", + self._id, br_vlan_info) + + def del_br_vlan(self, br_vlan_info): + self._machine._rpc_call_x(self._netns, "del_br_vlan", + self._id, br_vlan_info) + class StaticInterface(Interface): """ Static interface
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py index 4aeed17..3c5b71d 100644 --- a/lnst/Controller/Task.py +++ b/lnst/Controller/Task.py @@ -508,6 +508,18 @@ class InterfaceAPI(object): def destroy(self): self._host._remove_iface(self)
+ def add_br_vlan(_self, vlan_tci, pvid=False, untagged=False, + self=False, master=False): + _self._if.add_br_vlan({"vlan_id": vlan_tci, "pvid": pvid, + "untagged": untagged, + "self": self, "master": master}) + + def del_br_vlan(_self, vlan_tci, pvid=False, untagged=False, + self=False, master=False): + _self._if.del_br_vlan({"vlan_id": vlan_tci, "pvid": pvid, + "untagged": untagged, + "self": self, "master": master}) + class ModuleAPI(object): """ An API class representing a module. """
diff --git a/lnst/Slave/BridgeTool.py b/lnst/Slave/BridgeTool.py new file mode 100644 index 0000000..017ed1e --- /dev/null +++ b/lnst/Slave/BridgeTool.py @@ -0,0 +1,36 @@ +""" +This module defines a class useful to work with "bridge" tool. + +Copyright 2015 Mellanox Technologies. All rights reserved. +Licensed under the GNU General Public License, version 2 as +published by the Free Software Foundation; see COPYING for details. +""" + +__author__ = """ +jiri@mellanox.com (Jiri Pirko) +""" + +from lnst.Common.ExecCmd import exec_cmd + +class BridgeTool: + def __init__(self, dev_name): + self._dev_name = dev_name + + def _add_del_vlan(self, op, br_vlan_info): + cmd = "bridge vlan %s dev %s vid %d" % (op, self._dev_name, + br_vlan_info["vlan_id"]) + if br_vlan_info["pvid"]: + cmd += " pvid" + if br_vlan_info["untagged"]: + cmd += " untagged" + if br_vlan_info["self"]: + cmd += " self" + if br_vlan_info["master"]: + cmd += " master" + exec_cmd(cmd) + + def add_vlan(self, br_vlan_info): + return self._add_del_vlan("add", br_vlan_info) + + def del_vlan(self, br_vlan_info): + return self._add_del_vlan("del", br_vlan_info) diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py index 9104e31..df28a6a 100644 --- a/lnst/Slave/NetTestSlave.py +++ b/lnst/Slave/NetTestSlave.py @@ -36,6 +36,7 @@ from lnst.Common.ConnectionHandler import ConnectionHandler from lnst.Common.Config import lnst_config from lnst.Common.Config import DefaultRPCPort from lnst.Slave.InterfaceManager import InterfaceManager +from lnst.Slave.BridgeTool import BridgeTool
class SlaveMethods: ''' @@ -692,6 +693,24 @@ class SlaveMethods: device.set_netns(None) return True
+ def add_br_vlan(self, if_id, br_vlan_info): + dev = self._if_manager.get_mapped_device(if_id) + if not dev: + logging.error("Device with id '%s' not found." % if_id) + return False + brt = BridgeTool(dev.get_name()) + brt.add_vlan(br_vlan_info) + return True + + def del_br_vlan(self, if_id, br_vlan_info): + dev = self._if_manager.get_mapped_device(if_id) + if not dev: + logging.error("Device with id '%s' not found." % if_id) + return False + brt = BridgeTool(dev.get_name()) + brt.del_vlan(br_vlan_info) + return True + class ServerHandler(ConnectionHandler): def __init__(self, addr): super(ServerHandler, self).__init__()