8000 gini system documentation by mohd-adnaan · Pull Request #86 · citelab/gini · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Runs the test suite on every push and pull request.
#
# The fourth workflow, and the first that is not a publish. Until now nothing automated ran the
# suite (3,389 tests and growing): `release.sh` runs them locally before it tags, which is a real gate but only for the
# person cutting the release, and only on their machine. Everything merged between two releases was
# covered by whoever remembered. A tag then publishes to PyPI on the strength of that.
#
# It is deliberately a TEST workflow and nothing else — no lint, no type check. `ruff check` on this
# tree currently reports 746 errors, so adding it would make the badge red on the first run, and a
# CI that is always red is a CI nobody reads. Cleaning those up is its own piece of work; when it is
# done, a lint job belongs here beside this one.
name: tests

on:
push:
branches: ["**"] # every branch: os-improvements and personal branches merge via PR, and
# a failure is cheapest to read on the branch that caused it
pull_request:
workflow_dispatch:

# A second push to the same branch makes the first run irrelevant. Cancel it rather than queue it.
concurrency:
group: tests-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 25 # a full run is ~3 min; this only catches a hang
strategy:
fail-fast: false # 3.10 and 3.12 fail for different reasons; show both
matrix:
python-version: ["3.10", "3.12"] # the declared floor, and the recommended version

env:
# Most UI tests set this themselves at import, but a few build a QApplication without it
# (test_board_dialog, test_flash_dialog, test_pricing). A runner has no display, so it has to
# be set for the whole job — the same note `scripts/dev.sh` gives for a headless machine.
QT_QPA_PLATFORM: offscreen

steps:
- uses: actions/checkout@v4
with:
# NOT optional, and the failure it prevents is silent rather than loud. setuptools-scm
# derives the version from the nearest tag; a shallow clone has none, so `gini-core`
# would build as 0.1.dev1 — which does not satisfy gini-toolkit's `gini-core>=6.3.2`.
# pip would then resolve that floor by downloading the PUBLISHED gini-core over the top
# of this checkout, and the suite would test PyPI's domain model instead of the branch's.
# That is exactly the trap `scripts/dev.sh` exists to avoid for humans.
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

# PySide6 ships its own Qt, but Qt still dlopens a few system libraries even under the
# offscreen platform plugin.
#
# Installed one at a time, best-effort, ON PURPOSE. These names drift between Ubuntu releases
# — the t64 transition renamed a batch of them in 24.04 — and `ubuntu-latest` moves underneath
# this file without notice. A single name that no longer exists makes apt exit 100 and fails
# the build before anything useful has been learned, which is exactly what the first version
# of this step did. So try each, say which ones are not there, and let the check AFTER the
# install be the real gate: it tests the thing actually at stake (does Qt start?) rather than
# a list of package names nobody can verify without pushing.
#
# No Chromium dependencies on purpose. The three tests that mention QtWebEngine
# (test_webengine_startup, test_terminal_panel, test_quit_guard) are static checks — they
# parse import nodes and assert about them, and never construct a QWebEngineView.
- name: Qt's system libraries (best-effort)
run: |
set +e # NOTHING in this step may fail the job — see the note above.
. /etc/os-release && echo "runner image: $PRETTY_NAME"
# `apt-get update` exits 100 when it merely cannot reach one repository, and a runner
# with a stale or 404ing mirror is common. That — not a renamed package — is what killed
# the first two runs of this workflow: the loop below was already guarded, the update
# above it was not, and both failures look identical from the outside (exit 100).
sudo apt-get update || echo " note: apt-get update did not finish cleanly; continuing"
for pkg in libegl1 libgl1 libxkbcommon0 libdbus-1-3 libxcb-cursor0; do
if sudo apt-get install -y --no-install-recommends "$pkg" >/dev/null 2>&1; then
echo " ok $pkg"
else
echo " MISSING $pkg — not on this image; the Qt check below decides if it mattered"
fi
done
exit 0 # explicit, so a future edit has to mean it to break this

# The script, not a hand-written pip line: `gini` is a namespace package split across
# gini-core and gini-toolkit, and dev.sh installs core FIRST for the reason in the comment
# above. Using it here also means CI exercises the command the README tells contributors to
# run, so it cannot rot without a red run.
- name: install (editable, all three packages)
run: ./scripts/dev.sh install

# From the `dev` extra in frontend-ng/pyproject.toml. Without pytest-qt, 86 tests do not fail
# — they ERROR with "fixture 'qtbot' not found", which reads like broken tests rather than a
# missing package.
- name: test dependencies
run: python3 -m pip install pytest pytest-qt

# The real gate for the apt step above, and the reason it is allowed to be best-effort. If a
# Qt library is genuinely absent this fails naming the missing .so — which is what you need
# in order to fix it — rather than apt failing on a package name that was merely renamed.
- name: Qt starts headless
run: |
python3 - <<'PY'
from PySide6.QtWidgets import QApplication
app = QApplication([])
print("Qt platform plugin:", app.platformName())
assert app.platformName() == "offscreen", app.platformName()
PY

- name: the suite
run: ./scripts/dev.sh test

# A runner has no container runtime, and the suite is written for that: `test_bootstrap`
# checks `shutil.which("docker")` first. Three tests therefore SKIP here that run on a
# developer machine, so this job's totals sit three below a local run. Deliberately not
# writing the exact pair of numbers down: the suite gained ~400 tests in nine days, and a
# hard-coded count in a comment is a lie with a timestamp on it.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ pytest-cache-files-*/

# --- C router build ---
*.o
*.zigobj.o
# `*.zigobj.o` alone did not match the real artifacts, which are `*.zigobj.o.tmpXXXXXXX` — which is
# how six of them stayed tracked through the Zig removal and were still in the tree afterwards.
*.zigobj.o*
config.log
backend/build/
# legacy: Zig removed; kept so any stray cache never re-enters git
Expand Down
123 changes: 92 additions & 31 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,128 @@
# GINI 6 — repository layout

GINI is being modernized **in place** (strangler-fig): the new toolkit grows alongside
the original, and the C gRouter is *adopted and evolved*, not rewritten. This file says
what is part of the new version (v6) and what is archived legacy, so the tree is easy to
navigate during the transition.
What is part of GINI 6, what is archived, and where each piece runs. `CLAUDE.md` at the repo root
covers the same tree in more depth, plus the state of each subsystem; this file is the map.

GINI was modernized **in place** (strangler-fig): the new toolkit grew alongside the original, and
the C gRouter was *adopted and evolved*, not rewritten.

## Active — the GINI 6 toolkit

Three Python distributions, one namespace. `gini` is an implicit **namespace package** split
across `gini-core` and `gini-toolkit`: core owns `gini.domain` and `gini.version`, the toolkit owns
everything else under `gini.`, and neither ships a `gini/__init__.py` or one would shadow the
other's half. Installing one without the other gives a working install of a broken import, which is
why `scripts/dev.sh install` exists and installs core first.

```
frontend-ng/ The new app (PySide6 / Qt 6 / Python 3.12)
core/ gini-core — pure Python, no Qt, no Docker (PyPI: gini-core)
src/gini/domain/ 72 modules: devices, topology, connection grammar, recipes,
the proof-of-activity format, the AOP schema, the xv6 parsers,
the routing model, the tutor's knowledge base
src/gini/version.py which build produced a given proof

frontend-ng/ gBuilder 6 — PySide6 / Qt 6 / Python 3.10+ (PyPI: gini-toolkit)
src/gini/
domain/ pure-Python model (devices, topology) — no Qt
ui/ canvas, palette, inspector, themes, Router Lab
agent/ GiniAPI + tool registry + Ollama loop + MCP server
runtime/ portable user-space data plane (switch, host, shuttle)
ui/ canvas, palette, inspector, themes, the Labs (Machine/Router/
Memory/Storage/Trap/Syscall/Lock/CPU) and the HUDs
agent/ GiniAPI + tool registry + Ollama loop + the Reasoning Twin +
an MCP server, so external agents can drive GINI too
runtime/ the portable user-space data plane (Ethernet-in-UDP)
services/ compiler (topology→wiring), orchestrator (Docker), persistence
tests/ pytest suite (35 passing)
server/ optional: run a lab on a remote Docker/Kata host
setup/ first-run runtime detection and image pull/build
tests/ the pytest suite — 3,389 tests, Qt included

backend/ The real gRouter (adopted C, modernized)
src/grouter/ ~20k-line C router + the Z1/Z2 module seams
include/ gRouter headers
build.zig build the router with Zig (`zig build`)
teaching-center/ the course server — no Qt (PyPI: gini-teaching-center)
src/gini_teaching_center/ threaded HTTPS server over SQLite: activity codes, submissions,
materials, staff accounts. HTTPS only; there is no HTTP mode.

scripts/ dev.sh (install/test/check) · release.sh · images.sh
docs/ design docs, and docs/manual/ — 17 pages on the xv6 integration,
including os-15-known-issues.md, which is kept honest
.github/workflows/ three publish workflows (one per distribution) + tests.yml
```

## Active — the backend, and what runs in the containers

```
backend/
src/grouter/ the real GINI C router, ~23k lines. Forwarding, ARP, ICMP,
include/ OpenFlow 1.0, a Lua control plane, and the VNF modules
(delay, rate, tap, classify, block).
grouter-build/
build.sh zig cc build (used by Docker)
Dockerfile `gini-grouter` image (libslack + readline + the router)
build.sh builds it with a plain C compiler (clang or gcc)
Dockerfile the `gini-grouter` image (libslack + readline + Lua + the router)
run_grouter.py entrypoint: ROUTER_CONFIG → ifconfig/route → grouter
tests/ end-to-end forwarding proofs (forward_test, multihop_test)
third-party/ vendored 10BC8 helpers used by the router/tests (mut)
grconsole.py the router CLI, with history and completion
tests/ end-to-end forwarding proofs (forward_test, multihop_test, …)
sdn/ vendored POX `gar` (Python 3) → the `gini-pox` image
xv6/ gini_patch.py (anchored kernel instrumentation), gini_agent.py
(PID 1, owns QEMU, HTTP :5000) → the `gini-xv6` image
oszoo/ emulated historical OSes over noVNC → the `gini-oszoo` image
gini32/ ESP-IDF firmware for real ESP32-S3 boards on the fabric
tests/ doc/ third-party/ C unit tests, man pages, vendored helpers
```

Four images are built from this tree — **`gini-grouter`, `gini-pox`, `gini-oszoo`, `gini-xv6`**.
Everything else a topology can run (MinIO, PostgreSQL, Redis, Grafana, …) is an off-the-shelf
image. The registry defaults to `ghcr.io/gini-toolkit`; override with `GINI_REGISTRY`.

**The router builds with C, not Zig.** A Zig port was attempted and reverted in July 2026
(`0f07f46`): the router only ever builds inside a Linux container, so the cross-compilation
`zig cc` offered was never used, and a normal clang/gcc is equivalent with one fewer dependency.
The reasoning is preserved at the top of `grouter-build/build.sh`.

## Legacy — kept for reference, not part of v6

```
legacy/
frontend/ the original gBuilder (Python 2.7 / PyQt4) — superseded by frontend-ng
runtime-spike/ the R0 portability spike — superseded by frontend-ng/.../runtime
SConstruct, site_scons/ the old SCons build — the router now builds with Zig
SConstruct, site_scons/ the old SCons build
scripts/ old launcher/setup scripts
backend-src/
gcloud/ gloader/ legacy cloud scripts + the old XML topology loader
gvirtual_switch/ pox/ old UML switch + the POX SDN controller
gvirtual_switch/ pox/ old UML switch + the original POX SDN controller
```

Nothing under `legacy/` is referenced by the active build or tests — re-verified 2026-09-09. It
stays as a harvest source; it lives in git history regardless.

## How a topology becomes containers

```
canvas → Topology → RuntimeCompiler → RuntimeConfig → Orchestrator → docker compose up
(pure) assigns subnets, (a plain writes a self-
IPs, MACs, ports dataclass) contained project
```

Nothing under `legacy/` is referenced by the active build or tests (verified). It stays
as a harvest source until the modernization (Track B/Z) has taken what it needs, then it
can be deleted — it lives in git history regardless.
Experiment traffic does **not** ride Docker networking. Each machine container makes TAP interfaces
and bridges each to a UDP endpoint — Ethernet-in-UDP in user space, no kernel modules, no
privileges beyond `NET_ADMIN`. Docker's `eth0` stays as the management NIC. The same
`RuntimeConfig` also runs fully in-process over localhost UDP (`orchestrator.simulate()`), which is
how the suite tests the data plane without Docker.

## Run it

```bash
# the app
cd frontend-ng && pip install -e . && python -m gini # or: gbuilder
python3 -m venv .venv && source .venv/bin/activate
./scripts/dev.sh install # all three packages, editable, core first
gbuilder # or: python -m gini

# build the real router image once (so "Run" can launch real routers)
QT_QPA_PLATFORM=offscreen ./scripts/dev.sh test # the suite, headless

# build the router image so Run can launch real routers
cd backend && docker build -f grouter-build/Dockerfile -t gini-grouter .

# prove the router forwards (host build or in the image)
# prove the router forwards (host build, or inside the image)
GROUTER_BIN=/path/to/grouter python3 backend/grouter-build/tests/forward_test.py
```

`scripts/README.md` covers releases, version bumps and multi-arch images.

## Graduating to a clean `gini6/`

A clean fork is deliberately deferred. The gRouter is still being ported to Zig (Z3/Z4)
in place, so copying it now would freeze a snapshot that immediately diverges. Once the
Zig port is mature and `legacy/` is fully harvested, the repo can simply be renamed/cut
to `gini6` with only the active tree.
Still deferred, but the reason has changed. The original reason — an in-flight Zig port that a copy
would freeze mid-flight — went away when Zig was reverted. What remains is that `legacy/` has not
been fully harvested. Once it has, the repo can be cut down to the active tree.
Loading
Loading
0