/* * void * handle_stdin * * Handle the standard input from the user and call the appropriate * functions */ void handle_stdin(char buff[80]) { char c; int i; /* If only one character is present */ if(sscanf(buff, "%c", &c) == 1) { switch(buff[0]) { case 'N': print_neighbors(); return; case 'T': print_routing_table(); return; case 'p': print_router(); return; } } /* To send messages */ if(sscanf(buff, "%d", &i) == 1) { if(i >= 0 && i<=19) send_msg(i); return; } /* Reject policy */ if(sscanf(buff, "R %d", &i) == 1) { if(i < 0 || i > 19) printf("Invalid router ID specified."); else if(router.is_border_router == FALSE) { printf("Reject commands can be run only on border routers.\n"); } else { printf("Router rejected: %d.", i); reject(i); } printf("\n\n"); fflush(stdout); return; } /* Prefer policy */ if(buff[0] == 'P') { if(router.is_border_router == FALSE) { printf("Commands to set preferred paths can be run only on \ border routers.\n\n"); fflush(stdout); return; } set_prefer_policy(buff); return; }
int main(void) { SkipListPtr list; double usec, usec2, usec3, usec4; list = N(SLCreate)(); printf( "list at %p\n", list); print(list); printf("\n==============================\n\n"); N(SLInsert)(list, 123, NULL); N(SLInsert)(list, 213, NULL); N(SLInsert)(list, 50, NULL); print(list); printf("\n==============================\n\n"); print_neighbors(list, 0); print_neighbors(list, 50); print_neighbors(list, 51); print_neighbors(list, 123); print_neighbors(list, 200); print_neighbors(list, 213); print_neighbors(list, 256); printf("\n==============================\n\n"); N(SLDelete)(list, 50); print(list); printf("\n==============================\n\n"); N(SLDump)(list); N(SLDestroy)(list); printf("\n==============================\n\n"); usec = do_time(100, 10000); usec2 = do_time(1000, 500); printf("Table size increased by %0.2f, search time increased by %0.2f\n", 1000.0/100.0, usec2 / usec); usec3 = do_time(10000, 50); printf("Table size increased by %0.2f, search time increased by %0.2f\n", 10000.0/100.0, usec3 / usec); usec4 = do_time(100000, 4); printf("Table size increased by %0.2f, search time increased by %0.2f\n", 100000.0/100.0, usec4 / usec); return 0; }
int main(int argc, char *argv[]) { uint64_t MACADDRESS = 9890190479;/**<MAC address of host; sent to the arp module*/ uint32_t IPADDRESS = 672121;/**<IP address of host; sent to the arp module*/ host_MAC_addrs = MACADDRESS; host_IP_addrs = IPADDRESS; gen_neighbor_list(argv[1]); init_recordsARP(argv[1]); print_neighbors(ptr_neighbor_list); arp_test_harness(); //test functionality of ARP module return 0; }
/** * @brief this function prints the contents of a cache for each of the interfaces * ptr_cacheHeader points to the first element/header of the cache */ void print_cache(struct node *ptr_elementInList){ print_neighbors(ptr_elementInList); printf("\n\n"); }
/* --------------------------------- */ PROCESS_THREAD(print_neigh_process, ev, data) { PROCESS_BEGIN(); print_neighbors(); PROCESS_END(); }
void dvmrp_print(netdissect_options *ndo, register const u_char *bp, register u_int len) { register const u_char *ep; register u_char type; ep = (const u_char *)ndo->ndo_snapend; if (bp >= ep) return; ND_TCHECK(bp[1]); type = bp[1]; /* Skip IGMP header */ bp += 8; len -= 8; switch (type) { case DVMRP_PROBE: ND_PRINT((ndo, " Probe")); if (ndo->ndo_vflag) { if (print_probe(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_REPORT: ND_PRINT((ndo, " Report")); if (ndo->ndo_vflag > 1) { if (print_report(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_ASK_NEIGHBORS: ND_PRINT((ndo, " Ask-neighbors(old)")); break; case DVMRP_NEIGHBORS: ND_PRINT((ndo, " Neighbors(old)")); if (print_neighbors(ndo, bp, ep, len) < 0) goto trunc; break; case DVMRP_ASK_NEIGHBORS2: ND_PRINT((ndo, " Ask-neighbors2")); break; case DVMRP_NEIGHBORS2: ND_PRINT((ndo, " Neighbors2")); /* * extract version and capabilities from IGMP group * address field */ bp -= 4; ND_TCHECK2(bp[0], 4); target_level = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3]; bp += 4; if (print_neighbors2(ndo, bp, ep, len) < 0) goto trunc; break; case DVMRP_PRUNE: ND_PRINT((ndo, " Prune")); if (print_prune(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT: ND_PRINT((ndo, " Graft")); if (print_graft(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT_ACK: ND_PRINT((ndo, " Graft-ACK")); if (print_graft_ack(ndo, bp) < 0) goto trunc; break; default: ND_PRINT((ndo, " [type %d]", type)); break; } return; trunc: ND_PRINT((ndo, "[|dvmrp]")); return; }
void dvmrp_print(netdissect_options *ndo, const u_char *bp, u_int len) { const u_char *ep; u_char type; uint8_t major_version, minor_version; ndo->ndo_protocol = "dvmrp"; ep = ndo->ndo_snapend; if (bp >= ep) return; ND_TCHECK_1(bp + 1); type = GET_U_1(bp + 1); /* Skip IGMP header */ bp += 8; len -= 8; switch (type) { case DVMRP_PROBE: ND_PRINT(" Probe"); if (ndo->ndo_vflag) { if (print_probe(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_REPORT: ND_PRINT(" Report"); if (ndo->ndo_vflag > 1) { if (print_report(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_ASK_NEIGHBORS: ND_PRINT(" Ask-neighbors(old)"); break; case DVMRP_NEIGHBORS: ND_PRINT(" Neighbors(old)"); if (print_neighbors(ndo, bp, ep, len) < 0) goto trunc; break; case DVMRP_ASK_NEIGHBORS2: ND_PRINT(" Ask-neighbors2"); break; case DVMRP_NEIGHBORS2: ND_PRINT(" Neighbors2"); /* * extract version from IGMP group address field */ bp -= 4; ND_TCHECK_4(bp); major_version = GET_U_1(bp + 3); minor_version = GET_U_1(bp + 2); bp += 4; if (print_neighbors2(ndo, bp, ep, len, major_version, minor_version) < 0) goto trunc; break; case DVMRP_PRUNE: ND_PRINT(" Prune"); if (print_prune(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT: ND_PRINT(" Graft"); if (print_graft(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT_ACK: ND_PRINT(" Graft-ACK"); if (print_graft_ack(ndo, bp) < 0) goto trunc; break; default: ND_PRINT(" [type %u]", type); break; } return; trunc: nd_print_trunc(ndo); return; }
/**@brief this function tests a set of functions which are used when * (1) a host receives an ARP request, and (2) keeps updating its cache based on * these ARP requests * @param fileName is the file from which the list of neighbors is drawn */ void send_receive_update(char *fileName) { extern struct node *ptr_cacheHeader; struct finsFrame request_fins, reply_fins, *request_fins_ptr, *reply_fins_ptr; struct ARP_message request_ARP1, request_ARP2, reply_ARP1, reply_ARP2; struct ARP_message *request_ARP_ptr1, *request_ARP_ptr2, *reply_ARP_ptr1, *reply_ARP_ptr2; struct arp_hdr hdr_ARP, *hdr_ARP_ptr; uint64_t MAC_addrs; uint32_t IP_addrs_read; int task; /**Following code generates a list of IP/MAC addresses of 'neighbors' and initializes cache*/ ptr_cacheHeader = init_intface(); gen_neighbor_list(fileName); init_recordsARP(fileName); print_cache(); print_neighbors(ptr_neighbor_list); hdr_ARP_ptr = &hdr_ARP; IP_addrs_read = 1; task = 1; /**Begin Initialize/Instantiate Pointers */ request_fins_ptr = &request_fins; reply_fins_ptr = &reply_fins; request_ARP_ptr1 = &request_ARP1; request_ARP_ptr2 = &request_ARP2; reply_ARP_ptr1 = &reply_ARP1; reply_ARP_ptr2 = &reply_ARP2; /**A host can send update its cache based on its own request or a request from another network host*/ while (IP_addrs_read!=0 && (task==0 || task == 1)) { PRINT_DEBUG("\nTest send request and update `0' or test receive a request `1' \n"); scanf("%d", &task); IP_addrs_read = read_IP_addrs(); /**The following functions test the internal operations of the module*/ if (task==0){ gen_requestARP(IP_addrs_read, request_ARP_ptr1); print_msgARP(request_ARP_ptr1); arp_to_fins(request_ARP_ptr1, request_fins_ptr); fins_to_arp(request_fins_ptr, request_ARP_ptr2); mimic_net_reply(request_ARP_ptr2, reply_ARP_ptr1); if (check_valid_arp(reply_ARP_ptr1)==1){ arp_to_fins(reply_ARP_ptr1, reply_fins_ptr); fins_to_arp(reply_fins_ptr, reply_ARP_ptr2); print_msgARP(reply_ARP_ptr2); update_cache(reply_ARP_ptr2);} print_cache(); } else if (task==1){ MAC_addrs = search_MAC_addrs(IP_addrs_read, ptr_neighbor_list); mimic_net_request(IP_addrs_read, MAC_addrs,request_ARP_ptr1); print_msgARP(request_ARP_ptr1); if (check_valid_arp(request_ARP_ptr1)==1){ arp_to_fins(request_ARP_ptr1, request_fins_ptr); fins_to_arp(request_fins_ptr, request_ARP_ptr2); print_msgARP(request_ARP_ptr2); update_cache(request_ARP_ptr2);} print_cache(); } /**The following functions test the external operation of the module*/ if (check_valid_arp(request_ARP_ptr2)==1){ hdr_ARP_ptr = &hdr_ARP; /**convert ARP message to htons format and generate MAC addresses as unsigned char ptr*/ net_fmt_conversion(request_ARP_ptr2, hdr_ARP_ptr); print_arp_hdr(hdr_ARP_ptr);/**print some fields of the ARP message in external format*/ host_fmt_conversion(hdr_ARP_ptr, request_ARP_ptr2);/**convert ARP message to ntohs format*/ print_msgARP(request_ARP_ptr2);/**print ARP message internal format*/ } } term_intface(); }
/*Print the neightbor cache*/ void print_cache() { print_neighbors(neighbors); }