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, 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);
}
Пример #5
0
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, 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(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_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);
}
Пример #10
0
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);
}
Пример #11
0
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);
}
Пример #12
0
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);
}
Пример #13
0
int
reader_writer(CCNxPortalFactory *factory, const char *uri)
{

    CCNxPortal *portal = ccnxPortalFactory_GetInstance(factory, ccnxPortalTypeDatagram, ccnxPortalProtocol_TLV, &ccnxPortalAttributes_Blocking);

    CCNxName *prefix = ccnxName_CreateFromURI(uri);
    CCNxName *bye = ccnxName_CreateFromURI("lci:/Hello/Goodbye%21");
    CCNxName *contentname = ccnxName_CreateFromURI("lci:/Hello/World");

    if (ccnxPortal_Listen(portal, prefix, 365 * 86400, CCNxStackTimeout_Never)) {
        CCNxMetaMessage *msg;

        while ((msg = ccnxPortal_Receive(portal, CCNxStackTimeout_Never)) != NULL) {

            if (ccnxMetaMessage_IsInterest(msg)) {
                CCNxInterest *interest = ccnxMetaMessage_GetInterest(msg);

                CCNxName *interestName = ccnxInterest_GetName(interest);

                if (ccnxName_Equals(interestName, contentname)) {
                    const PARCKeyId *publisherKeyId = ccnxPortal_GetKeyId(portal);

                    char buffer[128];
                    time_t theTime = time(0);
                    sprintf(buffer, "Hello World. The time is %s", ctime(&theTime));

                    PARCBuffer *payload = parcBuffer_CreateFromArray(buffer, 128);
                    parcBuffer_Flip(payload);

                    PARCBuffer *b = parcBuffer_Acquire(payload);
                    CCNxContentObject *uob = ccnxContentObject_CreateWithDataPayload(contentname, b);

                    // missing NULL check, case 1024

                    CCNxMetaMessage *message = ccnxMetaMessage_CreateFromContentObject(uob);
                    if (ccnxPortal_Send(portal, message, CCNxTransportStackTimeCCNxStackTimeout_Neverout_Never) == false) {
                        fprintf(stderr, "ccnx_write failed\n");
                    }
                    // ccnxMessage_Release(message);
                } else if (ccnxName_Equals(interestName, bye)) {
                    break;
                }
            } else {
                ccnxMetaMessage_Display(msg, 0);
            }
            ccnxMetaMessage_Release(&msg);
        }
    }

    ccnxName_Release(&prefix);
    ccnxName_Release(&bye);
    ccnxName_Release(&contentname);

    ccnxPortal_Release(&portal);

    return 0;
}
Пример #14
0
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);
}
Пример #15
0
/**
 * Given a Name, a payload, and the number of the last chunk, create a CCNxContentObject suitable for
 * passing to the Portal. This new CCNxContentObject must eventually be released by calling
 * ccnxContentObject_Release().
 *
 * @param name [in] The CCNxName to use when creating the new ContentObject.
 * @param payload [in] A PARCBuffer to use as the payload of the new ContentObject.
 * @param finalChunkNumber [in] The number of the final chunk that will be required to completely transfer
 *        the requested content.
 *
 * @return A newly created CCNxContentObject with the specified name, payload, and finalChunkNumber.
 */
static CCNxContentObject *
_createContentObject(const CCNxName *name, PARCBuffer *payload, uint64_t finalChunkNumber)
{
    // In the call below, we are un-const'ing name for ccnxContentObject_CreateWithDataPayload()
    // but we will not be changing it.
    CCNxContentObject *result = ccnxContentObject_CreateWithDataPayload((CCNxName *) name, payload);
    ccnxContentObject_SetFinalChunkNumber(result, finalChunkNumber);

    return result;
}
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);
}
Пример #17
0
int
ccnServe(const PARCIdentity *identity, const CCNxName *listenName, const char *commandString)
{
    parcSecurity_Init();

    CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity);

    CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message);
    assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");

    if (ccnxPortal_Listen(portal, listenName, 365 * 86400, CCNxStackTimeout_Never)) {
        while (true) {
            CCNxMetaMessage *request = ccnxPortal_Receive(portal, CCNxStackTimeout_Never);

            if (request == NULL) {
                break;
            }

            CCNxInterest *interest = ccnxMetaMessage_GetInterest(request);

            if (interest != NULL) {
                CCNxName *interestName = ccnxInterest_GetName(interest);

                PARCBuffer *payload = makePayload(interestName, commandString);

                CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(interestName, payload);

                CCNxMetaMessage *message = ccnxMetaMessage_CreateFromContentObject(contentObject);
                if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never) == false) {
                    fprintf(stderr, "ccnxPortal_Write failed: %d\n", ccnxPortal_GetError(portal));
                }
                {
                    char *name = ccnxName_ToString(interestName);
                    time_t theTime = time(0);
                    char *time = ctime(&theTime);
                    printf("%24.24s  %s\n", time, name);
                    parcMemory_Deallocate((void **) &name);
                }

                parcBuffer_Release(&payload);
            }
            ccnxMetaMessage_Release(&request);
        }
    }

    ccnxPortal_Release(&portal);

    ccnxPortalFactory_Release(&factory);

    parcSecurity_Fini();

    return 0;
}
Пример #18
0
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);
}
Пример #19
0
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);
}
Пример #20
0
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);
}
Пример #21
0
/**
 * Create a CCNxContentObject with the given LCI name, chunknumber, and payload.
 */
static CCNxContentObject *
_createContentObject(char *lci, uint64_t chunkNum, PARCBuffer *payload)
{
    CCNxName *name = ccnxName_CreateFromURI(lci);
    CCNxNameSegment *chunkSegment = ccnxNameSegmentNumber_Create(CCNxNameLabelType_CHUNK, chunkNum);
    ccnxName_Append(name, chunkSegment);

    CCNxContentObject *result = ccnxContentObject_CreateWithDataPayload(name, payload);

    ccnxName_Release(&name);
    ccnxNameSegment_Release(&chunkSegment);

    return result;
}
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);
}
LONGBOW_TEST_CASE(Global, ccnxContentObject_HasFinalChunkNumber)
{
    CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
    PARCBuffer *payload = parcBuffer_Allocate(100);

    CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, payload);
    assertFalse(ccnxContentObject_HasFinalChunkNumber(contentObject), "Expected no final chunk number");

    ccnxContentObject_SetFinalChunkNumber(contentObject, 100);
    ccnxContentObject_AssertValid(contentObject);
    assertTrue(ccnxContentObject_HasFinalChunkNumber(contentObject), "Expected HasFinalChunkNumber to return true");
    assertTrue(ccnxContentObject_GetFinalChunkNumber(contentObject) == 100, "Expected final chunk number to be 100");

    ccnxName_Release(&name);
    parcBuffer_Release(&payload);
    ccnxContentObject_Release(&contentObject);
}
LONGBOW_TEST_CASE(Global, ccnxContentObject_SetSignature)
{
    CCNxName *name = ccnxName_CreateFromCString("lci:/hello/dolly");
    PARCBuffer *payload = parcBuffer_WrapCString("hello");

    CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, payload);

    PARCBuffer *keyId = parcBuffer_WrapCString("keyhash");
    PARCBuffer *sigbits = parcBuffer_WrapCString("siggybits");
    PARCSignature *signature = parcSignature_Create(PARCSigningAlgorithm_RSA, PARC_HASH_SHA256, parcBuffer_Flip(sigbits));

    ccnxContentObject_SetSignature(contentObject, keyId, signature, NULL);

    parcBuffer_Release(&payload);
    parcBuffer_Release(&sigbits);
    parcBuffer_Release(&keyId);
    parcSignature_Release(&signature);
    ccnxName_Release(&name);
    ccnxContentObject_Release(&contentObject);
}
static CCNxTlvDictionary *
createSignedContentObject(void)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/some/name");
    PARCBuffer *payload = parcBuffer_Flip(parcBuffer_PutArray(parcBuffer_Allocate(20), 11, (uint8_t *) "the payload"));
    CCNxTlvDictionary *contentObject = ccnxContentObject_CreateWithDataPayload(name, payload);
    parcBuffer_Release(&payload);
    ccnxName_Release(&name);

    PARCBuffer *keyid = parcBuffer_Flip(parcBuffer_PutArray(parcBuffer_Allocate(20), 5, (uint8_t *) "keyid"));
    ccnxValidationRsaSha256_Set(contentObject, keyid, NULL);
    parcBuffer_Release(&keyid);

    PARCBuffer *sigbits = parcBuffer_WrapCString("the signature");
    PARCSignature *signature = parcSignature_Create(PARCSigningAlgorithm_RSA, PARC_HASH_SHA256, parcBuffer_Flip(sigbits));
    ccnxContentObject_SetSignature(contentObject, keyid, signature, NULL);

    parcSignature_Release(&signature);
    parcBuffer_Release(&sigbits);

    return contentObject;
}
Пример #26
0
static CCNxMetaMessage *
_create_linkList_response(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, CCNxName *ccnxName)
{
    PARCJSONArray *jsonLinkList = parcJSONArray_Create();

    for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->listenerList); index++) {
        AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->listenerList, index);
        const char *linkName = athenaTransportLink_GetName(athenaTransportLink);
        bool notLocal = athenaTransportLink_IsNotLocal(athenaTransportLink);
        bool localForced = athenaTransportLink_IsForceLocal(athenaTransportLink);
        PARCJSON *jsonItem = parcJSON_Create();
        parcJSON_AddString(jsonItem, "linkName", linkName);
        parcJSON_AddInteger(jsonItem, "index", -1);
        parcJSON_AddBoolean(jsonItem, "notLocal", notLocal);
        parcJSON_AddBoolean(jsonItem, "localForced", localForced);

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

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

        if (notLocal) {
            parcLog_Debug(athenaTransportLinkAdapter->log, "\n    Link listener%s: %s", localForced ? " (forced remote)" : "", linkName);
        } else {
            parcLog_Debug(athenaTransportLinkAdapter->log, "\n    Link listener%s: %s", localForced ? " (forced local)" : "", linkName);
        }
    }
    for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->instanceList); index++) {
        AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, index);
        if (athenaTransportLink) {
            const char *linkName = athenaTransportLink_GetName(athenaTransportLink);
            bool notLocal = athenaTransportLink_IsNotLocal(athenaTransportLink);
            bool localForced = athenaTransportLink_IsForceLocal(athenaTransportLink);
            PARCJSON *jsonItem = parcJSON_Create();
            parcJSON_AddString(jsonItem, "linkName", linkName);
            parcJSON_AddInteger(jsonItem, "index", index);
            parcJSON_AddBoolean(jsonItem, "notLocal", notLocal);
            parcJSON_AddBoolean(jsonItem, "localForced", localForced);

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

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

            if (notLocal) {
                parcLog_Debug(athenaTransportLinkAdapter->log, "\n    Link instance [%d] %s: %s", index, localForced ? "(forced remote)" : "(remote)", linkName);
            } else {
                parcLog_Debug(athenaTransportLinkAdapter->log, "\n    Link instance [%d] %s: %s", index, localForced ? "(forced local)" : "(local)", linkName);
            }
        }
    }

    char *jsonString = parcJSONArray_ToString(jsonLinkList);

    parcJSONArray_Release(&jsonLinkList);

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

    CCNxContentObject *contentObject =
        ccnxContentObject_CreateWithDataPayload(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;
}
Пример #27
0
LONGBOW_TEST_CASE(Local, putContentAndExpireByExpiryTime)
{
    AthenaLRUContentStoreConfig config;
    config.capacityInMB = 1; // 2M

    AthenaLRUContentStore *impl = _athenaLRUContentStore_Create(&config);

    uint64_t now = parcClock_GetTime(impl->wallClock);

    PARCBuffer *payload = parcBuffer_Allocate(300 * 1000); // 300K payload. Should fit 3 into the store.

    CCNxName *name1 = ccnxName_CreateFromURI("lci:/object/1");
    CCNxName *name2 = ccnxName_CreateFromURI("lci:/object/2");
    CCNxName *name3 = ccnxName_CreateFromURI("lci:/object/3");
    CCNxName *name4 = ccnxName_CreateFromURI("lci:/object/4");

    CCNxContentObject *contentObject1 = ccnxContentObject_CreateWithDataPayload(name1, payload);
    _AthenaLRUContentStoreEntry *entry = _athenaLRUContentStoreEntry_Create(contentObject1);
    entry->hasExpiryTime = true;
    entry->expiryTime = now + 2000000;
    bool status = _athenaLRUContentStore_PutLRUContentStoreEntry(impl, entry);
    _athenaLRUContentStoreEntry_Release(&entry);
    assertTrue(status, "Expected to put the content in the store");

    CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name2, payload);
    entry = _athenaLRUContentStoreEntry_Create(contentObject2);
    entry->expiryTime = now - 10000; // This one expires first. (it's already expired)
    entry->hasExpiryTime = true;
    status = _athenaLRUContentStore_PutLRUContentStoreEntry(impl, entry);
    _athenaLRUContentStoreEntry_Release(&entry);
    assertTrue(status, "Expected to put the content in the store");

    CCNxContentObject *contentObject3 = ccnxContentObject_CreateWithDataPayload(name3, payload);
    entry = _athenaLRUContentStoreEntry_Create(contentObject3);
    entry->expiryTime = now + 3000000;
    entry->hasExpiryTime = true;
    status = _athenaLRUContentStore_PutLRUContentStoreEntry(impl, entry);
    _athenaLRUContentStoreEntry_Release(&entry);
    assertTrue(status, "Expected to put the content in the store");

    // At this point, there are three items in the store. Try to put in a 4th, which should force the one
    // with the earliest expiration time to be expired.

    CCNxContentObject *contentObject4 = ccnxContentObject_CreateWithDataPayload(name4, payload);
    entry = _athenaLRUContentStoreEntry_Create(contentObject4);
    entry->expiryTime = now + 3000000;
    entry->hasExpiryTime = true;
    status = _athenaLRUContentStore_PutLRUContentStoreEntry(impl, entry);
    _athenaLRUContentStoreEntry_Release(&entry);
    assertTrue(status, "Expected to put the content in the store");

    assertTrue(impl->currentSizeInBytes < impl->maxSizeInBytes, "Expected the current store size to be less than the capacity");

    athenaLRUContentStore_Display(impl, 0);

    // Now check that the oldest was removed.
    CCNxInterest *interest = ccnxInterest_CreateSimple(name2);
    CCNxContentObject *match = _athenaLRUContentStore_GetMatch(impl, interest);
    assertNull(match, "Expected the content for name2 to have been removed from the store");
    ccnxInterest_Release(&interest);

    // Now check that the others still exist.
    interest = ccnxInterest_CreateSimple(name1);
    match = _athenaLRUContentStore_GetMatch(impl, interest);
    assertNotNull(match, "Expected the content for name1 to be in the store");
    ccnxInterest_Release(&interest);

    interest = ccnxInterest_CreateSimple(name3);
    match = _athenaLRUContentStore_GetMatch(impl, interest);
    assertNotNull(match, "Expected the content for name3 to be in the store");
    ccnxInterest_Release(&interest);

    interest = ccnxInterest_CreateSimple(name4);
    match = _athenaLRUContentStore_GetMatch(impl, interest);
    assertNotNull(match, "Expected the content for name4 to be in the store");
    ccnxInterest_Release(&interest);

    ccnxContentObject_Release(&contentObject1);
    ccnxContentObject_Release(&contentObject2);
    ccnxContentObject_Release(&contentObject3);
    ccnxContentObject_Release(&contentObject4);
    ccnxName_Release(&name1);
    ccnxName_Release(&name2);
    ccnxName_Release(&name3);
    ccnxName_Release(&name4);
    parcBuffer_Release(&payload);

    _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl);
}