ADD+BUGFIX [mictcp/mictcp_core] (see details below)

1) BUGFIX: Fixed the return value of IP_send() and IP_recv() so that they does not include the header size anymore.

2) ADD: Harmonization of IP_send() and IP_recv() so that they both use mic_tcp_pdu data instead of ip_payload data.
Moved therefore the ip_payload type declaration in mictcp_core.h.

3) ADD: Add the source address to the arguments of process_received_PDU() in order to make the multiplexing implementation possible.

4) ADD: Generate a stub addr in IP_recv()
This commit is contained in:
Guillaume Averlant 2018-05-03 19:14:04 +02:00
parent d8da9cac5e
commit 5e4a2b64a9
4 changed files with 47 additions and 27 deletions

View file

@ -11,7 +11,7 @@
int initialize_components(start_mode sm);
int IP_send(mic_tcp_pdu, mic_tcp_sock_addr);
int IP_recv(ip_payload*, mic_tcp_sock_addr*, unsigned long timeout);
int IP_recv(mic_tcp_pdu*, mic_tcp_sock_addr*, unsigned long timeout);
int app_buffer_get(mic_tcp_payload);
void app_buffer_put(mic_tcp_payload);
@ -27,6 +27,12 @@ unsigned long get_now_time_usec();
#define API_SC_Port 8525
#define API_HD_Size 15
typedef struct ip_payload
{
char* data; /* données transport */
int size; /* taille des données */
} ip_payload;
int mic_tcp_core_send(mic_tcp_payload);
mic_tcp_payload get_full_stream(mic_tcp_pdu);
mic_tcp_payload get_mic_tcp_data(ip_payload);

View file

@ -82,16 +82,6 @@ typedef struct mic_tcp_pdu
mic_tcp_payload payload; /* charge utile du PDU */
} mic_tcp_pdu;
/*
* Structure des données utiles dun PDU IP
*/
typedef struct ip_payload
{
char* data; /* données transport */
int size; /* taille des données */
} ip_payload;
typedef struct app_buffer
{
mic_tcp_payload packet;
@ -109,7 +99,7 @@ int mic_tcp_accept(int socket, mic_tcp_sock_addr* addr);
int mic_tcp_connect(int socket, mic_tcp_sock_addr addr);
int mic_tcp_send (int socket, char* mesg, int mesg_size);
int mic_tcp_recv (int socket, char* mesg, int max_mesg_size);
void process_received_PDU(mic_tcp_pdu pdu);
void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_sock_addr addr);
int mic_tcp_close(int socket);
#endif

View file

@ -108,13 +108,14 @@ int IP_send(mic_tcp_pdu pk, mic_tcp_sock_addr addr)
free (tmp.data);
result = sent_size;
/* Correct the sent size */
result = (sent_size == -1) ? -1 : sent_size - API_HD_Size;
}
return result;
}
int IP_recv(ip_payload* pk,mic_tcp_sock_addr* addr, unsigned long timeout)
int IP_recv(mic_tcp_pdu* pk, mic_tcp_sock_addr* addr, unsigned long timeout)
{
int result = -1;
@ -132,11 +133,34 @@ int IP_recv(ip_payload* pk,mic_tcp_sock_addr* addr, unsigned long timeout)
/* Convert the remainder to microseconds */
tv.tv_usec = (timeout - tv.tv_sec * 1000) * 1000;
/* Create a reception buffer */
int buffer_size = API_HD_Size + pk->payload.size;
char *buffer = malloc(buffer_size);
if ((setsockopt(sys_socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))) >= 0) {
result = recvfrom(sys_socket, pk->data, pk->size, 0, (struct sockaddr *)&tmp_addr, &tmp_addr_size);
pk->size = result;
result = recvfrom(sys_socket, buffer, buffer_size, 0, (struct sockaddr *)&tmp_addr, &tmp_addr_size);
}
if (result != -1) {
/* Create the mic_tcp_pdu */
memcpy (&(pk->header), buffer, API_HD_Size);
pk->payload.size = result - API_HD_Size;
memcpy (pk->payload.data, buffer + API_HD_Size, pk->payload.size);
/* Generate a stub address */
if (addr != NULL) {
addr->ip_addr = "localhost";
addr->ip_addr_size = strlen(addr->ip_addr) + 1; // don't forget '\0'
addr->port = pk->header.source_port;
}
/* Correct the receved size */
result -= API_HD_Size;
}
/* Free the reception buffer */
free(buffer);
return result;
}
@ -242,7 +266,9 @@ void app_buffer_put(mic_tcp_payload bf)
{
/* Prepare a buffer entry to store the data */
struct app_buffer_entry * entry = malloc(sizeof(struct app_buffer_entry));
entry->bf = bf;
entry->bf.size = bf.size;
entry->bf.data = malloc(bf.size);
memcpy(entry->bf.data, bf.data, bf.size);
/* Lock a mutex to protect the buffer from corruption */
pthread_mutex_lock(&lock);
@ -265,26 +291,24 @@ void* listening(void* arg)
mic_tcp_pdu pdu_tmp;
int recv_size;
mic_tcp_sock_addr remote;
ip_payload tmp_buff;
pthread_mutex_init(&lock, NULL);
printf("[MICTCP-CORE] Demarrage du thread de reception reseau...\n");
tmp_buff.size = 1500;
tmp_buff.data = malloc(1500);
const int payload_size = 1500 - API_HD_Size;
pdu_tmp.payload.size = payload_size;
pdu_tmp.payload.data = malloc(payload_size);
while(1)
{
tmp_buff.size = 1500;
recv_size = IP_recv(&tmp_buff, &remote, 0);
pdu_tmp.payload.size = payload_size;
recv_size = IP_recv(&pdu_tmp, &remote, 0);
if(recv_size > 0)
if(recv_size != -1)
{
pdu_tmp.header = get_mic_tcp_header (tmp_buff);
pdu_tmp.payload = get_mic_tcp_data (tmp_buff);
process_received_PDU(pdu_tmp);
process_received_PDU(pdu_tmp, remote);
} else {
/* This should never happen */
printf("Error in recv\n");

View file

@ -84,7 +84,7 @@ int mic_tcp_close (int socket)
* le buffer de réception du socket. Cette fonction utilise la fonction
* app_buffer_put().
*/
void process_received_PDU(mic_tcp_pdu pdu)
void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_sock_addr addr)
{
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
}