CCNxControl *
cpi_CreateResponse(CCNxControl *request, PARCJSON *operation)
{
    PARCJSON *requestJson = ccnxControl_GetJson(request);

    // use the same key as the request
    uint64_t seqnum = controlPlaneInterface_GetSequenceNumber(requestJson);

    PARCJSONValue *value = parcJSON_GetValueByName(requestJson, cpiRequest);
    assertNotNull(value, "Could not get request or response");
    assertTrue(parcJSONValue_IsJSON(value), "cpiRequest should be a JSON object");

    PARCJSON *operationJson = parcJSONValue_GetJSON(value);
    PARCJSONPair *pair = parcJSON_GetPairByIndex(operationJson, 1);
    const PARCBuffer *opKeyBuf = parcJSONPair_GetName(pair);
    const char *opKey = parcBuffer_ToString(opKeyBuf);

    PARCJSON *response = parcJSON_Create();
    parcJSON_AddInteger(response, cpiSeqnum, (int) seqnum);
    parcJSON_AddObject(response, opKey, operation);
    parcMemory_Deallocate(&opKey);

    PARCJSON *responseJson = parcJSON_Create();
    parcJSON_AddObject(responseJson, cpiResponse, response);
    parcJSON_Release(&response);

    CCNxControl *result = ccnxControl_CreateCPIRequest(responseJson);

    parcJSON_Release(&responseJson);

    return result;
}
CCNxControl *
ccnxControl_CreateCancelFlowRequest(const CCNxName *name)
{
    PARCJSON *request = cpiCancelFlow_CreateRequest(name);
    CCNxControl *result = ccnxControl_CreateCPIRequest(request);
    parcJSON_Release(&request);
    return result;
}
CCNxControl *
ccnxControl_CreateIPTunnelRequest(const CPIInterfaceIPTunnel *tunnel)
{
    PARCJSON *request = cpiLinks_CreateIPTunnel(tunnel);
    CCNxControl *result = ccnxControl_CreateCPIRequest(request);
    parcJSON_Release(&request);
    return result;
}
CCNxControl *
ccnxControl_CreateFlushRequest(void)
{
    PARCJSON *cpiRequest = cpi_CreateFlushRequest();
    CCNxControl *result = ccnxControl_CreateCPIRequest(cpiRequest);
    parcJSON_Release(&cpiRequest);
    return result;
}
CCNxControl *
ccnxControl_CreatePauseInputRequest()
{
    PARCJSON *cpiRequest = cpi_CreatePauseInputRequest();
    CCNxControl *result = ccnxControl_CreateCPIRequest(cpiRequest);
    parcJSON_Release(&cpiRequest);
    return result;
}
CCNxControl *
ccnxControl_CreateInterfaceListRequest()
{
    PARCJSON *cpiRequest = cpiLinks_CreateInterfaceListRequest();
    CCNxControl *result = ccnxControl_CreateCPIRequest(cpiRequest);
    parcJSON_Release(&cpiRequest);
    return result;
}
CCNxControl *
ccnxControl_CreateRouteListRequest()
{
    PARCJSON *cpiRequest = cpiForwarding_CreateRouteListRequest();
    CCNxControl *result = ccnxControl_CreateCPIRequest(cpiRequest);
    parcJSON_Release(&cpiRequest);
    return result;
}
CCNxControl *
ccnxControl_CreateRemoveRouteRequest(const CPIRouteEntry *route)
{
    PARCJSON *cpiRequest = cpiForwarding_CreateRemoveRouteRequest(route);
    CCNxControl *result = ccnxControl_CreateCPIRequest(cpiRequest);
    parcJSON_Release(&cpiRequest);
    return result;
}
Beispiel #9
0
static CCNxControl *
_createAck(MetisConfiguration *config, CCNxControl *control, unsigned ingressId)
{
    PARCJSON *json = ccnxControl_GetJson(control);
    PARCJSON *jsonAck = cpiAcks_CreateAck(json);

    CCNxControl *response = ccnxControl_CreateCPIRequest(jsonAck);
    parcJSON_Release(&jsonAck);
    return response;
}
LONGBOW_TEST_CASE(Global, cpiCancelFlow_NameFromControlMessage)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/who/doesnt/like/pie");
    PARCJSON *cpiRequest = cpiCancelFlow_CreateRequest(name);
    CCNxControl *controlRequest = ccnxControl_CreateCPIRequest(cpiRequest);

    CCNxName *test_name = cpiCancelFlow_NameFromControlMessage(controlRequest);
    assertTrue(ccnxName_Equals(test_name, name),
               "Expected %s actual %s",
               ccnxName_ToString(name),
               ccnxName_ToString(test_name));

    ccnxName_Release(&test_name);
    ccnxControl_Release(&controlRequest);
    parcJSON_Release(&cpiRequest);
    ccnxName_Release(&name);
}
LONGBOW_TEST_CASE(Global, cpiCancelFlow_CreateRequest)
{
    const char truth_format[] = "{\"CPI_REQUEST\":{\"SEQUENCE\":%" PRIu64 ",\"CPI_CANCEL_FLOW\":{\"FLOW_NAME\":\"lci:/who/doesnt/like/pie\"}}}";

    CCNxName *name = ccnxName_CreateFromURI("lci:/who/doesnt/like/pie");
    PARCJSON *cpiRequest = cpiCancelFlow_CreateRequest(name);
    CCNxControl *controlRequest = ccnxControl_CreateCPIRequest(cpiRequest);

    PARCJSON *json = ccnxControl_GetJson(controlRequest);

    char buffer[1024];
    sprintf(buffer, truth_format, cpi_GetSequenceNumber(controlRequest));

    char *test_string = parcJSON_ToCompactString(json);
    assertTrue(strcmp(buffer, test_string) == 0, "Incorrect JSON, expected '%s' got '%s'", buffer, test_string);
    parcMemory_Deallocate((void **) &test_string);

    ccnxControl_Release(&controlRequest);
    parcJSON_Release(&cpiRequest);
    ccnxName_Release(&name);
}