diff options
author | Uros Majstorovic <majstor@majstor.org> | 2018-01-20 19:15:13 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2018-01-20 19:15:13 +0100 |
commit | 30b62efc8f044a7fd00e21c56490aefa32686a52 (patch) | |
tree | d6574ec84c9213c5739dae91953f0bac81593c9e /code/test | |
parent | 3e50c4990f4703e2c04d0f959d33e36504d43716 (diff) |
added client timing test
Diffstat (limited to 'code/test')
-rw-r--r-- | code/test/Makefile | 7 | ||||
-rw-r--r-- | code/test/client.c | 58 | ||||
-rw-r--r-- | code/test/init_vconn.c | 4 | ||||
-rw-r--r-- | code/test/server.c | 26 | ||||
-rw-r--r-- | code/test/vc_client_t.c | 114 | ||||
-rw-r--r-- | code/test/vc_server.c | 4 |
6 files changed, 152 insertions, 61 deletions
diff --git a/code/test/Makefile b/code/test/Makefile index 5eeb6b7..ae400ee 100644 --- a/code/test/Makefile +++ b/code/test/Makefile @@ -7,7 +7,7 @@ dep=../ecp/build-posix/*.a ../util/libecputil.a %.o: %.c $(CC) $(CFLAGS) -c $< -all: basic client server echo frag stress vcs vc_server vc_client +all: basic client server echo frag stress vcs vc_server vc_client vc_client_t basic: basic.o init.o $(dep) $(CC) -o $@ $< init.o $(dep) $(LDFLAGS) @@ -36,6 +36,9 @@ vc_server: vc_server.o init_vconn.o $(dep) vc_client: vc_client.o init_vconn.o $(dep) $(CC) -o $@ $< init_vconn.o $(dep) $(LDFLAGS) +vc_client_t: vc_client_t.o init_vconn.o $(dep) + $(CC) -o $@ $< init_vconn.o $(dep) $(LDFLAGS) + opus_root=/opt/my/opus-1.1.5 voip.o: voip.c @@ -46,4 +49,4 @@ voip: voip.o init.o $(dep) clean: rm -f *.o - rm -f basic client server echo frag stress vcs vc_server vc_client voip + rm -f basic client server echo frag stress vcs vc_server vc_client vc_client_t voip diff --git a/code/test/client.c b/code/test/client.c index b8a2ba5..e6c8208 100644 --- a/code/test/client.c +++ b/code/test/client.c @@ -2,14 +2,13 @@ #include <string.h> #include <unistd.h> #include <stdlib.h> -#include <sys/time.h> #include "core.h" #include "util.h" -ECPContext ctx_c; -ECPSocket sock_c; -ECPConnHandler handler_c; +ECPContext ctx; +ECPSocket sock; +ECPConnHandler handler; ECPNode node; ECPConnection conn; @@ -17,11 +16,7 @@ ECPConnection conn; #define CTYPE_TEST 0 #define MTYPE_MSG 8 -int counter = 0; -uint64_t t_start = 0; -uint64_t t_end = 0; - -ssize_t handle_open_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { +ssize_t handle_open(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { uint32_t seq = 0; ecp_conn_handle_open(conn, sq, t, p, s, b); @@ -36,32 +31,11 @@ ssize_t handle_open_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsign strcpy((char *)buf, msg); ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, 1000); - struct timeval tv; - gettimeofday(&tv, NULL); - t_start = tv.tv_sec*(uint64_t)1000000+tv.tv_usec; - return s; } -ssize_t handle_msg_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { - counter++; - // printf("MSG C:%s size:%ld\n", p, s); - char *msg = "PERA JE CAR!"; - unsigned char buf[1000]; - - strcpy((char *)buf, msg); - ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, 1000); - - if (counter % 100 == 0) { - struct timeval tv; - uint64_t t_time; - - gettimeofday(&tv, NULL); - t_end = tv.tv_sec*(uint64_t)1000000+tv.tv_usec; - t_time = t_end - t_start; - printf("T:%f\n", (float)t_time/1000000); - t_start = t_end; - } +ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { + printf("MSG C:%s size:%ld\n", p, s); return s; } @@ -76,27 +50,27 @@ int main(int argc, char *argv[]) { if (argc != 2) usage(argv[0]); - rv = ecp_init(&ctx_c); + rv = ecp_init(&ctx); printf("ecp_init RV:%d\n", rv); - rv = ecp_conn_handler_init(&handler_c); - handler_c.msg[ECP_MTYPE_OPEN] = handle_open_c; - handler_c.msg[MTYPE_MSG] = handle_msg_c; - ctx_c.handler[CTYPE_TEST] = &handler_c; + rv = ecp_conn_handler_init(&handler); + handler.msg[ECP_MTYPE_OPEN] = handle_open; + handler.msg[MTYPE_MSG] = handle_msg; + ctx.handler[CTYPE_TEST] = &handler; - rv = ecp_sock_create(&sock_c, &ctx_c, NULL); + rv = ecp_sock_create(&sock, &ctx, NULL); printf("ecp_sock_create RV:%d\n", rv); - rv = ecp_sock_open(&sock_c, NULL); + rv = ecp_sock_open(&sock, NULL); printf("ecp_sock_open RV:%d\n", rv); - rv = ecp_start_receiver(&sock_c); + rv = ecp_start_receiver(&sock); printf("ecp_start_receiver RV:%d\n", rv); - rv = ecp_util_node_load(&ctx_c, &node, argv[1]); + rv = ecp_util_node_load(&ctx, &node, argv[1]); printf("ecp_util_node_load RV:%d\n", rv); - rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST); + rv = ecp_conn_create(&conn, &sock, CTYPE_TEST); printf("ecp_conn_create RV:%d\n", rv); rv = ecp_conn_open(&conn, &node); diff --git a/code/test/init_vconn.c b/code/test/init_vconn.c index 29c8db5..7e3dd04 100644 --- a/code/test/init_vconn.c +++ b/code/test/init_vconn.c @@ -31,12 +31,12 @@ static void conn_free(ECPConnection *conn) { int ecp_init(ECPContext *ctx) { int rv; - rv = ecp_ctx_create(ctx); + rv = ecp_ctx_create_vconn(ctx); if (rv) return rv; ctx->rng = v_rng; ctx->conn_alloc = conn_alloc; ctx->conn_free = conn_free; - return ecp_ctx_vconn_init(ctx); + return ECP_OK; }
\ No newline at end of file diff --git a/code/test/server.c b/code/test/server.c index e2001eb..f70cc79 100644 --- a/code/test/server.c +++ b/code/test/server.c @@ -6,15 +6,15 @@ #include "core.h" #include "util.h" -ECPContext ctx_s; -ECPSocket sock_s; -ECPDHKey key_perma_s; -ECPConnHandler handler_s; +ECPContext ctx; +ECPSocket sock; +ECPDHKey key_perma; +ECPConnHandler handler; #define CTYPE_TEST 0 #define MTYPE_MSG 8 -ssize_t handle_msg_s(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { +ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { printf("MSG S:%s size:%ld\n", p, s); char *msg = "VAISTINU JE CAR!"; @@ -36,23 +36,23 @@ int main(int argc, char *argv[]) { if (argc != 3) usage(argv[0]); - rv = ecp_init(&ctx_s); + rv = ecp_init(&ctx); printf("ecp_init RV:%d\n", rv); - rv = ecp_conn_handler_init(&handler_s); - handler_s.msg[MTYPE_MSG] = handle_msg_s; - ctx_s.handler[CTYPE_TEST] = &handler_s; + rv = ecp_conn_handler_init(&handler); + handler.msg[MTYPE_MSG] = handle_msg; + ctx.handler[CTYPE_TEST] = &handler; - rv = ecp_util_key_load(&ctx_s, &key_perma_s, argv[2]); + rv = ecp_util_key_load(&ctx, &key_perma, argv[2]); printf("ecp_util_key_load RV:%d\n", rv); - rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s); + rv = ecp_sock_create(&sock, &ctx, &key_perma); printf("ecp_sock_create RV:%d\n", rv); - rv = ecp_sock_open(&sock_s, argv[1]); + rv = ecp_sock_open(&sock, argv[1]); printf("ecp_sock_open RV:%d\n", rv); - rv = ecp_start_receiver(&sock_s); + rv = ecp_start_receiver(&sock); printf("ecp_start_receiver RV:%d\n", rv); while (1) sleep(1); diff --git a/code/test/vc_client_t.c b/code/test/vc_client_t.c new file mode 100644 index 0000000..54c657d --- /dev/null +++ b/code/test/vc_client_t.c @@ -0,0 +1,114 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/time.h> + +#include "core.h" +#include "vconn/vconn.h" +#include "util.h" + +ECPContext ctx; +ECPSocket sock; +ECPConnHandler handler; + +ECPNode node; +ECPConnection conn; + +ECPVConnection vconn[20]; +ECPNode vconn_node[20]; + +#define CTYPE_TEST 0 +#define MTYPE_MSG 8 + + +int counter = 0; +uint64_t t_start = 0; +uint64_t t_end = 0; +ssize_t handle_open(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { + uint32_t seq = 0; + + ecp_conn_handle_open(conn, sq, t, p, s, b); + if (s < 0) { + printf("OPEN ERR:%ld\n", s); + return s; + } + + char *msg = "PERA JE CAR!"; + unsigned char buf[1000]; + + strcpy((char *)buf, msg); + ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, 1000); + + struct timeval tv; + gettimeofday(&tv, NULL); + t_start = tv.tv_sec*(uint64_t)1000000+tv.tv_usec; + + return s; +} + +ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { + counter++; + // printf("MSG C:%s size:%ld\n", p, s); + char *msg = "PERA JE CAR!"; + unsigned char buf[1000]; + + strcpy((char *)buf, msg); + ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, strlen(msg)+1); + + if (counter % 100 == 0) { + struct timeval tv; + uint64_t t_time; + + gettimeofday(&tv, NULL); + t_end = tv.tv_sec*(uint64_t)1000000+tv.tv_usec; + t_time = t_end - t_start; + printf("T:%f\n", (float)t_time/1000000); + t_start = t_end; + } + return s; +} + +static void usage(char *arg) { + fprintf(stderr, "Usage: %s <server.pub> <vcs1.pub> ... <vcsn.pub>\n", arg); + exit(1); +} + +int main(int argc, char *argv[]) { + int rv, i; + + if ((argc < 3) || (argc > 22)) usage(argv[0]); + + rv = ecp_init(&ctx); + printf("ecp_init RV:%d\n", rv); + + rv = ecp_conn_handler_init(&handler); + handler.msg[ECP_MTYPE_OPEN] = handle_open; + handler.msg[MTYPE_MSG] = handle_msg; + ctx.handler[CTYPE_TEST] = &handler; + + rv = ecp_sock_create(&sock, &ctx, NULL); + printf("ecp_sock_create RV:%d\n", rv); + + rv = ecp_sock_open(&sock, NULL); + printf("ecp_sock_open RV:%d\n", rv); + + rv = ecp_start_receiver(&sock); + printf("ecp_start_receiver RV:%d\n", rv); + + rv = ecp_util_node_load(&ctx, &node, argv[1]); + printf("ecp_util_node_load RV:%d\n", rv); + + for (i=0; i<argc-2; i++) { + rv = ecp_util_node_load(&ctx, &vconn_node[i], argv[i+2]); + printf("ecp_util_node_load RV:%d\n", rv); + } + + rv = ecp_conn_create(&conn, &sock, CTYPE_TEST); + printf("ecp_conn_create RV:%d\n", rv); + + rv = ecp_vconn_open(&conn, &node, vconn, vconn_node, argc-2); + printf("ecp_vconn_open RV:%d\n", rv); + + while (1) sleep(1); +} diff --git a/code/test/vc_server.c b/code/test/vc_server.c index 04b8104..55f15d1 100644 --- a/code/test/vc_server.c +++ b/code/test/vc_server.c @@ -24,13 +24,13 @@ ssize_t handle_open(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned } ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { - printf("MSG S:%s size:%ld\n", p, s); + // printf("MSG S:%s size:%ld\n", p, s); char *msg = "VAISTINU JE CAR!"; unsigned char buf[1000]; strcpy((char *)buf, msg); - ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, 1000); + ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, strlen(msg)+1); return s; } |