summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-12-06 10:20:09 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-12-29 14:47:06 +0900
commitd01c1586b9b1a25965448f9e15a05d94f2b22a5f (patch)
tree744609e474a9561dab792b60ab70d82696ab691e
parent58946b7924840f1effc993e95440266479c668d5 (diff)
config: use viper and support multiple configuration formats
// toml by default $ gobgpd -f gobgpd.toml // use -t to change configuration type $ gobgpd -t yaml -f gobgpd.yaml Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--config/bgp_configs.go26
-rw-r--r--config/default.go130
-rw-r--r--config/serve.go49
-rw-r--r--gobgpd/main.go3
-rw-r--r--server/bmp.go4
-rw-r--r--server/fsm.go28
-rw-r--r--server/peer.go6
-rw-r--r--server/rpki.go2
-rw-r--r--server/server.go55
-rw-r--r--server/zclient.go2
-rw-r--r--table/destination.go4
-rw-r--r--table/path.go2
-rw-r--r--table/policy.go6
-rw-r--r--table/policy_test.go2
-rw-r--r--test/performance_test/main.go2
-rw-r--r--tools/pyang_plugins/bgpyang2golang.py6
16 files changed, 168 insertions, 159 deletions
diff --git a/config/bgp_configs.go b/config/bgp_configs.go
index fbe829db..c8d61dca 100644
--- a/config/bgp_configs.go
+++ b/config/bgp_configs.go
@@ -15,8 +15,6 @@
package config
-import "net"
-
// typedef for typedef bgp-types:rr-cluster-id-type
type RrClusterIdType string
@@ -148,7 +146,7 @@ type BmpServerState struct {
type BmpServerConfig struct {
// original -> gobgp:address
//gobgp:address's original type is inet:ip-address
- Address net.IP
+ Address string
// original -> gobgp:port
Port uint32
// original -> gobgp:route-monitoring-policy
@@ -221,7 +219,7 @@ type RpkiServerState struct {
type RpkiServerConfig struct {
// original -> gobgp:address
//gobgp:address's original type is inet:ip-address
- Address net.IP
+ Address string
// original -> gobgp:port
Port uint32
// original -> gobgp:refresh-time
@@ -541,13 +539,13 @@ type TransportState struct {
LocalPort uint16
// original -> bgp-op:remote-address
//bgp-op:remote-address's original type is inet:ip-address
- RemoteAddress net.IP
+ RemoteAddress string
// original -> bgp-op:remote-port
//bgp-op:remote-port's original type is inet:port-number
RemotePort uint16
// original -> gobgp:local-address
//gobgp:local-address's original type is inet:ip-address
- LocalAddress net.IP
+ LocalAddress string
}
//struct for container bgp:config
@@ -562,7 +560,7 @@ type TransportConfig struct {
PassiveMode bool
// original -> gobgp:local-address
//gobgp:local-address's original type is inet:ip-address
- LocalAddress net.IP
+ LocalAddress string
}
//struct for container bgp:transport
@@ -711,7 +709,7 @@ type NeighborState struct {
PeerGroup string
// original -> bgp:neighbor-address
//bgp:neighbor-address's original type is inet:ip-address
- NeighborAddress net.IP
+ NeighborAddress string
// original -> bgp-op:session-state
//bgp-op:session-state's original type is enumeration
SessionState uint32
@@ -756,14 +754,14 @@ type NeighborConfig struct {
PeerGroup string
// original -> bgp:neighbor-address
//bgp:neighbor-address's original type is inet:ip-address
- NeighborAddress net.IP
+ NeighborAddress string
}
//struct for container bgp:neighbor
type Neighbor struct {
// original -> bgp:neighbor-address
//bgp:neighbor-address's original type is inet:ip-address
- NeighborAddress net.IP
+ NeighborAddress string
// original -> bgp:neighbor-config
Config NeighborConfig
// original -> bgp:neighbor-state
@@ -1339,7 +1337,7 @@ type GlobalState struct {
As uint32
// original -> bgp:router-id
//bgp:router-id's original type is inet:ipv4-address
- RouterId net.IP
+ RouterId string
// original -> bgp-op:total-paths
TotalPaths uint32
// original -> bgp-op:total-prefixes
@@ -1353,7 +1351,7 @@ type GlobalConfig struct {
As uint32
// original -> bgp:router-id
//bgp:router-id's original type is inet:ipv4-address
- RouterId net.IP
+ RouterId string
}
//struct for container bgp:global
@@ -1543,7 +1541,7 @@ type BgpConditions struct {
OriginEq BgpOriginAttrType
// original -> bgp-pol:next-hop-in
//original type is list of inet:ip-address
- NextHopIn []net.IP
+ NextHopIn []string
// original -> bgp-pol:local-pref-eq
LocalPrefEq uint32
// original -> bgp-pol:community-count
@@ -1727,7 +1725,7 @@ type TagSets struct {
type NeighborInfo struct {
// original -> gobgp:address
//gobgp:address's original type is inet:ip-address
- Address net.IP
+ Address string
}
//struct for container rpol:neighbor-set
diff --git a/config/default.go b/config/default.go
index 5e5c8a53..11b62a71 100644
--- a/config/default.go
+++ b/config/default.go
@@ -1,8 +1,10 @@
package config
import (
- "github.com/BurntSushi/toml"
+ "fmt"
"github.com/osrg/gobgp/packet"
+ "github.com/spf13/viper"
+ "net"
"strings"
)
@@ -14,25 +16,12 @@ const (
DEFAULT_MPLS_LABEL_MAX = 1048575
)
-type neighbor struct {
- attributes map[string]bool
-}
-
-func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) error {
- neighbors := []neighbor{}
- global := make(map[string]bool)
-
- for _, key := range md.Keys() {
- if !strings.HasPrefix(key.String(), "Global") {
- continue
- }
- if key.String() != "Global" {
- global[key.String()] = true
- }
+func SetDefaultConfigValues(v *viper.Viper, b *Bgp) error {
+ if v == nil {
+ v = viper.New()
}
-
- if _, ok := global["Global.AfiSafis.AfiSafiList"]; !ok {
- bt.Global.AfiSafis.AfiSafiList = []AfiSafi{
+ if !v.IsSet("global.afisafis.afisafilist") {
+ b.Global.AfiSafis.AfiSafiList = []AfiSafi{
AfiSafi{AfiSafiName: "ipv4-unicast"},
AfiSafi{AfiSafiName: "ipv6-unicast"},
AfiSafi{AfiSafiName: "l3vpn-ipv4-unicast"},
@@ -47,77 +36,84 @@ func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) error {
}
}
- if bt.Global.ListenConfig.Port == 0 {
- bt.Global.ListenConfig.Port = bgp.BGP_PORT
+ if b.Global.ListenConfig.Port == 0 {
+ b.Global.ListenConfig.Port = bgp.BGP_PORT
}
- if _, ok := global["Global.MplsLabelRange.MinLabel"]; !ok {
- bt.Global.MplsLabelRange.MinLabel = DEFAULT_MPLS_LABEL_MIN
+ if !v.IsSet("global.mplslabelrange.minlabel") {
+ b.Global.MplsLabelRange.MinLabel = DEFAULT_MPLS_LABEL_MIN
}
- if _, ok := global["Global.MplsLabelRange.MaxLabel"]; !ok {
- bt.Global.MplsLabelRange.MaxLabel = DEFAULT_MPLS_LABEL_MAX
+ if !v.IsSet("global.mplslabelrange.maxlabel") {
+ b.Global.MplsLabelRange.MaxLabel = DEFAULT_MPLS_LABEL_MAX
}
-
- nidx := 0
- for _, key := range md.Keys() {
- if !strings.HasPrefix(key.String(), "Neighbors.NeighborList") {
- continue
- }
- if key.String() == "Neighbors.NeighborList" {
- neighbors = append(neighbors, neighbor{attributes: make(map[string]bool)})
- nidx++
- } else {
- neighbors[nidx-1].attributes[key.String()] = true
+ 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{})
+ 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)
+ }
+ }
}
}
- for i, n := range neighbors {
- neighbor := &bt.Neighbors.NeighborList[i]
- timerConfig := &neighbor.Timers.Config
-
- if _, ok := n.attributes["Neighbors.NeighborList.Timers.Config.ConnectRetry"]; !ok {
- timerConfig.HoldTime = float64(DEFAULT_CONNECT_RETRY)
+ for idx, n := range b.Neighbors.NeighborList {
+ vv := viper.New()
+ if len(list) > idx {
+ vv.Set("neighbor", list[idx])
}
- if _, ok := n.attributes["Neighbors.NeighborList.Timers.Config.HoldTime"]; !ok {
- timerConfig.HoldTime = float64(DEFAULT_HOLDTIME)
+ if !vv.IsSet("neighbor.timers.config.connectretry") {
+ n.Timers.Config.ConnectRetry = float64(DEFAULT_CONNECT_RETRY)
}
- if _, ok := n.attributes["Neighbors.NeighborList.Timers.Config.KeepaliveInterval"]; !ok {
- timerConfig.KeepaliveInterval = timerConfig.HoldTime / 3
+ if !vv.IsSet("neighbor.timers.config.holdtime") {
+ n.Timers.Config.HoldTime = float64(DEFAULT_HOLDTIME)
}
-
- if _, ok := n.attributes["Neighbors.NeighborList.Timers.Config.IdleHoldTimeAfterReset"]; !ok {
- timerConfig.IdleHoldTimeAfterReset = float64(DEFAULT_IDLE_HOLDTIME_AFTER_RESET)
+ if !vv.IsSet("neighbor.timers.config.keepaliveinterval") {
+ n.Timers.Config.KeepaliveInterval = n.Timers.Config.HoldTime / 3
+ }
+ if !vv.IsSet("neighbor.timers.config.idleholdtimeafterreset") {
+ n.Timers.Config.IdleHoldTimeAfterReset = float64(DEFAULT_IDLE_HOLDTIME_AFTER_RESET)
}
- if _, ok := n.attributes["Neighbors.NeighborList.AfiSafis.AfiSafiList"]; !ok {
- if neighbor.Config.NeighborAddress.To4() != nil {
- neighbor.AfiSafis.AfiSafiList = []AfiSafi{
- AfiSafi{AfiSafiName: "ipv4-unicast"}}
- } else {
- neighbor.AfiSafis.AfiSafiList = []AfiSafi{
- AfiSafi{AfiSafiName: "ipv6-unicast"}}
- }
- } else {
- for _, rf := range neighbor.AfiSafis.AfiSafiList {
- _, err := bgp.GetRouteFamily(rf.AfiSafiName)
- if err != nil {
- return err
+ if !vv.IsSet("neighbor.afisafis.afisafilist") {
+ if ip := net.ParseIP(n.Config.NeighborAddress); ip.To4() != nil {
+ n.AfiSafis.AfiSafiList = []AfiSafi{
+ AfiSafi{AfiSafiName: "ipv4-unicast"},
+ }
+ } else if ip.To16() != nil {
+ n.AfiSafis.AfiSafiList = []AfiSafi{
+ AfiSafi{AfiSafiName: "ipv6-unicast"},
}
+ } else {
+ return fmt.Errorf("invalid neighbor address: %s", n.Config.NeighborAddress)
}
}
- if _, ok := n.attributes["Neighbors.NeighborList.Config.PeerType"]; !ok {
- if neighbor.Config.PeerAs != bt.Global.Config.As {
- neighbor.Config.PeerType = PEER_TYPE_EXTERNAL
+ if !vv.IsSet("neighbor.config.peertype") {
+ if n.Config.PeerAs != b.Global.Config.As {
+ n.Config.PeerType = PEER_TYPE_EXTERNAL
} else {
- neighbor.Config.PeerType = PEER_TYPE_INTERNAL
+ n.Config.PeerType = PEER_TYPE_INTERNAL
}
}
+ b.Neighbors.NeighborList[idx] = n
}
- for _, r := range bt.RpkiServers.RpkiServerList {
+
+ for _, r := range b.RpkiServers.RpkiServerList {
if r.Config.Port == 0 {
r.Config.Port = bgp.RPKI_DEFAULT_PORT
}
}
+
return nil
}
diff --git a/config/serve.go b/config/serve.go
index ef9b0ae0..6de993b8 100644
--- a/config/serve.go
+++ b/config/serve.go
@@ -1,8 +1,8 @@
package config
import (
- "github.com/BurntSushi/toml"
log "github.com/Sirupsen/logrus"
+ "github.com/spf13/viper"
"reflect"
)
@@ -11,41 +11,54 @@ type BgpConfigSet struct {
Policy RoutingPolicy
}
-func ReadConfigfileServe(path string, configCh chan BgpConfigSet, reloadCh chan bool) {
+func ReadConfigfileServe(path, format string, configCh chan BgpConfigSet, reloadCh chan bool) {
cnt := 0
for {
<-reloadCh
b := Bgp{}
p := RoutingPolicy{}
- md, err := toml.DecodeFile(path, &b)
- if err == nil {
- err = SetDefaultConfigValues(md, &b)
- if err == nil {
- _, err = toml.DecodeFile(path, &p)
- }
+ v := viper.New()
+ v.SetConfigFile(path)
+ v.SetConfigType(format)
+ err := v.ReadInConfig()
+ if err != nil {
+ goto ERROR
}
-
+ err = v.Unmarshal(&b)
if err != nil {
- if cnt == 0 {
- log.Fatal("can't read config file ", path, ", ", err)
- } else {
- log.Warning("can't read config file ", path, ", ", err)
- continue
- }
+ goto ERROR
+ }
+ err = SetDefaultConfigValues(v, &b)
+ if err != nil {
+ goto ERROR
+ }
+ err = v.Unmarshal(&p)
+ if err != nil {
+ goto ERROR
}
+
if cnt == 0 {
log.Info("finished reading the config file")
}
cnt++
- bgpConfig := BgpConfigSet{Bgp: b, Policy: p}
- configCh <- bgpConfig
+ configCh <- BgpConfigSet{Bgp: b, Policy: p}
+ continue
+
+ ERROR:
+ if cnt == 0 {
+ log.Fatal("can't read config file ", path, ", ", err)
+ } else {
+ log.Warning("can't read config file ", path, ", ", err)
+ continue
+ }
+
}
}
func inSlice(n Neighbor, b []Neighbor) int {
for i, nb := range b {
- if nb.Config.NeighborAddress.String() == n.Config.NeighborAddress.String() {
+ if nb.Config.NeighborAddress == n.Config.NeighborAddress {
return i
}
}
diff --git a/gobgpd/main.go b/gobgpd/main.go
index 32743497..204a068b 100644
--- a/gobgpd/main.go
+++ b/gobgpd/main.go
@@ -39,6 +39,7 @@ func main() {
var opts struct {
ConfigFile string `short:"f" long:"config-file" description:"specifying a config file"`
+ ConfigType string `short:"t" long:"config-type" description:"specifying config type (toml, yaml, json)" default:"toml"`
LogLevel string `short:"l" long:"log-level" description:"specifying log level"`
LogPlain bool `short:"p" long:"log-plain" description:"use plain format for logging (json by default)"`
UseSyslog string `short:"s" long:"syslog" description:"use syslogd"`
@@ -161,7 +162,7 @@ func main() {
}
go m.Serve()
} else if opts.ConfigFile != "" {
- go config.ReadConfigfileServe(opts.ConfigFile, configCh, reloadCh)
+ go config.ReadConfigfileServe(opts.ConfigFile, opts.ConfigType, configCh, reloadCh)
reloadCh <- true
}
go bgpServer.Serve()
diff --git a/server/bmp.go b/server/bmp.go
index 2a5b245a..33011048 100644
--- a/server/bmp.go
+++ b/server/bmp.go
@@ -72,7 +72,7 @@ func newBMPClient(conf config.BmpServers, connCh chan *bmpConn) (*bmpClient, err
for _, c := range conf.BmpServerList {
b := c.Config
- go tryConnect(net.JoinHostPort(b.Address.String(), strconv.Itoa(int(b.Port))))
+ go tryConnect(net.JoinHostPort(b.Address, strconv.Itoa(int(b.Port))))
}
go func() {
@@ -99,7 +99,7 @@ func newBMPClient(conf config.BmpServers, connCh chan *bmpConn) (*bmpClient, err
c := func() *config.BmpServerConfig {
for _, c := range conf.BmpServerList {
b := &c.Config
- if host == net.JoinHostPort(b.Address.String(), strconv.Itoa(int(b.Port))) {
+ if host == net.JoinHostPort(b.Address, strconv.Itoa(int(b.Port))) {
return b
}
}
diff --git a/server/fsm.go b/server/fsm.go
index d05e9e23..d435b08c 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -237,11 +237,11 @@ func (fsm *FSM) connectLoop() error {
connect := func() {
if fsm.state == bgp.BGP_FSM_ACTIVE {
addr := fsm.pConf.Config.NeighborAddress
- host := net.JoinHostPort(addr.String(), strconv.Itoa(bgp.BGP_PORT))
+ host := net.JoinHostPort(addr, strconv.Itoa(bgp.BGP_PORT))
// check if LocalAddress has been configured
laddr := fsm.pConf.Transport.Config.LocalAddress
- if laddr != nil {
- lhost := net.JoinHostPort(laddr.String(), "0")
+ if laddr != "" {
+ lhost := net.JoinHostPort(laddr, "0")
ltcpaddr, err := net.ResolveTCPAddr("tcp", lhost)
if err != nil {
log.WithFields(log.Fields{
@@ -427,7 +427,7 @@ func buildopen(gConf *config.Global, pConf *config.Neighbor) *bgp.BGPMessage {
if as > (1<<16)-1 {
as = bgp.AS_TRANS
}
- return bgp.NewBGPOpenMessage(uint16(as), holdTime, gConf.Config.RouterId.String(),
+ return bgp.NewBGPOpenMessage(uint16(as), holdTime, gConf.Config.RouterId,
[]bgp.OptionParameterInterface{opt})
}
@@ -459,8 +459,8 @@ func (h *FSMHandler) recvMessageWithError() error {
}).Warn("malformed BGP Header")
h.msgCh <- &FsmMsg{
MsgType: FSM_MSG_BGP_MESSAGE,
- MsgSrc: h.fsm.pConf.Config.NeighborAddress.String(),
- MsgDst: h.fsm.pConf.Transport.Config.LocalAddress.String(),
+ MsgSrc: h.fsm.pConf.Config.NeighborAddress,
+ MsgDst: h.fsm.pConf.Transport.Config.LocalAddress,
MsgData: err,
}
return err
@@ -482,8 +482,8 @@ func (h *FSMHandler) recvMessageWithError() error {
}
fmsg := &FsmMsg{
MsgType: FSM_MSG_BGP_MESSAGE,
- MsgSrc: h.fsm.pConf.Config.NeighborAddress.String(),
- MsgDst: h.fsm.pConf.Transport.Config.LocalAddress.String(),
+ MsgSrc: h.fsm.pConf.Config.NeighborAddress,
+ MsgDst: h.fsm.pConf.Transport.Config.LocalAddress,
timestamp: now,
}
if err != nil {
@@ -504,7 +504,7 @@ func (h *FSMHandler) recvMessageWithError() error {
if err != nil {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": h.fsm.pConf.Config.NeighborAddress.String(),
+ "Key": h.fsm.pConf.Config.NeighborAddress,
"error": err,
}).Warn("malformed BGP update message")
fmsg.MsgData = err
@@ -512,7 +512,7 @@ func (h *FSMHandler) recvMessageWithError() error {
// FIXME: we should use the original message for bmp/mrt
table.UpdatePathAttrs4ByteAs(body)
fmsg.PathList = table.ProcessMessage(m, h.fsm.peerInfo, fmsg.timestamp)
- id := h.fsm.pConf.Config.NeighborAddress.String()
+ id := h.fsm.pConf.Config.NeighborAddress
policyMutex.RLock()
for _, path := range fmsg.PathList {
if h.fsm.policy.ApplyPolicy(id, table.POLICY_DIRECTION_IN, path) == nil {
@@ -595,8 +595,8 @@ func (h *FSMHandler) opensent() bgp.FSMState {
e := &FsmMsg{
MsgType: FSM_MSG_BGP_MESSAGE,
- MsgSrc: fsm.pConf.Config.NeighborAddress.String(),
- MsgDst: fsm.pConf.Transport.Config.LocalAddress.String(),
+ MsgSrc: fsm.pConf.Config.NeighborAddress,
+ MsgDst: fsm.pConf.Transport.Config.LocalAddress,
MsgData: m,
}
h.incoming <- e
@@ -974,8 +974,8 @@ func (h *FSMHandler) loop() error {
if nextState >= bgp.BGP_FSM_IDLE {
e := &FsmMsg{
MsgType: FSM_MSG_STATE_CHANGE,
- MsgSrc: fsm.pConf.Config.NeighborAddress.String(),
- MsgDst: fsm.pConf.Transport.Config.LocalAddress.String(),
+ MsgSrc: fsm.pConf.Config.NeighborAddress,
+ MsgDst: fsm.pConf.Transport.Config.LocalAddress,
MsgData: nextState,
}
h.incoming <- e
diff --git a/server/peer.go b/server/peer.go
index f7c31fda..f083baf4 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -58,7 +58,7 @@ func NewPeer(g config.Global, conf config.Neighbor, loc *table.TableManager, pol
}
tableId := table.GLOBAL_RIB_NAME
if peer.isRouteServerClient() {
- tableId = conf.Config.NeighborAddress.String()
+ tableId = conf.Config.NeighborAddress
}
peer.tableId = tableId
conf.State.SessionState = uint32(bgp.BGP_FSM_IDLE)
@@ -79,7 +79,7 @@ func (peer *Peer) Outgoing() chan *bgp.BGPMessage {
}
func (peer *Peer) ID() string {
- return peer.conf.Config.NeighborAddress.String()
+ return peer.conf.Config.NeighborAddress
}
func (peer *Peer) TableID() string {
@@ -274,7 +274,7 @@ func (peer *Peer) ToApiStruct() *api.Peer {
}
conf := &api.PeerConf{
- NeighborAddress: c.Config.NeighborAddress.String(),
+ NeighborAddress: c.Config.NeighborAddress,
Id: peer.fsm.peerInfo.ID.To4().String(),
PeerAs: c.Config.PeerAs,
LocalAs: c.Config.LocalAs,
diff --git a/server/rpki.go b/server/rpki.go
index a5f5dbee..57a76bc5 100644
--- a/server/rpki.go
+++ b/server/rpki.go
@@ -105,7 +105,7 @@ func newROAManager(as uint32, conf config.RpkiServers) (*roaManager, error) {
for _, entry := range conf.RpkiServerList {
c := entry.Config
client := &roaClient{
- host: net.JoinHostPort(c.Address.String(), strconv.Itoa(int(c.Port))),
+ host: net.JoinHostPort(c.Address, strconv.Itoa(int(c.Port))),
eventCh: m.eventCh,
}
m.clientMap[client.host] = client
diff --git a/server/server.go b/server/server.go
index a29e7e91..20a8eebc 100644
--- a/server/server.go
+++ b/server/server.go
@@ -18,7 +18,6 @@ package server
import (
"bytes"
"fmt"
- "github.com/BurntSushi/toml"
log "github.com/Sirupsen/logrus"
"github.com/armon/go-radix"
api "github.com/osrg/gobgp/api"
@@ -240,9 +239,9 @@ func (server *BgpServer) Serve() {
}
}
- listener := func(addr net.IP) *net.TCPListener {
+ listener := func(addr string) *net.TCPListener {
var l *net.TCPListener
- if addr.To4() != nil {
+ if net.ParseIP(addr).To4() != nil {
l = server.listenerMap["tcp4"]
} else {
l = server.listenerMap["tcp6"]
@@ -296,7 +295,7 @@ func (server *BgpServer) Serve() {
return false
}
return true
- }(peer.conf.Transport.Config.LocalAddress)
+ }(net.ParseIP(peer.conf.Transport.Config.LocalAddress))
if localAddrValid == false {
conn.Close()
return
@@ -360,14 +359,14 @@ func (server *BgpServer) Serve() {
case conn := <-acceptCh:
passConn(conn)
case config := <-server.addedPeerCh:
- addr := config.Config.NeighborAddress.String()
+ addr := config.Config.NeighborAddress
_, found := server.neighborMap[addr]
if found {
log.Warn("Can't overwrite the exising peer ", addr)
continue
}
if g.ListenConfig.Port > 0 {
- SetTcpMD5SigSockopts(listener(config.Config.NeighborAddress), addr, config.Config.AuthPassword)
+ SetTcpMD5SigSockopts(listener(addr), addr, config.Config.AuthPassword)
}
peer := NewPeer(g, config, server.globalRib, server.policy)
server.setPolicyByConfig(peer.ID(), config.ApplyPolicy)
@@ -389,8 +388,8 @@ func (server *BgpServer) Serve() {
peer.startFSMHandler(server.fsmincomingCh)
server.broadcastPeerState(peer)
case config := <-server.deletedPeerCh:
- addr := config.Config.NeighborAddress.String()
- SetTcpMD5SigSockopts(listener(config.Config.NeighborAddress), addr, "")
+ addr := config.Config.NeighborAddress
+ SetTcpMD5SigSockopts(listener(addr), addr, "")
peer, found := server.neighborMap[addr]
if found {
log.Info("Delete a peer configuration for ", addr)
@@ -414,7 +413,7 @@ func (server *BgpServer) Serve() {
log.Info("Can't delete a peer configuration for ", addr)
}
case config := <-server.updatedPeerCh:
- addr := config.Config.NeighborAddress.String()
+ addr := config.Config.NeighborAddress
peer := server.neighborMap[addr]
peer.conf = config
server.setPolicyByConfig(peer.ID(), config.ApplyPolicy)
@@ -448,7 +447,7 @@ func newSenderMsg(peer *Peer, messages []*bgp.BGPMessage) *SenderMsg {
return &SenderMsg{
messages: messages,
sendCh: peer.outgoing,
- destination: peer.conf.Config.NeighborAddress.String(),
+ destination: peer.conf.Config.NeighborAddress,
twoBytesAs: y,
}
}
@@ -484,7 +483,7 @@ func filterpath(peer *Peer, path *table.Path) *table.Path {
// RFC4456 8. Avoiding Routing Information Loops
// A router that recognizes the ORIGINATOR_ID attribute SHOULD
// ignore a route received with its BGP Identifier as the ORIGINATOR_ID.
- if id := path.GetOriginatorID(); peer.gConf.Config.RouterId.Equal(id) {
+ if id := path.GetOriginatorID(); peer.gConf.Config.RouterId == id.String() {
log.WithFields(log.Fields{
"Topic": "Peer",
"Key": remoteAddr,
@@ -524,7 +523,7 @@ func filterpath(peer *Peer, path *table.Path) *table.Path {
}
}
- if remoteAddr.Equal(path.GetSource().Address) {
+ if remoteAddr == path.GetSource().Address.String() {
log.WithFields(log.Fields{
"Topic": "Peer",
"Key": remoteAddr,
@@ -536,7 +535,7 @@ func filterpath(peer *Peer, path *table.Path) *table.Path {
if !peer.isRouteServerClient() && isASLoop(peer, path) {
return nil
}
- return path.Clone(remoteAddr, path.IsWithdraw)
+ return path.Clone(net.ParseIP(remoteAddr), path.IsWithdraw)
}
func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg {
@@ -652,7 +651,7 @@ func (server *BgpServer) broadcastPeerState(peer *Peer) {
default:
}
ignore := req.RequestType != REQ_MONITOR_NEIGHBOR_PEER_STATE
- ignore = ignore || (req.Name != "" && req.Name != peer.conf.Config.NeighborAddress.String())
+ ignore = ignore || (req.Name != "" && req.Name != peer.conf.Config.NeighborAddress)
if ignore {
remainReqs = append(remainReqs, req)
continue
@@ -797,7 +796,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg, incoming chan *
if nextState == bgp.BGP_FSM_ESTABLISHED {
// update for export policy
laddr, lport := peer.fsm.LocalHostPort()
- peer.conf.Transport.Config.LocalAddress = net.ParseIP(laddr)
+ peer.conf.Transport.Config.LocalAddress = laddr
if ch := server.bmpClient.send(); ch != nil {
_, rport := peer.fsm.RemoteHostPort()
m := &broadcastBMPMsg{
@@ -1093,7 +1092,7 @@ func (server *BgpServer) Api2PathList(resource api.Resource, name string, ApiPat
} else {
pi = &table.PeerInfo{
AS: server.bgpConfig.Global.Config.As,
- LocalID: server.bgpConfig.Global.Config.RouterId,
+ LocalID: net.ParseIP(server.bgpConfig.Global.Config.RouterId).To4(),
}
}
@@ -1304,7 +1303,7 @@ func (server *BgpServer) handleVrfMod(arg *api.ModVrfArguments) ([]*table.Path,
}
pi := &table.PeerInfo{
AS: server.bgpConfig.Global.Config.As,
- LocalID: server.bgpConfig.Global.Config.RouterId,
+ LocalID: net.ParseIP(server.bgpConfig.Global.Config.RouterId).To4(),
}
msgs, err = rib.AddVrf(arg.Vrf.Name, rd, importRt, exportRt, pi)
if err != nil {
@@ -1406,14 +1405,14 @@ func (server *BgpServer) handleModConfig(grpcReq *GrpcRequest) error {
Global: config.Global{
Config: config.GlobalConfig{
As: g.As,
- RouterId: net.ParseIP(g.RouterId),
+ RouterId: g.RouterId,
},
ListenConfig: config.ListenConfig{
Port: g.ListenPort,
},
},
}
- err := config.SetDefaultConfigValues(toml.MetaData{}, &c)
+ err := config.SetDefaultConfigValues(nil, &c)
if err != nil {
return err
}
@@ -1490,7 +1489,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
result := &GrpcResponse{
Data: &api.Global{
As: server.bgpConfig.Global.Config.As,
- RouterId: server.bgpConfig.Global.Config.RouterId.String(),
+ RouterId: server.bgpConfig.Global.Config.RouterId,
},
}
grpcReq.ResponseCh <- result
@@ -1723,7 +1722,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
pathList := []*table.Path{}
for _, path := range peer.adjRibIn.PathList([]bgp.RouteFamily{grpcReq.RouteFamily}, false) {
if path = server.policy.ApplyPolicy(peer.ID(), table.POLICY_DIRECTION_IN, path); path != nil {
- pathList = append(pathList, path.Clone(peer.conf.Config.NeighborAddress, false))
+ pathList = append(pathList, path.Clone(net.ParseIP(peer.conf.Config.NeighborAddress), false))
}
}
m, _ := server.propagateUpdate(peer, pathList)
@@ -1958,8 +1957,8 @@ func (server *BgpServer) handleGrpcModNeighbor(grpcReq *GrpcRequest) (sMsgs []*S
apitoConfig := func(a *api.Peer) (config.Neighbor, error) {
var pconf config.Neighbor
if a.Conf != nil {
- pconf.NeighborAddress = net.ParseIP(a.Conf.NeighborAddress)
- pconf.Config.NeighborAddress = net.ParseIP(a.Conf.NeighborAddress)
+ pconf.NeighborAddress = a.Conf.NeighborAddress
+ pconf.Config.NeighborAddress = a.Conf.NeighborAddress
pconf.Config.PeerAs = a.Conf.PeerAs
pconf.Config.LocalAs = a.Conf.LocalAs
if pconf.Config.PeerAs != server.bgpConfig.Global.Config.As {
@@ -1973,7 +1972,7 @@ func (server *BgpServer) handleGrpcModNeighbor(grpcReq *GrpcRequest) (sMsgs []*S
pconf.Config.SendCommunity = config.CommunityType(a.Conf.SendCommunity)
pconf.Config.Description = a.Conf.Description
pconf.Config.PeerGroup = a.Conf.PeerGroup
- pconf.Config.NeighborAddress = net.ParseIP(a.Conf.NeighborAddress)
+ pconf.Config.NeighborAddress = a.Conf.NeighborAddress
}
if a.Timers != nil {
if a.Timers.Config != nil {
@@ -2033,7 +2032,7 @@ func (server *BgpServer) handleGrpcModNeighbor(grpcReq *GrpcRequest) (sMsgs []*S
}
}
if a.Transport != nil {
- pconf.Transport.Config.LocalAddress = net.ParseIP(a.Transport.LocalAddress)
+ pconf.Transport.Config.LocalAddress = a.Transport.LocalAddress
pconf.Transport.Config.PassiveMode = a.Transport.PassiveMode
}
return pconf, nil
@@ -2443,7 +2442,7 @@ func (server *BgpServer) handleModRpki(grpcReq *GrpcRequest) {
switch arg.Operation {
case api.Operation_ADD:
r := config.RpkiServer{}
- r.Config.Address = net.ParseIP(arg.Address)
+ r.Config.Address = arg.Address
r.Config.Port = arg.Port
server.bgpConfig.RpkiServers.RpkiServerList = append(server.bgpConfig.RpkiServers.RpkiServerList, r)
server.roaManager, _ = newROAManager(server.bgpConfig.Global.Config.As, server.bgpConfig.RpkiServers)
@@ -2555,11 +2554,11 @@ func (server *BgpServer) mkMrtPeerIndexTableMsg(t uint32, view string) (*bgp.MRT
peers := make([]*bgp.Peer, 0, len(server.neighborMap))
for _, peer := range server.neighborMap {
id := peer.fsm.peerInfo.ID.To4().String()
- ipaddr := peer.conf.Config.NeighborAddress.String()
+ ipaddr := peer.conf.Config.NeighborAddress
asn := peer.conf.Config.PeerAs
peers = append(peers, bgp.NewPeer(id, ipaddr, asn, true))
}
- bgpid := server.bgpConfig.Global.Config.RouterId.To4().String()
+ bgpid := server.bgpConfig.Global.Config.RouterId
table := bgp.NewPeerIndexTable(bgpid, view, peers)
return bgp.NewMRTMessage(t, bgp.TABLE_DUMPv2, bgp.PEER_INDEX_TABLE, table)
}
diff --git a/server/zclient.go b/server/zclient.go
index 33875476..ba731cce 100644
--- a/server/zclient.go
+++ b/server/zclient.go
@@ -152,7 +152,7 @@ func handleZapiMsg(msg *zebra.Message, server *BgpServer) []*SenderMsg {
case *zebra.IPRouteBody:
pi := &table.PeerInfo{
AS: server.bgpConfig.Global.Config.As,
- LocalID: server.bgpConfig.Global.Config.RouterId,
+ LocalID: net.ParseIP(server.bgpConfig.Global.Config.RouterId).To4(),
}
if b.Prefix != nil && len(b.Nexthops) > 0 && b.Type != zebra.ROUTE_KERNEL {
diff --git a/table/destination.go b/table/destination.go
index ca3a39f0..2577e7cb 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -103,8 +103,8 @@ func NewPeerInfo(g *config.Global, p *config.Neighbor) *PeerInfo {
return &PeerInfo{
AS: p.Config.PeerAs,
LocalAS: g.Config.As,
- LocalID: g.Config.RouterId,
- Address: p.Config.NeighborAddress,
+ LocalID: net.ParseIP(g.Config.RouterId).To4(),
+ Address: net.ParseIP(p.Config.NeighborAddress),
RouteReflectorClient: p.RouteReflector.Config.RouteReflectorClient,
RouteReflectorClusterID: id,
}
diff --git a/table/path.go b/table/path.go
index bfc967d2..05144812 100644
--- a/table/path.go
+++ b/table/path.go
@@ -90,7 +90,7 @@ func (path *Path) UpdatePathAttrs(global *config.Global, peer *config.Neighbor)
return
}
- localAddress := peer.Transport.Config.LocalAddress
+ localAddress := net.ParseIP(peer.Transport.Config.LocalAddress)
if peer.Config.PeerType == config.PEER_TYPE_EXTERNAL {
// NEXTHOP handling
path.SetNexthop(localAddress)
diff --git a/table/policy.go b/table/policy.go
index 52d6900c..7148b764 100644
--- a/table/policy.go
+++ b/table/policy.go
@@ -515,7 +515,11 @@ func NewNeighborSet(c config.NeighborSet) (*NeighborSet, error) {
}
list := make([]net.IP, 0, len(c.NeighborInfoList))
for _, x := range c.NeighborInfoList {
- list = append(list, x.Address)
+ addr := net.ParseIP(x.Address)
+ if addr == nil {
+ return nil, fmt.Errorf("invalid address: %s", x.Address)
+ }
+ list = append(list, addr)
}
return &NeighborSet{
name: name,
diff --git a/table/policy_test.go b/table/policy_test.go
index c29b15c1..1ab6acce 100644
--- a/table/policy_test.go
+++ b/table/policy_test.go
@@ -2839,7 +2839,7 @@ func createNeighborSet(name string, addr string) config.NeighborSet {
NeighborSetName: name,
NeighborInfoList: []config.NeighborInfo{
config.NeighborInfo{
- Address: net.ParseIP(addr),
+ Address: addr,
}},
}
return ns
diff --git a/test/performance_test/main.go b/test/performance_test/main.go
index d005bcfa..4385dd68 100644
--- a/test/performance_test/main.go
+++ b/test/performance_test/main.go
@@ -72,7 +72,7 @@ func main() {
},
}
peer := newPeer(g, p, incoming)
- peerMap[p.Transport.Config.LocalAddress.String()] = peer
+ peerMap[p.Transport.Config.LocalAddress] = peer
}
established := 0
ticker := time.NewTicker(time.Second * 5)
diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py
index 42e4e65e..ed02b451 100644
--- a/tools/pyang_plugins/bgpyang2golang.py
+++ b/tools/pyang_plugins/bgpyang2golang.py
@@ -528,9 +528,9 @@ _type_translation_map = {
'decimal64': 'float64',
'boolean': 'bool',
'empty': 'bool',
- 'inet:ip-address': 'net.IP',
+ 'inet:ip-address': 'string',
'inet:ip-prefix': 'string',
- 'inet:ipv4-address': 'net.IP',
+ 'inet:ipv4-address': 'string',
'inet:as-number': 'uint32',
'bgp-set-community-option-type' : 'string',
'identityref' : 'string',
@@ -570,8 +570,6 @@ def generate_header(ctx):
print _COPYRIGHT_NOTICE
print 'package config'
print ''
- print 'import "net"'
- print ''
def translate_type(key):