Traffic Control
[Routing Netlink]

Modules

 Queueing Classes
 Classifiers
 Queueing Disciplines

Defines

#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.
int rtnl_tc_calc_bufsize (int txtime, int rate)
 Calculate buffer size able to transmit in a specific time and rate.
int rtnl_tc_calc_cell_log (int cell_size)
 Calculate the binary logarithm for a specific cell size.

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.

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).
int rtnl_tc_str2handle (const char *name, uint32_t *res)
 Convert a charactering strint to a traffic control handle.

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.

00027                       {
00028         RTNL_TC_PACKETS,        /**< Packets seen */
00029         RTNL_TC_BYTES,          /**< Bytes seen */
00030         RTNL_TC_RATE_BPS,       /**< Current bits/s (rate estimator) */
00031         RTNL_TC_RATE_PPS,       /**< Current packet/s (rate estimator) */
00032         RTNL_TC_QLEN,           /**< Queue length */
00033         RTNL_TC_BACKLOG,        /**< Backlog length */
00034         RTNL_TC_DROPS,          /**< Packets dropped */
00035         RTNL_TC_REQUEUES,       /**< Number of requeues */
00036         RTNL_TC_OVERLIMITS,     /**< Number of overlimits */
00037         __RTNL_TC_STATS_MAX,
00038 };


Function Documentation

int rtnl_tc_calc_txtime ( int  bufsize,
int  rate 
)
Parameters:
bufsize Size of buffer to be transmited in bytes.
rate Transmit 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().

00384 {
00385         double tx_time_secs;
00386         
00387         tx_time_secs = (double) bufsize / (double) rate;
00388 
00389         return tx_time_secs * 1000000.;
00390 }

int rtnl_tc_calc_bufsize ( int  txtime,
int  rate 
)
Parameters:
txtime Available transmit time in micro seconds.
rate Transmit 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.

00407 {
00408         double bufsize;
00409 
00410         bufsize = (double) txtime * (double) rate;
00411 
00412         return bufsize / 1000000.;
00413 }

int rtnl_tc_calc_cell_log ( int  cell_size  ) 
Parameters:
cell_size Size 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().

00421 {
00422         int i;
00423 
00424         for (i = 0; i < 32; i++)
00425                 if ((1 << i) == cell_size)
00426                         return i;
00427 
00428         return nl_errno(EINVAL);
00429 }

int rtnl_tc_build_rate_table ( uint32_t *  dst,
uint8_t  mpu,
uint8_t  overhead,
int  cell,
int  rate 
)
Parameters:
dst Destination buffer of RTNL_TC_RTABLE_SIZE uint32_t[].
mpu Minimal size of a packet at all times.
overhead Overhead to be added to each packet.
cell Size of cell, i.e. size of step between entries in bytes.
rate Rate 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.

00456 {
00457         int i, size, cell_log;
00458 
00459         cell_log = rtnl_tc_calc_cell_log(cell);
00460         if (cell_log < 0)
00461                 return cell_log;
00462 
00463         for (i = 0; i < RTNL_TC_RTABLE_SIZE; i++) {
00464                 size = (i << cell_log) + overhead;
00465                 if (size < mpu)
00466                         size = mpu;
00467 
00468                 dst[i] = rtnl_tc_calc_txtime(size, rate);
00469         }
00470 
00471         return 0;
00472 }

char* rtnl_tc_handle2str ( uint32_t  handle,
char *  buf,
size_t  len 
)
Parameters:
handle traffic control handle
buf destination buffer
len buffer 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.

00494 {
00495         if (TC_H_ROOT == handle)
00496                 snprintf(buf, len, "root");
00497         else if (TC_H_UNSPEC == handle)
00498                 snprintf(buf, len, "none");
00499         else if (0 == TC_H_MAJ(handle))
00500                 snprintf(buf, len, ":%02x", TC_H_MIN(handle));
00501         else if (0 == TC_H_MIN(handle))
00502                 snprintf(buf, len, "%02x:", TC_H_MAJ(handle) >> 16);
00503         else
00504                 snprintf(buf, len, "%02x:%02x",
00505                         TC_H_MAJ(handle) >> 16, TC_H_MIN(handle));
00506 
00507         return buf;
00508 }

int rtnl_tc_str2handle ( const char *  name,
uint32_t *  res 
)
Parameters:
name traffic control handle as character string
res destination 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.

00529 {
00530         char *colon, *end;
00531         uint32_t h;
00532 
00533         if (!strcasecmp(name, "root")) {
00534                 *res = TC_H_ROOT;
00535                 return 0;
00536         }
00537 
00538         if (!strcasecmp(name, "none")) {
00539                 *res = TC_H_UNSPEC;
00540                 return 0;
00541         }
00542 
00543         h = strtoul(name, &colon, 16);
00544 
00545         if (colon == name) {
00546                 /* :YYYY */
00547                 h = 0;
00548                 if (':' != *colon)
00549                         return -EINVAL;
00550         }
00551 
00552         if (':' == *colon) {
00553                 /* check if we would lose bits */
00554                 if (TC_H_MAJ(h))
00555                         return -ERANGE;
00556                 h <<= 16;
00557 
00558                 if ('\0' == colon[1]) {
00559                         /* XXXX: */
00560                         *res = h;
00561                 } else {
00562                         /* XXXX:YYYY */
00563                         uint32_t l = strtoul(colon+1, &end, 16);
00564 
00565                         /* check if we overlap with major part */
00566                         if (TC_H_MAJ(l))
00567                                 return -ERANGE;
00568 
00569                         if ('\0' != *end)
00570                                 return -EINVAL;
00571 
00572                         *res = (h | l);
00573                 }
00574         } else if ('\0' == *colon) {
00575                 /* XXXXYYYY */
00576                 *res = h;
00577         } else
00578                 return -EINVAL;
00579 
00580         return 0;
00581 }


Generated on 30 Oct 2009 for libnl by  doxygen 1.6.1