#ifndef CTP_H
#define CTP_H

#include <Collection.h>
#include <AM.h>

#define UQ_CTP_CLIENT "CtpSenderC.CollectId"

enum {
    // AM types:
    AM_CTP_ROUTING = 0x70,
    AM_CTP_DATA    = 0x71,
    AM_CTP_DEBUG   = 0x72,

    // CTP Options:
    CTP_OPT_PULL      = 0x80, // TEP 123: P field
    CTP_OPT_ECN       = 0x40, // TEP 123: C field
};

typedef nx_uint8_t nx_ctp_options_t;
typedef uint8_t ctp_options_t;

typedef nx_struct {
	nx_am_addr_t nb;
	nx_uint16_t in_mac_delay_mean;
	nx_uint16_t in_mac_delay_var;
} mac_delay_t;


typedef nx_struct {
	nx_ctp_options_t    options;
	nx_uint8_t          thl;
	nx_uint16_t         etx;
	nx_am_addr_t        origin;
	
	//XL
	//nx_uint8_t originSeqNo;
	nx_uint16_t originSeqNo;  	
	//forwarding #
	nx_uint16_t localNtwSeq;
	//sequence # for each packet transmitted
	nx_uint16_t localSeq;
#if defined(TOSSIM)	
	nx_uint32_t tx_timestamp;
#endif
	mac_delay_t mac_delays[NEIGHBOR_TABLE_SIZE];
	
	nx_collection_id_t  type;
	nx_uint8_t (COUNT(0) data)[0]; // Deputy place-holder, field will probably be removed when we Deputize Ctp
} ctp_data_header_t;

typedef nx_struct {
	nx_ctp_options_t    options;
	nx_am_addr_t        parent;
	nx_uint16_t         etx;
	
	//XL
	mac_delay_t mac_delays[NEIGHBOR_TABLE_SIZE];
	//path delay and ETX from the neighbor
	delay_etx_t node_delay_etxs[DELAY_ETX_LEVEL_CNTS];
	
	nx_uint8_t (COUNT(0) data)[0]; // Deputy place-holder, field will probably be removed when we Deputize Ctp
} ctp_routing_header_t;

#endif
