Commit Graph

63 Commits

Author SHA1 Message Date
Ben Roberts
567a84095e Implement support for multiple BGP peers
The BGP controller now supports announcing routes to multiple BGP peers for redundancy and resilience. If one peer fails, route announcements continue to succeed for other healthy peers.

```yaml
bgp:
  local_as: 12345
  local_ip: 192.168.1.100  # optional
  peers:
    - peer_ip: 10.10.10.1
      peer_as: 6789
      communities:        # per-peer communities (optional)
        - 100:100
    - peer_ip: 10.10.10.2
      peer_as: 6789
      communities:
        - 100:101
      multi_hop: true     # optional, defaults to true for eBGP
  communities:            # global communities applied to all peers
    - 1000:1000
  origin: igp
```

```yaml
bgp:
  local_as: 12345
  peer_as: 6789
  peer_ip: 10.10.10.1
  communities:
    - 100:100
  origin: igp
```

Legacy configurations are automatically converted to the new format internally, ensuring backward compatibility.

Routes are announced to all configured peers. If announcement to one peer fails, the operation continues for other peers. Errors are aggregated and returned, but partial success is allowed.

Communities are merged in the following order:
1. **Global communities** (defined at `bgp.communities`)
2. **Per-peer communities** (defined at `bgp.peers[].communities`)
3. **Per-route communities** (defined at `apps[].vip_config.bgp_communities`)

Example: If global communities are `[1000:1000]`, peer communities are `[100:100]`, and route communities are `[5000:5000]`, the announced route will have all three: `[1000:1000, 100:100, 5000:5000]`.

- **Default behavior**: Multi-hop is disabled by default
- **Enable**: Set `multi_hop: true` per peer to explicitly enable multi-hop BGP

The `/info` endpoint now returns an array of peer information instead of a single peer object:

**Before:**
```json
{
  "conf": {
    "neighbor_address": "10.10.10.1",
    "peer_as": 6789
  },
  "state": {...}
}
```

**After:**
```json
[
  {
    "conf": {
      "neighbor_address": "10.10.10.1",
      "peer_as": 6789
    },
    "state": {...}
  },
  {
    "conf": {
      "neighbor_address": "10.10.10.2",
      "peer_as": 6789
    },
    "state": {...}
  }
]
```

- `config/config.go`: Added `PeerConfig` struct and `Peers` slice to `BgpConfig`
- `controller/bgp.go`: Refactored to support multiple peers with best-effort semantics
- `controller/monitor.go`: Updated `GetInfo()` to return slice of peers
- `server/server.go`: Updated info handler to return array of peers

1. **Controller struct** now stores `[]PeerConfig` instead of single peer fields
2. **Announce/Withdraw** methods loop through all peers with error aggregation
3. **getApiPath** accepts a `PeerConfig` parameter for per-peer community merging
4. **addPeer** determines multi-hop settings per peer
5. **PeerInfo** returns information for all configured peers
6. **Shutdown** gracefully shuts down all peer sessions

The implementation includes comprehensive test coverage:

1. **TestLegacyConfigConversion** - Verifies backward compatibility by testing that legacy single-peer configs are automatically converted to multi-peer format
2. **TestMultiPeerConfig** - Tests that new multi-peer configurations are properly loaded with multiple peers
3. **TestNoPeersConfigError** - Ensures proper error handling when no peers are configured
4. **TestCommunityMerging** - Validates that global, per-peer, and per-route communities are correctly merged in order
5. **TestMultiHopConfiguration** - Tests multi-hop BGP settings with various scenarios:
   - Default behavior (multi-hop disabled)
   - Explicit multi-hop disable
   - Explicit multi-hop enable
6. **TestBestEffortAnnouncement** - Verifies that announcements succeed even when individual peers may have issues
7. **TestWithdrawMultiplePeers** - Tests route withdrawal across multiple peers
8. **TestPeerInfoMultiplePeers** - Validates that peer information is correctly returned for all configured peers

- **TestBgpNew** - Full integration test with actual BGP listeners (requires root, skipped in CI)
- **TestMultiPeerAnnouncement** - Tests actual route announcements to multiple BGP listeners (requires root, skipped in CI)

Existing configurations using `peer_ip` and `peer_as` continue to work without modification.

To add a second peer for resilience:

```yaml
bgp:
  local_as: 12345
  # Keep existing config for backward compatibility, or remove these lines
  # peer_as: 6789
  # peer_ip: 10.10.10.1

  # Add new multi-peer config
  peers:
    - peer_ip: 10.10.10.1
      peer_as: 6789
    - peer_ip: 10.10.10.2  # redundant peer
      peer_as: 6789
  communities:
    - 100:100
  origin: igp
```

All operations (Announce, Withdraw, Shutdown) use best-effort error handling:
- Operations continue even if individual peers fail
- Errors are collected and returned as aggregated error messages
- Format: `"announcement errors: [peer 10.10.10.1: error message, peer 10.10.10.2: error message]"`

These changes were authored via AI LLM.

Authored-By: Claude Code (Sonnet 4.5)
2026-06-17 15:52:43 +01:00
mayuresh82
6f26e86964 Update README.md 2023-08-18 16:08:19 -07:00
mayuresh82
92c9ae3859 Merge pull request #22 from spanthetree/patch-1
Update config.yaml
2023-08-16 16:21:39 -07:00
David Woodruff
1d8c3936e1 Update config.yaml 2023-07-11 07:51:38 +09:00
mayuresh82
e3ed374b53 Merge pull request #17 from naveenachyuta/add_consul_token_support
add support for consul token auth
2022-09-20 11:50:17 -07:00
Naveen Achyuta
8a36bb153a check for error 2022-09-01 13:59:24 -07:00
Naveen Achyuta
e1825b4581 add support for consul token auth 2022-08-22 12:26:35 -07:00
mayuresh82
e285d3a1c5 Merge pull request #16 from isazpiazu-roblox/gobgp_update
Update GoBGP module to v2.34.0
2022-06-02 13:20:14 -07:00
Ian Azpiazu
80d743ffa5 update gobgp pkg 2022-05-16 13:40:57 -04:00
Ian Azpiazu
878ee3a63e update gobgp package to v2.34.0 commit 2022-05-12 14:57:47 -04:00
mayuresh82
adaa755430 Merge pull request #14 from philipcristiano/healcheck
consul: healcheck -> healthcheck
2022-04-25 11:29:15 -07:00
Philip Cristiano
2ab950667e consul: healcheck -> healthcheck 2022-04-23 11:27:33 -04:00
mayuresh82
8d3c63637c Merge pull request #13 from danlsgiga/iptables-listen-destination-port
Add listen port option for NAT routing
2022-03-31 12:23:22 -07:00
mayuresh82
c6adbd9fb5 Update README.md 2022-03-26 11:16:50 -07:00
Daniel Santos
fa25f9430f doc(README): Add alternative way of specifying gocast_nat 2022-03-24 11:00:21 -06:00
Daniel Santos
837226952d chore(monitor): Backwards compatibility 2022-03-24 10:32:52 -06:00
Daniel Santos
58d37566bf doc(README): Cosmetic change 2022-03-16 13:30:26 -06:00
Daniel Santos
f1542981d6 feat(gocast_nat): Add listen port option 2022-03-16 13:23:35 -06:00
mgaitonde
f883e4d4b3 Expand system error message 2022-03-09 13:17:04 -08:00
mayuresh82
a38dc2f48f Merge pull request #12 from mayuresh82/race_fix
attempt to fix a race condition
v1.1.3
2022-03-09 12:28:28 -08:00
Mayuresh Gaitonde
04159185c9 Fix 2021-12-15 17:10:28 -08:00
Mayuresh Gaitonde
c860f3c50e checks to Add new app 2021-12-15 16:44:13 -08:00
Mayuresh Gaitonde
62db2e5af7 attempt to fix a race condition 2021-12-15 15:36:51 -08:00
mayuresh82
d39e46096f Merge pull request #11 from mayuresh82/deadlock_fix
fix the deadlock
v1.1.2
2021-10-20 11:23:51 -07:00
Mayuresh Gaitonde
a99f92e9a5 fix 2021-10-18 18:21:01 -07:00
Mayuresh Gaitonde
5ac02c373b dockerfile fix 2021-10-18 18:16:22 -07:00
Mayuresh Gaitonde
6fdff28716 fix the deadlock 2021-10-18 15:50:13 -07:00
mayuresh82
e32ff1d52c Merge pull request #8 from mayuresh82/vip_config
Add ability to specify vip parameters
v1.1.1
2021-05-14 09:35:05 -07:00
Mayuresh Gaitonde
82152d030d Fix dockerfile 2021-05-13 23:54:52 -07:00
Mayuresh Gaitonde
5821c01a7b Add ability to specify vip parameters 2021-05-13 20:33:05 -07:00
mayuresh82
8ca38f4b77 Merge pull request #7 from mayuresh82/tests
Tests
v1.1.0
2020-12-18 11:47:07 -08:00
Mayuresh Gaitonde
96b39ec9bb add comment 2020-12-18 11:44:32 -08:00
Mayuresh Gaitonde
30303bb875 fix gh yml 2020-12-18 11:38:50 -08:00
Mayuresh Gaitonde
12dc52edc6 ignore bgp test in ci 2020-12-18 11:36:18 -08:00
Mayuresh Gaitonde
6be4d69d02 Add unit tests 2020-12-17 17:25:53 -08:00
mayuresh82
b8ec7a3391 Create LICENSE 2020-11-28 00:41:16 -08:00
mayuresh82
3702339f44 Update README.md 2020-04-03 15:02:33 -07:00
mayuresh82
d96f461375 Update config.yaml 2020-04-03 14:56:49 -07:00
mayuresh82
7f542acc03 Update README.md 2020-04-03 14:55:32 -07:00
mayuresh82
8a26f23729 Merge pull request #4 from chuckyz/allow_consul_stale
Allow stale requests from Consul
v1.0.3
2020-01-30 17:11:07 -08:00
chuckyz
4a9df038fb switch from implicit to explicit string 2020-01-30 13:23:13 -08:00
chuckyz
6e00028410 revert using url.Values as url.Add wont work 2020-01-30 10:20:44 -08:00
chuckyz
1001600a68 use url.Values and .Encode 2020-01-30 09:42:57 -08:00
chuckyz
52a05e0317 os.Getenv returns a string 2020-01-30 09:26:32 -08:00
chuckyz
b129bc8184 allow consul stale 2020-01-30 09:24:51 -08:00
mayuresh82
e23c242d9c Merge pull request #3 from roberteckert/add_support_for_consul_agent_checks
Add support for local consul agent checking
2020-01-29 17:37:07 -08:00
Mayuresh Gaitonde
62279ab31a fix syntax and json parsing 2020-01-29 17:27:56 -08:00
Robert Eckert
b6f865bb73 Add support for local consul agent checking
Direct healthchecking can be expensive at scale. Using the local
agent is a best practice.
2020-01-28 15:20:51 -08:00
mayuresh82
484ae5d00e Merge pull request #2 from mayuresh82/fix_appsrc
Add app source, add vendoring and module support
2019-10-16 16:08:26 -07:00
Mayuresh Gaitonde
a8fd79c0e1 Add app source, add vendoring and module support 2019-10-16 15:57:55 -07:00