Exemplo n.º 1
0
int handle_trans_message(void *args)
{
	struct packet *pkt = (struct packet*)args;
	DEBUG(INFO, "%s %d %d %u handle",pkt->ip, pkt->sockfd, pkt->ops_type, pkt->len);
	pkt->data += sizeof(struct common_header);
	pkt->len -= sizeof(struct common_header);
	char *buff = pkt->data;
	int len = pkt->len;
	int type = pkt->ops_type;

	if( buff == NULL || len == 0)
	{
		DEBUG( ERROR, "Trans message Empty");
		return ENORMERR;
	}
	char	*pms_addr;
	int	    pms_port = 0;
	int	    iret = 0;
	pms_addr = get_server_address();
	pms_port = get_server_port();
	if( pms_addr == NULL )
	{
		DEBUG( ERROR, "\n[%s][%d]pms_addr error\n", __FILE__, __LINE__ );
		return ENORMERR;
	}
	DEBUG( INFO, "\n[%s][%d]pms_addr=[%s] pms_port=[%d]\n", __FILE__, __LINE__, pms_addr, pms_port );

	iret = send_message_to_pms( pms_addr, pms_port, type, buff, len );
	if( iret != SUCCESS )
	{
		DEBUG( ERROR, "\n[%s][%d]send message to pms error\n", __FILE__, __LINE__ );
	}
	return SUCCESS;
}
Exemplo n.º 2
0
//LSDB_INFO
int handle_lsdb_snapshoot_dbm_to_pms(void *args)
{
	struct pkt * info = (struct pkt*)args;
	local_module_header *pkt = (local_module_header*)(info->data);
	char *buff = (char*)pkt->pkt;
	int len = pkt->pkt_len - sizeof(local_module_header);
	send_message_to_pms(get_server_address(), get_server_port(), OPS_PMA_LINKSTATE, buff, len); 
}
Exemplo n.º 3
0
int handle_bgp_path_info_ic_to_pms(void *args)
{
	struct pkt* info = (struct pkt*)args;
	local_module_header* pkt = (local_module_header*)(info->data);
	char* buff = (char*)pkt->pkt;
	int len = pkt->pkt_len - sizeof(local_module_header);
	return send_message_to_pms(get_server_address(), get_server_port(),
			OPS_PMA_ROUTING_TABLE, buff, len);
}
Exemplo n.º 4
0
int handle_bgp_interface_ic_to_pms(void *args)
{
	struct pkt* info = (struct pkt*)args;
	local_module_header *pkt = (local_module_header*)(info->data);
	char* buff = (char*)pkt->pkt;
	int len = pkt->pkt_len - sizeof(local_module_header);
	return send_message_to_pms(get_server_address(), get_server_port(),
			OPS_PMA_BGP_INTERFACE_INFO, buff, len);
}
Exemplo n.º 5
0
int handle_trans_packet_to_pms(void *args)
{
	struct packet *pkt = (struct packet*)args;
	DEBUG(INFO, "%s %d %d %u handle",pkt->ip, pkt->sockfd, pkt->ops_type, pkt->len);
	memcpy(pkt->ip , get_server_address(), sizeof(pkt->ip)-1);
	pkt->port = get_server_port();
	int ret = send_message_to_pms( pkt->ip , pkt->port , pkt->ops_type, pkt->data, pkt->len);
	return ret;
}
Exemplo n.º 6
0
Arquivo: reg.c Projeto: exeasy/pma2
int heart_beat_send()
{
	DEBUG(INFO,"Heart Beat Sended");
	int ret = send_message_to_pms( get_server_address(),  
			get_server_port(), OPS_PMA_HEARTBEAT,
			NULL, 0);
	pthread_detach(pthread_self());
	return ret;
}
Exemplo n.º 7
0
//UP_INTERFACE_INFO
int handle_tc_message_to_pms(void *args)
{
	struct pkt* info = (struct pkt*)args;
	local_module_header *pkt = (local_module_header*)(info->data);
	char *buff = (char*)pkt->pkt;
	int info_type = pkt->pkt_type;
	int len = pkt->pkt_len - sizeof(local_module_header);
	return send_message_to_pms(get_server_address(), get_server_port(), 
			TC_TO_PMA_INTERFACE_INFO, buff, len);
}
Exemplo n.º 8
0
Arquivo: reg.c Projeto: 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;
}
Exemplo n.º 9
0
void send_udp_packet(
    char *ip,
    int port,
    char message[MAX_PAYLOAD_LENGTH],
    int message_length,
    int socket
) {
    struct sockaddr_in destination_server = get_server_address(ip, port);

    sendto(socket, message, message_length, 0, (struct sockaddr*)&destination_server, sizeof(destination_server));
}
Exemplo n.º 10
0
int create_socket(char *ip, unsigned int port) {
    int socket_ = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    struct sockaddr_in udp_load_balancer_address = get_server_address(ip, port);

    bind(
        socket_,
        (struct sockaddr*)&udp_load_balancer_address,
        sizeof(udp_load_balancer_address)
    );

    return socket_;
}
Exemplo n.º 11
0
/**************************************************************************
  Connect to a freeciv-server instance -- or at least try to.  On success,
  return 0; on failure, put an error message in ERRBUF and return -1.
**************************************************************************/
int connect_to_server(const char *username, const char *hostname, int port,
		      char *errbuf, int errbufsize)
{
  if (0 != get_server_address(hostname, port, errbuf, errbufsize)) {
    return -1;
  }

  if (0 != try_to_connect(username, errbuf, errbufsize)) {
    return -1;
  }

  return 0;
}
Exemplo n.º 12
0
//UP_ROUTE_INFO
int handle_route_table_ic_to_pms(void *args)
{
	struct pkt* info = (struct pkt*)args;
	local_module_header *pkt = (local_module_header*)(info->data);
	int pkt_len = pkt->pkt_len - sizeof(local_module_header);
	char * data = (char*)malloc(pkt_len+1);
	memcpy(data, pkt->pkt, pkt_len);
	data[pkt_len] = 0;
	char *buff = save_router_table_to_xml(data);
	int len = strlen(buff);
	free(data);
	int ret =  send_message_to_pms(get_server_address(), get_server_port(),
		OPS_PMA_ROUTING_TABLE, buff, len);
	free( buff );
	return ret;
	
}
Exemplo n.º 13
0
/**************************************************************************
  Start trying to autoconnect to civserver.  Calls
  get_server_address(), then arranges for try_to_autoconnect(), which
  calls try_to_connect(), to be called roughly every
  AUTOCONNECT_INTERVAL milliseconds, until success, fatal error or
  user intervention.
**************************************************************************/
void start_autoconnecting_to_server(void)
{
  char buf[512];

  output_window_printf(FTC_CLIENT_INFO, NULL,
                       _("Auto-connecting to server \"%s\" at port %d "
                         "as \"%s\" every %f second(s) for %d times"),
                       server_host, server_port, user_name,
                       0.001 * AUTOCONNECT_INTERVAL,
                       MAX_AUTOCONNECT_ATTEMPTS);

  if (get_server_address(server_host, server_port, buf, sizeof(buf)) < 0) {
    freelog(LOG_FATAL,
            _("Error contacting server \"%s\" at port %d "
              "as \"%s\":\n %s\n"),
            server_host, server_port, user_name, buf);
    exit(EXIT_FAILURE);
  }
  autoconnecting = TRUE;
}
Exemplo n.º 14
0
Arquivo: reg.c Projeto: 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;
	 
}
Exemplo n.º 15
0
apr_status_t test_server_create(test_baton_t **tb_p,
                                test_server_action_t *action_list,
                                apr_size_t action_count,
                                apr_int32_t options,
                                const char *host_url,
                                apr_sockaddr_t *address,
                                serf_connection_setup_t conn_setup,
                                apr_pool_t *pool)
{
    apr_status_t status;
    test_baton_t *tb;

    tb = apr_palloc(pool, sizeof(*tb));
    *tb_p = tb;

    if (address) {
        tb->serv_addr = address;
    }
    else {
        status = get_server_address(&tb->serv_addr, pool);
        if (status != APR_SUCCESS)
          return status;
    }

    tb->pool = pool;
    tb->options = options;
    tb->context = serf_context_create(pool);
    tb->bkt_alloc = serf_bucket_allocator_create(pool, NULL, NULL);
    if (host_url) {
        apr_uri_t url;
        status = apr_uri_parse(pool, host_url, &url);
        if (status != APR_SUCCESS)
            return status;

        status = serf_connection_create2(&tb->connection, tb->context,
                                         url,
                                         conn_setup ? conn_setup :
                                             default_conn_setup,
                                         tb,
                                         default_closed_connection,
                                         tb,
                                         pool);
        if (status != APR_SUCCESS)
          return status;
    } else {
        tb->connection = serf_connection_create(tb->context,
                                                tb->serv_addr,
                                                conn_setup ? conn_setup :
                                                    default_conn_setup,
                                                tb,
                                                default_closed_connection,
                                                tb,
                                                pool);
    }
    tb->action_list = action_list;
    tb->action_count = action_count;

    /* Prepare a server. */
    status = prepare_server(tb, pool);
    if (status != APR_SUCCESS)
      return status;

    return APR_SUCCESS;
}