]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/m_estimator.c
lib: introduce print_nl
[mirror_iproute2.git] / tc / m_estimator.c
CommitLineData
aba5acdf
SH
1/*
2 * m_estimator.c Parse/print estimator module options.
3 *
4 * This program is free software; you can u32istribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 *
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
aba5acdf
SH
16#include <fcntl.h>
17#include <sys/socket.h>
18#include <netinet/in.h>
19#include <arpa/inet.h>
20#include <string.h>
21
22#include "utils.h"
23#include "tc_util.h"
d1f28cf1 24#include "tc_common.h"
aba5acdf 25
94c9cc51 26static void est_help(void);
aba5acdf
SH
27
28static void est_help(void)
29{
30 fprintf(stderr, "Usage: ... estimator INTERVAL TIME-CONST\n");
31 fprintf(stderr, " INTERVAL is interval between measurements\n");
32 fprintf(stderr, " TIME-CONST is averaging time constant\n");
33 fprintf(stderr, "Example: ... est 1sec 8sec\n");
aba5acdf
SH
34}
35
36int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est)
37{
38 int argc = *p_argc;
39 char **argv = *p_argv;
32a121cb 40 unsigned int A, time_const;
ae665a52 41
aba5acdf
SH
42 NEXT_ARG();
43 if (est->ewma_log)
44 duparg("estimator", *argv);
45 if (matches(*argv, "help") == 0)
46 est_help();
8f34caaf 47 if (get_time(&A, *argv))
aba5acdf
SH
48 invarg("estimator", "invalid estimator interval");
49 NEXT_ARG();
50 if (matches(*argv, "help") == 0)
51 est_help();
8f34caaf 52 if (get_time(&time_const, *argv))
aba5acdf
SH
53 invarg("estimator", "invalid estimator time constant");
54 if (tc_setup_estimator(A, time_const, est) < 0) {
55 fprintf(stderr, "Error: estimator parameters are out of range.\n");
94c9cc51 56 return -1;
aba5acdf
SH
57 }
58 if (show_raw)
59 fprintf(stderr, "[estimator i=%u e=%u]\n", est->interval, est->ewma_log);
60 *p_argc = argc;
61 *p_argv = argv;
62 return 0;
63}