diff options
author | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-11-24 23:37:04 -0500 |
---|---|---|
committer | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-11-24 23:37:04 -0500 |
commit | fd9f3797aa886513210b65a7791ecb745c758d15 (patch) | |
tree | 88943e034102d25a675970355744f5683ada67d6 | |
parent | 8c7772f5d5a55d52cca2d4e8593f5884cdb6ea2a (diff) |
gobgpd: support global policy assignment update via configuration file
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | gobgpd/main.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/gobgpd/main.go b/gobgpd/main.go index 8ecc8877..4ee76bd7 100644 --- a/gobgpd/main.go +++ b/gobgpd/main.go @@ -24,6 +24,7 @@ import ( "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet/bgp" "github.com/osrg/gobgp/server" + "github.com/osrg/gobgp/table" "io/ioutil" "log/syslog" "net/http" @@ -250,6 +251,40 @@ func main() { p := config.ConfigSetToRoutingPolicy(newConfig) bgpServer.UpdatePolicy(*p) } + // global policy update + if !newConfig.Global.ApplyPolicy.Config.Equal(&c.Global.ApplyPolicy.Config) { + a := newConfig.Global.ApplyPolicy.Config + toDefaultTable := func(r config.DefaultPolicyType) table.RouteType { + var def table.RouteType + switch r { + case config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE: + def = table.ROUTE_TYPE_ACCEPT + case config.DEFAULT_POLICY_TYPE_REJECT_ROUTE: + def = table.ROUTE_TYPE_REJECT + } + return def + } + toPolicyDefinitions := func(r []string) []*config.PolicyDefinition { + p := make([]*config.PolicyDefinition, 0, len(r)) + for _, n := range r { + p = append(p, &config.PolicyDefinition{ + Name: n, + }) + } + return p + } + + def := toDefaultTable(a.DefaultImportPolicy) + ps := toPolicyDefinitions(a.ImportPolicyList) + bgpServer.ReplacePolicyAssignment("", table.POLICY_DIRECTION_IMPORT, ps, def) + + def = toDefaultTable(a.DefaultExportPolicy) + ps = toPolicyDefinitions(a.ExportPolicyList) + bgpServer.ReplacePolicyAssignment("", table.POLICY_DIRECTION_EXPORT, ps, def) + + updatePolicy = true + + } c = newConfig } |