From cf23ecec82526d33a67cb101c4384839fea2f95f Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Mon, 3 Aug 2015 15:41:25 +0900 Subject: mrt: merge gomrt to gobgp cli command Usage $ gobgp mrt inject global [] Signed-off-by: ISHIDA Wataru --- table/destination.go | 3 +++ table/destination_test.go | 2 +- table/path.go | 6 ++++-- table/path_test.go | 20 ++++++++++---------- table/table_manager.go | 8 ++++---- table/table_test.go | 2 +- 6 files changed, 23 insertions(+), 18 deletions(-) (limited to 'table') diff --git a/table/destination.go b/table/destination.go index 65697570..5b704e6b 100644 --- a/table/destination.go +++ b/table/destination.go @@ -369,6 +369,9 @@ func (dest *Destination) removeOldPaths() { knownPaths := dest.knownPathList for _, newPath := range newPaths { + if newPath.NoImplicitWithdraw { + continue + } oldPaths := make([]*Path, 0) for _, path := range knownPaths { // Here we just check if source is same and not check if path diff --git a/table/destination_test.go b/table/destination_test.go index 0b1b8e3b..80eaa2a4 100644 --- a/table/destination_test.go +++ b/table/destination_test.go @@ -124,7 +124,7 @@ func DestCreatePath(peerD []*PeerInfo) []*Path { nlriList := updateMsgD.NLRI pathAttributes := updateMsgD.PathAttributes nlri_info := nlriList[0] - pathD[i] = NewPath(peerD[i], &nlri_info, false, pathAttributes, false, time.Now()) + pathD[i] = NewPath(peerD[i], &nlri_info, false, pathAttributes, false, time.Now(), false) } return pathD } diff --git a/table/path.go b/table/path.go index 251eefbc..18b118b9 100644 --- a/table/path.go +++ b/table/path.go @@ -35,9 +35,10 @@ type Path struct { pathAttrs []bgp.PathAttributeInterface medSetByTargetNeighbor bool timestamp time.Time + NoImplicitWithdraw bool } -func NewPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, pattrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool, timestamp time.Time) *Path { +func NewPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, pattrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool, timestamp time.Time, noImplicitWithdraw bool) *Path { if !isWithdraw && pattrs == nil { log.WithFields(log.Fields{ "Topic": "Table", @@ -54,6 +55,7 @@ func NewPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, pa pathAttrs: pattrs, medSetByTargetNeighbor: medSetByTargetNeighbor, timestamp: timestamp, + NoImplicitWithdraw: noImplicitWithdraw, } } @@ -172,7 +174,7 @@ func (path *Path) Clone(isWithdraw bool) *Path { newPathAttrs[i] = v } - return NewPath(path.source, nlri, isWithdraw, newPathAttrs, false, path.timestamp) + return NewPath(path.source, nlri, isWithdraw, newPathAttrs, false, path.timestamp, path.NoImplicitWithdraw) } func (path *Path) GetRouteFamily() bgp.RouteFamily { diff --git a/table/path_test.go b/table/path_test.go index d973294a..7fca310f 100644 --- a/table/path_test.go +++ b/table/path_test.go @@ -14,13 +14,13 @@ import ( func TestPathNewIPv4(t *testing.T) { peerP := PathCreatePeer() pathP := PathCreatePath(peerP) - ipv4p := NewPath(pathP[0].GetSource(), pathP[0].GetNlri(), true, pathP[0].GetPathAttrs(), pathP[0].getMedSetByTargetNeighbor(), time.Now()) + ipv4p := NewPath(pathP[0].GetSource(), pathP[0].GetNlri(), true, pathP[0].GetPathAttrs(), pathP[0].getMedSetByTargetNeighbor(), time.Now(), false) assert.NotNil(t, ipv4p) } func TestPathNewIPv6(t *testing.T) { peerP := PathCreatePeer() pathP := PathCreatePath(peerP) - ipv6p := NewPath(pathP[0].GetSource(), pathP[0].GetNlri(), true, pathP[0].GetPathAttrs(), pathP[0].getMedSetByTargetNeighbor(), time.Now()) + ipv6p := NewPath(pathP[0].GetSource(), pathP[0].GetNlri(), true, pathP[0].GetPathAttrs(), pathP[0].getMedSetByTargetNeighbor(), time.Now(), false) assert.NotNil(t, ipv6p) } @@ -72,7 +72,7 @@ func TestPathCreatePath(t *testing.T) { nlriList := updateMsgP.NLRI pathAttributes := updateMsgP.PathAttributes nlri_info := nlriList[0] - path := NewPath(peerP[0], &nlri_info, false, pathAttributes, false, time.Now()) + path := NewPath(peerP[0], &nlri_info, false, pathAttributes, false, time.Now(), false) assert.NotNil(t, path) } @@ -118,7 +118,7 @@ func TestASPathLen(t *testing.T) { update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now()) + p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) assert.Equal(10, p.GetAsPathLen()) } @@ -145,7 +145,7 @@ func TestPathPrependAsnToExistingSeqAttr(t *testing.T) { update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now()) + p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) p.PrependAsn(65000, 1) assert.Equal([]uint32{65000, 65001, 65002, 65003, 65004, 65005}, p.GetAsSeqList()) @@ -168,7 +168,7 @@ func TestPathPrependAsnToNewAsPathAttr(t *testing.T) { update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now()) + p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) asn := uint32(65000) p.PrependAsn(asn, 1) @@ -197,7 +197,7 @@ func TestPathPrependAsnToNewAsPathSeq(t *testing.T) { update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now()) + p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) asn := uint32(65000) p.PrependAsn(asn, 1) @@ -228,7 +228,7 @@ func TestPathPrependAsnToEmptyAsPathAttr(t *testing.T) { update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now()) + p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) asn := uint32(65000) p.PrependAsn(asn, 1) @@ -265,7 +265,7 @@ func TestPathPrependAsnToFullPathAttr(t *testing.T) { update := bgpmsg.Body.(*bgp.BGPUpdate) UpdatePathAttrs4ByteAs(update) peer := PathCreatePeer() - p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now()) + p := NewPath(peer[0], &update.NLRI[0], false, update.PathAttributes, false, time.Now(), false) expected := []uint32{65000, 65000} for _, v := range asns { @@ -294,7 +294,7 @@ func PathCreatePath(peerP []*PeerInfo) []*Path { nlriList := updateMsgP.NLRI pathAttributes := updateMsgP.PathAttributes nlri_info := nlriList[0] - pathP[i] = NewPath(peerP[i], &nlri_info, false, pathAttributes, false, time.Now()) + pathP[i] = NewPath(peerP[i], &nlri_info, false, pathAttributes, false, time.Now(), false) } return pathP } diff --git a/table/table_manager.go b/table/table_manager.go index 65ead593..4b164228 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -30,7 +30,7 @@ func nlri2Path(m *bgp.BGPMessage, p *PeerInfo, now time.Time) []*Path { // define local variable to pass nlri's address to CreatePath var nlri bgp.NLRInfo = nlri_info // create Path object - path := NewPath(p, &nlri, false, pathAttributes, false, now) + path := NewPath(p, &nlri, false, pathAttributes, false, now, false) pathList = append(pathList, path) } return pathList @@ -44,7 +44,7 @@ func withdraw2Path(m *bgp.BGPMessage, p *PeerInfo, now time.Time) []*Path { // define local variable to pass nlri's address to CreatePath var w bgp.WithdrawnRoute = nlriWithdraw // create withdrawn Path object - path := NewPath(p, &w, true, pathAttributes, false, now) + path := NewPath(p, &w, true, pathAttributes, false, now, false) pathList = append(pathList, path) } return pathList @@ -67,7 +67,7 @@ func mpreachNlri2Path(m *bgp.BGPMessage, p *PeerInfo, now time.Time) []*Path { for _, mp := range attrList { nlri_info := mp.Value for _, nlri := range nlri_info { - path := NewPath(p, nlri, false, pathAttributes, false, now) + path := NewPath(p, nlri, false, pathAttributes, false, now, false) pathList = append(pathList, path) } } @@ -92,7 +92,7 @@ func mpunreachNlri2Path(m *bgp.BGPMessage, p *PeerInfo, now time.Time) []*Path { nlri_info := mp.Value for _, nlri := range nlri_info { - path := NewPath(p, nlri, true, pathAttributes, false, now) + path := NewPath(p, nlri, true, pathAttributes, false, now, false) pathList = append(pathList, path) } } diff --git a/table/table_test.go b/table/table_test.go index de8b271c..9f1e6f16 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -107,7 +107,7 @@ func TableCreatePath(peerT []*PeerInfo) []*Path { nlriList := updateMsgT.NLRI pathAttributes := updateMsgT.PathAttributes nlri_info := nlriList[0] - pathT[i] = NewPath(peerT[i], &nlri_info, false, pathAttributes, false, time.Now()) + pathT[i] = NewPath(peerT[i], &nlri_info, false, pathAttributes, false, time.Now(), false) } return pathT } -- cgit v1.2.3