]> git.pld-linux.org Git - packages/iproute2.git/blame - wrr-iproute2-2.2.4.patch
4859b836749ebfeb3cf9a13a5d5eb0cc wrr-iproute2-2.2.4.patch
[packages/iproute2.git] / wrr-iproute2-2.2.4.patch
CommitLineData
ca1c0e2c 1diff -uNrbB org/tc/Makefile new/tc/Makefile
2--- org/tc/Makefile Fri Feb 25 20:51:57 2000
3+++ new/tc/Makefile Mon Feb 12 17:24:48 2001
4@@ -9,6 +9,7 @@
5 TCMODULES += q_prio.o
6 TCMODULES += q_tbf.o
7 TCMODULES += q_cbq.o
8+TCMODULES += q_wrr.o
9 TCMODULES += f_rsvp.o
10 TCMODULES += f_u32.o
11 TCMODULES += f_route.o
12diff -uNrbB org/tc/q_wrr.c new/tc/q_wrr.c
13--- org/tc/q_wrr.c Thu Jan 1 01:00:00 1970
14+++ new/tc/q_wrr.c Sun Sep 9 12:44:28 2001
15@@ -0,0 +1,323 @@
16+#include <stdio.h>
17+#include <stdlib.h>
18+#include <unistd.h>
19+#include <syslog.h>
20+#include <fcntl.h>
21+#include <sys/socket.h>
22+#include <netinet/in.h>
23+#include <arpa/inet.h>
24+#include <string.h>
25+#include <math.h>
26+
27+#include "utils.h"
28+#include "tc_util.h"
29+
30+#define usage() return(-1)
31+
32+// Returns -1 on error
33+static int wrr_parse_qdisc_weight(int argc, char** argv,
34+ struct tc_wrr_qdisc_modf* opt) {
35+ int i;
36+
37+ opt->weight1.weight_mode=-1;
38+ opt->weight2.weight_mode=-1;
39+
40+ for(i=0; i<argc; i++) {
41+ if(!memcmp(argv[i],"wmode1=",7)) {
42+ opt->weight1.weight_mode=atoi(argv[i]+7);
43+ } else if(!memcmp(argv[i],"wmode2=",7)) {
44+ opt->weight2.weight_mode=atoi(argv[i]+7);
45+ } else {
46+ printf("Usage: ... [wmode1=0|1|2|3] [wmode2=0|1|2|3]\n");
47+ return -1;
48+ }
49+ }
50+ return 0;
51+}
52+
53+static int wrr_parse_class_modf(int argc, char** argv,
54+ struct tc_wrr_class_modf* modf) {
55+ int i;
56+
57+ if(argc<1) {
58+ fprintf(stderr, "Usage: ... [weight1=val] [decr1=val] [incr1=val] [min1=val] [max1=val] [val2=val] ...\n");
59+ fprintf(stderr, " The values can be floating point like 0.42 or divisions like 42/100\n");
60+ return -1;
61+ }
62+
63+ // Set meaningless values:
64+ modf->weight1.val=0;
65+ modf->weight1.decr=(__u64)-1;
66+ modf->weight1.incr=(__u64)-1;
67+ modf->weight1.min=0;
68+ modf->weight1.max=0;
69+ modf->weight2.val=0;
70+ modf->weight2.decr=(__u64)-1;
71+ modf->weight2.incr=(__u64)-1;
72+ modf->weight2.min=0;
73+ modf->weight2.max=0;
74+
75+ // And read values:
76+ for(i=0; i<argc; i++) {
77+ char arg[80];
78+ char* name,*value1=0,*value2=0;
79+ long double f_val1,f_val2=1,value;
80+ if(strlen(argv[i])>=sizeof(arg)) {
81+ fprintf(stderr,"Argument too long: %s\n",argv[i]);
82+ return -1;
83+ }
84+ strcpy(arg,argv[i]);
85+
86+ name=strtok(arg,"=");
87+ if(name) value1=strtok(0,"/");
88+ if(value1) value2=strtok(0,"");
89+
90+ if(!value1) {
91+ fprintf(stderr,"No = found in argument: %s\n",argv[i]);
92+ return -1;
93+ }
94+
95+ f_val1=atof(value1);
96+ if(value2) f_val2=atof(value2);
97+
98+ if(f_val2==0) {
99+ fprintf(stderr,"Division by 0\n");
100+ return -1;
101+ }
102+
103+ value=f_val1/f_val2;
104+ if(value>1) value=1;
105+ if(value<0) value=0;
106+ value*=((__u64)-1);
107+
108+ // And find the value set
109+ if(!strcmp(name,"weight1")) modf->weight1.val=value;
110+ else if(!strcmp(name,"decr1")) modf->weight1.decr=value;
111+ else if(!strcmp(name,"incr1")) modf->weight1.incr=value;
112+ else if(!strcmp(name,"min1")) modf->weight1.min=value;
113+ else if(!strcmp(name,"max1")) modf->weight1.max=value;
114+ else if(!strcmp(name,"weight2")) modf->weight2.val=value;
115+ else if(!strcmp(name,"decr2")) modf->weight2.decr=value;
116+ else if(!strcmp(name,"incr2")) modf->weight2.incr=value;
117+ else if(!strcmp(name,"min2")) modf->weight2.min=value;
118+ else if(!strcmp(name,"max2")) modf->weight2.max=value;
119+ else {
120+ fprintf(stderr,"illegal value: %s\n",name);
121+ return -1;
122+ }
123+ }
124+
125+ return 0;
126+}
127+
128+static int wrr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
129+{
130+ if(n->nlmsg_flags & NLM_F_CREATE) {
131+ // This is a create request:
132+ struct tc_wrr_qdisc_crt opt;
133+
134+ int sour,dest,ip,mac,masq;
135+
136+ if(argc<4) {
137+ fprintf(stderr, "Usage: ... wrr sour|dest ip|masq|mac maxclasses proxymaxcon [penalty-setup]\n");
138+ return -1;
139+ }
140+
141+ // Read sour/dest:
142+ memset(&opt,0,sizeof(opt));
143+ sour=!strcmp(argv[0],"sour");
144+ dest=!strcmp(argv[0],"dest");
145+
146+ if(!sour && !dest) {
147+ fprintf(stderr,"sour or dest must be specified\n");
148+ return -1;
149+ }
150+
151+ // Read ip/mac
152+ ip=!strcmp(argv[1],"ip");
153+ mac=!strcmp(argv[1],"mac");
154+ masq=!strcmp(argv[1],"masq");
155+
156+ if(!ip && !mac && !masq) {
157+ fprintf(stderr,"ip, masq or mac must be specified\n");
158+ return -1;
159+ }
160+
161+ opt.srcaddr=sour;
162+ opt.usemac=mac;
163+ opt.usemasq=masq;
164+ opt.bands_max=atoi(argv[2]);
165+
166+ opt.proxy_maxconn=atoi(argv[3]);
167+
168+ // Read weights:
169+ if(wrr_parse_qdisc_weight(argc-4,argv+4,&opt.qdisc_modf)<0) return -1;
170+ if(opt.qdisc_modf.weight1.weight_mode==-1) opt.qdisc_modf.weight1.weight_mode=0;
171+ if(opt.qdisc_modf.weight2.weight_mode==-1) opt.qdisc_modf.weight2.weight_mode=0;
172+
173+ addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
174+ } else {
175+ struct tc_wrr_qdisc_modf_std opt;
176+ char qdisc,class;
177+
178+ // This is a modify request:
179+ if(argc<1) {
180+ fprintf(stderr,"... qdisc ... or ... class ...\n");
181+ return -1;
182+ }
183+
184+ qdisc=!strcmp(argv[0],"qdisc");
185+ class=!strcmp(argv[0],"class");
186+
187+ if(!qdisc && !class) {
188+ fprintf(stderr,"qdisc or class must be specified\n");
189+ return -1;
190+ }
191+
192+ argc--;
193+ argv++;
194+
195+ opt.proxy=0;
196+
197+ if(qdisc) {
198+ opt.change_class=0;
199+ if(wrr_parse_qdisc_weight(argc, argv, &opt.qdisc_modf)<0) return -1;
200+ } else {
201+ int a0,a1,a2,a3,a4=0,a5=0;
202+
203+ opt.change_class=1;
204+
205+ if(argc<1) {
206+ fprintf(stderr,"... <mac>|<ip>|<masq> ...\n");
207+ return -1;
208+ }
209+ memset(opt.addr,0,sizeof(opt.addr));
210+
211+ if((sscanf(argv[0],"%i.%i.%i.%i",&a0,&a1,&a2,&a3)!=4) &&
212+ (sscanf(argv[0],"%x:%x:%x:%x:%x:%x",&a0,&a1,&a2,&a3,&a4,&a5)!=6)) {
213+ fprintf(stderr,"Wrong format of mac or ip address\n");
214+ return -1;
215+ }
216+
217+ opt.addr[0]=a0; opt.addr[1]=a1; opt.addr[2]=a2;
218+ opt.addr[3]=a3; opt.addr[4]=a4; opt.addr[5]=a5;
219+
220+ if(wrr_parse_class_modf(argc-1, argv+1, &opt.class_modf)<0) return -1;
221+ }
222+
223+ addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
224+ }
225+ return 0;
226+}
227+
228+static int wrr_parse_copt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) {
229+ struct tc_wrr_class_modf opt;
230+
231+ memset(&opt,0,sizeof(opt));
232+ if(wrr_parse_class_modf(argc,argv,&opt)<0) return -1;
233+
234+ addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
235+ return 0;
236+}
237+
238+static int wrr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
239+{
240+ struct tc_wrr_qdisc_stats *qopt;
241+
242+ if (opt == NULL)
243+ return 0;
244+
245+ if (RTA_PAYLOAD(opt) < sizeof(*qopt))
246+ return -1;
247+ qopt = RTA_DATA(opt);
248+
249+ fprintf(f,"\n (%s/%s) (maxclasses %i) (usedclasses %i) (reused classes %i)\n",
250+ qopt->qdisc_crt.srcaddr ? "sour" : "dest",
251+ qopt->qdisc_crt.usemac ? "mac" : (qopt->qdisc_crt.usemasq ? "masq" : "ip"),
252+ qopt->qdisc_crt.bands_max,
253+ qopt->bands_cur,
254+ qopt->bands_reused
255+ );
256+
257+ if(qopt->qdisc_crt.proxy_maxconn) {
258+ fprintf(f," (proxy maxcon %i) (proxy curcon %i)\n",
259+ qopt->qdisc_crt.proxy_maxconn,qopt->proxy_curconn);
260+ }
261+
262+ fprintf(f," (waiting classes %i) (packets requeued %i) (priosum: %Lg)\n",
263+ qopt->nodes_in_heap,
264+ qopt->packets_requed,
265+ qopt->priosum/((long double)((__u32)-1))
266+ );
267+
268+ fprintf(f," (wmode1 %i) (wmode2 %i) \n",
269+ qopt->qdisc_crt.qdisc_modf.weight1.weight_mode,
270+ qopt->qdisc_crt.qdisc_modf.weight2.weight_mode);
271+
272+ return 0;
273+}
274+
275+static int wrr_print_copt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) {
276+ struct tc_wrr_class_stats *copt;
277+ long double d=(__u64)-1;
278+
279+ if (opt == NULL) return 0;
280+
281+ if (RTA_PAYLOAD(opt) < sizeof(*copt))
282+ return -1;
283+ copt = RTA_DATA(opt);
284+
285+ if(!copt->used) {
286+ fprintf(f,"(unused)");
287+ return 0;
288+ }
289+
290+ if(copt->usemac) {
291+ fprintf(f,"\n (address: %.2X:%.2X:%.2X:%.2X:%.2X:%.2X)\n",
292+ copt->addr[0],copt->addr[1],copt->addr[2],
293+ copt->addr[3],copt->addr[4],copt->addr[5]);
294+ } else {
295+ fprintf(f,"\n (address: %i.%i.%i.%i)\n",copt->addr[0],copt->addr[1],copt->addr[2],copt->addr[3]);
296+ }
297+
298+ fprintf(f," (total weight: %Lg) (current position: %i) (counters: %u %u : %u %u)\n",
299+ (copt->class_modf.weight1.val/d)*(copt->class_modf.weight2.val/d),
300+ copt->heappos,
301+ (unsigned)(copt->penal_ms>>32),
302+ (unsigned)(copt->penal_ms & 0xffffffffU),
303+ (unsigned)(copt->penal_ls>>32),
304+ (unsigned)(copt->penal_ls & 0xffffffffU)
305+ );
306+
307+ fprintf(f," Pars 1: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)\n",
308+ copt->class_modf.weight1.val/d,
309+ copt->class_modf.weight1.decr/d,
310+ copt->class_modf.weight1.incr/d,
311+ copt->class_modf.weight1.min/d,
312+ copt->class_modf.weight1.max/d);
313+
314+ fprintf(f," Pars 2: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)",
315+ copt->class_modf.weight2.val/d,
316+ copt->class_modf.weight2.decr/d,
317+ copt->class_modf.weight2.incr/d,
318+ copt->class_modf.weight2.min/d,
319+ copt->class_modf.weight2.max/d);
320+
321+ return 0;
322+}
323+
324+static int wrr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
325+{
326+ return 0;
327+}
328+
329+
330+struct qdisc_util wrr_util = {
331+ NULL,
332+ "wrr",
333+ wrr_parse_opt,
334+ wrr_print_opt,
335+ wrr_print_xstats,
336+ wrr_parse_copt,
337+ wrr_print_copt
338+};
This page took 0.07339 seconds and 4 git commands to generate.