Universal Third-Party Tools useful for testing¶
WHAT TO EXPECT
The xNIC installation provides a number of useful tools to test the cloudSwXtch network (swx-perf, swx-tcpdump, etc.). There is also a wealth of universal third-party tools that can be used for the same purposes, because the xNIC and the cloudSwXtch need no changes in the applications.
In this article, users will take a deeper dive into these alternative options and their basic functionality:
Choosing the interface¶
When a VM has more than one network interface, the multicast (or broadcast) traffic must be produced and consumed on the interface the xNIC uses for the applications:
| xNIC type | Interface for the applications |
|---|---|
| Type 1 and Type 3 | swx0, the virtual interface created by the xNIC (use its IP address where a tool asks for an IP) |
| Type 2 | The data interface of the VM (for example ens6 or eth1) |
Some tools let the user select the interface (by name or by its IP address); others do not, and then the operating system picks it from the routing table. In the latter case, users need to modify the routing table so that multicast goes through the right interface. The examples in this article were captured on VMs whose interface for the applications was ens6; replace it with the right one for the xNIC type in use.
PLEASE NOTE
On an xNIC Type 1 or Type 3, joining or sending on the data interface of the VM, or letting the operating system choose (for example, joining with INADDR_ANY), may deliver nothing. Always select swx0 explicitly.
To check which interface an application joined a group on:
| OS | Command |
|---|---|
| Linux | ip maddr show dev swx0 (or the data interface on Type 2) |
| Windows (PowerShell) | netsh.exe interface ipv4 show joins |
Receiving tools that do not print statistics can be checked with swx-top, wXcked Eye, or swx-tcpdump on swx0. To measure the loss of a stream produced by any of these tools, receive it with swx-perf in generic mode.
VLC¶
VLC is a free and open-source cross-platform multimedia player and framework that plays most multimedia files and various streaming protocols. As a highly visual tool, it can be used to demonstrate the delivery and fidelity of video streams from the cloudSwXtch to the xNIC. It also has a fairly powerful command-line interface. On Linux, the cvlc command runs VLC without its graphical interface, which works better on headless VMs.
In the following example, a Linux producer streams a .ts file (MPEG Transport Stream) with RTP to the multicast address 239.1.1.2, port 10000, in an endless loop, using the interface ens6. The consumer receives the stream on its interface ens6. Please note that a headless Linux VM can use cvlc instead of vlc, so no interface is shown; Windows, on the other hand, does not come with cvlc.
Producer¶
Sample output in the console for the producer:
$ cvlc /home/ubuntu/your_video.ts --sout '#rtp{dst=239.1.1.2,port=10000,mux=ts}' --miface=ens6 --loop
VLC media player 3.0.20 Vetinari (revision 3.0.20-0-g6f0d0ab126b)
[000055dac7b95dd0] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[000055dac7bbe8f0] dummy interface: using the dummy interface module...
NOTES
- The PulseAudio and ALSA audio errors are normal on a headless VM in a cloud: there is no sound hardware.
- On the consumer VM, the video only shows if the session has a graphical display (for example, a remote desktop, or X forwarding over SSH). Without one, use
cvlcand confirm the delivery with the statistics in swx-top or wXcked Eye.
Consumer¶
Sample output in the console. The audio-related errors can be ignored:
$ vlc rtp://@239.1.1.2:10000 --miface=ens6
VLC media player 3.0.20 Vetinari (revision 3.0.20-0-g6f0d0ab126b)
[00005d46352141b0] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[00005d463517b220] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
ALSA lib confmisc.c:855:(parse_card) cannot find card '0'
ALSA lib conf.c:5204:(_snd_config_evaluate) function snd_func_card_inum returned error: No such file or directory
...
[00005d46352141b0] alsa audio output error: cannot open ALSA device "default": No such file or directory
[00005d46352141b0] main audio output error: module not functional
[0000792a60037200] main decoder error: failed to create audio output
Failed to open VDPAU backend libvdpau_nvidia.so: cannot open shared object file: No such file or directory
Sample output for the video:

NOTE FOR WINDOWS VMs WITH MULTIPLE NICs
VLC on Windows (version 3.0.x) does not let users choose the interface. To make VLC use the right interface, users need to modify the routing table.
FFmpeg¶
The FFmpeg project has two command-line tools, ffmpeg and ffplay, that can be used to demonstrate the delivery of a stream: ffmpeg as the streamer and ffplay as the player. Unlike VLC, it has no full graphical interface (ffplay only opens a video window). And while VLC needs a file to stream, ffmpeg can generate video test patterns. The following example uses testsrc as the video source, which displays a color pattern with a scrolling gradient and a timestamp.
NOTE
ffmpeg can also be used to consume the traffic, instead of ffplay.
NOTE
FFmpeg can be compiled with different sets of features, so some of them may not be available in the binary installed on the VM. For example, SRT support is not included by default on some Linux distributions.
In this example, the user sends a 640×480 test signal at 30 fps, encoded as MPEG-2 video in an MPEG-TS stream, generated with lavfi (the libavfilter virtual input device), for 1000 seconds to the multicast address 239.1.1.1, port 11000, with a packet size of 1316 bytes (7 MPEG-TS packets).
Producer¶
ffmpeg -hide_banner -f lavfi -re -i testsrc=duration=1000:size=640x480:rate=30 -f mpegts "udp://239.1.1.1:11000?pkt_size=1316"
Below is an example of the ffmpeg producer output:
$ ffmpeg -hide_banner -f lavfi -re -i testsrc=duration=1000:size=640x480:rate=30 -f mpegts "udp://239.1.1.1:11000?pkt_size=1316"
Input #0, lavfi, from 'testsrc=duration=1000:size=640x480:rate=30':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: wrapped_avframe, rgb24, 640x480 [SAR 1:1 DAR 4:3], 30 fps, 30 tbr, 30 tbn
Stream mapping:
Stream #0:0 -> #0:0 (wrapped_avframe (native) -> mpeg2video (native))
Press [q] to stop, [?] for help
Output #0, mpegts, to 'udp://239.1.1.1:11000?pkt_size=1316':
Metadata:
encoder : Lavf60.16.100
Stream #0:0: Video: mpeg2video (Main), yuv420p(tv, progressive), 640x480 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 30 fps, 90k tbn
Metadata:
encoder : Lavc60.31.102 mpeg2video
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
frame= 155 fps= 33 q=11.9 size= 369kB time=00:00:05.13 bitrate= 588.3kbits/s speed= 1.1x
Consumer¶
Below is an example of the ffplay output. A "Packet corrupt" message at the start is normal: the player joined in the middle of the stream.
$ ffplay -hide_banner "udp://239.1.1.1:11000"
[mpegts @ 0x74ec68000c80] Packet corrupt (stream = 0, dts = 432000).
Input #0, mpegts, from 'udp://239.1.1.1:11000':KB sq= 0B f=0/0
Duration: N/A, start: 1.433333, bitrate: N/A
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, progressive), 640x480 [SAR 1:1 DAR 4:3], 30 fps, 30 tbr, 90k tbn
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 49152 vbv_delay: N/A
43.78 M-V: 0.347 fd=1261 aq= 0KB vq= 4KB sq= 0B f=1/1
A successful delivery displays the following video on the consumer VM (ffplay needs a graphical display):

NOTE ABOUT THE INTERFACE
To choose the interface used to produce or consume, add localaddr=<IP address of the interface> to the URL. Separate it from the rest of the URL with ?, or with & if the URL already has a ?. For example, the same producer as above, sending through the interface whose IP address is 192.168.0.2:
iPerf (v2.x)¶
Similar to swx-perf, iPerf 2 is a multi-platform tool for network performance measurement and tuning, commonly used for connectivity, bandwidth and latency tests. iPerf 3 does not support multicast, so use iPerf 2 (v2.x) to test a cloudSwXtch network.
In this example, the user sends a UDP stream to the multicast address 239.1.1.3, port 10000, for 120 seconds, with 1000-byte datagrams, and prints enhanced statistics every second.
Producer¶
- -c: client: the VM is the producer, sending to the multicast address (239.1.1.3). The
%ens6suffix binds the interface - -p: the port (10000)
- -u: send UDP packets
- -t: the duration of the stream in seconds (120)
- -i: the interval between reports, in seconds (1)
- -e: enhanced reporting (interval, transfer, bandwidth, write/err, PPS)
- -l: the length of the datagrams, in bytes (1000)
This is an example of an iPerf producer output, binding the interface ens6 (without -t, -e and -l, so it runs for the default 10 seconds with 1470-byte datagrams):
$ iperf -c 239.1.1.1%ens6 -p 10000 -u -i 1
------------------------------------------------------------
Client connecting to 239.1.1.1, UDP port 10000 with pid 379893 via ens6 (1 flows)
Sending 1470 byte datagrams, IPG target: 11215.21 us (kalman adjust)
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 1] local 172.31.103.38 port 47031 connected with 239.1.1.1 port 10000
[ ID] Interval Transfer Bandwidth
[ 1] 0.0000-1.0000 sec 131 KBytes 1.07 Mbits/sec
[ 1] 1.0000-2.0000 sec 128 KBytes 1.05 Mbits/sec
...
[ 1] 9.0000-10.0000 sec 128 KBytes 1.05 Mbits/sec
[ 1] 0.0000-10.0153 sec 1.25 MBytes 1.05 Mbits/sec
NOTE
By default, iPerf 2 sends UDP at about 1 Mbit/s, as in the output above. Use -b to set the rate, for example -b 100M for 100 Mbit/s, or -b 10000pps for a packet rate.
PLEASE NOTE
Binding the interface with % did not work on Windows when this article was last tested. On Windows, modify the routing table instead.
Consumer¶
- -s: server: the VM is the consumer
- -u: receive UDP packets
- -B: bind: the multicast address to join (239.1.1.3; note the capital B). The
%ens6suffix selects the interface - -p: the port (10000)
- -i: the interval between reports, in seconds (1)
This is an example of an iPerf consumer output on the interface ens6. Each line covers one second:
$ iperf -s -u -B 239.1.1.3%ens6 -p 10000 -i 1
------------------------------------------------------------
Server listening on UDP port 10000
Joining multicast (*,G)=*,239.1.1.3 w/iface ens6
Server set to single client traffic mode (per multicast receive)
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 1] local 239.1.1.3 port 10000 connected with 172.31.103.38 port 54577
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 1] 0.0000-1.0000 sec 129 KBytes 1.06 Mbits/sec 0.003 ms 5179/5311 (98%)
[ 1] 1.0000-2.0000 sec 128 KBytes 1.05 Mbits/sec 0.004 ms 0/131 (0%)
[ 1] 2.0000-3.0000 sec 128 KBytes 1.05 Mbits/sec 0.003 ms 0/131 (0%)
...
[ 1] 8.0000-9.0000 sec 128 KBytes 1.05 Mbits/sec 0.003 ms 0/131 (0%)
READING THE FIRST LINE
The consumer was started after the producer. iPerf counts every datagram the producer sent before the consumer joined as lost, so the first interval shows a high loss (5179/5311). From the second interval on, the loss is 0. Start the consumer before the producer to avoid this.
NO CONSUMER OUTPUT
Some older versions of iPerf 2 print no output on the consumer, even when configured to do so. Users can still check in swx-top that the xNIC receives the traffic. To fix this, use the latest version of iPerf 2.
NOTE FOR WINDOWS VMs WITH MULTIPLE NICs
To make iPerf 2 use the right interface, users need to modify the routing table.
sockperf¶
Another alternative to swx-perf is sockperf (documentation here), a Linux-only network benchmarking utility based on the socket API, designed to test the latency and throughput of high-performance systems. It has fewer options than swx-perf and iPerf. It is a good choice to saturate the Network Interface and reach the maximum bandwidth of the VM.
In this example, the user sends to the multicast address 239.1.1.4, port 10000, 1472-byte messages at 2000 messages per second for 30 seconds, and selects the interface by its IP address on the producer (--mc-tx-if) and on the consumer (--mc-rx-if):
Producer¶
sockperf throughput --ip 239.1.1.4 --msg-size 1472 --port 10000 --mps 2000 --time 30 --mc-tx-if 172.31.103.38
This is a sample output for the producer:
$ sockperf throughput --ip 239.1.1.4 --msg-size 1472 --port 10000 --mps 2000 --time 30 --mc-tx-if 172.31.103.38
sockperf: == version #3.7-no.git ==
sockperf[CLIENT] send on:
[ 0] IP = 239.1.1.4 PORT = 10000 # UDP
sockperf: Warmup stage (sending a few dummy messages)...
sockperf: Starting test...
sockperf: Test end (interrupted by timer)
sockperf: Test ended
sockperf: Total of 60001 messages sent in 30.000 sec
sockperf: NOTE: test was performed, using msg-size=1472, mps=2000. For getting maximum throughput use --mps=max (and consider --msg-size=1472 or --msg-size=4096)
sockperf: Summary: Message Rate is 2000 [msg/sec]
sockperf: Summary: BandWidth is 2.808 MBps (22.461 Mbps)
As the output suggests, use --mps=max to send as fast as possible.
Consumer¶
The consumer receives the traffic and prints a line every 800 messages. It keeps waiting for traffic until it is stopped with Ctrl+C.
$ sockperf server --ip 239.1.1.4 --Activity 800 --port 10000 --mc-rx-if 172.31.106.231
sockperf: == version #3.7-no.git ==
sockperf: [SERVER] listen on:
[ 0] IP = 239.1.1.4 PORT = 10000 # UDP
sockperf: Warmup stage (sending a few dummy messages)...
sockperf: [tid 315630] using recvfrom() to block on socket(s)
-- Interval -- -- Message Rate -- -- Total Message Count --
6227693 [usec] 128 [msg/s] 800 [msg]
399994 [usec] 2000 [msg/s] 1600 [msg]
400008 [usec] 1999 [msg/s] 2400 [msg]
399977 [usec] 2000 [msg/s] 3200 [msg]
...
399991 [usec] 2000 [msg/s] 12000 [msg]
Python/Go¶
Users may also build their own tools to test their cloudSwXtch network. Below are two examples, in Python and in Go, that send and receive multicast messages. Just as applications need no code changes to use the cloudSwXtch, neither do test programs: this is standard multicast code.
Python¶
Python is installed by default on most Linux distributions, which makes it a simple way to test the xNIC.
Producer¶
The key object here is the socket module, and the method used to send is sock.sendto. Nothing in the code is specific to the xNIC or the cloudSwXtch: it works in any environment that supports multicast. In a public cloud, that environment is provided by the xNIC; without it, the messages do not reach other VMs.
- Create a producer.py file on the producer VM.
-
Copy and paste the following script:
import socket import struct import time def send_multicast_message(ip, port, message, delay, interface_ip=None): # Create the socket multicast_group = (ip, port) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Set the time-to-live for messages to 1 so they do not go past the local network segment ttl = struct.pack('b', 1) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl) if interface_ip: print(f"Sending via interface {interface_ip}") sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(interface_ip)) try: while True: # Send the message print(f'Sending "{message}" to {ip}:{port}') sock.sendto(message.encode('utf-8'), multicast_group) # Delay between messages time.sleep(delay) finally: print('Closing socket') sock.close() # Example usage # Replace 'x.x.x.x' with the IP address of the interface to use (swx0 on xNIC Type 1 and 3). send_multicast_message('239.1.1.1', 10000, 'Hello, Multicast!', 2, 'x.x.x.x') -
Replace
x.x.x.xwith the IP address of the interface for the applications (see Choosing the interface). Save and close. -
Run the script:
Below is an example of the output:
$ python3 producer.py
Sending via interface 172.31.103.38
Sending "Hello, Multicast!" to 239.1.1.1:10000
Sending "Hello, Multicast!" to 239.1.1.1:10000
Sending "Hello, Multicast!" to 239.1.1.1:10000
Sending "Hello, Multicast!" to 239.1.1.1:10000
Consumer¶
The key here is the setsockopt() method, which joins the multicast group (IP_ADD_MEMBERSHIP) on the given interface.
- Create a receiver.py file on the consumer VM.
-
Copy and paste the following script:
import socket import struct def receive_multicast_message(ip, port, interface_ip=None): # Create the socket sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Bind to the port sock.bind(('', port)) # Tell the operating system to add the socket to the multicast group group = socket.inet_aton(ip) if interface_ip: print(f"Joining multicast group on interface {interface_ip}") mreq = struct.pack('4s4s', group, socket.inet_aton(interface_ip)) else: mreq = struct.pack('=4sl', group, socket.INADDR_ANY) sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) # Receive loop while True: print('Waiting to receive') data, address = sock.recvfrom(1024) print(f'Received "{data.decode("utf-8")}" from {address}') # Example usage # Replace 'x.x.x.x' with the IP address of the interface to use (swx0 on xNIC Type 1 and 3). receive_multicast_message('239.1.1.1', 10000, 'x.x.x.x') -
Replace
x.x.x.xwith the IP address of the interface for the applications. Save and close. -
Run the script:
Below is an example of the output on the consumer VM:
$ python3 receiver.py
Joining multicast group on interface 172.31.106.231
Waiting to receive
Received "Hello, Multicast!" from ('172.31.103.38', 56547)
Waiting to receive
Received "Hello, Multicast!" from ('172.31.103.38', 56547)
Waiting to receive
NOTE
Always pass the interface IP address. Without it, the script joins with INADDR_ANY and the operating system picks the interface, which on an xNIC Type 1 or Type 3 may not be swx0.
Go¶
Go is another popular programming language to write test programs. Unlike Python, it must be installed, but it produces faster programs. The producer uses the package golang.org/x/net/ipv4, so create a module first:
Producer¶
The producer uses net.DialUDP to send, and SetMulticastInterface to select the interface.
// producer.go
package main
import (
"fmt"
"net"
"os"
"time"
"golang.org/x/net/ipv4"
)
func check(err error) {
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
}
func main() {
multicastAddr := "239.1.1.1:10000"
interfaceName := "swx0" // Replace with the interface for the applications (swx0 on xNIC Type 1 and 3)
// Resolve the network interface by name
iface, err := net.InterfaceByName(interfaceName)
check(err)
// Resolve the multicast address
remoteAddr, err := net.ResolveUDPAddr("udp", multicastAddr)
check(err)
// Create a UDP connection
conn, err := net.DialUDP("udp", nil, remoteAddr)
check(err)
defer conn.Close()
// Set the multicast interface
pc := ipv4.NewPacketConn(conn)
check(pc.SetMulticastInterface(iface))
for {
message := "Hello, Multicast!"
_, err = conn.Write([]byte(message))
check(err)
fmt.Println("Message sent:", message)
time.Sleep(2 * time.Second)
}
}
Run it with go run producer.go. Sample output:
$ go run producer.go
Message sent: Hello, Multicast!
Message sent: Hello, Multicast!
Message sent: Hello, Multicast!
Message sent: Hello, Multicast!
Consumer¶
The consumer uses net.ListenMulticastUDP, which joins the group on the given interface.
// receiver.go
package main
import (
"fmt"
"net"
"os"
)
func check(err error) {
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
}
func main() {
multicastAddr := "239.1.1.1:10000"
interfaceName := "swx0" // Replace with the interface for the applications (swx0 on xNIC Type 1 and 3)
// Resolve the network interface by name
iface, err := net.InterfaceByName(interfaceName)
check(err)
// Resolve the multicast address
addr, err := net.ResolveUDPAddr("udp", multicastAddr)
check(err)
// Listen for multicast traffic on the interface
conn, err := net.ListenMulticastUDP("udp", iface, addr)
check(err)
defer conn.Close()
buf := make([]byte, 1500)
for {
n, src, err := conn.ReadFromUDP(buf)
check(err)
fmt.Printf("Received message from %v: %s\n", src, string(buf[:n]))
}
}
Run it with go run receiver.go. Sample output:
$ go run receiver.go
Received message from 172.31.19.230:53197: Hello, Multicast!
Received message from 172.31.19.230:53197: Hello, Multicast!
Received message from 172.31.19.230:53197: Hello, Multicast!
OTHER PROGRAMMING LANGUAGES
As with Python or Go, users can write programs in virtually any language with the same logic and let the xNIC and the cloudSwXtch take care of the rest: select the interface, join the group, send and receive. For example, in Node.js, the dgram module provides setMulticastInterface(), addMembership(), send() and the message event. In C and C++, the calls are setsockopt() (with IP_MULTICAST_IF and IP_ADD_MEMBERSHIP), sendto() and recvfrom().