Skip to content

parse: auto-detect sh ip bgp text dumps and support --mrt-type for RIB/updates MRT output #142

Description

@digizeph

Motivation

PCH publishes daily BGP routing snapshots from 100+ route collectors as Cisco sh ip bgp text format (not MRT). These contain valuable routing data that is currently inaccessible to Monocle users without manual conversion.

Example file: https://downloads.pch.net/files/Routing_Data/IPv4_daily_snapshots/2026/07/route-collector.bom2.pch.net/route-collector.bom2.pch.net-ipv4_bgp_routes.2026.07.01.gz

Design

Integrate text dump support into the existing monocle parse command with format auto-detection, rather than a separate subcommand. All existing parse features (filters, field selection, ordering, output formats, MRT export) are reused without changes.

input file → peek first bytes
  ├─ "BGP table version…" → text dump parser → BgpElem stream ─┐
  └─ MRT binary           → BgpkitParser     → BgpElem stream ─┤
                                                                └→ [existing: filters, format, MRT export]

Format auto-detection

Peek at the first ~100 bytes. If printable ASCII containing "BGP table" or "Next Hop" → text dump. Otherwise → existing MRT path.

New --mrt-type flag

Add a --mrt-type flag to the parse command to control which MRT subtype is written:

  • rib (default): encode as TABLE_DUMP_V2 using MrtRibEncoder — produces a peer-index-table + per-prefix RIB entries. Appropriate for full table snapshots (text dumps, RIB MRT files).
  • updates: encode as BGP4MP updates using MrtUpdatesEncoder — produces individual update messages. Appropriate for update/withdrawal streams.

This flag is particularly important for text dumps since the output should be a clean RIB dump (single peer, one entry per prefix-path), not individual BGP4MP messages.

Text dump format

Cisco sh ip bgp fixed-width column format:

BGP table version is N, local router ID is X.X.X.X, vrf id 0
Default local pref 100, local AS NNNN
...
    Network          Next Hop            Metric LocPrf Weight Path
 *> 1.0.0.0/24       103.77.108.118           0             0 13335 i
 *=                   103.77.108.11            0             0 13335 i

Header provides peer_ip (router ID) and peer_asn (local AS). Single peer in the index table. Route entries use fixed-width columns with continuation lines for multi-path prefixes. Status flags (*>, *=, * ) are captured in output.

Output formats

  • JSON: standard BgpElem JSON (serde, identical to existing MRT parse output)
  • PSV / Table / Markdown: existing format_elem() pipeline
  • MRT: --mrt-type ribMrtRibEncoder (TABLE_DUMP_V2), --mrt-type updatesMrtUpdatesEncoder (BGP4MP)

Scope

  • v1: Cisco sh ip bgp format (the format PCH publishes)
  • Multi-vendor (Juniper, Nokia, etc.) deferred to v2

Implementation

  • New module: src/lens/parse/text_dump.rs — header extraction, fixed-width column parser, BgpElem constructor
  • Modify: src/lens/parse/mod.rs — add is_text_dump() detector, parse_text_dump() entry point
  • Modify: src/bin/commands/parse.rs — peek + branch, add --mrt-type flag
  • Modify: src/bin/monocle.rs — add MrtType to OutputFormat or as separate CLI flag
  • Tests: round-trip text → BgpElem → JSON, text → BgpElem → MRT RIB → re-parse

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions