예제 #1
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);
}
예제 #2
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, 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(Global, ccnxContentObject_Equals)
{
    CCNxName *nameA = ccnxName_CreateFromURI("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_CreateFromURI("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);
}
예제 #5
0
LONGBOW_TEST_CASE(Global, ccnxInterest_Equals)
{
    CCNxName *nameA = ccnxName_CreateFromURI("lci:/name");
    PARCBuffer *keyA = parcBuffer_Allocate(8);
    parcBuffer_PutUint64(keyA, 1234L);

    CCNxInterest *interestA = ccnxInterest_Create(nameA,
                                                  1000, /* lifetime */
                                                  keyA, /* KeyId */
                                                  NULL  /* ContentObjectHash */
                                                  );

    CCNxName *nameB = ccnxName_CreateFromURI("lci:/name");
    PARCBuffer *keyB = parcBuffer_Allocate(8);
    parcBuffer_PutUint64(keyB, 1234L);
    CCNxInterest *interestB = ccnxInterest_Create(nameB,
                                                  1000, /* lifetime */
                                                  keyB, /* KeyId */
                                                  NULL  /* ContentObjectHash */
                                                  );

    assertTrue(ccnxInterest_Equals(interestA, interestB), "Expected equivalent interests to be equal.");

    ccnxName_Release(&nameA);
    ccnxName_Release(&nameB);
    parcBuffer_Release(&keyA);
    parcBuffer_Release(&keyB);
    ccnxInterest_Release(&interestA);
    ccnxInterest_Release(&interestB);
}
예제 #6
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;
}
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);
}
예제 #8
0
void
testValidationSetV1_KeyId_KeyLocator_KeyId_KeyName(TestData *data,
                                                   bool (*set)(CCNxTlvDictionary *message, const PARCBuffer *keyid,
                                                               const CCNxKeyLocator *keyLocator),
                                                   bool (*test)(const CCNxTlvDictionary *message))
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/parc/validation/test");
    CCNxTlvDictionary *packetV1 = ccnxContentObject_CreateWithImplAndPayload(&CCNxContentObjectFacadeV1_Implementation,
                                                                             name,
                                                                             CCNxPayloadType_DATA,
                                                                             NULL);
    bool success = set(packetV1, data->keyid, data->locatorByName);
    assertTrue(success, "Failed to set on V1");

    bool testResult = test(packetV1);
    assertTrue(testResult, "Test function failed on V1 packet");

    PARCBuffer *testKeyId = ccnxValidationFacadeV1_GetKeyId(packetV1);
    assertTrue(parcBuffer_Equals(testKeyId, data->keyid), "keyid not equal");

    // XXX: TODO: GetKeyName() returns a Link, so it should be GetLink().
    //            It also creates a new object (the CCNxLink), so... needs thinking about.
    //            See BugzId: 3322

    CCNxLink *testLink = ccnxValidationFacadeV1_GetKeyName(packetV1);
    assertTrue(ccnxName_Equals(ccnxLink_GetName(testLink), data->keyname), "Keynames not equal");
    ccnxLink_Release(&testLink);

    ccnxName_Release(&name);
    ccnxTlvDictionary_Release(&packetV1);
}
예제 #9
0
void
testValidationSetV1_KeyId_KeyLocator_KeyId_Key(TestData *data,
                                               bool (*set)(CCNxTlvDictionary *message, const PARCBuffer *keyid,
                                                           const CCNxKeyLocator *keyLocator),
                                               bool (*test)(const CCNxTlvDictionary *message))
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/parc/validation/test");
    CCNxTlvDictionary *packetV1 = ccnxContentObject_CreateWithImplAndPayload(&CCNxContentObjectFacadeV1_Implementation,
                                                                             name,
                                                                             CCNxPayloadType_DATA,
                                                                             NULL);
    bool success = set(packetV1, data->keyid, data->locatorByKey);
    assertTrue(success, "Failed to set on V1");

    bool testResult = test(packetV1);
    assertTrue(testResult, "Test function failed on V1 packet");

    PARCBuffer *testKeyId = ccnxValidationFacadeV1_GetKeyId(packetV1);
    assertTrue(parcBuffer_Equals(testKeyId, data->keyid), "keyid not equal");

    PARCBuffer *testKey = ccnxValidationFacadeV1_GetPublicKey(packetV1);
    assertTrue(parcBuffer_Equals(testKey, data->key), "keys not equal");

    ccnxName_Release(&name);
    ccnxTlvDictionary_Release(&packetV1);
}
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_CreateFromURI(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);
}
예제 #11
0
TestData *
testData_Create(void)
{
    char keyidString[] = "the keyid";
    char keyString[] = "Memory, all alone in the moonlight";
    char certString[] = "The quick brown fox";

    TestData *data = parcMemory_AllocateAndClear(sizeof(TestData));
    assertNotNull(data, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(TestData));

    data->keyid = bufferFromString(sizeof(keyidString), keyidString);
    data->key = bufferFromString(sizeof(keyString), keyString);
    data->cert = bufferFromString(sizeof(certString), certString);
    data->keyname = ccnxName_CreateFromURI("lci:/lazy/dog");

    PARCBuffer *bb_id = parcBuffer_Wrap("choo choo", 9, 0, 9);
    PARCKeyId *keyid = parcKeyId_Create(bb_id);
    parcBuffer_Release(&bb_id);

    PARCKey *key = parcKey_CreateFromDerEncodedPublicKey(keyid, PARCSigningAlgorithm_RSA, data->key);

    data->locatorByKey = ccnxKeyLocator_CreateFromKey(key);
    parcKey_Release(&key);
    parcKeyId_Release(&keyid);

    CCNxLink *link = ccnxLink_Create(data->keyname, NULL, NULL);
    data->locatorByName = ccnxKeyLocator_CreateFromKeyLink(link);
    ccnxLink_Release(&link);

    return data;
}
예제 #12
0
LONGBOW_TEST_CASE(Global, ccnxContentObject_GetPayloadType)
{
    CCNxName *name = ccnxName_CreateFromURI("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);
}
예제 #13
0
/**
 * Given a command (e.g "fetch") and an optional target name (e.g. "file.txt"), create an appropriate CCNxInterest
 * and write it to the Portal.
 *
 * @param command The command to be handled.
 * @param targetName The name of the target content, if any, that the command applies to.
 *
 * @return true If a CCNxInterest for the specified command and optional target was successfully issued and answered.
 */
static bool
_executeUserCommand(const char *command, const char *targetName)
{
    bool result = false;
    CCNxPortalFactory *factory = _setupConsumerPortalFactory();

    CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Chunked);

    assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");

    // Given the user's command and optional target, create an Interest.
    CCNxInterest *interest = _createInterest(command, targetName);

    // Send the Interest through the Portal, and wait for a response.
    CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest);
    if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never)) {
        CCNxName *domainPrefix = ccnxName_CreateFromURI(tutorialCommon_DomainPrefix);  // e.g. 'lci:/ccnx/tutorial'

        result = _receiveResponseToIssuedInterest(portal, domainPrefix);

        ccnxName_Release(&domainPrefix);
    }

    ccnxMetaMessage_Release(&message);
    ccnxInterest_Release(&interest);
    ccnxPortal_Release(&portal);
    ccnxPortalFactory_Release(&factory);

    return result;
}
예제 #14
0
LONGBOW_TEST_CASE(Global, ccnxInterest_SetLifetime)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/name");
    PARCBuffer *key = parcBuffer_Allocate(8);
    parcBuffer_PutUint64(key, 1234L);

    uint32_t lifetime = 5000; // 5 seconds, in milliseconds

    CCNxInterest *interest = ccnxInterest_Create(name,
                                                 lifetime, /* lifetime */
                                                 key,      /* KeyId */
                                                 NULL      /* ContentObjectHash */
                                                 );

    uint32_t actual = ccnxInterest_GetLifetime(interest);

    assertTrue(actual == lifetime, "Expected the retrieved lifetime to be equal to the assigned one.");

    lifetime = 2000;
    ccnxInterest_SetLifetime(interest, lifetime);
    actual = ccnxInterest_GetLifetime(interest);

    assertTrue(actual == lifetime, "Expected the retrieved lifetime to be equal to the assigned one.");

    ccnxName_Release(&name);
    parcBuffer_Release(&key);
    ccnxInterest_Release(&interest);
}
예제 #15
0
LONGBOW_TEST_CASE(Global, ccnxInterest_SetContentObjectHashRestriction)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/name");
    PARCBuffer *coh = parcBuffer_Allocate(8);
    parcBuffer_PutUint64(coh, 77573L);

    CCNxInterest *interest = ccnxInterest_Create(name, CCNxInterestDefault_LifetimeMilliseconds, NULL, NULL);

    PARCBuffer *actual = ccnxInterest_GetContentObjectHashRestriction(interest);
    assertNull(actual, "Expected retrieved ContentObjectHash to be initially NULL");

    ccnxInterest_SetContentObjectHashRestriction(interest, coh);
    actual = ccnxInterest_GetContentObjectHashRestriction(interest);

    assertTrue(actual == coh, "Expected retrieved ContentObjectHash to be the same as assigned");

    // Re-setting is not yet supported. At the moment, you can only put the COHR once.
    // Now change it, and validate.
    //PARCBuffer *coh2 = parcBuffer_Allocate(8);
    //parcBuffer_PutUint64(coh2, 3262L);
    //ccnxInterest_SetContentObjectHashRestriction(interest, coh2);
    //actual = ccnxInterest_GetContentObjectHashRestriction(interest);
    //assertTrue(actual == coh2, "Expected retrieved ContentObjectHash to be the same as assigned");

    ccnxName_Release(&name);
    ccnxInterest_Release(&interest);
    parcBuffer_Release(&coh);
    //parcBuffer_Release(&coh2);
}
예제 #16
0
/**
 * Create and return a CCNxInterest whose Name contains our commend (e.g. "fetch" or "list"),
 * and, optionally, the name of a target object (e.g. "file.txt"). The newly created CCNxInterest
 * must eventually be released by calling ccnxInterest_Release().
 *
 * @param command The command to embed in the created CCNxInterest.
 * @param targetName The name of the content, if any, that the command applies to.
 *
 * @return A newly created CCNxInterest for the specified command and targetName.
 */
static CCNxInterest *
_createInterest(const char *command, const char *targetName)
{
    CCNxName *interestName = ccnxName_CreateFromURI(tutorialCommon_DomainPrefix); // Start with the prefix. We append to this.

    // Create a NameSegment for our command, which we will append after the prefix we just created.
    PARCBuffer *commandBuffer = parcBuffer_WrapCString((char *) command);
    CCNxNameSegment *commandSegment = ccnxNameSegment_CreateTypeValue(CCNxNameLabelType_NAME, commandBuffer);
    parcBuffer_Release(&commandBuffer);

    // Append the new command segment to the prefix
    ccnxName_Append(interestName, commandSegment);
    ccnxNameSegment_Release(&commandSegment);

    // If we have a target, then create another NameSegment for it and append that.
    if (targetName != NULL) {
        // Create a NameSegment for our target object
        PARCBuffer *targetBuf = parcBuffer_WrapCString((char *) targetName);
        CCNxNameSegment *targetSegment = ccnxNameSegment_CreateTypeValue(CCNxNameLabelType_NAME, targetBuf);
        parcBuffer_Release(&targetBuf);


        // Append it to the ccnxName.
        ccnxName_Append(interestName, targetSegment);
        ccnxNameSegment_Release(&targetSegment);
    }

    CCNxInterest *result = ccnxInterest_CreateSimple(interestName);
    ccnxName_Release(&interestName);

    return result;
}
예제 #17
0
LONGBOW_TEST_CASE(Global, ccnxInterest_SetPayloadAndId)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/name");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);

    CCNxInterestInterface *impl = ccnxInterestInterface_GetInterface(interest);

    if (impl->getPayload) {
        assertNull(ccnxInterest_GetPayload(interest), "Expected a NULL payload");
    }

    if (impl->getPayload && impl->setPayload) {
        PARCBuffer *payload = parcBuffer_WrapCString("impls have pimples");

        ccnxInterest_SetPayloadAndId(interest, payload);

        PARCBuffer *payloadOut = ccnxInterest_GetPayload(interest);

        assertTrue(parcBuffer_Equals(payload, payloadOut), "Expected an equal buffer");

        CCNxName *nameAfterPayload = ccnxInterest_GetName(interest);
        CCNxNameSegment *segment = ccnxName_GetSegment(nameAfterPayload, ccnxName_GetSegmentCount(nameAfterPayload) - 1);

        assertTrue(ccnxNameSegment_GetType(segment) == CCNxNameLabelType_PAYLOADID, "Expected to find a payload ID appended to the name");

        parcBuffer_Release(&payload);
    }
    ccnxName_Release(&name);
    ccnxInterest_Release(&interest);
}
예제 #18
0
파일: athena.c 프로젝트: chris-wood/ghost
Athena *
athena_Create(size_t contentStoreSizeInMB)
{
    Athena *athena = parcObject_CreateAndClearInstance(Athena);

    athena->athenaName = ccnxName_CreateFromURI(CCNxNameAthena_Forwarder);
    assertNotNull(athena->athenaName, "Failed to create forwarder name (%s)", CCNxNameAthena_Forwarder);

    athena->athenaFIB = athenaFIB_Create();
    assertNotNull(athena->athenaFIB, "Failed to create FIB");

    athena->athenaPIT = athenaPIT_Create();
    assertNotNull(athena->athenaPIT, "Failed to create PIT");

    AthenaLRUContentStoreConfig storeConfig;
    storeConfig.capacityInMB = contentStoreSizeInMB;

    athena->athenaContentStore = athenaContentStore_Create(&AthenaContentStore_LRUImplementation, &storeConfig);
    assertNotNull(athena->athenaContentStore, "Failed to create Content Store");

    athena->athenaTransportLinkAdapter = athenaTransportLinkAdapter_Create(_removeLink, athena);
    assertNotNull(athena->athenaTransportLinkAdapter, "Failed to create Transport Link Adapter");

    athena->log = _athena_logger_create();
    athena->athenaState = Athena_Running;

    return athena;
}
예제 #19
0
LONGBOW_TEST_CASE(Global, ccnxContentObject_AcquireRelease)
{
    CCNxName *name = ccnxName_CreateFromURI("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");
}
예제 #20
0
static int
_athenactl_RemoveLink(PARCIdentity *identity, int argc, char **argv)
{
    if (argc < 1) {
        printf("usage: remove link <linkName>\n");
        return 1;
    }

    CCNxName *name = ccnxName_CreateFromURI(CCNxNameAthenaCommand_LinkDisconnect);
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    ccnxName_Release(&name);

    PARCBuffer *payload = parcBuffer_AllocateCString(argv[0]);
    ccnxInterest_SetPayload(interest, payload);
    parcBuffer_Release(&payload);

    const char *result = _athenactl_SendInterestControl(identity, interest);
    if (result) {
        printf("Link: %s\n", result);
        parcMemory_Deallocate(&result);
    }

    ccnxMetaMessage_Release(&interest);

    return 0;
}
예제 #21
0
static int
_athenactl_Run(PARCIdentity *identity, int argc, char **argv)
{
    if (argc < 1) {
        printf("usage: spawn <port | link specification>\n");
        return 1;
    }

    char *linkSpecification = argv[0];
    char constructedLinkSpecification[MAXPATHLEN] = { 0 };

    // Short-cut, user can specify just a port and we will construct a default tcp listener specification
    if (atoi(argv[0]) != 0) {
        sprintf(constructedLinkSpecification, "tcp://localhost:%d/listener", atoi(argv[0]));
        linkSpecification = constructedLinkSpecification;
    }

    CCNxName *name = ccnxName_CreateFromURI(CCNxNameAthenaCommand_Run);
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    ccnxName_Release(&name);

    PARCBuffer *payload = parcBuffer_AllocateCString(linkSpecification);
    ccnxInterest_SetPayload(interest, payload);
    parcBuffer_Release(&payload);

    const char *result = _athenactl_SendInterestControl(identity, interest);
    if (result) {
        printf("%s\n", result);
        parcMemory_Deallocate(&result);
    }

    ccnxMetaMessage_Release(&interest);

    return 0;
}
예제 #22
0
static int
_athenactl_RemoveRoute(PARCIdentity *identity, int argc, char **argv)
{
    if (argc < 2) {
        printf("usage: remove route <linkName> <prefix>\n");
        return 1;
    }

    CCNxName *name = ccnxName_CreateFromURI(CCNxNameAthenaCommand_FIBRemoveRoute);
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    ccnxName_Release(&name);

    char *linkName = argv[0];
    char *prefix = argv[1];

    // passed in as <linkName> <prefix>, passed on as <prefix> <linkname>
    char routeArguments[MAXPATHLEN];
    sprintf(routeArguments, "%s %s", prefix, linkName);
    PARCBuffer *payload = parcBuffer_AllocateCString(routeArguments);
    ccnxInterest_SetPayload(interest, payload);
    parcBuffer_Release(&payload);

    const char *result = _athenactl_SendInterestControl(identity, interest);
    if (result) {
        printf("FIB: %s\n", result);
        parcMemory_Deallocate(&result);
    }

    ccnxMetaMessage_Release(&interest);

    return 0;
}
예제 #23
0
LONGBOW_TEST_CASE(Global, ccnxContentObject_GetKeyId)
{
    CCNxName *name = ccnxName_CreateFromURI("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);
}
예제 #24
0
LONGBOW_TEST_CASE(Local, _athenaLRUContentStore_ProcessMessage_StatHits)
{
    AthenaLRUContentStore *impl = _createLRUContentStore();

    CCNxName *name = ccnxName_CreateFromURI(CCNxNameAthena_ContentStore "/stat/hits");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    ccnxName_Release(&name);

    CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest);
    ccnxInterest_Release(&interest);

    CCNxMetaMessage *response = _athenaLRUContentStore_ProcessMessage(impl, message);

    assertNotNull(response, "Expected a response to ProcessMessage()");
    assertTrue(ccnxMetaMessage_IsContentObject(response), "Expected a content object");

    CCNxContentObject *content = ccnxMetaMessage_GetContentObject(response);

    PARCBuffer *payload = ccnxContentObject_GetPayload(content);
    parcBuffer_Display(payload, 0);

    ccnxMetaMessage_Release(&message);
    ccnxMetaMessage_Release(&response);
    _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl);
}
예제 #25
0
LONGBOW_TEST_CASE(Global, ccnxInterest_SetGetPayload)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/name");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    CCNxName *origNameCopy = ccnxName_Copy(name);

    CCNxInterestInterface *impl = ccnxInterestInterface_GetInterface(interest);

    if (impl->getPayload) {
        assertNull(ccnxInterest_GetPayload(interest), "Expected a NULL payload");
    }

    if (impl->getPayload && impl->setPayload) {
        PARCBuffer *payload = parcBuffer_WrapCString("impls have pimples");
        ccnxInterest_SetPayload(interest, payload);

        PARCBuffer *payloadOut = ccnxInterest_GetPayload(interest);

        assertTrue(parcBuffer_Equals(payload, payloadOut), "Expected an equal buffer");

        CCNxName *nameAfterPayload = ccnxInterest_GetName(interest);
        assertTrue(ccnxName_Equals(nameAfterPayload, origNameCopy), "Expected an unmodified name");

        parcBuffer_Release(&payload);
    }
    ccnxName_Release(&name);
    ccnxName_Release(&origNameCopy);
    ccnxInterest_Release(&interest);
}
예제 #26
0
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);
}
예제 #27
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);
}
예제 #28
0
LONGBOW_TEST_CASE(Global, ccnxInterest_CreateSimple)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/name");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);

    ccnxName_Release(&name);
    ccnxInterest_Release(&interest);
}
예제 #29
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);
}
예제 #30
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);
}