//#define DEBUG(x) printf x;
#define DEBUG(x)

#include "packet.h"
#include "drop-expired.h"
#include "ip.h"
#include <stdio.h>

FILE *f=NULL;

void atp_set_ttl(Packet *p, double lifetime) 
{
  hdr_ip *iph = hdr_ip::access(p);
  iph->ttl_ = lifetime* ATP_TIMESCALE;
  DEBUG(("Atp set ttl to %.2f\n", (float)(iph->ttl_)/ATP_TIMESCALE));  
}

void atp_log_ttl(Packet *p) 
{
  double time_now = Scheduler::instance().clock();
  hdr_ip *iph = hdr_ip::access(p);
  int i=0;

  if (p==NULL) {
    fclose(f); 
    return;
  }
  
  if (f==NULL)        
     	f=fopen("ttl.tr", "a");

  if (f!=NULL)
        i=fprintf(f, "%.2f\t%.2f\n", time_now, (double)(iph->ttl_)/ATP_TIMESCALE -time_now);

//  printf("wrote %d\n", i);

  fclose(f);
  f=NULL;
}




