#include "scheduler.h"
#include "tcp-sink.h"

class ActiveTcpSink : public TcpSink {
public:
    double start;
    int seqno;
    ActiveTcpSink(Acker *a) : TcpSink(a), start(0), seqno(0) {}
    void recv(Packet* p, Handler *h) {
	hdr_tcp *tcp = HDR_TCP(p);
	if ( start == 0.0 ) start = Scheduler::instance().clock();
	if ( tcp->seqno() > seqno ) seqno = tcp->seqno();
	TcpSink::recv(p,h);
    }
    int command(int argc, const char*const* argv) {
	Tcl& tcl = Tcl::instance();
	Scheduler &s = Scheduler::instance();
	double now;
	double th=0.0;
	
	if (argc == 2) {
 	    if (strcmp(argv[1], "throughput") == 0) {
		now = (&s) ? s.clock() : 0;
 		if ( now - start > 0.0 ) {
 		    th = seqno * size_ * 8.0 /1024.0 /(now - start);
		    tcl.resultf("%g kb/s",th);
		}
		else tcl.result("Error");
		return (TCL_OK);
	    }
	}
	return (TcpSink::command(argc, argv));
    }
};


	
