Exemple #1
0
void
ccnl_core_cleanup(struct ccnl_relay_s *ccnl)
{
    int k;

    DEBUGMSG_CORE(TRACE, "ccnl_core_cleanup %p\n", (void *) ccnl);

    while (ccnl->pit)
        ccnl_interest_remove(ccnl, ccnl->pit);
    while (ccnl->faces)
        ccnl_face_remove(ccnl, ccnl->faces); // removes allmost all FWD entries
    while (ccnl->fib) {
        struct ccnl_forward_s *fwd = ccnl->fib->next;
        ccnl_prefix_free(ccnl->fib->prefix);
        ccnl_free(ccnl->fib);
        ccnl->fib = fwd;
    }
    while (ccnl->contents)
        ccnl_content_remove(ccnl, ccnl->contents);
    while (ccnl->nonces) {
        struct ccnl_buf_s *tmp = ccnl->nonces->next;
        ccnl_free(ccnl->nonces);
        ccnl->nonces = tmp;
    }
    for (k = 0; k < ccnl->ifcount; k++)
        ccnl_interface_cleanup(ccnl->ifs + k);
}
Exemple #2
0
void ccnl_core_cleanup(struct ccnl_relay_s *ccnl)
{
    int k;
    DEBUGMSG(99, "ccnl_core_cleanup %p\n", (void *) ccnl);

    while (ccnl->pit) {
        ccnl_interest_remove(ccnl, ccnl->pit);
    }

    while (ccnl->faces) {
        ccnl_face_remove(ccnl, ccnl->faces);    // also removes all FWD entries
    }

    while (ccnl->contents) {
        ccnl_content_remove(ccnl, ccnl->contents);
    }

    while (ccnl->nonces) {
        ccnl_nonce_remove(ccnl, ccnl->nonces);
    }

    for (k = 0; k < ccnl->ifcount; k++) {
        ccnl_interface_cleanup(ccnl->ifs + k);
    }
}
Exemple #3
0
struct ccnl_content_s*
ccnl_content_add2cache(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c)
{
    struct ccnl_content_s *cit;

    DEBUGMSG_CORE(DEBUG, "ccnl_content_add2cache (%d/%d) --> %p = %s [%d]\n",
                  ccnl->contentcnt, ccnl->max_cache_entries,
                  (void*)c, ccnl_prefix_to_path(c->pkt->pfx), (c->pkt->pfx->chunknum)? *(c->pkt->pfx->chunknum) : -1);
    for (cit = ccnl->contents; cit; cit = cit->next) {
        if (c == cit) {
            DEBUGMSG_CORE(DEBUG, "--- Already in cache ---\n");
            return NULL;
        }
    }
#ifdef USE_NACK
    if (ccnl_nfnprefix_contentIsNACK(c))
        return NULL;
#endif
    if (ccnl->max_cache_entries > 0 &&
        ccnl->contentcnt >= ccnl->max_cache_entries) { // remove oldest content
        struct ccnl_content_s *c2;
        int age = 0;
        for (c2 = ccnl->contents; c2; c2 = c2->next)
            if (!(c2->flags & CCNL_CONTENT_FLAGS_STATIC) &&
                                        ((age == 0) || c2->last_used < age))
                age = c2->last_used;
        if (c2)
            ccnl_content_remove(ccnl, c2);
    }
    DBL_LINKED_LIST_ADD(ccnl->contents, c);
    ccnl->contentcnt++;
    return c;
}
Exemple #4
0
void ccnl_do_ageing(void *ptr, void *dummy)
{

    (void) dummy; /* unused */

    struct ccnl_relay_s *relay = (struct ccnl_relay_s *) ptr;
    struct ccnl_interest_s *i = relay->pit;
    struct ccnl_content_s *c = relay->contents;

    struct ccnl_face_s *f = relay->faces;
    struct timeval now;
    ccnl_get_timeval(&now);
    //DEBUGMSG(999, "ccnl_do_ageing %ld:%ld\n", now.tv_sec, now.tv_usec);

    while (i) {
        if (ccnl_is_timed_out(&now, &i->last_used, CCNL_INTEREST_TIMEOUT_SEC,
                CCNL_INTEREST_TIMEOUT_USEC)) {
            if (i->from->ifndx == RIOT_MSG_IDX) {
                /* this interest was requested by an app from this node */
                /* inform this app about this problem */
                riot_send_nack(i->from->faceid);
            }
            i = ccnl_interest_remove(relay, i);
        }
        else {
            i = i->next;
        }
    }

    while (c) {
        if (ccnl_is_timed_out(&now, &c->last_used, CCNL_CONTENT_TIMEOUT_SEC, CCNL_CONTENT_TIMEOUT_USEC)
            && !(c->flags & CCNL_CONTENT_FLAGS_STATIC)) {
            c = ccnl_content_remove(relay, c);
        }
        else {
            c = c->next;
        }
    }

    while (f) {
        if (!(f->flags & CCNL_FACE_FLAGS_STATIC)
            && ccnl_is_timed_out(&now, &f->last_used, CCNL_FACE_TIMEOUT_SEC, CCNL_FACE_TIMEOUT_USEC)) {
            f = ccnl_face_remove(relay, f);
        }
        else {
            f = f->next;
        }
    }

    struct ccnl_forward_s *fwd = relay->fib;
    while (fwd) {
        if (!(fwd->flags & CCNL_FORWARD_FLAGS_STATIC)
            && ccnl_is_timed_out(&now, &fwd->last_used, CCNL_FWD_TIMEOUT_SEC, CCNL_FWD_TIMEOUT_USEC)) {
            fwd = ccnl_forward_remove(relay, fwd);
        }
        else {
            fwd = fwd->next;
        }
    }
}
Exemple #5
0
void
ccnl_do_ageing(void *ptr, void *dummy)
{
    (void) dummy;
    struct ccnl_relay_s *relay = (struct ccnl_relay_s*) ptr;
    struct ccnl_content_s *c = relay->contents;
    struct ccnl_interest_s *i = relay->pit;
    struct ccnl_face_s *f = relay->faces;
    time_t t = CCNL_NOW();
    DEBUGMSG_CORE(TRACE, "ageing t=%d\n", (int)t);

    while (c) {
        if ((c->last_used + CCNL_CONTENT_TIMEOUT) <= t &&
                                !(c->flags & CCNL_CONTENT_FLAGS_STATIC)){
          DEBUGMSG_CORE(TRACE, "AGING: CONTENT REMOVE %p\n", (void*) c);
            c = ccnl_content_remove(relay, c);
        }
        else
            c = c->next;
    }
    while (i) { // CONFORM: "Entries in the PIT MUST timeout rather
                // than being held indefinitely."
        if ((i->last_used + CCNL_INTEREST_TIMEOUT) <= t ||
                                i->retries > CCNL_MAX_INTEREST_RETRANSMIT) {
            DEBUGMSG_CORE(TRACE, "AGING: INTEREST REMOVE %p\n", (void*) i);
            DEBUGMSG_CORE(DEBUG, " timeout: remove interest 0x%p <%s>\n",
                          (void*)i,
                     ccnl_prefix_to_path(i->pkt->pfx));
            i = ccnl_nfn_interest_remove(relay, i);
        } else {
            // CONFORM: "A node MUST retransmit Interest Messages
            // periodically for pending PIT entries."
            DEBUGMSG_CORE(DEBUG, " retransmit %d <%s>\n", i->retries,
                     ccnl_prefix_to_path(i->pkt->pfx));
#ifdef USE_NFN
            if (i->flags & CCNL_PIT_COREPROPAGATES){
#endif
                DEBUGMSG_CORE(TRACE, "AGING: PROPAGATING INTEREST %p\n", (void*) i);
                ccnl_interest_propagate(relay, i);
#ifdef USE_NFN
            }
#endif

            i->retries++;
            i = i->next;
        }
    }
    while (f) {
        if (!(f->flags & CCNL_FACE_FLAGS_STATIC) &&
                (f->last_used + CCNL_FACE_TIMEOUT) <= t){
            DEBUGMSG_CORE(TRACE, "AGING: FACE REMOVE %p\n", (void*) f);
            f = ccnl_face_remove(relay, f);
    }
        else
            f = f->next;
    }
}
Exemple #6
0
struct ccnl_content_s *
ccnl_content_add2cache(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c)
{
    DEBUGMSG(99, "ccnl_content_add2cache (%d/%d)\n", ccnl->contentcnt,
             ccnl->max_cache_entries);

    if (ccnl->max_cache_entries <= 0) {
        DEBUGMSG(1, "  content store disabled...\n");
        return NULL;
    }

    while (ccnl->max_cache_entries <= ccnl->contentcnt) {
        DEBUGMSG(1, "  remove Least Recently Used content...\n");
        struct ccnl_content_s *c2, *lru = NULL;

        for (c2 = ccnl->contents; c2; c2 = c2->next) {
            DEBUGMSG(1, "    '%s' -> %ld:%ld\n", ccnl_prefix_to_path(c2->name), c2->last_used.tv_sec, c2->last_used.tv_usec);
            if (!(c2->flags & CCNL_CONTENT_FLAGS_STATIC)
                && ((!lru) || timevaldelta(&c2->last_used, &lru->last_used) < 0)) {
                lru = c2;
            }
        }

        if (lru) {
            DEBUGMSG(1, "   replaced: '%s'\n", ccnl_prefix_to_path(lru->name));
            ccnl_content_remove(ccnl, lru);
        }
        else {
            DEBUGMSG(1, "   no dynamic content to remove...\n");
            break;
        }
    }

    DEBUGMSG(1, "  add new content to store: '%s'\n", ccnl_prefix_to_path(c->name));
    DBL_LINKED_LIST_ADD(ccnl->contents, c);
    ccnl->contentcnt++;
    return c;
}
void
ccnl_do_ageing(void *ptr, void *dummy)
{
    struct ccnl_relay_s *relay = (struct ccnl_relay_s*) ptr;
    struct ccnl_content_s *c = relay->contents;
    struct ccnl_interest_s *i = relay->pit;
    struct ccnl_face_s *f = relay->faces;
    time_t t = CCNL_NOW();
    char *bufp = NULL;
    DEBUGMSG_CORE(INFO, " ICNIoT: ageing t=%d\n", (int)t);

    while (c) {
        if ((c->last_used + CCNL_CONTENT_TIMEOUT) <= t &&
                                !(c->flags & CCNL_CONTENT_FLAGS_STATIC)){
          DEBUGMSG_CORE(INFO, " ICNIoT: AGING: CONTENT REMOVE %p\n", (void*) c);
            c = ccnl_content_remove(relay, c);
        }
        else{
//akhila 29-10-2015
        // check if it is the n th time instant. If yes then save the content store 
             if ((((int)t)%CS_SAVE_PERIOD == 0) && !(c->flags & CCNL_CONTENT_FLAGS_STATIC)){
                 bufp = ccnl_prefix_to_path((c->pkt)->pfx);
                 DEBUGMSG_CORE(INFO, " ICNIoT: ContentStoreItem :%s\n",bufp);
                 ccnl_free(bufp);
             }
            c = c->next;
        }
    }
    if (((int)t)%CS_SAVE_PERIOD == 0){
    	DEBUGMSG_CORE(INFO, " ICNIoT: ContentStoreItem contentCount:%d\n",relay->contentcnt);
      }
    while (i) { // CONFORM: "Entries in the PIT MUST timeout rather
                // than being held indefinitely."
        if ((i->last_used + CCNL_INTEREST_TIMEOUT) <= t){ // if it has timed out either resend it or remove it based on MAX_RETRIES
                if(i->retries >= CCNL_MAX_INTEREST_RETRANSMIT){
            		DEBUGMSG_CORE(INFO, " ICNIoT: AGING: INTEREST REMOVE %p\n", (void*) i);
//            		DEBUGMSG_CORE(DEBUG, " timeout: remove interest 0x%p <%s>\n",(void*)i,ccnl_prefix_to_path(i->pkt->pfx));
            		i = ccnl_nfn_interest_remove(relay, i);
        	  }
        	else {
            		// CONFORM: "A node MUST retransmit Interest Messages
            		// periodically for pending PIT entries."
            		DEBUGMSG_CORE(INFO, " ICNIoT: retransmit %d \n", i->retries);
//                      ccnl_prefix_to_path(i->pkt->pfx));
#ifdef USE_NFN
            		if (i->flags & CCNL_PIT_COREPROPAGATES){
#endif
     		           DEBUGMSG_CORE(INFO, " ICNIoT: AGING: PROPAGATING INTEREST %p\n", (void*) i);
                	   ccnl_interest_propagate(relay, i);
#ifdef USE_NFN
                        }
#endif
            		i->retries++;
            		i = i->next;
        	}
         }
        else{ // The interest has not timed out yet, so leave it alone !
//		DEBUGMSG_CORE(INFO, " ICNIoT: AGING: DO NOTHING %p\n", (void*) i);
		i = i->next;
            } 
    }
//    DEBUGMSG_CORE(INFO, " ICNIoT: PITcount %d\n",relay->pitcnt);
    while (f) {
        if (!(f->flags & CCNL_FACE_FLAGS_STATIC) &&
                (f->last_used + CCNL_FACE_TIMEOUT) <= t){
            DEBUGMSG_CORE(TRACE, "AGING: FACE REMOVE %p\n", (void*) f);
            f = ccnl_face_remove(relay, f);
    }
        else
            f = f->next;
    }
}
struct ccnl_content_s*
ccnl_content_add2cache(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c)
{
    struct ccnl_content_s *cit;

    for (cit = ccnl->contents; cit; cit = cit->next) {
        if (c == cit) {
            DEBUGMSG_CORE(DEBUG, "--- Already in cache ---\n");
            return NULL;
        }
    }
#ifdef USE_NACK
    if (ccnl_nfnprefix_contentIsNACK(c))
        return NULL;
#endif

    if (c->flags & CCNL_CONTENT_FLAGS_STATIC){
//        DEBUGMSG_CORE(INFO, " ICNIoT: going to add self published content to cache \n");
        DBL_LINKED_LIST_ADD(ccnl->contents, c);
        DEBUGMSG_CORE(INFO, " ICNIoT: added_content2cache without incrementing count:%d\n",ccnl->contentcnt);
        return c;
     }

   
// not self published content
    if (ccnl->max_cache_entries > 0 &&
        ccnl->contentcnt >= ccnl->max_cache_entries) { //Cache replacement strategy
        struct ccnl_content_s *c2;
        struct ccnl_content_s *c3 = NULL;
        int age = 0;
//        char* prefixBuf = NULL;



#ifdef UPDATE_TIME_SERIES
   	if(IsTimeSeriesContent(c->pkt->pfx)){
		DEBUGMSG_CORE(INFO, " ICNIoT: UTS-LRU The new received content is time series content\n");
        	c3 = findOlderVersion(ccnl, c->pkt->pfx);
        }
#endif

#ifdef RECOMMENDED_CACHE_TIME
      c3 = oldestCacheTimeExpiredContent(ccnl);
      if(c3)
          DEBUGMSG_CORE(INFO, " ICNIoT: RCT, Found a content object with expired RCT\n");        	      
#endif

	if (!c3){//if not time series CO OR if time series CO but older version of stream doesnt
                 //exist in cache. For both cases use LRU
		DEBUGMSG_CORE(INFO, " ICNIoT: using LRU\n");
        	for (c2 = ccnl->contents; c2; c2 = c2->next){
            		if (!(c2->flags & CCNL_CONTENT_FLAGS_STATIC) && ((age == 0) || c2->last_used < age)){
                		age = c2->last_used;
                		c3 = c2;
             		}
         	}
	}
//            prefixBuf = ccnl_prefix_to_path(c3->pkt->pfx);
//            DEBUGMSG_CORE(INFO, " ICNIoT: yes ! removed content\n");
//            free(prefixBuf);
            ccnl_content_remove(ccnl, c3);
    }
    if(ccnl->contentcnt < ccnl->max_cache_entries){
//        char* prefixBuf2 = NULL;
//        prefixBuf2 = ccnl_prefix_to_path(c->pkt->pfx);
//        DEBUGMSG_CORE(INFO, " ICNIoT: going to add %s content to cache\n",prefixBuf2);
//        free(prefixBuf2);
    	DBL_LINKED_LIST_ADD(ccnl->contents, c);
    	ccnl->contentcnt++;
    	DEBUGMSG_CORE(INFO, " ICNIoT: added_content2cache count:%d\n",ccnl->contentcnt);
    }
    return c;
}