/* -*-c++-*- */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

#include "ip.h"
#include "tcp.h"
#include "flags.h"

#define TCP_REASON_ACTIVE	0x4

class ActiveTcpAgent : public TcpAgent {
protected:
    TracedInt active_closes_;	// Times a close was caused by Active feedback
    TracedInt active_packets_;	// Times a close was caused by Active feedback
    int dupackcloses_;		// Times a close was caused bya dup ack
    double last_active_close_;	// The last time a close was acuased by AF
    double minbetween;		// minimum time between two active closes
    int second;
    int actid;

public:
    ActiveTcpAgent(): active_closes_(0), dupackcloses_(0), last_active_close_(-10.0),minbetween(1000.0), second(0), actid(-1) {
	bind("active_packets_",&active_packets_);
	bind("active_closes_",&active_closes_);
	bind("dupackcloses_",&dupackcloses_);
//	bind("minbetween",&minbetween);
    }
    virtual void timeout(int);
    virtual void recv(Packet*, Handler*);
    virtual void output_helper(Packet *);

    // This is a hook to allow active routers to allocate packets for
    // us safely.  Don't fool with this unless you understand the
    // difference between Packet::alloc() and Agent::allocpkt().
    // Misallocating packets can cause very unpredicatble results.
    
    inline Packet *alloc_fb_pkt() const { return allocpkt(); }
};

struct hdr_act_tcp {
    ActiveTcpAgent *src;     // This allows active queues to allocate
                             // packets properly (see above comment)
    int wind_;
    int in_ss_;
    int killed_;
    int id_;
    static int offset_;

    int& window() { return wind_;}
    int& killed() { return killed_;}
    int& ss() { return in_ss_;}
    int& id() { return id_;}
};
