Ejemplo n.º 1
0
LONGBOW_TEST_CASE(Global, athenaFIB_RemoveLink)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    athenaFIB_AddRoute(data->testFIB, data->testName1, data->testVector1);
    athenaFIB_AddRoute(data->testFIB, data->testName2, data->testVector2);

    PARCBitVector *result = athenaFIB_Lookup(data->testFIB, data->testName1, NULL);
    assertTrue(parcBitVector_Equals(result, data->testVector1), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);
    result = athenaFIB_Lookup(data->testFIB, data->testName2, NULL);
    assertTrue(parcBitVector_Equals(result, data->testVector2), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);

    athenaFIB_RemoveLink(data->testFIB, data->testVector1);
    result = athenaFIB_Lookup(data->testFIB, data->testName1, NULL);
    assertNull(result, "Expecting a NULL result from Lookup after Delete Route");
    result = athenaFIB_Lookup(data->testFIB, data->testName2, NULL);
    assertTrue(parcBitVector_Equals(result, data->testVector2), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);

    athenaFIB_AddRoute(data->testFIB, data->testName1, data->testVector12);

    athenaFIB_RemoveLink(data->testFIB, data->testVector2);
    result = athenaFIB_Lookup(data->testFIB, data->testName2, NULL);
    assertNull(result, "Expecting a NULL result from Lookup after Delete Route");
    result = athenaFIB_Lookup(data->testFIB, data->testName1, NULL);
    assertTrue(parcBitVector_Equals(result, data->testVector1), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);
}
Ejemplo n.º 2
0
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);
    }
}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 6
0
LONGBOW_TEST_CASE(Global, parcBitVector_Create_Release)
{
    PARCBitVector *parcBitVector = parcBitVector_Create();
    assertTrue(parcBitVector, "parcBitVector_Create returned a NULL pointer");
    PARCBitVector *reference = parcBitVector;
    parcBitVector_Acquire(reference);
    parcBitVector_Release(&parcBitVector);
    parcBitVector_Release(&reference);
}
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);
}
Ejemplo n.º 8
0
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(&copy);
    parcBitVector_Release(&parcBitVector);
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 10
0
LONGBOW_TEST_CASE(Global, athena_ProcessControl)
{
    PARCURI *connectionURI;
    Athena *athena = athena_Create(100);

    CCNxControl *control = ccnxControl_CreateFlushRequest();

    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_ProcessMessage(athena, control, ingressVector);

    parcBitVector_Release(&ingressVector);

    ccnxInterest_Release(&control);
    athena_Release(&athena);
}
Ejemplo n.º 11
0
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);
}
Ejemplo n.º 12
0
LONGBOW_TEST_CASE(Global, athenaFIB_CreateEntryList)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    athenaFIB_AddRoute(data->testFIB, data->testName1, data->testVector12);

    PARCBitVector *result = athenaFIB_Lookup(data->testFIB, data->testName1, NULL);
    assertTrue(parcBitVector_Equals(result, data->testVector12), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);

    PARCList *entryList = athenaFIB_CreateEntryList(data->testFIB);
    assertTrue(parcList_Size(entryList) == 2, "Expected the EntryList to have 2 elements");

    AthenaFIBListEntry *entry = parcList_GetAtIndex(entryList, 0);
    assertNotNull(entry, "Expect entry at 0 to be non-NULL");
    assertTrue(ccnxName_Equals(data->testName1, entry->name), "Expect the name at 0 to be testName1");
    assertTrue(entry->linkId == 0, "Expect the routeId at 0 to be 0");

    entry = parcList_GetAtIndex(entryList, 1);
    assertNotNull(entry, "Expect entry at 1 to be non-NULL");
    assertTrue(ccnxName_Equals(data->testName1, entry->name), "Expect the name at 1 to be testName1");
    assertTrue(entry->linkId == 42, "Expect the routeId at 0 to be 42");

    parcList_Release(&entryList);
}
Ejemplo n.º 13
0
LONGBOW_TEST_CASE(Global, parcBitVector_Contains)
{
    PARCBitVector *supersetVector = parcBitVector_Create();

    parcBitVector_Set(supersetVector, 10);
    parcBitVector_Set(supersetVector, 11);

    PARCBitVector *testVector = parcBitVector_Create();
    parcBitVector_Set(testVector, 10);
    assertTrue(parcBitVector_Contains(supersetVector, testVector), "Expect superset to contain testVector");

    parcBitVector_Set(testVector, 12);
    assertFalse(parcBitVector_Contains(supersetVector, testVector), "Expect superset to not contain testVector");

    parcBitVector_Release(&supersetVector);
    parcBitVector_Release(&testVector);
}
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);
}
Ejemplo n.º 15
0
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);
}
Ejemplo n.º 16
0
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);
}
Ejemplo n.º 17
0
LONGBOW_TEST_CASE(Global, athenaFIB_Lookup_EmptyPath)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    athenaFIB_AddRoute(data->testFIB, data->testName3, data->testVector1);
    PARCBitVector *result = athenaFIB_Lookup(data->testFIB, data->testName3, NULL);
    assertNotNull(result, "Expect non-null match to global path (\"/\")");
    assertTrue(parcBitVector_Equals(result, data->testVector1), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);
    result = athenaFIB_Lookup(data->testFIB, data->testName1, NULL);
    assertNotNull(result, "Expect non-null match to global path (\"/\")");
    assertTrue(parcBitVector_Equals(result, data->testVector1), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);
    result = athenaFIB_Lookup(data->testFIB, data->testName2, NULL);
    assertNotNull(result, "Expect non-null match to global path (\"/\")");
    assertTrue(parcBitVector_Equals(result, data->testVector1), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);

    athenaFIB_AddRoute(data->testFIB, data->testName3, data->testVector2);
    result = athenaFIB_Lookup(data->testFIB, data->testName3, NULL);
    assertNotNull(result, "Expect non-null match to global path (\"/\")");
    assertTrue(parcBitVector_Equals(result, data->testVector12), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);
    result = athenaFIB_Lookup(data->testFIB, data->testName1, NULL);
    assertNotNull(result, "Expect non-null match to global path (\"/\")");
    assertTrue(parcBitVector_Equals(result, data->testVector12), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);
    result = athenaFIB_Lookup(data->testFIB, data->testName2, NULL);
    assertNotNull(result, "Expect non-null match to global path (\"/\")");
    assertTrue(parcBitVector_Equals(result, data->testVector12), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);
}
Ejemplo n.º 18
0
LONGBOW_TEST_CASE(Global, athenaTransportLinkAdapter_NameToIdToName)
{
    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=TCP_0");
    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_1");
    result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI);
    assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno));
    parcURI_Release(&connectionURI);

    PARCBitVector *linkVector = parcBitVector_Create();
    int linkId = athenaTransportLinkAdapter_LinkNameToId(athenaTransportLinkAdapter, "TCP_1");
    const char *linkName = athenaTransportLinkAdapter_LinkIdToName(athenaTransportLinkAdapter, linkId);
    assertTrue(strcmp(linkName, "TCP_1") == 0, "athenaTransportLinkAdapter_LinkIdToName failed (%s != TCP_1", linkName);

    linkName = athenaTransportLinkAdapter_LinkIdToName(athenaTransportLinkAdapter, 9999);
    assertTrue(linkName == NULL, "athenaTransportLinkAdapter_LinkIdToName returned name for unknown linkID (9999/%s)", linkName);

    parcBitVector_Set(linkVector, linkId);
    PARCBitVector *resultVector = athenaTransportLinkAdapter_Close(athenaTransportLinkAdapter, linkVector);
    assertNotNull(resultVector, "athenaTransportLinkAdapter_Close failed");
    parcBitVector_Release(&linkVector);
    parcBitVector_Release(&resultVector);

    linkId = athenaTransportLinkAdapter_LinkNameToId(athenaTransportLinkAdapter, "TCP_0");
    assertTrue(linkId == -1, "athenaTransportLinkAdapter_LinkNameToId returned id for non routable link (TCP_0 == %d)", linkId);
    int closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "TCP_0");
    assertTrue(closeResult == 0, "athenaTransportLinkAdapter_CloseByName failed (%s)", strerror(errno));

    athenaTransportLinkAdapter_Destroy(&athenaTransportLinkAdapter);
}
Ejemplo n.º 19
0
/**
 * @abstract called from below the link adapter to coordinate termination of a link instance
 * @discussion
 *
 * This is called exclusively from the Transport Link Module to instigate the removal of
 * an active link.  The link has been flagged closing by the originator.  This method
 * must ensure that all references to the link have been removed and then call the
 * instance close method to finish the operation.
 *
 * @param [in] athenaTransportLinkAdapter link adapter instance
 * @param [in] athenaTransportLink link instance to remove
 *
 * Example:
 * @code
 * {
 *
 * }
 * @endcode
 */
static void
_athenaTransportLinkAdapter_RemoveLink(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, AthenaTransportLink *athenaTransportLink)
{
    int linkId = -1;

    // if this is a listener it can simply be removed
    if (athenaTransportLink_IsNotRoutable(athenaTransportLink)) {
        if (athenaTransportLinkAdapter->listenerList) {
            for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->listenerList); index++) {
                AthenaTransportLink *transportLink = parcArrayList_Get(athenaTransportLinkAdapter->listenerList, index);
                if (athenaTransportLink == transportLink) {
                    parcArrayList_RemoveAtIndex(athenaTransportLinkAdapter->listenerList, index);
                    _remove_from_pollfdList(athenaTransportLinkAdapter, athenaTransportLink);
                    parcLog_Debug(athenaTransportLinkAdapter_GetLogger(athenaTransportLinkAdapter), "listener removed: %s",
                                  athenaTransportLink_GetName(athenaTransportLink));
                    athenaTransportLink_Release(&athenaTransportLink);
                    return;
                }
            }
        }
    }

    // Remove from our internal instance list.
    // The index entry remains to be reused by links that are added in the future.
    if (athenaTransportLinkAdapter->instanceList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->instanceList); index++) {
            AthenaTransportLink *transportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, index);
            if (athenaTransportLink == transportLink) {
                parcArrayList_Set(athenaTransportLinkAdapter->instanceList, index, NULL);
                _remove_from_pollfdList(athenaTransportLinkAdapter, athenaTransportLink);
                linkId = index;
                break;
            }
        }
    }

    assertFalse(linkId == -1, "Attempt to remove link not found in link adapter lists");

    // Callback to notify that the link has been removed and references need to be dropped.
    PARCBitVector *linkVector = parcBitVector_Create();
    parcBitVector_Set(linkVector, linkId);
    athenaTransportLinkAdapter->removeLink(athenaTransportLinkAdapter->removeLinkContext, linkVector);
    parcBitVector_Release(&linkVector);

    // we assume all references to the linkId associated with this instance have been
    // cleared from the PIT and FIB when removeLink returns.

    parcLog_Debug(athenaTransportLinkAdapter_GetLogger(athenaTransportLinkAdapter),
                  "link removed: %s", athenaTransportLink_GetName(athenaTransportLink));

    athenaTransportLink_Release(&athenaTransportLink);
}
Ejemplo n.º 20
0
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);
}
Ejemplo n.º 21
0
LONGBOW_TEST_CASE(Global, parcBitVector_Equals)
{
    PARCBitVector *parcBitVector = parcBitVector_Create();
    assertTrue(parcBitVector, "parcBitVector_Create returned a NULL pointer");

    parcBitVector_Set(parcBitVector, 10);
    PARCBitVector *copy = parcBitVector_Copy(parcBitVector);
    assertTrue(parcBitVector_Equals(parcBitVector, copy), "Duplicate vector found unequal");

    parcBitVector_Set(copy, 9);
    assertFalse(parcBitVector_Equals(parcBitVector, copy), "Unequal vector found equal");

    parcBitVector_Clear(copy, 9);
    parcBitVector_Set(copy, 29);
    assertFalse(parcBitVector_Equals(parcBitVector, copy), "Unequal long vector found equal");

    parcBitVector_Clear(copy, 29);
    assertTrue(parcBitVector_Equals(parcBitVector, copy), "Equal long vector found unequal");
    assertTrue(parcBitVector_Equals(copy, parcBitVector), "Equal long vector found unequal");

    parcBitVector_Release(&copy);
    parcBitVector_Release(&parcBitVector);
}
Ejemplo n.º 22
0
LONGBOW_TEST_CASE(Global, athenaFIB_Lookup)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    athenaFIB_AddRoute(data->testFIB, data->testName1, data->testVector1);
    PARCBitVector *result = athenaFIB_Lookup(data->testFIB, data->testName1, NULL);
    assertTrue(parcBitVector_Equals(result, data->testVector1), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);

    //
    // Name3 (the default route) contains both vector1 and vector2.
    // Name1 (a/b/c) contains only vector 1.
    // Name4 (a/b/c/d) is what we're looking for.
    // Although Name1 is a match for Name4, it only contains the ingress vector1.
    // We must the search until we match the default route. Ingress vector1
    // must be removed from the returned vector list from the default route.
    //
    // Make sure we see only vector2 in the result.
    //
    athenaFIB_AddRoute(data->testFIB, data->testName3, data->testVector12);
    result = athenaFIB_Lookup(data->testFIB, data->testName4, data->testVector1);
    assertTrue(parcBitVector_Equals(result, data->testVector2), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);
}
Ejemplo n.º 23
0
LONGBOW_TEST_CASE(Global, parcBitVector_ToString)
{
    PARCBitVector *parcBitVector = parcBitVector_Create();
    assertTrue(parcBitVector, "parcBitVector_Create returned a NULL pointer");

    char *string = parcBitVector_ToString(parcBitVector);
    assertTrue(strcmp(string, "[ ]") == 0, "parcBitVector_ToString returned unexpected representation (%s != [ ])", string);
    parcMemory_Deallocate(&string);

    parcBitVector_Set(parcBitVector, 10);
    parcBitVector_Set(parcBitVector, 1);
    string = parcBitVector_ToString(parcBitVector);
    assertTrue(strcmp(string, "[ 1 10 ]") == 0, "parcBitVector_ToString returned unexpected representation (%s != [ 1 10 ])", string);
    parcMemory_Deallocate(&string);

    parcBitVector_Release(&parcBitVector);
}
Ejemplo n.º 24
0
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);
}
Ejemplo n.º 25
0
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);
}
Ejemplo n.º 26
0
CCNxMetaMessage *
athenaTransportLinkAdapter_Receive(AthenaTransportLinkAdapter *athenaTransportLinkAdapter,
                                   PARCBitVector **resultVector, int timeout)
{
    int linkId;
    *resultVector = parcBitVector_Create();

    // Traverse instance list starting from where we last left off.
    linkId = athenaTransportLinkAdapter->nextLinkToRead;
    CCNxMetaMessage *ccnxMetaMessage = _retrieve_next_message(athenaTransportLinkAdapter, athenaTransportLinkAdapter->instanceList, &linkId);
    if (ccnxMetaMessage) {
        parcBitVector_Set(*resultVector, linkId);
        athenaTransportLinkAdapter->nextLinkToRead = linkId + 1;
        athenaTransportLinkAdapter->stats.messageReceived++;
        return ccnxMetaMessage;
    }

    // Once the instance list is clear, traverse the entire listener list
    ccnxMetaMessage = _retrieve_next_message(athenaTransportLinkAdapter, athenaTransportLinkAdapter->listenerList, NULL);
    assertNull(ccnxMetaMessage, "listener returned an unexpected message");

    // Last instance event has been serviced, poll all modules.
    athenaTransportLinkAdapter_Poll(athenaTransportLinkAdapter, timeout);

    // Traverse the entire listener list (could potentially populate other instances)
    ccnxMetaMessage = _retrieve_next_message(athenaTransportLinkAdapter, athenaTransportLinkAdapter->listenerList, NULL);
    assertNull(ccnxMetaMessage, "listener returned an unexpected message");

    // Search instance list from the beginning.
    athenaTransportLinkAdapter->nextLinkToRead = 0;
    linkId = athenaTransportLinkAdapter->nextLinkToRead;
    ccnxMetaMessage = _retrieve_next_message(athenaTransportLinkAdapter, athenaTransportLinkAdapter->instanceList, &linkId);
    if (ccnxMetaMessage) {
        parcBitVector_Set(*resultVector, linkId);
        athenaTransportLinkAdapter->nextLinkToRead = linkId + 1;
        athenaTransportLinkAdapter->stats.messageReceived++;
        return ccnxMetaMessage;
    }

    parcBitVector_Release(resultVector);
    errno = EAGAIN;
    return NULL;
}
Ejemplo n.º 27
0
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);
}
Ejemplo n.º 28
0
LONGBOW_TEST_CASE(Global, athena_ProcessInterestReturn)
{
    PARCURI *connectionURI;
    Athena *athena = athena_Create(100);

    CCNxName *name = ccnxName_CreateFromCString("lci:/boose/roo/pie");

    CCNxInterest *interest =
        ccnxInterest_CreateWithImpl(&CCNxInterestFacadeV1_Implementation,
                                    name,
                                    CCNxInterestDefault_LifetimeMilliseconds,
                                    NULL,
                                    NULL,
                                    CCNxInterestDefault_HopLimit);
    ccnxName_Release(&name);
    CCNxInterestReturn *interestReturn = ccnxInterestReturn_Create(interest, CCNxInterestReturn_ReturnCode_Congestion);
    ccnxInterest_Release(&interest);

    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(interestReturn);

    athena_ProcessMessage(athena, interestReturn, ingressVector);

    parcBitVector_Release(&ingressVector);

    ccnxInterest_Release(&interestReturn);
    athena_Release(&athena);
}
Ejemplo n.º 29
0
void *
athena_ForwarderEngine(void *arg)
{
    Athena *athena = (Athena *) arg;

    if (athena) {
        while (athena->athenaState == Athena_Running) {
            CCNxMetaMessage *ccnxMessage;
            PARCBitVector *ingressVector;
            int receiveTimeout = -1; // block until message received
            ccnxMessage = athenaTransportLinkAdapter_Receive(athena->athenaTransportLinkAdapter,
                                                             &ingressVector, receiveTimeout);
            if (ccnxMessage) {
                athena_ProcessMessage(athena, ccnxMessage, ingressVector);

                parcBitVector_Release(&ingressVector);
                ccnxMetaMessage_Release(&ccnxMessage);
            }
        }
        usleep(1000); // workaround for coordinating with test infrastructure
        athena_Release(&athena);
    }
    return NULL;
}
Ejemplo n.º 30
0
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);
}