Token Bucket Filter (TBF)
[Queueing Discipline Modules]

Attribute Access



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

Function Documentation

int rtnl_qdisc_tbf_set_limit ( struct rtnl_qdisc *  qdisc,
int  limit 
)
Parameters:
qdisc TBF qdisc to be modified.
limit New 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().

00224 {
00225         struct rtnl_tbf *tbf;
00226         
00227         tbf = tbf_alloc(qdisc);
00228         if (!tbf)
00229                 return nl_errno(ENOMEM);
00230 
00231         tbf->qt_limit = limit;
00232         tbf->qt_mask |= TBF_ATTR_LIMIT;
00233 
00234         return 0;
00235 }

int rtnl_qdisc_tbf_set_limit_by_latency ( struct rtnl_qdisc *  qdisc,
int  latency 
)
Parameters:
qdisc TBF qdisc to be modified.
latency Latency 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().

00267 {
00268         struct rtnl_tbf *tbf;
00269         double limit, limit2;
00270 
00271         tbf = tbf_alloc(qdisc);
00272         if (!tbf)
00273                 return nl_errno(ENOMEM);
00274 
00275         if (!(tbf->qt_mask & TBF_ATTR_RATE))
00276                 return nl_error(EINVAL, "The rate must be specified before "
00277                                 "limit can be calculated based on latency.");
00278 
00279         limit = calc_limit(&tbf->qt_rate, latency, tbf->qt_rate_bucket);
00280 
00281         if (tbf->qt_mask & TBF_ATTR_PEAKRATE) {
00282                 limit2 = calc_limit(&tbf->qt_peakrate, latency,
00283                                     tbf->qt_peakrate_bucket);
00284 
00285                 if (limit2 < limit)
00286                         limit = limit2;
00287         }
00288 
00289         return rtnl_qdisc_tbf_set_limit(qdisc, (int) limit);
00290 }

int rtnl_qdisc_tbf_get_limit ( struct rtnl_qdisc *  qdisc  ) 
Parameters:
qdisc TBF qdisc.
Returns:
Limit in bytes or a negative error code.

Definition at line 297 of file tbf.c.

00298 {
00299         struct rtnl_tbf *tbf;
00300         
00301         tbf = tbf_qdisc(qdisc);
00302         if (tbf && (tbf->qt_mask & TBF_ATTR_LIMIT))
00303                 return tbf->qt_limit;
00304         return
00305                 nl_errno(ENOENT);
00306 }

int rtnl_qdisc_tbf_set_mpu ( struct rtnl_qdisc *  qdisc,
int  mpu 
)
Parameters:
qdisc TBF qdisc to be modified.
mpu New MPU in bytes.
Returns:
0 on success or a negative error code.

Definition at line 314 of file tbf.c.

00315 {
00316         struct rtnl_tbf *tbf;
00317         
00318         tbf = tbf_alloc(qdisc);
00319         if (!tbf)
00320                 return nl_errno(ENOMEM);
00321 
00322         tbf->qt_mpu = mpu;
00323         tbf->qt_mask |= TBF_ATTR_MPU;
00324 
00325         return 0;
00326 }

int rtnl_qdisc_tbf_get_mpu ( struct rtnl_qdisc *  qdisc  ) 
Parameters:
qdisc TBF qdisc.
Returns:
MPU in bytes or a negative error code.

Definition at line 333 of file tbf.c.

00334 {
00335         struct rtnl_tbf *tbf;
00336         
00337         tbf = tbf_qdisc(qdisc);
00338         if (tbf && (tbf->qt_mask & TBF_ATTR_MPU))
00339                 return tbf->qt_mpu;
00340         return
00341                 nl_errno(ENOENT);
00342 }

int rtnl_qdisc_tbf_set_rate ( struct rtnl_qdisc *  qdisc,
int  rate,
int  bucket,
int  cell 
)
Parameters:
qdisc TBF qdisc to be modified.
rate New rate in bytes per second.
bucket Size of bucket in bytes.
cell Size 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().

00371 {
00372         struct rtnl_tbf *tbf;
00373         int cell_log;
00374         
00375         tbf = tbf_alloc(qdisc);
00376         if (!tbf)
00377                 return nl_errno(ENOMEM);
00378 
00379         cell_log = calc_cell_log(cell, bucket);
00380         if (cell_log < 0)
00381                 return cell_log;
00382 
00383         tbf->qt_rate.rs_rate = rate;
00384         tbf->qt_rate_bucket = bucket;
00385         tbf->qt_rate.rs_cell_log = cell_log;
00386         tbf->qt_rate_txtime = rtnl_tc_calc_txtime(bucket, rate);
00387         tbf->qt_mask |= TBF_ATTR_RATE;
00388 
00389         return 0;
00390 }

int rtnl_qdisc_tbf_get_rate ( struct rtnl_qdisc *  qdisc  ) 
Parameters:
qdisc TBF qdisc.
Returns:
Rate in bytes per seconds or a negative error code.

Definition at line 397 of file tbf.c.

00398 {
00399         struct rtnl_tbf *tbf;
00400 
00401         tbf = tbf_qdisc(qdisc);
00402         if (tbf && (tbf->qt_mask & TBF_ATTR_RATE))
00403                 return tbf->qt_rate.rs_rate;
00404         else
00405                 return -1;
00406 }

int rtnl_qdisc_tbf_get_rate_bucket ( struct rtnl_qdisc *  qdisc  ) 
Parameters:
qdisc TBF qdisc.
Returns:
Size of rate bucket or a negative error code.

Definition at line 413 of file tbf.c.

00414 {
00415         struct rtnl_tbf *tbf;
00416 
00417         tbf = tbf_qdisc(qdisc);
00418         if (tbf && (tbf->qt_mask & TBF_ATTR_RATE))
00419                 return tbf->qt_rate_bucket;
00420         else
00421                 return -1;
00422 }

int rtnl_qdisc_tbf_get_rate_cell ( struct rtnl_qdisc *  qdisc  ) 
Parameters:
qdisc TBF qdisc.
Returns:
Size of rate cell in bytes or a negative error code.

Definition at line 429 of file tbf.c.

00430 {
00431         struct rtnl_tbf *tbf;
00432 
00433         tbf = tbf_qdisc(qdisc);
00434         if (tbf && (tbf->qt_mask & TBF_ATTR_RATE))
00435                 return (1 << tbf->qt_rate.rs_cell_log);
00436         else
00437                 return -1;
00438 }

int rtnl_qdisc_tbf_set_peakrate ( struct rtnl_qdisc *  qdisc,
int  rate,
int  bucket,
int  cell 
)
Parameters:
qdisc TBF qdisc to be modified.
rate New peak rate in bytes per second.
bucket Size of peakrate bucket.
cell Size 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().

00450 {
00451         struct rtnl_tbf *tbf;
00452         int cell_log;
00453         
00454         tbf = tbf_alloc(qdisc);
00455         if (!tbf)
00456                 return nl_errno(ENOMEM);
00457 
00458         cell_log = calc_cell_log(cell, bucket);
00459         if (cell_log < 0)
00460                 return cell_log;
00461 
00462         tbf->qt_peakrate.rs_rate = rate;
00463         tbf->qt_peakrate_bucket = bucket;
00464         tbf->qt_peakrate.rs_cell_log = cell_log;
00465         tbf->qt_peakrate_txtime = rtnl_tc_calc_txtime(bucket, rate);
00466         
00467         tbf->qt_mask |= TBF_ATTR_PEAKRATE;
00468 
00469         return 0;
00470 }

int rtnl_qdisc_tbf_get_peakrate ( struct rtnl_qdisc *  qdisc  ) 
Parameters:
qdisc TBF qdisc.
Returns:
Peak rate in bytes per seconds or a negative error code.

Definition at line 477 of file tbf.c.

00478 {
00479         struct rtnl_tbf *tbf;
00480 
00481         tbf = tbf_qdisc(qdisc);
00482         if (tbf && (tbf->qt_mask & TBF_ATTR_PEAKRATE))
00483                 return tbf->qt_peakrate.rs_rate;
00484         else
00485                 return -1;
00486 }

int rtnl_qdisc_tbf_get_peakrate_bucket ( struct rtnl_qdisc *  qdisc  ) 
Parameters:
qdisc TBF qdisc.
Returns:
Size of peak rate bucket or a negative error code.

Definition at line 493 of file tbf.c.

00494 {
00495         struct rtnl_tbf *tbf;
00496 
00497         tbf = tbf_qdisc(qdisc);
00498         if (tbf && (tbf->qt_mask & TBF_ATTR_PEAKRATE))
00499                 return tbf->qt_peakrate_bucket;
00500         else
00501                 return -1;
00502 }

int rtnl_qdisc_tbf_get_peakrate_cell ( struct rtnl_qdisc *  qdisc  ) 
Parameters:
qdisc TBF qdisc.
Returns:
Size of peak rate cell in bytes or a negative error code.

Definition at line 509 of file tbf.c.

00510 {
00511         struct rtnl_tbf *tbf;
00512 
00513         tbf = tbf_qdisc(qdisc);
00514         if (tbf && (tbf->qt_mask & TBF_ATTR_PEAKRATE))
00515                 return (1 << tbf->qt_peakrate.rs_cell_log);
00516         else
00517                 return -1;
00518 }


Generated on 30 Oct 2009 for libnl by  doxygen 1.6.1