Example #1
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;
}
Example #2
0
int
ccnl_nfn_RX_result(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
                   struct ccnl_content_s *c)
{
    struct ccnl_interest_s *i_it = NULL;
    int found = 0;

    DEBUGMSG_CFWD(INFO, "data in rx result %.*s\n", c->pkt->contlen, c->pkt->content);
    TRACEIN();
#ifdef USE_NACK
    if (ccnl_nfnprefix_contentIsNACK(c)) {
        ccnl_nfn_nack_local_computation(relay, c->pkt->buf, c->pkt->pfx,
                                        from, c->pkt->pfx->suite);
        return -1;
    }
#endif // USE_NACK
    for (i_it = relay->pit; i_it;/* i_it = i_it->next*/) {
        //Check if prefix match and it is a nfn request
        if (!ccnl_prefix_cmp(c->pkt->pfx, NULL, i_it->pkt->pfx, CMP_EXACT) &&
                                        i_it->from && i_it->from->faceid < 0) {
            struct ccnl_face_s *from = i_it->from;
            int faceid = - from->faceid;

            DEBUGMSG(TRACE, "  interest faceid=%d\n", i_it->from->faceid);

            ccnl_content_add2cache(relay, c);
	    DEBUGMSG_CFWD(INFO, "data in rx resulti after add to cache %.*s\n", c->pkt->contlen, c->pkt->content);
            DEBUGMSG(DEBUG, "Continue configuration for configid: %d with prefix: %s\n",
                  faceid, ccnl_prefix_to_path(c->pkt->pfx));
            i_it->flags |= CCNL_PIT_COREPROPAGATES;
            i_it->from = NULL;
            ccnl_nfn_continue_computation(relay, faceid, 0);
            i_it = ccnl_interest_remove(relay, i_it);
            //ccnl_face_remove(relay, from);
            ++found;
            //goto Done;
        } else
            i_it = i_it->next;
    }
    TRACEOUT();
    return found > 0;
}
Example #3
0
int
ccnl_nfn_RX_result(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
                   struct ccnl_content_s *c)
{
    struct ccnl_interest_s *i_it = NULL;
    int found = 0;

    DEBUGMSG(TRACE, "ccnl_nfn_RX_result()\n");
#ifdef USE_NACK
    if (ccnl_nfnprefix_contentIsNACK(c)) {
        ccnl_nfn_nack_local_computation(relay, c->pkt, c->name,
                                        from, c->name->suite);
        return -1;
    }
#endif // USE_NACK
    for (i_it = relay->pit; i_it;/* i_it = i_it->next*/) {
        //Check if prefix match and it is a nfn request
        DEBUGMSG(DEBUG, "CMP: %d (match if zero), faceid: %d \n", 
			ccnl_prefix_cmp(c->name, NULL, i_it->prefix, CMP_EXACT),
			i_it->from->faceid);
        if (!ccnl_prefix_cmp(c->name, NULL, i_it->prefix, CMP_EXACT) &&
                                                i_it->from->faceid < 0) {
            int faceid = -i_it->from->faceid;

            ccnl_content_add2cache(relay, c);
	    DEBUGMSG(DEBUG, "Continue configuration for configid: %d with prefix: %s\n",
                     -i_it->from->faceid, ccnl_prefix_to_path(c->name));
            i_it->flags |= CCNL_PIT_COREPROPAGATES;
            i_it = ccnl_interest_remove(relay, i_it);
            ccnl_nfn_continue_computation(relay, faceid, 0);
            ++found;
            //goto Done;
        }
        else
            i_it = i_it->next;
    }
    return found > 0;
}
Example #4
0
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;
}