osrg / gobgp

BGP implemented in the Go Programming Language
https://osrg.github.io/gobgp/
Apache License 2.0
3.66k stars 699 forks source link

How to use `ListPath` to get OpenConfig BGP RIB information? #2765

Closed wenovus closed 8 months ago

wenovus commented 9 months ago

TLDR: The API behaviour of ListPath is hard to understand. After experimentation I can't get the correct information to populate OpenConfig BGP RIB schema. Specifically, ListPath may be incorrectly populating path attributes for post-policy ADJ_IN.

Ask: Requesting guidance on how to use or improve this API to get pre/post-policy ADJ_IN/ADJ_OUT RIB information.

Background

I'm using ListPath with ADJ_IN and ADJ_OUT to get the BGP RIB for the following types of RIBs:

The use case is to populate the BGP RIBs defined in OpenConfig.

Problem

At first, the EnableFiltered parameter seems to do what I want: it applies the policies, and marks each route as either "filtered", (or rejected).

Case/Attempt 1

So I did this:

Observations

Case/Attempt 2

So now I tried flipping EnableFiltered for adj-rib-out-*:

Observations

Case 2 is tested here: https://github.com/osrg/gobgp/pull/2764, which shows the incorrect adj-rib-in-post results (last added test case)

Case/Attempt 3

So now I tried flipping EnableFiltered for adj-rib-in-* as well:

Observations


Based on the above Case 2 was the closest the behaviour I expected., but for ADJ_IN, the community attribute of the IMPORT policy was not being applied.

I tried to understand the code at https://github.com/osrg/gobgp/blob/8fdda5dd2d6442c7c03636831bc536b67daa8f65/pkg/server/server.go#L2614-L2645 but I could not make sense of the code to the above behaviours.

Requesting guidance on how to use or improve this API to get pre/post-policy ADJ_IN/ADJ_OUT RIB information.

fujita commented 9 months ago

In the case of the global rib (not route server case),

adj-in -> in-filter -> the global rib -> out-filter -> adj-out

ListPath with ADJ_IN and EnableFiltered=false gets adj-in ListPath with ADJ_IN and EnableFiltered=true gets routes between in-filter and the global rib ListPath with ADJ_OUT and EnableFiltered=false gets routes between the global rib and out-filter ListPath with ADJ_OUT and EnableFiltered=true gets routes adj-out

wenovus commented 9 months ago

In the case of the global rib (not route server case),

adj-in -> in-filter -> the global rib -> out-filter -> adj-out

ListPath with ADJ_IN and EnableFiltered=false gets adj-in ListPath with ADJ_IN and EnableFiltered=true gets routes between in-filter and the global rib ListPath with ADJ_OUT and EnableFiltered=false gets routes between the global rib and out-filter ListPath with ADJ_OUT and EnableFiltered=true gets routes adj-out

Hi Fujita, this is also what I first assumed and tried in "Case/Attempt 1" above, but I observed that it didn't work.

See the test failures here: https://github.com/osrg/gobgp/pull/2764 -- I tried all the permutations of EnableFiltered=false/true and the closest I got was "Case/Attempt 2" -- there was no way of getting the "routes between in-filter and the global rib" with the correct community attributes populated.

fujita commented 8 months ago

Very sorry about the delay. I was wrong. EnableFiltered sets path.Filtered if a path is dropped by a policy. The current API doesn't give the information that you need. I think that we needs a new option like AppliedPolicies.

wenovus commented 8 months ago

Very sorry about the delay. I was wrong. EnableFiltered sets path.Filtered if a path is dropped by a policy. The current API doesn't give the information that you need. I think that we needs a new option like AppliedPolicies.

What you just described is actually the behaviour I want -- the issue is that I'm not seeing the same thing. In particular the community attributes at adj-rib-in-post cannot be populated by any flag permutation.

fujita commented 8 months ago

The current API doesn't provide routes between in-filter and the global rib because the CLI doesn't need to provide such. You could get routes from the global rib and filter these routes from a particular peer.

wenovus commented 8 months ago

The current API doesn't provide routes between in-filter and the global rib because the CLI doesn't need to provide such. You could get routes from the global rib and filter these routes from a particular peer.

I still think the API was intended to get what I wanted, but because the CLI was the primary use case that's why the community attributes weren't populated correctly.

Opened https://github.com/osrg/gobgp/pull/2784 to fix this and make the behaviour conform to "Case/Attempt 2" described above.

wenovus commented 8 months ago

Even though the semantics is still confusing, "Case/Attempt 2" is now working so the requested behaviour is now possible. I'll consider this closed.