Skip to content
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
10 changes: 6 additions & 4 deletions src/sonic_ax_impl/mibs/ietf/rfc1213.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ def update_data(self):
continue
for nh in nexthops.split(','):
# TODO: if ipn contains IP range, create more sub_id here
sub_id = ip2byte_tuple(ipn.network_address)
self.route_list.append(sub_id)
self.nexthop_map[sub_id] = ipaddress.ip_address(nh).packed
break # Just need the first nexthop
if type(ipaddress.ip_address(nh)) is ipaddress.IPv4Address:
sub_id = ip2byte_tuple(ipn.network_address)
self.route_list.append(sub_id)
self.nexthop_map[sub_id] = ipaddress.ip_address(nh).packed
break # Just need the first nexthop
mibs.logger.warning("Route {} has non-IPv4 nexthop: {}".format(routestr, nh))

self.route_list.sort()

Expand Down
4 changes: 2 additions & 2 deletions tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@
"speed": 100000
},
"ROUTE_TABLE:0.0.0.0/0": {
"ifname": "Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet78",
"nexthop": "10.0.0.1,10.0.0.3,10.0.0.5,10.0.0.7,10.0.0.9,10.0.0.11,10.0.0.13,10.0.0.15,10.0.0.17,10.0.0.19,10.0.0.21,10.0.0.23,10.0.0.25,10.0.0.27"
"ifname": "Ethernet74,Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet78",
"nexthop": "2001:0db8:85a3:0000:0000:8a2e:0370:7334,10.0.0.1,10.0.0.3,10.0.0.5,10.0.0.7,10.0.0.9,10.0.0.11,10.0.0.13,10.0.0.15,10.0.0.17,10.0.0.19,10.0.0.21,10.0.0.23,10.0.0.25,10.0.0.27"
},
"ROUTE_TABLE:10.1.0.32": {
"nexthop": "",
Expand Down
1 change: 1 addition & 0 deletions tests/test_nexthop.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def test_getnextpdu(self):
n = len(response.values)
value0 = response.values[0]
self.assertEqual(value0.type_, ValueType.IP_ADDRESS)
self.assertEqual(type(ipaddress.ip_address(value0.data.string)), ipaddress.IPv4Address)
self.assertEqual(str(value0.data), ipaddress.ip_address("10.0.0.1").packed.decode())

def test_getnextpdu_exactmatch(self):
Expand Down
35 changes: 34 additions & 1 deletion tests/test_rfc1213.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,40 @@ def test_NextHopUpdater_route_no_next_hop(self):

self.assertTrue(len(updater.route_list) == 0)

@mock.patch('sonic_ax_impl.mibs.Namespace.dbs_keys', mock.MagicMock(return_value=(["ROUTE_TABLE:0.0.0.0/0"])))
@mock.patch('sonic_ax_impl.mibs.Namespace.dbs_get_all', mock.MagicMock(return_value=({"nexthop": "2001:db8:1111:2222:3333:4444:5555:6666,2001:db8:3333:4444:5555:6666:7777:8888", "ifname": "Ethernet0,Ethernet4"})))
def test_NextHopUpdater_route_ipv6_next_hop(self):
updater = NextHopUpdater()

with mock.patch('sonic_ax_impl.mibs.logger.warning') as mocked_warning:
updater.update_data()

# check warning
expected = [
mock.call("Route ROUTE_TABLE:0.0.0.0/0 has non-IPv4 nexthop: 2001:db8:1111:2222:3333:4444:5555:6666"),
mock.call("Route ROUTE_TABLE:0.0.0.0/0 has non-IPv4 nexthop: 2001:db8:3333:4444:5555:6666:7777:8888")
]
mocked_warning.assert_has_calls(expected)

self.assertTrue(len(updater.route_list) == 0)
self.assertTrue(len(updater.nexthop_map) == 0)

@mock.patch('sonic_ax_impl.mibs.Namespace.dbs_keys', mock.MagicMock(return_value=(["ROUTE_TABLE:0.0.0.0/0"])))
@mock.patch('sonic_ax_impl.mibs.Namespace.dbs_get_all', mock.MagicMock(return_value=({"nexthop": "2001:db8:1111:2222:3333:4444:5555:6666,127.1.1.1", "ifname": "Ethernet0,Ethernet4"})))
def test_NextHopUpdater_route_ipv4_ipv6_next_hop(self):
updater = NextHopUpdater()

with mock.patch('sonic_ax_impl.mibs.logger.warning') as mocked_warning:
updater.update_data()

# check warning
expected = [
mock.call("Route ROUTE_TABLE:0.0.0.0/0 has non-IPv4 nexthop: 2001:db8:1111:2222:3333:4444:5555:6666")
]
mocked_warning.assert_has_calls(expected)

self.assertTrue(len(updater.route_list) == 1)
self.assertTrue(len(updater.nexthop_map) == 1)

class TestNextHopUpdaterRedisException(TestCase):
def __init__(self, name):
Expand Down Expand Up @@ -106,7 +140,6 @@ def mock_get_sync_d_from_all_namespace(per_namespace_func, db_conn):
# check re-init
connect_namespace_dbs.assert_called()


def test_InterfaceUpdater_get_counters(self):

def mock_lag_entry_table(lag_name):
Expand Down
Loading