Skip to content

Commit

Permalink
Add grpc for deleting sr-policy
Browse files Browse the repository at this point in the history
Signed-off-by: kanaya516 <[email protected]>
  • Loading branch information
kanaya516 authored and Motok1 committed Jun 8, 2024
1 parent c9852c5 commit b631391
Show file tree
Hide file tree
Showing 11 changed files with 554 additions and 191 deletions.
413 changes: 250 additions & 163 deletions api/grpc/pola.pb.go

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion api/grpc/pola.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ service PceService {

rpc CreateSRPolicyWithoutLinkState (CreateSRPolicyInput) returns (RequestStatus) {};

rpc DeleteSRPolicy (DeleteSRPolicyInput) returns (RequestStatus) {};

rpc DeleteSRPolicyWithoutLinkState (DeleteSRPolicyInput) returns (RequestStatus) {};

rpc GetSessionList (google.protobuf.Empty) returns (SessionList) {};

rpc GetSRPolicyList (google.protobuf.Empty) returns (SRPolicyList) {};
Expand Down Expand Up @@ -51,7 +55,12 @@ message SRPolicy {
message CreateSRPolicyInput {
SRPolicy SRPolicy = 1;
uint32 asn = 2;
}
}

message DeleteSRPolicyInput {
SRPolicy SRPolicy = 1;
uint32 asn = 2;
}

message RequestStatus {
bool isSuccess = 1;
Expand Down
116 changes: 104 additions & 12 deletions api/grpc/pola_grpc.pb.go

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

22 changes: 15 additions & 7 deletions cmd/pola/grpc_client.go → cmd/pola/grpc/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is released under the MIT License.
// see https://github.com/nttcom/pola/blob/main/LICENSE

package main
package grpc

import (
"context"
Expand All @@ -20,7 +20,7 @@ func withTimeout() (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), time.Second)
}

func getSessionAddrList(client pb.PceServiceClient) ([]netip.Addr, error) {
func GetSessionAddrList(client pb.PceServiceClient) ([]netip.Addr, error) {
ctx, cancel := withTimeout()
defer cancel()

Expand All @@ -38,7 +38,7 @@ func getSessionAddrList(client pb.PceServiceClient) ([]netip.Addr, error) {
return addrs, nil
}

func deleteSession(client pb.PceServiceClient, session *pb.Session) error {
func DeleteSession(client pb.PceServiceClient, session *pb.Session) error {
ctx, cancel := withTimeout()
defer cancel()
_, err := client.DeleteSession(ctx, session)
Expand All @@ -48,7 +48,7 @@ func deleteSession(client pb.PceServiceClient, session *pb.Session) error {
return nil
}

func getSRPolicyList(client pb.PceServiceClient) (map[netip.Addr][]table.SRPolicy, error) {
func GetSRPolicyList(client pb.PceServiceClient) (map[netip.Addr][]table.SRPolicy, error) {
ctx, cancel := withTimeout()
defer cancel()

Expand Down Expand Up @@ -85,23 +85,31 @@ func getSRPolicyList(client pb.PceServiceClient) (map[netip.Addr][]table.SRPolic
return policies, nil
}

func createSRPolicy(client pb.PceServiceClient, input *pb.CreateSRPolicyInput) error {
func CreateSRPolicy(client pb.PceServiceClient, input *pb.CreateSRPolicyInput) error {
ctx, cancel := withTimeout()
defer cancel()

_, err := client.CreateSRPolicy(ctx, input)
return err
}

func createSRPolicyWithoutLinkState(client pb.PceServiceClient, input *pb.CreateSRPolicyInput) error {
func CreateSRPolicyWithoutLinkState(client pb.PceServiceClient, input *pb.CreateSRPolicyInput) error {
ctx, cancel := withTimeout()
defer cancel()

_, err := client.CreateSRPolicyWithoutLinkState(ctx, input)
return err
}

func getTed(client pb.PceServiceClient) (*table.LsTed, error) {
func DeleteSRPolicy(client pb.PceServiceClient, input *pb.DeleteSRPolicyInput) error {
ctx, cancel := withTimeout()
defer cancel()

_, err := client.DeleteSRPolicy(ctx, input)
return err
}

func GetTed(client pb.PceServiceClient) (*table.LsTed, error) {
ctx, cancel := withTimeout()
defer cancel()

Expand Down
3 changes: 2 additions & 1 deletion cmd/pola/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"

"github.com/nttcom/pola/cmd/pola/grpc"
"github.com/spf13/cobra"
)

Expand All @@ -28,7 +29,7 @@ func newSessionCmd() *cobra.Command {
}

func showSession(jsonFlag bool) error {
sessionAddrList, err := getSessionAddrList(client)
sessionAddrList, err := grpc.GetSessionAddrList(client)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/pola/session_del.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/netip"

pb "github.com/nttcom/pola/api/grpc"
"github.com/nttcom/pola/cmd/pola/grpc"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func delSession(session netip.Addr, jsonFlag bool) error {
ss := &pb.Session{
Addr: session.AsSlice(),
}
err := deleteSession(client, ss)
err := grpc.DeleteSession(client, ss)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/pola/sr_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ func newSRPolicyCmd() *cobra.Command {
},
Args: cobra.NoArgs,
}
cmd.AddCommand(newSRPolicyListCmd(), newSRPolicyAddCmd())
cmd.AddCommand(newSRPolicyListCmd(), newSRPolicyAddCmd(), newSRPolicyDeleteCmd())
return cmd
}
Loading

0 comments on commit b631391

Please sign in to comment.