Skip to content

Commit

Permalink
time to connection and initial documentation to test
Browse files Browse the repository at this point in the history
  • Loading branch information
davisouzaluna committed Aug 4, 2024
1 parent f1144ef commit 0e26fd4
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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



Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions fases/implementacao/pub_sub_hiredis/teste/quic/pub/publisher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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;

Expand Down
21 changes: 21 additions & 0 deletions fases/implementacao/pub_sub_hiredis/teste/tcp/pub/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 22 additions & 1 deletion fases/implementacao/pub_sub_hiredis/teste/tcp/pub_tls/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#endif

#define BILLION 1000000000
double time_connection;

void fatal(const char *msg, int rv)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 0e26fd4

Please sign in to comment.