NOTE: This documents describes the internal architecture of NC-SId daemon. However, it is meant to be used as a guide for understanding the code, not on its own. Some details are intentionally omitted.
In the diagram above the components are split into four groups:
NC-SId Core. These are new components implemented in NC-SId.
Hardware. External hardware components, in this case, the NIC.
EC. This is the code borrowed from EC. The three state machines are pretty much copied from EC code.
External Components. These are external services/daemons NC-SIs interacts with.
Let's look into their details.
In the NIC — NC-SId interactions, NIC acts as a server, replying to NC-SId requests and NC-SId itself acts as a client, sending those requests. Thus, there is no state in NIC (server), but there is a state in NC-SId (client).
NC-SId reuses the state machines from EC. They are treated like black boxes. They are C functions with simple interface: the state machine is given incoming NC-SI command buffer (reply from the NIC) and returns the buffer that needs to be sent to the NIC (the next command).
This state machine performs basic configuration of the NC-SI comm channel and also reads the MAC Address of the NIC.
Once BMC's network is configured, this state machine sets up filters in the NIC.
This state machine periodically tests NC-SI connection with the NIC, verifies filters and queries the NIC state (hostless or host-based). If it ever fails, all state machines restart, which means that NC-SI in the NIC is also reset and reconfigured.
In addition to the buffer there are parameters that provide information which is not a part of EC state machines' state:
In the initial state the command buffer (reply from the NIC) is empty. When there is nothing more to send to the NIC, i.e. that particular state machine is done, it returns empty buffer.
NC-SId uses phosphord-networkd to configure the BMC's network (MAC Address). In turn, phosphord-networkd uses systemd. Their interactions go through DBus.
This component coordinates the interaction between EC State Machines and is also heavily based on EC code. It uses net::SockIO interface to interact with the NIC and net::ConfigBase interface to set/query MAC Address.
Implements net::ConfigBase and makes calls to phosphord-networkd via DBus to get/set MAC Address.
Implements net::SockIO and sends NC-SI commands to the NIC through raw Unix socket. That socket is configured using net::IFace component, which represents the network interface (think ethX). To simplify testing, the abstract net::IFaceBase interface is introduced.
To allow some fairly sophisticated unit-tests, EC State Machines as well as ncsi::StateMachine component only interact with the outside world using net::SockIO and net::ConfigBase interfaces. This makes it easy to mock them.
The most complicated part of these tests is mock::NIC, which acts as a NC-SI server, replying to NC-SI requests coming from NC-SI State Machines.