refactor for better usability
This commit is contained in:
2
.idea/workspace.xml
generated
2
.idea/workspace.xml
generated
@@ -4,7 +4,7 @@
|
|||||||
<list default="true" id="fc2840de-29dc-4fca-8e0e-a283562f60ca" name="Default Changelist" comment="">
|
<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$/.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$/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$/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" />
|
<change beforePath="$PROJECT_DIR$/shared.go" beforeDir="false" afterPath="$PROJECT_DIR$/shared.go" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
|
|||||||
78
client.go
78
client.go
@@ -21,9 +21,7 @@ func NewClient(host string) *Client {
|
|||||||
streams := 1
|
streams := 1
|
||||||
c := &Client{
|
c := &Client{
|
||||||
options: &ClientOptions{
|
options: &ClientOptions{
|
||||||
SharedOptions: SharedOptions{
|
JSON: &json,
|
||||||
JSON: &json,
|
|
||||||
},
|
|
||||||
Proto: &proto,
|
Proto: &proto,
|
||||||
TimeSec: &time,
|
TimeSec: &time,
|
||||||
Length: &length,
|
Length: &length,
|
||||||
@@ -37,48 +35,56 @@ func NewClient(host string) *Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ClientOptions struct {
|
type ClientOptions struct {
|
||||||
SharedOptions
|
Port *int `json:"port" yaml:"port" xml:"port"`
|
||||||
Host *string
|
Format *rune `json:"format" yaml:"format" xml:"format"`
|
||||||
Proto *Protocol
|
Interval *int `json:"interval" yaml:"interval" xml:"interval"`
|
||||||
Bandwidth *string
|
JSON *bool `json:"json" yaml:"json" xml:"json"`
|
||||||
TimeSec *int
|
LogFile *string `json:"log_file" yaml:"log_file" xml:"log_file"`
|
||||||
Bytes *string
|
Host *string `json:"host" yaml:"host" xml:"host"`
|
||||||
BlockCount *string
|
Proto *Protocol `json:"proto" yaml:"proto" xml:"proto"`
|
||||||
Length *string
|
Bandwidth *string `json:"bandwidth" yaml:"bandwidth" xml:"bandwidth"`
|
||||||
Streams *int
|
TimeSec *int `json:"time_sec" yaml:"time_sec" xml:"time_sec"`
|
||||||
Reverse *bool
|
Bytes *string `json:"bytes" yaml:"bytes" xml:"bytes"`
|
||||||
Window *string
|
BlockCount *string `json:"block_count" yaml:"block_count" xml:"block_count"`
|
||||||
MSS *int
|
Length *string `json:"length" yaml:"length" xml:"length"`
|
||||||
NoDelay *bool
|
Streams *int `json:"streams" yaml:"streams" xml:"streams"`
|
||||||
Version4 *bool
|
Reverse *bool `json:"reverse" yaml:"reverse" xml:"reverse"`
|
||||||
Version6 *bool
|
Window *string `json:"window" yaml:"window" xml:"window"`
|
||||||
TOS *int
|
MSS *int `json:"mss" yaml:"mss" xml:"mss"`
|
||||||
ZeroCopy *bool
|
NoDelay *bool `json:"no_delay" yaml:"no_delay" xml:"no_delay"`
|
||||||
OmitSec *int
|
Version4 *bool `json:"version_4" yaml:"version_4" xml:"version_4"`
|
||||||
Prefix *string
|
Version6 *bool `json:"version_6" yaml:"version_6" xml:"version_6"`
|
||||||
IncludeServer *bool
|
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 {
|
type Client struct {
|
||||||
Id string
|
Id string `json:"id" yaml:"id" xml:"id"`
|
||||||
Running bool
|
Running bool `json:"running" yaml:"running" xml:"running"`
|
||||||
Done chan bool
|
Done chan bool `json:"done" yaml:"done" xml:"done"`
|
||||||
options *ClientOptions
|
options *ClientOptions `json:"options" yaml:"options" xml:"options"`
|
||||||
exitCode *int
|
exitCode *int `json:"exit_code" yaml:"exit_code" xml:"exit_code"`
|
||||||
report *TestReport
|
report *TestReport `json:"report" yaml:"report" xml:"report"`
|
||||||
outputStream io.ReadCloser
|
outputStream io.ReadCloser `json:"output_stream" yaml:"output_stream" xml:"output_stream"`
|
||||||
errorStream io.ReadCloser
|
errorStream io.ReadCloser `json:"error_stream" yaml:"error_stream" xml:"error_stream"`
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc `json:"cancel" yaml:"cancel" xml:"cancel"`
|
||||||
mode TestMode
|
mode TestMode `json:"mode" yaml:"mode" xml:"mode"`
|
||||||
live bool
|
live bool `json:"live" yaml:"live" xml:"live"`
|
||||||
reportingChan chan *StreamIntervalReport
|
reportingChan chan *StreamIntervalReport `json:"reporting_chan" yaml:"reporting_chan" xml:"reporting_chan"`
|
||||||
reportingFile string
|
reportingFile string `json:"reporting_file" yaml:"reporting_file" xml:"reporting_file"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) LoadOptionsJSON(jsonStr string) (err error) {
|
func (c *Client) LoadOptionsJSON(jsonStr string) (err error) {
|
||||||
return json.Unmarshal([]byte(jsonStr), c.options)
|
return json.Unmarshal([]byte(jsonStr), c.options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) LoadOptions(options *ClientOptions) {
|
||||||
|
c.options = options
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) commandString() (cmd string, err error) {
|
func (c *Client) commandString() (cmd string, err error) {
|
||||||
builder := strings.Builder{}
|
builder := strings.Builder{}
|
||||||
if c.options.Host == nil || *c.options.Host == "" {
|
if c.options.Host == nil || *c.options.Host == "" {
|
||||||
|
|||||||
74
cmd/main.go
74
cmd/main.go
@@ -1,46 +1,46 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
//"fmt"
|
||||||
"github.com/BGrewell/go-conversions"
|
//"github.com/BGrewell/go-conversions"
|
||||||
"github.com/BGrewell/go-iperf"
|
//"github.com/BGrewell/go-iperf"
|
||||||
"time"
|
//"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
s := iperf.NewServer()
|
//s := iperf.NewServer()
|
||||||
c := iperf.NewClient("127.0.0.1")
|
//c := iperf.NewClient("127.0.0.1")
|
||||||
includeServer := true
|
//includeServer := true
|
||||||
c.IncludeServer = &includeServer
|
//c.IncludeServer = &includeServer
|
||||||
fmt.Println(s.Id)
|
//fmt.Println(s.Id)
|
||||||
fmt.Println(c.Id)
|
//fmt.Println(c.Id)
|
||||||
|
//
|
||||||
err := s.Start()
|
//err := s.Start()
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
fmt.Println(err)
|
// fmt.Println(err)
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
err = c.Start()
|
//err = c.Start()
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
fmt.Println(err)
|
// fmt.Println(err)
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
for c.Running {
|
//for c.Running {
|
||||||
time.Sleep(1 * time.Second)
|
// time.Sleep(1 * time.Second)
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
fmt.Println("stopping server")
|
//fmt.Println("stopping server")
|
||||||
s.Stop()
|
//s.Stop()
|
||||||
|
//
|
||||||
fmt.Printf("Client exit code: %d\n", *c.ExitCode)
|
//fmt.Printf("Client exit code: %d\n", *c.ExitCode)
|
||||||
fmt.Printf("Server exit code: %d\n", *s.ExitCode)
|
//fmt.Printf("Server exit code: %d\n", *s.ExitCode)
|
||||||
iperf.Cleanup()
|
//iperf.Cleanup()
|
||||||
if c.Report.Error != "" {
|
//if c.Report.Error != "" {
|
||||||
fmt.Println(c.Report.Error)
|
// fmt.Println(c.Report.Error)
|
||||||
} else {
|
//} else {
|
||||||
fmt.Printf("Recv Rate: %s\n", conversions.IntBitRateToString(int64(c.Report.End.SumReceived.BitsPerSecond)))
|
// 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)))
|
// fmt.Printf("Send Rate: %s\n", conversions.IntBitRateToString(int64(c.Report.End.SumSent.BitsPerSecond)))
|
||||||
}
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
26
server.go
26
server.go
@@ -12,24 +12,26 @@ func NewServer() *Server {
|
|||||||
defaultPort := 5201
|
defaultPort := 5201
|
||||||
defaultInterval := 1
|
defaultInterval := 1
|
||||||
s := &Server{
|
s := &Server{
|
||||||
SharedOptions: SharedOptions{
|
Port: &defaultPort,
|
||||||
Port: &defaultPort,
|
Interval: &defaultInterval,
|
||||||
Interval: &defaultInterval,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
s.Id = uuid.New().String()
|
s.Id = uuid.New().String()
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
SharedOptions
|
Id string `json:"id" yaml:"id" xml:"id"`
|
||||||
Id string
|
OneOff *bool `json:"one_off" yaml:"one_off" xml:"one_off"`
|
||||||
OneOff *bool
|
ExitCode *int `json:"exit_code" yaml:"exit_code" xml:"exit_code"`
|
||||||
ExitCode *int
|
Port *int `json:"port" yaml:"port" xml:"port"`
|
||||||
Running bool
|
Format *rune `json:"format" yaml:"format" xml:"format"`
|
||||||
outputStream io.ReadCloser
|
Interval *int `json:"interval" yaml:"interval" xml:"interval"`
|
||||||
errorStream io.ReadCloser
|
JSON *bool `json:"json" yaml:"json" xml:"json"`
|
||||||
cancel context.CancelFunc
|
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) {
|
func (s *Server) Start() (err error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user