Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtain management port speed from system file #337

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/sonic_ax_impl/mibs/ietf/rfc2863.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ def _get_if_entry(self, oid):

return Namespace.dbs_get_all(self.db_conn, db, if_table, blocking=True)

def _get_mgmt_speed(self, oid):
interface = self.mgmt_oid_name_map[oid]
try:
with open(f'/sys/class/net/{interface}/speed', 'r') as f:
speed = int(f.read().strip())
return speed
except:
return 0

def get_high_speed(self, sub_id):
"""
:param sub_id: The 1-based sub-identifier query.
Expand All @@ -298,6 +307,9 @@ def get_high_speed(self, sub_id):
if not oid:
return

if oid in self.mgmt_oid_name_map:
return self._get_mgmt_speed(oid)

if oid in self.oid_lag_name_map:
speed = 0
for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]:
Expand Down
4 changes: 3 additions & 1 deletion tests/namespace/test_hc_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
sys.path.insert(0, os.path.join(modules_path, 'src'))

from unittest import TestCase
from unittest.mock import patch, mock_open

from ax_interface import ValueType
from ax_interface.pdu import PDU
Expand Down Expand Up @@ -222,7 +223,8 @@ def test_mgmt_iface_alias(self):
self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 1, 10001))))
self.assertEqual(str(value0.data), 'mgmt1')

def test_mgmt_iface_speed(self):
@patch("builtins.open", new_callable=mock_open, read_data="1000\n")
def test_mgmt_iface_speed(self, mock_file):
"""
Test that mgmt port speed is 1000
"""
Expand Down
4 changes: 3 additions & 1 deletion tests/test_hc_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
sys.path.insert(0, os.path.join(modules_path, 'src'))

from unittest import TestCase
from unittest.mock import patch, mock_open

from ax_interface import ValueType
from ax_interface.pdu import PDU
Expand Down Expand Up @@ -225,7 +226,8 @@ def test_mgmt_iface_alias(self):
self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 1, 10001))))
self.assertEqual(str(value0.data), 'mgmt1')

def test_mgmt_iface_speed(self):
@patch("builtins.open", new_callable=mock_open, read_data="1000\n")
def test_mgmt_iface_speed(self, mock_file):
"""
Test that mgmt port speed is 1000
"""
Expand Down
Loading