Upload the contribution of vstf as bottleneck network framework.
[bottlenecks.git] / vstf / vstf / agent / env / vswitch_plugins / bridge_plugin.py
1 """
2 Created on 2015-10-12
3
4 @author: y00228926
5 """
6 from vstf.agent.env.vswitch_plugins import model
7 from vstf.common.utils import check_call, get_eth_by_bdf, check_output
8
9
10 class BridgePlugin(model.VswitchPlugin):
11     def __init__(self):
12         pass
13
14     def clean(self):
15         """clean brs created before.
16
17         """
18         out = check_output(r"brctl show | grep -v '^\s' | awk '{print $1}'|sed '1,1d'", shell=True)
19         print out
20         for br in out.split():
21             if br != 'br0':
22                 self._del_br(br)
23
24         return True
25
26     def init(self):
27         pass
28
29     def _del_br(self, name):
30         check_call('ip link set dev %s down' % name, shell=True)
31         check_call('brctl delbr %s' % name, shell=True)
32
33     def create_br(self, br_cfg):
34         """Create a bridge(virtual switch). Return True for success, return False for failure.
35
36         :param dict    br_cfg: configuration for bridge creation like
37                 {
38                     "name": "br1",
39                     "uplinks": [
40                         {
41                             "bdf": "04:00.0",
42                         },
43                         {
44                             "bdf": "04:00.1",
45                         }
46                     ]
47                 }
48
49         """
50         name, uplinks = br_cfg['name'], br_cfg['uplinks']
51         check_call("brctl addbr %s" % name, shell=True)
52         for uplink in uplinks:
53             device = get_eth_by_bdf(uplink['bdf'])
54             check_call("ip link set dev %s up" % device, shell=True)
55             check_call("brctl addif %s %s" % (name, device), shell=True)
56         check_call("ip link set dev %s up" % name, shell=True)
57         return True
58
59     def set_tap_vid(self, tap_cfg):
60         """linux bridge doesn't support vlan id setting.
61         """
62         return True
63
64     def set_fastlink(self, br_cfg):
65         """linux bridge doesn't support openflow protocol.
66         """
67         return True