服务层 - Orch

Finally, to facilitate the use of the individual services, SONiC has further encapsulated the communication layer by providing a base class for each service: [Orch](https://github.com/sonic-net/sonic-swss/blob/master/src/orchagent/orch. hcommon/consumertatetable.h).

Thanks to these above encapsulations, the encapsulation of message communication in Orch is relatively simple, and the main class diagram is as follows:

Note

注意:由于这一层是服务层,所以其代码是在sonic-swss的仓库中,而不是sonic-swss。这个类中除了消息通信的封装以外,还提供了很多和服务实现相关的公共函数,比如,日志文件等等。

As you can see, Orch mainly encapsulates SubscriberStateTable and ConsumerStateTable to simplify and unify the subscription of messages. The core code is very simple, which is to create different Consumers according to different database types, as follows:

void Orch::addConsumer(DBConnector *db, string tableName, int pri)
{
    if (db->getDbId() == CONFIG_DB || db->getDbId() == STATE_DB || db->getDbId() == CHASSIS_APP_DB) {
        addExecutor(
            new Consumer(
                new SubscriberStateTable(db, tableName, TableConsumable::DEFAULT_POP_BATCH_SIZE, pri),
                this,
                tableName));
    } else {
        addExecutor(
            new Consumer(
                new ConsumerStateTable(db, tableName, gBatchSize, pri),
                this,
                tableName));
    }
}

参考资料

  1. SONiC Architecture
  2. Github repo: sonic-swss
  3. Github repo: sonic-swss-common