/******************************************************************* * Removes a given subnet from a given router. Moves last entry in subnets array into deleted space. *******************************************************************/ int remove_subnet_from_router(struct sr_instance *sr, struct router *rt, struct route *subnet) { /*decrease size, remove appropriate subnet, move last subnet into empty spot in the array this keeps all entries packed*/ int i; for(i = 0; i < rt->subnet_size; i++) { if(route_cmp(rt->subnets[i], subnet) == 0) { rt->subnets[i] = NULL; rt->subnets[i] = rt->subnets[rt->subnet_size-1]; i = rt->subnet_size; rt->subnet_size--; } } /*if this subnet is a router*/ if(subnet->r_id != 0) { for(i = 0; i < rt->adj_size; i++) { if(subnet->r_id == rt->adjacencies[i]->rid) { rt->adjacencies[i] = NULL; rt->adjacencies[i] = rt->adjacencies[rt->adj_size-1]; i = rt->adj_size; rt->adj_size--; } } } return 1; }
route * r3_node_match_route(node *n, match_entry * entry) { if (n->routes && n->route_len > 0) { int i; for (i = 0; i < n->route_len ; i++ ) { if ( route_cmp(n->routes[i], entry) == 0 ) { return n->routes[i]; } } } return NULL; }
/******************************************************************* * Checks if a router contains a subnet based on prefix, mask, and rid. *******************************************************************/ int router_contains(struct route* rt, struct router *host) { int i; for(i = 0; i < host->subnet_size; i++) { if(route_cmp(host->subnets[i], rt) == 0) { return 1; } } return 0; }
/*********************************************************** * Checks that the array of advertisements contains a specific subnet **************************************************************/ int sub_in_adv(struct sr_instance* sr, struct route** advs, struct route* route, int num_ads) { int i; for(i=0; i< num_ads; i++) { if(route_cmp(route, advs[i])==0) { return 1; } } return 0; }