User Datagram Protocol (UDP)

Requirements

Sandbox environment

Setup your sandbox environment with Docker and Docker Compose, and clone the Envoy repository with Git.

curl

Used to make HTTP requests.

netcat

Used to send UDP packets.

This sandbox provides a very simple example of Envoy proxying UDP.

It also demonstrates UDP traffic stats provided by the Envoy admin endpoint.

Step 1: Build the sandbox

Change directory to examples/udp in the Envoy repository.

Start the Docker composition:

  1. $ pwd
  2. envoy/examples/udp
  3. $ docker-compose pull
  4. $ docker-compose up --build -d
  5. $ docker-compose ps
  6. Name Command State Ports
  7. -----------------------------------------------------------------------------------------------------------------------
  8. udp_envoy-udp_1 /docker-entrypoint.sh /usr ... Up 10000/tcp, 0.0.0.0:10000->10000/udp, 0.0.0.0:10001->10001/tcp
  9. udp_service-udp_1 python -u /udplistener.py Up 5005/tcp, 5005/udp

Envoy should proxy UDP on port 10000 to an upstream server listening on port 5005.

Envoy also provides an admin endpoint listening on port 10001.

Step 2: Send some UDP messages

You can use netcat to send packets to the upstream server, proxied by Envoy:

  1. echo -n HELO | nc -4u -w1 127.0.0.1 10000
  2. echo -n OLEH | nc -4u -w1 127.0.0.1 10000

Step 3: Check the logs of the upstream UDP listener server

Checking the logs of the upstream server you should see the packets that you sent:

  1. $ docker-compose logs service-udp
  2. Attaching to udp_service-udp_1
  3. service-udp_1 | Listening on UDP port 5005
  4. service-udp_1 | HELO
  5. service-udp_1 | OLEH

Step 4: View the Envoy admin UDP stats

You can view the UDP-related stats provided by the Envoy admin endpoint.

For example, to view the non-zero stats:

  1. $ curl -s http://127.0.0.1:10001/stats | grep udp | grep -v "\: 0"
  2. cluster.service_udp.default.total_match_count: 1
  3. cluster.service_udp.max_host_weight: 1
  4. cluster.service_udp.membership_change: 1
  5. cluster.service_udp.membership_healthy: 1
  6. cluster.service_udp.membership_total: 1
  7. cluster.service_udp.udp.sess_tx_datagrams: 2
  8. cluster.service_udp.update_attempt: 1
  9. cluster.service_udp.update_success: 1
  10. cluster.service_udp.upstream_cx_tx_bytes_total: 8
  11. udp.service.downstream_sess_active: 2
  12. udp.service.downstream_sess_rx_bytes: 8
  13. udp.service.downstream_sess_rx_datagrams: 2
  14. udp.service.downstream_sess_total: 2
  15. cluster.service_udp.upstream_cx_connect_ms: No recorded values
  16. cluster.service_udp.upstream_cx_length_ms: No recorded values