Checkign in new iproute2
[iproute2.git] / tc / q_htb.c
index 828d4b1..c69e350 100644 (file)
@@ -41,7 +41,7 @@ static void explain(void)
                " burst    max bytes burst which can be accumulated during idle period {computed}\n"
                " mpu      minimum packet size used in rate computations\n"
                " overhead per-packet size overhead used in rate computations\n"
-
+               " linklay  adapting to a linklayer e.g. atm\n"
                " ceil     definite upper class rate (no borrows) {rate}\n"
                " cburst   burst but for ceil {computed}\n"
                " mtu      max packet size we create rate map for {1600}\n"
@@ -107,8 +107,10 @@ static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
        __u32 rtab[256],ctab[256];
        unsigned buffer=0,cbuffer=0;
        int cell_log=-1,ccell_log = -1;
-       unsigned mtu, mpu;
-       unsigned char mpu8 = 0, overhead = 0;
+       unsigned mtu;
+       unsigned short mpu = 0;
+       unsigned short overhead = 0;
+       unsigned int linklayer  = LINKLAYER_ETHERNET; /* Assume ethernet */
        struct rtattr *tail;
 
        memset(&opt, 0, sizeof(opt)); mtu = 1600; /* eth packet len */
@@ -127,14 +129,19 @@ static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
                        }
                } else if (matches(*argv, "mpu") == 0) {
                        NEXT_ARG();
-                       if (get_u8(&mpu8, *argv, 10)) {
+                       if (get_u16(&mpu, *argv, 10)) {
                                explain1("mpu"); return -1;
                        }
                } else if (matches(*argv, "overhead") == 0) {
                        NEXT_ARG();
-                       if (get_u8(&overhead, *argv, 10)) {
+                       if (get_u16(&overhead, *argv, 10)) {
                                explain1("overhead"); return -1;
                        }
+               } else if (matches(*argv, "linklayer") == 0) {
+                       NEXT_ARG();
+                       if (get_linklayer(&linklayer, *argv)) {
+                               explain1("linklayer"); return -1;
+                       }
                } else if (matches(*argv, "quantum") == 0) {
                        NEXT_ARG();
                        if (get_u32(&opt.quantum, *argv, 10)) {
@@ -206,23 +213,23 @@ static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
        if (!buffer) buffer = opt.rate.rate / get_hz() + mtu;
        if (!cbuffer) cbuffer = opt.ceil.rate / get_hz() + mtu;
 
-/* encode overhead and mpu, 8 bits each, into lower 16 bits */
-       mpu = (unsigned)mpu8 | (unsigned)overhead << 8;
-       opt.ceil.mpu = mpu; opt.rate.mpu = mpu;
+       opt.ceil.overhead = overhead;
+       opt.rate.overhead = overhead;
 
-       if ((cell_log = tc_calc_rtable(opt.rate.rate, rtab, cell_log, mtu, mpu)) < 0) {
+       opt.ceil.mpu = mpu;
+       opt.rate.mpu = mpu;
+
+       if (tc_calc_rtable(&opt.rate, rtab, cell_log, mtu, linklayer) < 0) {
                fprintf(stderr, "htb: failed to calculate rate table.\n");
                return -1;
        }
        opt.buffer = tc_calc_xmittime(opt.rate.rate, buffer);
-       opt.rate.cell_log = cell_log;
-       
-       if ((ccell_log = tc_calc_rtable(opt.ceil.rate, ctab, cell_log, mtu, mpu)) < 0) {
+
+       if (tc_calc_rtable(&opt.ceil, ctab, ccell_log, mtu, linklayer) < 0) {
                fprintf(stderr, "htb: failed to calculate ceil rate table.\n");
                return -1;
        }
        opt.cbuffer = tc_calc_xmittime(opt.ceil.rate, cbuffer);
-       opt.ceil.cell_log = ccell_log;
 
        tail = NLMSG_TAIL(n);
        addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
@@ -259,9 +266,9 @@ static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
                                fprintf(f, "quantum %d ", (int)hopt->quantum);
                }
            fprintf(f, "rate %s ", sprint_rate(hopt->rate.rate, b1));
-           buffer = ((double)hopt->rate.rate*tc_core_tick2usec(hopt->buffer))/1000000;
+           buffer = tc_calc_xmitsize(hopt->rate.rate, hopt->buffer);
            fprintf(f, "ceil %s ", sprint_rate(hopt->ceil.rate, b1));
-           cbuffer = ((double)hopt->ceil.rate*tc_core_tick2usec(hopt->cbuffer))/1000000;
+           cbuffer = tc_calc_xmitsize(hopt->ceil.rate, hopt->cbuffer);
            if (show_details) {
                fprintf(f, "burst %s/%u mpu %s overhead %s ",
                        sprint_size(buffer, b1),
@@ -279,14 +286,14 @@ static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
                fprintf(f, "cburst %s ", sprint_size(cbuffer, b1));
            }
            if (show_raw)
-               fprintf(f, "buffer [%08x] cbuffer [%08x] ", 
+               fprintf(f, "buffer [%08x] cbuffer [%08x] ",
                        hopt->buffer,hopt->cbuffer);
        }
        if (tb[TCA_HTB_INIT]) {
            gopt = RTA_DATA(tb[TCA_HTB_INIT]);
            if (RTA_PAYLOAD(tb[TCA_HTB_INIT])  < sizeof(*gopt)) return -1;
 
-           fprintf(f, "r2q %d default %x direct_packets_stat %u", 
+           fprintf(f, "r2q %d default %x direct_packets_stat %u",
                    gopt->rate2quantum,gopt->defcls,gopt->direct_pkts);
                if (show_details)
                        fprintf(f," ver %d.%d",gopt->version >> 16,gopt->version & 0xffff);
@@ -304,7 +311,7 @@ static int htb_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstat
                return -1;
 
        st = RTA_DATA(xstats);
-       fprintf(f, " lended: %u borrowed: %u giants: %u\n", 
+       fprintf(f, " lended: %u borrowed: %u giants: %u\n",
                st->lends,st->borrows,st->giants);
        fprintf(f, " tokens: %d ctokens: %d\n", st->tokens,st->ctokens);
        return 0;