/* * This is the main routine of the CLI. Everything starts here. * The CLI registers and commands into a hash table and forks a thread to * handle the command line. */ int CLIInit(router_config *rarg) { int stat, *jstat; if (!(cli_map = map_create(free))) return EXIT_FAILURE; /* * Disable certain signals such as Ctrl+C.. make the shell a little stable */ redefineSignalHandler(SIGINT, dummyFunction); redefineSignalHandler(SIGQUIT, dummyFunction); redefineSignalHandler(SIGTSTP, dummyFunction); verbose(2, "[cliHandler]:: Registering CLI commands in the command table "); /* * Register the commands allowed in the CLI. Each command is implemented by a * function. The function is inserted into the command registary and picked up * when the leading string is typed in the CLI. */ registerCLI("help", helpCmd, SHELP_HELP, USAGE_HELP, LHELP_HELP); // Check registerCLI("version", versionCmd, SHELP_VERSION, USAGE_VERSION, LHELP_VERSION); // Check registerCLI("set", setCmd, SHELP_SET, USAGE_SET, LHELP_SET); // Check registerCLI("get", getCmd, SHELP_GET, USAGE_GET, LHELP_GET); // Check registerCLI("source", sourceCmd, SHELP_SOURCE, USAGE_SOURCE, LHELP_SOURCE); // Check registerCLI("ifconfig", ifconfigCmd, SHELP_IFCONFIG, USAGE_IFCONFIG, LHELP_IFCONFIG); registerCLI("route", routeCmd, SHELP_ROUTE, USAGE_ROUTE, LHELP_ROUTE); registerCLI("arp", arpCmd, SHELP_ARP, USAGE_ARP, LHELP_ARP); registerCLI("ping", pingCmd, SHELP_PING, USAGE_PING, LHELP_PING); // Check registerCLI("console", consoleCmd, SHELP_CONSOLE, USAGE_CONSOLE, LHELP_CONSOLE); // Check registerCLI("halt", haltCmd, SHELP_HALT, USAGE_HALT, LHELP_HALT); // Check registerCLI("exit", haltCmd, SHELP_EXIT, USAGE_EXIT, LHELP_EXIT); // Check registerCLI("queue", queueCmd, SHELP_QUEUE, USAGE_QUEUE, LHELP_QUEUE); // Check registerCLI("qdisc", qdiscCmd, SHELP_QDISC, USAGE_QDISC, LHELP_QDISC); // Check registerCLI("spolicy", spolicyCmd, SHELP_SPOLICY, USAGE_SPOLICY, LHELP_SPOLICY); // Check registerCLI("class", classCmd, SHELP_CLASS, USAGE_CLASS, LHELP_CLASS); registerCLI("filter", filterCmd, SHELP_FILTER, USAGE_FILTER, LHELP_FILTER); registerCLI("hello", helloCmd, SHELP_EXIT, USAGE_EXIT, LHELP_EXIT); if (rarg->config_dir != NULL) chdir(rarg->config_dir); // change to the configuration directory if (rarg->config_file != NULL) { FILE *ifile = fopen(rarg->config_file, "r"); rl_instream = ifile; // redirect the input stream CLIProcessCmds(ifile, 0); rl_instream = stdin; } if (rarg->cli_flag != 0) stat = pthread_create((pthread_t *)(&(rarg->clihandler)), NULL, CLIProcessCmdsInteractive, (void *)stdin); pthread_join(rarg->clihandler, (void **)&jstat); verbose(2, "[cliHandler]:: Destroying the CLI datastructures "); CLIDestroy(); }
int main(int ac, char *av[]) { char rpath[MAX_NAME_LEN]; int status, *jstatus; simplequeue_t *outputQ, *workQ, *qtoa; pthread_t IGMP_broadcast_thread; // create separate thread for broadcasting IGMP group query messages pthread_create(&IGMP_broadcast_thread, NULL, IGMPBroadcast, NULL); // setup the program properties setupProgram(ac, av); // creates a PID file under router_name.pid in the current directory status = makePIDFile(rconfig.router_name, rpath); // shutdown the router on receiving SIGUSR1 or SIGUSR2 redefineSignalHandler(SIGUSR1, shutdownRouter); redefineSignalHandler(SIGUSR2, shutdownRouter); outputQ = createSimpleQueue("outputQueue", INFINITE_Q_SIZE, 0, 1); workQ = createSimpleQueue("work Queue", INFINITE_Q_SIZE, 0, 1); GNETInit(&(rconfig.ghandler), rconfig.config_dir, rconfig.router_name, outputQ); ARPInit(); IPInit(); classifier = createClassifier(); filter = createFilter(classifier, 0); pcore = createPacketCore(rconfig.router_name, outputQ, workQ); // add a default Queue.. the createClassifier has already added a rule with "default" tag // char *qname, char *dqisc, double qweight, double delay_us, int nslots); addPktCoreQueue(pcore, "default", "taildrop", 1.0, 2.0, 0); rconfig.scheduler = PktCoreSchedulerInit(pcore); rconfig.worker = PktCoreWorkerInit(pcore); infoInit(rconfig.config_dir, rconfig.router_name); addTarget("Output Queue", outputQ); qtoa = getCoreQueue(pcore, "default"); if (qtoa != NULL) addTarget("Default Queue", qtoa); else printf("Error .. found null queue for default\n"); // start the CLI.. CLIInit(&(rconfig)); wait4thread(rconfig.scheduler); wait4thread(rconfig.worker); wait4thread(rconfig.ghandler); wait4thread(IGMP_broadcast_thread); }
int main(int ac, char *av[]) { char rpath[MAX_NAME_LEN]; int status, *jstatus; simplequeue_t *outputQ, *workQ, *qtoa; // setup the program properties setupProgram(ac, av); // creates a PID file under router_name.pid in the current directory status = makePIDFile(rconfig.router_name, rpath); // shutdown the router on receiving SIGUSR1 or SIGUSR2 redefineSignalHandler(SIGUSR1, shutdownRouter); redefineSignalHandler(SIGUSR2, shutdownRouter); outputQ = createSimpleQueue("outputQueue", INFINITE_Q_SIZE, 0, 1); workQ = createSimpleQueue("work Queue", INFINITE_Q_SIZE, 0, 1); GNETInit(&(rconfig.ghandler), rconfig.config_dir, rconfig.router_name, outputQ); ARPInit(); IPInit(); init_ports(); init_tcp(); /*uint32_t dest_ip = 12319800; uint16_t dest_port = 123; uint16_t src_port = 456; char *data = "Hello"; int len = 6; send_udp(dest_ip,dest_port,src_port,data,len);*/ /* *Test udp_recv * */ /*open_port(1, UDP_PROTOCOL); gpacket_t *packet = (gpacket_t *) malloc(sizeof(gpacket_t)); ip_packet_t *ipPacket = (ip_packet_t *)(packet->data.data); ipPacket->ip_src = {0x1,0x1,0x1,0x1}; ipPacket->ip_dst = {0x2,0x2,0x2,0x2}; ipPacket->ip_cksum = 65535; ipPacket->ip_pkt_len = ipPacket->ip_hdr_len; udphdr_t *udpHeader = (udphdr_t *)((uchar *)ipPacket + ipPacket->ip_hdr_len*4); udpHeader->source = 0; // ports udpHeader->dest = 1; udpHeader->len = 0; // length of data in octets udpHeader->check = 65535; udp_recv(packet); free(packet); free(ipPacket); free(udpHeader);*/ /* * * * End test udp_recv * */ printf("dis router"); classifier = createClassifier(); filter = createFilter(classifier, 0); pcore = createPacketCore(rconfig.router_name, outputQ, workQ); // add a default Queue.. the createClassifier has already added a rule with "default" tag // char *qname, char *dqisc, double qweight, double delay_us, int nslots); addPktCoreQueue(pcore, "default", "taildrop", 1.0, 2.0, 0); rconfig.scheduler = PktCoreSchedulerInit(pcore); rconfig.worker = PktCoreWorkerInit(pcore); infoInit(rconfig.config_dir, rconfig.router_name); addTarget("Output Queue", outputQ); qtoa = getCoreQueue(pcore, "default"); if (qtoa != NULL) addTarget("Default Queue", qtoa); else printf("Error .. found null queue for default\n"); // start the CLI.. CLIInit(&(rconfig)); wait4thread(rconfig.scheduler); wait4thread(rconfig.worker); wait4thread(rconfig.ghandler); }