diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-04-15 05:26:23 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-04-19 14:15:15 +0900 |
commit | 893f92f861291b369532b75baa87a63dca57d2ab (patch) | |
tree | 4eb2dec56c6117d13dfca2fbe3277421267a9514 | |
parent | 3bd6e20fe4e3fb60b28dbd06367627bd4df9ddff (diff) |
table: fix bug of incomplete withdrawal handling
When mod action is used in route server configuration,
`Destination.knownPathList` holds multiple modified paths whose original path
is same.
In that case, when the original path is withdrawn, we must remove all
modified paths.
There was a wrong `break` in `Destination.explicitWithdraw()` which avoids
this.
test is also added to check the behavior.
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | table/destination.go | 2 | ||||
-rw-r--r-- | table/destination_test.go | 42 |
2 files changed, 42 insertions, 2 deletions
diff --git a/table/destination.go b/table/destination.go index 6839c608..5603f894 100644 --- a/table/destination.go +++ b/table/destination.go @@ -317,8 +317,6 @@ func (dest *Destination) explicitWithdraw() paths { isFound = true path.IsWithdraw = true matches = append(matches, path) - // One withdraw can remove only one path. - break } } diff --git a/table/destination_test.go b/table/destination_test.go index d7498142..f30a52ff 100644 --- a/table/destination_test.go +++ b/table/destination_test.go @@ -63,6 +63,48 @@ func TestDestinationGetNlri(t *testing.T) { r_nlri := dd.GetNlri() assert.Equal(t, r_nlri, nlri) } + +func TestCalculate(t *testing.T) { + origin := bgp.NewPathAttributeOrigin(0) + aspathParam := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{65001})} + aspath := bgp.NewPathAttributeAsPath(aspathParam) + nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") + med := bgp.NewPathAttributeMultiExitDisc(0) + pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} + nlri := bgp.NewIPAddrPrefix(24, "10.10.0.101") + updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, []*bgp.IPAddrPrefix{nlri}) + peer1 := &PeerInfo{AS: 1, Address: net.IP{1, 1, 1, 1}} + path1 := ProcessMessage(updateMsg, peer1, time.Now())[0] + path1.Filter("1", POLICY_DIRECTION_IMPORT) + + action := &AsPathPrependAction{ + asn: 100, + repeat: 10, + } + + path2 := action.Apply(path1.Clone(false)) + path1.Filter("2", POLICY_DIRECTION_IMPORT) + path2.Filter("1", POLICY_DIRECTION_IMPORT) + + d := NewDestination(nlri) + d.addNewPath(path1) + d.addNewPath(path2) + + d.Calculate([]string{"1", "2"}) + + assert.Equal(t, len(d.GetKnownPathList("1")), 0) + assert.Equal(t, len(d.GetKnownPathList("2")), 1) + assert.Equal(t, len(d.knownPathList), 2) + + d.addWithdraw(path1.Clone(true)) + + d.Calculate([]string{"1", "2"}) + + assert.Equal(t, len(d.GetKnownPathList("1")), 0) + assert.Equal(t, len(d.GetKnownPathList("2")), 0) + assert.Equal(t, len(d.knownPathList), 0) +} + func DestCreatePeer() []*PeerInfo { peerD1 := &PeerInfo{AS: 65000} peerD2 := &PeerInfo{AS: 65001} |