Merge branch 'Gwen'
This commit is contained in:
commit
f64dfead5c
2 changed files with 76 additions and 87 deletions
|
@ -72,7 +72,6 @@ typedef struct mic_tcp_header
|
|||
unsigned char ack; /* flag ACK (valeur 1 si activé et 0 si non) */
|
||||
unsigned char fin; /* flag FIN (valeur 1 si activé et 0 si non) */
|
||||
} mic_tcp_header;
|
||||
|
||||
/*
|
||||
* Structure d'un PDU MIC-TCP
|
||||
*/
|
||||
|
|
162
src/mictcp.c
162
src/mictcp.c
|
@ -3,8 +3,11 @@
|
|||
#include <mictcp.h>
|
||||
#include <api/mictcp_core.h>
|
||||
|
||||
#define TIMEOUT 100
|
||||
#define SIZE 1000
|
||||
#define TIMEOUT 10
|
||||
#define TIMEOUT2 100
|
||||
#define SIZE 100
|
||||
#define LOST 10
|
||||
#define LOSTRATE "15"
|
||||
|
||||
/*
|
||||
* Permet de créer un socket entre l’application et MIC-TCP
|
||||
|
@ -16,7 +19,7 @@
|
|||
float lostpdu = 0.0;
|
||||
float lostrate = 15.0;
|
||||
|
||||
float pduemis =0.0;
|
||||
int pduemis =0;
|
||||
int fenetre[SIZE];
|
||||
void init (int* tab,int size){
|
||||
for(int i=0;i<size;i++){
|
||||
|
@ -24,11 +27,11 @@
|
|||
}
|
||||
}
|
||||
float rate(int* tab, int size){
|
||||
int s =0;
|
||||
float s =0.0;
|
||||
for(int i=0; i<size;i++){
|
||||
s += tab[i];
|
||||
s += (float)tab[i];
|
||||
}
|
||||
return (float)((s/SIZE)*100);
|
||||
return ((s/(float)SIZE)*100.0);
|
||||
}
|
||||
pthread_mutex_t mutex= PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t cond= PTHREAD_COND_INITIALIZER;
|
||||
|
@ -40,7 +43,7 @@ int mic_tcp_socket(start_mode sm)
|
|||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
result = initialize_components(sm); /* Appel obligatoire */
|
||||
sock.fd=result;
|
||||
set_loss_rate(0);
|
||||
set_loss_rate(LOST);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -67,10 +70,9 @@ int mic_tcp_bind(int socket, mic_tcp_sock_addr addr)
|
|||
int mic_tcp_accept(int socket, mic_tcp_sock_addr* addr)
|
||||
{
|
||||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
/*
|
||||
printf("Je vais dormir\n");
|
||||
//printf("Je vais dormir\n");
|
||||
pthread_cond_wait(&cond,&mutex);
|
||||
printf("Je suis réveillé\n");*/
|
||||
//printf("Je suis réveillé\n");
|
||||
sock.state = CONNECTED;
|
||||
|
||||
return 0;
|
||||
|
@ -84,12 +86,12 @@ int mic_tcp_connect(int socket, mic_tcp_sock_addr addr)
|
|||
{
|
||||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
//Encpsulation SYN
|
||||
/*
|
||||
|
||||
mic_tcp_pdu pdusyn;
|
||||
mic_tcp_pdu ack;
|
||||
|
||||
int sent= -1;
|
||||
int max = 20;
|
||||
int max = 300;
|
||||
int count = 0;
|
||||
int test=0;
|
||||
|
||||
|
@ -98,26 +100,25 @@ int mic_tcp_connect(int socket, mic_tcp_sock_addr addr)
|
|||
pdusyn.header.syn= 1;
|
||||
pdusyn.header.ack=0;
|
||||
pdusyn.header.fin=0;
|
||||
|
||||
char jpp[] = "";
|
||||
|
||||
memcpy(&(pdu.payload.data),&jpp,sizeof(jpp));
|
||||
|
||||
pdusyn.payload.data= LOSTRATE;
|
||||
pdusyn.payload.size = 0;
|
||||
|
||||
pdu.header.ack = 0;
|
||||
pdu.header.syn = 0;
|
||||
printf("Test1\n");
|
||||
while(pdu.header.syn != 1 && pdu.header.ack !=1){
|
||||
count = 0;
|
||||
while(pdu.header.syn != 1 && pdu.header.ack !=1){
|
||||
|
||||
if(count == max){return(-1);}
|
||||
if (count != 0)
|
||||
printf("Paquet message perdu \n");
|
||||
count++;
|
||||
printf("Test2\n");
|
||||
if((sent=IP_send(pdusyn,addr))==-1){
|
||||
printf("Erreur d'envoi du pdu\n");
|
||||
exit(1);
|
||||
}
|
||||
test=(IP_recv(&pdu,&sock.addr,TIMEOUT) ==-1);
|
||||
printf("Test2\n");
|
||||
test=(IP_recv(&pdu,&sock.addr,TIMEOUT2) ==-1);
|
||||
|
||||
|
||||
while(count < max && test){
|
||||
|
@ -127,7 +128,7 @@ int mic_tcp_connect(int socket, mic_tcp_sock_addr addr)
|
|||
printf("Erreur d'envoi du pdu");
|
||||
return(1);
|
||||
}
|
||||
test=(IP_recv(&pdu,&sock.addr,TIMEOUT) ==-1);
|
||||
test=(IP_recv(&pdu,&sock.addr,TIMEOUT2) ==-1);
|
||||
}
|
||||
printf("Count : %d\n",count);
|
||||
if(count == max)
|
||||
|
@ -146,8 +147,9 @@ int mic_tcp_connect(int socket, mic_tcp_sock_addr addr)
|
|||
if(IP_send(ack,sock.addr)==-1){
|
||||
printf("Erreur d'envoi du pdu");
|
||||
exit(1);
|
||||
}*/
|
||||
}
|
||||
printf("Connected\n");
|
||||
init(fenetre,SIZE);
|
||||
sock.state=CONNECTED;
|
||||
return 0;
|
||||
}
|
||||
|
@ -160,12 +162,12 @@ int mic_tcp_send (int mic_sock, char* mesg, int mesg_size)
|
|||
{
|
||||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
int sent= -1;
|
||||
|
||||
|
||||
if(sock.state==CONNECTED){
|
||||
int max = 20;
|
||||
int count = 0;
|
||||
int test;
|
||||
|
||||
|
||||
pdu.header.syn = 0;
|
||||
pdu.header.ack = 0;
|
||||
pdu.header.fin = 0;
|
||||
|
@ -175,7 +177,6 @@ int mic_tcp_send (int mic_sock, char* mesg, int mesg_size)
|
|||
pdu.payload.size=mesg_size;
|
||||
|
||||
mic_tcp_pdu mem = pdu;
|
||||
printf("%d\n",pdu.header.seq_num);
|
||||
if((sent=IP_send(pdu,sock.addr))==-1){
|
||||
printf("Erreur d'envoi du pdu");
|
||||
exit(1);
|
||||
|
@ -186,12 +187,16 @@ int mic_tcp_send (int mic_sock, char* mesg, int mesg_size)
|
|||
test = (IP_recv(&pdu,&sock.addr,TIMEOUT) ==-1);
|
||||
|
||||
if (test){
|
||||
lostpdu++;
|
||||
fenetre[pduemis%SIZE]=1;
|
||||
printf("Lost Pdu : %f\n",lostpdu);
|
||||
}
|
||||
printf("Lost rate= %f \n",(lostpdu/pduemis)*100.0);
|
||||
else{
|
||||
fenetre[pduemis%SIZE]=0;
|
||||
}
|
||||
float truc =rate(fenetre,SIZE);
|
||||
printf("Lost rate= %f \n",truc);
|
||||
|
||||
if((lostpdu/pduemis)*100.0 >= lostrate && test){
|
||||
if(truc>= lostrate && test){
|
||||
while(count < max && test){
|
||||
count++;
|
||||
printf("Count: %d \n", count);
|
||||
|
@ -272,7 +277,6 @@ void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_sock_addr addr)
|
|||
printf("[MIC-TCP] Appel de la fonction: "); printf(__FUNCTION__); printf("\n");
|
||||
if (sock.state == CONNECTED){
|
||||
printf("Paquet recu \n");
|
||||
printf("ACK NUM %d\n",pdu.header.ack);
|
||||
mic_tcp_pdu ack;
|
||||
|
||||
if(pdu.header.seq_num == PA){
|
||||
|
@ -292,71 +296,57 @@ void process_received_PDU(mic_tcp_pdu pdu, mic_tcp_sock_addr addr)
|
|||
exit(1);
|
||||
}
|
||||
printf("Ack envoyé \n");
|
||||
}else{
|
||||
printf("Paquet Ack perdu\n");
|
||||
}else{
|
||||
int test=0;
|
||||
int sent= -1;
|
||||
int max = 20;
|
||||
int count = 0;
|
||||
mic_tcp_pdu paqu;
|
||||
while(paqu.header.syn != 1){
|
||||
test=(IP_recv(&paqu,&sock.addr,TIMEOUT) ==-1);
|
||||
if(test){}
|
||||
//printf("En attente\n");
|
||||
}
|
||||
ack.header.ack=1;
|
||||
ack.header.ack_num=PA;
|
||||
ack.payload.data ="";
|
||||
ack.payload.size=0;
|
||||
mic_tcp_pdu sack;
|
||||
|
||||
sack.header.seq_num = PE; // Création du header et setup PA et PE
|
||||
sack.header.ack_num = PA;
|
||||
sack.header.syn= 1;
|
||||
sack.header.ack=1;
|
||||
sack.header.fin=0;
|
||||
|
||||
sack.payload.data = pdu.payload.data;
|
||||
sack.payload.size = sizeof(pdu.payload.data);
|
||||
|
||||
if (IP_send(ack,addr)==-1)
|
||||
{
|
||||
printf("Erreur d'envoi du pdu");
|
||||
exit(1);
|
||||
}
|
||||
printf("Ack envoyé \n");
|
||||
printf("Je me connecte\n");
|
||||
int test=0;
|
||||
int sent= -1;
|
||||
int max = 20;
|
||||
int count = 0;
|
||||
mic_tcp_pdu paqu;
|
||||
while(paqu.header.syn != 1){
|
||||
test=(IP_recv(&paqu,&sock.addr,TIMEOUT) ==-1);
|
||||
if(test){}
|
||||
//printf("En attente\n");
|
||||
}
|
||||
mic_tcp_pdu sack;
|
||||
|
||||
sack.header.seq_num = PE; // Création du header et setup PA et PE
|
||||
sack.header.ack_num = PA;
|
||||
sack.header.syn= 1;
|
||||
sack.header.ack=1;
|
||||
sack.header.fin=0;
|
||||
|
||||
sack.payload.data = pdu.payload.data;
|
||||
sack.payload.size = sizeof(pdu.payload.data);
|
||||
|
||||
while(paqu.header.ack != 1){
|
||||
|
||||
if(count == max){exit(-1);}
|
||||
count++;
|
||||
if (count == 0)
|
||||
printf("Paquet message perdu \n");
|
||||
if((sent=IP_send(sack,sock.addr))==-1){
|
||||
printf("Erreur d'envoi du pdu");
|
||||
exit(1);
|
||||
}
|
||||
test=(IP_recv(&paqu,&sock.addr,TIMEOUT) ==-1);
|
||||
while(count < max && test){
|
||||
count++;
|
||||
while(paqu.header.ack != 1){
|
||||
|
||||
if(count == max){exit(-1);}
|
||||
if(IP_send(sack,sock.addr)==-1){
|
||||
count++;
|
||||
if (count == 0)
|
||||
printf("Paquet message perdu \n");
|
||||
if((sent=IP_send(sack,sock.addr))==-1){
|
||||
printf("Erreur d'envoi du pdu");
|
||||
exit(1);
|
||||
}
|
||||
test=(IP_recv(&paqu,&sock.addr,TIMEOUT) ==-1);
|
||||
test=(IP_recv(&paqu,&sock.addr,TIMEOUT2) ==-1);
|
||||
while(count < max && test){
|
||||
count++;
|
||||
if(count == max){exit(-1);}
|
||||
if(IP_send(sack,sock.addr)==-1){
|
||||
printf("Erreur d'envoi du pdu");
|
||||
exit(1);
|
||||
}
|
||||
test=(IP_recv(&paqu,&sock.addr,TIMEOUT2) ==-1);
|
||||
}
|
||||
|
||||
printf("Count : %d\n",count);
|
||||
if(count == max)
|
||||
exit(-1);
|
||||
}
|
||||
printf("Connected\n");
|
||||
pthread_cond_broadcast(&cond);
|
||||
sock.state = CONNECTED;
|
||||
|
||||
printf("Count : %d\n",count);
|
||||
if(count == max)
|
||||
exit(-1);
|
||||
}
|
||||
printf("Connected\n");
|
||||
pthread_cond_broadcast(&cond);
|
||||
sock.state = CONNECTED;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue