libnl 3.5.0

tc.h
1 /*
2 * netlink/route/tc.h Traffic Control
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
7 * of the License.
8 *
9 * Copyright (c) 2003-2011 Thomas Graf <tgraf@suug.ch>
10 */
11
12 #ifndef NETLINK_TC_H_
13 #define NETLINK_TC_H_
14
15 #include <netlink/netlink.h>
16 #include <netlink/cache.h>
17 #include <netlink/data.h>
18 #include <netlink/route/link.h>
19 #include <linux/pkt_sched.h>
20 #include <linux/pkt_cls.h>
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 enum rtnl_tc_type {
27 RTNL_TC_TYPE_QDISC,
28 RTNL_TC_TYPE_CLASS,
29 RTNL_TC_TYPE_CLS,
30 RTNL_TC_TYPE_ACT,
31 __RTNL_TC_TYPE_MAX,
32 };
33
34 #define RTNL_TC_TYPE_MAX (__RTNL_TC_TYPE_MAX - 1)
35
36 /**
37 * Compute tc handle based on major and minor parts
38 * @ingroup tc
39 */
40 #define TC_HANDLE(maj, min) (TC_H_MAJ((maj) << 16) | TC_H_MIN(min))
41
42 /**
43 * Traffic control object
44 * @ingroup tc
45 */
46 struct rtnl_tc;
47
48 /**
49 * Macro to cast qdisc/class/classifier to tc object
50 * @ingroup tc
51 *
52 * @code
53 * rtnl_tc_set_mpu(TC_CAST(qdisc), 40);
54 * @endcode
55 */
56 #define TC_CAST(ptr) ((struct rtnl_tc *) (ptr))
57
58 /**
59 * Traffic control statistical identifier
60 * @ingroup tc
61 *
62 * @code
63 * uint64_t n = rtnl_tc_get_stat(TC_CAST(class), RTNL_TC_PACKETS);
64 * @endcode
65 */
66 enum rtnl_tc_stat {
67 RTNL_TC_PACKETS, /**< Number of packets seen */
68 RTNL_TC_BYTES, /**< Total bytes seen */
69 RTNL_TC_RATE_BPS, /**< Current bits/s (rate estimator) */
70 RTNL_TC_RATE_PPS, /**< Current packet/s (rate estimator) */
71 RTNL_TC_QLEN, /**< Current queue length */
72 RTNL_TC_BACKLOG, /**< Current backlog length */
73 RTNL_TC_DROPS, /**< Total number of packets dropped */
74 RTNL_TC_REQUEUES, /**< Total number of requeues */
75 RTNL_TC_OVERLIMITS, /**< Total number of overlimits */
76 __RTNL_TC_STATS_MAX,
77 };
78
79 #define RTNL_TC_STATS_MAX (__RTNL_TC_STATS_MAX - 1)
80
81 extern void rtnl_tc_set_ifindex(struct rtnl_tc *, int);
82 extern int rtnl_tc_get_ifindex(struct rtnl_tc *);
83 extern void rtnl_tc_set_link(struct rtnl_tc *, struct rtnl_link *);
84 extern struct rtnl_link *rtnl_tc_get_link(struct rtnl_tc *);
85 extern void rtnl_tc_set_mtu(struct rtnl_tc *, uint32_t);
86 extern uint32_t rtnl_tc_get_mtu(struct rtnl_tc *);
87 extern void rtnl_tc_set_mpu(struct rtnl_tc *, uint32_t);
88 extern uint32_t rtnl_tc_get_mpu(struct rtnl_tc *);
89 extern void rtnl_tc_set_overhead(struct rtnl_tc *, uint32_t);
90 extern uint32_t rtnl_tc_get_overhead(struct rtnl_tc *);
91 extern void rtnl_tc_set_linktype(struct rtnl_tc *, uint32_t);
92 extern uint32_t rtnl_tc_get_linktype(struct rtnl_tc *);
93 extern void rtnl_tc_set_handle(struct rtnl_tc *, uint32_t);
94 extern uint32_t rtnl_tc_get_handle(struct rtnl_tc *);
95 extern void rtnl_tc_set_parent(struct rtnl_tc *, uint32_t);
96 extern uint32_t rtnl_tc_get_parent(struct rtnl_tc *);
97 extern int rtnl_tc_set_kind(struct rtnl_tc *, const char *);
98 extern char * rtnl_tc_get_kind(struct rtnl_tc *);
99 extern uint64_t rtnl_tc_get_stat(struct rtnl_tc *, enum rtnl_tc_stat);
100 extern char * rtnl_tc_stat2str(enum rtnl_tc_stat, char *, size_t);
101 extern int rtnl_tc_str2stat(const char *);
102
103 extern int rtnl_tc_calc_txtime(int, int);
104 extern int rtnl_tc_calc_bufsize(int, int);
105 extern int rtnl_tc_calc_cell_log(int);
106
107 extern int rtnl_tc_read_classid_file(void);
108 extern char * rtnl_tc_handle2str(uint32_t, char *, size_t);
109 extern int rtnl_tc_str2handle(const char *, uint32_t *);
110 extern int rtnl_classid_generate(const char *, uint32_t *,
111 uint32_t);
112 extern void rtnl_tc_set_chain(struct rtnl_tc *, uint32_t);
113 extern int rtnl_tc_get_chain(struct rtnl_tc *, uint32_t *);
114
115 #ifdef __cplusplus
116 }
117 #endif
118
119 #endif
rtnl_tc_get_stat
uint64_t rtnl_tc_get_stat(struct rtnl_tc *, enum rtnl_tc_stat)
Return value of a statistical counter of a traffic control object.
Definition: tc.c:570
rtnl_tc_calc_txtime
int rtnl_tc_calc_txtime(int, int)
Calculate time required to transmit buffer at a specific rate.
Definition: tc.c:649
RTNL_TC_BACKLOG
Current backlog length.
Definition: tc.h:72
rtnl_tc_set_kind
int rtnl_tc_set_kind(struct rtnl_tc *, const char *)
Define the type of traffic control object.
Definition: tc.c:530
rtnl_tc_get_linktype
uint32_t rtnl_tc_get_linktype(struct rtnl_tc *)
Return the linktype of a traffic control object.
Definition: tc.c:472
rtnl_tc_get_overhead
uint32_t rtnl_tc_get_overhead(struct rtnl_tc *)
Return per packet overhead of a traffic control object.
Definition: tc.c:441
RTNL_TC_RATE_BPS
Current bits/s (rate estimator)
Definition: tc.h:69
rtnl_tc_calc_cell_log
int rtnl_tc_calc_cell_log(int)
Calculate the binary logarithm for a specific cell size.
Definition: tc.c:678
rtnl_tc_str2handle
int rtnl_tc_str2handle(const char *, uint32_t *)
Convert a charactering strint to a traffic control handle.
Definition: classid.c:155
rtnl_tc_set_linktype
void rtnl_tc_set_linktype(struct rtnl_tc *, uint32_t)
Set the linktype of a traffic control object.
Definition: tc.c:457
RTNL_TC_PACKETS
Number of packets seen.
Definition: tc.h:67
RTNL_TC_RATE_PPS
Current packet/s (rate estimator)
Definition: tc.h:70
rtnl_tc_set_parent
void rtnl_tc_set_parent(struct rtnl_tc *, uint32_t)
Set the parent identifier of a traffic control object.
Definition: tc.c:508
rtnl_link
Link object.
RTNL_TC_BYTES
Total bytes seen.
Definition: tc.h:68
rtnl_tc_set_link
void rtnl_tc_set_link(struct rtnl_tc *, struct rtnl_link *)
Set link of traffic control object.
Definition: tc.c:311
rtnl_tc_get_handle
uint32_t rtnl_tc_get_handle(struct rtnl_tc *)
Return identifier of a traffic control object.
Definition: tc.c:497
rtnl_tc_read_classid_file
int rtnl_tc_read_classid_file(void)
(Re-)read classid file
Definition: classid.c:312
RTNL_TC_QLEN
Current queue length.
Definition: tc.h:71
RTNL_TC_OVERLIMITS
Total number of overlimits.
Definition: tc.h:75
rtnl_tc_calc_bufsize
int rtnl_tc_calc_bufsize(int, int)
Calculate buffer size able to transmit in a specific time and rate.
Definition: tc.c:668
rtnl_tc_stat
rtnl_tc_stat
Traffic control statistical identifier.
Definition: tc.h:66
rtnl_tc_get_mtu
uint32_t rtnl_tc_get_mtu(struct rtnl_tc *)
Return the MTU of traffic control object.
Definition: tc.c:380
rtnl_tc_set_ifindex
void rtnl_tc_set_ifindex(struct rtnl_tc *, int)
Set interface index of traffic control object.
Definition: tc.c:279
rtnl_tc_get_parent
uint32_t rtnl_tc_get_parent(struct rtnl_tc *)
Return parent identifier of a traffic control object.
Definition: tc.c:518
rtnl_tc_set_handle
void rtnl_tc_set_handle(struct rtnl_tc *, uint32_t)
Set identifier of traffic control object.
Definition: tc.c:487
rtnl_tc_set_mpu
void rtnl_tc_set_mpu(struct rtnl_tc *, uint32_t)
Set the Minimum Packet Unit (MPU) of a traffic control object.
Definition: tc.c:400
rtnl_tc_set_chain
void rtnl_tc_set_chain(struct rtnl_tc *, uint32_t)
Set the chain index of a traffic control object.
Definition: tc.c:584
rtnl_tc_set_mtu
void rtnl_tc_set_mtu(struct rtnl_tc *, uint32_t)
Set the Maximum Transmission Unit (MTU) of traffic control object.
Definition: tc.c:365
rtnl_tc_handle2str
char * rtnl_tc_handle2str(uint32_t, char *, size_t)
Convert a traffic control handle to a character string (Reentrant).
Definition: classid.c:110
rtnl_tc_get_kind
char * rtnl_tc_get_kind(struct rtnl_tc *)
Return kind of traffic control object.
Definition: tc.c:555
RTNL_TC_REQUEUES
Total number of requeues.
Definition: tc.h:74
rtnl_tc_set_overhead
void rtnl_tc_set_overhead(struct rtnl_tc *, uint32_t)
Set per packet overhead of a traffic control object.
Definition: tc.c:429
rtnl_tc_get_mpu
uint32_t rtnl_tc_get_mpu(struct rtnl_tc *)
Return the Minimum Packet Unit (MPU) of a traffic control object.
Definition: tc.c:412
rtnl_tc_get_link
struct rtnl_link * rtnl_tc_get_link(struct rtnl_tc *)
Get link of traffic control object.
Definition: tc.c:342
rtnl_tc_get_chain
int rtnl_tc_get_chain(struct rtnl_tc *, uint32_t *)
Return chain index of traffic control object.
Definition: tc.c:598
rtnl_tc_get_ifindex
int rtnl_tc_get_ifindex(struct rtnl_tc *)
Return interface index of traffic control object.
Definition: tc.c:294
RTNL_TC_DROPS
Total number of packets dropped.
Definition: tc.h:73