Exemple #1
0
qdr_core_t *qdr_core(qd_dispatch_t *qd, qd_router_mode_t mode, const char *area, const char *id)
{
    qdr_core_t *core = NEW(qdr_core_t);
    ZERO(core);

    core->qd          = qd;
    core->router_mode = mode;
    core->router_area = area;
    core->router_id   = id;

    //
    // Set up the logging sources for the router core
    //
    core->log       = qd_log_source("ROUTER_CORE");
    core->agent_log = qd_log_source("AGENT");

    //
    // Report on the configuration for unsettled multicasts
    //
    qd_log(core->log, QD_LOG_INFO, "Allow Unsettled Multicast: %s", qd->allow_unsettled_multicast ? "yes" : "no");

    //
    // Set up the threading support
    //
    core->action_cond = sys_cond();
    core->action_lock = sys_mutex();
    core->running     = true;
    DEQ_INIT(core->action_list);

    core->work_lock = sys_mutex();
    DEQ_INIT(core->work_list);
    core->work_timer = qd_timer(core->qd, qdr_general_handler, core);

    //
    // Set up the unique identifier generator
    //
    core->next_identifier = 1;
    core->id_lock = sys_mutex();

    //
    // Launch the core thread
    //
    core->thread = sys_thread(router_core_thread, core);

    //
    // Perform outside-of-thread setup for the management agent
    //
    core->agent_subscription_mobile = qdr_core_subscribe(core, "$management", 'M', '0',
                                                         QD_TREATMENT_ANYCAST_CLOSEST,
                                                         qdr_management_agent_on_message, core);
    core->agent_subscription_local = qdr_core_subscribe(core, "$management", 'L', '0',
                                                        QD_TREATMENT_ANYCAST_CLOSEST,
                                                        qdr_management_agent_on_message, core);

    return core;
}
qd_router_t *qd_router(qd_dispatch_t *qd, qd_router_mode_t mode, const char *area, const char *id)
{
    if (!type_registered) {
        type_registered = 1;
        qd_container_register_node_type(qd, &router_node);
    }

    size_t dplen = 9 + strlen(area) + strlen(id);
    node_id = (char*) malloc(dplen);
    strcpy(node_id, area);
    strcat(node_id, "/");
    strcat(node_id, id);

    qd_router_t *router = NEW(qd_router_t);
    ZERO(router);

    router_node.type_context = router;

    qd->router = router;
    router->qd           = qd;
    router->router_core  = 0;
    router->log_source   = qd_log_source("ROUTER");
    router->router_mode  = mode;
    router->router_area  = area;
    router->router_id    = id;
    router->node         = qd_container_set_default_node_type(qd, &router_node, (void*) router, QD_DIST_BOTH);

    router->lock  = sys_mutex();
    router->timer = qd_timer(qd, qd_router_timer_handler, (void*) router);

    //
    // Inform the field iterator module of this router's id and area.  The field iterator
    // uses this to offload some of the address-processing load from the router.
    //
    qd_iterator_set_address(area, id);

    //
    // Seed the random number generator
    //
    unsigned int seed = (unsigned int) time(0);
    srandom(seed);

    switch (router->router_mode) {
    case QD_ROUTER_MODE_STANDALONE: qd_log(router->log_source, QD_LOG_INFO, "Router started in Standalone mode");  break;
    case QD_ROUTER_MODE_INTERIOR:   qd_log(router->log_source, QD_LOG_INFO, "Router started in Interior mode, area=%s id=%s", area, id);  break;
    case QD_ROUTER_MODE_EDGE:       qd_log(router->log_source, QD_LOG_INFO, "Router started in Edge mode");  break;
    case QD_ROUTER_MODE_ENDPOINT:   qd_log(router->log_source, QD_LOG_INFO, "Router started in Endpoint mode");  break;
    }

    return router;
}
Exemple #3
0
void qdr_agent_setup_CT(qdr_core_t *core)
{
    DEQ_INIT(core->outgoing_query_list);
    core->query_lock  = sys_mutex();
    core->agent_timer = qd_timer(core->qd, qdr_agent_response_handler, core);
}
Exemple #4
0
int timer_tests()
{
    char *test_group = "timer_tests";
    int result = 0;
    fire_mask = fired = 0;
    time_value = 1;

    timers[0]  = qd_timer(0, on_timer, (void*) 0x00000001);
    timers[1]  = qd_timer(0, on_timer, (void*) 0x00000002);
    timers[2]  = qd_timer(0, on_timer, (void*) 0x00000004);
    timers[3]  = qd_timer(0, on_timer, (void*) 0x00000008);
    timers[4]  = qd_timer(0, on_timer, (void*) 0x00000010);
    timers[5]  = qd_timer(0, on_timer, (void*) 0x00000020);
    timers[6]  = qd_timer(0, on_timer, (void*) 0x00000040);
    timers[7]  = qd_timer(0, on_timer, (void*) 0x00000080);
    timers[8]  = qd_timer(0, on_timer, (void*) 0x00000100);
    timers[9]  = qd_timer(0, on_timer, (void*) 0x00000200);
    timers[10] = qd_timer(0, on_timer, (void*) 0x00000400);
    timers[11] = qd_timer(0, on_timer, (void*) 0x00000800);
    timers[12] = qd_timer(0, on_timer, (void*) 0x00001000);
    timers[13] = qd_timer(0, on_timer, (void*) 0x00002000);
    timers[14] = qd_timer(0, on_timer, (void*) 0x00004000);
    timers[15] = qd_timer(0, on_timer, (void*) 0x00008000);

    TEST_CASE(test_quiet, 0);
    TEST_CASE(test_immediate, 0);
    TEST_CASE(test_immediate_reschedule, 0);
    TEST_CASE(test_immediate_plus_delayed, 0);
    TEST_CASE(test_single, 0);
    TEST_CASE(test_two_inorder, 0);
    TEST_CASE(test_two_reverse, 0);
    TEST_CASE(test_two_duplicate, 0);
    TEST_CASE(test_separated, 0);
    TEST_CASE(test_big, 0);

    int i;
    for (i = 0; i < 16; i++)
        qd_timer_free(timers[i]);

    return result;
}
Exemple #5
0
int timer_tests(void)
{
    int result = 0;

    fire_mask = 0;
    DEQ_INIT(pending_timers);
    lock = qd_timer_lock();
    time_value = 1;

    timers[0]  = qd_timer(0, 0, (void*) 0x00000001);
    timers[1]  = qd_timer(0, 0, (void*) 0x00000002);
    timers[2]  = qd_timer(0, 0, (void*) 0x00000004);
    timers[3]  = qd_timer(0, 0, (void*) 0x00000008);
    timers[4]  = qd_timer(0, 0, (void*) 0x00000010);
    timers[5]  = qd_timer(0, 0, (void*) 0x00000020);
    timers[6]  = qd_timer(0, 0, (void*) 0x00000040);
    timers[7]  = qd_timer(0, 0, (void*) 0x00000080);
    timers[8]  = qd_timer(0, 0, (void*) 0x00000100);
    timers[9]  = qd_timer(0, 0, (void*) 0x00000200);
    timers[10] = qd_timer(0, 0, (void*) 0x00000400);
    timers[11] = qd_timer(0, 0, (void*) 0x00000800);
    timers[12] = qd_timer(0, 0, (void*) 0x00001000);
    timers[13] = qd_timer(0, 0, (void*) 0x00002000);
    timers[14] = qd_timer(0, 0, (void*) 0x00004000);
    timers[15] = qd_timer(0, 0, (void*) 0x00008000);

    TEST_CASE(test_quiet, 0);
    TEST_CASE(test_immediate, 0);
    TEST_CASE(test_immediate_reschedule, 0);
    TEST_CASE(test_immediate_plus_delayed, 0);
    TEST_CASE(test_single, 0);
    TEST_CASE(test_two_inorder, 0);
    TEST_CASE(test_two_reverse, 0);
    TEST_CASE(test_two_duplicate, 0);
    TEST_CASE(test_separated, 0);
    TEST_CASE(test_big, 0);

    int i;
    for (i = 0; i < 16; i++)
        qd_timer_free(timers[i]);

    return result;
}