Skip to content

Commit 35d3ddd

Browse files
author
Marc Odermatt
committed
desc-lookup local
1 parent 587995b commit 35d3ddd

File tree

7 files changed

+18
-139
lines changed

7 files changed

+18
-139
lines changed

pkg/daemon/daemon.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package daemon
1818

1919
import (
2020
"context"
21-
"github.com/scionproto/scion/pkg/proto/control_plane/experimental"
2221
"net/netip"
2322

2423
"github.com/scionproto/scion/pkg/addr"
@@ -91,7 +90,7 @@ type Connector interface {
9190
DRKeyGetHostHostKey(ctx context.Context, meta drkey.HostHostMeta) (drkey.HostHostKey, error)
9291
// FabridKeys requests FABRID DRKeys for all provided ASes and the path validation key
9392
FabridKeys(ctx context.Context, meta drkey.FabridKeysMeta) (drkey.FabridKeysResponse, error)
94-
RemotePolicyDescription(context.Context, *experimental.RemotePolicyDescriptionRequest) (*experimental.RemotePolicyDescriptionResponse, error)
93+
RemotePolicyDescription(ctx context.Context, identifier uint32, ia addr.IA) (string, error)
9594
// Close shuts down the connection to the daemon.
9695
Close() error
9796
}

pkg/daemon/grpc.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"google.golang.org/protobuf/types/known/emptypb"
2525
"google.golang.org/protobuf/types/known/timestamppb"
2626

27-
fabrid_control "github.com/scionproto/scion/control/fabrid"
2827
"github.com/scionproto/scion/pkg/addr"
2928
"github.com/scionproto/scion/pkg/drkey"
3029
"github.com/scionproto/scion/pkg/experimental/fabrid"
@@ -280,17 +279,17 @@ func (c grpcConn) FabridKeys(ctx context.Context, meta drkey.FabridKeysMeta,
280279
}
281280

282281
func (c grpcConn) RemotePolicyDescription(ctx context.Context,
283-
identifier fabrid_control.RemotePolicyIdentifier) (fabrid_control.RemotePolicyDescription, error) {
282+
identifier uint32, ia addr.IA) (string, error) {
284283

285284
client := sdpb.NewDaemonServiceClient(c.conn)
286285
response, err := client.RemotePolicyDescription(ctx, &cppb.RemotePolicyDescriptionRequest{
287-
PolicyIdentifier: identifier.Identifier,
288-
IsdAs: identifier.ISDAS,
286+
PolicyIdentifier: identifier,
287+
IsdAs: uint64(ia),
289288
})
290289
if err != nil {
291-
return fabrid_control.RemotePolicyDescription{}, err
290+
return "", nil
292291
}
293-
return fabrid_control.RemotePolicyDescription{Description: }, err
292+
return response.Description, err
294293
}
295294

296295
func (c grpcConn) Close() error {

scion/cmd/scion/BUILD.bazel

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ go_library(
1212
"ping.go",
1313
"showpaths.go",
1414
"traceroute.go",
15+
"fabrid.go",
1516
],
1617
importpath = "github.com/scionproto/scion/scion/cmd/scion",
1718
visibility = ["//visibility:private"],
@@ -32,6 +33,7 @@ go_library(
3233
"//private/path/pathpol:go_default_library",
3334
"//private/topology:go_default_library",
3435
"//private/tracing:go_default_library",
36+
"//scion/fabrid:go_default_library",
3537
"//scion/ping:go_default_library",
3638
"//scion/showpaths:go_default_library",
3739
"//scion/traceroute:go_default_library",

scion/cmd/scion/fabrid.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ description of a specific policy.`,
7272
if flags.json && !cmd.Flags().Lookup("format").Changed {
7373
flags.format = "json"
7474
}
75-
printf, err := getPrintf(flags.format, cmd.OutOrStdout())
76-
if err != nil {
77-
return serrors.WrapStr("get formatting", err)
78-
}
7975

8076
cmd.SilenceUsage = true
8177

@@ -100,26 +96,17 @@ description of a specific policy.`,
10096
if err != nil {
10197
return err
10298
}
103-
99+
fmt.Println(res.Destination, res.Description)
104100
switch flags.format {
105101
case "human":
106-
if res.IsLocal() {
107-
printf("Empty path, destination is local AS %s\n", res.Destination)
108-
return nil
109-
}
110-
printf("Available policies at %s\n", res.Destination)
111-
if len(res.Paths) == 0 {
112-
return app.WithExitCode(serrors.New("no policies found"), 1)
113-
}
114-
res.Human(cmd.OutOrStdout(), flags.extended, !flags.noColor)
102+
return nil
115103
case "json":
116104
return serrors.New("Not implemented", "format", flags.format)
117105
case "yaml":
118106
return serrors.New("Not implemented", "format", flags.format)
119107
default:
120108
return serrors.New("output format not supported", "format", flags.format)
121109
}
122-
return nil
123110
},
124111
}
125112

scion/cmd/scion/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func main() {
5656
newTraceroute(cmd),
5757
newAddress(cmd),
5858
newGendocs(cmd),
59+
newFabrid(cmd),
5960
)
6061
// This Templatefunc allows use some escape characters for the rst
6162
// documentation conversion without compromising the readability of the help

scion/fabrid/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go_library(
44
name = "go_default_library",
55
srcs = [
66
"config.go",
7-
"showpaths.go",
7+
"fabrid.go",
88
],
99
importpath = "github.com/scionproto/scion/scion/fabrid",
1010
visibility = ["//visibility:public"],

scion/fabrid/fabrid.go

+6-115
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,16 @@ package fabrid
1616

1717
import (
1818
"context"
19-
"net/netip"
20-
"strings"
21-
"time"
22-
19+
"fmt"
2320
"github.com/scionproto/scion/pkg/addr"
2421
"github.com/scionproto/scion/pkg/daemon"
25-
"github.com/scionproto/scion/pkg/private/common"
2622
"github.com/scionproto/scion/pkg/private/serrors"
27-
"github.com/scionproto/scion/pkg/snet"
28-
"github.com/scionproto/scion/private/app/path"
29-
"github.com/scionproto/scion/private/app/path/pathprobe"
30-
"github.com/scionproto/scion/private/path/pathpol"
3123
)
3224

3325
// Result contains all the discovered paths.
3426
type Result struct {
35-
LocalIA addr.IA `json:"local_isd_as" yaml:"local_isd_as"`
3627
Destination addr.IA `json:"destination" yaml:"destination"`
37-
Policies []Path `json:"paths,omitempty" yaml:"paths,omitempty"`
38-
}
39-
40-
// Policy holds information about the available policy.
41-
type Path struct {
42-
FullPath snet.Path `json:"-" yaml:"-"`
43-
Fingerprint string `json:"fingerprint" yaml:"fingerprint"`
44-
Hops []Hop `json:"hops" yaml:"hops"`
45-
Sequence string `json:"sequence" yaml:"sequence"`
46-
NextHop string `json:"next_hop" yaml:"next_hop"`
47-
Expiry time.Time `json:"expiry" yaml:"expiry"`
48-
MTU uint16 `json:"mtu" yaml:"mtu"`
49-
Latency []time.Duration `json:"latency" yaml:"latency"`
50-
CarbonIntensity []int64 `json:"carbon_intensity"`
51-
Status string `json:"status,omitempty" yaml:"status,omitempty"`
52-
StatusInfo string `json:"status_info,omitempty" yaml:"status_info,omitempty"`
53-
Local netip.Addr `json:"local_ip,omitempty" yaml:"local_ip,omitempty"`
54-
}
55-
56-
// Hop represents an hop on the path.
57-
type Hop struct {
58-
IfID common.IFIDType `json:"ifid"`
59-
IA addr.IA `json:"isd_as"`
28+
Description string `json:"description,omitempty" yaml:"description,omitempty"`
6029
}
6130

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

74-
allPaths, err := sdConn.RemotePolicyDescription()
75-
if err != nil {
76-
return nil, serrors.WrapStr("retrieving paths from the SCION Daemon", err)
77-
}
78-
paths, err := path.Filter(cfg.Sequence, allPaths)
39+
description, err := sdConn.RemotePolicyDescription(ctx, 10, dst)
7940
if err != nil {
80-
return nil, err
81-
}
82-
if cfg.MaxPaths != 0 && len(paths) > cfg.MaxPaths {
83-
paths = paths[:cfg.MaxPaths]
84-
}
85-
86-
// If the epic flag is set, filter all paths that do not have
87-
// the necessary epic authenticators.
88-
if cfg.Epic {
89-
epicPaths := []snet.Path{}
90-
for _, p := range paths {
91-
if p.Metadata().EpicAuths.SupportsEpic() {
92-
epicPaths = append(epicPaths, p)
93-
}
94-
}
95-
paths = epicPaths
96-
}
97-
98-
var statuses map[string]pathprobe.Status
99-
if !cfg.NoProbe {
100-
p := pathprobe.FilterEmptyPaths(paths)
101-
statuses, err = pathprobe.Prober{
102-
DstIA: dst,
103-
LocalIA: localIA,
104-
LocalIP: cfg.Local,
105-
Topology: sdConn,
106-
}.GetStatuses(ctx, p, pathprobe.WithEPIC(cfg.Epic))
107-
if err != nil {
108-
return nil, serrors.WrapStr("getting statuses", err)
109-
}
110-
}
111-
path.Sort(paths)
112-
res := &Result{
113-
LocalIA: localIA,
114-
Destination: dst,
115-
Paths: []Path{},
116-
}
117-
for _, path := range paths {
118-
fingerprint := "local"
119-
if len(path.Metadata().Interfaces) > 0 {
120-
fp := snet.Fingerprint(path).String()
121-
fingerprint = fp[:16]
122-
}
123-
var nextHop string
124-
if nh := path.UnderlayNextHop(); nh != nil {
125-
nextHop = path.UnderlayNextHop().String()
126-
}
127-
pathMeta := path.Metadata()
128-
rpath := Path{
129-
FullPath: path,
130-
Fingerprint: fingerprint,
131-
NextHop: nextHop,
132-
Expiry: pathMeta.Expiry,
133-
MTU: pathMeta.MTU,
134-
Latency: pathMeta.Latency,
135-
CarbonIntensity: pathMeta.CarbonIntensity,
136-
Hops: []Hop{},
137-
}
138-
for _, hop := range path.Metadata().Interfaces {
139-
rpath.Hops = append(rpath.Hops, Hop{IA: hop.IA, IfID: hop.ID})
140-
}
141-
if status, ok := statuses[pathprobe.PathKey(path)]; ok {
142-
rpath.Status = strings.ToLower(string(status.Status))
143-
rpath.StatusInfo = status.AdditionalInfo
144-
rpath.Local = status.LocalIP
145-
}
146-
seq, err := pathpol.GetSequence(path)
147-
rpath.Sequence = seq
148-
if err != nil {
149-
rpath.Sequence = "invalid"
150-
}
151-
res.Paths = append(res.Paths, rpath)
41+
return nil, serrors.WrapStr("retrieving description from the SCION Daemon", err)
15242
}
153-
return res, nil
43+
fmt.Println(description)
44+
return &Result{Destination: dst, Description: description}, nil
15445
}

0 commit comments

Comments
 (0)