static CCNxTransportConfig *
createParams(const char *keystore_name, const char *keystore_passwd)
{
    assertNotNull(keystore_name, "Got null keystore name\n");
    assertNotNull(keystore_passwd, "Got null keystore passwd\n");

    CCNxStackConfig *stackConfig = apiConnector_ProtocolStackConfig(
        testingUpper_ProtocolStackConfig(
            vegasFlowController_ProtocolStackConfig(
                testingLower_ProtocolStackConfig(
                    protocolStack_ComponentsConfigArgs(ccnxStackConfig_Create(),
                                                       apiConnector_GetName(),
                                                       testingUpper_GetName(),
                                                       vegasFlowController_GetName(),
                                                       testingLower_GetName(),
                                                       NULL)))));

    CCNxConnectionConfig *connConfig = apiConnector_ConnectionConfig(
        testingUpper_ConnectionConfig(
            vegasFlowController_ConnectionConfig(
                tlvCodec_ConnectionConfig(
                    testingLower_ConnectionConfig(ccnxConnectionConfig_Create())))));

    publicKeySignerPkcs12Store_ConnectionConfig(connConfig, keystore_name, keystore_passwd);

    CCNxTransportConfig *result = ccnxTransportConfig_Create(stackConfig, connConfig);
    ccnxStackConfig_Release(&stackConfig);
    return result;
}
LONGBOW_TEST_CASE(Global, ccnxStackConfig_AssertValid)
{
    CCNxStackConfig *instance = ccnxStackConfig_Create();
    ccnxStackConfig_AssertValid(instance);

    ccnxStackConfig_Release(&instance);
}
static CCNxTransportConfig *
codecTlv_CreateParams(const char *keystore_filename, const char *keystore_password)
{
    assertNotNull(keystore_filename, "Got null keystore name\n");
    assertNotNull(keystore_password, "Got null keystore passwd\n");

    CCNxStackConfig *stackConfig = ccnxStackConfig_Create();

    apiConnector_ProtocolStackConfig(stackConfig);
    testingUpper_ProtocolStackConfig(stackConfig);
    tlvCodec_ProtocolStackConfig(stackConfig);
    testingLower_ProtocolStackConfig(stackConfig);
    protocolStack_ComponentsConfigArgs(stackConfig, apiConnector_GetName(), testingUpper_GetName(), tlvCodec_GetName(), testingLower_GetName(), NULL);

    CCNxConnectionConfig *connConfig = apiConnector_ConnectionConfig(ccnxConnectionConfig_Create());
    testingUpper_ConnectionConfig(connConfig);
    tlvCodec_ConnectionConfig(connConfig);
    testingLower_ConnectionConfig(connConfig);

    unlink(keystore_filename);

    bool success = parcPublicKeySignerPkcs12Store_CreateFile(keystore_filename, keystore_password, "alice", 1024, 30);
    assertTrue(success, "parcPublicKeySignerPkcs12Store_CreateFile() failed.");

    publicKeySignerPkcs12Store_ConnectionConfig(connConfig, keystore_filename, keystore_password);

    CCNxTransportConfig *result = ccnxTransportConfig_Create(stackConfig, connConfig);
    ccnxStackConfig_Release(&stackConfig);
    return result;
}
LONGBOW_TEST_CASE(Global, ccnxStackConfig_HashCode)
{
    CCNxStackConfig *instance = ccnxStackConfig_Create();
    uint64_t hashCode = ccnxStackConfig_HashCode(instance);
    printf("%" PRIu64 "\n", hashCode);
    ccnxStackConfig_Release(&instance);
}
LONGBOW_TEST_CASE(Global, ccnxStackConfig_Display)
{
    CCNxStackConfig *config = ccnxStackConfig_Create();
    ccnxStackConfig_Display(config, 1);

    ccnxStackConfig_Release(&config);
}
static CCNxTransportConfig *
_createParams(const char *local_name, const char *keystore_name, const char *keystore_passwd)
{
    assertNotNull(local_name, "Got null local name\n");
    assertNotNull(keystore_name, "Got null keystore name\n");
    assertNotNull(keystore_passwd, "Got null keystore passwd\n");

    CCNxStackConfig *stackConfig = apiConnector_ProtocolStackConfig(
        tlvCodec_ProtocolStackConfig(
            localForwarder_ProtocolStackConfig(
                protocolStack_ComponentsConfigArgs(ccnxStackConfig_Create(),
                                                   apiConnector_GetName(),
                                                   tlvCodec_GetName(),
                                                   localForwarder_GetName(),
                                                   NULL))));

    CCNxConnectionConfig *connConfig = apiConnector_ConnectionConfig(
            localForwarder_ConnectionConfig(ccnxConnectionConfig_Create(), local_name));

    connConfig = tlvCodec_ConnectionConfig(connConfig);

    publicKeySigner_ConnectionConfig(connConfig, keystore_name, keystore_passwd);

    CCNxTransportConfig *result = ccnxTransportConfig_Create(stackConfig, connConfig);
    ccnxStackConfig_Release(&stackConfig);
    return result;
}
LONGBOW_TEST_CASE(Global, ccnxStackConfig_ToJSON)
{
    CCNxStackConfig *instance = ccnxStackConfig_Create();
    PARCJSON *json = ccnxStackConfig_ToJSON(instance);
    assertNotNull(json, "Expected non-null JSON");

    ccnxStackConfig_Release(&instance);
}
LONGBOW_TEST_CASE(Global, ccnxStackConfig_IsValid)
{
    CCNxStackConfig *instance = ccnxStackConfig_Create();
    assertTrue(ccnxStackConfig_IsValid(instance), "Expected ccnxStackConfig_Create to result in a valid instance.");

    ccnxStackConfig_Release(&instance);
    assertFalse(ccnxStackConfig_IsValid(instance), "Expected ccnxStackConfig_Create to result in an invalid instance.");
}
LONGBOW_TEST_CASE(Global, ccnxStackConfig_ToString)
{
    CCNxStackConfig *instance = ccnxStackConfig_Create();
    char *string = ccnxStackConfig_ToString(instance);
    assertNotNull(string, "Expected non-null ccnxStackConfig_ToString");

    parcMemory_Deallocate((void **) &string);
    ccnxStackConfig_Release(&instance);
}
LONGBOW_TEST_CASE(Global, ccnxStackConfig_Equals)
{
    CCNxStackConfig *x = ccnxStackConfig_Create();
    CCNxStackConfig *y = ccnxStackConfig_Create();
    CCNxStackConfig *z = ccnxStackConfig_Create();

    CCNxStackConfig *u1 = ccnxStackConfig_Create();
    PARCJSONValue *val = parcJSONValue_CreateFromNULL();
    ccnxStackConfig_Add(u1, "key", val);
    parcJSONValue_Release(&val);

    parcObjectTesting_AssertEquals(x, y, z, NULL);

    ccnxStackConfig_Release(&x);
    ccnxStackConfig_Release(&y);
    ccnxStackConfig_Release(&z);
    ccnxStackConfig_Release(&u1);
}
LONGBOW_TEST_CASE(Global, ccnxStackConfig_Copy)
{
    CCNxStackConfig *instance = ccnxStackConfig_Create();
    CCNxStackConfig *copy = ccnxStackConfig_Copy(instance);
    assertTrue(ccnxStackConfig_Equals(instance, copy), "Expected the copy to be equal to the original");

    ccnxStackConfig_Release(&instance);
    ccnxStackConfig_Release(&copy);
}
Example #12
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;
}
static TestData *
_commonSetup(void)
{
    TestData *data = parcMemory_AllocateAndClear(sizeof(TestData));
    assertNotNull(data, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(TestData));

    data->commandRingBuffer = parcRingBuffer1x1_Create(128, NULL);
    data->commandNotifier = parcNotifier_Create();
    data->framework = rtaFramework_Create(data->commandRingBuffer, data->commandNotifier);
    assertNotNull(data->framework, "rtaFramework_Create returned null");

    CCNxStackConfig *stackConfig = ccnxStackConfig_Create();

    apiConnector_ProtocolStackConfig(stackConfig);
    testingLower_ProtocolStackConfig(stackConfig);
    protocolStack_ComponentsConfigArgs(stackConfig, apiConnector_GetName(), testingLower_GetName(), NULL);

    rtaFramework_NonThreadedStepCount(data->framework, 10);
    
    // Create the protocol stack

    data->stackId = 1;
    RtaCommandCreateProtocolStack *createStack = rtaCommandCreateProtocolStack_Create(data->stackId, stackConfig);
    _rtaFramework_ExecuteCreateStack(data->framework, createStack);
    rtaCommandCreateProtocolStack_Release(&createStack);

    rtaFramework_NonThreadedStepCount(data->framework, 10);
    data->stack = (rtaFramework_GetProtocolStackByStackId(data->framework, data->stackId))->stack;

    // Create a connection in the stack

    int error = socketpair(AF_UNIX, SOCK_STREAM, 0, data->api_fds);
    assertFalse(error, "Error creating socket pair: (%d) %s", errno, strerror(errno));

    CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create();
    apiConnector_ConnectionConfig(connConfig);

    tlvCodec_ConnectionConfig(connConfig);

    testingLower_ConnectionConfig(connConfig);

    RtaCommandOpenConnection *openConnection = rtaCommandOpenConnection_Create(data->stackId, data->api_fds[PAIR_OTHER], data->api_fds[PAIR_TRANSPORT], ccnxConnectionConfig_GetJson(connConfig));
    _rtaFramework_ExecuteOpenConnection(data->framework, openConnection);
    rtaCommandOpenConnection_Release(&openConnection);

    rtaFramework_NonThreadedStepCount(data->framework, 10);

    data->connection = rtaConnectionTable_GetByApiFd(data->framework->connectionTable, data->api_fds[PAIR_OTHER]);

    // cleanup

    ccnxConnectionConfig_Destroy(&connConfig);
    ccnxStackConfig_Release(&stackConfig);

    return data;
}
LONGBOW_TEST_CASE(Global, ccnxStackConfig_CreateAcquireRelease)
{
    CCNxStackConfig *config = ccnxStackConfig_Create();
    assertNotNull(config, "Expected non-NULL result from ccnxConnectionConfig_Create.");

    CCNxStackConfig *reference = ccnxStackConfig_Acquire(config);

    ccnxStackConfig_Release(&config);
    assertNull(config, "Expected NULL result from ccnxConnectionConfig_Destroy");
    ccnxStackConfig_Release(&reference);
}
LONGBOW_TEST_CASE(Global, ccnxStackConfig_AddGet)
{
    CCNxStackConfig *instance = ccnxStackConfig_Create();

    PARCJSONValue *expected = parcJSONValue_CreateFromNULL();
    ccnxStackConfig_Add(instance, "key", expected);

    PARCJSONValue *actual = ccnxStackConfig_Get(instance, "key");

    assertTrue(parcJSONValue_Equals(expected, actual), "ccnxStackConfig_Get did not return what was 'added'");

    parcJSONValue_Release(&expected);

    ccnxStackConfig_Release(&instance);
}
LONGBOW_TEST_CASE(Global, ccnxStackConfig_Get)
{
    CCNxStackConfig *instance = ccnxStackConfig_Create();

    ccnxStackConfig_Release(&instance);
}