|
| 1 | +# fboss-sim - FBOSS Simulator Runtime |
| 2 | + |
| 3 | +Minimal Docker runtime (~1.2 GB) for FBOSS with fake SAI — no hardware required. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +```bash |
| 8 | +# 1. Build FBOSS with fake SAI (binaries land in .build_dir/build/fboss/). |
| 9 | +# Use the standard getdeps OSS build with the fake-SAI target. |
| 10 | +sudo ./build/fbcode_builder/getdeps.py build --allow-system-packages fboss |
| 11 | + |
| 12 | +# 2. Build the runtime image. |
| 13 | +# The packager has two phases: |
| 14 | +# --collect-only : resolve binaries+libs into tmp_build_dir/ (ldd must run |
| 15 | +# in an OS matching the image base — CentOS Stream 9) |
| 16 | +# --build-only : docker build the image from tmp_build_dir/ |
| 17 | +# If you built on a CentOS Stream 9 host, run both at once with no flag: |
| 18 | +python3 fboss-sim/scripts/fboss-sim-docker-package.py |
| 19 | + |
| 20 | +# 3. Start the container |
| 21 | +python3 fboss-sim/scripts/fboss-sim-docker-run.py |
| 22 | + |
| 23 | +# 4. Run integration test |
| 24 | +docker exec fboss_sim_runtime_${USER} /opt/fboss/bin/fboss2_integration_test |
| 25 | +``` |
| 26 | + |
| 27 | +### Split build/host environments |
| 28 | + |
| 29 | +When FBOSS is built inside a CentOS build container on a different-distro host |
| 30 | +(e.g. Ubuntu), `ldd` must resolve libraries inside the container, but |
| 31 | +`docker build` needs the host's Docker daemon. Run the two phases separately: |
| 32 | + |
| 33 | +```bash |
| 34 | +# collect inside the build container (CentOS libs resolve correctly) |
| 35 | +docker exec <build-container> python3 \ |
| 36 | + fboss-sim/scripts/fboss-sim-docker-package.py --collect-only |
| 37 | + |
| 38 | +# build the image on the host |
| 39 | +python3 fboss-sim/scripts/fboss-sim-docker-package.py --build-only |
| 40 | +``` |
| 41 | + |
| 42 | +## Agent Modes |
| 43 | + |
| 44 | +**Split mode** (default): `fboss_sw_agent` + `fboss_hw_agent@0` run as separate systemd services. |
| 45 | +The hw_agent connects to sw_agent over IPv6 (`::1`). This requires the container to have a |
| 46 | +non-loopback IPv6 address — `fboss-sim-docker-run.py` handles this automatically by creating |
| 47 | +a user-defined IPv6-enabled Docker network (`fboss_sim_net_${USER}`, subnet `fd00:fb05:5::/64`). |
| 48 | + |
| 49 | +**Monolithic mode**: single `wedge_agent` process. |
| 50 | +```bash |
| 51 | +docker exec fboss_sim_runtime_${USER} switch-agent-mode.sh mono |
| 52 | +``` |
| 53 | + |
| 54 | +## Useful Commands |
| 55 | + |
| 56 | +```bash |
| 57 | +# Check agent status |
| 58 | +docker exec fboss_sim_runtime_${USER} systemctl status fboss_sw_agent |
| 59 | +docker exec fboss_sim_runtime_${USER} systemctl status fboss_hw_agent@0 |
| 60 | + |
| 61 | +# View agent logs |
| 62 | +docker exec fboss_sim_runtime_${USER} tail -f /var/facebook/logs/fboss/wedge_agent.log |
| 63 | + |
| 64 | +# Run FBOSS CLI |
| 65 | +docker exec fboss_sim_runtime_${USER} /opt/fboss/bin/fboss2 show interface |
| 66 | + |
| 67 | +# Open a shell |
| 68 | +docker exec -it fboss_sim_runtime_${USER} bash |
| 69 | +``` |
| 70 | + |
| 71 | +## Architecture |
| 72 | + |
| 73 | +``` |
| 74 | +fboss-sim/ |
| 75 | +├── docker/ |
| 76 | +│ ├── Dockerfile.runtime # CentOS Stream 9 minimal runtime image |
| 77 | +│ └── runtime/ |
| 78 | +│ ├── mono.conf # Monolithic agent config |
| 79 | +│ ├── fruid.json # Platform identification (virtual env) |
| 80 | +│ ├── setup-container.sh # Runs at image build time: symlinks, jemalloc, services |
| 81 | +│ └── switch-agent-mode.sh # Toggle between split and monolithic mode |
| 82 | +└── scripts/ |
| 83 | + ├── fboss-sim-docker-package.py # Collect binaries+libs (via ldd), build runtime image |
| 84 | + └── fboss-sim-docker-run.py # Create IPv6 network, start runtime container |
| 85 | +``` |
| 86 | + |
| 87 | +`Dockerfile.runtime` copies the FBOSS `centos-09.0` rootfs overlay |
| 88 | +(`fboss-image/image_builder/templates/centos-09.0/root_files/`) for the systemd |
| 89 | +layout — the agent units the simulator runs (`fboss_sw_agent`, |
| 90 | +`fboss_hw_agent@`, the hw-agents target), the login-shell env hook, and the |
| 91 | +eth0 IPv6 sysctl. That rootfs is part of the FBOSS tree, so this directory |
| 92 | +has no external build dependencies. |
| 93 | + |
| 94 | +### How `fboss-sim-docker-package.py` works |
| 95 | + |
| 96 | +1. Verifies required binaries exist in `.build_dir/build/fboss/` |
| 97 | +2. **Collect phase** (`--collect-only`, or the first half of a flagless run): |
| 98 | + resolves each binary's shared libraries via `ldd` and copies binaries, |
| 99 | + libraries, and config files into `tmp_build_dir/`. This must run where the |
| 100 | + resolved libs match the image base OS (CentOS Stream 9). |
| 101 | +3. **Build phase** (`--build-only`, or the second half of a flagless run): |
| 102 | + builds the Docker image from `Dockerfile.runtime` using `tmp_build_dir/` as |
| 103 | + context, then cleans up `tmp_build_dir/`. |
| 104 | + |
| 105 | +### Why IPv6 matters for split mode |
| 106 | + |
| 107 | +`folly::SocketAddress::setFromLocalPort()` calls `getaddrinfo(nullptr, port, AI_ADDRCONFIG)`. |
| 108 | +`AI_ADDRCONFIG` only returns IPv6 results if the host has at least one non-loopback IPv6 address. |
| 109 | +Docker's default bridge sets `net.ipv6.conf.eth0.disable_ipv6=1` per-interface, so containers |
| 110 | +get no non-loopback IPv6 → Thrift servers bind to `0.0.0.0` only → hw_agent's connection to |
| 111 | +`::1` is refused. The user-defined network with `--ipv6` prevents this. |
| 112 | + |
| 113 | +## Binaries Included |
| 114 | + |
| 115 | +| Binary | Purpose | |
| 116 | +|--------|---------| |
| 117 | +| `wedge_agent-sai_impl` | Monolithic agent (fake SAI) | |
| 118 | +| `fboss_sw_agent` | Split mode: SW/control plane | |
| 119 | +| `fboss_hw_agent-sai_impl` | Split mode: HW/forwarding plane (fake SAI) | |
| 120 | +| `fboss2` | FBOSS CLI | |
| 121 | +| `fboss2-dev` | FBOSS dev CLI | |
| 122 | +| `fboss2_integration_test` | CLI integration test suite | |
| 123 | +| `setup_fboss_env` | Environment setup helper | |
| 124 | + |
| 125 | +## Container Capabilities |
| 126 | + |
| 127 | +- `CAP_NET_ADMIN`: TUN interface creation (TunManager) |
| 128 | +- `CAP_SYS_ADMIN`: systemd cgroup management |
| 129 | +- `/dev/net/tun`: virtual network interfaces |
| 130 | +- `--shm-size=512m`: shared memory for FBOSS IPC |
0 commit comments