Пример #1
0
Файл: reg.c Проект: exeasy/pma2
int agent_register(u32 agent_id, const char *seq)
{

	//pack the login xml
	xmlDocPtr doc = create_xml_doc();
	xmlNodePtr devnode;
	xmlNodePtr childnode;

	xmlNodePtr rootnode = create_xml_root_node(doc,"AGENT_REGISTER");
	struct timeval now;
	gettimeofday(&now, NULL);
	char * time = PRINTTIME(now);
	add_xml_child(rootnode, "timestamp",time); free(time);

	devnode = add_xml_child(rootnode, "device", NULL);
	char aid[24];
	sprintf(aid,"%d", get_pma_id());
	add_xml_child_prop(devnode, "id",aid); 
	char dev_type[10];
	if( get_protocol_type() == OSPF_ROUTER )
		sprintf(dev_type, "ospf");
	else if( get_protocol_type() == BGP_ROUTER )
		sprintf(dev_type, "bgp");
	else {}
	add_xml_child(devnode, "type", dev_type);
	
	char* xmlbuff;
	int len = 0;
	xmlDocDumpFormatMemoryEnc( doc, &xmlbuff, &len, "UTF-8", 0);
	char* buff = (char*)malloc(len+1);
	memcpy(buff, xmlbuff, len);
	buff[len] = 0;
	xmlFree(xmlbuff);
	xmlFreeDoc(doc);

	struct req_args *login_args =
		(struct req_args *)malloc(sizeof(struct req_args)+len);

	memset(login_args->ip, 0, sizeof(login_args->ip));
	char *ip = get_server_address();
	memcpy(login_args->ip, ip, strlen(ip));
	login_args->port = get_server_port();
	login_args->ops_type = OPS_PMA_LOGIN;
	login_args->len = len;
	memcpy(login_args->data, buff, len);
	free(buff);
	if (login(login_args) == ((void *)-1)) {
		free(login_args);
		return -1;
	}
	free(login_args);
	agent_login_status = AGENT_LOGIN;
	return SUCCESS;
}
Пример #2
0
void
testmem(size_t size)
{
	int i;
	void (*rout)();
	size_t sz;

again:
	if (domode == NEXTPAT) {
		TIMEVAL st, et;

		sz = size >> 2;
		printf("%d longwords, 4 pattern tests ", sz);
		GETTIME(st);
		i = testpatterns(sz);
		GETTIME(et);
		if (i == 0)
			printf("[ OK ]");
		else
			printf("[ FAILED ]");
		PRINTTIME(st, et, size);
	} else {
Пример #3
0
char* save_router_table_to_xml(char* rtable)
{
	xmlDocPtr doc = create_xml_doc();
	if (rtable == NULL)
		return NULL;
	xmlNodePtr routernode;
	xmlNodePtr childnode;

	xmlNodePtr rootnode = create_xml_root_node(doc, "SNAPSHOT");
	
	routernode = add_xml_child(rootnode, "ROUTER", NULL);
	char* rid[24];
	sprintf(rid,"%d", get_pma_id());
	add_xml_child_prop(routernode, "id",rid); 
	
	struct timeval now;
	gettimeofday(&now, NULL);
	char * time = PRINTTIME(now);
	add_xml_child(routernode, "timestamp",time); free(time);
	
	add_xml_child(routernode, "LSDB", NULL);

	childnode = add_xml_child(routernode, "Routing_table", NULL);
	
	add_xml_child(childnode,"IPV4",rtable);

	u8 *xmlbuff;
	int len  = 0;
	xmlDocDumpFormatMemoryEnc( doc, &xmlbuff, &len, "UTF-8", 0 );
	char *buff = (char*)malloc(len+1);
	memcpy(buff, xmlbuff, len);
	buff[len]= 0;
	xmlFree(xmlbuff);
	xmlFreeDoc(doc);
	return buff;

}
Пример #4
0
char* flow_info_to_xml(NetFlow *flow, int rate)
{
	
	int in_flow = 0, out_flow = 0;
	if ( flow->in_ifdex == 0 ) 
		out_flow = 1;
	if ( flow->out_ifdex == 0)
		in_flow = 1;
	xmlDocPtr doc = create_xml_doc();
	xmlNodePtr devnode;
	xmlNodePtr ifnode;
	xmlNodePtr flownode;
	xmlNodePtr childnode;

	char value[100];
	memset(value, 0x00, 100);
	
	xmlNodePtr rootnode = create_xml_root_node(doc, "TC_FLOW_INFO");
	struct timeval now;
	gettimeofday(&now, NULL);
	char * time = PRINTTIME(now);
	add_xml_child(rootnode, "timestamp",time); free(time);

	devnode = add_xml_child(rootnode, "ROUTER", NULL);
	char aid[24];
	int agentid = 0;
//	inet_pton(AF_INET, routerid, &agentid); 
	agentid = ntohl(agentid);

	sprintf(aid,"%d", device_id);
	add_xml_child_prop(devnode, "id",aid); 

	// Add the Element
	int ifid = 0;
	if ( in_flow )
	{
		ifid = flow->in_ifdex;
	}
	if ( out_flow )
	{
		ifid = flow->out_ifdex;
	}

	ifnode = add_xml_child(devnode, "interface", NULL);

	memset(value, 0x00, 100);
	sprintf(value,"%d",ifid);
	add_xml_child_prop(ifnode, "id", value);

	memset(value, 0x00, 100);
	sprintf(value,"GigabitEthernet0/0/%d", ifid-3);
	add_xml_child(ifnode, "interface_name", value);
	flownode  = add_xml_child(ifnode, "flow_info", NULL);
	childnode = add_xml_child(flownode, "flow",NULL);

	memset(value, 0x00, 100);
	sprintf(value, "%d",4);
	add_xml_child(childnode, "flow_type", value);

	add_xml_child(childnode, "protocol", NULL);

	memset(value, 0x00, 100);
	sprintf(value, "%d", flow->tos);
	add_xml_child(childnode, "dscp", value);

	memset(value, 0x00, 100);
	inet_ntop(AF_INET, &flow->sip, value, 24);
	add_xml_child(childnode,"src", value);

	memset(value, 0x00, 100);
	inet_ntop(AF_INET, &flow->dip, value, 24);
	add_xml_child(childnode,"dst", value);

	memset(value, 0x00, 100);
	sprintf(value,"%d", flow->sport);
	add_xml_child(childnode,"src_port", value);

	memset(value, 0x00, 100);
	sprintf(value,"%d", flow->dport);
	add_xml_child(childnode,"dst_port", value);

	if( in_flow )
	{
		memset(value, 0x00, 100);
		sprintf(value, "%d", ifid);
		add_xml_child(childnode,"input_if", value);
		add_xml_child(childnode, "output_if", "0");

		memset(value, 0x00,100);
		sprintf(value,"%d",rate);
		add_xml_child(childnode, "in_send_rate", value);
		add_xml_child(childnode, "out_send_rate", NULL);
	}
	if (out_flow )
	{
		memset(value, 0x00, 100);
		sprintf(value, "%d", ifid);
		add_xml_child(childnode,"input_if", "0");
		add_xml_child(childnode, "output_if", value);

		memset(value, 0x00,100);
		sprintf(value,"%d",rate);
		add_xml_child(childnode, "in_send_rate", NULL);
		add_xml_child(childnode, "out_send_rate", value);
	}

	u8 *xmlbuff;
	int len  = 0;
	xmlDocDumpFormatMemoryEnc( doc, &xmlbuff, &len, "UTF-8", 0 );
	char *buff = (char*)malloc(len+1);
	memcpy(buff, xmlbuff, len);
	buff[len]= 0;
	xmlFree(xmlbuff);
	xmlFreeDoc(doc);
	return buff;
}
Пример #5
0
Файл: reg.c Проект: exeasy/pma2
int agent_init_request(char* routerid)
{
	//pack the login xml
	xmlDocPtr doc = create_xml_doc();
	xmlNodePtr devnode;
	xmlNodePtr childnode;

	xmlNodePtr rootnode = create_xml_root_node(doc,"AGENT_INIT");
	struct timeval now;
	gettimeofday(&now, NULL);
	char * time = PRINTTIME(now);
	add_xml_child(rootnode, "timestamp",time); free(time);

	devnode = add_xml_child(rootnode, "device", NULL);
	char aid[24];
	sprintf(aid,"%d", get_pma_id());
	add_xml_child_prop(devnode, "id",aid); 
	char dev_type[10];
	if( get_protocol_type() == OSPF_ROUTER )
	{
		sprintf(dev_type, "ospf");
		add_xml_child(devnode, "type", dev_type);
	}
	else if( get_protocol_type() == BGP_ROUTER )
	{
		sprintf(dev_type, "bgp");
		add_xml_child(devnode, "type", dev_type);
	}
	else {}

	char asid[24];
	inet_ntop(AF_INET, &pma_conf.as_num , asid, 24);
	add_xml_child(devnode, "as_id", asid);
	add_xml_child(devnode, "router_id", routerid);
	char ctlip[24];
	inet_ntop(AF_INET, &pma_conf.ic_config.hello_ip, ctlip,24);
	add_xml_child(devnode, "agent_control_ip", ctlip);
	
	char* xmlbuff;
	int len = 0;
	xmlDocDumpFormatMemoryEnc( doc, &xmlbuff, &len, "UTF-8", 0);
	char* buff = (char*)malloc(len+1);
	memcpy(buff, xmlbuff, len);
	buff[len] = 0;
	xmlFree(xmlbuff);
	xmlFreeDoc(doc);

	len = strlen(buff);
	char rid[24];
	strcpy(rid,routerid);
	struct req_args *req_arg =
		(struct req_args *)malloc(sizeof(struct req_args));

	memset(req_arg->ip, 0, sizeof(req_arg->ip));
	char *ip = get_server_address();
	memcpy(req_arg->ip, ip, strlen(ip));
	req_arg->port = get_server_port();
	req_arg->ops_type = OPS_PMA_INIT_REQUEST;
	req_arg->len = 0;
	int ret = send_message_to_pms(req_arg->ip,
			req_arg->port,
			req_arg->ops_type,
			buff,
			len);
	free(req_arg);
	free(buff);
	return ret;
	 
}