From e184c0808b980e81ee87791264a7fa030f52e962 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Wed, 11 May 2022 10:25:25 -0400 Subject: Refactor RPM calculations Refactor RPM calculations to make them more reusble. Enable (perhaps temporarily) probe calculations on the saturated connections. This change is to check whether this makes our RPM calculations match the ones generated by Apple's native client. --- lgc/lgc.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lgc/lgc.go') diff --git a/lgc/lgc.go b/lgc/lgc.go index a32bb36..1f6332d 100644 --- a/lgc/lgc.go +++ b/lgc/lgc.go @@ -126,6 +126,10 @@ func (lgd *LoadGeneratingConnectionDownload) SetGotConnTimeInfo( now time.Time, gotConnInfo httptrace.GotConnInfo, ) { + if gotConnInfo.Reused { + fmt.Printf("Unexpectedly reusing a connection!\n") + panic(!gotConnInfo.Reused) + } lgd.stats.GetConnectionDoneTime = now lgd.stats.ConnInfo = gotConnInfo if debug.IsDebug(lgd.debug) { -- cgit v1.2.3 From 140c64907408d1cf998f1616d6aec4bc2904ce95 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Fri, 13 May 2022 23:49:56 -0400 Subject: [Improvement] Increase granularity of transfer rate calculation Previously the code relied on the fact that the go runtime would wake up the saturation go function at exactly 1 second intervals, as we asked. With this change, the code takes into account any minor fluctuations in that time when calculating the throughput in an interval. I hope that this change is an improvement. --- lgc/lgc.go | 70 +++++++++++++++++++++++++++++++++++++++----------------------- rpm/rpm.go | 16 +++++--------- 2 files changed, 49 insertions(+), 37 deletions(-) (limited to 'lgc/lgc.go') diff --git a/lgc/lgc.go b/lgc/lgc.go index 1f6332d..59b623d 100644 --- a/lgc/lgc.go +++ b/lgc/lgc.go @@ -34,22 +34,25 @@ import ( type LoadGeneratingConnection interface { Start(context.Context, debug.DebugLevel) bool - Transferred() uint64 + TransferredInInterval() (uint64, time.Duration) Client() *http.Client IsValid() bool ClientId() uint64 } type LoadGeneratingConnectionDownload struct { - Path string - downloaded uint64 - client *http.Client - debug debug.DebugLevel - valid bool - KeyLogger io.Writer - clientId uint64 - tracer *httptrace.ClientTrace - stats stats.TraceStats + Path string + downloaded uint64 + downloadStartTime time.Time + lastDownloaded uint64 + lastIntervalEnd int64 + client *http.Client + debug debug.DebugLevel + valid bool + KeyLogger io.Writer + clientId uint64 + tracer *httptrace.ClientTrace + stats stats.TraceStats } func (lgd *LoadGeneratingConnectionDownload) SetDnsStartTimeInfo( @@ -204,12 +207,15 @@ func (lgd *LoadGeneratingConnectionDownload) ClientId() uint64 { return lgd.clientId } -func (lgd *LoadGeneratingConnectionDownload) Transferred() uint64 { - transferred := atomic.LoadUint64(&lgd.downloaded) +func (lgd *LoadGeneratingConnectionDownload) TransferredInInterval() (uint64, time.Duration) { + transferred := atomic.SwapUint64(&lgd.downloaded, 0) + newIntervalEnd := (time.Now().Sub(lgd.downloadStartTime)).Nanoseconds() + previousIntervalEnd := atomic.SwapInt64(&lgd.lastIntervalEnd, newIntervalEnd) + intervalLength := time.Duration(newIntervalEnd - previousIntervalEnd) if debug.IsDebug(lgd.debug) { - fmt.Printf("download: Transferred: %v\n", transferred) + fmt.Printf("download: Transferred: %v bytes in %v.\n", transferred, intervalLength) } - return transferred + return transferred, intervalLength } func (lgd *LoadGeneratingConnectionDownload) Client() *http.Client { @@ -291,6 +297,9 @@ func (lbd *LoadGeneratingConnectionDownload) doDownload(ctx context.Context) { return } + lbd.downloadStartTime = time.Now() + lbd.lastIntervalEnd = 0 + if get, err = lbd.client.Do(request); err != nil { lbd.valid = false return @@ -304,25 +313,31 @@ func (lbd *LoadGeneratingConnectionDownload) doDownload(ctx context.Context) { } type LoadGeneratingConnectionUpload struct { - Path string - uploaded uint64 - client *http.Client - debug debug.DebugLevel - valid bool - KeyLogger io.Writer - clientId uint64 + Path string + uploaded uint64 + uploadStartTime time.Time + lastUploaded uint64 + lastIntervalEnd int64 + client *http.Client + debug debug.DebugLevel + valid bool + KeyLogger io.Writer + clientId uint64 } func (lgu *LoadGeneratingConnectionUpload) ClientId() uint64 { return lgu.clientId } -func (lgu *LoadGeneratingConnectionUpload) Transferred() uint64 { - transferred := atomic.LoadUint64(&lgu.uploaded) - if debug.IsDebug(lgu.debug) { - fmt.Printf("upload: Transferred: %v\n", transferred) +func (lgd *LoadGeneratingConnectionUpload) TransferredInInterval() (uint64, time.Duration) { + transferred := atomic.SwapUint64(&lgd.uploaded, 0) + newIntervalEnd := (time.Now().Sub(lgd.uploadStartTime)).Nanoseconds() + previousIntervalEnd := atomic.SwapInt64(&lgd.lastIntervalEnd, newIntervalEnd) + intervalLength := time.Duration(newIntervalEnd - previousIntervalEnd) + if debug.IsDebug(lgd.debug) { + fmt.Printf("upload: Transferred: %v bytes in %v.\n", transferred, intervalLength) } - return transferred + return transferred, intervalLength } func (lgu *LoadGeneratingConnectionUpload) Client() *http.Client { @@ -355,6 +370,9 @@ func (lgu *LoadGeneratingConnectionUpload) doUpload(ctx context.Context) bool { var resp *http.Response = nil var err error + lgu.uploadStartTime = time.Now() + lgu.lastIntervalEnd = 0 + if resp, err = lgu.client.Post(lgu.Path, "application/octet-stream", s); err != nil { lgu.valid = false return false diff --git a/rpm/rpm.go b/rpm/rpm.go index 8956509..3425566 100644 --- a/rpm/rpm.go +++ b/rpm/rpm.go @@ -23,13 +23,11 @@ func addFlows( ctx context.Context, toAdd uint64, lgcs *[]lgc.LoadGeneratingConnection, - lgcsPreviousTransferred *[]uint64, lgcGenerator func() lgc.LoadGeneratingConnection, debug debug.DebugLevel, ) { for i := uint64(0); i < toAdd; i++ { *lgcs = append(*lgcs, lgcGenerator()) - *lgcsPreviousTransferred = append(*lgcsPreviousTransferred, 0) if !(*lgcs)[len(*lgcs)-1].Start(ctx, debug) { fmt.Printf( "Error starting lgc with id %d!\n", @@ -55,13 +53,11 @@ func Saturate( go func() { lgcs := make([]lgc.LoadGeneratingConnection, 0) - lgcsPreviousTransferred := make([]uint64, 0) addFlows( saturationCtx, constants.StartingNumberOfLoadGeneratingConnections, &lgcs, - &lgcsPreviousTransferred, lgcGenerator, debugging.Level, ) @@ -116,7 +112,7 @@ func Saturate( // Compute "instantaneous aggregate" goodput which is the number of // bytes transferred within the last second. - totalTransfer := uint64(0) + var totalTransfer float64 = 0 allInvalid := true for i := range lgcs { if !lgcs[i].IsValid() { @@ -130,11 +126,10 @@ func Saturate( continue } allInvalid = false - previousTransferred := lgcsPreviousTransferred[i] - currentTransferred := lgcs[i].Transferred() - instantaneousTransferred := currentTransferred - previousTransferred + currentTransferred, currentInterval := lgcs[i].TransferredInInterval() + // normalize to a second-long interval! + instantaneousTransferred := float64(currentTransferred) / float64(currentInterval.Seconds()) totalTransfer += instantaneousTransferred - lgcsPreviousTransferred[i] = currentTransferred } // For some reason, all the lgcs are invalid. This likely means that @@ -208,7 +203,6 @@ func Saturate( saturationCtx, constants.AdditiveNumberOfLoadGeneratingConnections, &lgcs, - &lgcsPreviousTransferred, lgcGenerator, debugging.Level, ) @@ -234,7 +228,7 @@ func Saturate( if debug.IsDebug(debugging.Level) { fmt.Printf("%v: New flows to add to try to increase our saturation!\n", debugging) } - addFlows(saturationCtx, constants.AdditiveNumberOfLoadGeneratingConnections, &lgcs, &lgcsPreviousTransferred, lgcGenerator, debugging.Level) + addFlows(saturationCtx, constants.AdditiveNumberOfLoadGeneratingConnections, &lgcs, lgcGenerator, debugging.Level) previousFlowIncreaseInterval = currentInterval } } -- cgit v1.2.3 From d38bea818a90a0ca2bfc17e96c00b9896e2c61ca Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Sat, 4 Jun 2022 04:02:07 -0400 Subject: [Bugfix #21] Bad alignment of elements in structs accessed atomically Fixes #21 --- lgc/lgc.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lgc/lgc.go') diff --git a/lgc/lgc.go b/lgc/lgc.go index 59b623d..13f2c06 100644 --- a/lgc/lgc.go +++ b/lgc/lgc.go @@ -40,12 +40,14 @@ type LoadGeneratingConnection interface { ClientId() uint64 } +// TODO: All 64-bit fields that are accessed atomically must +// appear at the top of this struct. type LoadGeneratingConnectionDownload struct { - Path string downloaded uint64 + lastIntervalEnd int64 + Path string downloadStartTime time.Time lastDownloaded uint64 - lastIntervalEnd int64 client *http.Client debug debug.DebugLevel valid bool @@ -312,12 +314,14 @@ func (lbd *LoadGeneratingConnectionDownload) doDownload(ctx context.Context) { } } +// TODO: All 64-bit fields that are accessed atomically must +// appear at the top of this struct. type LoadGeneratingConnectionUpload struct { - Path string uploaded uint64 + lastIntervalEnd int64 + Path string uploadStartTime time.Time lastUploaded uint64 - lastIntervalEnd int64 client *http.Client debug debug.DebugLevel valid bool -- cgit v1.2.3 From de7a7bf994a020049eca89098aab9d13ff81f361 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Sat, 4 Jun 2022 05:49:07 -0400 Subject: [Feature] Access TCP_INFO about underlying TCP connections This will only work on *nix systems. Code that displays information in this PR is only exemplary -- I am sure that there are better places in the code to display it! --- go.mod | 5 ++++- go.sum | 2 ++ lgc/lgc.go | 9 +++++++++ networkQuality.go | 19 ++++++++++++++++++ utilities/utilities.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) (limited to 'lgc/lgc.go') diff --git a/go.mod b/go.mod index d60ef0a..39b9252 100644 --- a/go.mod +++ b/go.mod @@ -4,4 +4,7 @@ go 1.18 require golang.org/x/net v0.0.0-20220225172249-27dd8689420f -require golang.org/x/text v0.3.7 // indirect +require ( + golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect + golang.org/x/text v0.3.7 // indirect +) diff --git a/go.sum b/go.sum index 4832ce9..ce291cf 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,6 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= diff --git a/lgc/lgc.go b/lgc/lgc.go index 13f2c06..5b35fd1 100644 --- a/lgc/lgc.go +++ b/lgc/lgc.go @@ -38,6 +38,7 @@ type LoadGeneratingConnection interface { Client() *http.Client IsValid() bool ClientId() uint64 + Stats() *stats.TraceStats } // TODO: All 64-bit fields that are accessed atomically must @@ -284,6 +285,10 @@ func (lbd *LoadGeneratingConnectionDownload) IsValid() bool { return lbd.valid } +func (lbd *LoadGeneratingConnectionDownload) Stats() *stats.TraceStats { + return &lbd.stats +} + func (lbd *LoadGeneratingConnectionDownload) doDownload(ctx context.Context) { var request *http.Request = nil var get *http.Response = nil @@ -420,3 +425,7 @@ func (lgu *LoadGeneratingConnectionUpload) Start( go lgu.doUpload(ctx) return true } + +func (lbd *LoadGeneratingConnectionUpload) Stats() *stats.TraceStats { + return nil +} diff --git a/networkQuality.go b/networkQuality.go index ab9517e..7593714 100644 --- a/networkQuality.go +++ b/networkQuality.go @@ -21,6 +21,7 @@ import ( "fmt" _ "io" _ "log" + "net" "net/http" "os" "runtime/pprof" @@ -323,6 +324,24 @@ func main() { continue } + if *debugCliFlag { + // Note: This code is just an example of how to use utilities.GetTCPInfo. + rawConn := downloadSaturation.LGCs[randomLGCsIndex].Stats().ConnInfo.Conn + tlsConn, ok := rawConn.(*tls.Conn) + if !ok { + fmt.Printf("OOPS: Could not get the TCP info for the connection (not a TLS connection)!\n") + } + tcpConn, ok := tlsConn.NetConn().(*net.TCPConn) + if !ok { + fmt.Printf("OOPS: Could not get the TCP info for the connection (not a TCP connection)!\n") + } + if info, err := utilities.GetTCPInfo(tcpConn); err != nil { + fmt.Printf("OOPS: Could not get the TCP info for the connection: %v!\n", err) + } else { + utilities.PrintTCPInfo(info) + } + } + unsaturatedMeasurementTransport := http2.Transport{} unsaturatedMeasurementTransport.TLSClientConfig = &tls.Config{} if sslKeyFileConcurrentWriter != nil { diff --git a/utilities/utilities.go b/utilities/utilities.go index a143d31..e4c8a0d 100644 --- a/utilities/utilities.go +++ b/utilities/utilities.go @@ -18,10 +18,13 @@ import ( "fmt" "math" "math/rand" + "net" "os" "reflect" "sync/atomic" "time" + + "golang.org/x/sys/unix" ) func IsInterfaceNil(ifc interface{}) bool { @@ -122,3 +125,54 @@ func (optional Optional[S]) String() string { func RandBetween(max int) int { return rand.New(rand.NewSource(int64(time.Now().Nanosecond()))).Int() % max } + +func GetTCPInfo(connection net.Conn) (*unix.TCPInfo, error) { + tcpConn, ok := connection.(*net.TCPConn) + if !ok { + return nil, fmt.Errorf("connection is not a net.TCPConn") + } + rawConn, err := tcpConn.SyscallConn() + if err != nil { + return nil, err + } + + var info *unix.TCPInfo = nil + rawConn.Control(func(fd uintptr) { + info, err = unix.GetsockoptTCPInfo(int(fd), unix.SOL_TCP, unix.TCP_INFO) + }) + return info, err +} + +func PrintTCPInfo(info *unix.TCPInfo) { + fmt.Printf("TCPInfo: \n") + fmt.Printf(" State: %v\n", info.State) + fmt.Printf(" Ca_state: %v\n", info.Ca_state) + fmt.Printf(" Retransmits: %v\n", info.Retransmits) + fmt.Printf(" Probes: %v\n", info.Probes) + fmt.Printf(" Backoff: %v\n", info.Backoff) + fmt.Printf(" Options: %v\n", info.Options) + fmt.Printf(" Rto: %v\n", info.Rto) + fmt.Printf(" Ato: %v\n", info.Ato) + fmt.Printf(" Snd_mss: %v\n", info.Snd_mss) + fmt.Printf(" Rcv_mss: %v\n", info.Rcv_mss) + fmt.Printf(" Unacked: %v\n", info.Unacked) + fmt.Printf(" Sacked: %v\n", info.Sacked) + fmt.Printf(" Lost: %v\n", info.Lost) + fmt.Printf(" Retrans: %v\n", info.Retrans) + fmt.Printf(" Fackets: %v\n", info.Fackets) + fmt.Printf(" Last_data_sent: %v\n", info.Last_data_sent) + fmt.Printf(" Last_ack_sent: %v\n", info.Last_ack_sent) + fmt.Printf(" Last_data_recv: %v\n", info.Last_data_recv) + fmt.Printf(" Last_ack_recv: %v\n", info.Last_ack_recv) + fmt.Printf(" Pmtu: %v\n", info.Pmtu) + fmt.Printf(" Rcv_ssthresh: %v\n", info.Rcv_ssthresh) + fmt.Printf(" Rtt: %v\n", info.Rtt) + fmt.Printf(" Rttvar: %v\n", info.Rttvar) + fmt.Printf(" Snd_ssthresh: %v\n", info.Snd_ssthresh) + fmt.Printf(" Snd_cwnd: %v\n", info.Snd_cwnd) + fmt.Printf(" Advmss: %v\n", info.Advmss) + fmt.Printf(" Reordering: %v\n", info.Reordering) + fmt.Printf(" Rcv_rtt: %v\n", info.Rcv_rtt) + fmt.Printf(" Rcv_space: %v\n", info.Rcv_space) + fmt.Printf(" Total_retrans: %v\n", info.Total_retrans) +} -- cgit v1.2.3 From 9be87fa5ec89c9e393c9c93b3cb36668c71593d6 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Sat, 4 Jun 2022 21:24:19 -0400 Subject: [Feature] Add conditional compilation support for GetTCPInfo Now there is functionality for conditionally supporting GetTCPInfo depending on the platform. If the platform supports it, then the client can call utilities.GetTCPInfo. In the case that the platform does not support the GetTCPInfo function call, the result is an error of the type `NotImplemented`. --- lgc/lgc.go | 31 ++++++++++++----------- networkQuality.go | 7 +++++- utilities/tcpinfo_other.go | 18 ++++++++++++++ utilities/tcpinfo_unix.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++ utilities/utilities.go | 56 ++++------------------------------------- 5 files changed, 107 insertions(+), 67 deletions(-) create mode 100644 utilities/tcpinfo_other.go create mode 100644 utilities/tcpinfo_unix.go (limited to 'lgc/lgc.go') diff --git a/lgc/lgc.go b/lgc/lgc.go index 5b35fd1..fb51ec1 100644 --- a/lgc/lgc.go +++ b/lgc/lgc.go @@ -281,40 +281,40 @@ func (lgd *LoadGeneratingConnectionDownload) Start( go lgd.doDownload(ctx) return true } -func (lbd *LoadGeneratingConnectionDownload) IsValid() bool { - return lbd.valid +func (lgd *LoadGeneratingConnectionDownload) IsValid() bool { + return lgd.valid } -func (lbd *LoadGeneratingConnectionDownload) Stats() *stats.TraceStats { - return &lbd.stats +func (lgd *LoadGeneratingConnectionDownload) Stats() *stats.TraceStats { + return &lgd.stats } -func (lbd *LoadGeneratingConnectionDownload) doDownload(ctx context.Context) { +func (lgd *LoadGeneratingConnectionDownload) doDownload(ctx context.Context) { var request *http.Request = nil var get *http.Response = nil var err error = nil if request, err = http.NewRequestWithContext( - httptrace.WithClientTrace(ctx, lbd.tracer), + httptrace.WithClientTrace(ctx, lgd.tracer), "GET", - lbd.Path, + lgd.Path, nil, ); err != nil { - lbd.valid = false + lgd.valid = false return } - lbd.downloadStartTime = time.Now() - lbd.lastIntervalEnd = 0 + lgd.downloadStartTime = time.Now() + lgd.lastIntervalEnd = 0 - if get, err = lbd.client.Do(request); err != nil { - lbd.valid = false + if get, err = lgd.client.Do(request); err != nil { + lgd.valid = false return } - cr := &countingReader{n: &lbd.downloaded, ctx: ctx, readable: get.Body} + cr := &countingReader{n: &lgd.downloaded, ctx: ctx, readable: get.Body} _, _ = io.Copy(ioutil.Discard, cr) get.Body.Close() - if debug.IsDebug(lbd.debug) { + if debug.IsDebug(lgd.debug) { fmt.Printf("Ending a load-generating download.\n") } } @@ -426,6 +426,7 @@ func (lgu *LoadGeneratingConnectionUpload) Start( return true } -func (lbd *LoadGeneratingConnectionUpload) Stats() *stats.TraceStats { +func (lgu *LoadGeneratingConnectionUpload) Stats() *stats.TraceStats { + // Get all your stats from the download side of the LGC. return nil } diff --git a/networkQuality.go b/networkQuality.go index 7593714..d9bdc94 100644 --- a/networkQuality.go +++ b/networkQuality.go @@ -336,7 +336,12 @@ func main() { fmt.Printf("OOPS: Could not get the TCP info for the connection (not a TCP connection)!\n") } if info, err := utilities.GetTCPInfo(tcpConn); err != nil { - fmt.Printf("OOPS: Could not get the TCP info for the connection: %v!\n", err) + switch err.(type) { + case *utilities.NotImplemented: + fmt.Printf("GetTCPInfo not implemented on this platform.\n") + default: + fmt.Printf("OOPS: Could not get the TCP info for the connection: %v!\n", err) + } } else { utilities.PrintTCPInfo(info) } diff --git a/utilities/tcpinfo_other.go b/utilities/tcpinfo_other.go new file mode 100644 index 0000000..8dd070b --- /dev/null +++ b/utilities/tcpinfo_other.go @@ -0,0 +1,18 @@ +//go:build !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd +// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd + +package utilities + +import ( + "net" + + "golang.org/x/sys/unix" +) + +func GetTCPInfo(connection net.Conn) (*unix.TCPInfo, error) { + return nil, NotImplemented{Functionality: "GetTCPInfo"} +} + +func PrintTCPInfo(info *unix.TCPInfo) { + return +} diff --git a/utilities/tcpinfo_unix.go b/utilities/tcpinfo_unix.go new file mode 100644 index 0000000..b0b5252 --- /dev/null +++ b/utilities/tcpinfo_unix.go @@ -0,0 +1,62 @@ +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd + +package utilities + +import ( + "fmt" + "net" + + "golang.org/x/sys/unix" +) + +func GetTCPInfo(connection net.Conn) (*unix.TCPInfo, error) { + tcpConn, ok := connection.(*net.TCPConn) + if !ok { + return nil, fmt.Errorf("connection is not a net.TCPConn") + } + rawConn, err := tcpConn.SyscallConn() + if err != nil { + return nil, err + } + + var info *unix.TCPInfo = nil + rawConn.Control(func(fd uintptr) { + info, err = unix.GetsockoptTCPInfo(int(fd), unix.SOL_TCP, unix.TCP_INFO) + }) + return info, err +} + +func PrintTCPInfo(info *unix.TCPInfo) { + fmt.Printf("TCPInfo: \n") + fmt.Printf(" State: %v\n", info.State) + fmt.Printf(" Ca_state: %v\n", info.Ca_state) + fmt.Printf(" Retransmits: %v\n", info.Retransmits) + fmt.Printf(" Probes: %v\n", info.Probes) + fmt.Printf(" Backoff: %v\n", info.Backoff) + fmt.Printf(" Options: %v\n", info.Options) + fmt.Printf(" Rto: %v\n", info.Rto) + fmt.Printf(" Ato: %v\n", info.Ato) + fmt.Printf(" Snd_mss: %v\n", info.Snd_mss) + fmt.Printf(" Rcv_mss: %v\n", info.Rcv_mss) + fmt.Printf(" Unacked: %v\n", info.Unacked) + fmt.Printf(" Sacked: %v\n", info.Sacked) + fmt.Printf(" Lost: %v\n", info.Lost) + fmt.Printf(" Retrans: %v\n", info.Retrans) + fmt.Printf(" Fackets: %v\n", info.Fackets) + fmt.Printf(" Last_data_sent: %v\n", info.Last_data_sent) + fmt.Printf(" Last_ack_sent: %v\n", info.Last_ack_sent) + fmt.Printf(" Last_data_recv: %v\n", info.Last_data_recv) + fmt.Printf(" Last_ack_recv: %v\n", info.Last_ack_recv) + fmt.Printf(" Pmtu: %v\n", info.Pmtu) + fmt.Printf(" Rcv_ssthresh: %v\n", info.Rcv_ssthresh) + fmt.Printf(" Rtt: %v\n", info.Rtt) + fmt.Printf(" Rttvar: %v\n", info.Rttvar) + fmt.Printf(" Snd_ssthresh: %v\n", info.Snd_ssthresh) + fmt.Printf(" Snd_cwnd: %v\n", info.Snd_cwnd) + fmt.Printf(" Advmss: %v\n", info.Advmss) + fmt.Printf(" Reordering: %v\n", info.Reordering) + fmt.Printf(" Rcv_rtt: %v\n", info.Rcv_rtt) + fmt.Printf(" Rcv_space: %v\n", info.Rcv_space) + fmt.Printf(" Total_retrans: %v\n", info.Total_retrans) +} diff --git a/utilities/utilities.go b/utilities/utilities.go index e4c8a0d..7e26ab9 100644 --- a/utilities/utilities.go +++ b/utilities/utilities.go @@ -18,13 +18,10 @@ import ( "fmt" "math" "math/rand" - "net" "os" "reflect" "sync/atomic" "time" - - "golang.org/x/sys/unix" ) func IsInterfaceNil(ifc interface{}) bool { @@ -126,53 +123,10 @@ func RandBetween(max int) int { return rand.New(rand.NewSource(int64(time.Now().Nanosecond()))).Int() % max } -func GetTCPInfo(connection net.Conn) (*unix.TCPInfo, error) { - tcpConn, ok := connection.(*net.TCPConn) - if !ok { - return nil, fmt.Errorf("connection is not a net.TCPConn") - } - rawConn, err := tcpConn.SyscallConn() - if err != nil { - return nil, err - } +type NotImplemented struct { + Functionality string +} - var info *unix.TCPInfo = nil - rawConn.Control(func(fd uintptr) { - info, err = unix.GetsockoptTCPInfo(int(fd), unix.SOL_TCP, unix.TCP_INFO) - }) - return info, err -} - -func PrintTCPInfo(info *unix.TCPInfo) { - fmt.Printf("TCPInfo: \n") - fmt.Printf(" State: %v\n", info.State) - fmt.Printf(" Ca_state: %v\n", info.Ca_state) - fmt.Printf(" Retransmits: %v\n", info.Retransmits) - fmt.Printf(" Probes: %v\n", info.Probes) - fmt.Printf(" Backoff: %v\n", info.Backoff) - fmt.Printf(" Options: %v\n", info.Options) - fmt.Printf(" Rto: %v\n", info.Rto) - fmt.Printf(" Ato: %v\n", info.Ato) - fmt.Printf(" Snd_mss: %v\n", info.Snd_mss) - fmt.Printf(" Rcv_mss: %v\n", info.Rcv_mss) - fmt.Printf(" Unacked: %v\n", info.Unacked) - fmt.Printf(" Sacked: %v\n", info.Sacked) - fmt.Printf(" Lost: %v\n", info.Lost) - fmt.Printf(" Retrans: %v\n", info.Retrans) - fmt.Printf(" Fackets: %v\n", info.Fackets) - fmt.Printf(" Last_data_sent: %v\n", info.Last_data_sent) - fmt.Printf(" Last_ack_sent: %v\n", info.Last_ack_sent) - fmt.Printf(" Last_data_recv: %v\n", info.Last_data_recv) - fmt.Printf(" Last_ack_recv: %v\n", info.Last_ack_recv) - fmt.Printf(" Pmtu: %v\n", info.Pmtu) - fmt.Printf(" Rcv_ssthresh: %v\n", info.Rcv_ssthresh) - fmt.Printf(" Rtt: %v\n", info.Rtt) - fmt.Printf(" Rttvar: %v\n", info.Rttvar) - fmt.Printf(" Snd_ssthresh: %v\n", info.Snd_ssthresh) - fmt.Printf(" Snd_cwnd: %v\n", info.Snd_cwnd) - fmt.Printf(" Advmss: %v\n", info.Advmss) - fmt.Printf(" Reordering: %v\n", info.Reordering) - fmt.Printf(" Rcv_rtt: %v\n", info.Rcv_rtt) - fmt.Printf(" Rcv_space: %v\n", info.Rcv_space) - fmt.Printf(" Total_retrans: %v\n", info.Total_retrans) +func (ni *NotImplemented) Error() string { + return fmt.Sprintf("%v not implemented.\n", ni.Functionality) } -- cgit v1.2.3