hsa: fix echo-bytes echo client runs over UDP 85/43285/3
authorSemir Sionek <[email protected]>
Tue, 24 Jun 2025 12:19:04 +0000 (12:19 +0000)
committerFlorin Coras <[email protected]>
Wed, 25 Jun 2025 19:57:31 +0000 (19:57 +0000)
Previously counting received bytes didn't take into account the
datagram header size, leading to a bigger than expected size and an
overflow of es->bytes_to_receive.

Type: fix
Change-Id: If31d4ed5f989645388dbf9c1b9829c6f2e4e8c62
Signed-off-by: Semir Sionek <[email protected]>
extras/hs-test/echo_test.go
src/plugins/hs_apps/echo_client.c

index b753121..53f8354 100644 (file)
@@ -8,7 +8,7 @@ import (
 )
 
 func init() {
-       RegisterVethTests(EchoBuiltinTest, EchoBuiltinBandwidthTest)
+       RegisterVethTests(EchoBuiltinTest, EchoBuiltinBandwidthTest, EchoBuiltinEchobytesTest)
        RegisterSoloVethTests(TcpWithLossTest)
        RegisterVeth6Tests(TcpWithLoss6Test)
 }
@@ -57,6 +57,20 @@ func EchoBuiltinBandwidthTest(s *VethsSuite) {
        }
 }
 
+func EchoBuiltinEchobytesTest(s *VethsSuite) {
+       serverVpp := s.Containers.ServerVpp.VppInstance
+
+       serverVpp.Vppctl("test echo server " +
+               " uri udp://" + s.Interfaces.Server.Ip4AddressString() + "/" + s.Ports.Port1)
+
+       clientVpp := s.Containers.ClientVpp.VppInstance
+
+       o := clientVpp.Vppctl("test echo client echo-bytes verbose uri" +
+               " udp://" + s.Interfaces.Server.Ip4AddressString() + "/" + s.Ports.Port1)
+       s.Log(o)
+       s.AssertNotContains(o, "test echo clients: failed: timeout with 1 sessions")
+}
+
 func TcpWithLossTest(s *VethsSuite) {
        serverVpp := s.Containers.ServerVpp.VppInstance
 
index 54e806a..843ce40 100644 (file)
@@ -190,6 +190,7 @@ receive_data_chunk (ec_worker_t *wrk, ec_session_t *es)
 {
   ec_main_t *ecm = &ec_main;
   svm_fifo_t *rx_fifo = es->rx_fifo;
+  session_dgram_pre_hdr_t ph;
   int n_read, i;
 
   if (ecm->cfg.test_bytes)
@@ -199,8 +200,23 @@ receive_data_chunk (ec_worker_t *wrk, ec_session_t *es)
     }
   else
     {
-      n_read = svm_fifo_max_dequeue_cons (rx_fifo);
-      svm_fifo_dequeue_drop (rx_fifo, n_read);
+      if (!es->is_dgram)
+       {
+         n_read = svm_fifo_max_dequeue_cons (rx_fifo);
+         svm_fifo_dequeue_drop (rx_fifo, n_read);
+       }
+      else
+       {
+         n_read = svm_fifo_max_dequeue_cons (rx_fifo);
+         if (n_read <= sizeof (session_dgram_hdr_t))
+           return;
+         svm_fifo_peek (rx_fifo, 0, sizeof (ph), (u8 *) &ph);
+         if (n_read < (ph.data_length + SESSION_CONN_HDR_LEN))
+           return;
+         svm_fifo_dequeue_drop (rx_fifo,
+                                ph.data_length + SESSION_CONN_HDR_LEN);
+         n_read = ph.data_length;
+       }
     }
 
   if (n_read > 0)
@@ -233,7 +249,14 @@ receive_data_chunk (ec_worker_t *wrk, ec_session_t *es)
                }
            }
        }
-      ASSERT (n_read <= es->bytes_to_receive);
+      if (n_read > es->bytes_to_receive)
+       {
+         ec_err ("expected %llu, received %llu bytes!",
+                 es->bytes_received + es->bytes_to_receive,
+                 es->bytes_received + n_read);
+         ecm->test_failed = 1;
+         es->bytes_to_receive = n_read;
+       }
       es->bytes_to_receive -= n_read;
       es->bytes_received += n_read;
     }