Skip to content

Fix PTF/DUT subnet mismatch when VLAN has multiple IPv4 addresses#23204

Merged
StormLiangMS merged 1 commit intosonic-net:masterfrom
cshivashgit:fix/arp-vlan-ipv4-selection
Mar 24, 2026
Merged

Fix PTF/DUT subnet mismatch when VLAN has multiple IPv4 addresses#23204
StormLiangMS merged 1 commit intosonic-net:masterfrom
cshivashgit:fix/arp-vlan-ipv4-selection

Conversation

@cshivashgit
Copy link
Copy Markdown
Contributor

Description of PR

Summary:

Fix PTF/DUT subnet mismatch in ARP tests when a VLAN interface has multiple IPv4 addresses.

Root Cause

After the community added a second VLAN IP (192.169.0.1), two APIs used by the ARP tests diverged in which IPv4 they selected:

API Behavior Selected IP
get_first_vlan_ipv4 Returns the first IPv4 in the VLAN 192.168.0.1 (DUT)
ip_and_intf_info (conftest) Uses the last IPv4 network and assigns PTF an IP in that subnet 192.169.x.x (PTF)

This put PTF and DUT in different subnets, causing ping failures and MAC learning tests to break.

Fix

Rename get_first_vlan_ipv4 to get_vlan_last_ipv4 so it returns the last IPv4 in the VLAN, matching the behavior of ip_and_intf_info. Both APIs now consistently use 192.169.0.1, keeping PTF and DUT in the same subnet.

Additionally, improve robustness:

  • Use ip_network/IPv4Network type checking for IPv4 detection instead of the ":" in addr heuristic
  • Add try/except for ValueError on malformed addresses

Files Changed

  • tests/arp/arp_utils.py — renamed function, updated import, new selection logic
  • tests/arp/test_arp_update.py — updated import and call site

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511

Approach

What is the motivation for this PR?

How did you do it?

How did you verify/test it?

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

After the community added a second VLAN IP (192.169.0.1),
get_first_vlan_ipv4 and ip_and_intf_info diverged: the former
returned the first IPv4 (192.168.0.1) while the latter assigned
PTF an IP in the last IPv4's subnet (192.169.x.x). This put PTF
and DUT in different subnets, causing ping failures and MAC
learning tests to break.

Rename get_first_vlan_ipv4 to get_vlan_last_ipv4 and change it to
return the last IPv4 in the VLAN, matching the behavior of
ip_and_intf_info in conftest. Also improve robustness by using
ip_network/IPv4Network type checking instead of the naive ":" in
addr heuristic, and add try/except for malformed addresses.

Signed-off-by: Shivashankar CR <shivashankar.c.r@gmail.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@vrajeshe
Copy link
Copy Markdown
Contributor

Following

Copy link
Copy Markdown
Collaborator

@StormLiangMS StormLiangMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — correctly aligns DUT/PTF subnet selection by using the last IPv4 address. CI all green.

Minor (non-blocking): Prefer isinstance(ip_network(addr, strict=False), IPv4Network) over type(...) is IPv4Network for Pythonic type checking.

@StormLiangMS StormLiangMS merged commit 72f7341 into sonic-net:master Mar 24, 2026
17 checks passed
@cshivashgit cshivashgit deleted the fix/arp-vlan-ipv4-selection branch March 24, 2026 15:22
ravaliyel pushed a commit to ravaliyel/sonic-mgmt that referenced this pull request Mar 27, 2026
…nic-net#23204)

After the community added a second VLAN IP (192.169.0.1),
get_first_vlan_ipv4 and ip_and_intf_info diverged: the former
returned the first IPv4 (192.168.0.1) while the latter assigned
PTF an IP in the last IPv4's subnet (192.169.x.x). This put PTF
and DUT in different subnets, causing ping failures and MAC
learning tests to break.

Rename get_first_vlan_ipv4 to get_vlan_last_ipv4 and change it to
return the last IPv4 in the VLAN, matching the behavior of
ip_and_intf_info in conftest. Also improve robustness by using
ip_network/IPv4Network type checking instead of the naive ":" in
addr heuristic, and add try/except for malformed addresses.

Signed-off-by: Shivashankar CR <shivashankar.c.r@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants