diff --git a/README.md b/README.md index f2699eb..50d7577 100644 --- a/README.md +++ b/README.md @@ -271,6 +271,9 @@ In this mode, Ethr client can only talk to an Ethr server. -w Use specified number of iterations for warmup. Default: 1 + -T + Use the given title in log files for logging results. + Default: ``` ### External Mode Parameters ``` @@ -317,6 +320,9 @@ few types of measurements, such as Ping, Connections/s and TraceRoute. -w Use specified number of iterations for warmup. Default: 1 + -T + Use the given title in log files for logging results. + Default: ``` # Status diff --git a/client.go b/client.go index 2bb5657..f0dee44 100644 --- a/client.go +++ b/client.go @@ -69,8 +69,8 @@ func runDurationTimer(d time.Duration, toStop chan int) { }() } -func initClient() { - initClientUI() +func initClient(title string) { + initClientUI(title) } func handshakeWithServer(test *ethrTest, conn net.Conn) (err error) { @@ -117,8 +117,8 @@ func getServerIPandPort(server string) (string, string, string, error) { return hostName, hostIP, port, err } -func runClient(testID EthrTestID, clientParam EthrClientParam, server string) { - initClient() +func runClient(testID EthrTestID, title string, clientParam EthrClientParam, server string) { + initClient(title) hostName, hostIP, port, err := getServerIPandPort(server) if err != nil { return diff --git a/clientui.go b/clientui.go index ecc791a..5232258 100644 --- a/clientui.go +++ b/clientui.go @@ -12,11 +12,16 @@ import ( ) type clientUI struct { + title string } func (u *clientUI) fini() { } +func (u *clientUI) getTitle() string { + return u.title +} + func (u *clientUI) printMsg(format string, a ...interface{}) { s := fmt.Sprintf(format, a...) logInfo(s) @@ -74,8 +79,8 @@ func (u *clientUI) emitStats(netStats ethrNetStat) { func (u *clientUI) printTestResults(s []string) { } -func initClientUI() { - cli := &clientUI{} +func initClientUI(title string) { + cli := &clientUI{title} ui = cli } diff --git a/ethr.go b/ethr.go index c5ba521..8c201bc 100644 --- a/ethr.go +++ b/ethr.go @@ -69,6 +69,7 @@ func main() { reverse := flag.Bool("r", false, "") testTypePtr := flag.String("t", "", "") tos := flag.Int("tos", 0, "") + title := flag.String("T", "", "") thCount := flag.Int("n", 1, "") wc := flag.Int("w", 1, "") xClientDest := flag.String("x", "", "") @@ -121,6 +122,9 @@ func main() { if *wc != 1 { printServerModeArgError("wc") } + if *title != "" { + printServerModeArgError("T") + } } else if *clientDest != "" || *xClientDest != "" { if *clientDest != "" && *xClientDest != "" { printUsageError("Invalid argument, both \"-c\" and \"-x\" cannot be specified at the same time.") @@ -244,7 +248,7 @@ func main() { validateClientParams(testId, clientParam) rServer := destination - runClient(testId, clientParam, rServer) + runClient(testId, *title, clientParam, rServer) } } @@ -421,6 +425,7 @@ func ethrUsage() { printTestType() printToSUsage() printWarmupUsage() + printTitleUsage() fmt.Println("\nMode: External") fmt.Println("================================================================================") @@ -436,6 +441,7 @@ func ethrUsage() { printExtTestType() printToSUsage() printWarmupUsage() + printTitleUsage() } func printFlagUsage(flag, info string, helptext ...string) { @@ -575,3 +581,9 @@ func printIPUsage() { "This must be a valid IPv4 or IPv6 address.", "Default: - Any IP") } + +func printTitleUsage() { + printFlagUsage("T", "", + "Use the given title in log files for logging results.", + "Default: ") +} diff --git a/log.go b/log.go index 380e3d0..9774b23 100644 --- a/log.go +++ b/log.go @@ -24,12 +24,14 @@ const ( type logMessage struct { Time string + Title string Type string Message string } type logLatencyData struct { Time string + Title string Type string RemoteAddr string Protocol string @@ -46,6 +48,7 @@ type logLatencyData struct { type logTestResults struct { Time string + Title string Type string RemoteAddr string Protocol string @@ -89,6 +92,7 @@ func logMsg(prefix, msg string) { if loggingActive { logData := logMessage{} logData.Time = time.Now().UTC().Format(time.RFC3339) + logData.Title = ui.getTitle() logData.Type = prefix logData.Message = msg logJSON, _ := json.Marshal(logData) @@ -112,6 +116,7 @@ func logResults(s []string) { if loggingActive { logData := logTestResults{} logData.Time = time.Now().UTC().Format(time.RFC3339) + logData.Title = ui.getTitle() logData.Type = "TestResult" logData.RemoteAddr = s[0] logData.Protocol = s[1] @@ -128,6 +133,7 @@ func logLatency(remoteIP, proto string, avg, min, p50, p90, p95, p99, p999, p999 if loggingActive { logData := logLatencyData{} logData.Time = time.Now().UTC().Format(time.RFC3339) + logData.Title = ui.getTitle() logData.Type = "LatencyResult" logData.RemoteAddr = remoteIP logData.Protocol = proto diff --git a/server.go b/server.go index e34e3d3..b17c1a1 100644 --- a/server.go +++ b/server.go @@ -123,8 +123,8 @@ func srvrHandleNewTcpConn(conn net.Conn) { safeDeleteTest(test) }() - // Always increment CPS count and then check if the test is Bandwidth - // etc. and handle those cases as well. + // Always increment CPS count and then check if the test is Bandwidth etc. and handle + // those cases as well. atomic.AddUint64(&test.testResult.cps, 1) testID, clientParam, err := handshakeWithClient(test, conn) diff --git a/serverui.go b/serverui.go index 757c827..43c9a79 100644 --- a/serverui.go +++ b/serverui.go @@ -141,6 +141,10 @@ func (u *serverTui) fini() { tm.Close() } +func (u *serverTui) getTitle() string { + return "" +} + func (u *serverTui) printMsg(format string, a ...interface{}) { s := fmt.Sprintf(format, a...) logInfo(s) @@ -300,6 +304,10 @@ func initServerCli() { func (u *serverCli) fini() { } +func (u *serverCli) getTitle() string { + return "" +} + func (u *serverCli) printMsg(format string, a ...interface{}) { s := fmt.Sprintf(format, a...) fmt.Println(s) diff --git a/session.go b/session.go index 276f22a..d986365 100644 --- a/session.go +++ b/session.go @@ -8,7 +8,9 @@ package main import ( "bytes" "container/list" + "encoding/binary" "encoding/gob" + "io" "net" "os" "sync" @@ -319,14 +321,24 @@ func createAckMsg() (ethrMsg *EthrMsg) { func recvSessionMsg(conn net.Conn) (ethrMsg *EthrMsg) { ethrMsg = &EthrMsg{} ethrMsg.Type = EthrInv - // TODO: Assuming max ethr message size as 4096 sent over gob. - msgBytes := make([]byte, 4096) - n, err := conn.Read(msgBytes) + msgBytes := make([]byte, 4) + _, err := io.ReadFull(conn, msgBytes) if err != nil { ui.printDbg("Error receiving message on control channel. Error: %v", err) return } - ethrMsg = decodeMsg(msgBytes[:n]) + msgSize := binary.BigEndian.Uint32(msgBytes[0:]) + // TODO: Assuming max ethr message size as 16K sent over gob. + if msgSize > 16384 { + return + } + msgBytes = make([]byte, msgSize) + _, err = io.ReadFull(conn, msgBytes) + if err != nil { + ui.printDbg("Error receiving message on control channel. Error: %v", err) + return + } + ethrMsg = decodeMsg(msgBytes) return } @@ -341,6 +353,13 @@ func sendSessionMsg(conn net.Conn, ethrMsg *EthrMsg) (err error) { ui.printDbg("Error sending message on control channel. Message: %v, Error: %v", ethrMsg, err) return } + msgSize := len(msgBytes) + tempBuf := make([]byte, 4) + binary.BigEndian.PutUint32(tempBuf[0:], uint32(msgSize)) + _, err = conn.Write(tempBuf) + if err != nil { + ui.printDbg("Error sending message on control channel. Message: %v, Error: %v", ethrMsg, err) + } _, err = conn.Write(msgBytes) if err != nil { ui.printDbg("Error sending message on control channel. Message: %v, Error: %v", ethrMsg, err) diff --git a/ui.go b/ui.go index 0d8192f..57df4b7 100644 --- a/ui.go +++ b/ui.go @@ -211,6 +211,7 @@ func printDivider2() { type ethrUI interface { fini() + getTitle() string printMsg(format string, a ...interface{}) printErr(format string, a ...interface{}) printDbg(format string, a ...interface{})