init ems server code
This commit is contained in:
99
plat/debug/Makefile
Normal file
99
plat/debug/Makefile
Normal file
@@ -0,0 +1,99 @@
|
||||
|
||||
##----------------------------------------------------------##
|
||||
## ##
|
||||
## Universal Makefile for module template : V1.6.3 ##
|
||||
## ##
|
||||
## Created : Wei Liu 07/04/11 ##
|
||||
## Revision: [Last]Wei Liu 07/07/07 ##
|
||||
## ##
|
||||
##----------------------------------------------------------##
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
##--------------------------------------
|
||||
##
|
||||
## Project correlation(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
## MODULE= [Module Name]
|
||||
## TYPE = app/plat => Module Type
|
||||
|
||||
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Debug ]
|
||||
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Release]
|
||||
|
||||
## BUILD = lib/exef => Output file format
|
||||
## CFG = debug/release => Build Configuration
|
||||
|
||||
## SRC_PATH = [Source file path]
|
||||
## INC_PATH = [Include file path]
|
||||
## APP_PATH = [App Module path]
|
||||
## PLT_PATH = [Plat Module path]
|
||||
|
||||
## PLT_LIB = [Needed plat lib for Link] => just for test or wxc2main
|
||||
## APP_LIB = [Needed app lib for Link] => just for test or wxc2main
|
||||
## LIB_ADD = [Needed Extend lib for Link] => just for test or wxc2main
|
||||
|
||||
## PLT_LIB e.g. = haepub fsm mng proto kernel aif mgc mgcp sip rtp \
|
||||
## 8ecp bicc smpp xapp tcap mtp3 m2ua \
|
||||
## snmp iptrans debug sccp public
|
||||
##
|
||||
## APP_LIB e.g. = msc vlr ssf hlr ae pps mnp smsc vms aas
|
||||
## LIB_ADD e.g. = -liba3a8 -lm
|
||||
|
||||
## OBJ_ADD = [Extend third party object files needed]
|
||||
## TEST_OBJ_PATH = [module object files Path for test ] => just for test
|
||||
##---------------------------------------------------------------------##
|
||||
|
||||
MODULE = debug
|
||||
TYPE = plat
|
||||
|
||||
DBUG_FLAGS_ADD = -DDEBUG
|
||||
RELS_FLAGS_ADD =
|
||||
|
||||
##Default commonly as below
|
||||
|
||||
BUILD = lib
|
||||
CFG = debug
|
||||
|
||||
|
||||
PLT_LIB =
|
||||
|
||||
APP_LIB =
|
||||
LIB_ADD =
|
||||
|
||||
SRC_PATH = ./src
|
||||
INC_PATH = ./src/include
|
||||
PLT_PATH = ../../plat
|
||||
APP_PATH = ../../mss
|
||||
|
||||
OBJ_ADD =
|
||||
TEST_OBJ_PATH =
|
||||
|
||||
PREPROC_CMD =
|
||||
POSTPROC_CMD =
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make configuration(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
## CCFLAG_SWITCH = on/off => gcc flag show on/off
|
||||
## COVER_NEED = yes/no => PTF cover report needed
|
||||
## COVER_REPORT_PATH = [path ] => PTF cover report path
|
||||
|
||||
CCFLAG_SWITCH = off
|
||||
COVER_NEED = no
|
||||
COVER_REPORT_PATH = ./output
|
||||
MAKE_INCLUDE = $(HOME)/ems.git/include
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## include makefile.rules (Do not change)
|
||||
##
|
||||
##--------------------------------------
|
||||
include $(MAKE_INCLUDE)/Makefile.rules
|
||||
15649
plat/debug/src/debug.c
Normal file
15649
plat/debug/src/debug.c
Normal file
File diff suppressed because it is too large
Load Diff
64
plat/debug/src/include/debug.h
Normal file
64
plat/debug/src/include/debug.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* Debug module strucutre head file */
|
||||
/* Written by Liu Wei 2005-05-10 */
|
||||
/* Version 4.0 */
|
||||
/* -------------------------------- */
|
||||
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG
|
||||
|
||||
#include "debug_struct.h"
|
||||
#include "dirent.h"
|
||||
|
||||
/* by simon at 23/9/25
|
||||
mib_node *mib_root_node;
|
||||
mib_node *mib_curr_node;
|
||||
menu_node *menu_root_node;
|
||||
menu_node *menu_curr_node;
|
||||
mib_node mib_nodes[MIB_MAX_NODES];
|
||||
*/
|
||||
|
||||
/* by simon at 23/9/25
|
||||
//for test
|
||||
char file_name[128];
|
||||
FILE *fp_prt;
|
||||
long int timeuse,max_time;
|
||||
struct timeval tv_start, tv_end;
|
||||
//for test
|
||||
*/
|
||||
|
||||
/* by simon at 23/9/25
|
||||
menu_node menu_nodes[MENU_MAX_NODES];
|
||||
mib_child_node mib_child_nodes[MIB_MAX_CHILD_NODES];
|
||||
|
||||
debug_snmp_agent debug_snmp_agent_buf[MAX_PACKET_NUM];
|
||||
end by simon */
|
||||
|
||||
//////////////////////////////interface declaration////////////////////////
|
||||
|
||||
void debug_init();
|
||||
|
||||
void debug_rt();
|
||||
|
||||
|
||||
WORD find_child_index(mib_node *node_ptr, DWORD oid, char *name, BYTE type);
|
||||
|
||||
mib_node *find_node(mib_node *start_node_ptr, char *node_name, int find_type, DWORD *last_node_oid);
|
||||
|
||||
mib_node *search_mib_node(mib_node *start_mib_node_ptr, DWORD *oid, BYTE oid_len);
|
||||
|
||||
int debug_set_response(unsigned char object_id_len,unsigned int *object_id,unsigned char *data,unsigned short data_len);
|
||||
|
||||
int debug_get_response(unsigned char object_id_len,unsigned int *object_id,unsigned char *data,unsigned char *vartype);
|
||||
|
||||
menu_node *search_menu_node(menu_node *start_menu_node_ptr, BYTE *menu_id, BYTE id_len);
|
||||
|
||||
void Clear_Access_History();
|
||||
|
||||
void debug_set_agent();
|
||||
|
||||
void debug_get_agent();
|
||||
|
||||
int get_my_address (struct in_addr *addr);
|
||||
|
||||
//////////////////////////////end of interface declaration////////////////////////
|
||||
#endif
|
||||
375
plat/debug/src/include/debug_struct.h
Normal file
375
plat/debug/src/include/debug_struct.h
Normal file
@@ -0,0 +1,375 @@
|
||||
/* Debug module strucutre head file */
|
||||
/* Written by Liu Zhiguo 2003-04-22 */
|
||||
/* Version 2.0 */
|
||||
/* -------------------------------- */
|
||||
|
||||
#ifndef _DEBUG_STRUCT
|
||||
#define _DEBUG_STRUCT
|
||||
|
||||
#include "../../../public/src/include/pub_include.h"
|
||||
#include "../../../iptrans/src/include/iptrans.h"
|
||||
#include "../../../snmp/src/include/snmp.h"
|
||||
#include "../../../snmp/src/include/heartbeat.h"
|
||||
|
||||
//Module ID
|
||||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
||||
//a b c d e f g h i j k l m n o p q r s t u v w x y z
|
||||
//a b c d e f g h i j k l m n o p r s t u v w y z
|
||||
|
||||
#define DEBUG_PORT 4965
|
||||
#define DEBUG_SNMP_PORT 4956
|
||||
#define SNMP_PORT 4957
|
||||
#define DEBUG_VERSION "R9V0_03"
|
||||
|
||||
#define TELNET_SEND_BUF_LEN 1000
|
||||
#define SERIAL_BUF_LEN 2048
|
||||
#define DEBUG_MAX_PAGE 2
|
||||
#define PAGE_MODULE_COUNT 24
|
||||
#define MODULE_COUNT (PAGE_MODULE_COUNT*DEBUG_MAX_PAGE)
|
||||
#define DEBUG_MAX_SEQID 0x7fffffff
|
||||
#define DEBUG_SEQID_LEN 8
|
||||
#define DEBUG_OMCBUF_LEN 1024
|
||||
#define DEBUG_NAME_LEN 8
|
||||
#define PAGE_COUNT 24
|
||||
#define LINE_COUNT 23
|
||||
#define MAX_ROW 25
|
||||
#define MAX_COLUMN 80
|
||||
#define TITLE_CHAR 2048
|
||||
#define MAX_ASCII_LEN (1024*16)
|
||||
|
||||
#define DEBUG_SHM_KEY 0xa0600000
|
||||
#define DEBUG_SHM_PERM 0664
|
||||
|
||||
#define MENU_TYPE 0
|
||||
#define OID_TYPE 1
|
||||
|
||||
// MIB wangjian add
|
||||
#define MIB_LIST_FILE "mib_list_file.txt"
|
||||
#define MIB_FILES_DIR "./conf/MIB_files/"
|
||||
#define MIB_OMC_PUB_SYSCONF_FILE "OMC_PUB_sysConf.csv"
|
||||
#define MIB_PARAM_LIST_FILE "mib_param_list_file.txt"
|
||||
#define MIB_WRITE_TREE "mib_write_tree.txt"
|
||||
#define MIB_SYSTEM_CONFIG_FILE "System_Config.txt"
|
||||
#define MIB_SYSTEM_IP_LIST_FILE "System_IP_List.txt"
|
||||
#define MENU_TREE_FILE "menu_tree.txt"
|
||||
|
||||
#define MIB_MAX_CHILD_NODES_PER_NODE 256
|
||||
#define MIB_MAX_NODES 1536
|
||||
#define MIB_MAX_CHILD_NODES 1536 * 5
|
||||
|
||||
#define MIB_MAX_PARAM_SELECTS 1536 * 8
|
||||
#define MIB_MAX_PARAM_INPUTS 1536 * 8
|
||||
#define MIB_MAX_NODE_PARAMS 1536 * 4
|
||||
#define MAX_TOTAL_INSTANCE 2048
|
||||
#define MAX_NODE_PACKET_LENGTH 256
|
||||
#define MAX_SEND_CHAR_NUM 512
|
||||
|
||||
//#define MIB_OPER_TYPE_GET 1
|
||||
//#define MIB_OPER_TYPE_GET_ALL 2
|
||||
//#define MIB_OPER_TYPE_SET 3
|
||||
//#define MIB_OPER_TYPE_HELP 4
|
||||
|
||||
#define MIB_MODULE_REVISION_MAX_NUM 10
|
||||
|
||||
#define MIB_SUBSYS_MODULE_MAX_NUM 64
|
||||
|
||||
#define MIB_HOST_MAX_NUM 127
|
||||
|
||||
#define MIB_NODE_PARAM_MAX_LEN 64
|
||||
#define GROUP_NUM 2
|
||||
#define MEMBER_MAX_NUM 16
|
||||
#define MENU_MAX_NODES 640
|
||||
|
||||
#define TODEC_HIGH_0 0
|
||||
#define KEEPHEX_HIGH_0 1
|
||||
#define KEEPHEX_LOW_0 2
|
||||
#define KEEPHEX_LOW_E 3
|
||||
#define KEEPHEX_LOW_F 4
|
||||
#define TOASCII_LOW_0 5
|
||||
#define KEEPASC_LOW_F 6
|
||||
|
||||
|
||||
#define MAX_PACKET_NUM 16
|
||||
#define MAX_SELECT_OPTION_NUM 21
|
||||
#define MAX_OPTION_LENGTH 32
|
||||
#define MAX_HOST_IP 16
|
||||
#define MAX_PARAM_NUM 64
|
||||
|
||||
typedef struct CommandList
|
||||
{
|
||||
char cmm[128];
|
||||
struct CommandList *nextcmm;
|
||||
}cmmset,cmmrem;
|
||||
|
||||
// MIB end
|
||||
|
||||
typedef struct _DEBUG_TELNET_SEND_DATA
|
||||
{
|
||||
int telsend_datah;
|
||||
BYTE telsend_data[TELNET_SEND_BUF_LEN];
|
||||
}DEBUG_TELNET_SEND_DATA;
|
||||
|
||||
struct debug_line
|
||||
{
|
||||
BYTE pt_vartype;
|
||||
WORD length;
|
||||
BYTE *pointer;
|
||||
};
|
||||
|
||||
struct debug_page
|
||||
{
|
||||
BYTE pointer_set_flag;
|
||||
char title[TITLE_CHAR];
|
||||
struct debug_line line_d[LINE_COUNT];
|
||||
};
|
||||
|
||||
typedef struct debug_module_struct
|
||||
{
|
||||
char name[DEBUG_NAME_LEN];
|
||||
char status[2];
|
||||
char version[20];
|
||||
BYTE maxpage;
|
||||
BYTE ascii_in_set_flag;
|
||||
BYTE ascii_out_set_flag;
|
||||
BYTE *ascii_in;
|
||||
WORD ascii_in_len;
|
||||
BYTE *ascii_out;
|
||||
WORD ascii_out_len;
|
||||
struct debug_page page_d[PAGE_COUNT];
|
||||
int seqid_h; // head sequence id for omc get
|
||||
int seqid_t; // tail sequence id for omc get
|
||||
BYTE omc_outbuf[DEBUG_SEQID_LEN][DEBUG_OMCBUF_LEN];
|
||||
} debug_module_struct;
|
||||
|
||||
typedef struct debug_shm_struct
|
||||
{
|
||||
debug_module_struct module_d[MODULE_COUNT];
|
||||
DEBUG_TELNET_SEND_DATA TelnetSendData;
|
||||
} debug_shm_struct;
|
||||
|
||||
// by simon at 23/9/25
|
||||
//struct debug_shm_struct *debug_shm_ptr;
|
||||
//struct iptrans_shm *pIptransShm;
|
||||
|
||||
// MIB wangjian add
|
||||
typedef struct _mibfile_imports_data
|
||||
{
|
||||
char father_name[64];
|
||||
char from_file[32];
|
||||
} mibfile_imports_data;
|
||||
|
||||
typedef struct _mibfile_module_data
|
||||
{
|
||||
char name[64]; // nod name
|
||||
char LU[32]; // LAST-UPDATED
|
||||
char OR[64]; // ORGANIZATION
|
||||
char CI[128]; // CONTACT-INFO
|
||||
char DE[1024]; // DESCRIPTION
|
||||
char RE[MIB_MODULE_REVISION_MAX_NUM][32]; // REVISION
|
||||
char RE_DE[MIB_MODULE_REVISION_MAX_NUM][1024]; // REVISION'S DESCRIPTION
|
||||
int RE_index; // the number of RE and RE_DE
|
||||
char father_name[64]; // father's name
|
||||
char ID[32]; // child ID
|
||||
} mibfile_module_data;
|
||||
|
||||
typedef struct _mibfile_object_data
|
||||
{
|
||||
char name[64]; // nod name
|
||||
int ST; // STATUS: 1: current, 2: deprecated, 3: obsolete. 0: invalid
|
||||
char DE[1024]; // DESCRIPTION
|
||||
char RF[1024]; // ReferPart
|
||||
char father_name[64]; // father's name
|
||||
char ID[32]; // child ID
|
||||
} mibfile_object_data;
|
||||
|
||||
typedef struct _mibfile_type_data
|
||||
{
|
||||
char name[64]; // nod name
|
||||
int SY; // SYNTAX: 0:invalid. 1: Integer32, 2: INTEGER, 3: OCTET STRING, 4: OBJECT IDENTIFIER, 5: BITS, 6: IpAddress, 7: Counter32,
|
||||
// 8: Gauge32, 9: TimeTicks, 10: Opaque, 11: Counter64, 12: Unsigned32, 13:Conceptual Tables
|
||||
char UP[32]; // UnitsPart
|
||||
BYTE MA; // MAX-ACCESS: 0: invalid, 1: not-accessible, 2: accessible-for-notify, 3: read-only, 4: read-write, 5: read-create 6: write-only
|
||||
int ST; // STATUS
|
||||
char DE[8192]; // DESCRIPTION
|
||||
int total_instance; // total_instance
|
||||
char RF[1024]; // ReferPart;
|
||||
char father_name[64]; // father's name
|
||||
char ID[32]; // child ID
|
||||
} mibfile_type_data;
|
||||
|
||||
//typedef int (*mib_call)(DWORD *oid, BYTE oid_len, char *name, char *value, BYTE oper_type);
|
||||
|
||||
typedef struct _mib_child_node
|
||||
{
|
||||
char name[64];
|
||||
DWORD oid;
|
||||
void *child_ptr;
|
||||
} mib_child_node;
|
||||
|
||||
typedef struct _mib_node
|
||||
{
|
||||
void *parent_ptr;
|
||||
char name[32];
|
||||
BYTE oid_len;
|
||||
DWORD oid[32];
|
||||
BYTE data_length;
|
||||
BYTE module_index;
|
||||
WORD total_instance;
|
||||
WORD curr_instance;
|
||||
WORD total_child_nodes;
|
||||
BYTE enable_field_id;
|
||||
BYTE enable_flag[32];
|
||||
BYTE access_history;
|
||||
char init_value[256];
|
||||
//mib_call mib_proc;
|
||||
char *remark_ptr;
|
||||
//char remark[DEBUG_OMCBUF_LEN * 2];
|
||||
mib_child_node *child_nodes[MIB_MAX_CHILD_NODES_PER_NODE];
|
||||
BYTE max_access; // MAX-ACCESS: 0: invalid, 1: not-accessible, 2: accessible-for-notify, 3: read-only, 4: read-write, 5: read-create 6: write-only
|
||||
}mib_node;
|
||||
|
||||
typedef struct _menu_node
|
||||
{
|
||||
void *father_ptr;
|
||||
void *child_node[MENU_MAX_NODES];
|
||||
mib_node *menu_oid_node;
|
||||
BYTE oid[23];
|
||||
BYTE id_len;
|
||||
BYTE total_menu_child;
|
||||
char name[32];
|
||||
BYTE menu_id[20];
|
||||
BYTE sys_group;
|
||||
}menu_node;
|
||||
|
||||
// MIB FIELD struct
|
||||
typedef struct _mib_param_select
|
||||
{
|
||||
WORD number;
|
||||
char description[MIB_NODE_PARAM_MAX_LEN];
|
||||
} mib_param_select;
|
||||
|
||||
typedef struct _instance_arr
|
||||
{
|
||||
DWORD ins;
|
||||
BYTE eable;
|
||||
}INSTANCE_ARR;
|
||||
|
||||
typedef struct _mib_param_input
|
||||
{
|
||||
BYTE input_param_type; // 0: toDec_high_0
|
||||
// 1: keepHex_high_0
|
||||
// 2: keepHex_low_0
|
||||
// 3: keepHex_low_E
|
||||
// 4: keepHex_low_F
|
||||
// 5: toAscii_low_0
|
||||
// 6: keepAscii_low_F
|
||||
char input[MIB_NODE_PARAM_MAX_LEN];
|
||||
} mib_param_input;
|
||||
|
||||
typedef struct _mib_node_param
|
||||
{
|
||||
void *parent_ptr;
|
||||
char name[64];
|
||||
BYTE id;
|
||||
BYTE byte_begin;
|
||||
BYTE byte_end;
|
||||
BYTE bit_begin;
|
||||
BYTE bit_end;
|
||||
mib_param_select *select_ptr[16];
|
||||
BYTE select_total;
|
||||
BYTE select_value;
|
||||
mib_param_input *input_ptr;
|
||||
} mib_node_param;
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct _mib_subsys_module
|
||||
{
|
||||
BYTE index;
|
||||
DWORD oid[8];
|
||||
char name[10];
|
||||
BYTE max_group;
|
||||
//char obj_type_no[3];
|
||||
}mib_subsys_module;
|
||||
|
||||
typedef struct _mib_host
|
||||
{
|
||||
BYTE index;
|
||||
BYTE group_index;
|
||||
BYTE member_index;
|
||||
char host_name[32];
|
||||
WORD host_ip[4];
|
||||
}mib_host;
|
||||
|
||||
typedef struct _module_command_save_flag
|
||||
{
|
||||
BYTE module_index;
|
||||
DWORD oid[32];
|
||||
BYTE oid_len;
|
||||
BYTE save_select_id;
|
||||
BYTE save_field_id;
|
||||
}module_command_save_flag;
|
||||
|
||||
|
||||
typedef struct param_field
|
||||
{
|
||||
char name[48]; //set fill in
|
||||
char curr_input_value[32]; //set fill in
|
||||
BYTE input_type;
|
||||
BYTE curr_select_id;
|
||||
BYTE total_select;
|
||||
WORD value_arr[MAX_SELECT_OPTION_NUM];
|
||||
char value_arr_remark[MAX_SELECT_OPTION_NUM][MAX_OPTION_LENGTH];
|
||||
}param_field;
|
||||
|
||||
typedef struct debug_snmp_agent_packet
|
||||
{
|
||||
DWORD oid[32]; //set fill in
|
||||
//0 idle 1 waitting get 2 waitting set 3 process 4 fail 5 success
|
||||
BYTE cmm_state; //set fill in
|
||||
//0 success 1 time out 2 buffer full 3 oid error 4 ip str error
|
||||
//5 instance error 6 leaf node param forbidden 7 total field error
|
||||
//8 no select option 9 snmp send error 1xx no child 2xx no select 3xx field input error
|
||||
BYTE result_state;
|
||||
BYTE agentClient;
|
||||
BYTE oid_len; //set fill in
|
||||
BYTE total_field; //set fill in
|
||||
WORD total_instance; //set fill in
|
||||
BYTE total_ip; //set fill in
|
||||
char dst_ip[MAX_HOST_IP][15]; //set fill inxxx.xxx.xxx.xxx
|
||||
param_field param_field_arr[MAX_PARAM_NUM];
|
||||
|
||||
}debug_snmp_agent;
|
||||
|
||||
//MIB end
|
||||
|
||||
|
||||
|
||||
typedef struct _comput_list
|
||||
{
|
||||
BYTE list_field_id;
|
||||
char field_val[256][32];
|
||||
mib_node *list_node;
|
||||
}compute_list;
|
||||
|
||||
typedef struct _compute_field
|
||||
{
|
||||
char name[32];
|
||||
mib_node *compute_node;
|
||||
BYTE field_id;
|
||||
char syntax_str[10][64];
|
||||
BYTE syntax_count;
|
||||
char print_val_str[128][32];
|
||||
char print_name_str[128][32];
|
||||
BYTE print_count;
|
||||
}compute_field;
|
||||
|
||||
typedef struct _wxc2_debug_info
|
||||
{
|
||||
char wxc2_ver[32];
|
||||
BYTE sys_type; // cdma 1 gsm 2 gc_ssw 3
|
||||
BYTE mmi_switch; // on 1 0 off
|
||||
}wxc2_debug_info;
|
||||
|
||||
#endif
|
||||
926
plat/debug/ut/debug_test.c
Normal file
926
plat/debug/ut/debug_test.c
Normal file
@@ -0,0 +1,926 @@
|
||||
|
||||
/************************************************
|
||||
* debug_test.c
|
||||
* Author: LiuWei
|
||||
* Create: 2005-05-31
|
||||
************************************************/
|
||||
|
||||
#include "./include/debug.h"
|
||||
#include "../../iptrans/src/include/iptrans.h"
|
||||
#include "../../snmp/src/include/snmp.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/telnet.h>
|
||||
#include <linux/kd.h>
|
||||
#include <linux/keyboard.h>
|
||||
#define BUFLEN 1024
|
||||
#define MAX_RECV_NONE 20
|
||||
#define REC_NUM 50
|
||||
|
||||
char shellcode[] = "\x97\x97\x97\x97\x97\x97";
|
||||
|
||||
//add test line
|
||||
|
||||
static struct itimerval itimer, old_itimer;
|
||||
fd_set rset;
|
||||
BYTE connect_flag = 0;
|
||||
struct sockaddr_in sin_addr;
|
||||
int flag = 1;
|
||||
int sockfd;
|
||||
char buffer[2048];
|
||||
int command_list_count;
|
||||
BYTE recv_over = 0;
|
||||
int addr_len = sizeof(struct sockaddr_in);
|
||||
int len = 0;
|
||||
BYTE recv_ten_times = 0;
|
||||
BYTE test_style = 2;
|
||||
BYTE test_snmp_mode = 0;
|
||||
char oid_cmm_state[128];
|
||||
BYTE recv_none = 0;
|
||||
//char file_name[128];
|
||||
FILE *fp_conf,*fp_agent;
|
||||
struct timeval tv_start, tv_end;
|
||||
long timeuse;
|
||||
long max_time;
|
||||
int i, j;
|
||||
int time_vel;
|
||||
int multi;
|
||||
char data_arr[1024], multi_str[16];
|
||||
char command[1024];
|
||||
char oid_command[128];
|
||||
|
||||
|
||||
void AsciiToRbcd (BYTE *bcd_buf, const char *ascii_buf, int len);
|
||||
void MMI_telnet();
|
||||
void MMI_telnet_send(char *str);
|
||||
void MMI_auto_test();
|
||||
void MMI_telnet_recv();
|
||||
void Set_Timer();
|
||||
void On_Timer();
|
||||
void MMI_telnet_cmd();
|
||||
void debug_snmp_agent_test_input();
|
||||
void debug_snmp_agent_test_output();
|
||||
void debug_snmp_print();
|
||||
void MMI_File_Test(char *data_arr);
|
||||
|
||||
void usage(char *p)
|
||||
{
|
||||
printf("Usage: %s [ip] [-a atuo test] [-m manual test] [-n normal start] [-f script file]\n\n", p);
|
||||
printf("\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void msg(char *msg)
|
||||
{
|
||||
perror(msg);
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
u_int32_t get_ip(char *host)
|
||||
{
|
||||
struct hostent *hp;
|
||||
|
||||
if(!(hp = gethostbyname(host)))
|
||||
{
|
||||
fprintf(stderr, "cannot resolve %s\n", host);
|
||||
return (0);
|
||||
}
|
||||
return (*(u_int32_t *) hp->h_addr_list[0]);
|
||||
}
|
||||
|
||||
int get_socket(char *target, int port)
|
||||
{
|
||||
int sock;
|
||||
u_int32_t ip;
|
||||
|
||||
if(!(ip = get_ip(target)))
|
||||
return (0);
|
||||
|
||||
bzero(&sin_addr, sizeof(sin_addr));
|
||||
sin_addr.sin_family = AF_INET;
|
||||
sin_addr.sin_port = htons(port);
|
||||
sin_addr.sin_addr.s_addr = ip;
|
||||
|
||||
if(!(sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
msg("Get socket:");
|
||||
if(ioctl(sock, FIONBIO, &flag) == -1)
|
||||
{
|
||||
printf("Set nonblock:");
|
||||
close(sockfd);
|
||||
exit(1);
|
||||
}
|
||||
if(connect(sock, (struct sockaddr *)&sin_addr, sizeof(sin_addr)) < 0)
|
||||
if((errno != EWOULDBLOCK) && (errno != EINPROGRESS))
|
||||
msg("Connect:");
|
||||
return (sock);
|
||||
}
|
||||
|
||||
void send_wont(int sock, int option)
|
||||
{
|
||||
char buf[3], *ptr = buf;
|
||||
|
||||
*ptr++ = IAC;
|
||||
*ptr++ = WONT;
|
||||
*ptr++ = (unsigned char)option;
|
||||
if(write(sock, buf, 3) < 0)
|
||||
msg("write");
|
||||
return;
|
||||
}
|
||||
|
||||
void send_will(int sock, int option)
|
||||
{
|
||||
char buf[3], *ptr = buf;
|
||||
|
||||
*ptr++ = IAC;
|
||||
*ptr++ = WILL;
|
||||
*ptr++ = (unsigned char)option;
|
||||
if(write(sock, buf, 3) < 0)
|
||||
msg("write");
|
||||
return;
|
||||
}
|
||||
|
||||
void send_do(int sock, int option)
|
||||
{
|
||||
char buf[3], *ptr = buf;
|
||||
|
||||
*ptr++ = IAC;
|
||||
*ptr++ = DO;
|
||||
*ptr++ = (unsigned char)option;
|
||||
if(write(sock, buf, 3) < 0)
|
||||
msg("write");
|
||||
return;
|
||||
}
|
||||
|
||||
void send_env(int sock, char *name, char *value)
|
||||
{
|
||||
char buf[BUFLEN], *ptr = buf;
|
||||
|
||||
*ptr++ = IAC;
|
||||
*ptr++ = SB;
|
||||
*ptr++ = TELOPT_NEW_ENVIRON;
|
||||
*ptr++ = TELQUAL_IS;
|
||||
*ptr++ = NEW_ENV_VAR;
|
||||
strncpy(ptr, name, BUFLEN - 20);
|
||||
ptr += strlen(ptr);
|
||||
*ptr++ = NEW_ENV_VALUE;
|
||||
strncpy(ptr, value, (&buf[BUFLEN - 1] - ptr) - 1);
|
||||
ptr += strlen(ptr);
|
||||
*ptr++ = IAC;
|
||||
*ptr++ = SE;
|
||||
|
||||
if(write(sock, buf, (ptr - buf)) < 0)
|
||||
msg("write");
|
||||
return;
|
||||
}
|
||||
|
||||
void do_negotiate(int sock)
|
||||
{
|
||||
send_will(sock, TELOPT_ECHO);
|
||||
send_wont(sock, TELOPT_TTYPE);
|
||||
send_wont(sock, TELOPT_NAWS);
|
||||
send_wont(sock, TELOPT_LFLOW);
|
||||
send_wont(sock, TELOPT_LINEMODE);
|
||||
send_wont(sock, TELOPT_XDISPLOC);
|
||||
send_will(sock, TELOPT_LFLOW);
|
||||
send_will(sock, TELOPT_LINEMODE);
|
||||
send_wont(sock, TELOPT_OLD_ENVIRON);
|
||||
send_will(sock, TELOPT_NEW_ENVIRON);
|
||||
send_will(sock, TELOPT_BINARY);
|
||||
send_env(sock, "TTYPROMPT", shellcode);
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c, port = DEBUG_PORT;
|
||||
char host[36] = "172.18.234.231";
|
||||
|
||||
strcpy(command, "");
|
||||
strcpy(oid_command, "");
|
||||
strcpy(oid_cmm_state, "");
|
||||
if(argc < 2)
|
||||
usage(argv[0]);
|
||||
|
||||
tv_start.tv_sec = 0;
|
||||
tv_start.tv_usec = 0;
|
||||
tv_end.tv_sec = 0;
|
||||
tv_end.tv_usec = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
//ioperm(0x378,3,1);
|
||||
/*
|
||||
strcpy(file_name, "");
|
||||
strcat(file_name, "debug_agent.txt");
|
||||
remove(file_name);
|
||||
*/
|
||||
|
||||
strcpy(file_name, "");
|
||||
strcat(file_name, "debug_test_time_log.txt");
|
||||
remove(file_name);
|
||||
|
||||
if((fp_prt = fopen(file_name, "a+")) == NULL)
|
||||
{
|
||||
printf("[debug] Error: cannot open %s.\r\n", file_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
while((c = getopt(argc, argv, "famn")) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'f': // costumer test
|
||||
printf("The Debug test control by command script!");
|
||||
test_style = 4;
|
||||
break;
|
||||
case 'a': // auto test
|
||||
printf("The Debug Atuo Test!");
|
||||
test_style = 1;
|
||||
break;
|
||||
case 'm': // manually test
|
||||
printf("The Debug manually Test!");
|
||||
test_style = 2;
|
||||
break;
|
||||
case 'n': // normal start
|
||||
printf("The Debug Normal start!");
|
||||
test_style = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
debug_init(1);
|
||||
iptrMainInit();
|
||||
snmp_init(4957);
|
||||
|
||||
if(!(sockfd = get_socket(host, port)))
|
||||
exit(-1);
|
||||
command_list_count = 0;
|
||||
if(test_style == 4)
|
||||
strcpy(command, "");
|
||||
strcpy(multi_str, "");
|
||||
strcpy(data_arr, "");
|
||||
strcpy(file_name, "");
|
||||
strcat(file_name, "debug_test_conf.txt");
|
||||
j = REC_NUM + 1;
|
||||
if((fp_conf = fopen(file_name, "r")) == NULL)
|
||||
{
|
||||
printf("[debug] Error: cannot open %s.\r\n", file_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Set_Timer();
|
||||
while(1)
|
||||
{
|
||||
usleep(10);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MMI_File_Test(char *data_arr)
|
||||
{
|
||||
|
||||
for(i = 0; i < strlen(data_arr); i++)
|
||||
if(data_arr[i] == ' ')
|
||||
break;
|
||||
if(i != strlen(data_arr))
|
||||
strncpy(multi_str, data_arr, i);
|
||||
multi_str[i] = '\0';
|
||||
multi = strtoul(multi_str, NULL, 10);
|
||||
for(; i < strlen(data_arr); i++)
|
||||
{
|
||||
if(data_arr[i] != ' ')
|
||||
break;
|
||||
}
|
||||
strcpy(command, data_arr + i);
|
||||
if(strncasecmp(command, "\\e", 2) == 0)
|
||||
{
|
||||
command[0] = 27;
|
||||
command[1] = '\0';
|
||||
}
|
||||
if(strcmp(command, oid_command) != 0)
|
||||
{
|
||||
strcpy(oid_command, command);
|
||||
if(strcmp(command, "\e") == 0)
|
||||
fprintf(fp_prt, "Command :\e\n");
|
||||
else
|
||||
fprintf(fp_prt, "Command :%s \n", command);
|
||||
}
|
||||
|
||||
if(strcmp(command, "\e") != 0)
|
||||
{
|
||||
strcat(command, "\r\n");
|
||||
}
|
||||
printf("%s", command);
|
||||
MMI_telnet_send(command);
|
||||
usleep(5);
|
||||
|
||||
recv_over = 0;
|
||||
usleep(time_vel);
|
||||
|
||||
}
|
||||
|
||||
void MMI_auto_test()
|
||||
{
|
||||
|
||||
strcpy(command, "");
|
||||
switch (command_list_count)
|
||||
{
|
||||
case 0:
|
||||
strcpy(command, "\e");
|
||||
multi = 1;
|
||||
break;
|
||||
case 1:
|
||||
strcpy(command, "menu");
|
||||
multi = 5;
|
||||
break;
|
||||
case 2:
|
||||
|
||||
strcpy(command, "contents");
|
||||
multi = 8;
|
||||
break;
|
||||
case 3:
|
||||
strcpy(command, "cd 1");
|
||||
multi = 10;
|
||||
break;
|
||||
case 4:
|
||||
strcpy(command, "cd 4");
|
||||
multi = 10;
|
||||
break;
|
||||
case 5:
|
||||
strcpy(command, "list -a -f[2 4 10] -r -t");
|
||||
multi = 25;
|
||||
break;
|
||||
case 6:
|
||||
strcpy(command, "get #0.1");
|
||||
multi = 15;
|
||||
break;
|
||||
case 7:
|
||||
strcpy(command, "cmm");
|
||||
multi = 15;
|
||||
break;
|
||||
case 8:
|
||||
strcpy(command, "\e");
|
||||
multi = 20;
|
||||
break;
|
||||
/*
|
||||
case 9:
|
||||
strcpy(command, "log all");
|
||||
multi = 150;
|
||||
break;
|
||||
case 10:
|
||||
strcpy(command, "\e");
|
||||
multi = 10;
|
||||
break;
|
||||
case 11:
|
||||
strcpy(command, "\e");
|
||||
multi = 10;
|
||||
break;
|
||||
case 12:
|
||||
strcpy(command, "log none");
|
||||
multi = 15;
|
||||
break;
|
||||
case 13:
|
||||
strcpy(command, "\e");
|
||||
multi = 15;
|
||||
break;
|
||||
case 14:
|
||||
strcpy(command, "help");
|
||||
multi = 15;
|
||||
break;
|
||||
case 15:
|
||||
strcpy(command, "\e");
|
||||
multi = 15;
|
||||
break;
|
||||
*/
|
||||
default:
|
||||
command_list_count = 0xfffe;
|
||||
break;
|
||||
}
|
||||
command_list_count++;
|
||||
if(command_list_count == 0xffff)
|
||||
{
|
||||
test_snmp_mode = 1;
|
||||
printf("The command test over\r\n");
|
||||
printf("Test snmp senior interface......\r\n");
|
||||
return;
|
||||
}
|
||||
time_vel = multi * 500;
|
||||
if(command_list_count != 0xffff && recv_over == 2)
|
||||
{
|
||||
|
||||
if(strcmp(command, oid_command) != 0)
|
||||
{
|
||||
strcpy(oid_command, command);
|
||||
if(strcmp(command, "\e") == 0)
|
||||
fprintf(fp_prt, "Command :\e");
|
||||
else
|
||||
fprintf(fp_prt, "Command :%s ", command);
|
||||
}
|
||||
|
||||
if(strcmp(command, "\e") != 0)
|
||||
{
|
||||
strcat(command, "\r\n");
|
||||
}
|
||||
MMI_telnet_send(command);
|
||||
|
||||
usleep(5);
|
||||
if(command_list_count > 0)
|
||||
printf("%s", command);
|
||||
recv_over = 0;
|
||||
usleep(time_vel);
|
||||
}
|
||||
else
|
||||
command_list_count--;
|
||||
}
|
||||
|
||||
void MMI_telnet_recv()
|
||||
{
|
||||
|
||||
len = 0;
|
||||
bzero(buffer, sizeof(buffer));
|
||||
|
||||
len = recvfrom(sockfd, buffer, sizeof(buffer), 0,
|
||||
(struct sockaddr *)&sin_addr, &addr_len);
|
||||
if(len > 0)
|
||||
{
|
||||
printf("%s", buffer);
|
||||
recv_none = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(recv_none < MAX_RECV_NONE)
|
||||
recv_none++;
|
||||
else if(recv_over == 1)
|
||||
recv_over = 2;
|
||||
return;
|
||||
}
|
||||
if(strstr(buffer, "<--"))
|
||||
{
|
||||
recv_over = 1;
|
||||
return;
|
||||
}
|
||||
if(strstr(buffer, "CMM>") || strstr(buffer, "CFG>") ||
|
||||
strstr(buffer, "MENU>") || recv_over == 1)
|
||||
recv_over = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
void MMI_telnet_cmd()
|
||||
{
|
||||
|
||||
|
||||
|
||||
if(ioctl(fileno(stdin), FIONBIO, &flag) == -1)
|
||||
{
|
||||
printf("Set stdin nonblock:");
|
||||
exit(1);
|
||||
}
|
||||
len = 0;
|
||||
bzero(buffer, sizeof(buffer));
|
||||
strcpy(command, "");
|
||||
fgets(buffer, sizeof(buffer), stdin);
|
||||
len = strlen(buffer);
|
||||
if(!len)
|
||||
return;
|
||||
strcpy(command, buffer);
|
||||
if(strcmp(command, oid_command) != 0)
|
||||
{
|
||||
strcpy(oid_command, command);
|
||||
|
||||
if(strcmp(command, "\e") == 0)
|
||||
fprintf(fp_prt, "Command :ESC");
|
||||
else
|
||||
fprintf(fp_prt, "Command :%s ", command);
|
||||
|
||||
}
|
||||
usleep(5);
|
||||
if(strstr(buffer, "\e\n"))
|
||||
recv_over = 2;
|
||||
if(strcmp(buffer, "\e\n") != 0)
|
||||
{
|
||||
buffer[strlen(buffer) - 1] = '\0';
|
||||
strcat(buffer, "\r\n");
|
||||
}
|
||||
if(recv_over > 1)
|
||||
{
|
||||
if(sendto(sockfd, buffer, len, 0, (struct sockaddr *)&sin_addr,
|
||||
addr_len) < 0)
|
||||
msg("Send");
|
||||
recv_over = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void MMI_telnet_send(char *str)
|
||||
{
|
||||
bzero(buffer, sizeof(buffer));
|
||||
strcpy(buffer, str);
|
||||
len = strlen(buffer);
|
||||
if(strlen(str))
|
||||
if(sendto(sockfd, buffer, len, 0, (struct sockaddr *)&sin_addr,
|
||||
addr_len) < 0)
|
||||
msg("Send");
|
||||
}
|
||||
|
||||
void On_Timer()
|
||||
{
|
||||
if(test_style == 1)
|
||||
{
|
||||
iptrans_timer();
|
||||
snmp_timer();
|
||||
outb(0xff, 0x378);
|
||||
//timeuse = 0;
|
||||
//gettimeofday(&tv_start, NULL);
|
||||
debug_rt();
|
||||
/*
|
||||
gettimeofday(&tv_end, NULL);
|
||||
timeuse =
|
||||
1000000 * (tv_end.tv_sec - tv_start.tv_sec) -
|
||||
tv_start.tv_usec + tv_end.tv_usec;
|
||||
if(timeuse > max_time)
|
||||
max_time = timeuse;
|
||||
fprintf(fp_prt,
|
||||
" debug_rt time used: %ld (u sec)<=%ld\r\n\r\n",
|
||||
timeuse, max_time);
|
||||
*/
|
||||
outb(0x00, 0x378);
|
||||
if(connect_flag == 0)
|
||||
{
|
||||
do_negotiate(sockfd);
|
||||
MMI_telnet_recv();
|
||||
send_wont(sockfd, TELOPT_BINARY);
|
||||
MMI_telnet_recv();
|
||||
FD_ZERO(&rset);
|
||||
connect_flag = 1;
|
||||
}
|
||||
MMI_telnet_recv();
|
||||
if(!test_snmp_mode)
|
||||
MMI_auto_test();
|
||||
else
|
||||
{
|
||||
debug_snmp_agent_test_input();
|
||||
debug_snmp_agent_test_output();
|
||||
debug_snmp_print();
|
||||
}
|
||||
}
|
||||
if(test_style == 2)
|
||||
{
|
||||
|
||||
iptrans_timer();
|
||||
snmp_timer();
|
||||
outb(0xff, 0x378);
|
||||
//timeuse = 0;
|
||||
//gettimeofday(&tv_start, NULL);
|
||||
debug_rt();
|
||||
/*
|
||||
gettimeofday(&tv_end, NULL);
|
||||
timeuse =
|
||||
1000000 * (tv_end.tv_sec - tv_start.tv_sec) -
|
||||
tv_start.tv_usec + tv_end.tv_usec;
|
||||
if(timeuse > max_time)
|
||||
max_time = timeuse;
|
||||
fprintf(fp_prt,
|
||||
" debug_rt time used: %ld (u sec)<=%ld\r\n\r\n",
|
||||
timeuse, max_time);
|
||||
*/
|
||||
outb(0x00, 0x378);
|
||||
if(connect_flag == 0)
|
||||
{
|
||||
do_negotiate(sockfd);
|
||||
MMI_telnet_recv();
|
||||
send_wont(sockfd, TELOPT_BINARY);
|
||||
MMI_telnet_recv();
|
||||
FD_ZERO(&rset);
|
||||
connect_flag = 1;
|
||||
}
|
||||
MMI_telnet_recv();
|
||||
MMI_telnet_cmd();
|
||||
}
|
||||
if(test_style == 3)
|
||||
{
|
||||
iptrans_timer();
|
||||
snmp_timer();
|
||||
|
||||
//timeuse = 0;
|
||||
// gettimeofday(&tv_start, NULL);
|
||||
//outb(0xff, 0x378);
|
||||
debug_rt();
|
||||
//outb(0x00, 0x378);
|
||||
/*
|
||||
gettimeofday(&tv_end, NULL);
|
||||
timeuse =
|
||||
1000000 * (tv_end.tv_sec - tv_start.tv_sec) -
|
||||
tv_start.tv_usec + tv_end.tv_usec;
|
||||
if(timeuse > max_time)
|
||||
max_time = timeuse;
|
||||
fprintf(fp_prt,
|
||||
"debug_rt time used: %ld (u sec)<=%ld\r\n\r\n",
|
||||
timeuse, max_time);
|
||||
*/
|
||||
|
||||
}
|
||||
if(test_style == 4)
|
||||
{
|
||||
iptrans_timer();
|
||||
snmp_timer();
|
||||
|
||||
timeuse = 0;
|
||||
gettimeofday(&tv_start, NULL);
|
||||
outb(0xff, 0x378);
|
||||
debug_rt();
|
||||
outb(0x00, 0x378);
|
||||
|
||||
gettimeofday(&tv_end, NULL);
|
||||
timeuse =
|
||||
1000000 * (tv_end.tv_sec - tv_start.tv_sec) -
|
||||
tv_start.tv_usec + tv_end.tv_usec;
|
||||
|
||||
if(timeuse > max_time)
|
||||
max_time = timeuse;
|
||||
if(timeuse>500)
|
||||
fprintf(fp_prt,
|
||||
" debug_rt time used: %ld (u sec)<=%ld\r\n\r\n",
|
||||
timeuse, max_time);
|
||||
|
||||
if(connect_flag == 0)
|
||||
{
|
||||
do_negotiate(sockfd);
|
||||
MMI_telnet_recv();
|
||||
send_wont(sockfd, TELOPT_BINARY);
|
||||
MMI_telnet_recv();
|
||||
FD_ZERO(&rset);
|
||||
connect_flag = 1;
|
||||
}
|
||||
MMI_telnet_recv();
|
||||
if(recv_over == 2)
|
||||
{
|
||||
if(!feof(fp_conf))
|
||||
{
|
||||
|
||||
fgets(data_arr, 1024, fp_conf);
|
||||
if(data_arr[strlen(data_arr) - 1] == '\n')
|
||||
data_arr[strlen(data_arr) - 1] = '\0';
|
||||
else
|
||||
{
|
||||
if(!feof(fp_conf))
|
||||
{
|
||||
printf("Debug test conf file error!:%s\n",data_arr);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
if(!strlen(data_arr) ||(strstr(data_arr,"\\")) == data_arr + 0)
|
||||
return;
|
||||
MMI_File_Test(data_arr);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(j == 1)
|
||||
test_style = 0;
|
||||
else if(j > 0)
|
||||
{
|
||||
j--;
|
||||
rewind(fp_conf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Set_Timer()
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
act.sa_handler = On_Timer;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
if(sigaction(SIGALRM, &act, NULL) < 0)
|
||||
{
|
||||
perror("Produce Sigaction");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
itimer.it_interval.tv_sec = 0;
|
||||
itimer.it_interval.tv_usec = 20 * 1000;
|
||||
itimer.it_value.tv_sec = 0;
|
||||
itimer.it_value.tv_usec = 20 * 1000;
|
||||
|
||||
if(setitimer(ITIMER_REAL, &itimer, &old_itimer) != 0)
|
||||
{
|
||||
printf("Setting Timer error! \n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void debug_snmp_agent_test_input()
|
||||
{
|
||||
debug_snmp_agent snmp_agent_packet1;
|
||||
DWORD temp_oid1[32] =
|
||||
{ 1, 3, 6, 1, 4, 1, 1373, 1, 3, 3, 2, 2, 2, 1, 2 };
|
||||
DWORD temp_oid2[32] =
|
||||
{ 1, 3, 6, 1, 4, 1, 1373, 1, 3, 3, 2, 2, 2, 1, 3 };
|
||||
WORD i,index;
|
||||
|
||||
for(i=0;i<MAX_PACKET_NUM;i++)
|
||||
{
|
||||
if(debug_snmp_agent_buf[i].cmm_state==6)
|
||||
debug_snmp_agent_buf[i].cmm_state=0;
|
||||
}
|
||||
|
||||
|
||||
for(index = 0; index < MAX_PACKET_NUM; index++)
|
||||
if(debug_snmp_agent_buf[index].cmm_state == 0)
|
||||
break;
|
||||
if(index==MAX_PACKET_NUM)
|
||||
return;
|
||||
|
||||
switch (test_snmp_mode)
|
||||
{
|
||||
case 1: // get once ,do not fill ip
|
||||
for(i = 0; i < 32; i++)
|
||||
snmp_agent_packet1.oid[i] = temp_oid1[i];
|
||||
snmp_agent_packet1.oid_len = 16;
|
||||
snmp_agent_packet1.oid[snmp_agent_packet1.oid_len - 1] = 0;
|
||||
snmp_agent_packet1.cmm_state = 1;
|
||||
break;
|
||||
case 2: // get once ,fill ip
|
||||
snmp_agent_packet1.total_ip = 1;
|
||||
strcpy(snmp_agent_packet1.dst_ip[0], "172.18.133.1");
|
||||
for(i = 0; i < 32; i++)
|
||||
snmp_agent_packet1.oid[i] = temp_oid1[i];
|
||||
snmp_agent_packet1.oid_len = 16;
|
||||
snmp_agent_packet1.oid[snmp_agent_packet1.oid_len - 1] = 1;
|
||||
snmp_agent_packet1.cmm_state = 1;
|
||||
break;
|
||||
case 3: // get all
|
||||
if(index==0)
|
||||
{
|
||||
for(i = 0; i < 32; i++)
|
||||
snmp_agent_packet1.oid[i] = temp_oid1[i];
|
||||
snmp_agent_packet1.oid_len = 16;
|
||||
snmp_agent_packet1.oid[snmp_agent_packet1.oid_len - 1] = 0;
|
||||
snmp_agent_packet1.cmm_state = 1;
|
||||
}
|
||||
break;
|
||||
case 4: // get all
|
||||
if(index==0)
|
||||
{
|
||||
for(i = 0; i < 32; i++)
|
||||
snmp_agent_packet1.oid[i] = temp_oid2[i];
|
||||
snmp_agent_packet1.oid_len = 16;
|
||||
snmp_agent_packet1.oid[snmp_agent_packet1.oid_len - 1] = 0;
|
||||
snmp_agent_packet1.cmm_state = 1;
|
||||
}
|
||||
break;
|
||||
case 5: // set once
|
||||
for(i = 0; i < 32; i++)
|
||||
snmp_agent_packet1.oid[i] = temp_oid2[i];
|
||||
snmp_agent_packet1.oid_len = 16;
|
||||
snmp_agent_packet1.oid[snmp_agent_packet1.oid_len - 1] = 255;
|
||||
snmp_agent_packet1.total_ip = 1;
|
||||
snmp_agent_packet1.total_field = 15;
|
||||
strcpy(snmp_agent_packet1.dst_ip[0], "172.18.144.1");
|
||||
strcpy(snmp_agent_packet1.param_field_arr[0].curr_input_value,
|
||||
"");
|
||||
snmp_agent_packet1.param_field_arr[0].total_select = 6;
|
||||
snmp_agent_packet1.param_field_arr[0].curr_select_id = 3;
|
||||
strcpy(snmp_agent_packet1.param_field_arr[1].curr_input_value,
|
||||
"");
|
||||
snmp_agent_packet1.param_field_arr[1].total_select = 6;
|
||||
snmp_agent_packet1.param_field_arr[1].curr_select_id = 3;
|
||||
strcpy(snmp_agent_packet1.param_field_arr[2].curr_input_value,
|
||||
"");
|
||||
snmp_agent_packet1.param_field_arr[2].total_select = 6;
|
||||
snmp_agent_packet1.param_field_arr[2].curr_select_id = 3;
|
||||
strcpy(snmp_agent_packet1.param_field_arr[9].curr_input_value,
|
||||
"");
|
||||
snmp_agent_packet1.param_field_arr[9].total_select = 2;
|
||||
snmp_agent_packet1.param_field_arr[9].curr_select_id = 1;
|
||||
snmp_agent_packet1.cmm_state = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(index != MAX_PACKET_NUM)
|
||||
{
|
||||
memcpy(&debug_snmp_agent_buf[index], &snmp_agent_packet1,
|
||||
sizeof(debug_snmp_agent));
|
||||
test_snmp_mode++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void debug_snmp_agent_test_output()
|
||||
{
|
||||
WORD i;
|
||||
for(i=0;i<MAX_PACKET_NUM;i++)
|
||||
{
|
||||
if(debug_snmp_agent_buf[i].cmm_state>3)
|
||||
debug_snmp_agent_buf[i].cmm_state=6;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void debug_snmp_print()
|
||||
{
|
||||
char cmm_state_flag[128], result_state_flag[128], temp_str[32];
|
||||
WORD i, j;
|
||||
|
||||
|
||||
strcpy(file_name, "");
|
||||
strcat(file_name, "debug_agent.txt");
|
||||
|
||||
if((fp_agent = fopen(file_name, "a+")) == NULL)
|
||||
{
|
||||
printf("[debug] Error: cannot open %s.\r\n", file_name);
|
||||
return ;
|
||||
}
|
||||
|
||||
strcpy(cmm_state_flag, "cmm_state: ");
|
||||
strcpy(result_state_flag, "result : ");
|
||||
fprintf(fp_agent,"\r\nDebug snmp senior interface buffer: \r\n");
|
||||
fprintf(fp_agent,"index : ");
|
||||
for(i = 0; i < 16; i++)
|
||||
fprintf(fp_agent,"%3d ", i);
|
||||
fprintf(fp_agent,"\r\n");
|
||||
for(i = 0; i < MAX_PACKET_NUM; i++)
|
||||
if(debug_snmp_agent_buf[i].cmm_state != 0)
|
||||
break;
|
||||
//if(i == MAX_PACKET_NUM)
|
||||
// return;
|
||||
|
||||
for(i = 0; i < MAX_PACKET_NUM; i++)
|
||||
{
|
||||
sprintf(temp_str, "%3d ", debug_snmp_agent_buf[i].cmm_state);
|
||||
strcat(cmm_state_flag, temp_str);
|
||||
}
|
||||
if(strcmp(oid_cmm_state, cmm_state_flag) != 0)
|
||||
{
|
||||
|
||||
strcpy(oid_cmm_state, cmm_state_flag);
|
||||
fprintf(fp_agent,cmm_state_flag);
|
||||
fprintf(fp_agent,"\r\n");
|
||||
for(i = 0; i < MAX_PACKET_NUM; i++)
|
||||
{
|
||||
sprintf(temp_str, "%3d ",debug_snmp_agent_buf[i].result_state);
|
||||
strcat(result_state_flag, temp_str);
|
||||
}
|
||||
fprintf(fp_agent,result_state_flag);
|
||||
|
||||
fprintf(fp_agent,"\r\n id OID OID_len Total field Total instance \r\n");
|
||||
for(i = 0; i < MAX_PACKET_NUM; i++)
|
||||
{
|
||||
strcpy(cmm_state_flag, "");
|
||||
sprintf(temp_str, "[%2d]: ", i);
|
||||
strcat(cmm_state_flag, temp_str);
|
||||
for(j = 0; j < 32 && debug_snmp_agent_buf[i].oid[j] != 0;
|
||||
j++)
|
||||
{
|
||||
sprintf(temp_str, "%ld.",
|
||||
debug_snmp_agent_buf[i].oid[j]);
|
||||
strcat(cmm_state_flag, temp_str);
|
||||
}
|
||||
if(j < debug_snmp_agent_buf[i].oid_len - 1)
|
||||
{
|
||||
fprintf(fp_agent,"%ld.", debug_snmp_agent_buf[i].oid[j]);
|
||||
}
|
||||
sprintf(temp_str, " %d ",
|
||||
debug_snmp_agent_buf[i].oid_len);
|
||||
strcat(cmm_state_flag, temp_str);
|
||||
fprintf(fp_agent,cmm_state_flag);
|
||||
fprintf(fp_agent," %3d ",
|
||||
debug_snmp_agent_buf[i].total_field);
|
||||
fprintf(fp_agent," %3d \r\n",
|
||||
debug_snmp_agent_buf[i].total_instance);
|
||||
}
|
||||
fprintf(fp_agent,"\r\n");
|
||||
}
|
||||
fclose(fp_agent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
#define numFuncs 2
|
||||
|
||||
|
||||
typedef void ( *ptFuncDef )();
|
||||
ptFuncDef ptFuncArr[] = { &debug_mmi_list, &debug_snmp_get_rt,&debug_snmp_set_rt,&debug_ };
|
||||
|
||||
for ( i = 0; i < numFuncs; i++ )
|
||||
{
|
||||
gettimeofday( &start, NULL );
|
||||
ptFuncArr[i]();
|
||||
gettimeofday( &end, NULL );
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user