diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-02-19 15:40:30 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-02-29 15:59:42 -0800 |
commit | 0b78f57ccdf63591fd211ade0b571189e070f598 (patch) | |
tree | 0c92ff928bcd4aabb9735740f98da486686b051d | |
parent | 53c5bc0258cede44d3544270309b6dd2e83cf058 (diff) |
config/server: support per-peer asn
you can override `global.config.as` by `neighbor.config.local-as`
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | config/default.go | 6 | ||||
-rw-r--r-- | docs/sources/configuration.md | 2 | ||||
-rw-r--r-- | gobgp/cmd/common.go | 2 | ||||
-rw-r--r-- | server/fsm.go | 10 | ||||
-rw-r--r-- | server/peer.go | 2 | ||||
-rw-r--r-- | table/path.go | 2 | ||||
-rw-r--r-- | test/lib/base.py | 5 | ||||
-rw-r--r-- | test/lib/gobgp.py | 3 |
8 files changed, 22 insertions, 10 deletions
diff --git a/config/default.go b/config/default.go index fe7d547b..21b95758 100644 --- a/config/default.go +++ b/config/default.go @@ -131,8 +131,12 @@ func SetDefaultConfigValues(v *viper.Viper, b *Bgp) error { } } + if !vv.IsSet("neighbor.config.local-as") { + n.Config.LocalAs = b.Global.Config.As + } + if !vv.IsSet("neighbor.config.peer-type") { - if n.Config.PeerAs != b.Global.Config.As { + if n.Config.PeerAs != n.Config.LocalAs { n.Config.PeerType = PEER_TYPE_EXTERNAL } else { n.Config.PeerType = PEER_TYPE_INTERNAL diff --git a/docs/sources/configuration.md b/docs/sources/configuration.md index 26985d2e..5ec3bfc7 100644 --- a/docs/sources/configuration.md +++ b/docs/sources/configuration.md @@ -43,6 +43,8 @@ peer-as = 2 auth-password = "password" neighbor-address = "192.168.10.2" + # override global.config.as value + local-as = 1000 [neighbors.timers.config] connect-retry = 5 hold-time = 9 diff --git a/gobgp/cmd/common.go b/gobgp/cmd/common.go index f41d5bcd..a430cbbb 100644 --- a/gobgp/cmd/common.go +++ b/gobgp/cmd/common.go @@ -244,6 +244,7 @@ type PeerConf struct { RemoteIp net.IP `json:"remote_ip,omitempty"` Id net.IP `json:"id,omitempty"` RemoteAs uint32 `json:"remote_as,omitempty"` + LocalAs uint32 `json:"local-as,omitempty"` RemoteCap []bgp.ParameterCapabilityInterface `json:"remote_cap,omitempty"` LocalCap []bgp.ParameterCapabilityInterface `json:"local_cap,omitempty"` Holdtime uint32 `json:"holdtime,omitempty"` @@ -271,6 +272,7 @@ func ApiStruct2Peer(p *gobgpapi.Peer) *Peer { RemoteIp: net.ParseIP(p.Conf.NeighborAddress), Id: net.ParseIP(p.Conf.Id), RemoteAs: p.Conf.PeerAs, + LocalAs: p.Conf.LocalAs, RemoteCap: remoteCaps, LocalCap: localCaps, } diff --git a/server/fsm.go b/server/fsm.go index e4007764..cc4fb95f 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -446,7 +446,7 @@ func (h *FSMHandler) active() (bgp.FSMState, FsmStateReason) { break } fsm.conn = conn - if fsm.gConf.Config.As != fsm.pConf.Config.PeerAs { + if fsm.pConf.Config.PeerType == config.PEER_TYPE_EXTERNAL { ttl := 1 if fsm.pConf.EbgpMultihop.Config.Enabled == true { ttl = int(fsm.pConf.EbgpMultihop.Config.MultihopTtl) @@ -488,14 +488,14 @@ func (h *FSMHandler) active() (bgp.FSMState, FsmStateReason) { } } -func capabilitiesFromConfig(gConf *config.Global, pConf *config.Neighbor) []bgp.ParameterCapabilityInterface { +func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInterface { caps := make([]bgp.ParameterCapabilityInterface, 0, 4) caps = append(caps, bgp.NewCapRouteRefresh()) for _, rf := range pConf.AfiSafis { family, _ := bgp.GetRouteFamily(string(rf.AfiSafiName)) caps = append(caps, bgp.NewCapMultiProtocol(family)) } - caps = append(caps, bgp.NewCapFourOctetASNumber(gConf.Config.As)) + caps = append(caps, bgp.NewCapFourOctetASNumber(pConf.Config.LocalAs)) if c := pConf.GracefulRestart.Config; c.Enabled { tuples := []*bgp.CapGracefulRestartTuple{} @@ -529,10 +529,10 @@ func capabilitiesFromConfig(gConf *config.Global, pConf *config.Neighbor) []bgp. } func buildopen(gConf *config.Global, pConf *config.Neighbor) *bgp.BGPMessage { - caps := capabilitiesFromConfig(gConf, pConf) + caps := capabilitiesFromConfig(pConf) opt := bgp.NewOptionParameterCapability(caps) holdTime := uint16(pConf.Timers.Config.HoldTime) - as := gConf.Config.As + as := pConf.Config.LocalAs if as > (1<<16)-1 { as = bgp.AS_TRANS } diff --git a/server/peer.go b/server/peer.go index b8b8d5a8..07a1288b 100644 --- a/server/peer.go +++ b/server/peer.go @@ -265,7 +265,7 @@ func (peer *Peer) ToApiStruct() *api.Peer { } } - caps := capabilitiesFromConfig(&peer.gConf, &peer.conf) + caps := capabilitiesFromConfig(&peer.conf) localCap := make([][]byte, 0, len(caps)) for _, c := range caps { buf, _ := c.Serialize() diff --git a/table/path.go b/table/path.go index 9d1b00b1..e48b7258 100644 --- a/table/path.go +++ b/table/path.go @@ -167,7 +167,7 @@ func (path *Path) UpdatePathAttrs(global *config.Global, peer *config.Neighbor) path.SetNexthop(localAddress) // AS_PATH handling - path.PrependAsn(global.Config.As, 1) + path.PrependAsn(peer.Config.LocalAs, 1) // MED Handling if med := path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC); med != nil && !path.IsLocal() { diff --git a/test/lib/base.py b/test/lib/base.py index 37cc26f4..3dcbc1e8 100644 --- a/test/lib/base.py +++ b/test/lib/base.py @@ -248,7 +248,7 @@ class BGPContainer(Container): policies=None, passive=False, is_rr_client=False, cluster_id=None, flowspec=False, bridge='', reload_config=True, as2=False, - graceful_restart=None): + graceful_restart=None, local_as=None): neigh_addr = '' local_addr = '' for me, you in itertools.product(self.ip_addrs, peer.ip_addrs): @@ -276,7 +276,8 @@ class BGPContainer(Container): 'passive': passive, 'local_addr': local_addr, 'as2': as2, - 'graceful_restart': graceful_restart} + 'graceful_restart': graceful_restart, + 'local_as': local_as} if self.is_running and reload_config: self.create_config() self.reload_config() diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py index 1f956587..774113e0 100644 --- a/test/lib/gobgp.py +++ b/test/lib/gobgp.py @@ -215,6 +215,9 @@ class GoBGPContainer(BGPContainer): if info['is_rs_client']: n['route-server'] = {'config': {'route-server-client': True}} + if info['local_as']: + n['config']['local-as'] = info['local_as'] + if info['graceful_restart'] is not None: n['graceful-restart'] = {'config': {'enabled': True, 'restart-time': 20}} for afi_safi in afi_safi_list: |