Skip to content

Commit

Permalink
Refactoring server and Path calculation using TED
Browse files Browse the repository at this point in the history
  • Loading branch information
Motok1 committed Oct 11, 2022
1 parent 0ae6d63 commit 73cb926
Show file tree
Hide file tree
Showing 4 changed files with 337 additions and 150 deletions.
36 changes: 26 additions & 10 deletions api/grpc/pola.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,55 @@ option go_package = "github.com/nttcom/pola/api/grpc";
import "google/protobuf/empty.proto";

service PceService {
rpc CreateLsp (LspData) returns (LspStatus) {};
rpc CreateSrPolicy (CreateSrPolicyInput) returns (SrPolicyStatus) {};

rpc CreateSrPolicyWithoutLinkState (CreateSrPolicyInput) returns (SrPolicyStatus) {};

rpc GetPeerAddrList (google.protobuf.Empty) returns (PeerAddrList) {};

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

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

message Label {
message Segment {
uint32 sid = 1;
bytes loAddr = 2;
}

message LspData {
enum SrPolicyType {
EXPLICIT = 0;
DYNAMIC = 1;
}

message SrPolicy {
bytes pcepSessionAddr = 1;
bytes srcAddr = 2;
bytes dstAddr = 3;
repeated Label labels = 4;
uint32 color = 5;
string policyName = 6;
string srcRouterId = 4;
string dstRouterId = 5;
uint32 color = 6;
string policyName = 7;
SrPolicyType type = 8;
repeated Segment segmentList = 9;
MetricType metric = 10;
}

message LspStatus {
message CreateSrPolicyInput {
SrPolicy srPolicy = 1;
uint32 asn = 2;
}

message SrPolicyStatus {
bool isSuccess = 1;
}

message PeerAddrList {
repeated bytes PeerAddrs = 1;
}

message LspList {
repeated LspData Lsps = 1;
message SrPolicyList {
repeated SrPolicy SrPolicies = 1;
}

message LsPrefix {
Expand Down
47 changes: 46 additions & 1 deletion internal/pkg/table/ted.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package table

import (
"errors"
"fmt"
"net"
)
Expand Down Expand Up @@ -43,8 +44,9 @@ func (ted LsTed) ShowTed() {
for _, link := range node.Links {
fmt.Printf(" Local: %s Remote: %s\n", link.LocalIP.String(), link.RemoteIP.String())
fmt.Printf(" RemoteNode: %s\n", link.RemoteNode.RouterId)
fmt.Printf(" Metrics:\n")
for _, metric := range link.Metrics {
fmt.Printf(" Metrics: %s %d\n", metric.Type.String(), metric.Value)
fmt.Printf(" %s: %d\n", metric.Type.String(), metric.Value)
}
fmt.Printf(" Adj-SID: %d\n", link.AdjSid)
}
Expand All @@ -55,6 +57,20 @@ func (ted LsTed) ShowTed() {
}
}

func (ted LsTed) GetRouterIdFromSid(as uint32, Sid uint32) (string, error) {
nodes := ted.Nodes[as]
for routerId, node := range nodes {
nodeSid, err := node.NodeSid()
if err != nil {
return "", err
}
if nodeSid == Sid {
return routerId, nil
}
}
return "", errors.New("specified node could not be found")
}

type TedElem interface {
UpdateTed(*LsTed)
}
Expand All @@ -79,6 +95,26 @@ func NewLsNode(asn uint32, nodeId string) *LsNode {
return lsnode
}

func (node LsNode) NodeSid() (uint32, error) {
for _, prefix := range node.Prefixes {
// If it's a loopback prefix, it should be non-zero.
if prefix.SidIndex != 0 {
return node.SrgbBegin + prefix.SidIndex, nil
}
}
return 0, errors.New("node doesn't have node-sid")
}

func (node LsNode) LoopbackAddr() (net.IP, error) {
for _, prefix := range node.Prefixes {
// If it's a loopback prefix, it should be non-zero.
if prefix.SidIndex != 0 {
return prefix.Prefix.IP, nil
}
}
return nil, errors.New("node doesn't have loopback addr")
}

func (lsNode *LsNode) UpdateTed(ted *LsTed) {
if _, ok := ted.Nodes[lsNode.Asn]; !ok {
ted.Nodes[lsNode.Asn] = map[string]*LsNode{}
Expand Down Expand Up @@ -111,6 +147,15 @@ func NewLsLink(localNode *LsNode, remoteNode *LsNode) *LsLink {
return lsLink
}

func (link LsLink) Metric(metricType MetricType) (uint32, error) {
for _, metric := range link.Metrics {
if metric.Type == metricType {
return metric.Value, nil
}
}
return 0, errors.New("don't define metric")
}

func (lsLink *LsLink) UpdateTed(ted *LsTed) {
if _, ok := ted.Nodes[lsLink.LocalNode.Asn]; !ok {
ted.Nodes[lsLink.LocalNode.Asn] = map[string]*LsNode{}
Expand Down
Loading

0 comments on commit 73cb926

Please sign in to comment.