blob: 87745cc2d4d61f5096b698a47c9c0a437e7783ab [file] [log] [blame]
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +00001/*
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>
16#include <syslog.h>
17#include <fcntl.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <arpa/inet.h>
21#include <string.h>
22
23#include "utils.h"
24#include "tc_util.h"
Stephen Hemmingerd1f28cf2013-02-12 11:09:03 -080025#include "tc_common.h"
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000026
osdl.net!shemminger94c9cc52005-03-14 19:02:41 +000027static void est_help(void);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000028
29static void est_help(void)
30{
31 fprintf(stderr, "Usage: ... estimator INTERVAL TIME-CONST\n");
32 fprintf(stderr, " INTERVAL is interval between measurements\n");
33 fprintf(stderr, " TIME-CONST is averaging time constant\n");
34 fprintf(stderr, "Example: ... est 1sec 8sec\n");
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000035}
36
37int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est)
38{
39 int argc = *p_argc;
40 char **argv = *p_argv;
Stephen Hemminger32a121c2016-03-21 11:48:36 -070041 unsigned int A, time_const;
Stephen Hemmingerae665a52006-12-05 10:10:22 -080042
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000043 NEXT_ARG();
44 if (est->ewma_log)
45 duparg("estimator", *argv);
46 if (matches(*argv, "help") == 0)
47 est_help();
Patrick McHardy8f34caa2007-03-04 20:15:00 +010048 if (get_time(&A, *argv))
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000049 invarg("estimator", "invalid estimator interval");
50 NEXT_ARG();
51 if (matches(*argv, "help") == 0)
52 est_help();
Patrick McHardy8f34caa2007-03-04 20:15:00 +010053 if (get_time(&time_const, *argv))
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000054 invarg("estimator", "invalid estimator time constant");
55 if (tc_setup_estimator(A, time_const, est) < 0) {
56 fprintf(stderr, "Error: estimator parameters are out of range.\n");
osdl.net!shemminger94c9cc52005-03-14 19:02:41 +000057 return -1;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000058 }
59 if (show_raw)
60 fprintf(stderr, "[estimator i=%u e=%u]\n", est->interval, est->ewma_log);
61 *p_argc = argc;
62 *p_argv = argv;
63 return 0;
64}