+
+ token = strtok_r(&argv[i][4],":", &tokptr);
+ token_idx = error_flag = 0;
+ while (token != NULL)
+ {
+ switch(token_idx)
+ {
+ case 0:
+ if (sscanf(token,CF_NAM_FMT,
+ rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam) != 1)
+ rrd_set_error("Failed to parse CF name");
+ switch(cf_conv(rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam))
+ {
+ case CF_HWPREDICT:
+ /* initialize some parameters */
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_hw_alpha].u_val = 0.1;
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_hw_beta].u_val = 1.0/288;
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_dependent_rra_idx].u_cnt =
+ rrd.stat_head -> rra_cnt;
+ break;
+ case CF_DEVSEASONAL:
+ case CF_SEASONAL:
+ /* initialize some parameters */
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_seasonal_gamma].u_val = 0.1;
+ /* fall through */
+ case CF_DEVPREDICT:
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_dependent_rra_idx].u_cnt = -1;
+ break;
+ case CF_FAILURES:
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_delta_pos].u_val = 2.0;
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_delta_neg].u_val = 2.0;
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_window_len].u_cnt = 3;
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_failure_threshold].u_cnt = 2;
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_dependent_rra_idx].u_cnt = -1;
+ break;
+ /* invalid consolidation function */
+ case -1:
+ rrd_set_error("Unrecognized consolidation function %s",
+ rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam);
+ default:
+ break;
+ }
+ /* default: 1 pdp per cdp */
+ rrd.rra_def[rrd.stat_head->rra_cnt].pdp_cnt = 1;
+ break;
+ case 1:
+ switch(cf_conv(rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam))
+ {
+ case CF_HWPREDICT:
+ case CF_DEVSEASONAL:
+ case CF_SEASONAL:
+ case CF_DEVPREDICT:
+ case CF_FAILURES:
+ rrd.rra_def[rrd.stat_head->rra_cnt].row_cnt = atoi(token);
+ break;
+ default:
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_cdp_xff_val].u_val = atof(token);
+ if (rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_cdp_xff_val].u_val<0.0 ||
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_cdp_xff_val].u_val>=1.0)
+ rrd_set_error("Invalid xff: must be between 0 and 1");
+ break;
+ }
+ break;
+ case 2:
+ switch(cf_conv(rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam))
+ {
+ case CF_HWPREDICT:
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_hw_alpha].u_val = atof(token);
+ if (atof(token) <= 0.0 || atof(token) >= 1.0)
+ rrd_set_error("Invalid alpha: must be between 0 and 1");
+ break;
+ case CF_DEVSEASONAL:
+ case CF_SEASONAL:
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_seasonal_gamma].u_val =
+ atof(token);
+ if (atof(token) <= 0.0 || atof(token) >= 1.0)
+ rrd_set_error("Invalid gamma: must be between 0 and 1");
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_seasonal_smooth_idx].u_cnt
+ = hashed_name % rrd.rra_def[rrd.stat_head->rra_cnt].row_cnt;
+ break;
+ case CF_FAILURES:
+ /* specifies the # of violations that constitutes the failure threshold */
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_failure_threshold].u_cnt =
+ atoi(token);
+ if (atoi(token) < 1 || atoi(token) > MAX_FAILURES_WINDOW_LEN)
+ rrd_set_error("Failure threshold is out of range %d, %d",1,
+ MAX_FAILURES_WINDOW_LEN);
+ break;
+ case CF_DEVPREDICT:
+ /* specifies the index (1-based) of CF_DEVSEASONAL array
+ * associated with this CF_DEVPREDICT array. */
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_dependent_rra_idx].u_cnt =
+ atoi(token) - 1;
+ break;
+ default:
+ rrd.rra_def[rrd.stat_head->rra_cnt].pdp_cnt = atoi(token);
+ break;
+ }
+ break;
+ case 3:
+ switch(cf_conv(rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam))
+ {
+ case CF_HWPREDICT:
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_hw_beta].u_val = atof(token);
+ if (atof(token) < 0.0 || atof(token) > 1.0)
+ rrd_set_error("Invalid beta: must be between 0 and 1");
+ break;
+ case CF_DEVSEASONAL:
+ case CF_SEASONAL:
+ /* specifies the index (1-based) of CF_HWPREDICT array
+ * associated with this CF_DEVSEASONAL or CF_SEASONAL array.
+ * */
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_dependent_rra_idx].u_cnt =
+ atoi(token) - 1;
+ break;
+ case CF_FAILURES:
+ /* specifies the window length */
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_window_len].u_cnt =
+ atoi(token);
+ if (atoi(token) < 1 || atoi(token) > MAX_FAILURES_WINDOW_LEN)
+ rrd_set_error("Window length is out of range %d, %d",1,
+ MAX_FAILURES_WINDOW_LEN);
+ /* verify that window length exceeds the failure threshold */
+ if (rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_window_len].u_cnt <
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_failure_threshold].u_cnt)
+ rrd_set_error("Window length is shorter than the failure threshold");
+ break;
+ case CF_DEVPREDICT:
+ /* shouldn't be any more arguments */
+ rrd_set_error("Unexpected extra argument for consolidation function DEVPREDICT");
+ break;
+ default:
+ rrd.rra_def[rrd.stat_head->rra_cnt].row_cnt = atoi(token);
+ break;
+ }
+ break;
+ case 4:
+ switch(cf_conv(rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam))
+ {
+ case CF_FAILURES:
+ /* specifies the index (1-based) of CF_DEVSEASONAL array
+ * associated with this CF_DEVFAILURES array. */
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_dependent_rra_idx].u_cnt =
+ atoi(token) - 1;
+ break;
+ case CF_HWPREDICT:
+ /* length of the associated CF_SEASONAL and CF_DEVSEASONAL arrays. */
+ period = atoi(token);
+ if (period > rrd.rra_def[rrd.stat_head->rra_cnt].row_cnt)
+ rrd_set_error("Length of seasonal cycle exceeds length of HW prediction array");
+ break;
+ default:
+ /* shouldn't be any more arguments */
+ rrd_set_error("Unexpected extra argument for consolidation function %s",
+ rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam);
+ break;
+ }
+ break;
+ case 5:
+ /* If we are here, this must be a CF_HWPREDICT RRA.
+ * Specifies the index (1-based) of CF_SEASONAL array
+ * associated with this CF_HWPREDICT array. If this argument
+ * is missing, then the CF_SEASONAL, CF_DEVSEASONAL, CF_DEVPREDICT,
+ * CF_FAILURES.
+ * arrays are created automatically. */
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_dependent_rra_idx].u_cnt =
+ atoi(token) - 1;
+ break;
+ default:
+ /* should never get here */
+ rrd_set_error("Unknown error");
+ break;
+ } /* end switch */
+ if (rrd_test_error())
+ {
+ /* all errors are unrecoverable */
+ rrd_free(&rrd);
+ return (-1);
+ }
+ token = strtok_r(NULL,":", &tokptr);
+ token_idx++;
+ } /* end while */
+#ifdef DEBUG
+ fprintf(stderr,"Creating RRA CF: %s, dep idx %lu, current idx %lu\n",
+ rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam,
+ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_dependent_rra_idx].u_cnt,
+ rrd.stat_head -> rra_cnt);
+#endif
+ /* should we create CF_SEASONAL, CF_DEVSEASONAL, and CF_DEVPREDICT? */
+ if (cf_conv(rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam) == CF_HWPREDICT
+ && rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_dependent_rra_idx].u_cnt
+ == rrd.stat_head -> rra_cnt)
+ {
+#ifdef DEBUG
+ fprintf(stderr,"Creating HW contingent RRAs\n");
+#endif
+ if (create_hw_contingent_rras(&rrd,period,hashed_name) == -1) {
+ rrd_set_error("creating contingent RRA");
+ rrd_free(&rrd);
+ return -1;
+ }