mirror of
https://github.com/osrg/gobgp.git
synced 2024-05-11 05:55:10 +00:00
config: set default config value only when not specified
Signed-off-by: FUJITA Tomonori <[email protected]>
This commit is contained in:
+34
-12
@@ -1,22 +1,44 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/BurntSushi/toml"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_HOLDTIME = 90
|
||||
DEFAULT_IDLE_HOLDTIME_AFTER_RESET = 30
|
||||
)
|
||||
|
||||
func setTimersTypeDefault(timersT *TimersType) {
|
||||
if timersT.HoldTime == 0 {
|
||||
timersT.HoldTime = float64(DEFAULT_HOLDTIME)
|
||||
}
|
||||
if timersT.KeepaliveInterval == 0 {
|
||||
timersT.KeepaliveInterval = timersT.HoldTime / 3
|
||||
}
|
||||
if timersT.IdleHoldTImeAfterReset == 0 {
|
||||
timersT.IdleHoldTImeAfterReset = float64(DEFAULT_IDLE_HOLDTIME_AFTER_RESET)
|
||||
}
|
||||
type neighbor struct {
|
||||
attributes map[string]bool
|
||||
}
|
||||
|
||||
func SetNeighborTypeDefault(neighborT *NeighborType) {
|
||||
setTimersTypeDefault(&neighborT.Timers)
|
||||
func SetDefaultConfigValues(md toml.MetaData, bt *BgpType) {
|
||||
neighbors := []neighbor{}
|
||||
|
||||
nidx := 0
|
||||
for _, key := range md.Keys() {
|
||||
if !strings.HasPrefix(key.String(), "NeighborList") {
|
||||
continue
|
||||
}
|
||||
if key.String() == "NeighborList" {
|
||||
neighbors = append(neighbors, neighbor{attributes: make(map[string]bool)})
|
||||
nidx++
|
||||
} else {
|
||||
neighbors[nidx-1].attributes[key.String()] = true
|
||||
}
|
||||
}
|
||||
for i, n := range neighbors {
|
||||
if _, ok := n.attributes["NeighborList.Timers.HoldTime"]; !ok {
|
||||
bt.NeighborList[i].Timers.HoldTime = float64(DEFAULT_HOLDTIME)
|
||||
}
|
||||
if _, ok := n.attributes["NeighborList.Timers.KeepaliveInterval"]; !ok {
|
||||
bt.NeighborList[i].Timers.KeepaliveInterval = bt.NeighborList[i].Timers.HoldTime / 3
|
||||
}
|
||||
|
||||
if _, ok := n.attributes["NeighborList.Timers.IdleHoldTImeAfterReset"]; !ok {
|
||||
bt.NeighborList[i].Timers.IdleHoldTImeAfterReset = float64(DEFAULT_IDLE_HOLDTIME_AFTER_RESET)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-6
@@ -10,14 +10,11 @@ func ReadConfigfileServe(path string, configCh chan BgpType, reloadCh chan bool)
|
||||
<-reloadCh
|
||||
|
||||
b := BgpType{}
|
||||
_, err := toml.DecodeFile(path, &b)
|
||||
md, err := toml.DecodeFile(path, &b)
|
||||
if err != nil {
|
||||
log.Fatal("can't read config file ", path)
|
||||
log.Fatal("can't read config file ", path, err)
|
||||
} else {
|
||||
// TODO: validate configuration
|
||||
for i, _ := range b.NeighborList {
|
||||
SetNeighborTypeDefault(&b.NeighborList[i])
|
||||
}
|
||||
SetDefaultConfigValues(md, &b)
|
||||
}
|
||||
|
||||
configCh <- b
|
||||
|
||||
Reference in New Issue
Block a user