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_CreateFromCString(lci); CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(origName, NULL); ccnxContentObject_SetExpiryTime(contentObject, parcClock_GetTime(clock) + 100); ccnxName_Release(&origName); athenaContentStore_PutContentObject(store, contentObject); ccnxContentObject_Release(&contentObject); CCNxName *testName = ccnxName_CreateFromCString(lci); bool status = athenaContentStore_RemoveMatch(store, testName, NULL, NULL); // TODO: match on other than name! assertTrue(status, "Expected to remove the contentobject we had"); ccnxName_Release(&testName); parcClock_Release(&clock); athenaContentStore_Release(&store); }
LONGBOW_TEST_CASE(Global, 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_CreateFromCString(lci); CCNxContentObject *truthObject = ccnxContentObject_CreateWithNameAndPayload(truthName, NULL); ccnxContentObject_SetExpiryTime(truthObject, parcClock_GetTime(clock) + 100); ccnxName_Release(&truthName); athenaContentStore_PutContentObject(store, truthObject); CCNxName *testName = ccnxName_CreateFromCString(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(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(Global, ccnxKeyLocator_Copy) { CCNxName *keyURIName = ccnxName_CreateFromCString("lci://name"); CCNxLink *keyLink = ccnxLink_Create(keyURIName, NULL, NULL); CCNxKeyLocator *keyLocator = ccnxKeyLocator_CreateFromKeyLink(keyLink); ccnxKeyLocator_AssertValid(keyLocator); CCNxKeyLocator *copy = ccnxKeyLocator_Copy(keyLocator); assertTrue(ccnxKeyLocator_Equals(copy, keyLocator), "Expected orig and copy to be the same"); ccnxKeyLocator_Release(&keyLocator); ccnxKeyLocator_Release(©); ccnxName_Release(&keyURIName); ccnxLink_Release(&keyLink); // Try FromHexString, too, for yucks. PARCBuffer *keyBuffer = parcBuffer_WrapCString("hello world"); PARCKeyId *keyId = parcKeyId_Create(keyBuffer); PARCKey *key = parcKey_CreateFromDerEncodedPublicKey(keyId, PARCSigningAlgorithm_RSA, keyBuffer); parcKeyId_Release(&keyId); parcBuffer_Release(&keyBuffer); CCNxKeyLocator *keyLocator2 = ccnxKeyLocator_CreateFromKey(key); CCNxKeyLocator *copy2 = ccnxKeyLocator_Copy(keyLocator2); assertTrue(ccnxKeyLocator_Equals(copy, keyLocator), "Expected orig and copy to be the same"); parcKey_Release(&key); ccnxKeyLocator_Release(&keyLocator2); ccnxKeyLocator_Release(©2); }
LONGBOW_TEST_CASE(Global, ccnxKeyLocator_GetType) { // Try FromKey char *hexString = "ABCDEF1234"; PARCBuffer *keyBuffer = parcBuffer_WrapCString(hexString); PARCKeyId *keyId = parcKeyId_Create(keyBuffer); PARCKey *key = parcKey_CreateFromDerEncodedPublicKey(keyId, PARCSigningAlgorithm_RSA, keyBuffer); CCNxKeyLocator *keyLocator = ccnxKeyLocator_CreateFromKey(key); parcKeyId_Release(&keyId); parcBuffer_Release(&keyBuffer); ccnxKeyLocator_AssertValid(keyLocator); assertTrue(ccnxKeyLocator_GetType(keyLocator) == CCNxKeyLocatorType_Key, "Actual certificate type didn't match expected type"); ccnxKeyLocator_Release(&keyLocator); parcKey_Release(&key); // Try KeyName CCNxName *keyURIName = ccnxName_CreateFromCString("lci://name/test"); CCNxLink *keyLink = ccnxLink_Create(keyURIName, NULL, NULL); keyLocator = ccnxKeyLocator_CreateFromKeyLink(keyLink); ccnxKeyLocator_AssertValid(keyLocator); assertTrue(ccnxKeyLocator_GetType(keyLocator) == CCNxKeyLocatorType_Link, "Actual certificate type didn't match expected type"); assertFalse(ccnxKeyLocator_GetType(keyLocator) == CCNxKeyLocatorType_Key, "Actual certificate type didn't match expected type"); ccnxKeyLocator_Release(&keyLocator); ccnxName_Release(&keyURIName); ccnxLink_Release(&keyLink); }
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, 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); }
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); }
LONGBOW_TEST_CASE(Global, ccnxContentObject_GetPayloadType) { CCNxName *name = ccnxName_CreateFromCString("lci:/name"); PARCBuffer *payload = parcBuffer_Allocate(100); CCNxPayloadType types[] = { CCNxPayloadType_DATA, CCNxPayloadType_KEY, CCNxPayloadType_LINK, CCNxPayloadType_MANIFEST, }; for (int i = 0; i < sizeof(types) / sizeof(CCNxPayloadType); i++) { CCNxPayloadType type = types[i]; CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, NULL); ccnxContentObject_SetPayload(contentObject, type, payload); assertTrue(ccnxContentObject_GetPayloadType(contentObject) == type, "Unexpected PayloadType"); ccnxContentObject_Release(&contentObject); } parcBuffer_Release(&payload); ccnxName_Release(&name); }
LONGBOW_TEST_CASE(Global, ccnxContentObject_GetKeyId) { CCNxName *name = ccnxName_CreateFromCString("lci:/hello/dolly"); PARCBuffer *payload = parcBuffer_WrapCString("hello"); CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, payload); assertNull(ccnxContentObject_GetKeyId(contentObject), "Expect NULL for KeyId here"); PARCBuffer *testKeyId = parcBuffer_WrapCString("keyhash"); PARCBuffer *sigbits = parcBuffer_WrapCString("siggybits"); PARCSignature *signature = parcSignature_Create(PARCSigningAlgorithm_RSA, PARC_HASH_SHA256, parcBuffer_Flip(sigbits)); ccnxContentObject_SetSignature(contentObject, testKeyId, signature, NULL); PARCBuffer *keyId = ccnxContentObject_GetKeyId(contentObject); assertTrue(parcBuffer_Equals(keyId, testKeyId), "Expect key ids to match"); parcBuffer_Release(&payload); parcBuffer_Release(&sigbits); parcBuffer_Release(&keyId); parcSignature_Release(&signature); ccnxName_Release(&name); ccnxContentObject_Release(&contentObject); }
LONGBOW_TEST_CASE(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, athena_ProcessControl_CPI_REGISTER_PREFIX) { PARCURI *connectionURI; Athena *athena = athena_Create(100); CCNxName *name = ccnxName_CreateFromCString("ccnx:/foo/bar"); CCNxControl *control = ccnxControl_CreateAddRouteToSelfRequest(name); // CPI_REGISTER_PREFIX CCNxMetaMessage *registerPrefixCommand = ccnxMetaMessage_CreateFromControl(control); ccnxControl_Release(&control); control = ccnxControl_CreateRemoveRouteToSelfRequest(name); // CPI_UNREGISTER_PREFIX CCNxMetaMessage *unregisterPrefixCommand = ccnxMetaMessage_CreateFromControl(control); ccnxControl_Release(&control); ccnxName_Release(&name); connectionURI = parcURI_Parse("tcp://localhost:50100/listener/name=TCPListener"); const char *result = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); connectionURI = parcURI_Parse("tcp://localhost:50100/name=TCP_0"); result = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); int linkId = athenaTransportLinkAdapter_LinkNameToId(athena->athenaTransportLinkAdapter, "TCP_0"); PARCBitVector *ingressVector = parcBitVector_Create(); parcBitVector_Set(ingressVector, linkId); // Call _Receive() once to prime the link. Messages are dropped until _Receive() is called once. PARCBitVector *linksRead = NULL; CCNxMetaMessage *msg = athenaTransportLinkAdapter_Receive(athena->athenaTransportLinkAdapter, &linksRead, -1); assertNull(msg, "Expected to NOT receive a message after the first call to _Receive()"); CCNxMetaMessage *cpiMessages[2]; cpiMessages[0] = registerPrefixCommand; // CPI_REGISTER_PREFIX cpiMessages[1] = unregisterPrefixCommand; // CPI_UNREGISTER_PREFIX for (int i = 0; i < 2; i++) { CCNxMetaMessage *cpiMessageToSend = cpiMessages[i]; athena_ProcessMessage(athena, cpiMessageToSend, ingressVector); ccnxMetaMessage_Release(&cpiMessageToSend); CCNxMetaMessage *ack = athenaTransportLinkAdapter_Receive(athena->athenaTransportLinkAdapter, &linksRead, -1); assertNotNull(ack, "Expected a CPI_ACK message back"); assertTrue(ccnxMetaMessage_IsControl(ack), "Expected a control message back"); parcBitVector_Release(&linksRead); PARCJSON *json = ccnxControl_GetJson(ack); const PARCJSONValue *cpiAckResult = parcJSON_GetByPath(json, "CPI_ACK/REQUEST/RESULT"); bool commandResult = parcJSONValue_GetBoolean(cpiAckResult); assertTrue(commandResult, "Expected the ACK to contain RESULT=true"); ccnxMetaMessage_Release(&ack); } parcBitVector_Release(&ingressVector); athena_Release(&athena); }
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); }
int athenaInterestControl(Athena *athena, CCNxInterest *interest, PARCBitVector *ingressVector) { CCNxMetaMessage *responseMessage = NULL; CCNxName *ccnxName = ccnxInterest_GetName(interest); CCNxName *ccnxComponentName = ccnxName_CreateFromCString(CCNxNameAthena_Control); if (ccnxName_StartsWith(ccnxName, ccnxComponentName) == true) { responseMessage = _Control_Command(athena, interest); } ccnxName_Release(&ccnxComponentName); ccnxComponentName = ccnxName_CreateFromCString(CCNxNameAthena_Link); if (ccnxName_StartsWith(ccnxName, ccnxComponentName) == true) { responseMessage = _TransportLinkAdapter_Command(athena, interest); } ccnxName_Release(&ccnxComponentName); ccnxComponentName = ccnxName_CreateFromCString(CCNxNameAthena_FIB); if (ccnxName_StartsWith(ccnxName, ccnxComponentName) == true) { responseMessage = _FIB_Command(athena, interest, ingressVector); } ccnxName_Release(&ccnxComponentName); ccnxComponentName = ccnxName_CreateFromCString(CCNxNameAthena_PIT); if (ccnxName_StartsWith(ccnxName, ccnxComponentName) == true) { responseMessage = _PIT_Command(athena, interest); } ccnxName_Release(&ccnxComponentName); ccnxComponentName = ccnxName_CreateFromCString(CCNxNameAthena_ContentStore); if (ccnxName_StartsWith(ccnxName, ccnxComponentName) == true) { responseMessage = _ContentStore_Command(athena, interest); } ccnxName_Release(&ccnxComponentName); if (responseMessage) { athena_ProcessMessage(athena, responseMessage, ingressVector); ccnxContentObject_Release(&responseMessage); } return 0; }
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, athena_ProcessContentObject) { PARCURI *connectionURI; Athena *athena = athena_Create(100); CCNxName *name = ccnxName_CreateFromCString("lci:/cakes/and/pies"); uint64_t chunkNum = 0; CCNxNameSegment *chunkSegment = ccnxNameSegmentNumber_Create(CCNxNameLabelType_CHUNK, chunkNum); ccnxName_Append(name, chunkSegment); ccnxNameSegment_Release(&chunkSegment); PARCBuffer *payload = parcBuffer_WrapCString("this is a payload"); CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload); ccnxName_Release(&name); parcBuffer_Release(&payload); connectionURI = parcURI_Parse("tcp://localhost:50100/listener/name=TCPListener"); const char *result = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); connectionURI = parcURI_Parse("tcp://localhost:50100/name=TCP_0"); result = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); int linkId = athenaTransportLinkAdapter_LinkNameToId(athena->athenaTransportLinkAdapter, "TCP_0"); PARCBitVector *ingressVector = parcBitVector_Create(); parcBitVector_Set(ingressVector, linkId); athena_EncodeMessage(contentObject); athena_ProcessMessage(athena, contentObject, ingressVector); parcBitVector_Release(&ingressVector); // Make sure we recover processing a "nameless" content object payload = parcBuffer_WrapCString("Hello World"); CCNxContentObject *reply = ccnxContentObject_CreateWithPayload(payload); parcBuffer_Release(&payload); CCNxMetaMessage *response = ccnxMetaMessage_CreateFromContentObject(reply); ccnxContentObject_Release(&reply); athena_EncodeMessage(response); athena_ProcessMessage(athena, response, ingressVector); assertNull(ingressVector, "Processing nameless content object didn't fail."); ccnxInterest_Release(&contentObject); ccnxInterest_Release(&response); athena_Release(&athena); }
LONGBOW_TEST_CASE(Global, ccnxContentObject_CreateWithDataPayload) { CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); PARCBuffer *payload = parcBuffer_Allocate(100); CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, payload); ccnxContentObject_AssertValid(contentObject); ccnxName_Release(&name); parcBuffer_Release(&payload); ccnxContentObject_Release(&contentObject); }
LONGBOW_TEST_CASE(Local, ccnxKeyLocator_Create) { CCNxName *keyURIName = ccnxName_CreateFromCString("lci://name"); CCNxLink *keyLink = ccnxLink_Create(keyURIName, NULL, NULL); CCNxKeyLocator *keyLocator = ccnxKeyLocator_CreateFromKeyLink(keyLink); ccnxKeyLocator_AssertValid(keyLocator); ccnxKeyLocator_Release(&keyLocator); ccnxName_Release(&keyURIName); ccnxLink_Release(&keyLink); }
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); }
/** * Create a CCNxContentObject with the given LCI name, chunknumber, and payload. */ static CCNxContentObject * _createContentObject(char *lci, uint64_t chunkNum, PARCBuffer *payload) { CCNxName *name = ccnxName_CreateFromCString(lci); CCNxNameSegment *chunkSegment = ccnxNameSegmentNumber_Create(CCNxNameLabelType_CHUNK, chunkNum); ccnxName_Append(name, chunkSegment); CCNxContentObject *result = ccnxContentObject_CreateWithNameAndPayload(name, payload); ccnxName_Release(&name); ccnxNameSegment_Release(&chunkSegment); return result; }
LONGBOW_TEST_CASE(EmptyImplementation, apiFunctions) { AthenaContentStore *store = athenaContentStore_Create(&EmptyContentStoreImplementation, NULL); CCNxName *name = ccnxName_CreateFromCString("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, ccnxPortal_Ignore) { TestData *data = longBowTestCase_GetClipBoardData(testCase); CCNxPortal *portal = ccnxPortalFactory_CreatePortal(data->factory, TEST_STACK); CCNxName *name = ccnxName_CreateFromCString("lci:/Hello/World"); bool actual = ccnxPortal_Ignore(portal, name, CCNxStackTimeout_Never); ccnxName_Release(&name); ccnxPortal_Release(&portal); assertTrue(actual, "Expected ccnxPortal_Ignore to return true"); }
LONGBOW_TEST_CASE(Global, ccnxLink_Create_EmptyBoth) { CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar/name"); PARCBuffer *keyId = NULL; PARCBuffer *contentObjectHash = NULL; CCNxLink *object = ccnxLink_Create(name, keyId, contentObjectHash); assertNotNull(object, "Expected non-null return value."); ccnxLink_Release(&object); ccnxName_Release(&name); }
LONGBOW_TEST_CASE(Global, ccnxMetaMessage_CreateFromContentObject) { CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); PARCBuffer *payload = parcBuffer_WrapCString("This is some data. It's not good data, but it is data."); CCNxContentObject *contentObject = ccnxContentObject_CreateWithNameAndPayload(name, payload); CCNxMetaMessage *portalMessage = ccnxMetaMessage_CreateFromContentObject(contentObject); assertNotNull(portalMessage, "Expected a non-null portal message"); ccnxMetaMessage_Release(&portalMessage); ccnxContentObject_Release(&contentObject); parcBuffer_Release(&payload); ccnxName_Release(&name); }
LONGBOW_TEST_CASE(Global, ccnxKeyLocator_IsKeyName) { CCNxName *keyURIName = ccnxName_CreateFromCString("lci://name/test"); CCNxLink *keyLink = ccnxLink_Create(keyURIName, NULL, NULL); CCNxKeyLocator *keyLocator = ccnxKeyLocator_CreateFromKeyLink(keyLink); ccnxKeyLocator_AssertValid(keyLocator); assertFalse(ccnxKeyLocator_IsKey(keyLocator), "Expected Iskey to be false"); assertTrue(ccnxKeyLocator_IsKeyLink(keyLocator), "Expected IsKeyLink to be true"); ccnxKeyLocator_Release(&keyLocator); ccnxName_Release(&keyURIName); ccnxLink_Release(&keyLink); }
LONGBOW_TEST_CASE(Global, ccnxKeyLocator_GetKeyName) { CCNxName *keyURIName = ccnxName_CreateFromCString("lci://name/test"); CCNxLink *keyLink = ccnxLink_Create(keyURIName, NULL, NULL); CCNxKeyLocator *keyLocator = ccnxKeyLocator_CreateFromKeyLink(keyLink); ccnxKeyLocator_AssertValid(keyLocator); const CCNxName *actual = ccnxLink_GetName(ccnxKeyLocator_GetKeyLink(keyLocator)); assertTrue(ccnxName_Equals(actual, keyURIName), "Actual keyName did not match the one returned by GetKeyName()"); ccnxKeyLocator_Release(&keyLocator); ccnxName_Release(&keyURIName); ccnxLink_Release(&keyLink); }
LONGBOW_TEST_CASE(Global, ccnxKeyLocator_Destroy) { CCNxName *keyURIName = ccnxName_CreateFromCString("lci://name"); CCNxLink *keyLink = ccnxLink_Create(keyURIName, NULL, NULL); CCNxKeyLocator *keyLocator = ccnxKeyLocator_CreateFromKeyLink(keyLink); ccnxKeyLocator_AssertValid(keyLocator); ccnxKeyLocator_Release(&keyLocator); assertNull(keyLocator, "keyLocator was not nulled out by Release()"); ccnxLink_Release(&keyLink); ccnxName_Release(&keyURIName); }
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); }