Exemplo n.º 1
0
void
ccnl_client_TX(char node, char *name, int seqn, int nonce)
{
    char tmp[512];
    struct ccnl_prefix_s *p;
    struct ccnl_buf_s *buf;
    struct ccnl_relay_s *relay = char2relay(node);

    DEBUGMSG(TRACE, "ccnl_client_tx node=%c: request %s #%d\n",
             node, name, seqn);

    if (!relay)
        return;

    sprintf(tmp, "%s/.%d", name, seqn);
    //    p = ccnl_path_to_prefix(tmp);
    //    p->suite = suite;
    p = ccnl_URItoPrefix(tmp, theSuite, NULL, NULL);
    DEBUGMSG(TRACE, "  create interest for %s\n", ccnl_prefix_to_path(p));
    buf = ccnl_mkSimpleInterest(p, &nonce);
    free_prefix(p);

    // inject it into the relay:
    if (buf) {
        ccnl_core_RX(relay, -1, buf->data, buf->datalen, 0, 0);
        ccnl_free(buf);
    }
}
Exemplo n.º 2
0
void
ccnl_io_loop(struct ccnl_relay_s *ccnl)
{
    int i, maxfd = -1, rc;
    fd_set readfs, writefs;

    if (ccnl->ifcount == 0) {
        fprintf(stderr, "no socket to work with, not good, quitting\n");
        exit(EXIT_FAILURE);
    }
    for (i = 0; i < ccnl->ifcount; i++)
        if (ccnl->ifs[i].sock > maxfd)
            maxfd = ccnl->ifs[i].sock;
    maxfd++;

    FD_ZERO(&readfs);
    FD_ZERO(&writefs);
    while(!ccnl->halt_flag) {
        struct timeval *timeout;

        for (i = 0; i < ccnl->ifcount; i++) {
            FD_SET(ccnl->ifs[i].sock, &readfs);
            if (ccnl->ifs[i].qlen > 0)
                FD_SET(ccnl->ifs[i].sock, &writefs);
            else
                FD_CLR(ccnl->ifs[i].sock, &writefs);
        }

        timeout = ccnl_run_events();
        rc = select(maxfd, &readfs, &writefs, NULL, timeout);
        if (rc < 0) {
            perror("select(): ");
            exit(EXIT_FAILURE);
        }

        for (i = 0; i < ccnl->ifcount; i++) {
            if (FD_ISSET(ccnl->ifs[i].sock, &readfs)) {
                sockunion src_addr;
                socklen_t addrlen = sizeof(sockunion);
                unsigned char buf[CCNL_MAX_PACKET_SIZE];
                int len;
                if ((len = recvfrom(ccnl->ifs[i].sock, buf, sizeof(buf), 0,
                                (struct sockaddr*) &src_addr, &addrlen)) > 0)
                    ccnl_core_RX(ccnl, i, buf, len, &src_addr.sa, sizeof(src_addr.ip4));
            }
            if (FD_ISSET(ccnl->ifs[i].sock, &writefs))
                ccnl_interface_CTS(&theRelay, &theRelay.ifs[0]);
        }
    }
}
Exemplo n.º 3
0
JNIEXPORT void JNICALL
Java_ch_unibas_ccn_1lite_1android_CcnLiteAndroid_relayRX(JNIEnv* env,
                                                         jobject thiz,
                                                         jbyteArray addr,
                                                         jbyteArray data)
{
    int len;
    unsigned char buf[1024];
    sockunion su;

    len = (*env)->GetArrayLength(env, data);
    DEBUGMSG(DEBUG, "relayRX: %d bytes\n", len);

    memset(&su, 0, sizeof(su));
    su.linklayer.sll_family = AF_PACKET;
    (*env)->GetByteArrayRegion(env, addr, 0, ETH_ALEN,
                               (signed char*) &su.linklayer.sll_addr);

    if (len > sizeof(buf))
        len = sizeof(buf);
    (*env)->GetByteArrayRegion(env, data, 0, len, (signed char*) buf);

    ccnl_core_RX(&theRelay, 0, buf, len, (struct sockaddr*) &su, sizeof(su));

    // hack: when the first packet from the BT LE device is received,
    // (and the FIB is empty), install two forwarding entries
    if (theRelay.faces && (!theRelay.fib || theRelay.fib->tap)) {
        theRelay.faces->flags |= CCNL_FACE_FLAGS_STATIC;
#ifdef USE_SUITE_CCNTLV
        add_route("/TinC", theRelay.faces, CCNL_SUITE_CCNTLV, 20);
        add_route("/TinF", theRelay.faces, CCNL_SUITE_CCNTLV, 20);
#endif
#ifdef USE_SUITE_NDNTLV
        add_route("/TinC", theRelay.faces, CCNL_SUITE_IOTTLV, 20);
        add_route("/TinF", theRelay.faces, CCNL_SUITE_IOTTLV, 20);
#endif
#ifdef USE_SUITE_NDNTLV
        add_route("/TinC", theRelay.faces, CCNL_SUITE_NDNTLV, 20);
        add_route("/TinF", theRelay.faces, CCNL_SUITE_NDNTLV, 20);
#endif
        return;
    }
}
Exemplo n.º 4
0
void
ccnl_simu_ethernet(void *dummy, void *dummy2)
{
    if (etherqueue) {
        int i, qlen;
        struct ccnl_ethernet_s **pp, *p;

        // pick the last element in the queue
        for (qlen = 1, pp = &etherqueue; (*pp)->next; pp = &((*pp)->next))
            qlen++;
        p = *pp;
        *pp = NULL;

        for (i = 0; i < 5; i++) {
            if (!memcmp(p->dst, &relays[i].ifs[0].addr.eth.sll_addr, ETH_ALEN)) {
                break;
            }
        }
        if (i < 5) {
            sockunion sun;

            sun.sa.sa_family = AF_PACKET;
            memcpy(sun.eth.sll_addr, p->src, ETH_ALEN);

            DEBUGMSG(DEBUG, "simu_ethernet: sending %d Bytes to %s, (qlen=%d)\n",
                     p->len, eth2ascii(p->dst), qlen);

            ccnl_core_RX(relays + i, 0, (unsigned char*) p->data,
                        p->len, &sun.sa, sizeof(sun.eth));
        } else {
            DEBUGMSG(WARNING, "simu_ethernet: dest %s not found\n",
                     eth2ascii(etherqueue->dst));
        }
        ccnl_free(p);
    }
    ccnl_set_timer(2000, ccnl_simu_ethernet, dummy, dummy2);
}
Exemplo n.º 5
0
int
ccnl_io_loop(struct ccnl_relay_s *ccnl)
{
    int i, maxfd = -1, rc;
    fd_set readfs, writefs;
    unsigned char buf[CCNL_MAX_PACKET_SIZE];
    int len;
    
    if (ccnl->ifcount == 0) {
	fprintf(stderr, "no socket to work with, not good, quitting\n");
	exit(EXIT_FAILURE);
    }
    for (i = 0; i < ccnl->ifcount; i++)
	if (ccnl->ifs[i].sock > maxfd)
	    maxfd = ccnl->ifs[i].sock;
    maxfd++;

    DEBUGMSG(1, "starting main event and IO loop\n");
    while(!ccnl->halt_flag) {
	struct timeval *timeout;

	FD_ZERO(&readfs);
	FD_ZERO(&writefs);

#ifdef USE_HTTP_STATUS
	ccnl_http_anteselect(ccnl, ccnl->http, &readfs, &writefs, &maxfd);
#endif
	for (i = 0; i < ccnl->ifcount; i++) {
	    FD_SET(ccnl->ifs[i].sock, &readfs);
	    if (ccnl->ifs[i].qlen > 0)
		FD_SET(ccnl->ifs[i].sock, &writefs);
	}

	timeout = ccnl_run_events();
	rc = select(maxfd, &readfs, &writefs, NULL, timeout);

	if (rc < 0) {
	    perror("select(): ");
	    exit(EXIT_FAILURE);
	}

#ifdef USE_HTTP_STATUS
	ccnl_http_postselect(ccnl, ccnl->http, &readfs, &writefs);
#endif
	for (i = 0; i < ccnl->ifcount; i++) {
	    if (FD_ISSET(ccnl->ifs[i].sock, &readfs)) {
		sockunion src_addr;
		socklen_t addrlen = sizeof(sockunion);
		if ((len = recvfrom(ccnl->ifs[i].sock, buf, sizeof(buf), 0,
				(struct sockaddr*) &src_addr, &addrlen)) > 0) {
                    
		    if (src_addr.sa.sa_family == AF_INET) {
			ccnl_core_RX(ccnl, i, buf, len,
				     &src_addr.sa, sizeof(src_addr.ip4));
		    }
#ifdef USE_ETHERNET
		    else if (src_addr.sa.sa_family == AF_PACKET) {
			if (len > 14)
			    ccnl_core_RX(ccnl, i, buf+14, len-14,
					 &src_addr.sa, sizeof(src_addr.eth));
		    }
#endif
#ifdef USE_UNIXSOCKET
		    else if (src_addr.sa.sa_family == AF_UNIX) {
			ccnl_core_RX(ccnl, i, buf, len,
				     &src_addr.sa, sizeof(src_addr.ux));
		    }
#endif
		}
	    }

	    if (FD_ISSET(ccnl->ifs[i].sock, &writefs)) {
	      ccnl_interface_CTS(ccnl, ccnl->ifs + i);
	    }
	}
    }

    return 0;
}
Exemplo n.º 6
0
int ccnl_io_loop(struct ccnl_relay_s *ccnl)
{
    if (ccnl->ifcount == 0) {
        DEBUGMSG(1, "no socket to work with, not good, quitting\n");
        return -1;
    }

    DEBUGMSG(1, "starting main event and IO loop\n");

    if (msg_init_queue(msg_buffer_relay, RELAY_MSG_BUFFER_SIZE) != 0) {
        DEBUGMSG(1, "msg init queue failed...abording\n");
        return -1;
    }

    msg_t in;
    radio_packet_t *p;
    riot_ccnl_msg_t *m;

    while (!ccnl->halt_flag) {

        msg_receive(&in);

        mutex_lock(&ccnl->global_lock);
        switch (in.type) {
            case PKT_PENDING:
                /* msg from transceiver */
                p = (radio_packet_t *) in.content.ptr;
                DEBUGMSG(1, "\tLength:\t%u\n", p->length);
                DEBUGMSG(1, "\tSrc:\t%u\n", p->src);
                DEBUGMSG(1, "\tDst:\t%u\n", p->dst);

                // p->src must be > 0
                if (!p->src) {
                    p->src = RIOT_BROADCAST;
                }

                ccnl_core_RX(ccnl, RIOT_TRANS_IDX, (unsigned char *) p->data, (int) p->length, p->src);
                p->processing--;
                break;

            case (CCNL_RIOT_MSG):
                /* msg from device local client */
                m = (riot_ccnl_msg_t *) in.content.ptr;
                DEBUGMSG(1, "\tLength:\t%u\n", m->size);
                DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid);

                ccnl_core_RX(ccnl, RIOT_MSG_IDX, (unsigned char *) m->payload, m->size,
                             in.sender_pid);
                break;

            case (CCNL_RIOT_HALT):
                /* cmd to stop the relay */
                DEBUGMSG(1, "\tSrc:\t%" PRIkernel_pid "\n", in.sender_pid);
                DEBUGMSG(1, "\tNumb:\t%" PRIu32 "\n", in.content.value);

                ccnl->halt_flag = 1;
                break;

#if RIOT_CCNL_POPULATE
            case (CCNL_RIOT_POPULATE):
                /* cmd to polulate the cache */
                DEBUGMSG(1, "\tSrc:\t%" PRIkernel_pid "\n", in.sender_pid);
                DEBUGMSG(1, "\tNumb:\t%" PRIu32 "\n", in.content.value);

                handle_populate_cache(ccnl);
                break;
#endif
#if ENABLE_DEBUG
            case (CCNL_RIOT_PRINT_STAT):
                /* cmd to print face statistics */
                for (struct ccnl_face_s *f = ccnl->faces; f; f = f->next) {
                    ccnl_face_print_stat(f);
                }
                break;
#endif
            case (CCNL_RIOT_CONFIG_CACHE):
                /* cmd to configure the size of the cache at runtime */
                ccnl->max_cache_entries = in.content.value;
                DEBUGMSG(1, "max_cache_entries set to %d\n", ccnl->max_cache_entries);
                break;
            case (ENOBUFFER):
                /* transceiver has not enough buffer to store incoming packets, one packet is dropped  */
                DEBUGMSG(1, "transceiver: one packet is dropped because buffers are full\n");
                break;
            default:
                DEBUGMSG(1, "%s Packet waiting\n", riot_ccnl_event_to_string(in.type));
                DEBUGMSG(1, "\tSrc:\t%" PRIkernel_pid "\n", in.sender_pid);
                DEBUGMSG(1, "\tdropping it...\n");
                break;
        }
        mutex_unlock(&ccnl->global_lock);
    }

    return 0;
}