131921Sbrian/*-
231921Sbrian * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
331921Sbrian * All rights reserved.
431921Sbrian *
531921Sbrian * Redistribution and use in source and binary forms, with or without
631921Sbrian * modification, are permitted provided that the following conditions
731921Sbrian * are met:
831921Sbrian * 1. Redistributions of source code must retain the above copyright
931921Sbrian *    notice, this list of conditions and the following disclaimer.
1031921Sbrian * 2. Redistributions in binary form must reproduce the above copyright
1131921Sbrian *    notice, this list of conditions and the following disclaimer in the
1231921Sbrian *    documentation and/or other materials provided with the distribution.
1331921Sbrian *
1431921Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1531921Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1631921Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1731921Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1831921Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1931921Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2031921Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2131921Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2231921Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2331921Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2431921Sbrian * SUCH DAMAGE.
2531921Sbrian *
2650479Speter * $FreeBSD$
2731272Sbrian */
2831272Sbrian
2949434Sbrian#define SAMPLE_PERIOD 5		/* Default sample period */
3031272Sbrian
3136934Sbrian#define THROUGHPUT_OVERALL 0x0001
3236934Sbrian#define THROUGHPUT_CURRENT 0x0002
3336934Sbrian#define THROUGHPUT_PEAK    0x0004
3449434Sbrian#define THROUGHPUT_ALL     0x0007
3536934Sbrian
3631272Sbrianstruct pppThroughput {
3749434Sbrian  time_t uptime, downtime;
3846686Sbrian  unsigned long long OctetsIn;
3946686Sbrian  unsigned long long OctetsOut;
4065178Sbrian  unsigned long long PacketsIn;
4165178Sbrian  unsigned long long PacketsOut;
4249434Sbrian  int SamplePeriod;
4364670Sbrian  struct {
4464670Sbrian    unsigned long long *SampleOctets;
4564670Sbrian    unsigned long long OctetsPerSecond;
4664670Sbrian  } in, out;
4746686Sbrian  unsigned long long BestOctetsPerSecond;
4836819Sbrian  time_t BestOctetsPerSecondTime;
4931272Sbrian  int nSample;
5036285Sbrian  unsigned rolling : 1;
5131272Sbrian  struct pppTimer Timer;
5249434Sbrian  struct {
5349434Sbrian    void *data;
5449434Sbrian    void (*fn)(void *v);
5549434Sbrian  } callback;
5631272Sbrian};
5731272Sbrian
5849434Sbrianextern void throughput_init(struct pppThroughput *, int);
5949434Sbrianextern void throughput_destroy(struct pppThroughput *);
6036285Sbrianextern void throughput_disp(struct pppThroughput *, struct prompt *);
6131272Sbrianextern void throughput_log(struct pppThroughput *, int, const char *);
6236285Sbrianextern void throughput_start(struct pppThroughput *, const char *, int);
6349434Sbrianextern void throughput_restart(struct pppThroughput *, const char *, int);
6431272Sbrianextern void throughput_stop(struct pppThroughput *);
6546686Sbrianextern void throughput_addin(struct pppThroughput *, long long);
6646686Sbrianextern void throughput_addout(struct pppThroughput *, long long);
6736934Sbrianextern void throughput_clear(struct pppThroughput *, int, struct prompt *);
6849434Sbrianextern void throughput_callback(struct pppThroughput *, void (*)(void *),
6949434Sbrian                                void *);
7049434Sbrianextern int throughput_uptime(struct pppThroughput *);
71