[Asterisk-Users] TDM users: modified zttest.c for testing

Rich Adamson radamson at routers.com
Tue May 3 08:48:38 MST 2005


TDM & X100P card users:

Attached is a modified zaptel/zttest.c app called "attest-mod.c". It
has been modified to report the "delay" in receiving 8,192 bytes
from the TDM card (instead of reporting a percentage). It works with
the digium x100p cards as well.

Drop the attachment in your zaptel directory and compile it with:
  gcc zttest-mod.c -o zttest-mod.o
Then run the executable like this:
  ./zttest-mod.o -v
and report the results.

The output should look like:
8192 bytes in 1.023843 seconds
8192 bytes in 1.023866 seconds
8192 bytes in 1.023853 seconds
8192 bytes in 1.023876 seconds
8192 bytes in 1.023841 secondsr
--- Results after 5 passes ---
Best: 1.023876 -- Worst: 1.023841 -- Average: 1.023856

The design objective of the TDM (and x100p) cards was to transfer
8,192 bytes of data from the card in exactly 1.00000 seconds.
The above sample indicates my system required 1.023856 seconds to
accomplish this, or 23856 microseconds too late.

Since the data transfer is to late, it implies that one frame of 
data (or 1,024 bytes) will be dropped every 5.2 seconds on average
(or, one frame dropped for every 42 received). 

I'm about 90% sure that's why spandsp does not function correctly
and probably impacts how well the echo canceller works in some 
cases as well.

It would be very interesting to see everyone's results in running
this, and even more interesting to report the results with the OS
distro in use, mobo in use (if known), etc. If anyone actually
get's a result that is very close to 1.000 seconds, I'd really
like to know more about those systems. (email off list is fine
if you want.)

Rich
-------------- next part --------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/signal.h>
#include <math.h>

#define SIZE 8000

static int pass = 0;
static float best = 0.0;
static float worst = 100.0;
static float total = 0.0;

void hup_handler(int sig)
{
	printf("\n--- Results after %d passes ---\n", pass);
	printf("Best: %f -- Worst: %f -- Average: %f\n", best, worst, pass ? total/pass : 100.00);
	exit(0);
}

int main(int argc, char *argv[])
{
	int fd;
	int res;
	int count=0;
	float ms;
	int sec;
	int curarg = 1;
	int verbose=0;
	char buf[8192];
	float score;
	struct timeval start, now;
	fd = open("/dev/zap/pseudo", O_RDWR);
	if (fd < 0) {
		fprintf(stderr, "Unable to open zap interface: %s\n", strerror(errno));
		exit(1);
	}
	while(curarg < argc) {
		if (!strcasecmp(argv[curarg], "-v"))
			verbose++;
		curarg++;
	}
	printf("Objective: to read 8192 bytes from TDM card in 1.000000 seconds.\n");
	printf("Opened pseudo zap interface, measuring accuracy...\n");
	signal(SIGHUP, hup_handler);
	signal(SIGINT, hup_handler);
	/* Flush input buffer */
	for (count = 0;count < 4; count++)
		res = read(fd, buf, sizeof(buf));
	count = 0;
	gettimeofday(&start, NULL);
	for(;;) {
		/* res contains the number of bytes read in */
		res = read(fd, buf, sizeof(buf));
		if (res < 0) {
			fprintf(stderr, "Failed to read from pseudo interface: %s\n", strerror(errno));
			exit(1);
		}
		count += res;	/* count = total number of bytes read */
		if (count >= SIZE) {
			gettimeofday(&now, NULL);
			sec = (now.tv_sec - start.tv_sec);
			ms = sec +  ((float)(now.tv_usec - start.tv_usec) / 1000000 );
			start = now;
			score = ms;
			if (verbose)
				printf("\n%d bytes in %f seconds", count, ms);
			else 	{
				printf("%f ", score);
				if ((pass % 8) == 7) printf("\n");
			}
			if (score > best)
				best = score;
			if (score < worst)
				worst = score;
			/* printf("%f ", score); */
			total += score;
			fflush(stdout);
			count = 0;
			pass++;
		}
	}
}


More information about the asterisk-users mailing list