⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcp.cc

📁 adtcp.tar.gz TCL TCL
💻 CC
📖 第 1 页 / 共 5 页
字号:
	if (tcph->seqno() > last_ack_) {
		recv_newack_helper(pkt);
		if (last_ack_ == 0 && delay_growth_) { 
			cwnd_ = initial_window();
		}
	} else if (tcph->seqno() == last_ack_) {
                if (hdr_flags::access(pkt)->eln_ && eln_) {
                        tcp_eln(pkt);
                        return;
                }
		if (++dupacks_ == numdupacks_ && !noFastRetrans_) {
			dupack_action();
		} else if (dupacks_ < numdupacks_ && singledup_ ) {
			send_one();
		}
	}

	if (QOption_ && EnblRTTCtr_)
		process_qoption_after_ack (tcph->seqno());

	Packet::free(pkt);
	/*
	 * Try to send more data.
	 */
	send_much(0, 0, maxburst_);
}

/*
 * Process timeout events other than rtx timeout. Having this as a separate 
 * function allows derived classes to make alterations/enhancements (e.g.,
 * response to new types of timeout events).
 */ 
void TcpAgent::timeout_nonrtx(int tno) 
{
	if (tno == TCP_TIMER_DELSND)  {
	 /*
	 	* delayed-send timer, with random overhead
	 	* to avoid phase effects
	 	*/
		send_much(1, TCP_REASON_TIMEOUT, maxburst_);
	}
}

double TcpAgent::getmax(double d1,double d2, double d3)
{

	if(d1>d2)
	{
		if(d1>d3)
			return(d1);
		else
			return(d3);
	};
	if(d2 > d3)
		return(d2);
	else
		return(d3);
}


int TcpAgent::ifConn(int n1, int n2, double t)
{
 	double x1,y1,x2,y2, dist;
	int i,j;
        FILE *fp;

	if(node_sp[n1] == 0.0) 
	{x1 = node_x1[n1]; y1= node_y1[n1];}
	else {
 	x1 = getCurrentX(n1, t);
	y1 = getCurrentY(n1, t);
	};

	if(node_sp[n2] == 0.0)
	{ x2 = node_x1[n2]; y2 = node_y1[n2]; }
	else {
	x2 = getCurrentX(n2, t);
	y2 = getCurrentY(n2, t);
	};

	dist = getDist(x1,y1,x2,y2);

/*	fp = fopen("node_move", "a+");
	fprintf(fp, "t=%f\tn1=%d\tn2=%d\tx1=%f\ty1=%f\tx2=%f\ty2=%f\tdist=%f\n", t, n1,n2,x1,y1,x2,y2,dist);
	fclose(fp);
*/

	if(dist>250.0) return(0); 
		 else return(1);
}

double TcpAgent::getDist(double x1, double y1, double x2, double y2)
{
	return(sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)));
}

double TcpAgent::getCurrentX(int n1, double ct)
{

	return(((ct-node_t0[n1])/node_T[n1])*(node_x2[n1]-node_x1[n1])+node_x1[n1]);
}

double TcpAgent::getCurrentY(int n1, double ct)
{
        return(((ct-node_t0[n1])/node_T[n1])*(node_y2[n1]-node_y1[n1])+node_y1[n1]);
}   

void TcpAgent::putthu(double t, double thu)
{
	
        double pc_sample, iad = thu;
        int itvl,i ;
        FILE *fp2;
	double *cnt, *tm, totn,j;

	thu = (double)thu/(double)MAX_PACKET_PER_SECOND * HIGHEST_VAL;
	iad = thu;
	cnt = (double*)int_cnt_thu;
	tm =  (double*)time_cnt_thu;
	totn = tot_thu;

        if(iad > HIGHEST_VAL) iad = HIGHEST_VAL;
        if(iad < LOWEST_VAL) iad = LOWEST_VAL;
        
        itvl = (int)floor((iad)/(double)INTERVAL);

        if(t-start_time >10*nt_rtt_ && totn > MINIMUM_SAMPLES)
        {       // adjust counts
                for(i=0;i<MAX_INTERVALS;i++)
                {
                        if(cnt[i] != 0)
                                cnt[i] *= pow(0.933,(t-tm[i])/(double)nt_rtt_);
                };
                cnt[itvl]+=1.0;
                tm[itvl] = t;
        }
        else
        {
                cnt[itvl] += 1.0;
                // tot_idd ++;
                tm[itvl] = t;
        };
        totn = 0;
        for(i=0;i<MAX_INTERVALS;i++)
                totn += cnt[i];


        j = 0;
        for(i=itvl+1;i<MAX_INTERVALS;i++)
                j+= cnt[i];
        pc_sample = (double)j/(double)totn;

        // record everything in a table

	tot_thu = totn;
        current_pc_thu = 0.5 * current_pc_thu + 0.5 * pc_sample;
        record_matrics(2,t,iad); // 1 is iad, 2 is thu, 3 is po, 4 is los

}

void TcpAgent::putlos(double t, double los)
{
        double pc_sample, iad = los;
        int itvl,i ;
        FILE *fp2;
	double *cnt, *tm, totn,j;

	los = (double)los * HIGHEST_VAL;
        iad = los;
        cnt = (double*)int_cnt_los;
        tm =  (double*)time_cnt_los;
        totn = tot_los;

        if(iad > HIGHEST_VAL) iad = HIGHEST_VAL;
        if(iad < LOWEST_VAL) iad = LOWEST_VAL;

        itvl = (int)floor((iad)/(double)INTERVAL);

        if(t-start_time >10*nt_rtt_ && totn > MINIMUM_SAMPLES)
        {       // adjust counts
                for(i=0;i<MAX_INTERVALS;i++)
                {
                        if(cnt[i] != 0)
                                cnt[i] *= pow(0.933,(t-tm[i])/(double)nt_rtt_);
                };
                cnt[itvl]+=1.0;
                tm[itvl] = t;
        }
        else
        {
                cnt[itvl] += 1.0;
                // tot_idd ++;
                tm[itvl] = t;
        };
        totn = 0;
        for(i=0;i<MAX_INTERVALS;i++)
                totn += cnt[i];


        j = 0;
        for(i=0;i<itvl;i++)
                j+= cnt[i];
        pc_sample = (double)j/(double)totn;

        // record everything in a table

        tot_los = totn;
        current_pc_los = pc_sample;
        record_matrics(4,t,iad); // 1 is iad, 2 is thu, 3 is po, 4 is los
}

void TcpAgent::putpo(double t, double po)
{        
        double pc_sample, iad = po;
        int itvl,i ;
        FILE *fp2;
        double *cnt, *tm, totn,j;

        po = (double)po * HIGHEST_VAL;
        iad = po;
        cnt = (double*)int_cnt_po;
        tm =  (double*)time_cnt_po;
        totn = tot_po;

        if(iad > HIGHEST_VAL) iad = HIGHEST_VAL;
        if(iad < LOWEST_VAL) iad = LOWEST_VAL;

        itvl = (int)floor((iad)/(double)INTERVAL);

        if(t-start_time >10*nt_rtt_ && totn > MINIMUM_SAMPLES)
        {       // adjust counts
                for(i=0;i<MAX_INTERVALS;i++)
                {
                        if(cnt[i] != 0)
                                cnt[i] *= pow(0.933,(t-tm[i])/(double)nt_rtt_);
                };
                cnt[itvl]+=1.0;
                tm[itvl] = t;
        }
        else
        {
                cnt[itvl] += 1.0;
                // tot_idd ++;
                tm[itvl] = t;
        };
        totn = 0;
        for(i=0;i<MAX_INTERVALS;i++)
                totn += cnt[i];


        j = 0;
        for(i=0;i<itvl;i++)
                j+= cnt[i];
        pc_sample = (double)j/(double)totn;

        // record everything in a table

        tot_po = totn;
        current_pc_po = pc_sample;
        record_matrics(3,t,iad); // 1 is iad, 2 is thu, 3 is po, 4 is los
}



void TcpAgent::putidd(double idd, double t)
{
	double pc_sample, j;
        int itvl,i;
	FILE *fp2;

	//fp2 = fopen("idd.exp","a+"); fprintf(fp2, "%f\t%f\n", t, idd); fclose(fp2);

	if(idd > HIGHEST_VAL) idd = HIGHEST_VAL;
	if(idd < 0) idd = 0;

	itvl = (int)floor(idd/(double)INTERVAL);
        if(t-start_time >10*nt_rtt_ )
        {       // adjust counts
                for(i=0;i<MAX_INTERVALS;i++)
                {
			if(int_cnt_idd[itvl] != 0)
                                int_cnt_idd[itvl] *= pow(0.933,(t-time_cnt_idd[itvl])/(double)nt_rtt_);
                };
		int_cnt_idd[itvl]+=1.0;
		time_cnt_idd[itvl] = t;
        }
        else
        {
                int_cnt_idd[itvl] += 1.0;
                // tot_idd ++;
		time_cnt_idd[itvl] = t;
        };
        tot_idd = 0;
	for(i=0;i<MAX_INTERVALS;i++)
		tot_idd += int_cnt_idd[i];

//	itvl = (int)floor(idd/(double)INTERVAL);
//	int_cnt_idd[itvl] ++;
//      tot_idd ++;

	j = 0;
	for(i=0;i<itvl;i++)
		j+= int_cnt_idd[i];
	pc_sample = (double)j/(double)tot_idd;
	// calculate the exponential algorithm

	if(pc_sample > current_pc_idd_exp) current_pc_idd_exp = pc_sample;
	else 
		current_pc_idd_exp = pow(current_pc_idd_exp, PC_WEIGHT_EXP); 

	fp2 = fopen("idd.exp","a+");
	fprintf(fp2, "%f\t%f\n", t, current_pc_idd_exp);
	fclose(fp2);

	
	// calculate the linear algorithm

	//current_pc_idd = (1-PC_WEIGHT_LINEAR)*current_pc_idd + PC_WEIGHT_LINEAR*pc_sample;
	current_pc_idd = pc_sample;
 
	fp2 = fopen("idd.lin","a+");
        fprintf(fp2, "%f\t%f\n", t, current_pc_idd);
        fclose(fp2);


	if(tot_idd > STARTUP_PKTS) 
		if(idd > current_idd_average + BETA * current_idd_var) 
			idd_ind = 1;
		else
			idd_ind = 0;
	current_idd_var = (1-PC_WEIGHT_LINEAR)*current_idd_var + PC_WEIGHT_LINEAR*fabs(idd - current_idd_average);
	current_idd_average = (1-PC_WEIGHT_LINEAR)*current_idd_average + PC_WEIGHT_LINEAR*idd;


	fp2 = fopen("idd.wt","a+");
        fprintf(fp2,"%f\t%d\n",t,idd_ind);
        fclose(fp2);
}      

void TcpAgent::record_matrics(int what, double t, double sample)
{

	FILE * fp;
	int i;

	if(what == 1) // about iad
	{
		fp = fopen("cdf_iad","a+");
		fprintf(fp,"%f\t%f\n", t,current_pc_iad);
		fclose(fp);
		fp = fopen("tot_iad","a+");
                fprintf(fp,"%f\t%f\t%f\n", t,tot_iad,(double)nt_rtt_);
                fclose(fp);
		fp = fopen("sam_iad","a+");
                fprintf(fp,"%f\t%f\n", t,sample);
                fclose(fp);
	}

        if(what == 2) // about thu
        {
                fp = fopen("cdf_thu","a+");
                fprintf(fp,"%f\t%f\n", t,current_pc_thu);
                fclose(fp);
                fp = fopen("tot_thu","a+");
                fprintf(fp,"%f\t%f\t%f\n", t,tot_thu,(double)nt_rtt_);
                fclose(fp);
                fp = fopen("sam_thu","a+");
                fprintf(fp,"%f\t%f\n", t,sample);
                fclose(fp);
        }

	if(what == 3) // about thu
        {
                fp = fopen("cdf_po","a+");
                fprintf(fp,"%f\t%f\n", t,current_pc_po);
                fclose(fp);
                fp = fopen("tot_po","a+");
                fprintf(fp,"%f\t%f\t%f\n", t,tot_po,(double)nt_rtt_);
                fclose(fp);
                fp = fopen("sam_po","a+");
                fprintf(fp,"%f\t%f\n", t,sample);
                fclose(fp);
        }

	if(what == 4) // about thu
        {
                fp = fopen("cdf_los","a+");
                fprintf(fp,"%f\t%f\n", t,current_pc_los);
                fclose(fp);
                fp = fopen("tot_los","a+");
                fprintf(fp,"%f\t%f\t%f\n", t,tot_los,(double)nt_rtt_);
                fclose(fp);
                fp = fopen("sam_los","a+");
                fprintf(fp,"%f\t%f\n", t,sample);
                fclose(fp);
        }
}

void TcpAgent::putiad(double iad, double t)
{
	double pc_sample, j;
	int itvl, i,k;
	FILE * fp2;

	//fp2 = fopen("iad.exp","a+"); fprintf(fp2, "%f\t%f\n", t, iad); fclose(fp2);

        iad = fabs(iad);

	//smooth it a little bit
        current_iad_average = (1-IAD_WEIGHT)*current_iad_average + IAD_WEIGHT * iad;
        iad = current_iad_average;

	if(iad > HIGHEST_VAL) iad = HIGHEST_VAL;
	if(iad < LOWEST_VAL) iad = LOWEST_VAL;
	
	itvl = (int)floor((iad)/(double)INTERVAL);

        if(t-start_time >10*nt_rtt_ && tot_iad > MINIMUM_SAMPLES)
        {       // adjust counts
                for(i=0;i<MAX_INTERVALS;i++)
                {
                        if(int_cnt_iad[i] != 0)
                                int_cnt_iad[i] *= pow(0.933,(t-time_cnt_iad[i])/(double)nt_rtt_);
                };
                int_cnt_iad[itvl]+=1.0;
                time_cnt_iad[itvl] = t;
        }
        else
        {
                int_cnt_iad[itvl] += 1.0;
                // tot_idd ++;
                time_cnt_iad[itvl] = t;
        };
        tot_iad = 0;
        for(i=0;i<MAX_INTERVALS;i++)
                tot_iad += int_cnt_iad[i];


	j = 0;
//  	k = (int)floor(HIGHEST_VAL/INTERVAL);
//      for(i=k-abs(k-itvl)+1;i<k+abs(k-itvl);i++)
	for(i=0;i<itvl;i++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -