Skip to content

Commit

Permalink
desc-lookup local
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Odermatt committed Sep 12, 2024
1 parent d17df4b commit bc8a1da
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 139 deletions.
3 changes: 1 addition & 2 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package daemon

import (
"context"
"github.com/scionproto/scion/pkg/proto/control_plane/experimental"
"net/netip"

"github.com/scionproto/scion/pkg/addr"
Expand Down Expand Up @@ -91,7 +90,7 @@ type Connector interface {
DRKeyGetHostHostKey(ctx context.Context, meta drkey.HostHostMeta) (drkey.HostHostKey, error)
// FabridKeys requests FABRID DRKeys for all provided ASes and the path validation key
FabridKeys(ctx context.Context, meta drkey.FabridKeysMeta) (drkey.FabridKeysResponse, error)
RemotePolicyDescription(context.Context, *experimental.RemotePolicyDescriptionRequest) (*experimental.RemotePolicyDescriptionResponse, error)
RemotePolicyDescription(ctx context.Context, identifier uint32, ia addr.IA) (string, error)
// Close shuts down the connection to the daemon.
Close() error
}
11 changes: 5 additions & 6 deletions pkg/daemon/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"

fabrid_control "github.com/scionproto/scion/control/fabrid"
"github.com/scionproto/scion/pkg/addr"
"github.com/scionproto/scion/pkg/drkey"
"github.com/scionproto/scion/pkg/experimental/fabrid"
Expand Down Expand Up @@ -280,17 +279,17 @@ func (c grpcConn) FabridKeys(ctx context.Context, meta drkey.FabridKeysMeta,
}

func (c grpcConn) RemotePolicyDescription(ctx context.Context,
identifier fabrid_control.RemotePolicyIdentifier) (fabrid_control.RemotePolicyDescription, error) {
identifier uint32, ia addr.IA) (string, error) {

client := sdpb.NewDaemonServiceClient(c.conn)
response, err := client.RemotePolicyDescription(ctx, &cppb.RemotePolicyDescriptionRequest{
PolicyIdentifier: identifier.Identifier,
IsdAs: identifier.ISDAS,
PolicyIdentifier: identifier,
IsdAs: uint64(ia),
})
if err != nil {
return fabrid_control.RemotePolicyDescription{}, err
return "", nil
}
return fabrid_control.RemotePolicyDescription{Description: }, err
return response.Description, err
}

func (c grpcConn) Close() error {
Expand Down
2 changes: 2 additions & 0 deletions scion/cmd/scion/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
"ping.go",
"showpaths.go",
"traceroute.go",
"fabrid.go",
],
importpath = "github.com/scionproto/scion/scion/cmd/scion",
visibility = ["//visibility:private"],
Expand All @@ -32,6 +33,7 @@ go_library(
"//private/path/pathpol:go_default_library",
"//private/topology:go_default_library",
"//private/tracing:go_default_library",
"//scion/fabrid:go_default_library",
"//scion/ping:go_default_library",
"//scion/showpaths:go_default_library",
"//scion/traceroute:go_default_library",
Expand Down
17 changes: 2 additions & 15 deletions scion/cmd/scion/fabrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ description of a specific policy.`,
if flags.json && !cmd.Flags().Lookup("format").Changed {
flags.format = "json"
}
printf, err := getPrintf(flags.format, cmd.OutOrStdout())
if err != nil {
return serrors.WrapStr("get formatting", err)
}

cmd.SilenceUsage = true

Expand All @@ -100,26 +96,17 @@ description of a specific policy.`,
if err != nil {
return err
}

fmt.Println(res.Destination, res.Description)
switch flags.format {
case "human":
if res.IsLocal() {
printf("Empty path, destination is local AS %s\n", res.Destination)
return nil
}
printf("Available policies at %s\n", res.Destination)
if len(res.Paths) == 0 {
return app.WithExitCode(serrors.New("no policies found"), 1)
}
res.Human(cmd.OutOrStdout(), flags.extended, !flags.noColor)
return nil
case "json":
return serrors.New("Not implemented", "format", flags.format)
case "yaml":
return serrors.New("Not implemented", "format", flags.format)
default:
return serrors.New("output format not supported", "format", flags.format)
}
return nil
},
}

Expand Down
1 change: 1 addition & 0 deletions scion/cmd/scion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func main() {
newTraceroute(cmd),
newAddress(cmd),
newGendocs(cmd),
newFabrid(cmd),
)
// This Templatefunc allows use some escape characters for the rst
// documentation conversion without compromising the readability of the help
Expand Down
2 changes: 1 addition & 1 deletion scion/fabrid/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go_library(
name = "go_default_library",
srcs = [
"config.go",
"showpaths.go",
"fabrid.go",
],
importpath = "github.com/scionproto/scion/scion/fabrid",
visibility = ["//visibility:public"],
Expand Down
121 changes: 6 additions & 115 deletions scion/fabrid/fabrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,16 @@ package fabrid

import (
"context"
"net/netip"
"strings"
"time"

"fmt"
"github.com/scionproto/scion/pkg/addr"
"github.com/scionproto/scion/pkg/daemon"
"github.com/scionproto/scion/pkg/private/common"
"github.com/scionproto/scion/pkg/private/serrors"
"github.com/scionproto/scion/pkg/snet"
"github.com/scionproto/scion/private/app/path"
"github.com/scionproto/scion/private/app/path/pathprobe"
"github.com/scionproto/scion/private/path/pathpol"
)

// Result contains all the discovered paths.
type Result struct {
LocalIA addr.IA `json:"local_isd_as" yaml:"local_isd_as"`
Destination addr.IA `json:"destination" yaml:"destination"`
Policies []Path `json:"paths,omitempty" yaml:"paths,omitempty"`
}

// Policy holds information about the available policy.
type Path struct {
FullPath snet.Path `json:"-" yaml:"-"`
Fingerprint string `json:"fingerprint" yaml:"fingerprint"`
Hops []Hop `json:"hops" yaml:"hops"`
Sequence string `json:"sequence" yaml:"sequence"`
NextHop string `json:"next_hop" yaml:"next_hop"`
Expiry time.Time `json:"expiry" yaml:"expiry"`
MTU uint16 `json:"mtu" yaml:"mtu"`
Latency []time.Duration `json:"latency" yaml:"latency"`
CarbonIntensity []int64 `json:"carbon_intensity"`
Status string `json:"status,omitempty" yaml:"status,omitempty"`
StatusInfo string `json:"status_info,omitempty" yaml:"status_info,omitempty"`
Local netip.Addr `json:"local_ip,omitempty" yaml:"local_ip,omitempty"`
}

// Hop represents an hop on the path.
type Hop struct {
IfID common.IFIDType `json:"ifid"`
IA addr.IA `json:"isd_as"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
}

// Run lists information for FABRID policies to stdout.
Expand All @@ -66,89 +35,11 @@ func Run(ctx context.Context, dst addr.IA, cfg Config) (*Result, error) {
return nil, serrors.WrapStr("connecting to the SCION Daemon", err, "addr", cfg.Daemon)
}
defer sdConn.Close()
localIA, err := sdConn.LocalIA(ctx)
if err != nil {
return nil, serrors.WrapStr("determining local ISD-AS", err)
}

allPaths, err := sdConn.RemotePolicyDescription()
if err != nil {
return nil, serrors.WrapStr("retrieving paths from the SCION Daemon", err)
}
paths, err := path.Filter(cfg.Sequence, allPaths)
description, err := sdConn.RemotePolicyDescription(ctx, 10, dst)
if err != nil {
return nil, err
}
if cfg.MaxPaths != 0 && len(paths) > cfg.MaxPaths {
paths = paths[:cfg.MaxPaths]
}

// If the epic flag is set, filter all paths that do not have
// the necessary epic authenticators.
if cfg.Epic {
epicPaths := []snet.Path{}
for _, p := range paths {
if p.Metadata().EpicAuths.SupportsEpic() {
epicPaths = append(epicPaths, p)
}
}
paths = epicPaths
}

var statuses map[string]pathprobe.Status
if !cfg.NoProbe {
p := pathprobe.FilterEmptyPaths(paths)
statuses, err = pathprobe.Prober{
DstIA: dst,
LocalIA: localIA,
LocalIP: cfg.Local,
Topology: sdConn,
}.GetStatuses(ctx, p, pathprobe.WithEPIC(cfg.Epic))
if err != nil {
return nil, serrors.WrapStr("getting statuses", err)
}
}
path.Sort(paths)
res := &Result{
LocalIA: localIA,
Destination: dst,
Paths: []Path{},
}
for _, path := range paths {
fingerprint := "local"
if len(path.Metadata().Interfaces) > 0 {
fp := snet.Fingerprint(path).String()
fingerprint = fp[:16]
}
var nextHop string
if nh := path.UnderlayNextHop(); nh != nil {
nextHop = path.UnderlayNextHop().String()
}
pathMeta := path.Metadata()
rpath := Path{
FullPath: path,
Fingerprint: fingerprint,
NextHop: nextHop,
Expiry: pathMeta.Expiry,
MTU: pathMeta.MTU,
Latency: pathMeta.Latency,
CarbonIntensity: pathMeta.CarbonIntensity,
Hops: []Hop{},
}
for _, hop := range path.Metadata().Interfaces {
rpath.Hops = append(rpath.Hops, Hop{IA: hop.IA, IfID: hop.ID})
}
if status, ok := statuses[pathprobe.PathKey(path)]; ok {
rpath.Status = strings.ToLower(string(status.Status))
rpath.StatusInfo = status.AdditionalInfo
rpath.Local = status.LocalIP
}
seq, err := pathpol.GetSequence(path)
rpath.Sequence = seq
if err != nil {
rpath.Sequence = "invalid"
}
res.Paths = append(res.Paths, rpath)
return nil, serrors.WrapStr("retrieving description from the SCION Daemon", err)
}
return res, nil
fmt.Println(description)
return &Result{Destination: dst, Description: description}, nil
}

0 comments on commit bc8a1da

Please sign in to comment.