Example #1
0
LONGBOW_TEST_CASE(JSON, parcJSON_GetMembers)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    char *s = parcJSON_ToString(data->json);
    parcMemory_Deallocate((void **) &s);

    PARCList *members = parcJSON_GetMembers(data->json);
    assertTrue(parcList_Size(members) == 8, "Expected 8, actual %zd", parcList_Size(members));
}
Example #2
0
static CCNxMetaMessage *
_PIT_Command(Athena *athena, CCNxInterest *interest)
{
    CCNxMetaMessage *responseMessage;
    responseMessage = athenaPIT_ProcessMessage(athena->athenaPIT, interest);
    if (responseMessage) {
        return responseMessage;
    }

    CCNxName *ccnxName = ccnxInterest_GetName(interest);
    if (ccnxName_GetSegmentCount(ccnxName) > AthenaCommandSegment) {
        CCNxNameSegment *nameSegment = ccnxName_GetSegment(ccnxName, AthenaCommandSegment);
        char *command = ccnxNameSegment_ToString(nameSegment);

        if (strcasecmp(command, AthenaCommand_List) == 0) {
            parcLog_Debug(athena->log, "PIT List command invoked");
            PARCList *pitEntries = athenaPIT_CreateEntryList(athena->athenaPIT);
            printf("\n");
            for (size_t i = 0; i < parcList_Size(pitEntries); ++i) {
                PARCBuffer *strbuf = parcList_GetAtIndex(pitEntries, i);
                char *toprint = parcBuffer_ToString(strbuf);
                parcLog_Info(athena->log, "%s\n", toprint);
                parcMemory_Deallocate(&toprint);
            }
            parcList_Release(&pitEntries);
            responseMessage = _create_response(athena, ccnxName, "PIT listed on forwarder output log.");
        } else {
            responseMessage = _create_response(athena, ccnxName, "Unknown command: %s", command);
        }

        parcMemory_Deallocate(&command);
    }
    return responseMessage;
}
Example #3
0
LONGBOW_TEST_CASE(Global, athenaFIB_CreateEntryList)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    athenaFIB_AddRoute(data->testFIB, data->testName1, data->testVector12);

    PARCBitVector *result = athenaFIB_Lookup(data->testFIB, data->testName1, NULL);
    assertTrue(parcBitVector_Equals(result, data->testVector12), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);

    PARCList *entryList = athenaFIB_CreateEntryList(data->testFIB);
    assertTrue(parcList_Size(entryList) == 2, "Expected the EntryList to have 2 elements");

    AthenaFIBListEntry *entry = parcList_GetAtIndex(entryList, 0);
    assertNotNull(entry, "Expect entry at 0 to be non-NULL");
    assertTrue(ccnxName_Equals(data->testName1, entry->name), "Expect the name at 0 to be testName1");
    assertTrue(entry->linkId == 0, "Expect the routeId at 0 to be 0");

    entry = parcList_GetAtIndex(entryList, 1);
    assertNotNull(entry, "Expect entry at 1 to be non-NULL");
    assertTrue(ccnxName_Equals(data->testName1, entry->name), "Expect the name at 1 to be testName1");
    assertTrue(entry->linkId == 42, "Expect the routeId at 0 to be 42");

    parcList_Release(&entryList);
}
Example #4
0
LONGBOW_TEST_CASE(Global, PARCList_Add)
{
    PARCList *list = parcList(parcArrayList_Create(parcArrayList_StdlibFreeFunction), PARCArrayListAsPARCList);

    parcList_Add(list, 0);
    size_t actual = parcList_Size(list);
    assertTrue(1 == actual, "Expected=%d, actual=%zu", 1, actual);

    parcList_Release(&list);
}
Example #5
0
LONGBOW_TEST_CASE(Global, PARCList_AddAll)
{
    PARCList *list = parcList(parcArrayList_Create(parcArrayList_StdlibFreeFunction), PARCArrayListAsPARCList);

    void *elements[] = {
        strdup("a"),
        strdup("b"),
        strdup("c"),
    };

    parcList_AddAll(list, 3, elements);
    size_t actual = parcList_Size(list);

    assertTrue(3 == actual, "Expected=%d, actual=%zu", 3, actual);

    parcList_Release(&list);
}
Example #6
0
static CCNxMetaMessage *
_create_FIBList_response(Athena *athena, CCNxName *ccnxName, PARCList *fibEntryList)
{
    PARCJSON *jsonPayload = parcJSON_Create();
    PARCJSONArray *jsonEntryList = parcJSONArray_Create();
    parcJSON_AddArray(jsonPayload, JSON_KEY_RESULT, jsonEntryList);

    for (size_t i = 0; i < parcList_Size(fibEntryList); ++i) {
        AthenaFIBListEntry *entry = parcList_GetAtIndex(fibEntryList, i);
        if (entry != NULL) {
            CCNxName *prefixName = athenaFIBListEntry_GetName(entry);
            if (prefixName) {
                char *prefix = ccnxName_ToString(prefixName);
                int linkId = athenaFIBListEntry_GetLinkId(entry);
                const char *linkName = athenaTransportLinkAdapter_LinkIdToName(athena->athenaTransportLinkAdapter, linkId);
                parcLog_Debug(athena->log, "  Route: %s->%s", prefix, linkName);

                PARCJSON *jsonItem = parcJSON_Create();
                parcJSON_AddString(jsonItem, JSON_KEY_NAME, prefix);
                parcJSON_AddString(jsonItem, JSON_KEY_LINK, linkName);

                PARCJSONValue *jsonItemValue = parcJSONValue_CreateFromJSON(jsonItem);
                parcJSON_Release(&jsonItem);

                parcJSONArray_AddValue(jsonEntryList, jsonItemValue);
                parcJSONValue_Release(&jsonItemValue);

                parcMemory_Deallocate(&prefix);
            } else {
                int linkId = athenaFIBListEntry_GetLinkId(entry);
                const char *linkName = athenaTransportLinkAdapter_LinkIdToName(athena->athenaTransportLinkAdapter, linkId);
                parcLog_Debug(athena->log, "  Route: <empty>->%s", linkName);

                PARCJSON *jsonItem = parcJSON_Create();
                parcJSON_AddString(jsonItem, JSON_KEY_NAME, "");
                parcJSON_AddString(jsonItem, JSON_KEY_LINK, linkName);

                PARCJSONValue *jsonItemValue = parcJSONValue_CreateFromJSON(jsonItem);
                parcJSON_Release(&jsonItem);

                parcJSONArray_AddValue(jsonEntryList, jsonItemValue);
                parcJSONValue_Release(&jsonItemValue);
            }
        }
    }

    char *jsonString = parcJSON_ToString(jsonPayload);

    parcJSONArray_Release(&jsonEntryList);
    parcJSON_Release(&jsonPayload);

    PARCBuffer *payload = parcBuffer_CreateFromArray(jsonString, strlen(jsonString));

    CCNxContentObject *contentObject =
        ccnxContentObject_CreateWithNameAndPayload(ccnxName, parcBuffer_Flip(payload));

    struct timeval tv;
    gettimeofday(&tv, NULL);
    uint64_t nowInMillis = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
    ccnxContentObject_SetExpiryTime(contentObject, nowInMillis + 100); // this response is good for 100 millis

    CCNxMetaMessage *result = ccnxMetaMessage_CreateFromContentObject(contentObject);

    ccnxContentObject_Release(&contentObject);
    parcBuffer_Release(&payload);
    parcMemory_Deallocate(&jsonString);

    athena_EncodeMessage(result);
    return result;
}