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


Golang Path.GetAsSeqList方法代碼示例

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


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

示例1: apply

func (a *AsPathPrependAction) apply(path *table.Path) *table.Path {

	var asn uint32
	if a.useLeftMost {
		asns := path.GetAsSeqList()
		if len(asns) == 0 {
			log.WithFields(log.Fields{
				"Topic": "Policy",
				"Type":  "AsPathPrepend Action",
			}).Error("aspath length is zero.")
			return path
		}
		asn = asns[0]
		log.WithFields(log.Fields{
			"Topic":  "Policy",
			"Type":   "AsPathPrepend Action",
			"LastAs": asn,
			"Repeat": a.repeat,
		}).Debug("use last AS.")
	} else {
		asn = a.asn
	}

	path.PrependAsn(asn, a.repeat)
	return path
}
開發者ID:ttaanngg,項目名稱:gobgp,代碼行數:26,代碼來源:policy.go

示例2: evaluate

// compare AS_PATH in the message's AS_PATH attribute with
// the one in condition.
func (c *AsPathCondition) evaluate(path *table.Path) bool {

	aspath := path.GetAsSeqList()

	if len(aspath) == 0 {
		return false
	}

	matched := false
	for _, member := range c.AsPathList {

		switch member.postiion {
		case AS_FROM:
			matched = aspath[0] == member.asn
		case AS_ANY:
			for _, n := range aspath {
				if n == member.asn {
					matched = true
					break
				}
			}
		case AS_ORIGIN:
			matched = aspath[len(aspath)-1] == member.asn

		case AS_ONLY:
			matched = len(aspath) == 1 && aspath[0] == member.asn

		}

		if matched {
			log.WithFields(log.Fields{
				"Topic":     "Policy",
				"Condition": "aspath length",
				"ASN":       member.asn,
				"Position":  member.postiion,
			}).Debug("condition matched")
			return true
		}

	}
	return false
}
開發者ID:ttaanngg,項目名稱:gobgp,代碼行數:44,代碼來源:policy.go


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