Skip to content

Commit

Permalink
Output session details from gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
Motok1 committed Jun 8, 2024
1 parent 12ab5b0 commit a490314
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 175 deletions.
370 changes: 220 additions & 150 deletions api/grpc/pola.pb.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions api/grpc/pola.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ message RequestStatus {
bool isSuccess = 1;
}

enum SessionState {
DOWN = 0;
UP = 1;
}

message Session {
bytes Addr = 1;
SessionState State = 2;
repeated string Caps = 3;
}

message SessionList {
Expand Down
40 changes: 20 additions & 20 deletions api/grpc/pola_grpc.pb.go

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

1 change: 1 addition & 0 deletions pkg/packet/pcep/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package pcep

type CapabilityInterface interface {
TLVInterface
CapStrings() []string
}

func PolaCapability() []CapabilityInterface {
Expand Down
38 changes: 38 additions & 0 deletions pkg/packet/pcep/tlv.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"errors"
"fmt"
"net/netip"
"slices"
"strconv"
"strings"

"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -163,6 +165,18 @@ func (tlv *StatefulPceCapability) Len() uint16 {
return TL_LENGTH + TLV_STATEFUL_PCE_CAPABILITY_LENGTH
}

func (tlv *StatefulPceCapability) CapStrings() []string {
ret := []string{}
ret = append(ret, "Stateful")
if tlv.LspUpdateCapability {
ret = append(ret, "Update")
}
if tlv.LspInstantiationCapability {
ret = append(ret, "Initiate")
}
return ret
}

type SymbolicPathName struct {
Name string
}
Expand Down Expand Up @@ -325,6 +339,10 @@ func (tlv *SRPceCapability) Len() uint16 {
return TL_LENGTH + TLV_SR_PCE_CAPABILITY_LENGTH
}

func (tlv *SRPceCapability) CapStrings() []string {
return []string{"SR-TE"}
}

type Pst uint8

const (
Expand Down Expand Up @@ -532,6 +550,17 @@ func (tlv *PathSetupTypeCapability) Len() uint16 {
return TL_LENGTH + l
}

func (tlv *PathSetupTypeCapability) CapStrings() []string {
ret := []string{}
if slices.Contains(tlv.PathSetupTypes, PST_SR_TE) {
ret = append(ret, "SR-TE")
}
if slices.Contains(tlv.PathSetupTypes, PST_SRV6_TE) {
ret = append(ret, "SRv6-TE")
}
return ret
}

type AssocType uint16

const (
Expand Down Expand Up @@ -599,6 +628,10 @@ func (tlv *AssocTypeList) Len() uint16 {
return TL_LENGTH + l + padding
}

func (tlv *AssocTypeList) CapStrings() []string {
return []string{}
}

type SRPolicyCandidatePathIdentifier struct {
OriginatorAddr netip.Addr // After DecodeFromBytes, even ipv4 addresses are assigned in ipv6 format
}
Expand Down Expand Up @@ -734,6 +767,11 @@ func (tlv *UndefinedTLV) Len() uint16 {
return TL_LENGTH + tlv.Length + padding
}

func (tlv *UndefinedTLV) CapStrings() []string {
cap := "unknown_type_" + strconv.FormatInt(int64(tlv.Typ), 10)
return []string{cap}
}

func (tlv *UndefinedTLV) SetLength() {
tlv.Length = uint16(len(tlv.Value))
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/server/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"net"
"net/netip"
"slices"

"github.com/golang/protobuf/ptypes/empty"
pb "github.com/nttcom/pola/api/grpc"
Expand Down Expand Up @@ -145,10 +146,6 @@ func (s *APIServer) createSRPolicy(ctx context.Context, input *pb.CreateSRPolicy
}

func (s *APIServer) DeleteSRPolicy(ctx context.Context, input *pb.DeleteSRPolicyInput) (*pb.RequestStatus, error) {
return s.deleteSRPolicy(ctx, input)
}

func (s *APIServer) deleteSRPolicy(ctx context.Context, input *pb.DeleteSRPolicyInput) (*pb.RequestStatus, error) {
err := validate(input.GetSRPolicy(), input.GetAsn(), ValidationDelete)
if err != nil {
return &pb.RequestStatus{IsSuccess: false}, err
Expand Down Expand Up @@ -311,8 +308,14 @@ func (s *APIServer) GetSessionList(context.Context, *empty.Empty) (*pb.SessionLi
var ret pb.SessionList
for _, pcepSession := range s.pce.sessionList {
ss := &pb.Session{
Addr: pcepSession.peerAddr.AsSlice(),
Addr: pcepSession.peerAddr.AsSlice(),
State: pb.SessionState_UP, // Only the UP state in the current specification
Caps: []string{},
}
for _, cap := range pcepSession.pccCapabilities {
ss.Caps = append(ss.Caps, cap.CapStrings()...)
}
ss.Caps = slices.Compact(ss.Caps)
ret.Sessions = append(ret.Sessions, ss)
}

Expand Down

0 comments on commit a490314

Please sign in to comment.