BgpParser

Recursive, template-aware parser for BGP blocks.

  • Location: parsers/bgp_parser.py
  • Uses a two-pass approach recursive approach to find instances of peer-session and peer-policy that have been inherited in neighbors to write out expanded formats.
  • Pass one:
    • Collect template peer-session and template peer-policy into in-memory dicts.
  • Pass two:
    • Expand every neighbor … inherit … by inlining the stored template commands.
  • Splits between global neighbor commands and per-AF sections.
  • Emits a clean, expanded neighbor-only view (no leftover templates).

  • Challenge: Understanding BGP's hierarchial and inheritance-rich config nature to use a more complex recursive parser that goes beyond line-by-line parsing. Also needing to expand upon templates in the expanded formats when outputting to CLI or JSON.