Simplest development setup for Orchagent development

122 views
Skip to first unread message

Łukasz Drożdż

unread,
Sep 28, 2022, 6:30:20 AM9/28/22
to sonicproject
I'd like to add some functionality to Orchagent. I wanted to use an IDE (CLion), so I'd like to build orchagent locally (and run the unit tests) so I can have CLion index the sources properly.

Looking at sonic-swss repo, it says I'd just need prerequisite packages. Namely:
sudo apt-get install libswsscommon libswsscommon-dev libsairedis libsairedis-dev

It's unclear to me where do I get those packages from? Where is the repository hosting those? If that's possible, I'd like to re-use as many pre-build publicly available artifacts as possible.

I know I can just build the target inside docker using the makefile in sonic-buildimage repo, but that's my last resort at the moment.

Bryan.Crossland

unread,
Sep 28, 2022, 11:11:05 AM9/28/22
to Łukasz Drożdż, sonicproject

I use CLion for development and have been working on SWSS. The packages are built from other sections of SONiC. You can get copies of them from the target folder when you do a full build of SONiC.

 

What I’ve ended having to do is create a dev environment that starts with sonic-buildimage as a base. Then run a make configuration, make init, and make to get a full build of SONiC. Then, editing files in the src/sonic-swss, then rebuilding again to run tests.

Error! Filename not specified.

-------------------------------

This document contains material that is confidential in CodiLime Sp. z o.o. DO NOT PRINT. DO NOT COPY. DO NOT DISTRIBUTE. If you are not the intended recipient of this document, be aware that any use, review, retransmission, distribution, reproduction or any action taken in reliance upon this message is strictly prohibited. If you received this in error, please contact the sender and he...@codilime.com. Return the paper copy, delete the material from all computers and storage media.

--
You received this message because you are subscribed to the Google Groups "sonicproject" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonicproject...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonicproject/24d68871-87e6-40a6-a289-156fbf5660e1n%40googlegroups.com.

Łukasz Drożdż

unread,
Sep 28, 2022, 12:27:20 PM9/28/22
to sonicproject
"What I’ve ended having to do is create a dev environment that starts with sonic-buildimage as a base. Then run a make configuration, make init, and make to get a full build of SONiC. Then, editing files in the src/sonic-swss, then rebuilding again to run tests."
So you are simply editing the src/swss submodule in sonic-buildimage and using the docker-based makefile to rebuild swss?

Bryan.Crossland

unread,
Sep 28, 2022, 2:20:36 PM9/28/22
to Łukasz Drożdż, sonicproject

I just run the whole build again. I haven’t tried getting it to run just the SWSS tests by themselves. I looked at the Azure pipeline files a while back but could not reproduce it locally so I just went with rebuilding the whole project each time.

 

The submodules, while should be modular, are not really independent pieces of software. They are tightly coupled to the sonic-build image and other subprojects under it.

Łukasz Drożdż

unread,
Oct 5, 2022, 7:32:56 AM10/5/22
to sonicproject
For future reference: I've managed to setup sonic-swss as a CLion makefile project. That might also work for other means of remote development and similarly for other components.

Here's what I did:
- go to sonic-buildimage repository root

- run debian bullseye with mounted sonic-buildimage and  exposed ssh port 22:
     docker run -it -v $(pwd):/var/sonic-buildimage -p <any free port>:22 debian:bullseye bash

- apt install openssh-server -y

- add a new user:password, for example clion:clion

- reboot && ssh to the image with the new user (easier than later using chown or usermod to access the repository by the clion user)

- install build dependencies mentioned in https://github.com/sonic-net/sonic-swss

- go to https://sonic-build.azurewebsites.net/ui/sonic/Pipelines  ->  Build History  ->  Artifacts  and download the libswsscommon, libsairedis and the .deb dependencies for those. curl is useful. That was an iterative proccess, checking what is missing during the   ./autogen.sh && ./configure && make all. I ended up with:
libnl-3-200_3.5.0-1_amd64.deb
libnl-route-3-200_3.5.0-1_amd64.deb
libnl-nf-3-200_3.5.0-1_amd64.deb
libswsscommon_1.0.0_amd64.deb
libswsscommon-dev_1.0.0_amd64.deb
libsairedis_1.0.0_amd64.deb
libsairedis-dev_1.0.0_amd64.deb
libnl-3-dev_3.5.0-1_amd64.deb
libnl-route-3-dev_3.5.0-1_amd64.deb
libnl-nf-3-dev_3.5.0-1_amd64.deb
libsaivs_1.0.0_amd64.deb
libsaivs-dev_1.0.0_amd64.deb
libsaimetadata_1.0.0_amd64.deb
libsaimetadata-dev_1.0.0_amd64.deb
libnl-genl-3-200_3.5.0-1_amd64.deb
libnl-genl-3-dev_3.5.0-1_amd64.deb
libsairedis_1.0.0_amd64.deb
libswsscommon-dev_1.0.0_amd64.deb
libsaivs_1.0.0_amd64.deb
libsaimetadata_1.0.0_amd64.deb
libsaimetadata-dev_1.0.0_amd64.deb
python3-swsscommon_1.0.0_amd64.deb
libnl-cli-3-200_3.5.0-1_amd64.deb
libnl-cli-3-dev_3.5.0-1_amd64.deb

- apt install all the above debs

- make sure swss is made without errors with make all

- download the CLion Remote Development plugin, go to File -> Remote Development

- connect to the debian image (the port configured earlier, localhost, user clion, password clion, or sth else you picked)

- pick the proper project directory. In my case that was: /var/sonic-buildimage/src/sonic-swss/

- Remote CLion should boot up

- Go to: File  ->  Settings  ->  Build, Execution, Deployment  ->  Makefile  ->  Commands    and set the configuration steps. In my case, the ./configure file had some syntax error due to line "PKG_CHECK_MODULES(JANSSON, jansson)", so I had to delete that line. I wanted no optimization to ease debugging. I ended up with the following steps:
./autogen.sh
grep -v "PKG_CHECK_MODULES(JANSSON, jansson)" ./configure > configure_fixed
cp configure_fixed configure
CXXFLAGS="-g -O0" CFLAGS="-g -O0" sh ./configure

- at that point, I got a fully indexed CLion project.


I guess one could try the same for other components as well.


Regards,
Łukasz

Bryan.Crossland

unread,
Oct 5, 2022, 8:47:31 AM10/5/22
to Łukasz Drożdż, sonicproject

Łukasz, this is excellent! Thank you for sharing.

Łukasz Drożdż

unread,
Jun 7, 2023, 11:58:38 AM6/7/23
to sonicproject
Coming back too this topic, I could share something useful for future readers.
I needed to work a bit with orchagent again. I ended up with the following files and commands, giving me a simple dockerized development environment:


Latitude-5531:~/workspace/sonic-training/sonic-buildimage/src/sonic-swss$ cat Dockerfile.devenv
# syntax=docker/dockerfile:1
FROM debian:bullseye as debs-container
RUN mkdir /var/debs
WORKDIR /var/debs

# pick some azure pipeline artifacts build version
ENV BUILD_ID=287152
ENV DEB_DIR="https://sonic-build.azurewebsites.net/api/sonic/artifacts?branchName=master&platform=vs&buildId=${BUILD_ID}&target=target%2Fdebs%2Fbullseye%2F"

RUN apt update
RUN apt install curl -y
RUN FILE="libnl-3-200_3.5.0-1_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libnl-route-3-200_3.5.0-1_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libnl-nf-3-200_3.5.0-1_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libswsscommon_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libswsscommon-dev_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libsairedis_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libsairedis-dev_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libnl-3-dev_3.5.0-1_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libnl-route-3-dev_3.5.0-1_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libnl-nf-3-dev_3.5.0-1_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libsaivs_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libsaivs-dev_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libsaimetadata_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libsaimetadata-dev_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libnl-genl-3-200_3.5.0-1_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libnl-genl-3-dev_3.5.0-1_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libsairedis_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libswsscommon-dev_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libsaivs_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libsaimetadata_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libsaimetadata-dev_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="python3-swsscommon_1.0.0_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libnl-cli-3-200_3.5.0-1_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libnl-cli-3-dev_3.5.0-1_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libyang-dev_1.0.73_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})
RUN FILE="libyang_1.0.73_amd64.deb" && (curl -L "${DEB_DIR}${FILE}" > ${FILE})

FROM debian:bullseye as devenv

RUN apt update && \
  apt install openssh-server -y
RUN useradd -ms /bin/bash clion
RUN echo 'clion:clion' | chpasswd

RUN apt update
RUN apt install redis-server -y
RUN apt install libhiredis0.14 -y
RUN apt install libhiredis-dev -y
RUN apt install libzmq5 libzmq3-dev -y
RUN apt install libtool -y
RUN apt install autoconf automake -y
RUN apt install dh-exec -y
RUN apt install libgtest-dev -y
RUN apt install libgmock-dev -y

RUN mkdir /var/debs
COPY --from=debs-container /var/debs/* /var/debs/
RUN apt install -y /var/debs/*.deb

WORKDIR /var/sonic-buildimage
RUN service ssh start
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]


Latitude-5531:~/workspace/sonic-training/sonic-buildimage/src/sonic-swss$ DOCKER_BUILDKIT=1 docker build -f Dockerfile.devenv -t swss-devenv:latest .
Latitude-5531:~/workspace/sonic-training/sonic-buildimage/src/sonic-swss$ FREE_PORT=`python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'`
Latitude-5531:~/workspace/sonic-training/sonic-buildimage/src/sonic-swss$ docker run  -d -v $(pwd)/../..:/var/sonic-buildimage -p ${FREE_PORT}:22  swss-devenv:latest
Latitude-5531:~/workspace/sonic-training/sonic-buildimage/src/sonic-swss$ echo $FREE_PORT
54771

Latitude-5531:~/workspace/sonic-training/sonic-buildimage/src/sonic-swss$ cat makefile_pre_configuration.sh
./autogen.sh
grep -v "PKG_CHECK_MODULES(JANSSON, jansson)" ./configure > configure_fixed
cp configure_fixed configure
CXXFLAGS="-g -O0" CFLAGS="-g -O0" sh ./configure 


Then in Clion I do:
- go to File -> Remote Development -> New Connection
- configure ssh with localhost:${FREE_PORT}
- choose project directory /var/sonic-buildimage/src/sonic-swss  -> click Download IDE & Connect
- in the opened remote editor, go to makefile project settings and use the preconfiguration steps from makefile_pre_configuration.sh and voila, I have a buildable complete swss project, indexed with Clion.

In guess the steps are similar for VSCode remote development plugin. 
Reply all
Reply to author
Forward
0 new messages