@@ -3253,3 +3253,74 @@ func TestEBGPRouteStuck(test *testing.T) {
32533253 assertPathCount (collect , peers [2 ], 1 )
32543254 }, 20 * time .Second , 1 * time .Millisecond )
32553255}
3256+
3257+ func TestUpdatePeer (t * testing.T ) {
3258+ s := NewBgpServer ()
3259+ go s .Serve ()
3260+ err := s .StartBgp (context .Background (), & api.StartBgpRequest {
3261+ Global : & api.Global {
3262+ Asn : 65000 ,
3263+ RouterId : "1.1.1.1" ,
3264+ ListenPort : - 1 ,
3265+ },
3266+ })
3267+ assert .NoError (t , err )
3268+ defer s .StopBgp (context .Background (), & api.StopBgpRequest {})
3269+
3270+ // add peer
3271+ p := & api.Peer {
3272+ Conf : & api.PeerConf {
3273+ NeighborAddress : "2.2.2.2" ,
3274+ LocalAsn : 65000 ,
3275+ PeerAsn : 65001 ,
3276+ Type : api .PeerType_PEER_TYPE_EXTERNAL ,
3277+ ReplacePeerAsn : false ,
3278+ },
3279+ Timers : & api.Timers {
3280+ Config : & api.TimersConfig {
3281+ HoldTime : 30 ,
3282+ KeepaliveInterval : 10 ,
3283+ ConnectRetry : 20 ,
3284+ IdleHoldTimeAfterReset : 30 ,
3285+ },
3286+ },
3287+ }
3288+ err = s .AddPeer (context .Background (), & api.AddPeerRequest {Peer : p })
3289+ assert .NoError (t , err )
3290+
3291+ // update timer config
3292+ p .Timers .Config .HoldTime = 33
3293+ resp , err := s .UpdatePeer (context .Background (), & api.UpdatePeerRequest {Peer : p })
3294+ assert .NoError (t , err )
3295+ assert .False (t , resp .NeedsSoftResetIn )
3296+
3297+ assert .EventuallyWithT (t , func (collect * assert.CollectT ) {
3298+ _ = s .ListPeer (context .Background (), & api.ListPeerRequest {}, func (peer * api.Peer ) {
3299+ assert .Equal (collect , peer .Timers .Config , p .Timers .Config )
3300+ })
3301+ }, time .Second , 10 * time .Millisecond )
3302+
3303+ // update AS_PATH option
3304+ p .Conf .ReplacePeerAsn = true
3305+ resp , err = s .UpdatePeer (context .Background (), & api.UpdatePeerRequest {Peer : p })
3306+ assert .NoError (t , err )
3307+ assert .True (t , resp .NeedsSoftResetIn )
3308+
3309+ assert .EventuallyWithT (t , func (collect * assert.CollectT ) {
3310+ _ = s .ListPeer (context .Background (), & api.ListPeerRequest {}, func (peer * api.Peer ) {
3311+ assert .Equal (collect , peer .Conf , p .Conf )
3312+ })
3313+ }, time .Second , 10 * time .Millisecond )
3314+
3315+ // set admin down
3316+ p .Conf .AdminDown = true
3317+ resp , err = s .UpdatePeer (context .Background (), & api.UpdatePeerRequest {Peer : p })
3318+ assert .NoError (t , err )
3319+ assert .False (t , resp .NeedsSoftResetIn )
3320+
3321+ assert .EventuallyWithT (t , func (collect * assert.CollectT ) {
3322+ _ = s .ListPeer (context .Background (), & api.ListPeerRequest {}, func (peer * api.Peer ) {
3323+ assert .Equal (collect , peer .Conf , p .Conf )
3324+ })
3325+ }, time .Second , 10 * time .Millisecond )
3326+ }
0 commit comments