{"id":27163024,"url":"https://github.com/jwhited/corebgp","last_synced_at":"2025-04-09T01:35:14.295Z","repository":{"id":39899140,"uuid":"273600126","full_name":"jwhited/corebgp","owner":"jwhited","description":"CoreBGP is a BGP library written in Go that implements the BGP FSM with an event-driven, pluggable model.","archived":false,"fork":false,"pushed_at":"2024-07-13T17:14:29.000Z","size":126,"stargazers_count":171,"open_issues_count":2,"forks_count":11,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-07-13T18:24:24.729Z","etag":null,"topics":["bgp","go","golang","network-programming","sdn"],"latest_commit_sha":null,"homepage":"https://www.jordanwhited.com/posts/corebgp-plugging-in-to-bgp/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwhited.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-19T22:50:59.000Z","updated_at":"2024-07-13T17:11:01.000Z","dependencies_parsed_at":"2023-12-26T22:20:33.148Z","dependency_job_id":"37bfeef9-ce78-449f-90a0-be473b57803a","html_url":"https://github.com/jwhited/corebgp","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwhited%2Fcorebgp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwhited%2Fcorebgp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwhited%2Fcorebgp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwhited%2Fcorebgp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwhited","download_url":"https://codeload.github.com/jwhited/corebgp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247957881,"owners_count":21024775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bgp","go","golang","network-programming","sdn"],"created_at":"2025-04-09T01:35:13.870Z","updated_at":"2025-04-09T01:35:14.282Z","avatar_url":"https://github.com/jwhited.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CoreBGP\n\n[![GoDev](https://img.shields.io/static/v1?label=godev\u0026message=reference\u0026color=00add8)](https://pkg.go.dev/github.com/jwhited/corebgp)\n\nCoreBGP is a BGP library written in Go that implements the BGP FSM with an event-driven, pluggable model. It exposes an API that empowers the user to:\n* send and validate OPEN message capabilities\n* handle \"important\" state transitions\n* handle incoming UPDATE messages\n* send outgoing UPDATE messages\n\nCoreBGP provides optional, composable UPDATE message decoding facilities via [UpdateDecoder](https://pkg.go.dev/github.com/jwhited/corebgp#example-UpdateDecoder). CoreBGP does not manage a routing table or send its own UPDATE messages. Those responsibilities are passed down to the user. Therefore, the intended user is someone who wants that responsibility.\n\nSee this [blog post](https://www.jordanwhited.com/posts/corebgp-plugging-in-to-bgp/) for the background and reasoning behind the development of CoreBGP.\n\n## Plugin\nThe primary building block of CoreBGP is a Plugin, defined by the following interface:\n```go\n// Plugin is a BGP peer plugin.\ntype Plugin interface {\n\t// GetCapabilities is fired when a peer's FSM is in the Connect state prior\n\t// to sending an Open message. The returned capabilities are included in the\n\t// Open message sent to the peer.\n\t//\n\t// The four-octet AS number space capability will be implicitly handled,\n\t// Plugin implementations are not required to return it.\n\tGetCapabilities(peer PeerConfig) []Capability\n\n\t// OnOpenMessage is fired when an Open message is received from a peer\n\t// during the OpenSent state. Returning a non-nil Notification will cause it\n\t// to be sent to the peer and the FSM will transition to the Idle state.\n\t//\n\t// Remote peers MUST include the four-octet AS number space capability in\n\t// their open message. corebgp will return a Notification message if a\n\t// remote peer does not support said capability, and will not invoke\n\t// OnOpenMessage.\n\t//\n\t// Per RFC5492 a BGP speaker should only send a Notification if a required\n\t// capability is missing; unknown or unsupported capabilities should be\n\t// ignored.\n\tOnOpenMessage(peer PeerConfig, routerID netip.Addr, capabilities []Capability) *Notification\n\n\t// OnEstablished is fired when a peer's FSM transitions to the Established\n\t// state. The returned UpdateMessageHandler will be fired when an Update\n\t// message is received from the peer.\n\t//\n\t// The provided writer can be used to send Update messages to the peer for\n\t// the lifetime of the FSM's current, established state. It should be\n\t// discarded once OnClose() fires.\n\tOnEstablished(peer PeerConfig, writer UpdateMessageWriter) UpdateMessageHandler\n\n\t// OnClose is fired when a peer's FSM transitions out of the Established\n\t// state.\n\tOnClose(peer PeerConfig)\n}\n```\n\nHere's an example Plugin that logs when a peer enters/leaves an established state and when an UPDATE message is received:\n```go\ntype plugin struct{}\n\nfunc (p *plugin) GetCapabilities(c corebgp.PeerConfig) []corebgp.Capability {\n\tcaps := make([]corebgp.Capability, 0)\n\treturn caps\n}\n\nfunc (p *plugin) OnOpenMessage(peer corebgp.PeerConfig, routerID netip.Addr, capabilities []corebgp.Capability) *corebgp.Notification {\n\treturn nil\n}\n\nfunc (p *plugin) OnEstablished(peer corebgp.PeerConfig, writer corebgp.UpdateMessageWriter) corebgp.UpdateMessageHandler {\n\tlog.Println(\"peer established\")\n\t// send End-of-Rib\n\twriter.WriteUpdate([]byte{0, 0, 0, 0})\n\treturn p.handleUpdate\n}\n\nfunc (p *plugin) OnClose(peer corebgp.PeerConfig) {\n\tlog.Println(\"peer closed\")\n}\n\nfunc (p *plugin) handleUpdate(peer corebgp.PeerConfig, u []byte) *corebgp.Notification {\n\tlog.Printf(\"got update message of len: %d\", len(u))\n\treturn nil\n}\n```\n\nPlugins are attached to peers when they are added to the Server, which manages their lifetime:\n``` go\nrouterID := netip.MustParseAddr(\"192.0.2.1\")\nsrv, err := corebgp.NewServer(routerID)\nif err != nil {\n    log.Fatalf(\"error constructing server: %v\", err)\n}\np := \u0026plugin{}\nerr = srv.AddPeer(corebgp.PeerConfig{\n    RemoteAddress: netip.MustParseAddr(\"198.51.100.10\"),\n    LocalAS:       65001,\n    RemoteAS:      65010,\n}, p, corebgp.WithLocalAddress(routerID))\nif err != nil {\n    log.Fatalf(\"error adding peer: %v\", err)\n}\n```\n\nFor more examples check out the [examples directory](https://github.com/jwhited/corebgp/tree/main/examples) and [pkg.go.dev](https://pkg.go.dev/github.com/jwhited/corebgp?tab=doc) for the complete API.\n\n## Versioning\nCoreBGP follows [semver](https://semver.org) as closely as it can. Seeing as we are still major version zero (0.y.z), the public API should not be considered stable. You are encouraged to pin CoreBGP's version with your dependency management solution of choice.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwhited%2Fcorebgp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwhited%2Fcorebgp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwhited%2Fcorebgp/lists"}