hsa: vcl test client allow non-blocking connects 74/35974/2
authorFlorin Coras <fcoras@cisco.com>
Fri, 15 Apr 2022 23:01:43 +0000 (16:01 -0700)
committerFlorin Coras <fcoras@cisco.com>
Sat, 16 Apr 2022 18:03:23 +0000 (11:03 -0700)
Type: improvement

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: If7dd56e76efc31ed66b865e2c7231d22ec2322b4

src/plugins/hs_apps/vcl/vcl_test.h
src/plugins/hs_apps/vcl/vcl_test_client.c
src/plugins/hs_apps/vcl/vcl_test_protos.c

index d51e204..ac94979 100644 (file)
@@ -125,9 +125,10 @@ typedef struct
 
 typedef struct vcl_test_session
 {
-  uint8_t is_alloc;
-  uint8_t is_open;
   uint8_t is_done;
+  uint8_t is_alloc : 1;
+  uint8_t is_open : 1;
+  uint8_t noblk_connect : 1;
   int fd;
   int (*read) (struct vcl_test_session *ts, void *buf, uint32_t buflen);
   int (*write) (struct vcl_test_session *ts, void *buf, uint32_t buflen);
index f096e23..1b149b2 100644 (file)
@@ -1077,7 +1077,10 @@ vt_incercept_sigs (void)
 static void
 vtc_alloc_workers (vcl_test_client_main_t *vcm)
 {
+  vcl_test_main_t *vt = &vcl_test_main;
+
   vcm->workers = calloc (vcm->n_workers, sizeof (vcl_test_client_worker_t));
+  vt->wrk = calloc (vcm->n_workers, sizeof (vcl_test_wrk_t));
 
   for (int i = 0; i < vcm->n_workers; i++)
     {
index 60ee092..97d64b5 100644 (file)
@@ -21,16 +21,15 @@ vt_tcp_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
   uint32_t flags, flen;
   int rv;
 
-  ts->fd = vppcom_session_create (VPPCOM_PROTO_TCP, 0 /* is_nonblocking */);
+  ts->fd = vppcom_session_create (VPPCOM_PROTO_TCP, ts->noblk_connect);
   if (ts->fd < 0)
     {
       vterr ("vppcom_session_create()", ts->fd);
       return ts->fd;
     }
 
-  /* Connect is blocking */
   rv = vppcom_session_connect (ts->fd, endpt);
-  if (rv < 0)
+  if (rv < 0 && rv != VPPCOM_EINPROGRESS)
     {
       vterr ("vppcom_session_connect()", rv);
       return rv;
@@ -38,10 +37,14 @@ vt_tcp_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
 
   ts->read = vcl_test_read;
   ts->write = vcl_test_write;
-  flags = O_NONBLOCK;
-  flen = sizeof (flags);
-  vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
-  vtinf ("Test session %d (fd %d) connected.", ts->session_index, ts->fd);
+
+  if (!ts->noblk_connect)
+    {
+      flags = O_NONBLOCK;
+      flen = sizeof (flags);
+      vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
+      vtinf ("Test session %d (fd %d) connected.", ts->session_index, ts->fd);
+    }
 
   return 0;
 }
@@ -108,16 +111,15 @@ vt_udp_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
   uint32_t flags, flen;
   int rv;
 
-  ts->fd = vppcom_session_create (VPPCOM_PROTO_UDP, 0 /* is_nonblocking */);
+  ts->fd = vppcom_session_create (VPPCOM_PROTO_UDP, ts->noblk_connect);
   if (ts->fd < 0)
     {
       vterr ("vppcom_session_create()", ts->fd);
       return ts->fd;
     }
 
-  /* Connect is blocking */
   rv = vppcom_session_connect (ts->fd, endpt);
-  if (rv < 0)
+  if (rv < 0 && rv != VPPCOM_EINPROGRESS)
     {
       vterr ("vppcom_session_connect()", rv);
       return rv;
@@ -125,10 +127,14 @@ vt_udp_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
 
   ts->read = vcl_test_read;
   ts->write = vcl_test_write;
-  flags = O_NONBLOCK;
-  flen = sizeof (flags);
-  vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
-  vtinf ("Test session %d (fd %d) connected.", ts->session_index, ts->fd);
+
+  if (!ts->noblk_connect)
+    {
+      flags = O_NONBLOCK;
+      flen = sizeof (flags);
+      vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
+      vtinf ("Test session %d (fd %d) connected.", ts->session_index, ts->fd);
+    }
 
   return 0;
 }
@@ -282,7 +288,7 @@ vt_tls_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
   uint32_t flags, flen, ckp_len;
   int rv;
 
-  ts->fd = vppcom_session_create (VPPCOM_PROTO_TLS, 0 /* is_nonblocking */);
+  ts->fd = vppcom_session_create (VPPCOM_PROTO_TLS, ts->noblk_connect);
   if (ts->fd < 0)
     {
       vterr ("vppcom_session_create()", ts->fd);
@@ -293,9 +299,8 @@ vt_tls_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
   vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_CKPAIR, &vt->ckpair_index,
                       &ckp_len);
 
-  /* Connect is blocking */
   rv = vppcom_session_connect (ts->fd, endpt);
-  if (rv < 0)
+  if (rv < 0 && rv != VPPCOM_EINPROGRESS)
     {
       vterr ("vppcom_session_connect()", rv);
       return rv;
@@ -303,10 +308,14 @@ vt_tls_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
 
   ts->read = vcl_test_read;
   ts->write = vcl_test_write;
-  flags = O_NONBLOCK;
-  flen = sizeof (flags);
-  vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
-  vtinf ("Test session %d (fd %d) connected.", ts->session_index, ts->fd);
+
+  if (!ts->noblk_connect)
+    {
+      flags = O_NONBLOCK;
+      flen = sizeof (flags);
+      vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
+      vtinf ("Test session %d (fd %d) connected.", ts->session_index, ts->fd);
+    }
 
   return 0;
 }
@@ -387,7 +396,7 @@ vt_dtls_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
   uint32_t flags, flen, ckp_len;
   int rv;
 
-  ts->fd = vppcom_session_create (VPPCOM_PROTO_DTLS, 0 /* is_nonblocking */);
+  ts->fd = vppcom_session_create (VPPCOM_PROTO_DTLS, ts->noblk_connect);
   if (ts->fd < 0)
     {
       vterr ("vppcom_session_create()", ts->fd);
@@ -398,9 +407,8 @@ vt_dtls_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
   vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_CKPAIR, &vt->ckpair_index,
                       &ckp_len);
 
-  /* Connect is blocking */
   rv = vppcom_session_connect (ts->fd, endpt);
-  if (rv < 0)
+  if (rv < 0 && rv != VPPCOM_EINPROGRESS)
     {
       vterr ("vppcom_session_connect()", rv);
       return rv;
@@ -408,10 +416,14 @@ vt_dtls_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
 
   ts->read = vcl_test_read;
   ts->write = vcl_test_write;
-  flags = O_NONBLOCK;
-  flen = sizeof (flags);
-  vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
-  vtinf ("Test session %d (fd %d) connected.", ts->session_index, ts->fd);
+
+  if (!ts->noblk_connect)
+    {
+      flags = O_NONBLOCK;
+      flen = sizeof (flags);
+      vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
+      vtinf ("Test session %d (fd %d) connected.", ts->session_index, ts->fd);
+    }
 
   return 0;
 }
@@ -568,7 +580,7 @@ vt_quic_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
   /* Make sure qsessions are initialized */
   vt_quic_maybe_init_wrk (vt, wrk, endpt);
 
-  ts->fd = vppcom_session_create (VPPCOM_PROTO_QUIC, 0 /* is_nonblocking */);
+  ts->fd = vppcom_session_create (VPPCOM_PROTO_QUIC, ts->noblk_connect);
   if (ts->fd < 0)
     {
       vterr ("vppcom_session_create()", ts->fd);
@@ -579,21 +591,23 @@ vt_quic_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
   tq = &wrk->qsessions[ts->session_index / vt->cfg.num_test_sessions_perq];
 
   rv = vppcom_session_stream_connect (ts->fd, tq->fd);
-  if (rv < 0)
+  if (rv < 0 && rv != VPPCOM_EINPROGRESS)
     {
       vterr ("vppcom_session_stream_connect()", rv);
       return rv;
     }
 
-  flags = O_NONBLOCK;
-  flen = sizeof (flags);
-  vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
-
   ts->read = vcl_test_read;
   ts->write = vcl_test_write;
 
-  vtinf ("Test (quic stream) session %d (fd %d) connected.", ts->session_index,
-        ts->fd);
+  if (!ts->noblk_connect)
+    {
+      flags = O_NONBLOCK;
+      flen = sizeof (flags);
+      vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
+      vtinf ("Test (quic stream) session %d (fd %d) connected.",
+            ts->session_index, ts->fd);
+    }
 
   return 0;
 }
@@ -864,7 +878,7 @@ vt_srtp_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
   uint32_t flags, flen;
   int rv;
 
-  ts->fd = vppcom_session_create (VPPCOM_PROTO_SRTP, 0 /* is_nonblocking */);
+  ts->fd = vppcom_session_create (VPPCOM_PROTO_SRTP, ts->noblk_connect);
   if (ts->fd < 0)
     {
       vterr ("vppcom_session_create()", ts->fd);
@@ -873,9 +887,8 @@ vt_srtp_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
 
   vt_session_add_srtp_policy (ts, 1 /* is connect */);
 
-  /* Connect is blocking */
   rv = vppcom_session_connect (ts->fd, endpt);
-  if (rv < 0)
+  if (rv < 0 && rv != VPPCOM_EINPROGRESS)
     {
       vterr ("vppcom_session_connect()", rv);
       return rv;
@@ -883,10 +896,14 @@ vt_srtp_connect (vcl_test_session_t *ts, vppcom_endpt_t *endpt)
 
   ts->read = vt_srtp_read;
   ts->write = vt_srtp_write;
-  flags = O_NONBLOCK;
-  flen = sizeof (flags);
-  vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
-  vtinf ("Test session %d (fd %d) connected.", ts->session_index, ts->fd);
+
+  if (!ts->noblk_connect)
+    {
+      flags = O_NONBLOCK;
+      flen = sizeof (flags);
+      vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
+      vtinf ("Test session %d (fd %d) connected.", ts->session_index, ts->fd);
+    }
 
   vt_srtp_session_init (ts, 1 /* is connect */);