From cff2b01d1dc00eadfed8c219c3d7c40018e8ad9c Mon Sep 17 00:00:00 2001 From: Carl Baldwin Date: Wed, 24 Jul 2019 09:01:32 -0600 Subject: Create a clearer line between initial config and updating config --- cmd/gobgpd/main.go | 55 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'cmd/gobgpd') diff --git a/cmd/gobgpd/main.go b/cmd/gobgpd/main.go index 8dd0cd52..433bd9ab 100644 --- a/cmd/gobgpd/main.go +++ b/cmd/gobgpd/main.go @@ -317,10 +317,6 @@ func main() { } return case newConfig := <-configCh: - var added, deleted, updated []config.Neighbor - var addedPg, deletedPg, updatedPg []config.PeerGroup - var updatePolicy bool - if c == nil { if err := bgpServer.StartBgp(context.Background(), &api.StartBgpRequest{ Global: config.NewGlobalFromConfigStruct(&newConfig.Global), @@ -425,8 +421,8 @@ func main() { assignGlobalpolicy(bgpServer, &newConfig.Global.ApplyPolicy.Config) - added = newConfig.Neighbors - addedPg = newConfig.PeerGroups + added := newConfig.Neighbors + addedPg := newConfig.PeerGroups if opts.GracefulRestart { for i, n := range added { if n.GracefulRestart.Config.Enabled { @@ -434,10 +430,14 @@ func main() { } } } + + addPeerGroups(bgpServer, addedPg) + addDynamicNeighbors(bgpServer, newConfig.DynamicNeighbors) + addNeighbors(bgpServer, added) } else { - addedPg, deletedPg, updatedPg = config.UpdatePeerGroupConfig(c, newConfig) - added, deleted, updated = config.UpdateNeighborConfig(c, newConfig) - updatePolicy = config.CheckPolicyDifference(config.ConfigSetToRoutingPolicy(c), config.ConfigSetToRoutingPolicy(newConfig)) + addedPg, deletedPg, updatedPg := config.UpdatePeerGroupConfig(c, newConfig) + added, deleted, updated := config.UpdateNeighborConfig(c, newConfig) + updatePolicy := config.CheckPolicyDifference(config.ConfigSetToRoutingPolicy(c), config.ConfigSetToRoutingPolicy(newConfig)) if updatePolicy { log.Info("Policy config is updated") @@ -457,24 +457,25 @@ func main() { assignGlobalpolicy(bgpServer, &newConfig.Global.ApplyPolicy.Config) updatePolicy = true } - } - addPeerGroups(bgpServer, addedPg) - deletePeerGroups(bgpServer, deletedPg) - needsSoftResetIn := updatePeerGroups(bgpServer, updatedPg) - updatePolicy = updatePolicy || needsSoftResetIn - addDynamicNeighbors(bgpServer, newConfig.DynamicNeighbors) - addNeighbors(bgpServer, added) - deleteNeighbors(bgpServer, deleted) - needsSoftResetIn = updateNeighbors(bgpServer, updated) - updatePolicy = updatePolicy || needsSoftResetIn - - if updatePolicy { - if err := bgpServer.ResetPeer(context.Background(), &api.ResetPeerRequest{ - Address: "", - Direction: api.ResetPeerRequest_IN, - Soft: true, - }); err != nil { - log.Warn(err) + + addPeerGroups(bgpServer, addedPg) + deletePeerGroups(bgpServer, deletedPg) + needsSoftResetIn := updatePeerGroups(bgpServer, updatedPg) + updatePolicy = updatePolicy || needsSoftResetIn + addDynamicNeighbors(bgpServer, newConfig.DynamicNeighbors) + addNeighbors(bgpServer, added) + deleteNeighbors(bgpServer, deleted) + needsSoftResetIn = updateNeighbors(bgpServer, updated) + updatePolicy = updatePolicy || needsSoftResetIn + + if updatePolicy { + if err := bgpServer.ResetPeer(context.Background(), &api.ResetPeerRequest{ + Address: "", + Direction: api.ResetPeerRequest_IN, + Soft: true, + }); err != nil { + log.Warn(err) + } } } c = newConfig -- cgit v1.2.3