config

package
v3.25.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 9 Imported by: 5

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitialConfig

func InitialConfig(ctx context.Context, bgpServer *server.BgpServer, newConfig *oc.BgpConfigSet, isGracefulRestart bool) (*oc.BgpConfigSet, error)

InitialConfig applies initial configuration to a pristine gobgp instance. It can only be called once for an instance. Subsequent changes to the configuration can be applied using UpdateConfig. The BgpConfigSet can be obtained by calling ReadConfigFile. If graceful restart behavior is desired, pass true for isGracefulRestart. Otherwise, pass false.

Example

ExampleUpdateConfig shows how InitialConfig can be used without UpdateConfig

bgpServer := server.NewBgpServer()
go bgpServer.Serve()

initialConfig, err := ReadConfigFile("gobgp.conf", "toml")
if err != nil {
	// Handle error
	return
}

isGracefulRestart := true
_, err = InitialConfig(context.Background(), bgpServer, initialConfig, isGracefulRestart)

if err != nil {
	// Handle error
	return
}
Output:

func ReadConfigFile

func ReadConfigFile(configFile, configType string) (*oc.BgpConfigSet, error)

ReadConfigFile parses a config file into a BgpConfigSet which can be applied using InitialConfig and UpdateConfig.

func UpdateConfig

func UpdateConfig(ctx context.Context, bgpServer *server.BgpServer, c, newConfig *oc.BgpConfigSet) (*oc.BgpConfigSet, error)

UpdateConfig updates the configuration of a running gobgp instance. InitialConfig must have been called once before this can be called for subsequent changes to config. The differences are that this call 1) does not hangle graceful restart and 2) requires a BgpConfigSet for the previous configuration so that it can compute the delta between it and the new config. The new BgpConfigSet can be obtained using ReadConfigFile.

Example

ExampleUpdateConfig shows how UpdateConfig is used in conjunction with InitialConfig.

bgpServer := server.NewBgpServer()
go bgpServer.Serve()

initialConfig, err := ReadConfigFile("gobgp.conf", "toml")
if err != nil {
	// Handle error
	return
}

isGracefulRestart := true
currentConfig, err := InitialConfig(context.Background(), bgpServer, initialConfig, isGracefulRestart)

if err != nil {
	// Handle error
	return
}

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGHUP)

for range sigCh {
	newConfig, err := ReadConfigFile("gobgp.conf", "toml")
	if err != nil {
		// Handle error
		continue
	}

	currentConfig, err = UpdateConfig(context.Background(), bgpServer, currentConfig, newConfig)
	if err != nil {
		// Handle error
		continue
	}
}
Output:

func WatchConfigFile added in v3.20.0

func WatchConfigFile(configFile, configType string, callBack func())

WatchConfigFile calls the callback function anytime an update to the config file is detected.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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