refactor for better usability

main
Ben Grewell 4 years ago
parent dcfd84cf13
commit 1d9e0f856c

@ -4,7 +4,7 @@
<list default="true" id="fc2840de-29dc-4fca-8e0e-a283562f60ca" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client.go" beforeDir="false" afterPath="$PROJECT_DIR$/client.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/reporter_linux.go" beforeDir="false" afterPath="$PROJECT_DIR$/reporter_linux.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/main.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server.go" beforeDir="false" afterPath="$PROJECT_DIR$/server.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/shared.go" beforeDir="false" afterPath="$PROJECT_DIR$/shared.go" afterDir="false" />
</list>

@ -21,9 +21,7 @@ func NewClient(host string) *Client {
streams := 1
c := &Client{
options: &ClientOptions{
SharedOptions: SharedOptions{
JSON: &json,
},
Proto: &proto,
TimeSec: &time,
Length: &length,
@ -37,48 +35,56 @@ func NewClient(host string) *Client {
}
type ClientOptions struct {
SharedOptions
Host *string
Proto *Protocol
Bandwidth *string
TimeSec *int
Bytes *string
BlockCount *string
Length *string
Streams *int
Reverse *bool
Window *string
MSS *int
NoDelay *bool
Version4 *bool
Version6 *bool
TOS *int
ZeroCopy *bool
OmitSec *int
Prefix *string
IncludeServer *bool
Port *int `json:"port" yaml:"port" xml:"port"`
Format *rune `json:"format" yaml:"format" xml:"format"`
Interval *int `json:"interval" yaml:"interval" xml:"interval"`
JSON *bool `json:"json" yaml:"json" xml:"json"`
LogFile *string `json:"log_file" yaml:"log_file" xml:"log_file"`
Host *string `json:"host" yaml:"host" xml:"host"`
Proto *Protocol `json:"proto" yaml:"proto" xml:"proto"`
Bandwidth *string `json:"bandwidth" yaml:"bandwidth" xml:"bandwidth"`
TimeSec *int `json:"time_sec" yaml:"time_sec" xml:"time_sec"`
Bytes *string `json:"bytes" yaml:"bytes" xml:"bytes"`
BlockCount *string `json:"block_count" yaml:"block_count" xml:"block_count"`
Length *string `json:"length" yaml:"length" xml:"length"`
Streams *int `json:"streams" yaml:"streams" xml:"streams"`
Reverse *bool `json:"reverse" yaml:"reverse" xml:"reverse"`
Window *string `json:"window" yaml:"window" xml:"window"`
MSS *int `json:"mss" yaml:"mss" xml:"mss"`
NoDelay *bool `json:"no_delay" yaml:"no_delay" xml:"no_delay"`
Version4 *bool `json:"version_4" yaml:"version_4" xml:"version_4"`
Version6 *bool `json:"version_6" yaml:"version_6" xml:"version_6"`
TOS *int `json:"tos" yaml:"tos" xml:"tos"`
ZeroCopy *bool `json:"zero_copy" yaml:"zero_copy" xml:"zero_copy"`
OmitSec *int `json:"omit_sec" yaml:"omit_sec" xml:"omit_sec"`
Prefix *string `json:"prefix" yaml:"prefix" xml:"prefix"`
IncludeServer *bool `json:"include_server" yaml:"include_server" xml:"include_server"`
}
type Client struct {
Id string
Running bool
Done chan bool
options *ClientOptions
exitCode *int
report *TestReport
outputStream io.ReadCloser
errorStream io.ReadCloser
cancel context.CancelFunc
mode TestMode
live bool
reportingChan chan *StreamIntervalReport
reportingFile string
Id string `json:"id" yaml:"id" xml:"id"`
Running bool `json:"running" yaml:"running" xml:"running"`
Done chan bool `json:"done" yaml:"done" xml:"done"`
options *ClientOptions `json:"options" yaml:"options" xml:"options"`
exitCode *int `json:"exit_code" yaml:"exit_code" xml:"exit_code"`
report *TestReport `json:"report" yaml:"report" xml:"report"`
outputStream io.ReadCloser `json:"output_stream" yaml:"output_stream" xml:"output_stream"`
errorStream io.ReadCloser `json:"error_stream" yaml:"error_stream" xml:"error_stream"`
cancel context.CancelFunc `json:"cancel" yaml:"cancel" xml:"cancel"`
mode TestMode `json:"mode" yaml:"mode" xml:"mode"`
live bool `json:"live" yaml:"live" xml:"live"`
reportingChan chan *StreamIntervalReport `json:"reporting_chan" yaml:"reporting_chan" xml:"reporting_chan"`
reportingFile string `json:"reporting_file" yaml:"reporting_file" xml:"reporting_file"`
}
func (c *Client) LoadOptionsJSON(jsonStr string) (err error) {
return json.Unmarshal([]byte(jsonStr), c.options)
}
func (c *Client) LoadOptions(options *ClientOptions) {
c.options = options
}
func (c *Client) commandString() (cmd string, err error) {
builder := strings.Builder{}
if c.options.Host == nil || *c.options.Host == "" {

@ -1,46 +1,46 @@
package main
import (
"fmt"
"github.com/BGrewell/go-conversions"
"github.com/BGrewell/go-iperf"
"time"
//"fmt"
//"github.com/BGrewell/go-conversions"
//"github.com/BGrewell/go-iperf"
//"time"
)
func main() {
s := iperf.NewServer()
c := iperf.NewClient("127.0.0.1")
includeServer := true
c.IncludeServer = &includeServer
fmt.Println(s.Id)
fmt.Println(c.Id)
err := s.Start()
if err != nil {
fmt.Println(err)
}
err = c.Start()
if err != nil {
fmt.Println(err)
}
for c.Running {
time.Sleep(1 * time.Second)
}
fmt.Println("stopping server")
s.Stop()
fmt.Printf("Client exit code: %d\n", *c.ExitCode)
fmt.Printf("Server exit code: %d\n", *s.ExitCode)
iperf.Cleanup()
if c.Report.Error != "" {
fmt.Println(c.Report.Error)
} else {
fmt.Printf("Recv Rate: %s\n", conversions.IntBitRateToString(int64(c.Report.End.SumReceived.BitsPerSecond)))
fmt.Printf("Send Rate: %s\n", conversions.IntBitRateToString(int64(c.Report.End.SumSent.BitsPerSecond)))
}
//s := iperf.NewServer()
//c := iperf.NewClient("127.0.0.1")
//includeServer := true
//c.IncludeServer = &includeServer
//fmt.Println(s.Id)
//fmt.Println(c.Id)
//
//err := s.Start()
//if err != nil {
// fmt.Println(err)
//}
//
//err = c.Start()
//if err != nil {
// fmt.Println(err)
//}
//
//for c.Running {
// time.Sleep(1 * time.Second)
//}
//
//fmt.Println("stopping server")
//s.Stop()
//
//fmt.Printf("Client exit code: %d\n", *c.ExitCode)
//fmt.Printf("Server exit code: %d\n", *s.ExitCode)
//iperf.Cleanup()
//if c.Report.Error != "" {
// fmt.Println(c.Report.Error)
//} else {
// fmt.Printf("Recv Rate: %s\n", conversions.IntBitRateToString(int64(c.Report.End.SumReceived.BitsPerSecond)))
// fmt.Printf("Send Rate: %s\n", conversions.IntBitRateToString(int64(c.Report.End.SumSent.BitsPerSecond)))
//}
}

@ -12,24 +12,26 @@ func NewServer() *Server {
defaultPort := 5201
defaultInterval := 1
s := &Server{
SharedOptions: SharedOptions{
Port: &defaultPort,
Interval: &defaultInterval,
},
}
s.Id = uuid.New().String()
return s
}
type Server struct {
SharedOptions
Id string
OneOff *bool
ExitCode *int
Running bool
outputStream io.ReadCloser
errorStream io.ReadCloser
cancel context.CancelFunc
Id string `json:"id" yaml:"id" xml:"id"`
OneOff *bool `json:"one_off" yaml:"one_off" xml:"one_off"`
ExitCode *int `json:"exit_code" yaml:"exit_code" xml:"exit_code"`
Port *int `json:"port" yaml:"port" xml:"port"`
Format *rune `json:"format" yaml:"format" xml:"format"`
Interval *int `json:"interval" yaml:"interval" xml:"interval"`
JSON *bool `json:"json" yaml:"json" xml:"json"`
LogFile *string `json:"log_file" yaml:"log_file" xml:"log_file"`
Running bool `json:"running" yaml:"running" xml:"running"`
outputStream io.ReadCloser `json:"output_stream" yaml:"output_stream" xml:"output_stream"`
errorStream io.ReadCloser `json:"error_stream" yaml:"error_stream" xml:"error_stream"`
cancel context.CancelFunc `json:"cancel" yaml:"cancel" xml:"cancel"`
}
func (s *Server) Start() (err error) {

@ -13,14 +13,6 @@ const (
MODE_LIVE TestMode = "live"
)
type SharedOptions struct {
Port *int
Format *rune
Interval *int
JSON *bool
LogFile *string
}
type DebugScanner struct {
Silent bool
}

Loading…
Cancel
Save