int sync_cb(struct ccns_name_closure *nc, struct ccn_charbuf *lhash, struct ccn_charbuf *rhash, struct ccn_charbuf *name) { nlsr_lock(); int res; struct ccn_charbuf *content_name; struct ccn_indexbuf *content_comps; struct ccn_indexbuf *name_comps; content_comps = ccn_indexbuf_create(); res = ccn_name_split(name, content_comps); if ( res < 0 ) return 0; if (content_comps->n < 2) return 0; content_name = ccn_charbuf_create(); ccn_name_init(content_name); res = ccn_name_append_components( content_name, name->buf, content_comps->buf[0], content_comps->buf[content_comps->n - 1]); if ( res < 0) return 0; // for debugging struct ccn_charbuf *temp=ccn_charbuf_create(); ccn_uri_append(temp, content_name->buf, content_name->length, 0); if ( nlsr->debugging ) printf("Name before chopping: %s \n",ccn_charbuf_as_string(temp)); ccn_charbuf_destroy(&temp); name_comps = ccn_indexbuf_create(); res=ccn_name_split (content_name, name_comps); if (res < 0) return 0; if ( nlsr->debugging ) { printf("Number of components in name = %d \n",res); printf("Number of components in name as indexbuf->n = %d \n", (int)name_comps->n); } ccn_name_chop(content_name, name_comps, -3); if ( nlsr->debugging ) printf("Number of components in name as indexbuf->n after chopping= %d \n" , (int)name_comps->n); //for debugging struct ccn_charbuf *temp1=ccn_charbuf_create(); ccn_uri_append(temp1, content_name->buf, content_name->length, 0); if ( nlsr->debugging ) printf("Name after chopping: %s \n",ccn_charbuf_as_string(temp1)); ccn_charbuf_destroy(&temp1); //main method that processes contents from the sync process_content_from_sync(content_name, name_comps); ccn_charbuf_destroy(&content_name); ccn_indexbuf_destroy(&content_comps); ccn_indexbuf_destroy(&name_comps); nlsr_unlock(); return(0); }
int route_calculate(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) { if(flags == CCN_SCHEDULE_CANCEL) { return -1; } nlsr_lock(); if ( nlsr->debugging ) printf("route_calculate called\n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"route_calculate called\n"); if( ! nlsr->is_build_adj_lsa_sheduled ) { /* Calculate Route here */ print_routing_table(); print_npt(); //struct hashtb_param param_me = {0}; nlsr->map = hashtb_create(sizeof(struct map_entry), NULL); nlsr->rev_map = hashtb_create(sizeof(struct map_entry), NULL); make_map(); assign_mapping_number(); print_map(); print_rev_map(); do_old_routing_table_updates(); clear_old_routing_table(); print_routing_table(); print_npt(); int i; int **adj_matrix; int map_element=hashtb_n(nlsr->map); adj_matrix=malloc(map_element * sizeof(int *)); for(i = 0; i < map_element; i++) { adj_matrix[i] = malloc(map_element * sizeof(int)); } make_adj_matrix(adj_matrix,map_element); if ( nlsr->debugging ) print_adj_matrix(adj_matrix,map_element); long int source=get_mapping_no(nlsr->router_name); int num_link=get_no_link_from_adj_matrix(adj_matrix, map_element ,source); if ( nlsr->is_hyperbolic_calc == 1) { long int *links=(long int *)malloc(num_link*sizeof(long int)); long int *link_costs=(long int *)malloc(num_link*sizeof(long int)); get_links_from_adj_matrix(adj_matrix, map_element , links, link_costs, source); struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ for (hashtb_start(nlsr->rev_map, e); e->key != NULL; hashtb_next(e)) { struct map_entry *me=e->data; if ( me->mapping != source ) { long int *faces=(long int *)calloc(num_link,sizeof(long int)); double *nbr_dist=(double *)calloc(num_link,sizeof(double)); double *nbr_to_dest=(double *)calloc(num_link,sizeof(double)); for ( i=0 ; i < num_link; i++) { int face=get_next_hop_face_from_adl(get_router_from_rev_map(links[i])); double dist_to_nbr=get_hyperbolic_distance(source,links[i]); double dist_to_dest_from_nbr=get_hyperbolic_distance(links[i],me->mapping); faces[i]=face; nbr_dist[i]=dist_to_nbr; nbr_to_dest[i]= dist_to_dest_from_nbr; } sort_hyperbolic_route(nbr_to_dest,nbr_dist, faces,0,num_link); if (nlsr->max_faces_per_prefix == 0 ) { for ( i=0 ; i < num_link; i++) { update_routing_table_with_new_hyperbolic_route(me->mapping,faces[i],nbr_to_dest[i]); } } else if ( nlsr->max_faces_per_prefix > 0 ) { if ( num_link <= nlsr->max_faces_per_prefix ) { for ( i=0 ; i < num_link; i++) { update_routing_table_with_new_hyperbolic_route(me->mapping,faces[i],nbr_to_dest[i]); } } else if (num_link > nlsr->max_faces_per_prefix) { for ( i=0 ; i < nlsr->max_faces_per_prefix; i++) { update_routing_table_with_new_hyperbolic_route(me->mapping,faces[i],nbr_to_dest[i]); } } } free(faces); free(nbr_dist); free(nbr_to_dest); } } hashtb_end(e); free(links); free(link_costs); } else if (nlsr->is_hyperbolic_calc == 0 ) { long int *parent=(long int *)malloc(map_element * sizeof(long int)); long int *dist=(long int *)malloc(map_element * sizeof(long int)); if ( (num_link == 0) || (nlsr->max_faces_per_prefix == 1 ) ) { calculate_path(adj_matrix,parent,dist, map_element, source); print_all_path_from_source(parent,source); print_all_next_hop(parent,source); update_routing_table_with_new_route(parent, dist,source); } else if ( (num_link != 0) && (nlsr->max_faces_per_prefix == 0 || nlsr->max_faces_per_prefix > 1 ) ) { long int *links=(long int *)malloc(num_link*sizeof(long int)); long int *link_costs=(long int *)malloc(num_link*sizeof(long int)); get_links_from_adj_matrix(adj_matrix, map_element , links, link_costs, source); for ( i=0 ; i < num_link; i++) { adjust_adj_matrix(adj_matrix, map_element,source,links[i],link_costs[i]); calculate_path(adj_matrix,parent,dist, map_element, source); print_all_path_from_source(parent,source); print_all_next_hop(parent,source); update_routing_table_with_new_route(parent, dist,source); } free(links); free(link_costs); } free(parent); free(dist); } print_routing_table(); print_npt(); update_npt_with_new_route(); print_routing_table(); print_npt(); for(i = 0; i < map_element; i++) { free(adj_matrix[i]); } free(adj_matrix); destroy_map(); destroy_rev_map(); //hashtb_destroy(&nlsr->map); //hashtb_destroy(&nlsr->rev_map); } nlsr->is_route_calculation_scheduled=0; nlsr_unlock(); return 0; }