diff options
author | Michele Papalini <micpapal+fdio@cisco.com> | 2017-02-24 08:00:13 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@fd.io> | 2017-02-24 08:00:13 +0000 |
commit | 6d4b6878ceff22f9ec8d8e9423214f9666007472 (patch) | |
tree | fa27e0c747676519cb87ff8448bfed62fce5009d /libccnx-transport-rta/ccnx/api/control/cpi_Forwarding.c | |
parent | f28308bd99381ef5f1e178e2e1f870f245e35873 (diff) | |
parent | d18ae43123fcd7604d1c36a1ec8450dbe6071824 (diff) |
Merge "Initial commit: ccnxlibs." into ccnxlibs/master
Diffstat (limited to 'libccnx-transport-rta/ccnx/api/control/cpi_Forwarding.c')
-rw-r--r-- | libccnx-transport-rta/ccnx/api/control/cpi_Forwarding.c | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/libccnx-transport-rta/ccnx/api/control/cpi_Forwarding.c b/libccnx-transport-rta/ccnx/api/control/cpi_Forwarding.c new file mode 100644 index 00000000..3cd836d2 --- /dev/null +++ b/libccnx-transport-rta/ccnx/api/control/cpi_Forwarding.c @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <config.h> +#include <stdio.h> + +#include <ccnx/api/control/controlPlaneInterface.h> +#include <ccnx/api/control/cpi_Forwarding.h> +#include <LongBow/runtime.h> + +#include "cpi_private.h" + +static const char *cpiRegister = "REGISTER"; +static const char *cpiUnregister = "UNREGISTER"; +static const char *cpiRouteList = "ROUTE_LIST"; +static const char *cpiSetStrategy = "SET_STRATEGY"; + +PARCJSON * +cpiForwarding_CreateSetStrategyRequest(CPIForwardingStrategy *fwdStrategy) +{ + PARCJSON *json = cpiForwardingStrategy_ToJson(fwdStrategy); + PARCJSON *result = cpi_CreateRequest(cpiSetStrategy, json); + parcJSON_Release(&json); + + return result; +} + +PARCJSON * +cpiForwarding_CreateAddRouteRequest(const CPIRouteEntry *route) +{ + PARCJSON *routeAsJSON = cpiRouteEntry_ToJson(route); + PARCJSON *result = cpi_CreateRequest(cpiRegister, routeAsJSON); + parcJSON_Release(&routeAsJSON); + + return result; +} + +PARCJSON * +cpiForwarding_CreateRemoveRouteRequest(const CPIRouteEntry *route) +{ + PARCJSON *routeAsJSON = cpiRouteEntry_ToJson(route); + PARCJSON *result = cpi_CreateRequest(cpiUnregister, routeAsJSON); + parcJSON_Release(&routeAsJSON); + + return result; +} + +PARCJSON * +cpiForwarding_AddRouteToSelf(const CCNxName *prefix) +{ + CPIRouteEntry *route = cpiRouteEntry_CreateRouteToSelf(prefix); + PARCJSON *result = cpiForwarding_AddRoute(route); + cpiRouteEntry_Destroy(&route); + return result; +} + +PARCJSON * +cpiForwarding_RemoveRouteToSelf(const CCNxName *prefix) +{ + CPIRouteEntry *route = cpiRouteEntry_CreateRouteToSelf(prefix); + PARCJSON *result = cpiForwarding_RemoveRoute(route); + cpiRouteEntry_Destroy(&route); + return result; +} + +PARCJSON * +cpiForwarding_AddRoute(const CPIRouteEntry *route) +{ + PARCJSON *operation = cpiRouteEntry_ToJson(route); + PARCJSON *result = cpi_CreateRequest(cpiRegister, operation); + parcJSON_Release(&operation); + + return result; +} + +PARCJSON * +cpiForwarding_RemoveRoute(const CPIRouteEntry *route) +{ + PARCJSON *operation = cpiRouteEntry_ToJson(route); + PARCJSON *result = cpi_CreateRequest(cpiUnregister, operation); + parcJSON_Release(&operation); + + return result; +} + +CPIRouteEntry * +cpiForwarding_RouteFromControlMessage(CCNxControl *control) +{ + assertNotNull(control, "Parameter control must be non-null"); + PARCJSON *json = ccnxControl_GetJson(control); + + PARCJSONPair *routeOpPair = cpi_ParseRequest(json); + PARCJSON *routeJson = parcJSONValue_GetJSON(parcJSONPair_GetValue(routeOpPair)); + + CPIRouteEntry *route = cpiRouteEntry_FromJson(routeJson); + + return route; +} + +CPIForwardingStrategy * +cpiForwarding_ForwardingStrategyFromControlMessage(CCNxControl *control) +{ + assertNotNull(control, "Parameter control must be non-null"); + PARCJSON *json = ccnxControl_GetJson(control); + + PARCJSONPair *fwdStrOpPair = cpi_ParseRequest(json); + PARCJSON *fwdStrategyJson = parcJSONValue_GetJSON(parcJSONPair_GetValue(fwdStrOpPair)); + CPIForwardingStrategy *fwdStrategy = cpiForwardingStrategy_FromJson(fwdStrategyJson); + + return fwdStrategy; +} + +const char * +cpiForwarding_AddRouteJsonTag() +{ + return cpiRegister; +} + +const char * +cpiForwarding_RemoveRouteJsonTag() +{ + return cpiUnregister; +} + +const char * +cpiForwarding_RouteListJsonTag() +{ + return cpiRouteList; +} + +const char * +cpiForwarding_SetStrategyJsonTag() +{ + return cpiSetStrategy; +} + + +PARCJSON * +cpiForwarding_CreateRouteListRequest() +{ + PARCJSON *json = parcJSON_Create(); + PARCJSON *result = cpi_CreateRequest(cpiRouteList, json); + parcJSON_Release(&json); + + return result; +} + +CPIRouteEntryList * +cpiForwarding_RouteListFromControlMessage(CCNxControl *control) +{ + PARCJSON *json = ccnxControl_GetJson(control); + PARCJSONValue *value = parcJSON_GetValueByName(json, cpiRequest_GetJsonTag()); + if (value == NULL) { + value = parcJSON_GetValueByName(json, cpiResponse_GetJsonTag()); + } + PARCJSON *innerJson = parcJSONValue_GetJSON(value); + + value = parcJSON_GetValueByName(innerJson, cpiRouteList); + PARCJSON *operation = parcJSONValue_GetJSON(value); + return cpiRouteEntryList_FromJson(operation); +} |