#ifndef CLICK_WINGQUERIER_HH
#define CLICK_WINGQUERIER_HH
#include <click/element.hh>
#include <click/glue.hh>
#include <click/timer.hh>
#include <click/etheraddress.hh>
#include <click/hashmap.hh>
#include "pathmulti.hh"
CLICK_DECLS

/*
 * =c
 * WINGQuerier(ETH, WINGForwarder element, LinkTable element)
 * =s Wifi, Wireless Routing
 * Sends route queries if it can't find a valid source route.
 */

class WINGQuerier: public Element {
public:

	WINGQuerier();
	~WINGQuerier();

	const char *class_name() const { return "WINGQuerier"; }
	const char *port_count() const { return "1/2"; }
	const char *processing() const { return PUSH; }
	const char *flow_code() const { return "#/#"; }

	int configure(Vector<String> &, ErrorHandler *);

	/* handler stuff */
	void add_handlers();
	String print_queries();

	void push(int, Packet *);
	void send_query(IPAddress, int);

private:

	class DstInfo {
	public:
		DstInfo() {}
		DstInfo(IPAddress ip) : _ip(ip) {}
		IPAddress _ip;
		int _best_metric;
		int _count;
		Timestamp _last_query;
		PathMulti _p;
		Timestamp _last_switch; // last time we picked a new best route
		Timestamp _first_selected; // when _p was first selected as best route
	};

	typedef HashMap<IPAddress, DstInfo> DstTable;
	DstTable _queries;

	Timestamp _query_wait;
	Timestamp _time_before_switch;
	IPAddress _ip;

	class WINGForwarder *_forwarder;
	class LinkTableMulti *_link_table;
	class ARPTableMulti *_arp_table;

	bool _debug;

	static int write_handler(const String &, Element *, void *, ErrorHandler *);
	static String read_handler(Element *, void *);

};

CLICK_ENDDECLS
#endif
