Skip to content

feat: add pynng support for docker-ptf - #27777

Merged
yijingyan2 merged 1 commit into
sonic-net:masterfrom
auspham:austinpham/38213269-add-pynng-support-for-docker-ptf
Jul 15, 2026
Merged

feat: add pynng support for docker-ptf#27777
yijingyan2 merged 1 commit into
sonic-net:masterfrom
auspham:austinpham/38213269-add-pynng-support-for-docker-ptf

Conversation

@auspham

@auspham auspham commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Why I did it

PTF tests on scale topologies frequently fail with nnpy.errors.NNError: Connection timed out coming from ptf_nn_agent.py.

Upstream p4lang/ptf has already replaced nnpy with pynng (p4lang/ptf#234). SONiC tried to pick this up but had to pin ptf_nn_agent.py back to an older nnpy-compatible commit in #26912, because docker-ptf did not ship the pynng package.

This PR adds pynng to docker-ptf and moves the Python 3 image's ptf_nn_agent.py onto the upstream pynng-based agent, aligning SONiC with p4lang/ptf master and unblocking the migration off nnpy.

Work item tracking
  • Microsoft ADO (number only): 38213269

How I did it

In dockers/docker-ptf/Dockerfile.j2, gated the change on PTF_ENV_PY_VER so the two PTF images keep working independently:

  • py3 image (default): install pynng into the virtualenv, and fetch ptf_nn_agent.py from p4lang/ptf master (the pynng-based agent).
  • mixed image (legacy Python 2 / buster): unchanged — keeps nnpy and the nnpy-pinned agent commit from chore: pin ptf_nn_agent.py to use nnpy #26912, because pynng requires Python 3.7+ and the agent there runs under Python 2.

docker-ptf-sai builds FROM docker-ptf, so it inherits the change automatically.

How to verify it

  1. Build the PTF image:
    make configure PLATFORM=vs
    make target/docker-ptf.gz
    
  2. Start the container and confirm the agent dependency is present and the agent is running:
    docker run --rm -it docker-ptf bash
    python -c "import pynng; print(pynng.__version__)"
    grep -n "import pynng" /opt/ptf_nn_agent.py
    supervisorctl status ptf_nn_agent      # -> RUNNING
    
  3. Run a PTF test that exercises the nn agent on a scale topology and confirm there is no nnpy.errors.NNError: Connection timed out.

Which release branch to backport (provide reason below if selected)

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

Tested branch (Please provide the tested image version)

Description for the changelog

[docker-ptf]: Add pynng package and move py3 ptf_nn_agent off nnpy to pynng (aligns with p4lang/ptf master; addresses NNError connection timeouts on scale topologies)

Link to config_db schema for YANG module changes

N/A — no YANG/config_db changes.

Signed-off-by: Austin (Ngoc Thang) Pham <austinpham@microsoft.com>
Copilot AI review requested due to automatic review settings June 9, 2026 07:13
@auspham
auspham requested a review from lguohan as a code owner June 9, 2026 07:13
@auspham
auspham force-pushed the austinpham/38213269-add-pynng-support-for-docker-ptf branch from c28428d to 1f33d07 Compare June 9, 2026 07:13
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the docker-ptf container build to support the newer PTF nn-agent transport by adding pynng for the Python 3 PTF environment and selecting a different upstream ptf_nn_agent.py depending on the PTF Python env.

Changes:

  • Fetch ptf_nn/ptf_nn_agent.py from different upstream refs depending on PTF_ENV_PY_VER (mixed vs py3).
  • Install pynng in the py3 PTF environment.

Comment on lines +260 to +263
{# ptf_nn_agent.py is pinned per Python env: the "mixed" image runs the agent
under Python 2 (nnpy), so it stays on the last nnpy-compatible upstream
commit; the py3 image ships pynng and tracks a p4lang/ptf main commit that
uses pynng (see #26912 / upstream p4lang/ptf#234). #}
{% if PTF_ENV_PY_VER == "mixed" %}
&& wget https://raw.githubusercontent.com/p4lang/ptf/23ebe7237f3c284032bda02fbd1f4a98f1bc12f4/ptf_nn/ptf_nn_agent.py
{% else %}
&& wget https://raw.githubusercontent.com/p4lang/ptf/main/ptf_nn/ptf_nn_agent.py
Comment on lines +340 to +342
{% if PTF_ENV_PY_VER == "py3" %}
&& pip3 install pynng \
{% endif %}
@auspham auspham closed this Jun 15, 2026
@auspham auspham reopened this Jun 15, 2026
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@weiguo-nvidia

Copy link
Copy Markdown

Hi @auspham

Could you help merge the fix?

@auspham

auspham commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Build not found. Please close and reopen the PR or rebase your branch to trigger a new build.

@auspham

auspham commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@weiguo-nvidia the test is still failing, so i cant merge yet

@auspham auspham closed this Jun 26, 2026
@auspham auspham reopened this Jun 26, 2026
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@auspham

auspham commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1149409:

✅Stage Test:

  • Job impacted-area-kvmtest-t1-lag-vpp by Elastictest: retried.

@auspham

auspham commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1149409:

✅Stage Test:

  • Job impacted-area-kvmtest-t1-lag-vpp by Elastictest: retried.

@auspham

auspham commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

No failed(or canceled) stages or jobs found in the most recent build 1149409.

@yijingyan2

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@yijingyan2
yijingyan2 merged commit 30e4d69 into sonic-net:master Jul 15, 2026
37 checks passed
younghuang-CLS pushed a commit to younghuang-CLS/sonic-buildimage that referenced this pull request Jul 15, 2026
Signed-off-by: Austin (Ngoc Thang) Pham <austinpham@microsoft.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.

5 participants