📄 pathrate_rcv.c
字号:
if (pack_sz > max_pack_sz) pack_sz = max_pack_sz; if (!abort_phase1){ sprintf(message,"\n\tToo many ignored measurements..\n\tAdjust train length: %d packets\n\tAdjust packet size: %d bytes\n\n", train_len, MIN_V(pack_sz,max_pack_sz)+28); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); } else break; } } /* Compute number of valid (non-ignored) measurements */ no_trains = trains_msrd-1; /* --------------------------------------------------------- Detect all local modes in Phase I --------------------------------------------------------- */ if (!abort_phase1) { /* Order measurements */ order(measurs_P1,ord_measurs_P1,no_trains); /* Detect and store all local modes */ sprintf(message,"\n\n-- Local modes : In Phase I --\n"); prntmsg(pathrate_fp); if (verbose) prntmsg(stdout); /* Mark all measurements as valid (needed for local mode detection) */ for (train_no=0; train_no<no_trains; train_no++) measurs_vld_P1[train_no]=1; no_modes_P1=0; while ((mode_value = get_mode(ord_measurs_P1, measurs_vld_P1, bin_wd, no_trains, &curr_mode)) != LAST_MODE) { /* the modes are ordered based on the number of measurements in the modal bin (strongest mode first) */ if (mode_value != UNIMPORTANT_MODE) { modes_P1[no_modes_P1++]= curr_mode; /*modes_P1[no_modes_P1].mode_value = mode_value; modes_P1[no_modes_P1].mode_cnt = mode_cnt; modes_P1[no_modes_P1].bell_cnt = bell_cnt; modes_P1[no_modes_P1].bell_lo = bell_lo; modes_P1[no_modes_P1].bell_hi = bell_hi; modes_P1[no_modes_P1].bell_kurtosis = bell_kurtosis; no_modes_P1++; */ if (no_modes_P1 >= MAX_NO_MODES) { fprintf(stderr,"Increase MAX_NO_MODES constant\n\n"); termint(-1); } } } sprintf(message,"\n"); prntmsg(pathrate_fp); if (verbose) prntmsg(stdout); } else { sprintf(message,"\n\tAborting Phase I measurements..\n\tToo many ignored measurements\n\tPhase II will report lower bound on path capacity.\n"); prntmsg(pathrate_fp); if (verbose) prntmsg(stdout); } no_trains_P1 = no_trains; /* Tell sender to continue with next phase */ //ctr_code = CONTINUE; //send_ctr_msg(ctr_code); sleep(1); /* ------------------------------------------------- Phase II: Packet trains with maximum train length ------------------------------------------------- */ sprintf(message,"\n\n-- Phase II: Estimate Asymptotic Dispersion Rate (ADR) -- \n\n"); prntmsg(pathrate_fp); if (verbose) prntmsg(stdout); /* Train spacing in Phase II */ train_spacing = max_train_spacing; ctr_code = TRAIN_SPACING | (train_spacing<<8); send_ctr_msg(ctr_code); /* Determine train length for Phase II. Tell sender about it. */ /* Note: the train length in Phase II is normally the maximum train length, determined in the "Maximum Train Length Discovery" phase which was executed earlier. The following constraint is only used in very low capacity paths. */ train_len = max_train_len; //train_len = (long) (((avg_bw*0.5) * (max_train_spacing*1000)) / (max_pack_sz*8)); //if (train_len > max_train_len) train_len = max_train_len; //if (train_len < train_len_P1) train_len = train_len_P1; ctr_code = TRAIN_LEN | (train_len<<8); send_ctr_msg(ctr_code); /* Packet size in Phase II. Tell sender about it. */ pack_sz = max_pack_sz; ctr_code = PCK_LEN | (pack_sz<<8); send_ctr_msg(ctr_code); /* Number of trains in Phase II. Tell sender about it. Ravi:Not anymore..*/ no_trains = NO_TRAINS_P2; sprintf(message,"\t-- Number of trains: %d - Train length: %d - Packet size: %dB\n", no_trains, train_len, pack_sz+28); prntmsg(pathrate_fp); if (verbose) prntmsg(stdout); /* Tell sender to start sending */ round++; trains_msrd=0; trains_rcvd=0; bad_tstamps=0; do { /* Wait for a complete packet train */ if ( time_stmps != NULL ) free(time_stmps); bad_train = recv_train(train_len, &round, &time_stmps); /* Compute dispersion and bandwidth measurement */ if (!bad_train) { delta = time_to_us_delta(time_stmps[1], time_stmps[train_len]); bw_msr = ((28+pack_sz) << 3) * (train_len-1) / delta; sprintf(message,"\tMeasurement-%4d out of %3d:", trains_rcvd+1, no_trains); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); print_bw(pathrate_fp, bw_msr); if (Verbose) print_bw(stdout, bw_msr); sprintf(message," (%.0f usec)", delta); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); /* Acceptable measurement */ if (delta > min_possible_delta*(train_len-1)) { /* store bw value */ measurs_P2[trains_msrd++] = bw_msr; } else { bad_tstamps++; sprintf(message," (ignored)"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); } trains_rcvd++; sprintf(message,"\n"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); } } while(trains_rcvd<no_trains); /* Tell sender to continue with next phase */ //ctr_code = CONTINUE; //send_ctr_msg(ctr_code); /* Compute number of valid (non-ignored measurements) */ no_trains = trains_msrd-1; /* --------------------------------------------------------- Detect all local modes in Phase II --------------------------------------------------------- */ /* Order measurements */ order(measurs_P2,ord_measurs_P2,no_trains); /* Detect and store all local modes in Phase II */ sprintf(message,"\n-- Local modes : In Phase II --\n"); prntmsg(pathrate_fp); if (verbose) prntmsg(stdout); /* Mark all measurements as valid (needed for local mode detection) */ for (train_no=0; train_no<no_trains; train_no++) measurs_vld_P2[train_no]=1; no_modes_P2=0; while ((mode_value = get_mode(ord_measurs_P2, measurs_vld_P2, bin_wd, no_trains, &curr_mode)) != LAST_MODE) { /* the modes are ordered based on the number of measurements in the modal bin (strongest mode first) */ if (mode_value != UNIMPORTANT_MODE) { modes_P2[no_modes_P2++]= curr_mode; /* modes_P2[no_modes_P2].mode_value = mode_value; modes_P2[no_modes_P2].mode_cnt = mode_cnt; modes_P2[no_modes_P2].bell_cnt = bell_cnt; modes_P2[no_modes_P2].bell_lo = bell_lo; modes_P2[no_modes_P2].bell_hi = bell_hi; modes_P2[no_modes_P2].bell_kurtosis = bell_kurtosis; no_modes_P2++; */ if (no_modes_P2 >= MAX_NO_MODES) { fprintf(stderr,"Increase MAX_NO_MODES constant\n\n"); termint(-1); } } } sprintf(message,"\n"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); /* If the Phase II measurements are distributed in a very narrow fashion (i.e., low coefficient of variation, and std_dev less than bin width), and the ADR is not much lower than the earlier avg bandwidth estimate, the ADR is a good estimate of the capacity mode. This happens when the narrow link is of significantly lower capacity than the rest of the links, and it is only lightly used. */ /* Compute ADR estimate */ adr = get_avg(ord_measurs_P2+10, no_trains-20); std_dev = get_std(ord_measurs_P2+10, trains_msrd-20); adr_narrow=0; if (no_modes_P2==1 && std_dev/adr<COEF_VAR_THR && adr/avg_bw>ADR_REDCT_THR) { //sprintf(message," The capacity estimate will be based on the ADR mode.\n"); //prntmsg(pathrate_fp); //if (Verbose) prntmsg(stdout); adr = (modes_P2[0].mode_value_lo + modes_P2[0].mode_value_hi)/2.0; adr_narrow=1; } if (no_modes_P2 > 1){ sprintf(message,"\n WARNING: Phase II did not lead to unimodal distribution.\n\ The ADR estimate may be wrong. Run again later. \n\n"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); max_merit=0.; for(i=0;i<no_modes_P2;i++) { sprintf(message,"\t"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); print_bw(pathrate_fp, modes_P2[i].mode_value_lo); if (Verbose) print_bw(stdout, modes_P2[i].mode_value_lo); sprintf(message,"to"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); print_bw(pathrate_fp, modes_P2[i].mode_value_hi); if(Verbose) print_bw(stdout, modes_P2[i].mode_value_hi); // merit = (modes_P2[i].mode_cnt / (double)modes_P2[i].bell_cnt) // Weiling: merit is calculated using kurtosis as the narrowness of the bell merit = modes_P2[i].bell_kurtosis * (modes_P2[i].mode_cnt / (double)no_trains); sprintf(message," - Figure of merit: %.2f\n", merit); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); if (merit > max_merit) { max_merit = merit; cap_mode_ind = i; } } adr = (modes_P2[cap_mode_ind].mode_value_lo+modes_P2[cap_mode_ind].mode_value_lo)/2.0; } sprintf(message,"--> Asymptotic Dispersion Rate (ADR) estimate:"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); print_bw(pathrate_fp, adr); if (Verbose) print_bw(stdout, adr); sprintf(message,"\n"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); /* --------------------------------------------------------- The end of the story... Final capacity estimate --------------------------------------------------------- */ /* Final capacity estimate: the Phase I mode that is larger than ADR, and it has the maximum "figure of merit". This figure of metric is the "density fraction" of the mode, times the "strength fraction" of the mode. The "density fraction" is the number of measurements in the central bin of the mode, divided by the number of measurements in the entire bell of that mode. The "strength fraction" is the number of measurements in the central bin of the mode, divided by the number of measurements in the entire Phase I phase. */ if (!abort_phase1){ sprintf(message,"\n--> Possible capacity values:\n"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); max_merit=0.; for(i=0;i<no_modes_P1;i++){ /* Give possible capacity modes */ if (modes_P1[i].mode_value_hi > adr) { sprintf(message,"\t"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); print_bw(pathrate_fp, modes_P1[i].mode_value_lo); if (Verbose) print_bw(stdout, modes_P1[i].mode_value_lo); sprintf(message,"to"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); print_bw(pathrate_fp, modes_P1[i].mode_value_hi); if (Verbose) print_bw(stdout, modes_P1[i].mode_value_hi); // merit = (modes_P1[i].mode_cnt / (double)modes_P1[i].bell_cnt) // Weiling: merit is calculated using kurtosis as the narrowness of the bell merit = modes_P1[i].bell_kurtosis * (modes_P1[i].mode_cnt / (double)no_trains_P1); sprintf(message," - Figure of merit: %.2f\n", merit); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); if (merit > max_merit) { max_merit = merit; cap_mode_ind = i; } } } //if (max_merit>0. && !adr_narrow) if (max_merit>0.) { happy_end(modes_P1[cap_mode_ind].mode_value_lo, modes_P1[cap_mode_ind].mode_value_hi); termint(0); } /* If there is no Phase I mode that is larger than the ADR, //or if Phase II gave a very narrow distribution, the final capacity estimate is the ADR. */ else { /* If there are multiple modes in Phase II (not unique estimate for ADR), * the best choice for the capacity mode is the largest mode of Phase II */ sprintf(message,"\t"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); print_bw(pathrate_fp, adr-bin_wd/2.); if (Verbose) print_bw(stdout, adr-bin_wd/2.); sprintf(message,"to"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); print_bw(pathrate_fp, adr+bin_wd/2.); if (Verbose) print_bw(stdout, adr+bin_wd/2.); sprintf(message," - ADR mode\n"); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); happy_end(adr-bin_wd/2., adr+bin_wd/2.); termint(0); } } else{ max_merit=0.; sprintf(message,"--> Phase I was aborted.\n--> The following estimate is a lower bound for the path capacity.\n "); prntmsg(pathrate_fp); if (Verbose) prntmsg(stdout); happy_end(adr-bin_wd/2., adr+bin_wd/2.); termint(0); } exit(-1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -