libnl  1.1.4
Token Bucket Filter (TBF)

Attribute Access

int rtnl_qdisc_tbf_set_limit (struct rtnl_qdisc *qdisc, int limit)
 Set limit of TBF qdisc. More...
 
int rtnl_qdisc_tbf_set_limit_by_latency (struct rtnl_qdisc *qdisc, int latency)
 Set limit of TBF qdisc by latency. More...
 
int rtnl_qdisc_tbf_get_limit (struct rtnl_qdisc *qdisc)
 Get limit of TBF qdisc. More...
 
int rtnl_qdisc_tbf_set_mpu (struct rtnl_qdisc *qdisc, int mpu)
 Set MPU of TBF qdisc. More...
 
int rtnl_qdisc_tbf_get_mpu (struct rtnl_qdisc *qdisc)
 Get MPU of TBF qdisc. More...
 
int rtnl_qdisc_tbf_set_rate (struct rtnl_qdisc *qdisc, int rate, int bucket, int cell)
 Set rate of TBF qdisc. More...
 
int rtnl_qdisc_tbf_get_rate (struct rtnl_qdisc *qdisc)
 Get rate of TBF qdisc. More...
 
int rtnl_qdisc_tbf_get_rate_bucket (struct rtnl_qdisc *qdisc)
 Get rate bucket size of TBF qdisc. More...
 
int rtnl_qdisc_tbf_get_rate_cell (struct rtnl_qdisc *qdisc)
 Get rate cell size of TBF qdisc. More...
 
int rtnl_qdisc_tbf_set_peakrate (struct rtnl_qdisc *qdisc, int rate, int bucket, int cell)
 Set peak rate of TBF qdisc. More...
 
int rtnl_qdisc_tbf_get_peakrate (struct rtnl_qdisc *qdisc)
 Get peak rate of TBF qdisc. More...
 
int rtnl_qdisc_tbf_get_peakrate_bucket (struct rtnl_qdisc *qdisc)
 Get peak rate bucket size of TBF qdisc. More...
 
int rtnl_qdisc_tbf_get_peakrate_cell (struct rtnl_qdisc *qdisc)
 Get peak rate cell size of TBF qdisc. More...
 

Detailed Description

Function Documentation

int rtnl_qdisc_tbf_set_limit ( struct rtnl_qdisc *  qdisc,
int  limit 
)
Parameters
qdiscTBF qdisc to be modified.
limitNew limit in bytes.
Returns
0 on success or a negative error code.

Definition at line 223 of file tbf.c.

Referenced by rtnl_qdisc_tbf_set_limit_by_latency().

224 {
225  struct rtnl_tbf *tbf;
226 
227  tbf = tbf_alloc(qdisc);
228  if (!tbf)
229  return nl_errno(ENOMEM);
230 
231  tbf->qt_limit = limit;
232  tbf->qt_mask |= TBF_ATTR_LIMIT;
233 
234  return 0;
235 }
int rtnl_qdisc_tbf_set_limit_by_latency ( struct rtnl_qdisc *  qdisc,
int  latency 
)
Parameters
qdiscTBF qdisc to be modified.
latencyLatency in micro seconds.

Calculates and sets the limit based on the desired latency and the configured rate and peak rate. In order for this operation to succeed, the rate and if required the peak rate must have been set in advance.

\[ limit_n = \frac{{rate_n} \times {latency}}{10^6}+{bucketsize}_n \]

\[ limit = min(limit_{rate},limit_{peak}) \]

Returns
0 on success or a negative error code.

Definition at line 266 of file tbf.c.

References rtnl_qdisc_tbf_set_limit().

267 {
268  struct rtnl_tbf *tbf;
269  double limit, limit2;
270 
271  tbf = tbf_alloc(qdisc);
272  if (!tbf)
273  return nl_errno(ENOMEM);
274 
275  if (!(tbf->qt_mask & TBF_ATTR_RATE))
276  return nl_error(EINVAL, "The rate must be specified before "
277  "limit can be calculated based on latency.");
278 
279  limit = calc_limit(&tbf->qt_rate, latency, tbf->qt_rate_bucket);
280 
281  if (tbf->qt_mask & TBF_ATTR_PEAKRATE) {
282  limit2 = calc_limit(&tbf->qt_peakrate, latency,
283  tbf->qt_peakrate_bucket);
284 
285  if (limit2 < limit)
286  limit = limit2;
287  }
288 
289  return rtnl_qdisc_tbf_set_limit(qdisc, (int) limit);
290 }
int rtnl_qdisc_tbf_get_limit ( struct rtnl_qdisc *  qdisc)
Parameters
qdiscTBF qdisc.
Returns
Limit in bytes or a negative error code.

Definition at line 297 of file tbf.c.

298 {
299  struct rtnl_tbf *tbf;
300 
301  tbf = tbf_qdisc(qdisc);
302  if (tbf && (tbf->qt_mask & TBF_ATTR_LIMIT))
303  return tbf->qt_limit;
304  return
305  nl_errno(ENOENT);
306 }
int rtnl_qdisc_tbf_set_mpu ( struct rtnl_qdisc *  qdisc,
int  mpu 
)
Parameters
qdiscTBF qdisc to be modified.
mpuNew MPU in bytes.
Returns
0 on success or a negative error code.

Definition at line 314 of file tbf.c.

315 {
316  struct rtnl_tbf *tbf;
317 
318  tbf = tbf_alloc(qdisc);
319  if (!tbf)
320  return nl_errno(ENOMEM);
321 
322  tbf->qt_mpu = mpu;
323  tbf->qt_mask |= TBF_ATTR_MPU;
324 
325  return 0;
326 }
int rtnl_qdisc_tbf_get_mpu ( struct rtnl_qdisc *  qdisc)
Parameters
qdiscTBF qdisc.
Returns
MPU in bytes or a negative error code.

Definition at line 333 of file tbf.c.

334 {
335  struct rtnl_tbf *tbf;
336 
337  tbf = tbf_qdisc(qdisc);
338  if (tbf && (tbf->qt_mask & TBF_ATTR_MPU))
339  return tbf->qt_mpu;
340  return
341  nl_errno(ENOENT);
342 }
int rtnl_qdisc_tbf_set_rate ( struct rtnl_qdisc *  qdisc,
int  rate,
int  bucket,
int  cell 
)
Parameters
qdiscTBF qdisc to be modified.
rateNew rate in bytes per second.
bucketSize of bucket in bytes.
cellSize of a rate cell or 0 to get default value.
Returns
0 on success or a negative error code.

Definition at line 369 of file tbf.c.

References rtnl_tc_calc_txtime().

371 {
372  struct rtnl_tbf *tbf;
373  int cell_log;
374 
375  tbf = tbf_alloc(qdisc);
376  if (!tbf)
377  return nl_errno(ENOMEM);
378 
379  cell_log = calc_cell_log(cell, bucket);
380  if (cell_log < 0)
381  return cell_log;
382 
383  tbf->qt_rate.rs_rate = rate;
384  tbf->qt_rate_bucket = bucket;
385  tbf->qt_rate.rs_cell_log = cell_log;
386  tbf->qt_rate_txtime = rtnl_tc_calc_txtime(bucket, rate);
387  tbf->qt_mask |= TBF_ATTR_RATE;
388 
389  return 0;
390 }
int rtnl_qdisc_tbf_get_rate ( struct rtnl_qdisc *  qdisc)
Parameters
qdiscTBF qdisc.
Returns
Rate in bytes per seconds or a negative error code.

Definition at line 397 of file tbf.c.

398 {
399  struct rtnl_tbf *tbf;
400 
401  tbf = tbf_qdisc(qdisc);
402  if (tbf && (tbf->qt_mask & TBF_ATTR_RATE))
403  return tbf->qt_rate.rs_rate;
404  else
405  return -1;
406 }
int rtnl_qdisc_tbf_get_rate_bucket ( struct rtnl_qdisc *  qdisc)
Parameters
qdiscTBF qdisc.
Returns
Size of rate bucket or a negative error code.

Definition at line 413 of file tbf.c.

414 {
415  struct rtnl_tbf *tbf;
416 
417  tbf = tbf_qdisc(qdisc);
418  if (tbf && (tbf->qt_mask & TBF_ATTR_RATE))
419  return tbf->qt_rate_bucket;
420  else
421  return -1;
422 }
int rtnl_qdisc_tbf_get_rate_cell ( struct rtnl_qdisc *  qdisc)
Parameters
qdiscTBF qdisc.
Returns
Size of rate cell in bytes or a negative error code.

Definition at line 429 of file tbf.c.

430 {
431  struct rtnl_tbf *tbf;
432 
433  tbf = tbf_qdisc(qdisc);
434  if (tbf && (tbf->qt_mask & TBF_ATTR_RATE))
435  return (1 << tbf->qt_rate.rs_cell_log);
436  else
437  return -1;
438 }
int rtnl_qdisc_tbf_set_peakrate ( struct rtnl_qdisc *  qdisc,
int  rate,
int  bucket,
int  cell 
)
Parameters
qdiscTBF qdisc to be modified.
rateNew peak rate in bytes per second.
bucketSize of peakrate bucket.
cellSize of a peakrate cell or 0 to get default value.
Returns
0 on success or a negative error code.

Definition at line 448 of file tbf.c.

References rtnl_tc_calc_txtime().

450 {
451  struct rtnl_tbf *tbf;
452  int cell_log;
453 
454  tbf = tbf_alloc(qdisc);
455  if (!tbf)
456  return nl_errno(ENOMEM);
457 
458  cell_log = calc_cell_log(cell, bucket);
459  if (cell_log < 0)
460  return cell_log;
461 
462  tbf->qt_peakrate.rs_rate = rate;
463  tbf->qt_peakrate_bucket = bucket;
464  tbf->qt_peakrate.rs_cell_log = cell_log;
465  tbf->qt_peakrate_txtime = rtnl_tc_calc_txtime(bucket, rate);
466 
467  tbf->qt_mask |= TBF_ATTR_PEAKRATE;
468 
469  return 0;
470 }
int rtnl_qdisc_tbf_get_peakrate ( struct rtnl_qdisc *  qdisc)
Parameters
qdiscTBF qdisc.
Returns
Peak rate in bytes per seconds or a negative error code.

Definition at line 477 of file tbf.c.

478 {
479  struct rtnl_tbf *tbf;
480 
481  tbf = tbf_qdisc(qdisc);
482  if (tbf && (tbf->qt_mask & TBF_ATTR_PEAKRATE))
483  return tbf->qt_peakrate.rs_rate;
484  else
485  return -1;
486 }
int rtnl_qdisc_tbf_get_peakrate_bucket ( struct rtnl_qdisc *  qdisc)
Parameters
qdiscTBF qdisc.
Returns
Size of peak rate bucket or a negative error code.

Definition at line 493 of file tbf.c.

494 {
495  struct rtnl_tbf *tbf;
496 
497  tbf = tbf_qdisc(qdisc);
498  if (tbf && (tbf->qt_mask & TBF_ATTR_PEAKRATE))
499  return tbf->qt_peakrate_bucket;
500  else
501  return -1;
502 }
int rtnl_qdisc_tbf_get_peakrate_cell ( struct rtnl_qdisc *  qdisc)
Parameters
qdiscTBF qdisc.
Returns
Size of peak rate cell in bytes or a negative error code.

Definition at line 509 of file tbf.c.

510 {
511  struct rtnl_tbf *tbf;
512 
513  tbf = tbf_qdisc(qdisc);
514  if (tbf && (tbf->qt_mask & TBF_ATTR_PEAKRATE))
515  return (1 << tbf->qt_peakrate.rs_cell_log);
516  else
517  return -1;
518 }