TED and CSPF

TED model, BGP-LS ingestion, path computation, and TED readiness.

User-facing behavior is described in Traffic Engineering Database and Dynamic Paths.

TED model

table.LsTED (pkg/table/ted.go) stores LsNode values keyed by IGP router ID. Each node contains prefixes and Prefix-SIDs, the SRGB, links, SRv6 SIDs, SR-Algorithm information, and advertised FADs.

  • A dual-stack node is represented by a single node.
  • A link is keyed by its local and remote router IDs, the endpoint identifier for each side, and sorted multi-topology IDs. An endpoint identifier is the interface ID when present; otherwise, it is the IPv4 address, falling back to the IPv6 address.
  • A link NLRI with both IPv4 and IPv6 addresses creates one LsLink. Separate NLRIs create separate links unless their keys match, in which case the later NLRI replaces the earlier one without merging attributes.
  • Link endpoints carry IPv4 and IPv6 addresses independently. Without multi-topology IDs, CSPF uses links with an address in the plane’s family; unnumbered links are usable in either family.
  • With multi-topology IDs, IPv4 requires MT-ID 0 and an IPv4 address. IPv6 accepts MT-ID 2 without an address check, or MT-ID 0 with an IPv6 address unless an MT-ID 2 link to the same neighbor exists.
  • Path computation runs on an underlay plane (pkg/table/plane.go), defined by an address family, a data plane, and an IGP algorithm. IPv4/SR-MPLS, IPv6/SR-MPLS, and IPv6/SRv6 are valid; IPv4/SRv6 is not. Algorithm 0 is the default SPF algorithm; 128-255 select a Flexible Algorithm (RFC 9350); 1-127 are rejected.
  • LsTED.FlexAlgoDefinition(algo) returns the winning FAD for an algorithm across the TED. The election rule is in FAD election.

Ingestion from GoBGP

internal/gobgp connects to GoBGP over plaintext gRPC.

  1. Initial sync: ListPath retrieves the global BGP-LS table and converts it into TEDElem values (nodes, links, prefixes, and SRv6 SIDs).
  2. An unfiltered Adj-RIB-In watch acts only as a trigger. After 5 seconds without an event, a full ListPath is performed.
  3. If the watch stream breaks, the client retries every 10 seconds and refetches the table after the watch is re-established. Retries during initial watch setup do not trigger a refetch.

Server.syncTEDLoop (pkg/server/server.go) builds a new LsTED from each snapshot and replaces the server’s pointer. An existing LsTED is never mutated.

  • Elements belonging to an AS other than ted.asn are dropped. A link is dropped if either endpoint belongs to another AS.
  • A BGP-LS destination (one NLRI) must contain exactly one path, regardless of the NLRI type. Otherwise, conversion fails.
  • A conversion error aborts the entire snapshot, leaving the previous TED unchanged.
  • NLRIs without a BGP-LS attribute are skipped.
  • Information the TED does not store is listed in Not supported.
  • Unknown FAD sub-TLVs and the FAD Unsupported sub-TLV are detected but not stored; FlexAlgoDefinition.Unsupported records why a FAD cannot be used.

CSPF

cspf.Compute (pkg/cspf/cspf.go) is the single entry point. A request specifies the source and destination router IDs, plane, metric, and optional loose waypoints; the function runs Dijkstra and returns one node SID per hop.

  • Node SID selection:
    • SR-MPLS: the first Prefix-SID matching the plane’s algorithm and address family.
    • SRv6: the first SRv6 SID matching the plane’s algorithm.
    • “First” follows GoBGP’s element order.
  • For algorithm 0, computation fails if any usable link leaving a settled node lacks the requested metric, or if its neighbor has no node SID. These checks apply even when the link or neighbor is not on the resulting path. A TE, delay, or min-delay value of 0 is treated as missing.
  • Equal-cost paths may be resolved nondeterministically: the next node is selected by iterating a Go map, and a predecessor is replaced only when a strictly lower cost is found.

Flex-Algo extension

Flex-Algo (RFC 9350) uses a computation profile that determines the metric, node eligibility, and link eligibility from the request’s plane and the winning FAD.

  • Metric selection: algorithm 0 uses the request’s metric; Flex-Algo uses the metric selected by the FAD’s Metric-Type (IGP, minimum delay, or TE). A Flex-Algo request must not specify a metric.
  • Node eligibility: algorithm 0 does not prune nodes. Flex-Algo requires the node to advertise the algorithm in the SR-Algorithm TLV (RFC 9350 §11.1) and have a node SID for the requested data plane. See Flexible Algorithm.
  • FAD validation: ResolveMetricType rejects the winning FAD when FlexAlgoDefinition.Unsupported is set. See FAD parsing and validation.
  • Link eligibility: algorithm 0 uses the normal plane-specific link checks. Flex-Algo applies the FAD’s constraints to LsLink.FlexAlgoAttributes. A link that lacks the required metric or has a malformed ASLA (LsLink.ASLAMalformed) is pruned rather than causing a computation error (RFC 9350 §13).
  • Metric source: LsLink.FlexAlgoMetric reads the IGP metric from the top-level attribute and TE and min-delay from FlexAlgoAttributes. The selection rules are in Link attributes.

FAD parsing and validation

GoBGP’s API omits unknown FAD sub-TLVs and the FAD Unsupported sub-TLV. internal/gobgp/fad.go therefore parses FAD TLVs (1039) from the raw BGP-LS attribute (PattrsBinary) when converting a Node NLRI, and sets FlexAlgoDefinition.Unsupported for the conditions listed in Flexible Algorithm.

  • Multiple FAD TLVs for one algorithm are detected in both the API results and the raw parse. GoBGP returns all FADs, but a per-algorithm map would retain only one.
  • If the raw FAD content cannot be found or parsed, the definition is marked unverifiable.

IS-IS may split a FAD across LSPs, requiring Exclude-SRLG union and LSP-order-dependent field selection (RFC 9350 §6). OSPF uses the first applicable FAD (§5.2). BGP-LS carries the originating protocol (Node NLRI Protocol-ID, RFC 9552 §5.2) but not the LSP order. Pola marks an algorithm unsupported when a node advertises multiple FAD TLVs for it.

ASLA parsing

GoBGP v4 does not decode ASLA (TLV 1122), so internal/gobgp requests raw path attributes (EnableAttributeBinary) and parses the BGP-LS attribute in asla.go. Malformed ASLA marks the link without failing the snapshot. A delay or min-delay with the A bit set (RFC 8571 §2.1–§2.2) is stored as not advertised. ASLA selection is implemented in pkg/table/linkattr.go; the rules are in Link attributes.

TED readiness and recomputation

  • With TED enabled, NewPCE initializes an empty LsTED that is not ready; with TED disabled, the TED is nil.
  • Each tedElemsChan message contains a complete snapshot. applyTEDSnapshot replaces the TED, marks it ready, and reports whether this is the first snapshot. An empty first snapshot also marks it ready.
  • Each Session uses a tedSource (Server.tedState) that returns the TED and readiness under one lock. Each computation reads both once. Session.ted is used only when no source is set.
  • handleSRPolicyWithPLSPID handles a report in this order:
    • LSP removal, a nil TED, or an explicit path: skip path computation. Remove the policy for an LSP removal; otherwise, register the report unchanged.
    • TED not ready: register the report and defer it in pendingRecompute. For each PLSP-ID, pendingRecompute keeps one report: the one with the greatest LSPObject.LSPID (distinct from the PLSP-ID), or the latest report when those LSP-IDs are equal.
    • Otherwise: compute the path and send PCUpd. Once the PCUpd is successfully sent, register the report with the computed path. If sending fails, register the report unchanged.
  • After the first snapshot, syncTEDLoop calls recomputeSessions. Each session runs recomputePending in its own goroutine, preventing a slow peer from blocking others. Deferred reports are reprocessed in PLSP-ID order by handleSRPolicyWithPLSPID.
  • reportMu serializes PCRpt handling with recomputePending, so each report is either computed against a ready TED or deferred for recomputation, whichever takes the lock first.
  • DeleteSRPolicy drops the deferred report for that PLSP-ID.
  • gRPC handlers read the current TED through s.pce.TED() without waiting for TED readiness.

Later snapshots do not trigger recomputation; see the limitation in Dynamic Paths.

Last modified December 3, 2026: feat: add ASLA (34bd43d)