summaryrefslogtreecommitdiffstats
path: root/vstf/vstf/agent/env/vswitch_plugins/bridge_plugin.py
blob: 252f190d5749f9aefd6594ddb397dc1bc655899e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Created on 2015-10-12

@author: y00228926
"""
from vstf.agent.env.vswitch_plugins import model
from vstf.common.utils import check_call, get_eth_by_bdf, check_output


class BridgePlugin(model.VswitchPlugin):
    def __init__(self):
        pass

    def clean(self):
        """clean brs created before.

        """
        out = check_output(r"brctl show | grep -v '^\s' | awk '{print $1}'|sed '1,1d'", shell=True)
        print out
        for br in out.split():
            if br != 'br0':
                self._del_br(br)

        return True

    def init(self):
        pass

    def _del_br(self, name):
        check_call('ip link set dev %s down' % name, shell=True)
        check_call('brctl delbr %s' % name, shell=True)

    def create_br(self, br_cfg):
        """Create a bridge(virtual switch). Return True for success, return False for failure.

        :param dict    br_cfg: configuration for bridge creation like
                {
                    "name": "br1",
                    "uplinks": [
                        {
                            "bdf": "04:00.0",
                        },
                        {
                            "bdf": "04:00.1",
                        }
                    ]
                }

        """
        name, uplinks = br_cfg['name'], br_cfg['uplinks']
        check_call("brctl addbr %s" % name, shell=True)
        for uplink in uplinks:
            device = get_eth_by_bdf(uplink['bdf'])
            check_call("ip link set dev %s up" % device, shell=True)
            check_call("brctl addif %s %s" % (name, device), shell=True)
        check_call("ip link set dev %s up" % name, shell=True)
        return True

    def set_tap_vid(self, tap_cfg):
        """linux bridge doesn't support vlan id setting.
        """
        return True

    def set_fastlink(self, br_cfg):
        """linux bridge doesn't support openflow protocol.
        """
        return True