netem->qnm_mask |= (SCH_NETEM_ATTR_RO_PROB |
SCH_NETEM_ATTR_RO_CORR);
}
-
+
if (tb[TCA_NETEM_CORRUPT]) {
struct tc_netem_corrupt corrupt;
-
+
nla_memcpy(&corrupt, tb[TCA_NETEM_CORRUPT], sizeof(corrupt));
netem->qnm_crpt.nmcr_probability = corrupt.probability;
netem->qnm_crpt.nmcr_correlation = corrupt.correlation;
-
+
netem->qnm_mask |= (SCH_NETEM_ATTR_CORRUPT_PROB |
SCH_NETEM_ATTR_CORRUPT_CORR);
}
-
+
/* sch_netem does not currently dump TCA_NETEM_DELAY_DIST */
netem->qnm_dist.dist_data = NULL;
netem->qnm_dist.dist_size = 0;
static void netem_free_data(struct rtnl_qdisc *qdisc)
{
struct rtnl_netem *netem;
-
+
if ( ! qdisc ) return;
-
+
netem = netem_qdisc(qdisc);
if ( ! netem ) return;
-
+
if ( netem->qnm_dist.dist_data )
free(netem->qnm_dist.dist_data);
-
+
netem = NULL;
-
+
free (qdisc->q_subdata);
}
struct tc_netem_reorder reorder;
struct tc_netem_corrupt corrupt;
struct rtnl_netem *netem;
-
+
unsigned char set_correlation = 0, set_reorder = 0,
set_corrupt = 0, set_dist = 0;
netem = netem_qdisc(qdisc);
if (!netem || !msg)
return EFAULT;
-
+
msg->nm_nlh->nlmsg_flags |= NLM_F_REQUEST;
-
+
if ( netem->qnm_ro.nmro_probability != 0 ) {
if (netem->qnm_latency == 0) {
return -NLE_MISSING_ATTR;
}
if (netem->qnm_gap == 0) netem->qnm_gap = 1;
}
- else if ( netem->qnm_gap ) {
+ else if ( netem->qnm_gap ) {
return -NLE_MISSING_ATTR;
}
}
set_correlation = 1;
}
-
+
if ( netem->qnm_corr.nmc_loss != 0 ) {
if ( netem->qnm_loss == 0 ) {
return -NLE_MISSING_ATTR;
}
set_correlation = 1;
}
-
+
if ( netem->qnm_ro.nmro_probability != 0 ) set_reorder = 1;
else if ( netem->qnm_ro.nmro_correlation != 0 ) {
return -NLE_MISSING_ATTR;
}
-
+
if ( netem->qnm_crpt.nmcr_probability != 0 ) set_corrupt = 1;
else if ( netem->qnm_crpt.nmcr_correlation != 0 ) {
return -NLE_MISSING_ATTR;
}
-
+
if ( netem->qnm_dist.dist_data && netem->qnm_dist.dist_size ) {
if (netem->qnm_latency == 0 || netem->qnm_jitter == 0) {
return -NLE_MISSING_ATTR;
/* Resize to accomodate the large distribution table */
int new_msg_len = msg->nm_size + netem->qnm_dist.dist_size *
sizeof(netem->qnm_dist.dist_data[0]);
-
+
msg->nm_nlh = (struct nlmsghdr *) realloc(msg->nm_nlh, new_msg_len);
if ( msg->nm_nlh == NULL )
return -NLE_NOMEM;
set_dist = 1;
}
}
-
+
opts.latency = netem->qnm_latency;
opts.limit = netem->qnm_limit ? netem->qnm_limit : 1000;
opts.loss = netem->qnm_loss;
opts.gap = netem->qnm_gap;
opts.duplicate = netem->qnm_duplicate;
opts.jitter = netem->qnm_jitter;
-
+
NLA_PUT(msg, TCA_OPTIONS, sizeof(opts), &opts);
-
+
if ( set_correlation ) {
cor.delay_corr = netem->qnm_corr.nmc_delay;
cor.loss_corr = netem->qnm_corr.nmc_loss;
NLA_PUT(msg, TCA_NETEM_CORR, sizeof(cor), &cor);
}
-
+
if ( set_reorder ) {
reorder.probability = netem->qnm_ro.nmro_probability;
reorder.correlation = netem->qnm_ro.nmro_correlation;
NLA_PUT(msg, TCA_NETEM_REORDER, sizeof(reorder), &reorder);
}
-
+
if ( set_corrupt ) {
corrupt.probability = netem->qnm_crpt.nmcr_probability;
corrupt.correlation = netem->qnm_crpt.nmcr_correlation;
NLA_PUT(msg, TCA_NETEM_CORRUPT, sizeof(corrupt), &corrupt);
}
-
+
if ( set_dist ) {
NLA_PUT(msg, TCA_NETEM_DELAY_DIST,
netem->qnm_dist.dist_size * sizeof(netem->qnm_dist.dist_data[0]),
*/
struct nlattr* head = (struct nlattr *)(NLMSG_DATA(msg->nm_nlh) +
NLMSG_LENGTH(sizeof(struct tcmsg)) - NLMSG_ALIGNTO);
-
+
struct nlattr* tail = (struct nlattr *)(((void *) (msg->nm_nlh)) +
NLMSG_ALIGN(msg->nm_nlh->nlmsg_len));
-
+
int old_len = head->nla_len;
head->nla_len = (void *)tail - (void *)head;
msg->nm_nlh->nlmsg_len += (head->nla_len - old_len);
-
+
return err;
nla_put_failure:
return -NLE_MSGSIZE;
netem = netem_alloc(qdisc);
if (!netem)
return -NLE_NOMEM;
-
+
netem->qnm_limit = limit;
netem->qnm_mask |= SCH_NETEM_ATTR_LIMIT;
* @name Corruption
* @{
*/
-
+
/**
* Set corruption probability of netem qdisc.
* @arg qdisc Netem qdisc to be modified.
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/" };
-
+ char *test_path[] = { "", "./", "/usr/lib/tc/", "/usr/lib64/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;
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;
+ return 0;
}
/** @} */