Working on reboot statistics
FossilOrigin-Name: 134a5b893fbd0a7a240b1a60113a3f071ae7ce83811392a87f4abd782cf3070c
This commit is contained in:
		@ -450,13 +450,13 @@ extern int cw_readelem_vendor_specific_payload(void *data, int msgtype, int elem
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum cw_reboot_failure_types {
 | 
					enum cw_reboot_failure_types {
 | 
				
			||||||
	CW_REBOOT_FAILURE_TYPE_NOT_SUPPORTED=0,
 | 
						CW_REBOOT_TYPE_NOT_SUPPORTED=0,
 | 
				
			||||||
	CW_REBOOT_FAILURE_TYPE_AC_INITIATED=1,
 | 
						CW_REBOOT_TYPE_AC_INITIATED=1,
 | 
				
			||||||
	CW_REBOOT_FAILURE_TYPE_LINK_FAILURE=2,
 | 
						CW_REBOOT_TYPE_LINK_FAILURE=2,
 | 
				
			||||||
	CW_REBOOT_FAILURE_TYPE_SOFTWARE_FAILURE=3,
 | 
						CW_REBOOT_TYPE_SOFTWARE_FAILURE=3,
 | 
				
			||||||
	CW_REBOOT_FAILURE_TYPE_HARDWARE_FAILURE=4,
 | 
						CW_REBOOT_TYPE_HARDWARE_FAILURE=4,
 | 
				
			||||||
	CW_REBOOT_FAILURE_TYPE_OTHER_FAILURE=5,
 | 
						CW_REBOOT_TYPE_OTHER_FAILURE=5,
 | 
				
			||||||
	CW_REBOOT_FAILURE_ONKNOWN
 | 
						CW_REBOOT_TYPE_FAILURE_ONKNOWN
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -133,6 +133,11 @@ cisco_items or so */
 | 
				
			|||||||
{CW_ITEM_CISCO_BOARD_DATA_OPTIONS,CW_ITEM_NONE,MBAG_BSTR16},
 | 
					{CW_ITEM_CISCO_BOARD_DATA_OPTIONS,CW_ITEM_NONE,MBAG_BSTR16},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{CW_ITEM_WTP_REBOOT_STATISTICS,CW_ITEM_REBOOT_COUNT,MBAG_WORD},
 | 
				
			||||||
 | 
					{CW_ITEM_WTP_REBOOT_STATISTICS,CW_ITEM_REBOOT_AC_INITIATED_COUNT,MBAG_WORD},
 | 
				
			||||||
 | 
					{CW_ITEM_WTP_REBOOT_STATISTICS,CW_ITEM_REBOOT_OTHER_FAILURE_COUNT,MBAG_WORD},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{CW_ITEM_NONE}
 | 
					{CW_ITEM_NONE}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -173,6 +173,15 @@ extern const char CW_ITEM_RADIO_INFOS[];
 | 
				
			|||||||
extern const char CW_ITEM_ECN_SUPPORT[];
 | 
					extern const char CW_ITEM_ECN_SUPPORT[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define CW_ITEM_REBOOT_COUNT "reboot_count"
 | 
				
			||||||
 | 
					#define CW_ITEM_REBOOT_AC_INITIATED_COUNT "ac_initiated"
 | 
				
			||||||
 | 
					#define CW_ITEM_REBOOT_LINK_FAILURE_COUNT "link_failure"
 | 
				
			||||||
 | 
					#define CW_ITEM_REBOOT_SW_FAILURE_COUNT "sw_failure"
 | 
				
			||||||
 | 
					#define CW_ITEM_REBOOT_HW_FAILURE_COUNT "hw_failure"
 | 
				
			||||||
 | 
					#define CW_ITEM_REBOOT_OTHER_FAILURE_COUNT "other_failure"
 | 
				
			||||||
 | 
					#define CW_ITEM_REBOOT_UNKNOWN_FAILURE_COUNT "unknown_failure"
 | 
				
			||||||
 | 
					#define CW_ITEM_REBOOT_LAST_FAILURE_TYPE "last_failure"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern struct cw_itemdef capwap_itemdefs[];
 | 
					extern struct cw_itemdef capwap_itemdefs[];
 | 
				
			||||||
 | 
				
			|||||||
@ -177,6 +177,7 @@ static inline int mbag_set_word(mbag_t s, const char *id, uint16_t word)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline struct mbag_item * mbag_set_dword(mbag_t s, const char *id, uint32_t dword)
 | 
					static inline struct mbag_item * mbag_set_dword(mbag_t s, const char *id, uint32_t dword)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct mbag_item *i = mbag_item_create(s, id);
 | 
						struct mbag_item *i = mbag_item_create(s, id);
 | 
				
			||||||
@ -440,6 +441,17 @@ static inline mavl_t mbag_get_mbag_c(mbag_t s, const char *id,
 | 
				
			|||||||
	return avltree;
 | 
						return avltree;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int mbag_inc_word(mbag_t s, const char * id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						uint16_t w = mbag_get_word(s,id,0);
 | 
				
			||||||
 | 
						mbag_set_word(s,id,w+1);
 | 
				
			||||||
 | 
						return 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline mavl_t mbag_i_get_mbag_c(mbag_t s, uint32_t iid,
 | 
					static inline mavl_t mbag_i_get_mbag_c(mbag_t s, uint32_t iid,
 | 
				
			||||||
							 mavl_t (creator) ())
 | 
												 mavl_t (creator) ())
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
				
			|||||||
@ -293,6 +293,7 @@ static cw_action_in_t actions_in[] = {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	,
 | 
						,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* AC Name - Config Status Request */
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		.capwap_state = CW_STATE_CONFIGURE, 
 | 
							.capwap_state = CW_STATE_CONFIGURE, 
 | 
				
			||||||
		.msg_id = CW_MSG_CONFIGURATION_STATUS_REQUEST,
 | 
							.msg_id = CW_MSG_CONFIGURATION_STATUS_REQUEST,
 | 
				
			||||||
@ -306,6 +307,7 @@ static cw_action_in_t actions_in[] = {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	,
 | 
						,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*  Radio Admin State - Config Status Request */
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		.capwap_state = CW_STATE_CONFIGURE, 
 | 
							.capwap_state = CW_STATE_CONFIGURE, 
 | 
				
			||||||
		.msg_id = CW_MSG_CONFIGURATION_STATUS_REQUEST,
 | 
							.msg_id = CW_MSG_CONFIGURATION_STATUS_REQUEST,
 | 
				
			||||||
@ -317,7 +319,7 @@ static cw_action_in_t actions_in[] = {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	,
 | 
						,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Vendor Specific Payload - Echo Request*/
 | 
						/* Vendor Specific Payload - Config Status Request */
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		.capwap_state = CW_STATE_CONFIGURE, 
 | 
							.capwap_state = CW_STATE_CONFIGURE, 
 | 
				
			||||||
		.msg_id = CW_MSG_CONFIGURATION_STATUS_REQUEST, 
 | 
							.msg_id = CW_MSG_CONFIGURATION_STATUS_REQUEST, 
 | 
				
			||||||
 | 
				
			|||||||
@ -61,6 +61,23 @@ int setup_conf(struct conn *  conn)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	mbag_set_byte(conn->config,CW_ITEM_ECN_SUPPORT,get_ecn_support());
 | 
						mbag_set_byte(conn->config,CW_ITEM_ECN_SUPPORT,get_ecn_support());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						n = mbag_get(conn->config,CW_ITEM_WTP_REBOOT_STATISTICS);
 | 
				
			||||||
 | 
						if (!n){
 | 
				
			||||||
 | 
							mbag_t rs =mbag_create();
 | 
				
			||||||
 | 
							mbag_set_mbag(conn->config, CW_ITEM_WTP_REBOOT_STATISTICS,rs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							mbag_set_dword(rs,CW_ITEM_REBOOT_COUNT,0);
 | 
				
			||||||
 | 
							mbag_set_dword(rs,CW_ITEM_REBOOT_AC_INITIATED_COUNT,0);
 | 
				
			||||||
 | 
							mbag_set_dword(rs,CW_ITEM_REBOOT_LINK_FAILURE_COUNT,0);
 | 
				
			||||||
 | 
							mbag_set_dword(rs,CW_ITEM_REBOOT_SW_FAILURE_COUNT,0);
 | 
				
			||||||
 | 
							mbag_set_dword(rs,CW_ITEM_REBOOT_HW_FAILURE_COUNT,0);
 | 
				
			||||||
 | 
							mbag_set_dword(rs,CW_ITEM_REBOOT_OTHER_FAILURE_COUNT,0);
 | 
				
			||||||
 | 
							mbag_set_dword(rs,CW_ITEM_REBOOT_UNKNOWN_FAILURE_COUNT,0);
 | 
				
			||||||
 | 
							mbag_set_dword(rs,CW_ITEM_REBOOT_LAST_FAILURE_TYPE, CW_REBOOT_TYPE_NOT_SUPPORTED);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -60,9 +60,50 @@ int handle_update_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const char *t = CW_ITEM_WTP_NAME;
 | 
					const char *t = CW_ITEM_WTP_NAME;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <signal.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void update_reboot_stats(struct conn * conn, int cause)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mbag_t rs = mbag_get_mbag(conn->config,CW_ITEM_WTP_REBOOT_STATISTICS,NULL);
 | 
				
			||||||
 | 
						uint16_t rv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						printf("Loaded mbag %p\n",rs);
 | 
				
			||||||
 | 
						switch (cause){
 | 
				
			||||||
 | 
							case CW_REBOOT_TYPE_NOT_SUPPORTED:
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case CW_REBOOT_TYPE_AC_INITIATED:
 | 
				
			||||||
 | 
								mbag_inc_word(rs,CW_ITEM_REBOOT_AC_INITIATED_COUNT);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case CW_REBOOT_TYPE_OTHER_FAILURE:
 | 
				
			||||||
 | 
								mbag_inc_word(rs,CW_ITEM_REBOOT_OTHER_FAILURE_COUNT);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						cfg_to_json();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void sig_handler(int sig)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct conn * conn = the_conn; //get_conn();
 | 
				
			||||||
 | 
						printf("Ctrl+C pressed, updating reboot statistics for %p\n",conn);	
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						update_reboot_stats(conn, CW_REBOOT_TYPE_OTHER_FAILURE);
 | 
				
			||||||
 | 
						exit(0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main()
 | 
					int main()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						signal (SIGINT, sig_handler);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wtpconf_preinit();
 | 
						wtpconf_preinit();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -165,6 +206,10 @@ int main()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	mbag_set_mbag(conn->config, CW_ITEM_WTP_BOARD_DATA, board_data);
 | 
						mbag_set_mbag(conn->config, CW_ITEM_WTP_BOARD_DATA, board_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mbag_t reboot_statistics = mbag_create();
 | 
				
			||||||
 | 
						mbag_set_mbag(conn->config, CW_ITEM_WTP_REBOOT_STATISTICS,reboot_statistics);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//      mbag_set_bstrv(conn->config, CW_ITEM_WTP_SOFTWARE_VERSION, sw);
 | 
					//      mbag_set_bstrv(conn->config, CW_ITEM_WTP_SOFTWARE_VERSION, sw);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user