# BGP

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

This page includes setup, release pins, credentials, hosting and verification evidence. [JSON alternative](https://query.farm/products/orchard/api/v1/connectors/bgp.json) contains the same setup facts for structured readers; choose one format.

## Runtime and release

Use DuckDB or Haybarn **2.0.1** with **VGI protocol 3.4**.
Catalog alias: `bgp`. Release: [v0.5.0](https://github.com/Query-farm/vgi-bgp/releases/tag/v0.5.0). Metadata generated: 2026-12-01T18:22:16+00:00.

## Choose where it runs

- On your machine: use an installation method below. No Query Farm account is required for local execution.
- Self-host: follow [the connector deployment instructions](https://github.com/Query-farm/vgi-bgp) and [connection guide](https://query.farm/vgi/connect-to-a-worker/). Use your real endpoint and its authentication settings.
- Query Farm hosted: [create a deployment](https://auth.queryfarm.cloud/console/new?worker=bgp). Hosting has a $10 monthly minimum per organization; usage and license fees may apply. Copy the deployment-specific ATTACH from the console.

## Service credentials and prerequisites

No service credentials are declared by this connector. Individual datasets, input files or deployments may have their own prerequisites.

Secret parameter required flags describe the upstream declaration; they do not override the service-level mode above. Keep secrets in environment variables or the deployment secret store. SQL values in angle brackets are placeholders, not automatic environment lookups. Native DuckDB and Haybarn 2.0.1 do not provide a SQL getenv() function, even when worker-supplied snippets mention it. Read environment variables in your application and pass credential values through client parameter bindings (for example, Python con.execute("CREATE SECRET stripe (TYPE stripe, api_key ?)", [os.environ["STRIPE_API_KEY"]]) after attaching the connector. Omit unused optional parameters and keep real values out of saved SQL and logs.

## Install the extension

In stock DuckDB:

```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;
```

In Haybarn:

```sql
INSTALL vgi FROM community;
LOAD vgi;
```

## Attach the connector

The local recipes below pin the catalog release for repeatability. A public demo endpoint follows its deployed release.

### From GitHub

Attach the release directly

Uses the verified release each time you attach the connector.

```sql
ATTACH 'bgp' AS bgp (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-bgp@v0.5.0'
);
```

### Docker

Attach the signed image

Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.

```sql
ATTACH 'bgp' AS bgp (
  TYPE vgi,
  LOCATION 'oci://ghcr.io/query-farm/vgi-bgp:0.5.0'
);
```

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

Service credentials required for this example: not declared by this example; check the connector requirements above.

```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;
```

- [bgp.main.read_rib — table_function](https://query.farm/products/orchard/connectors/bgp/objects/table_function.bWFpbg.cmVhZF9yaWI.md): exact declaration for this example.

Execution evidence: **captured_result**.

```json
{
  "status": "captured_result",
  "capturedAt": "2026-12-01T06:12:39+00:00",
  "engineVersion": "2.0.1",
  "protocolVersion": "3.4.0",
  "releaseTag": "v0.5.0",
  "sample": {
    "columns": [
      "origin_asn",
      "routes"
    ],
    "types": [
      "UINTEGER",
      "BIGINT"
    ],
    "rows": [
      [
        64512,
        2
      ],
      [
        64600,
        1
      ]
    ],
    "more": false
  }
}
```

## Connector reference

### bgp

Decode **MRT** routing dumps — the archive format RouteViews and RIPE RIS publish — directly in SQL. MRT comes in two flavors this worker reads: **BGP4MP** update streams (announcements, withdrawals, and session state changes) and **TABLE_DUMP_V2** RIB snapshots (a full routing table at one instant). Streaming them into rows turns route-leak / hijack / RIB-diff analysis into a JOIN in the engine instead of an ETL-to-Parquet step.

A source argument is a path (local / glob / `s3://` / `http(s)://`) or an inline `BLOB`; `.gz` / `.bz2` inputs auto-decompress. Prefixes, peer IPs, and next hops are DuckDB **INET** values (cast with `::INET`), so containment such as `prefix::INET <<= '203.0.113.0/24'` and prefix joins work directly. AS paths are `LIST(UINTEGER)` and BGP communities are `LIST(VARCHAR)`; scalar helpers operate on those columns. RPKI / route-origin validation is out of scope — JOIN the origin AS against your VRP table (ROV lives in vgi-netflow).

## Sources and references

- [RFC 6396](https://www.rfc-editor.org/rfc/rfc6396) — the MRT routing information export format (BGP4MP and TABLE_DUMP_V2)
- [RFC 4271](https://www.rfc-editor.org/rfc/rfc4271) — BGP-4, the protocol whose UPDATE messages and path attributes the rows carry
- [RFC 8092](https://www.rfc-editor.org/rfc/rfc8092) — BGP large communities (`a:b:c`)
- [RouteViews archive](https://archive.routeviews.org/) and [RIPE RIS raw data](https://ris.ripe.net/docs/mrt/) — public MRT dumps to query
- [bgpkit-parser](https://github.com/bgpkit/bgpkit-parser) — the MRT decoding library this worker uses

## Find the exact SQL object

[Browse 10 object declarations](https://query.farm/products/orchard/api/v1/connectors/bgp/objects.json) or [search within this connector](https://query.farm/products/orchard/api/v1/search.json?kind=object&connector=bgp&q=bgp).

Follow one format of each needed object for complete argument types, defaults, named flags, return columns and examples. Existing links above can replace another search. For questions about hosting, credentials or supported operations, stop once the documentation answers the question; SQL and unrelated object lookups are unnecessary.

## Verification and interpretation

- Missing, null, or undeclared metadata means unknown; do not invent defaults, credential scope, platform support or endpoint URLs.
- Search is keyword retrieval, not proof of a capability. Read the exact object declaration before generating SQL.
- A table and a table function can have the same name. Preserve parentheses and use the matching overload and schema.
- Service credentials, external data availability and deployment authentication are separate requirements.
- Catalog verification records the harvest environment. It is not proof that every query or current live API call succeeds. Only an example with captured_result has a saved result for that exact SQL.

```json
{
  "generatedAt": "2026-12-01T18:22:16+00:00",
  "repository": "https://github.com/Query-farm/vgi-bgp",
  "harvest": {
    "status": "ok",
    "method": "github-auto",
    "error": null,
    "vgi_version": "9773130dde"
  },
  "catalogVerification": {
    "verified": true,
    "status": "passed",
    "total": 2,
    "passed": 2,
    "failed": 0,
    "needs_credentials": 0,
    "location": "github-auto://Query-farm/vgi-bgp@v0.5.0",
    "transport": "github-auto",
    "environment": {
      "vgi_extension_version": "9773130dde",
      "haybarn_version": "2.0.1rc3",
      "engine_version": "v2.0.1",
      "python": "3.12.4",
      "platform": "darwin_arm64",
      "protocol_version": "3.4.0"
    },
    "checked_at": "2026-12-01T06:10:18+00:00"
  },
  "interpretation": "Catalog verification records the harvest environment. It is not proof that every query or current live API call succeeds. Only an example with captured_result has a saved result for that exact SQL."
}
```
