LONGBOW_TEST_CASE(Global, parcBitVector_Set) { PARCBitVector *parcBitVector = parcBitVector_Create(); assertTrue(parcBitVector, "parcBitVector_Create returned a NULL pointer"); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 0, "parcBitVector_Create created a non-empty vector"); parcBitVector_Set(parcBitVector, 0); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 1, "Expect number of bits set to be 1"); assertTrue(parcBitVector->firstBitSet == 0, "Expect first bit set to be 0"); assertTrue(parcBitVector->bitLength == 8, "Expect the bitLength to be 8"); assertTrue(parcBitVector->bitArray[0] == (uint8_t) 1, "Expect the bitArray as a unsigned char to be = 1"); parcBitVector_Set(parcBitVector, 7); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 2, "Expect number of bits set to be 2"); assertTrue(parcBitVector->firstBitSet == 0, "Expect first bit set to be 0"); assertTrue(parcBitVector->bitLength == 8, "Expect the bitLength to be 8"); assertTrue(parcBitVector->bitArray[0] == (uint8_t) 0x81, "Expect the bitArray as a unsigned char to be = 0x81"); parcBitVector_Set(parcBitVector, 8); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 3, "Expect number of bits set to be 3"); assertTrue(parcBitVector->firstBitSet == 0, "Expect first bit set to be 0"); assertTrue(parcBitVector->bitLength == 16, "Expect the bitLength to be 16"); assertTrue(parcBitVector->bitArray[0] == (uint8_t) 0x81, "Expect the bitArray as a unsigned char to be = 0x81"); assertTrue(parcBitVector->bitArray[1] == (uint8_t) 0x1, "Expect the bitArray as a unsigned char to be = 0x1"); parcBitVector_Release(&parcBitVector); }
static void _processContentObject(Athena *athena, CCNxContentObject *contentObject, PARCBitVector *ingressVector) { // // * (1) If it does not match anything in the PIT, drop it // PARCBitVector *egressVector = athenaPIT_Match(athena->athenaPIT, contentObject, ingressVector); if (egressVector) { if (parcBitVector_NumberOfBitsSet(egressVector) > 0) { // // * (2) Add to the Content Store // athenaContentStore_PutContentObject(athena->athenaContentStore, contentObject); // // * (3) Reverse path forward it via PIT entries // const char *egressVectorString = parcBitVector_ToString(egressVector); parcLog_Debug(athena->log, "Content Object forwarded to %s.", egressVectorString); parcMemory_Deallocate(&egressVectorString); PARCBitVector *result = athenaTransportLinkAdapter_Send(athena->athenaTransportLinkAdapter, contentObject, egressVector); if (result) { // if there are failed channels, client will resend interest unless we wish to retry here parcBitVector_Release(&result); } } parcBitVector_Release(&egressVector); } }
LONGBOW_TEST_CASE(Global, parcBitVector_NextBitSet) { PARCBitVector *parcBitVector = parcBitVector_Create(); assertTrue(parcBitVector, "parcBitVector_Create returned a NULL pointer"); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 0, "parcBitVector_Create created a non-empty vector"); int nextBit = parcBitVector_NextBitSet(parcBitVector, 0); assertTrue(nextBit == -1, "parcBitVector_NextBitSet should have failed (%d)", nextBit); parcBitVector_Set(parcBitVector, 10); nextBit = parcBitVector_NextBitSet(parcBitVector, 0); assertTrue(nextBit == 10, "parcBitVector_NextBitSet failed (%d)", nextBit); nextBit = parcBitVector_NextBitSet(parcBitVector, 20); assertTrue(nextBit == -1, "parcBitVector_NextBitSet read past end of vector (%d)", nextBit); nextBit = parcBitVector_NextBitSet(parcBitVector, 10); assertTrue(nextBit == 10, "parcBitVector_NextBitSet failed (%d)", nextBit); nextBit = parcBitVector_NextBitSet(parcBitVector, 11); assertTrue(nextBit == -1, "parcBitVector_NextBitSet should have failed (%d)", nextBit); parcBitVector_Set(parcBitVector, 20); nextBit = parcBitVector_NextBitSet(parcBitVector, 11); assertTrue(nextBit == 20, "parcBitVector_NextBitSet failed (%d)", nextBit); parcBitVector_Release(&parcBitVector); }
LONGBOW_TEST_CASE(Global, parcBitVector_SetClear) { PARCBitVector *parcBitVector = parcBitVector_Create(); assertTrue(parcBitVector, "parcBitVector_Create returned a NULL pointer"); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 0, "parcBitVector_Create created a non-empty vector"); parcBitVector_Set(parcBitVector, 10); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 1, "parcBitVector_Set failed"); parcBitVector_Clear(parcBitVector, 10); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 0, "parcBitVector_Clear failed"); parcBitVector_Clear(parcBitVector, 20); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 0, "parcBitVector_Clear failed"); parcBitVector_Release(&parcBitVector); }
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, 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, parcBitVector_Reset) { PARCBitVector *parcBitVector = parcBitVector_Create(); assertTrue(parcBitVector, "parcBitVector_Create returned a NULL pointer"); // Reset and empty vector test parcBitVector_Reset(parcBitVector); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 0, "parcBitVector_Reset failed"); parcBitVector_Set(parcBitVector, 1); parcBitVector_Set(parcBitVector, 42); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 2, "parcBitVector_Set failed"); assertTrue(parcBitVector->bitLength == 48, "Expected a bitLength of 48"); parcBitVector_Reset(parcBitVector); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 0, "parcBitVector_Reset failed"); assertTrue(parcBitVector->bitLength == 48, "Expected a bitLength of 48"); parcBitVector_Release(&parcBitVector); }
LONGBOW_TEST_CASE(Global, parcBitVector_SetVector) { PARCBitVector *parcBitVector = parcBitVector_Create(); assertTrue(parcBitVector, "parcBitVector_Create returned a NULL pointer"); PARCBitVector *setVector = parcBitVector_Create(); parcBitVector_Set(parcBitVector, 1); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 1, "parcBitVector_Set failed"); parcBitVector_Set(setVector, 20); parcBitVector_SetVector(parcBitVector, setVector); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 2, "parcBitVector_SetVector failed"); assertTrue(parcBitVector_NextBitSet(parcBitVector, 0) == 1, "parcBitVector_Set failed to set bit 1"); assertTrue(parcBitVector_NextBitSet(parcBitVector, 2) == 20, "parcBitVector_SetVector failed to set bit 20"); parcBitVector_Set(setVector, 10); parcBitVector_SetVector(parcBitVector, setVector); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 3, "parcBitVector_SetVector failed"); parcBitVector_Release(&parcBitVector); parcBitVector_Release(&setVector); }
LONGBOW_TEST_CASE(Global, parcBitVector_Copy) { PARCBitVector *parcBitVector = parcBitVector_Create(); assertTrue(parcBitVector, "parcBitVector_Create returned a NULL pointer"); parcBitVector_Set(parcBitVector, 10); PARCBitVector *copy = parcBitVector_Copy(parcBitVector); assertTrue(parcBitVector_NumberOfBitsSet(copy) == 1, "parcBitVector_Copy failed to copy set bit"); assertTrue(parcBitVector_NextBitSet(copy, 0) == 10, "parcBitVector_Copy failed to copy correct bit"); parcBitVector_Release(©); parcBitVector_Release(&parcBitVector); }
LONGBOW_TEST_CASE(Global, parcBitVector_ClearVector) { PARCBitVector *parcBitVector = parcBitVector_Create(); assertTrue(parcBitVector, "parcBitVector_Create returned a NULL pointer"); PARCBitVector *setVector = parcBitVector_Create(); parcBitVector_Set(parcBitVector, 1); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 1, "parcBitVector_Set failed to set bit"); parcBitVector_Set(setVector, 1); parcBitVector_Set(setVector, 20); parcBitVector_ClearVector(parcBitVector, setVector); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 0, "parcBitVector_ClearVector failed to clear vector"); parcBitVector_Set(parcBitVector, 12); parcBitVector_Set(parcBitVector, 17); parcBitVector_ClearVector(parcBitVector, parcBitVector); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 0, "parcBitVector_ClearVector failed to clear vector"); parcBitVector_Release(&parcBitVector); parcBitVector_Release(&setVector); }
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, parcBitVector_Get) { PARCBitVector *parcBitVector = parcBitVector_Create(); assertTrue(parcBitVector, "parcBitVector_Create returned a NULL pointer"); assertTrue(parcBitVector_NumberOfBitsSet(parcBitVector) == 0, "parcBitVector_Create created a non-empty vector"); parcBitVector_Set(parcBitVector, 10); int bitValue = parcBitVector_Get(parcBitVector, 10); assertTrue(bitValue == 1, "parcBitVector_Get returned wrong value (%d)", bitValue); bitValue = parcBitVector_Get(parcBitVector, 11); assertTrue(bitValue == 0, "parcBitVector_Get returned wrong value (%d)", bitValue); bitValue = parcBitVector_Get(parcBitVector, 100); assertTrue(bitValue == -1, "parcBitVector_NextBitSet should have failed (%d)", bitValue); parcBitVector_Release(&parcBitVector); }
LONGBOW_TEST_CASE(Global, athenaTransportLinkAdapter_SendReceive) { PARCURI *connectionURI; const char *result; CCNxMetaMessage *receiveMessage; PARCBitVector *resultVector; 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); receiveMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertNull(resultVector, "Received message when none sent"); connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/name=TCP_1"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); receiveMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertNull(resultVector, "Received message when none sent"); connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/name=TCP_2"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); receiveMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertNull(resultVector, "Received message when none sent"); connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/name=TCP_3"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); receiveMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertNull(resultVector, "Received message when none sent"); connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/name=TCP_4"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); receiveMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertNull(resultVector, "Received message when none sent"); connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/name=TCP_5"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); receiveMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertNull(resultVector, "Received message when none sent"); int closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "TCP_3"); assertTrue(closeResult == 0, "athenaTransportLinkAdapter_CloseByName failed (%s)", strerror(errno)); connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/name=TCP_3"); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); receiveMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertNull(resultVector, "Received message when none sent"); CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); CCNxMetaMessage *sendMessage = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); PARCBitVector *linkVector = parcBitVector_Create(); int linkId = athenaTransportLinkAdapter_LinkNameToId(athenaTransportLinkAdapter, "TCP_1"); parcBitVector_Set(linkVector, linkId); linkId = athenaTransportLinkAdapter_LinkNameToId(athenaTransportLinkAdapter, "TCP_2"); parcBitVector_Set(linkVector, linkId); linkId = athenaTransportLinkAdapter_LinkNameToId(athenaTransportLinkAdapter, "TCP_3"); parcBitVector_Set(linkVector, linkId); athena_EncodeMessage(sendMessage); resultVector = athenaTransportLinkAdapter_Send(athenaTransportLinkAdapter, sendMessage, linkVector); assertNull(resultVector, "athenaTransportLinkAdapter_Send failed"); usleep(1000); char *resultString; receiveMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, -1); assertNotNull(resultVector, "athenaTransportLinkAdapter_Receive failed"); printf("Receive1 = %s\n", resultString = parcBitVector_ToString(resultVector)); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) > 0, "athenaTransportLinkAdapter_Receive failed"); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) == 1, "athenaTransportLinkAdapter_Receive returned message with more than one ingress link (%s)", resultString); parcMemory_Deallocate(&resultString); parcBitVector_Release(&resultVector); ccnxMetaMessage_Release(&receiveMessage); receiveMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, -1); assertNotNull(resultVector, "athenaTransportLinkAdapter_Receive failed"); printf("Receive2 = %s\n", resultString = parcBitVector_ToString(resultVector)); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) > 0, "athenaTransportLinkAdapter_Receive failed"); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) == 1, "athenaTransportLinkAdapter_Receive returned message with more than one ingress link (%s)", resultString); parcMemory_Deallocate(&resultString); parcBitVector_Release(&resultVector); ccnxMetaMessage_Release(&receiveMessage); receiveMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, -1); assertNotNull(resultVector, "athenaTransportLinkAdapter_Receive failed"); printf("Receive3 = %s\n", resultString = parcBitVector_ToString(resultVector)); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) > 0, "athenaTransportLinkAdapter_Receive failed"); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) == 1, "athenaTransportLinkAdapter_Receive returned message with more than one ingress link (%s)", resultString); parcMemory_Deallocate(&resultString); parcBitVector_Release(&resultVector); ccnxMetaMessage_Release(&receiveMessage); closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "TCP_1"); assertTrue(closeResult == 0, "athenaTransportLinkAdapter_CloseByName failed (%s)", strerror(errno)); closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "TCP_2"); assertTrue(closeResult == 0, "athenaTransportLinkAdapter_CloseByName failed (%s)", strerror(errno)); resultVector = athenaTransportLinkAdapter_Send(athenaTransportLinkAdapter, sendMessage, linkVector); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) == 2, "athenaTransportLinkAdapter_Send should have partially failed"); parcBitVector_Release(&linkVector); parcBitVector_Release(&resultVector); linkVector = parcBitVector_Create(); parcBitVector_Set(linkVector, 100); resultVector = athenaTransportLinkAdapter_Send(athenaTransportLinkAdapter, sendMessage, linkVector); assertTrue(parcBitVector_NumberOfBitsSet(resultVector) == 1, "athenaTransportLinkAdapter_Send should have failed to send to unknown link"); parcBitVector_Release(&resultVector); parcBitVector_Release(&linkVector); ccnxMetaMessage_Release(&sendMessage); athenaTransportLinkAdapter_Destroy(&athenaTransportLinkAdapter); }
LONGBOW_TEST_CASE(Global, athenaTransportLinkModuleTEMPLATE_SendReceive) { PARCURI *connectionURI; char linkSpecificationURI[MAXPATHLEN]; const char *result; AthenaTransportLinkAdapter *athenaTransportLinkAdapter = athenaTransportLinkAdapter_Create(_removeLink, NULL); assertNotNull(athenaTransportLinkAdapter, "athenaTransportLinkAdapter_Create returned NULL"); // Open a link we can send messages on sprintf(linkSpecificationURI, "template:///name=TEMPLATE_1"); connectionURI = parcURI_Parse(linkSpecificationURI); result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); // Enable debug logging after all instances are open athenaTransportLinkAdapter_SetLogLevel(athenaTransportLinkAdapter, PARCLogLevel_Debug); // Construct an interest CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar"); CCNxMetaMessage *ccnxMetaMessage = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); PARCBitVector *sendVector = parcBitVector_Create(); // Send the interest out on the link, this message will also be received by ourself // since we're sending it to our own MAC destination. int linkId = athenaTransportLinkAdapter_LinkNameToId(athenaTransportLinkAdapter, "TEMPLATE_1"); parcBitVector_Set(sendVector, linkId); athena_EncodeMessage(ccnxMetaMessage); PARCBitVector *resultVector; resultVector = athenaTransportLinkAdapter_Send(athenaTransportLinkAdapter, ccnxMetaMessage, sendVector); assertNull(resultVector, "athenaTransportLinkAdapter_Send failed"); // Send the message a second time resultVector = athenaTransportLinkAdapter_Send(athenaTransportLinkAdapter, ccnxMetaMessage, sendVector); assertNull(resultVector, "athenaTransportLinkAdapter_Send failed"); parcBitVector_Release(&sendVector); ccnxMetaMessage_Release(&ccnxMetaMessage); 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); // Receive the duplicate ccnxMetaMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertTrue(ccnxMetaMessage != NULL, "athenaTransportLinkAdapter_Receive failed to receive duplicate message"); parcBitVector_Release(&resultVector); ccnxMetaMessage_Release(&ccnxMetaMessage); // Nothing else should remain ccnxMetaMessage = athenaTransportLinkAdapter_Receive(athenaTransportLinkAdapter, &resultVector, 0); assertTrue(ccnxMetaMessage == NULL, "athenaTransportLinkAdapter_Receive received extraneous message"); int closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "TEMPLATE_1"); assertTrue(closeResult == 0, "athenaTransportLinkAdapter_CloseByName failed (%s)", strerror(errno)); athenaTransportLinkAdapter_Destroy(&athenaTransportLinkAdapter); }
static void _processInterest(Athena *athena, CCNxInterest *interest, PARCBitVector *ingressVector) { uint8_t hoplimit; // // * (0) Hoplimit check, exclusively on interest messages // int linkId = parcBitVector_NextBitSet(ingressVector, 0); if (athenaTransportLinkAdapter_IsNotLocal(athena->athenaTransportLinkAdapter, linkId)) { hoplimit = ccnxInterest_GetHopLimit(interest); if (hoplimit == 0) { // We should never receive a message with a hoplimit of 0 from a non-local source. parcLog_Error(athena->log, "Received a message with a hoplimit of zero from a non-local source (%s).", athenaTransportLinkAdapter_LinkIdToName(athena->athenaTransportLinkAdapter, linkId)); return; } ccnxInterest_SetHopLimit(interest, hoplimit - 1); } // // * (1) if the interest is in the ContentStore, reply and return, // assuming that other PIT entries were satisified when the content arrived. // CCNxMetaMessage *content = athenaContentStore_GetMatch(athena->athenaContentStore, interest); if (content) { const char *ingressVectorString = parcBitVector_ToString(ingressVector); parcLog_Debug(athena->log, "Forwarding content from store to %s", ingressVectorString); parcMemory_Deallocate(&ingressVectorString); PARCBitVector *result = athenaTransportLinkAdapter_Send(athena->athenaTransportLinkAdapter, content, ingressVector); if (result) { // failed channels - client will resend interest unless we wish to optimize things here parcBitVector_Release(&result); } return; } // // * (2) add it to the PIT, if it was aggregated or there was an error we're done, otherwise we // forward the interest. The expectedReturnVector is populated with information we get from // the FIB and used to verify content objects ingress ports when they arrive. // PARCBitVector *expectedReturnVector; AthenaPITResolution result; if ((result = athenaPIT_AddInterest(athena->athenaPIT, interest, ingressVector, &expectedReturnVector)) != AthenaPITResolution_Forward) { if (result == AthenaPITResolution_Error) { parcLog_Error(athena->log, "PIT resolution error"); } return; } // Divert interests destined to the forwarder, we assume these are control messages CCNxName *ccnxName = ccnxInterest_GetName(interest); if (ccnxName_StartsWith(ccnxName, athena->athenaName) == true) { _processInterestControl(athena, interest, ingressVector); return; } // // * (3) if it's in the FIB, forward, then update the PIT expectedReturnVector so we can verify // when the returned object arrives that it came from an interface it was expected from. // Interest messages with a hoplimit of 0 will never be sent out by the link adapter to a // non-local interface so we need not check that here. // ccnxName = ccnxInterest_GetName(interest); PARCBitVector *egressVector = athenaFIB_Lookup(athena->athenaFIB, ccnxName); if (egressVector != NULL) { // Remove the link the interest came from if it was included in the FIB entry parcBitVector_ClearVector(egressVector, ingressVector); // If no links remain, send a no route interest return message if (parcBitVector_NumberOfBitsSet(egressVector) == 0) { CCNxInterestReturn *interestReturn = ccnxInterestReturn_Create(interest, CCNxInterestReturn_ReturnCode_NoRoute); PARCBitVector *result = athenaTransportLinkAdapter_Send(athena->athenaTransportLinkAdapter, interestReturn, ingressVector); parcBitVector_Release(&result); ccnxInterestReturn_Release(&interestReturn); } else { parcBitVector_SetVector(expectedReturnVector, egressVector); PARCBitVector *result = athenaTransportLinkAdapter_Send(athena->athenaTransportLinkAdapter, interest, egressVector); if (result) { // remove failed channels - client will resend interest unless we wish to optimize here parcBitVector_ClearVector(expectedReturnVector, result); parcBitVector_Release(&result); } } } else { // No FIB entry found, return a NoRoute interest return and remove the entry from the PIT. CCNxInterestReturn *interestReturn = ccnxInterestReturn_Create(interest, CCNxInterestReturn_ReturnCode_NoRoute); PARCBitVector *result = athenaTransportLinkAdapter_Send(athena->athenaTransportLinkAdapter, interestReturn, ingressVector); parcBitVector_Release(&result); ccnxInterestReturn_Release(&interestReturn); const char *name = ccnxName_ToString(ccnxName); if (athenaPIT_RemoveInterest(athena->athenaPIT, interest, ingressVector) != true) { parcLog_Error(athena->log, "Unable to remove interest (%s) from the PIT.", name); } parcLog_Debug(athena->log, "Name (%s) not found in FIB and no default route. Message dropped.", name); parcMemory_Deallocate(&name); } }