Ejemplo n.º 1
0
void
ccnl_simu_phase_two(void *ptr, void *dummy)
{
    phaseOne = 0;
    ccnl_set_timer(0, ccnl_simu_client_start, char2relay('A'), 0);
    ccnl_set_timer(500000, ccnl_simu_client_start, char2relay('B'), 0);
}
Ejemplo n.º 2
0
void
ccnl_simu_add_fwd(char node, const char *name, char dstnode)
{
    struct ccnl_relay_s *relay = char2relay(node), *dst = char2relay(dstnode);
    struct ccnl_forward_s *fwd;
    sockunion sun;
    char *cp;

    DEBUGMSG(TRACE, "ccnl_simu_add_fwd\n");

    sun.eth.sll_family = AF_PACKET;
    memcpy(sun.eth.sll_addr, dst->ifs[0].addr.eth.sll_addr, ETH_ALEN);
    fwd = (struct ccnl_forward_s *) ccnl_calloc(1, sizeof(*fwd));
    //    fwd->prefix = ccnl_path_to_prefix(name);
    cp = ccnl_strdup(name);
    fwd->prefix = ccnl_URItoPrefix(cp, theSuite, NULL, NULL);
    ccnl_free(cp);
    fwd->suite = theSuite;
    fwd->face = ccnl_get_face_or_create(relay, 0, &sun.sa, sizeof(sun.eth));
#ifdef USE_FRAG
    //    fwd->face->frag = ccnl_frag_new(CCNL_FRAG_SEQUENCED2012, 1500);
    fwd->face->frag = ccnl_frag_new(CCNL_FRAG_CCNx2013, 1200);
#endif
    fwd->face->flags |= CCNL_FACE_FLAGS_STATIC;
    fwd->next = relay->fib;
    relay->fib = fwd;
}
Ejemplo n.º 3
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);
    }
}
Ejemplo n.º 4
0
void
ccnl_simu_add2cache(char node, const char *name, int seqn, void *data, int len)
{
    struct ccnl_relay_s *relay;
    char tmp[100];
    struct ccnl_prefix_s *p;
    struct ccnl_buf_s *buf;
    int dataoffset;
    struct ccnl_content_s *c;

    relay = char2relay(node);
    if (!relay)
        return;

    sprintf(tmp, "%s/.%d", name, seqn);
    DEBUGMSG(VERBOSE, "  %s\n", tmp);
    //    p = ccnl_path_to_prefix(tmp);
    //    p->suite = suite;
    p = ccnl_URItoPrefix(tmp, theSuite, NULL, NULL);
    DEBUGMSG(VERBOSE, "  %s\n", ccnl_prefix_to_path(p));
    buf = ccnl_mkSimpleContent(p, data, len, &dataoffset);
    c = ccnl_content_new(relay, theSuite, &buf, &p,
                         NULL, buf->data + dataoffset, len);
    if (c)
        ccnl_content_add2cache(relay, c);
    return;
}
Ejemplo n.º 5
0
void
ccnl_simu_add2cache(char node, const char *name, int seqn, void *data, int len)
{
    struct ccnl_relay_s *relay;
    char tmp[100];
    int dataoffset;
    struct ccnl_content_s *c;
    struct ccnl_pkt_s *pkt;

    relay = char2relay(node);
    if (!relay)
        return;

    sprintf(tmp, "%s/.%d", name, seqn);
    DEBUGMSG(VERBOSE, "  %s\n", tmp);
    //    p = ccnl_path_to_prefix(tmp);
    //    p->suite = suite;
    pkt = ccnl_calloc(1, sizeof(*pkt));
    pkt->pfx = ccnl_URItoPrefix(tmp, theSuite, NULL, NULL);
    DEBUGMSG(VERBOSE, "  %s\n", ccnl_prefix_to_path(pkt->pfx));
    pkt->buf = ccnl_mkSimpleContent(pkt->pfx, data, len, &dataoffset);
    pkt->content = pkt->buf->data + dataoffset;
    pkt->contlen = len;
    c = ccnl_content_new(relay, &pkt);
    if (c)
        ccnl_content_add2cache(relay, c);
    return;
}
Ejemplo n.º 6
0
void
ccnl_simu_init_node(char node, const char *addr,
                    int max_cache_entries, int mtu)
{
    struct ccnl_relay_s *relay = char2relay(node);
    struct ccnl_if_s *i;

    DEBUGMSG(TRACE, "ccnl_simu_init_node\n");

    relay->id = relay - relays;
    relay->max_cache_entries = node == 'C' ? -1 : max_cache_entries;

    // add (fake) eth0 interface with index 0:
    i = &relay->ifs[0];
    i->addr.eth.sll_family = AF_PACKET;
    memcpy(i->addr.eth.sll_addr, addr, ETH_ALEN);
    if (mtu)
        i->mtu = mtu;
    else
        i->mtu = 4096;
    i->reflect = 1;
    i->fwdalli = 1;
    relay->ifcount++;

#ifdef USE_SCHEDULER
    i->sched = ccnl_sched_pktrate_new(ccnl_interface_CTS, relay,
                                      inter_packet_interval);
    relay->defaultFaceScheduler = ccnl_simu_defaultFaceScheduler;
#endif

    if (node == 'A' || node == 'B') {

        struct ccnl_client_s *client = ccnl_calloc(1,
                                           sizeof(struct ccnl_client_s));
        client->lastseq = SIMU_NUMBER_OF_CHUNKS-1;
        client->last_received = -1;
        client->name = node == 'A' ?
            "/ccnl/simu/movie1" : "/ccnl/simu/movie2";
        relay->aux = (void *) client;
    }

    ccnl_set_timer(1000000, ccnl_ageing, relay, 0);
}
Ejemplo n.º 7
0
void
ccnl_simu_client_kick(char node, int ndx)
{
    struct ccnl_relay_s *relay = char2relay(node);
    struct ccnl_client_s *cl = relay->aux;

    if (cl->nextseq > cl->lastseq)
        return;

    if (!cl->to_handlers[ndx]) {
        cl->onthefly[ndx] = cl->nextseq;
        cl->nextseq++;
        cl->nonces[ndx] = random();
        cl->to_handlers[ndx] = ccnl_set_timer(TIMEOUT, ccnl_simu_client_timeout,
                                             relay, cl->to_handlers + ndx);
        cl->threadcnt++;
//      printf("number of threads: %d\n", cl->threadcnt);
        ccnl_client_TX(node, cl->name, cl->onthefly[ndx], cl->nonces[ndx]);
    }
}
Ejemplo n.º 8
0
int
ccnl_simu_init(int max_cache_entries)
{
    static char dat[SIMU_CHUNK_SIZE];
    static char init_was_visited;
    int i;

    if (init_was_visited)
        return 0;
    init_was_visited = 1;

    DEBUGMSG(TRACE, "ccnl_simu_init\n");

 #ifdef USE_SCHEDULER
    // initialize the scheduling subsystem
    ccnl_sched_init();
#endif

    // define each node's eth address:
    ccnl_simu_init_node('A', "\x00\x00\x00\x00\x00\x0a",
                       max_cache_entries);
    ccnl_simu_init_node('B', "\x00\x00\x00\x00\x00\x0b",
                       max_cache_entries);
    ccnl_simu_init_node('C', "\x00\x00\x00\x00\x00\x0c",
                       max_cache_entries);
    ccnl_simu_init_node('1', "\x00\x00\x00\x00\x00\x01",
                       max_cache_entries);
    ccnl_simu_init_node('2', "\x00\x00\x00\x00\x00\x02",
                       max_cache_entries);

    // install the system's forwarding pointers:
    ccnl_simu_add_fwd('A', "/ccnl/simu", '2');
    ccnl_simu_add_fwd('B', "/ccnl/simu", '2');
    ccnl_simu_add_fwd('2', "/ccnl/simu", '1');
    ccnl_simu_add_fwd('1', "/ccnl/simu", 'C');

/*
    for (i = 0; i < 5; i++)
        ccnl_dump(0, CCNL_RELAY, relays+i);
*/

    // turn node 'C' into a repository for three movies
    sprintf(dat, "%d", (int) sizeof(dat));
    for (i = 0; i < SIMU_NUMBER_OF_CHUNKS; i++) {
        ccnl_simu_add2cache('C', "/ccnl/simu/movie1", i, dat, sizeof(dat));
        ccnl_simu_add2cache('C', "/ccnl/simu/movie2", i, dat, sizeof(dat));
        ccnl_simu_add2cache('C', "/ccnl/simu/movie3", i, dat, sizeof(dat));
    }

    ccnl_set_timer(5000, ccnl_simu_ethernet, 0, 0);

    // start clients:
    ccnl_set_timer( 500000, ccnl_simu_client_start, char2relay('A'), 0);
    ccnl_set_timer(1000000, ccnl_simu_client_start, char2relay('B'), 0);
    phaseOne = 1;

    printf("Press ENTER to start the simulation\n");
    while (getchar() != '\n');

    return 0;
}