You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[dhcp-server] match condition based DHCP server tests - #29054
Summary:
Adds sonic-mgmt test coverage for the IPv4 match-condition (MATCH mode) DHCP server feature, implementing the test plan in #28933. This covers address assignment, runtime config changes, CLI/GCU validation, lease clear, multi-VLAN isolation, and scale/flood.
The PR has two commits:
[dhcp_server] Add MATCH mode DHCP server tests: shared helpers plus the functional (F), config-change (C) and CLI validation (V) modules.
[dhcp_server] Add MATCH mode lease clear, multi-VLAN and stress tests: the lease clear (L), multi-VLAN (M) and stress (S) modules, plus a PTF flood generator.
Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO):
Failure type:
Tested branch
[x ] master
202311
202405
202411
202505
202511
202512
202605
N/A
Test result
master: SONiC.master.0-c0666d2c8 (KVM vlab-01, vms-kvm-t0), with the dhcp_server container built from sonic-buildimage#30361. Results below cover both isc-relay-agent and sonic-relay-agent where the module is relay-parametrized.
18/18 passed on each relay (including config_reload, service restart and cold reboot persistence)
V: CLI/GCU validation
test_dhcp_server_match_cli.py
All passed
L: lease clear
test_dhcp_server_lease_clear.py
16/16 passed (PORT and MATCH modes, including 2 cold reboots)
M: multi-VLAN
test_dhcp_server_match_multi_vlans.py
4/4 passed
S01: scale (24 ports, 120 bindings)
test_dhcp_server_match_stress.py
2/2 passed; Kea converged 0.4 s after GCU apply
S02: DISCOVER flood (100 pps, 60 s)
test_dhcp_server_match_stress.py
Passed on both relays: 0% loss; average latency about 5 ms (sonic-relay) and 72 ms (isc)
Approach
What is the motivation for this PR?
MATCH mode lets the SONiC DHCP server pick an address pool by matching named conditions: the circuit-id port identity from Option 82 and the vendor class from Option 60, used alone or combined, with the most specific binding winning. This PR adds end-to-end coverage for the feature and the lease clear CLI, as defined in the MATCH test plan (#28933).
How did you do it?
dhcp_server_match_common.py: shared fixtures and helpers. They cover:
discovering the MATCH test environment (VLAN, PTF ports, prefix);
building MatchConfig objects and applying them through CLI or GCU;
snapshotting and restoring the existing DHCP server config;
building Option 82/60 DISCOVER/REQUEST packets and checking OFFER/ACK;
reading Kea pools and leases (lease4-get-all) and State DB leases;
a multi-VLAN GCU patch builder and a second_vlan context manager that moves PTF members into a temporary Vlan4001 and restores them afterwards.
dhcp_server_test_common.py: clean_dhcp_server_config now also deletes DHCP_SERVER_IPV4_BINDING and DHCP_SERVER_IPV4_MATCH, ahead of ranges and ports, so dependent entries are removed first.
F (test_dhcp_server_match.py):
circuit-id on the wire;
port-only, Option 60-only and combined bindings;
specificity across CLI/GCU and binding order;
pool exhaustion, shared pools, multiple ranges;
Option 60 byte matching and changes between messages;
RENEW/RELEASE, client MAC move, customized options;
PortChannel circuit-id.
C (test_dhcp_server_match_config_change.py):
binding add/update/delete, condition and range updates;
mode switch, interface enable/disable;
VLAN member and prefix changes;
invalid config keeping the last known good Kea config, missing references;
persistence (config reload, service restart, cold reboot);
critical process restart.
V (test_dhcp_server_match_cli.py):
show output;
CLI and GCU rejection of invalid input (multi-prefix, mode switch, rules in PORT mode);
CLI order independence.
L (test_dhcp_server_lease_clear.py):
clearing a single IP and --all, the latter also across a second VLAN;
persistence across Kea restart, service restart and cold reboot;
device replacement;
negative cases, including feature disabled, invalid IP and non-root;
stale State DB entry cleanup;
concurrent clear contention on the lock.
M (test_dhcp_server_match_multi_vlans.py):
MATCH and PORT VLANs side by side, where an invalid update on one VLAN must not affect the other's pools, leases, RENEW or new offers;
one match condition shared across two VLANs, each with its own pool.
S (test_dhcp_server_match_stress.py and dhcp_server_match_flood.py):
a scale test with 120 bindings across 24 ports, checking Kea convergence;
a PTF-side scapy flood that sends DISCOVERs at a fixed rate and matches OFFERs by xid/chaddr. It reports loss, wrong pool and latency, and the test asserts 0% loss and that DHCP server/relay processes did not restart.
How did you verify/test it?
Ran every module on a KVM vms-kvm-t0 testbed (vlab-01) running master with the dhcp_server container from sonic-buildimage#30361.
Ran relay-parametrized cases with both isc-relay-agent and sonic-relay-agent.
After each run, checked the DUT was restored: original VLAN membership, original DHCP server config, saved config matching running config, no leftover test leases.
flake8 is clean (--max-line-length=120).
Any platform specific information?
Supported testbed topology if it's a new test case?
Add sonic-mgmt tests for MATCH condition based DHCPv4 address assignment
(test plan sonic-net#28933):
- test_dhcp_server_match.py (F01-F14): circuit_id, option60 and combined
bindings, specificity, pool exhaustion, shared pools, multiple ranges,
option60 byte matching, renew/release, MAC move, customized options and
PortChannel circuit IDs.
- test_dhcp_server_match_config_change.py (C01-C12): runtime binding,
match, range, mode, interface state, VLAN member and prefix changes,
last-known-good recovery, missing references, persistence across config
reload, service restart and cold reboot, and critical process restart.
- test_dhcp_server_match_cli.py (V01-V06): show output, CLI and GCU
rejection of invalid configuration, PORT mode non-regression and order
independence.
- dhcp_server_match_common.py: shared MATCH helpers. Kea leases are read
from the memfile CSV so the tests do not depend on the lease_cmds hook.
- dhcp_server_test_common.py: clean MATCH binding and match tables.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Nishant Sharma <nshntsharma86@gmail.com>
Implement the remaining modules of the IPv4 match-condition DHCP server
test plan:
- test_dhcp_server_lease_clear.py (L01-L07): single-IP and --all clear,
persistence across Kea/service restart and cold reboot, device
replacement, negative/feature-disabled cases, stale State DB entry
and concurrent clear lock contention, in PORT and MATCH modes.
- test_dhcp_server_match_multi_vlans.py (M01-M02): per-VLAN isolation
(MATCH and PORT side by side, invalid update on one VLAN does not
affect the other) and a shared match condition across VLANs.
- test_dhcp_server_match_stress.py (S01-S02): 120-binding scale
convergence and a 100 pps DISCOVER flood with 0% loss check, run
with both isc and sonic relay agents.
- dhcp_server_match_flood.py: PTF-side flood generator/correlator.
- dhcp_server_match_common.py: multi-VLAN GCU helpers, second_vlan
context manager and State DB / Kea lease readers.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Nishant Sharma <nshntsharma86@gmail.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved test defects can cause premature failures, unnecessary skips, or false passes through insufficient address allocation, stale lease handling, missing runtime checks, and unreliable flood timing and restart detection.
Adds end-to-end coverage for IPv4 DHCP server MATCH mode in sonic-mgmt, implementing the scenarios from test plan #28933 alongside existing PORT-mode tests.
Changes:
Adds address-assignment, runtime configuration, CLI/GCU validation, lease-clear, and multi-VLAN tests.
Introduces shared configuration, DHCP client, lease-inspection, and cleanup helpers.
Adds scale tests and a PTF DISCOVER flood generator with response and latency checks.
File
Description
tests/dhcp_server/test_dhcp_server_match.py
Tests matching, specificity, allocation, and client behavior.
- Select the test address window from the longest run of addresses
without an active lease, ignoring released, deleted and expired Kea
leases, and skip S01 when the VLAN cannot hold every scale binding.
- Skip MATCH tests unless both the YANG model and the dhcp_server
runtime support MATCH mode, checked before the DUT is changed.
- Wait for the State DB lease to converge on the expected address and
lifetime, so a lease left from a previous pool is not returned.
- Include the container start time in the DHCP server process snapshot
and check the relay container and its processes across the flood.
- Timestamp each DISCOVER immediately before it is sent, and fail the
flood when sending exceeds the scheduled duration; report rates from
the measured duration.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Nishant Sharma <nshntsharma86@gmail.com>
Please register these new functional modules in the KVM PR-gate manifest. tests/kvmtest.sh explicitly enumerates its test suites and contains no DHCP server MATCH entries, so these cases are not run by the gate.
Include configuration apply time in the convergence timeout
The convergence timer starts after the synchronous GCU command returns, although Kea can compile and activate the configuration while that command is running. Consequently, an update taking more than the 30-second limit can still pass because only the remaining wait is measured. Start timing before applying the configuration so the assertion includes that work.
…ests
- Do not log Config DB dumps (sonic-cfggen --print-data, saved config).
- Treat VLAN SVI addresses as occupied when choosing the free pool window.
- Skip second_vlan when the VLAN already exists instead of clobbering it.
- Assert DHCP replies arrive on a member port of the client's VLAN.
- Keep every reply per xid in the flood script; any invalid reply fails.
- Require PortChannel0999 to be absent before the PortChannel test.
- Exclude Ansible's own "Invoked with" syslog entries in wait_for_syslog.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Nishant Sharma <nshntsharma86@gmail.com>
This test can pass with the lease-clear lock bypassed: both commands may succeed on distinct IPs and leave the expected final lease map. Add deterministic contention by holding the lease-clear lock in a separate process and waiting for confirmation that it is held. Assert that a clear reports clear-in-progress without changing leases, and release the lock in cleanup.
Add new test modules to the PR test manifest
tests/dhcp_server/test_dhcp_server_match.py:62
The six new test modules are absent from .azure-pipelines/pr_test_scripts.yaml, which .azure-pipelines/test_plan.py uses by default for PR runs, so they will not receive ongoing PR-gate coverage. Register the functional, config-change, CLI, multi-VLAN, stress, and lease-clear modules in the applicable manifest test set.
Start convergence timing before configuration apply
Start the convergence timer before cfg.apply(...). Although wait=False skips the explicit pool wait, the GCU command still runs synchronously, so Kea can spend the entire compilation/reload interval converging before this timer starts. A 40-second apply followed by a 0.4-second pool check currently passes the 30-second limit and reports 0.4 seconds, masking the scale regression this assertion is intended to catch.
- L07: hold the lease-clear lock from a separate DUT process and verify that
single-IP and --all clears report clear-in-progress without changing leases,
then succeed once the lock is released.
- S01: start the convergence timer before the synchronous GCU apply.
- Register the new MATCH and lease-clear modules in pr_test_scripts.yaml.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Nishant Sharma <nshntsharma86@gmail.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because the review evidence identifies gaps in CI coverage, failure handling, and state verification that could leave test failures or inconsistent DHCP state undetected.
The reason will be displayed to describe this comment to others. Learn more.
@nishant111 — one remaining correctness blocker in reply-delivery validation; see the inline comment.
Reviewed 654ea6daf1783b9c9444b74af93950be20814067. The new revision addresses the prior scale-timing, lease-clear-locking, and PR-test-registration findings.
DCO / CLA / static checks: passing. CI: build 1288258 is red; inspected failures report Celery timeouts, testbed sanity failures, and an unrelated ARP test failure. I have not established a DHCP regression from those failures.
Please address the client-port false pass before merge.
DhcpClient.exchange polled every PTF port, so a reply delivered only to
another member of the same VLAN was accepted as if the client had received
it. Poll the client's own port instead; flooded copies on other ports are
ignored, and a matching reply seen only on another port fails the test.
Add unit tests with a fake dataplane covering a reply on the wrong
same-VLAN port only, a flooded copy before the client's reply, no reply,
and expect_no_offer staying strict.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Nishant Sharma <nshntsharma86@gmail.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because omitted findings identify risks of deleting real client leases and leaving relay selection or DHCP configuration unrestored.
No open issues 🎉
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
triage-CiscoPR assigned to Cisco for triage (assign_triage_labels workflow)triage-MicrosoftPR assigned to Microsoft for triage (assign_triage_labels workflow)
5 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of PR
Summary:
Adds sonic-mgmt test coverage for the IPv4 match-condition (MATCH mode) DHCP server feature, implementing the test plan in #28933. This covers address assignment, runtime config changes, CLI/GCU validation, lease clear, multi-VLAN isolation, and scale/flood.
The PR has two commits:
[dhcp_server] Add MATCH mode DHCP server tests: shared helpers plus the functional (F), config-change (C) and CLI validation (V) modules.[dhcp_server] Add MATCH mode lease clear, multi-VLAN and stress tests: the lease clear (L), multi-VLAN (M) and stress (S) modules, plus a PTF flood generator.Dependencies (sonic-buildimage):
Fixes # (issue)
Type of change
Back port request
Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO):
Failure type:
Tested branch
Test result
SONiC.master.0-c0666d2c8(KVM vlab-01,vms-kvm-t0), with the dhcp_server container built from sonic-buildimage#30361. Results below cover bothisc-relay-agentandsonic-relay-agentwhere the module is relay-parametrized.test_dhcp_server_match.pytest_dhcp_server_match_config_change.pytest_dhcp_server_match_cli.pytest_dhcp_server_lease_clear.pytest_dhcp_server_match_multi_vlans.pytest_dhcp_server_match_stress.pytest_dhcp_server_match_stress.pyApproach
What is the motivation for this PR?
MATCH mode lets the SONiC DHCP server pick an address pool by matching named conditions: the circuit-id port identity from Option 82 and the vendor class from Option 60, used alone or combined, with the most specific binding winning. This PR adds end-to-end coverage for the feature and the lease clear CLI, as defined in the MATCH test plan (#28933).
How did you do it?
dhcp_server_match_common.py: shared fixtures and helpers. They cover:MatchConfigobjects and applying them through CLI or GCU;lease4-get-all) and State DB leases;second_vlancontext manager that moves PTF members into a temporary Vlan4001 and restores them afterwards.dhcp_server_test_common.py:clean_dhcp_server_confignow also deletesDHCP_SERVER_IPV4_BINDINGandDHCP_SERVER_IPV4_MATCH, ahead of ranges and ports, so dependent entries are removed first.test_dhcp_server_match.py):test_dhcp_server_match_config_change.py):test_dhcp_server_match_cli.py):showoutput;test_dhcp_server_lease_clear.py):--all, the latter also across a second VLAN;test_dhcp_server_match_multi_vlans.py):test_dhcp_server_match_stress.pyanddhcp_server_match_flood.py):How did you verify/test it?
vms-kvm-t0testbed (vlab-01) running master with the dhcp_server container from sonic-buildimage#30361.isc-relay-agentandsonic-relay-agent.--max-line-length=120).Any platform specific information?
Supported testbed topology if it's a new test case?
mx (validated on a t0 KVM testbed)
Documentation
Test plan: #28933 (
docs/testplan/IPv4-Match-Condition-Based-DHCP-Server-test-plan.md)HLD: Port-based DHCP server HLD