Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Community Count BGP Policy Condition #394

Merged
merged 4 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions bgp/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func TestIntendedToGoBGPPolicies(t *testing.T) {
}
v4Stmt.GetOrCreateConditions().GetOrCreateMatchPrefixSet().SetPrefixSet(prefixSet1Name)
v4Stmt.GetOrCreateConditions().GetOrCreateMatchPrefixSet().SetMatchSetOptions(oc.PolicyTypes_MatchSetOptionsRestrictedType_ANY)
v4Stmt.GetOrCreateConditions().GetOrCreateBgpConditions().GetOrCreateCommunityCount().SetOperator(oc.PolicyTypes_ATTRIBUTE_COMPARISON_ATTRIBUTE_EQ)
v4Stmt.GetOrCreateConditions().GetOrCreateBgpConditions().GetOrCreateCommunityCount().SetValue(42)
v4Stmt.GetOrCreateActions().GetOrCreateBgpActions().GetOrCreateSetCommunity().GetOrCreateReference().SetCommunitySetRef(commsetName)
v4Stmt.GetOrCreateActions().GetOrCreateBgpActions().GetOrCreateSetCommunity().SetMethod(oc.SetCommunity_Method_REFERENCE)
v4Stmt.GetOrCreateActions().GetOrCreateBgpActions().GetOrCreateSetCommunity().SetOptions(oc.BgpPolicy_BgpSetCommunityOptionType_ADD)
Expand Down Expand Up @@ -156,12 +158,15 @@ func TestIntendedToGoBGPPolicies(t *testing.T) {
MatchAsPathSet: gobgpoc.MatchAsPathSet{
AsPathSet: "", MatchSetOptions: "any",
},
MedEq: 0x0,
OriginEq: "",
NextHopInList: []string(nil),
AfiSafiInList: []gobgpoc.AfiSafiType(nil),
LocalPrefEq: 0x0,
CommunityCount: gobgpoc.CommunityCount{Operator: "", Value: 0x0},
MedEq: 0x0,
OriginEq: "",
NextHopInList: []string(nil),
AfiSafiInList: []gobgpoc.AfiSafiType(nil),
LocalPrefEq: 0x0,
CommunityCount: gobgpoc.CommunityCount{
Operator: gobgpoc.ATTRIBUTE_COMPARISON_EQ,
Value: 42,
},
AsPathLength: gobgpoc.AsPathLength{Operator: "", Value: 0x0},
RouteType: "",
RpkiValidationResult: "",
Expand Down Expand Up @@ -273,12 +278,15 @@ func TestIntendedToGoBGPPolicies(t *testing.T) {
MatchAsPathSet: gobgpoc.MatchAsPathSet{
AsPathSet: "", MatchSetOptions: "any",
},
MedEq: 0x0,
OriginEq: "",
NextHopInList: []string(nil),
AfiSafiInList: []gobgpoc.AfiSafiType(nil),
LocalPrefEq: 0x0,
CommunityCount: gobgpoc.CommunityCount{Operator: "", Value: 0x0},
MedEq: 0x0,
OriginEq: "",
NextHopInList: []string(nil),
AfiSafiInList: []gobgpoc.AfiSafiType(nil),
LocalPrefEq: 0x0,
CommunityCount: gobgpoc.CommunityCount{
Operator: gobgpoc.ATTRIBUTE_COMPARISON_EQ,
Value: 42,
},
AsPathLength: gobgpoc.AsPathLength{Operator: "", Value: 0x0},
RouteType: "",
RpkiValidationResult: "",
Expand Down
17 changes: 17 additions & 0 deletions bgp/ocgobgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func convertPolicyDefinition(policy *oc.RoutingPolicy_PolicyDefinition, neighAdd
CommunitySet: statement.Conditions.GetBgpConditions().GetCommunitySet(),
MatchSetOptions: convertMatchSetOptionsType(occommset[statement.GetConditions().GetBgpConditions().GetCommunitySet()].GetMatchSetOptions()),
},
CommunityCount: gobgpoc.CommunityCount{
Operator: convertAttributeComparison(statement.Conditions.GetBgpConditions().GetCommunityCount().GetOperator()),
Value: statement.Conditions.GetBgpConditions().GetCommunityCount().GetValue(),
},
MatchAsPathSet: gobgpoc.MatchAsPathSet{
AsPathSet: statement.Conditions.GetBgpConditions().GetMatchAsPathSet().GetAsPathSet(),
MatchSetOptions: convertMatchSetOptionsType(statement.GetConditions().GetBgpConditions().GetMatchAsPathSet().GetMatchSetOptions()),
Expand Down Expand Up @@ -203,6 +207,19 @@ func defaultPolicyToRouteDisp(gobgpdefaultpolicy gobgpoc.DefaultPolicyType) gobg
}
}

func convertAttributeComparison(ocpolicy oc.E_PolicyTypes_ATTRIBUTE_COMPARISON) gobgpoc.AttributeComparison {
switch ocpolicy {
case oc.PolicyTypes_ATTRIBUTE_COMPARISON_ATTRIBUTE_EQ:
return gobgpoc.ATTRIBUTE_COMPARISON_EQ
case oc.PolicyTypes_ATTRIBUTE_COMPARISON_ATTRIBUTE_GE:
return gobgpoc.ATTRIBUTE_COMPARISON_GE
case oc.PolicyTypes_ATTRIBUTE_COMPARISON_ATTRIBUTE_LE:
return gobgpoc.ATTRIBUTE_COMPARISON_LE
default:
return ""
}
}

// ConvertCommunity converts any community union type to its string representation to be used in GoBGP.
func ConvertCommunity(community any) string {
switch c := community.(type) {
Expand Down
1 change: 1 addition & 0 deletions bgp/tests/local_tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go_test(
name = "local_tests_test",
size = "large",
srcs = [
"community_count_test.go",
"community_set_test.go",
"policy_test.go",
"prefix_set_test.go",
Expand Down
Loading
Loading