From 483d37a1b4b5ea053ec7c95073b9f05a2152385f Mon Sep 17 00:00:00 2001 From: Hiroshi Yokoi Date: Tue, 28 Apr 2015 20:13:10 +0900 Subject: policy: add AsPathLength match --- table/path.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'table/path.go') 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) { -- cgit v1.2.3