Example #1
0
static const struct babel_route *
min_conflict(const struct zone *zone, const struct babel_route *rt)
{
    struct babel_route *rt1 = NULL;
    const struct babel_route *min = NULL;
    struct route_stream *stream = NULL;
    struct zone curr_zone;
    stream = route_stream(ROUTE_INSTALLED);
    if(!stream) {
        fprintf(stderr, "Couldn't allocate route stream.\n");
        return NULL;
    }
    while(1) {
        rt1 = route_stream_next(stream);
        if(rt1 == NULL) break;
        __builtin_prefetch(rt1->src,0,1);
        __builtin_prefetch(rt->src,0,1);

        if(!(conflicts(rt, rt1) &&
             zone_equal(inter(rt, rt1, &curr_zone), zone)))
             continue;
        min = min_route(rt1, min);
    }
    route_stream_done(stream);
    return min;
}
Example #2
0
static const struct babel_route *
conflict_solution(const struct babel_route *rt)
{
    const struct babel_route *rt1 = NULL, *rt2 = NULL;
    struct route_stream *stream1 = NULL;
    struct route_stream *stream2 = NULL;
    const struct babel_route *min = NULL; /* == solution */
    struct zone zone;
    struct zone tmp;
    /* Having a conflict requires at least one specific route. */
    stream1 = route_stream(ROUTE_SS_INSTALLED);
    if(!stream1) {
        return NULL;
    }
    while(1) {
        rt1 = route_stream_next(stream1);
        if(rt1 == NULL) break;

        stream2 = route_stream(ROUTE_INSTALLED);
        if(!stream2) {
            route_stream_done(stream1);
            fprintf(stderr, "Couldn't allocate route stream.\n");
            return NULL;
        }

        while(1) {
            rt2 = route_stream_next(stream2);
            if(rt2 == NULL) break;
            if(!(conflicts(rt1, rt2) &&
                 zone_equal(inter(rt1, rt2, &tmp), to_zone(rt, &zone)) &&
                 rt_cmp(rt1, rt2) < 0))
                continue;
            min = min_route(rt1, min);
        }
        route_stream_done(stream2);
    }
    route_stream_done(stream1);
    return min;
}
Example #3
0
void
local_notify_all_1(int s)
{
    int rc;
    struct neighbour *neigh;
    const char *header = "BABEL 0.0\n";
    struct xroute_stream *xroutes;
    struct route_stream *routes;

    rc = write_timeout(s, header, strlen(header));
    if(rc < 0)
        goto fail;

    local_notify_self_1(s);
    FOR_ALL_NEIGHBOURS(neigh) {
        local_notify_neighbour_1(s, neigh, LOCAL_ADD);
    }

    xroutes = xroute_stream();
    if(xroutes) {
        while(1) {
            struct xroute *xroute = xroute_stream_next(xroutes);
            if(xroute == NULL)
                break;
            local_notify_xroute_1(s, xroute, LOCAL_ADD);
        }
        xroute_stream_done(xroutes);
    }

    routes = route_stream(0);
    if(routes) {
        while(1) {
            struct babel_route *route = route_stream_next(routes);
            if(route == NULL)
                break;
            local_notify_route_1(s, route, LOCAL_ADD);
        }
        route_stream_done(routes);
    }

    rc = write_timeout(s, "done\n", 5);
    if(rc < 0)
        goto fail;
    return;

 fail:
    shutdown(s, 1);
    return;
}
Example #4
0
static void
local_notify_all_1(struct local_socket *s)
{
    struct interface *ifp;
    struct neighbour *neigh;
    struct xroute_stream *xroutes;
    struct route_stream *routes;

    FOR_ALL_INTERFACES(ifp) {
        local_notify_interface_1(s, ifp, LOCAL_ADD);
    }

    FOR_ALL_NEIGHBOURS(neigh) {
        local_notify_neighbour_1(s, neigh, LOCAL_ADD);
    }

    xroutes = xroute_stream();
    if(xroutes) {
        while(1) {
            struct xroute *xroute = xroute_stream_next(xroutes);
            if(xroute == NULL)
                break;
            local_notify_xroute_1(s, xroute, LOCAL_ADD);
        }
        xroute_stream_done(xroutes);
    }

    routes = route_stream(ROUTE_ALL);
    if(routes) {
        while(1) {
            struct babel_route *route = route_stream_next(routes);
            if(route == NULL)
                break;
            local_notify_route_1(s, route, LOCAL_ADD);
        }
        route_stream_done(routes);
    }
    return;
}