Exemple #1
0
int main(int argc, char *argv[])
{
	mmatic *mm;
	struct flowcalc *fc;
	void *h;
	struct module *mod;
	char *name, *s;
	tlist *ls;
	void *pdata;

	/*
	 * initialization
	 */
	mm = mmatic_create();
	fc = mmatic_zalloc(mm, sizeof *fc);
	fc->mm = mm;
	fc->modules = tlist_create(NULL, mm);

	/* read options */
	if (parse_argv(fc, argc, argv))
		return 1;

	/* enable all modules found in given directory */
	if (tlist_count(fc->modules) == 0) {
		ls = pjf_ls(fc->dir, mm);
		tlist_iter_loop(ls, name) {
			s = strrchr(name, '.');
			if (s && streq(s, ".so")) {
				*s = 0;
				tlist_push(fc->modules, name);
			}
		}
Exemple #2
0
struct spi_ep *ep_new_pkt(struct spi_source *source, spi_epaddr_t epa,
	const struct timeval *ts, void *data, uint32_t size)
{
	struct spi *spi = source->spi;
	struct spi_ep *ep;
	char *key;
	struct spi_pkt *pkt;
	mmatic *mm;

	key = _k(source, epa);
	ep = thash_get(spi->eps, key);
	if (!ep) {
		mm = mmatic_create();
		ep = mmatic_zalloc(mm, sizeof *ep);
		ep->mm = mm;
		ep->source = source;
		ep->epa = epa;
		thash_set(spi->eps, key, ep);

		source->eps++;

		dbg(8, "new ep %s\n", spi_epa2a(epa));
	}

	/* make packet */
	pkt = mmatic_zalloc(ep->mm, sizeof *pkt);
	pkt->size = size;
	pkt->payload = mmatic_zalloc(ep->mm, spi->options.N);
	memcpy(pkt->payload, data, spi->options.N);
	memcpy(&pkt->ts, ts, sizeof(struct timeval));

	/* update last packet time */
	memcpy(&ep->last, ts, sizeof(struct timeval));

	/* store packet */
	if (!ep->pkts)
		ep->pkts = tlist_create(mmatic_free, ep->mm);

	tlist_push(ep->pkts, pkt);

	/* generate event if pkts big enough */
	if (ep->gclock1 == 0 && tlist_count(ep->pkts) >= spi->options.C) {
		ep->gclock1++;
		spi_announce(spi, "endpointPacketsReady", 0, ep, false);
		dbg(7, "ep %s ready\n", spi_epa2a(epa));
	}

	return ep;
}
Exemple #3
0
tlist *tlist_listify(void (*free_func)(void *val), mmatic *mm, ...)
{
	va_list args;
	const void *arg;
	tlist *ret;

	ret = MMTLIST_CREATE(free_func);
	if (!ret) return NULL;

	va_start(args, mm);
	while ((arg = va_arg(args, const void *))) tlist_push(ret, arg);
	va_end(args);

	return ret;
}
Exemple #4
0
tlist *asn_fcparselist(const char *listorder, mmatic *mm)
{
	char *buf;
	int i, j, l;
	tlist *ret;
	struct fcel *el;

	ret = MMTLIST_CREATE(NULL);

	if (!listorder) return ret;

	buf = mmstrdup(listorder);
	l = strlen(buf);

	for (i = 0; i < l; i = j + 1) {
		/* skip rubbish */
		while (buf[i] && !(buf[i] == '#' || (buf[i] >= '0' && buf[i] <= '9'))) i++;
		if (!buf[i]) break;

		el = mmalloc(sizeof(*el));

		/* skip comment */
		if (buf[i] == '#')
			el->enabled = false, i++;
		else
			el->enabled = true;

		/* read elid */
		for (j = i; buf[j] >= '0' && buf[j] <= '9'; j++);
		buf[j] = '\0';
		el->elid = strtoul(buf + i, NULL, 10);

		for (i = ++j; buf[j] && buf[j] != '\n'; j++);
		buf[j] = '\0';
		el->elname = buf + i; /* XXX: @mm */

		tlist_push(ret, el);
	}

	return ret;
}
Exemple #5
0
/** Parses arguments and loads modules
 * @retval 0     ok
 * @retval 1     error, main() should exit (eg. wrong arg. given)
 * @retval 2     ok, but main() should exit (eg. on --version or --help) */
static int parse_argv(struct flowcalc *fc, int argc, char *argv[])
{
	int i, c;
	char *d, *s;

	static char *short_opts = "hvVf:r:d:e:an:t:l";
	static struct option long_opts[] = {
		/* name, has_arg, NULL, short_ch */
		{ "verbose",    0, NULL,  1  },
		{ "debug",      1, NULL,  2  },
		{ "help",       0, NULL,  3  },
		{ "version",    0, NULL,  4  },
		{ 0, 0, 0, 0 }
	};

	/* defaults */
	debug = 0;
	fc->dir = MYDIR;

	for (;;) {
		c = getopt_long(argc, argv, short_opts, long_opts, &i);
		if (c == -1) break; /* end of options */

		switch (c) {
			case 'V':
			case  1 : debug = 5; break;
			case  2 : debug = atoi(optarg); break;
			case 'h':
			case  3 : help(); return 2;
			case 'v':
			case  4 : version(); return 2;
			case 'f': fc->filter = mmatic_strdup(fc->mm, optarg); break;
			case 'r': fc->relation = mmatic_strdup(fc->mm, optarg); break;
			case 'd': fc->dir = mmatic_strdup(fc->mm, optarg); break;
			case 'e':
				s = mmatic_strdup(fc->mm, optarg);
				while ((d = strchr(s, ','))) {
					*d = 0;
					tlist_push(fc->modules, s);
					s = d + 1;
				}
				tlist_push(fc->modules, s);
				break;
			case 'l': fc->list = true; break;
			case 'a': fc->any = true; break;
			case 'n': fc->n = strtoul(optarg, NULL, 10); break;
			case 't': fc->t = strtod(optarg, NULL); break;
			default: help(); return 1;
		}
	}

	if (fc->list) {
		tlist_flush(fc->modules);
		return 0;
	}

	if (argc - optind > 0) {
		fc->file = mmatic_strdup(fc->mm, argv[optind]);
	} else {
		help();
		return 1;
	}

	return 0;
}