Ejemplo n.º 1
0
LONGBOW_TEST_CASE(Global, PARCList_InsertAtIndex_Last)
{
    PARCArrayList *array = parcArrayList_Create(NULL);

    parcArrayList_Add(array, (void *) 1);
    parcArrayList_Add(array, (void *) 2);
    size_t actual = parcArrayList_Size(array);

    assertTrue(2 == actual, "Expected=%d, actual=%zu", 2, actual);

    parcArrayList_InsertAtIndex(array, 2, (void *) 3);

    actual = parcArrayList_Size(array);
    assertTrue(3 == actual, "Expected=%d, actual=%zu", 3, actual);

    void *element0 = parcArrayList_Get(array, 0);
    assertTrue(element0 == (void *) 1, "Element 1 moved?");

    void *element1 = parcArrayList_Get(array, 1);
    assertTrue(element1 == (void *) 2, "Element 1 moved?");

    void *element2 = parcArrayList_Get(array, 2);
    assertTrue(element2 == (void *) 3, "Element 1 moved?");

    parcArrayList_Destroy(&array);
}
Ejemplo n.º 2
0
/**
 * This composes a CCNxTransportConfig instance that describes a complete transport stack assembly.
 */
static const CCNxTransportConfig *
_createTransportConfig(const CCNxPortalFactory *factory, _CCNxPortalType type, _CCNxPortalProtocol protocol)
{
    if (type == ccnxPortalTypeChunked) {
        // Good.
    } else if (type == ccnxPortalTypeMessage) {
        // Good.
    } else {
        return NULL;
    }

    // TODO: This is in need of some narrative of what's going on here.

    CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create();
    CCNxStackConfig *stackConfig = ccnxStackConfig_Create();

    PARCArrayList *listOfComponentNames = parcArrayList_Create_Capacity(NULL, NULL, 8);

    parcArrayList_Add(listOfComponentNames, (char *) apiConnector_GetName());

    apiConnector_ProtocolStackConfig(stackConfig);
    apiConnector_ConnectionConfig(connConfig);

    if (type == ccnxPortalTypeChunked) {
        parcArrayList_Add(listOfComponentNames, (char *) vegasFlowController_GetName());
        vegasFlowController_ProtocolStackConfig(stackConfig);
        vegasFlowController_ConnectionConfig(connConfig);
    }

    switch (protocol) {
        case CCNxPortalProtocol_RTALoopback:
            _ccnxPortalProtocol_RTALoopback(connConfig, stackConfig, listOfComponentNames);
            break;

        case ccnxPortalProtocol_RTA:
            _ccnxPortalProtocol_RTAMetis(connConfig, stackConfig, listOfComponentNames);
            break;

        default:
            errno = EPROTOTYPE;
            assertTrue(0, "Unknown protocol type: %d", protocol);
    }


    protocolStack_ComponentsConfigArrayList(stackConfig, listOfComponentNames);
    parcArrayList_Destroy(&listOfComponentNames);

    const PARCIdentity *identity = ccnxPortalFactory_GetIdentity(factory);

    configPublicKeySigner_SetIdentity(connConfig, identity);

    CCNxTransportConfig *result = ccnxTransportConfig_Create(stackConfig, connConfig);

    ccnxStackConfig_Release(&stackConfig);

    return result;
}
Ejemplo n.º 3
0
/**
 * @abstract add a new link instance to the AthenaTransportLinkAdapter instance list
 * @discussion
 *
 * When athenaTransportLinkAdapter_Open is called on a link specific module, the module instantiates
 * the link and then creates a new AthenaTransportLink to interface with the AthenaTransportLinkAdapter.
 * The AthenaTransportLinkModule passes the new AthenaTransportLink to the AthenaTransportLinkAdapter by
 * calling AthenaTransportLinkAdapter_AddLink with the new link AthenaTransportLink data. The AthenaTransportLinkAdapter
 * then places the new link instance on its internal instance list in a pending state until it has been verified and ensures
 * that the new link doesn't collide (i.e. by name) with any currently registered link before returning success.
 *
 * New routable links are placed into instanceList slots that have previously been vacated before being added
 * to the end of the instanceList.  This is in order to keep bit vectors that are based on the instanceList as
 * small as is necessary.
 *
 * @param [in] athenaTransportLinkAdapter link adapter instance
 * @param [in] linkInstance instance structure created by the link specific module
 * @return 0 on success, -1 with errno set to indicate the error
 *
 * Example:
 * @code
 * {
 * }
 * @endcode
 */
static int
_athenaTransportLinkAdapter_AddLink(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, AthenaTransportLink *newTransportLink)
{
    int linkId = -1;

    // Check for existing linkName in listenerList
    if (athenaTransportLinkAdapter->listenerList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->listenerList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->listenerList, index);
            if (strcmp(athenaTransportLink_GetName(athenaTransportLink), athenaTransportLink_GetName(newTransportLink)) == 0) {
                errno = EADDRINUSE; // name is already in listenerList
                return -1;
            }
        }
    }

    // Check for existing linkName in the instanceList
    if (athenaTransportLinkAdapter->instanceList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->instanceList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, index);
            if (athenaTransportLink) {
                if (strcmp(athenaTransportLink_GetName(athenaTransportLink), athenaTransportLink_GetName(newTransportLink)) == 0) {
                    errno = EADDRINUSE; // name is already in instanceList
                    return -1;
                }
            } else {
                // remember the first available index found along the way
                if (linkId == -1) {
                    linkId = index;
                }
            }
        }
    }

    // Add to listenerList or instanceList
    athenaTransportLink_Acquire(newTransportLink);
    if (athenaTransportLink_IsNotRoutable(newTransportLink)) { // listener
        bool result = parcArrayList_Add(athenaTransportLinkAdapter->listenerList, newTransportLink);
        assertTrue(result, "parcArrayList_Add failed to add new listener");
    } else { // routable link, add to instances using the last available id if one was seen
        if (linkId != -1) {
            parcArrayList_Set(athenaTransportLinkAdapter->instanceList, linkId, newTransportLink);
        } else {
            bool result = parcArrayList_Add(athenaTransportLinkAdapter->instanceList, newTransportLink);
            assertTrue(result, "parcArrayList_Add failed to add new link instance");
        }
    }

    // If any transport link has a registered file descriptor add it to the general polling list.
    int eventFd = athenaTransportLink_GetEventFd(newTransportLink);
    if (eventFd != -1) {
        _add_to_pollfdList(athenaTransportLinkAdapter, newTransportLink, eventFd);
    }
    return 0;
}
Ejemplo n.º 4
0
LONGBOW_TEST_CASE(Global, PARC_TreeRedBlack_Values)
{
    PARCTreeRedBlack *tree1;
    PARCArrayList *list;

    tree1 = parcTreeRedBlack_Create(pointerComp, NULL, NULL, NULL, NULL, NULL);
    list = parcArrayList_Create(NULL);

    // Insert in tree out of order
    for (long i = 10; i < 20; i++) {
        // Add some elements to the tree
        parcTreeRedBlack_Insert(tree1, (void *) i, (void *) (i << 8));
    }
    for (long i = 1; i < 10; i++) {
        // Add some elements to the tree
        parcTreeRedBlack_Insert(tree1, (void *) i, (void *) (i << 8));
    }

    // Insert in list in order
    for (long i = 1; i < 20; i++) {
        // Add some elements to the tree
        parcArrayList_Add(list, (void *) (i << 8));
    }

    PARCArrayList *values = parcTreeRedBlack_Values(tree1);

    assertTrue(parcArrayList_Equals(list, values), "Key list doesnt' match");

    parcArrayList_Destroy(&values);
    parcArrayList_Destroy(&list);
    parcTreeRedBlack_Destroy(&tree1);
}
Ejemplo n.º 5
0
/**
 * @function metisListenerSet_Add
 * @abstract Adds the listener to the set
 * @discussion
 *     Unique set based on pair (MetisEncapType, localAddress)
 *
 * @param <#param1#>
 * @return <#return#>
 */
bool
metisListenerSet_Add(MetisListenerSet *set, MetisListenerOps *ops)
{
    assertNotNull(set, "Parameter set must be non-null");
    assertNotNull(ops, "Parameter ops must be non-null");

    int opsEncap = ops->getEncapType(ops);
    const CPIAddress *opsAddress = ops->getListenAddress(ops);

    // make sure its not in the set
    size_t length = parcArrayList_Size(set->listOfListeners);
    for (size_t i = 0; i < length; i++) {
        MetisListenerOps *entry = parcArrayList_Get(set->listOfListeners, i);

        int entryEncap = entry->getEncapType(entry);
        const CPIAddress *entryAddress = entry->getListenAddress(entry);

        if (opsEncap == entryEncap && cpiAddress_Equals(opsAddress, entryAddress)) {
            // duplicate
            return false;
        }
    }

    parcArrayList_Add(set->listOfListeners, ops);
    return true;
}
Ejemplo n.º 6
0
static void
_ccnxPortalProtocol_RTAMetis(CCNxConnectionConfig *connConfig, CCNxStackConfig *stackConfig, PARCArrayList *listOfComponentNames)
{
    uint16_t metisPort = ccnxPortal_MetisPort;
    char *metisPortEnv = getenv("METIS_PORT");
    if (metisPortEnv != NULL) {
        metisPort = (uint16_t) atoi(metisPortEnv);
    }
    parcArrayList_Add(listOfComponentNames, (char *) tlvCodec_GetName());
    tlvCodec_ProtocolStackConfig(stackConfig);
    tlvCodec_ConnectionConfig(connConfig);

    parcArrayList_Add(listOfComponentNames, (char *) metisForwarder_GetName());
    metisForwarder_ProtocolStackConfig(stackConfig);
    metisForwarder_ConnectionConfig(connConfig, metisPort);
}
Ejemplo n.º 7
0
void
metisConnectionList_Append(MetisConnectionList *list, MetisConnection *entry)
{
    assertNotNull(list, "Parameter list must be non-null");
    assertNotNull(entry, "Parameter entry must be non-null");

    parcArrayList_Add(list->listOfConnections, metisConnection_Acquire(entry));
}
Ejemplo n.º 8
0
static void
_ccnxPortalProtocol_RTALoopback(CCNxConnectionConfig *connConfig, CCNxStackConfig *stackConfig, PARCArrayList *listOfComponentNames)
{
    char *bentPipeNameEnv = getenv("BENT_PIPE_NAME");
    if (bentPipeNameEnv != NULL) {
    } else {
        printf("The BENT_PIPE_NAME environment variable needs to the name of a 'fifo' file.  Try /tmp/test_ccnx_Portal\n");
    }

    parcArrayList_Add(listOfComponentNames, (char *) tlvCodec_GetName());
    tlvCodec_ProtocolStackConfig(stackConfig);
    tlvCodec_ConnectionConfig(connConfig);

    parcArrayList_Add(listOfComponentNames, (char *) localForwarder_GetName());
    localForwarder_ProtocolStackConfig(stackConfig);
    localForwarder_ConnectionConfig(connConfig, bentPipeNameEnv);
}
void
cpiConnectionList_Append(CPIConnectionList *list, CPIConnection *entry)
{
    assertNotNull(list, "Parameter list must be non-null");
    assertNotNull(entry, "Parameter entry must be non-null");

    parcArrayList_Add(list->listOfConnections, entry);
}
Ejemplo n.º 10
0
LONGBOW_TEST_CASE(Global, PARCList_Length)
{
    PARCArrayList *array = parcArrayList_Create(NULL);
    parcArrayList_Add(array, 0);

    size_t size = parcArrayList_Size(array);
    assertTrue(1 == size, "Expected %d actual=%zd", 1, size);
    parcArrayList_Destroy(&array);
}
Ejemplo n.º 11
0
LONGBOW_TEST_CASE(Global, PARCList_IsEmpty)
{
    PARCArrayList *array = parcArrayList_Create(NULL);
    assertTrue(parcArrayList_IsEmpty(array), "Expected a new array to be empty.");

    parcArrayList_Add(array, 0);
    assertFalse(parcArrayList_IsEmpty(array), "Expected an array with more than zero elements to be empty.");

    parcArrayList_Destroy(&array);
}
Ejemplo n.º 12
0
/**
 * @abstract called from the link specific adapter to coordinate the addition of a link instance
 * @discussion
 *
 * @param [in] athenaTransportLink link adapter instance
 * @param [in] athenaTransportLink link instance to add
 * @return 0 if successful, -1 on failure with errno set to indicate error
 *
 * Example:
 * @code
 * {
 *
 * }
 * @endcode
 */
static int
_athenaTransportLinkModule_AddLink(AthenaTransportLinkModule *athenaTransportLinkModule, AthenaTransportLink *newTransportLink)
{
    // up call to add link to transport adapter
    int result = athenaTransportLinkModule->addLink(athenaTransportLinkModule->addLinkContext, newTransportLink);
    if (result == 0) {
        athenaTransportLink_Acquire(newTransportLink);
        parcArrayList_Add(athenaTransportLinkModule->instanceList, newTransportLink);
    }
    return result;
}
Ejemplo n.º 13
0
/**
 * Called on a new connection to the server socket
 *
 *   Will allocate a new _MetisCommandLineInterface_Session and put it in the
 *   server's PARCArrayList
 *
 * @param <#param1#>
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
static void
_metisCommandLineInterface_ListenerCallback(MetisSocketType client_socket,
                                            struct sockaddr *client_addr, int socklen, void *user_data)
{
    MetisCommandLineInterface *cli = (MetisCommandLineInterface *) user_data;
    _MetisCommandLineInterface_Session *session = metisCliSession_Create(cli, client_socket, client_addr, socklen);
    parcArrayList_Add(cli->openSessions, session);

    _metisCliSession_DisplayMotd(session);
    _metisCliSession_DisplayPrompt(session);
}
Ejemplo n.º 14
0
static void
_AddModule(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, AthenaTransportLinkModule *newTransportLinkModule)
{
    athenaTransportLinkModule_SetAddLinkCallback(newTransportLinkModule,
                                                 (AthenaTransportLinkModule_AddLinkCallback *) _athenaTransportLinkAdapter_AddLink,
                                                 athenaTransportLinkAdapter);
    athenaTransportLinkModule_SetRemoveLinkCallback(newTransportLinkModule,
                                                    (AthenaTransportLinkModule_RemoveLinkCallback *) _athenaTransportLinkAdapter_RemoveLink,
                                                    athenaTransportLinkAdapter);

    assertTrue(parcArrayList_Add(athenaTransportLinkAdapter->moduleList, newTransportLinkModule) == true, "parcArrayList_Add of module failed");
}
Ejemplo n.º 15
0
LONGBOW_TEST_CASE(Global, PARCList_Get)
{
    PARCArrayList *array = parcArrayList_Create(parcArrayList_StdlibFreeFunction);

    char *expected = strdup("Hello World");
    parcArrayList_Add(array, expected);

    char *actual = parcArrayList_Get(array, 0);

    assertTrue(expected == actual, "Expected=%p, actual=%p", (void *) expected, (void *) actual);

    parcArrayList_Destroy(&array);
}
Ejemplo n.º 16
0
LONGBOW_TEST_CASE(Global, PARCList_RemoveAndDestroy_AtIndex_Last)
{
    char a[] = "apple";
    char b[] = "bananna";
    char c[] = "cherry";

    PARCArrayList *array = parcArrayList_Create(NULL);
    parcArrayList_Add(array, a);
    parcArrayList_Add(array, b);
    parcArrayList_Add(array, c);

    PARCArrayList *expected = parcArrayList_Create(NULL);
    parcArrayList_Add(expected, a);
    parcArrayList_Add(expected, b);

    parcArrayList_RemoveAndDestroyAtIndex(array, 2);

    assertTrue(parcArrayList_Equals(expected, array), "Expected ");

    parcArrayList_Destroy(&expected);
    parcArrayList_Destroy(&array);
}
Ejemplo n.º 17
0
LONGBOW_TEST_CASE(Global, PARCList_Remove_AtIndex)
{
    char a[] = "apple";
    char b[] = "bananna";
    char c[] = "cherry";

    PARCArrayList *array = parcArrayList_Create(NULL);
    parcArrayList_Add(array, a);
    parcArrayList_Add(array, b);
    parcArrayList_Add(array, c);

    PARCArrayList *expected = parcArrayList_Create(NULL);
    parcArrayList_Add(expected, a);
    parcArrayList_Add(expected, c);

    void *removedElement = parcArrayList_RemoveAtIndex(array, 1);

    assertTrue(removedElement == b, "Expected ");
    assertTrue(parcArrayList_Equals(expected, array), "Expected ");

    parcArrayList_Destroy(&expected);
    parcArrayList_Destroy(&array);
}
Ejemplo n.º 18
0
PARCArrayList *
athenaTransportLinkModuleUDP_Init()
{
    // Module for providing UDP tunnel connections.
    AthenaTransportLinkModule *athenaTransportLinkModule;
    PARCArrayList *moduleList = parcArrayList_Create(NULL);
    assertNotNull(moduleList, "parcArrayList_Create failed to create module list");

    athenaTransportLinkModule = athenaTransportLinkModule_Create("UDP",
                                                                 _UDPOpen,
                                                                 _UDPPoll);
    assertNotNull(athenaTransportLinkModule, "parcMemory_AllocateAndClear failed allocate UDP athenaTransportLinkModule");
    bool result = parcArrayList_Add(moduleList, athenaTransportLinkModule);
    assertTrue(result == true, "parcArrayList_Add failed");

    return moduleList;
}
//
// This function must be named "athenaTransportLinkModule" <module name> "_Init" so that
// athenaTransportLinkAdapter can locate it to invoke initialization when it's loaded.  It's
// named uniquely (as opposed to _init()) so that it can also be statically linked into Athena.
//
PARCArrayList *
athenaTransportLinkModuleTEMPLATE_Init()
{
    // Template module for establishing point to point tunnel connections.
    AthenaTransportLinkModule *athenaTransportLinkModule;
    PARCArrayList *moduleInstanceList = parcArrayList_Create(NULL);
    assertNotNull(moduleInstanceList, "parcArrayList_Create failed to create module list");

    athenaTransportLinkModule = athenaTransportLinkModule_Create("TEMPLATE",
                                                                 _TemplateOpen,
                                                                 _TemplatePoll);
    assertNotNull(athenaTransportLinkModule, "parcMemory_AllocateAndClear failed allocate Template athenaTransportLinkModule");
    bool result = parcArrayList_Add(moduleInstanceList, athenaTransportLinkModule);
    assertTrue(result == true, "parcArrayList_Add failed");

    return moduleInstanceList;
}
PARCArrayList *
athenaTransportLinkModuleETH_Init()
{
    // Module for providing Ethernet links.
    AthenaTransportLinkModule *athenaTransportLinkModule;
    PARCArrayList *moduleList = parcArrayList_Create(NULL);
    assertNotNull(moduleList, "parcArrayList_Create failed to create module list");

    athenaTransportLinkModule = athenaTransportLinkModule_Create("ETH",
                                                                 _ETHOpen,
                                                                 _ETHPoll);
    assertNotNull(athenaTransportLinkModule, "parcMemory_AllocateAndClear failed allocate ETH athenaTransportLinkModule");
    bool result = parcArrayList_Add(moduleList, athenaTransportLinkModule);
    assertTrue(result == true, "parcArrayList_Add failed");

    return moduleList;
}
Ejemplo n.º 21
0
bool
cpiInterfaceSet_Add(CPIInterfaceSet *set, CPIInterface *iface)
{
    assertNotNull(set, "Parameter set must be non-null");
    assertNotNull(iface, "Parameter iface must be non-null");

    unsigned ifaceIndex = cpiInterface_GetInterfaceIndex(iface);
    size_t length = parcArrayList_Size(set->listOfInterfaces);
    for (size_t i = 0; i < length; i++) {
        CPIInterface *listEntry = (CPIInterface *) parcArrayList_Get(set->listOfInterfaces, i);
        unsigned entryInterfaceIndex = cpiInterface_GetInterfaceIndex(listEntry);
        if (entryInterfaceIndex == ifaceIndex) {
            return false;
        }
    }

    parcArrayList_Add(set->listOfInterfaces, (PARCObject *) iface);
    return true;
}
Ejemplo n.º 22
0
PARCURIPath *
parcURIPath_Append(PARCURIPath *path, const PARCURISegment *segment)
{
    parcArrayList_Add(path->segments, segment);
    return path;
}
Ejemplo n.º 23
0
LONGBOW_TEST_CASE(Global, PARCList_Equals_Contract_Deep)
{
    char a[] = "apple";
    char b[] = "bananna";
    char c[] = "cherry";
    char d[] = "potato";

    PARCArrayList *x = parcArrayList_Create_Capacity(stringEquals, NULL, 0);
    parcArrayList_Add(x, a);
    parcArrayList_Add(x, b);
    parcArrayList_Add(x, c);

    PARCArrayList *y = parcArrayList_Create_Capacity(stringEquals, NULL, 0);
    parcArrayList_Add(y, a);
    parcArrayList_Add(y, b);
    parcArrayList_Add(y, c);

    PARCArrayList *z = parcArrayList_Create_Capacity(stringEquals, NULL, 0);
    parcArrayList_Add(z, a);
    parcArrayList_Add(z, b);
    parcArrayList_Add(z, c);

    PARCArrayList *u1 = parcArrayList_Create_Capacity(stringEquals, NULL, 0);
    parcArrayList_Add(u1, a);
    parcArrayList_Add(u1, b);

    PARCArrayList *u2 = parcArrayList_Create_Capacity(stringEquals, NULL, 0);
    parcArrayList_Add(u2, a);
    parcArrayList_Add(u2, b);
    parcArrayList_Add(u2, c);
    parcArrayList_Add(u2, c);

    PARCArrayList *u3 = parcArrayList_Create_Capacity(stringEquals, NULL, 0);
    parcArrayList_Add(u3, a);
    parcArrayList_Add(u3, b);
    parcArrayList_Add(u3, d);

    parcObjectTesting_AssertEqualsFunction(parcArrayList_Equals, x, y, z, u1, u2, u3);

    parcArrayList_Destroy(&x);
    parcArrayList_Destroy(&y);
    parcArrayList_Destroy(&z);
    parcArrayList_Destroy(&u1);
    parcArrayList_Destroy(&u2);
    parcArrayList_Destroy(&u3);
}