summaryrefslogtreecommitdiffhomepage
path: root/config/default.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-02-25 21:45:26 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-02-25 21:45:26 +0900
commit149f1f2ea90e9d92a5839a45dcd8e533d0055efe (patch)
treeaa72a87e169c02a6dbe78fa60e681324dcbc78d9 /config/default.go
parent8d1ad9a4bdb4206e3a1999f74b8979a3bb55761e (diff)
config: set default config value only when not specified
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'config/default.go')
-rw-r--r--config/default.go46
1 files changed, 34 insertions, 12 deletions
diff --git a/config/default.go b/config/default.go
index f4a2e301..dcb1b7ed 100644
--- a/config/default.go
+++ b/config/default.go
@@ -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)
+ }
+ }
}