Skip to content

BGP

Query RouteViews and RIPE RIS MRT archives (RIB snapshots and BGP updates) as SQL rows, with AS-path and community helpers

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/bgp/index.md to help me query BGP with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Decode the built-in inline TABLE_DUMP_V2 RIB fixture and count routes per origin AS.

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT origin_asn, count(*) AS routes
FROM bgp.main.read_rib(from_hex('68608200000d00010000003b000000000000000302c0000201c00002010000fde902c6336407c63364070000fdea030000000020010db80000000000000000000000010000fde968608200000d000400000079000000003020010db8abcd00010002686082000064800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110e02030000fde90000fbf40000fc58400101004005040000006480040400000000c0200c0000fde9000000070000000968608200000d0002000000af0000000118cb007100020001686082000041800e0d00010104c63364070018cb0071400304c6336407c0110e02030000fdea0000fc010000fc00400101004005040000006480040400000000c00804fdea00c80000686082000054800e0d00010104c00002010018cb0071400304c0000201c0111202040000fde90000fbf40000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002'))
GROUP BY origin_asn
ORDER BY routes DESC, origin_asn;
Result
origin_asn routes
64,512 2
64,600 1

Quick start

Choose where to run BGP, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'bgp' AS bgp (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-bgp'
);

3. Run a query

query.sql
SELECT origin_asn, count(*) AS routes
FROM bgp.main.read_rib(from_hex('68608200000d00010000003b000000000000000302c0000201c00002010000fde902c6336407c63364070000fdea030000000020010db80000000000000000000000010000fde968608200000d000400000079000000003020010db8abcd00010002686082000064800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110e02030000fde90000fbf40000fc58400101004005040000006480040400000000c0200c0000fde9000000070000000968608200000d0002000000af0000000118cb007100020001686082000041800e0d00010104c63364070018cb0071400304c6336407c0110e02030000fdea0000fc010000fc00400101004005040000006480040400000000c00804fdea00c80000686082000054800e0d00010104c00002010018cb0071400304c0000201c0111202040000fde90000fbf40000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002'))
GROUP BY origin_asn
ORDER BY routes DESC, origin_asn;
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'bgp' AS bgp (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Decode MRT routing dumps (BGP4MP updates + TABLE_DUMP_V2 RIB snapshots) into SQL rows, reusing the core INET type for prefixes and peer IPs.

Catalog

Everything bgp exposes once attached — read straight from the worker's released build.

bgp 1 schema
main 1 view · 9 functions

MRT decode (read_rib / read_updates / peers) plus AS-path and community helper functions.

Schema examples (12)
Examples (12)

Count the AS hops in an inline AS-path literal.

SELECT bgp.main.path_length([7018, 174, 13335]) AS hops;

Get the origin AS (last ASN) of an inline AS-path literal.

SELECT bgp.main.origin_asn([7018, 174, 13335]) AS origin;

Count the prepended (padded) ASNs in an inline AS-path literal.

SELECT bgp.main.as_path_prepends([7018, 174, 174, 13335]) AS prepends;

Test whether an inline AS path traverses a given ASN.

SELECT bgp.main.path_contains([7018, 174, 13335], 174) AS via_174;
8 more examples

Split a standard community string into its ASN and value parts.

SELECT bgp.main.community_parse('65001:100') AS parts;

Classify whether a community string is an RFC 8092 large community.

SELECT bgp.main.is_large_community('65001:1:2') AS is_large;

Count the RIB entries decoded from the built-in inline TABLE_DUMP_V2 fixture.

SELECT count(*) AS entries
FROM bgp.main.read_rib(from_hex('68608200000d00010000003b000000000000000302c0000201c00002010000fde902c6336407c63364070000fdea030000000020010db80000000000000000000000010000fde968608200000d000400000079000000003020010db8abcd00010002686082000064800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110e02030000fde90000fbf40000fc58400101004005040000006480040400000000c0200c0000fde9000000070000000968608200000d0002000000af0000000118cb007100020001686082000041800e0d00010104c63364070018cb0071400304c6336407c0110e02030000fdea0000fc010000fc00400101004005040000006480040400000000c00804fdea00c80000686082000054800e0d00010104c00002010018cb0071400304c0000201c0111202040000fde90000fbf40000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002'));

Rank the inline RIB routes by AS-path length using the path_length helper on the emitted as_path column.

SELECT origin_asn, as_path, bgp.main.path_length(as_path) AS hops
FROM bgp.main.read_rib(from_hex('68608200000d00010000003b000000000000000302c0000201c00002010000fde902c6336407c63364070000fdea030000000020010db80000000000000000000000010000fde968608200000d000400000079000000003020010db8abcd00010002686082000064800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110e02030000fde90000fbf40000fc58400101004005040000006480040400000000c0200c0000fde9000000070000000968608200000d0002000000af0000000118cb007100020001686082000041800e0d00010104c63364070018cb0071400304c6336407c0110e02030000fdea0000fc010000fc00400101004005040000006480040400000000c00804fdea00c80000686082000054800e0d00010104c00002010018cb0071400304c0000201c0111202040000fde90000fbf40000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002'))
ORDER BY hops;

Count each message type in the built-in inline BGP4MP update stream.

SELECT message_type, count(*) AS messages
FROM bgp.main.read_updates(from_hex('68608200001100040000007f000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff00670200000050800e0d00010104c00002010018cb0071400304c0000201c0110e02030000fde90000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002686082010011000400000098000000000000fde9000000000000000220010db800000000000000000000000100000000000000000000000000000000ffffffffffffffffffffffffffffffff00680200000051800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110a02020000fde90000fc58400101004005040000006480040400000000686082020011000400000039000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff0021020000000a800f0700010118cb0071'))
GROUP BY 1;

Diff the built-in sample RIB routes (example_rib) against announcements in the inline update stream: for each peer + prefix announced with a different AS path than the RIB held, compare hop count (path_length) and prepends (as_path_prepends) before and after (both paths got one hop shorter; one lost its prepend).

SELECT r.peer_asn, r.origin_asn, r.as_path AS rib_path,
  u.as_path AS update_path, bgp.main.path_length(r.as_path) AS rib_hops,
  bgp.main.path_length(u.as_path) AS update_hops,
  bgp.main.as_path_prepends(r.as_path) AS rib_prepends,
  bgp.main.as_path_prepends(u.as_path) AS update_prepends
FROM bgp.main.example_rib AS r
JOIN bgp.main.read_updates(from_hex('68608200001100040000007f000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff00670200000050800e0d00010104c00002010018cb0071400304c0000201c0110e02030000fde90000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002686082010011000400000098000000000000fde9000000000000000220010db800000000000000000000000100000000000000000000000000000000ffffffffffffffffffffffffffffffff00680200000051800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110a02020000fde90000fc58400101004005040000006480040400000000686082020011000400000039000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff0021020000000a800f0700010118cb0071')) AS u ON u.peer_ip = r.peer_ip AND u.prefix = r.prefix
WHERE u.message_type = 'announce' AND u.as_path <> r.as_path
ORDER BY r.origin_asn, r.peer_asn;

Join the built-in sample RIB routes (example_rib) to the inline update stream on peer and prefix to find which RIB routes are later withdrawn, and when (one route: peer AS 65001, origin AS 64512, withdrawn at 00:00:02).

SELECT r.peer_asn, r.origin_asn, r.as_path, u.timestamp AS withdrawn_at
FROM bgp.main.example_rib AS r
JOIN bgp.main.read_updates(from_hex('68608200001100040000007f000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff00670200000050800e0d00010104c00002010018cb0071400304c0000201c0110e02030000fde90000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002686082010011000400000098000000000000fde9000000000000000220010db800000000000000000000000100000000000000000000000000000000ffffffffffffffffffffffffffffffff00680200000051800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110a02020000fde90000fc58400101004005040000006480040400000000686082020011000400000039000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff0021020000000a800f0700010118cb0071')) AS u ON u.peer_ip = r.peer_ip AND u.prefix = r.prefix
WHERE u.message_type = 'withdraw'
ORDER BY withdrawn_at, r.peer_asn;

Unnest the communities on every built-in sample RIB route (example_rib), skip RFC 8092 large communities with is_large_community, and split each standard one into its tagging ASN and value with community_parse.

SELECT r.peer_asn, r.origin_asn, c.community,
  bgp.main.community_parse(c.community).asn AS tagger_asn,
  bgp.main.community_parse(c.community).value AS tag_value
FROM bgp.main.example_rib AS r
CROSS JOIN unnest(r.communities) AS c(community)
WHERE NOT bgp.main.is_large_community(c.community)
ORDER BY r.peer_asn, c.community;
Views
example_rib 1 example9 cols

A built-in sample of three decoded TABLE_DUMP_V2 RIB routes — browse it to learn the reader's output columns without supplying an MRT file.

Columns
timestamp TIMESTAMP
Route timestamp (UTC) from the sample RIB record's MRT header.
view_name VARCHAR
RIB view / collector name from the fixture's PEER_INDEX_TABLE.
peer_ip STRUCT of 3 fields
The reporting peer's IP address in DuckDB's INET physical layout; cast `::INET`.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
peer_asn UINTEGER
The reporting peer's autonomous-system number.
prefix STRUCT of 3 fields
The announced prefix in DuckDB's INET physical layout; cast `::INET`.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
origin_asn UINTEGER
The origin AS (last ASN in as_path) that announced the prefix.
as_path UINTEGER[]
The AS path in path order — the origin AS is last.
next_hop STRUCT of 3 fields
The BGP next-hop address in DuckDB's INET physical layout; cast `::INET`.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
communities VARCHAR[]
BGP communities as strings (standard `asn:value` and RFC 8092 large).
Example

Group the built-in sample routes by origin AS to see how many prefixes each announced.

SELECT origin_asn, count(*) AS routes
FROM bgp.main.example_rib
GROUP BY origin_asn
ORDER BY routes DESC, origin_asn;
Link
Scalar functions
as_path_prepends (as_path BIGINT[]) 1 example

Number of AS-path prepends (padded repeated ASNs)

Arguments
as_path BIGINT[]
The AS path, in path order — the origin AS that announced the prefix is last. This is the `as_path` column emitted by read_rib / read_updates.
ReturnsBIGINT
Example

Count the prepended (padded) ASNs in a path (here 1).

SELECT bgp.main.as_path_prepends([7018, 174, 174, 13335]);
Link
community_parse (raw VARCHAR) 2 examples

Parse a standard community 'asn:value' into a STRUCT(asn, value)

Arguments
raw VARCHAR
A community string, e.g. '65001:100' (standard) or '65001:1:2' (large).
ReturnsSTRUCT(asn UINTEGER, "value" UINTEGER)
Examples (2)

Split a standard community into {asn: 65001, value: 100}.

SELECT bgp.main.community_parse('65001:100');

Unnest the communities on every built-in sample RIB route (example_rib), skip RFC 8092 large communities with is_large_community, and split each standard one into its tagging ASN and value with community_parse.

SELECT r.peer_asn, r.origin_asn, c.community,
  bgp.main.community_parse(c.community).asn AS tagger_asn,
  bgp.main.community_parse(c.community).value AS tag_value
FROM bgp.main.example_rib AS r
CROSS JOIN unnest(r.communities) AS c(community)
WHERE NOT bgp.main.is_large_community(c.community)
ORDER BY r.peer_asn, c.community;
Link
is_large_community (raw VARCHAR) 1 example

Whether a community string is an RFC 8092 large community

Arguments
raw VARCHAR
A community string, e.g. '65001:100' (standard) or '65001:1:2' (large).
ReturnsBOOLEAN
Example

Detect a large community (three numeric parts, so true).

SELECT bgp.main.is_large_community('65001:1:2');
Link
origin_asn (as_path BIGINT[]) 1 example

The origin AS (last AS) of an AS path

Arguments
as_path BIGINT[]
The AS path, in path order — the origin AS that announced the prefix is last. This is the `as_path` column emitted by read_rib / read_updates.
ReturnsUINTEGER
Example

Get the origin AS that announced the prefix (here 13335).

SELECT bgp.main.origin_asn([7018, 174, 13335]);
Link
path_contains (as_path BIGINT[], asn BIGINT) 1 example

Whether an AS path traverses a given ASN

Arguments
as_path BIGINT[]
The AS path, in path order — the origin AS that announced the prefix is last. This is the `as_path` column emitted by read_rib / read_updates.
asn BIGINT
The autonomous-system number to look for anywhere along the path.
ReturnsBOOLEAN
Example

Test whether a path traverses AS 174 (here true).

SELECT bgp.main.path_contains([7018, 174, 13335], 174);
Link
path_length (as_path BIGINT[]) 2 examples

Number of AS hops in an AS path

Arguments
as_path BIGINT[]
The AS path, in path order — the origin AS that announced the prefix is last. This is the `as_path` column emitted by read_rib / read_updates.
ReturnsBIGINT
Examples (2)

Count the AS hops in a path (here 3).

SELECT bgp.main.path_length([7018, 174, 13335]);

Diff the built-in sample RIB routes (example_rib) against announcements in the inline update stream: for each peer + prefix announced with a different AS path than the RIB held, compare hop count (path_length) and prepends (as_path_prepends) before and after (both paths got one hop shorter; one lost its prepend).

SELECT r.peer_asn, r.origin_asn, r.as_path AS rib_path,
  u.as_path AS update_path, bgp.main.path_length(r.as_path) AS rib_hops,
  bgp.main.path_length(u.as_path) AS update_hops,
  bgp.main.as_path_prepends(r.as_path) AS rib_prepends,
  bgp.main.as_path_prepends(u.as_path) AS update_prepends
FROM bgp.main.example_rib AS r
JOIN bgp.main.read_updates(from_hex('68608200001100040000007f000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff00670200000050800e0d00010104c00002010018cb0071400304c0000201c0110e02030000fde90000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002686082010011000400000098000000000000fde9000000000000000220010db800000000000000000000000100000000000000000000000000000000ffffffffffffffffffffffffffffffff00680200000051800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110a02020000fde90000fc58400101004005040000006480040400000000686082020011000400000039000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff0021020000000a800f0700010118cb0071')) AS u ON u.peer_ip = r.peer_ip AND u.prefix = r.prefix
WHERE u.message_type = 'announce' AND u.as_path <> r.as_path
ORDER BY r.origin_asn, r.peer_asn;
Link
Table functions
peers (src ANY, endpoint := VARCHAR, region := VARCHAR, url_style := VARCHAR, use_ssl := BOOLEAN) 1 example

List the distinct peers / collectors in an MRT file

Positional arguments
src ANY
The MRT file to inspect: a path (local, a glob, `s3://bucket/key`, or `https://host/file`), several such paths in a list, or inline MRT bytes. gzip/bzip2 archives are decompressed automatically.
Named arguments
endpoint := VARCHAR
Custom S3 endpoint for an `s3://` path (e.g. MinIO/R2 'host:9000'). Overrides any endpoint from a CREATE SECRET.
region := VARCHAR
AWS region for an `s3://` path. Overrides the region from a CREATE SECRET.
url_style := VARCHAR
S3 addressing for an `s3://` path: 'path' (path-style, e.g. MinIO) or 'vhost' (the default).
use_ssl := BOOLEAN
Whether to use TLS for an `s3://` path's custom endpoint (default true). Set false for a plain-HTTP endpoint such as a local MinIO.
Returns columns
peer_ip STRUCT of 3 fields
The peer's IP address in DuckDB's INET physical layout; cast `::INET`.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
peer_asn UINTEGER
The peer's autonomous-system number.
collector VARCHAR
The RIB view name (TABLE_DUMP_V2 PEER_INDEX_TABLE); NULL for a BGP4MP update stream, which carries no collector name.
Example

List the peers in an inline TABLE_DUMP_V2 PEER_INDEX_TABLE.

SELECT peer_asn, collector
FROM bgp.main.peers(from_hex('68608200000d00010000003b000000000000000302c0000201c00002010000fde902c6336407c63364070000fdea030000000020010db80000000000000000000000010000fde968608200000d000400000079000000003020010db8abcd00010002686082000064800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110e02030000fde90000fbf40000fc58400101004005040000006480040400000000c0200c0000fde9000000070000000968608200000d0002000000af0000000118cb007100020001686082000041800e0d00010104c63364070018cb0071400304c6336407c0110e02030000fdea0000fc010000fc00400101004005040000006480040400000000c00804fdea00c80000686082000054800e0d00010104c00002010018cb0071400304c0000201c0111202040000fde90000fbf40000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002'));
Link
read_rib (src ANY, strict := BOOLEAN, endpoint := VARCHAR, region := VARCHAR, url_style := VARCHAR, use_ssl := BOOLEAN) 1 example

Read an MRT TABLE_DUMP_V2 RIB snapshot into rows

Positional arguments
src ANY
The RIB dump to read: a path (local, a glob, `s3://bucket/key`, or `https://host/file`), several such paths in a list, or inline MRT bytes. gzip/bzip2 archives are decompressed automatically.
Named arguments
strict := BOOLEAN
When true, a malformed MRT record aborts the scan with an error. When false (the default), each bad record yields a row with NULL fields and a populated `error` column, so a truncated tail record never crashes the query.
endpoint := VARCHAR
Custom S3 endpoint for an `s3://` path (e.g. MinIO/R2 'host:9000'). Overrides any endpoint from a CREATE SECRET.
region := VARCHAR
AWS region for an `s3://` path. Overrides the region from a CREATE SECRET.
url_style := VARCHAR
S3 addressing for an `s3://` path: 'path' (path-style, e.g. MinIO) or 'vhost' (the default).
use_ssl := BOOLEAN
Whether to use TLS for an `s3://` path's custom endpoint (default true). Set false for a plain-HTTP endpoint such as a local MinIO.
Returns columns
timestamp TIMESTAMP
Route timestamp from the MRT record header — when this RIB entry was captured.
view_name VARCHAR
The RIB view / collector name from the TABLE_DUMP_V2 PEER_INDEX_TABLE.
peer_ip STRUCT of 3 fields
The reporting peer's IP address in DuckDB's INET physical layout; cast `::INET`.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
peer_asn UINTEGER
The reporting peer's autonomous-system number.
prefix STRUCT of 3 fields
The announced prefix in DuckDB's INET physical layout; cast `::INET` for containment tests (`<<=` / `>>=`).
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
as_path UINTEGER[]
The AS path in path order — the origin AS that announced the prefix is last.
origin_asn UINTEGER
The origin AS (last ASN in as_path) that announced the prefix.
next_hop STRUCT of 3 fields
The BGP next-hop address in DuckDB's INET physical layout; cast `::INET`.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
communities VARCHAR[]
BGP communities as strings — standard `asn:value` and RFC 8092 large `global:data1:data2`.
med UINTEGER
The MULTI_EXIT_DISC (MED) attribute, or NULL when the route carries none.
local_pref UINTEGER
The LOCAL_PREF attribute, or NULL when the route carries none.
atomic_aggregate BOOLEAN
Whether the ATOMIC_AGGREGATE attribute is set on the route.
aggregator_asn UINTEGER
The AS that formed an aggregate route (AGGREGATOR attribute), or NULL.
error VARCHAR
Decode error for a malformed record (all other columns NULL); NULL on a clean row. A malformed record instead aborts the scan when `strict => true`.
Example

Scan an inline TABLE_DUMP_V2 RIB snapshot (3 entries) into rows.

SELECT prefix, origin_asn, as_path
FROM bgp.main.read_rib(from_hex('68608200000d00010000003b000000000000000302c0000201c00002010000fde902c6336407c63364070000fdea030000000020010db80000000000000000000000010000fde968608200000d000400000079000000003020010db8abcd00010002686082000064800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110e02030000fde90000fbf40000fc58400101004005040000006480040400000000c0200c0000fde9000000070000000968608200000d0002000000af0000000118cb007100020001686082000041800e0d00010104c63364070018cb0071400304c6336407c0110e02030000fdea0000fc010000fc00400101004005040000006480040400000000c00804fdea00c80000686082000054800e0d00010104c00002010018cb0071400304c0000201c0111202040000fde90000fbf40000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002'));
Link
read_updates (src ANY, strict := BOOLEAN, endpoint := VARCHAR, region := VARCHAR, url_style := VARCHAR, use_ssl := BOOLEAN) 2 examples

Read an MRT BGP4MP update stream into rows

Positional arguments
src ANY
The update stream to read: a path (local, a glob, `s3://bucket/key`, or `https://host/file`), several such paths in a list, or inline MRT bytes. gzip/bzip2 archives are decompressed automatically.
Named arguments
strict := BOOLEAN
When true, a malformed MRT record aborts the scan with an error. When false (the default), each bad record yields a row with NULL fields and a populated `error` column, so a truncated tail record never crashes the query.
endpoint := VARCHAR
Custom S3 endpoint for an `s3://` path (e.g. MinIO/R2 'host:9000'). Overrides any endpoint from a CREATE SECRET.
region := VARCHAR
AWS region for an `s3://` path. Overrides the region from a CREATE SECRET.
url_style := VARCHAR
S3 addressing for an `s3://` path: 'path' (path-style, e.g. MinIO) or 'vhost' (the default).
use_ssl := BOOLEAN
Whether to use TLS for an `s3://` path's custom endpoint (default true). Set false for a plain-HTTP endpoint such as a local MinIO.
Returns columns
timestamp TIMESTAMP
Message timestamp from the MRT record header.
peer_ip STRUCT of 3 fields
The reporting peer's IP address in DuckDB's INET physical layout; cast `::INET`.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
peer_asn UINTEGER
The reporting peer's autonomous-system number.
message_type VARCHAR
The message kind: 'announce', 'withdraw', or 'state_change'.
prefix STRUCT of 3 fields
The announced or withdrawn prefix in DuckDB's INET physical layout; cast `::INET`. NULL for a state_change message.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
as_path UINTEGER[]
The AS path (origin AS last) for an announcement; NULL for a withdrawal or state change.
origin_asn UINTEGER
The origin AS (last ASN in as_path) for an announcement; NULL otherwise.
next_hop STRUCT of 3 fields
The BGP next-hop address for an announcement in DuckDB's INET physical layout; cast `::INET`.
STRUCT 3 fields
  • ip_typeUTINYINT
  • addressHUGEINT
  • maskUSMALLINT
communities VARCHAR[]
BGP communities as strings (standard `asn:value` and RFC 8092 large) for an announcement.
old_state USMALLINT
The prior BGP FSM state for a state_change message; NULL otherwise.
new_state USMALLINT
The new BGP FSM state for a state_change message; NULL otherwise.
error VARCHAR
Decode error for a malformed record (all other columns NULL); NULL on a clean row. A malformed record instead aborts the scan when `strict => true`.
Examples (2)

Count announce / withdraw / state-change messages in an inline BGP4MP update stream.

SELECT message_type, count(*)
FROM bgp.main.read_updates(from_hex('68608200001100040000007f000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff00670200000050800e0d00010104c00002010018cb0071400304c0000201c0110e02030000fde90000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002686082010011000400000098000000000000fde9000000000000000220010db800000000000000000000000100000000000000000000000000000000ffffffffffffffffffffffffffffffff00680200000051800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110a02020000fde90000fc58400101004005040000006480040400000000686082020011000400000039000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff0021020000000a800f0700010118cb0071'))
GROUP BY 1;

Join the built-in sample RIB routes (example_rib) to the inline update stream on peer and prefix to find which RIB routes are later withdrawn, and when (one route: peer AS 65001, origin AS 64512, withdrawn at 00:00:02).

SELECT r.peer_asn, r.origin_asn, r.as_path, u.timestamp AS withdrawn_at
FROM bgp.main.example_rib AS r
JOIN bgp.main.read_updates(from_hex('68608200001100040000007f000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff00670200000050800e0d00010104c00002010018cb0071400304c0000201c0110e02030000fde90000fbf40000fc00400101004005040000006480040400000000c00804fde90064c0200c0000fde90000000100000002686082010011000400000098000000000000fde9000000000000000220010db800000000000000000000000100000000000000000000000000000000ffffffffffffffffffffffffffffffff00680200000051800e1c0002011020010db8000000000000000000000001003020010db8abcd40031020010db8000000000000000000000001c0110a02020000fde90000fc58400101004005040000006480040400000000686082020011000400000039000000000000fde90000000000000001c000020100000000ffffffffffffffffffffffffffffffff0021020000000a800f0700010118cb0071')) AS u ON u.peer_ip = r.peer_ip AND u.prefix = r.prefix
WHERE u.message_type = 'withdraw'
ORDER BY withdrawn_at, r.peer_asn;
Link

Try these queries

AS-path and community helpers over inline literals: hop count, origin AS, prepend count, path membership, large-community classification, and standard-community parse.

SELECT bgp.main.path_length([7018, 174, 174, 13335]) AS hops;
SELECT bgp.main.origin_asn([7018, 174, 13335]) AS origin;
SELECT bgp.main.as_path_prepends([7018, 174, 174, 13335]) AS prepends;
SELECT bgp.main.path_contains([7018, 174, 13335], 174) AS via_174;
SELECT bgp.main.is_large_community('65001:1:2') AS is_large;
SELECT bgp.main.community_parse('65001:100').asn AS asn;

Uses path_lengthorigin_asnas_path_prependspath_containsis_large_community

Get the origin AS (last ASN) of an inline AS-path literal.

SELECT bgp.main.origin_asn([7018, 174, 13335]) AS origin;

Uses origin_asn

Count the prepended (padded) ASNs in an inline AS-path literal.

SELECT bgp.main.as_path_prepends([7018, 174, 174, 13335]) AS prepends;

Uses as_path_prepends

Test whether an inline AS path traverses a given ASN.

SELECT bgp.main.path_contains([7018, 174, 13335], 174) AS via_174;

Uses path_contains

Split a standard community string into its ASN and value parts.

SELECT bgp.main.community_parse('65001:100') AS parts;

Uses community_parse

Classify whether a community string is an RFC 8092 large community.

SELECT bgp.main.is_large_community('65001:1:2') AS is_large;

Uses is_large_community

17 more examples in the Catalog, each listed under the table or function it uses.

BGP is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.