Code repo
SONiC的代码都托管在GitHub的sonic-net账号上,仓库数量有30几个之多,所以刚开始看SONiC的代码时,肯定是会有点懵的,不过不用担心,我们这里就来一起看看~
核心仓库
First are the two most important core repositories in SONiC: SONiC and sonic-buildimage.
Landing仓库:SONiC
https://github.com/sonic-net/SONiC
This repository stores SONiC's Landing Page and a lot of documentation, wiki, tutorials, Slides from previous Talks, etc. etc. This repository can be said to be the most common repository for every newcomer to get started, but note that there is no code in this repository, only documentation.
镜像构建仓库:sonic-buildimage
https://github.com/sonic-net/sonic-buildimage
Why is this build repository important to us? Unlike other projects, SONiC's build repository is actually its main repository! This repository contains:
- 所有的功能实现仓库,它们都以submodule的形式被加入到了这个仓库中(
src
目录) - 所有设备厂商的支持文件(
device
目录),比如每个型号的交换机的配置文件,用来访问硬件的支持脚本,等等等等,比如:我的交换机是Arista 7050 QX-32S,那么我就可以在device/arista/x86_64-arista_7050_qx32s
目录中找到它的支持文件。 - 所有ASIC芯片厂商提供的支持文件(
platform
目录),比如每个平台的驱动程序,BSP,底层支持的脚本等等。这里我们可以看到几乎所有的主流芯片厂商的支持文件,比如:Broadcom,Mellanox,等等,也有用来做模拟软交换机的实现,比如vs和p4。 - SONiC用来构建所有容器镜像的Dockerfile(
dockers
目录) - 各种各样通用的配置文件和脚本(
files
目录) - 用来做构建的编译容器的dockerfile(
sonic-slave-*
目录) - 等等……
Because this repository has all the relevant resources put together, we basically only need to download this one source code repository when learning SONiC's code, no matter it is very convenient to search or jump!
功能实现仓库
In addition to the core repository, there are also many feature implementation repositories under SONiC, which are implementations of various containers and subservices. These repositories are placed under the src
directory of sonic-buildimage in the form of submodule, which we also need to know if we want to make changes and contributions to SONiC.
SWSS(Switch State Service)相关仓库
As we introduced in the previous article, the SWSS container is the brain of SONiC. Under SONiC, it consists of two repo's: sonic-swss-common and sonic-swss.
SWSS公共库:sonic-swss-common
First is the public library: sonic-swss-common (https://github.com/sonic-net/sonic-swss-common).
This repository contains all the public functions required by the *mgrd
and *syncd
services, such as the encapsulation of logger, json, netlink, Redis operations and various Redis-based inter-service communication mechanisms. Although it can be seen that this repository was initially targeted specifically for use by the swss service, it is also referenced by many other repositories, such as swss-sairedis
and swss-restapi
, because of its many features.
SWSS主仓库:sonic-swss
Then there is the main SWSS repository, sonic-swss: https://github.com/sonic-net/sonic-swss.
We can find in this repository:
- 绝大部分的
*mgrd
和*syncd
服务:orchagent
,portsyncd/portmgrd/intfmgrd
,neighsyncd/nbrmgrd
,natsyncd/natmgrd
,buffermgrd
,coppmgrd
,macsecmgrd
,sflowmgrd
,tunnelmgrd
,vlanmgrd
,vrfmgrd
,vxlanmgrd
,等等。 swssconfig
:在swssconfig
目录下,用于在快速重启时(fast reboot)恢复FDB和ARP表。swssplayer
:也在swssconfig
目录下,用来记录所有通过SWSS进行的配置下发操作,这样我们就可以利用它来做replay,从而对问题进行重现和调试。- 甚至一些不在SWSS容器中的服务,比如
fpmsyncd
(bgp容器)和teamsyncd/teammgrd
(teamd容器)。
SAI/平台相关仓库
Next up is SAI as a switch abstraction interface, [although SAI was proposed by Microsoft and released in March 2015 as version 0.1](https://www.opencompute.org/documents/switch-abstraction-interface-ocp- specification-v0-2-pdf), [it was accepted by OCP and made a public standard in September 2015, before SONiC even released the first version](https://azure.microsoft.com/en-us/blog/switch- abstraction-interface-sai-officially-accepted-by-the-open-compute-project-ocp/), which is one of the reasons why SONiC has been able to get support from so many vendors in such a short time. And because of this, SAI's code repository has been divided into two parts:
- OCP下的OpenComputeProject/SAI:https://github.com/opencomputeproject/SAI。里面包含了有关SAI标准的所有代码,包括SAI的头文件,behavior model,测试用例,文档等等。
- SONiC下的sonic-sairedis:https://github.com/sonic-net/sonic-sairedis。里面包含了SONiC中用来和SAI交互的所有代码,比如syncd服务,和各种调试统计,比如用来做replay的
saiplayer
和用来导出asic状态的saidump
。
In addition to these two repositories, there is also a platform-related repository, for example: sonic-platform-vpp, which serves to implement data plane functions using vpp through SAI's interface, equivalent to a High-performance soft switch. I personally feel that it may be merged into the buildimage repository in the future, as part of the platform directory.
管理服务(mgmt)相关仓库
然后是SONiC中所有和管理服务相关的仓库:
名称 | 说明 |
---|---|
sonic-mgmt-common | 管理服务的基础库,里面包含着translib ,yang model相关的代码 |
sonic-mgmt-framework | 使用Go来实现的REST Server,是下方架构图中的REST Gateway(进程名:rest_server ) |
sonic-gnmi | 和sonic-mgmt-framework类似,是下方架构图中,基于gRPC的gNMI(gRPC Network Management Interface)Server |
sonic-restapi | 这是SONiC使用go来实现的另一个配置管理的REST Server,和mgmt-framework不同,这个server在收到消息后会直接对CONFIG_DB进行操作,而不是走translib(下图中没有,进程名:go-server-server ) |
sonic-mgmt | 各种自动化脚本(ansible 目录),测试(tests 目录),用来搭建test bed和测试上报(test_reporting 目录)之类的, |
这里还是附上SONiC管理服务的架构图,方便大家配合食用 [4]:
平台监控相关仓库:sonic-platform-common和sonic-platform-daemons
The following two warehouses are related to platform monitoring and control, such as LEDs, fans, power supplies, temperature control, etc.:
名称 | 说明 |
---|---|
sonic-platform-common | 这是给厂商们提供的基础包,用来定义访问风扇,LED,电源管理,温控等等模块的接口定义,这些接口都是用python来实现的 |
sonic-platform-daemons | 这里包含了SONiC中pmon容器中运行的各种监控服务:chassisd ,ledd ,pcied ,psud ,syseepromd ,thermalctld ,xcvrd ,ycabled ,它们都使用python实现,通过和中心数据库Redis进行连接,和加载并调用各个厂商提供的接口实现来对各个模块进行监控和控制 |
其他功能实现仓库
In addition to these repositories above, SONiC has a number of repositories that implement various aspects of its functionality, some of which are one or more processes, and some of which are libraries that serve the following purposes:
仓库 | 介绍 |
---|---|
sonic-snmpagent | AgentX SNMP subagent的实现(sonic_ax_impl ),用于连接Redis数据库,给snmpd提供所需要的各种信息,可以把它理解成snmpd的控制面,而snmpd是数据面,用于响应外部SNMP的请求 |
sonic-frr | FRRouting,各种路由协议的实现,所以这个仓库中我们可以找到如bgpd ,zebra 这类的路由相关的进程实现 |
sonic-linkmgrd | Dual ToR support,检查Link的状态,并且控制ToR的连接 |
sonic-dhcp-relay | DHCP relay agent |
sonic-dhcpmon | 监控DHCP的状态,并报告给中心数据库Redis |
sonic-dbsyncd | lldp_syncd 服务,但是repo的名字没取好,叫做dbsyncd |
sonic-pins | Google开发的基于P4的网络栈支持(P4 Integrated Network Stack,PINS),更多信息可以参看PINS的官网。 |
sonic-stp | STP(Spanning Tree Protocol)的支持 |
sonic-ztp | Zero Touch Provisioning |
DASH | Disaggregated API for SONiC Hosts |
sonic-host-services | 运行在host上通过dbus用来为容器中的服务提供支持的服务,比如保存和重新加载配置,保存dump之类的非常有限的功能,类似一个host broker |
sonic-fips | FIPS(Federal Information Processing Standards)的支持,里面有很多为了支持FIPS标准而加入的各种补丁文件 |
sonic-wpa-supplicant | 各种无线网络协议的支持 |
工具仓库:sonic-utilities
https://github.com/sonic-net/sonic-utilities
This repository holds all of SONiC's tools under the command line:
config
,show
,clear
目录:这是三个SONiC CLI的主命令的实现。需要注意的是,具体的命令实现并不一定在这几个目录里面,大量的命令是通过调用其他命令来实现的,这几个命令只是提供了一个入口。scripts
,sfputil
,psuutil
,pcieutil
,fwutil
,ssdutil
,acl_loader
目录:这些目录下提供了大量的工具命令,但是它们大多并不是直接给用户使用的,而是被config
,show
和clear
目录下的命令调用的,比如:show platform fan
命令,就是通过调用scripts
目录下的fanshow
命令来实现的。utilities_common
,flow_counter_util
,syslog_util
目录:这些目录和上面类似,但是提供的是基础类,可以直接在python中import调用。- 另外还有很多其他的命令:
fdbutil
,pddf_fanutil
,pddf_ledutil
,pddf_psuutil
,pddf_thermalutil
,等等,用于查看和控制各个模块的状态。 connect
和consutil
目录:这两个目录下的命令是用来连接到其他SONiC设备并对其进行管理的。crm
目录:用来配置和查看SONiC中的CRM(Critical Resource Monitoring)。这个命令并没有被包含在config
和show
命令中,所以用户可以直接使用。pfc
目录:用来配置和查看SONiC中的[PFC(Priority-based Flow Control)][SONiCPFC]。pfcwd
目录:用来配置和查看SONiC中的[PFC Watch Dog][SONiCPFCWD],比如启动,停止,修改polling interval之类的操作。
内核补丁:sonic-linux-kernel
https://github.com/sonic-net/sonic-linux-kernel
Although SONiC is based on debian, the default debian kernel is not always able to run SONiC, for example, a module is not started by default, or some old version of the driver has problems, so SONiC needs a more or less modified Linux kernel. And this repository is used to store all the kernel patches.
参考资料
- SONiC Architecture
- SONiC Source Repositories
- SONiC Management Framework
- SAI API
- SONiC Critical Resource Monitoring
- SONiC Zero Touch Provisioning
- SONiC Critical Resource Monitoring
- SONiC P4 Integrated Network Stack
- SONiC Disaggregated API for Switch Hosts
- SAI spec for OCP