當前位置: 首頁>>代碼示例>>Golang>>正文


Golang AddrPrefixInterface.AFI方法代碼示例

本文整理匯總了Golang中github.com/osrg/gobgp/packet/bgp.AddrPrefixInterface.AFI方法的典型用法代碼示例。如果您正苦於以下問題:Golang AddrPrefixInterface.AFI方法的具體用法?Golang AddrPrefixInterface.AFI怎麽用?Golang AddrPrefixInterface.AFI使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/osrg/gobgp/packet/bgp.AddrPrefixInterface的用法示例。


在下文中一共展示了AddrPrefixInterface.AFI方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewRib

func NewRib(seq uint32, prefix bgp.AddrPrefixInterface, entries []*RibEntry) *Rib {
    rf := bgp.AfiSafiToRouteFamily(prefix.AFI(), prefix.SAFI())
    return &Rib{
        SequenceNumber: seq,
        Prefix:         prefix,
        Entries:        entries,
        RouteFamily:    rf,
    }
}
開發者ID:mfeed,項目名稱:gobgp,代碼行數:9,代碼來源:mrt.go

示例2: NewDestination

func NewDestination(nlri bgp.AddrPrefixInterface) *Destination {
    d := &Destination{
        routeFamily:   bgp.AfiSafiToRouteFamily(nlri.AFI(), nlri.SAFI()),
        nlri:          nlri,
        knownPathList: make([]*Path, 0),
        withdrawList:  make([]*Path, 0),
        newPathList:   make([]*Path, 0),
    }
    switch d.routeFamily {
    case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC:
        d.RadixKey = CidrToRadixkey(nlri.String())
    }
    return d
}
開發者ID:mfeed,項目名稱:gobgp,代碼行數:14,代碼來源:destination.go

示例3: api2PathList

func (s *Server) api2PathList(resource Resource, ApiPathList []*Path) ([]*table.Path, error) {
    var nlri bgp.AddrPrefixInterface
    var nexthop string
    var pi *table.PeerInfo

    pathList := make([]*table.Path, 0, len(ApiPathList))
    for _, path := range ApiPathList {
        seen := make(map[bgp.BGPAttrType]bool)

        pattr := make([]bgp.PathAttributeInterface, 0)
        extcomms := make([]bgp.ExtendedCommunityInterface, 0)

        if path.SourceAsn != 0 {
            pi = &table.PeerInfo{
                AS:      path.SourceAsn,
                LocalID: net.ParseIP(path.SourceId),
            }
        }

        if len(path.Nlri) > 0 {
            nlri = &bgp.IPAddrPrefix{}
            err := nlri.DecodeFromBytes(path.Nlri)
            if err != nil {
                return nil, err
            }
        }

        for _, attr := range path.Pattrs {
            p, err := bgp.GetPathAttribute(attr)
            if err != nil {
                return nil, err
            }

            err = p.DecodeFromBytes(attr)
            if err != nil {
                return nil, err
            }

            if _, ok := seen[p.GetType()]; !ok {
                seen[p.GetType()] = true
            } else {
                return nil, fmt.Errorf("the path attribute apears twice. Type : " + strconv.Itoa(int(p.GetType())))
            }
            switch p.GetType() {
            case bgp.BGP_ATTR_TYPE_NEXT_HOP:
                nexthop = p.(*bgp.PathAttributeNextHop).Value.String()
            case bgp.BGP_ATTR_TYPE_EXTENDED_COMMUNITIES:
                value := p.(*bgp.PathAttributeExtendedCommunities).Value
                if len(value) > 0 {
                    extcomms = append(extcomms, value...)
                }
            case bgp.BGP_ATTR_TYPE_MP_REACH_NLRI:
                mpreach := p.(*bgp.PathAttributeMpReachNLRI)
                if len(mpreach.Value) != 1 {
                    return nil, fmt.Errorf("include only one route in mp_reach_nlri")
                }
                nlri = mpreach.Value[0]
                nexthop = mpreach.Nexthop.String()
            default:
                pattr = append(pattr, p)
            }
        }

        if nlri == nil || nexthop == "" {
            return nil, fmt.Errorf("not found nlri or nexthop")
        }

        rf := bgp.AfiSafiToRouteFamily(nlri.AFI(), nlri.SAFI())

        if resource != Resource_VRF && rf == bgp.RF_IPv4_UC {
            pattr = append(pattr, bgp.NewPathAttributeNextHop(nexthop))
        } else {
            pattr = append(pattr, bgp.NewPathAttributeMpReachNLRI(nexthop, []bgp.AddrPrefixInterface{nlri}))
        }

        if len(extcomms) > 0 {
            pattr = append(pattr, bgp.NewPathAttributeExtendedCommunities(extcomms))
        }
        newPath := table.NewPath(pi, nlri, path.IsWithdraw, pattr, time.Now(), path.NoImplicitWithdraw)
        newPath.SetIsFromExternal(path.IsFromExternal)
        pathList = append(pathList, newPath)
    }
    return pathList, nil
}
開發者ID:jojimt,項目名稱:netplugin,代碼行數:84,代碼來源:grpc_server.go


注:本文中的github.com/osrg/gobgp/packet/bgp.AddrPrefixInterface.AFI方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。