LONGBOW_TEST_CASE(Global, ccnxContentObject_AcquireRelease) { CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); PARCBuffer *payload = parcBuffer_Allocate(100); CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, payload); ccnxContentObject_AssertValid(contentObject); CCNxContentObject *reference = ccnxContentObject_Acquire(contentObject); assertTrue(reference == contentObject, "Expected acquired reference to be equal to original"); ccnxName_Release(&name); parcBuffer_Release(&payload); ccnxContentObject_AssertValid(contentObject); ccnxContentObject_AssertValid(reference); ccnxContentObject_Release(&contentObject); assertTrue(contentObject == NULL, "Expected contentObject pointer to be null"); ccnxContentObject_AssertValid(reference); ccnxContentObject_Release(&reference); assertTrue(reference == NULL, "Expected contentObject pointer to be null"); }
LONGBOW_TEST_CASE(Global, ccnxContentObject_Equals) { CCNxName *nameA = ccnxName_CreateFromCString("lci:/foo/bar/A"); PARCBuffer *payloadA = parcBuffer_Allocate(100); CCNxContentObject *objectA = ccnxContentObject_CreateWithDataPayload(nameA, payloadA); ccnxContentObject_AssertValid(objectA); assertTrue(ccnxContentObject_Equals(objectA, objectA), "Expected same instance to be equal"); CCNxContentObject *objectA2 = ccnxContentObject_CreateWithDataPayload(nameA, payloadA); ccnxContentObject_AssertValid(objectA2); assertTrue(ccnxContentObject_Equals(objectA, objectA2), "Expected ContentObject with same payload and name to be equal"); CCNxName *nameB = ccnxName_CreateFromCString("lci:/foo/bar/B"); CCNxContentObject *objectB = ccnxContentObject_CreateWithDataPayload(nameB, payloadA); ccnxContentObject_AssertValid(objectB); assertFalse(ccnxContentObject_Equals(objectA, objectB), "Expected ContentObject with same payload and different name"); ccnxName_Release(&nameA); ccnxName_Release(&nameB); parcBuffer_Release(&payloadA); ccnxContentObject_Release(&objectA); ccnxContentObject_Release(&objectA2); ccnxContentObject_Release(&objectB); }
LONGBOW_TEST_CASE(Local, _athenaLRUContentStore_PutManyContentObjects) { AthenaLRUContentStore *impl = _createLRUContentStore(); PARCBuffer *payload = parcBuffer_Allocate(1200); int numEntriesToPut = 100; for (int i = 0; i < numEntriesToPut; i++) { // Re-use the payload per contentObject, though the store will think each is seperate (for size calculations) CCNxContentObject *contentObject = _createContentObject("lci:/boose/roo/pie", i, payload); bool status = _athenaLRUContentStore_PutContentObject(impl, contentObject); assertTrue(status, "Expected CO %d to be put in to the store", i); ccnxContentObject_Release(&contentObject); } assertTrue(impl->numEntries == numEntriesToPut, "Expected the numbe of entries put in the store to match"); // Now put the same ones (by name) again. These should kick out the old ones. for (int i = 0; i < numEntriesToPut; i++) { // Re-use the payload per contentObject, though the store will think each is seperate (for size calculations) CCNxContentObject *contentObject = _createContentObject("lci:/boose/roo/pie", i, payload); bool status = _athenaLRUContentStore_PutContentObject(impl, contentObject); assertTrue(status, "Expected CO %d to be put in to the store", i); ccnxContentObject_Release(&contentObject); } assertTrue(impl->numEntries == numEntriesToPut, "Expected the numbe of entries put in the store to match"); parcBuffer_Release(&payload); athenaLRUContentStore_Display(impl, 0); _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl); }
LONGBOW_TEST_CASE(Local, putWithExpiryTime) { AthenaLRUContentStore *impl = _createLRUContentStore(); CCNxName *name1 = ccnxName_CreateFromURI("lci:/first/entry"); CCNxContentObject *contentObject1 = ccnxContentObject_CreateWithDataPayload(name1, NULL); CCNxName *name2 = ccnxName_CreateFromURI("lci:/second/entry"); CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name2, NULL); CCNxName *name3 = ccnxName_CreateFromURI("lci:/third/entry"); CCNxContentObject *contentObject3 = ccnxContentObject_CreateWithDataPayload(name3, NULL); uint64_t now = parcClock_GetTime(impl->wallClock); ccnxContentObject_SetExpiryTime(contentObject1, now + 200); // Expires AFTER object 2 ccnxContentObject_SetExpiryTime(contentObject2, now + 100); // contentObject3 has no expiry time, so it expires last. _AthenaLRUContentStoreEntry *entry1 = _athenaLRUContentStoreEntry_Create(contentObject1); _AthenaLRUContentStoreEntry *entry2 = _athenaLRUContentStoreEntry_Create(contentObject2); _AthenaLRUContentStoreEntry *entry3 = _athenaLRUContentStoreEntry_Create(contentObject3); bool status = _athenaLRUContentStore_PutContentObject(impl, contentObject1); assertTrue(status, "Exepected to insert content"); status = _athenaLRUContentStore_PutContentObject(impl, contentObject2); assertTrue(status, "Exepected to insert content"); _AthenaLRUContentStoreEntry *oldestEntry = _getEarliestExpiryTime(impl); assertTrue(oldestEntry->contentObject == entry2->contentObject, "Expected entry 2 to be the earliest expiring entry"); status = _athenaLRUContentStore_PutContentObject(impl, contentObject3); assertTrue(status, "Exepected to insert content"); // The entry with no expiration time should not affect list ordering. oldestEntry = _getEarliestExpiryTime(impl); assertTrue(oldestEntry->contentObject == entry2->contentObject, "Expected entry 2 to be the earliest expiring entry"); // Now remove the oldest one we added. The next oldest one should be contentObject1 _athenaLRUContentStore_RemoveMatch(impl, name2, NULL, NULL); // The entry with no expiration time should not affect list ordering. oldestEntry = _getEarliestExpiryTime(impl); assertTrue(oldestEntry->contentObject == entry1->contentObject, "Expected entry 1 to be the earliest expiring entry"); _athenaLRUContentStoreEntry_Release(&entry1); _athenaLRUContentStoreEntry_Release(&entry2); _athenaLRUContentStoreEntry_Release(&entry3); ccnxContentObject_Release(&contentObject1); ccnxContentObject_Release(&contentObject2); ccnxContentObject_Release(&contentObject3); ccnxName_Release(&name1); ccnxName_Release(&name2); ccnxName_Release(&name3); _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl); }
LONGBOW_TEST_CASE(Local, _athenaLRUContentStore_GetMatchByName) { AthenaLRUContentStore *impl = _createLRUContentStore(); PARCBuffer *payload = parcBuffer_Allocate(500); CCNxName *name = ccnxName_CreateFromURI("lci:/boose/roo/pie"); CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, payload); parcBuffer_Release(&payload); bool status = _athenaLRUContentStore_PutContentObject(impl, contentObject); assertTrue(status, "Expected to put content into the store"); PARCBuffer *payload2 = parcBuffer_Allocate(500); CCNxName *name2 = ccnxName_CreateFromURI("lci:/roo/pie/boose"); CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name2, payload2); parcBuffer_Release(&payload2); bool status2 = _athenaLRUContentStore_PutContentObject(impl, contentObject2); assertTrue(status2, "Expected to put content into the store"); // At this point, both objects should be in the store. athenaLRUContentStore_Display(impl, 2); assertTrue(impl->stats.numAdds == 2, "Expected 2 store adds"); // Now try to fetch each of them. CCNxInterest *interest1 = ccnxInterest_CreateSimple(name); CCNxContentObject *match = _athenaLRUContentStore_GetMatch(impl, interest1); assertTrue(match == contentObject, "Expected to match the first content object"); CCNxInterest *interest2 = ccnxInterest_CreateSimple(name2); CCNxContentObject *match2 = _athenaLRUContentStore_GetMatch(impl, interest2); assertTrue(match2 == contentObject2, "Expected to match the second content object"); // Now try to match a non-existent name. CCNxName *nameNoMatch = ccnxName_CreateFromURI("lci:/pie/roo/boose/this/should/not/match"); CCNxInterest *interest3 = ccnxInterest_CreateSimple(nameNoMatch); CCNxContentObject *noMatch = _athenaLRUContentStore_GetMatch(impl, interest3); assertNull(noMatch, "Expected a NULL response from an unmatchable name"); ccnxInterest_Release(&interest1); ccnxInterest_Release(&interest2); ccnxInterest_Release(&interest3); ccnxName_Release(&nameNoMatch); ccnxName_Release(&name); ccnxName_Release(&name2); ccnxContentObject_Release(&contentObject); ccnxContentObject_Release(&contentObject2); _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl); }
LONGBOW_TEST_CASE(Local, _athenaLRUContentStore_GetMatchByNameAndObjectHash) { AthenaLRUContentStore *impl = _createLRUContentStore(); PARCBuffer *payload = parcBuffer_Allocate(1200); CCNxName *name = ccnxName_CreateFromURI("lci:/boose/roo/pie"); CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, NULL); parcBuffer_Release(&payload); _AthenaLRUContentStoreEntry *entry1 = _athenaLRUContentStoreEntry_Create(contentObject); entry1->hasKeyId = false; entry1->hasContentObjectHash = false; bool status = _athenaLRUContentStore_PutLRUContentStoreEntry(impl, entry1); assertTrue(status, "Expected to add the entry"); // Now add another content object with the same name, but an object hash too. CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name, NULL); _AthenaLRUContentStoreEntry *entry2 = _athenaLRUContentStoreEntry_Create(contentObject2); entry2->contentObjectHash = parcBuffer_WrapCString("corned beef"); entry2->hasContentObjectHash = true; status = _athenaLRUContentStore_PutLRUContentStoreEntry(impl, entry2); assertTrue(status, "Expected to add the entry"); assertTrue(impl->numEntries == 2, "Expected 2 store items"); // Now match on Name + ObjectHash. CCNxInterest *interest = ccnxInterest_CreateSimple(name); PARCBuffer *hashRestriction = parcBuffer_Copy(entry2->contentObjectHash); ccnxInterest_SetContentObjectHashRestriction(interest, hashRestriction); parcBuffer_Release(&hashRestriction); CCNxContentObject *match = _athenaLRUContentStore_GetMatch(impl, interest); assertNotNull(match, "Expected to match something"); assertTrue(match == contentObject2, "Expected the content object with the keyId"); _athenaLRUContentStoreEntry_Release(&entry1); _athenaLRUContentStoreEntry_Release(&entry2); ccnxContentObject_Release(&contentObject2); ccnxContentObject_Release(&contentObject); ccnxName_Release(&name); ccnxInterest_Release(&interest); _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl); }
LONGBOW_TEST_CASE(Global, removeMatch) { AthenaLRUContentStoreConfig config; config.capacityInMB = 10; AthenaContentStore *store = athenaContentStore_Create(&AthenaContentStore_LRUImplementation, &config); PARCClock *clock = parcClock_Wallclock(); char *lci = "lci:/cakes/and/pies"; CCNxName *origName = ccnxName_CreateFromURI(lci); CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(origName, NULL); ccnxContentObject_SetExpiryTime(contentObject, parcClock_GetTime(clock) + 100); ccnxName_Release(&origName); athenaContentStore_PutContentObject(store, contentObject); ccnxContentObject_Release(&contentObject); CCNxName *testName = ccnxName_CreateFromURI(lci); bool status = athenaContentStore_RemoveMatch(store, testName, NULL, NULL); // TODO: match on other than name! assertTrue(status, "Expected to remove the contentobject we had"); ccnxName_Release(&testName); parcClock_Release(&clock); athenaContentStore_Release(&store); }
LONGBOW_TEST_CASE(Global, athenaTransportLinkAdapter_ListLinks) { PARCURI *connectionURI; const char *result; AthenaTransportLinkAdapter *athenaTransportLinkAdapter = athenaTransportLinkAdapter_Create(_removeLink, NULL); assertNotNull(athenaTransportLinkAdapter, "athenaTransportLinkAdapter_Create returned NULL"); _LoadModule(athenaTransportLinkAdapter, "TCP"); connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/listener/name=TCPListener"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/name=TCP_0"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); CCNxName *name = ccnxName_CreateFromCString(CCNxNameAthenaCommand_LinkList); CCNxInterest *ccnxMessage = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); CCNxContentObject *contentObject = athenaTransportLinkAdapter_ProcessMessage(athenaTransportLinkAdapter, ccnxMessage); assertNotNull(contentObject, "athenaTransportLinkAdapter_ProcessMessage failed"); ccnxInterest_Release(&ccnxMessage); ccnxContentObject_Release(&contentObject); int closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "TCP_0"); assertTrue(closeResult == 0, "athenaTransportLinkAdapter_CloseByName failed (%s)", strerror(errno)); athenaTransportLinkAdapter_Destroy(&athenaTransportLinkAdapter); }
/** * Listen for arriving Interests and respond to them if possible. We expect that the Portal we are passed is * listening for messages matching the specified domainPrefix. * * @param [in] portal The CCNxPortal that we will read from. * @param [in] domainPrefix A CCNxName containing the domain prefix that the specified `portal` is listening for. * @param [in] directoryPath A string containing the path to the directory being served. * * @return true if at least one Interest is received and responded to, false otherwise. */ static bool _receiveAndAnswerInterests(CCNxPortal *portal, const CCNxName *domainPrefix, const char *directoryPath) { bool result = false; CCNxMetaMessage *inboundMessage = NULL; while ((inboundMessage = ccnxPortal_Receive(portal)) != NULL) { if (ccnxMetaMessage_IsInterest(inboundMessage)) { CCNxInterest *interest = ccnxMetaMessage_GetInterest(inboundMessage); CCNxContentObject *response = _createInterestResponse(interest, domainPrefix, directoryPath); // At this point, response has either the requested chunk of the request file/command, // or remains NULL. if (response != NULL) { // We had a response, so send it back through the Portal. CCNxMetaMessage *responseMessage = ccnxMetaMessage_CreateFromContentObject(response); if (ccnxPortal_Send(portal, responseMessage) == false) { fprintf(stderr, "ccnxPortal_Send failed (error %d). Is the Forwarder running?\n", ccnxPortal_GetError(portal)); } ccnxMetaMessage_Release(&responseMessage); ccnxContentObject_Release(&response); result = true; // We have received, and responded to, at least one Interest. } } ccnxMetaMessage_Release(&inboundMessage); } return result; }
LONGBOW_TEST_CASE(Local, getMatch_Expired) { AthenaLRUContentStore *impl = _createLRUContentStore(); CCNxName *name = ccnxName_CreateFromURI("lci:/boose/roo/pie"); CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, NULL); _AthenaLRUContentStoreEntry *entry = _athenaLRUContentStoreEntry_Create(contentObject); ccnxContentObject_Release(&contentObject); entry->expiryTime = 10000; entry->hasExpiryTime = true; bool status = _athenaLRUContentStore_PutLRUContentStoreEntry(impl, entry); assertTrue(status, "Expected to put content into the store"); assertTrue(status, "Expected to put content into the store a second time"); assertTrue(impl->numEntries == 1, "Expected 1 entry in the store"); assertTrue(impl->stats.numAdds == 1, "Expected stats to show 1 adds"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); CCNxContentObject *match = _athenaLRUContentStore_GetMatch(impl, interest); assertNull(match, "Expected to NOT match an interest, due to expired content"); assertTrue(impl->numEntries == 0, "Expected 0 entries in the store, after removing expired content"); _athenaLRUContentStoreEntry_Release(&entry); ccnxInterest_Release(&interest); _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl); }
LONGBOW_TEST_CASE(Local, putContentAndEnforceCapacity) { AthenaLRUContentStore *impl = _createLRUContentStore(); size_t lastSizeOfStore = 0; size_t payloadSize = 100 * 1024; _athenaLRUContentStore_SetCapacity(impl, 1); // set to 1 MB, or ~10 of our payloads PARCBuffer *payload = parcBuffer_Allocate(payloadSize); // 1M buffer int i; for (i = 0; i < 20; i++) { // Add more than 10 items. CCNxContentObject *content = _createContentObject("lci:/this/is/content", i, payload); assertNotNull(content, "Expected to allocated a content object"); bool status = _athenaLRUContentStore_PutContentObject(impl, content); assertTrue(status, "Expected to be able to insert content"); assertTrue(impl->currentSizeInBytes > lastSizeOfStore, "expected store size in bytes to grow"); ccnxContentObject_Release(&content); } // Make sure that the contentobjects were added, but that the size didn't grow past the capacity assertTrue(impl->currentSizeInBytes < (11 * payloadSize), "expected the current store size to be less than 11 x payload size"); assertTrue(impl->currentSizeInBytes >= (10 * payloadSize), "expected the current store size to be roughly 10 x payload size"); parcBuffer_Release(&payload); _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl); }
LONGBOW_TEST_CASE(Global, ccnxContentObject_GetPayloadType) { CCNxName *name = ccnxName_CreateFromCString("lci:/name"); PARCBuffer *payload = parcBuffer_Allocate(100); CCNxPayloadType types[] = { CCNxPayloadType_DATA, CCNxPayloadType_KEY, CCNxPayloadType_LINK, CCNxPayloadType_MANIFEST, }; for (int i = 0; i < sizeof(types) / sizeof(CCNxPayloadType); i++) { CCNxPayloadType type = types[i]; CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, NULL); ccnxContentObject_SetPayload(contentObject, type, payload); assertTrue(ccnxContentObject_GetPayloadType(contentObject) == type, "Unexpected PayloadType"); ccnxContentObject_Release(&contentObject); } parcBuffer_Release(&payload); ccnxName_Release(&name); }
LONGBOW_TEST_CASE(Global, ccnxContentObject_GetKeyId) { CCNxName *name = ccnxName_CreateFromCString("lci:/hello/dolly"); PARCBuffer *payload = parcBuffer_WrapCString("hello"); CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, payload); assertNull(ccnxContentObject_GetKeyId(contentObject), "Expect NULL for KeyId here"); PARCBuffer *testKeyId = parcBuffer_WrapCString("keyhash"); PARCBuffer *sigbits = parcBuffer_WrapCString("siggybits"); PARCSignature *signature = parcSignature_Create(PARCSigningAlgorithm_RSA, PARC_HASH_SHA256, parcBuffer_Flip(sigbits)); ccnxContentObject_SetSignature(contentObject, testKeyId, signature, NULL); PARCBuffer *keyId = ccnxContentObject_GetKeyId(contentObject); assertTrue(parcBuffer_Equals(keyId, testKeyId), "Expect key ids to match"); parcBuffer_Release(&payload); parcBuffer_Release(&sigbits); parcBuffer_Release(&keyId); parcSignature_Release(&signature); ccnxName_Release(&name); ccnxContentObject_Release(&contentObject); }
LONGBOW_TEST_CASE(Local, putTooBig) { AthenaLRUContentStoreConfig config; config.capacityInMB = 1; AthenaLRUContentStore *impl = _athenaLRUContentStore_Create(&config); size_t payloadSize = 2 * 1024 * 1024; // 2M PARCBuffer *payload = parcBuffer_Allocate(payloadSize); CCNxContentObject *content = _createContentObject("lci:/this/is/content", 10, payload); assertNotNull(content, "Expected to allocated a content object"); bool status = _athenaLRUContentStore_PutContentObject(impl, content); assertFalse(status, "Expected insertion of too large a content object to fail."); ccnxContentObject_Release(&content); parcBuffer_Release(&payload); // Make sure that the contentobjects were added, but that the size didn't grow past the capacity assertTrue(impl->currentSizeInBytes == 0, "expected the current store size to be 0."); _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl); }
LONGBOW_TEST_CASE(Global, getMatchByName) { AthenaLRUContentStoreConfig config; config.capacityInMB = 10; AthenaContentStore *store = athenaContentStore_Create(&AthenaContentStore_LRUImplementation, &config); char *lci = "lci:/cakes/and/pies"; PARCClock *clock = parcClock_Wallclock(); CCNxName *truthName = ccnxName_CreateFromURI(lci); CCNxContentObject *truthObject = ccnxContentObject_CreateWithDataPayload(truthName, NULL); ccnxContentObject_SetExpiryTime(truthObject, parcClock_GetTime(clock) + 100); ccnxName_Release(&truthName); athenaContentStore_PutContentObject(store, truthObject); CCNxName *testName = ccnxName_CreateFromURI(lci); CCNxInterest *interest = ccnxInterest_CreateSimple(testName); ccnxName_Release(&testName); //athena_EncodeMessage(interest); CCNxContentObject *testObject = athenaContentStore_GetMatch(store, interest); ccnxInterest_Release(&interest); // TODO: match on other than name! assertTrue(ccnxContentObject_Equals(truthObject, testObject), "Expected to get the same ContentObject back"); assertTrue(truthObject == testObject, "Expected the same pointer back"); athenaContentStore_Release(&store); ccnxContentObject_Release(&truthObject); parcClock_Release(&clock); }
LONGBOW_TEST_CASE(Local, putWithExpiryTime_Expired) { AthenaLRUContentStore *impl = _createLRUContentStore(); CCNxName *name1 = ccnxName_CreateFromURI("lci:/first/entry"); CCNxContentObject *contentObject1 = ccnxContentObject_CreateWithDataPayload(name1, NULL); CCNxName *name2 = ccnxName_CreateFromURI("lci:/second/entry"); CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name2, NULL); CCNxName *name3 = ccnxName_CreateFromURI("lci:/third/entry"); CCNxContentObject *contentObject3 = ccnxContentObject_CreateWithDataPayload(name3, NULL); uint64_t now = parcClock_GetTime(impl->wallClock); // NOTE: These two are considered expired and should NOT be added to the store. ccnxContentObject_SetExpiryTime(contentObject1, now); _AthenaLRUContentStoreEntry *entry1 = _athenaLRUContentStoreEntry_Create(contentObject1); ccnxContentObject_SetExpiryTime(contentObject2, now - 100); _AthenaLRUContentStoreEntry *entry2 = _athenaLRUContentStoreEntry_Create(contentObject2); // NOTE: This one does not have an expiry time, so should be added. _AthenaLRUContentStoreEntry *entry3 = _athenaLRUContentStoreEntry_Create(contentObject3); bool status = _athenaLRUContentStore_PutContentObject(impl, contentObject1); assertFalse(status, "Exepected to fail on inserting expired content"); status = _athenaLRUContentStore_PutContentObject(impl, contentObject2); assertFalse(status, "Exepected to fail on inserting expired content"); status = _athenaLRUContentStore_PutContentObject(impl, contentObject3); assertTrue(status, "Exepected to insert a ContentObject with no expiry time."); _athenaLRUContentStoreEntry_Release(&entry1); _athenaLRUContentStoreEntry_Release(&entry2); _athenaLRUContentStoreEntry_Release(&entry3); ccnxContentObject_Release(&contentObject1); ccnxContentObject_Release(&contentObject2); ccnxContentObject_Release(&contentObject3); ccnxName_Release(&name1); ccnxName_Release(&name2); ccnxName_Release(&name3); _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl); }
LONGBOW_TEST_CASE(Local, _compareByRecommendedCacheTime) { CCNxName *name1 = ccnxName_CreateFromURI("lci:/first/entry"); CCNxContentObject *contentObject1 = ccnxContentObject_CreateWithDataPayload(name1, NULL); CCNxName *name2 = ccnxName_CreateFromURI("lci:/second/entry"); CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name2, NULL); CCNxName *name3 = ccnxName_CreateFromURI("lci:/third/entry"); CCNxContentObject *contentObject3 = ccnxContentObject_CreateWithDataPayload(name3, NULL); _AthenaLRUContentStoreEntry *entry1 = _athenaLRUContentStoreEntry_Create(contentObject1); _AthenaLRUContentStoreEntry *entry2 = _athenaLRUContentStoreEntry_Create(contentObject2); _AthenaLRUContentStoreEntry *entry3 = _athenaLRUContentStoreEntry_Create(contentObject3); // There is no interface (yet) for assigning the recommended cache time. So update the store entries directly. entry1->hasRecommendedCacheTime = true; entry1->recommendedCacheTime = 1000; entry2->hasRecommendedCacheTime = true; entry2->recommendedCacheTime = 5000; entry3->hasRecommendedCacheTime = false; // treat contentObject3 as if it has no RCT entry3->recommendedCacheTime = 10; assertTrue(_compareByRecommendedCacheTime(entry1, entry2) == -1, "Expected result -1"); assertTrue(_compareByRecommendedCacheTime(entry2, entry1) == 1, "Expected result 1"); assertTrue(_compareByRecommendedCacheTime(entry2, entry2) == 0, "Expected result 0"); assertTrue(_compareByRecommendedCacheTime(entry1, entry3) == -1, "Expected result -1"); assertTrue(_compareByRecommendedCacheTime(entry3, entry2) == 1, "Expected result 1"); assertTrue(_compareByRecommendedCacheTime(entry3, entry3) == 0, "Expected result 0"); _athenaLRUContentStoreEntry_Release(&entry1); _athenaLRUContentStoreEntry_Release(&entry2); _athenaLRUContentStoreEntry_Release(&entry3); ccnxContentObject_Release(&contentObject1); ccnxContentObject_Release(&contentObject2); ccnxContentObject_Release(&contentObject3); ccnxName_Release(&name1); ccnxName_Release(&name2); ccnxName_Release(&name3); }
LONGBOW_TEST_CASE(Local, _getLeastUsedFromLRU) { AthenaLRUContentStore *impl = _createLRUContentStore(); CCNxName *name1 = ccnxName_CreateFromURI("lci:/first/entry"); CCNxContentObject *contentObject1 = ccnxContentObject_CreateWithDataPayload(name1, NULL); CCNxName *name2 = ccnxName_CreateFromURI("lci:/second/entry"); CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name2, NULL); CCNxName *name3 = ccnxName_CreateFromURI("lci:/third/entry"); CCNxContentObject *contentObject3 = ccnxContentObject_CreateWithDataPayload(name3, NULL); bool status = _athenaLRUContentStore_PutContentObject(impl, contentObject1); assertTrue(status, "Exepected to insert content"); status = _athenaLRUContentStore_PutContentObject(impl, contentObject2); assertTrue(status, "Exepected to insert content"); status = _athenaLRUContentStore_PutContentObject(impl, contentObject3); assertTrue(status, "Exepected to insert content"); athenaLRUContentStore_Display(impl, 2); _AthenaLRUContentStoreEntry *entry1 = _getLeastUsedFromLRU(impl); assertTrue(ccnxContentObject_Equals(entry1->contentObject, contentObject1), "Expected to retrieve contentObject1"); _athenaLRUContentStore_PurgeContentStoreEntry(impl, entry1); _AthenaLRUContentStoreEntry *entry2 = _getLeastUsedFromLRU(impl); assertTrue(ccnxContentObject_Equals(entry2->contentObject, contentObject2), "Expected to retrieve contentObject1"); _athenaLRUContentStore_PurgeContentStoreEntry(impl, entry2); _AthenaLRUContentStoreEntry *entry3 = _getLeastUsedFromLRU(impl); assertTrue(ccnxContentObject_Equals(entry3->contentObject, contentObject3), "Expected to retrieve contentObject1"); _athenaLRUContentStore_PurgeContentStoreEntry(impl, entry3); ccnxContentObject_Release(&contentObject1); ccnxContentObject_Release(&contentObject2); ccnxContentObject_Release(&contentObject3); ccnxName_Release(&name1); ccnxName_Release(&name2); ccnxName_Release(&name3); _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl); }
LONGBOW_TEST_CASE(Local, _athenaLRUContentStoreEntry_CreateRelease) { CCNxContentObject *contentObject = _createContentObject("lci:/boose/roo/pie", 0, NULL); _AthenaLRUContentStoreEntry *entry = _athenaLRUContentStoreEntry_Create(contentObject); _athenaLRUContentStoreEntry_Release(&entry); ccnxContentObject_Release(&contentObject); }
void ccnxSimpleFileTransferChunkList_SetChunk(CCNxSimpleFileTransferChunkList *chunkList, int slot, const CCNxContentObject *content) { CCNxContentObject **chunkPointers = chunkList->chunkPointers; if (chunkPointers[slot] != NULL) { ccnxContentObject_Release(&chunkPointers[slot]); } chunkPointers[slot] = ccnxContentObject_Acquire(content); }
LONGBOW_TEST_CASE(Global, athena_ProcessContentObject) { PARCURI *connectionURI; Athena *athena = athena_Create(100); CCNxName *name = ccnxName_CreateFromCString("lci:/cakes/and/pies"); uint64_t chunkNum = 0; CCNxNameSegment *chunkSegment = ccnxNameSegmentNumber_Create(CCNxNameLabelType_CHUNK, chunkNum); ccnxName_Append(name, chunkSegment); ccnxNameSegment_Release(&chunkSegment); PARCBuffer *payload = parcBuffer_WrapCString("this is a payload"); CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload); ccnxName_Release(&name); parcBuffer_Release(&payload); connectionURI = parcURI_Parse("tcp://localhost:50100/listener/name=TCPListener"); const char *result = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); connectionURI = parcURI_Parse("tcp://localhost:50100/name=TCP_0"); result = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); int linkId = athenaTransportLinkAdapter_LinkNameToId(athena->athenaTransportLinkAdapter, "TCP_0"); PARCBitVector *ingressVector = parcBitVector_Create(); parcBitVector_Set(ingressVector, linkId); athena_EncodeMessage(contentObject); athena_ProcessMessage(athena, contentObject, ingressVector); parcBitVector_Release(&ingressVector); // Make sure we recover processing a "nameless" content object payload = parcBuffer_WrapCString("Hello World"); CCNxContentObject *reply = ccnxContentObject_CreateWithPayload(payload); parcBuffer_Release(&payload); CCNxMetaMessage *response = ccnxMetaMessage_CreateFromContentObject(reply); ccnxContentObject_Release(&reply); athena_EncodeMessage(response); athena_ProcessMessage(athena, response, ingressVector); assertNull(ingressVector, "Processing nameless content object didn't fail."); ccnxInterest_Release(&contentObject); ccnxInterest_Release(&response); athena_Release(&athena); }
LONGBOW_TEST_CASE(Global, ccnxContentObject_CreateWithDataPayload) { CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); PARCBuffer *payload = parcBuffer_Allocate(100); CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, payload); ccnxContentObject_AssertValid(contentObject); ccnxName_Release(&name); parcBuffer_Release(&payload); ccnxContentObject_Release(&contentObject); }
static void _commonTeardown(TestData *data) { if (data->contentObject) { ccnxContentObject_Release(&data->contentObject); } if (data->name) { ccnxName_Release(&data->name); } parcMemory_Deallocate((void **) &data); }
LONGBOW_TEST_CASE(Local, _moveContentStoreEntryToLRUHead) { AthenaLRUContentStore *impl = _createLRUContentStore(); CCNxName *name = ccnxName_CreateFromURI("lci:/first/entry"); CCNxContentObject *contentObject1 = ccnxContentObject_CreateWithDataPayload(name, NULL); ccnxName_Release(&name); name = ccnxName_CreateFromURI("lci:/second/entry"); CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name, NULL); ccnxName_Release(&name); name = ccnxName_CreateFromURI("lci:/third/entry"); CCNxContentObject *contentObject3 = ccnxContentObject_CreateWithDataPayload(name, NULL); ccnxName_Release(&name); bool status = _athenaLRUContentStore_PutContentObject(impl, contentObject1); assertTrue(status, "Exepected to insert content"); status = _athenaLRUContentStore_PutContentObject(impl, contentObject2); assertTrue(status, "Exepected to insert content"); status = _athenaLRUContentStore_PutContentObject(impl, contentObject3); assertTrue(status, "Exepected to insert content"); athenaLRUContentStore_Display(impl, 2); _moveContentStoreEntryToLRUHead(impl, impl->lruTail); athenaLRUContentStore_Display(impl, 2); _moveContentStoreEntryToLRUHead(impl, impl->lruTail->next); athenaLRUContentStore_Display(impl, 2); ccnxContentObject_Release(&contentObject1); ccnxContentObject_Release(&contentObject2); ccnxContentObject_Release(&contentObject3); _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl); }
LONGBOW_TEST_CASE(Local, _compareByExpiryTime) { CCNxName *name1 = ccnxName_CreateFromURI("lci:/first/entry"); CCNxContentObject *contentObject1 = ccnxContentObject_CreateWithDataPayload(name1, NULL); CCNxName *name2 = ccnxName_CreateFromURI("lci:/second/entry"); CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name2, NULL); CCNxName *name3 = ccnxName_CreateFromURI("lci:/third/entry"); CCNxContentObject *contentObject3 = ccnxContentObject_CreateWithDataPayload(name3, NULL); ccnxContentObject_SetExpiryTime(contentObject1, 100); ccnxContentObject_SetExpiryTime(contentObject2, 200); // contentObject3 has no expiry time. _AthenaLRUContentStoreEntry *entry1 = _athenaLRUContentStoreEntry_Create(contentObject1); _AthenaLRUContentStoreEntry *entry2 = _athenaLRUContentStoreEntry_Create(contentObject2); _AthenaLRUContentStoreEntry *entry3 = _athenaLRUContentStoreEntry_Create(contentObject3); assertTrue(_compareByExpiryTime(entry1, entry2) == -1, "Expected result -1"); assertTrue(_compareByExpiryTime(entry2, entry1) == 1, "Expected result 1"); assertTrue(_compareByExpiryTime(entry2, entry2) == 0, "Expected result 0"); assertTrue(_compareByExpiryTime(entry1, entry3) == -1, "Expected result -1"); assertTrue(_compareByExpiryTime(entry3, entry2) == 1, "Expected result 1"); assertTrue(_compareByExpiryTime(entry3, entry3) == 0, "Expected result 0"); _athenaLRUContentStoreEntry_Release(&entry1); _athenaLRUContentStoreEntry_Release(&entry2); _athenaLRUContentStoreEntry_Release(&entry3); ccnxContentObject_Release(&contentObject1); ccnxContentObject_Release(&contentObject2); ccnxContentObject_Release(&contentObject3); ccnxName_Release(&name1); ccnxName_Release(&name2); ccnxName_Release(&name3); }
LONGBOW_TEST_CASE(Local, _athenaLRUContentStoreEntry_Display) { CCNxName *name1 = ccnxName_CreateFromURI("lci:/first/entry"); CCNxContentObject *contentObject1 = ccnxContentObject_CreateWithDataPayload(name1, NULL); ccnxContentObject_SetExpiryTime(contentObject1, 87654321); _AthenaLRUContentStoreEntry *entry1 = _athenaLRUContentStoreEntry_Create(contentObject1); _athenaLRUContentStoreEntry_Display(entry1, 4); _athenaLRUContentStoreEntry_Release(&entry1); ccnxContentObject_Release(&contentObject1); ccnxName_Release(&name1); }
static CCNxMetaMessage * _mockRead(void *privateData, const uint64_t *microSeconds) { CCNxName *name = ccnxName_Create(); PARCBuffer *payload = parcBuffer_Allocate(10); CCNxContentObject *object = ccnxContentObject_CreateWithNameAndPayload(name, payload); ccnxName_Release(&name); parcBuffer_Release(&payload); CCNxMetaMessage *result = ccnxMetaMessage_CreateFromContentObject(object); ccnxContentObject_Release(&object); return result; }
LONGBOW_TEST_CASE(Global, ccnxMetaMessage_CreateFromContentObject) { CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); PARCBuffer *payload = parcBuffer_WrapCString("This is some data. It's not good data, but it is data."); CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload); CCNxMetaMessage *portalMessage = ccnxMetaMessage_CreateFromContentObject(contentObject); assertNotNull(portalMessage, "Expected a non-null portal message"); ccnxMetaMessage_Release(&portalMessage); ccnxContentObject_Release(&contentObject); parcBuffer_Release(&payload); ccnxName_Release(&name); }
static void _athenaLRUContentStoreEntry_Finalize(_AthenaLRUContentStoreEntry **entryPtr) { _AthenaLRUContentStoreEntry *entry = (_AthenaLRUContentStoreEntry *) *entryPtr; //printf("LRUContentStoreEntry being finalized. %p\n", entry); ccnxContentObject_Release(&entry->contentObject); if (entry->keyId) { parcBuffer_Release(&entry->keyId); } if (entry->contentObjectHash) { parcBuffer_Release(&entry->contentObjectHash); } }
LONGBOW_TEST_CASE(Global, ccnxContentObject_GetPayload) { CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); PARCBuffer *payload = parcBuffer_Allocate(100); CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, payload); ccnxContentObject_AssertValid(contentObject); PARCBuffer *actual = ccnxContentObject_GetPayload(contentObject); assertTrue(actual == payload, "Expected GetPayload() to return the original PARCBuffer"); ccnxName_Release(&name); parcBuffer_Release(&payload); ccnxContentObject_Release(&contentObject); }