/*
 * tcp_trace.c
 *
 * Modified for x-kernel v3.3
 * Modifications Copyright (c) 1993,1996  Arizona Board of Regents
 *          
 * $Revision: 1.5 $
 * $Date: 1997/06/26 06:50:30 $
 */

#include "xkernel.h"
#include "tcp.h"
#include "tcp_internal.h"
#include "tcp_timer.h"
#include "tcp_var.h"

static XTime	Tcp_beg_time={0,0};

long tcpInitTime () /* VENKAT */
{
#ifndef XNETSIM
  if (Tcp_beg_time.sec == 0  &&  Tcp_beg_time.usec == 0)
    xGetTime(&Tcp_beg_time);
#endif
  return 0;
}

/*                
 * tcpGetTime
 */
unsigned long tcpGetTime () /* VENKAT */
{
  XTime cur_time;
  
  xGetTime(&cur_time);
  return ((cur_time.sec - Tcp_beg_time.sec)*1000 +
                  (cur_time.usec - Tcp_beg_time.usec)/1000);
  
} 
 
/*
 * tcpSaveTrace
 */
int tcpSaveTrace (traceObj, buf, len, statp)

  dt            *traceObj;
  char 		*buf;
  int  		len;
  struct tcpstat *statp;
{

/**********************  TRACE */
#ifdef TCP_TRACE
    {
/*      long  time(); */
      TcpTraceMisc misc;

      misc.time = time(NULL);
      misc.sndbyte = statp->tcps_sndbyte;
      misc.rcvbyte = statp->tcps_rcvbyte;
      misc.run_time = tcpGetTime();
      misc.read_np_lost = 0;
      misc.zero = 0;
      misc.tcpstatlen = sizeof(struct tcpstat);
      misc.stat = *statp;
      dtAppendPostAmble(traceObj, (char *)&misc, sizeof(TcpTraceMisc));
      if (len) dtAppendPostAmble(traceObj, buf, len);

      dtClose(traceObj);
      /* sleep(2); */
    }
#endif
/**********************  TRACE */
    return 0;
}


