diff options
-rw-r--r-- | server/peer.go | 26 | ||||
-rw-r--r-- | server/peer_test.go | 8 | ||||
-rw-r--r-- | table/table_manager.go | 21 | ||||
-rw-r--r-- | table/table_manager_test.go | 228 |
4 files changed, 143 insertions, 140 deletions
diff --git a/server/peer.go b/server/peer.go index 2efceeac..c237aff7 100644 --- a/server/peer.go +++ b/server/peer.go @@ -311,18 +311,10 @@ func (peer *Peer) handleREST(restReq *api.RestRequest) { close(restReq.ResponseCh) } -func (peer *Peer) sendUpdateMsgFromPaths(pList []table.Path, wList []table.Path) { - pathList := append([]table.Path(nil), pList...) - pathList = append(pathList, wList...) - - for _, p := range wList { - if !p.IsWithdraw() { - log.Fatal("withdraw pathlist has non withdraw path") - } - } - peer.adjRib.UpdateOut(pathList) +func (peer *Peer) sendUpdateMsgFromPaths(pList []table.Path) { + peer.adjRib.UpdateOut(pList) sendpathList := []table.Path{} - for _, p := range pathList { + for _, p := range pList { if _, ok := peer.rfMap[p.GetRouteFamily()]; ok { sendpathList = append(sendpathList, p) } @@ -333,12 +325,12 @@ func (peer *Peer) sendUpdateMsgFromPaths(pList []table.Path, wList []table.Path) func (peer *Peer) handlePeerMsg(m *peerMsg) { switch m.msgType { case PEER_MSG_PATH: - pList, wList, _ := peer.rib.ProcessPaths(m.msgData.([]table.Path)) - peer.sendUpdateMsgFromPaths(pList, wList) + pList, _ := peer.rib.ProcessPaths(m.msgData.([]table.Path)) + peer.sendUpdateMsgFromPaths(pList) case PEER_MSG_PEER_DOWN: for _, rf := range peer.configuredRFlist() { - pList, wList, _ := peer.rib.DeletePathsforPeer(m.msgData.(*table.PeerInfo), rf) - peer.sendUpdateMsgFromPaths(pList, wList) + pList, _ := peer.rib.DeletePathsforPeer(m.msgData.(*table.PeerInfo), rf) + peer.sendUpdateMsgFromPaths(pList) } } } @@ -356,8 +348,8 @@ func (peer *Peer) handleServerMsg(m *serverMsg) { if _, ok := peer.siblings[d.Address.String()]; ok { delete(peer.siblings, d.Address.String()) for _, rf := range peer.configuredRFlist() { - pList, wList, _ := peer.rib.DeletePathsforPeer(d, rf) - peer.sendUpdateMsgFromPaths(pList, wList) + pList, _ := peer.rib.DeletePathsforPeer(d, rf) + peer.sendUpdateMsgFromPaths(pList) } } else { log.Warning("can not find peer: ", d.Address.String()) diff --git a/server/peer_test.go b/server/peer_test.go index cceb6992..f8703d2c 100644 --- a/server/peer_test.go +++ b/server/peer_test.go @@ -69,9 +69,9 @@ func TestProcessBGPUpdate_fourbyteAS(t *testing.T) { msg := table.NewProcessMessage(m, peerInfo) pathList := msg.ToPathList() - pList, wList, _ := rib1.ProcessPaths(pathList) + pList, _ := rib1.ProcessPaths(pathList) assert.Equal(t, len(pList), 1) - assert.Equal(t, len(wList), 0) + assert.Equal(t, pList[0].IsWithdraw(), false) fmt.Println(pList) sendMsg := table.CreateUpdateMsgFromPaths(pList) assert.Equal(t, len(sendMsg), 1) @@ -87,9 +87,9 @@ func TestProcessBGPUpdate_fourbyteAS(t *testing.T) { assert.Equal(t, attrAS.Value[0].(*bgp.AsPathParam).AS, []uint16{bgp.AS_TRANS, 4000, bgp.AS_TRANS}) rib2 := table.NewTableManager("peer_test", []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC}) - pList2, wList2, _ := rib2.ProcessPaths(pathList) + pList2, _ := rib2.ProcessPaths(pathList) assert.Equal(t, len(pList2), 1) - assert.Equal(t, len(wList2), 0) + assert.Equal(t, pList[0].IsWithdraw(), false) sendMsg2 := table.CreateUpdateMsgFromPaths(pList2) assert.Equal(t, len(sendMsg2), 1) update2 := sendMsg2[0].Body.(*bgp.BGPUpdate) diff --git a/table/table_manager.go b/table/table_manager.go index f2ff1ee6..c8ff0833 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -146,9 +146,8 @@ func NewTableManager(owner string, rfList []bgp.RouteFamily) *TableManager { return t } -func (manager *TableManager) calculate(destinationList []Destination) ([]Path, []Path, error) { - bestPaths := make([]Path, 0) - lostPaths := make([]Path, 0) +func (manager *TableManager) calculate(destinationList []Destination) ([]Path, error) { + newPaths := make([]Path, 0) for _, destination := range destinationList { // compute best path @@ -202,7 +201,7 @@ func (manager *TableManager) calculate(destinationList []Destination) ([]Path, [ p := destination.getBestPath() destination.setOldBestPath(p) - lostPaths = append(lostPaths, p.clone(true)) + newPaths = append(newPaths, p.clone(true)) } destination.setBestPath(nil) } else { @@ -223,7 +222,7 @@ func (manager *TableManager) calculate(destinationList []Destination) ([]Path, [ "reason": reason, }).Debug("new best path") - bestPaths = append(bestPaths, newBestPath) + newPaths = append(newPaths, newBestPath) destination.setBestPath(newBestPath) } @@ -239,18 +238,18 @@ func (manager *TableManager) calculate(destinationList []Destination) ([]Path, [ }).Debug("destination removed") } } - return bestPaths, lostPaths, nil + return newPaths, nil } -func (manager *TableManager) DeletePathsforPeer(peerInfo *PeerInfo, rf bgp.RouteFamily) ([]Path, []Path, error) { +func (manager *TableManager) DeletePathsforPeer(peerInfo *PeerInfo, rf bgp.RouteFamily) ([]Path, error) { if _, ok := manager.Tables[rf]; ok { destinationList := manager.Tables[rf].DeleteDestByPeer(peerInfo) return manager.calculate(destinationList) } - return []Path{}, []Path{}, nil + return []Path{}, nil } -func (manager *TableManager) ProcessPaths(pathList []Path) ([]Path, []Path, error) { +func (manager *TableManager) ProcessPaths(pathList []Path) ([]Path, error) { destinationList := make([]Destination, 0) for _, path := range pathList { rf := path.GetRouteFamily() @@ -264,7 +263,7 @@ func (manager *TableManager) ProcessPaths(pathList []Path) ([]Path, []Path, erro // process BGPUpdate message // this function processes only BGPUpdate -func (manager *TableManager) ProcessUpdate(fromPeer *PeerInfo, message *bgp.BGPMessage) ([]Path, []Path, error) { +func (manager *TableManager) ProcessUpdate(fromPeer *PeerInfo, message *bgp.BGPMessage) ([]Path, error) { // check msg's type if it's BGPUpdate if message.Header.Type != bgp.BGP_MSG_UPDATE { log.WithFields(log.Fields{ @@ -273,7 +272,7 @@ func (manager *TableManager) ProcessUpdate(fromPeer *PeerInfo, message *bgp.BGPM "key": fromPeer.Address.String(), "Type": message.Header.Type, }).Warn("message is not BGPUpdate") - return []Path{}, []Path{}, nil + return []Path{}, nil } msg := &ProcessMessage{ diff --git a/table/table_manager_test.go b/table/table_manager_test.go index fecee20a..5d3ed1b8 100644 --- a/table/table_manager_test.go +++ b/table/table_manager_test.go @@ -71,9 +71,9 @@ func TestProcessBGPUpdate_0_select_onlypath_ipv4(t *testing.T) { bgpMessage := update_fromR1() peer := peerR1() - pList, wList, err := tm.ProcessUpdate(peer, bgpMessage) + pList, err := tm.ProcessUpdate(peer, bgpMessage) assert.Equal(t, len(pList), 1) - assert.Equal(t, len(wList), 0) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -122,9 +122,9 @@ func TestProcessBGPUpdate_0_select_onlypath_ipv6(t *testing.T) { bgpMessage := update_fromR1_ipv6() peer := peerR1() - pList, wList, err := tm.ProcessUpdate(peer, bgpMessage) + pList, err := tm.ProcessUpdate(peer, bgpMessage) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -202,15 +202,15 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv4(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -288,15 +288,15 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv6(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -374,17 +374,17 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv4(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) var peer2 *PeerInfo = &PeerInfo{ Address: net.ParseIP("0.0.0.0"), } - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -462,18 +462,18 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv6(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) var peer2 *PeerInfo = &PeerInfo{ Address: net.ParseIP("0.0.0.0"), } - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -524,15 +524,15 @@ func TestProcessBGPUpdate_3_select_aspath_ipv4(t *testing.T) { bgpMessage1 := update_fromR2viaR1() peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) bgpMessage2 := update_fromR2() peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -581,15 +581,15 @@ func TestProcessBGPUpdate_3_select_aspath_ipv6(t *testing.T) { bgpMessage1 := update_fromR2viaR1_ipv6() peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) bgpMessage2 := update_fromR2_ipv6() peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -667,15 +667,15 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv4(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -753,15 +753,15 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv6(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -839,15 +839,15 @@ func TestProcessBGPUpdate_5_select_low_med_ipv4(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -925,15 +925,15 @@ func TestProcessBGPUpdate_5_select_low_med_ipv6(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -1013,15 +1013,15 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv4(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -1100,15 +1100,15 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv6(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -1190,15 +1190,15 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv4(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer3 := peerR3() - pList, wList, err = tm.ProcessUpdate(peer3, bgpMessage2) + pList, err = tm.ProcessUpdate(peer3, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -1277,15 +1277,15 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv6(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer3 := peerR3() - pList, wList, err = tm.ProcessUpdate(peer3, bgpMessage2) + pList, err = tm.ProcessUpdate(peer3, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -1364,15 +1364,15 @@ func TestProcessBGPUpdate_8_withdraw_path_ipv4(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -1419,9 +1419,9 @@ func TestProcessBGPUpdate_8_withdraw_path_ipv4(t *testing.T) { w := []bgp.WithdrawnRoute{w1} bgpMessage3 := bgp.NewBGPUpdateMessage(w, []bgp.PathAttributeInterface{}, []bgp.NLRInfo{}) - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage3) + pList, err = tm.ProcessUpdate(peer2, bgpMessage3) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) path = pList[0] @@ -1474,15 +1474,15 @@ func TestProcessBGPUpdate_8_mpunreach_path_ipv6(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) peer2 := peerR2() - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) + pList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -1554,9 +1554,9 @@ func TestProcessBGPUpdate_8_mpunreach_path_ipv6(t *testing.T) { bgpMessage3 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, []bgp.PathAttributeInterface{mp_unreach}, []bgp.NLRInfo{}) - pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage3) + pList, err = tm.ProcessUpdate(peer2, bgpMessage3) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) path = pList[0] @@ -1599,18 +1599,18 @@ func TestProcessBGPUpdate_bestpath_lost_ipv4(t *testing.T) { bgpMessage1_w := bgp.NewBGPUpdateMessage(w, []bgp.PathAttributeInterface{}, []bgp.NLRInfo{}) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) - pList, wList, err = tm.ProcessUpdate(peer1, bgpMessage1_w) - assert.Equal(t, 0, len(pList)) - assert.Equal(t, 1, len(wList)) + pList, err = tm.ProcessUpdate(peer1, bgpMessage1_w) + assert.Equal(t, 1, len(pList)) + assert.Equal(t, pList[0].IsWithdraw(), true) assert.NoError(t, err) // check old best path - path := wList[0] + path := pList[0] expectedType := "*table.IPv4Path" assert.Equal(t, reflect.TypeOf(path).String(), expectedType) @@ -1668,9 +1668,9 @@ func TestProcessBGPUpdate_bestpath_lost_ipv6(t *testing.T) { bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes1, pathAttributes1, nlri1) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // path1 mpunreach @@ -1678,13 +1678,13 @@ func TestProcessBGPUpdate_bestpath_lost_ipv6(t *testing.T) { bgpMessage1_w := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, []bgp.PathAttributeInterface{mp_unreach}, []bgp.NLRInfo{}) - pList, wList, err = tm.ProcessUpdate(peer1, bgpMessage1_w) - assert.Equal(t, 0, len(pList)) - assert.Equal(t, 1, len(wList)) + pList, err = tm.ProcessUpdate(peer1, bgpMessage1_w) + assert.Equal(t, 1, len(pList)) + assert.Equal(t, pList[0].IsWithdraw(), true) assert.NoError(t, err) // check old best path - path := wList[0] + path := pList[0] expectedType := "*table.IPv6Path" assert.Equal(t, reflect.TypeOf(path).String(), expectedType) @@ -1758,14 +1758,14 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv4(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) - pList, wList, err = tm.ProcessUpdate(peer1, bgpMessage2) + pList, err = tm.ProcessUpdate(peer1, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -1845,14 +1845,14 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv6(t *testing.T) { bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes2, pathAttributes2, nlri2) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) - pList, wList, err = tm.ProcessUpdate(peer1, bgpMessage2) + pList, err = tm.ProcessUpdate(peer1, bgpMessage2) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check type @@ -2013,9 +2013,11 @@ func TestProcessBGPUpdate_multiple_nlri_ipv4(t *testing.T) { bgpMessage4 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes4, nlri4) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 5, len(pList)) - assert.Equal(t, 0, len(wList)) + for _, p := range pList { + assert.Equal(t, p.IsWithdraw(), false) + } assert.NoError(t, err) checkBestPathResult("*table.IPv4Path", "10.10.10.0/24", "192.168.50.1", pList[0], bgpMessage1) @@ -2024,9 +2026,11 @@ func TestProcessBGPUpdate_multiple_nlri_ipv4(t *testing.T) { checkBestPathResult("*table.IPv4Path", "40.40.40.0/24", "192.168.50.1", pList[3], bgpMessage1) checkBestPathResult("*table.IPv4Path", "50.50.50.0/24", "192.168.50.1", pList[4], bgpMessage1) - pList, wList, err = tm.ProcessUpdate(peer1, bgpMessage2) + pList, err = tm.ProcessUpdate(peer1, bgpMessage2) assert.Equal(t, 5, len(pList)) - assert.Equal(t, 0, len(wList)) + for _, p := range pList { + assert.Equal(t, p.IsWithdraw(), false) + } assert.NoError(t, err) checkBestPathResult("*table.IPv4Path", "11.11.11.0/24", "192.168.50.1", pList[0], bgpMessage2) @@ -2035,14 +2039,16 @@ func TestProcessBGPUpdate_multiple_nlri_ipv4(t *testing.T) { checkBestPathResult("*table.IPv4Path", "44.44.44.0/24", "192.168.50.1", pList[3], bgpMessage2) checkBestPathResult("*table.IPv4Path", "55.55.55.0/24", "192.168.50.1", pList[4], bgpMessage2) - pList, wList, err = tm.ProcessUpdate(peer1, bgpMessage3) + pList, err = tm.ProcessUpdate(peer1, bgpMessage3) assert.Equal(t, 2, len(pList)) - assert.Equal(t, 0, len(wList)) + for _, p := range pList { + assert.Equal(t, p.IsWithdraw(), false) + } assert.NoError(t, err) - pList, wList, err = tm.ProcessUpdate(peer1, bgpMessage4) + pList, err = tm.ProcessUpdate(peer1, bgpMessage4) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check table @@ -2154,9 +2160,11 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { bgpMessage4 := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes4, []bgp.NLRInfo{}) peer1 := peerR1() - pList, wList, err := tm.ProcessUpdate(peer1, bgpMessage1) + pList, err := tm.ProcessUpdate(peer1, bgpMessage1) assert.Equal(t, 5, len(pList)) - assert.Equal(t, 0, len(wList)) + for _, p := range pList { + assert.Equal(t, p.IsWithdraw(), false) + } assert.NoError(t, err) checkBestPathResult("*table.IPv6Path", "2001:123:1210:11::/64", "2001::192:168:50:1", pList[0], bgpMessage1) @@ -2165,9 +2173,11 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { checkBestPathResult("*table.IPv6Path", "2001:123:1240:11::/64", "2001::192:168:50:1", pList[3], bgpMessage1) checkBestPathResult("*table.IPv6Path", "2001:123:1250:11::/64", "2001::192:168:50:1", pList[4], bgpMessage1) - pList, wList, err = tm.ProcessUpdate(peer1, bgpMessage2) + pList, err = tm.ProcessUpdate(peer1, bgpMessage2) assert.Equal(t, 5, len(pList)) - assert.Equal(t, 0, len(wList)) + for _, p := range pList { + assert.Equal(t, p.IsWithdraw(), false) + } assert.NoError(t, err) checkBestPathResult("*table.IPv6Path", "2001:123:1211:11::/64", "2001::192:168:50:1", pList[0], bgpMessage2) @@ -2176,14 +2186,16 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { checkBestPathResult("*table.IPv6Path", "2001:123:1244:11::/64", "2001::192:168:50:1", pList[3], bgpMessage2) checkBestPathResult("*table.IPv6Path", "2001:123:1255:11::/64", "2001::192:168:50:1", pList[4], bgpMessage2) - pList, wList, err = tm.ProcessUpdate(peer1, bgpMessage3) + pList, err = tm.ProcessUpdate(peer1, bgpMessage3) assert.Equal(t, 2, len(pList)) - assert.Equal(t, 0, len(wList)) + for _, p := range pList { + assert.Equal(t, p.IsWithdraw(), false) + } assert.NoError(t, err) - pList, wList, err = tm.ProcessUpdate(peer1, bgpMessage4) + pList, err = tm.ProcessUpdate(peer1, bgpMessage4) assert.Equal(t, 1, len(pList)) - assert.Equal(t, 0, len(wList)) + assert.Equal(t, pList[0].IsWithdraw(), false) assert.NoError(t, err) // check table |