From 8ee64dcb768da113cb0e54de4cf88f342260a8a6 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Mon, 30 Nov 2026 13:16:20 -0500 Subject: [PATCH 1/4] test(vlanprobe): Measure 802.1Q handling at XDP and tc hooks Add a root-only characterization test for the transport contract's questions Q1 to Q5. It builds veth and 802.3ad bond parents with VLANs 101 and 202 in throwaway network namespaces, attaches small probe programs at XDP and tc, and records which attach modes a VLAN netdevice accepts, where the tag sits at each hook with VLAN offloads on and off, whether the XDP VLAN metadata kfunc separates two VLANs on one parent, what bpf_fib_lookup returns through a VLAN, and what XDP and tc redirects toward a VLAN put on the wire. The probe object is compiled when the test runs, the package has no non-test code, and the test skips unless run as root. Its assertions are positive controls only; VLANPROBE_REPORT writes every observation. --- internal/plumbing/ebpf/vlanprobe/doc.go | 19 + .../plumbing/ebpf/vlanprobe/probe_test.go | 1008 +++++++++++++++++ .../plumbing/ebpf/vlanprobe/testdata/probe.c | 207 ++++ 3 files changed, 1234 insertions(+) create mode 100644 internal/plumbing/ebpf/vlanprobe/doc.go create mode 100644 internal/plumbing/ebpf/vlanprobe/probe_test.go create mode 100644 internal/plumbing/ebpf/vlanprobe/testdata/probe.c diff --git a/internal/plumbing/ebpf/vlanprobe/doc.go b/internal/plumbing/ebpf/vlanprobe/doc.go new file mode 100644 index 00000000..cdf82bee --- /dev/null +++ b/internal/plumbing/ebpf/vlanprobe/doc.go @@ -0,0 +1,19 @@ +// Copyright 2026 Datum Cloud, Inc. +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +// Package vlanprobe holds a root-only characterization test for the tagged +// and untagged transport contract (docs/designs/vlan-transport/contract.md, +// questions Q1 to Q5 of its section 10). The test builds veth, bond and +// 802.1Q topologies in throwaway network namespaces, attaches the small probe +// programs in testdata/probe.c at XDP and tc hooks, and records where the +// 802.1Q tag is at each hook, which XDP attach modes each interface accepts, +// what bpf_fib_lookup returns for a route through a VLAN netdevice, and what +// an XDP or tc redirect toward a VLAN netdevice puts on the wire. +// +// It is test-only. The package has no non-test code, no Galactic binary +// imports it, and the probe object is compiled when the test runs (with +// clang, or from VLANPROBE_OBJ). Run it with `task test:unit-root`, or see +// docs/archive/benchmarks for the recorded results and the container runner. +// Unprivileged runs skip. +package vlanprobe diff --git a/internal/plumbing/ebpf/vlanprobe/probe_test.go b/internal/plumbing/ebpf/vlanprobe/probe_test.go new file mode 100644 index 00000000..8856cf28 --- /dev/null +++ b/internal/plumbing/ebpf/vlanprobe/probe_test.go @@ -0,0 +1,1008 @@ +// Copyright 2026 Datum Cloud, Inc. +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +package vlanprobe + +import ( + "encoding/json" + "errors" + "fmt" + "net" + "os" + "os/exec" + "path/filepath" + "sort" + "strings" + "testing" + "time" + + "github.com/cilium/ebpf" + "github.com/cilium/ebpf/link" + "github.com/containernetworking/plugins/pkg/ns" + "github.com/containernetworking/plugins/pkg/testutils" + "github.com/safchain/ethtool" + "github.com/vishvananda/netlink" + + "go.datum.net/galactic/internal/plumbing/ebpf/edgepreflight" +) + +// Synthetic VLAN IDs, matching the contract's examples: 101 stands for the +// public side and 202 for the fabric side. Both ride one parent in every +// topology here, which is the contract's cell C5 shape (question Q3). +const ( + vidPublic = 101 + vidFabric = 202 +) + +const ( + hookXDP = 1 + hookTC = 2 + hookXDPMeta = 3 + hookXDPFib = 4 + hookTCFib = 5 + + // BPF_F_XDP_DEV_BOUND_ONLY: the program may call XDP metadata kfuncs and + // attaches only to the device it was loaded for. + bpfFXDPDevBoundOnly = 1 << 6 + + modeNative = "native" + modeGeneric = "generic" + hookXDPName = "xdp" + tagNone = "none" + kindNIC = "nic" + kindBond = "bond" + targetFIB = "fib" + targetParent = "parent" + + featTxVLAN = "tx-vlan-hw-insert" + featRxVLAN = "rx-vlan-hw-parse" + featGRO = "rx-gro" +) + +func requireRoot(t *testing.T) { + t.Helper() + if os.Geteuid() != 0 { + t.Skip("test requires root (CAP_BPF/CAP_NET_ADMIN/CAP_SYS_ADMIN) to load/attach BPF programs " + + "and create test network namespaces; re-run via task test:unit-root") + } +} + +// obsKey mirrors struct obs_key in testdata/probe.c. +type obsKey struct { + Hook uint32 + Ifindex uint32 + DataProto uint16 + DataVID uint16 + InnerProto uint16 + MetaVID uint16 + MetaProto uint16 + MetaState uint8 + Pad uint8 + FibRC int32 + FibIfindex uint32 +} + +// Observation is one recorded row: what one hook saw, how often. +type Observation struct { + Experiment string `json:"experiment"` + Case string `json:"case"` + Hook string `json:"hook"` + Iface string `json:"iface"` + Wire string `json:"wire"` // tag as seen in packet data + Meta string `json:"meta"` // tag as seen in metadata + Fib string `json:"fib,omitempty"` + Count uint64 `json:"count"` +} + +// Outcome is a non-packet result: an attach, a delivery count, a gate answer. +type Outcome struct { + Experiment string `json:"experiment"` + Case string `json:"case"` + Item string `json:"item"` + Result string `json:"result"` +} + +type report struct { + Kernel string `json:"kernel"` + Observations []Observation `json:"observations"` + Outcomes []Outcome `json:"outcomes"` +} + +func (r *report) outcome(t *testing.T, exp, c, item, result string) { + t.Helper() + t.Logf("%-10s %-40s %-44s %s", exp, c, item, result) + r.Outcomes = append(r.Outcomes, Outcome{exp, c, item, result}) +} + +func (r *report) write(t *testing.T) { + path := os.Getenv("VLANPROBE_REPORT") + if path == "" { + return + } + b, err := json.MarshalIndent(r, "", " ") + if err != nil { + t.Errorf("marshal report: %v", err) + return + } + if err := os.WriteFile(path, b, 0o644); err != nil { + t.Errorf("write report: %v", err) + } +} + +// probeSpec returns the probe's collection spec, compiling testdata/probe.c +// unless VLANPROBE_OBJ names a prebuilt object. +func probeSpec(t *testing.T) *ebpf.CollectionSpec { + t.Helper() + obj := os.Getenv("VLANPROBE_OBJ") + if obj == "" { + cc := os.Getenv("BPF2GO_CC") + if cc == "" { + cc = "clang" + } + if _, err := exec.LookPath(cc); err != nil { + t.Skipf("no %s to compile testdata/probe.c and VLANPROBE_OBJ unset", cc) + } + obj = filepath.Join(t.TempDir(), "probe.o") + out, err := exec.CommandContext(t.Context(), cc, "-O2", "-g", "-Wall", "-target", "bpf", + "-idirafter", "/usr/include/x86_64-linux-gnu", "-idirafter", "/usr/include/aarch64-linux-gnu", + "-c", "testdata/probe.c", "-o", obj).CombinedOutput() + if err != nil { + t.Fatalf("compile probe.c: %v\n%s", err, out) + } + } + spec, err := ebpf.LoadCollectionSpec(obj) + if err != nil { + t.Fatalf("load probe spec: %v", err) + } + return spec +} + +// probe is one loaded copy of the probe collection, owned by one namespace so +// that recorded ifindexes are unambiguous. +type probe struct { + spec *ebpf.CollectionSpec + coll *ebpf.Collection + links []link.Link +} + +func loadProbe(t *testing.T, spec *ebpf.CollectionSpec) *probe { + t.Helper() + s := spec.Copy() + delete(s.Programs, "xdp_observe_meta") // device-bound; loaded per device + coll, err := ebpf.NewCollection(s) + if err != nil { + t.Fatalf("load probe collection: %v", err) + } + p := &probe{spec: spec, coll: coll} + t.Cleanup(func() { p.detach(); coll.Close() }) + return p +} + +func (p *probe) detach() { + for _, l := range p.links { + _ = l.Close() + } + p.links = nil +} + +func (p *probe) reset(t *testing.T) { + t.Helper() + p.detach() + m := p.coll.Maps["observations"] + var k obsKey + var keys []obsKey + it := m.Iterate() + var v uint64 + for it.Next(&k, &v) { + keys = append(keys, k) + } + for _, k := range keys { + _ = m.Delete(k) + } + if err := p.coll.Maps["redirect_cfg"].Put(uint32(0), uint32(0)); err != nil { + t.Fatalf("reset redirect_cfg: %v", err) + } +} + +func xdpFlags(mode string) link.XDPAttachFlags { + if mode == modeNative { + return link.XDPDriverMode + } + return link.XDPGenericMode +} + +// attachXDP must run inside the namespace that owns ifindex. +func (p *probe) attachXDP(prog string, ifindex int, mode string) error { + l, err := link.AttachXDP(link.XDPOptions{Program: p.coll.Programs[prog], Interface: ifindex, Flags: xdpFlags(mode)}) + if err != nil { + return err + } + p.links = append(p.links, l) + return nil +} + +// attachMeta loads xdp_observe_meta bound to ifindex, sharing the +// observations map, and attaches it. +func (p *probe) attachMeta(ifindex int, mode string) error { + s := p.spec.Copy() + for name := range s.Programs { + if name != "xdp_observe_meta" { + delete(s.Programs, name) + } + } + ps := s.Programs["xdp_observe_meta"] + ps.Ifindex = uint32(ifindex) + ps.Flags |= bpfFXDPDevBoundOnly + coll, err := ebpf.NewCollectionWithOptions(s, ebpf.CollectionOptions{ + MapReplacements: map[string]*ebpf.Map{"observations": p.coll.Maps["observations"]}, + }) + if err != nil { + return fmt.Errorf("load device-bound program: %w", err) + } + defer coll.Close() + l, err := link.AttachXDP(link.XDPOptions{ + Program: coll.Programs["xdp_observe_meta"], Interface: ifindex, Flags: xdpFlags(mode), + }) + if err != nil { + return err + } + p.links = append(p.links, l) + return nil +} + +func (p *probe) attachTC(t *testing.T, prog string, ifindex int) { + t.Helper() + l, err := link.AttachTCX(link.TCXOptions{ + Program: p.coll.Programs[prog], Interface: ifindex, Attach: ebpf.AttachTCXIngress, + }) + if err != nil { + t.Fatalf("attach %s to ifindex %d: %v", prog, ifindex, err) + } + p.links = append(p.links, l) +} + +var hookNames = map[uint32]string{ + hookXDP: hookXDPName, hookTC: "tc-ingress", hookXDPMeta: "xdp+kfunc", hookXDPFib: "xdp-fib", hookTCFib: "tc-fib", +} + +func tagString(proto, vid uint16) string { + switch proto { + case 0x8100: + return fmt.Sprintf("802.1Q vid %d", vid) + case 0x88a8: + return fmt.Sprintf("802.1ad vid %d", vid) + } + return tagNone +} + +// collect reads every observation, naming interfaces from names (ifindex to +// name within the probe's namespace). +func (p *probe) collect(t *testing.T, r *report, exp, c string, names map[uint32]string) { + t.Helper() + var k obsKey + var v uint64 + var rows []Observation + it := p.coll.Maps["observations"].Iterate() + for it.Next(&k, &v) { + o := Observation{Experiment: exp, Case: c, Hook: hookNames[k.Hook], Iface: names[k.Ifindex], Count: v} + if o.Iface == "" { + o.Iface = fmt.Sprintf("ifindex %d", k.Ifindex) + } + o.Wire = tagString(k.DataProto, k.DataVID) + if o.Wire == tagNone { + o.Wire = fmt.Sprintf("none (ethertype 0x%04x)", k.DataProto) + } else { + o.Wire += fmt.Sprintf(" (inner 0x%04x)", k.InnerProto) + } + switch k.MetaState { + case 1: + o.Meta = tagString(k.MetaProto, k.MetaVID) + case 2: + o.Meta = "kfunc error" + default: + o.Meta = tagNone + } + if k.FibRC >= 0 { + o.Fib = fmt.Sprintf("rc %d ifindex %s", k.FibRC, names[k.FibIfindex]) + } + rows = append(rows, o) + } + if err := it.Err(); err != nil { + t.Fatalf("iterate observations: %v", err) + } + sort.Slice(rows, func(i, j int) bool { + a, b := rows[i], rows[j] + if a.Hook != b.Hook { + return a.Hook < b.Hook + } + if a.Iface != b.Iface { + return a.Iface < b.Iface + } + return a.Wire+a.Meta < b.Wire+b.Meta + }) + for _, o := range rows { + t.Logf("%-10s %-40s %-10s %-10s wire=%-36s meta=%-16s %s n=%d", + exp, c, o.Hook, o.Iface, o.Wire, o.Meta, o.Fib, o.Count) + } + r.Observations = append(r.Observations, rows...) +} + +// node is one network namespace with a lookup of its interfaces. +type node struct { + ns ns.NetNS +} + +func newNode(t *testing.T) *node { + t.Helper() + n, err := testutils.NewNS() + if err != nil { + t.Fatalf("new netns: %v", err) + } + t.Cleanup(func() { _ = n.Close(); _ = testutils.UnmountNS(n) }) + return &node{ns: n} +} + +func (n *node) do(t *testing.T, f func() error) { + t.Helper() + if err := n.ns.Do(func(ns.NetNS) error { return f() }); err != nil { + t.Fatal(err) + } +} + +func (n *node) ifindex(t *testing.T, name string) int { + t.Helper() + var idx int + n.do(t, func() error { + l, err := netlink.LinkByName(name) + if err != nil { + return err + } + idx = l.Attrs().Index + return nil + }) + return idx +} + +func (n *node) names(t *testing.T) map[uint32]string { + t.Helper() + m := map[uint32]string{} + n.do(t, func() error { + links, err := netlink.LinkList() + if err != nil { + return err + } + for _, l := range links { + m[uint32(l.Attrs().Index)] = l.Attrs().Name + } + return nil + }) + return m +} + +func (n *node) sysctl(t *testing.T, key, val string) { + t.Helper() + n.do(t, func() error { + return os.WriteFile("/proc/sys/"+strings.ReplaceAll(key, ".", "/"), []byte(val), 0o644) + }) +} + +func (n *node) features(t *testing.T, iface string, cfg map[string]bool) { + t.Helper() + n.do(t, func() error { + e, err := ethtool.NewEthtool() + if err != nil { + return err + } + defer e.Close() + if err := e.Change(iface, cfg); err != nil { + return fmt.Errorf("ethtool %s %v: %w", iface, cfg, err) + } + return nil + }) +} + +func addAddr(l netlink.Link, cidr string) error { + a, err := netlink.ParseAddr(cidr) + if err != nil { + return err + } + return netlink.AddrAdd(l, a) +} + +// vethPair creates a veth with one end in each namespace. +func vethPair(t *testing.T, a *node, aName string, b *node, bName string) { + t.Helper() + a.do(t, func() error { + v := &netlink.Veth{ + LinkAttrs: netlink.LinkAttrs{Name: aName, MTU: 1500}, + PeerName: bName, + PeerNamespace: netlink.NsFd(int(b.ns.Fd())), + } + return netlink.LinkAdd(v) + }) +} + +func up(name string) error { + l, err := netlink.LinkByName(name) + if err != nil { + return err + } + return netlink.LinkSetUp(l) +} + +func mkBond(name string, members ...string) error { + b := netlink.NewLinkBond(netlink.LinkAttrs{Name: name, MTU: 1500}) + b.Mode = netlink.BOND_MODE_802_3AD + b.Miimon = 100 + b.LacpRate = netlink.BOND_LACP_RATE_FAST + b.XmitHashPolicy = netlink.BOND_XMIT_HASH_POLICY_LAYER3_4 + if err := netlink.LinkAdd(b); err != nil { + return fmt.Errorf("add bond %s: %w", name, err) + } + bl, err := netlink.LinkByName(name) + if err != nil { + return err + } + for _, m := range members { + ml, err := netlink.LinkByName(m) + if err != nil { + return err + } + if err := netlink.LinkSetDown(ml); err != nil { + return err + } + if err := netlink.LinkSetMasterByIndex(ml, bl.Attrs().Index); err != nil { + return fmt.Errorf("enslave %s: %w", m, err) + } + if err := netlink.LinkSetUp(ml); err != nil { + return err + } + } + return netlink.LinkSetUp(bl) +} + +func mkVLAN(parent string, vid int, proto netlink.VlanProtocol, cidr string) error { + pl, err := netlink.LinkByName(parent) + if err != nil { + return err + } + name := fmt.Sprintf("%s.%d", parent, vid) + v := &netlink.Vlan{ + LinkAttrs: netlink.LinkAttrs{Name: name, ParentIndex: pl.Attrs().Index}, VlanId: vid, VlanProtocol: proto, + } + if err := netlink.LinkAdd(v); err != nil { + return fmt.Errorf("add vlan %s: %w", name, err) + } + if cidr != "" { + if err := addAddr(v, cidr); err != nil { + return err + } + } + return up(name) +} + +// pairTopo is the two-node transport segment: A plays the external router or +// the far fabric node, B the Galactic node. Each side's parent carries an +// untagged address and VLANs 101 and 202 on top. +type pairTopo struct { + kind string // kindNIC or kindBond + a, b *node + aParent, bParent string + aPhys, bPhys []string // the veths: the parent itself, or the bond's members +} + +func newPair(t *testing.T, kind string) *pairTopo { + t.Helper() + p := &pairTopo{kind: kind, a: newNode(t), b: newNode(t)} + switch kind { + case kindNIC: + vethPair(t, p.a, "a0", p.b, "b0") + p.aParent, p.bParent = "a0", "b0" + p.aPhys, p.bPhys = []string{"a0"}, []string{"b0"} + case kindBond: + vethPair(t, p.a, "a0", p.b, "b0") + vethPair(t, p.a, "a1", p.b, "b1") + p.aParent, p.bParent = "abond", "bbond" + p.aPhys, p.bPhys = []string{"a0", "a1"}, []string{"b0", "b1"} + default: + t.Fatalf("unknown parent kind %q", kind) + } + for _, side := range []struct { + n *node + parent string + phys []string + host int + }{{p.a, p.aParent, p.aPhys, 1}, {p.b, p.bParent, p.bPhys, 2}} { + side.n.do(t, func() error { + _ = up("lo") + if kind == kindBond { + if err := mkBond(side.parent, side.phys...); err != nil { + return err + } + } else if err := up(side.parent); err != nil { + return err + } + pl, err := netlink.LinkByName(side.parent) + if err != nil { + return err + } + if err := addAddr(pl, fmt.Sprintf("10.0.0.%d/24", side.host)); err != nil { + return err + } + pubAddr := fmt.Sprintf("10.101.0.%d/24", side.host) + if err := mkVLAN(side.parent, vidPublic, netlink.VLAN_PROTOCOL_8021Q, pubAddr); err != nil { + return err + } + return mkVLAN(side.parent, vidFabric, netlink.VLAN_PROTOCOL_8021Q, fmt.Sprintf("10.202.0.%d/24", side.host)) + }) + side.n.sysctl(t, "net.ipv4.conf.all.rp_filter", "0") + side.n.sysctl(t, "net.ipv4.conf.default.rp_filter", "0") + for _, ph := range side.phys { + // GRO lets a veth receive frames a peer's native XDP program + // redirected to it without an XDP program of its own. + side.n.features(t, ph, map[string]bool{featGRO: true}) + } + } + p.waitReady(t) + return p +} + +// waitReady waits until untagged traffic crosses the segment, which for a +// bond means LACP has converged. +func (p *pairTopo) waitReady(t *testing.T) { + t.Helper() + deadline := time.Now().Add(20 * time.Second) + for time.Now().Before(deadline) { + if n := sendUDP(t, p.a, p.b, "10.0.0.1", "10.0.0.2", 3); n > 0 { + return + } + } + t.Fatalf("%s segment never passed untagged traffic", p.kind) +} + +var nextPort = 20000 + +// sendUDP sends n datagrams from src (in node from) to dst (in node to) and +// returns how many the listener on dst received. +func sendUDP(t *testing.T, from, to *node, src, dst string, n int) int { + const wait = 300 * time.Millisecond + t.Helper() + nextPort++ + port := nextPort + var conn *net.UDPConn + to.do(t, func() error { + var err error + conn, err = net.ListenUDP("udp4", &net.UDPAddr{IP: net.ParseIP(dst), Port: port}) + return err + }) + defer func() { _ = conn.Close() }() + got := make(chan int, 1) + go func() { + buf := make([]byte, 2048) + c := 0 + _ = conn.SetReadDeadline(time.Now().Add(wait + time.Duration(n)*20*time.Millisecond + time.Second)) + for { + if _, _, err := conn.ReadFromUDP(buf); err != nil { + break + } + c++ + } + got <- c + }() + from.do(t, func() error { + c, err := net.DialUDP("udp4", &net.UDPAddr{IP: net.ParseIP(src)}, &net.UDPAddr{IP: net.ParseIP(dst), Port: port}) + if err != nil { + return err + } + defer func() { _ = c.Close() }() + // The first datagram triggers ARP; give it time to resolve so the + // counted ones are not queued behind it. + _, _ = c.Write([]byte("warmup")) + time.Sleep(wait) + for i := range n { + _, _ = fmt.Fprintf(c, "probe-%d", i) + time.Sleep(20 * time.Millisecond) + } + return nil + }) + c := <-got + if c > 0 { + c-- // the warmup + } + return c +} + +func kernelRelease() string { + b, err := os.ReadFile("/proc/sys/kernel/osrelease") + if err != nil { + return "unknown" + } + return strings.TrimSpace(string(b)) +} + +func errString(err error) string { + if err == nil { + return "ok" + } + var ve *ebpf.VerifierError + if errors.As(err, &ve) { + return "verifier: " + strings.SplitN(ve.Error(), "\n", 2)[0] + } + return "error: " + err.Error() +} + +// TestVLANTransportProbe runs every experiment and writes one report. The +// assertions are positive controls only: the characterization itself records +// whatever the kernel does. +func TestVLANTransportProbe(t *testing.T) { + requireRoot(t) + spec := probeSpec(t) + r := &report{Kernel: kernelRelease()} + t.Cleanup(func() { r.write(t) }) + t.Logf("kernel %s", r.Kernel) + + for _, kind := range []string{kindNIC, kindBond} { + t.Run(kind, func(t *testing.T) { + p := newPair(t, kind) + attachMatrix(t, r, p, spec) + tagLocation(t, r, p, spec) + }) + } + t.Run("redirect", func(t *testing.T) { + for _, kind := range []string{kindNIC, kindBond} { + redirects(t, r, kind, spec) + } + }) + t.Run("invalid", func(t *testing.T) { invalidVLANs(t, r) }) +} + +// attachMatrix answers Q1: which XDP attach modes each kind of interface +// accepts, and what the native-support gate Galactic uses reports for it. +func attachMatrix(t *testing.T, r *report, p *pairTopo, spec *ebpf.CollectionSpec) { + pr := loadProbe(t, spec) + targets := []string{p.bParent, fmt.Sprintf("%s.%d", p.bParent, vidPublic)} + if p.kind == kindBond { + targets = append(targets, p.bPhys[0]) + } + for _, iface := range targets { + var gate string + p.b.do(t, func() error { + ok, err := edgepreflight.InterfaceXDPFn(iface) + switch { + case err != nil: + gate = "unknown: " + err.Error() + case ok: + gate = "supported" + default: + gate = "not supported (Galactic refuses native attach)" + } + return nil + }) + r.outcome(t, "Q1", p.kind, iface+" native XDP feature", gate) + idx := p.b.ifindex(t, iface) + for _, mode := range []string{modeNative, modeGeneric} { + var err error + p.b.do(t, func() error { err = pr.attachXDP("xdp_observe", idx, mode); return nil }) + r.outcome(t, "Q1", p.kind, iface+" attach "+mode, errString(err)) + p.b.do(t, func() error { pr.detach(); return nil }) + } + for _, mode := range []string{modeNative, modeGeneric} { + var err error + p.b.do(t, func() error { err = pr.attachMeta(idx, mode); return nil }) + r.outcome(t, "Q1", p.kind, iface+" attach device-bound "+mode, errString(err)) + p.b.do(t, func() error { pr.detach(); return nil }) + } + } +} + +type offload struct { + name string + aTx bool // sender's transmit VLAN offload + bRx bool // receiver's receive VLAN offload +} + +var offloads = []offload{ + {"tx-on/rx-on", true, true}, + {"tx-off/rx-on", false, true}, + {"tx-on/rx-off", true, false}, + {"tx-off/rx-off", false, false}, +} + +// tagLocation answers Q2 and Q3: for each XDP mode and offload setting, where +// the tag is at XDP on the physical interface, at tc on the physical +// interface, the bond and each VLAN, and whether XDP_PASS still delivers to +// the right VLAN netdevice. VLANs 101 and 202 share the parent throughout. +func tagLocation(t *testing.T, r *report, p *pairTopo, spec *ebpf.CollectionSpec) { + pr := loadProbe(t, spec) + names := p.b.names(t) + for _, mode := range []string{modeNative, modeGeneric} { + for _, off := range offloads { + c := fmt.Sprintf("%s %s %s", p.kind, mode, off.name) + for _, ph := range p.aPhys { + p.a.features(t, ph, map[string]bool{featTxVLAN: off.aTx}) + } + for _, ph := range p.bPhys { + p.b.features(t, ph, map[string]bool{featRxVLAN: off.bRx}) + } + pr.reset(t) + ok := true + p.b.do(t, func() error { + for _, ph := range p.bPhys { + idx := p.b.ifindexInside(ph) + if err := pr.attachXDP("xdp_observe", idx, mode); err != nil { + r.outcome(t, "Q2", c, ph+" attach xdp", errString(err)) + ok = false + } + } + return nil + }) + tcTargets := append([]string{}, p.bPhys...) + if p.kind == kindBond { + tcTargets = append(tcTargets, p.bParent) + } + tcTargets = append(tcTargets, fmt.Sprintf("%s.%d", p.bParent, vidPublic), fmt.Sprintf("%s.%d", p.bParent, vidFabric)) + for _, iface := range tcTargets { + idx := p.b.ifindex(t, iface) + p.b.do(t, func() error { pr.attachTC(t, "tc_observe", idx); return nil }) + } + if !ok { + continue + } + got101 := sendUDP(t, p.a, p.b, "10.101.0.1", "10.101.0.2", 10) + got202 := sendUDP(t, p.a, p.b, "10.202.0.1", "10.202.0.2", 10) + gotUn := sendUDP(t, p.a, p.b, "10.0.0.1", "10.0.0.2", 10) + r.outcome(t, "Q2", c, "delivered to VLAN 101 / 202 / untagged", + fmt.Sprintf("%d/10, %d/10, %d/10", got101, got202, gotUn)) + if gotUn == 0 { + t.Errorf("%s: untagged positive control delivered nothing", c) + } + pr.collect(t, r, "Q2/Q3", c, names) + p.b.do(t, func() error { pr.detach(); return nil }) + } + } + // Device-bound kfunc read of the tag, native mode only, on the physical + // interfaces with default offloads. + for _, ph := range p.aPhys { + p.a.features(t, ph, map[string]bool{featTxVLAN: true}) + } + for _, ph := range p.bPhys { + p.b.features(t, ph, map[string]bool{featRxVLAN: true}) + } + pr.reset(t) + c := p.kind + " native kfunc tx-on/rx-on" + attached := true + for _, ph := range p.bPhys { + idx := p.b.ifindex(t, ph) + var err error + p.b.do(t, func() error { err = pr.attachMeta(idx, modeNative); return nil }) + if err != nil { + r.outcome(t, "Q3", c, ph+" attach device-bound", errString(err)) + attached = false + } + } + if attached { + got101 := sendUDP(t, p.a, p.b, "10.101.0.1", "10.101.0.2", 10) + got202 := sendUDP(t, p.a, p.b, "10.202.0.1", "10.202.0.2", 10) + r.outcome(t, "Q3", c, "delivered to VLAN 101 / 202", fmt.Sprintf("%d/10, %d/10", got101, got202)) + pr.collect(t, r, "Q3", c, names) + } + p.b.do(t, func() error { pr.detach(); return nil }) +} + +// snmp reads the namespace's IP, ICMP and UDP counters. /proc/net follows +// the process's namespace, so it reads through thread-self instead. +func (n *node) snmp(t *testing.T) map[string]int64 { + t.Helper() + m := map[string]int64{} + n.do(t, func() error { + for _, f := range []string{"snmp", "netstat"} { + b, err := os.ReadFile("/proc/thread-self/net/" + f) + if err != nil { + return err + } + lines := strings.Split(strings.TrimSpace(string(b)), "\n") + for i := 0; i+1 < len(lines); i += 2 { + h, v := strings.Fields(lines[i]), strings.Fields(lines[i+1]) + for j := 1; j < len(h) && j < len(v); j++ { + var x int64 + _, _ = fmt.Sscan(v[j], &x) + m[strings.TrimSuffix(h[0], ":")+"."+h[j]] = x + } + } + } + return nil + }) + return m +} + +// snmpDelta lists the drop and error counters that rose. +func snmpDelta(before, after map[string]int64) string { + var out []string + for k, v := range after { + lk := strings.ToLower(k) + if !strings.Contains(lk, "err") && !strings.Contains(lk, "discard") && !strings.Contains(lk, "drop") && + !strings.Contains(lk, "noroutes") && !strings.Contains(lk, "martian") && !strings.Contains(lk, "rpfilter") { + continue + } + if d := v - before[k]; d > 0 { + out = append(out, fmt.Sprintf("%s+%d", k, d)) + } + } + sort.Strings(out) + return strings.Join(out, " ") +} + +func (n *node) ifindexInside(name string) int { + l, err := netlink.LinkByName(name) + if err != nil { + return 0 + } + return l.Attrs().Index +} + +// redirects answers Q4 and Q5. A third namespace S sends untagged IPv4 into +// B on bs0. B routes the destination through its fabric VLAN (parent.202) +// toward A. A probe on bs0 looks the destination up with bpf_fib_lookup and +// redirects to the FIB result, or to the parent instead, from XDP (native or +// generic) or tc. A's tc probe on its physical interfaces shows what reached +// the wire, and a listener on A shows whether it was delivered. +func redirects(t *testing.T, r *report, kind string, spec *ebpf.CollectionSpec) { + p := newPair(t, kind) + s := newNode(t) + vethPair(t, s, "s0", p.b, "bs0") + s.do(t, func() error { + _ = up("lo") + l, err := netlink.LinkByName("s0") + if err != nil { + return err + } + if err := addAddr(l, "10.50.0.1/24"); err != nil { + return err + } + if err := netlink.LinkSetUp(l); err != nil { + return err + } + _, dst, _ := net.ParseCIDR("10.99.0.0/24") + return netlink.RouteAdd(&netlink.Route{LinkIndex: l.Attrs().Index, Dst: dst, Gw: net.ParseIP("10.50.0.2")}) + }) + fabricVLAN := fmt.Sprintf("%s.%d", p.bParent, vidFabric) + var aMAC net.HardwareAddr + p.a.do(t, func() error { + d := &netlink.Dummy{LinkAttrs: netlink.LinkAttrs{Name: "dst0"}} + if err := netlink.LinkAdd(d); err != nil { + return err + } + if err := addAddr(d, "10.99.0.1/32"); err != nil { + return err + } + pl, err := netlink.LinkByName(fmt.Sprintf("%s.%d", p.aParent, vidFabric)) + if err != nil { + return err + } + aMAC = pl.Attrs().HardwareAddr + return up("dst0") + }) + p.b.sysctl(t, "net.ipv4.ip_forward", "1") + p.b.do(t, func() error { + l, err := netlink.LinkByName("bs0") + if err != nil { + return err + } + if err := addAddr(l, "10.50.0.2/24"); err != nil { + return err + } + if err := netlink.LinkSetUp(l); err != nil { + return err + } + vl, err := netlink.LinkByName(fabricVLAN) + if err != nil { + return err + } + _, dst, _ := net.ParseCIDR("10.99.0.0/24") + route := &netlink.Route{LinkIndex: vl.Attrs().Index, Dst: dst, Gw: net.ParseIP("10.202.0.1")} + if err := netlink.RouteAdd(route); err != nil { + return err + } + // A warm neighbour, so the lookup returns success rather than NO_NEIGH. + return netlink.NeighAdd(&netlink.Neigh{LinkIndex: vl.Attrs().Index, IP: net.ParseIP("10.202.0.1"), + HardwareAddr: aMAC, State: netlink.NUD_PERMANENT, Family: netlink.FAMILY_V4}) + }) + // S fills in its UDP checksums itself. With transmit checksum offload a + // veth hands B a frame whose checksum is still partial, which a native + // XDP redirect forwards as is and the receiver then rejects. + s.features(t, "s0", map[string]bool{featGRO: true, "tx-checksum-ip-generic": false}) + p.b.features(t, "bs0", map[string]bool{featGRO: true}) + + bp := loadProbe(t, spec) + ap := loadProbe(t, spec) + bNames, aNames := p.b.names(t), p.a.names(t) + bs0 := p.b.ifindex(t, "bs0") + parentIdx := p.b.ifindex(t, p.bParent) + + type rc struct { + hook, mode, target string + } + cases := []rc{ + {hookXDPName, modeNative, targetFIB}, {hookXDPName, modeGeneric, targetFIB}, + {hookXDPName, modeNative, targetParent}, {hookXDPName, modeGeneric, targetParent}, + {"tc", "", targetFIB}, {"tc", "", targetParent}, + } + for _, txOn := range []bool{true, false} { + for _, ph := range p.bPhys { + p.b.features(t, ph, map[string]bool{featTxVLAN: txOn}) + } + for _, ph := range p.aPhys { + p.a.features(t, ph, map[string]bool{featRxVLAN: false}) + } + for _, cs := range cases { + c := fmt.Sprintf("%s %s %s->%s B tx-vlan %v", kind, cs.hook, cs.mode, cs.target, txOn) + bp.reset(t) + ap.reset(t) + if cs.target == targetParent { + if err := bp.coll.Maps["redirect_cfg"].Put(uint32(0), uint32(parentIdx)); err != nil { + t.Fatal(err) + } + } + var err error + p.b.do(t, func() error { + if cs.hook == hookXDPName { + err = bp.attachXDP("xdp_fib_redirect", bs0, cs.mode) + } else { + bp.attachTC(t, "tc_fib_redirect", bs0) + } + return nil + }) + if err != nil { + r.outcome(t, "Q4/Q5", c, "attach", errString(err)) + continue + } + for _, ph := range p.aPhys { + idx := p.a.ifindex(t, ph) + p.a.do(t, func() error { ap.attachTC(t, "tc_observe", idx); return nil }) + } + before := p.a.snmp(t) + got := sendUDP(t, s, p.a, "10.50.0.1", "10.99.0.1", 10) + r.outcome(t, "Q4/Q5", c, "delivered at A", fmt.Sprintf("%d/10", got)) + if d := snmpDelta(before, p.a.snmp(t)); d != "" { + r.outcome(t, "Q4/Q5", c, "A stack counters", d) + } + bp.collect(t, r, "Q4/Q5 B", c, bNames) + ap.collect(t, r, "Q4/Q5 A", c, aNames) + p.b.do(t, func() error { bp.detach(); return nil }) + p.a.do(t, func() error { ap.detach(); return nil }) + } + } +} + +// invalidVLANs records what the kernel lets infrastructure create for the +// contract's rejected cases (section 5): VLAN ID 0 and 4095, an 802.1ad VLAN, +// and a VLAN stacked on a VLAN. Each exists only so later validation work +// (#1404) knows which cases reach Galactic at all. +func invalidVLANs(t *testing.T, r *report) { + n := newNode(t) + n.do(t, func() error { + d := &netlink.Dummy{LinkAttrs: netlink.LinkAttrs{Name: "p0"}} + if err := netlink.LinkAdd(d); err != nil { + return err + } + if err := up("p0"); err != nil { + return err + } + for _, c := range []struct { + name string + vid int + proto netlink.VlanProtocol + on string + }{ + {"vid 0", 0, netlink.VLAN_PROTOCOL_8021Q, "p0"}, + {"vid 4095", 4095, netlink.VLAN_PROTOCOL_8021Q, "p0"}, + {"802.1ad", 300, netlink.VLAN_PROTOCOL_8021AD, "p0"}, + {"802.1Q on 802.1ad (stacked)", 301, netlink.VLAN_PROTOCOL_8021Q, "p0.300"}, + } { + err := mkVLAN(c.on, c.vid, c.proto, "") + r.outcome(t, "V18", "kernel", "create "+c.name, errString(err)) + } + return nil + }) +} diff --git a/internal/plumbing/ebpf/vlanprobe/testdata/probe.c b/internal/plumbing/ebpf/vlanprobe/testdata/probe.c new file mode 100644 index 00000000..0a5a9643 --- /dev/null +++ b/internal/plumbing/ebpf/vlanprobe/testdata/probe.c @@ -0,0 +1,207 @@ +//go:build ignore + +// Copyright 2026 Datum Cloud, Inc. +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +// probe.c observes where an 802.1Q tag is when a frame reaches an XDP or tc +// hook, and what the kernel does with redirects toward VLAN netdevices. It is +// characterization code for the vlanprobe root test only: no Galactic binary +// loads it. Every program records into one hash map and passes the frame on +// unchanged, except the two redirect programs, which forward IPv4 frames to +// the interface bpf_fib_lookup returns (or to a fixed interface) so the test +// can see what reaches the far side. + +#include +#include +#include + +#define SEC(name) __attribute__((section(name), used)) +#define __uint(name, val) int (*name)[val] +#define __type(name, val) typeof(val) *name +#define __ksym __attribute__((section(".ksyms"))) +#define __weak __attribute__((weak)) + +static void *(*bpf_map_lookup_elem)(void *map, const void *key) = (void *) BPF_FUNC_map_lookup_elem; +static long (*bpf_map_update_elem)(void *map, const void *key, const void *value, __u64 flags) = + (void *) BPF_FUNC_map_update_elem; +static long (*bpf_fib_lookup)(void *ctx, struct bpf_fib_lookup *params, int plen, __u32 flags) = + (void *) BPF_FUNC_fib_lookup; +static long (*bpf_redirect)(__u32 ifindex, __u64 flags) = (void *) BPF_FUNC_redirect; + +// Present on kernels 6.8 and later, implemented by a few drivers (veth among +// them). Weak, so the object still loads where the kfunc does not exist. +extern int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx, __be16 *vlan_proto, + __u16 *vlan_tci) __ksym __weak; + +enum hook { + HOOK_XDP = 1, // xdp_observe + HOOK_TC = 2, // tc_observe + HOOK_XDP_META = 3, // xdp_observe_meta (device-bound) + HOOK_XDP_FIB = 4, // xdp_fib_redirect + HOOK_TC_FIB = 5, // tc_fib_redirect +}; + +// One row per distinct observation. data_proto and data_vid are read from the +// packet bytes; meta_* come from skb metadata (tc) or the XDP metadata kfunc. +struct obs_key { + __u32 hook; + __u32 ifindex; + __u16 data_proto; // EtherType at offset 12, host order + __u16 data_vid; // VLAN ID in packet data when data_proto is 802.1Q/802.1ad + __u16 inner_proto; // EtherType after one in-data tag, else 0 + __u16 meta_vid; // VLAN ID from metadata + __u16 meta_proto; // tag protocol from metadata, host order + __u8 meta_state; // 0 none, 1 present, 2 kfunc error + __u8 pad; + __s32 fib_rc; // bpf_fib_lookup return, fib hooks only, else -1 + __u32 fib_ifindex; +}; + +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, 1024); + __type(key, struct obs_key); + __type(value, __u64); +} observations SEC(".maps"); + +// redirect_cfg[0]: 0 means redirect to the FIB result, otherwise this ifindex. +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u32); +} redirect_cfg SEC(".maps"); + +static __always_inline __u16 bswap16(__u16 v) { return (v << 8) | (v >> 8); } + +static __always_inline void record(struct obs_key *k) +{ + __u64 one = 1, *v = bpf_map_lookup_elem(&observations, k); + if (v) + __sync_fetch_and_add(v, 1); + else + bpf_map_update_elem(&observations, k, &one, BPF_NOEXIST); +} + +static __always_inline void read_data(struct obs_key *k, void *data, void *end) +{ + unsigned char *p = data; + if (p + 14 > (unsigned char *) end) + return; + k->data_proto = ((__u16) p[12] << 8) | p[13]; + if ((k->data_proto == ETH_P_8021Q || k->data_proto == ETH_P_8021AD) && p + 18 <= (unsigned char *) end) { + k->data_vid = (((__u16) p[14] << 8) | p[15]) & 0x0fff; + k->inner_proto = ((__u16) p[16] << 8) | p[17]; + } +} + +SEC("xdp") +int xdp_observe(struct xdp_md *ctx) +{ + struct obs_key k = { .hook = HOOK_XDP, .ifindex = ctx->ingress_ifindex, .fib_rc = -1 }; + read_data(&k, (void *) (long) ctx->data, (void *) (long) ctx->data_end); + record(&k); + return XDP_PASS; +} + +SEC("xdp") +int xdp_observe_meta(struct xdp_md *ctx) +{ + struct obs_key k = { .hook = HOOK_XDP_META, .ifindex = ctx->ingress_ifindex, .fib_rc = -1 }; + __be16 proto = 0; + __u16 tci = 0; + read_data(&k, (void *) (long) ctx->data, (void *) (long) ctx->data_end); + if (bpf_xdp_metadata_rx_vlan_tag) { + int err = bpf_xdp_metadata_rx_vlan_tag(ctx, &proto, &tci); + if (err == 0) { + k.meta_state = 1; + k.meta_vid = tci & 0x0fff; + k.meta_proto = bswap16(proto); + } else if (err != -61 /* ENODATA: no tag */) { + k.meta_state = 2; + } + } else { + k.meta_state = 2; + } + record(&k); + return XDP_PASS; +} + +SEC("tc") +int tc_observe(struct __sk_buff *skb) +{ + struct obs_key k = { .hook = HOOK_TC, .ifindex = skb->ifindex, .fib_rc = -1 }; + read_data(&k, (void *) (long) skb->data, (void *) (long) skb->data_end); + if (skb->vlan_present) { + k.meta_state = 1; + k.meta_vid = skb->vlan_tci & 0x0fff; + k.meta_proto = bswap16(skb->vlan_proto); + } + record(&k); + return TC_ACT_OK; +} + +// fib_fill looks up an untagged IPv4 frame's destination and, on success, +// rewrites its Ethernet addresses. It returns the target ifindex or 0. +static __always_inline __u32 fib_fill(void *ctx, struct obs_key *k, void *data, void *end, __u32 in_ifindex) +{ + unsigned char *p = data; + struct bpf_fib_lookup f = {}; + if (k->data_proto != ETH_P_IP || p + 34 > (unsigned char *) end) + return 0; + f.family = 2; // AF_INET + f.ifindex = in_ifindex; + f.tos = p[15]; + f.l4_protocol = p[23]; + f.tot_len = ((__u16) p[16] << 8) | p[17]; + __builtin_memcpy(&f.ipv4_src, p + 26, 4); + __builtin_memcpy(&f.ipv4_dst, p + 30, 4); + k->fib_rc = bpf_fib_lookup(ctx, &f, sizeof(f), 0); + k->fib_ifindex = f.ifindex; + if (k->fib_rc != BPF_FIB_LKUP_RET_SUCCESS) + return 0; + __builtin_memcpy(p, f.dmac, 6); + __builtin_memcpy(p + 6, f.smac, 6); + // Decrement TTL without fixing the checksum: the receiving side only + // counts frames, it does not validate them. + return f.ifindex; +} + +static __always_inline __u32 target(__u32 fib_ifindex) +{ + __u32 zero = 0, *fixed = bpf_map_lookup_elem(&redirect_cfg, &zero); + if (fixed && *fixed) + return *fixed; + return fib_ifindex; +} + +SEC("xdp") +int xdp_fib_redirect(struct xdp_md *ctx) +{ + void *data = (void *) (long) ctx->data, *end = (void *) (long) ctx->data_end; + struct obs_key k = { .hook = HOOK_XDP_FIB, .ifindex = ctx->ingress_ifindex, .fib_rc = -1 }; + __u32 out; + read_data(&k, data, end); + out = fib_fill(ctx, &k, data, end, ctx->ingress_ifindex); + record(&k); + if (!out) + return XDP_PASS; + return bpf_redirect(target(out), 0); +} + +SEC("tc") +int tc_fib_redirect(struct __sk_buff *skb) +{ + void *data = (void *) (long) skb->data, *end = (void *) (long) skb->data_end; + struct obs_key k = { .hook = HOOK_TC_FIB, .ifindex = skb->ifindex, .fib_rc = -1 }; + __u32 out; + read_data(&k, data, end); + out = fib_fill(skb, &k, data, end, skb->ifindex); + record(&k); + if (!out) + return TC_ACT_OK; + return bpf_redirect(target(out), 0); +} + +char _license[] SEC("license") = "GPL"; From eb974b278078a6ee0575a39607c534f28ae11c9e Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Mon, 30 Nov 2026 13:16:20 -0500 Subject: [PATCH 2/4] feat(containerlab): Add a tagged and untagged transport lab variant The lab builds untagged bonds only. Add scripts/vlan-transport.sh, which moves sjc's public and fabric sides between 802.1Q and untagged transport at run time for the contract's cells C1 to C4 and C6, points the gateway, NAT and CNI DaemonSets at the chosen interfaces, and reverts to the deployed settings. A plan subcommand prints the changes without a lab. VLAN IDs and parents come from cells.env or PUB_VID and FAB_VID, never from the scripts. Add the row runners that record a cell's baseline with captures on every link, the isolation injector, and the interruption prober, plus Taskfile targets and a README section. The gateway verify scripts and the listener conformance test accept an override for tr's device so they can pin a VIP through a VLAN. --- deploy/containerlab/README.md | 23 + deploy/containerlab/Taskfile.yaml | 52 ++ .../resources/vlan-transport/cells.env | 38 ++ .../scripts/verify-gateway-ingress-ipv4.sh | 16 + .../scripts/verify-gateway-ingress.sh | 16 + deploy/containerlab/scripts/vlan-inject.py | 80 +++ .../scripts/vlan-transport-baseline.sh | 158 ++++++ .../scripts/vlan-transport-inject.sh | 96 ++++ .../scripts/vlan-transport-interrupt.sh | 75 +++ deploy/containerlab/scripts/vlan-transport.sh | 482 ++++++++++++++++++ tests/edgeconformance/listener_test.go | 15 +- 11 files changed, 1050 insertions(+), 1 deletion(-) create mode 100644 deploy/containerlab/resources/vlan-transport/cells.env create mode 100755 deploy/containerlab/scripts/vlan-inject.py create mode 100755 deploy/containerlab/scripts/vlan-transport-baseline.sh create mode 100755 deploy/containerlab/scripts/vlan-transport-inject.sh create mode 100755 deploy/containerlab/scripts/vlan-transport-interrupt.sh create mode 100755 deploy/containerlab/scripts/vlan-transport.sh diff --git a/deploy/containerlab/README.md b/deploy/containerlab/README.md index 24cca5ee..db3ddf4d 100644 --- a/deploy/containerlab/README.md +++ b/deploy/containerlab/README.md @@ -669,6 +669,29 @@ what lived in its network namespace: its gvpc.clab.yaml links (through sysctls and exec commands, its peers' bonds, the pass-through XDP programs and its addresses. The script works for any Kind node of the topology. +### Tagged transport variant + +The [VLAN transport contract](../../docs/designs/vlan-transport/contract.md) needs each side of an edge node to run tagged (802.1Q) or untagged. The topology above builds untagged bonds only. `scripts/vlan-transport.sh` re-plumbs sjc at run time, without changing a manifest. It changes the public side (sjc-worker2 `bond0` to tr2 `bond1`) and the fabric side (sjc-worker2 `bond1` to sjc-worker `bond0`). + +- `resources/vlan-transport/cells.env` defines cells C1 to C6 of the [acceptance matrix](../../docs/designs/vlan-transport/acceptance.md) except C5, which point-to-point links cannot build. `PUB_VID` and `FAB_VID` override a cell's IDs. +- `apply` creates the VLAN netdevices on both ends of each tagged side and moves the link's addresses onto them: with `ip` on the Kind nodes and in vtysh's running configuration on tr2. It then points `galactic-gateway`, `galactic-nat` and `galactic-cni` at the new interfaces with `kubectl set env`. `SELECT=logical` names the VLAN netdevice, as the contract requires. `SELECT=parent` names the parent instead. +- sjc's single `galactic-cni` DaemonSet needs a different interface on each node once a side is tagged. `apply` gives sjc-worker2 its own copy, `galactic-cni-vt-edge`, and excludes that node from the original. +- `apply` saves the deployed settings on sjc-worker2 in `/galactic/vlan-transport.state`. `revert` uses it to restore C1. `offload on|off` toggles VLAN offloads on every transport member. +- `VT_SITE=dfw-worker3` re-plumbs only dfw-worker3's public side. It exists for the same-node delivery row, which `verify:edge-listener` runs on dfw. Set `EDGE_CONFORMANCE_UPLINK_DEV=dfw-worker3=bond2.101` so the test pins its VIP through the VLAN. + +```bash +task variant:vlan-transport:plan CELL=C4 SELECT=logical # no lab needed +task variant:vlan-transport:apply CELL=C4 SELECT=parent PUB_VID=1234 FAB_VID=3456 +task baseline:vlan-transport CELL=C4 SELECT=parent OUT=/tmp/c4 ROWS="V06 V01 V03 V05" +task variant:vlan-transport:revert +``` + +`baseline:vlan-transport` (`scripts/vlan-transport-baseline.sh`) records the cell's rows. It captures on the receiving end of every transport link, on bond members, so the tag shows whether it travels in the frame or in skb metadata. It also records the gateway and NAT counters that moved and the components' interface log lines. Isolation (`vlan-transport-inject.sh`, with `vlan-inject.py` for raw frames) and interruption timing (`vlan-transport-interrupt.sh`) have their own scripts. + +`verify-gateway-ingress*.sh` take `UPLINK_DEV="sjc-worker2=bond1.101"` to pin through a tagged transit-side device. + +Hold a containerlab-manager reservation for everything except `plan`, and end with `revert` and the sjc checks: `verify-gateway-ingress*.sh --node sjc-worker2`, `verify:nat-datapath SENDER_SITE=sjc SHARD_NODE=sjc-worker2 SHARD_SITE=sjc`, `verify-ns20.sh` and `verify:bonds`. The [baseline report](../../docs/archive/benchmarks/vlan-transport-baseline-2026-11-30.md) lists which rows have run. + ## Notes - All three Kind clusters use `disableDefaultCNI: true`. Cilium and Multus are installed diff --git a/deploy/containerlab/Taskfile.yaml b/deploy/containerlab/Taskfile.yaml index 92866015..7b295829 100644 --- a/deploy/containerlab/Taskfile.yaml +++ b/deploy/containerlab/Taskfile.yaml @@ -1377,6 +1377,58 @@ tasks: cmds: - ./scripts/verify-ns40.sh + # Tagged/untagged transport variant (docs/designs/vlan-transport/, #1401). + # Moves sjc's public and fabric sides between 802.1Q and untagged transport + # at run time; see scripts/vlan-transport.sh. CELL is one of + # resources/vlan-transport/cells.env; SELECT=logical names each side's + # logical interface, as the contract requires, and SELECT=parent names the + # parent instead. PUB_VID and FAB_VID override the cell's IDs. Run every + # target except plan inside a containerlab-manager reservation, and end + # with variant:vlan-transport:revert. + "variant:vlan-transport:plan": + desc: Print what applying a transport cell would change, without touching the lab (CELL=, SELECT=) + requires: + vars: [CELL] + cmds: + - >- + {{if .PUB_VID}}PUB_VID={{.PUB_VID}} {{end}}{{if .FAB_VID}}FAB_VID={{.FAB_VID}} {{end}} + ./scripts/vlan-transport.sh plan {{.CELL}} {{.SELECT | default "logical"}} + + "variant:vlan-transport:apply": + desc: Apply a transport cell to sjc (CELL=, SELECT=, PUB_VID=, FAB_VID=) + requires: + vars: [CELL] + cmds: + - >- + LAB={{.LAB}} {{if .PUB_VID}}PUB_VID={{.PUB_VID}} {{end}}{{if .FAB_VID}}FAB_VID={{.FAB_VID}} {{end}} + ./scripts/vlan-transport.sh apply {{.CELL}} {{.SELECT | default "logical"}} + + "variant:vlan-transport:revert": + desc: Return sjc to untagged transport (C1) with its deployed Galactic settings + cmds: + - LAB={{.LAB}} ./scripts/vlan-transport.sh revert + + "variant:vlan-transport:offload": + desc: Turn VLAN receive and transmit offload on or off on every sjc transport member (STATE=on|off) + requires: + vars: [STATE] + cmds: + - LAB={{.LAB}} ./scripts/vlan-transport.sh offload {{.STATE}} + + "variant:vlan-transport:status": + desc: Show the applied transport cell and sjc's transport interfaces + cmds: + - LAB={{.LAB}} ./scripts/vlan-transport.sh status + + "baseline:vlan-transport": + desc: Apply a transport cell and record its traffic rows with captures (CELL=, SELECT=, OUT=, ROWS=); does not revert + requires: + vars: [CELL, OUT] + cmds: + - >- + LAB={{.LAB}} {{if .PUB_VID}}PUB_VID={{.PUB_VID}} {{end}}{{if .FAB_VID}}FAB_VID={{.FAB_VID}} {{end}} + ./scripts/vlan-transport-baseline.sh {{.CELL}} {{.SELECT | default "logical"}} {{.OUT}} {{.ROWS | default "V06 V01 V03 V05 V07"}} + clean: desc: Destroy the lab and delete artifacts cmds: diff --git a/deploy/containerlab/resources/vlan-transport/cells.env b/deploy/containerlab/resources/vlan-transport/cells.env new file mode 100644 index 00000000..8eb56cf7 --- /dev/null +++ b/deploy/containerlab/resources/vlan-transport/cells.env @@ -0,0 +1,38 @@ +# Configuration cells for the tagged/untagged transport variant +# (scripts/vlan-transport.sh), from docs/designs/vlan-transport/acceptance.md. +# Each cell sets, per side, the VLAN ID (empty: untagged) and the kind of +# parent the side's logical interface sits on. VLAN IDs are synthetic and +# overridable at apply time (PUB_VID=, FAB_VID=), so a run can prove that the +# operator-selected ID, not a fixture constant, is what reaches the wire. +# +# The variant runs on the sjc site. Contract name to lab interface: +# bondpub sjc-worker2 bond0 (peer tr2 bond1) public side +# bondfab sjc-worker2 bond1 (peer sjc-worker bond0) fabric side +# PARENT=nic takes each side's first bond member out of its bond on both ends +# and uses that veth as a plain NIC. +# +# C5 (two VLANs on one parent) is not a lab cell: the lab's links are +# point-to-point, so one parent cannot reach both the external router and the +# compute node. Its kernel behaviour is measured by the vlanprobe root test +# (internal/plumbing/ebpf/vlanprobe). + +# cell public-VID fabric-VID parent +C1_PUB_VID= +C1_FAB_VID= +C1_PARENT=bond + +C2_PUB_VID=101 +C2_FAB_VID= +C2_PARENT=bond + +C3_PUB_VID= +C3_FAB_VID=202 +C3_PARENT=bond + +C4_PUB_VID=101 +C4_FAB_VID=202 +C4_PARENT=bond + +C6_PUB_VID=101 +C6_FAB_VID=202 +C6_PARENT=nic diff --git a/deploy/containerlab/scripts/verify-gateway-ingress-ipv4.sh b/deploy/containerlab/scripts/verify-gateway-ingress-ipv4.sh index e311fbc9..43920e69 100755 --- a/deploy/containerlab/scripts/verify-gateway-ingress-ipv4.sh +++ b/deploy/containerlab/scripts/verify-gateway-ingress-ipv4.sh @@ -137,6 +137,18 @@ case "${1:-}" in esac transit() { docker exec "clab-${LAB}-$1" "${@:2}"; } + +uplink_dev() { + local pair + local list=${UPLINK_DEV:-} + for pair in ${list//,/ }; do + if [ "${pair%%=*}" = "$1" ]; then + echo "${pair#*=}" + return + fi + done + echo "$2" +} client() { docker exec "clab-${LAB}-remote-host" "$@"; } unpin_all() { @@ -361,6 +373,10 @@ for site in "${SITES[@]}"; do [ -z "${only}" ] || [ "${only}" = "${gw}" ] || continue want_pins=$((want_pins + 1)) read -r tr nexthop dev <<<"${UPLINK[${gw}]}" + # UPLINK_DEV=NODE=DEV,... overrides the transit-side device, for the + # tagged transport variant (vlan-transport.sh), where the link's addresses + # live on a VLAN netdevice rather than the bond. + dev=$(uplink_dev "${gw}" "${dev}") echo "--- ${site}: ${vip} through ${gw} (pinned on ${tr}) ---" if ! transit "${tr}" ip -4 route replace "${vip}/32" via "${nexthop}" dev "${dev}"; then fail "could not pin ${vip} to ${gw} on ${tr}" diff --git a/deploy/containerlab/scripts/verify-gateway-ingress.sh b/deploy/containerlab/scripts/verify-gateway-ingress.sh index 9f83227d..7b43b07b 100755 --- a/deploy/containerlab/scripts/verify-gateway-ingress.sh +++ b/deploy/containerlab/scripts/verify-gateway-ingress.sh @@ -73,6 +73,18 @@ esac transit() { docker exec "clab-${LAB}-$1" "${@:2}"; } +uplink_dev() { + local pair + local list=${UPLINK_DEV:-} + for pair in ${list//,/ }; do + if [ "${pair%%=*}" = "$1" ]; then + echo "${pair#*=}" + return + fi + done + echo "$2" +} + unpin_all() { local site tr for site in "${SITES[@]}"; do @@ -172,6 +184,10 @@ for site in "${SITES[@]}"; do [ -z "${only}" ] || [ "${only}" = "${gw}" ] || continue checked=$((checked + 1)) read -r tr nexthop dev <<<"${UPLINK[${gw}]}" + # UPLINK_DEV=NODE=DEV,... overrides the transit-side device, for the + # tagged transport variant (vlan-transport.sh), where the link's addresses + # live on a VLAN netdevice rather than the bond. + dev=$(uplink_dev "${gw}" "${dev}") echo "--- ${site}: ${vip} through ${gw} (pinned on ${tr}) ---" transit "${tr}" ip -6 route replace "${vip}/128" via "${nexthop}" dev "${dev}" diff --git a/deploy/containerlab/scripts/vlan-inject.py b/deploy/containerlab/scripts/vlan-inject.py new file mode 100755 index 00000000..9fc9fd07 --- /dev/null +++ b/deploy/containerlab/scripts/vlan-inject.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# vlan-inject.py -- send crafted IPv6/UDP frames with chosen 802.1Q/802.1ad +# headers out of one interface, for the isolation rows of the tagged +# transport baseline (docs/designs/vlan-transport/acceptance.md V11 to V13). +# Runs inside a lab node (tr2 or a Kind node), which has python3. Standard +# library only. +# +# vlan-inject.py IFACE DST_MAC SRC_IP6 DST_IP6 DPORT CASE COUNT +# +# CASE is one of: +# untagged no tag +# q:VID one 802.1Q tag +# prio 802.1Q with VLAN ID 0 (priority tag) +# qq:VID1:VID2 two 802.1Q tags +# ad:VID1:VID2 802.1ad outer tag, 802.1Q inner tag +# trunc:VID 802.1Q tag with the frame cut inside the tag header +import socket +import struct +import sys + + +def csum(data): + if len(data) % 2: + data += b"\0" + s = sum(struct.unpack("!%dH" % (len(data) // 2), data)) + while s >> 16: + s = (s & 0xFFFF) + (s >> 16) + return (~s) & 0xFFFF + + +def ipv6_udp(src, dst, sport, dport, payload): + s = socket.inet_pton(socket.AF_INET6, src) + d = socket.inet_pton(socket.AF_INET6, dst) + length = 8 + len(payload) + udp = struct.pack("!HHHH", sport, dport, length, 0) + payload + pseudo = s + d + struct.pack("!I3xB", length, 17) + c = csum(pseudo + udp) or 0xFFFF + udp = udp[:6] + struct.pack("!H", c) + udp[8:] + hdr = struct.pack("!IHBB", 6 << 28, length, 17, 64) + s + d + return hdr + udp + + +def tags(case): + kind, _, rest = case.partition(":") + ids = [int(x) for x in rest.split(":")] if rest else [] + if kind == "untagged": + return b"", False + if kind == "q": + return struct.pack("!HH", 0x8100, ids[0]), False + if kind == "prio": + return struct.pack("!HH", 0x8100, 0), False + if kind == "qq": + return struct.pack("!HHHH", 0x8100, ids[0], 0x8100, ids[1]), False + if kind == "ad": + return struct.pack("!HHHH", 0x88A8, ids[0], 0x8100, ids[1]), False + if kind == "trunc": + return struct.pack("!HH", 0x8100, ids[0]), True + raise SystemExit("unknown case " + case) + + +def main(): + iface, dst_mac, src, dst, dport, case, count = sys.argv[1:8] + sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW) + sock.bind((iface, 0)) + src_mac = sock.getsockname()[4] + dmac = bytes.fromhex(dst_mac.replace(":", "")) + tag, truncate = tags(case) + sent = 0 + for i in range(int(count)): + body = ipv6_udp(src, dst, 40000 + i, int(dport), b"vlan-inject %s %d" % (case.encode(), i)) + frame = dmac + src_mac + tag + struct.pack("!H", 0x86DD) + body + if truncate: + frame = dmac + src_mac + tag[:3] + sock.send(frame) + sent += 1 + print("sent %d %s frames on %s" % (sent, case, iface)) + + +if __name__ == "__main__": + main() diff --git a/deploy/containerlab/scripts/vlan-transport-baseline.sh b/deploy/containerlab/scripts/vlan-transport-baseline.sh new file mode 100755 index 00000000..136985c5 --- /dev/null +++ b/deploy/containerlab/scripts/vlan-transport-baseline.sh @@ -0,0 +1,158 @@ +#!/bin/bash +# vlan-transport-baseline.sh: record the tagged/untagged transport baseline +# for one configuration cell on the sjc site (issue #1401). Applies the cell +# with vlan-transport.sh, runs each traffic row with captures on every +# transport link, and writes everything under OUT. It does not revert: the +# caller runs `vlan-transport.sh revert` and the site baseline afterwards, +# inside the same containerlab-manager reservation. +# +# Usage: vlan-transport-baseline.sh CELL SELECT OUT [ROWS] +# ROWS: space-separated subset of "V06 V01 V03 V05 V07 V11" (default all but V11) +# +# A row's result is what happened, pass or fail; a failing row is baseline +# evidence, so this script exits 0 unless the harness itself breaks. +set -uo pipefail + +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +LAB=${LAB:-gvpc} +CELL=${1:?cell} +SELECT=${2:?logical or parent} +OUT=${3:?output directory} +ROWS=${4:-V06 V01 V03 V05 V07} +EDGE=sjc-worker2 +COMPUTE=sjc-worker +TR=clab-${LAB}-tr2 +VT="${SCRIPT_DIR}/vlan-transport.sh" +GW_METRICS=8081 +NAT_METRICS=9182 +mkdir -p "${OUT}" +exec > >(tee -a "${OUT}/run.log") 2>&1 + +q() { docker exec "$@"; } +result() { echo "RESULT ${CELL}/${SELECT} $1: $2" | tee -a "${OUT}/results.txt"; } + +metrics() { # NODE PORT FILE + q "$1" curl -s --max-time 4 "http://localhost:$2/metrics" | grep -E '^galactic_' >"$3" || true +} + +# metric_delta BEFORE AFTER PATTERN: per-series increases for matching series. +metric_delta() { + join -a2 -e 0 -o '0,1.2,2.2' <(grep -E "$3" "$1" | awk '{print $1, $2}' | sort) \ + <(grep -E "$3" "$2" | awk '{print $1, $2}' | sort) | awk '$3 != $2 {printf " %s %s -> %s\n", $1, $2, $3}' +} + +counters_before() { + metrics "${EDGE}" "${GW_METRICS}" "${OUT}/$1-gw.before" + metrics "${EDGE}" "${NAT_METRICS}" "${OUT}/$1-nat.before" +} + +counters_after() { + metrics "${EDGE}" "${GW_METRICS}" "${OUT}/$1-gw.after" + metrics "${EDGE}" "${NAT_METRICS}" "${OUT}/$1-nat.after" + { + echo "gateway counters that moved:" + metric_delta "${OUT}/$1-gw.before" "${OUT}/$1-gw.after" '^galactic_(edge|xdp|gateway)' + echo "nat counters that moved:" + metric_delta "${OUT}/$1-nat.before" "${OUT}/$1-nat.after" '^galactic_(nat|xdp)' + } | tee "${OUT}/$1-counters.txt" +} + +field() { q "${EDGE}" sh -c "grep '^$1=' /galactic/vlan-transport.state | cut -d= -f2-"; } + +echo "=== ${CELL} ${SELECT} $(date -u +%FT%TZ)" +"${VT}" apply "${CELL}" "${SELECT}" +"${VT}" snapshot "${OUT}" +IFS=/ read -r PUB_L PUB_P PUB_VID <<<"$(field public)" +IFS=/ read -r FAB_L FAB_P FAB_VID <<<"$(field fabric)" +TR_DEV=bond1 +[ -n "${PUB_VID}" ] && TR_DEV=$(q "${TR}" sh -c "ip -o link show type vlan | awk -F': ' '{print \$2}' | cut -d@ -f1 | grep '\.${PUB_VID}\$' | head -1") +[ "${PUB_P}" = eth1 ] && [ -z "${PUB_VID}" ] && TR_DEV=eth1 +export TAG_A=${PUB_VID:-101} TAG_B=${FAB_VID:-202} +echo "public ${PUB_L} (parent ${PUB_P}, VID ${PUB_VID:-none}); fabric ${FAB_L} (parent ${FAB_P}, VID ${FAB_VID:-none}); tr2 device ${TR_DEV}" + +# Component state after the change: readiness, restarts and the log lines +# that say which interfaces each component took (V17/V18, contract Q1). +sleep 20 +{ + docker exec sjc-control-plane kubectl -n galactic-system get pods -o wide | grep -E "(${EDGE}|${COMPUTE})" + for app in galactic-gateway galactic-nat galactic-cni; do + for pod in $(docker exec sjc-control-plane kubectl -n galactic-system get pods -o wide | awk -v a="${app}" -v e="${EDGE}" -v c="${COMPUTE}" '$1 ~ "^"a && ($7 == e || $7 == c) {print $1}'); do + echo "--- ${pod}" + docker exec sjc-control-plane kubectl -n galactic-system logs "${pod}" --all-containers --tail=400 2>&1 \ + | grep -iE 'interface|xdp|attach|uplink|vlan|refus|error|fail|ready' | tail -25 + docker exec sjc-control-plane kubectl -n galactic-system logs "${pod}" --all-containers --previous --tail=60 2>/dev/null \ + | grep -iE 'refus|error|fail' | tail -5 | sed 's/^/previous: /' + done + done +} >"${OUT}/components.txt" 2>&1 +grep -cE 'Running' "${OUT}/components.txt" >/dev/null +head -80 "${OUT}/components.txt" + +for row in ${ROWS}; do + case "${row}" in + V06) + { + echo "--- tr2 BGP toward the edge" + q "${TR}" vtysh -c 'show bgp ipv6 unicast summary' | grep -E '2001:db8:1:21::2|Neighbor' + q "${TR}" vtysh -c 'show bgp ipv4 unicast summary' | grep -E '10\.1\.21\.2|Neighbor' + echo "--- neighbours" + q "${TR}" ip neigh show dev "${TR_DEV}" + q "${EDGE}" ip neigh show dev "${PUB_L}" + q "${EDGE}" ip neigh show dev "${FAB_L}" + } | tee "${OUT}/V06.txt" + if grep -qE '2001:db8:1:21::2 .*[0-9]+ +[0-9]+ *$|2001:db8:1:21::2.* [0-9]+ +N/A' "${OUT}/V06.txt" \ + && ! grep -E '2001:db8:1:21::2' "${OUT}/V06.txt" | grep -qE 'Active|Connect|Idle'; then + result V06 "public BGP Established" + else + result V06 "public BGP not established (see V06.txt)" + fi + ;; + V01) + counters_before V01 + "${VT}" capture-start "${OUT}" V01 + UPLINK_DEV="${EDGE}=${TR_DEV}" LAB=${LAB} "${SCRIPT_DIR}/verify-gateway-ingress.sh" --node "${EDGE}" >"${OUT}/V01-ipv6.txt" 2>&1 && r6=pass || r6=fail + UPLINK_DEV="${EDGE}=${TR_DEV}" LAB=${LAB} "${SCRIPT_DIR}/verify-gateway-ingress-ipv4.sh" --node "${EDGE}" >"${OUT}/V01-ipv4.txt" 2>&1 && r4=pass || r4=fail + "${VT}" capture-stop "${OUT}" V01 + counters_after V01 + tail -4 "${OUT}/V01-ipv6.txt" "${OUT}/V01-ipv4.txt" + result "V01/V02" "IPv6 VIP ${r6}, IPv4 VIP ${r4}" + ;; + V03) + counters_before V03 + "${VT}" capture-start "${OUT}" V03 + (cd "${SCRIPT_DIR}/.." && task verify:nat-datapath SENDER_SITE=sjc SHARD_NODE="${EDGE}" SHARD_SITE=sjc) >"${OUT}/V03.txt" 2>&1 && r=pass || r=fail + "${VT}" capture-stop "${OUT}" V03 + counters_after V03 + cat "${OUT}/V03.txt" + result "V03/V04" "NAT66 and NAT64 round trip ${r} ($(grep -cE '^ ok' "${OUT}/V03.txt") ok lines, $(grep -cE 'FAIL' "${OUT}/V03.txt") FAIL lines)" + ;; + V05) + "${VT}" capture-start "${OUT}" V05 + # ns20 is dual-stack and spans every site, so sjc's pod reaches dfw's and + # iad's across sjc's fabric and public sides. + "${SCRIPT_DIR}/verify-ns20.sh" >"${OUT}/V05.txt" 2>&1 && r=pass || r=fail + "${VT}" capture-stop "${OUT}" V05 + cat "${OUT}/V05.txt" + result V05 "ns20 dual-stack tenant ping between every site pair ${r}" + ;; + V07) + counters_before V07 + echo "change: ${EDGE}: ip neigh flush dev ${PUB_L}; ip neigh flush dev ${FAB_L}" + q "${EDGE}" ip neigh flush dev "${PUB_L}" + q "${EDGE}" ip neigh flush dev "${FAB_L}" + UPLINK_DEV="${EDGE}=${TR_DEV}" LAB=${LAB} "${SCRIPT_DIR}/verify-gateway-ingress.sh" --node "${EDGE}" >"${OUT}/V07-gw.txt" 2>&1 && rg=pass || rg=fail + echo "change: ${EDGE}: ip neigh flush dev ${PUB_L}; ip neigh flush dev ${FAB_L}" + q "${EDGE}" ip neigh flush dev "${PUB_L}" + q "${EDGE}" ip neigh flush dev "${FAB_L}" + (cd "${SCRIPT_DIR}/.." && task verify:nat-datapath SENDER_SITE=sjc SHARD_NODE="${EDGE}" SHARD_SITE=sjc) >"${OUT}/V07-nat.txt" 2>&1 && rn=pass || rn=fail + counters_after V07 + result V07 "after neighbour flush: gateway ${rg}, NAT ${rn}; fallbacks: $(grep -E 'neigh|fallback' "${OUT}/V07-counters.txt" | tr -s ' ' | tr '\n' ';')" + ;; + V11) + "${SCRIPT_DIR}/vlan-transport-inject.sh" "${OUT}" "${PUB_L}" "${PUB_VID}" | tee "${OUT}/V11.txt" + result "V11-V13" "$(grep -c '^case' "${OUT}/V11.txt") injection cases recorded" + ;; + esac +done +echo "=== ${CELL} ${SELECT} done $(date -u +%FT%TZ)" +exit 0 diff --git a/deploy/containerlab/scripts/vlan-transport-inject.sh b/deploy/containerlab/scripts/vlan-transport-inject.sh new file mode 100755 index 00000000..5710497f --- /dev/null +++ b/deploy/containerlab/scripts/vlan-transport-inject.sh @@ -0,0 +1,96 @@ +#!/bin/bash +# vlan-transport-inject.sh OUT PUB_LOGICAL PUB_VID: isolation baseline for +# the tagged transport variant (acceptance rows V11 to V13). Sends UDP to +# sjc's IPv6 VIP from tr2 toward sjc-worker2's public side in two +# representations, and reports for each case whether the edge's gateway +# claimed it (its per-VIP rule counter rose): +# +# in-frame raw frames from vlan-inject.py on tr2's bond member, so every +# tag is in packet data when sjc-worker2 receives it; +# kernel datagrams sent through a temporary VLAN netdevice on tr2's +# bond, so the tag crosses the veth as skb metadata, as receive +# VLAN offload presents it to XDP. +# +# Called by vlan-transport-baseline.sh inside the lab reservation; every +# change on tr2 is echoed with "change:" and removed before returning. +set -uo pipefail + +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +LAB=${LAB:-gvpc} +OUT=${1:?out} +PUB_L=${2:?public logical interface} +PUB_VID=${3:-} +EDGE=sjc-worker2 +TR=clab-${LAB}-tr2 +VIP=2001:db8:6060:2::1 +SRC=2001:db8:1:40::2 +COUNT=20 +q() { docker exec "$@"; } +mkdir -p "${OUT}" +exec > >(tee "${OUT}/inject.txt") 2>&1 + +rule_packets() { + q "${EDGE}" curl -s --max-time 4 http://localhost:8081/metrics \ + | awk -v vip="${VIP}" '/^galactic_edge_rule_packets_total/ && index($0, vip) {s += $2} END {print s + 0}' +} + +edge_mac=$(q "${EDGE}" cat "/sys/class/net/${PUB_L}/address") +docker cp "${SCRIPT_DIR}/vlan-inject.py" "${TR}:/tmp/vlan-inject.py" >/dev/null +other=$(( ${PUB_VID:-0} == 999 ? 998 : 999 )) +pub=${PUB_VID:-101} + +echo "edge public ${PUB_L} (VID ${PUB_VID:-none}); edge MAC ${edge_mac}" +for c in untagged "q:${pub}" "q:${other}" q:202 prio "qq:${pub}:5" "ad:300:${pub}" "trunc:${pub}"; do + before=$(rule_packets) + q "${TR}" python3 /tmp/vlan-inject.py eth1 "${edge_mac}" "${SRC}" "${VIP}" 80 "${c}" "${COUNT}" >/dev/null + sleep 2 + after=$(rule_packets) + echo "case in-frame ${c}: sent ${COUNT}, gateway rule packets +$((after - before))" +done + +# Kernel-tagged: the same VIP reached through a temporary VLAN on tr2's bond. +for vid in "${pub}" "${other}" 202; do + dev="bond1.${vid}" + created=0 + if ! q "${TR}" ip link show dev "${dev}" >/dev/null 2>&1; then + echo "change: ${TR}: ip link add link bond1 name ${dev} type vlan id ${vid}" + q "${TR}" ip link add link bond1 name "${dev}" type vlan id "${vid}" + q "${TR}" ip link set dev "${dev}" up + created=1 + fi + q "${TR}" ip -6 addr add 2001:db8:ffff::1/64 dev "${dev}" nodad 2>/dev/null + q "${TR}" ip -6 neigh replace 2001:db8:ffff::2 lladdr "${edge_mac}" dev "${dev}" + before=$(rule_packets) + q "${TR}" python3 - "${VIP}" "${dev}" "${COUNT}" <<'EOF' +import socket, sys +vip, dev, n = sys.argv[1], sys.argv[2], int(sys.argv[3]) +s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) +s.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, dev.encode()) +s.bind(("2001:db8:ffff::1", 0)) +for i in range(n): + # Through the static neighbour: the destination is reached on-link. + s.sendto(b"vlan-transport kernel %d" % i, ("2001:db8:ffff::2", 9)) +EOF + # The datagram above proves the netdevice transmits; the VIP probe below is + # what the gateway would claim. + q "${TR}" ip -6 route replace "${VIP}/128" via 2001:db8:ffff::2 dev "${dev}" table 4242 + q "${TR}" ip -6 rule add to "${VIP}/128" ipproto udp dport 80 lookup 4242 priority 4242 2>/dev/null + q "${TR}" python3 -c " +import socket +s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) +s.bind(('2001:db8:ffff::1', 0)) +for i in range(${COUNT}): + s.sendto(b'vlan-transport vip %d' % i, ('${VIP}', 80)) +" + sleep 2 + after=$(rule_packets) + q "${TR}" ip -6 rule del to "${VIP}/128" ipproto udp dport 80 lookup 4242 priority 4242 2>/dev/null + q "${TR}" ip -6 route flush table 4242 2>/dev/null + q "${TR}" ip -6 neigh del 2001:db8:ffff::2 dev "${dev}" 2>/dev/null + q "${TR}" ip -6 addr del 2001:db8:ffff::1/64 dev "${dev}" 2>/dev/null + if [ "${created}" = 1 ]; then + echo "change: ${TR}: ip link del ${dev}" + q "${TR}" ip link del dev "${dev}" + fi + echo "case kernel q:${vid}: sent ${COUNT}, gateway rule packets +$((after - before))" +done diff --git a/deploy/containerlab/scripts/vlan-transport-interrupt.sh b/deploy/containerlab/scripts/vlan-transport-interrupt.sh new file mode 100755 index 00000000..2b8d0ad3 --- /dev/null +++ b/deploy/containerlab/scripts/vlan-transport-interrupt.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# vlan-transport-interrupt.sh OUT: interruption baselines for the tagged +# transport variant (acceptance rows V23, V24, V27, V28). A tenant pod on +# sjc's compute node pings the off-fabric host every 20 ms through sjc's NAT +# shard, crossing both of sjc's transport sides, while one event happens. The +# interruption is the longest run of missing replies times 20 ms. +# +# Events, each with its own prober: +# restart-C1 galactic-nat restarted on untagged sides (V27 baseline) +# transition-C1-C2 C1 to C2 with parent selection (V23) +# restart-C2 galactic-nat restarted with the public side tagged (V27) +# recreate-C2 the edge's public VLAN netdevice deleted and recreated (V24) +# rollback-C2-C1 C2 back to C1 (V28) +# +# Runs inside the lab reservation; leaves sjc at C1. +set -uo pipefail + +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +source "${SCRIPT_DIR}/lib.sh" +OUT=${1:?out} +VT="${SCRIPT_DIR}/vlan-transport.sh" +CP=sjc-control-plane +EDGE=sjc-worker2 +TARGET=2001:db8:1:40::2 +INTERVAL=0.02 +COUNT=9000 # 180 s, enough for an apply or revert to finish +mkdir -p "${OUT}" + +POD=$(pod_name "${CP}" ns20) + +# probe NAME EVENT_DELAY COMMAND...: start the prober, run COMMAND after +# EVENT_DELAY seconds, wait for the prober, and report the longest gap. +probe() { + local name="$1" delay="$2" + shift 2 + docker exec "${CP}" kubectl -n ns20 exec "${POD}" -- \ + ping -6 -n -i "${INTERVAL}" -c "${COUNT}" -W 1 "${TARGET}" >"${OUT}/${name}.ping" 2>&1 & + local pinger=$! + sleep "${delay}" + echo "event ${name} at $(date -u +%T.%N | cut -c1-12): $*" + "$@" >"${OUT}/${name}.event" 2>&1 + wait "${pinger}" + python3 - "${OUT}/${name}.ping" "${COUNT}" <<'EOF' | tee -a "${OUT}/results.txt" +import re, sys +path, count = sys.argv[1], int(sys.argv[2]) +seen = set(int(m.group(1)) for m in re.finditer(r"icmp_seq=(\d+)", open(path).read())) +gap = run = 0 +for s in range(1, count + 1): + run = 0 if s in seen else run + 1 + gap = max(gap, run) +name = path.rsplit("/", 1)[1][:-5] +print("%s: %d/%d replies, longest gap %d probes = %d ms" % (name, len(seen), count, gap, gap * 20)) +EOF +} + +restart_nat() { + docker exec "${CP}" kubectl -n galactic-system rollout restart ds/galactic-nat + docker exec "${CP}" kubectl -n galactic-system rollout status ds/galactic-nat --timeout=120s +} + +recreate_vlan() { + local dev vid + dev=$(docker exec "${EDGE}" sh -c "grep '^public=' /galactic/vlan-transport.state | cut -d= -f2 | cut -d/ -f1") + vid=${dev##*.} + echo "change: ${EDGE}: ip link del ${dev}; recreate it with VID ${vid} and its addresses" + docker exec "${EDGE}" sh -c "ip link del ${dev} && ip link add link ${dev%.*} name ${dev} type vlan id ${vid} \ + && ip link set ${dev} up && ip -6 addr add 2001:db8:1:21::2/64 dev ${dev} && ip -4 addr add 10.1.21.2/24 dev ${dev}" +} + +probe restart-C1 10 restart_nat +probe transition-C1-C2 10 "${VT}" apply C2 parent +probe restart-C2 10 restart_nat +probe recreate-C2 10 recreate_vlan +probe rollback-C2-C1 10 "${VT}" revert +cat "${OUT}/results.txt" diff --git a/deploy/containerlab/scripts/vlan-transport.sh b/deploy/containerlab/scripts/vlan-transport.sh new file mode 100755 index 00000000..82175eab --- /dev/null +++ b/deploy/containerlab/scripts/vlan-transport.sh @@ -0,0 +1,482 @@ +#!/bin/bash +# vlan-transport.sh: the tagged/untagged transport lab variant on the sjc +# site (docs/designs/vlan-transport/, issue #1401). +# +# Moves sjc's public side (sjc-worker2 bond0 <-> tr2 bond1) and fabric side +# (sjc-worker2 bond1 <-> sjc-worker bond0) between untagged and 802.1Q tagged +# transport at run time, and points galactic-gateway, galactic-nat and +# galactic-cni at the chosen interfaces. Nothing under config/ or resources/ +# changes: interfaces and addresses change on the live nodes, routing config +# on tr2 changes in vtysh's running config only, and the Galactic settings +# change with kubectl on the live DaemonSets. `revert` undoes all of it from +# the state the first `apply` saved on the edge node. +# +# Usage: +# vlan-transport.sh plan CELL [logical|parent] print what apply would change; needs no lab +# vlan-transport.sh apply CELL [logical|parent] cells in ../resources/vlan-transport/cells.env +# vlan-transport.sh revert back to C1 with the saved Galactic settings +# vlan-transport.sh status what is applied now +# vlan-transport.sh offload on|off VLAN offloads on every transport member +# vlan-transport.sh snapshot DIR interfaces, offloads, XDP, versions +# vlan-transport.sh capture-start DIR NAME tcpdump every transport link +# vlan-transport.sh capture-stop DIR NAME stop and summarize tags per link +# +# SELECT=logical (default) names each side's logical interface, as the +# contract requires: the VLAN netdevice on a tagged side. SELECT=parent names +# the parent instead, the misconfiguration the contract's section 4 accepts, +# which lets the unchanged XDP programs show how they treat tagged traffic. +# PUB_VID and FAB_VID override the cell's IDs. +# +# The caller holds the containerlab-manager reservation. Every change here is +# echoed with a "change:" prefix so the run's log records it exactly. +set -euo pipefail + +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +source "${SCRIPT_DIR}/lib.sh" + +LAB=${LAB:-gvpc} +NS=galactic-system +STATE=/galactic/vlan-transport.state +CELLS="${RESOURCES_DIR}/vlan-transport/cells.env" +CNI_COPY=galactic-cni-vt-edge + +# VT_SITE picks the edge node the variant re-plumbs. sjc (the default) is the +# full variant: sjc-worker2's public and fabric sides. dfw-worker3 changes +# only that node's public side, for the same-node delivery row (V10), which +# the edge conformance suite runs on dfw; dfw's NAT DaemonSet also serves +# dfw-worker2, so its settings stay as deployed there. +# +# Per side: " " for +# both ends. Keep in step with resources/node-addresses/ and node_files/tr*. +# The side arrays are read through namerefs (side_apply, side_revert). +# shellcheck disable=SC2034 +case "${VT_SITE:-sjc}" in + sjc) + EDGE=sjc-worker2 COMPUTE=sjc-worker CP=sjc-control-plane TR=clab-${LAB}-tr2 + PUB_EDGE=("${EDGE}" bond0 eth1 2001:db8:1:21::2/64 10.1.21.2/24) + PUB_PEER=("${TR}" bond1 eth1 2001:db8:1:21::1/64 10.1.21.1/24) + FAB_EDGE=("${EDGE}" bond1 eth2 2001:db8:1:20::1/64 10.1.20.1/24) + FAB_PEER=("${COMPUTE}" bond0 eth1 2001:db8:1:20::2/64 10.1.20.2/24) + MEMBERS=("${TR} eth1 eth5" "${EDGE} eth1 eth3 eth2 eth4" "${COMPUTE} eth1 eth2") + SET_NAT=1 + ;; + dfw-worker3) + EDGE=dfw-worker3 COMPUTE=dfw-worker CP=dfw-control-plane TR=clab-${LAB}-tr1 + PUB_EDGE=("${EDGE}" bond0 eth1 2001:db8:1:12::2/64 10.1.12.2/24) + PUB_PEER=("${TR}" bond2 eth5 2001:db8:1:12::1/64 10.1.12.1/24) + FAB_EDGE=("${EDGE}" bond1 eth2 2001:db8:1:13::1/64 10.1.13.1/24) + FAB_PEER=("${COMPUTE}" bond1 eth2 2001:db8:1:13::2/64 10.1.13.2/24) + MEMBERS=("${TR} eth5 eth7" "${EDGE} eth1 eth3") + SET_NAT=0 + ;; + *) echo "vlan-transport: unknown VT_SITE ${VT_SITE}" >&2; exit 2 ;; +esac +# Datapath images and kubectl live on the Kind nodes; the transit routers +# have vtysh. +kc() { docker exec "${CP}" kubectl -n "${NS}" "$@"; } +on() { local n="$1"; shift; echo "change: ${n}: $*"; docker exec "${n}" "$@"; } +q() { local n="$1"; shift; docker exec "${n}" "$@"; } + +die() { echo "vlan-transport: $*" >&2; exit 1; } + +# ethtool runs on the Kind nodes directly. tr2's image has none, so it runs +# from the Kind node image joined to tr2's network namespace. +eth() { + local n="$1" + shift + if [ "${n}" = "${TR}" ]; then + docker run --rm --privileged --network "container:${TR}" --entrypoint ethtool kindest/node:galactic "$@" + else + docker exec "${n}" ethtool "$@" + fi +} + +state_get() { q "${EDGE}" sh -c "test -f ${STATE} && grep '^$1=' ${STATE} | cut -d= -f2- || true"; } +state_put() { q "${EDGE}" sh -c "grep -v '^$1=' ${STATE} 2>/dev/null > ${STATE}.new || true; echo '$1=$2' >> ${STATE}.new; mv ${STATE}.new ${STATE}"; } + +ds_env() { # DS CONTAINER VAR + kc get ds "$1" -o jsonpath="{.spec.template.spec.containers[?(@.name=='$2')].env[?(@.name=='$3')].value}" +} + +gateway_ds() { kc get ds -o name | grep -E "galactic-gateway.*${EDGE}" | head -1 | cut -d/ -f2; } + +# save_original records the C1 Galactic settings once, before the first change. +save_original() { + [ -n "$(state_get gw_public)" ] && return + local gw + gw=$(gateway_ds) + [ -n "${gw}" ] || die "no galactic-gateway DaemonSet for ${EDGE}" + q "${EDGE}" sh -c ": > ${STATE}" + state_put gw_ds "${gw}" + state_put gw_public "$(ds_env "${gw}" galactic-gateway GALACTIC_GATEWAY_PUBLIC_INTERFACE)" + state_put gw_internal "$(ds_env "${gw}" galactic-gateway GALACTIC_GATEWAY_INTERNAL_INTERFACES)" + state_put nat_uplinks "$(ds_env galactic-nat galactic-nat GALACTIC_NAT_UPLINK_INTERFACES)" + state_put cni_ifaces "$(ds_env galactic-cni credential-refresh GALACTIC_CNI_EBPF_INTERFACES)" + q "${EDGE}" cat "${STATE}" | sed 's/^/saved: /' +} + +# --- interfaces ------------------------------------------------------------- + +# tr2 addresses belong to FRR (node_files/tr2/frr.conf), so they move with +# vtysh; the Kind nodes' addresses are host-managed (deploy:node-addresses), +# so they move with ip. +addr_move() { # NODE FROM TO V6 V4 + local n="$1" from="$2" to="$3" v6="$4" v4="$5" + if [ "${n}" = "${TR}" ]; then + on "${n}" vtysh -c "configure terminal" -c "interface ${from}" -c "no ipv6 address ${v6}" -c "no ip address ${v4}" \ + -c "interface ${to}" -c "ipv6 address ${v6}" -c "ip address ${v4}" + else + on "${n}" ip -6 addr del "${v6}" dev "${from}" 2>/dev/null || true + on "${n}" ip -4 addr del "${v4}" dev "${from}" 2>/dev/null || true + on "${n}" ip -6 addr replace "${v6}" dev "${to}" + on "${n}" ip -4 addr replace "${v4}" dev "${to}" + fi +} + +# side_apply END PARENT_KIND VID: build one end of one side and print its +# logical interface and parent as "logical parent". +side_apply() { + local -n e="$1" + local kind="$2" vid="$3" n="${e[0]}" bond="${e[1]}" member="${e[2]}" v6="${e[3]}" v4="${e[4]}" + local parent="${bond}" + if [ "${kind}" = nic ]; then + parent="${member}" + if q "${n}" ip -o link show dev "${member}" | grep -q " master ${bond} "; then + on "${n}" ip link set dev "${member}" nomaster + on "${n}" ip link set dev "${member}" mtu 1500 up + fi + fi + local logical="${parent}" + if [ -n "${vid}" ]; then + logical="${parent}.${vid}" + q "${n}" ip link show dev "${logical}" >/dev/null 2>&1 \ + || on "${n}" ip link add link "${parent}" name "${logical}" type vlan protocol 802.1Q id "${vid}" + on "${n}" ip link set dev "${logical}" up + fi + if [ "${logical}" != "${bond}" ]; then + addr_move "${n}" "${bond}" "${logical}" "${v6}" "${v4}" + fi + echo "${logical} ${parent}" >&3 +} + +# side_revert END: remove any VLAN and re-bond, moving the addresses home. +side_revert() { + local -n e="$1" + local n="${e[0]}" bond="${e[1]}" member="${e[2]}" v6="${e[3]}" v4="${e[4]}" dev + for dev in $(q "${n}" sh -c "ip -o link show type vlan | awk -F': ' '{print \$2}' | cut -d@ -f1"); do + case "${dev}" in + "${bond}".* | "${member}".*) + addr_move "${n}" "${dev}" "${bond}" "${v6}" "${v4}" + on "${n}" ip link del dev "${dev}" + ;; + esac + done + if ! q "${n}" ip -o link show dev "${member}" | grep -q " master ${bond} "; then + if [ "${n}" = "${TR}" ]; then + on "${n}" /opt/lab/mkbond.sh "${bond}" "${member}" + else + on "${n}" /galactic/scripts/mkbond.sh "${bond}" "${member}" + fi + fi + if [ "${n}" != "${TR}" ]; then + on "${n}" ip -6 addr replace "${v6}" dev "${bond}" + on "${n}" ip -4 addr replace "${v4}" dev "${bond}" + fi +} + +# --- Galactic settings ------------------------------------------------------ + +set_gateway() { # PUBLIC INTERNAL + local gw + gw=$(state_get gw_ds) + echo "change: ds/${gw}: GALACTIC_GATEWAY_PUBLIC_INTERFACE=$1 GALACTIC_GATEWAY_INTERNAL_INTERFACES=$2" + kc set env "ds/${gw}" -c galactic-gateway "GALACTIC_GATEWAY_PUBLIC_INTERFACE=$1" "GALACTIC_GATEWAY_INTERNAL_INTERFACES=$2" +} + +set_nat() { + echo "change: ds/galactic-nat: GALACTIC_NAT_UPLINK_INTERFACES=$1" + kc set env ds/galactic-nat -c galactic-nat "GALACTIC_NAT_UPLINK_INTERFACES=$1" +} + +# set_cni COMPUTE_VALUE EDGE_VALUE. One cluster-wide DaemonSet serves both +# sjc nodes, and bond0 is the public side on the edge but the fabric side on +# the compute node, so a tagged side needs different names per node. When the +# values differ, the edge gets its own copy of the DaemonSet and the original +# excludes it. +set_cni() { + local compute="$1" edge="$2" + if kc get ds "${CNI_COPY}" >/dev/null 2>&1; then + cni_unsplit + fi + if [ "${edge}" != "${compute}" ]; then + echo "change: ds/galactic-cni: exclude ${EDGE}; ds/${CNI_COPY} on ${EDGE} with GALACTIC_CNI_EBPF_INTERFACES=${edge}" + kc patch ds galactic-cni --type=json -p "[{\"op\":\"add\",\"path\":\"/spec/template/spec/affinity/nodeAffinity/requiredDuringSchedulingIgnoredDuringExecution/nodeSelectorTerms/0/matchExpressions/-\",\"value\":{\"key\":\"kubernetes.io/hostname\",\"operator\":\"NotIn\",\"values\":[\"${EDGE}\"]}}]" + kc rollout status ds/galactic-cni --timeout=300s + kc get ds galactic-cni -o json | jq --arg name "${CNI_COPY}" --arg node "${EDGE}" --arg v "${edge}" ' + {apiVersion, kind, metadata: {name: $name, namespace: .metadata.namespace, labels: .metadata.labels}, + spec: (.spec + | .selector.matchLabels["vlan-transport.lab/copy"] = "edge" + | .template.metadata.labels["vlan-transport.lab/copy"] = "edge" + | .template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions + |= map(if .key == "kubernetes.io/hostname" then .operator = "In" | .values = [$node] else . end) + | (.template.spec.containers[], (.template.spec.initContainers // [])[]).env + |= ((. // []) | map(if .name == "GALACTIC_CNI_EBPF_INTERFACES" then .value = $v else . end)))}' \ + | docker exec -i "${CP}" kubectl apply -f - + kc rollout status "ds/${CNI_COPY}" --timeout=300s || echo "set_cni: ${CNI_COPY} not ready (recorded, not fatal)" + fi + echo "change: ds/galactic-cni: GALACTIC_CNI_EBPF_INTERFACES=${compute} (all containers)" + kc set env ds/galactic-cni --containers='*' "GALACTIC_CNI_EBPF_INTERFACES=${compute}" + kc rollout status ds/galactic-cni --timeout=300s || echo "set_cni: galactic-cni not ready (recorded, not fatal)" +} + +cni_unsplit() { + echo "change: delete ds/${CNI_COPY}; ds/galactic-cni: drop the ${EDGE} exclusion" + kc delete ds "${CNI_COPY}" --wait=true + local idx + idx=$(kc get ds galactic-cni -o json | jq '.spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions | map(.key) | index("kubernetes.io/hostname")') + if [ "${idx}" != null ]; then + kc patch ds galactic-cni --type=json -p "[{\"op\":\"remove\",\"path\":\"/spec/template/spec/affinity/nodeAffinity/requiredDuringSchedulingIgnoredDuringExecution/nodeSelectorTerms/0/matchExpressions/${idx}\"}]" + fi +} + +wait_galactic() { + local gw rc=0 + gw=$(state_get gw_ds) + kc rollout status "ds/${gw}" --timeout=180s || rc=1 + if [ "${SET_NAT}" = 1 ]; then + kc rollout status ds/galactic-nat --timeout=180s || rc=1 + fi + return "${rc}" +} + +# --- commands --------------------------------------------------------------- + +# cell_values CELL SELECT sets pv, fv and kind from cells.env, applying the +# PUB_VID and FAB_VID overrides, and rejects values no transport may use. +cell_values() { + local cell="$1" select="$2" v + case "${cell}" in C[0-9]) ;; *) die "unknown cell ${cell}" ;; esac + case "${select}" in logical | parent) ;; *) die "select must be logical or parent, not ${select}" ;; esac + # shellcheck disable=SC1090 + source "${CELLS}" + eval "pv=\${${cell}_PUB_VID-unset} fv=\${${cell}_FAB_VID-unset} kind=\${${cell}_PARENT-unset}" + [ "${kind}" != unset ] || die "unknown cell ${cell}" + pv=${PUB_VID-${pv}} + fv=${FAB_VID-${fv}} + for v in "${pv}" "${fv}"; do + [ -z "${v}" ] && continue + if ! [[ "${v}" =~ ^[0-9]+$ ]] || [ "${v}" -lt 1 ] || [ "${v}" -gt 4094 ]; then + die "VLAN ID ${v} is outside 1 to 4094" + fi + done +} + +# name_of END KIND VID prints an end's logical interface and parent, as +# side_apply builds them. +name_of() { + local -n e="$1" + local parent="${e[1]}" + [ "$2" = nic ] && parent="${e[2]}" + if [ -n "$3" ]; then echo "${parent}.$3 ${parent}"; else echo "${parent} ${parent}"; fi +} + +# cmd_plan CELL [SELECT] prints what apply would change, touching nothing. +cmd_plan() { + local cell="${1:?cell}" select="${2:-logical}" pv fv kind end l p + cell_values "${cell}" "${select}" + echo "plan ${cell} on ${VT_SITE:-sjc}: public VID '${pv:-none}', fabric VID '${fv:-none}', parent ${kind}, select ${select}" + declare -A pick + for end in PUB_PEER PUB_EDGE FAB_EDGE FAB_PEER; do + local vid=${pv} + [[ "${end}" == FAB_* ]] && vid=${fv} + read -r l p <<<"$(name_of "${end}" "${kind}" "${vid}")" + local -n arr="${end}" + echo " ${end}: ${arr[0]#clab-"${LAB}"-} logical ${l}, parent ${p}, addresses ${arr[3]} ${arr[4]}" + pick[${end}]=${l} + [ "${select}" = parent ] && pick[${end}]=${p} + unset -n arr + done + echo " galactic-gateway on ${EDGE}: PUBLIC=${pick[PUB_EDGE]} INTERNAL=${pick[FAB_EDGE]}" + if [ "${SET_NAT}" = 1 ]; then + echo " galactic-nat: UPLINK_INTERFACES=${pick[PUB_EDGE]},${pick[FAB_EDGE]}" + echo " galactic-cni: ${COMPUTE} EBPF_INTERFACES=${pick[FAB_PEER]}; ${EDGE} EBPF_INTERFACES=${pick[PUB_EDGE]}" + else + echo " galactic-cni: ${EDGE} EBPF_INTERFACES=${pick[PUB_EDGE]},${pick[FAB_EDGE]}; other nodes unchanged" + fi +} + +cmd_apply() { + local cell="${1:?cell}" select="${2:-logical}" pv fv kind + cell_values "${cell}" "${select}" + save_original + [ -z "$(state_get cell)" ] || [ "$(state_get cell)" = C1 ] || cmd_revert_interfaces + echo "apply ${cell}: public VID '${pv:-none}', fabric VID '${fv:-none}', parent ${kind}, select ${select}" + + local pub fab cpt + exec 3>/tmp/vlan-transport.$$ + side_apply PUB_PEER "${kind}" "${pv}" + side_apply PUB_EDGE "${kind}" "${pv}" + side_apply FAB_EDGE "${kind}" "${fv}" + side_apply FAB_PEER "${kind}" "${fv}" + exec 3>&- + mapfile -t lines /dev/null || echo 'no state: C1 as deployed'" + local n + for n in "${TR}" "${EDGE}" "${COMPUTE}"; do + echo "--- ${n}" + q "${n}" sh -c "ip -br addr show | grep -E '^(bond|eth[1-5])' || true" + done + kc get pods -o wide 2>/dev/null | grep -E "galactic-(gateway|nat|cni).*(${EDGE}|${COMPUTE})" || true +} + +cmd_snapshot() { + local dir="${1:?dir}" n i + mkdir -p "${dir}" + { + echo "date: $(date -u +%FT%TZ)" + echo "host kernel: $(uname -r)" + for n in "${TR}" "${EDGE}" "${COMPUTE}"; do + echo "=== ${n}" + q "${n}" uname -r + q "${n}" ip -d link show 2>/dev/null | grep -A3 -E '^[0-9]+: (bond|eth[1-5])' || true + for i in $(q "${n}" sh -c "ls /sys/class/net | grep -E '^(bond|eth[1-5])'"); do + echo "--- ${n} ${i} ethtool" + { eth "${n}" -i "${i}" 2>/dev/null | head -2; eth "${n}" -k "${i}" 2>/dev/null | grep -E 'vlan|generic-receive'; } || true + done + done + echo "=== galactic images" + kc get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.nodeName}{"\t"}{range .status.containerStatuses[*]}{.imageID}{" "}{end}{"\n"}{end}' \ + | grep -E "(${EDGE}|${COMPUTE})" || true + } >"${dir}/snapshot.txt" 2>&1 + echo "snapshot: ${dir}/snapshot.txt" +} + +# Capture points: the receiving end of every transport link, so frames a +# sender transmits from XDP (invisible to its own tcpdump) are still seen. +# Captures run on bond members or plain NICs, never on VLAN netdevices, so +# libpcap reports the tag whether it is in the frame or in skb metadata. +if [ "${VT_SITE:-sjc}" = sjc ]; then + CAPS=( + "${TR} eth1 public-at-router" "${TR} eth5 public-at-router" + "${EDGE} eth1 public-at-edge" "${EDGE} eth3 public-at-edge" + "${EDGE} eth2 fabric-at-edge" "${EDGE} eth4 fabric-at-edge" + "${COMPUTE} eth1 fabric-at-compute" "${COMPUTE} eth2 fabric-at-compute" + ) +else + CAPS=( + "${TR} eth5 public-at-router" "${TR} eth7 public-at-router" + "${EDGE} eth1 public-at-edge" "${EDGE} eth3 public-at-edge" + ) +fi + +cmd_capture_start() { + local dir="${1:?dir}" name="${2:?name}" c n i role + for c in "${CAPS[@]}"; do + read -r n i role <<<"${c}" + q "${n}" sh -c "rm -f /tmp/vt-${name}-${i}.pcap; (timeout 300 tcpdump -i ${i} -nn -e -s 128 -w /tmp/vt-${name}-${i}.pcap >/dev/null 2>/tmp/vt-${name}-${i}.err &)" + done + sleep 2 +} + +cmd_capture_stop() { + local dir="${1:?dir}" name="${2:?name}" c n i role f + mkdir -p "${dir}" + sleep 1 + for c in "${CAPS[@]}"; do + read -r n i role <<<"${c}" + q "${n}" sh -c "pkill -INT -f 'tcpdump -i ${i} -nn -e -s 128 -w /tmp/vt-${name}-${i}.pcap' || true" + done + sleep 1 + for c in "${CAPS[@]}"; do + read -r n i role <<<"${c}" + f="${dir}/${name}-${n#clab-"${LAB}"-}-${i}.pcap" + docker cp "${n}:/tmp/vt-${name}-${i}.pcap" "${f}" >/dev/null 2>&1 || continue + local tot v1 v2 un + tot=$(tcpdump -r "${f}" -nn 2>/dev/null | wc -l) + v1=$(tcpdump -r "${f}" -nn "vlan ${TAG_A:-101}" 2>/dev/null | wc -l) + v2=$(tcpdump -r "${f}" -nn "vlan ${TAG_B:-202}" 2>/dev/null | wc -l) + un=$(tcpdump -r "${f}" -nn 'not vlan' 2>/dev/null | wc -l) + printf '%-18s %-12s %-5s total=%-6s vlan%s=%-6s vlan%s=%-6s untagged=%-6s other-tag=%s\n' "${role}" "${n#clab-"${LAB}"-}" "${i}" \ + "${tot}" "${TAG_A:-101}" "${v1}" "${TAG_B:-202}" "${v2}" "${un}" "$((tot - v1 - v2 - un))" + done | tee "${dir}/${name}-tags.txt" +} + +case "${1:-}" in + plan) shift; cmd_plan "$@" ;; + apply) shift; cmd_apply "$@" ;; + revert) cmd_revert ;; + status) cmd_status ;; + offload) shift; cmd_offload "$@" ;; + snapshot) shift; cmd_snapshot "$@" ;; + capture-start) shift; cmd_capture_start "$@" ;; + capture-stop) shift; cmd_capture_stop "$@" ;; + *) sed -n '2,30p' "$0"; exit 2 ;; +esac diff --git a/tests/edgeconformance/listener_test.go b/tests/edgeconformance/listener_test.go index 25d42234..5afbbd3c 100644 --- a/tests/edgeconformance/listener_test.go +++ b/tests/edgeconformance/listener_test.go @@ -433,6 +433,19 @@ func clab(node string) string { func transitRouter() string { return clab("tr1") } +// uplinkDev returns tr1's device toward gateway: def, unless +// EDGE_CONFORMANCE_UPLINK_DEV ("node=dev,...") names another. The tagged +// transport variant (deploy/containerlab/scripts/vlan-transport.sh) moves a +// link's addresses onto a VLAN netdevice, which the pin must then name. +func uplinkDev(gateway, def string) string { + for _, pair := range strings.Split(os.Getenv("EDGE_CONFORMANCE_UPLINK_DEV"), ",") { + if node, dev, ok := strings.Cut(pair, "="); ok && node == gateway { + return dev + } + } + return def +} + // pin routes f's VIP from tr1 to gateway only, more specific than the // prefix both dfw edge nodes originate. func (p *listenerProof) pin(t *testing.T, f listenerFamily, gateway string) { @@ -443,7 +456,7 @@ func (p *listenerProof) pin(t *testing.T, f listenerFamily, gateway string) { fam, plen = "-4", "/32" } if _, err := nodeExec(transitRouter(), "ip", fam, "route", "replace", f.vip+plen, "via", up[0], "dev", - up[1]); err != nil { + uplinkDev(gateway, up[1])); err != nil { t.Fatal(err) } } From 97d25ae35c6dd429f3e187cb882f5e896854218f Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Mon, 30 Nov 2026 13:31:44 -0500 Subject: [PATCH 3/4] docs(archive): Record the VLAN transport baseline Answer the contract's questions Q1 to Q6 from the kernel probe and from source, labelling each answer, and record the expected result of every packet path on main, the owner of each expected failure, the gaps, and proposed task refinements. Every lab row is deferred to the epic's end-of-epic lab pass and none is reported as passed. Link the report from the evidence archive, the contract and the acceptance matrix. The probe also ran in CI's root unit-test job on kernel 7.0.0. It saw the same tag representation at every hook and on every wire, but its receiver accepted none of the redirected datagrams, including untagged ones, so the Q4 and Q5 answers rest on the wire observations. --- docs/archive/README.md | 1 + .../vlan-transport-baseline-2026-11-30.md | 206 ++++++++++++++++++ docs/designs/vlan-transport/acceptance.md | 2 +- docs/designs/vlan-transport/contract.md | 2 +- 4 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 docs/archive/benchmarks/vlan-transport-baseline-2026-11-30.md diff --git a/docs/archive/README.md b/docs/archive/README.md index a012f93e..2bdd91a0 100644 --- a/docs/archive/README.md +++ b/docs/archive/README.md @@ -14,5 +14,6 @@ Use the [current egress rollout checklist](../nat/active-active-rollout.md). In - [fabric-api full-table measurements, October 7](benchmarks/fabric-api-2026-10-07.md). - [Looking Glass qualification on the lab, October 27](benchmarks/looking-glass-qualification-2026-10-27.md). +- [VLAN transport baseline, November 30](benchmarks/vlan-transport-baseline-2026-11-30.md): kernel probe results and the expected result of each path, before the transport work. Use the [maintained load-test procedure](../fabric-api/load-test.md) and the [Looking Glass qualification procedure](../fabric-api/qualification.md) to qualify a new release. Record its revision, environment and result instead of replacing the older evidence. diff --git a/docs/archive/benchmarks/vlan-transport-baseline-2026-11-30.md b/docs/archive/benchmarks/vlan-transport-baseline-2026-11-30.md new file mode 100644 index 00000000..7f6a50ad --- /dev/null +++ b/docs/archive/benchmarks/vlan-transport-baseline-2026-11-30.md @@ -0,0 +1,206 @@ +# VLAN transport baseline, 2026-11-30 + +This is the baseline for issue [#1401](https://github.com/datum-cloud/galactic/issues/1401) under epic [#1399](https://github.com/datum-cloud/galactic/issues/1399). It records what the code below does with tagged and untagged transport, checked against the [transport contract](../../designs/vlan-transport/contract.md) and its [acceptance matrix](../../designs/vlan-transport/acceptance.md). A failing or inferred row is discovery evidence, not acceptance. Nothing here qualifies a hardware environment, a staging cell or a release. + +| Item | Value | +| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Code | `epic/1399-vlan-transport` at `352fe3a2`, which carries `main` at `c504549a` plus the contract documents. `main` has since moved; nothing here covers that. | +| Environment U | veth and 802.3ad bond parents in network namespaces. Run as root in a privileged container on kernel 7.3.3, and in CI's root unit-test job on kernel 7.0.0, on 2026-11-30. | +| Environment L | Not run. The epic moved every lab run to one pass at its end ([#1405](https://github.com/datum-cloud/galactic/issues/1405)). The variant tooling is in place. | +| Environment H | Not run; [#1406](https://github.com/datum-cloud/galactic/issues/1406). | + +Each answer and row is labelled: + +- **Probe-measured**: executed by the kernel probe below. +- **Source-inferred**: read from code at `352fe3a2`, combined with probe results where stated. It is not observed behaviour of a Galactic component. +- **Deferred to #1405 end-of-epic lab pass**: not run here. It is never counted as passed. + +No row is lab-measured. + +## Answers to the contract's questions + +| Question | Answer | Label | +| ----------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | +| Q1. Where XDP hooks attach for a tagged side | A VLAN netdevice accepts generic XDP only. Native attach fails with `EOPNOTSUPP`, and the kernel reports it as having no native XDP, so Galactic's gate refuses it first. On `main`, `edgeattach.ResolveTargets` and `natattach.ResolveTargets` keep a VLAN netdevice as the target. A gateway or NAT shard pointed at a tagged side's logical interface therefore fails to attach in native mode. Native hooks have to go on the parent or its members, with the tag handled in the program. | Probe-measured; source-inferred for Galactic | +| Q2. Where the tag is, and whether `XDP_PASS` keeps it | At XDP the tag is in packet data unless VLAN offload has moved it into metadata: on veth, the sender's transmit offload decides. When it is in metadata the frame looks untagged. At tc on the physical interface or bond it is always in `skb->vlan_tci`. At tc on the VLAN netdevice it is gone. `XDP_PASS` delivered every frame to the correct VLAN netdevice in all 16 mode and offload combinations. | Probe-measured | +| Q3. How XDP tells two VLANs on one parent apart | From packet data it cannot when the tag is in metadata: both VLANs' frames are identical. The device-bound kfunc `bpf_xdp_metadata_rx_vlan_tag` returned the right VID on a veth and a bond member in native mode. It does not load for a VLAN netdevice, does not attach in generic mode, and binds a program to one device, which the shared XDP dispatcher does not do today. | Probe-measured | +| Q4. XDP redirect to a VLAN netdevice; FIB result through it | `bpf_fib_lookup` returns the VLAN netdevice. A native XDP redirect to it drops every frame, since there is no `ndo_xdp_xmit`. A generic redirect transmits it tagged. A redirect to the parent sends it untagged. | Probe-measured | +| Q5. tc `bpf_redirect` to a VLAN netdevice | It inserts the tag, on veth and bond parents, with transmit VLAN offload on and off. | Probe-measured; hardware parents deferred to #1406 | +| Q6. Same-node delivery with a tagged public side | Not reachable on `main` in the contract's configuration, because `edge_lb` cannot attach natively to the public VLAN netdevice (Q1). With the parent named instead and the tag in metadata, `edge_lb` would claim the frame: it checks only the EtherType (`edgedsr.c:1306`), and the probe shows such frames look untagged. It would push the outer header and return `XDP_PASS`, and the tag stays in metadata through `XDP_PASS` (Q2). `usid_ingress` on the bond members then sees it in `skb->vlan_tci` and pops it after decapsulation (`usid.c:4479`). With the tag in packet data, `edge_lb` does not claim the frame at all. Which hook claims the packet first, and the end-to-end result, are deferred to #1405. | Source-inferred from probe results | + +## Kernel behaviour (environment U) + +**Measured.** `TestVLANTransportProbe` (`internal/plumbing/ebpf/vlanprobe`) ran as root in a privileged container on host kernel 7.3.3. Parents are veths, either a single veth (the "NIC" case) or an 802.3ad bond of two veths, with VLANs 101 and 202 on every parent. Every delivery row sends 10 UDP datagrams after a warm-up datagram. Probe programs at each hook record the EtherType in packet data and any tag in metadata: `skb->vlan_tci` at tc, the `bpf_xdp_metadata_rx_vlan_tag` kfunc at XDP. Reproduce with: + +```sh +task test:unit-root # or, without host root, in a privileged container: +CGO_ENABLED=0 go test -c -o vlanprobe.test ./internal/plumbing/ebpf/vlanprobe/ +clang -O2 -g -target bpf -c internal/plumbing/ebpf/vlanprobe/testdata/probe.c -o probe.o +docker run --rm --privileged -v "$PWD:/w" -w /w -e VLANPROBE_OBJ=/w/probe.o \ + -e VLANPROBE_REPORT=/w/vlanprobe-report.json fabric-router:latest /w/vlanprobe.test -test.v +``` + +`VLANPROBE_REPORT` writes every observation as JSON. Two local runs on kernel 7.3.3 produced identical outcomes. CI's root unit-test job on kernel 7.0.0 recorded the same tag representation at every hook and on every wire; the bond spread flows over its members differently. Two delivery counts differed in CI, and the Q4 table notes them. + +### Q1: where XDP can attach + +| Interface | Kernel reports native XDP | Native attach | Generic attach | Device-bound program (kfunc) | +| ------------------- | ------------------------- | ------------- | -------------- | ---------------------------- | +| veth (plain NIC) | yes | ok | ok | native ok, generic `EINVAL` | +| 802.3ad bond master | yes | ok | ok | native ok, generic `EINVAL` | +| bond member | yes | ok | ok | native ok, generic `EINVAL` | +| VLAN on a veth | no | `EOPNOTSUPP` | ok | load fails with `EOPNOTSUPP` | +| VLAN on a bond | no | `EOPNOTSUPP` | ok | load fails with `EOPNOTSUPP` | + +`edgepreflight.InterfaceSupportsNativeXDP`, the check `xdpattach` runs before a native attach, reports both VLAN netdevices as unsupported. **Source:** `checkNativeXDPSupport` (`internal/plumbing/ebpf/xdpattach/gate.go`) then refuses the whole attach. + +### Q2: where the tag is at each hook + +Every row below delivered 10 of 10 datagrams on VLAN 101, on VLAN 202 and untagged, with an observing program at XDP on the physical interfaces returning `XDP_PASS`. So `XDP_PASS` always kept enough context for the kernel to deliver to the right VLAN netdevice. + +| Sender `tx-vlan-offload` | XDP on the physical interface, native or generic | tc ingress on the physical interface or bond | tc ingress on the VLAN netdevice | +| ------------------------ | ------------------------------------------------ | -------------------------------------------- | -------------------------------- | +| on | Frame untagged, no tag in packet data | Tag in `skb->vlan_tci` | No tag | +| off | Tag in packet data (EtherType `0x8100`) | Tag in `skb->vlan_tci` | No tag | + +- On veth, the receiver's `rx-vlan-offload` setting changed nothing. The sender's transmit offload decided where the tag was: with it on, the tag crosses the veth as skb metadata. A hardware NIC with receive VLAN offload strips the tag into its descriptor instead. That is the analogous case, but it was not measured here (environment H). +- The tc rows did not depend on either setting. The kernel moves an in-frame tag into metadata before tc ingress runs on the physical interface or bond, and pops it before the VLAN netdevice's tc ingress. +- Generic and native XDP saw the same representation. + +### Q3: two VLANs on one parent + +With the tag in metadata (sender offload on), XDP on the shared parent sees frames for VLAN 101 and VLAN 202 with identical, untagged packet data. **Packet data alone cannot tell the two VLANs apart.** A device-bound program calling `bpf_xdp_metadata_rx_vlan_tag` read VID 101 and VID 202 correctly on a veth and on a bond member in native mode, and both VLANs still delivered 10 of 10. That kfunc is the only XDP-side discriminator measured. It requires native mode, a driver that implements it (veth does; hardware drivers were not measured) and a program bound to one device. A program shared through the XDP dispatcher across several interfaces is not bound to one device. With the tag in packet data (sender offload off), the VID is readable from the frame. + +### Q4: `bpf_fib_lookup` and XDP redirect to a VLAN + +A route in B points through B's fabric VLAN (`parent.202`) toward A. A probe on B's ingress interface `bs0` looks the destination up and redirects. The neighbour is warm. + +| Program | Redirect target | Delivered at A on 7.3.3, both B `tx-vlan-offload` settings | What reached A's wire, on 7.3.3 and 7.0.0 | +| ----------------- | ------------------------- | ---------------------------------------------------------- | ----------------------------------------- | +| XDP, native | FIB result (`parent.202`) | 0/10 | nothing | +| XDP, generic | FIB result (`parent.202`) | 10/10 | 802.1Q VID 202 | +| XDP, native | the parent | 10/10 | untagged | +| XDP, generic | the parent | 10/10 | untagged | +| tc `bpf_redirect` | FIB result (`parent.202`) | 10/10 | 802.1Q VID 202 | +| tc `bpf_redirect` | the parent | 10/10 | untagged | + +- `bpf_fib_lookup` returned success with the VLAN netdevice's ifindex, on veth and bond parents, from XDP and from tc. +- A native XDP redirect to that ifindex drops every frame: a VLAN netdevice has no `ndo_xdp_xmit`. +- A generic redirect transmits through the VLAN netdevice and is tagged. +- A redirect to the parent, in either mode, puts the frame on the wire untagged. Nothing inserts the tag on its behalf. + +The rows are the same on a single veth and on a bond. + +The answer rests on the last column, the frames A's tc probe saw on its physical interfaces. Both kernels agree on it. On the CI kernel, A's UDP listener received none of these redirected datagrams in any row, including the untagged redirects to the parent, and no drop or error counter rose in A's namespace. That points at the probe's receive side on that runner, not at tagging, and it is left unexplained. One run in CI also delivered 9 of 10 on VLAN 101 for the bond, native, offload-on row. + +### Q5: tc redirect to a VLAN + +`bpf_redirect` from tc to the VLAN netdevice put all 10 datagrams on the wire with VID 202, and A received all 10 on kernel 7.3.3. That held on veth and bond parents, with B's transmit VLAN offload on and off. + +### Invalid VLAN netdevices the kernel accepts + +**Measured**, for [contract section 5](../../designs/vlan-transport/contract.md#validation): the kernel creates a VLAN with ID 0, an 802.1ad VLAN, and an 802.1Q VLAN stacked on an 802.1ad VLAN. It refuses ID 4095 (`ERANGE`). So infrastructure can hand Galactic every invalid case except ID 4095, and Galactic's own validation ([#1404](https://github.com/datum-cloud/galactic/issues/1404)) has to reject them. + +### Probe-rig artifact + +A veth sender with transmit checksum offload hands the receiver a frame whose UDP checksum is still partial. A native XDP redirect forwards those bytes as they are, and the far end counts `Udp.InCsumErrors`. The rig turns the sender's checksum offload off. The lab has the same exposure wherever a veth peer's traffic is natively redirected, which the #1405 lab pass should account for. + +### Finding: a single 802.1Q tag never reaches tc ingress in the frame + +**Probe-measured.** Every frame carrying one 802.1Q tag reached tc ingress on the physical interface or bond with the tag in `skb->vlan_tci`. The sender's offload setting made no difference, because the kernel moves an in-frame tag into metadata before tc runs. The worksheet's [P6](../../designs/vlan-transport/packet-paths.md#p6-tenant-srv6-ingress-fabric-to-tenant) and the contract's section 10 say a tag left in packet data reaches `usid_ingress`'s EtherType check. That did not happen for a single 802.1Q tag on this kernel. It remains possible for frames the kernel does not untag, such as an 802.1ad outer tag or a second tag. Hardware receive paths were not measured. + +## Expected result of each path on `main` + +**Source-inferred**, from the code at `352fe3a2` combined with the probe results above. "Tag in metadata" is what receive VLAN offload produces, and what a veth produces with the sender's transmit offload on. "Logical selection" names the VLAN netdevice, as the contract requires. "Parent selection" names its parent, the misconfiguration the [contract's section 4](../../designs/vlan-transport/contract.md#failure-this-design-accepts) accepts. + +| Path | Rows | Expected on a tagged side | Owner | +| -------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | +| P1 gateway ingress | V01 | **Logical selection:** `edge_lb` does not attach (Q1), so no VIP traffic is claimed. **Parent selection, tag in metadata:** claimed, because the frame looks untagged. With a tagged fabric, `bpf_fib_lookup` then returns the fabric VLAN netdevice and the native redirect drops every packet (Q4). **Tag in data:** not claimed (`edgedsr.c:1306`); the kernel handles it. | [#1403](https://github.com/datum-cloud/galactic/issues/1403) | +| P2 same-node delivery | V10 | As Q6: unreachable with logical selection. With parent selection, the tag survives `XDP_PASS` in metadata and `usid_ingress` pops it. | [#1403](https://github.com/datum-cloud/galactic/issues/1403) | +| P3 DSR return | V02 | **Backend node:** `usid_egress` redirects to the `public_uplink_table` row, which `srv6.ResolvePublicUplink` fills from the first interface `attach.ResolveInterfaces` lists. With the fabric VLAN named, that is the VLAN netdevice, and a tc redirect to it is tagged (Q5). **Edge:** `edge_return` does not attach to a fabric VLAN (Q1). With parent selection it claims the reply, `bpf_fib_lookup` returns the public VLAN netdevice when the public side is tagged, and the native redirect drops it (Q4). | [#1403](https://github.com/datum-cloud/galactic/issues/1403) | +| P4, P5 NAT66 and NAT64 | V03, V04 | `nat_ingress` does not attach to a VLAN netdevice (Q1). With parent selection: claimed when the tag is in metadata. A FIB result naming the other side's VLAN is dropped by the native redirect (Q4). A neighbour miss returns `XDP_PASS`, and the tag survives that (Q2), so a cold neighbour may succeed through the kernel where a warm one fails. That inverts V07's expectation. | [#1403](https://github.com/datum-cloud/galactic/issues/1403) | +| P6 tenant SRv6 ingress | V05 | `usid_ingress` is tc on the VLAN netdevice and on the bond's members (`expandBondSlaves`). The members see the tag in metadata, and the tag is popped after decapsulation (`usid.c:4479`). Expected to deliver. | [#1402](https://github.com/datum-cloud/galactic/issues/1402) | +| P7 tenant SRv6 egress | V05 | `EgressRouteTable.Register` stores the route's interface, the VLAN netdevice, and a tc redirect to it is tagged (Q5). Expected to deliver. | [#1402](https://github.com/datum-cloud/galactic/issues/1402) | +| P8 control plane | V06 | Kernel only: BGP, ND and ARP run on the VLAN netdevice. Expected to work. | [#1405](https://github.com/datum-cloud/galactic/issues/1405) | +| P9 unrelated trunk traffic | V11–V15 | With the tag in metadata, an XDP program on a parent sees every VLAN's frames as untagged (Q3). With parent selection, `edge_lb` and `nat_ingress` would claim VIP- or shard-addressed traffic arriving on any VLAN of that parent. `usid_ingress` on the members likewise does not compare `skb->vlan_tci` with the side's ID before claiming a local SID. | [#1402](https://github.com/datum-cloud/galactic/issues/1402), [#1403](https://github.com/datum-cloud/galactic/issues/1403) | + +The untagged cell C1 is today's lab configuration, which `task verify` exercises. It is not re-measured here. + +## Lab rows + +Every L row of the [acceptance matrix](../../designs/vlan-transport/acceptance.md) is **deferred to #1405 end-of-epic lab pass**. None is reported as passed. That includes the untagged baselines that the [contract's section 8](../../designs/vlan-transport/contract.md#measurement-and-recovery-targets) assigned to #1401 for the throughput, latency and recovery targets: V09, and V21 to V28 in C1. The tooling below runs each row. + +| Rows | Cells | Command, from `deploy/containerlab` | +| -------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| V01–V07 | C1–C4, C6 | `task baseline:vlan-transport CELL= SELECT=logical\|parent OUT=` | +| V01–V05, offload off | C1–C4 | `task variant:vlan-transport:offload STATE=off`, then the row above | +| Other VLAN IDs | C4 | the same with `PUB_VID=1234 FAB_VID=3456` | +| V10 | C2 on dfw-worker3 | `VT_SITE=dfw-worker3 scripts/vlan-transport.sh apply C2