void ccnl_simu_cleanup(void *dummy, void *dummy2) { printf("Simulation ended; press ENTER to terminate\n"); while (getchar() != '\n'); int i; for (i = 0; i < 5; i++) { struct ccnl_relay_s *relay = relays + i; if (relay->aux) { ccnl_free(relay->aux); relay->aux = NULL; } ccnl_core_cleanup(relay); } while(eventqueue) ccnl_rem_timer(eventqueue); while(etherqueue) { struct ccnl_ethernet_s *e = etherqueue->next; ccnl_free(etherqueue); etherqueue = e; } #ifdef USE_SCHEDULER ccnl_sched_cleanup(); #endif #ifdef USE_DEBUG_MALLOC debug_memdump(); #endif }
/** * @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; }
// callback from the chemflow engine when a timer for the first reaction shall be set/changed/canceled static int ccnl_sched_cf_engine_set_timer(struct cf_engine *e, void *userptr, cf_time time) { struct timeval tv; DEBUGMSG(TRACE, "%s()\n", __FUNCTION__); // stop the currently running timer if (engine_timer) { ccnl_rem_timer(engine_timer); engine_timer = NULL; } // start the timer if (time < CF_TIME_INF) { tv.tv_sec = cf_u64_div(time, 1000000000); tv.tv_usec = cf_u64_mod(time, 1000000000) / 1000; engine_timer = ccnl_set_absolute_timer(tv, ccnl_sched_cf_timeout, NULL, NULL); } return CF_OK; }
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; }
void ccnl_simu_client_RX(struct ccnl_relay_s *relay, char *name, int seqn, char *data, int len) // receiving side { char node = relay2char(relay); struct ccnl_client_s *cl = relay->aux; int i; DEBUGMSG(INFO, "*** node %c received %d content bytes for name %s, seq=%d\n", node, len, name, seqn); if (strcmp(name, cl->name)) { DEBUGMSG(WARNING, "*** content name does not match our request!!\n" " <%s> instead of <%s>\n", name, cl->name); return; } for (i = 0; i < MAX_PIPELINE; i++) { if (cl->onthefly[i] == seqn) break; } if (i == MAX_PIPELINE) // must be old content, ignore return; if (seqn != (cl->last_received+1)) { DEBUGMSG(INFO, "*** content %d out of sequence (expected %d)\n", seqn, cl->last_received+1); cl->outofseq++; } cl->last_received = seqn; if (cl->to_handlers[i]) { ccnl_rem_timer(cl->to_handlers[i]); cl->to_handlers[i] = 0; } if (cl->nextseq > cl->lastseq) { DEBUGMSG(INFO, "*** node %c, client thread %d terminated, %d remaining\n", node, i, cl->threadcnt-1); cl->onthefly[i] = -1; cl->threadcnt--; if (cl->threadcnt <= 0) { pending_client_tasks--; DEBUGMSG(INFO, "task for node %c ended, %d retransmit(s), %d outofseq /%d\n", node, cl->retries, cl->outofseq, pending_client_tasks); if (pending_client_tasks <= 0) { if (phaseOne == 1){ DEBUGMSG(INFO, "Enter Phase-TWO (by node %c)\n\n", node); //make a fake zero log ccnl_set_timer(500000, ccnl_simu_phase_two, 0, 0); } else { DEBUGMSG(INFO, "all tasks of phase two terminated\n"); for (i = 0; i < MAX_PIPELINE; i++) { if (cl->to_handlers[i]) { ccnl_rem_timer(cl->to_handlers[i]); cl->to_handlers[i] = 0; } } // wait a little before cleaning up // (e.g. eth drive to drain its queue) ccnl_set_timer(2000000, ccnl_simu_cleanup, 0, 0); } } } return; } cl->onthefly[i] = cl->nextseq; cl->nextseq++; cl->nonces[i] = random(); cl->to_handlers[i] = ccnl_set_timer(TIMEOUT, ccnl_simu_client_timeout, relay, cl->to_handlers + i); ccnl_client_TX(node, cl->name, cl->onthefly[i], cl->nonces[i]); }
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; }