diff options
Diffstat (limited to 'table/destination_test.go')
-rw-r--r-- | table/destination_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/table/destination_test.go b/table/destination_test.go index c0666e21..275c4473 100644 --- a/table/destination_test.go +++ b/table/destination_test.go @@ -217,6 +217,62 @@ func TestImplicitWithdrawCalculate(t *testing.T) { assert.Equal(t, len(d.knownPathList), 1) } +func TestMedTieBreaker(t *testing.T) { + nlri := bgp.NewIPAddrPrefix(24, "10.10.0.0") + + p0 := func() *Path { + aspath := bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{65001, 65002}), bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{65003, 65004})}) + attrs := []bgp.PathAttributeInterface{aspath, bgp.NewPathAttributeMultiExitDisc(0)} + return NewPath(nil, nlri, false, attrs, time.Now(), false) + }() + + p1 := func() *Path { + aspath := bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{65001, 65002}), bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{65003, 65004})}) + attrs := []bgp.PathAttributeInterface{aspath, bgp.NewPathAttributeMultiExitDisc(10)} + return NewPath(nil, nlri, false, attrs, time.Now(), false) + }() + + // same AS + assert.Equal(t, compareByMED(p0, p1), p0) + + p2 := func() *Path { + aspath := bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{65003})}) + attrs := []bgp.PathAttributeInterface{aspath, bgp.NewPathAttributeMultiExitDisc(10)} + return NewPath(nil, nlri, false, attrs, time.Now(), false) + }() + + // different AS + assert.Equal(t, compareByMED(p0, p2), (*Path)(nil)) + + p3 := func() *Path { + aspath := bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{65001, 65002}), bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint32{65003, 65004})}) + attrs := []bgp.PathAttributeInterface{aspath, bgp.NewPathAttributeMultiExitDisc(0)} + return NewPath(nil, nlri, false, attrs, time.Now(), false) + }() + + p4 := func() *Path { + aspath := bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{65001, 65002}), bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint32{65005, 65006})}) + attrs := []bgp.PathAttributeInterface{aspath, bgp.NewPathAttributeMultiExitDisc(10)} + return NewPath(nil, nlri, false, attrs, time.Now(), false) + }() + + // ignore confed + assert.Equal(t, compareByMED(p3, p4), p3) + + p5 := func() *Path { + attrs := []bgp.PathAttributeInterface{bgp.NewPathAttributeMultiExitDisc(0)} + return NewPath(nil, nlri, false, attrs, time.Now(), false) + }() + + p6 := func() *Path { + attrs := []bgp.PathAttributeInterface{bgp.NewPathAttributeMultiExitDisc(10)} + return NewPath(nil, nlri, false, attrs, time.Now(), false) + }() + + // no aspath + assert.Equal(t, compareByMED(p5, p6), p5) +} + func TestTimeTieBreaker(t *testing.T) { origin := bgp.NewPathAttributeOrigin(0) aspathParam := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{65001})} |