On Fri, Sep 09, 2011 at 03:05:26AM +0200, [email protected] wrote:
> From: Pablo Neira Ayuso <[email protected]>
> 
> Hi,
> 
> These patchset contains the port of libctrl to use the IPA
> infrastructure available in libosmo-abis.
> 
> I've also made one small cleanup to bail out in case that
> we cannot bind to the telnet port. Another patch follows up
> to avoid disabling nagle (to avoid problems with TCP
> segmentation, we still have to support this appropriately),
> I noticed this while doing the port work.
> 
> Pablo Neira Ayuso (3):
>   ctrl: use generic IPA socket infrastructure available in libosmo-abis
>   src: check for error returned by controlif_setup()
>   ctrl: do not disable nagle algorithm until we fully support
>     segmentation

I forgot to say that they are available in the pablo/ctrl-updates
branch.

BTW, I have used the following command line interactive client to test
the changes. I made it because I wanted to test the IPA socket
infrastructure from the client side. Just in case you find it of any
use. You can find it attached.
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include <osmocom/core/talloc.h>
#include <osmocom/abis/abis.h>
#include <osmocom/abis/e1_input.h>
#include <osmocom/abis/ipa.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/application.h>
#include <osmocom/vty/vty.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/gsm/protocol/ipaccess.h>

static void *tall_test;

#define DCTRL_TEST 0

struct log_info_cat ctrl_test_cat[] = {
	[DCTRL_TEST] = {
		.name = "DLINP_CTRL_TEST",
		.description = "IPA proxy test",
		.color = "\033[1;35m",
		.enabled = 1, .loglevel = LOGL_NOTICE,
	},
};

const struct log_info ctrl_test_log_info = {
	.filter_fn = NULL,
	.cat = ctrl_test_cat,
	.num_cat = ARRAY_SIZE(ctrl_test_cat),
};

static struct msgb *msg_alloc(void)
{
        struct msgb *msg;
	int headroom;

        headroom += sizeof(struct ipaccess_head) +
		    sizeof(struct ipaccess_head_ext);

        msg = msgb_alloc_headroom(1200 + headroom, headroom, "Abis/IP");
        if (!msg)
                return NULL;

	return msg;
}

static int ipaccess_cb(struct ipa_client_conn *link, struct msgb *msg)
{
	char *payload = msg->data + sizeof(struct ipaccess_head)
				  + sizeof(struct ipaccess_head_ext);

	printf("%s\n", payload);

	return 0;
}

static struct ipa_client_conn *ipa_conn;

static int kbd_cb(struct osmo_fd *fd, unsigned int what)
{
	char buf[1024];
	struct msgb *msg;
	uint8_t *data;
	int ret;
        struct ipaccess_head *hh;

	ret = read(STDIN_FILENO, buf, sizeof(buf));

	LOGP(DCTRL_TEST, LOGL_NOTICE, "read %d byte from keyboard\n", ret);

	msg = msg_alloc();
	if (!msg) {
		exit(EXIT_FAILURE);
	}
	data = msgb_put(msg, strlen(buf)-1);
	memcpy(data, buf, strlen(buf)-1);

        ipaccess_prepend_header_ext(msg, IPAC_PROTO_EXT_CTRL);
        ipaccess_prepend_header(msg, IPAC_PROTO_OSMO);

	LOGP(DCTRL_TEST, LOGL_NOTICE, "message of %d bytes sent\n", msg->len);

	ipa_client_conn_send(fd->data, msg);
	return 0;
}

int main(void)
{
	struct osmo_fd *kbd_ofd;

	tall_test = talloc_named_const(NULL, 1, "ipa proxy test");
	libosmo_abis_init(tall_test);

	osmo_init_logging(&ctrl_test_log_info);

	LOGP(DCTRL_TEST, LOGL_NOTICE, "entering main loop\n");

	ipa_conn = ipa_client_conn_create(tall_test,
					  NULL, 0,
					  "127.0.0.1", 4249,
					  NULL,
					  ipaccess_cb,
					  NULL,
					  NULL);
	if (!ipa_conn) {
		LOGP(DCTRL_TEST, LOGL_ERROR, "OOM\n");
		exit(EXIT_FAILURE);
	}

	if (ipa_client_conn_open(ipa_conn) < 0) {
		LOGP(DCTRL_TEST, LOGL_ERROR, "cannot open client: %s\n",
			strerror(errno));
		ipa_client_conn_close(ipa_conn);
		ipa_client_conn_destroy(ipa_conn);
		exit(EXIT_FAILURE);
	}

	kbd_ofd = talloc_zero(tall_test, struct osmo_fd);
	if (!kbd_ofd) {
		LOGP(DCTRL_TEST, LOGL_ERROR, "OOM\n");
		exit(EXIT_FAILURE);
	}
	kbd_ofd->fd = STDIN_FILENO;
	kbd_ofd->when = BSC_FD_READ;
	kbd_ofd->data = ipa_conn;
	kbd_ofd->cb = kbd_cb;
	osmo_fd_register(kbd_ofd);

	while (1) {
		osmo_select_main(0);
	}
}

Reply via email to