diff options
Diffstat (limited to 'table')
-rw-r--r-- | table/path.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/table/path.go b/table/path.go index 29d8a92d..a1f87391 100644 --- a/table/path.go +++ b/table/path.go @@ -33,6 +33,7 @@ type Path interface { getPathAttr(bgp.BGPAttrType) (int, bgp.PathAttributeInterface) updatePathAttrs(global *config.Global, peer *config.Neighbor) GetRouteFamily() bgp.RouteFamily + GetAsPathLen() int setSource(source *PeerInfo) GetSource() *PeerInfo GetSourceAs() uint32 @@ -332,6 +333,34 @@ func (pi *PathDefault) getPrefix() string { return pi.nlri.String() } +// return total length of AS_PATH whose type is AS_SEQ or AS_SET +func (pd *PathDefault) GetAsPathLen() int { + + aslen := func(p *bgp.As4PathParam) int { + if p.Type == bgp.BGP_ASPATH_ATTR_TYPE_SEQ || p.Type == bgp.BGP_ASPATH_ATTR_TYPE_SET { + return p.ASLen() + } + return 0 + } + + var length int = 0 + if _, attr := pd.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH); attr != nil { + aspath := attr.(*bgp.PathAttributeAsPath) + for _, paramIf := range aspath.Value { + segment := paramIf.(*bgp.As4PathParam) + length += aslen(segment) + } + + } else { + _, attr := pd.getPathAttr(bgp.BGP_ATTR_TYPE_AS4_PATH) + aspath := attr.(*bgp.PathAttributeAs4Path) + for _, segment := range aspath.Value { + length += aslen(segment) + } + } + return length +} + // create Path object based on route family func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.PathAttributeInterface, isWithdraw bool, now time.Time) (Path, error) { |