Compare commits

..

No commits in common. "v2" and "master" have entirely different histories.
v2 ... master

2 changed files with 17 additions and 75 deletions

View file

@ -27,11 +27,6 @@ struct app_buffer_entry {
/* Condition variable used for passive wait when buffer is empty */
pthread_cond_t buffer_empty_cond;
#define COLOR_RED "\x1b[31m"
#define COLOR_GREEN "\x1b[32m"
#define COLOR_BOLD "\x1b[1m"
#define COLOR_RESET "\x1b[0m"
/* ************************
* Fonctions Utilitaires *
* ************************/
@ -218,7 +213,7 @@ int mic_tcp_core_send(mic_tcp_payload buff)
if(random > lr_tresh) {
result = sendto(sys_socket, buff.data, buff.size, 0, (struct sockaddr *)&remote_addr, sizeof(struct sockaddr));
} else {
printf("[MICTCP-CORE] "COLOR_RED"Perte du paquet"COLOR_RESET"\n");
printf("[MICTCP-CORE] Perte du paquet\n");
}
return result;

View file

@ -1,16 +1,7 @@
#include <mictcp.h>
#include <api/mictcp_core.h>
#define COLOR_RED "\x1b[31m"
#define COLOR_GREEN "\x1b[32m"
#define COLOR_BOLD "\x1b[1m"
#define COLOR_RESET "\x1b[0m"
#define LOSS_RATE 5
#define TIMEOUT 2
struct mic_tcp_sock g_sock;
int next_msg_num;
/**
* Permet de créer un socket entre lapplication et MIC-TCP.
@ -22,11 +13,10 @@ int mic_tcp_socket(start_mode sm) {
printf(__FUNCTION__);
printf("\n");
result = initialize_components(sm); /* Appel obligatoire */
set_loss_rate(LOSS_RATE);
set_loss_rate(0);
g_sock.fd = result;
g_sock.state = IDLE;
next_msg_num = 1;
return result;
}
@ -40,7 +30,7 @@ int mic_tcp_bind(int socket, mic_tcp_sock_addr addr) {
printf(__FUNCTION__);
printf("\n");
int result = 0;
int result = 0; // TODO change in v2
g_sock.addr = addr;
@ -56,7 +46,7 @@ int mic_tcp_accept(int socket, mic_tcp_sock_addr *addr) {
printf(__FUNCTION__);
printf("\n");
int result = 0;
int result = 0; // TODO change in v2
g_sock.state = ESTABLISHED;
@ -72,7 +62,7 @@ int mic_tcp_connect(int socket, mic_tcp_sock_addr addr) {
printf(__FUNCTION__);
printf("\n");
int result = 0;
int result = 0; // TODO change in v2
g_sock.addr = addr;
g_sock.state = ESTABLISHED;
@ -88,43 +78,20 @@ int mic_tcp_send(int socket, char *mesg, int mesg_size) {
printf("[MIC-TCP] Appel de la fonction: ");
printf(__FUNCTION__);
printf("\n");
int result = -1;
while (result == -1) {
struct mic_tcp_pdu pdu;
pdu.payload.data = mesg;
pdu.payload.size = mesg_size;
struct mic_tcp_pdu pdu;
pdu.payload.data = mesg;
pdu.payload.size = mesg_size;
pdu.header.source_port = 0;
pdu.header.dest_port = g_sock.addr.port;
pdu.header.seq_num = next_msg_num;
pdu.header.ack_num = 0;
pdu.header.syn = 0;
pdu.header.ack = 0;
pdu.header.fin = 0;
pdu.header.source_port = 0;
pdu.header.dest_port = g_sock.addr.port;
pdu.header.seq_num = 0;
pdu.header.ack_num = 0;
pdu.header.syn = 0;
pdu.header.ack = 0;
pdu.header.fin = 0;
printf("\n[MIC-TCP] Sending PDU\n");
if ((result = IP_send(pdu, g_sock.addr)) != -1) {
struct mic_tcp_pdu rcv_pdu;
struct mic_tcp_sock_addr rcv_sock_addr;
printf("[MIC-TCP] Waiting for ACK\n");
result = IP_recv(&rcv_pdu, &rcv_sock_addr, TIMEOUT);
if (result == -1)
printf("[MIC-TCP] "COLOR_BOLD"Timeout"COLOR_RESET"\n");
else if (rcv_pdu.header.ack_num != next_msg_num + 1) {
printf("[MIC-TCP] Received ACK: %d | "COLOR_RED"INVALID"COLOR_RESET"\n", rcv_pdu.header.ack_num);
printf("[MIC-TCP] | Expected: %d\n", next_msg_num + 1);
printf("[MIC-TCP] | Received: %d\n", rcv_pdu.header.ack_num);
result = -1;
} else
printf("[MIC-TCP] Received ACK: "COLOR_GREEN"VALID"COLOR_RESET"\n");
} else
printf("[MIC-TCP] Ip_send "COLOR_RED"ERROR"COLOR_RESET"\n");
}
next_msg_num = next_msg_num + 1;
return result;
return IP_send(pdu, g_sock.addr);
}
/**
@ -177,25 +144,5 @@ void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_sock_addr addr) {
printf(__FUNCTION__);
printf("\n");
struct mic_tcp_pdu ack_pdu;
ack_pdu.header.source_port = 0;
ack_pdu.header.dest_port = addr.port;
ack_pdu.header.ack_num = 0;
ack_pdu.header.syn = 0;
ack_pdu.header.ack = 0;
ack_pdu.header.fin = 0;
if (pdu.header.seq_num == next_msg_num) {
next_msg_num = next_msg_num + 1;
app_buffer_put(pdu.payload);
printf("[MIC-TCP] Received PDU: "COLOR_GREEN"VALID"COLOR_RESET"\n");
} else {
printf("[MIC-TCP] Received PDU: "COLOR_RED"INVALID"COLOR_RESET"\n");
printf("[MIC-TCP] | Expected: %d\n", next_msg_num);
printf("[MIC-TCP] | Received: %d\n", pdu.header.seq_num);
}
ack_pdu.header.ack_num = next_msg_num;
printf("[MIC-TCP] Sending ack: %d\n", next_msg_num);
IP_send(ack_pdu, addr);
app_buffer_put(pdu.payload);
}