Beispiel #1
0
void reliablyTransfer(char* hostname, unsigned short int hostUDPport, char* filename, unsigned long long int bytesToTransfer)
{

	//printf("%s %hu %s %llu\n",hostname ,hostUDPport,filename,bytesToTransfer);
	/*
		make a udp socket. reach the host and the destination port. waiting for receive ack. if ok, send part 2. otherwise nack send last part again.
	*/
	
	int socket_fd;
	//data
	struct addrinfo * dest;
	
	log_init(&data_to_send);
	
	
	if( (socket_fd = socket_init(hostname, hostUDPport, &dest)) < 0){
		return;
	}
	
	if( (Convert_File_To_List(&data_to_send , filename, bytesToTransfer)) < 0){
		return;
	}

	a = data_to_send.head;///////
	int rv = 1;
	//rv = slow_start(socket_fd, dest, &data_to_send);
	ack_r = calloc(total,sizeof(int));///
	
	while(data_to_send.head != NULL){
		//printf("timeout or dup or other?\n");
		switch(rv){
			case -1:{
				free(ack_r);
				freeaddrinfo(servinfo);
				return;
			}
			case 1:{
				rv = slow_start(socket_fd, dest, &data_to_send);
				break;
			}				
				//rv = slow_start(socket_fd, dest, &data_to_send);							
			//case 2:
			//	rv = slow_start(socket_fd, dest, &data_to_send);
			//	break;
			case 2:{
				//rv = slow_start(socket_fd, dest, &data_to_send);
				rv = congestion_avoidance(socket_fd, dest, &data_to_send);
				break;
			}
			//default:
			//	break;//rv = slow_start(socket_fd, dest, &data_to_send);
			
		}	
	}
	free(ack_r);
	freeaddrinfo(servinfo);
	/*
		after part 1, add the function of trafic control which includes increase window size and decrease window size. 
	*/
}
Beispiel #2
0
int slow_start(){

  printf("\nStarting slow start!");
  int minWindow;
  int number_of_packets;

  //calculating number of packets
  //getting the minimum of advertised window and congestion window

  if( intial_start ){

    printf("\nInitial Start!");
    cwnd = 200;
    minWindow = minimum(cwnd,advertised_window);
    printf("\nWindow size calculated:%d",minWindow);
    number_of_packets = minWindow/MSS;
    exponentVal =2;
    intial_start = false;
    read_file(number_of_packets);

  }
  //when u get an ACK you do exponentially increase cwnd
  else{

    printf("\nIncreasing CWND exponentially!");
    //checking cwnd
    if(cwnd >= SSTHRESH ){
      congestion_avoidance();
    }

    cwnd = exponentVal*cwnd;
    exponentVal = exponentVal*2;
    minWindow = minimum(cwnd,advertised_window);
    number_of_packets = minWindow/MSS;
    printf("Window size calculated:%d",minWindow);
    read_file(number_of_packets);
  }

}