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); }
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; }
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); }
LONGBOW_TEST_CASE(Global, ccnxPortal_Send_ImmediateTimeout_WouldBlock) { TestData *data = longBowTestCase_GetClipBoardData(testCase); CCNxPortal *portalOut = ccnxPortalFactory_CreatePortal(data->factory, TEST_STACK); CCNxName *name = ccnxName_CreateFromCString("lci:/Hello/World"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); CCNxMetaMessage *interestMessage = ccnxMetaMessage_CreateFromInterest(interest); for (int count = 0; count < 10000; count++) { if (ccnxPortal_Send(portalOut, interestMessage, CCNxStackTimeout_Immediate) == false) { break; } count++; } assertFalse(ccnxPortal_Send(portalOut, interestMessage, CCNxStackTimeout_Immediate), "Expected send to fail due to blocking"); ccnxMetaMessage_Release(&interestMessage); ccnxInterest_Release(&interest); ccnxPortal_Release(&portalOut); }
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; }
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); }
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); }
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); }
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); }
/** * 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; }
LONGBOW_TEST_CASE(Global, ccnxPortal_Receive_ImmediateTimeout) { TestData *data = longBowTestCase_GetClipBoardData(testCase); CCNxPortal *portalOut = ccnxPortalFactory_CreatePortal(data->factory, TEST_STACK); CCNxPortal *portalIn = ccnxPortalFactory_CreatePortal(data->factory, TEST_STACK); CCNxName *name = ccnxName_CreateFromCString("lci:/Hello/World"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); CCNxMetaMessage *interestMessage = ccnxMetaMessage_CreateFromInterest(interest); if (ccnxPortal_Send(portalOut, interestMessage, CCNxStackTimeout_Never)) { sleep(2); ccnxMetaMessage_Release(&interestMessage); CCNxMetaMessage *message = ccnxPortal_Receive(portalIn, CCNxStackTimeout_Immediate); assertTrue(ccnxInterest_Equals(interest, ccnxMetaMessage_GetInterest(message)), "Expected Interest to be received."); ccnxMetaMessage_Release(&message); } ccnxInterest_Release(&interest); ccnxPortal_Release(&portalIn); ccnxPortal_Release(&portalOut); }
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; }
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, ccnxInterest_CreateSimple) { CCNxName *name = ccnxName_CreateFromURI("lci:/name"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); ccnxInterest_Release(&interest); }
LONGBOW_TEST_CASE(Global, athena_ForwarderEngine) { // Create a new athena instance Athena *newAthena = athena_Create(AthenaDefaultContentStoreSize); assertNotNull(newAthena, "Could not create a new Athena instance"); // Add a link PARCURI *connectionURI = parcURI_Parse("tcp://localhost:50100/listener"); const char *result = athenaTransportLinkAdapter_Open(newAthena->athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed\n"); parcURI_Release(&connectionURI); pthread_t thread; // Passing in a reference that will be released by the new thread as the thread may not // have time to acquire a reference itself before we release our reference. int ret = pthread_create(&thread, NULL, athena_ForwarderEngine, (void *) athena_Acquire(newAthena)); assertTrue(ret == 0, "pthread_create failed"); athena_Release(&newAthena); // Create a new local instance we can send a quit message from Athena *athena = athena_Create(AthenaDefaultContentStoreSize); assertNotNull(athena, "Could not create a new Athena instance"); connectionURI = parcURI_Parse("tcp://localhost:50100/name=TCP_1"); result = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); PARCBitVector *linkVector = parcBitVector_Create(); int linkId = athenaTransportLinkAdapter_LinkNameToId(athena->athenaTransportLinkAdapter, "TCP_1"); parcBitVector_Set(linkVector, linkId); CCNxName *name = ccnxName_CreateFromCString(CCNxNameAthenaCommand_Quit); CCNxMetaMessage *interest = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); athena_EncodeMessage(interest); PARCBitVector *resultVector = athenaTransportLinkAdapter_Send(athena->athenaTransportLinkAdapter, interest, linkVector); assertNull(resultVector, "athenaTransportLinkAdapter_Send failed"); ccnxMetaMessage_Release(&interest); parcBitVector_Release(&linkVector); CCNxMetaMessage *response = athenaTransportLinkAdapter_Receive(athena->athenaTransportLinkAdapter, &resultVector, -1); assertNotNull(resultVector, "athenaTransportLinkAdapter_Receive failed"); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) > 0, "athenaTransportLinkAdapter_Receive failed"); parcBitVector_Release(&resultVector); ccnxMetaMessage_Release(&response); athenaTransportLinkAdapter_CloseByName(athena->athenaTransportLinkAdapter, "TCP_1"); pthread_join(thread, NULL); // Wait for the child athena to actually finish athena_Release(&athena); }
LONGBOW_TEST_CASE(Global, athenaTransportLinkModuleUDP_SendReceive) { PARCURI *connectionURI; const char *result; AthenaTransportLinkAdapter *athenaTransportLinkAdapter = athenaTransportLinkAdapter_Create(_removeLink, NULL); assertNotNull(athenaTransportLinkAdapter, "athenaTransportLinkAdapter_Create returned NULL"); connectionURI = parcURI_Parse("udp://127.0.0.1:40000/Listener/name=UDPListener"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); connectionURI = parcURI_Parse("udp://127.0.0.1:40000/name=UDP_1"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); athenaTransportLinkAdapter_Poll(athenaTransportLinkAdapter, 0); CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); CCNxMetaMessage *ccnxMetaMessage = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); PARCBitVector *sendVector = parcBitVector_Create(); int linkId = athenaTransportLinkAdapter_LinkNameToId(athenaTransportLinkAdapter, "UDP_1"); parcBitVector_Set(sendVector, linkId); athena_EncodeMessage(ccnxMetaMessage); PARCBitVector *resultVector; resultVector = athenaTransportLinkAdapter_Send(athenaTransportLinkAdapter, ccnxMetaMessage, sendVector); assertNotNull(resultVector, "athenaTransportLinkAdapter_Send failed"); parcBitVector_Release(&resultVector); ccnxMetaMessage_Release(&ccnxMetaMessage); parcBitVector_Release(&sendVector); usleep(1000); ccnxMetaMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertNotNull(resultVector, "athenaTransportLinkAdapter_Receive failed"); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) == 1, "athenaTransportLinkAdapter_Receive return message with more than one ingress link"); assertNotNull(ccnxMetaMessage, "athenaTransportLinkAdapter_Receive failed to provide message"); parcBitVector_Release(&resultVector); ccnxMetaMessage_Release(&ccnxMetaMessage); // Close one end of the connection and send a message from the other. int closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "UDPListener"); assertTrue(closeResult == 0, "athenaTransportLinkAdapter_CloseByName failed (%s)", strerror(errno)); ccnxMetaMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 1); assertNull(resultVector, "athenaTransportLinkAdapter_Receive should have failed"); closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "UDP_1"); assertTrue(closeResult == 0, "athenaTransportLinkAdapter_CloseByName failed (%s)", strerror(errno)); athenaTransportLinkAdapter_Destroy(&athenaTransportLinkAdapter); }
LONGBOW_TEST_CASE(Global, ccnxInterest_AssertValid) { CCNxName *name = ccnxName_CreateFromURI("lci:/boose/roo/pie"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); ccnxInterest_AssertValid(interest); ccnxName_Release(&name); ccnxInterest_Release(&interest); }
LONGBOW_TEST_CASE(Global, athenaTransportLinkModuleUDP_MTU) { PARCURI *connectionURI; const char *result; AthenaTransportLinkAdapter *athenaTransportLinkAdapter = athenaTransportLinkAdapter_Create(_removeLink, NULL); assertNotNull(athenaTransportLinkAdapter, "athenaTransportLinkAdapter_Create returned NULL"); connectionURI = parcURI_Parse("udp://127.0.0.1:40000/Listener/name=UDPListener/mtu="); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result == NULL, "athenaTransportLinkAdapter_Open failed to detect improper MTU (%s)", strerror(errno)); parcURI_Release(&connectionURI); connectionURI = parcURI_Parse("udp://127.0.0.1:40000/Listener/name=UDPListener/mtu=20"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); connectionURI = parcURI_Parse("udp://127.0.0.1:40000/name=UDP_1/mtu=20"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); athenaTransportLinkAdapter_Poll(athenaTransportLinkAdapter, 0); CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); CCNxMetaMessage *ccnxMetaMessage = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); PARCBitVector *sendVector = parcBitVector_Create(); int linkId = athenaTransportLinkAdapter_LinkNameToId(athenaTransportLinkAdapter, "UDP_1"); parcBitVector_Set(sendVector, linkId); athena_EncodeMessage(ccnxMetaMessage); PARCBitVector *resultVector; resultVector = athenaTransportLinkAdapter_Send(athenaTransportLinkAdapter, ccnxMetaMessage, sendVector); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) == 0, "athenaTransportLinkAdapter_Send should have failed"); assertTrue(errno == EMSGSIZE, "athenaTransportLinkAdapter_Send should have failed with EMSGSIZE (%d): %s", errno, strerror(errno)); parcBitVector_Release(&resultVector); ccnxMetaMessage_Release(&ccnxMetaMessage); parcBitVector_Release(&sendVector); usleep(1000); ccnxMetaMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertNull(ccnxMetaMessage, "athenaTransportLinkAdapter_Receive should have failed"); int closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "UDPListener"); assertTrue(closeResult == 0, "athenaTransportLinkAdapter_CloseByName failed (%s)", strerror(errno)); closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "UDP_1"); assertTrue(closeResult == 0, "athenaTransportLinkAdapter_CloseByName failed (%s)", strerror(errno)); athenaTransportLinkAdapter_Destroy(&athenaTransportLinkAdapter); }
LONGBOW_TEST_CASE(Global, ccnxInterest_GetName) { CCNxName *name = ccnxName_CreateFromURI("lci:/name"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); CCNxName *actual = ccnxInterest_GetName(interest); assertTrue(ccnxName_Equals(name, actual), "Expected the same name."); ccnxName_Release(&name); ccnxInterest_Release(&interest); }
LONGBOW_TEST_CASE(Global, ccnxMetaMessage_CreateFromInterest) { CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); CCNxMetaMessage *portalMessage = ccnxMetaMessage_CreateFromInterest(interest); assertNotNull(portalMessage, "Expected a non-null portal message"); ccnxMetaMessage_Release(&portalMessage); ccnxInterest_Release(&interest); ccnxName_Release(&name); }
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(EmptyImplementation, apiFunctions) { AthenaContentStore *store = athenaContentStore_Create(&EmptyContentStoreImplementation, NULL); CCNxName *name = ccnxName_CreateFromURI("lci:/pie/is/always/good"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); athena_EncodeMessage(interest); assertNull(athenaContentStore_ProcessMessage(store, interest), "Expected a NULL response."); ccnxName_Release(&name); ccnxInterest_Release(&interest); athenaContentStore_Release(&store); }
LONGBOW_TEST_CASE(Global, ccnxMetaMessage_GetInterest) { CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); CCNxMetaMessage *portalMessage = ccnxMetaMessage_CreateFromInterest(interest); CCNxInterest *reference = ccnxMetaMessage_GetInterest(portalMessage); assertTrue(ccnxInterest_Equals(interest, reference), "Expected reference to equal original interest"); ccnxInterest_AssertValid(reference); ccnxInterest_Release(&reference); ccnxMetaMessage_Release(&portalMessage); ccnxName_Release(&name); }
LONGBOW_TEST_CASE(Global, ccnxMetaMessage_IsInterest) { CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); CCNxMetaMessage *portalMessage = ccnxMetaMessage_CreateFromInterest(interest); assertTrue(ccnxMetaMessage_IsInterest(portalMessage), "Expected portal message to be an Interest"); assertFalse(ccnxMetaMessage_IsContentObject(portalMessage), "Did not expect portal message to be a ContentObject"); assertFalse(ccnxMetaMessage_IsControl(portalMessage), "Did not expect portal message to be a Control message"); ccnxMetaMessage_Release(&portalMessage); ccnxInterest_Release(&interest); ccnxName_Release(&name); }
LONGBOW_TEST_CASE(Global, ccnxInterest_Release) { CCNxName *name = ccnxName_CreateFromURI("lci:/name"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); CCNxInterest *reference = ccnxInterest_Acquire(interest); ccnxName_Release(&name); ccnxInterest_Release(&interest); ccnxInterest_Release(&reference); assertNull(interest, "Expected ccnxInterest_Release to null the pointer."); assertNull(reference, "Expected ccnxInterest_Release to null the pointer."); }
LONGBOW_TEST_CASE(Global, ccnxPortalStack_Send) { CCNxPortalStack *stack = (CCNxPortalStack *) longBowTestCase_GetClipBoardData(testCase); CCNxName *name = ccnxName_Create(); CCNxInterest *interest = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest); ccnxInterest_Release(&interest); bool result = ccnxPortalStack_Send(stack, message, CCNxStackTimeout_Never); ccnxMetaMessage_Release(&message); assertTrue(result, "Expected ccnxPortalStack_Ignore to return true."); }
static int _athenactl_UnSetDebug(PARCIdentity *identity, int argc, char **argv) { CCNxName *name = ccnxName_CreateFromURI(CCNxNameAthenaCommand_Set "/" AthenaCommand_LogLevel "/" AthenaCommand_LogInfo); CCNxInterest *interest = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); const char *result = _athenactl_SendInterestControl(identity, interest); if (result) { printf("%s\n", result); parcMemory_Deallocate(&result); } ccnxMetaMessage_Release(&interest); return 0; }
int consumer(void) { parcSecurity_Init(); CCNxPortalFactory *factory = setupConsumerFactory(); CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message); assertNotNull(portal, "Expected a non-null CCNxPortal pointer."); CCNxName *name = ccnxName_CreateFromCString("lci:/Hello/World"); CCNxInterest *interest = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest); if (ccnxPortal_Send(portal, message,CCNxStackTimeout_Never)) { while (ccnxPortal_IsError(portal) == false) { CCNxMetaMessage *response = ccnxPortal_Receive(portal,CCNxStackTimeout_Never); if (response != NULL) { if (ccnxMetaMessage_IsContentObject(response)) { CCNxContentObject *contentObject = ccnxMetaMessage_GetContentObject(response); PARCBuffer *payload = ccnxContentObject_GetPayload(contentObject); char *string = parcBuffer_ToString(payload); printf("%s\n", string); parcMemory_Deallocate((void **)&string); break; } } ccnxMetaMessage_Release(&response); } } ccnxPortal_Release(&portal); ccnxPortalFactory_Release(&factory); parcSecurity_Fini(); return 0; }
LONGBOW_TEST_CASE(Global, athenaTransportLinkModuleUDP_P2P) { PARCURI *connectionURI; const char *result; AthenaTransportLinkAdapter *athenaTransportLinkAdapter = athenaTransportLinkAdapter_Create(_removeLink, NULL); assertNotNull(athenaTransportLinkAdapter, "athenaTransportLinkAdapter_Create returned NULL"); connectionURI = parcURI_Parse("udp://localhost:40001/src=localhost:40002/name=UDP_0"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); connectionURI = parcURI_Parse("udp://localhost:40002/src=localhost:40001/name=UDP_1"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); CCNxName *name = ccnxName_CreateFromURI("lci:/foo/bar"); CCNxMetaMessage *ccnxMetaMessage = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); PARCBitVector *sendVector = parcBitVector_Create(); int linkId = athenaTransportLinkAdapter_LinkNameToId(athenaTransportLinkAdapter, "UDP_1"); parcBitVector_Set(sendVector, linkId); athena_EncodeMessage(ccnxMetaMessage); PARCBitVector *resultVector; resultVector = athenaTransportLinkAdapter_Send(athenaTransportLinkAdapter, ccnxMetaMessage, sendVector); assertNotNull(resultVector, "athenaTransportLinkAdapter_Send failed"); parcBitVector_Release(&resultVector); ccnxMetaMessage_Release(&ccnxMetaMessage); parcBitVector_Release(&sendVector); usleep(1000); ccnxMetaMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertNotNull(resultVector, "athenaTransportLinkAdapter_Receive failed"); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) == 1, "athenaTransportLinkAdapter_Receive return message with more than one ingress link"); assertNotNull(ccnxMetaMessage, "athenaTransportLinkAdapter_Receive failed to provide message"); parcBitVector_Release(&resultVector); ccnxMetaMessage_Release(&ccnxMetaMessage); athenaTransportLinkAdapter_Destroy(&athenaTransportLinkAdapter); }
LONGBOW_TEST_CASE(Global, ccnxInterest_SetPayloadWithId) { 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"); PARCBuffer *payloadIdBuffer = parcBuffer_WrapCString("payload Id buffer"); CCNxInterestPayloadId *payloadId = ccnxInterestPayloadId_Create(payloadIdBuffer, CCNxInterestPayloadId_TypeCode_App + 2); ccnxInterest_SetPayloadWithId(interest, payload, payloadId); 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"); CCNxInterestPayloadId *outId = ccnxInterestPayloadId_CreateFromSegmentInName(nameAfterPayload); assertTrue(ccnxInterestPayloadId_Equals(outId, payloadId), "expected to see the same payload Id after setting the payload"); ccnxInterestPayloadId_Release(&payloadId); ccnxInterestPayloadId_Release(&outId); parcBuffer_Release(&payload); parcBuffer_Release(&payloadIdBuffer); } ccnxName_Release(&name); ccnxName_Release(&origNameCopy); ccnxInterest_Release(&interest); }