Skip to content

Commit

Permalink
Update grpc client tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Motok1 committed Oct 17, 2022
1 parent c975c2d commit 607c259
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 432 deletions.
49 changes: 49 additions & 0 deletions tools/grpc/go/add_sr-policy/add_sr-policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2022 NTT Communications Corporation
//
// This software is released under the MIT License.
// see https://github.com/nttcom/pola/blob/main/LICENSE

package main

import (
"context"
"flag"
"log"
"net"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

pb "github.com/nttcom/pola/api/grpc"
)

func main() {
flag.Parse()
conn, err := grpc.Dial("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("Can't connect: %v", err)
}
defer conn.Close()
c := pb.NewPceServiceClient(conn)

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

r, err := c.CreateSrPolicy(ctx, &pb.CreateSrPolicyInput{
Asn: 65000,
SrPolicy: &pb.SrPolicy{
PcepSessionAddr: []byte(net.ParseIP("192.0.2.1").To4()),
SrcRouterId: "0000.0aff.0001",
DstRouterId: "0000.0aff.0004",
Color: uint32(100),
PolicyName: "sample-name",
Type: pb.SrPolicyType_DYNAMIC,
Metric: pb.MetricType_TE,
},
})
if err != nil {
log.Fatalf("CreateLsp error: %v", err)
}
log.Printf("Success: %#v", r)
}
50 changes: 50 additions & 0 deletions tools/grpc/go/add_sr-policy_no_ls/add_sr-policy_no_ls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2022 NTT Communications Corporation
//
// This software is released under the MIT License.
// see https://github.com/nttcom/pola/blob/main/LICENSE

package main

import (
"context"
"flag"
"log"
"net"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

pb "github.com/nttcom/pola/api/grpc"
)

func main() {
flag.Parse()
conn, err := grpc.Dial("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("Can't connect: %v", err)
}
defer conn.Close()
c := pb.NewPceServiceClient(conn)

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

r, err := c.CreateSrPolicyWithoutLinkState(ctx, &pb.CreateSrPolicyInput{
SrPolicy: &pb.SrPolicy{
PcepSessionAddr: []byte(net.ParseIP("192.0.2.1").To4()),
SrcAddr: []byte(net.ParseIP("192.0.2.1").To4()),
DstAddr: []byte(net.ParseIP("192.0.2.2").To4()),
Color: uint32(100),
PolicyName: "sample-name",
SegmentList: []*pb.Segment{{Sid: 16002, LoAddr: []byte(net.ParseIP("10.255.0.2").To4())},
{Sid: 16003, LoAddr: []byte(net.ParseIP("10.255.0.3").To4())},
{Sid: 16004, LoAddr: []byte(net.ParseIP("10.255.0.4").To4())},
},
},
})
if err != nil {
log.Fatalf("CreateLsp error: %v", err)
}
log.Printf("Success: %#v", r)
}
118 changes: 0 additions & 118 deletions tools/grpc/go/client/add_lsp/test_add_lsp.go

This file was deleted.

42 changes: 0 additions & 42 deletions tools/grpc/go/server/test_server.go

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
var empty empty.Empty
ret, err := c.GetLspList(ctx, &empty)
ret, err := c.GetSrPolicyList(ctx, &empty)
if err != nil {
log.Fatalf("could not greet: %v", err)
}

for i, lsp := range ret.GetLsps() {
fmt.Printf("lsp(%d): \n", i)
sessionAddr := net.IP(lsp.GetPcepSessionAddr())
for i, srPolicy := range ret.GetSrPolicies() {
fmt.Printf("srPolicy(%d): \n", i)
sessionAddr := net.IP(srPolicy.GetPcepSessionAddr())
fmt.Printf(" sessionAddr: %s\n", sessionAddr.String())
fmt.Printf(" policyName: %s\n", lsp.GetPolicyName())
fmt.Printf(" SrcAddr: %s\n", net.IP(lsp.GetSrcAddr()))
fmt.Printf(" DstAddr: %s\n", net.IP(lsp.GetDstAddr()))
fmt.Printf(" policyName: %s\n", srPolicy.GetPolicyName())
fmt.Printf(" SrcAddr: %s\n", net.IP(srPolicy.GetSrcAddr()))
fmt.Printf(" DstAddr: %s\n", net.IP(srPolicy.GetDstAddr()))
fmt.Printf(" path: ")

if len(lsp.GetLabels()) == 0 {
if len(srPolicy.GetSegmentList()) == 0 {
fmt.Printf("None \n")
continue
}
for j, label := range lsp.GetLabels() {
fmt.Printf("%d ", label.GetSid())
if j == len(lsp.GetLabels())-1 {
for j, segment := range srPolicy.GetSegmentList() {
fmt.Printf("%d ", segment.GetSid())
if j == len(srPolicy.GetSegmentList())-1 {
fmt.Printf("\n")
} else {
fmt.Printf("-> ")
Expand Down
53 changes: 53 additions & 0 deletions tools/grpc/go/show_ted/show_ted.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2022 NTT Communications Corporation
//
// This software is released under the MIT License.
// see https://github.com/nttcom/pola/blob/main/LICENSE

package main

import (
"context"
"flag"
"fmt"
"log"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

empty "github.com/golang/protobuf/ptypes/empty"
pb "github.com/nttcom/pola/api/grpc"
)

func main() {
flag.Parse()
conn, err := grpc.Dial("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewPceServiceClient(conn)

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
var empty empty.Empty

ret, err := c.GetTed(ctx, &empty)
if err != nil {
log.Fatalf("did not get TED info: %v", err)
}

for _, node := range ret.GetLsNodes() {
fmt.Printf("node info:\n")
fmt.Printf("%#v\n", node)
for _, prefix := range node.GetLsPrefixes() {
fmt.Printf("prefix info:\n")
fmt.Printf("%#v\n", prefix)
}
for _, link := range node.GetLsLinks() {
fmt.Printf("link info:\n")
fmt.Printf("%#v\n", link)
}
fmt.Printf("\n\n")
}
}
Loading

0 comments on commit 607c259

Please sign in to comment.