(Sending on behalf of Thuan)
---
 src/mds/apitest/mdstest.c      |   5 +-
 src/mds/apitest/mdstipc.h      |   6 +-
 src/mds/apitest/mdstipc_api.c  | 237 +++++++++++++++++++++++++++++++++++++++++
 src/mds/apitest/mdstipc_conf.c |  19 ++--
 4 files changed, 253 insertions(+), 14 deletions(-)

diff --git a/src/mds/apitest/mdstest.c b/src/mds/apitest/mdstest.c
index bf6e173..a381aad 100644
--- a/src/mds/apitest/mdstest.c
+++ b/src/mds/apitest/mdstest.c
@@ -84,12 +84,13 @@ int main(int argc, char **argv)
                return 0;
        }
 
-       if (mds_startup() != 0) {
+       if ((suite != 27) && (mds_startup() != 0)) {
                printf("Fail to start mds agents\n");
                return 1;
        }
 
        int rc = test_run(suite, tcase);
-       mds_shutdown();
+       if (suite != 27)
+               mds_shutdown();
        return rc;
 }
diff --git a/src/mds/apitest/mdstipc.h b/src/mds/apitest/mdstipc.h
index 07cf556..2bd44b4 100644
--- a/src/mds/apitest/mdstipc.h
+++ b/src/mds/apitest/mdstipc.h
@@ -20,6 +20,7 @@
 
 #include "base/ncssysf_tsk.h"
 #include "base/ncssysf_def.h"
+#include "base/ncsencdec_pub.h"
 
 typedef struct tet_task {
   NCS_OS_CB entry;
@@ -163,9 +164,6 @@ int gl_DEC_FLAT_CB_FAIL;
 int gl_RECEIVE_CB_FAIL;
 int gl_COPY_CB_FAIL;
 
-uint32_t ncs_encode_16bit(uint8_t **, uint32_t);
-uint16_t ncs_decode_16bit(uint8_t **);
-
 uint32_t tet_mds_svc_callback(NCSMDS_CALLBACK_INFO *);
 /******************MDS call back routines *********************************/
 uint32_t tet_mds_cb_cpy(NCSMDS_CALLBACK_INFO *);
@@ -528,5 +526,7 @@ uint32_t mds_send_get_redack(MDS_HDL mds_hdl, MDS_SVC_ID 
svc_id,
 uint32_t mds_send_redrsp_getack(MDS_HDL mds_hdl, MDS_SVC_ID svc_id,
                                 int64_t time_to_wait, TET_MDS_MSG *response);
 uint32_t tet_sync_point(void);
+int mds_startup(void);
+int mds_shutdown(void);
 
 #endif  // MDS_APITEST_MDSTIPC_H_
diff --git a/src/mds/apitest/mdstipc_api.c b/src/mds/apitest/mdstipc_api.c
index b5547e3..8057284 100644
--- a/src/mds/apitest/mdstipc_api.c
+++ b/src/mds/apitest/mdstipc_api.c
@@ -27,6 +27,7 @@
 #include "base/ncs_main_papi.h"
 #include "mdstipc.h"
 #include "base/ncssysf_tmr.h"
+#include "base/osaf_poll.h"
 
 #define MSG_SIZE MDS_DIRECT_BUF_MAXSIZE
 static MDS_CLIENT_MSG_FORMAT_VER gl_set_msg_fmt_ver;
@@ -13104,6 +13105,234 @@ void tet_create_default_PWE_VDEST_tp()
        test_validate(FAIL, 0);
 }
 
+void tet_sender(char *send_buff, uint32_t buff_len, int msg_count)
+{
+       int live = 100; // sender live max 100s
+       TET_MDS_MSG *mesg;
+       mesg = (TET_MDS_MSG *)malloc(sizeof(TET_MDS_MSG));
+       memset(mesg, 0, sizeof(TET_MDS_MSG));
+
+       printf("\nStarted Sender (pid:%d) svc_id=%d\n",
+                       (int)getpid(), NCSMDS_SVC_ID_INTERNAL_MIN);
+       if (adest_get_handle() != NCSCC_RC_SUCCESS) {
+               printf("\n: Sender FAIL to get adest handle\n");
+               exit(1);
+       }
+
+       if (mds_service_install(gl_tet_adest.mds_pwe1_hdl,
+                               NCSMDS_SVC_ID_INTERNAL_MIN, 1,
+                               NCSMDS_SCOPE_NONE, false, false) != 
NCSCC_RC_SUCCESS) {
+               printf("\nSender FAIL to install the service\n");
+               exit(1);
+       }
+
+       MDS_SVC_ID svcids[] = {NCSMDS_SVC_ID_EXTERNAL_MIN};
+       if (mds_service_subscribe(
+               gl_tet_adest.mds_pwe1_hdl, NCSMDS_SVC_ID_INTERNAL_MIN,
+               NCSMDS_SCOPE_INTRANODE, 1, svcids) != NCSCC_RC_SUCCESS) {
+               printf("\nSender FAIL to subscribe receiver\n");
+               exit(1);
+       }
+
+       while(!gl_tet_adest.svc[0].svcevt[0].dest && live-- > 0) {
+               printf("\nSender is waiting for receiver UP\n");
+               sleep(1);
+       }
+       printf("\nSender got last event=%d of svc_id=%d dest=<%llx>\n",
+                       gl_tet_adest.svc[0].svcevt[0].event,
+                       gl_tet_adest.svc[0].svcevt[0].svc_id,
+                       gl_tet_adest.svc[0].svcevt[0].dest);
+
+       // wait for receiver subscribe sender
+       // otherwise, receiver won't detect loss message
+       sleep(1);
+
+       uint32_t offset = 0;
+       uint32_t msg_len = buff_len / msg_count;
+       for (int i = 1; i <= msg_count; i++) {
+               memcpy(mesg->send_data, &send_buff[offset], msg_len);
+               mesg->send_len = msg_len;
+               if (mds_just_send(gl_tet_adest.mds_pwe1_hdl,
+                                 NCSMDS_SVC_ID_INTERNAL_MIN,
+                                 NCSMDS_SVC_ID_EXTERNAL_MIN,
+                                 gl_tet_adest.svc[0].svcevt[0].dest,
+                                 MDS_SEND_PRIORITY_HIGH,
+                                 mesg) != NCSCC_RC_SUCCESS) {
+                       printf("\nSender FAIL send message\n");
+                       exit(1);
+               } else {
+                       printf("\nSender SENT message %d successfully\n", i);
+               }
+               offset += msg_len;
+       }
+       free(mesg);
+       while(live-- > 0) {
+               // Keep sender alive for retransmission
+               sleep(1);
+       }
+}
+
+bool tet_receiver(char *expected_buff, uint32_t buff_len, int msg_count)
+{
+       int ret = 1;
+       printf("\nStarted Receiver (pid:%d) svc_id=%d\n",
+                       (int)getpid(), NCSMDS_SVC_ID_EXTERNAL_MIN);
+       if (adest_get_handle() != NCSCC_RC_SUCCESS) {
+               printf("\nReceiver FAIL to get adest handle\n");
+               return ret;
+       }
+
+       sleep(1); //Let sender subscribe before receiver install
+       if (mds_service_install(gl_tet_adest.mds_pwe1_hdl,
+                               NCSMDS_SVC_ID_EXTERNAL_MIN, 1,
+                               NCSMDS_SCOPE_NONE, true, false) != 
NCSCC_RC_SUCCESS) {
+               printf("\nReceiver FAIL to install the service\n");
+       }
+
+       MDS_SVC_ID svcids[] = {NCSMDS_SVC_ID_INTERNAL_MIN};
+       if (mds_service_subscribe(
+               gl_tet_adest.mds_pwe1_hdl, NCSMDS_SVC_ID_EXTERNAL_MIN,
+               NCSMDS_SCOPE_INTRANODE, 1, svcids) != NCSCC_RC_SUCCESS) {
+               printf("\nReceiver FAIL to subscribe sender\n");
+               exit(1);
+       }
+
+       char *received_buff = malloc(buff_len);
+       memset(received_buff, 0, buff_len);
+       uint32_t offset = 0;
+       struct pollfd sel;
+       int counter = 0;
+       sel.fd = m_GET_FD_FROM_SEL_OBJ(gl_tet_adest.svc[0].sel_obj);
+       sel.events = POLLIN;
+       while(counter < msg_count) {
+               int ret = osaf_poll(&sel, 1, 10000);
+               if (ret > 0) {
+                       gl_rcvdmsginfo.msg = NULL;
+                       if (mds_service_retrieve(gl_tet_adest.mds_pwe1_hdl,
+                                                NCSMDS_SVC_ID_EXTERNAL_MIN,
+                                                SA_DISPATCH_ONE) != 
NCSCC_RC_SUCCESS) {
+                               printf("\nReceiver FAIL to retrieve message\n");
+                               break;
+                       }
+                       TET_MDS_MSG *msg = (TET_MDS_MSG*)gl_rcvdmsginfo.msg;
+                       if (msg != NULL) {
+                               memcpy(&received_buff[offset],msg->recvd_data, 
msg->recvd_len);
+                               offset += msg->recvd_len;
+                               counter++;
+                       }
+               } else {
+                       printf("\nReceiver got %d messages\n", counter);
+                       printf("\nReceiver poll FAIL\n");
+                       break;
+               }
+       }
+
+       printf("\nReceiver verify received buffer is same as expected\n");
+       if (offset == buff_len) {
+               if (memcmp(received_buff, expected_buff, buff_len) != 0) {
+                       printf("\nReceiver: Received buffer is not as 
expected\n");
+                       printf("\nReceiver: Dump buffer to /var/log/opensaf/ 
\n");
+                       FILE *fp = 
fopen("/var/log/opensaf/mdstest_received_buff","wb");
+                       fwrite(received_buff, sizeof(char), buff_len, fp);
+                       fclose(fp);
+                       fp = fopen("/var/log/opensaf/mdstest_expect_buff","wb");
+                       fwrite(expected_buff, sizeof(char), buff_len, fp);
+                       fclose(fp);
+               } else {
+                       ret = 0;
+               }
+       } else {
+               printf("\nReceiver: Total received length=%d differ expected 
%d\n", offset, buff_len);
+       }
+       free(received_buff);
+       printf("\nEnd Receiver (pid:%d) svc_id=%d\n",
+                       (int)getpid(), NCSMDS_SVC_ID_EXTERNAL_MIN);
+       return ret;
+}
+
+void tet_overload_tp_1(void)
+{
+       int pid = 0;
+       int FAIL = 0;
+       uint32_t buff_len = 100000000;
+       int msg_count = 2000;
+       int msg_size = buff_len/msg_count;
+       char *buff = malloc(buff_len);
+
+       for (unsigned int i = 0; i < msg_count; i++) {
+               /* to verify received correct order */
+               memset(buff+(i*msg_size), 'X', msg_size);
+               sprintf(buff+(i*msg_size), "%u", i+1);
+       }
+
+       printf("\nTest Case 1: Receiver wait for drop normal message retransmit 
and receive all messages in order\n");
+       /*--------------------------------------------------------------------*/
+       pid = fork();
+       if (pid == 0) {
+               /* child as sender */
+               setenv("MDS_TIPC_FCTRL_ENABLED", "1", 1);
+               mds_startup();
+               tet_sender(buff, buff_len, msg_count);
+               mds_shutdown();
+       } else if (pid > 0) {
+               /* parent as receiver */
+               setenv("MDS_TIPC_FCTRL_ENABLED", "1", 1);
+               mds_startup();
+               FAIL = tet_receiver(buff, buff_len, msg_count);
+               printf("\nReceiver finish, kill Sender\n");
+               kill(pid, SIGKILL);
+               mds_shutdown();
+       } else {
+               /* fork() error */
+               printf("\nFAIL to fork()\n");
+               FAIL = 1;
+       }
+
+       free(buff);
+       test_validate(FAIL, 0);
+}
+
+void tet_overload_tp_2(void)
+{
+       int pid = 0;
+       int FAIL = 0;
+       uint32_t buff_len = 100000000;
+       int msg_count = 1000;
+       int msg_size = buff_len/msg_count;
+       char *buff = malloc(buff_len);
+
+       for (unsigned int i = 0; i < msg_count; i++) {
+               /* to verify received correct order */
+               memset(buff+(i*msg_size), 'X', msg_size);
+               sprintf(buff+(i*msg_size), "%u", i+1);
+       }
+
+       printf("\nTest Case 2: Receiver wait for drop fragment message 
retransmit and receive all messages in order\n");
+       /*--------------------------------------------------------------------*/
+       pid = fork();
+       if (pid == 0) {
+               /* child as sender */
+               setenv("MDS_TIPC_FCTRL_ENABLED", "1", 1);
+               mds_startup();
+               tet_sender(buff, buff_len, msg_count);
+               mds_shutdown();
+       } else if (pid > 0) {
+               /* parent as receiver */
+               setenv("MDS_TIPC_FCTRL_ENABLED", "1", 1);
+               mds_startup();
+               FAIL = tet_receiver(buff, buff_len, msg_count);
+               kill(pid, SIGKILL);
+               mds_shutdown();
+       } else {
+               /* fork() error */
+               printf("\nFAIL to fork()\n");
+               FAIL = 1;
+       }
+
+       free(buff);
+       test_validate(FAIL, 0);
+}
+
 void Print_return_status(uint32_t rs)
 {
        switch (rs) {
@@ -13821,4 +14050,12 @@ __attribute__((constructor)) static void 
mdsTipcAPI_constructor(void)
                      "create_PWE_upto_MAX_VDEST");
        test_case_add(26, tet_create_default_PWE_VDEST_tp,
                      "create_default_PWE_VDEST");
+
+       test_suite_add(27, "MDS TIPC OVERLOAD Test");
+       test_case_add(
+               27, tet_overload_tp_1,
+               "Receiver wait for drop normal message retransmit and receive 
all messages in order");
+       test_case_add(
+               27, tet_overload_tp_2,
+               "Receiver wait for drop fragment message retransmit and receive 
all messages in order");
 }
diff --git a/src/mds/apitest/mdstipc_conf.c b/src/mds/apitest/mdstipc_conf.c
index bf4c1de..4556df5 100644
--- a/src/mds/apitest/mdstipc_conf.c
+++ b/src/mds/apitest/mdstipc_conf.c
@@ -1924,14 +1924,15 @@ uint32_t tet_mds_cb_enc_flat(NCSMDS_CALLBACK_INFO 
*mds_to_svc_info)
        mds_to_svc_info->info.enc_flat.o_msg_fmt_ver =
            mds_to_svc_info->info.enc_flat.i_rem_svc_pvt_ver;
        printf(
-           "Flat encoding the message sent from Sender svc = %d with 
msg_fmt_ver=%d\n",
+           "Flat encoding the message sent (length=%d) from Sender svc = %d 
with msg_fmt_ver=%d\n",
+           msg->send_len,
            mds_to_svc_info->i_yr_svc_id,
            mds_to_svc_info->info.enc_flat.o_msg_fmt_ver);
 
        /* ENCODE length */
-       p8 = ncs_enc_reserve_space(mds_to_svc_info->info.enc_flat.io_uba, 2);
-       ncs_encode_16bit(&p8, msg->send_len);
-       ncs_enc_claim_space(mds_to_svc_info->info.enc_flat.io_uba, 2);
+       p8 = ncs_enc_reserve_space(mds_to_svc_info->info.enc_flat.io_uba, 
sizeof(uint32_t));
+       ncs_encode_32bit(&p8, msg->send_len);
+       ncs_enc_claim_space(mds_to_svc_info->info.enc_flat.io_uba, 
sizeof(uint32_t));
 
        /* ENCODE data */
        ncs_encode_n_octets_in_uba(mds_to_svc_info->info.enc_flat.io_uba,
@@ -1962,9 +1963,9 @@ uint32_t tet_mds_cb_dec_flat(NCSMDS_CALLBACK_INFO 
*mds_to_svc_info)
 
        /* DECODE length */
        p8 = ncs_dec_flatten_space(mds_to_svc_info->info.dec_flat.io_uba,
-                                  (uint8_t *)&msg->recvd_len, 2);
-       msg->recvd_len = ncs_decode_16bit(&p8);
-       ncs_dec_skip_space(mds_to_svc_info->info.dec_flat.io_uba, 2);
+                                  (uint8_t *)&msg->recvd_len, 
sizeof(uint32_t));
+       msg->recvd_len = ncs_decode_32bit(&p8);
+       ncs_dec_skip_space(mds_to_svc_info->info.dec_flat.io_uba, 
sizeof(uint32_t));
 
        /*Decode data*/
        /*msg->recvd_data = (char *) malloc(msg->recvd_len+1);*/
@@ -1974,9 +1975,9 @@ uint32_t tet_mds_cb_dec_flat(NCSMDS_CALLBACK_INFO 
*mds_to_svc_info)
                                     msg->recvd_len);
        msg->recvd_data[msg->recvd_len] = 0; /* NULL termination for string */
        if (mds_to_svc_info->info.dec_flat.i_is_resp)
-               printf("\nThis is a RESPONSE");
+               printf("\nThis is a RESPONSE (length=%d)", msg->recvd_len);
        else
-               printf("\nThis is a MESSAGE");
+               printf("\nThis is a MESSAGE (length=%d)", msg->recvd_len);
 
        return NCSCC_RC_SUCCESS;
 }
-- 
2.7.4



_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to