gobgp

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

Ligato BGP GoBGP Plugin

The Ligato GoBGP plugin is a Ligato CN-Infra Plugin implementation using GoBGP Library as source of the BGP information.

arch

GoBGP library uses the BGP protocol to retrieve the information from the neighbour nodes (i.e. Route reflector) and reflects them to the GoBGP plugin. Currently, the GoBGP plugin accepts only the IPv4 reachable routes from the GoBGP library. The reachable routes are afterwards forwarded to all registered watchers of the GoBGP plugin.

To acquire IPv4 reachable routes using GoBGP plugin we must do 2 things:

  1. Configure GoBGP library to communicate to neighbours(i.e. to Route Reflector). We can do this by injecting configuration into constructor gobgp.New(...), i.e.:
import "github.com/osrg/gobgp/config"
...
  gobgp.New(Deps{
    SessionConfig: &config.Bgp{
	  Global: config.Global{    //configuring goBGP network node
	    Config: config.GlobalConfig{
	      As:       65000,
	      RouterId: "172.18.0.1",
	      Port:     -1,
	    },
	  },      ...
      Neighbors: []config.Neighbor{   //configuring initially known neighbors
        config.Neighbor{
          Config: config.NeighborConfig{
            PeerAs:          65001,
            NeighborAddress: "172.18.0.2",
          },
        },
      },
    },
  })

or by using external yaml configuration file. For example, if we name the plugin goBgpPlugin

goBgpPlugin := gobgp.New(gobgp.Deps{
    PluginInfraDeps: *flavor.InfraDeps("goBgpPlugin", local.WithConf()),...})

then we can define absolute path to the plugin's config by adding parameter to the go program launch

[terminal]$ go run main.go --goBgpPlugin-config=/home/user/myexternalconfig.yaml

In case of using both configuration methods, the external configuration is more important and will overrride any injected configuration. 2. Become registered watcher of GoBGP plugin. We can do it by using WatchIPRoutes(...), i.e.:

	// start watching
	watchRegistration, startErr := gobgpPlugin.WatchIPRoutes("watcherName1", func(route *bgp.ReachableIPRoute) {
		fmt.Printf("Just received new IPv4 reachable route: %+v ", route)
	})
	...
	// end watching
	closeErr := watchRegistration.Close()

For further usage please look into our example.

Documentation

Overview

Package gobgp contains Ligato GoBGP Plugin implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	local.PluginInfraDeps             // inject
	SessionConfig         *config.Bgp // optional inject (if not injected, it must be set using external config file)
}

Deps combines all needed dependencies for Plugin struct. These dependencies should be injected into Plugin by using constructor's Deps parameter.

type Plugin

type Plugin struct {
	Deps
	// contains filtered or unexported fields
}

Plugin is GoBGP Ligato BGP Plugin implementation. Purpose of this plugin is to retrieve BGP related information and expose it to watchers that can register to this plugin. To be able to communicate using BGP communication protocol, this plugin uses GoBGP library

func New

func New(dependencies Deps) *Plugin

New creates a GoBGP Ligato BGP Plugin implementation. Needed <dependencies> are injected into plugin implementation.

func (*Plugin) AfterInit

func (plugin *Plugin) AfterInit() error

AfterInit starts gobgp with dedicated goroutine for watching gobgp and forwarding best path reachable ip routes to registered watchers. After start of gobgp session, known neighbors from configuration are added to gobgp server. AfterInit fails if session start or adding of known neighbors from configuration fails. Due to fact that AfterInit is called once Init() of all plugins have returned without error, other plugins can be registered watchers from the start of gobgp server if they call this plugin's WatchIPRoutes() in their Init(). In this way they won't miss any information forwarded to registered watchers just because they registered too late.

func (*Plugin) Close

func (plugin *Plugin) Close() error

Close stops dedicated goroutine for watching gobgp. Then stops watcher provider by gobgp server and finally stops that gobgp server itself. Close will fail if bgpServer fails to stop.

func (*Plugin) Init

func (plugin *Plugin) Init() error

Init creates the gobgp server and checks if needed SessionConfig was injected and fails if it is not.

func (*Plugin) WatchIPRoutes

func (plugin *Plugin) WatchIPRoutes(watcher string, callback func(*bgp.ReachableIPRoute)) (bgp.WatchRegistration, error)

WatchIPRoutes register watcher to notifications for any new learned IP-based routes. Watcher have to identify himself by name(<watcher> param) and provide <callback> so that GoBGP can sent information to watcher. WatchIPRoutes returns <bgp.WatchRegistration> as way how to control the watcher-goBGPlugin agreement from the watcher side in the future. It also returns error to indicate failure, but currently for this plugin is not known use case of failure. WatchRegistration is not retroactive, that means that any IP-based routes learned in the past are not send to new watchers. This also means that if you want be notified of all learned IP-based routes, you must register before calling of AfterInit(). In case of external(=not other plugin started with this plugin) watchers this means before plugin start. However, late-registered watchers are permitted (no error will be returned), but they can miss some learned IP-based routes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL