sbridge_bool_t sbridge_config_parse(sbridge_config_t *configuration, const char *configuration_file_name) { const char *envstr = NULL; char *spansdup = NULL; char *spanstr = NULL; int32_t conf_dchan; int32_t conf_spanchans; int32_t conf_pridebug; int32_t spanno, maxspans, res; sangoma_pri_switch_t conf_switch; sangoma_pri_node_t conf_node; sbridge_assert(configuration != NULL, -1); sbridge_assert(configuration_file_name != NULL, -1); memset(configuration, 0, sizeof(*configuration)); /* if its ever needed, a configuration file can be used here, for now environment variables work just fine */ envstr = sbridge_getenv("sbridge_database"); if (!envstr) { sbridge_log(SBRIDGE_LOG_ERROR, "sbridge_database not specified\n"); return SBRIDGE_FALSE; } res = sqlite3_open(envstr, &configuration->db); if (res) { sbridge_log(SBRIDGE_LOG_ERROR, "failed to open sqlite3 database %s: %s\n", envstr, sqlite3_errmsg(configuration->db)); sqlite3_close(configuration->db); return SBRIDGE_FALSE; } envstr = sbridge_getenv("sbridge_tcp_hosts"); if (!envstr) { sbridge_log(SBRIDGE_LOG_ERROR, "sbridge_tcp_hosts not specified\n"); return SBRIDGE_FALSE; } if (!create_hosts(envstr, configuration)) { sbridge_log(SBRIDGE_LOG_ERROR, "Failed to create hosts from string %s\n", envstr); return SBRIDGE_FALSE; } envstr = sbridge_getenv("sbridge_loglevel"); configuration->loglevel = str_to_loglevel(envstr); if (configuration->loglevel == SBRIDGE_LOG_EXDEBUG) { sbridge_log(SBRIDGE_LOG_NOTICE, "PRI debugging will be enabled\n"); conf_pridebug = PRI_DEBUG_ALL; } else { conf_pridebug = 0; } envstr = sbridge_getenv("sbridge_v110_rate"); configuration->v110_urate = str_to_v110_urate(envstr); envstr = sbridge_getenv("sbridge_trace"); if (envstr) { sbridge_snprintf(configuration->trace_prefix, sizeof(configuration->trace_prefix), "%s", envstr); } /* D-channel number */ conf_dchan = 16; /* channels per span */ conf_spanchans = 31; /* PRI switch type */ envstr = sbridge_getenv("sbridge_pri_switch"); conf_switch = str_to_switch(envstr); /* PRI node type */ envstr = sbridge_getenv("sbridge_pri_node"); conf_node = str_to_node(envstr); envstr = sbridge_getenv("sbridge_pri_spans"); if (!envstr) { sbridge_log(SBRIDGE_LOG_ERROR, "sbridge_spans was not specified\n"); return SBRIDGE_FALSE; } spansdup = strdupa(envstr); spanstr = strsep(&spansdup, ","); maxspans = sizeof(configuration->spans)/sizeof(configuration->spans[0]); while (spanstr && strlen(spanstr) && configuration->numspans < maxspans) { spanno = atoi(spanstr); if (!spanno) { sbridge_log(SBRIDGE_LOG_ERROR, "Invalid span specified: %s\n", spanstr); return SBRIDGE_FALSE; } configuration->spans[configuration->numspans].spanno = spanno; configuration->spans[configuration->numspans].numchans = conf_spanchans; configuration->spans[configuration->numspans].dchan = conf_dchan; configuration->spans[configuration->numspans].pridebug = conf_pridebug; configuration->spans[configuration->numspans].switch_type = conf_switch; configuration->spans[configuration->numspans].node_type = conf_node; configuration->spans[configuration->numspans].signaling_thread = SBRIDGE_INVALID_THREAD_ID; configuration->spans[configuration->numspans].config = configuration; configuration->spans[configuration->numspans].need_hangup = SBRIDGE_FALSE; configuration->numspans++; spanstr = strsep(&spansdup, ","); } return SBRIDGE_TRUE; }
/* * start producer */ int main(int argc, char** argv) { int c; char *userid = "test_admin"; char *password = "******"; char *broker_uri = "tcp://127.0.0.1:5500"; char *loglevel = "event"; char * topic = "test"; char * consumer_type = "zmq"; uint64_t messages_to_receive = 1000000; while ((c = getopt (argc, argv, "ht:u:p:b:c:m:l:")) != -1) switch (c) { case 'h': printf("Usage: [%s] [-t topic[%s]] [-u userid[%s]] [-p password[%s]] [-b broker_uri[%s]] [-c consumer_type[%s]] [-m messages_to_receive[%llu]] [-l loglevel[event]]\n", argv[0], topic, userid, password, broker_uri, consumer_type, messages_to_receive ); return 0; case 't': topic = optarg; printf("%c %s\n",c, topic); break; case 'u': userid = optarg; break; case 'p': password = optarg; break; case 'b': broker_uri = optarg; break; case 'c': consumer_type = optarg; break; case 'm': messages_to_receive = strtoull(optarg, NULL, 10); break; case 'l': loglevel = optarg; break; case '?': if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); return 1; default: break; } lightq_loglevel level = str_to_loglevel(loglevel); init_log(argv[0], level); consumer_socket_type type = zmq_consumer; if(!strcmp(consumer_type, "socket")) { type = socket_consumer; } lightq_consumer_conn* p_consumer = init_consumer(userid, password, topic,broker_uri, type); if(p_consumer) { uint64_t total_bytes_received = 0; unsigned long start_time = 0; unsigned long end_time = 0; unsigned buffer_size = 0; char buffer[buffer_size]; for(uint64_t i = 0; i < messages_to_receive; ++i) { buffer[0] = '\0'; int bytes_received = receive_message(p_consumer, buffer, buffer_size); if(bytes_received > 0) { total_bytes_received += bytes_received; }else { printf("Failed to received message. index [%llu]\n", i); } if(i == 0) { start_time = get_current_time_millsec(); } } end_time = get_current_time_millsec(); unsigned total_time_ms = end_time-start_time; float total_time_sec = total_time_ms / 1000; printf("Total message received [%llu] in [%.2f]sec\n", messages_to_receive, total_time_sec); printf("Average messages sent per second [%.2f]\n", messages_to_receive/total_time_sec); printf("Average bandwidth sent per second [%.4f]MB\n", total_bytes_received / (1024*1024*total_time_sec)); } return (EXIT_SUCCESS); }