Skip to content

Commit

Permalink
[neighsyncd] Enabling ipv4 link local entries for non-dualtor (sonic-…
Browse files Browse the repository at this point in the history
…net#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.
  • Loading branch information
Ndancejic authored Aug 30, 2022
1 parent 5624e87 commit 8cc0a45
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
12 changes: 6 additions & 6 deletions neighsyncd/neighsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj)
string key;
string family;
string intfName;
std::vector<std::string> peerSwitchKeys;
m_cfgPeerSwitchTable.getKeys(peerSwitchKeys);
bool is_dualtor = peerSwitchKeys.size() > 0;

if ((nlmsg_type != RTM_NEWNEIGH) && (nlmsg_type != RTM_GETNEIGH) &&
(nlmsg_type != RTM_DELNEIGH))
Expand All @@ -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;
}

Expand All @@ -109,11 +112,8 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj)
return;
}

std::vector<std::string> 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());
Expand Down
63 changes: 63 additions & 0 deletions tests/test_neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8cc0a45

Please sign in to comment.