void mem_event_handler_rc(mem_state * s, tw_bf * bf, mem_message * m, tw_lp * lp) { tw_memory *b; int i; s->stats.s_rb++; s->stats.s_recv--; tw_rand_reverse_unif(lp->rng); tw_rand_reverse_unif(lp->rng); if(bf->c1 == 1) tw_rand_reverse_unif(lp->rng); // undo the membuf frees and reattach them to the RB event for(i = 0; i < nbufs; i++) { b = tw_memory_free_rc(lp, my_fd); s->stats.s_mem_free_rc++; tw_event_memory_get_rc(lp, b, my_fd); s->stats.s_mem_get_rc++; /* * unnecessary to undo the allocs .. * they will be reclaimed when the events are reclaimed. */ } // sanity check if(i != nbufs) tw_error(TW_LOC, "Did not free_rc %d (%d) memory buffers!", nbufs, i); }
tw_event * tcp_rc_timer_cancel(tcp_message * old, tw_lp * lp) { tw_event * timer = NULL; //if(!old->RC.timer_ts) tw_error(TW_LOC, "No prev timer ts!"); if(!timer) tw_error(TW_LOC, "Why cannot I create this timer now?"); //timer = rn_timer_init(lp, old->RC.timer_ts); timer->memory = tw_memory_free_rc(lp, g_tcp_fd); // more debug if(timer->memory) { tcp_message *m = tw_memory_data(timer->memory); if(m->src != old->src) tw_error(TW_LOC, "bad membuf!"); } else tw_error(TW_LOC, "Could not unfree membuf!"); return timer; }
void rm_rc_particle_handler(rm_state * state, tw_bf * bf, rm_message * m, tw_lp * lp) { //tw_memory *b; //tw_memory *b_in; //state->prev_time = tw_now(lp); #if DWB if(bf->c0 == 1) { state->initial = tw_memory_free_rc(lp, g_rm_fd); tw_event_memory_get_rc(lp, tw_memory_free_rc(lp, g_rm_fd), g_rm_fd); } else { tw_event_memory_get_rc(lp, state->initial, g_rm_fd); state->initial = NULL; if(bf->c1 == 1) state->initial = tw_memory_free_rc(lp, g_rm_fd); } #endif #if 0 // remove this particle to the queue b_in = tw_memoryq_pop(state->particles); // place particle back onto event //tw_event_memory_get_rc(lp, b_in, g_rm_fd); // if in next timestep, dump the particle queue and add this particle if(bf->c0 == 1) { state->prev_time = tw_now(lp); // unfree particles and place back into queue while((NULL != (b = tw_memory_free_rc(lp, g_rm_fd)))) tw_memoryq_push(state->particles, b); } #endif }
void r_deal_with_timed_out_bgp_routers(bgp_state * state, tw_bf * bf, bgp_message * msg, tw_lp * lp) { tw_stime now; tw_memory *b; bgp_route *r; bgp_nbr *n; int i; while (msg->rc_asp) { b = tw_memory_free_rc(lp, g_bgp_fd_rtes); r = tw_memory_data(b); i = r->as_path.size; bzero(&r->as_path, sizeof(r->as_path)); while(i) { tw_memoryq_push(&r->as_path, tw_memory_free_rc(lp, g_bgp_fd_asp)); i--; } msg->rc_asp--; tw_memoryq_push(&state->routes, b); } now = tw_now(lp); for(i = 0; i < state->n_interfaces; i++) { n = &state->nbr[i]; if ((now - n->last_update) > state->hold_interval && (now - n->last_update) < (2 * state->hold_interval)) n->up = TW_TRUE; } }
void r_msg_update(bgp_state * state, tw_bf * bf, bgp_message * msg, tw_lp * lp) { int i; if (bf->c6) { for (i = 0; i < msg->rev_num_neighbors; i++) { tw_rand_reverse_unif(lp->id); } } if (bf->c1) { // reverse add tw_memory *as_path; if (bf->c2) { if (bf->c3) { tw_memoryq_delete_any(&state->routes, msg->this_route); // state->routes.remove(msg->this_bgp_route); // state->routes.pop_back(); // makes it non-deterministic if (bf->c4) { tw_memory *jim = tw_memory_free_rc(lp, g_bgp_fd_rtes); bgp_route *rjim = tw_memory_data(jim);; tw_memoryq_push(&state->routes, jim); // state->bgp_routes.push_back(msg->erased_route); bzero(&rjim->as_path, sizeof(rjim->as_path)); while (msg->rc_asp) { tw_memoryq_push(&rjim->as_path, tw_memory_free_rc(lp, g_bgp_fd_asp)); msg->rc_asp--; } } } } while ((as_path = tw_memoryq_pop(&((bgp_route *) msg->this_route->data)-> as_path))) tw_event_memory_get_rc(lp, as_path, g_bgp_fd_asp); state->stats->s_nupdateadds--; } else { // reverse remove if (bf->c5) { int i = msg->rc_asp; tw_memory *it4; bgp_route *r; msg->this_route = tw_memory_free_rc(lp, g_bgp_fd_rtes); while (i) { tw_event_memory_get_rc(lp, tw_memory_free_rc(lp, g_bgp_fd_asp), g_bgp_fd_asp); i--; } it4 = tw_memory_free_rc(lp, g_bgp_fd_rtes); r = tw_memory_data(it4); bzero(&r->as_path, sizeof(r->as_path)); while (msg->rc_asp) { tw_memoryq_push(&r->as_path, tw_memory_free_rc(lp, g_bgp_fd_asp)); msg->rc_asp--; } tw_memoryq_push(&state->routes, it4); // state->bgp_routes.push_back(msg->erased_bgp_route); } state->stats->s_nupdateremoves--; } tw_event_memory_get_rc(lp, msg->this_route, g_bgp_fd_rtes); msg->this_route = NULL; }