Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: report bgp states of connected neighbors #136

Merged
merged 4 commits into from
Jan 23, 2025
Merged

feat: report bgp states of connected neighbors #136

merged 4 commits into from
Jan 23, 2025

Conversation

mwennrich
Copy link
Contributor

@mwennrich mwennrich commented Nov 25, 2024

@mwennrich mwennrich marked this pull request as ready for review January 23, 2025 14:17
@mwennrich mwennrich requested a review from a team as a code owner January 23, 2025 14:17
@majst01 majst01 merged commit d99dfe4 into master Jan 23, 2025
1 check passed
@majst01 majst01 deleted the bgp-state branch January 23, 2025 14:45
Copy link
Contributor

@robertvolkmann robertvolkmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test?

Comment on lines +70 to +115
var tempData map[string]map[string]json.RawMessage
if err := json.Unmarshal(byteValue, &tempData); err != nil {
return nil, fmt.Errorf("error unmarshalling bgp vrf all neigh output: %w", err)
}

bgpstates := make(map[string]models.V1SwitchBGPPortState)
for _, vrfData := range tempData {

var VrfName string
if err := json.Unmarshal(vrfData["vrfName"], &VrfName); err != nil {
return nil, fmt.Errorf("error parsing vrfName: %w", err)
}

for key, value := range vrfData {
if key == "vrfId" || key == "vrfName" {
continue
}
var port Port
if err := json.Unmarshal(value, &port); err != nil {
return nil, fmt.Errorf("error parsing port info for %s: %w", key, err)
}
bgptimerup := port.BgpTimerUpEstablished
sentPrefixCounter := port.AddressFamilyInfo.IPv4UnicastCumulus.SentPrefixCounter +
port.AddressFamilyInfo.IPv6UnicastCumulus.SentPrefixCounter +
port.AddressFamilyInfo.IPv4UnicastSonic.SentPrefixCounter +
port.AddressFamilyInfo.IPv6UnicastSonic.SentPrefixCounter

acceptedPrefixCounter := port.AddressFamilyInfo.IPv4UnicastCumulus.AcceptedPrefixCounter +
port.AddressFamilyInfo.IPv6UnicastCumulus.AcceptedPrefixCounter +
port.AddressFamilyInfo.IPv4UnicastSonic.AcceptedPrefixCounter +
port.AddressFamilyInfo.IPv6UnicastSonic.AcceptedPrefixCounter

bgpstates[key] = models.V1SwitchBGPPortState{
Neighbor: &port.Hostname,
PeerGroup: &port.PeerGroup,
BgpState: &port.BgpState,
BgpTimerUpEstablished: &bgptimerup,
VrfName: &VrfName,
SentPrefixCounter: &sentPrefixCounter,
AcceptedPrefixCounter: &acceptedPrefixCounter,
}
}
}

return bgpstates, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test for parsing the JSON output from FRR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants