1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
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 ##############################################################################
10 import vstf.common.utils as utils
12 __all__ = ["autoneg_on", "autoneg_off", "autoneg_query"]
15 "Autonegotiate": ("-A", "-a", "autoneg"),
16 "RX": ("-A", "-a", "rx"),
17 "TX": ("-A", "-a", "tx"),
21 def autoneg_on(iface, nspace=None):
22 return _set(nspace, iface, Autonegotiate="on", RX="on", TX="on")
25 def autoneg_off(iface, nspace=None):
26 return _set(nspace, iface, Autonegotiate="off", RX="off", TX="off")
29 def autoneg_query(iface, nspace=None):
30 return _query(nspace, iface, "-a")
33 def _set(nspace, iface, **kwargs):
35 for item, value in kwargs.items():
36 opt, _, key = _para_map[item]
37 cmds.setdefault(opt, [])
39 cmds[opt].append(value)
41 for key, value in cmds.items():
42 cmd = _namespace(nspace)
43 cmd += ["ethtool", key, iface] + value
49 def _query(nspace, iface, item):
50 cmd = _namespace(nspace)
51 cmd += ["ethtool", item, iface]
52 return utils.check_output(cmd)
55 def _namespace(nspace):
58 result = "ip netns exec %(namespace)s " % {"namespace": nspace}