本文整理匯總了Golang中github.com/osrg/gobgp/table.Path.GetCommunities方法的典型用法代碼示例。如果您正苦於以下問題:Golang Path.GetCommunities方法的具體用法?Golang Path.GetCommunities怎麽用?Golang Path.GetCommunities使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/osrg/gobgp/table.Path
的用法示例。
在下文中一共展示了Path.GetCommunities方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: evaluate
// compare community in the message's attribute with
// the one in the condition.
func (c *CommunityCondition) evaluate(path *table.Path) bool {
communities := path.GetCommunities()
if len(communities) == 0 {
return false
}
makeStr := func(c uint32) string {
upper := strconv.FormatUint(uint64(c&0xFFFF0000>>16), 10)
lower := strconv.FormatUint(uint64(c&0x0000FFFF), 10)
return upper + ":" + lower
}
var strCommunities []string = nil
matched := false
idx := -1
for _, member := range c.CommunityList {
if member.isRegExp {
if strCommunities == nil {
// create community string.
strCommunities = make([]string, len(communities))
for i, c := range communities {
strCommunities[i] = makeStr(c)
}
}
for i, c := range strCommunities {
if member.communityRegExp.MatchString(c) {
matched = true
idx = i
log.WithFields(log.Fields{
"Topic": "Policy",
"RegExp": member.communityRegExp.String(),
}).Debug("community regexp used")
break
}
}
} else {
for i, c := range communities {
if c == member.community {
matched = true
idx = i
break
}
}
}
if matched {
log.WithFields(log.Fields{
"Topic": "Policy",
"Condition": "Community",
"Community": makeStr(communities[idx]),
}).Debug("condition matched")
return true
}
}
return false
}