include communities

This commit is contained in:
Annika Hannig 2021-07-02 15:14:26 +02:00
parent d75db85e96
commit ea6b740f99
No known key found for this signature in database
GPG Key ID: 62E226E47DDCE58D
4 changed files with 24 additions and 4 deletions

View File

@ -18,7 +18,14 @@ func MapGet(m interface{}, key string, fallback interface{}) interface{} {
// MapGetString retrievs a key from a map and
// asserts its type is a string. Otherwise fallback
// will be returned.
func MapGetString(m interface{}, key, fallback string) string {
func MapGetString(m interface{}, key string, fallback string) string {
val := MapGet(m, key, fallback)
return val.(string)
}
// MapGetBool will retrieve a boolean value
// for a given key.
func MapGetBool(m interface{}, key string, fallback bool) bool {
val := MapGet(m, key, fallback)
return val.(bool)
}

View File

@ -35,6 +35,16 @@ func (src *Source) ShowNeighborRIBInRequest(
return http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
}
// ShowNeighborRIBRequest retrives the routes accepted from the neighbor
// identified by bgp-id.
func (src *Source) ShowNeighborRIBRequest(
ctx context.Context,
neighborID string,
) (*http.Request, error) {
url := src.cfg.APIURL("/v1/bgpd/show/rib/neighbor/%s/detail", neighborID)
return http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
}
// ShowRIBRequest makes a request for retrieving all routes imported
// from all peers
func (src *Source) ShowRIBRequest(ctx context.Context) (*http.Request, error) {

View File

@ -167,6 +167,9 @@ func decodeRoute(details map[string]interface{}) (*api.Route, error) {
extendedCommunities := decodeExtendedCommunities(
decoders.MapGet(details, "extended_communities", nil))
// Is preferred route
isPrimary := decoders.MapGetBool(details, "best", false)
// Make bgp info
bgpInfo := api.BgpInfo{
Origin: origin,
@ -186,7 +189,7 @@ func decodeRoute(details map[string]interface{}) (*api.Route, error) {
Bgp: bgpInfo,
Age: lastUpdate,
Type: []string{origin},
Primary: false, // TODO
Primary: isPrimary,
Details: api.Details(details),
}
return r, nil

View File

@ -156,7 +156,7 @@ func (src *Source) Routes(neighborID string) (*api.RoutesResponse, error) {
}
// Query RIB for routes received
req, err := src.ShowNeighborRIBInRequest(context.Background(), neighborID)
req, err := src.ShowNeighborRIBRequest(context.Background(), neighborID)
if err != nil {
return nil, err
}
@ -193,7 +193,7 @@ func (src *Source) RoutesReceived(neighborID string) (*api.RoutesResponse, error
}
// Query RIB for routes received
req, err := src.ShowNeighborRIBInRequest(context.Background(), neighborID)
req, err := src.ShowNeighborRIBRequest(context.Background(), neighborID)
if err != nil {
return nil, err
}