Blog>>Networks>>Network infrastructure>>Enhancing SONiC — the process of developing custom network functionality

Enhancing SONiC — the process of developing custom network functionality

In the previous article, we introduced our reasons for exploring SONiC’s potential in terms of building new network functionalities, presented a use case, and described how we approached the task on the logical level.

In this part, we want to share the experience we have gained through the development process. Note: please do not treat this as a comprehensive developer’s guide. What we explain here is our process and the key takeaways from it, which we believe might come in handy for other SONiC developers.

The developer’s resources

Before we start, a few words about the knowledge sources and repos.

From a developer’s perspective, the SONiC project has several resources used on a daily basis. Those include:

Apart from the official sources, we’ve found the Developer’s Overview of Sonic      link-icon (presented on Youtube      link-icon as well) by Praveen Chaudhary to be a good starting point for an aspiring SONiC developer.

Development plan

The intended solution was to extend ACLs with UDFs. How was that approached?

Having to deal with ACLs, the first place we checked was the doc/acl      link-icon directory, specifically ACL High Level Design      link-icon. It showcases the flow diagram of the creation of ACL objects in terms of the logical architecture of the control plane (figure modified):

Fig.1: Flow diagram of the creation of ACL objectsSource: SONiC GitHub      link-icon
Flow diagram of the creation of ACL objects

The logical architecture does not map 1-to-1 to the physical software architecture. In terms of the processes involved, ACL creation needs to engage the following physical components:

Fig.2: Physical components involved in ACL creation
Physical components involved in ACL creation

Our plan was to update the control flow and verify that the ACL configuration based on user-defined fields is handled correctly throughout the entire stack.

SAI specification

First, based on the SAI documentation UDF-based ACL      link-icon and the actual SAI definitions      link-icon, we’ve specified the proper SAI API usage for our use case.

SAI, for ACL and UDF mechanisms, defines several object types which must be used. Those objects and their relationships are presented in the picture below:

Fig.3: SAI objects’ relationships for ACL and UDF mechanisms
SAI objects’ relationships for ACL and UDF mechanisms

Note: for ACL RULE and ACL TABLE objects not all attributes are shown (only those important/used for the use case)

In general, a UDF Group may contain multiple UDF objects (in fact a UDF object references the UDF Group to which it belongs). Multiple UDF objects may point to the same or different UDF Match objects (when a packet goes through a UDF group object, one UDF is selected based on its UDF match object). For the purposes of our use case, single UDF Match and UDF objects are enough.

The initial research has shown that most of the development work will be done in Orchestration Agent (aka Orchagent). It’s the component responsible for interpreting the user configuration and calling the SAI API (through a database proxy). We needed to implement two kinds of change in orchagent:

  1. add new logic for creating UDF objects with SAI,
  2. modify the existing logic to use the UDF in ACL tables and ACL rules with SAI.
Improve your network operations. Check how we can help.

Development execution

We could separate the two phases of development:

  1. Core logic changes in Orchagent - implementing the core logic for configuring UDF with SAI API and connecting the UDFs with ACLs.
  2. Integrating the Orchagent changes through SONiC - fixing any follow-up bugs or problems.

Phase 1 Core logic changes - Orchagent

Knowing what new data is required by SAI from the user, we’ve updated the Configuration Database schema, which serves as an input for Orchestration Agent.

Having specified the required input and expected output for Orchagent, it was enough to implement the test case for configuring UDF-based ACLs using the existing Orchagent unittest infrastructure:

Fig.4: Orchagent unit test scenario visualization
Orchagent unit test scenario visualization

Finally, using the test-first approach, we implemented and verified the required logic in Orchagent. Looking at the ACL flow diagram, the central piece was working as expected:

Fig.5: ACL configuration phase 1 work-in-progress
ACL configuration phase 1 work-in-progress

Phase 2 Breaking further through this jungle (watch out for the bugs)

At that point, we were not in possession of a physical switch with SONiC installed and were thus limited by the capabilities of the SONiC virtual (software) switch. We performed multiple trials, but could not get the software switch to respect the ACL configurations. That made it impossible for us to test ACLs on the data plane.

We could only verify if the control plane worked as expected. A valid approach to test that in SONiC is to check the ASIC_DB database, which reflects the current state of the underlying SAI-compliant ASIC.

The scenario was simple:

  • pass a simple UDF-based ACL config to swssconfig,
  • verify that the content of ASIC_DB Redis database resembles our input.
Fig.6: The principle of end-2-end test scenario
The principle of end-2-end test scenario

The first results were negative. The ASIC_DB database showed no valid UDF-based ACLs configured. Orchagent syslog analysis gave us the reason.

There is a library in SONiC (saimetadata) responsible for enriching SAI API with additional runtime metadata. We configured a SAI object not used by SONiC before and some part of the SAI metadata logic for that object was not implemented yet.

Moreover, there are two components dependent on saimetadata: Orchagent (via the SAI Redis proxy) and SyncD (responsible for interfacing with the vendor ASIC according to the state of ASIC_DB). So now we knew that both Orchagent and SyncD needed a fix.

Fig.7: ACL configuration phase 2 work-in-progress
ACL configuration phase 2 work-in-progress

The saimetadata fix required adding missing validation of the data and turned out to be rather simple. We rebuilt and redeployed the swss and syncd containers.

At that point, the control plane test was successful: a UDF-based ACL configuration was correctly digested by the system, which could be verified by the ASIC state represented in ASIC_DB.

Fig.8: ACL+UDF successful configuration applied
ACL+UDF successful configuration applied

Development environment setup

Now we would like to share some of our experience with development setup.

Because of the large number and variety of components in the SONiC system, the build system is rather complicated. There is a convenient Makefile available for the user. The actual build of targets, i.e. .deb packages, Docker images and binary images, is dockerized in multiple layers of containers and governed by autotools, aka GNU Build System. That gives a useful separation between the host machine and the build process, resulting in a robust build toolchain working out-of-the-box.

That however, does not play well with the smart modern IDEs used for development. Accurate index search, test framework integration, integrated debugger, code completion, and compilation errors shown in the editor before the code is compiled - all these increase one's productivity, but require the development tools to be fully aligned with the build process.

Remote development, but hosted locally

Our use case required most of the work to be performed within the Orchagent component, written in C++. Practically speaking, the simplest setup for a C++ project would be to have the dependencies and build tools natively on the host system, alongside the IDE (CLion by JetBrains      link-icon in our case):

Fig.9: Regular IDE development overview
Regular IDE development overview

Given the system dependencies and package versions required, it is not possible to build Orchagent natively on a regular Ubuntu machine using the preferred IDE in a simple manner.

To work around that problem we used a tool called JetBrains Gateway      link-icon. Orchagent build is configured inside a Debian Docker container hosted locally, with all the specific required .deb packages installed by hand. Then, the JetBrains client connects via ssh to the Docker builder instance and runs a CLion backend there. The host system is just used for rendering and interacting with the IDE frontend. The Gateway supports any ssh-enabled system, but hosting a Docker instance locally was just the most convenient solution:

Fig.10: Remote IDE development overview
Remote IDE development overview

Judging from the information we got from the SONiC community via the sonicproject Google Group      link-icon, such an approach does not seem to be widespread among SONiC developers.

There are of course alternatives to the JetBrains Gateway. For example, an analogous approach is available for VS Code in the Visual Studio Code Remote Development extension      link-icon.

Judging from the information we got from the SONiC community via the sonicproject Google Group      link-icon, such an approach does not seem to be widespread among SONiC developers.

There are of course alternatives to the JetBrains Gateway. For example, an analogous approach is available for VS Code in the Visual Studio Code Remote Development extension      link-icon.

Summary - lessons learned

  • This specific project required flexibility and trial-and-error methods. We never knew if we were chasing a dead end or a silver bullet. One can never be certain about the time estimates for research tasks.

  • The SONiC control plane is divided into functional containers. The data plane is abstracted behind the SAI layer. That results in a flexible and relatively easy-to-learn architecture, open for extension.

  • From the developer's perspective, SONiC has a rather complicated build system with knowledge stored in multiple spots:

  • “Remote” development on a local container can be a lifesaver when working on projects with strict or complicated dependency requirements.

In the next part, we will take you through the final stage - verification of our proof of concept in a lab setup. In general, a UDF Group may contain multiple UDF objects (in fact a UDF object references the UDF Group to which it belongs). Multiple UDF objects may point to the same or different UDF Match objects (when a packet goes through a UDF group object, one UDF is selected based on its UDF match object).

Drożdż Łukasz

Łukasz Drożdż

Software Engineer

Łukasz Drożdż is a Software Development Engineer with seven years of experience. With a diverse skill set and a keen eye for detail, Łukasz has established himself as a capable and innovative contributor in the field of technology. His expertise in C++ reflects his ability to create high-performance and...Read about author >
Pawłowski Michał

Michał Pawłowski

Senior Network Engineer

Michał Pawłowski is a network engineer and solution architect whose main areas of focus are cloud, SDN, NFV, automation. He has over 10 years of experience in telco/ITC industry and has worked as an architect in projects related to telco networks, automation, network virtualization and orchestration. At...Read about author >
Sikorski  Tomasz

Tomasz Sikorski

Engineering Manager

Tomasz Sikorski is an Engineering Manager with over 15 years of experience in networks and telecommunications. He is a highly motivated and experienced team manager, engineer, and enthusiast of new technologies in the IT and ICT industry. Following trends and innovations, he has gained experience in leading...Read about author >

Read also

Get your project estimate

For businesses that need support in their software or network engineering projects, please fill in the form and we'll get back to you within one business day.