summaryrefslogtreecommitdiffhomepage
path: root/config/default.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-01-23 18:20:54 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-01-25 04:57:11 -0800
commitc21a95bde591d8b409685d021eaff9b3d7852d25 (patch)
tree9b3394cc53b0b362efb9aec1e4ed512dae79bd0b /config/default.go
parentd94f5d2c03b8eb265cfa1af5dce43da7194538b8 (diff)
config: remove hard-coded default address family
address family is now typed as AfiSafiType Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'config/default.go')
-rw-r--r--config/default.go74
1 files changed, 49 insertions, 25 deletions
diff --git a/config/default.go b/config/default.go
index 787a160b..90b7b2ff 100644
--- a/config/default.go
+++ b/config/default.go
@@ -20,19 +20,23 @@ func SetDefaultConfigValues(v *viper.Viper, b *Bgp) error {
v = viper.New()
}
+ defaultAfiSafi := func(typ AfiSafiType, enable bool) AfiSafi {
+ return AfiSafi{
+ AfiSafiName: typ,
+ Config: AfiSafiConfig{
+ AfiSafiName: typ,
+ Enabled: enable,
+ },
+ State: AfiSafiState{
+ AfiSafiName: typ,
+ },
+ }
+ }
+
if !v.IsSet("global.afi-safis") {
- b.Global.AfiSafis = []AfiSafi{
- AfiSafi{AfiSafiName: "ipv4-unicast"},
- AfiSafi{AfiSafiName: "ipv6-unicast"},
- AfiSafi{AfiSafiName: "l3vpn-ipv4-unicast"},
- AfiSafi{AfiSafiName: "l3vpn-ipv6-unicast"},
- AfiSafi{AfiSafiName: "l2vpn-evpn"},
- AfiSafi{AfiSafiName: "encap"},
- AfiSafi{AfiSafiName: "rtc"},
- AfiSafi{AfiSafiName: "ipv4-flowspec"},
- AfiSafi{AfiSafiName: "l3vpn-ipv4-flowspec"},
- AfiSafi{AfiSafiName: "ipv6-flowspec"},
- AfiSafi{AfiSafiName: "l3vpn-ipv6-flowspec"},
+ b.Global.AfiSafis = []AfiSafi{}
+ for k, _ := range AfiSafiTypeToIntMap {
+ b.Global.AfiSafis = append(b.Global.AfiSafis, defaultAfiSafi(k, true))
}
}
@@ -59,21 +63,28 @@ func SetDefaultConfigValues(v *viper.Viper, b *Bgp) error {
// but toml is decoded as []map[string]interface{}.
// currently, viper can't hide this difference.
// handle the difference here.
- var list []interface{}
- intf := v.Get("neighbors")
- if intf != nil {
- var ok bool
- list, ok = intf.([]interface{})
- if !ok {
+ extractArray := func(intf interface{}) ([]interface{}, error) {
+ if intf != nil {
+ list, ok := intf.([]interface{})
+ if ok {
+ return list, nil
+ }
l, ok := intf.([]map[string]interface{})
if !ok {
- return fmt.Errorf("invalid configuration: neighborlist must be a list")
+ return nil, fmt.Errorf("invalid configuration: neither []interface{} nor []map[string]interface{}")
}
list = make([]interface{}, 0, len(l))
for _, m := range l {
list = append(list, m)
}
+ return list, nil
}
+ return nil, nil
+ }
+
+ list, err := extractArray(v.Get("neighbors"))
+ if err != nil {
+ return err
}
for idx, n := range b.Neighbors {
vv := viper.New()
@@ -95,16 +106,29 @@ func SetDefaultConfigValues(v *viper.Viper, b *Bgp) error {
if !vv.IsSet("neighbor.afi-safis") {
if ip := net.ParseIP(n.Config.NeighborAddress); ip.To4() != nil {
- n.AfiSafis = []AfiSafi{
- AfiSafi{AfiSafiName: "ipv4-unicast"},
- }
+ n.AfiSafis = []AfiSafi{defaultAfiSafi(AFI_SAFI_TYPE_IPV4_UNICAST, true)}
} else if ip.To16() != nil {
- n.AfiSafis = []AfiSafi{
- AfiSafi{AfiSafiName: "ipv6-unicast"},
- }
+ n.AfiSafis = []AfiSafi{defaultAfiSafi(AFI_SAFI_TYPE_IPV6_UNICAST, true)}
} else {
return fmt.Errorf("invalid neighbor address: %s", n.Config.NeighborAddress)
}
+ } else {
+ afs, err := extractArray(vv.Get("neighbor.afi-safis"))
+ if err != nil {
+ return err
+ }
+ for i, af := range n.AfiSafis {
+ vvv := viper.New()
+ if len(afs) > i {
+ vvv.Set("afi-safi", afs[i])
+ }
+ af.Config.AfiSafiName = af.AfiSafiName
+ af.State.AfiSafiName = af.AfiSafiName
+ if !vvv.IsSet("afi-safi.config") {
+ af.Config.Enabled = true
+ }
+ n.AfiSafis[i] = af
+ }
}
if !vv.IsSet("neighbor.config.peer-type") {