]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Added ping-pong test
authorMartin Molnar <molnam1@fel.cvut.cz>
Wed, 11 Mar 2009 01:06:55 +0000 (02:06 +0100)
committerMartin Molnar <molnam1@fel.cvut.cz>
Wed, 11 Mar 2009 01:06:55 +0000 (02:06 +0100)
frsh_api/tests/Makefile.omk
frsh_api/tests/pingpong/Makefile [new file with mode: 0644]
frsh_api/tests/pingpong/ping.c [new file with mode: 0644]
frsh_api/tests/pingpong/pong.c [new file with mode: 0644]
frsh_api/tests/pingpong/test_config.h [new file with mode: 0644]

index 5b377851b4e2799453b854ed7c7380e57b0e6930..b03c9ee9ca44736f799afe1959413780dffc25a1 100644 (file)
@@ -4,7 +4,7 @@ negotiation_SOURCES = negotiation.c
 lib_LOADLIBES += pthread rt frsh 
 
 ifeq ($(CONFIG_FWP),y)
-SUBDIRS= fwptest
+SUBDIRS= fwptest pingpong
 
 test_PROGRAMS += distributed distributed2 
 distributed_SOURCES+= distributed.c
diff --git a/frsh_api/tests/pingpong/Makefile b/frsh_api/tests/pingpong/Makefile
new file mode 100644 (file)
index 0000000..b22a357
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/frsh_api/tests/pingpong/ping.c b/frsh_api/tests/pingpong/ping.c
new file mode 100644 (file)
index 0000000..c9a4700
--- /dev/null
@@ -0,0 +1,181 @@
+/**
+ * \file fwpsender.c  
+ *
+ */
+#include <frsh.h>
+#include "test_config.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <pthread.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+char msg[MSGBUFFSIZE];
+
+frsh_resource_id_t resource_id = TEST_RESOURCE_ID;
+frsh_stream_id_t stream_id = TEST_STREAM_ID;
+long int num_msg = TEST_NUM_MSG;
+size_t msg_size = MSGBUFFSIZE;
+
+int exit_flag = 0;
+int node_id = 0;
+
+inline void timespec_sub(struct timespec *diff, const struct timespec *left,
+             const struct timespec *right)
+{
+       diff->tv_sec = left->tv_sec - right->tv_sec;
+       diff->tv_nsec = left->tv_nsec - right->tv_nsec;
+
+       if (diff->tv_nsec < 0){
+                 --diff->tv_sec;
+                 diff->tv_nsec += 1000000000;
+       }
+}
+
+void* sender(void * arg)
+{
+       frsh_send_endpoint_t sepoint;
+       frsh_vres_id_t vres;
+       frsh_send_endpoint_protocol_info_t send_pinfo;
+       frsh_contract_t contract;
+       frsh_rel_time_t budget, period;
+       int count, ret;
+       struct timespec  sendtime;
+
+       send_pinfo.body = NULL;         
+       if (frsh_send_endpoint_create(resource_id, node_id, stream_id, 
+                                       send_pinfo, &sepoint)< 0) {
+               return NULL;
+       }
+       
+       /* Contract negotiation */
+       ret = frsh_contract_init(&contract);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
+               
+       frsh_network_bytes_to_budget(resource_id, msg_size, &budget);
+       period = fosa_msec_to_rel_time(1000);
+       ret = frsh_contract_set_basic_params(&contract,
+                                            &budget,
+                                            &period,
+                                            FRSH_WT_BOUNDED,
+                                            FRSH_CT_REGULAR);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+       ret = frsh_contract_set_resource_and_label(&contract,FRSH_RT_NETWORK,
+                                               resource_id, "net_cont1");
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+
+       ret = frsh_contract_negotiate(&contract, &vres);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
+       
+       printf("Send endpoint created\n");
+       frsh_send_endpoint_bind(vres, sepoint);
+       printf("Send endpoint bounded\n");
+       
+       sleep(2);
+       //fwp_set_rt_prio(90);
+       
+       count = 1;
+       while (count != num_msg) {
+               count++;
+               clock_gettime(CLOCK_MONOTONIC, &sendtime);
+               sprintf(msg,"msg%d-%ld-%ld", count, 
+                               sendtime.tv_sec, sendtime.tv_nsec);
+               frsh_send_async(sepoint, msg, msg_size);
+
+               printf("%s sent\n",msg);        
+       }
+       
+       /* TODO: destroy vres and send enpoint */
+       
+       while (!(exit_flag)) {
+               sleep(1);
+       }
+       
+       return NULL;
+} 
+
+void* receiver()
+{
+    size_t len;
+       frsh_receive_endpoint_t repoint;
+       int count;
+       frsh_network_address_t  from;
+       frsh_receive_endpoint_protocol_info_t recv_pinfo;
+       frsh_endpoint_queueing_info_t qinfo;
+       struct timespec recvtime;
+       struct timespec sendtime;
+       struct timespec difftime;
+       
+       recv_pinfo.body = NULL;
+       /* local_addr should be handled when creating socket */
+       if (frsh_receive_endpoint_create(resource_id, stream_id, qinfo, recv_pinfo, 
+                       &repoint) != 0){
+               return NULL;
+       }
+       printf("Receive endpoint created\n");
+       
+       count = 1;
+       while (count != num_msg){
+               count++;
+               if ((frsh_receive_sync(repoint, msg, msg_size, &len, 
+                       &from))) {
+                               perror("Error while receiving data");
+                               return NULL;
+               } 
+               
+               sscanf(msg,"msg%d-%ld-%ld", &count, 
+                               &sendtime.tv_sec, &sendtime.tv_nsec);
+               clock_gettime(CLOCK_MONOTONIC, &recvtime);
+               timespec_sub(&difftime, &recvtime, &sendtime);  
+               printf("Received - %s\n time= %ld us", msg, 
+                               difftime.tv_nsec / 1000);
+       }
+       
+       /* TODO: destroy vres and send enpoint */
+
+       return NULL;
+}
+
+int main(int argc, char* argv[])
+{
+       pthread_attr_t  thattr;
+       pthread_t       thread;
+       int opt;
+       int ret;
+
+       opterr = 0;
+       while ((opt = getopt (argc, argv, "n:p:s:m:")) != -1) {
+
+               switch (opt) {
+                       case 'n':
+                               node_id = inet_addr(optarg);
+                               break;
+                       case 'p':
+                               stream_id = atoi(optarg);
+                               break;
+                       case 'm':
+                               num_msg = atoi(optarg);
+                               break;
+                       case 's':
+                               msg_size = atoi(optarg);
+                               break;
+                       case '?':
+                               printf("Usage: %s -n node_id -p stream_id"
+                                               "-m num_msg -s msg_size\n", 
+                                               argv[0]); 
+               }
+       }
+       
+       ret = frsh_init();
+       if (ret) PERROR_AND_EXIT(ret, "frsh_init");
+       
+       pthread_attr_init(&thattr);
+       pthread_create(&thread, &thattr, sender, NULL); 
+       pthread_join(thread, (void**) NULL);    
+
+       printf("Test PASSED!\n");
+       return 0;
+}
diff --git a/frsh_api/tests/pingpong/pong.c b/frsh_api/tests/pingpong/pong.c
new file mode 100644 (file)
index 0000000..9c005c1
--- /dev/null
@@ -0,0 +1,134 @@
+#include <frsh.h>
+#include "test_config.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <pthread.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+char msg[MSGBUFFSIZE];
+
+frsh_resource_id_t resource_id = TEST_RESOURCE_ID;
+frsh_stream_id_t stream_id = TEST_STREAM_ID;
+long int num_msg = TEST_NUM_MSG;
+size_t msg_size = MSGBUFFSIZE;
+
+frsh_send_endpoint_t sepoint;
+frsh_vres_id_t vres;
+
+void 
+create_send_endpoint(frsh_network_address_t node_id, frsh_stream_id_t stream_id)
+{
+       frsh_send_endpoint_protocol_info_t send_pinfo;
+       frsh_contract_t contract;
+       frsh_rel_time_t budget, period;
+       int ret;
+
+       send_pinfo.body = NULL;         
+       if (frsh_send_endpoint_create(resource_id, node_id, stream_id, 
+                                       send_pinfo, &sepoint) < 0) {
+               return;
+       }
+       
+       /* Contract negotiation */
+       ret = frsh_contract_init(&contract);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
+               
+       frsh_network_bytes_to_budget(resource_id, msg_size, &budget);
+       period = fosa_msec_to_rel_time(1000);
+       ret = frsh_contract_set_basic_params(&contract,
+                                            &budget,
+                                            &period,
+                                            FRSH_WT_BOUNDED,
+                                            FRSH_CT_REGULAR);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+       ret = frsh_contract_set_resource_and_label(&contract,FRSH_RT_NETWORK,
+                                               resource_id, "net_cont1");
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+
+       ret = frsh_contract_negotiate(&contract, &vres);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
+       
+       printf("Send endpoint created\n");
+       frsh_send_endpoint_bind(vres, sepoint);
+       printf("Send endpoint bounded\n");
+} 
+
+void* receiver()
+{
+       size_t len;
+       frsh_receive_endpoint_t repoint;
+       int count;
+       //struct timespec recvtime;
+       frsh_network_address_t  from;
+       frsh_receive_endpoint_protocol_info_t recv_pinfo;
+       frsh_endpoint_queueing_info_t qinfo;
+       int first = 1;
+       
+       recv_pinfo.body = NULL;
+       /* local_addr should be handled when creating socket */
+       if (frsh_receive_endpoint_create(resource_id, stream_id, qinfo, recv_pinfo, 
+                       &repoint) != 0){
+               return NULL;
+       }
+       printf("Receive endpoint created\n");
+       
+       count = 1;
+       while (count != num_msg){
+               count++;
+               if ((frsh_receive_sync(repoint, msg, msg_size, &len, 
+                       &from))){
+                               perror("Error while receiving data");
+                               return NULL;
+               } 
+               
+               if (first) {
+                       create_send_endpoint(from, stream_id);
+                       first = 0;
+               }
+
+               frsh_send_async(sepoint, msg, msg_size);
+               printf("pong - %s\n", msg);
+       }
+       
+       /* TODO: destroy vres and send enpoint */
+
+       return NULL;
+}
+
+int main(int argc, char* argv[])
+{
+       pthread_attr_t  thattr;
+       pthread_t       thread;
+       int ret;
+       int opt;
+       
+       opterr = 0;
+
+       while ((opt = getopt (argc, argv, "p:m:")) != -1) {
+
+               switch (opt) {
+                       case 'p':
+                               stream_id = atoi(optarg);
+                               break;
+                       case 'm':
+                               num_msg = atoi(optarg);
+                       case '?':
+                               printf("Usage: %s -p stream_id -m num_msg\n", 
+                                               argv[0]); 
+               }
+       }
+       
+       ret = frsh_init();
+       if (ret) PERROR_AND_EXIT(ret, "frsh_init");
+       
+       pthread_attr_init(&thattr);
+       pthread_create(&thread, &thattr, receiver, NULL); 
+       pthread_join(thread, (void**) NULL);    
+
+       printf("Test PASSED!\n");
+       return 0;
+}
diff --git a/frsh_api/tests/pingpong/test_config.h b/frsh_api/tests/pingpong/test_config.h
new file mode 100644 (file)
index 0000000..46376d0
--- /dev/null
@@ -0,0 +1,23 @@
+/**
+ * The test:
+ * - creates vres 
+ * - creates send and receive endpoint 
+ * - binds that endpoint to vres
+ * - in cycle (NUM loops) sends/receives messages
+ * - destroys vres
+ *
+ */
+#ifndef TEST_CONFIG_H
+#define TEST_CONFIG_H
+
+#include <frsh.h>
+
+#define        MSGBUFFSIZE 65000
+#define TEST_RESOURCE_ID FRSH_NETPF_FWP
+#define TEST_STREAM_ID 65111
+/* Number of test messages sent/received
+ * 0 - infinite
+ */
+#define TEST_NUM_MSG 40 
+
+#endif /* TEST_CONFIG_H */