Skip to content

Commit a490314

Browse files
committed
Output session details from gRPC
1 parent 12ab5b0 commit a490314

File tree

6 files changed

+294
-175
lines changed

6 files changed

+294
-175
lines changed

api/grpc/pola.pb.go

+220-150
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/pola.proto

+7
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,15 @@ message RequestStatus {
6666
bool isSuccess = 1;
6767
}
6868

69+
enum SessionState {
70+
DOWN = 0;
71+
UP = 1;
72+
}
73+
6974
message Session {
7075
bytes Addr = 1;
76+
SessionState State = 2;
77+
repeated string Caps = 3;
7178
}
7279

7380
message SessionList {

api/grpc/pola_grpc.pb.go

+20-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/packet/pcep/capability.go

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package pcep
77

88
type CapabilityInterface interface {
99
TLVInterface
10+
CapStrings() []string
1011
}
1112

1213
func PolaCapability() []CapabilityInterface {

pkg/packet/pcep/tlv.go

+38
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"errors"
1111
"fmt"
1212
"net/netip"
13+
"slices"
14+
"strconv"
1315
"strings"
1416

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

168+
func (tlv *StatefulPceCapability) CapStrings() []string {
169+
ret := []string{}
170+
ret = append(ret, "Stateful")
171+
if tlv.LspUpdateCapability {
172+
ret = append(ret, "Update")
173+
}
174+
if tlv.LspInstantiationCapability {
175+
ret = append(ret, "Initiate")
176+
}
177+
return ret
178+
}
179+
166180
type SymbolicPathName struct {
167181
Name string
168182
}
@@ -325,6 +339,10 @@ func (tlv *SRPceCapability) Len() uint16 {
325339
return TL_LENGTH + TLV_SR_PCE_CAPABILITY_LENGTH
326340
}
327341

342+
func (tlv *SRPceCapability) CapStrings() []string {
343+
return []string{"SR-TE"}
344+
}
345+
328346
type Pst uint8
329347

330348
const (
@@ -532,6 +550,17 @@ func (tlv *PathSetupTypeCapability) Len() uint16 {
532550
return TL_LENGTH + l
533551
}
534552

553+
func (tlv *PathSetupTypeCapability) CapStrings() []string {
554+
ret := []string{}
555+
if slices.Contains(tlv.PathSetupTypes, PST_SR_TE) {
556+
ret = append(ret, "SR-TE")
557+
}
558+
if slices.Contains(tlv.PathSetupTypes, PST_SRV6_TE) {
559+
ret = append(ret, "SRv6-TE")
560+
}
561+
return ret
562+
}
563+
535564
type AssocType uint16
536565

537566
const (
@@ -599,6 +628,10 @@ func (tlv *AssocTypeList) Len() uint16 {
599628
return TL_LENGTH + l + padding
600629
}
601630

631+
func (tlv *AssocTypeList) CapStrings() []string {
632+
return []string{}
633+
}
634+
602635
type SRPolicyCandidatePathIdentifier struct {
603636
OriginatorAddr netip.Addr // After DecodeFromBytes, even ipv4 addresses are assigned in ipv6 format
604637
}
@@ -734,6 +767,11 @@ func (tlv *UndefinedTLV) Len() uint16 {
734767
return TL_LENGTH + tlv.Length + padding
735768
}
736769

770+
func (tlv *UndefinedTLV) CapStrings() []string {
771+
cap := "unknown_type_" + strconv.FormatInt(int64(tlv.Typ), 10)
772+
return []string{cap}
773+
}
774+
737775
func (tlv *UndefinedTLV) SetLength() {
738776
tlv.Length = uint16(len(tlv.Value))
739777
}

pkg/server/grpc_server.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"fmt"
1313
"net"
1414
"net/netip"
15+
"slices"
1516

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

147148
func (s *APIServer) DeleteSRPolicy(ctx context.Context, input *pb.DeleteSRPolicyInput) (*pb.RequestStatus, error) {
148-
return s.deleteSRPolicy(ctx, input)
149-
}
150-
151-
func (s *APIServer) deleteSRPolicy(ctx context.Context, input *pb.DeleteSRPolicyInput) (*pb.RequestStatus, error) {
152149
err := validate(input.GetSRPolicy(), input.GetAsn(), ValidationDelete)
153150
if err != nil {
154151
return &pb.RequestStatus{IsSuccess: false}, err
@@ -311,8 +308,14 @@ func (s *APIServer) GetSessionList(context.Context, *empty.Empty) (*pb.SessionLi
311308
var ret pb.SessionList
312309
for _, pcepSession := range s.pce.sessionList {
313310
ss := &pb.Session{
314-
Addr: pcepSession.peerAddr.AsSlice(),
311+
Addr: pcepSession.peerAddr.AsSlice(),
312+
State: pb.SessionState_UP, // Only the UP state in the current specification
313+
Caps: []string{},
314+
}
315+
for _, cap := range pcepSession.pccCapabilities {
316+
ss.Caps = append(ss.Caps, cap.CapStrings()...)
315317
}
318+
ss.Caps = slices.Compact(ss.Caps)
316319
ret.Sessions = append(ret.Sessions, ss)
317320
}
318321

0 commit comments

Comments
 (0)