Logo Search packages:      
Sourcecode: libnl2 version File versions  Download package

int rtnl_netem_set_delay_distribution ( struct rtnl_qdisc *  qdisc,
const char *  dist_type 
)

Set the delay distribution. Latency/jitter must be set before applying.

  • qdisc Netem qdisc.
  • dist_type The name of the distribution (type, file, path/file).
    Returns:
    0 on success, error code on failure.

Definition at line 856 of file netem.c.

                                                                                       {
      struct rtnl_netem *netem;

      netem = netem_alloc(qdisc);
      if (!netem)
            return -NLE_NOMEM;
            
      FILE *f = NULL;
      int i, n = 0;
      size_t len = 2048;
      char *line;
      char name[NAME_MAX];
      char dist_suffix[] = ".dist";
      
      /* If the given filename already ends in .dist, don't append it later */
      char *test_suffix = strstr(dist_type, dist_suffix);
      if (test_suffix != NULL && strlen(test_suffix) == 5)
            strcpy(dist_suffix, "");
      
      /* Check several locations for the dist file */
      char *test_path[] = { "", "./", "/usr/lib/tc/", "/usr/local/lib/tc/" };
      
      for (i = 0; i < sizeof(test_path) && f == NULL; i++) {
            snprintf(name, NAME_MAX, "%s%s%s", test_path[i], dist_type, dist_suffix);
            f = fopen(name, "r");
      }
      
      if ( f == NULL )
            return -nl_syserr2nlerr(errno);
      
      netem->qnm_dist.dist_data = (int16_t *) calloc (MAXDIST, sizeof(int16_t));
      
      line = (char *) calloc (sizeof(char), len + 1);
      
      while (getline(&line, &len, f) != -1) {
            char *p, *endp;
            
            if (*line == '\n' || *line == '#')
                  continue;

            for (p = line; ; p = endp) {
                  long x = strtol(p, &endp, 0);
                  if (endp == p) break;

                  if (n >= MAXDIST) {
                        free(line);
                        fclose(f);
                        return -NLE_INVAL;
                  }
                  netem->qnm_dist.dist_data[n++] = x;
            }           
      }
      
      free(line);
      
      netem->qnm_dist.dist_size = n;
      netem->qnm_mask |= SCH_NETEM_ATTR_DIST;
      
      fclose(f);
      return 0;   
}


Generated by  Doxygen 1.6.0   Back to index