2022-06-23 08:17:20 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"k8s.io/klog/v2"
|
|
|
|
)
|
|
|
|
|
2022-06-24 04:08:57 -07:00
|
|
|
func sendUDP(addr string, txb []byte, count int) {
|
2022-06-23 08:17:20 -07:00
|
|
|
// Send UDP packet to TPU
|
|
|
|
conn, err := net.Dial("udp", addr)
|
|
|
|
if err != nil {
|
2022-06-24 04:08:57 -07:00
|
|
|
// if we fail to open a UDP socket, something has gone really wrong
|
|
|
|
klog.Exitf("failed to dial %s: %v", addr, err)
|
|
|
|
return
|
2022-06-23 08:17:20 -07:00
|
|
|
}
|
|
|
|
defer conn.Close()
|
2022-06-24 04:08:57 -07:00
|
|
|
tn := 0
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
n, err := conn.Write(txb)
|
|
|
|
if err != nil {
|
|
|
|
klog.Errorf("failed to write to %s: %v", addr, err)
|
|
|
|
}
|
|
|
|
if n != len(txb) {
|
|
|
|
panic(fmt.Errorf("wrote %d bytes, expected %d", n, len(txb)))
|
|
|
|
}
|
|
|
|
tn += n
|
2022-06-23 08:17:20 -07:00
|
|
|
}
|
2022-06-24 04:08:57 -07:00
|
|
|
klog.V(2).Infof("sent %d bytes to %s", tn, addr)
|
2022-06-23 08:17:20 -07:00
|
|
|
}
|