Skip to content

Commit

Permalink
Update pola cli commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Motok1 committed Oct 17, 2022
1 parent 73cb926 commit c975c2d
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 165 deletions.
66 changes: 59 additions & 7 deletions cmd/pola/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Displays the peer addresses of the active session.
json formatted response
```
{
"peers": [
"sessions": [
{
"address": "192.0.2.1",
"status": "active",
Expand All @@ -21,7 +21,7 @@ json formatted response
}
```

### pola lsp list \[-j\]
### pola sr-policy list \[-j\]
Displays the lsp list managed by polad.

json formatted response
Expand Down Expand Up @@ -114,16 +114,68 @@ json formatted response
]
```

### pola lsp add -f _filepath_
Create a new SR-Policy
### pola sr-policy add -f _filepath_

Create a new SR Policy using TED

#### Case: Dynamic Path calculate

yaml input format
```
asn: 65000
srPolicy:
name: name
peerAddr: 192.0.2.1
pcepSessionAddr: 192.0.2.1
name: policy-name
srcRouterId: 0000.0aff.0001
dstRouterId: 0000.0aff.0004
color: 100
type: dynamic
metric: igp / te / delay
```

json formatted response
```
{
"status": "success"
}
```

#### Case: Explicit Path

yaml input format
```
asn: 65000
srPolicy:
pcepSessionAddr: 192.0.2.1
name: policy-name
srcRouterId: 0000.0aff.0001
dstRouterId: 0000.0aff.0004
color: 100
type: explicit
segmentlist:
- sid: 16003
- sid: 16002
- sid: 16004
```

json formatted response
```
{
"status": "success"
}
```

### pola sr-policy add -f _filepath_ --no-link-state

Create a new SR Policy without using TED

yaml input format
```
srPolicy:
pcepSessionAddr: 192.0.2.1
srcAddr: 192.0.2.1
dstAddr: 192.0.2.2
name: name
color: 100
segmentlist:
- sid: 16003
Expand Down Expand Up @@ -286,4 +338,4 @@ json formatted response
}
]
}
```
```
50 changes: 30 additions & 20 deletions cmd/pola/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ import (
"github.com/nttcom/pola/internal/pkg/table"
)

type lspInfo struct {
type srPolicyInfo struct {
peerAddr net.IP //TODO: Change to ("loopback addr" or "router name")
name string
path []uint32
srcAddr net.IP
dstAddr net.IP
}

func getPeerAddrList(client pb.PceServiceClient) ([]net.IP, error) {
func getSessionAddrList(client pb.PceServiceClient) ([]net.IP, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
var empty empty.Empty
ret, err := client.GetPeerAddrList(ctx, &empty)
if err != nil {
return nil, errors.New("could not get Peer Address")
return nil, err
}
var peerAddrList []net.IP
for _, peerAddr := range ret.GetPeerAddrs() {
Expand All @@ -39,36 +39,46 @@ func getPeerAddrList(client pb.PceServiceClient) ([]net.IP, error) {
return peerAddrList, nil
}

func getlspList(client pb.PceServiceClient) ([]lspInfo, error) {
func getSrPolicyList(client pb.PceServiceClient) ([]srPolicyInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
var empty empty.Empty
ret, err := client.GetLspList(ctx, &empty)
ret, err := client.GetSrPolicyList(ctx, &empty)
if err != nil {
return nil, errors.New("could not get Lsp List")
return nil, err
}
lspList := []lspInfo{}
for _, lsp := range ret.GetLsps() {
tmp := lspInfo{
srPolicyList := []srPolicyInfo{}
for _, lsp := range ret.GetSrPolicies() {
tmp := srPolicyInfo{
name: lsp.PolicyName,
peerAddr: net.IP(lsp.GetPcepSessionAddr()),
srcAddr: net.IP(lsp.GetSrcAddr()),
dstAddr: net.IP(lsp.GetDstAddr()),
}
if len(lsp.GetLabels()) != 0 {
for _, label := range lsp.GetLabels() {
if len(lsp.GetSegmentList()) != 0 {
for _, label := range lsp.GetSegmentList() {
tmp.path = append(tmp.path, label.GetSid())
}
}
lspList = append(lspList, tmp)
srPolicyList = append(srPolicyList, tmp)
}
return lspList, nil
return srPolicyList, nil
}

func createLsp(client pb.PceServiceClient, lspData *pb.LspData) error {
func createSrPolicy(client pb.PceServiceClient, createSrPolicyInput *pb.CreateSrPolicyInput) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_, err := client.CreateLsp(ctx, lspData)
_, err := client.CreateSrPolicy(ctx, createSrPolicyInput)
if err != nil {
return err
}
return nil
}

func createSrPolicyWithoutLinkState(client pb.PceServiceClient, createSrPolicyInput *pb.CreateSrPolicyInput) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_, err := client.CreateSrPolicyWithoutLinkState(ctx, createSrPolicyInput)
if err != nil {
return err
}
Expand All @@ -81,11 +91,11 @@ func getTed(client pb.PceServiceClient) (*table.LsTed, error) {
var empty empty.Empty
ret, err := client.GetTed(ctx, &empty)
if err != nil {
return nil, errors.New("could not get Peer Address")
return nil, err
}

if !ret.GetEnable() {
return nil, nil
return nil, errors.New("ted is disable")
}
ted := &table.LsTed{
Id: 1,
Expand Down Expand Up @@ -117,11 +127,11 @@ func getTed(client pb.PceServiceClient) (*table.LsTed, error) {
case "IGP":
metric = table.NewMetric(table.IGP_METRIC, metricInfo.GetValue())
case "TE":
metric = table.NewMetric(table.IGP_METRIC, metricInfo.GetValue())
metric = table.NewMetric(table.TE_METRIC, metricInfo.GetValue())
case "DELAY":
metric = table.NewMetric(table.IGP_METRIC, metricInfo.GetValue())
metric = table.NewMetric(table.DELAY_METRIC, metricInfo.GetValue())
case "HOPCOUNT":
metric = table.NewMetric(table.IGP_METRIC, metricInfo.GetValue())
metric = table.NewMetric(table.HOPCOUNT_METRIC, metricInfo.GetValue())
default:
return nil, errors.New("unknown metric type")
}
Expand Down
104 changes: 0 additions & 104 deletions cmd/pola/lsp_add.go

This file was deleted.

23 changes: 21 additions & 2 deletions cmd/pola/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@ import (
)

var client pb.PceServiceClient
var jsonFmt bool

func newRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "pola",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
conn, err := grpc.Dial("localhost:50052", grpc.WithTransportCredentials(insecure.NewCredentials()))
jFlag, err := cmd.Flags().GetBool("json")
if err != nil {
return err
}
jsonFmt = jFlag
host, err := cmd.Flags().GetString("host")
if err != nil {
return err
}
port, err := cmd.Flags().GetString("port")
if err != nil {
return err
}
conn, err := grpc.Dial(host+":"+port, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
conn.Close()
return err
Expand All @@ -31,6 +45,11 @@ func newRootCmd() *cobra.Command {
cmd.HelpFunc()(cmd, args)
},
}
rootCmd.AddCommand(newSessionCmd(), newLspCmd(), newTedCmd())

rootCmd.PersistentFlags().BoolP("json", "j", false, "output json format")
rootCmd.PersistentFlags().String("host", "127.0.0.1", "polad connection address")
rootCmd.PersistentFlags().StringP("port", "p", "50051", "polad connection port")

rootCmd.AddCommand(newSessionCmd(), newSrPolicyCmd(), newTedCmd())
return rootCmd
}
Loading

0 comments on commit c975c2d

Please sign in to comment.