diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-04-28 20:13:10 +0900 |
---|---|---|
committer | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-04-30 15:52:05 +0900 |
commit | 483d37a1b4b5ea053ec7c95073b9f05a2152385f (patch) | |
tree | 24c92c8779db8073a31a533b63a77fd4930d6c5c /table/path.go | |
parent | f9577fe75336776c6113ae065062a2455193c798 (diff) |
policy: add AsPathLength match
Diffstat (limited to 'table/path.go')
-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) { |