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).
Last modified November 20, 2026: docs: modernize documentation site (74dd3de)