void workers_completion (int rc, const struct String_vector *strings, const void *data) { switch (rc) { case ZCONNECTIONLOSS: case ZOPERATIONTIMEOUT: get_workers(); break; case ZOK: if(strings->count == 1) { LOG_DEBUG(("Got %d worker", strings->count)); } else { LOG_DEBUG(("Got %d workers", strings->count)); } struct String_vector *tmp_workers = removed_and_set(strings, &workers); free_vector(tmp_workers); get_tasks(); break; default: LOG_ERROR(("Something went wrong when checking workers: %s", rc2string(rc))); break; } }
void shutdown_workers() { int i; for (i = 0; i < get_workers(); i++) { pthread_cond_signal(&workers[i].optimization.queue.signal); pthread_cond_signal(&workers[i].deoptimization.queue.signal); } }
int cli_show_stats_out_dedup_thread(int client_fd, char **parameters, int numparameters) { char msg[MAX_BUFFER_SIZE] = { 0 }; sprintf(msg,"------------------------------------------------------------------\n"); cli_send_feedback(client_fd, msg); Statistics ds; int si; for (si=0;si<get_workers();si++) { getStatistics(get_worker_decompressor(si),&ds); memset(msg, 0, MAX_BUFFER_SIZE); sprintf(msg,"Decompressor statistics (thread %d)\n",si); cli_send_feedback(client_fd, msg); sprintf(msg,"total_input_bytes.value %" PRIu64 " \n", ds.inputBytes); cli_send_feedback(client_fd, msg); sprintf(msg,"total_output_bytes.value %" PRIu64 "\n", ds.outputBytes); cli_send_feedback(client_fd, msg); sprintf(msg,"processed_packets.value %" PRIu64 "\n", ds.processedPackets); cli_send_feedback(client_fd, msg); sprintf(msg,"uncompressed_packets.value %" PRIu64 "\n", ds.uncompressedPackets); cli_send_feedback(client_fd, msg); sprintf(msg,"FP_entries_not_found.value %" PRIu64 "\n", ds.errorsMissingFP); cli_send_feedback(client_fd, msg); sprintf(msg,"packet_hashes_not_found.value %" PRIu64 "\n", ds.errorsMissingPacket); cli_send_feedback(client_fd, msg); sprintf(msg,"bad_packet_format.value %" PRIu64 "\n", ds.errorsPacketFormat); cli_send_feedback(client_fd, msg); sprintf(msg,"------------------------------------------------------------------\n"); cli_send_feedback(client_fd, msg); } return 0; }
void workers_watcher (zhandle_t *zh, int type, int state, const char *path,void *watcherCtx) { if( type == ZOO_CHILD_EVENT) { assert( !strcmp(path, "/workers") ); get_workers(); } else { LOG_DEBUG(("Watched event: ", type2string(type))); } }
int cli_reset_stats_in_dedup_thread(int client_fd, char **parameters, int numparameters) { char msg[MAX_BUFFER_SIZE] = { 0 }; sprintf(msg,"-------------------------------------------------------------------------------\n"); cli_send_feedback(client_fd, msg); int si; for (si=0;si<get_workers();si++) resetStatistics(get_worker_compressor(si)); sprintf(msg,"Compressor statistics reset\n"); cli_send_feedback(client_fd, msg); sprintf(msg,"-------------------------------------------------------------------------------\n"); cli_send_feedback(client_fd, msg); return 0; }
int cli_show_stats_in_dedup_thread(int client_fd, char **parameters, int numparameters) { char msg[MAX_BUFFER_SIZE] = { 0 }; sprintf(msg,"------------------------------------------------------------------\n"); cli_send_feedback(client_fd, msg); Statistics cs; int si; for (si = 0; si < get_workers(); si++) { getStatistics(get_worker_compressor(si),&cs); memset(msg, 0, MAX_BUFFER_SIZE); sprintf(msg,"Compressor statistics (thread %d)\n",si); cli_send_feedback(client_fd, msg); sprintf(msg,"total_input_bytes.value %" PRIu64 " \n", cs.inputBytes); cli_send_feedback(client_fd, msg); sprintf(msg,"total_output_bytes.value %" PRIu64 "\n", cs.outputBytes); cli_send_feedback(client_fd, msg); sprintf(msg,"processed_packets.value %" PRIu64 "\n", cs.processedPackets); cli_send_feedback(client_fd, msg); sprintf(msg,"compressed_packets.value %" PRIu64 "\n", cs.compressedPackets); cli_send_feedback(client_fd, msg); sprintf(msg,"FP_entries.value %" PRIu64 "\n", cs.numOfFPEntries); cli_send_feedback(client_fd, msg); sprintf(msg,"last_pktId.value %" PRIu64 "\n", cs.lastPktId); cli_send_feedback(client_fd, msg); sprintf(msg,"FP_hash_collisions.value %" PRIu64 "\n", cs.numberOfFPHashCollisions); cli_send_feedback(client_fd, msg); sprintf(msg,"FP_collisions.value %" PRIu64 "\n", cs.numberOfFPCollisions); cli_send_feedback(client_fd, msg); sprintf(msg,"short_packets.value %" PRIu64 "\n", cs.numberOfShortPkts); cli_send_feedback(client_fd, msg); sprintf(msg,"------------------------------------------------------------------\n"); cli_send_feedback(client_fd, msg); } return 0; }
void take_leadership() { get_workers(); }
struct commandresult cli_show_workers(int client_fd, char **parameters, int numparameters, void *data) { int i; __u32 ppsbps; __u32 total_optimization_pps = 0, total_optimization_bpsin = 0, total_optimization_bpsout = 0; __u32 total_deoptimization_pps = 0, total_deoptimization_bpsin = 0, total_deoptimization_bpsout = 0; struct commandresult result = { 0 }; char msg[MAX_BUFFER_SIZE] = { 0 }; char message[LOGSZ]; char bps[11]; char optimizationbpsin[9]; char optimizationbpsout[9]; char deoptimizationbpsin[9]; char deoptimizationbpsout[9]; char col1[11]; char col2[9]; char col3[14]; char col4[14]; char col5[9]; char col6[14]; char col7[14]; char col8[3]; if (DEBUG_WORKER_CLI == true) { sprintf(message, "Counters: Showing counters"); logger(LOG_INFO, message); } sprintf( msg, "-------------------------------------------------------------------------------\n"); cli_send_feedback(client_fd, msg); sprintf( msg, "| 5 sec | optimization | deoptimization |\n"); cli_send_feedback(client_fd, msg); sprintf( msg, "-------------------------------------------------------------------------------\n"); cli_send_feedback(client_fd, msg); sprintf( msg, "| worker | pps | in | out | pps | in | out |\n"); cli_send_feedback(client_fd, msg); sprintf( msg, "-------------------------------------------------------------------------------\n"); cli_send_feedback(client_fd, msg); for (i = 0; i < get_workers(); i++) { strcpy(msg, ""); sprintf(col1, "| %-5i", i); strcat(msg, col1); ppsbps = workers[i].optimization.metrics.pps; total_optimization_pps += ppsbps; sprintf(col2, "| %-6u", ppsbps); strcat(msg, col2); ppsbps = workers[i].optimization.metrics.bpsin; total_optimization_bpsin += ppsbps; bytestostringbps(bps, ppsbps); sprintf(col3, "| %-11s", bps); strcat(msg, col3); ppsbps = workers[i].optimization.metrics.bpsout; total_optimization_bpsout += ppsbps; bytestostringbps(bps, ppsbps); sprintf(col4, "| %-11s", bps); strcat(msg, col4); ppsbps = workers[i].deoptimization.metrics.pps; total_deoptimization_pps += ppsbps; sprintf(col5, "| %-6u", ppsbps); strcat(msg, col5); ppsbps = workers[i].deoptimization.metrics.bpsin; total_deoptimization_bpsin += ppsbps; bytestostringbps(bps, ppsbps); sprintf(col6, "| %-11s", bps); strcat(msg, col6); ppsbps = workers[i].deoptimization.metrics.bpsout; total_deoptimization_bpsout += ppsbps; bytestostringbps(bps, ppsbps); sprintf(col7, "| %-11s", bps); strcat(msg, col7); sprintf(col8, "|\n"); strcat(msg, col8); cli_send_feedback(client_fd, msg); } sprintf( msg, "-------------------------------------------------------------------------------\n"); cli_send_feedback(client_fd, msg); bytestostringbps(optimizationbpsin, total_optimization_bpsin); bytestostringbps(optimizationbpsout, total_optimization_bpsout); bytestostringbps(deoptimizationbpsin, total_deoptimization_bpsin); bytestostringbps(deoptimizationbpsout, total_deoptimization_bpsout); sprintf(msg, "| total | %-6u| %-11s| %-11s| %-6u| %-11s| %-11s|\n", total_optimization_pps, optimizationbpsin, optimizationbpsout, total_deoptimization_pps, deoptimizationbpsin, deoptimizationbpsout); cli_send_feedback(client_fd, msg); sprintf( msg, "-------------------------------------------------------------------------------\n"); cli_send_feedback(client_fd, msg); result.finished = 0; result.mode = NULL; result.data = NULL; return result; }
int main(int argc, char *argv[]) { pthread_t t_cleanup; // thread for cleaning up dead sessions. pthread_t t_healthagent; // thread for health agent. pthread_t t_cli; // thread for cli. pthread_t t_counters; // thread for performance counters. pthread_t t_memorymanager; // thread for the memory manager. struct ifaddrs *ifaddr;//, *ifa; __u32 tempIP; // int s; int i; char message[LOGSZ]; char strIP[20]; // char host[NI_MAXHOST]; char path[100] = "/etc/opennop/opennop.conf"; int tmp; __u32 packet_size = PACKET_SIZE, packet_number = PACKET_NUMBER, thr_num = DEF_THR_NUM; __u32 fpPerPkt = DEF_FP_PER_PKT, fpsFactor = DEF_FPS_FACTOR; #if defined(DEBUG) int daemonize = false; #else int daemonize = true; #endif /* Setup signal handling */ signal(SIGHUP, signal_handler); signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); signal(SIGQUIT, signal_handler); signal(SIGPIPE,SIG_IGN); int c; while ((c = getopt(argc, argv, "nh|help")) != -1) { switch (c) { case 'h': PrintUsage(argc, argv); exit(0); break; case 'n': daemonize = 0; isdaemon = false; break; default: PrintUsage(argc, argv); break; } } sprintf(message, "Initialization: %s daemon starting up.\n", DAEMON_NAME); logger(LOG_INFO, message); /* * Configuration: read the configuration file */ sprintf(message, "Configuring: reading file %s.\n", path); logger(LOG_INFO, message); tmp = configure(path, &localID, &packet_number, &packet_size, &thr_num, &fpPerPkt, &fpsFactor); if(tmp == 1){ sprintf(message, "Configuring error. EXIT\n"); logger(LOG_INFO, message); exit(EXIT_FAILURE); } sprintf(message, "Initialization: Version %s.\n", VERSION); logger(LOG_INFO, message); /* * Get the numerically highest local IP address. * This will be used as the acceleratorID. */ if (getifaddrs(&ifaddr) == -1) { sprintf(message, "Initialization: Error opening interfaces.\n"); logger(LOG_INFO, message); exit(EXIT_FAILURE); } // for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { // loop through all interfaces. // // if (ifa->ifa_addr != NULL) { // // if (ifa->ifa_addr->sa_family == AF_INET) { // get all IPv4 addresses. // s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), // host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); // // if (s != 0) { // exit(EXIT_FAILURE); // } // // inet_pton(AF_INET, (char *) &host, &tempIP); // convert string to decimal. // // /* // * Lets fine the largest local IP, and use that as accelleratorID // * Lets also exclude 127.0.0.1 as a valid ID. // */ // if ((tempIP > localID) && (tempIP != LOOPBACKIP)) { // localID = tempIP; // } // } // end get all IPv4 addresses. // } // end ifa->ifa_addr NULL test. // } // end loop through all interfaces. if (localID == 0) { // fail if no usable IP found. inet_ntop(AF_INET, &tempIP, strIP, INET_ADDRSTRLEN); sprintf(message, "Initialization: No usable IP Address. %s\n", strIP); logger(LOG_INFO, message); exit(EXIT_FAILURE); } #if defined(DEBUG) setlogmask(LOG_UPTO(LOG_DEBUG)); openlog(DAEMON_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER); #else setlogmask(LOG_UPTO(LOG_INFO)); openlog(DAEMON_NAME, LOG_CONS, LOG_USER); #endif /* Our process ID and Session ID */ pid_t pid, sid; if (daemonize) { sprintf(message, "Initialization: Daemonizing the %s process.\n", DAEMON_NAME); logger(LOG_INFO, message); /* Fork off the parent process */ pid = fork(); if (pid < 0) { exit(EXIT_FAILURE); } /* If we got a good PID, then we can exit the parent process. */ if (pid > 0) { exit(EXIT_SUCCESS); } /* Change the file mode mask */ umask(0); /* Create a new SID for the child process */ sid = setsid(); if (sid < 0) { /* Log the failure */ exit(EXIT_FAILURE); } /* Change the current working directory */ if ((chdir("/")) < 0) { /* Log the failure */ exit(EXIT_FAILURE); } /* Close out the standard file descriptors */ close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); } /* * Starting up the daemon. */ initialize_sessiontable(); if (get_workers() == 0) { set_workers(thr_num); //set_workers(sysconf(_SC_NPROCESSORS_ONLN) * 2); } #ifdef ROLLING init_common(packet_number,packet_size, fpPerPkt, fpsFactor, shareddict); init_debugd() ; #endif for (i = 0; i < get_workers(); i++) { create_worker(i); } #ifdef BASIC create_hashmap(&ht); // Create hash table #endif // Only one type of optimization can be active // assert(deduplication != compression); /* * Create the fetcher thread that retrieves * IP packets from the Netfilter Queue. */ create_fetcher(); pthread_create(&t_cleanup, NULL, cleanup_function, (void *) NULL); pthread_create(&t_healthagent, NULL, healthagent_function, (void *) NULL); pthread_create(&t_cli, NULL, cli_manager_init, (void *) NULL); pthread_create(&t_counters, NULL, counters_function, (void *) NULL); pthread_create(&t_memorymanager, NULL, memorymanager_function, (void *) NULL); sprintf(message, "[OpenNOP]: Started all threads.\n"); logger(LOG_INFO, message); /* * All the threads have been created now commands should be registered. */ register_command("show traces mask", cli_show_traces_mask, false, false); register_command("traces mask orr", cli_traces_mask_orr, true, false); register_command("traces mask and", cli_traces_mask_and, true, false); register_command("traces mask nand", cli_traces_mask_nand, true, false); register_command("reset stats in_dedup", cli_reset_stats_in_dedup, false, false); register_command("reset stats in_dedup_thread", cli_reset_stats_in_dedup, false, false); register_command("show stats in_dedup", cli_show_stats_in_dedup, false, false); register_command("show stats in_dedup_thread", cli_show_stats_in_dedup_thread, false, false); register_command("reset stats out_dedup", cli_reset_stats_out_dedup, false, false); register_command("reset stats out_dedup_thread", cli_reset_stats_out_dedup, false, false); register_command("show stats out_dedup", cli_show_stats_out_dedup, false, false); register_command("show stats out_dedup_thread", cli_show_stats_out_dedup_thread, false, false); register_command("traces enable", cli_traces_enable, true, false); register_command("traces disable", cli_traces_disable, true, false); register_command("show version", cli_show_version, false, false); register_command("show compression", cli_show_compression, false, false); register_command("show workers", cli_show_workers, false, false); register_command("show fetcher", cli_show_fetcher, false, false); register_command("show sessions", cli_show_sessionss, false, false); register_command("show deduplication", cli_show_deduplication, false, false); register_command("compression enable", cli_compression_enable, false, false); register_command("compression disable", cli_compression_disable, false, false); register_command("deduplication enable", cli_deduplication_enable, false, false); register_command("deduplication disable", cli_deduplication_disable, false, false); /* * Rejoin all threads before we exit! */ rejoin_fetcher(); sprintf(message, "[OpenNOP] Fetcher joined\n"); logger(LOG_INFO, message); pthread_join(t_cleanup, NULL); sprintf(message, "joined cleanup\n"); logger(LOG_INFO, message); pthread_join(t_healthagent, NULL); sprintf(message, "joined health\n"); logger(LOG_INFO, message); pthread_join(t_cli, NULL); sprintf(message, "joined cli\n"); logger(LOG_INFO, message); pthread_join(t_counters, NULL); sprintf(message, "joined counters\n"); logger(LOG_INFO, message); pthread_join(t_memorymanager, NULL); for (i = 0; i < get_workers(); i++) { rejoin_worker(i); } #ifdef BASIC remove_hashmap(ht); #endif clear_sessiontable(); sprintf(message, "Exiting: %s daemon exiting", DAEMON_NAME); logger(LOG_INFO, message); exit(EXIT_SUCCESS); }
/* * Inserts a new sessio.n into the sessions linked list. * Will either use an empty slot, or create a new session in the list. */ struct session *insertsession(__u32 largerIP, __u16 largerIPPort, __u32 smallerIP, __u16 smallerIPPort) { struct session *newsession = NULL; int i; __u16 hash = 0; __u8 queuenum = 0; char message[LOGSZ]; hash = sessionhash(largerIP, smallerIP, largerIPPort, smallerIPPort); /* * What queue will the packets for this session go to? */ queuenum = 0; for (i = 0; i < get_workers(); i++) { if (DEBUG_SESSIONMANAGER_INSERT == true) { sprintf(message, "Session Manager: Queue #%d has %d sessions.\n", i, get_worker_sessions(i)); logger(LOG_INFO, message); } if (get_worker_sessions(queuenum) > get_worker_sessions(i)) { if (i < get_workers()) { queuenum = i; } } } if (DEBUG_SESSIONMANAGER_INSERT == true) { sprintf(message, "Session Manager: Assigning session to queue #: %d!\n", queuenum); logger(LOG_INFO, message); } newsession = calloc(1, sizeof(struct session)); // Allocate a new session. if (newsession != NULL) { // Write data to this new session. newsession->head = &sessiontable[hash]; // Pointer to the head of this list. newsession->next = NULL; newsession->prev = NULL; newsession->client = NULL; newsession->server = NULL; newsession->queue = queuenum; newsession->largerIP = largerIP; // Assign values and initialize this session. newsession->largerIPPort = largerIPPort; newsession->largerIPAccelerator = 0; newsession->largerIPseq = 0; newsession->smallerIP = smallerIP; newsession->smallerIPPort = smallerIPPort; newsession->smallerIPseq = 0; newsession->smallerIPAccelerator = 0; newsession->deadcounter = 0; newsession->state = 0; /* * Increase the counter for number of sessions assigned to this worker. */ increment_worker_sessions(queuenum); /* * Lets add the new session to the session bucket. */ pthread_mutex_lock(&sessiontable[hash].lock); // Grab lock on the session bucket. if (DEBUG_SESSIONMANAGER_INSERT == true) { sprintf(message, "Session Manager: Assigning session to bucket #: %u!\n", hash); logger(LOG_INFO, message); } if (sessiontable[hash].qlen == 0) { // Check if any session are in this bucket. sessiontable[hash].next = newsession; // Session Head next will point to the new session. sessiontable[hash].prev = newsession; // Session Head prev will point to the new session. } else { newsession->prev = sessiontable[hash].prev; // Session prev will point at the last packet in the session bucket. newsession->prev->next = newsession; sessiontable[hash].prev = newsession; // Make this new session the last session in the session bucket. } sessiontable[hash].qlen += 1; // Need to increase the session count in this session bucket. if (DEBUG_SESSIONMANAGER_INSERT == true) { sprintf( message, "Session Manager: There are %u sessions in this bucket now.\n", sessiontable[hash].qlen); logger(LOG_INFO, message); } pthread_mutex_unlock(&sessiontable[hash].lock); // Lose lock on session bucket. return newsession; } else { return NULL; // Failed to assign memory for newsession. } }