From 0e26fd4cc682f0bcd3e94a42c823b3465a0ad2e2 Mon Sep 17 00:00:00 2001 From: Davi Luna Date: Sun, 4 Aug 2024 01:49:11 -0300 Subject: [PATCH] time to connection and initial documentation to test --- .../{descricao.txt => teste_tcp_tls.txt} | 24 +++++++++++++++---- .../teste/installing_compile_project.sh | 2 ++ .../teste/quic/pub/publisher.c | 20 ++++++++++++++-- .../teste/tcp/pub/mqtt_client.c | 21 ++++++++++++++++ .../pub_sub_hiredis/teste/tcp/pub_tls/tls.c | 23 +++++++++++++++++- 5 files changed, 83 insertions(+), 7 deletions(-) rename fases/implementacao/pub_sub_hiredis/teste/Analise/validacao/{descricao.txt => teste_tcp_tls.txt} (56%) diff --git a/fases/implementacao/pub_sub_hiredis/teste/Analise/validacao/descricao.txt b/fases/implementacao/pub_sub_hiredis/teste/Analise/validacao/teste_tcp_tls.txt similarity index 56% rename from fases/implementacao/pub_sub_hiredis/teste/Analise/validacao/descricao.txt rename to fases/implementacao/pub_sub_hiredis/teste/Analise/validacao/teste_tcp_tls.txt index f99a9c9..ae30355 100644 --- a/fases/implementacao/pub_sub_hiredis/teste/Analise/validacao/descricao.txt +++ b/fases/implementacao/pub_sub_hiredis/teste/Analise/validacao/teste_tcp_tls.txt @@ -1,4 +1,9 @@ +Observações: + +* O tempo de 50 milisegundos +* O tamanho do pacote pode ser estudado usando o wireshark com os pacotes obtidos com tcpdump + Teste 1 com MQTT/TCP: @@ -17,10 +22,10 @@ tcpdump -ni enp0s3 port 1883 -w 1kpackets_tcp_50ms.pcap No publisher: -./publisher mqtt-tcp://10.35.5.57:1883 0 1000_packets_50ms_tcp 1000 50 +./publisher mqtt-tcp://192.168.56.102:1883 0 1000_packets_50ms_tcp 50 1000 No subscriber: -./sub sub "mqtt-tcp://10.35.5.57:1883" 0 1000_packets_50ms_tcp 1000_packets_50ms_tcp +./sub sub "mqtt-tcp://192.168.56.102:1883" 0 1000_packets_50ms_tcp 1000_packets_50ms_tcp @@ -41,9 +46,20 @@ tcpdump -ni enp0s3 port 1883 -w 10kpackets_tcp_50ms.pcap No publisher: -./publisher mqtt-tcp://10.35.5.57:1883 0 10000_packets_50ms_tcp 10000 50 +./publisher mqtt-tcp://192.168.56.102:1883 0 10000_packets_50ms_tcp 50 10000 No subscriber: -./sub sub "mqtt-tcp://10.35.5.57:1883" 0 10000_packets_50ms_quic 10000_packets_50ms_tcp +./sub sub "mqtt-tcp://192.168.56.102:1883" 0 10000_packets_50ms_tcp 10000_packets_50ms_tcp + + + + + + + + + +Teste 3 com MQTT/TLS +./tls -u tls++mqtt-tcp://192.168.56.102:8883 -t 1000_packets_50ms_tls \ No newline at end of file diff --git a/fases/implementacao/pub_sub_hiredis/teste/installing_compile_project.sh b/fases/implementacao/pub_sub_hiredis/teste/installing_compile_project.sh index 9805048..d051c9a 100644 --- a/fases/implementacao/pub_sub_hiredis/teste/installing_compile_project.sh +++ b/fases/implementacao/pub_sub_hiredis/teste/installing_compile_project.sh @@ -26,6 +26,8 @@ dependencies=( libc6-dev gcc-multilib python3-pip + libgconf2-dev + ntp # para sincronização de tempo ) # Verifica e instala cada dependência diff --git a/fases/implementacao/pub_sub_hiredis/teste/quic/pub/publisher.c b/fases/implementacao/pub_sub_hiredis/teste/quic/pub/publisher.c index 9f1fa25..ff12dd1 100644 --- a/fases/implementacao/pub_sub_hiredis/teste/quic/pub/publisher.c +++ b/fases/implementacao/pub_sub_hiredis/teste/quic/pub/publisher.c @@ -27,6 +27,8 @@ static nng_socket * g_sock; #define SUB 2 #define PUB 3 +double time_connection; + conf_quic config_user = { .tls = { .enable = false, @@ -183,10 +185,22 @@ client(int type, const char *url, const char *qos, const char *topic, const char printf("error in quic client cb set.\n"); } g_sock = &sock; + + //Teste para descobrir o tempo de envio da mensagem de conexão + // MQTT Connect... msg = mqtt_msg_compose(CONN, 0, NULL, NULL); + // Marcar o início do tempo + struct timespec start_time, end_time; + clock_gettime(CLOCK_REALTIME, &start_time); nng_sendmsg(sock, msg, NNG_FLAG_ALLOC); - + clock_gettime(CLOCK_REALTIME, &end_time); + // Calcular a diferença + long seconds = end_time.tv_sec - start_time.tv_sec; + long nanoseconds = end_time.tv_nsec - start_time.tv_nsec; + double elapsed = seconds + nanoseconds*1e-9; + time_connection = elapsed; + printf("Time taken to connect: %.9f seconds\n", elapsed); if (qos) { q = atoi(qos); @@ -236,7 +250,8 @@ client(int type, const char *url, const char *qos, const char *topic, const char sqlite_config(&sock, MQTT_PROTOCOL_VERSION_v311); #endif - printf("terminou o envio\n"); + printf("terminou o envio\n"); + printf("Time taken to connect: %.9f seconds\n", time_connection); //nng_msleep(0); nng_close(sock);//aqui demora um pouco pois ele está desalocando os recursos fprintf(stderr, "Done.\n"); @@ -260,6 +275,7 @@ int main(int argc, char **argv) { //client(PUB, argv[1], argv[2], argv[3], argv[4], argv[5]); client(PUB, argv[1], argv[2], argv[3], argv[4], argv[5]); + //printf("Time taken to connect: %.9f seconds\n", time_connection); return 0; diff --git a/fases/implementacao/pub_sub_hiredis/teste/tcp/pub/mqtt_client.c b/fases/implementacao/pub_sub_hiredis/teste/tcp/pub/mqtt_client.c index f13a67d..4694f82 100644 --- a/fases/implementacao/pub_sub_hiredis/teste/tcp/pub/mqtt_client.c +++ b/fases/implementacao/pub_sub_hiredis/teste/tcp/pub/mqtt_client.c @@ -29,6 +29,8 @@ // Subcommand #define PUBLISH "pub" +double time_connection; + void fatal(const char *msg, int rv) { fprintf(stderr, "%s: %s\n", msg, nng_strerror(rv)); } @@ -80,6 +82,8 @@ int client_connect(nng_socket *sock, nng_dialer *dialer, const char *url, bool v fatal("nng_dialer_create", rv); } + + // create a CONNECT message /* CONNECT */ nng_msg *connmsg; @@ -93,9 +97,25 @@ int client_connect(nng_socket *sock, nng_dialer *dialer, const char *url, bool v nng_mqtt_msg_set_connect_will_topic(connmsg, "will_topic"); nng_mqtt_msg_set_connect_clean_session(connmsg, true); + + + + printf("Connecting to server ...\n"); + // Marcar o início do tempo + struct timespec start_time, end_time; + clock_gettime(CLOCK_REALTIME, &start_time); + nng_dialer_set_ptr(*dialer, NNG_OPT_MQTT_CONNMSG, connmsg); nng_dialer_start(*dialer, NNG_FLAG_NONBLOCK); + clock_gettime(CLOCK_REALTIME, &end_time); + + // Calcular a diferença + long seconds = end_time.tv_sec - start_time.tv_sec; + long nanoseconds = end_time.tv_nsec - start_time.tv_nsec; + double elapsed = seconds + nanoseconds*1e-9; + time_connection = elapsed; + printf("Time taken to connect: %.9f seconds\n", elapsed); return (0); } @@ -205,6 +225,7 @@ int main(const int argc, const char **argv) { nng_msleep(interval_ms); // Espera o intervalo especificado antes de publicar novamente } } + printf("Time taken to connect: %.9f seconds\n", time_connection); if ((rv = nng_close(sock)) != 0) { fatal("nng_close", rv); diff --git a/fases/implementacao/pub_sub_hiredis/teste/tcp/pub_tls/tls.c b/fases/implementacao/pub_sub_hiredis/teste/tcp/pub_tls/tls.c index 39353ca..d93271d 100644 --- a/fases/implementacao/pub_sub_hiredis/teste/tcp/pub_tls/tls.c +++ b/fases/implementacao/pub_sub_hiredis/teste/tcp/pub_tls/tls.c @@ -20,6 +20,7 @@ #endif #define BILLION 1000000000 +double time_connection; void fatal(const char *msg, int rv) { @@ -171,6 +172,8 @@ int tls_client(const char *url, uint8_t proto_ver, const char *ca, const char *c } } + + nng_msg *msg; nng_mqtt_msg_alloc(&msg, 0); nng_mqtt_msg_set_packet_type(msg, NNG_MQTT_CONNECT); @@ -192,10 +195,24 @@ int tls_client(const char *url, uint8_t proto_ver, const char *ca, const char *c fatal("init_dialer_tls", rv); } + // Marcar o início do tempo + struct timespec start_time, end_time; + clock_gettime(CLOCK_REALTIME, &start_time); + nng_dialer_set_ptr(dialer, NNG_OPT_MQTT_CONNMSG, msg); if ((rv = nng_dialer_start(dialer, NNG_FLAG_ALLOC)) != 0){ fatal("nng_dialer_start", rv); } + + clock_gettime(CLOCK_REALTIME, &end_time); + + // Calcular a diferença + long seconds = end_time.tv_sec - start_time.tv_sec; + long nanoseconds = end_time.tv_nsec - start_time.tv_nsec; + double elapsed = seconds + nanoseconds*1e-9; + time_connection = elapsed; + + printf("Time taken to connect: %.9f seconds\n", elapsed); pub_time_packets(sock, topic, qos, verbose, interval, num_packets); @@ -318,6 +335,7 @@ int main(int argc, char const *argv[]) uint32_t interval = 1000; //default interval is 1000 ms or 1 second uint32_t num_packets = 1; //default number of packets is 1 bool verbose = false; + signal(SIGINT, intHandler); @@ -383,7 +401,10 @@ int main(int argc, char const *argv[]) if (tls_client(url, proto_ver, cafile, cert, key, key_psw, topic, qos, verbose, interval, num_packets) != 0) { fprintf(stderr, "Error: tls_client\n"); return 1; + }else{ + printf("TLS client connected successfully\n"); + printf("Time taken to connect: %.9f seconds\n", time_connection); } return 0; -} +} \ No newline at end of file