Skip to content

Commit

Permalink
Merge pull request #25 from karimra/qa
Browse files Browse the repository at this point in the history
QoL improvements
  • Loading branch information
karimra authored May 18, 2022
2 parents ac6453d + 42c52e2 commit 2252ad6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
7 changes: 4 additions & 3 deletions app/fileStat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 16 additions & 5 deletions app/systemPing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
}
13 changes: 7 additions & 6 deletions app/systemTraceRoute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 2252ad6

Please sign in to comment.