diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-23 00:47:47 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-23 00:47:47 +0900 |
commit | 07310dec12ca1d8e9dc0f04798ed4cac9bd0dd6d (patch) | |
tree | 4443847f595f10a14bc733a43b59a2210b9b90fc /table | |
parent | 12ae36fb0fecdd068fa4b3a8c1ea36d95b29bf7c (diff) |
table: handle timestamp in Path in UpdateIn()
We update rib-in first and then local. So should handle timestamp
before adding path to rib-in.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 3 | ||||
-rw-r--r-- | table/table_manager.go | 6 | ||||
-rw-r--r-- | table/table_manager_test.go | 51 |
3 files changed, 31 insertions, 29 deletions
diff --git a/table/destination.go b/table/destination.go index b35d380a..865ab03e 100644 --- a/table/destination.go +++ b/table/destination.go @@ -368,9 +368,6 @@ func (dest *DestinationDefault) removeOldPaths() { // paths and when doing RouteRefresh (not EnhancedRouteRefresh) // we get same paths again. if newPath.getSource() == path.getSource() { - if reflect.DeepEqual(newPath.getPathAttrs(), path.getPathAttrs()) { - newPath.setTimestamp(path.getTimestamp()) - } oldPaths = append(oldPaths, path) break } diff --git a/table/table_manager.go b/table/table_manager.go index 242b8ae2..a6fda7e3 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -18,6 +18,7 @@ package table import ( log "github.com/Sirupsen/logrus" "github.com/osrg/gobgp/packet" + "reflect" "time" ) @@ -246,12 +247,15 @@ func (adj *AdjRib) update(rib map[bgp.RouteFamily]map[string]*ReceivedRoute, pat for _, path := range pathList { rf := path.GetRouteFamily() key := path.getPrefix() + old, found := rib[rf][key] if path.IsWithdraw() { - _, found := rib[rf][key] if found { delete(rib[rf], key) } } else { + if found && reflect.DeepEqual(old.path.getPathAttrs(), path.getPathAttrs()) { + path.setTimestamp(old.path.getTimestamp()) + } rib[rf][key] = NewReceivedRoute(path, false) } } diff --git a/table/table_manager_test.go b/table/table_manager_test.go index f7c126bf..0cb81b6e 100644 --- a/table/table_manager_test.go +++ b/table/table_manager_test.go @@ -2185,8 +2185,6 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { } func TestProcessBGPUpdate_Timestamp(t *testing.T) { - tm := NewTableManager() - origin := bgp.NewPathAttributeOrigin(0) aspathParam := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{65000})} aspath := bgp.NewPathAttributeAsPath(aspathParam) @@ -2203,24 +2201,25 @@ func TestProcessBGPUpdate_Timestamp(t *testing.T) { nlri := []bgp.NLRInfo{*bgp.NewNLRInfo(24, "10.10.10.0")} withdrawnRoutes := []bgp.WithdrawnRoute{} - bgpMessage1 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) - + adjRib := NewAdjRib() + m1 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) peer := peerR1() - pList, wList, err := tm.ProcessUpdate(peer, bgpMessage1) - assert.Equal(t, len(pList), 1) - assert.Equal(t, len(wList), 0) - assert.NoError(t, err) - - path1 := pList[0].(*IPv4Path) - - bgpMessage2 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) - pList, wList, err = tm.ProcessUpdate(peer, bgpMessage2) - assert.Equal(t, len(pList), 1) - assert.Equal(t, len(wList), 0) - - path2 := pList[0].(*IPv4Path) - - assert.Equal(t, path1.timestamp, path2.timestamp) + msg1 := NewProcessMessage(m1, peer) + pList1 := msg1.ToPathList() + path1 := pList1[0].(*IPv4Path) + t1 := path1.timestamp + adjRib.UpdateIn(pList1) + + m2 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri) + msg2 := NewProcessMessage(m2, peer) + pList2 := msg2.ToPathList() + //path2 := pList2[0].(*IPv4Path) + //t2 = path2.timestamp + adjRib.UpdateIn(pList2) + + inList := adjRib.GetInPathList(bgp.RF_IPv4_UC) + assert.Equal(t, len(inList), 1) + assert.Equal(t, inList[0].getTimestamp(), t1) med2 := bgp.NewPathAttributeMultiExitDisc(1) pathAttributes2 := []bgp.PathAttributeInterface{ @@ -2230,13 +2229,15 @@ func TestProcessBGPUpdate_Timestamp(t *testing.T) { med2, } - bgpMessage3 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes2, nlri) - pList, wList, err = tm.ProcessUpdate(peer, bgpMessage3) - assert.Equal(t, len(pList), 1) - assert.Equal(t, len(wList), 0) + m3 := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes2, nlri) + msg3 := NewProcessMessage(m3, peer) + pList3 := msg3.ToPathList() + t3 := pList3[0].getTimestamp() + adjRib.UpdateIn(pList3) - path3 := pList[0].(*IPv4Path) - assert.NotEqual(t, path2.timestamp, path3.timestamp) + inList = adjRib.GetInPathList(bgp.RF_IPv4_UC) + assert.Equal(t, len(inList), 1) + assert.Equal(t, inList[0].getTimestamp(), t3) } func update_fromR1() *bgp.BGPMessage { |