-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 task
majst01
approved these changes
Jan 23, 2025
robertvolkmann
requested changes
Jan 23, 2025
There was a problem hiding this 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 | ||
} |
There was a problem hiding this comment.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
report bgp state of connected machines
References:
Depends on: