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 t
(ctx context.Context, bgpServer *server.BgpServer, newConfig *oc.BgpConfigSet, isGracefulRestart bool)
| 238 | // obtained by calling ReadConfigFile. If graceful restart behavior is desired, |
| 239 | // pass true for isGracefulRestart. Otherwise, pass false. |
| 240 | func InitialConfig(ctx context.Context, bgpServer *server.BgpServer, newConfig *oc.BgpConfigSet, isGracefulRestart bool) (*oc.BgpConfigSet, error) { |
| 241 | if err := bgpServer.StartBgp(ctx, &api.StartBgpRequest{ |
| 242 | Global: oc.NewGlobalFromConfigStruct(&newConfig.Global), |
| 243 | }); err != nil { |
| 244 | return nil, err |
| 245 | } |
| 246 | |
| 247 | if newConfig.Zebra.Config.Enabled { |
| 248 | tps := newConfig.Zebra.Config.RedistributeRouteTypeList |
| 249 | l := make([]string, 0, len(tps)) |
| 250 | l = append(l, tps...) |
| 251 | if err := bgpServer.EnableZebra(ctx, &api.EnableZebraRequest{ |
| 252 | Url: newConfig.Zebra.Config.Url, |
| 253 | RouteTypes: l, |
| 254 | Version: uint32(newConfig.Zebra.Config.Version), |
| 255 | NexthopTriggerEnable: newConfig.Zebra.Config.NexthopTriggerEnable, |
| 256 | NexthopTriggerDelay: uint32(newConfig.Zebra.Config.NexthopTriggerDelay), |
| 257 | MplsLabelRangeSize: newConfig.Zebra.Config.MplsLabelRangeSize, |
| 258 | SoftwareName: newConfig.Zebra.Config.SoftwareName, |
| 259 | }); err != nil { |
| 260 | bgpServer.Log().Error("failed to set zebra config", |
| 261 | slog.String("Topic", "config"), slog.Any("Error", err)) |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | if len(newConfig.Collector.Config.Url) > 0 { |
| 266 | bgpServer.Log().Error("collector feature is not supported", |
| 267 | slog.String("Topic", "config")) |
| 268 | } |
| 269 | |
| 270 | for _, c := range newConfig.RpkiServers { |
| 271 | if err := bgpServer.AddRpki(ctx, &api.AddRpkiRequest{ |
| 272 | Address: c.Config.Address.String(), |
| 273 | Port: c.Config.Port, |
| 274 | Lifetime: c.Config.RecordLifetime, |
| 275 | }); err != nil { |
| 276 | bgpServer.Log().Error("failed to set rpki config", |
| 277 | slog.String("Topic", "config"), slog.Any("Error", err)) |
| 278 | } |
| 279 | } |
| 280 | f := func(t oc.BmpRouteMonitoringPolicyType) api.AddBmpRequest_MonitoringPolicy { |
| 281 | switch t { |
| 282 | case oc.BMP_ROUTE_MONITORING_POLICY_TYPE_PRE_POLICY: |
| 283 | return api.AddBmpRequest_MONITORING_POLICY_PRE |
| 284 | case oc.BMP_ROUTE_MONITORING_POLICY_TYPE_POST_POLICY: |
| 285 | return api.AddBmpRequest_MONITORING_POLICY_POST |
| 286 | case oc.BMP_ROUTE_MONITORING_POLICY_TYPE_BOTH: |
| 287 | return api.AddBmpRequest_MONITORING_POLICY_BOTH |
| 288 | case oc.BMP_ROUTE_MONITORING_POLICY_TYPE_LOCAL_RIB: |
| 289 | return api.AddBmpRequest_MONITORING_POLICY_LOCAL |
| 290 | case oc.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL: |
| 291 | return api.AddBmpRequest_MONITORING_POLICY_ALL |
| 292 | } |
| 293 | return api.AddBmpRequest_MONITORING_POLICY_UNSPECIFIED |
| 294 | } |
| 295 | |
| 296 | for _, c := range newConfig.BmpServers { |
| 297 | if err := bgpServer.AddBmp(ctx, &api.AddBmpRequest{ |
searching dependent graphs…