# Test eBGP 4-Byte ASN Peering, OSPF & BFD Without Router VMs

> **FrameAssembly v3.2.2** · Operational Playbook (Routing, VLANs & Overlays) · Canonical URL: https://frameassembly-lang.dev/use-cases/bgp-ospf-bfd-routing-pcap

Craft TCP 179 BGP OPEN/UPDATE/KEEPALIVE with RFC 6793 AS_TRANS, multicast OSPFv2 Hello, and 50ms BFD Up frames in 12 lines.

- **Category:** Routing, VLANs & Overlays
- **Capture Filename:** `bgp_ospf_bfd_lab.frasm` (12 Ethernet frames)
- **Protocols Exercised:** `tcp`, `bgp`, `ospf`, `bfd`

## Operational Problem

Spinning up a 16 GB Containerlab or GNS3 topology with vendor router images just to verify a Control Plane Policing (CoPP) ACL, a BGP route-collector parser, or a BFD UDP 3784 timer filter eats half an afternoon.

Router control planes are picky: eBGP expects a valid 3-way TCP 179 handshake at TTL 1 and CS6 (DSCP 48), 4-byte ASNs above 65535 require RFC 6793 AS_TRANS (23456) plus Capability 65 inside the BGP OPEN message, and BFD control packets get dropped immediately unless Hop Limit / TTL equals 255.

Hand-coding 16-byte `0xff` BGP markers, variable-length NLRI prefix tuples, and OSPF multicast MACs (`01:00:5e:00:00:05`) in raw hex is error-prone. FrameAssembly computes every marker, capability length, and multicast destination MAC automatically.

## Scenario & Topology: Edge Peering Turn-Up & CoPP Audit (AS 4200000001 <-> ISP AS 64512 + OSPF + BFD)

- **Topology:** `DC Border Router (198.51.100.1, AS 4200000001) <-> ISP Edge (198.51.100.2, AS 64512) & AllSPFRouters (224.0.0.5)`

Twelve CS6-marked (`dscp 48`) control-plane packets exercise your entire routing ACL and telemetry parser: (1) a stateful TCP 179 handshake followed by 4-byte ASN `bgp open`, bidirectional `keepalive`, and an NLRI `update` advertising `203.0.113.0/24`; (2) an OSPFv2 multicast `hello` to `224.0.0.5` answered by unicast `lsack`; and (3) a sub-second `bfd` `state 3` (Up) session on UDP 3784 at `ttl 255`.

## FrameAssembly Workflow

Emits 12 CS6-marked routing frames covering stateful eBGP 4-byte ASN peering + NLRI UPDATE, multicast OSPFv2 Hello/LSAck, and TTL-255 BFD Up.

### Adapt It for Your Network

1. Set dc_border and isp_edge to your peering link `/30` or `/31` addresses and replace asn 4200000001 / prefix with your own ASN and subnet.
2. Keep ttl 1 on eBGP (or change to ttl 2..255 for eBGP multihop checks) and ttl 255 on single-hop BFD.
3. Run frameassembly bgp_ospf_bfd_lab.frasm, inspect Capability 65 and NLRI in tshark, or replay against your router CoPP test port.

## Runnable Capture Specification (`bgp_ospf_bfd_lab.frasm`)

```frameassembly
host dc_border { ip 198.51.100.1 mac 00:1c:73:b0:00:01 }
host isp_edge  { ip 198.51.100.2 mac 00:1c:73:b0:00:02 }
host ospf_all  { ip 224.0.0.5 }

flow ebgp_peering_and_nlri(local_rtr, peer_rtr) {
    // 1. Stateful TCP 179 handshake + 4-byte ASN eBGP OPEN, KEEPALIVE, and NLRI UPDATE
    local_rtr -> peer_rtr dscp 48 ttl 1 tcp syn srcport 51179 dstport 179 win 65535 mss 1460 wait 1ms
    local_rtr <- peer_rtr dscp 48 ttl 1 tcp syn ack win 65535 mss 1460 wait 1ms
    local_rtr -> peer_rtr dscp 48 ttl 1 tcp ack wait 1ms
    local_rtr -> peer_rtr dscp 48 ttl 1 bgp open asn 4200000001 holdtime 90 bgpid 198.51.100.1 wait 2ms
    local_rtr <- peer_rtr dscp 48 ttl 1 bgp open asn 64512 holdtime 90 bgpid 198.51.100.2 wait 2ms
    local_rtr -> peer_rtr dscp 48 ttl 1 bgp keepalive wait 1ms
    local_rtr <- peer_rtr dscp 48 ttl 1 bgp keepalive wait 2ms
    local_rtr -> peer_rtr dscp 48 ttl 1 bgp update asn 4200000001 prefix "203.0.113.0/24" nexthop 198.51.100.1 wait 5ms
}

flow igp_and_bfd_liveness(local_rtr, peer_rtr, mcast_ospf) {
    // 2. OSPFv2 multicast Hello (224.0.0.5 -> 01:00:5e:00:00:05) + unicast LSAck
    local_rtr -> mcast_ospf dscp 48 ttl 1 ospf hello routerid 198.51.100.1 areaid 0.0.0.0 hellointerval 10 deadinterval 40 priority 100 wait 2ms
    local_rtr <- peer_rtr dscp 48 ttl 1 ospf lsack routerid 198.51.100.2 areaid 0.0.0.0 wait 2ms

    // 3. Sub-second BFD Control Up session (state 3, TTL 255) on UDP 3784
    local_rtr -> peer_rtr dscp 48 ttl 255 bfd state 3 diag 0 mydisc 0x1001 yourdisc 0x2002 mintx 50000 minrx 50000 mult 3 wait 2ms
    local_rtr <- peer_rtr dscp 48 ttl 255 bfd state 3 diag 0 mydisc 0x2002 yourdisc 0x1001 mintx 50000 minrx 50000 mult 3 wait 2ms
}

compile {
    ebgp_peering_and_nlri(dc_border, isp_edge)
    igp_and_bfd_liveness(dc_border, isp_edge, ospf_all)
}
```

## Equivalent CLI Commands

```bash
# 1. Preview the 12-packet eBGP + OSPF + BFD control-plane timeline
frameassembly show bgp_ospf_bfd_lab.frasm

# 2. Compile to .pcap and inspect BGP 4-byte ASN, OSPF Area 0, and BFD state in tshark
frameassembly bgp_ospf_bfd_lab.frasm bgp_ospf_bfd_lab.pcap
tshark -r bgp_ospf_bfd_lab.pcap -Y "bgp || ospf || bfd"

# 3. Replay against a router CoPP interface or feed into Zeek /pmacct
sudo tcpreplay -i eth0 bgp_ospf_bfd_lab.pcap
```

## Protocol Reference Links

- [`tcp` — Transmission Control Protocol & RFC 7323 Options](https://frameassembly-lang.dev/docs/protocols/tcp) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/tcp.md))
- [`bgp` — Border Gateway Protocol 4 & 4-Byte ASN Capability](https://frameassembly-lang.dev/docs/protocols/bgp) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/bgp.md))
- [`ospf` — Open Shortest Path First — OSPFv2 & Dual-Stack OSPFv3](https://frameassembly-lang.dev/docs/protocols/ospf) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/ospf.md))
- [`bfd` — Bidirectional Forwarding Detection Control Packet](https://frameassembly-lang.dev/docs/protocols/bfd) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/bfd.md))
