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); }
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; }
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; }