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

BGPv1: Introduce generic bgp manager layer #25016

Merged
merged 1 commit into from May 4, 2023

Conversation

harsimran-pabla
Copy link
Contributor

@harsimran-pabla harsimran-pabla commented Apr 20, 2023

BGP subsystem refactor

TLDR

Introducing new manager layer in BGP subsystem, which decouples itself from gobgp structures. Also, using UUID in identifying paths instead of gobgp path pointers. This change is mostly refactoring code and not introducing any functionality.

Motivation/Problem Statement

The BGP subsystem was designed to be modular and support multiple BGP backends. In current architecture, BGP subsystem comprises of three parts controller, reconcilers, and the route manager. Controller works on Kubernetes specific events, whereas reconcilers and route manager use gobgp specific structures.

There is heavy usage of gobgp library in reconcilers and route manager. This raises few concerns

  • If we want to introduce new backend, we will have lot of refactoring to do to achieve it.
  • We are about to add many new features in BGP, which will make this decoupling difficult going forward.
flowchart 
    subgraph agent
        agent:node_spec("node event")
        agent:policy_spec("policy event")
        agent:signal("control loop")
    end
    agent:node_spec---agent:signal
    agent:policy_spec---agent:signal

    subgraph gobgp
        gobgp:router_manager("router manager")
        gobgp:reconcilers("reconcilers")
        gobgp:servers("server configs")
        gobgp:gobgp("gobgp client")
    end
    agent:signal---gobgp:router_manager
    gobgp:router_manager-->gobgp:servers
    gobgp:router_manager-->gobgp:reconcilers
    gobgp:reconcilers-->gobgp:gobgp

Goal

Introduce cilium specific BGP types and use those in reconcilers.

flowchart 
    subgraph agent
        agent:node_spec("node event")
        agent:policy_spec("policy event")
        agent:signal("control loop")
    end
    agent:node_spec---agent:signal
    agent:policy_spec---agent:signal

    subgraph manager
        manager:router_manager("router manager")
        manager:reconcilers("reconcilers")
        manager:servers("server configs")
    end
    agent:signal---manager:router_manager
    manager:router_manager-->manager:servers
    manager:router_manager-->manager:reconcilers

    subgraph types
        types:bgp("cilium bgp")
        types:router("bgp interface")
    end

    subgraph gobgp
    gobgp:gobgp("gobgp client")
    end

    manager:reconcilers-->gobgp:gobgp

Change

This change introduces new manager layer and BGP types which are cilium specific.

  • Reconcilers and route manager is moved into generic manager layer.
    • Configuration is declarative up to the layer
    • Running configuration is stored in route manager, as changes are detected by controller, new declarative config is pushed into route manager.
    • Reconcilers calculate the diff and calls underlying routing process/library.
    • Routing process is called using synchronous API calls, and running state is updated in route manager.
  • Note: this is current behaviour as well, this change is formalizing this contract between reconcilers and underlying routing layer.
  • Generic BGP types are introduced
    • Cilium specific BGP data types
    • Router Spec which underlying routing shim layer implements ( like AddNeighbor, RemoveNeighbor etc )

Impact

There is no functional impact of this change.

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Apr 20, 2023
@harsimran-pabla harsimran-pabla added the release-note/misc This PR makes changes that have no direct user impact. label Apr 20, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Apr 20, 2023
@harsimran-pabla harsimran-pabla marked this pull request as ready for review April 24, 2023 13:10
@harsimran-pabla harsimran-pabla requested a review from a team as a code owner April 24, 2023 13:10
@ldelossa
Copy link
Contributor

@harsimran-pabla I have no major objections to these changes.

I like the idea of creating a generic layer, and the initial set of changes are palpable. I think we get these changes upstream, and then back down stream, we can continue in this direction.

@harsimran-pabla
Copy link
Contributor Author

/test

pkg/bgpv1/gobgp/state.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ldelossa ldelossa left a comment

Choose a reason for hiding this comment

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

general nit, acronyms should be fully capitalized.

s/Asn/ASN
s/Bgp/BGP

and any others.

@harsimran-pabla
Copy link
Contributor Author

@ldelossa Some of the parameters are in gobgp API, which are defining ASN as Asn. :(

@ldelossa
Copy link
Contributor

Aha! totally missed that. Okay, disregard :).

@harsimran-pabla
Copy link
Contributor Author

/test

@harsimran-pabla harsimran-pabla force-pushed the decouple_gobgp branch 3 times, most recently from 23f76e2 to cc3955a Compare May 1, 2023 16:37
@harsimran-pabla
Copy link
Contributor Author

/test

Copy link
Member

@dylandreimerink dylandreimerink left a comment

Choose a reason for hiding this comment

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

LGTM!

@harsimran-pabla
Copy link
Contributor Author

/test-runtime

@harsimran-pabla
Copy link
Contributor Author

/test-1.26-net-next

// WithdrawPath method, making withdrawing an advertised route simple.
type Advertisement struct {
Net *net.IPNet
PathUuid []byte // path identifier in underlying implementation
Copy link
Member

Choose a reason for hiding this comment

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

If this is GoBGP-specific, how about making it clear by name? Like GoBGPPathUuid?

Copy link
Member

Choose a reason for hiding this comment

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

And UUID is an acronym, so can be capitalized.

type BGPGlobal struct {
ASN uint32
RouterID string
ListenPort int32
Copy link
Member

Choose a reason for hiding this comment

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

Better to document why this is signed 32bit (port number is unsigned 16bit in principle) and -1 has a special meaning.

@YutaroHayakawa
Copy link
Member

YutaroHayakawa commented May 2, 2023

I could find some gobgp leftover under the manager package. Some of them are necessary (e.g. NewGoBGPServerWithConfig), but others are not, I think (e.g. "component" field of the log).

$ rg gobgp pkg/bgpv1/manager
pkg/bgpv1/manager/instance.go
9:	"github.com/cilium/cilium/pkg/bgpv1/gobgp"
49:	s, err := gobgp.NewGoBGPServerWithConfig(ctx, log, global)

pkg/bgpv1/manager/manager.go
31:	// 'component=gobgp.{Struct}.{Method}' or 'component=gobgp.{Function}' to
35:	// `subsys=bgp-control-plane`, `component=gobgp.BgpServerInstance` and
52:// This BGPRouterMananger utilizes the gobgp project to implement a BGP routing
183:// registerBGPServer encapsulates the logic for instantiating a gobgp
368:// GetPeers gets peering state from previously initialized gobgp instances.

pkg/bgpv1/manager/reconcile.go
80:// permanent configurations for gobgp BgpServers (ones that cannot be changed after creation)
91:				"component": "gobgp.preflightReconciler",
226:				"component": "gobgp.neighborReconciler",
373:		component: "gobgp.exportPodCIDRReconciler",

Also, we should update the README.md as well.

Copy link
Member

@YutaroHayakawa YutaroHayakawa left a comment

Choose a reason for hiding this comment

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

Made some comments. Most of them are very easy to fix I believe. Otherwise, looks very nice to me 👍

@harsimran-pabla
Copy link
Contributor Author

/test

// The `Net` field makes comparing this Advertisement with another IPNet encoded
// prefixes simple.
//
// The `GoBGPPathUUID` field is a gobgp.GoBGPPathUUID object which can be forwarded to gobgp's
Copy link
Member

Choose a reason for hiding this comment

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

Nit: gobgp.GoBGPPathUUID => gobgp.PathUUID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh this is result of goland magic refactor :)

Copy link
Member

@YutaroHayakawa YutaroHayakawa left a comment

Choose a reason for hiding this comment

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

Now LGTM! @dylandreimerink I'm sorry, I accidentally re-requested your review. Please approve again if necessary 🙇

Introduce new manager layer, which decouples itself from gobgp
structures. Also, using UUID in identifying paths instead of gobgp path pointers.

This change is mostly refactoring code and not introducing any
functionality.

Signed-off-by: harsimran pabla <hpabla@isovalent.com>
@harsimran-pabla
Copy link
Contributor Author

/test

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label May 3, 2023
@joestringer joestringer merged commit d49146f into cilium:main May 4, 2023
56 checks passed
harsimran-pabla added a commit to harsimran-pabla/cilium that referenced this pull request Jun 9, 2023
Updating BGP documentation to match refactor done in cilium#25016.

Signed-off-by: harsimran pabla <hpabla@isovalent.com>
joestringer pushed a commit that referenced this pull request Jun 14, 2023
Updating BGP documentation to match refactor done in #25016.

Signed-off-by: harsimran pabla <hpabla@isovalent.com>
romanspb80 pushed a commit to romanspb80/cilium that referenced this pull request Jun 22, 2023
Updating BGP documentation to match refactor done in cilium#25016.

Signed-off-by: harsimran pabla <hpabla@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bgp ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants