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 }
// 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 }