/*
    Copyright 2000 (c) by David Schweikert,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public 
    Licence. A full copy of the GNU GPL is provided in the file COPYING 
    found in the development root of Topsy.
*/
/*
    File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Net/NetStat.c,v $
    Author(s):             
    Affiliation:           ETH Zuerich, TIK
    Version:               $Revision: 2936 $
    Creation Date:         
    Last Date of Change:   $Date: 2007-03-21 15:23:42 +0100 (Mit, 21 Mär 2007) $      by: $Author: baderma $
 
 
    $Log: NetStat.c,v $
    Revision 1.3  2001/01/10 11:34:19  blutz
    getting the network stack to work and adapting stuff to new IO structure
 
    Revision 1.2  2000/11/15 10:12:14  ruf
    Repository Reorganisation
 
    Revision 1.1  2000/03/31 17:50:35  gfa
    Merged with /Net from several term projects
 
*/
#include "../Topsy/Topsy.h"
#include "../Topsy/Syscall.h"
#include "../User/UserSupport.h"

#include "NetBuf.h"
#include "NetStat.h"

/* shell user program to display network statistics */
void NetStat(ThreadArg arg)
{
  ThreadId tty;
  char *arg1 = NULL;
  int i = 0;

  ioOpen(IO_CONSOLE, &tty);
  ioInit(tty);

  arg1 = ((char **)arg)[1];
  if(!arg1)
  {
    printf("m: NetBuf statistics\n");
    ioClose(tty);
    return;
  }

  switch(arg1[0])
  {
  case 'm':
    printf("%s","size\tpools\tnetbufs\tmemory\tfull\n");
    for(i=0; i<NETBUF_SIZES; i++)
    {
      printf("%d\t%d\t%d\t%dk\t%d%%\n", netbufStats->sizes[i],
             netbufStats->pools[i], netbufStats->usage[i],
             NETBUF_POOLSIZE*netbufStats->pools[i]/1024,
             (netbufStats->pools[i] ?
              (netbufStats->usage[i]*100 /
               (netbufStats->pools[i]*NETBUF_MAXBUFS(i)))
              :
              0)

            );
    }
    break;
  }

  ioClose(tty);
}
