Skip to content

Commit

Permalink
Add replace option to AddDefinedSet rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
floatingstatic committed Nov 10, 2023
1 parent 02fa612 commit 16412bf
Show file tree
Hide file tree
Showing 6 changed files with 1,454 additions and 1,437 deletions.
2,874 changes: 1,442 additions & 1,432 deletions api/gobgp.pb.go

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion api/gobgp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions api/gobgp_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/pkg/table/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 16412bf

Please sign in to comment.