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

📄 tcp.cc

📁 adtcp.tar.gz TCL TCL
💻 CC
📖 第 1 页 / 共 5 页
字号:
                j+= int_cnt_iad[i];
        pc_sample = (double)j/(double)tot_iad;

 	// record everything in a table 

        current_pc_iad = current_pc_iad * 0.875 + pc_sample * 0.125;

        record_matrics(1,t,iad); // 1 is iad, 2 is thu, 3 is po, 4 is los

/*

        // calculate the exponential algorithm

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

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


        // calculate the linear algorithm

        // current_pc_iad = (1-PC_WEIGHT_LINEAR)*current_pc_iad + PC_WEIGHT_LINEAR*pc_sample;
	current_pc_iad = pc_sample;

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

	// calculating a different way of using iad, getting the average of it

	if(tot_iad > STARTUP_PKTS)
		if(iad > current_iad_average + BETA * current_iad_var || 
		   iad < current_iad_average - BETA * current_iad_var)
                        iad_ind = 1;
                else
                        iad_ind = 0;

	current_iad_var = (1-PC_WEIGHT_LINEAR)*current_iad_var + PC_WEIGHT_LINEAR*fabs(iad - current_iad_average);
	current_iad_average = (1-IAD_WEIGHT)*current_iad_average + IAD_WEIGHT * iad;


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


	if(current_iad_average <0) itvl = 0;
	else
		itvl = (int)floor(current_iad_average/(double)IAD_INTERVAL);
	int_cnt_iad_average[itvl] ++;
	j = 0;
	for(i=0;i<itvl;i++)
		j+= int_cnt_iad_average[i];
	pc_sample = (double) j/(double) tot_iad;
	if(pc_sample > current_pc_iad_average_exp) current_pc_iad_average_exp = pc_sample;
	else
		current_pc_iad_average_exp = pow(current_pc_iad_average_exp, PC_WEIGHT_EXP);

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

	current_pc_iad_average = (1-PC_WEIGHT_LINEAR) * current_pc_iad_average +
				PC_WEIGHT_LINEAR * pc_sample;
        fp2 = fopen("iad_avg.lin","a+");
        fprintf(fp2, "%f\t%f\n", t, current_pc_iad_average);
        fclose(fp2);
*/
}
                      
int TcpAgent::get_thresh_ident()
{
	if (current_pc_iad > NOCONGEST_THRESHOLD_LIN && current_pc_thu > NOCONGEST_THRESHOLD_LIN)
		return(1);
	return(0);
}

int TcpAgent::get_ml_ident(int r)
{

	FILE * fp;
        double t = Scheduler::instance().clock();

/*
	fp = fopen("sched2","a+"); 
      fprintf(fp,"%f",t);
     if(r & F_LINK)
     {
          fprintf(fp,"\tF_LINK");
     };

     if(r & F_PO)
     {
          fprintf(fp,"\tF_PO");
     };

     if(r & F_ERR)
     {
          fprintf(fp,"\tF_ERR");
     };

     if(r & F_CONG)
     {
          fprintf(fp,"\tF_CONG");
     };
	fprintf(fp,"\n"); fclose(fp);
*/
	ml[0] = 0.5 * current_pc_iad + 0.5 * current_pc_thu;
	ml[1] = 0.333 * (1.0-current_pc_iad) + 0.333*(1-current_pc_los) + 0.333 * current_pc_po; //ml_mob
	ml[2] = 0.333 *(1.0 -current_pc_iad) + 0.333*(1-current_pc_po) + 0.333 * current_pc_los; //ml_err
	ml[3] = 0.333*(1.0-current_pc_iad) + 0.333 * current_pc_po + 0.333 * current_pc_los; //ml_mob&err
	ml[4] = 0.333 * (1.0 - current_pc_iad) + 0.333 *(1.0-current_pc_po) + 0.333 * (1.0-current_pc_los);
	ml[4] = ml[4]*0.5 + 0.5*( 0.5 * current_pc_iad + 0.5 * (1.0- current_pc_thu));  //ml_normal
	
	//begin to write epsilon file
	if(r & F_CONG) { ml_cnt[0] ++; ml_epsilon[0] += ml[0]; 
			fp=fopen("epsilon_ml0","a+"); fprintf(fp,"%f\t%f\n",t,ml_epsilon[0]/(double)ml_cnt[0]); fclose(fp);}
	else
	   if((r & F_LINK) && (r & F_ERR)) { ml_cnt[3] ++; ml_epsilon[3] += ml[3];
			fp=fopen("epsilon_ml3","a+"); fprintf(fp,"%f\t%f\n",t,ml_epsilon[3]/(double)ml_cnt[3]); fclose(fp);}
	   else
		if(r&  F_LINK ) { ml_cnt[1] ++ ; ml_epsilon[1] += ml[1];
			fp=fopen("epsilon_ml1","a+"); fprintf(fp,"%f\t%f\n",t,ml_epsilon[1]/(double)ml_cnt[1]); fclose(fp);}
		else
			if(r & F_ERR) { ml_cnt[2] ++; ml_epsilon[2] += ml[2];
			fp=fopen("epsilon_ml2","a+"); fprintf(fp,"%f\t%f\n",t,ml_epsilon[2]/(double)ml_cnt[2]); fclose(fp);}
			else
				{ml_cnt[4]++; ml_epsilon[4] += ml[4];
				fp=fopen("epsilon_ml4","a+"); fprintf(fp,"%f\t%f\n",t,ml_epsilon[4]/(double)ml_cnt[4]); fclose(fp);};
	
	if(get_maxml() == 0) return(1) ;
	return(0);
}

int TcpAgent::get_maxml(void)
{
	int i=0,j=0;
	double tmp;

	tmp = ml[0];
	for(i=1;i<5;i++)
		if(tmp < ml[i]) {
			tmp = ml[i];
			j = i;
		}
	return(j);
}


int TcpAgent::get_reason()
{
    // static int inited = 0;
    FILE *fp1, *fp2;
    char a[20],b[20],c[30],d[30],e[30];
    int i,j,k,l,m,n, reason=0;
    char s, ch;
    unsigned int ui, from_nodeid, to_nodeid, ui1;
    double t;
    int rt = 0, highest_tcp_loss=0;
    double at=0, highest_ack_loss=0;
    double x1,y1,x2,y2,speed, dumbz;
    int pktno;
    double pc1, pc2;	
    int ident_reason1=0, ident_reason2 = 0;

// debuging ==================
/*   fp2 = fopen("sched2","a+");
    fprintf(fp2,"%f\n inited = %d\thighest_ack=%d\trtt=%f\n", Scheduler::instance().clock(),inited, (int)highest_ack_, (double)((t_srtt_ >> T_SRTT_BITS)*tcp_tick_) );
    fclose(fp2);  */
// ==========================

	nt_rtt_ = (double)((t_srtt_ >> T_SRTT_BITS)*tcp_tick_); 

	if(nt_rtt_ <=1) nt_rtt_ = 1.0;	

    if(inited != 1 ) {


	for(i=0;i<MAX_NODES;i++)
	{
		prev_reason[i] = F_LINK;
		prev_reason_time[i] = 0.0;
		node_x1[i] = 0.0;
		node_y1[i] = 0.0;
		node_sp[i] = 0.0;
	};
     
	for(i=0; i<MAX_INTERVALS; i++)
	{
		int_cnt_idd[i] = 0;
		int_cnt_iad[i] = 0;
		int_cnt_iad_average[i] = 0;
		time_cnt_idd[i] = 0;
		time_cnt_iad[i] = 0;
	};
	start_time = Scheduler::instance().clock();

	for(i=0;i<MAX_PKTS; i++)
	{
		pkts[i] = 0;
	};
	for(i=0;i<1024;i++)
		snd[i]=0;

	for(i=0;i<MAX_PKTNO;i++)
	{   rcvd[i] = 0; pkts_no[i] = 0; };

//added by xiaoqiao
/*
	nbIDDHistory = 0;
	nbPOHistory = 0;
	nbTHRUHistory = 0;
	nbLOSHistory = 0;

	HistoryData.dIDDHistory_Mean = HistoryData.dIDDHistory_Deviation = 0;
	HistoryData.dPOHistory_Mean = HistoryData.dPOHistory_Deviation = 0;
	HistoryData.dTHRUHistory_Mean = HistoryData.dTHRUHistory_Deviation = 0;
	HistoryData.dLOSHistory_Mean = HistoryData.dLOSHistory_Deviation = 0;

	LDA_Con_NonCon_Coef[0] = LDA_Con_NonCon_Coef[0] = LDA_Con_NonCon_Coef[2] = 1.0; 			
	inbCongSample = inbNonCongSample = 0;
	LastReason = 0;//1 means last time it is congestion
	LastReason_Time = 0;
*/
//added ended

        tracefile_pos = 0;
	maxrt = -1;
	last_pkt = 0;
	cur_pkt = 0;
	last_time = -1.0;
	inited = 1;
	tot_iad = 0;
	tot_idd = 0;
	current_pc_idd_exp = 0;
	current_pc_idd = 0;
	current_pc_iad_exp = 0;
	current_pc_iad = 0;

	current_pc_iad_average =0;
	current_pc_iad_average_exp = 0;
	current_iad_average = 0;
	current_iad_var = 0;
	current_idd_average = 0;
	current_idd_var = 0;
	idd_ind = 0;
	iad_ind = 0;
	
	thu_lin = 0;
	po_lin = 0;
	los_lin = 0;
	cur_rtt = 2;
	cur_ts = 1.0;
	ts_tot_pkts = 0;
	ts_start_time = -1;
	ts_tot_po = 0;
	ts_start_sn = 0;
	ts_tot_los = 0;
	current_thu_average=current_thu_var=current_los_average=current_los_var=current_po_average =current_po_var=0;
	thu_ind=po_ind=los_ind = 0;
	acc_thu = acc_los = acc_po = 0;

	acc_exp = acc_lin = acc_wt = acc_iad_exp = acc_iad_lin = 0.0;
	acc_ct = 0;

	tcp_pkt_recvd = 0;
	last_reason = F_LINK;

	ack_no = ack_cnt = fr_pending = fr_recover_no =0;
	fr_pending_start_time = 0;
	max_snd_time = -1.0;

	fp2 = fopen("accuracy.exp","w");
	fclose(fp2);
	fp2 = fopen("accuracy.lin","w");
	fclose(fp2);
	fp2 = fopen("congest.ref","w");
	fclose(fp2);
	fp2 = fopen("accuracy_iad.exp","w");
	fclose(fp2);
	fp2 = fopen("accuracy_iad.lin","w");
	fclose(fp2);

	fp2 = fopen("accuracy_thu.lin","w");
	fclose(fp2);
	fp2 = fopen("accuracy_po.lin","w");
	fclose(fp2);
	fp2 = fopen("accuracy_los.lin","w");
	fclose(fp2);

	fp2 = fopen("accuracy.wt","w");
	fclose(fp2);

	fp2 = fopen("idd.exp","w");
	fclose(fp2);
	fp2 = fopen("iad.exp","w");
	fclose(fp2);
	fp2 = fopen("idd.lin","w");
	fclose(fp2);
	fp2 = fopen("iad.lin","w");
	fclose(fp2);
	fp2 = fopen("iad_avg.exp","w");
	fclose(fp2);
	fp2 = fopen("iad_avg.lin","w");
	fclose(fp2);

	fp2 = fopen("xiaoqiaotrace","w");
	fclose(fp2);
	fp2 = fopen("xiaoqiaotestIDD","w");
	fclose(fp2);
	fp2 = fopen("xiaoqiaotestTHRU","w");
	fclose(fp2);
	fp2 = fopen("xiaoqiaotestPO","w");
	fclose(fp2);
	fp2 = fopen("xiaoqiaotestLOS","w");
	fclose(fp2);

	// read in the parameters............................... 
	/*  debuging the code first, and then back and treat this

	fp2 = fopen("params", "r");
	if(fp2 == NULL) { alpha = ALPHA; beta = BETA; nocong_threshold = NOCONG_THRESHOLD; pc_weight_exp = PC_WEIGHT_EXP;}
	else	{
		fscanf(fp2,"%f %f %f %f", &alpha, &beta, &nocong_threshold, &pc_weight_exp);
		fclose(fp2);
	};
	*/

    };


    fp1 = fopen("out.tr","r");
    fseek(fp1,tracefile_pos,SEEK_SET);
    //find the sending event for packet number: highest_ack_+1
    while(!feof(fp1))
    {
         fscanf(fp1,"%c ", &ch);
         if(ch != 's' && ch != 'M' && ch!='D' && ch != 'r')
         {     
               fscanf(fp1, "%c", a);
               while( a[0] != '\n' && !feof(fp1))
               {
                      fscanf(fp1,"%c", a);
               };
               continue;
         };
	 if(ch == 'M')   {
		x1=-1.0, speed = -1.0;
		fscanf(fp1,"%lf %d (%lf, %lf, %lf), (%lf, %lf), %lf\n", &t, &m, &x1, &y1, &dumbz, &x2, &y2, &speed);
                if(x1 == -1.0 || speed == -1.0)
			continue;
		node_x1[m] = x1;
		node_y1[m] = y1;
		node_x2[m] = x2;
		node_y2[m] = y2;
		node_sp[m] = speed;
		node_t0[m] = t;
		if(speed == 0.0) 
			node_T[m] = -1.0; 
		else 
			node_T[m] = getDist(x1,y1,x2,y2)/speed;
		continue;
	  };

          c[0] = '\0';
	  fscanf(fp1,"%lf _%d_ %s %s %d %s %d [%x %x %x %x] ------- [%d:%d %d:%d %d %d] [%d %d] %d %d\n", &t, &m, a, b, &pktno, c, &i, &ui1, &to_nodeid, &from_nodeid, &ui, &k, &i, &l, &i,  &i, &i, &j, &i, &i, &i);

// debuging ====================
/*    fp2 = fopen("sched2","a+");
    fprintf(fp2,"%f -- loop1\n", t);
    fclose(fp2); */
// =============================

	//if(ch =='s' && strcmp(a,"MAC")==0 && strcmp(c,"ARP")==0 && ui1==0)  
	//{
        //
	//	fscanf(fp1," ------- [REQUEST %d/%d %d/%d]\n",  &i, &j, &i, &k);
	//	if(!ifConn(j,k,t))
	//	{
        //		prev_reason[m]=F_LINK;
	//		prev_reason_time[m]=t;
	//	};
        //        continue;
	// };

	  if(ch == 'D' && strcmp(b,"RET") == 0)
	  {
			if(!ifConn(to_nodeid, from_nodeid,t))
                        {
                                prev_reason[m] = F_LINK;
                                prev_reason_time[m] = t;
                        }
                        else
                        {
                                //prev_reason[m] = F_CONG;
                                //prev_reason_time[m] = t;
                        };
                continue;
	   };
	   if(strcmp(c,"tcp") != 0 && strcmp(c,"ack")!=0) continue;
	   if(k != nodeid_ && l != nodeid_) continue;

	   if(strcmp(a,"AGT") == 0)
	   {
	   if(ch == 's' && strcmp(c,"tcp") == 0)
	   {
		snd[j & 0x2ff] = t;
	        rcvd[pktno] = t;
	   };

	   if(ch == 'r' && strcmp(c,"tcp")==0)
	   {
		if(ts_start_time == -1) ts_start_time = t;
		ts_tot_pkts ++;
		if(last_time == -1.0) {last_time = t; last_pkt = j;last_pktno = pktno;};
		pkts[j]  ++;
		pkts_no[pktno ] ++;

 /* insert a module to calculate PO by packet sending time and received sequence. */
                if(max_snd_time < rcvd[pktno]) 
                        max_snd_time = rcvd[pktno];
                else {
                        if(max_snd_time > rcvd[pktno])
                              ts_tot_po ++;
			else { /* this is the max_snd_time = rcvd[pktno] case, compare their sequence number */
				if (maxrt > j)
					ts_tot_po ++;
			};
		}; 
/* end of PO computation */
	      
		if(pkts_no[pktno ] == 1 )
		{
	 	rcvd[pktno] = t-rcvd[pktno];
		if (pkts_no[last_pkt

⌨️ 快捷键说明

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