Example #1
0
MetisCommandLineInterface *
metisCommandLineInterface_Create(MetisForwarder *metis, uint16_t port)
{
    MetisCommandLineInterface *cli = parcMemory_AllocateAndClear(sizeof(MetisCommandLineInterface));
    assertNotNull(cli, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(MetisCommandLineInterface));
    cli->port = port;
    cli->listener = NULL;
    cli->metis = metis;
    cli->openSessions = parcArrayList_Create(_session_VoidDestroyer);

    return cli;
}
Example #2
0
int
athenaTransportLinkModule_Poll(AthenaTransportLinkModule *athenaTransportLinkModule, int timeout)
{
    athenaTransportLinkModule->stats.module_Poll++;
    int events = 0;
    for (int index = 0; index < parcArrayList_Size(athenaTransportLinkModule->instanceList); index++) {
        AthenaTransportLink *transportLink = parcArrayList_Get(athenaTransportLinkModule->instanceList, index);
        assertNotNull(transportLink, "Unexpected Null entry in module instance list");
        events += athenaTransportLinkModule->pollMethod(transportLink, timeout);
    }
    return events;
}
Example #3
0
int
ccnServe(const PARCIdentity *identity, const CCNxName *listenName, const char *commandString)
{
    parcSecurity_Init();

    CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity);

    CCNxPortal *portal = ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message);
    assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");

    if (ccnxPortal_Listen(portal, listenName, 365 * 86400, CCNxStackTimeout_Never)) {
        while (true) {
            CCNxMetaMessage *request = ccnxPortal_Receive(portal, CCNxStackTimeout_Never);

            if (request == NULL) {
                break;
            }

            CCNxInterest *interest = ccnxMetaMessage_GetInterest(request);

            if (interest != NULL) {
                CCNxName *interestName = ccnxInterest_GetName(interest);

                PARCBuffer *payload = makePayload(interestName, commandString);

                CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(interestName, payload);

                CCNxMetaMessage *message = ccnxMetaMessage_CreateFromContentObject(contentObject);
                if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never) == false) {
                    fprintf(stderr, "ccnxPortal_Write failed: %d\n", ccnxPortal_GetError(portal));
                }
                {
                    char *name = ccnxName_ToString(interestName);
                    time_t theTime = time(0);
                    char *time = ctime(&theTime);
                    printf("%24.24s  %s\n", time, name);
                    parcMemory_Deallocate((void **) &name);
                }

                parcBuffer_Release(&payload);
            }
            ccnxMetaMessage_Release(&request);
        }
    }

    ccnxPortal_Release(&portal);

    ccnxPortalFactory_Release(&factory);

    parcSecurity_Fini();

    return 0;
}
Example #4
0
PARCEventSignal *
parcEventSignal_Create(PARCEventScheduler *eventScheduler, int signal, PARCEventType flags, PARCEvent_Callback *callback, void *callbackArgs)
{
    PARCEventSignal *parcEventSignal = parcMemory_Allocate(sizeof(PARCEventSignal));
    assertNotNull(parcEventSignal, "parcMemory_Allocate(%zu) returned NULL", sizeof(PARCEventSignal));

    parcEventSignal->eventScheduler = eventScheduler;
    parcEventSignal->callback = callback;
    parcEventSignal->callbackUserData = callbackArgs;

    parcEventSignal->event = event_new(parcEventScheduler_GetEvBase(eventScheduler), signal,
                                       internal_PARCEventType_to_libevent_type(flags),
                                       _parc_event_signal_callback, parcEventSignal);
    assertNotNull(parcEventSignal->event, "Could not create a new event!");

    parcEventSignal_LogDebug(parcEventSignal,
                             "parcEventSignal_Create(base=%p,signal=%x,flags=%x,cb=%p,args=%p) = %p\n",
                             parcEventScheduler_GetEvBase(eventScheduler), signal, flags,
                             callback, callbackArgs, parcEventSignal);
    return parcEventSignal;
}
uint64_t
controlPlaneInterface_GetSequenceNumber(const PARCJSON *controlPlaneMessage)
{
    assertNotNull(controlPlaneMessage, "Invalid state, got NULL json from control message");

    PARCJSONValue *value = parcJSON_GetValueByName(controlPlaneMessage, cpiRequest);
    if (value == NULL) {
        value = parcJSON_GetValueByName(controlPlaneMessage, cpiResponse);
    }
    if (value == NULL) {
        value = parcJSON_GetValueByName(controlPlaneMessage, cpiAck);
    }

    assertNotNull(value, "Could not get request or response");

    PARCJSON *json = parcJSONValue_GetJSON(value);
    value = parcJSON_GetValueByName(json, cpiSeqnum);
    assertNotNull(value, "Could not retrieve key %s from CPI section", cpiSeqnum);

    return parcJSONValue_GetInteger(value);
}
/**
 * Returns the inner operation JSON from the request.
 *
 *   INPUT: "{ CPI_REQUEST: { SEQUENCE:number key: { operation } }}"
 *   OUTPUT: "{ key : { operation } }"
 *
 *   Example return: "{ operation }"
 * @param <#param1#>
 * @return The inner json, do not destroy it
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
PARCJSONPair *
cpi_ParseRequest(PARCJSON *request)
{
    PARCJSONValue *value = parcJSON_GetValueByName(request, cpiRequest);
    assertNotNull(value, "Could not find JSON key %s in %s", cpiRequest, parcJSON_ToString(request));
    assertTrue(parcJSONValue_IsJSON(value), "cpiRequest is unexpected type");

    PARCJSON *requestJson = parcJSONValue_GetJSON(value);
    PARCJSONPair *result = parcJSON_GetPairByIndex(requestJson, 1);

    return result;
}
LONGBOW_TEST_CASE(Global, ccnxMetaMessage_CreateFromInterest)
{
    CCNxName *name = ccnxName_CreateFromCString("lci:/foo/bar");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);

    CCNxMetaMessage *portalMessage = ccnxMetaMessage_CreateFromInterest(interest);
    assertNotNull(portalMessage, "Expected a non-null portal message");
    ccnxMetaMessage_Release(&portalMessage);

    ccnxInterest_Release(&interest);
    ccnxName_Release(&name);
}
Example #8
0
MetisTlvName *
metisTlvName_Slice(const MetisTlvName *original, size_t segmentCount)
{
    assertNotNull(original, "Parameter must be non-null");
    MetisTlvName *copy = parcMemory_AllocateAndClear(sizeof(MetisTlvName));
    assertNotNull(copy, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(MetisTlvName));

    memcpy(copy, original, sizeof(MetisTlvName));
    _incrementRefCount(copy);

    copy->segmentArrayLength = (copy->segmentArrayLength < segmentCount) ? copy->segmentArrayLength : segmentCount;

    // for equality to work, we need to shorten the MemoryLength to the amount
    // actually used by the number of segments.
    size_t startOfLastSegment = copy->segmentArray[ copy->segmentArrayLength - 1 ].offset;
    size_t lengthOfLastSegment = copy->segmentArray[ copy->segmentArrayLength - 1 ].length;

    copy->memoryLength = startOfLastSegment + lengthOfLastSegment;

    return copy;
}
CCNxConnectionConfig *
publicKeySignerPkcs12Store_ConnectionConfig(CCNxConnectionConfig *connConfig, const char *filename, const char *password)
{
    assertNotNull(connConfig, "Parameter connConfig must be non-null");
    assertNotNull(filename, "Parameter filename must be non-null");
    assertNotNull(password, "Parameter password must be non-null");

    PARCJSONValue *signerNameJson = parcJSONValue_CreateFromCString((char *) publicKeySignerPkcs12Store_GetName());
    ccnxConnectionConfig_Add(connConfig, param_SIGNER, signerNameJson);
    parcJSONValue_Release(&signerNameJson);

    PARCJSON *keystoreJson = parcJSON_Create();
    parcJSON_AddString(keystoreJson, param_KEYSTORE_NAME, filename);
    parcJSON_AddString(keystoreJson, param_KEYSTORE_PASSWD, password);

    PARCJSONValue *value = parcJSONValue_CreateFromJSON(keystoreJson);
    parcJSON_Release(&keystoreJson);
    CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connConfig, publicKeySignerPkcs12Store_GetName(), value);
    parcJSONValue_Release(&value);
    return result;
}
Example #10
0
static
void
rbCheckTree(const PARCTreeRedBlack *tree)
{
    assertNotNull(tree, "Tree can't be NULL");
    //printf("--- TREE ---\n");
    _rbNodeAssertTreeInvariants(tree);
    if (tree->size > 0) {
        //_rbNodeRecursiveRun((PARCTreeRedBlack *)tree,tree->root,rbCheckNode,(void *)tree);
        recursiveCheckBlackDepth(tree, tree->root);
    }
}
Example #11
0
LONGBOW_TEST_CASE(Global, longBowMeasureTime_Stop)
{
    LongBowMeasureTime *measure = longBowMeasureTime_Start(1);
    assertNotNull(measure, "Expected longBowMeasureTime_Start to return non-NULL result.");
    sleep(2);
    longBowMeasureTime_Stop(measure);

    uint64_t nanos = longBowMeasureTime_GetNanoseconds(measure);
    assertTrue(nanos >= 1000000000ULL, "Expected more than 1,000,000 ns to have elapsed.");

    longBowMeasureTime_Destroy(&measure);
}
Example #12
0
/*
 * Reading a BPF packet will include the BPF header.  Frame may include the FCS.
 */
bool
metisGenericEther_ReadNextFrame(MetisGenericEther *ether, PARCEventBuffer *readbuffer)
{
    assertNotNull(ether, "Parameter ether must be non-null");
    assertNotNull(readbuffer, "Parameter readbuffer must be non-null");

    bool success = false;

    if (metisLogger_IsLoggable(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug)) {
        metisLogger_Log(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug, __func__,
                        "Workbuffer length %zu", __func__, parcEventBuffer_GetLength(ether->workBuffer));
    }

    // Do we already have something in our work buffer?  If not, try to read something.
    if (parcEventBuffer_GetLength(ether->workBuffer) == 0) {
        _darwinEthernet_ReadSocket(ether);
    }

    success = _darwinEthernet_WorkBufferToReadBuffer(ether, readbuffer);
    return success;
}
Example #13
0
MetisListenerOps *
metisListenerSet_Find(const MetisListenerSet *set, MetisEncapType encapType, const CPIAddress *localAddress)
{
    assertNotNull(set, "Parameter set must be non-null");
    assertNotNull(localAddress, "Parameter localAddress must be non-null");

    MetisListenerOps *match = NULL;

    for (size_t i = 0; i < parcArrayList_Size(set->listOfListeners) && !match; i++) {
        MetisListenerOps *ops = parcArrayList_Get(set->listOfListeners, i);
        assertNotNull(ops, "Got null listener ops at index %zu", i);

        if (ops->getEncapType(ops) == encapType) {
            if (cpiAddress_Equals(localAddress, ops->getListenAddress(ops))) {
                match = ops;
            }
        }
    }

    return match;
}
Example #14
0
LONGBOW_TEST_CASE(Global, parcSigner_GetCryptoHasher)
{
    _MockSigner *mock = _createSigner();
    PARCSigner *signer = parcSigner_Create(mock, _MockSignerInterface);
    _mockSigner_Release(&mock);

    PARCCryptoHasher *hasher = parcSigner_GetCryptoHasher(signer);

    assertNotNull(hasher, "Expected non-NULL PARCCryptoHasher");

    parcSigner_Release(&signer);
}
Example #15
0
LONGBOW_TEST_CASE(Global, parcBufferComposer_Allocate)
{
    size_t size = 10;
    PARCBufferComposer *composer = parcBufferComposer_Allocate(size);
    PARCBuffer *buffer = parcBufferComposer_GetBuffer(composer);

    assertNotNull(composer, "PARCBufferComposer instance should be non-NULL.");
    assertTrue(parcBuffer_Limit(buffer) == size,
               "PARCBufferComposer instance's internal PARCBuffer limit must be %zu: %zu", size, parcBuffer_Limit(buffer));

    parcBufferComposer_Release(&composer);
}
Example #16
0
LONGBOW_TEST_CASE(Global, parcBufferComposer_Acquire)
{
    PARCBufferComposer *composer = parcBufferComposer_Create();

    PARCBufferComposer *handle = parcBufferComposer_Acquire(composer);

    assertNotNull(handle, "Acquired PARCBufferComposer handle should be non-NULL.");
    assertTrue(parcBufferComposer_Equals(composer, handle), "PARCBufferComposer instances should be equal");

    parcBufferComposer_Release(&handle);
    parcBufferComposer_Release(&composer);
}
Example #17
0
bool
metisGenericEther_SendFrame(MetisGenericEther *ether, PARCEventBuffer *buffer)
{
    assertNotNull(ether, "Parameter ether must be non-null");

    size_t length = parcEventBuffer_GetLength(buffer);
    int written = parcEventBuffer_WriteToFileDescriptor(buffer, ether->etherSocket, -1);
    if (written == length) {
        return true;
    }
    return false;
}
Example #18
0
void testConstruct()
{
	try
	{
		testInt = new JSONInt(5);
	}
	catch (std::bad_alloc &badAlloc)
	{
		fail(badAlloc.what());
	}
	assertNotNull(testInt);
}
Example #19
0
PARCEvent *
metisDispatcher_CreateNetworkEvent(MetisDispatcher *dispatcher, bool isPersistent, PARCEvent_Callback *callback, void *userData, int fd)
{
    short flags = PARCEventType_Timeout | PARCEventType_Read;
    if (isPersistent) {
        flags |= PARCEventType_Persist;
    }

    PARCEvent *event = parcEvent_Create(dispatcher->Base, fd, flags, callback, userData);
    assertNotNull(event, "Got null from parcEvent_Create for socket %d", fd);
    return event;
}
Example #20
0
MetisIoOperations *
metisStreamConnection_AcceptConnection(MetisForwarder *metis, int fd, MetisAddressPair *pair, bool isLocal)
{
    _MetisStreamState *stream = parcMemory_AllocateAndClear(sizeof(_MetisStreamState));
    assertNotNull(stream, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(_MetisStreamState));

    MetisDispatcher *dispatcher = metisForwarder_GetDispatcher(metis);
    PARCEventScheduler *eventBase = metisDispatcher_GetEventScheduler(dispatcher);
    stream->bufferEventVector = parcEventQueue_Create(eventBase, fd, PARCEventQueueOption_CloseOnFree | PARCEventQueueOption_DeferCallbacks);

    stream->metis = metis;
    stream->logger = metisLogger_Acquire(metisForwarder_GetLogger(metis));
    stream->fd = fd;
    stream->id = metisForwarder_GetNextConnectionId(metis);
    stream->addressPair = pair;
    stream->isClosed = false;

    // allocate a connection
    MetisIoOperations *io_ops = parcMemory_AllocateAndClear(sizeof(MetisIoOperations));
    assertNotNull(io_ops, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(MetisIoOperations));
    memcpy(io_ops, &_template, sizeof(MetisIoOperations));
    io_ops->closure = stream;

    parcEventQueue_SetCallbacks(stream->bufferEventVector, _conn_readcb, NULL, _conn_eventcb, (void *) io_ops);
    parcEventQueue_Enable(stream->bufferEventVector, PARCEventType_Read);

    metisMessenger_Send(metisForwarder_GetMessenger(stream->metis), metisMissive_Create(MetisMissiveType_ConnectionCreate, stream->id));

    // As we are acceting a connection, we begin in the UP state
    _setConnectionState(stream, true);

    if (metisLogger_IsLoggable(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug)) {
        char *pair_str = metisAddressPair_ToString(pair);
        metisLogger_Log(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug, __func__,
                        "StreamConnection %p accept for address pair %s", (void *) stream, pair_str);
        free(pair_str);
    }

    return io_ops;
}
Example #21
0
bool
parcObjectTesting_AssertCompareToImpl(int (*compareTo)(const void *a, const void *b),
                                      const void *exemplar,
                                      const void **equivalent,
                                      const void **lesser,
                                      const void **greater)
{
    assertNotNull(exemplar, "Parameter exemplar must not be NULL");
    assertNotNull(equivalent, "Parameter equivalent must not be NULL");
    assertNotNull(lesser, "Parameter less must not be NULL");
    assertNotNull(greater, "Parameter greater must not be NULL");

    assertTrue(compareTo(NULL, NULL) == 0, "Comparison of null values must be 0.");

    assertTrue(compareTo(exemplar, NULL) > 0, "Comparison of a non-null value to a null value must be > 0.");

    assertTrue(compareTo(NULL, exemplar) < 0, "Comparison of null value to a non-null value must be < 0.");

    assertTrue(compareTo(exemplar, exemplar) == 0, "Comparison of a value to itself must == 0");

    for (int i = 0; equivalent[i] != NULL; i++) {
        assertTrue(compareTo(exemplar, equivalent[i]) == 0,
                   "Comparison of the value to equivalent[%d] must == 0", i);
        assertTrue(compareTo(exemplar, equivalent[i]) == -compareTo(equivalent[i], exemplar),
                   "Requires sgn(compareTo(value, equivalent[%d])) == -sgn(equivalent[%d], value)", i, i);
    }
    for (int i = 0; lesser[i] != NULL; i++) {
        assertTrue(compareTo(exemplar, lesser[i]) > 0,
                   "Compare of value to lesser[%d] must be > 0", i);
        assertTrue(compareTo(exemplar, lesser[i]) == -compareTo(lesser[i], exemplar),
                   "Requires signum(compareTo(value, lesser[%d])) == -signum(lesser[%d], value)", i, i);
    }
    for (int i = 0; greater[i] != NULL; i++) {
        assertTrue(compareTo(exemplar, greater[i]) < 0, "Compare to greater[%d] must be > 0", i);
        assertTrue(compareTo(exemplar, greater[i]) == -compareTo(greater[i], exemplar),
                   "Requires compareTo(value, greater[%d]) == -compareTo(greater[%d], value)", i, i);
    }

    return true;
}
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);
}
Example #23
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);
}
Example #24
0
MetisGenericEther *
metisGenericEther_Create(MetisForwarder *metis, const char *deviceName, uint16_t etherType)
{
    assertNotNull(metis, "Parameter metis must be non-null");

    // The Darwin generic ether allows a NULL device name, it is used in the unit tests.

    MetisGenericEther *ether = NULL;

    if (metisEthernet_IsValidEthertype(etherType)) {
        ether = parcObject_CreateInstance(MetisGenericEther);
        ether->ethertype = etherType;
        ether->logger = metisLogger_Acquire(metisForwarder_GetLogger(metis));
        ether->etherSocket = -1; // invalid valid
        ether->workBuffer = parcEventBuffer_Create();
        ether->macAddress = NULL;
        ether->mtu = metisSystem_InterfaceMtu(metis, deviceName);

        _darwinEthernet_SetInterfaceAddress(ether, deviceName);

        bool success = _darwinEthernet_SetupReceive(ether, deviceName);

        if (success) {
            if (metisLogger_IsLoggable(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Info)) {
                char *str = parcBuffer_ToHexString(ether->macAddress);
                metisLogger_Log(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Info, __func__,
                                "GenericEther %p created on device %s (%s) for ethertype 0x%04x fd %d bufferLength %u mtu %u",
                                (void *) ether, deviceName, str, etherType, ether->etherSocket, ether->etherBufferLength, ether->mtu);
                parcMemory_Deallocate((void **) &str);
            }
        } else {
            if (metisLogger_IsLoggable(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Error)) {
                metisLogger_Log(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Error, __func__,
                                "GenericEther failed to created on device %s for ethertype 0x%04x",
                                deviceName, etherType);
            }

            // this will also null ether
            metisGenericEther_Release(&ether);
        }

        assertTrue(ether->etherBufferLength < 65536, "Buffer length way too big, expected less than 65536 got %u", ether->etherBufferLength);
    } else {
        if (metisLogger_IsLoggable(metisForwarder_GetLogger(metis), MetisLoggerFacility_IO, PARCLogLevel_Error)) {
            metisLogger_Log(metisForwarder_GetLogger(metis), MetisLoggerFacility_IO, PARCLogLevel_Error, __func__,
                            "GenericEther failed to created on device %s for ethertype 0x%04x, invalid ethertype",
                            deviceName, etherType);
        }
    }

    return ether;
}
LONGBOW_TEST_CASE(Global, athenaTransportLinkAdapter_OpenPollClose)
{
    PARCURI *connectionURI;
    const char *result;
    AthenaTransportLinkAdapter *athenaTransportLinkAdapter = athenaTransportLinkAdapter_Create(_removeLink, NULL);
    assertNotNull(athenaTransportLinkAdapter, "athenaTransportLinkAdapter_Create returned NULL");

    _LoadModule(athenaTransportLinkAdapter, "TCP");

    result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, NULL);
    assertTrue(result == NULL, "athenaTransportLinkAdapter_Open succeeded for NULL URI");

    connectionURI = parcURI_Parse("unknown://127.0.0.1:50200/name=TCP_0");
    result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI);
    assertTrue(result == NULL, "athenaTransportLinkAdapter_Open succeeded for Unknown module");
    parcURI_Release(&connectionURI);

    connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/nam=");
    result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI);
    assertTrue(result == NULL, "athenaTransportLinkAdapter_Open succeeded for module with bad argument");
    parcURI_Release(&connectionURI);

    connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/listener/name=TCPListener");
    result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI);
    assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno));
    parcURI_Release(&connectionURI);

    connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/listener/name=TCPListener");
    result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI);
    assertTrue(result == NULL, "athenaTransportLinkAdapter_Open succeeded for duplicate listener name");
    parcURI_Release(&connectionURI);

    connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/name=TCP_0");
    result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI);
    assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno));
    parcURI_Release(&connectionURI);

    connectionURI = parcURI_Parse("tcp://127.0.0.1:50200/name=TCP_0");
    result = athenaTransportLinkAdapter_Open(athenaTransportLinkAdapter, connectionURI);
    assertTrue(result == NULL, "athenaTransportLinkAdapter_Open succeeded for duplicate link name");
    parcURI_Release(&connectionURI);

    athenaTransportLinkAdapter_Poll(athenaTransportLinkAdapter, 0);

    int closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "TCP_0");
    assertTrue(closeResult == 0, "athenaTransportLinkAdapter_CloseByName failed (%s)", strerror(errno));

    closeResult = athenaTransportLinkAdapter_CloseByName(athenaTransportLinkAdapter, "TCP_999");
    assertTrue(closeResult == -1, "athenaTransportLinkAdapter_CloseByName succeeded for unknown link TCP_999");

    athenaTransportLinkAdapter_Destroy(&athenaTransportLinkAdapter);
}
Example #26
0
LONGBOW_TEST_CASE(Global, parcSigner_CreateKeyId)
{
    _MockSigner *mock = _createSigner();
    PARCSigner *signer = parcSigner_Create(mock, _MockSignerInterface);
    _mockSigner_Release(&mock);

    PARCKeyId *keyId = parcSigner_CreateKeyId(signer);

    assertNotNull(keyId, "Expected non-NULL PARCKeyId");

    parcKeyId_Release(&keyId);
    parcSigner_Release(&signer);
}
Example #27
0
LONGBOW_TEST_CASE(Global, parcSigner_AcquireRelease)
{
    _MockSigner *mock = _createSigner();
    PARCSigner *signer = parcSigner_Create(mock, _MockSignerInterface);
    _mockSigner_Release(&mock);

    assertNotNull(signer, "Expected non-null signer");

    parcObjectTesting_AssertAcquireReleaseContract(parcSigner_Acquire, signer);

    parcSigner_Release(&signer);
    assertNull(signer, "Expected null result from parcSigner_Release();");
}
Example #28
0
/**
 * Creates a client-specific session
 *
 *   <#Discussion#>
 *
 * @param <#param1#>
 * @return <#return#>
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
static _MetisCommandLineInterface_Session *
metisCliSession_Create(MetisCommandLineInterface *cli, MetisSocketType clientSocket, struct sockaddr *clientAddress, int clientAddressLength)
{
    _MetisCommandLineInterface_Session *session = parcMemory_AllocateAndClear(sizeof(_MetisCommandLineInterface_Session));
    assertNotNull(session, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(_MetisCommandLineInterface_Session));
    session->parentCli = cli;
    session->clientAddress = parcMemory_Allocate(clientAddressLength);
    assertNotNull(session->clientAddress, "parcMemory_Allocate(%d) returned NULL", clientAddressLength);
    session->clientAddressLength = clientAddressLength;
    session->clientSocket = clientSocket;

    memcpy(session->clientAddress, clientAddress, clientAddressLength);

    MetisDispatcher *dispatcher = metisForwarder_GetDispatcher(cli->metis);
    PARCEventScheduler *eventBase = metisDispatcher_GetEventScheduler(dispatcher);
    session->streamBuffer = parcEventQueue_Create(eventBase, clientSocket, PARCEventQueueOption_CloseOnFree | PARCEventQueueOption_DeferCallbacks);

    parcEventQueue_SetCallbacks(session->streamBuffer, _metisCliSession_ReadCallback, NULL, _metisCliSession_EventCallback, session);
    parcEventQueue_Enable(session->streamBuffer, PARCEventType_Read);

    return session;
}
LONGBOW_TEST_CASE(Object, parcRandomAccessFile_ToString)
{
    PARCFile *file = parcFile_Create("/tmp/tmpfile");
    PARCRandomAccessFile *instance = parcRandomAccessFile_Open(file);
    parcFile_Release(&file);

    char *string = parcRandomAccessFile_ToString(instance);

    assertNotNull(string, "Expected non-NULL result from parcRandomAccessFile_ToString");

    parcMemory_Deallocate((void **) &string);
    parcRandomAccessFile_Release(&instance);
}
LONGBOW_TEST_CASE(CreateAcquireRelease, CreateRelease)
{
    PARCFile *file = parcFile_Create("/tmp/tmpfile");
    PARCRandomAccessFile *instance = parcRandomAccessFile_Open(file);
    assertNotNull(instance, "Expected non-null result from parcRandomAccessFile_Open();");

    parcObjectTesting_AssertAcquireReleaseContract(parcRandomAccessFile_Acquire, instance);

    parcRandomAccessFile_Release(&instance);
    assertNull(instance, "Expected null result from parcRandomAccessFile_Release();");

    parcFile_Release(&file);
}