From ababf3068c48d665e2d9d7816cbb521c74fc47c5 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Sat, 22 Dec 2018 16:33:37 +0900 Subject: make Add/Delete/ListPath APIs symmetric - AddPath() with an api.Path object then DeletePath() works with the same api.Path object. - ListPath() returns an api.Path object then DeletePath() works with the same api.Path object. The above is guaranteed with and without PeerInfo (SourceAsn and SourceId). Signed-off-by: FUJITA Tomonori --- internal/pkg/table/path.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'internal/pkg/table') diff --git a/internal/pkg/table/path.go b/internal/pkg/table/path.go index 55748b08..eba0a6ec 100644 --- a/internal/pkg/table/path.go +++ b/internal/pkg/table/path.go @@ -146,7 +146,12 @@ type Path struct { IsWithdraw bool } +var localSource = &PeerInfo{} + func NewPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, pattrs []bgp.PathAttributeInterface, timestamp time.Time, noImplicitWithdraw bool) *Path { + if source == nil { + source = localSource + } if !isWithdraw && pattrs == nil { log.WithFields(log.Fields{ "Topic": "Table", @@ -323,7 +328,8 @@ func (path *Path) IsLocal() bool { } func (path *Path) IsIBGP() bool { - return path.GetSource().AS == path.GetSource().LocalAS + as := path.GetSource().AS + return (as == path.GetSource().LocalAS) && as != 0 } // create new PathAttributes @@ -380,9 +386,6 @@ func (path *Path) GetRouteFamily() bgp.RouteFamily { return bgp.AfiSafiToRouteFamily(path.OriginInfo().nlri.AFI(), path.OriginInfo().nlri.SAFI()) } -func (path *Path) SetSource(source *PeerInfo) { - path.OriginInfo().source = source -} func (path *Path) GetSource() *PeerInfo { return path.OriginInfo().source } -- cgit v1.2.3