### Quick Start Usage Examples Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/cli/README.md Common usage patterns for linting, formatting, and starting the LSP server via npx. ```bash # Lint check (text output) npx birdcc lint bird.conf # Lint `main` from bird.config.json npx birdcc lint # Lint check (JSON output for CI integration) npx birdcc lint bird.conf --format json # Combined with BIRD runtime validation npx birdcc lint bird.conf --bird # Format check npx birdcc fmt bird.conf --check # Format check for `main` from bird.config.json npx birdcc fmt --check # Format and write to file npx birdcc fmt bird.conf --write # Start LSP server npx birdcc lsp --stdio ``` -------------------------------- ### L3VPN Setup Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Demonstrates a typical L3VPN setup with MPLS, BGP for VPN route exchange, and kernel interfaces for VRF mapping. Ensure MPLS domain and table are defined, and appropriate protocols are configured for BGP and kernel routing. ```bird # MPLS basics mpls domain mdom; mpls table mtab; protocol kernel krt_mpls { mpls { table mtab; export all; }; } vpn4 table vpntab4; vpn6 table vpntab6; # Exchange VPN routes through BGP protocol bgp { vpn4 { table vpntab4; import all; export all; }; vpn6 { table vpntab6; import all; export all; }; mpls { label policy aggregate; }; local 10.0.0.1 as 10; neighbor 10.0.0.2 as 10; } # VRF 0 ipv4 table vrf0v4; ipv6 table vrf0v6; protocol kernel kernel0v4 { vrf "vrf0"; ipv4 { table vrf0v4; export all; }; kernel table 100; } protocol kernel kernel0v6 { vrf "vrf0"; ipv6 { table vrf0v6; export all; }; kernel table 100; } protocol l3vpn l3vpn0 { vrf "vrf0"; ipv4 { table vrf0v4; }; ipv6 { table vrf0v6; }; vpn4 { table vpntab4; }; vpn6 { table vpntab6; }; mpls { label policy vrf; }; rd 10:12; import target [(rt, 10, 32..40)]; export target [(rt, 10, 30), (rt, 10, 31)]; } ``` -------------------------------- ### Bash Commands for Project Setup and Build Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/README.md Provides essential bash commands for cloning the repository with submodules, installing dependencies, building all packages, and running tests. ```bash # Clone with submodules git clone --recursive https://github.com/bird-chinese-community/BIRD-LSP.git cd BIRD-LSP # Install dependencies pnpm install # Build all packages pnpm build # Run tests pnpm test ``` -------------------------------- ### Basic BIRD Configuration Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md This configuration enables synchronization with the OS kernel, learns network interfaces, and runs RIP on all found interfaces. Ensure correct protocol definitions for your network setup. ```bird protocol kernel { ipv4 { export all; # Default is export none }; persist; # Don't remove routes on BIRD shutdown } protocol device { } protocol rip { ipv4 { import all; export all; }; interface "*"; } ``` -------------------------------- ### L3VPN Configuration Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-3.2.0.md This example demonstrates a typical L3VPN setup with one VPN and a BGP uplink. It includes MPLS domain and table definitions, kernel protocol configurations for IPv4 and IPv6 within a VRF, and the main L3VPN protocol configuration with route distinguisher and import/export targets. ```bird # MPLS basics mpl s domain mdom; mpl s table mtab; protocol kernel krt_mpls { mpls { table mtab; export all; }; } vpn4 table vpntab4; vpn6 table vpntab6; # Exchange VPN routes through BGP protocol bgp { vpn4 { table vpntab4; import all; export all; }; vpn6 { table vpntab6; import all; export all; }; mpls { label policy aggregate; }; local 10.0.0.1 as 10; neighbor 10.0.0.2 as 10; } # VRF 0 ipv4 table vrf0v4; ipv6 table vrf0v6; protocol kernel kernel0v4 { vrf "vrf0"; ipv4 { table vrf0v4; export all; }; kernel table 100; } protocol kernel kernel0v6 { vrf "vrf0"; ipv6 { table vrf0v6; export all; }; kernel table 100; } protocol l3vpn l3vpn0 { vrf "vrf0"; ipv4 { table vrf0v4; }; ipv6 { table vrf0v6; }; vpn4 { table vpntab4; }; vpn6 { table vpntab6; }; mpls { label policy vrf; }; rd 10:12; import target [(rt, 10, 32..40)]; export target [(rt, 10, 30), (rt, 10, 31)]; } ``` -------------------------------- ### Setup Rust WASM Target Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/dprint-plugin-bird/README.md Before installing the plugin, ensure you have the necessary Rust WASM target installed. ```bash rustup target add wasm32-wasip1 ``` -------------------------------- ### Install Dependencies Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/parser/README.md Install project dependencies using pnpm. ```bash pnpm install ``` -------------------------------- ### Install @birdcc/formatter Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/formatter/README.md Install the package using your preferred package manager. ```bash # Using pnpm (recommended) pnpm add @birdcc/formatter # Using npm npm install @birdcc/formatter # Using yarn yarn add @birdcc/formatter ``` -------------------------------- ### Install @birdcc/lsp Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/lsp/README.md Install the package using your preferred package manager. ```bash pnpm add @birdcc/lsp ``` ```bash npm install @birdcc/lsp ``` ```bash yarn add @birdcc/lsp ``` -------------------------------- ### Install VSIX File with Command Line Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/vscode/README.md Install the extension from a VSIX file using the VS Code command line. ```bash code --install-extension bird2-lsp-0.1.0-alpha.vsix ``` -------------------------------- ### Interface Matching Examples Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-3.2.0.md Examples demonstrate various ways to specify interfaces for protocol configuration. Use '*' for all interfaces, enumerate specific interfaces, or use negation and wildcards for complex matching rules. ```bird interface "*" { type broadcast; }; ``` ```bird interface "eth1", "eth4", "eth5" { type ptp; }; ``` ```bird interface -192.168.1.0/24, 192.168.0.0/16; ``` ```bird interface "eth*" 192.168.1.0/24; ``` -------------------------------- ### Start LSP Server (stdio mode) Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/lsp/README.md Start the LSP server using stdio mode for editor integration. ```bash npx birdcc lsp --stdio ``` -------------------------------- ### BIRD Configuration File Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/AGENTS.md Example configuration for the BIRD router, specifying schema, main file, formatter settings, linter rules, and bird validation command. ```json { "$schema": "https://raw.githubusercontent.com/bird-chinese-community/BIRD-LSP/main/schemas/bird.config.schema.json", "main": "bird.conf", "formatter": { "engine": "dprint", "indentSize": 2, "lineWidth": 100, "safeMode": true }, "linter": { "rules": { "sym/*": "error", "cfg/*": "error", "net/*": "error", "type/*": "error", "bgp/*": "warning", "ospf/*": "warning" } }, "bird": { "validateCommand": "bird -p -c {file}" } } ``` -------------------------------- ### Install Plugin via npm Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/dprint-plugin-bird/README.md Install the dprint plugin for BIRD configuration files using npm. ```bash npm install @birdcc/dprint-plugin-bird ``` -------------------------------- ### Install BIRD Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Standard installation procedure for BIRD on UNIX-like systems. Ensure development tools are present before running. ```bash ./configure make make install vi /usr/local/etc/bird.conf bird ``` -------------------------------- ### Sync Examples with @birdcc/linter Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/linter/README.md Synchronize reference samples for the linter. This command copies sample configuration files to the examples directory and runs automatically during build and test. ```bash pnpm --filter @birdcc/linter sync:examples ``` -------------------------------- ### BIRD Channel Options Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Demonstrates basic channel options including import limits and interface specifications. ```bird import limit 50; }; interface "*"; } ``` -------------------------------- ### startLspServer Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/lsp/README.md Starts the Language Server Protocol server using standard input/output for communication with editors. ```APIDOC ## startLspServer(): void ### Description Start the LSP server with stdio transport. ### Method `startLspServer` ### Parameters None ### Returns `void` ``` -------------------------------- ### Install @birdcc/linter Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/linter/README.md Install the linter package using your preferred package manager. ```bash pnpm add @birdcc/linter ``` ```bash npm install @birdcc/linter ``` ```bash yarn add @birdcc/linter ``` -------------------------------- ### Install @birdcc/cli Globally or via npx Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/cli/README.md Install the CLI globally for direct use or use npx to run commands without installation. ```bash # Global installation npm install -g @birdcc/cli # Or use npx (no installation required) npx @birdcc/cli --help ``` -------------------------------- ### Install @birdcc/parser Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/parser/README.md Install the package using your preferred package manager. Node.js v18+ and TypeScript v5.0+ are recommended. ```bash # Using pnpm (recommended) pnpm add @birdcc/parser # Using npm npm install @birdcc/parser # Using yarn yarn add @birdcc/parser ``` -------------------------------- ### Install BIRD2 LSP CLI Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/README.md Install the BIRD2 LSP command-line interface globally using npm or pnpm. ```bash npm install -g @birdcc/cli # or pnpm add -g @birdcc/cli ``` -------------------------------- ### RIP Protocol Configuration Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Example configuration for a RIP protocol, specifying import/export policies and interface-specific settings like metric, port, mode, and authentication. ```bird protocol rip { ipv4 { import all; export all; }; interface "eth*" { metric 2; port 1520; mode multicast; update time 12; timeout time 60; authentication cryptographic; password "secret" { algorithm hmac sha256; }; }; } ``` -------------------------------- ### runLspStdio Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/cli/README.md Starts the Language Server Protocol (LSP) server in standard input/output mode. ```APIDOC ## runLspStdio() ### Description Initializes and runs the BIRD Language Server Protocol (LSP) server using standard input and output for communication. ### Endpoint N/A (Function call) ``` -------------------------------- ### Start BIRD-LSP Server with CLI Source: https://context7.com/bird-chinese-community/bird-lsp/llms.txt Start the BIRD-LSP server in stdio mode using the birdcc CLI. This is typically used by editors to communicate with the language server. ```bash # Start LSP in stdio mode (used by editors) birdcc lsp --stdio ``` -------------------------------- ### IPv6 Flowspec Configuration Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Example of configuring IPv6 Flowspec rules, demonstrating destination/source prefixes with offset, next header, port matching, TCP flags, fragmentation, and flow label. ```bird protocol static { flow6 { table myflow6; }; route flow6 { dst fec0:1122:3344:5566:7788:99aa:bbcc:ddee/128; src 0000:0000:0000:0001:1234:5678:9800:0000/101 offset 63; next header = 23; sport > 24 && < 30 || = 40 || 50,60,70..80; dport = 50; tcp flags 0x03/0x0f && !0/0xff || 0x33/0x33; fragment !is_fragment || !first_fragment; label > 1111 && != 1234; }; } ``` -------------------------------- ### Configure BMP Protocol Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-3.2.0.md Example configuration for the BMP protocol, specifying the monitoring station and which routing information to monitor. ```bird protocol bmp { # The monitoring station to connect to station address ip 198.51.100.10 port 1790; # Monitor received routes (in import table) monitoring rib in pre_policy; # Monitor accepted routes (passed import filters) monitoring rib in post_policy; # Allow only 64M of pending data tx buffer limit 64; } ``` -------------------------------- ### Aggregator Protocol Configuration Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Example configuration for the Aggregator protocol, demonstrating route aggregation based on common attributes like network and BGP path length. It includes filtering, merging logic, and import/export rules. ```bird protocol aggregator { table master6; export where defined(bgp_path); /* Merge all routes with the same AS Path length */ aggregate on net, bgp_path.len; merge by { for route r in routes do { if ! defined(bgp_path) then { bgp_path = r.bgp_path } bgp_community = bgp_community.add(r.bgp_community); } accept; }; import all; peer table agr_result; } ``` -------------------------------- ### Run BIRD3 Daemon with Compose Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/docker/README.md Starts the BIRD3 daemon in the foreground using Docker Compose. ```bash docker compose -f docker/compose.yml up bird3 ``` -------------------------------- ### Run BIRD2 Daemon with Compose Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/docker/README.md Starts the BIRD2 daemon in the foreground using Docker Compose. ```bash docker compose -f docker/compose.yml up bird2 ``` -------------------------------- ### Fragment Matching Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Example of matching packet fragmentation types. ```bird fragment is_fragment && !dont_fragment ``` -------------------------------- ### Configure Device Protocol Interface Options Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Example configuration for the Device protocol, specifying scan time and preferred IP addresses for a specific interface. ```bird protocol device { scan time 10; # Scan the interfaces often interface "eth0" { preferred 192.168.1.1; preferred 2001:db8:1:10::1; }; } ``` -------------------------------- ### ICMP Code Matching Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Example of matching ICMP code field numbers. ```bird icmp code 1 ``` -------------------------------- ### BIRD Configuration Schema Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/cli/README.md Example `bird.config.json` file demonstrating schema, main configuration file, BIRD validation command, formatter settings, and linter rules. ```json { "$schema": "https://raw.githubusercontent.com/bird-chinese-community/BIRD-LSP/main/schemas/bird.config.schema.json", "main": "bird.conf", "bird": { "validateCommand": "sudo bird -p -c {file}" }, "formatter": { "engine": "dprint", "indentSize": 2, "lineWidth": 100 }, "linter": { "rules": { "sym/*": "error", "bgp/*": "warning" } } } ``` -------------------------------- ### ICMP Type Matching Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Example of matching ICMP type field numbers. ```bird icmp type 3 ``` -------------------------------- ### IPv6 Destination Prefix with Offset Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Example of specifying an IPv6 destination prefix with an offset. ```bird dst ::1c77:3769:27ad:a11a/128 offset 64 ``` -------------------------------- ### BIRD Debugging with 'show route filter' Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md An example session demonstrating how to use the 'show route filter' command in the BIRD command-line client to test and debug filters. ```bash pavel@bug:~/bird$ ./birdc -s bird.ctl BIRD 0.0.0 ready. bird> show route 10.0.0.0/8 dev eth0 [direct1 23:21] (240) 195.113.30.2/32 dev tunl1 [direct1 23:21] (240) 127.0.0.0/8 dev lo [direct1 23:21] (240) bird> show route ? show route [] [table ] [filter ] [all] [primary]... bird> show route filter { if 127.0.0.5 ˜ net then accept; } 127.0.0.0/8 dev lo [direct1 23:21] (240) bird> ``` -------------------------------- ### Install birdcc CLI Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/vscode/README.md Install the birdcc CLI globally using npm. This is recommended for full functionality of the BIRD2 LSP extension. ```bash npm install -g @birdcc/cli ``` -------------------------------- ### Programmatic LSP Server Start and Diagnostic Conversion Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/lsp/README.md Start the LSP server programmatically and convert internal diagnostics to LSP format. ```typescript import { startLspServer, toLspDiagnostic } from "@birdcc/lsp"; import type { BirdDiagnostic } from "@birdcc/core"; // Start the LSP server startLspServer(); // Convert internal diagnostic to LSP format const lspDiagnostic = toLspDiagnostic(birdDiagnostic); ``` -------------------------------- ### Start BIRD LSP Server Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/packages/@birdcc/cli/README.md Launch the BIRD Language Server Protocol (LSP) process using stdio transport. ```bash birdcc lsp --stdio ``` -------------------------------- ### Define Prefix Set with Shorthands Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Provides examples of prefix set literals using standard notation, network prefix shorthands (`+` for subnets, `-` for supernets), and range specifications for prefix lengths. ```bird [ 1.0.0.0/8, 2.0.0.0/8+, 3.0.0.0/8-, 4.0.0.0/8{16,24} ] ``` -------------------------------- ### Minimal Project Configuration (`bird.config.json`) Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/docs/configuration.md Defines the entry file and validation command for a BIRD project. Ensure the schema is correctly referenced. ```json { "$schema": "https://raw.githubusercontent.com/bird-chinese-community/BIRD-LSP/main/schemas/bird.config.schema.json", "main": "bird.conf", "bird": { "validateCommand": "bird -p -c {file}" } } ``` -------------------------------- ### IPv4 Flowspec Configuration Example Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-2.18.md Example of configuring IPv4 Flowspec rules, including destination prefix, port ranges, TCP flags, packet length, DSCP, and fragmentation. ```bird protocol static { flow4; route flow4 { dst 10.0.0.0/8; port > 24 && < 30 || 40..50,60..70,80 && >= 90; tcp flags 0x03/0x0f; length > 1024; dscp = 63; fragment dont_fragment, is_fragment || !first_fragment; }; } ``` -------------------------------- ### Define Integer and Pair Sets in BIRD Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/refer/docs/BIRD-3.2.0.md Demonstrates defining integer and pair sets using named constants and compound expressions. Ensure expressions are evaluable before daemon boot. ```bird define one=1; define myas=64500; int set odds = [ one, (2+1), (6-one), (2*2*2-1), 9, 11 ]; pair set ps = [ (1,one+one), (3,4)..(4,8), (5,*), (6,3..6), (7..9,*) ]; ``` -------------------------------- ### Basic Project Configuration Source: https://github.com/bird-chinese-community/bird-lsp/blob/main/docs/spec.md A minimal configuration for a single BIRD router project, specifying the main configuration file, include paths, and linter rules. ```json { "$schema": "https://raw.githubusercontent.com/bird-chinese-community/BIRD-LSP/main/schemas/bird.config.schema.json", "main": "bird.conf", "includePaths": ["./filters", "./peers"], "bird": { "validateCommand": "bird -p -c {file}" }, "linter": { "rules": { "sym/*": "error", "bgp/*": "warning" } } } ```