コード例 #1
0
ファイル: mul_thread_core.c プロジェクト: bollaramya/mul-cc
int
mul_cc_recv_pkt(uint64_t dp_id, uint8_t aux_id, void *of_msg, uint32_t msg_len)
{
    
    struct cbuf *b = NULL;
    
    if(cbuf_list_queue_len(&ctrl_hdl.c_main_buf_head) > 1024) 
    {
	// Throw an error
	c_log_err("Main thread buffer queue is full\n");
    }
    else
    {
	// Allocate
	b = alloc_cbuf(msg_len);
	if(b == NULL)
	{
	    // Kajal: What else to log for a new connection
	    // chann_id.aux_id -- is of type uint64_t 
	    // c_log_err("Buffer node could not be allocated dp-id:0x%x aux-id:0x%x\n",
	    //          chann_id.dp_id, chann_id.aux_id);
	    //return 0;
	}

	// if_msg should be freed by library assuming that 
	// buffer should copy it.
	memcpy(b->data, of_msg, msg_len);
	// Insert buffer in queue	
	cbuf_list_queue_tail(&ctrl_hdl.c_main_buf_head, b);
    }

    return 0;
}
コード例 #2
0
ファイル: mul_service.c プロジェクト: ashang/openmul
void
c_service_send(mul_service_t *service, struct cbuf *b)
{
    if (service->is_client) {
        c_service_clr_rcv_buf(service);
        c_socket_write_block_loop(&service->conn, b);
        if (service->conn.dead && !service->reconn_timer_event)
            c_service_reconnect(service);
    } else {

        c_wr_lock(&service->conn.conn_lock);

        if (cbuf_list_queue_len(&service->conn.tx_q) > 1024) {
            c_wr_unlock(&service->conn.conn_lock);
            free_cbuf(b);
            return;
        }

        cbuf_list_queue_tail(&service->conn.tx_q, b);

        c_socket_write_nonblock_loop(&service->conn, 
                                     c_service_write_event_sched);

        c_wr_unlock(&service->conn.conn_lock);
    }
}
コード例 #3
0
ファイル: makdi_servlet.c プロジェクト: ashang/openmul
/*
 *
 * mul_makdi_show_nfv_stats_all - return the every nfv ingress/egress port statistics
 *
 */
void
mul_makdi_show_nfv_stats_all(void *service,  void *arg, bool nbapi, 
                             void (*cb_fn)(void *arg, void *pbuf))
{
    struct cbuf *b;
    struct c_ofp_auxapp_cmd *cofp_auc;
    struct c_ofp_switch_port_query *cofp_pq;
    int n_nfvs = 0;
    struct cbuf_head bufs;
    int retries = 0;
    char *pbuf;

    if (!service)
        return;
    
    cbuf_list_head_init(&bufs);


try_again:
    b = of_prep_msg(sizeof(struct c_ofp_auxapp_cmd), C_OFPT_AUX_CMD, 0);

    cofp_auc = (void *) (b->data);
    cofp_auc->cmd_code = htonl(C_AUX_CMD_MAKDI_NFV_STATS_ALL);

    c_service_send(service, b);
    while (1) {
        b = c_service_wait_response(service);
        if (b) {
            if (check_reply_type(b, C_AUX_CMD_SUCCESS) ||
                !check_reply_type(b, C_AUX_CMD_MUL_SWITCH_PORT_QUERY)) {
                free_cbuf(b);
                break;
            }
            cofp_auc = (void *) (b->data);
            cofp_pq = (void *) (cofp_auc->data);
            if (ntohs(cofp_auc->header.length) <
                    sizeof(*cofp_pq) + sizeof(*cofp_auc)) {
                free_cbuf(b);
                goto try_restart;
            }
            b = cbuf_realloc_headroom(b, 0, true);
            cbuf_list_queue_tail(&bufs, b);
            n_nfvs++;
        } else {
            goto try_restart;
        }
    }
    
    while ((b = cbuf_list_dequeue(&bufs))) {
        cofp_auc = (void *) (b->data);
        cofp_pq = (void *) (cofp_auc->data);
        if (nbapi) {
            cb_fn(arg, cofp_pq);
        } else {
            pbuf = makdi_dump_port_stats(cofp_auc, cofp_pq);
            if (pbuf) {
                cb_fn(arg, pbuf);
                free(pbuf);
            }
            free_cbuf(b);
        }
    }
    return;

try_restart:
    cbuf_list_purge(&bufs);
    if (retries++ >= C_SERV_RETRY_CNT) {
        cbuf_list_purge(&bufs);
        c_log_err("%s: Restarting serv msg", FN);
        goto try_again;
    }
    c_log_err("%s: Can't restart serv msg", FN);
    return;
}
コード例 #4
0
ファイル: makdi_servlet.c プロジェクト: ashang/openmul
/**
 * mul_makdi_show_nfv -
 */
int mul_makdi_show_servicechain_default(void *service, void *arg, bool nbapi,
        void (*cb_fn)(void *arg, void *pbuf)) {
    struct cbuf *b;
    struct c_ofp_auxapp_cmd *cofp_auc;
    struct c_ofp_default_rule_info *cofp_servicechain_default;
    char *pbuf;
    int n_services = 0;
    struct cbuf_head bufs;
    int retries = 0;

    if (!service)
        return -1;
    
    cbuf_list_head_init(&bufs);

try_again:
    b = of_prep_msg(sizeof(struct c_ofp_auxapp_cmd), C_OFPT_AUX_CMD, 0);

    cofp_auc = (void *) (b->data);
    cofp_auc->cmd_code = htonl(C_AUX_CMD_MAKDI_SHOW_DEFAULT_SERVICE);

    c_service_send(service, b);
    while (1) {
        b = c_service_wait_response(service);
        if (b) {
            if (check_reply_type(b, C_AUX_CMD_SUCCESS)
                    || !check_reply_type(b, C_AUX_CMD_MAKDI_SHOW_DEFAULT_SERVICE)) {
                free_cbuf(b);
                break;
            }
            cofp_auc = (void *) (b->data);
            cofp_servicechain_default = (void *) (cofp_auc->data);
            /*  FIXME : Length missmtach, header.length == 2050
                
            if (ntohs(cofp_nfv_group->header.length) < sizeof(*cofp_nfv_group))
            {   
                free_cbuf(b);
                goto try_restart;
            }
            */
            b = cbuf_realloc_headroom(b, 0, true);
            cbuf_list_queue_tail(&bufs, b);
            n_services++;
        } else {
            goto try_restart;
        }
    }

    while ((b = cbuf_list_dequeue(&bufs))) {
        cofp_auc = (void *) (b->data);
        cofp_servicechain_default = (void *)(cofp_auc->data);
        if (nbapi) {
            cb_fn(arg, cofp_servicechain_default);
        } else {
            pbuf = makdi_dump_servicechain_default(
                        cofp_servicechain_default);
            if (pbuf) {
                cb_fn(arg, pbuf);
                free(pbuf);
            }
            free_cbuf(b);
        }
    }
    return n_services;

try_restart:
    cbuf_list_purge(&bufs);
    if (retries++ >= C_SERV_RETRY_CNT) {
        cbuf_list_purge(&bufs);
        c_log_err("%s: Restarting serv msg", FN);
        goto try_again;
    }
    c_log_err("%s: Can't restart serv msg", FN);
    return 0;
}
コード例 #5
0
ファイル: makdi_servlet.c プロジェクト: ashang/openmul
/**
 * mul_makdi_show_nfv -
 */
int mul_makdi_show_nfv(void *service, void *arg, bool dump_cmd,
                       void (*cb_fn)(void *arg, void *pbuf))
{
    struct cbuf *b;
    struct c_ofp_auxapp_cmd *cofp_auc;
    struct c_ofp_s_chain_nfv_group_info *cofp_nfv_group;
    char *pbuf;
    int n_groups = 0;
    struct cbuf_head bufs;
    int retries = 0;

    if (!service)
        return -1;

    cbuf_list_head_init(&bufs);

try_again:
    b = of_prep_msg(sizeof(struct c_ofp_auxapp_cmd), C_OFPT_AUX_CMD, 0);

    cofp_auc = (void *) (b->data);
    cofp_auc->cmd_code = htonl(C_AUX_CMD_MAKDI_SHOW_NFV);

    c_service_send(service, b);
    while (1) {
        b = c_service_wait_response(service);
        if (b) {
            if (check_reply_type(b, C_AUX_CMD_SUCCESS) ||
                !check_reply_type(b, C_AUX_CMD_MAKDI_SHOW_NFV_GROUP)) {
                free_cbuf(b);
                break;
            }
            cofp_auc = (void *) (b->data);
            cofp_nfv_group = (void *) (cofp_auc->data);
            if (ntohs(cofp_auc->header.length)
                   < sizeof(*cofp_nfv_group) + sizeof(*cofp_auc)) {
                free_cbuf(b);
                goto try_restart;
            }
            b = cbuf_realloc_headroom(b, 0, true);
            cbuf_list_queue_tail(&bufs, b);
            n_groups++;
        } else {
            goto try_restart;
            break;
        }
    }
    
    while ((b = cbuf_list_dequeue(&bufs))) {
        cofp_auc = (void *) (b->data);
        cofp_nfv_group = (void *)(cofp_auc->data);
        if (dump_cmd) {
            makdi_dump_nfv_groups_cmd(cofp_nfv_group, arg, cb_fn);
        } else {
            pbuf = makdi_dump_nfv_groups(cofp_nfv_group);
            if (pbuf) {
                cb_fn(arg, pbuf);
                free(pbuf);
            }
        }
        free_cbuf(b);
    }
    return n_groups;

try_restart:
    cbuf_list_purge(&bufs);
    if (retries++ < C_SERV_RETRY_CNT) {
        cbuf_list_purge(&bufs);
        c_log_err("%s: Restarting serv msg", FN);
        goto try_again;
    }
    c_log_err("%s: Can't restart serv msg", FN);
    return 0;
}