initial source
This commit is contained in:
parent
1bc9f42271
commit
8533854a37
@ -22,21 +22,21 @@ func StatusRequest(ctx context.Context, src *Source) (*http.Request, error) {
|
||||
return http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
}
|
||||
|
||||
// NeighborsRequest makes an all neighbors request
|
||||
func NeighborsRequest(ctx context.Context, src *Source) (*http.Request, error) {
|
||||
// ShowNeighborsRequest makes an all neighbors request
|
||||
func ShowNeighborsRequest(ctx context.Context, src *Source) (*http.Request, error) {
|
||||
url := apiURL(src.API, "v1/bgpd/show/neighbor")
|
||||
return http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
}
|
||||
|
||||
// NeighborsSummaryRequest builds an neighbors status request
|
||||
func NeighborsSummaryRequest(ctx context.Context, src *Source) (*http.Request, error) {
|
||||
// ShowNeighborsSummaryRequest builds an neighbors status request
|
||||
func ShowNeighborsSummaryRequest(ctx context.Context, src *Source) (*http.Request, error) {
|
||||
url := apiURL(src.API, "v1/bgpd/show/summary")
|
||||
return http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
}
|
||||
|
||||
// NeighborRoutesReceivedRequest retrives the RIB IN for neighbor identified
|
||||
// by bgp-id.
|
||||
func NeighborRoutesReceivedRequest(
|
||||
// ShowNeighborRIBInRequest retrives the routes accepted from the neighbor
|
||||
// identified by bgp-id.
|
||||
func ShowNeighborRIBInRequest(
|
||||
ctx context.Context,
|
||||
src *Source,
|
||||
neighborID string,
|
||||
@ -44,3 +44,10 @@ func NeighborRoutesReceivedRequest(
|
||||
url := apiURL(src.API, "v1/bgpd/show/rib/in/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 ShowRIBRequest(ctx context.Context, src *Source) (*http.Request, error) {
|
||||
url := apiURL(src.API, "vi/bgpd/show/rib/in/detail")
|
||||
return http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func (src *Source) Neighbours() (*api.NeighboursResponse, error) {
|
||||
}
|
||||
|
||||
// Make API request and read response
|
||||
req, err := NeighborsRequest(context.Background(), src)
|
||||
req, err := ShowNeighborsRequest(context.Background(), src)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -106,7 +106,7 @@ func (src *Source) NeighboursStatus() (*api.NeighboursStatusResponse, error) {
|
||||
}
|
||||
|
||||
// Make API request and read response
|
||||
req, err := NeighborsSummaryRequest(context.Background(), src)
|
||||
req, err := ShowNeighborsSummaryRequest(context.Background(), src)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -144,8 +144,7 @@ func (src *Source) Routes(neighborID string) (*api.RoutesResponse, error) {
|
||||
}
|
||||
|
||||
// Query RIB for routes received
|
||||
req, err := NeighborRoutesReceivedRequest(
|
||||
context.Background(), src, neighborID)
|
||||
req, err := ShowNeighborRIBInRequest(context.Background(), src, neighborID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -174,21 +173,101 @@ func (src *Source) Routes(neighborID string) (*api.RoutesResponse, error) {
|
||||
|
||||
// RoutesReceived returns the routes exported by the neighbor.
|
||||
func (src *Source) RoutesReceived(neighborID string) (*api.RoutesResponse, error) {
|
||||
return nil, nil
|
||||
// Retrieve routes for the specific neighbor
|
||||
apiStatus := api.ApiStatus{
|
||||
Version: SourceVersion,
|
||||
ResultFromCache: false,
|
||||
Ttl: time.Now().UTC(),
|
||||
}
|
||||
|
||||
// Query RIB for routes received
|
||||
req, err := ShowNeighborRIBInRequest(context.Background(), src, neighborID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Read and decode response
|
||||
body, err := decoders.ReadJSONResponse(res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
recv, err := decodeRoutes(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := &api.RoutesResponse{
|
||||
Api: apiStatus,
|
||||
Imported: recv,
|
||||
NotExported: api.Routes{},
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// RoutesFiltered retrieves the routes filtered / not valid
|
||||
func (src *Source) RoutesFiltered(neighborID string) (*api.RoutesResponse, error) {
|
||||
return nil, nil
|
||||
apiStatus := api.ApiStatus{
|
||||
Version: SourceVersion,
|
||||
ResultFromCache: false,
|
||||
Ttl: time.Now().UTC(),
|
||||
}
|
||||
response := &api.RoutesResponse{
|
||||
Api: apiStatus,
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// RoutesNotExported retrievs the routes not exported
|
||||
// from the rs for a neighbor.
|
||||
func (src *Source) RoutesNotExported(neighborID string) (*api.RoutesResponse, error) {
|
||||
return nil, nil
|
||||
apiStatus := api.ApiStatus{
|
||||
Version: SourceVersion,
|
||||
ResultFromCache: false,
|
||||
Ttl: time.Now().UTC(),
|
||||
}
|
||||
response := &api.RoutesResponse{
|
||||
Api: apiStatus,
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// AllRoutes retrievs the entire RIB from the source
|
||||
func (src *Source) AllRoutes() (*api.RoutesResponse, error) {
|
||||
return nil, nil
|
||||
apiStatus := api.ApiStatus{
|
||||
Version: SourceVersion,
|
||||
ResultFromCache: false,
|
||||
Ttl: time.Now().UTC(),
|
||||
}
|
||||
|
||||
req, err := ShowRIBRequest(context.Background(), src)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Read and decode response
|
||||
body, err := decoders.ReadJSONResponse(res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
recv, err := decodeRoutes(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := &api.RoutesResponse{
|
||||
Api: apiStatus,
|
||||
Imported: recv,
|
||||
NotExported: api.Routes{},
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user