Add replace option to AddDefinedSet rpc

This commit is contained in:
Jeremiah Millay
2023-11-10 13:35:24 -05:00
parent 02fa6129af
commit 16412bfc03
6 changed files with 1469 additions and 1452 deletions
+1457 -1447
View File
File diff suppressed because it is too large Load Diff
+4 -1
View File
@@ -322,7 +322,10 @@ message SetPoliciesRequest {
repeated PolicyAssignment assignments = 3;
}
message AddDefinedSetRequest { DefinedSet defined_set = 1; }
message AddDefinedSetRequest {
DefinedSet defined_set = 1;
bool replace = 2;
}
message DeleteDefinedSetRequest {
DefinedSet defined_set = 1;
+4
View File
@@ -1,4 +1,8 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v4.25.0
// source: gobgp.proto
package apipb
+2 -2
View File
@@ -3491,14 +3491,14 @@ func (r *RoutingPolicy) GetDefinedSet(typ DefinedType, name string) (*oc.Defined
return sets, nil
}
func (r *RoutingPolicy) AddDefinedSet(s DefinedSet) error {
func (r *RoutingPolicy) AddDefinedSet(s DefinedSet, replace bool) error {
r.mu.Lock()
defer r.mu.Unlock()
if m, ok := r.definedSetMap[s.Type()]; !ok {
return fmt.Errorf("invalid defined-set type: %d", s.Type())
} else {
if d, ok := m[s.Name()]; ok {
if d, ok := m[s.Name()]; ok && !replace {
if err := d.Append(s); err != nil {
return err
}
+1 -1
View File
@@ -3675,7 +3675,7 @@ func (s *BgpServer) AddDefinedSet(ctx context.Context, r *api.AddDefinedSetReque
if err != nil {
return err
}
return s.policy.AddDefinedSet(set)
return s.policy.AddDefinedSet(set, r.GetReplace())
}, false)
}
+1 -1
View File
@@ -830,7 +830,7 @@ func TestFilterpathWithRejectPolicy(t *testing.T) {
CommunityList: []string{"100:100"},
}
s, _ := table.NewCommunitySet(comSet1)
p2.policy.AddDefinedSet(s)
p2.policy.AddDefinedSet(s, false)
statement := oc.Statement{
Name: "stmt1",