Skip to content

Commit

Permalink
Use TED in polad
Browse files Browse the repository at this point in the history
  • Loading branch information
Motok1 committed Sep 13, 2022
1 parent 1cf0011 commit 4b5d8a7
Show file tree
Hide file tree
Showing 8 changed files with 749 additions and 369 deletions.
927 changes: 571 additions & 356 deletions api/grpc/pola.pb.go

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions api/grpc/pola.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ service PceService {

rpc GetLspList (google.protobuf.Empty) returns (LspList) {};

rpc GetTed (google.protobuf.Empty) returns (Ted) {};
}

message Label {
Expand Down Expand Up @@ -45,3 +46,47 @@ message PeerAddrList {
message LspList {
repeated LspData Lsps = 1;
}

message LsPrefix {
string prefix = 1;
uint32 sid_index = 2;
}

enum MetricType {
IGP = 0;
TE = 1;
DELAY = 2;
HOPCOUNT = 3;
}

message Metric {
MetricType type = 1;
uint32 value = 2;
}

message LsLink {
string local_router_id = 1;
uint32 local_asn = 2;
string local_ip = 3;
string remote_router_id = 4;
uint32 remote_asn = 5;
string remote_ip = 6;
repeated Metric metrics = 7;
uint32 adj_sid = 8;
}

message LsNode {
uint32 asn = 1;
string router_id = 2;
string isis_area_id = 3;
string hostname = 4;
uint32 srgb_begin = 5;
uint32 srgb_end = 6;
repeated LsLink ls_links = 7;
repeated LsPrefix ls_prefixes = 8;
}


message Ted {
repeated LsNode ls_nodes = 1;
}
47 changes: 43 additions & 4 deletions api/grpc/pola_grpc.pb.go

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

5 changes: 4 additions & 1 deletion cmd/polad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.uber.org/zap"

"github.com/nttcom/pola/internal/config"
"github.com/nttcom/pola/internal/pkg/table"
"github.com/nttcom/pola/pkg/logger"
"github.com/nttcom/pola/pkg/server"
)
Expand Down Expand Up @@ -46,12 +47,14 @@ func main() {
}()
zap.ReplaceGlobals(logger)

tedElemsChan := make(chan []table.TedElem)

o := new(server.PceOptions)
o.PcepAddr = c.Global.Pcep.Address
o.PcepPort = c.Global.Pcep.Port
o.GrpcAddr = c.Global.Grpc.Address
o.GrpcPort = c.Global.Grpc.Port
if err := server.NewPce(o, logger); err != nil {
if err := server.NewPce(o, logger, tedElemsChan); err != nil {
logger.Panic("Failed to create New Server", zap.Error(err))
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/spf13/cobra v1.4.0
go.uber.org/zap v1.21.0
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.28.0
gopkg.in/yaml.v2 v2.4.0
)

Expand All @@ -22,4 +21,5 @@ require (
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
12 changes: 10 additions & 2 deletions internal/pkg/table/ted.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ type LsTed struct {
Nodes map[uint32]map[string]*LsNode // { ASN1: {"NodeID1": node1, "NodeID2": node2}, ASN2: {"NodeID3": node3, "NodeID4": node4}}
}

func NewLsTed() {

func (ted *LsTed) Update(tedElems []TedElem) {
fmt.Printf("%#v\n\n", tedElems)
ted = &LsTed{
Id: ted.Id,
Nodes: map[uint32]map[string]*LsNode{},
}
for _, tedElem := range tedElems {
tedElem.UpdateTed(ted)
}
ted.ShowTed()
}

func (ted LsTed) ShowTed() {
Expand Down
76 changes: 73 additions & 3 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

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

"github.com/nttcom/pola/internal/pkg/table"
"github.com/nttcom/pola/pkg/packet/pcep"
)

Expand All @@ -30,6 +32,7 @@ type Lsp struct {
type Server struct {
sessionList []*Session
lspList []Lsp
ted *table.LsTed
pb.UnimplementedPceServiceServer
logger *zap.Logger
}
Expand All @@ -41,8 +44,13 @@ type PceOptions struct {
GrpcPort string
}

func NewPce(o *PceOptions, logger *zap.Logger) error {
s := &Server{}
func NewPce(o *PceOptions, logger *zap.Logger, tedElemsChan chan []table.TedElem) error {
s := &Server{
ted: &table.LsTed{
Id: 1,
Nodes: map[uint32]map[string]*table.LsNode{},
},
}
s.logger = logger
lspChan := make(chan Lsp)
// Start PCEP listen
Expand All @@ -57,7 +65,21 @@ func NewPce(o *PceOptions, logger *zap.Logger) error {
s.logger.Panic("gRPC Listen Error", zap.Error(err), zap.String("server", "grpc"))
}
}()
// Display sessionList

// Update Ted
go func() {
for {
tedElems := <-tedElemsChan
s.ted = &table.LsTed{
Id: s.ted.Id,
Nodes: map[uint32]map[string]*table.LsNode{},
}

for _, tedElem := range tedElems {
tedElem.UpdateTed(s.ted)
}
}
}()
for {
lsp := <-lspChan
// Overwrite LSP
Expand Down Expand Up @@ -175,6 +197,54 @@ func (s *Server) GetLspList(context.Context, *empty.Empty) (*pb.LspList, error)
return &ret, nil
}

func (s *Server) GetTed(context.Context, *empty.Empty) (*pb.Ted, error) {
s.logger.Info("Get request GetTed API", zap.String("server", "grpc"))
var ret pb.Ted
for _, lsNodes := range s.ted.Nodes {
for _, lsNode := range lsNodes {
node := &pb.LsNode{
Asn: lsNode.Asn,
RouterId: lsNode.RouterId,
IsisAreaId: lsNode.IsisAreaId,
Hostname: lsNode.Hostname,
SrgbBegin: lsNode.SrgbBegin,
SrgbEnd: lsNode.SrgbEnd,
LsLinks: []*pb.LsLink{},
LsPrefixes: []*pb.LsPrefix{},
}
for _, lsLink := range lsNode.Links {
link := &pb.LsLink{
LocalRouterId: lsLink.LocalNode.RouterId,
LocalAsn: lsLink.LocalNode.Asn,
LocalIp: lsLink.LocalIP.String(),
RemoteRouterId: lsLink.RemoteNode.RouterId,
RemoteAsn: lsLink.RemoteNode.Asn,
RemoteIp: lsLink.RemoteIP.String(),
Metrics: []*pb.Metric{},
AdjSid: lsLink.AdjSid,
}
for _, metric := range lsLink.Metrics {
metric := &pb.Metric{
Type: pb.MetricType(pb.MetricType_value[metric.Type.String()]),
Value: metric.Value,
}
link.Metrics = append(link.Metrics, metric)
}
node.LsLinks = append(node.LsLinks, link)
}
for _, lsPrefix := range lsNode.Prefixes {
prefix := &pb.LsPrefix{
Prefix: lsPrefix.Prefix.String(),
SidIndex: lsPrefix.SidIndex,
}
node.LsPrefixes = append(node.LsPrefixes, prefix)
}
ret.LsNodes = append(ret.LsNodes, node)
}
}
return &ret, nil
}

func (s *Server) removeSession(session *Session) {
// Remove Session List
for i, v := range s.sessionList {
Expand Down

0 comments on commit 4b5d8a7

Please sign in to comment.