Exemple #1
0
/**
 * @brief initializing routing system
 * @param pointer to count transceiver pids
 *
 */
void *ccnl_riot_relay_start(void *arg)
{
    (void) arg;

    theRelay = calloc(1, sizeof(struct ccnl_relay_s));
    ccnl_get_timeval(&theRelay->startup_time);
    theRelay->riot_pid = sched_active_pid;
    mutex_init(&theRelay->global_lock);

    DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", theRelay->startup_time.tv_sec, theRelay->startup_time.tv_usec);
    DEBUGMSG(1, "  compile time: %s %s\n", __DATE__, __TIME__);
    DEBUGMSG(1, "  max_cache_entries: %d\n", CCNL_DEFAULT_MAX_CACHE_ENTRIES);
    DEBUGMSG(1, "  threshold_prefix: %d\n", CCNL_DEFAULT_THRESHOLD_PREFIX);
    DEBUGMSG(1, "  threshold_aggregate: %d\n", CCNL_DEFAULT_THRESHOLD_AGGREGATE);

    ccnl_relay_config(theRelay, CCNL_DEFAULT_MAX_CACHE_ENTRIES, CCNL_DEFAULT_THRESHOLD_PREFIX, CCNL_DEFAULT_THRESHOLD_AGGREGATE);

    theRelay->riot_helper_pid = riot_start_helper_thread();

    ccnl_io_loop(theRelay);
    DEBUGMSG(1, "ioloop stopped\n");

    while (eventqueue) {
        ccnl_rem_timer(eventqueue);
    }

    ccnl_core_cleanup(theRelay);

    mutex_lock(&theRelay->stop_lock);
    ccnl_free(theRelay);
    return NULL;
}
int
main(int argc, char **argv)
{
    int opt;
    int max_cache_entries = -1;
    int udpport = CCN_UDP_PORT;
    int tcpport = CCN_UDP_PORT;
    char *datadir = NULL;
    char *ethdev = NULL;
    char *crypto_sock_path = 0;
#ifdef USE_UNIXSOCKET
    char *uxpath = CCNL_DEFAULT_UNIXSOCKNAME;
#else
    char *uxpath = NULL;
#endif

    time(&theRelay.startup_time);
    srandom(time(NULL));

    while ((opt = getopt(argc, argv, "hc:d:e:g:i:s:u:v:x:p:")) != -1) {
        switch (opt) {
        case 'c':
            max_cache_entries = atoi(optarg);
            break;
        case 'd':
            datadir = optarg;
            break;
        case 'e':
            ethdev = optarg;
            break;
        case 'g':
            inter_pkt_interval = atoi(optarg);
            break;
        case 'i':
            inter_ccn_interval = atoi(optarg);
            break;
        case 's':
            tcpport = atoi(optarg);
            break;
        case 'u':
            udpport = atoi(optarg);
            break;
        case 'v':
            debug_level = atoi(optarg);
            break;
        case 'x':
            uxpath = optarg;
            break;
        case 'p':
            crypto_sock_path = optarg;
            break;
        case 'h':
        default:
            fprintf(stderr,
		    "usage: %s [-h] [-c MAX_CONTENT_ENTRIES]"
		    " [-d databasedir]"
		    " [-e ethdev]"
		    " [-g MIN_INTER_PACKET_INTERVAL]"
		    " [-i MIN_INTER_CCNMSG_INTERVAL]"
		    " [-s tcpport]"
		    " [-u udpport]"
		    " [-v DEBUG_LEVEL]"

#ifdef USE_UNIXSOCKET
                    " [-p crypto_face_ux_socket]"
		    " [-x unixpath]"
#endif
		    "\n", argv[0]);
            exit(EXIT_FAILURE);
        }
    }

    DEBUGMSG(1, "This is ccn-lite-relay, starting at %s", ctime(&theRelay.startup_time) + 4);
    DEBUGMSG(1, "  ccnl-core: %s\n", CCNL_VERSION);
    DEBUGMSG(1, "  compile time: %s %s\n", __DATE__, __TIME__);
    DEBUGMSG(1, "  compile options: %s\n", compile_string());

    ccnl_relay_config(&theRelay, ethdev, udpport, tcpport,
		      uxpath, max_cache_entries, crypto_sock_path);
    if (datadir)
	ccnl_populate_cache(&theRelay, datadir);
    
    ccnl_io_loop(&theRelay);

    while (eventqueue)
	ccnl_rem_timer(eventqueue);
    ccnl_core_cleanup(&theRelay);
#ifdef USE_HTTP_STATUS
    theRelay.http = ccnl_http_cleanup(theRelay.http);
#endif
#ifdef USE_DEBUG_MALLOC
    debug_memdump();
#endif

    return 0;
}
int
main(int argc, char **argv)
{
    int opt, max_cache_entries = -1, httpport = -1;
    int udpport1 = -1, udpport2 = -1;
    char *datadir = NULL, *ethdev = NULL, *crypto_sock_path = NULL;
#ifdef USE_UNIXSOCKET
    char *uxpath = CCNL_DEFAULT_UNIXSOCKNAME;
#else
    char *uxpath = NULL;
#endif
#ifdef USE_ECHO
    char *echopfx = NULL;
#endif

    time(&theRelay.startup_time);
    srandom(time(NULL));

    while ((opt = getopt(argc, argv, "hc:d:e:g:i:o:p:s:t:u:v:x:")) != -1) {
        switch (opt) {
        case 'c':
            max_cache_entries = atoi(optarg);
            break;
        case 'd':
            datadir = optarg;
            break;
        case 'e':
            ethdev = optarg;
            break;
        case 'g':
            inter_pkt_interval = atoi(optarg);
            break;
        case 'i':
            inter_ccn_interval = atoi(optarg);
            break;
#ifdef USE_ECHO
        case 'o':
            echopfx = optarg;
            break;
#endif
        case 'p':
            crypto_sock_path = optarg;
            break;
        case 's':
            suite = ccnl_str2suite(optarg);
            if (!ccnl_isSuite(suite))
                goto usage;
            break;
        case 't':
            httpport = atoi(optarg);
            break;
        case 'u':
            if (udpport1 == -1)
                udpport1 = atoi(optarg);
            else
                udpport2 = atoi(optarg);
            break;
        case 'v':
#ifdef USE_LOGGING
            if (isdigit(optarg[0]))
                debug_level = atoi(optarg);
            else
                debug_level = ccnl_debug_str2level(optarg);
#endif
            break;
        case 'x':
            uxpath = optarg;
            break;
        case 'h':
        default:
usage:
            fprintf(stderr,
                    "usage: %s [options]\n"
                    "  -c MAX_CONTENT_ENTRIES\n"
                    "  -d databasedir\n"
                    "  -e ethdev\n"
                    "  -g MIN_INTER_PACKET_INTERVAL\n"
                    "  -h\n"
                    "  -i MIN_INTER_CCNMSG_INTERVAL\n"
#ifdef USE_ECHO
                    "  -o echo_prefix\n"
#endif
                    "  -p crypto_face_ux_socket\n"
                    "  -s SUITE (ccnb, ccnx2015, cisco2015, iot2014, ndn2013)\n"
                    "  -t tcpport (for HTML status page)\n"
                    "  -u udpport (can be specified twice)\n"

#ifdef USE_LOGGING
                    "  -v DEBUG_LEVEL (fatal, error, warning, info, debug, verbose, trace)\n"
#endif
#ifdef USE_UNIXSOCKET
                    "  -x unixpath\n"
#endif
                    , argv[0]);
            exit(EXIT_FAILURE);
        }
    }

    opt = ccnl_suite2defaultPort(suite);
    if (udpport1 < 0)
        udpport1 = opt;
    if (httpport < 0)
        httpport = opt;

    ccnl_core_init();

    DEBUGMSG(INFO, "This is ccn-lite-relay, starting at %s",
             ctime(&theRelay.startup_time) + 4);
    DEBUGMSG(INFO, "  ccnl-core: %s\n", CCNL_VERSION);
    DEBUGMSG(INFO, "  compile time: %s %s\n", __DATE__, __TIME__);
    DEBUGMSG(INFO, "  compile options: %s\n", compile_string);
    DEBUGMSG(INFO, "Abhinav - Modified CCN lite");
//    DEBUGMSG(INFO, "using suite %s\n", ccnl_suite2str(suite));

    ccnl_relay_config(&theRelay, ethdev, udpport1, udpport2, httpport,
                      uxpath, suite, max_cache_entries, crypto_sock_path);
    if (datadir)
        ccnl_populate_cache(&theRelay, datadir);

#ifdef USE_ECHO
    if (echopfx) {
        struct ccnl_prefix_s *pfx;
        char *dup = ccnl_strdup(echopfx);

        pfx = ccnl_URItoPrefix(dup, suite, NULL, NULL);
        if (pfx)
            ccnl_echo_add(&theRelay, pfx);
        ccnl_free(dup);
    }
#endif

    ccnl_io_loop(&theRelay);

    while (eventqueue)
        ccnl_rem_timer(eventqueue);

    ccnl_core_cleanup(&theRelay);
#ifdef USE_HTTP_STATUS
    theRelay.http = ccnl_http_cleanup(theRelay.http);
#endif
#ifdef USE_DEBUG_MALLOC
    debug_memdump();
#endif

    return 0;
}