/******************************************************************* * Called when a LSU is received. Adds and updates the topology as necessary. *******************************************************************/ int add_to_top(struct sr_instance* sr, uint32_t host_rid, struct route** advert_routes, int num_ads) { pwospf_lock(sr->ospf_subsys); struct in_addr rid; rid.s_addr=host_rid; fprintf(stderr, "Printing Topo before add_to_top------LSU Received from %s\n", inet_ntoa(rid)); print_topo(sr); struct router* host = adj_list_contains(sr, host_rid); if(host != NULL) { add_to_existing_router(sr, advert_routes, host, num_ads); } else { host = add_new_router(sr, host_rid); add_to_existing_router(sr, advert_routes, host, num_ads); } /*TODO: check host's subnets. If any don't have a corresponding advertisement, delete.*/ if(time(NULL) > sr->ospf_subsys->init_time) { int i; for(i=0; i< host->subnet_size; i++) { if(sub_in_adv(sr, advert_routes, host->subnets[i], num_ads)==0) { struct router* nbor = adj_list_contains(sr, host->subnets[i]->r_id); remove_rt_sn_using_id(sr, host, host->subnets[i]->r_id); if(nbor!=NULL) { remove_rt_sn_using_id(sr, nbor, host_rid); remove_rt_adj_using_id(sr, nbor, host_rid); remove_rt_adj_using_id(sr, host, nbor->rid); } i--; } } } fprintf(stderr, "Printing Topo after add_to_top\n"); print_topo(sr); dijkstra(sr, sr->ospf_subsys->this_router); update_ftable(sr); pwospf_unlock(sr->ospf_subsys); return 1; }
int main(int argc, char *argv[]) { struct GModule *module; char *input_opt, *field_opt; int hist_flag, col_flag, shell_flag; struct Map_info Map; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("vector")); G_add_keyword(_("metadata")); G_add_keyword(_("topology")); G_add_keyword(_("extent")); G_add_keyword(_("history")); G_add_keyword(_("attribute columns")); module->description = _("Outputs basic information about a vector map."); G_debug(1, "LFS is %s", sizeof(off_t) == 8 ? "available" : "not available"); parse_args(argc, argv, &input_opt, &field_opt, &hist_flag, &col_flag, &shell_flag); /* try to open head-only on level 2 */ if (Vect_open_old_head2(&Map, input_opt, "", field_opt) < 2) { /* force level 1, open fully * NOTE: number of points, lines, boundaries, centroids, faces, kernels is still available */ Vect_close(&Map); Vect_set_open_level(1); /* no topology */ if (Vect_open_old2(&Map, input_opt, "", field_opt) < 1) G_fatal_error(_("Unable to open vector map <%s>"), Vect_get_full_name(&Map)); /* level one info not needed for history, title, columns */ if (!hist_flag && !col_flag) level_one_info(&Map); } if (hist_flag || col_flag) { if (hist_flag) { char buf[1001]; Vect_hist_rewind(&Map); while (Vect_hist_read(buf, 1000, &Map) != NULL) { fprintf(stdout, "%s\n", buf); } } else if (col_flag) { print_columns(&Map, input_opt, field_opt); } Vect_close(&Map); return (EXIT_SUCCESS); } if (shell_flag & SHELL_BASIC) { print_shell(&Map); } if (shell_flag & SHELL_REGION) { print_region(&Map); } if (shell_flag & SHELL_TOPO) { print_topo(&Map); } if (shell_flag == 0) { print_info(&Map); } Vect_close(&Map); return (EXIT_SUCCESS); }
int pwospf_init(struct sr_instance* sr) { assert(sr); sr->ospf_subsys = (struct pwospf_subsys*)malloc(sizeof(struct pwospf_subsys)); assert(sr->ospf_subsys); pthread_mutex_init(&(sr->ospf_subsys->lock), 0); /* -- handle subsystem initialization here! -- */ create_pwospf_ifaces(sr); char *eth0_interface = "eth0"; struct sr_if* zero = sr_get_interface(sr, eth0_interface); sr->ospf_subsys->fwrd_table = 0; sr->ospf_subsys->network = 0; sr->ospf_subsys->this_router = add_new_router(sr, zero->ip); sr->ospf_subsys->last_seq_sent=0; if(zero == NULL) { printf("null\n"); } int i = 0; struct pwospf_iflist *cur_if = sr->ospf_subsys->interfaces; struct ftable_entry* cur_ft_entry = NULL; while(cur_if) { sr->ospf_subsys->this_router->subnets[i] = (struct route*)malloc(sizeof(struct route)); sr->ospf_subsys->this_router->subnets[i]->mask.s_addr = cur_if->mask.s_addr; struct in_addr temp_add; struct in_addr temp_mask; temp_add.s_addr = cur_if->address.s_addr; temp_mask.s_addr = sr->ospf_subsys->this_router->subnets[i]->mask.s_addr; sr->ospf_subsys->this_router->subnets[i]->prefix.s_addr = (temp_add.s_addr & temp_mask.s_addr); if((cur_if->address.s_addr & cur_if->mask.s_addr) == cur_if->address.s_addr) { sr->ospf_subsys->this_router->subnets[i]->next_hop.s_addr = ntohl((htonl(cur_if->address.s_addr) | 1 )); } else { sr->ospf_subsys->this_router->subnets[i]->next_hop.s_addr = (cur_if->address.s_addr & cur_if->mask.s_addr); } sr->ospf_subsys->this_router->subnets[i]->r_id = 0; if(sr->ospf_subsys->fwrd_table == 0) { sr->ospf_subsys->fwrd_table = (struct ftable_entry*)malloc(sizeof(struct ftable_entry)); cur_ft_entry = sr->ospf_subsys->fwrd_table; } else { cur_ft_entry->next = (struct ftable_entry*)malloc(sizeof(struct ftable_entry)); cur_ft_entry = cur_ft_entry->next; } cur_ft_entry->prefix = sr->ospf_subsys->this_router->subnets[i]->prefix; cur_ft_entry->mask = sr->ospf_subsys->this_router->subnets[i]->mask; cur_ft_entry->next_hop = sr->ospf_subsys->this_router->subnets[i]->next_hop; cur_ft_entry->num_hops = 0; cur_ft_entry->next = 0; memmove(cur_ft_entry->interface, cur_if->name, sr_IFACE_NAMELEN); sr->ospf_subsys->this_router->subnet_size++; i++; cur_if = cur_if->next; } print_subs(sr->ospf_subsys->this_router->subnets, sr->ospf_subsys->this_router->subnet_size); sr->ospf_subsys->last_seq_sent = 0; sr->ospf_subsys->area_id = read_config(FILENAME); /* !!!! returns 0 if file read error !!!! */ sr->ospf_subsys->autype = 0; sr->ospf_subsys->init_time= time(NULL) + TOP_INITIALIZATION; print_topo(sr); /* -- start thread subsystem -- */ if( pthread_create(&sr->ospf_subsys->thread, 0, pwospf_run_thread, sr)) { perror("pthread_create"); assert(0); } return 0; /* success */ } /* -- pwospf_init -- */