feat: add RU defaults and fallback logic for unconfigured/empty peers
- Send RU default prefixes to unconfigured peers with no subscriptions, custom prefixes, or ASNs. - Implement fallback to RU prefixes when calculated routes for configured peers resolve to zero. - Improve logging to track RU prefix retrieval and fallback scenarios.
This commit is contained in:
parent
8bb2b0a9d3
commit
0d2cdc206d
1 changed files with 56 additions and 4 deletions
|
|
@ -327,6 +327,37 @@ public sealed class BgpSession : IDisposable
|
|||
_peerStore.UpdateSessionStatus(_peerConfig.Address, true);
|
||||
|
||||
var subscriptionIds = _peerStore.GetSubscriptions(peer.Id);
|
||||
var customPrefixes = _peerStore.GetCustomPrefixes(peer.Id);
|
||||
var customAsns = _peerStore.GetCustomAsns(peer.Id);
|
||||
|
||||
// Unconfigured peer — send RU defaults
|
||||
if (subscriptionIds.Count == 0 && customPrefixes.Count == 0 && customAsns.Count == 0)
|
||||
{
|
||||
_logger.LogInformation("Unconfigured peer {Peer}, sending RU defaults", _peerConfig.Address);
|
||||
try
|
||||
{
|
||||
var ruPrefixes = await _prefixService.GetRuPrefixesAsync();
|
||||
foreach (var (prefix, length, _) in ruPrefixes)
|
||||
{
|
||||
routes.Add(new Route
|
||||
{
|
||||
Prefix = prefix,
|
||||
PrefixLength = length,
|
||||
NextHop = nextHop
|
||||
});
|
||||
}
|
||||
_logger.LogInformation("Sent {Count} RU prefixes to unconfigured peer {Peer}",
|
||||
ruPrefixes.Count, _peerConfig.Address);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch RU prefixes for {Peer}", _peerConfig.Address);
|
||||
}
|
||||
|
||||
await SendRoutesAsync(nextHop, routes);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Peer {Peer} subscriptions: [{Subs}]", _peerConfig.Address, string.Join(", ", subscriptionIds));
|
||||
|
||||
var subscribedLists = _appConfig?.RipeStat?.AsnLists
|
||||
|
|
@ -388,8 +419,7 @@ public sealed class BgpSession : IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
// Add custom prefixes
|
||||
var customPrefixes = _peerStore.GetCustomPrefixes(peer.Id);
|
||||
// Add custom prefixes (already loaded above)
|
||||
_logger.LogInformation("Peer {Peer} has {SubRoutes} subscription routes + {CustomCount} custom prefixes",
|
||||
_peerConfig.Address, routes.Count, customPrefixes.Count);
|
||||
|
||||
|
|
@ -407,8 +437,7 @@ public sealed class BgpSession : IDisposable
|
|||
});
|
||||
}
|
||||
|
||||
// Add custom AS prefixes
|
||||
var customAsns = _peerStore.GetCustomAsns(peer.Id);
|
||||
// Add custom AS prefixes (already loaded above)
|
||||
if (customAsns.Count > 0)
|
||||
{
|
||||
try
|
||||
|
|
@ -435,6 +464,29 @@ public sealed class BgpSession : IDisposable
|
|||
|
||||
_logger.LogInformation("Sending {Count} total routes to {Peer}", routes.Count, _peerConfig.Address);
|
||||
|
||||
// Configured peer resolved 0 prefixes — fall back to RU
|
||||
if (routes.Count == 0)
|
||||
{
|
||||
_logger.LogInformation("Peer {Peer} resolved 0 prefixes, falling back to RU defaults", _peerConfig.Address);
|
||||
try
|
||||
{
|
||||
var ruPrefixes = await _prefixService.GetRuPrefixesAsync();
|
||||
foreach (var (prefix, length, _) in ruPrefixes)
|
||||
{
|
||||
routes.Add(new Route
|
||||
{
|
||||
Prefix = prefix,
|
||||
PrefixLength = length,
|
||||
NextHop = nextHop
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch RU fallback for {Peer}", _peerConfig.Address);
|
||||
}
|
||||
}
|
||||
|
||||
await SendRoutesAsync(nextHop, routes);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue