Exemplo n.º 1
0
static CCNxControl *
metisConfiguration_ProcessRegistrationList(MetisConfiguration *config, CCNxControl *request, unsigned ingressId)
{
    MetisFibEntryList *fibList = metisForwarder_GetFibEntries(config->metis);

    CPIRouteEntryList *routeEntryList = cpiRouteEntryList_Create();
    for (size_t i = 0; i < metisFibEntryList_Length(fibList); i++) {
        const MetisFibEntry *fibEntry = metisFibEntryList_Get(fibList, i);
        MetisTlvName *prefix = metisFibEntry_GetPrefix(fibEntry);
        const MetisNumberSet *nexthops = metisFibEntry_GetNexthops(fibEntry);

        for (int j = 0; j < metisNumberSet_Length(nexthops); j++) {
            CPIRouteEntry *route = cpiRouteEntry_Create(metisTlvName_ToCCNxName(prefix),
                                                        metisNumberSet_GetItem(nexthops, j),
                                                        NULL,
                                                        cpiNameRouteProtocolType_STATIC,
                                                        cpiNameRouteType_LONGEST_MATCH,
                                                        NULL, // lifetime
                                                        1);   // cost
            cpiRouteEntryList_Append(routeEntryList, route);
        }

        metisTlvName_Release(&prefix);
    }
    PARCJSON *entryListJson = cpiRouteEntryList_ToJson(routeEntryList);
    CCNxControl *response = cpi_CreateResponse(request, entryListJson);
    parcJSON_Release(&entryListJson);
    cpiRouteEntryList_Destroy(&routeEntryList);
    metisFibEntryList_Destroy(&fibList);
    return response;
}
Exemplo n.º 2
0
    MetisConnection *conn = metisConnection_Create(ops);
    metisConnectionTable_Add(metisForwarder_GetConnectionTable(metis_a), conn);

    cpiAddress_Destroy(&metisA_localCpiAddress);
    cpiAddress_Destroy(&metisA_remoteCpiAddress);

    // ---- run
    metisDispatcher_RunDuration(dispatcher_a, &((struct timeval) { 0, 1000 }));
    metisDispatcher_RunDuration(dispatcher_b, &((struct timeval) { 0, 1000 }));
    // ----

    // ===============================================
    /* 4) setup route to /foo from a to b */

    CCNxName *ccnxName = ccnxName_CreateFromURI("lci:/2=hello");
    CPIRouteEntry *route = cpiRouteEntry_Create(ccnxName, ops->getConnectionId(ops), NULL, cpiNameRouteProtocolType_STATIC, cpiNameRouteType_LONGEST_MATCH, NULL, 1);
    bool success = metisForwarder_AddOrUpdateRoute(metis_a, route);
    cpiRouteEntry_Destroy(&route);
    assertTrue(success, "error adding route from A to B");

    // ---- run
    metisDispatcher_RunDuration(dispatcher_a, &((struct timeval) { 0, 1000 }));
    metisDispatcher_RunDuration(dispatcher_b, &((struct timeval) { 0, 1000 }));
    // ----

    // ===============================================
    /* 5) Connect client 1 to A */

    struct sockaddr_in metisA_LoopbackAddress;
    memset(&metisA_LoopbackAddress, 0, sizeof(metisA_LoopbackAddress));
    metisA_LoopbackAddress.sin_family = PF_INET;
    char truth_format[] = "{\"CPI_REQUEST\":{\"SEQUENCE\":%" PRIu64 ",\"REGISTER\":{\"PREFIX\":\"lci:/howdie/stranger\",\"INTERFACE\":55,\"FLAGS\":0,\"NEXTHOP\":{\"ADDRESSTYPE\":\"INET\",\"DATA\":\"AgAAAAQDAgEAAAAAAAAAAA==\"},\"PROTOCOL\":\"STATIC\",\"ROUTETYPE\":\"LONGEST\",\"COST\":200,\"LIFETIME\":[3600,0]}}}";
#else
    // Case 1033
    testUnimplemented("Platform not supported");
    return;
#endif

    char truth[1024];

    CCNxName *prefix = ccnxName_CreateFromURI("lci:/howdie/stranger");
    unsigned ifidx = 55;
    CPIAddress *nexthop = cpiAddress_CreateFromInet(&(struct sockaddr_in) { .sin_addr.s_addr = 0x01020304 });
    struct timeval lifetime = { 3600, 0 };
    unsigned cost = 200;

    CPIRouteEntry *route = cpiRouteEntry_Create(prefix, ifidx, nexthop, cpiNameRouteProtocolType_STATIC, cpiNameRouteType_LONGEST_MATCH, &lifetime, cost);

    CCNxControl *control = ccnxControl_CreateAddRouteRequest(route);

    // get its sequence number
    uint64_t seqnum = cpi_GetSequenceNumber(control);
    sprintf(truth, truth_format, seqnum);

    PARCJSON *test_json = ccnxControl_GetJson(control);
    char *test = parcJSON_ToCompactString(test_json);
    assertTrue(strcasecmp(truth, test) == 0, "Expected '%s', actual '%s'", truth, test);
    parcMemory_Deallocate((void **) &test);

    ccnxControl_Release(&control);
    cpiRouteEntry_Destroy(&route);
    cpiAddress_Destroy(&nexthop);