Skip to content

Commit 7feb089

Browse files
author
Marc Odermatt
committed
Refactor description lookup and improve usage info
1 parent d8504b7 commit 7feb089

File tree

6 files changed

+68
-203
lines changed

6 files changed

+68
-203
lines changed

doc/command/scion/scion_fabrid.rst

+5-15
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,33 @@ Synopsis
1111
~~~~~~~~
1212

1313

14-
'fabrid' lists available policies at a remote AS, or shows the
15-
description of a specific policy.
14+
'fabrid' fetches the description of a global or local FABRID policy.
1615

1716
::
1817

19-
scion fabrid [flags]
18+
scion fabrid identifier [remote_as] [flags]
2019

2120
Examples
2221
~~~~~~~~
2322

2423
::
2524

26-
scion showpaths 1-ff00:0:110 --extended
27-
scion showpaths 1-ff00:0:110 --local 127.0.0.55 --json
28-
scion showpaths 1-ff00:0:111 --sequence="0-0#2 0*" # outgoing IfID=2
29-
scion showpaths 1-ff00:0:111 --sequence="0* 0-0#41" # incoming IfID=41 at dstIA
30-
scion showpaths 1-ff00:0:111 --sequence="0* 1-ff00:0:112 0*" # 1-ff00:0:112 on the path
31-
scion showpaths 1-ff00:0:110 --no-probe
25+
scion fabrid G1001
26+
scion fabrid L1101 1-ff00:0:110
27+
scion fabrid L1101 1-ff00:0:110 --log.level debug'
3228

3329
Options
3430
~~~~~~~
3531

3632
::
3733

38-
--epic Enable EPIC.
39-
-e, --extended Show extended path meta data information
4034
--format string Specify the output format (human|json|yaml) (default "human")
4135
-h, --help help for fabrid
4236
--isd-as isd-as The local ISD-AS to use. (default 0-0)
4337
-l, --local ip Local IP address to listen on. (default invalid IP)
4438
--log.level string Console logging level verbosity (debug|info|error)
45-
-m, --maxpaths int Maximum number of paths that are displayed (default 10)
4639
--no-color disable colored output
47-
--no-probe Do not probe the paths and print the health status
48-
-r, --refresh Set refresh flag for SCION Daemon path request
4940
--sciond string SCION Daemon address. (default "127.0.0.1:30255")
50-
--sequence string Space separated list of hop predicates
5141
--timeout duration Timeout (default 5s)
5242
--tracing.agent string Tracing agent address
5343

scion/cmd/scion/BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ go_library(
3333
"//private/path/pathpol:go_default_library",
3434
"//private/topology:go_default_library",
3535
"//private/tracing:go_default_library",
36-
"//scion/fabrid:go_default_library",
3736
"//scion/ping:go_default_library",
3837
"//scion/showpaths:go_default_library",
3938
"//scion/traceroute:go_default_library",

scion/cmd/scion/fabrid.go

+63-75
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,73 @@ package main
1717
import (
1818
"context"
1919
"fmt"
20-
"net"
2120
"strconv"
2221
"time"
2322

2423
"github.com/spf13/cobra"
2524

2625
"github.com/scionproto/scion/pkg/addr"
27-
"github.com/scionproto/scion/pkg/log"
26+
"github.com/scionproto/scion/pkg/daemon"
2827
"github.com/scionproto/scion/pkg/private/serrors"
2928
"github.com/scionproto/scion/private/app"
3029
"github.com/scionproto/scion/private/app/flag"
3130
"github.com/scionproto/scion/private/tracing"
32-
"github.com/scionproto/scion/scion/fabrid"
3331
)
3432

3533
func newFabrid(pather CommandPather) *cobra.Command {
3634
var envFlags flag.SCIONEnvironment
3735
var flags struct {
3836
timeout time.Duration
39-
cfg fabrid.Config
40-
extended bool
41-
json bool
4237
logLevel string
4338
noColor bool
4439
tracer string
4540
format string
4641
}
4742

4843
var cmd = &cobra.Command{
49-
Use: "fabrid",
44+
Use: "fabrid identifier [remote_as]",
5045
Short: "Display FABRID policy information",
5146
Args: cobra.RangeArgs(1, 2),
52-
Example: fmt.Sprintf(` %[1]s showpaths 1-ff00:0:110 --extended
53-
%[1]s showpaths 1-ff00:0:110 --local 127.0.0.55 --json
54-
%[1]s showpaths 1-ff00:0:111 --sequence="0-0#2 0*" # outgoing IfID=2
55-
%[1]s showpaths 1-ff00:0:111 --sequence="0* 0-0#41" # incoming IfID=41 at dstIA
56-
%[1]s showpaths 1-ff00:0:111 --sequence="0* 1-ff00:0:112 0*" # 1-ff00:0:112 on the path
57-
%[1]s showpaths 1-ff00:0:110 --no-probe`, pather.CommandPath()),
58-
Long: `'fabrid' lists available policies at a remote AS, or shows the
59-
description of a specific policy.`,
47+
Example: fmt.Sprintf(` %[1]s fabrid G1001
48+
%[1]s fabrid L1101 1-ff00:0:110
49+
%[1]s fabrid L1101 1-ff00:0:110 --log.level debug'`, pather.CommandPath()),
50+
Long: `'fabrid' fetches the description of a global or local FABRID policy.`,
6051
RunE: func(cmd *cobra.Command, args []string) error {
61-
if err := app.SetupLog(flags.logLevel); err != nil {
52+
if len(args[0]) < 2 {
53+
return serrors.New("Invalid identifier format", "identifier", args[0])
54+
}
55+
56+
identifierPrefix := args[0][0]
57+
var isLocal bool
58+
switch identifierPrefix {
59+
case 'L':
60+
isLocal = true
61+
case 'G':
62+
isLocal = false
63+
default:
64+
return serrors.New("invalid identifier prefix", "prefix", string(identifierPrefix))
65+
}
66+
67+
identifier, err := strconv.ParseUint(args[0][1:], 10, 32)
68+
if err != nil {
69+
return serrors.New("invalid identifier format", "identifier", args[0])
70+
}
71+
72+
if isLocal && len(args) == 1 {
73+
return serrors.New("missing destination ISD-AS for local policy")
74+
}
75+
var dst addr.IA
76+
if len(args) > 1 {
77+
if !isLocal {
78+
return serrors.New(
79+
"unexpected argument. Global policies require no destination AS.")
80+
}
81+
dst, err = addr.ParseIA(args[1])
82+
if err != nil {
83+
return serrors.WrapStr("invalid destination ISD-AS", err)
84+
}
85+
}
86+
if err = app.SetupLog(flags.logLevel); err != nil {
6287
return serrors.WrapStr("setting up logging", err)
6388
}
6489
closer, err := setupTracer("fabrid", flags.tracer)
@@ -67,88 +92,51 @@ description of a specific policy.`,
6792
}
6893
defer closer()
6994

70-
if flags.json && !cmd.Flags().Lookup("format").Changed {
71-
flags.format = "json"
72-
}
73-
7495
cmd.SilenceUsage = true
7596

76-
if err := envFlags.LoadExternalVars(); err != nil {
97+
if err = envFlags.LoadExternalVars(); err != nil {
7798
return err
7899
}
79100

80-
flags.cfg.Daemon = envFlags.Daemon()
81-
flags.cfg.Local = net.IP(envFlags.Local().AsSlice())
82-
log.Debug("Resolved SCION environment flags",
83-
"daemon", flags.cfg.Daemon,
84-
"local", flags.cfg.Local,
85-
)
101+
daemonAddr := envFlags.Daemon()
86102

87103
span, traceCtx := tracing.CtxWith(context.Background(), "run")
88104
defer span.Finish()
105+
span.SetTag("dst.isd_as", dst)
89106

90107
ctx, cancel := context.WithTimeout(traceCtx, flags.timeout)
91108
defer cancel()
92-
if len(args) == 1 {
93-
identifier, err := strconv.ParseUint(args[0], 10, 32)
94-
if err != nil {
95-
return serrors.WrapStr("invalid policy identifier", err)
96-
}
97-
_, err = fabrid.Run(ctx, false, nil, uint32(identifier), flags.cfg)
98-
if err != nil {
99-
return err
100-
}
101109

102-
} else if len(args) == 2 {
103-
dst, err := addr.ParseIA(args[0])
104-
if err != nil {
105-
return serrors.WrapStr("invalid destination ISD-AS", err)
106-
}
107-
identifier, err := strconv.ParseUint(args[1], 10, 32)
108-
if err != nil {
109-
return serrors.WrapStr("invalid policy identifier", err)
110-
}
111-
_, err = fabrid.Run(ctx, true, &dst, uint32(identifier), flags.cfg)
112-
if err != nil {
113-
return err
114-
}
115-
span.SetTag("dst.isd_as", dst)
110+
var description string
111+
daemonService := &daemon.Service{
112+
Address: daemonAddr,
116113
}
117-
switch flags.format {
118-
case "human":
119-
return nil
120-
case "json":
121-
return serrors.New("Not implemented", "format", flags.format)
122-
case "yaml":
123-
return serrors.New("Not implemented", "format", flags.format)
124-
default:
125-
return serrors.New("output format not supported", "format", flags.format)
114+
sdConn, err := daemonService.Connect(ctx)
115+
if err != nil {
116+
return serrors.WrapStr("connecting to the SCION Daemon", err, "addr", daemonAddr)
117+
}
118+
defer sdConn.Close()
119+
120+
description, err = sdConn.PolicyDescription(ctx, isLocal, uint32(identifier), &dst)
121+
if err != nil {
122+
return serrors.WrapStr("retrieving description from the SCION Daemon", err)
126123
}
124+
// Output the description
125+
if isLocal {
126+
fmt.Printf("Policy L%d@%s\n%s\n", identifier, dst, description)
127+
} else {
128+
fmt.Printf("Policy G%d\n%s\n", identifier, description)
129+
}
130+
return nil
127131
},
128132
}
129133

130134
envFlags.Register(cmd.Flags())
131135
cmd.Flags().DurationVar(&flags.timeout, "timeout", 5*time.Second, "Timeout")
132-
cmd.Flags().StringVar(&flags.cfg.Sequence, "sequence", "", app.SequenceUsage)
133-
cmd.Flags().IntVarP(&flags.cfg.MaxPaths, "maxpaths", "m", 10,
134-
"Maximum number of paths that are displayed")
135-
cmd.Flags().BoolVarP(&flags.extended, "extended", "e", false,
136-
"Show extended path meta data information")
137-
cmd.Flags().BoolVarP(&flags.cfg.Refresh, "refresh", "r", false,
138-
"Set refresh flag for SCION Daemon path request")
139-
cmd.Flags().BoolVar(&flags.cfg.NoProbe, "no-probe", false,
140-
"Do not probe the paths and print the health status")
141-
cmd.Flags().BoolVarP(&flags.json, "json", "j", false,
142-
"Write the output as machine readable json")
143136
cmd.Flags().StringVar(&flags.format, "format", "human",
144137
"Specify the output format (human|json|yaml)")
145138
cmd.Flags().BoolVar(&flags.noColor, "no-color", false, "disable colored output")
146139
cmd.Flags().StringVar(&flags.logLevel, "log.level", "", app.LogLevelUsage)
147140
cmd.Flags().StringVar(&flags.tracer, "tracing.agent", "", "Tracing agent address")
148-
cmd.Flags().BoolVar(&flags.cfg.Epic, "epic", false, "Enable EPIC.")
149-
err := cmd.Flags().MarkDeprecated("json", "json flag is deprecated, use format flag")
150-
if err != nil {
151-
panic(err)
152-
}
153141
return cmd
154142
}

scion/fabrid/BUILD.bazel

-16
This file was deleted.

scion/fabrid/config.go

-44
This file was deleted.

scion/fabrid/fabrid.go

-52
This file was deleted.

0 commit comments

Comments
 (0)