date and time created 85/06/24 18:27:03 by gusella
authorRiccardo Gusella <gusella@ucbvax.Berkeley.EDU>
Tue, 25 Jun 1985 09:27:03 +0000 (01:27 -0800)
committerRiccardo Gusella <gusella@ucbvax.Berkeley.EDU>
Tue, 25 Jun 1985 09:27:03 +0000 (01:27 -0800)
SCCS-vsn: usr.sbin/timed/timed/networkdelta.c 1.1

usr/src/usr.sbin/timed/timed/networkdelta.c [new file with mode: 0644]

diff --git a/usr/src/usr.sbin/timed/timed/networkdelta.c b/usr/src/usr.sbin/timed/timed/networkdelta.c
new file mode 100644 (file)
index 0000000..c47f8c5
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)networkdelta.c     1.1 (Berkeley) %G%";
+#endif not lint
+
+#include "globals.h"
+#include <protocols/timed.h>
+
+extern int machup;
+extern int slvcount;
+extern struct host hp[];
+
+/*
+ * `networkdelta' selects the largest set of deltas that fall within the
+ * interval RANGE, and uses them to compute the network average delta 
+ */
+
+long networkdelta()
+{
+       int i, j, maxind, minind;
+       int ext;
+       int tempind;
+       long tempdata;
+       long x[NHOSTS];
+       long average;
+
+       for (i=0; i<slvcount; i++)
+               x[i] = hp[i].delta;
+       for (i=0; i<slvcount-1; i++) {
+               tempdata = x[i];
+               tempind = i;
+               for (j=i+1; j<slvcount; j++) {
+                       if (x[j] < tempdata) {
+                               tempdata = x[j];
+                               tempind = j;
+                       }
+               }
+               x[tempind] = x[i];
+               x[i] = tempdata;
+       }
+
+       /* this piece of code is critical: DO NOT TOUCH IT! */
+/****/
+       i=0; j=1; minind=0; maxind=1;
+       if (machup == 2)
+               goto compute;
+       do {
+               if (x[j]-x[i] <= RANGE)
+                       j++;
+               else {
+                       if (j > i+1) 
+                               j--; 
+                       if ((x[j]-x[i] <= RANGE) && (j-i >= maxind-minind)) {
+                               minind=i;
+                               maxind=j;
+                       }       
+                       i++;
+                       if(i = j)
+                               j++;
+               }
+       } while (j < machup);
+       if ((x[machup-1] - x[i] <= RANGE) && (machup-i-1 >= maxind-minind)) {
+               minind=i; maxind=machup-1;
+       }
+/****/
+compute:
+       ext = maxind - minind + 1;
+       average = 0;
+       for (i=minind; i<=maxind; i++)
+               average += x[i];
+       average /= ext;
+       return(average);
+}