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; }
// Note: // As main thread will be responsible for the handling // Tying up the main thread to the worker context in the main thread // is the key. The logic for the controller operates on ? // So, once the information has been put into the ?? , then the logic // can get the information from the c_switch_t->cmn_ctx where the // hashtable stores the DPID and switch information static int c_thread_event_loop_lib_support(struct c_main_ctx *main_ctx) { c_switch_t *sw = NULL; struct cbuf *b = NULL; c_log_debug("%s: tid(%u)", __FUNCTION__, (unsigned int)pthread_self()); // instead of looping on the socket fd, the main thread // will be looping on the cbuf. // Not considering the application threads for now //return event_base_dispatch(cmn_ctx->base); // check cbuf // get first message from buffer and begin the processing. if(cbuf_list_queue_len(&ctrl_hdl.c_main_buf_head)) { // Get the first message b = cbuf_list_dequeue(&ctrl_hdl.c_main_buf_head); } if (!of_hdr_valid(b->data)) { c_log_err("%s: Corrupted header", FN); return 0; /* Close the socket */ } // No need to allocate the worker thread // Pass the main_ctx now. Previously, this was: // sw = of_switch_alloc(c_wrk_ctx); sw = of_switch_alloc(main_ctx); of_switch_recv_msg(sw, b); return 0; }
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); } }