summaryrefslogtreecommitdiffhomepage
path: root/config/default.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-01-02 02:13:30 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-01-09 05:17:57 -0800
commitcc8d0fd748f83d774ec59e680586421cd9d9a6d2 (patch)
tree393a564c3d6389084f098732528b3b4206cd60de /config/default.go
parent0c1c373e498db1023e4f307f362598a096e36df0 (diff)
config: refactor config structure
- change config variable name to chaincase from camelcase - remove unnecessary wrapper structs which only contain one slice field Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'config/default.go')
-rw-r--r--config/default.go66
1 files changed, 33 insertions, 33 deletions
diff --git a/config/default.go b/config/default.go
index 0cc55680..82a17446 100644
--- a/config/default.go
+++ b/config/default.go
@@ -5,7 +5,6 @@ import (
"github.com/osrg/gobgp/packet"
"github.com/spf13/viper"
"net"
- "strings"
)
const (
@@ -20,8 +19,8 @@ func SetDefaultConfigValues(v *viper.Viper, b *Bgp) error {
if v == nil {
v = viper.New()
}
- if !v.IsSet("global.afisafis.afisafilist") {
- b.Global.AfiSafis.AfiSafiList = []AfiSafi{
+ if !v.IsSet("global.afi-safis") {
+ b.Global.AfiSafis = []AfiSafi{
AfiSafi{AfiSafiName: "ipv4-unicast"},
AfiSafi{AfiSafiName: "ipv6-unicast"},
AfiSafi{AfiSafiName: "l3vpn-ipv4-unicast"},
@@ -40,65 +39,66 @@ func SetDefaultConfigValues(v *viper.Viper, b *Bgp) error {
b.Global.ListenConfig.Port = bgp.BGP_PORT
}
- for idx, server := range b.BmpServers.BmpServerList {
+ for idx, server := range b.BmpServers {
if server.Config.Port == 0 {
server.Config.Port = bgp.BMP_DEFAULT_PORT
}
- b.BmpServers.BmpServerList[idx] = server
+ b.BmpServers[idx] = server
}
- if !v.IsSet("global.mplslabelrange.minlabel") {
+ if !v.IsSet("global.mpls-label-range.min-label") {
b.Global.MplsLabelRange.MinLabel = DEFAULT_MPLS_LABEL_MIN
}
- if !v.IsSet("global.mplslabelrange.maxlabel") {
+ if !v.IsSet("global.mpls-label-range.max-label") {
b.Global.MplsLabelRange.MaxLabel = DEFAULT_MPLS_LABEL_MAX
}
+
+ // yaml is decoded as []interface{}
+ // but toml is decoded as []map[string]interface{}.
+ // currently, viper can't hide this difference.
+ // handle the difference here.
var list []interface{}
- for k, val := range v.GetStringMap("neighbors") {
- if strings.ToLower(k) == "neighborlist" {
- var ok bool
- // yaml is decoded as []interface{}
- // but toml is decoded as []map[string]interface{}.
- // currently, viper can't hide this difference.
- // handle the difference here.
- list, ok = val.([]interface{})
+ intf := v.Get("neighbors")
+ if intf != nil {
+ var ok bool
+ list, ok = intf.([]interface{})
+ if !ok {
+ l, ok := intf.([]map[string]interface{})
if !ok {
- l, ok := val.([]map[string]interface{})
- if !ok {
- return fmt.Errorf("invalid configuration: neighborlist must be a list")
- }
- for _, m := range l {
- list = append(list, m)
- }
+ return fmt.Errorf("invalid configuration: neighborlist must be a list")
+ }
+ list = make([]interface{}, 0, len(l))
+ for _, m := range l {
+ list = append(list, m)
}
}
}
- for idx, n := range b.Neighbors.NeighborList {
+ for idx, n := range b.Neighbors {
vv := viper.New()
if len(list) > idx {
vv.Set("neighbor", list[idx])
}
- if !vv.IsSet("neighbor.timers.config.connectretry") {
+ if !vv.IsSet("neighbor.timers.config.connect-retry") {
n.Timers.Config.ConnectRetry = float64(DEFAULT_CONNECT_RETRY)
}
- if !vv.IsSet("neighbor.timers.config.holdtime") {
+ if !vv.IsSet("neighbor.timers.config.hold-time") {
n.Timers.Config.HoldTime = float64(DEFAULT_HOLDTIME)
}
- if !vv.IsSet("neighbor.timers.config.keepaliveinterval") {
+ if !vv.IsSet("neighbor.timers.config.keepalive-interval") {
n.Timers.Config.KeepaliveInterval = n.Timers.Config.HoldTime / 3
}
- if !vv.IsSet("neighbor.timers.config.idleholdtimeafterreset") {
+ if !vv.IsSet("neighbor.timers.config.idle-hold-time-after-reset") {
n.Timers.Config.IdleHoldTimeAfterReset = float64(DEFAULT_IDLE_HOLDTIME_AFTER_RESET)
}
- if !vv.IsSet("neighbor.afisafis.afisafilist") {
+ if !vv.IsSet("neighbor.afi-safis") {
if ip := net.ParseIP(n.Config.NeighborAddress); ip.To4() != nil {
- n.AfiSafis.AfiSafiList = []AfiSafi{
+ n.AfiSafis = []AfiSafi{
AfiSafi{AfiSafiName: "ipv4-unicast"},
}
} else if ip.To16() != nil {
- n.AfiSafis.AfiSafiList = []AfiSafi{
+ n.AfiSafis = []AfiSafi{
AfiSafi{AfiSafiName: "ipv6-unicast"},
}
} else {
@@ -106,17 +106,17 @@ func SetDefaultConfigValues(v *viper.Viper, b *Bgp) error {
}
}
- if !vv.IsSet("neighbor.config.peertype") {
+ if !vv.IsSet("neighbor.config.peer-type") {
if n.Config.PeerAs != b.Global.Config.As {
n.Config.PeerType = PEER_TYPE_EXTERNAL
} else {
n.Config.PeerType = PEER_TYPE_INTERNAL
}
}
- b.Neighbors.NeighborList[idx] = n
+ b.Neighbors[idx] = n
}
- for _, r := range b.RpkiServers.RpkiServerList {
+ for _, r := range b.RpkiServers {
if r.Config.Port == 0 {
r.Config.Port = bgp.RPKI_DEFAULT_PORT
}