[1/2] framework/pmd_output: report link speed in Mbps
Commit Message
From: Qin Ke <qin.ke@corigine.com>
Link speeds read with get_port_link_speed() have no documented unit.
This leads to issues as different PMD reports speed in both Mbps and
Gbps. The only test-case making use of get_port_link_speed(),
TestSuite_speed_capabilities.py, assumes the speed is returned in Mbps
or an empty string if the speed could not be read.
Document this behavior and extend the get_port_link_speed()
implementations to convert links speeds reported by in Gbps to Mbps.
Signed-off-by: Qin Ke <qin.ke@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
---
framework/pmd_output.py | 12 +++++++++++-
tests/TestSuite_pmd_bonded.py | 12 +++++++++++-
tests/TestSuite_vf_pmd_bonded.py | 12 +++++++++++-
3 files changed, 33 insertions(+), 3 deletions(-)
@@ -235,8 +235,18 @@ class PmdOutput:
def get_port_link_speed(self, port_id):
"""
Get the specified port link speed now.
+ Return the link speed in Mbps or an empty string if speed can't be read.
"""
- return self.get_detail_from_port_info("Link speed: ", "\d+", port_id)
+ linkspeed = self.get_detail_from_port_info("Link speed: ", ".+", port_id)
+ s = re.compile(r"(\d+).*([MG])")
+ res = s.search(linkspeed)
+ if res:
+ if res.group(2) == "M":
+ return res.group(1)
+
+ if res.group(2) == "G":
+ return f"{res.group(1)}000"
+ return ""
def get_port_link_duplex(self, port_id):
"""
@@ -364,8 +364,18 @@ UDP(sport=srcport, dport=destport)/Raw(load="\x50"*%s)], iface="%s", count=%d)'
def get_port_link_speed(self, port_id):
"""
Get the specified port link speed now.
+ Return the link speed in Mbps or an empty string if speed can't be read.
"""
- return self.get_detail_from_port_info("Link speed: ", "\d+", port_id)
+ linkspeed = self.get_detail_from_port_info("Link speed: ", ".+", port_id)
+ s = re.compile(r"(\d+).*([MG])")
+ res = s.search(linkspeed)
+ if res:
+ if res.group(2) == "M":
+ return res.group(1)
+
+ if res.group(2) == "G":
+ return f"{res.group(1)}000"
+ return ""
def get_port_link_duplex(self, port_id):
"""
@@ -335,8 +335,18 @@ UDP(sport=srcport, dport=destport)/Raw(load="\x50"*%s)], iface="%s", count=%d, v
def get_port_link_speed(self, port_id):
"""
Get the specified port link speed now.
+ Return the link speed in Mbps or an empty string if speed can't be read.
"""
- return self.get_detail_from_port_info("Link speed: ", "\d+", port_id)
+ linkspeed = self.get_detail_from_port_info("Link speed: ", ".+", port_id)
+ s = re.compile(r"(\d+).*([MG])")
+ res = s.search(linkspeed)
+ if res:
+ if res.group(2) == "M":
+ return res.group(1)
+
+ if res.group(2) == "G":
+ return f"{res.group(1)}000"
+ return ""
def get_port_link_duplex(self, port_id):
"""