Skip to content

[src/libraries/sonic-fib]: Add sonic-fib library to build libnexthopgroup deb for RIB/FIB#26423

Merged
eddieruan-alibaba merged 2 commits into
sonic-net:masterfrom
GaladrielZhao:ribfib/sonic-fib
May 19, 2026
Merged

[src/libraries/sonic-fib]: Add sonic-fib library to build libnexthopgroup deb for RIB/FIB#26423
eddieruan-alibaba merged 2 commits into
sonic-net:masterfrom
GaladrielZhao:ribfib/sonic-fib

Conversation

@GaladrielZhao

Copy link
Copy Markdown
Contributor

Why I did it

This is the first PR of the RIB/FIB project.

Currently, fpmsyncd receives only partial nexthop information from FRR. To support nexthop object with full information
(called as NextHopGroupFull) passed from FRR (zebra) to fpmsyncd, a shared serialization library is needed so both processes can encode or decode NHG data consistently.

Work item tracking
  • Microsoft ADO (number only):

How I did it

Introduce sonic-fib, a C++ library that provides encoding and decoding capabilities for NextHopGroupFull objects:

  • FRR uses the encoding function to generate a JSON string embedded in messages sent to fpmsyncd
  • fpmsyncd uses the decoding function to reconstruct the NHG object from the incoming JSON string

To minimize human error, the library uses a JSON Schema as the single source of truth and Jinja2 templates to auto-generate the required code.

(1) Key components:

  • Data schema: NextHopGroupFull.json drives auto-generation of C++ classes, JSON codecs, and C struct wrappers via render_schema.py + Jinja2.
  • C-API: C-callable interface for FRR to encode NHG objects into JSON.
  • Logging callback: pluggable FIB_LOG macro with per-process callback registration (fib_frr_register_callback for FRR, registerLogCallback for SWSS).
  • Unit tests: covers C++ class behavior, JSON round-trip, C-API conversion, and logging callback using Google Test.

(2) Architecture
image

(3) Directory Structure

sonic-fib/
├── schema/
│   └── NextHopGroupFull.json      # Single source of truth: data schema (source)
├── scripts/
│   └── render_schema.py           # Code generation engine (source)
├── templates/
│   ├── *.j2                       # Jinja2 templates for code generation (source)
│   │   ├── nexthopgroupfull.h.j2  
│   │   ├── nexthopgroupfull.cpp.j2
│   │   ├── nexthopgroupfull_json.h.j2
│   │   └── c_nexthopgroupfull.h.j2
│   └── references/                # Generated code (reference only, for review)
│       ├── nexthopgroupfull.h         # NextHopGroupFull definitions
│       ├── nexthopgroupfull.cpp       # NextHopGroupFull function implementation
│       ├── nexthopgroupfull_json.h    # NextHopGroupFull to/from_json functions
│       └── c_nexthopgroupfull.h       # C_NextHopGroupFull definitions
├── src/
│   ├── c-api/
│   │   ├── nexthopgroup_capi.h    # C API header
│   │   └── nexthopgroup_capi.cpp  # C→C++ conversion & JSON wrapper
│   ├── nexthopgroup_debug.h       # Logging callback interface
│   └── nexthopgroup_debug.cpp     # Logging implementation
└── tests/
    ├── nexthopgroupfull_ut.cpp         # C++ class unit tests
    ├── nexthopgroupfull_json_ut.cpp    # JSON serialization tests
    ├── nexthopgroup_debug_ut.cpp       # Logging callback tests
    ├── c_api_ut.cpp                    # C-API round-trip tests
    └── main.cpp                        # gtest entry point

Note: The generated files in templates/references are only kept for review and will not be committed later.

How to verify it

There is a UT module in sonic-fib, containing GTests for all functions.

A picture of a cute animal (not mandatory but encouraged)

image

@GaladrielZhao GaladrielZhao changed the title [src/sonic-fib]: Add sonic-fib library to build libnexthopgroup deb for RIB/FIB [src/libraries/sonic-fib]: Add sonic-fib library to build libnexthopgroup deb for RIB/FIB Mar 27, 2026
@mssonicbld

This comment was marked as duplicate.

@GaladrielZhao
GaladrielZhao force-pushed the ribfib/sonic-fib branch 2 times, most recently from b2a3564 to 934bc94 Compare April 2, 2026 09:21
@yxieca

yxieca commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

1 similar comment
@yxieca

yxieca commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

/azpw ms_conflict

Comment thread src/libraries/sonic-fib/schema/NextHopGroupFull.json Outdated
Comment thread src/libraries/sonic-fib/src/c-api/nexthopgroup_capi.cpp Outdated
Comment thread src/libraries/sonic-fib/templates/references/nexthopgroupfull.cpp Outdated
Comment thread src/libraries/sonic-fib/src/Makefile.am
Comment thread src/libraries/sonic-fib/src/c-api/nexthopgroup_capi.h Outdated
Comment thread rules/sonic-fib.mk Outdated
Comment thread src/libraries/sonic-fib/templates/references/c_nexthopgroupfull.h Outdated
Comment thread src/libraries/sonic-fib/schema/NextHopGroupFull.json
Comment thread src/libraries/sonic-fib/src/c-api/nexthopgroup_capi.cpp
Comment thread src/libraries/sonic-fib/templates/references/c_nexthopgroupfull.h Outdated
Comment thread src/libraries/sonic-fib/templates/references/c_nexthopgroupfull.h Outdated
Comment thread src/libraries/sonic-fib/debian/control

@selva-nexthop selva-nexthop 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.

/

Comment thread src/libraries/sonic-fib/schema/NextHopGroupFull.json
@GaladrielZhao
GaladrielZhao force-pushed the ribfib/sonic-fib branch 2 times, most recently from 8a3afc9 to 508d9ee Compare April 21, 2026 05:35
@mssonicbld

This comment was marked as duplicate.

@azure-pipelines

This comment was marked as duplicate.

Comment thread src/libraries/sonic-fib/templates/nexthopgroupfull.cpp.j2 Outdated
Comment thread src/libraries/sonic-fib/src/nexthopgroup_debug.cpp
Comment thread src/libraries/sonic-fib/src/nexthopgroup_debug.cpp Outdated
Comment thread src/libraries/sonic-fib/templates/nexthopgroupfull.cpp.j2 Outdated
Comment thread src/libraries/sonic-fib/src/c-api/nexthopgroup_capi.cpp
Comment thread src/libraries/sonic-fib/templates/nexthopgroupfull_json.h.j2 Outdated
@mssonicbld

This comment was marked as duplicate.

@azure-pipelines

This comment was marked as duplicate.

@mssonicbld

This comment was marked as duplicate.

@azure-pipelines

This comment was marked as duplicate.

@mssonicbld

This comment was marked as duplicate.

@azure-pipelines

This comment was marked as duplicate.

Update compiling files to build libnexthopgroup debian for sonic-fib.

Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>
Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
Introduce sonic-fib, a C++ library that provides encoding and decoding
capabilities for NextHopGroupFull objects:
- FRR uses the encoding function to generate a JSON string embedded in
  messages sent to fpmsyncd
- fpmsyncd uses the decoding function to reconstruct the NHG object from
  the incoming JSON string

To minimize human error, the library uses a JSON Schema as the single source
of truth and Jinja2 templates to auto-generate the required code.

Key components:
- Data schema: NextHopGroupFull.json drives auto-generation of C++ classes,
  JSON codecs, and C struct wrappers via render_schema.py + Jinja2.
- C-API: C-callable interface for FRR to encode NHG objects into JSON.
- Logging: pluggable FIB_LOG macro with per-process callback registration
  (fib_frr_register_callback for FRR, registerLogCallback for SWSS).
- Unit tests: covers C++ class behavior, JSON round-trip, C-API conversion,
  and logging callback using Google Test.

Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>
@mssonicbld

This comment was marked as duplicate.

@azure-pipelines

This comment was marked as duplicate.

@GaladrielZhao

Copy link
Copy Markdown
Contributor Author

Hi @deepak-singhal0408 , thanks a lot for your review. I've addressed all the comments above.

@deepak-singhal0408 deepak-singhal0408 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.

Thanks for addressing the review comments @GaladrielZhao .. LGTM.

@eddieruan-alibaba
eddieruan-alibaba merged commit db77756 into sonic-net:master May 19, 2026
27 of 28 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in SONiC Routing Dashboard May 19, 2026
vidyac86 pushed a commit to vidyac86/sonic-buildimage that referenced this pull request May 23, 2026
…roup deb for RIB/FIB (sonic-net#26423)

* [rules][src]: Add sonic-fib for nexthopgroup deb

Update compiling files to build libnexthopgroup debian for sonic-fib.

Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>
Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>

* [src/libraries/sonic-fib]: Implementation for sonic-fib

Introduce sonic-fib, a C++ library that provides encoding and decoding
capabilities for NextHopGroupFull objects:
- FRR uses the encoding function to generate a JSON string embedded in
  messages sent to fpmsyncd
- fpmsyncd uses the decoding function to reconstruct the NHG object from
  the incoming JSON string

To minimize human error, the library uses a JSON Schema as the single source
of truth and Jinja2 templates to auto-generate the required code.

Key components:
- Data schema: NextHopGroupFull.json drives auto-generation of C++ classes,
  JSON codecs, and C struct wrappers via render_schema.py + Jinja2.
- C-API: C-callable interface for FRR to encode NHG objects into JSON.
- Logging: pluggable FIB_LOG macro with per-process callback registration
  (fib_frr_register_callback for FRR, registerLogCallback for SWSS).
- Unit tests: covers C++ class behavior, JSON round-trip, C-API conversion,
  and logging callback using Google Test.

Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>

---------

Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>
Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
Signed-off-by: Vidya Chidambaram <vidya_chidambaram@dell.com>
@radha-danda

Copy link
Copy Markdown

@GaladrielZhao, sairedis PR CI checks are failing with below linking errors. Can you please check if it is related to your PR and kindly fix?

2026-05-25T05:56:13.6377525Z /bin/bash ../libtool  --tag=CXX   --mode=link g++  -g -O2 -ffile-prefix-map=/__w/1/s=. -fstack-protector-strong -Wformat -Werror=format-security  -Wl,-z,relro -o fpmsyncd fpmsyncd-fpmsyncd.o fpmsyncd-fpmlink.o fpmsyncd-routesync.o fpmsyncd-warmRestartHelper.o fpmsyncd-orch_zmq_config.o    -lnl-3 -lnl-route-3 -lswsscommon -lnexthopgroup -lnl-nf-3 -lnl-route-3 -lnl-genl-3 -lnl-3 -lhiredis 
2026-05-25T05:56:13.7125550Z libtool: link: g++ -g -O2 -ffile-prefix-map=/__w/1/s=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z -Wl,relro -o fpmsyncd fpmsyncd-fpmsyncd.o fpmsyncd-fpmlink.o fpmsyncd-routesync.o fpmsyncd-warmRestartHelper.o fpmsyncd-orch_zmq_config.o  -lswsscommon -lnexthopgroup -lnl-nf-3 -lnl-route-3 -lnl-genl-3 -lnl-3 -lhiredis
2026-05-25T05:56:13.7258134Z /usr/bin/ld: cannot find -lnexthopgroup: No such file or directory
2026-05-25T05:56:13.7465330Z collect2: error: ld returned 1 exit status
2026-05-25T05:56:13.7477116Z make[4]: *** [Makefile:419: fpmsyncd] Error 1
2026-05-25T05:56:13.7478869Z make[4]: Leaving directory '/__w/1/s/fpmsyncd'
2026-05-25T05:56:13.7480812Z make[3]: *** [Makefile:420: all-recursive] Error 1

@GaladrielZhao

Copy link
Copy Markdown
Contributor Author

@GaladrielZhao, sairedis PR CI checks are failing with below linking errors. Can you please check if it is related to your PR and kindly fix?

2026-05-25T05:56:13.6377525Z /bin/bash ../libtool  --tag=CXX   --mode=link g++  -g -O2 -ffile-prefix-map=/__w/1/s=. -fstack-protector-strong -Wformat -Werror=format-security  -Wl,-z,relro -o fpmsyncd fpmsyncd-fpmsyncd.o fpmsyncd-fpmlink.o fpmsyncd-routesync.o fpmsyncd-warmRestartHelper.o fpmsyncd-orch_zmq_config.o    -lnl-3 -lnl-route-3 -lswsscommon -lnexthopgroup -lnl-nf-3 -lnl-route-3 -lnl-genl-3 -lnl-3 -lhiredis 
2026-05-25T05:56:13.7125550Z libtool: link: g++ -g -O2 -ffile-prefix-map=/__w/1/s=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z -Wl,relro -o fpmsyncd fpmsyncd-fpmsyncd.o fpmsyncd-fpmlink.o fpmsyncd-routesync.o fpmsyncd-warmRestartHelper.o fpmsyncd-orch_zmq_config.o  -lswsscommon -lnexthopgroup -lnl-nf-3 -lnl-route-3 -lnl-genl-3 -lnl-3 -lhiredis
2026-05-25T05:56:13.7258134Z /usr/bin/ld: cannot find -lnexthopgroup: No such file or directory
2026-05-25T05:56:13.7465330Z collect2: error: ld returned 1 exit status
2026-05-25T05:56:13.7477116Z make[4]: *** [Makefile:419: fpmsyncd] Error 1
2026-05-25T05:56:13.7478869Z make[4]: Leaving directory '/__w/1/s/fpmsyncd'
2026-05-25T05:56:13.7480812Z make[3]: *** [Makefile:420: all-recursive] Error 1

Hi @radha-danda , thanks for your update.
I believe this is caused by sonic-swss PR #4394 which added -lnexthopgroup to fpmsyncd's link dependencies and updated swss's own CI pipeline to download the libnexthopgroup deb, but did not update the sairedis CI pipeline accordingly. So when sairedis CI compiles swss from master, it cannot find the library.

I've opened a PR sonic-net/sonic-sairedis#1908 to fix this. It adds the libnexthopgroup deb download and installation to sairedis CI pipeline files.

purush-nexthop pushed a commit to nexthop-ai/sonic-buildimage that referenced this pull request Jun 10, 2026
…roup deb for RIB/FIB (sonic-net#26423)

* [rules][src]: Add sonic-fib for nexthopgroup deb

Update compiling files to build libnexthopgroup debian for sonic-fib.

Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>
Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>

* [src/libraries/sonic-fib]: Implementation for sonic-fib

Introduce sonic-fib, a C++ library that provides encoding and decoding
capabilities for NextHopGroupFull objects:
- FRR uses the encoding function to generate a JSON string embedded in
  messages sent to fpmsyncd
- fpmsyncd uses the decoding function to reconstruct the NHG object from
  the incoming JSON string

To minimize human error, the library uses a JSON Schema as the single source
of truth and Jinja2 templates to auto-generate the required code.

Key components:
- Data schema: NextHopGroupFull.json drives auto-generation of C++ classes,
  JSON codecs, and C struct wrappers via render_schema.py + Jinja2.
- C-API: C-callable interface for FRR to encode NHG objects into JSON.
- Logging: pluggable FIB_LOG macro with per-process callback registration
  (fib_frr_register_callback for FRR, registerLogCallback for SWSS).
- Unit tests: covers C++ class behavior, JSON round-trip, C-API conversion,
  and logging callback using Google Test.

Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>

---------

Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>
Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
roger530-ho pushed a commit to roger530-ho/sonic-buildimage that referenced this pull request Jun 23, 2026
…roup deb for RIB/FIB (sonic-net#26423)

* [rules][src]: Add sonic-fib for nexthopgroup deb

Update compiling files to build libnexthopgroup debian for sonic-fib.

Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>
Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>

* [src/libraries/sonic-fib]: Implementation for sonic-fib

Introduce sonic-fib, a C++ library that provides encoding and decoding
capabilities for NextHopGroupFull objects:
- FRR uses the encoding function to generate a JSON string embedded in
  messages sent to fpmsyncd
- fpmsyncd uses the decoding function to reconstruct the NHG object from
  the incoming JSON string

To minimize human error, the library uses a JSON Schema as the single source
of truth and Jinja2 templates to auto-generate the required code.

Key components:
- Data schema: NextHopGroupFull.json drives auto-generation of C++ classes,
  JSON codecs, and C struct wrappers via render_schema.py + Jinja2.
- C-API: C-callable interface for FRR to encode NHG objects into JSON.
- Logging: pluggable FIB_LOG macro with per-process callback registration
  (fib_frr_register_callback for FRR, registerLogCallback for SWSS).
- Unit tests: covers C++ class behavior, JSON round-trip, C-API conversion,
  and logging callback using Google Test.

Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>

---------

Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>
Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
xdqi pushed a commit to canonical/sonic-buildimage that referenced this pull request Jul 6, 2026
…roup deb for RIB/FIB (sonic-net#26423)

* [rules][src]: Add sonic-fib for nexthopgroup deb

Update compiling files to build libnexthopgroup debian for sonic-fib.

Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>
Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>

* [src/libraries/sonic-fib]: Implementation for sonic-fib

Introduce sonic-fib, a C++ library that provides encoding and decoding
capabilities for NextHopGroupFull objects:
- FRR uses the encoding function to generate a JSON string embedded in
  messages sent to fpmsyncd
- fpmsyncd uses the decoding function to reconstruct the NHG object from
  the incoming JSON string

To minimize human error, the library uses a JSON Schema as the single source
of truth and Jinja2 templates to auto-generate the required code.

Key components:
- Data schema: NextHopGroupFull.json drives auto-generation of C++ classes,
  JSON codecs, and C struct wrappers via render_schema.py + Jinja2.
- C-API: C-callable interface for FRR to encode NHG objects into JSON.
- Logging: pluggable FIB_LOG macro with per-process callback registration
  (fib_frr_register_callback for FRR, registerLogCallback for SWSS).
- Unit tests: covers C++ class behavior, JSON round-trip, C-API conversion,
  and logging callback using Google Test.

Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>

---------

Signed-off-by: Eddie Ruan <eddie.ruan@alibaba-inc.com>
Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

8 participants