libnl  1.1.4
Modules | Macros | Enumerations
Traffic Control

Modules

 Queueing Classes
 
 Classifiers
 
 Queueing Disciplines
 

Macros

#define RTNL_TC_RTABLE_SIZE   256
 Number of entries in a transmission time lookup table.
 

Enumerations

enum  rtnl_tc_stats_id {
  RTNL_TC_PACKETS, RTNL_TC_BYTES, RTNL_TC_RATE_BPS, RTNL_TC_RATE_PPS,
  RTNL_TC_QLEN, RTNL_TC_BACKLOG, RTNL_TC_DROPS, RTNL_TC_REQUEUES,
  RTNL_TC_OVERLIMITS, __RTNL_TC_STATS_MAX
}
 TC statistics identifiers. More...
 

Utilities

int rtnl_tc_calc_txtime (int bufsize, int rate)
 Calculate time required to transmit buffer at a specific rate. More...
 
int rtnl_tc_calc_bufsize (int txtime, int rate)
 Calculate buffer size able to transmit in a specific time and rate. More...
 
int rtnl_tc_calc_cell_log (int cell_size)
 Calculate the binary logarithm for a specific cell size. More...
 

Rate Tables

int rtnl_tc_build_rate_table (uint32_t *dst, uint8_t mpu, uint8_t overhead, int cell, int rate)
 Compute a transmission time lookup table. More...
 

Traffic Control Handle Translations

char * rtnl_tc_handle2str (uint32_t handle, char *buf, size_t len)
 Convert a traffic control handle to a character string (Reentrant). More...
 
int rtnl_tc_str2handle (const char *name, uint32_t *res)
 Convert a charactering strint to a traffic control handle. More...
 

Detailed Description

Enumeration Type Documentation

Enumerator
RTNL_TC_PACKETS 

Packets seen.

RTNL_TC_BYTES 

Bytes seen.

RTNL_TC_RATE_BPS 

Current bits/s (rate estimator)

RTNL_TC_RATE_PPS 

Current packet/s (rate estimator)

RTNL_TC_QLEN 

Queue length.

RTNL_TC_BACKLOG 

Backlog length.

RTNL_TC_DROPS 

Packets dropped.

RTNL_TC_REQUEUES 

Number of requeues.

RTNL_TC_OVERLIMITS 

Number of overlimits.

Definition at line 27 of file tc.h.

27  {
28  RTNL_TC_PACKETS, /**< Packets seen */
29  RTNL_TC_BYTES, /**< Bytes seen */
30  RTNL_TC_RATE_BPS, /**< Current bits/s (rate estimator) */
31  RTNL_TC_RATE_PPS, /**< Current packet/s (rate estimator) */
32  RTNL_TC_QLEN, /**< Queue length */
33  RTNL_TC_BACKLOG, /**< Backlog length */
34  RTNL_TC_DROPS, /**< Packets dropped */
35  RTNL_TC_REQUEUES, /**< Number of requeues */
36  RTNL_TC_OVERLIMITS, /**< Number of overlimits */
37  __RTNL_TC_STATS_MAX,
38 };
Bytes seen.
Definition: tc.h:29
Current packet/s (rate estimator)
Definition: tc.h:31
Number of overlimits.
Definition: tc.h:36
Backlog length.
Definition: tc.h:33
Queue length.
Definition: tc.h:32
Packets seen.
Definition: tc.h:28
Current bits/s (rate estimator)
Definition: tc.h:30
Packets dropped.
Definition: tc.h:34
Number of requeues.
Definition: tc.h:35

Function Documentation

int rtnl_tc_calc_txtime ( int  bufsize,
int  rate 
)
Parameters
bufsizeSize of buffer to be transmited in bytes.
rateTransmit rate in bytes per second.

Calculates the number of micro seconds required to transmit a specific buffer at a specific transmit rate.

\[ txtime=\frac{bufsize}{rate}10^6 \]

Returns
Required transmit time in micro seconds.

Definition at line 383 of file tc.c.

Referenced by rtnl_qdisc_tbf_set_peakrate(), rtnl_qdisc_tbf_set_rate(), and rtnl_tc_build_rate_table().

384 {
385  double tx_time_secs;
386 
387  tx_time_secs = (double) bufsize / (double) rate;
388 
389  return tx_time_secs * 1000000.;
390 }
int rtnl_tc_calc_bufsize ( int  txtime,
int  rate 
)
Parameters
txtimeAvailable transmit time in micro seconds.
rateTransmit rate in bytes per second.

Calculates the size of the buffer that can be transmitted in a specific time period at a specific transmit rate.

\[ bufsize=\frac{{txtime} \times {rate}}{10^6} \]

Returns
Size of buffer in bytes.

Definition at line 406 of file tc.c.

407 {
408  double bufsize;
409 
410  bufsize = (double) txtime * (double) rate;
411 
412  return bufsize / 1000000.;
413 }
int rtnl_tc_calc_cell_log ( int  cell_size)
Parameters
cell_sizeSize of cell, must be a power of two.
Returns
Binary logirhtm of cell size or a negative error code.

Definition at line 420 of file tc.c.

Referenced by rtnl_tc_build_rate_table().

421 {
422  int i;
423 
424  for (i = 0; i < 32; i++)
425  if ((1 << i) == cell_size)
426  return i;
427 
428  return nl_errno(EINVAL);
429 }
int rtnl_tc_build_rate_table ( uint32_t *  dst,
uint8_t  mpu,
uint8_t  overhead,
int  cell,
int  rate 
)
Parameters
dstDestination buffer of RTNL_TC_RTABLE_SIZE uint32_t[].
mpuMinimal size of a packet at all times.
overheadOverhead to be added to each packet.
cellSize of cell, i.e. size of step between entries in bytes.
rateRate in bytes per second.

Computes a table of RTNL_TC_RTABLE_SIZE entries specyfing the transmission times for various packet sizes, e.g. the transmission time for a packet of size pktsize could be looked up:

* txtime = table[pktsize >> log2(cell)];
*

Definition at line 454 of file tc.c.

References rtnl_tc_calc_cell_log(), rtnl_tc_calc_txtime(), and RTNL_TC_RTABLE_SIZE.

456 {
457  int i, size, cell_log;
458 
459  cell_log = rtnl_tc_calc_cell_log(cell);
460  if (cell_log < 0)
461  return cell_log;
462 
463  for (i = 0; i < RTNL_TC_RTABLE_SIZE; i++) {
464  size = (i << cell_log) + overhead;
465  if (size < mpu)
466  size = mpu;
467 
468  dst[i] = rtnl_tc_calc_txtime(size, rate);
469  }
470 
471  return 0;
472 }
int rtnl_tc_calc_txtime(int bufsize, int rate)
Calculate time required to transmit buffer at a specific rate.
Definition: tc.c:383
#define RTNL_TC_RTABLE_SIZE
Number of entries in a transmission time lookup table.
Definition: tc.h:50
int rtnl_tc_calc_cell_log(int cell_size)
Calculate the binary logarithm for a specific cell size.
Definition: tc.c:420
char* rtnl_tc_handle2str ( uint32_t  handle,
char *  buf,
size_t  len 
)
Parameters
handletraffic control handle
bufdestination buffer
lenbuffer length

Converts a tarffic control handle to a character string in the form of MAJ:MIN and stores it in the specified destination buffer.

Returns
The destination buffer or the type encoded in hexidecimal form if no match was found.

Definition at line 493 of file tc.c.

494 {
495  if (TC_H_ROOT == handle)
496  snprintf(buf, len, "root");
497  else if (TC_H_UNSPEC == handle)
498  snprintf(buf, len, "none");
499  else if (0 == TC_H_MAJ(handle))
500  snprintf(buf, len, ":%02x", TC_H_MIN(handle));
501  else if (0 == TC_H_MIN(handle))
502  snprintf(buf, len, "%02x:", TC_H_MAJ(handle) >> 16);
503  else
504  snprintf(buf, len, "%02x:%02x",
505  TC_H_MAJ(handle) >> 16, TC_H_MIN(handle));
506 
507  return buf;
508 }
int rtnl_tc_str2handle ( const char *  name,
uint32_t *  res 
)
Parameters
nametraffic control handle as character string
resdestination buffer

Converts the provided character string specifying a traffic control handle to the corresponding numeric value.

The handle must be provided in one of the following formats:

  • root
  • none
  • XXXX:
  • :YYYY
  • XXXX:YYYY
  • XXXXYYYY
Returns
0 on success or a negative error code

Definition at line 528 of file tc.c.

529 {
530  char *colon, *end;
531  uint32_t h;
532 
533  if (!strcasecmp(name, "root")) {
534  *res = TC_H_ROOT;
535  return 0;
536  }
537 
538  if (!strcasecmp(name, "none")) {
539  *res = TC_H_UNSPEC;
540  return 0;
541  }
542 
543  h = strtoul(name, &colon, 16);
544 
545  if (colon == name) {
546  /* :YYYY */
547  h = 0;
548  if (':' != *colon)
549  return -EINVAL;
550  }
551 
552  if (':' == *colon) {
553  /* check if we would lose bits */
554  if (TC_H_MAJ(h))
555  return -ERANGE;
556  h <<= 16;
557 
558  if ('\0' == colon[1]) {
559  /* XXXX: */
560  *res = h;
561  } else {
562  /* XXXX:YYYY */
563  uint32_t l = strtoul(colon+1, &end, 16);
564 
565  /* check if we overlap with major part */
566  if (TC_H_MAJ(l))
567  return -ERANGE;
568 
569  if ('\0' != *end)
570  return -EINVAL;
571 
572  *res = (h | l);
573  }
574  } else if ('\0' == *colon) {
575  /* XXXXYYYY */
576  *res = h;
577  } else
578  return -EINVAL;
579 
580  return 0;
581 }