]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
freetdm: ftmod_r2 - Fixed input size for tx and rx dumping
authorMoises Silva <moises.silva@gmail.com>
Wed, 8 Dec 2010 15:45:45 +0000 (10:45 -0500)
committerMoises Silva <moises.silva@gmail.com>
Wed, 8 Dec 2010 15:45:45 +0000 (10:45 -0500)
         ftmod_r2 - Set tx queue to 4 only
         ftmod_wanpipe - Fixed stats warnings

libs/freetdm/src/ftdm_io.c
libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c
libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c

index 3206ee431301e0d470db7bd8ac602e18eb1ab7e1..cdd734ba3c21480980f3bfe8e5fa72ec5e5f800e 100644 (file)
@@ -163,9 +163,7 @@ static ftdm_status_t start_chan_io_dump(ftdm_channel_t *chan, ftdm_io_dump_t *du
                return FTDM_FAIL;
        }
        memset(dump, 0, sizeof(*dump));
-       /* on 64bits, we get a weird number if we don't cast to uint here 
-        * which is what size_t will be anyway */
-       dump->buffer = ftdm_malloc((uint32_t)size);
+       dump->buffer = ftdm_malloc(size);
        if (!dump->buffer) {
                return FTDM_FAIL;
        }
@@ -350,7 +348,7 @@ static __inline__ void *ftdm_std_malloc(void *pool, ftdm_size_t size)
 {
        void *ptr = malloc(size);
        pool = NULL; /* fix warning */
-       ftdm_assert_return(ptr != NULL, NULL, "Out of memory");
+       ftdm_assert_return(ptr != NULL, NULL, "Out of memory\n");
        return ptr;
 }
 
@@ -358,7 +356,7 @@ static __inline__ void *ftdm_std_calloc(void *pool, ftdm_size_t elements, ftdm_s
 {
        void *ptr = calloc(elements, size);
        pool = NULL;
-       ftdm_assert_return(ptr != NULL, NULL, "Out of memory");
+       ftdm_assert_return(ptr != NULL, NULL, "Out of memory\n");
        return ptr;
 }
 
@@ -366,7 +364,7 @@ static __inline__ void *ftdm_std_realloc(void *pool, void *buff, ftdm_size_t siz
 {
        buff = realloc(buff, size);
        pool = NULL;
-       ftdm_assert_return(buff != NULL, NULL, "Out of memory");
+       ftdm_assert_return(buff != NULL, NULL, "Out of memory\n");
        return buff;
 }
 
@@ -2764,7 +2762,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_co
                                GOTO_STATUS(done, FTDM_FAIL);
                        }
                        if (start_chan_io_dump(ftdmchan, &ftdmchan->rxdump, size) != FTDM_SUCCESS) {
-                               ftdm_log_chan_msg(ftdmchan, FTDM_LOG_ERROR, "Failed to enable input dump\n");   
+                               ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Failed to enable input dump of size %zd\n", size);
                                GOTO_STATUS(done, FTDM_FAIL);
                        }
                        ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Enabled input dump with size %zd\n", size);
@@ -2794,7 +2792,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_co
                                GOTO_STATUS(done, FTDM_FAIL);
                        }
                        if (start_chan_io_dump(ftdmchan, &ftdmchan->txdump, size) != FTDM_SUCCESS) {
-                               ftdm_log_chan_msg(ftdmchan, FTDM_LOG_ERROR, "Failed to enable output dump\n");  
+                               ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Failed to enable output dump of size %d\n", size);     
                                GOTO_STATUS(done, FTDM_FAIL);
                        }
                        ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Enabled output dump with size %zd\n", size);
@@ -3847,7 +3845,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_write(ftdm_channel_t *ftdmchan, void *dat
        }
 
        if (ftdmchan->span->sig_write) {
-               status = ftdmchan->span->sig_write(ftdmchan, data, datalen);
+               status = ftdmchan->span->sig_write(ftdmchan, data, *datalen);
                if (status == FTDM_BREAK) {
                        /* signaling module decided to drop user frame */
                        status = FTDM_SUCCESS;
index 21f7a1202c6f69642234513ed8d43afac1fb0414..2a95b01fe9171a4bd1fb4622890c3f608acc0ddc 100644 (file)
@@ -91,7 +91,7 @@ typedef struct ft_r2_conf_s {
        int32_t max_dnis;
        int32_t mfback_timeout; 
        int32_t metering_pulse_timeout;
-       int32_t mf_dump_size;
+       ftdm_size_t mf_dump_size;
 
        /* booleans */
        int immediate_accept;
@@ -121,7 +121,7 @@ typedef struct ftdm_r2_data_s {
        /* whether accept the call when offered, or wait until the user decides to accept */
        int accept_on_offer:1;
        /* Size of multi-frequency (or any media) dumps used during protocol errors */
-       int32_t mf_dump_size;
+       ftdm_size_t mf_dump_size;
        /* max time spent in ms doing real work in a single loop */
        int32_t jobmax;
        /* Total number of loops performed so far */
@@ -473,7 +473,6 @@ static void ftdm_r2_on_call_init(openr2_chan_t *r2chan)
        memset(ftdmchan->caller_data.dnis.digits, 0, sizeof(ftdmchan->caller_data.collected));
        memset(ftdmchan->caller_data.ani.digits, 0, sizeof(ftdmchan->caller_data.collected));
 
-       /* clean the call data structure but keep the R2 processing flag on! */
        ft_r2_clean_call(ftdmchan->call_data);
        r2call = R2CALL(ftdmchan);
 
@@ -1120,6 +1119,7 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_r2_configure_span_signaling)
 {
        unsigned int i = 0;
        int conf_failure = 0;
+       int intval = 0;
        const char *var = NULL, *val = NULL;
        const char *log_level = "notice,warning,error"; /* default loglevel, if none is read from conf */
        ftdm_r2_data_t *r2data = NULL;
@@ -1226,11 +1226,12 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_r2_configure_span_signaling)
                        r2conf.advanced_protocol_file = (char *)val;
                        ftdm_log(FTDM_LOG_DEBUG, "Configuring R2 span %s with advanced protocol file %s\n", span->name, val);
                } else if (!strcasecmp(var, "mf_dump_size")) {
-                       r2conf.mf_dump_size = atoi(val);
-                       if (r2conf.mf_dump_size < 0) {
+                       intval = atoi(val);
+                       if (intval < 0) {
                                r2conf.mf_dump_size = FTDM_IO_DUMP_DEFAULT_BUFF_SIZE;
                                ftdm_log(FTDM_LOG_DEBUG, "Configuring R2 span %s with default mf_dump_size = %d bytes\n", span->name, r2conf.mf_dump_size);
                        } else {
+                               r2conf.mf_dump_size = intval;
                                ftdm_log(FTDM_LOG_DEBUG, "Configuring R2 span %s with mf_dump_size = %d bytes\n", span->name, r2conf.mf_dump_size);
                        }
                } else if (!strcasecmp(var, "allow_collect_calls")) {
@@ -1612,6 +1613,7 @@ static void *ftdm_r2_run(ftdm_thread_t *me, void *obj)
        int index = 0;
        struct timeval start, end;
        ftdm_iterator_t *chaniter = NULL;
+       uint32_t txqueue_size = 4;
        short *poll_events = ftdm_malloc(sizeof(short) * span->chan_count);
 
 #ifdef __linux__
@@ -1620,18 +1622,23 @@ static void *ftdm_r2_run(ftdm_thread_t *me, void *obj)
        
        ftdm_log(FTDM_LOG_DEBUG, "OpenR2 monitor thread %lu started.\n", r2data->monitor_thread_id);
        r2chan = NULL;
-       for (i = 1; i <= span->chan_count; i++) {
-               r2chan = R2CALL(span->channels[i])->r2chan;
+       chaniter = ftdm_span_get_chan_iterator(span, NULL);
+       for (i = 1; chaniter; chaniter = ftdm_iterator_next(chaniter), i++) {
+               ftdmchan = ftdm_iterator_current(chaniter);
+               r2chan = R2CALL(ftdmchan)->r2chan;
                openr2_chan_set_span_id(r2chan, span->span_id);
                openr2_chan_set_idle(r2chan);
                openr2_chan_process_cas_signaling(r2chan);
+               ftdm_channel_command(ftdmchan, FTDM_COMMAND_SET_TX_QUEUE_SIZE, &txqueue_size);
        }
 
        memset(&start, 0, sizeof(start));
        memset(&end, 0, sizeof(end));
-       chaniter = ftdm_span_get_chan_iterator(span, NULL);
        while (ftdm_running() && ftdm_test_flag(r2data, FTDM_R2_RUNNING)) {
                res = gettimeofday(&end, NULL);
+               if (res) {
+                       ftdm_log(FTDM_LOG_CRIT, "Failure gettimeofday [%s]\n", strerror(errno));
+               }
                if (start.tv_sec) {
                        ms = ((end.tv_sec - start.tv_sec) * 1000) 
                            + ((( 1000000 + end.tv_usec - start.tv_usec) / 1000) - 1000);
index 0bafa40bdd71fc823b180ce6403b14bfbedea37a..1c0baa731f0a73590f726474772af3073f299078 100644 (file)
@@ -760,8 +760,8 @@ static FIO_COMMAND_FUNCTION(wanpipe_command)
                {
                        err = sangoma_flush_rx_bufs(ftdmchan->sockfd, &tdm_api);
                }
-       case FTDM_COMMAND_FLUSH_TX_BUFFERS:
                break;
+       case FTDM_COMMAND_FLUSH_TX_BUFFERS:
                {
                        err = sangoma_flush_tx_bufs(ftdmchan->sockfd, &tdm_api);
                }
@@ -806,20 +806,17 @@ static void wanpipe_write_stats(ftdm_channel_t *ftdmchan, wp_tdm_api_tx_hdr_t *t
        
        /* we don't test for 80% full in tx since is typically full for voice channels, should we test tx 80% full for D-channels? */
        if (ftdmchan->iostats.tx.queue_len >= ftdmchan->iostats.tx.queue_size) {
-               ftdm_log_chan(ftdmchan, FTDM_LOG_CRIT, "Tx Queue Full (%d/%d)\n",
-                                         ftdmchan->iostats.tx.queue_len, ftdmchan->iostats.tx.queue_size);
                ftdm_set_flag(&(ftdmchan->iostats.tx), FTDM_IOSTATS_ERROR_QUEUE_FULL);
        } else if (ftdm_test_flag(&(ftdmchan->iostats.tx), FTDM_IOSTATS_ERROR_QUEUE_FULL)){
-               ftdm_log_chan(ftdmchan, FTDM_LOG_NOTICE, "Tx Queue no longer full (%d/%d)\n",
-                                         ftdmchan->iostats.tx.queue_len, ftdmchan->iostats.tx.queue_size);
                ftdm_clear_flag(&(ftdmchan->iostats.tx), FTDM_IOSTATS_ERROR_QUEUE_FULL);
        }
 
        if (ftdmchan->iostats.tx.idle_packets < tx_stats->wp_api_tx_hdr_number_of_frames_in_queue) {
                ftdmchan->iostats.tx.idle_packets = tx_stats->wp_api_tx_hdr_tx_idle_packets;
-               /* HDLC channels do not always transmit, so its ok for drivers to fill with idle */
-               if (FTDM_IS_VOICE_CHANNEL(ftdmchan)) {
-                       ftdm_log_chan(ftdmchan, FTDM_LOG_WARNING, "Tx idle:  %d\n", ftdmchan->iostats.tx.idle_packets);
+               /* HDLC channels do not always transmit, so its ok for drivers to fill with idle
+                * also do not report idle warning when we just started transmitting */
+               if (ftdmchan->iostats.tx.packets && FTDM_IS_VOICE_CHANNEL(ftdmchan)) {
+                       ftdm_log_chan(ftdmchan, FTDM_LOG_WARNING, "Tx idle: %d\n", ftdmchan->iostats.tx.idle_packets);
                }
        }
 
@@ -942,7 +939,9 @@ static FIO_READ_FUNCTION(wanpipe_read)
  */
 static FIO_WRITE_FUNCTION(wanpipe_write)
 {
-       int bsent;
+       int bsent = 0;
+       int err = 0;
+       ftdm_time_t ms = 0;
        wp_tdm_api_tx_hdr_t hdrframe;
 
        /* Do we even need the headerframe here? on windows, we don't even pass it to the driver */
@@ -950,6 +949,17 @@ static FIO_WRITE_FUNCTION(wanpipe_write)
        if (*datalen == 0) {
                return FTDM_SUCCESS;
        }
+
+       if (ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_IO_STATS) && !ftdmchan->iostats.tx.packets) {
+               wanpipe_tdm_api_t tdm_api;
+               memset(&tdm_api, 0, sizeof(tdm_api));
+               /* if this is the first write ever, flush the tx first to have clean stats */
+               err = sangoma_flush_tx_bufs(ftdmchan->sockfd, &tdm_api);
+               if (err) {
+                       ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Failed to flush on first write\n");
+               }
+       }
+
        bsent = sangoma_writemsg_tdm(ftdmchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen),0);
 
        /* should we be checking if bsent == *datalen here? */