Skip to content

Implement 'when' statement evaluation #443

Description

@steiler

Background

YANG when statements (RFC 7950 §7.21.5) attach a conditional xpath expression to a node — the node only exists in the data tree if the expression evaluates to true. Neither the schema-server nor the data-server currently implement when evaluation.

What needs to happen

schema-server (prerequisite)

The schema-server must:

  1. Serialise the when xpath string from yang.Entry.When.Name into the schema proto so data-server can retrieve it
  2. Apply import-alias prefix normalisation to the xpath before serialising it — identical to the rewrite already implemented for must statements. When a module imports an identity module under a local alias different from the declared prefix, quoted literals like 'alias-id:BGP' must be rewritten to 'declared-prefix:BGP'. The normalizeXPathLiterals helper in pkg/schema/leaf.go is directly reusable for this. See Normalise import-alias prefixes in 'when' xpath expressions schema-server#240 for details on this specific requirement.

data-server

The data-server must:

  1. Retrieve the normalised when xpath string from the schema proto
  2. Evaluate it during validation / tree operations against the current data tree context
  3. Exclude nodes whose when condition evaluates to false (node non-existence semantics per RFC 7950)

Notes

  • when evaluation context follows RFC 7950 §7.21.5: the context node is the node carrying the when, the accessible tree is the full data tree
  • when on a uses/augment node has slightly different context rules (§7.21.5 "context node" note) — worth scoping carefully
  • The xpath evaluator already used for must should be reusable here
  • Prefix normalisation in the schema-server is a hard prerequisite for correct evaluation of identity-valued comparisons in when expressions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions