From 8cc0a4519f80647c315843091ac1705c0dc8d440 Mon Sep 17 00:00:00 2001 From: Nikola Dancejic <26731235+Ndancejic@users.noreply.github.com> Date: Tue, 30 Aug 2022 09:15:26 -0700 Subject: [PATCH] [neighsyncd] Enabling ipv4 link local entries for non-dualtor (#2427) * [neighsyncd] Enabling ipv4 link local entries for non-dualtor Allow ipv4 link local entries to be programmed to the hardware unless on a dual-tor setup. --- neighsyncd/neighsync.cpp | 12 ++++---- tests/test_neighbor.py | 63 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/neighsyncd/neighsync.cpp b/neighsyncd/neighsync.cpp index 8864746cb563..8f208e73fedd 100644 --- a/neighsyncd/neighsync.cpp +++ b/neighsyncd/neighsync.cpp @@ -63,6 +63,9 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj) string key; string family; string intfName; + std::vector peerSwitchKeys; + m_cfgPeerSwitchTable.getKeys(peerSwitchKeys); + bool is_dualtor = peerSwitchKeys.size() > 0; if ((nlmsg_type != RTM_NEWNEIGH) && (nlmsg_type != RTM_GETNEIGH) && (nlmsg_type != RTM_DELNEIGH)) @@ -81,11 +84,11 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj) nl_addr2str(rtnl_neigh_get_dst(neigh), ipStr, MAX_ADDR_SIZE); - /* Ignore IPv4 link-local addresses as neighbors */ + /* Ignore IPv4 link-local addresses as neighbors if subtype is dualtor */ IpAddress ipAddress(ipStr); - if (family == IPV4_NAME && ipAddress.getAddrScope() == IpAddress::AddrScope::LINK_SCOPE) + if (family == IPV4_NAME && ipAddress.getAddrScope() == IpAddress::AddrScope::LINK_SCOPE && is_dualtor) { - SWSS_LOG_INFO("Link Local address received, ignoring for %s", ipStr); + SWSS_LOG_INFO("Link Local address received on dualtor, ignoring for %s", ipStr); return; } @@ -109,11 +112,8 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj) return; } - std::vector peerSwitchKeys; bool delete_key = false; bool use_zero_mac = false; - m_cfgPeerSwitchTable.getKeys(peerSwitchKeys); - bool is_dualtor = peerSwitchKeys.size() > 0; if (is_dualtor && (state == NUD_INCOMPLETE || state == NUD_FAILED)) { SWSS_LOG_INFO("Unable to resolve %s, setting zero MAC", key.c_str()); diff --git a/tests/test_neighbor.py b/tests/test_neighbor.py index 741ce9a71a9d..59618c75ce43 100644 --- a/tests/test_neighbor.py +++ b/tests/test_neighbor.py @@ -6,6 +6,14 @@ class TestNeighbor(object): + CONFIG_PEER_SWITCH = "PEER_SWITCH" + PEER_SWITCH_HOST = "peer_switch_hostname" + PEER_IPV4 = "10.1.0.33" + + DEFAULT_PEER_SWITCH_PARAMS = { + "address_ipv4": PEER_IPV4 + } + def setup_db(self, dvs): self.pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0) self.adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) @@ -428,6 +436,53 @@ def test_Ipv4LinkLocalNeighbor(self, dvs, testlog): # add neighbor self.add_neighbor("Ethernet8", "169.254.0.0", "00:01:02:03:04:05") + # check application database + tbl = swsscommon.Table(self.pdb, "NEIGH_TABLE:Ethernet8") + intf_entries = tbl.getKeys() + assert len(intf_entries) == 1 + + # check ASIC neighbor database + tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") + intf_entries = tbl.getKeys() + assert len(intf_entries) == 1 + + # remove neighbor + self.remove_neighbor("Ethernet8", "169.254.0.0") + + # remove IP from interface + self.remove_ip_address("Ethernet8", "10.0.0.1/24") + + # remove interface + self.remove_l3_intf("Ethernet8") + + # bring down interface + self.set_admin_status("Ethernet8", "down") + + # check application database + tbl = swsscommon.Table(self.pdb, "NEIGH_TABLE:Ethernet8") + intf_entries = tbl.getKeys() + assert len(intf_entries) == 0 + + # check ASIC neighbor database + tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") + intf_entries = tbl.getKeys() + assert len(intf_entries) == 0 + + def test_Ipv4LinkLocalNeighborWithDualToR(self, dvs, testlog, setup_peer_switch): + self.setup_db(dvs) + + # bring up interface + self.set_admin_status("Ethernet8", "up") + + # create interface + self.create_l3_intf("Ethernet8", "") + + # assign IP to interface + self.add_ip_address("Ethernet8", "10.0.0.1/24") + + # add neighbor + self.add_neighbor("Ethernet8", "169.254.0.0", "00:01:02:03:04:05") + # check application database tbl = swsscommon.Table(self.pdb, "NEIGH_TABLE:Ethernet8") intf_entries = tbl.getKeys() @@ -460,6 +515,14 @@ def test_Ipv4LinkLocalNeighbor(self, dvs, testlog): intf_entries = tbl.getKeys() assert len(intf_entries) == 0 + @pytest.fixture + def setup_peer_switch(self, dvs): + config_db = dvs.get_config_db() + config_db.create_entry( + self.CONFIG_PEER_SWITCH, + self.PEER_SWITCH_HOST, + self.DEFAULT_PEER_SWITCH_PARAMS + ) # Add Dummy always-pass test at end as workaroud # for issue when Flaky fail on final test it invokes module tear-down before retrying