This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Developer Guide

Architecture, internals, testing, and contribution guidance.

Contribution rules and Make targets are in CONTRIBUTING.md.

See pkg.go.dev for the public Go API.

1 - Architecture

Processes, packages, and data flow in Pola PCE.

Packages

PackageRole
cmd/poladThe daemon: loads configuration and starts the PCEP listener, gRPC server, and GoBGP monitor.
cmd/polaThe CLI client of the gRPC API.
api/pola/v1Protocol Buffers definitions and generated code for PCEService.
pkg/serverPCEP listener, one session per peer address, and the PCEService implementation.
pkg/packet/pcepPCEP message, object, and TLV encoding and decoding. See PCEP Library.
pkg/tableTED, SR Policy and segment models, SID validation, and underlay planes.
pkg/cspfShortest-path computation over the TED.
pkg/loggerStructured logging.
internal/gobgpReads BGP-LS from GoBGP and converts it into TED elements.
internal/configParses and validates polad.yaml.

Data flow

                                                      pola CLI / gRPC clients
                                                                 |
                                                                 v
                    +-- PCInitiate / PCUpd ----------------- APIServer
                    |                                            ^
                    v                                            |
PCC <--PCEP--> Session (one per peer)                            | reads current TED
                    ^                                            |
                    | reads current TED                          |
                    |                                            |
                    +---------------------------------------- Server (holds current TED)
                                                                 ^
                                      syncTEDLoop replaces the current TED with a new LsTED
                                                                 |
GoBGP --(ListPath, triggered by watch)--> internal/gobgp --> []TEDElem
  • Each accepted TCP connection creates a Session. A duplicate connection from the same peer address is rejected with PCErr 9/1.
  • Each TED update replaces the current TED with a new LsTED rather than modifying the existing one. Sessions read the current TED and its readiness on each use. See TED and CSPF.
  • SR Policy state is held in memory per session and is not persisted.
  • The gRPC handlers validate requests and pass them to the session, which sends PCInitiate or PCUpd. The handlers return once the message is written.

2 - PCEP Library

The Go PCEP library in pkg/packet/pcep.

github.com/nttcom/pola/pkg/packet/pcep is a Go library for encoding and decoding PCEP messages. It has no third-party dependencies. The PCInitiate and PCUpd constructors use Pola’s table.SRPolicy type (pkg/table). The API reference is available on pkg.go.dev.

Layout

FileContents
message.goCommon header, PCEP messages (Open, Keepalive, PCErr, Close, PCRpt, PCInitiate, PCUpd), and their constructors.
object.goObjects (OPEN, SRP, LSP, ERO, ASSOCIATION, VENDOR-INFORMATION, and others), timer helpers, and PCC type detection.
tlv.goTLVs, including typed capability TLVs and unknown TLVs.
tlv_common.goLength, padding, and address helpers.
pcep_util.goByte-slice and bit-manipulation helpers.
capability.goCapabilityInterface, the capabilities Pola advertises (DefaultCapabilities), capability negotiation helpers, and FlattenCapabilities.
vendor.goEnterprise numbers (Cisco, Huawei, Juniper) and their names.
reference.goThe Reference type that maps code points to their RFC or draft.

Behavior

  • Capability TLVs in received Open messages are decoded into typed values. Unknown TLVs are preserved as unknown capabilities; other known TLVs are discarded.
  • DeterminePccType identifies legacy Cisco (0x14) and Juniper (0xffe1) peers from ASSOC-TYPE-LIST. Juniper takes precedence if both are present in the same TLV; all other cases are classified as standard (RFCCompliant).
  • NewPCInitiateMessage selects color and preference encoding based on VendorSpecific (PCC type) and SRPolicyAssociation (whether the SR Policy Association was negotiated). pkg/server sets these options as described in What Pola sends.
  • The COLOR TLV is sent only if both Pola and the peer advertise color capability and Pola does not advertise SR Policy Association capability (RFC 9863 Sections 1 and 2). It is never sent with DefaultCapabilities.
  • Vendor-specific ASSOCIATION types are accepted in received messages, but only the standard SR Policy Association is advertised.

3 - Session State Machine

How polad establishes and maintains a PCEP session.

The session logic is implemented in negotiateOpen and the message loop in pkg/server/session.go; tests are in pkg/server/session_internal_test.go. Operator-facing settings are in PCEP Sessions.

States are derived, not stored

RFC 5440 Appendix A does not list an Open event in KeepWait, although section 6.2 allows a peer to resend its Open after a PCErr 1/4. Following the state table literally could therefore terminate a valid negotiation. Pola instead tracks two conditions and derives the state name from them:

  • RemoteOK: the peer’s Open has been accepted.
  • LocalOK: the peer has acknowledged Pola’s current Open with a Keepalive.
RemoteOKLocalOKPeer Open rejectedState
truetrue-Up
truefalse-KeepWait
falsefalseyesKeepWait
falsefalsenoOpenWait
falsetrue-OpenWait

During establishment, the derived state determines the initialization timer (1 minute) and the error sent on expiry (PCErr 1/2 in OpenWait or 1/7 in KeepWait).

Establishment

  • Pola sends its Open when the TCP connection is accepted, then reads messages.
  • Before the peer’s Open, a Keepalive or PCErr is answered with PCErr 1/1, and the attempt ends. Any other unexpected message type during establishment has the same result.
  • A malformed Open is answered with PCErr 1/1.
  • An Open is unacceptable if its DeadTimer does not exceed its Keepalive, unless either value is 0, or if its Keepalive is outside the inclusive range minKeepalive to maxKeepalive:
    • With allowNegotiation, Pola sends PCErr 1/4 with an OPEN object proposing acceptable values: the peer’s Session-ID, the Keepalive clamped into the range, and a DeadTimer of four times that (0 if that cannot exceed the Keepalive).
    • Without it, Pola sends PCErr 1/3 and closes.
    • If the second received Open is still unacceptable, Pola sends PCErr 1/5 and closes. The rejection counter counts Opens received, not proposals sent.
  • An accepted Open sets RemoteOK and starts Keepalives, the first sent immediately.
  • Once RemoteOK is set, another Open is answered with PCErr 1/1 and ends the attempt; the accepted parameters are kept.
  • After the peer’s Open, if the peer answers Pola’s Open with PCErr 1/4, Pola adopts the proposal when it passes the same checks (including the local Keepalive range), resends its Open, and resets LocalOK. Pola responds with PCErr 1/6 if the proposal is unacceptable, contains no OPEN object, or is the second PCErr 1/4 received during establishment.
  • Any other well-formed PCErr during establishment ends the attempt without a reply. A malformed PCErr is answered with PCErr 1/1.
  • Pola checks the capabilities in the peer’s Open. An empty PATH-SETUP-TYPE-CAPABILITY list results in PCErr 10/11, no common path setup type results in PCErr 21/2, and an unsupported SRv6 MSD type results in PCErr 1/1.

Session establishment failures are logged at debug level with the failure reason.

Established sessions

  • An Open received while Up is answered with PCErr 1/1; the session continues.
  • Unrecognized message types and recognized but unsupported messages, such as PCReq, are answered with PCErr 2/0. More than 5 such messages within a minute, including PCRep, PCUpd, and PCInitiate from the PCC, close the session (Close reason 5).
  • PCNtf is counted and otherwise ignored.
  • A PCRpt with the S flag marks LSP-DB synchronization as ongoing; a PCRpt with PLSP-ID 0 and the S flag clear finishes it.
  • A PCRpt with an unsupported ASSOCIATION type is answered with PCErr 26/1, and Pola still processes the PCRpt.
  • A malformed PCRpt, PCErr, or Close ends the session without a reply.

Timers

The advertised values and the Keepalive interval are described in PCEP Sessions.

  • effectiveKeepalive computes the interval. If the advertised Keepalive is 0, Pola sends no Keepalives, regardless of the peer’s DeadTimer (RFC 5440 section 7.3).
  • The read deadline of an established session is the peer’s advertised DeadTimer, disabled if the peer’s Keepalive or DeadTimer is 0. On expiry, Pola sends Close (reason 2, DeadTimer expired).

4 - 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.

5 - Testing

Unit tests, coverage checks, scenario tests, and API changes.

The contribution workflow and Make targets are documented in CONTRIBUTING.md.

Unit tests

Add unit tests to cover all reachable lines, and run make test-examples for the separate examples module.

make test-coverage-diff checks changed-line coverage against DIFF_BASE and fails below DIFF_COVER_MIN (default 90%). CI enforces the same threshold on pull requests.

make ci runs the local checks. CI runs these checks except make check-proto, and also runs the following CI-only checks:

  • make test-race
  • make vuln
  • editorconfig-checker
  • CodeQL

The documentation build runs for changes under docs/.

Scenario tests

Scenario tests run polad built from the source tree against emulated routers in Containerlab. Their topologies are under test/scenario/, separate from but similar to the example labs.

Run them with make test-scenario. make test-scenario-parallel runs four workers; tests that share a topology run on the same worker.

They require Docker, Containerlab, uv, and images for XRd and vJunos. Pola does not distribute these images. Setup and options are documented in test/README.md.

Changing the gRPC API

Edit api/pola/v1/pola.proto, run make proto, and verify that make check-proto passes. CI does not run this check.

Update the gRPC API and pola references in the same pull request.

6 - Documentation

How this site is organized, built, and kept in sync with the code.

This site documents the develop branch, not the latest release. It is built with Hugo and Docsy from docs/ and published at /pola/ on GitHub Pages.

make docs-setup   # check tools, then npm ci
make docs-serve   # preview at http://localhost:1313/
make docs-build   # production build with the /pola/ base path, then the link check

Organization

SectionAudience and content
User Guide (docs/user/)Operators: installation, provisioning, operation, and troubleshooting.
Reference (docs/reference/)Lookup material: CLI commands, configuration, gRPC API, and supported standards.
Developer Guide (docs/developer/)Contributors and library users: internals, tests, and documentation.
About (docs/about/)Presentations, license, and credits.

Keep each topic in one canonical source; other pages and READMEs link to it instead of repeating it.

TopicCanonical source
Example labsexamples/containerlab/*/README.md
Go gRPC client examplesexamples/grpc/go/README.md
Scenario teststest/README.md
Contribution rules, Make targets, image buildsCONTRIBUTING.md
Site dependencies and publishingdocs/README.md
Protocol Buffers APIapi/pola/v1/pola.proto
Go API referencepkg.go.dev

Writing rules

  • Write pages in English Markdown under docs/content/en/. The front matter title is the page heading; start body headings at ##.
  • Link to pages with the ref shortcode and an absolute content path, such as {{< ref "/docs/user/dynamic-paths" >}}. A broken ref fails the build.
  • Link to repository files with repo-url, adding "tree" for directories. Do not hard-code branch URLs; repo-url uses github_branch in hugo.yaml.
  • Use static-url for files under docs/static/. The docs/schemas/ directory is mounted at schemas/; for example, {{< static-url "schemas/server/polad_config.json" >}}.
  • Do not write root-relative links such as /docs/...; they lose the /pola/ base path. npm run check:links reports them.
  • Describe current behavior and limitations accurately; do not document planned behavior as implemented.
  • Base example output on actual program output, and use documentation prefixes (192.0.2.0/24 from RFC 5737, 2001:db8::/32 from RFC 3849).

Keeping docs in sync

Update the documentation in the same pull request as behavior changes, including fixes to documented limitations.