Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / agent / env / vswitch_plugins / bridge_plugin.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 from vstf.agent.env.vswitch_plugins import model
11 from vstf.common.utils import check_call, get_eth_by_bdf, check_output
12
13
14 class BridgePlugin(model.VswitchPlugin):
15
16     def __init__(self):
17         pass
18
19     def clean(self):
20         """clean brs created before.
21
22         """
23         out = check_output(
24             r"brctl show | grep -v '^\s' | awk '{print $1}'|sed '1,1d'",
25             shell=True)
26         print out
27         for br in out.split():
28             if br != 'br0':
29                 self._del_br(br)
30
31         return True
32
33     def init(self):
34         pass
35
36     def _del_br(self, name):
37         check_call('ip link set dev %s down' % name, shell=True)
38         check_call('brctl delbr %s' % name, shell=True)
39
40     def create_br(self, br_cfg):
41         """Create a bridge(virtual switch). Return True for success, return False for failure.
42
43         :param dict    br_cfg: configuration for bridge creation like
44                 {
45                     "name": "br1",
46                     "uplinks": [
47                         {
48                             "bdf": "04:00.0",
49                         },
50                         {
51                             "bdf": "04:00.1",
52                         }
53                     ]
54                 }
55
56         """
57         name, uplinks = br_cfg['name'], br_cfg['uplinks']
58         check_call("brctl addbr %s" % name, shell=True)
59         for uplink in uplinks:
60             device = get_eth_by_bdf(uplink['bdf'])
61             check_call("ip link set dev %s up" % device, shell=True)
62             check_call("brctl addif %s %s" % (name, device), shell=True)
63         check_call("ip link set dev %s up" % name, shell=True)
64         return True
65
66     def set_tap_vid(self, tap_cfg):
67         """linux bridge doesn't support vlan id setting.
68         """
69         return True
70
71     def set_fastlink(self, br_cfg):
72         """linux bridge doesn't support openflow protocol.
73         """
74         return True