void print_name_prefix_from_npl(void) { if ( nlsr->debugging ) printf("print_name_prefix_from_npl called \n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_name_prefix_from_npl called\n"); int i, npl_element; //struct name_prefix *np; struct name_prefix_list_entry *npe; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(nlsr->npl, e); npl_element=hashtb_n(nlsr->npl); for(i=0;i<npl_element;i++) { npe=e->data; if ( nlsr->debugging ) printf("Name Prefix: %s and Length: %d and LSA Id: %ld\n",npe->np->name,npe->np->length,npe->name_lsa_id); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name Prefix: %s and Length: %d \n",npe->np->name,npe->np->length); hashtb_next(e); } hashtb_end(e); if ( nlsr->debugging ) printf("\n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); }
void ndnx_name_opaque_lsa_print (struct ndnx_opaque_lsa *ol) { writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__," Name Opaque LSA\n"); struct name_opaque_lsa *nol=(struct name_opaque_lsa *)ol; writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__,"Name Prefix: %s\n",(char *)nol->body.name_data); }
void update_name_prefix_nexthop_list(struct prefixtable_entry *fe, struct hash *origin_table) { struct nexthop_entry *nhe; struct origin_entry *o = fe->origin_list; struct origintable_entry *oe; int res,j, no_element; no_element=no_nexthop(); //printf("-name prefix: %s\n", fe->nameprefix->name); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__, "-name prefix: %s\n", fe->nameprefix->name); //remove old nexthops nhe = fe->nexthop_list; while (nhe) { if(!is_nexthop(inet_ntoa(nhe->nexthop))) delete_ndn_face(ndn_handle, (char *)fe->nameprefix->name, inet_ntoa(nhe->nexthop), 6363); fe->nexthop_list = nhe->next; free(nhe); nhe = fe->nexthop_list; } for(j=1;j<=no_element;j++) delete_ndn_face(ndn_handle, (char *)fe->nameprefix->name, inet_ntoa(pop_nexthop_from_position(j)),6363); //foreach origin in origin_list while (o) { //get origintable_entry oe = origin_hash_get(origin_table, &(o->origin)); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__,"--origin: %s\n", inet_ntoa(oe->origin)); nhe = oe->nexthop_list; //foreach nexthop while (nhe) { writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__,"---nexthop: %s\n", inet_ntoa(nhe->nexthop)); res = insert_nexthop_to_list(&fe->nexthop_list, nhe->nexthop, nhe->cost, nhe->flag); if (res == 1) { for(j=1;j<=no_element;j++) { if(inet_addr(inet_ntoa(nhe->nexthop)) != inet_addr(inet_ntoa(pop_nexthop_from_position(j)))){ add_ndn_face(ndn_handle, (char *)fe->nameprefix->name, inet_ntoa(pop_nexthop_from_position(j)),6363); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__," Adding face to ndn for prefix : %s nexthop : %s\n",(char *)fe->nameprefix->name, inet_ntoa(pop_nexthop_from_position(j))); } } add_ndn_face(ndn_handle, (char *)fe->nameprefix->name, inet_ntoa(nhe->nexthop), 6363); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__," Adding face to ndn for prefix : %s nexthop : %s\n",(char *)fe->nameprefix->name, inet_ntoa(nhe->nexthop)); } nhe = nhe->next; } o = o->next; } }
void ospfn_stop_signal_handler(int sig) { signal(sig, SIG_IGN); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__,"Signal for ospfn stop\n"); hash_iterate_delete_npt (ospfn->prefix_table); ccn_destroy(&ccn_handle); ospf_apiclient_close(ospfn->oclient); free_all_nexthop(); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__,"Exiting ospfn...\n"); exit(0); }
void update_routing_table_with_new_route(long int *parent, long int *dist,long int source) { if ( nlsr->debugging ) printf("update_routing_table_with_new_route called\n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_routing_table_with_new_route called\n"); int i, map_element; struct map_entry *me; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(nlsr->rev_map, e); map_element=hashtb_n(nlsr->rev_map); for(i=0;i<map_element;i++) { me=e->data; if(me->mapping != source) { char *orig_router=get_router_from_rev_map(me->mapping); if (orig_router != NULL ) { int next_hop_router_num=get_next_hop_from_calculation(parent,me->mapping,source); if ( next_hop_router_num == NO_NEXT_HOP ) { if ( nlsr->debugging ) printf ("Orig_router: %s Next Hop Face: %d \n",orig_router,NO_FACE); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"Orig_router: %s Next Hop Face: %d \n",orig_router,NO_FACE); } else { char *next_hop_router=get_router_from_rev_map(next_hop_router_num); int next_hop_face=get_next_hop_face_from_adl(next_hop_router); update_routing_table(orig_router,next_hop_face,dist[me->mapping]); if ( nlsr->debugging ) printf ("Orig_router: %s Next Hop Face: %d \n",orig_router,next_hop_face); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"Orig_router: %s Next Hop Face: %d \n",orig_router,next_hop_face); } } } hashtb_next(e); } hashtb_end(e); }
void clear_old_routing_table(void) { if ( nlsr->debugging ) printf("clear_old_routing_table called\n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"clear_old_routing_table called\n"); int i,rt_element; struct routing_table_entry *rte; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(nlsr->routing_table, e); rt_element=hashtb_n(nlsr->routing_table); for(i=0;i<rt_element;i++) { rte=e->data; hashtb_destroy(&rte->face_list); struct hashtb_param param_fle = {0}; rte->face_list=hashtb_create(sizeof(struct face_list_entry), ¶m_fle); hashtb_next(e); } hashtb_end(e); }
void print_all_next_hop(long int *parent,long int source) { int i, map_element; struct map_entry *me; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(nlsr->map, e); map_element=hashtb_n(nlsr->map); for(i=0;i<map_element;i++) { me=e->data; if(me->mapping != source) { if ( nlsr->debugging ) printf("Dest: %d Next Hop: %ld\n",me->mapping,get_next_hop_from_calculation(parent,me->mapping,source)); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"Dest: %d Next Hop: %ld\n",me->mapping,get_next_hop_from_calculation(parent,me->mapping,source)); } hashtb_next(e); } hashtb_end(e); }
void print_keys(void){ if ( nlsr->debugging ) printf("print_keys called \n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_keys called \n"); int i, key_element; struct nlsr_key *key; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(nlsr->keys, e); key_element=hashtb_n(nlsr->keys); for(i=0;i<key_element;i++) { key=e->data; if ( nlsr->debugging ) printf("Key : %s \n",key->key_name); hashtb_next(e); } hashtb_end(e); }
void hash_iterate_delete_npt (struct hash *hash){ unsigned int i,j,no_element; struct hash_backet *hb; struct hash_backet *hbnext; no_element=no_nexthop(); for (i = 0; i < hash->size; i++) { for (hb = hash->index[i]; hb; hb = hbnext) { struct prefixtable_entry *pte = (struct prefixtable_entry *)hb->data; struct nexthop_entry *n1 = pte->nexthop_list; // get the pointer of next hop list while(n1) { writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__,"Deleting FIB prefix: Name: %s, Next Hop: %s, cost: %d, flag: %d\n",pte->nameprefix->name, inet_ntoa(n1->nexthop),n1->cost, n1->flag); if(!is_nexthop(inet_ntoa(n1->nexthop))) delete_ndn_face(ndn_handle, (char *)pte->nameprefix->name, inet_ntoa(n1->nexthop), 6363); n1 = n1->next; } for(j=1;j<=no_element;j++) delete_ndn_face(ndn_handle, (char *)pte->nameprefix->name, inet_ntoa(pop_nexthop_from_position(j)),6363); hbnext = hb->next; } } }
void delete_name_prefix(struct hash *prefix_table, struct name_prefix *np, struct hash *origin_table, struct in_addr *origin) { struct prefixtable_entry *fe; struct origintable_entry *oe; int res; fe = prefix_hash_get(prefix_table, np); res = delete_origin_from_list(&fe->origin_list, origin); if (res == 0) { printf("Error: origin %s does not exist\n", inet_ntoa(*origin)); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__,"Error: origin %s does not exist\n",inet_ntoa(*origin)); } oe = origin_hash_get(origin_table, origin); res = delete_name_prefix_from_list(&oe->nameprefix_list, np); if (res == 0) { printf("Error: name prefix %s does not exist\n",(char *) np->name); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__,"Error: name prefix %s does not exist\n",(char *) np->name); } update_name_prefix_nexthop_list(fe, origin_table); }
void update_routing_table_with_new_hyperbolic_route(long int dest_router_rev_map_index, long int face, double nbr_to_dest_dist) { if ( nlsr->debugging ) printf("update_routing_table_with_new_hyperbolic_route called\n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"update_routing_table_with_new_hyperbolic_route called\n"); char *orig_router=get_router_from_rev_map(dest_router_rev_map_index); if (face != NO_NEXT_HOP && face != NO_FACE ) { update_routing_table(orig_router,face,nbr_to_dest_dist); if ( nlsr->debugging ) printf ("Orig_router: %s Next Hop Face: %ld \n",orig_router,face); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"Orig_router: %s Next Hop Face: %ld \n",orig_router,face); } }
void do_old_routing_table_updates(void) { if ( nlsr->debugging ) printf("do_old_routing_table_updates called\n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"do_old_routing_table_updates called\n"); int i, rt_element; int mapping_no; struct routing_table_entry *rte; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(nlsr->routing_table, e); rt_element=hashtb_n(nlsr->routing_table); for(i=0;i<rt_element;i++) { rte=e->data; mapping_no=get_mapping_no(rte->dest_router); if ( mapping_no == NO_MAPPING_NUM) { delete_orig_router_from_npt(rte->dest_router); /* char *router=(char *)malloc(strlen(rte->dest_router)+1); memset(router,0,strlen(rte->dest_router)+1); memcpy(router,rte->dest_router,strlen(rte->dest_router)+1); nlsr->event = ccn_schedule_event(nlsr->sched, 1, &delete_empty_rte, (void *)router , 0); */ destroy_routing_table_entry_comp(rte); hashtb_delete(e); i++; } else { hashtb_next(e); } } hashtb_end(e); }
void ndnx_lsa_header_dump (struct lsa_header *lsah) { const char *lsah_type = LOOKUP (ospf_lsa_type_msg, lsah->type); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__," LSA Header\n"); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__," LS age %d\n", ntohs (lsah->ls_age)); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__," Options %d (%s)\n", lsah->options, ospf_options_dump (lsah->options)); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__," LS type %d (%s)\n", lsah->type, (lsah->type ? lsah_type : "unknown type")); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__," Link State ID %s\n", inet_ntoa (lsah->id)); if( lsah->type == 9 || lsah->type == 10 || lsah->type ==11) { writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__," Opaque Type %d\n" ,ntohl(lsah->id.s_addr)>>24); writeLogg(ospfn->logFile,__FILE__,__FUNCTION__,__LINE__," Opaque Id %d\n" ,ntohl(lsah->id.s_addr)& LSID_OPAQUE_ID_MASK); }
void print_all_path_from_source(long int *parent,long int source) { int i, map_element; struct map_entry *me; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(nlsr->map, e); map_element=hashtb_n(nlsr->map); if ( source != NO_MAPPING_NUM) { for(i=0;i<map_element;i++) { me=e->data; if(me->mapping != source) { if ( nlsr->debugging ) { print_path(parent,(long int)me->mapping); printf("\n"); } if ( nlsr->detailed_logging ) { print_path(parent,(long int)me->mapping); writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); } } hashtb_next(e); } } hashtb_end(e); }
void print_rev_map(void) { int i, map_element; struct map_entry *me; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(nlsr->map, e); map_element=hashtb_n(nlsr->map); for(i=0;i<map_element;i++) { me=e->data; if ( nlsr->debugging ) printf("Mapping Number: %d Router: %s \n",me->mapping,me->router); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"Mapping Number: %d Router: %s \n",me->mapping,me->router); hashtb_next(e); } hashtb_end(e); }
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; }
void print_routing_table(void) { if ( nlsr->debugging ) printf("print_routing_table called\n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_routing_table called\n"); int i,j, rt_element,face_list_element; struct routing_table_entry *rte; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(nlsr->routing_table, e); rt_element=hashtb_n(nlsr->routing_table); for(i=0;i<rt_element;i++) { if ( nlsr->debugging ) printf("----------Routing Table Entry %d------------------\n",i+1); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"----------Routing Table Entry %d------------------\n",i+1); rte=e->data; if ( nlsr->debugging ) printf(" Destination Router: %s \n",rte->dest_router); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__," Destination Router: %s \n",rte->dest_router); //rte->next_hop_face == NO_NEXT_HOP ? printf(" Next Hop Face: NO_NEXT_HOP \n") : printf(" Next Hop Face: %d \n", rte->next_hop_face); struct face_list_entry *fle; struct hashtb_enumerator eef; struct hashtb_enumerator *ef = &eef; hashtb_start(rte->face_list, ef); face_list_element=hashtb_n(rte->face_list); if ( face_list_element <= 0 ) { if ( nlsr->debugging ) printf(" Face: No Face \n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: No Face \n"); } else { for(j=0;j<face_list_element;j++) { fle=ef->data; if ( nlsr->debugging ) printf(" Face: %d Route_Cost: %f \n",fle->next_hop_face,fle->route_cost); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__," Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost); hashtb_next(ef); } } hashtb_end(ef); hashtb_next(e); } hashtb_end(e); if ( nlsr->debugging ) printf("\n"); if ( nlsr->detailed_logging ) writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); }