summaryrefslogtreecommitdiffhomepage
path: root/config
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-04-05 16:26:23 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-04-19 11:12:44 +0000
commitdaaa9302baae4259eb89c23f65cfcfc361d547bc (patch)
tree83442f77ab9889b4d2a6d83cb01a9bf1f66c2daf /config
parent642270bb32db2a0a55badf6a53076aeac2dfb215 (diff)
config/gobgpd: refactoring
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'config')
-rw-r--r--config/default.go2
-rw-r--r--config/serve.go63
2 files changed, 27 insertions, 38 deletions
diff --git a/config/default.go b/config/default.go
index 7431d267..6d70e9e5 100644
--- a/config/default.go
+++ b/config/default.go
@@ -17,7 +17,7 @@ const (
DEFAULT_MPLS_LABEL_MAX = 1048575
)
-func SetDefaultConfigValues(v *viper.Viper, b *Bgp) error {
+func SetDefaultConfigValues(v *viper.Viper, b *BgpConfigSet) error {
if v == nil {
v = viper.New()
}
diff --git a/config/serve.go b/config/serve.go
index afa8f340..e88cb74e 100644
--- a/config/serve.go
+++ b/config/serve.go
@@ -10,59 +10,41 @@ import (
)
type BgpConfigSet struct {
- Bgp Bgp
- Policy RoutingPolicy
+ Global Global `mapstructure:"global"`
+ Neighbors []Neighbor `mapstructure:"neighbors"`
+ PeerGroups []PeerGroup `mapstructure:"peer-groups"`
+ RpkiServers []RpkiServer `mapstructure:"rpki-servers"`
+ BmpServers []BmpServer `mapstructure:"bmp-servers"`
+ MrtDump []Mrt `mapstructure:"mrt-dump"`
+ DefinedSets DefinedSets `mapstructure:"defined-sets"`
+ PolicyDefinitions []PolicyDefinition `mapstructure:"policy-definitions"`
}
-func ReadConfigfileServe(path, format string, configCh chan BgpConfigSet) {
+func ReadConfigfileServe(path, format string, configCh chan *BgpConfigSet) {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGHUP)
cnt := 0
for {
- var b *Bgp
+ c := &BgpConfigSet{}
v := viper.New()
v.SetConfigFile(path)
v.SetConfigType(format)
- err := v.ReadInConfig()
- c := struct {
- Global Global `mapstructure:"global"`
- Neighbors []Neighbor `mapstructure:"neighbors"`
- RpkiServers []RpkiServer `mapstructure:"rpki-servers"`
- BmpServers []BmpServer `mapstructure:"bmp-servers"`
- MrtDump []Mrt `mapstructure:"mrt-dump"`
- DefinedSets DefinedSets `mapstructure:"defined-sets"`
- PolicyDefinitions []PolicyDefinition `mapstructure:"policy-definitions"`
- }{}
- if err != nil {
+ var err error
+ if err = v.ReadInConfig(); err != nil {
goto ERROR
}
- err = v.UnmarshalExact(&c)
- if err != nil {
+ if err = v.UnmarshalExact(c); err != nil {
goto ERROR
}
- b = &Bgp{
- Global: c.Global,
- Neighbors: c.Neighbors,
- RpkiServers: c.RpkiServers,
- BmpServers: c.BmpServers,
- MrtDump: c.MrtDump,
- }
- err = SetDefaultConfigValues(v, b)
- if err != nil {
+ if err = SetDefaultConfigValues(v, c); err != nil {
goto ERROR
}
if cnt == 0 {
log.Info("finished reading the config file")
}
cnt++
- configCh <- BgpConfigSet{
- Bgp: *b,
- Policy: RoutingPolicy{
- DefinedSets: c.DefinedSets,
- PolicyDefinitions: c.PolicyDefinitions,
- },
- }
+ configCh <- c
select {
case <-sigCh:
log.Info("reload the config file")
@@ -88,11 +70,18 @@ func inSlice(n Neighbor, b []Neighbor) int {
return -1
}
-func UpdateConfig(curC *Bgp, newC *Bgp) (*Bgp, []Neighbor, []Neighbor, []Neighbor) {
- bgpConfig := Bgp{}
+func ConfigSetToRoutingPolicy(c *BgpConfigSet) *RoutingPolicy {
+ return &RoutingPolicy{
+ DefinedSets: c.DefinedSets,
+ PolicyDefinitions: c.PolicyDefinitions,
+ }
+}
+
+func UpdateConfig(curC *BgpConfigSet, newC *BgpConfigSet) (*BgpConfigSet, []Neighbor, []Neighbor, []Neighbor, bool) {
+ bgpConfig := &BgpConfigSet{}
if curC == nil {
bgpConfig.Global = newC.Global
- curC = &bgpConfig
+ curC = bgpConfig
} else {
// can't update the global config
bgpConfig.Global = curC.Global
@@ -118,7 +107,7 @@ func UpdateConfig(curC *Bgp, newC *Bgp) (*Bgp, []Neighbor, []Neighbor, []Neighbo
}
bgpConfig.Neighbors = newC.Neighbors
- return &bgpConfig, added, deleted, updated
+ return bgpConfig, added, deleted, updated, CheckPolicyDifference(ConfigSetToRoutingPolicy(curC), ConfigSetToRoutingPolicy(newC))
}
func CheckPolicyDifference(currentPolicy *RoutingPolicy, newPolicy *RoutingPolicy) bool {