/** * Given a snap (likely read from a log) read a value as a double. * Upon failure will exit the program with error code EXIT_FAILURE. * * * @param name The name of the variable to read in Web100/Web10G. * @param snap A Web100/Web10G snap * @param group A Web100 group - ignored by Web10G should be NULL * @param agent A Web100 agent - ignored by Web10G should be NULL * * @return The value of 'name' covnerted to a double. */ double tcp_stat_read_double(const char * name, tcp_stat_snap* snap, tcp_stat_group* group, tcp_stat_agent* agent) { #if USE_WEB100 web100_var* var; char buf[256]; #elif USE_WEB10G estats_val val; #endif #if USE_WEB100 if ((web100_agent_find_var_and_group(agent, name, &group, &var)) != WEB100_ERR_SUCCESS) { web100_perror("web100_agent_find_var_and_group"); exit(EXIT_FAILURE); } if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) { web100_perror("web100_snap_read"); exit(EXIT_FAILURE); } return atof( web100_value_to_text(web100_get_var_type(var), buf)); #elif USE_WEB10G int vartype = ESTATS_UNSIGNED32; /* ELAPSED_TIME not working in kernel patch, so use time on the * snap */ if (strcmp(name, ELAPSED_TIME) == 0) { val.masked = 0; val.uv32 = snap->tv.sec * 1000000 + snap->tv.usec - start_time; } else { vartype = web10g_find_val(snap, name, &val); if (vartype == -1) { printf("Bad vartype tcp_stat_read_double %s\n", name); exit(EXIT_FAILURE); } } switch (vartype) { case ESTATS_UNSIGNED64: return (double) val.uv64; case ESTATS_UNSIGNED32: return (double) val.uv32; case ESTATS_SIGNED32: return (double) val.sv32; case ESTATS_UNSIGNED16: return (double) val.uv16; case ESTATS_UNSIGNED8: return (double) val.uv8; } fprintf(stderr, "Bad vartype tcp_stat_read_double %s\n", name); exit(EXIT_FAILURE); #endif }
/** * Count the CWND peaks from a snapshot and record the minimal and maximum one. * Also record the number of transitions between increasing or decreasing * trends of the values. * @param agent Web100 agent used to track the connection * @param peaks Structure containing CWND peaks information * @param snap Web100 snapshot structure */ void findCwndPeaks(tcp_stat_agent* agent, CwndPeaks* peaks, tcp_stat_snap* snap) { int CurCwnd; #if USE_WEB100 web100_group* group; web100_var* var; char tmpstr[256]; #elif USE_WEB10G struct estats_val value; #endif #if USE_WEB100 web100_agent_find_var_and_group(agent, "CurCwnd", &group, &var); web100_snap_read(var, snap, tmpstr); CurCwnd = atoi(web100_value_to_text(web100_get_var_type(var), tmpstr)); #elif USE_WEB10G web10g_find_val(snap, "CurCwnd", &value); CurCwnd = value.uv32; #endif if (slowStart) { if (CurCwnd < prevCWNDval) { slowStart = 0; peaks->max = prevCWNDval; peaks->amount = 1; decreasing = 1; } } else { // current congestion window < previous value, so, decreasing if (CurCwnd < prevCWNDval) { // update values based on actual values if (prevCWNDval > peaks->max) { peaks->max = prevCWNDval; } if (!decreasing) { peaks->amount += 1; } decreasing = 1; // current congestion window size > previous value, } else if (CurCwnd > prevCWNDval) { // not decreasing. if ((peaks->min == -1) || (prevCWNDval < peaks->min)) { peaks->min = prevCWNDval; } decreasing = 0; } } prevCWNDval = CurCwnd; }