当前位置: 首页>>代码示例>>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;未经允许,请勿转载。