diff --git a/app/fileStat.go b/app/fileStat.go index 2707364..b9fa773 100644 --- a/app/fileStat.go +++ b/app/fileStat.go @@ -110,13 +110,14 @@ func (a *App) FileStat(ctx context.Context, t *Target) ([]*fileStatInfo, error) } func (a *App) fileStat(ctx context.Context, t *Target, fileClient file.FileClient, path string) ([]*fileStatInfo, error) { - r, err := fileClient.Stat(ctx, &file.StatRequest{ - Path: path, - }) + req := &file.StatRequest{Path: path} + a.printMsg(t.Config.Name, req) + r, err := fileClient.Stat(ctx, req) if err != nil { return nil, fmt.Errorf("%q file %q stat err: %v", t.Config.Address, path, err) } a.Logger.Debugf("%q File Stat Response:\n%s", t.Config.Address, prototext.Format(r)) + a.printMsg(t.Config.Name, r) rsps := make([]*fileStatInfo, 0, len(r.Stats)) for _, si := range r.Stats { isDir, err := a.isDir(ctx, fileClient, si.Path) diff --git a/app/systemPing.go b/app/systemPing.go index f73d950..e93ff17 100644 --- a/app/systemPing.go +++ b/app/systemPing.go @@ -34,7 +34,7 @@ func (a *App) InitSystemPingFlags(cmd *cobra.Command) { cmd.Flags().Int32Var(&a.Config.SystemPingSize, "size", 0, "Size of request packet. (excluding ICMP header)") cmd.Flags().BoolVar(&a.Config.SystemPingDoNotFragment, "do-not-fragment", false, "Set the do not fragment bit. (IPv4 destinations)") cmd.Flags().BoolVar(&a.Config.SystemPingDoNotResolve, "do-not-resolve", false, "Do not try resolve the address returned") - cmd.Flags().StringVar(&a.Config.SystemPingProtocol, "protocol", "V4", "Layer3 protocol requested for the ping, V4 or V6") + cmd.Flags().StringVar(&a.Config.SystemPingProtocol, "protocol", "", "Layer3 protocol requested for the ping, V4 or V6, defaults to UNSPECIFIED") // cmd.Flags().VisitAll(func(flag *pflag.Flag) { a.Config.FileConfig.BindPFlag(fmt.Sprintf("%s-%s", cmd.Name(), flag.Name), flag) @@ -46,9 +46,8 @@ func (a *App) PreRunESystemPing(cmd *cobra.Command, args []string) error { if a.Config.SystemPingDestination == "" { return errors.New("flag --destination is required") } - a.Config.SystemPingProtocol = "IP" + strings.ToUpper(a.Config.SystemPingProtocol) - switch a.Config.SystemPingProtocol { - case "IPV4", "IPV6": + switch strings.ToUpper(a.Config.SystemPingProtocol) { + case "V4", "V6", "": default: return fmt.Errorf("unknown protocol %s", a.Config.SystemPingProtocol) } @@ -113,9 +112,10 @@ func (a *App) SystemPing(ctx context.Context, t *Target) error { Size: a.Config.SystemPingSize, DoNotFragment: a.Config.SystemPingDoNotFragment, DoNotResolve: a.Config.SystemPingDoNotResolve, - L3Protocol: types.L3Protocol(types.L3Protocol_value[a.Config.SystemPingProtocol]), + L3Protocol: getL3Protocol(a.Config.SystemPingProtocol), } a.Logger.Debugf("ping request:\n%s", prototext.Format(req)) + a.printMsg(t.Config.Name, req) stream, err := systemClient.Ping(ctx, req) if err != nil { a.Logger.Errorf("%q creating System Ping stream failed: %v", t.Config.Address, err) @@ -132,6 +132,7 @@ func (a *App) SystemPing(ctx context.Context, t *Target) error { return err } a.Logger.Debugf("ping response %s:\n%s", t.Config.Name, prototext.Format(rsp)) + a.printMsg(t.Config.Name, rsp) a.printPingResponse(t.Config.Name, rsp) } return nil @@ -215,3 +216,13 @@ func (a *App) printPingResponse(name string, rsp *system.PingResponse) { func formatDurationMS(d int64) string { return fmt.Sprintf("%.3f", float64(d)/float64(time.Millisecond)) } + +func getL3Protocol(s string) types.L3Protocol { + switch strings.ToUpper(s) { + case "V4": + return types.L3Protocol_IPV4 + case "V6": + return types.L3Protocol_IPV6 + } + return types.L3Protocol_UNSPECIFIED +} diff --git a/app/systemTraceRoute.go b/app/systemTraceRoute.go index 6f96890..1b107fa 100644 --- a/app/systemTraceRoute.go +++ b/app/systemTraceRoute.go @@ -11,7 +11,6 @@ import ( "time" "github.com/openconfig/gnoi/system" - "github.com/openconfig/gnoi/types" "github.com/spf13/cobra" "github.com/spf13/pflag" "google.golang.org/grpc/metadata" @@ -28,7 +27,7 @@ func (a *App) InitSystemTracerouteFlags(cmd *cobra.Command) { cmd.Flags().Int32Var(&a.Config.SystemTracerouteMaxTTL, "max-ttl", 0, "Maximum number of hops. (default=30)") cmd.Flags().BoolVar(&a.Config.SystemTracerouteDoNotFragment, "do-not-fragment", false, "Set the do not fragment bit. (IPv4 destinations)") cmd.Flags().BoolVar(&a.Config.SystemTracerouteDoNotResolve, "do-not-resolve", false, "Do not try resolve the address returned") - cmd.Flags().StringVarP(&a.Config.SystemTracerouteL3Protocol, "l3protocol", "3", "V4", "Layer3 protocol requested for the traceroute, IPv4 or IPv6") + cmd.Flags().StringVarP(&a.Config.SystemTracerouteL3Protocol, "l3protocol", "3", "", "Layer3 protocol requested for the traceroute, v4 or v6, defaults to UNSPECIFIED") cmd.Flags().StringVarP(&a.Config.SystemTracerouteL4Protocol, "l4protocol", "4", "ICMP", "Layer4 protocol requested for the traceroute, ICMP, UDP or TCP") // cmd.Flags().VisitAll(func(flag *pflag.Flag) { @@ -40,9 +39,8 @@ func (a *App) PreRunESystemTraceRoute(cmd *cobra.Command, args []string) error { if a.Config.SystemTracerouteDestination == "" { return errors.New("flag --destination is required") } - a.Config.SystemTracerouteL3Protocol = "IP" + strings.ToUpper(a.Config.SystemTracerouteL3Protocol) - switch a.Config.SystemTracerouteL3Protocol { - case "IPV4", "IPV6": + switch strings.ToUpper(a.Config.SystemTracerouteL3Protocol) { + case "V4", "V6", "": default: return fmt.Errorf("unknown L3 protocol %q", a.Config.SystemTracerouteL3Protocol) } @@ -112,10 +110,11 @@ func (a *App) SystemTraceRoute(ctx context.Context, t *Target) error { Wait: a.Config.SystemTracerouteWait.Nanoseconds(), DoNotFragment: a.Config.SystemTracerouteDoNotFragment, DoNotResolve: a.Config.SystemTracerouteDoNotResolve, - L3Protocol: types.L3Protocol(types.L3Protocol_value[a.Config.SystemTracerouteL3Protocol]), + L3Protocol: getL3Protocol(a.Config.SystemTracerouteL3Protocol), L4Protocol: system.TracerouteRequest_L4Protocol(system.TracerouteRequest_L4Protocol_value[a.Config.SystemTracerouteL4Protocol]), } a.Logger.Debug(prototext.Format(req)) + a.printMsg(t.Config.Name, req) stream, err := systemClient.Traceroute(ctx, req) if err != nil { a.Logger.Errorf("creating System Traceroute stream failed: %v", err) @@ -131,6 +130,8 @@ func (a *App) SystemTraceRoute(ctx context.Context, t *Target) error { a.Logger.Errorf("rcv System Traceroute stream failed: %v", err) return err } + a.Logger.Debugf("traceroute response %s:\n%s", t.Config.Name, prototext.Format(rsp)) + a.printMsg(t.Config.Name, req) a.printTracerouteResponse(t.Config.Name, rsp) } return nil