diff options
Diffstat (limited to 'libccnx-transport-rta/ccnx/transport/transport_rta/config')
38 files changed, 3751 insertions, 0 deletions
diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_All.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_All.h new file mode 100644 index 00000000..54d068fe --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_All.h @@ -0,0 +1,45 @@ +/* + * 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. + */ + + +/** + * This is a convenience header for an API that wishes to import all the standard + * component configuration headers. + */ + +#ifndef Libccnx_config_all_h +#define Libccnx_config_all_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> + +#include <ccnx/transport/transport_rta/config/config_ApiConnector.h> + +#include <ccnx/transport/transport_rta/config/config_Codec_Tlv.h> +#include <ccnx/transport/transport_rta/config/config_CryptoCache.h> + +#include <ccnx/transport/transport_rta/config/config_FlowControl_Vegas.h> +#include <ccnx/transport/transport_rta/config/config_Forwarder_Local.h> +#include <ccnx/transport/transport_rta/config/config_Forwarder_Metis.h> + +#include <ccnx/transport/transport_rta/config/config_InMemoryVerifier.h> + +#include <ccnx/transport/transport_rta/config/config_ProtocolStack.h> +#include <ccnx/transport/transport_rta/config/config_PublicKeySigner.h> + +#include <ccnx/transport/transport_rta/config/config_Signer.h> +#include <ccnx/transport/transport_rta/config/config_SymmetricKeySigner.h> + +#include <ccnx/transport/transport_rta/config/config_TestingComponent.h> +#endif diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ApiConnector.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ApiConnector.c new file mode 100644 index 00000000..6af665bb --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ApiConnector.c @@ -0,0 +1,52 @@ +/* + * 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 "config_ApiConnector.h" + +#include <ccnx/transport/transport_rta/core/components.h> + +/** + * Generates: + * + * { "API_CONNECTOR" : { } } + */ +CCNxStackConfig * +apiConnector_ProtocolStackConfig(CCNxStackConfig *stackConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxStackConfig *result = ccnxStackConfig_Add(stackConfig, apiConnector_GetName(), value); + parcJSONValue_Release(&value); + + return result; +} + +CCNxConnectionConfig * +apiConnector_ConnectionConfig(CCNxConnectionConfig *connectionConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connectionConfig, apiConnector_GetName(), value); + parcJSONValue_Release(&value); + + return result; +} + +const char * +apiConnector_GetName(void) +{ + return RtaComponentNames[API_CONNECTOR]; +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ApiConnector.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ApiConnector.h new file mode 100644 index 00000000..7e0867ad --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ApiConnector.h @@ -0,0 +1,89 @@ +/* + * 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. + */ + +/** + * @file config_ApiConnector.h + * @brief Generates stack and connection configuration information + * + * Each component in the protocol stack must have a configuration element. + * This module generates the configuration elements for the API Connector. + * + * @code + * { + * // Configure a stack with {APIConnector,TLVCodec,MetisConnector} + * + * CCNxStackConfig *stackConfig = ccnxStackConfig_Create(); + * CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + * + * apiConnector_ProtocolStackConfig(stackConfig); + * apiConnector_ConnectionConfig(connConfig); + * tlvCodec_ProtocolStackConfig(stackConfig); + * tlvCodec_ConnectionConfig(connConfig); + * metisForwarder_ProtocolStackConfig(stackConfig); + * metisForwarder_ConnectionConfig(connConfig, metisForwarder_GetDefaultPort()); + * + * CCNxTransportConfig *config = ccnxTransportConfig_Create(stackConfig, connConfig); + * } + * + */ +#ifndef Libccnx_config_ApiConnector_h +#define Libccnx_config_ApiConnector_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> + +/** + * Generates the configuration settings included in the Protocol Stack configuration + * + * Adds configuration elements to the Protocol Stack configuration + * { "API_CONNECTOR" : { } } + * + * @param [in] stackConfig The protocl stack configuration to update + * + * @return non-null The updated protocol stack configuration + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxStackConfig *apiConnector_ProtocolStackConfig(CCNxStackConfig *stackConfig); + +/** + * Generates the configuration settings included in the Connection configuration + * + * Adds configuration elements to the `CCNxConnectionConfig` + * + * @param [in] config A pointer to a valid CCNxConnectionConfig instance. + * + * @return non-null The modified `CCNxConnectionConfig` + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxConnectionConfig *apiConnector_ConnectionConfig(CCNxConnectionConfig *config); + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *apiConnector_GetName(void); +#endif + diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Codec_Ccnb.xc b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Codec_Ccnb.xc new file mode 100644 index 00000000..04820d6e --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Codec_Ccnb.xc @@ -0,0 +1,31 @@ + +#include <config.h> +#include <stdio.h> +#include "config_Codec_Ccnb.h" + +#include "components.h" + +/** + * Generates: + + { "CCNB_CODEC" : { } } + */ +ProtocolStackConfig * +ccnbCodec_ProtocolStackConfig(ProtocolStackConfig *stackConfig) +{ + return protocolStackConfig_Add(stackConfig, ccnbCodec_GetName(), parcJSONValue_CreateNULL());//ccnxJson_CreateObject()); +} + +ConnectionConfig * +ccnbCodec_ConnectionConfig(ConnectionConfig *connectionConfig) +{ + return connectionConfig_Add(connectionConfig, ccnbCodec_GetName(), parcJSONValue_CreateNULL());//ccnxJson_CreateObject()); +} + + +const char * ccnbCodec_GetName() +{ + return RtaComponentNames[CODEC_CCNB]; + +} + diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Codec_Tlv.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Codec_Tlv.c new file mode 100644 index 00000000..b3eeb6a7 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Codec_Tlv.c @@ -0,0 +1,62 @@ +/* + * 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 "config_Codec_Tlv.h" +#include <LongBow/runtime.h> + +#include <ccnx/transport/transport_rta/core/components.h> + +//static const char param_SCHEMA[] = "SCHEMA"; +//static const char param_CODEC[] = "CODEC"; +//static const int default_schema = 0; + +/** + * Generates: + * + * { "CODEC_TLV" : { } } + */ +CCNxStackConfig * +tlvCodec_ProtocolStackConfig(CCNxStackConfig *stackConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxStackConfig *result = ccnxStackConfig_Add(stackConfig, tlvCodec_GetName(), value); + parcJSONValue_Release(&value); + + return result; +} + +/** + * Generates: + * + * { "CODEC_TLV" : { } } + */ + +CCNxConnectionConfig * +tlvCodec_ConnectionConfig(CCNxConnectionConfig *connectionConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connectionConfig, tlvCodec_GetName(), value); + parcJSONValue_Release(&value); + return result; +} + +const char * +tlvCodec_GetName(void) +{ + return RtaComponentNames[CODEC_TLV]; +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Codec_Tlv.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Codec_Tlv.h new file mode 100644 index 00000000..213fc1c2 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Codec_Tlv.h @@ -0,0 +1,92 @@ +/* + * 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. + */ + +/** + * @file config_Codec_Tlv.h + * @brief Generates stack and connection configuration information + * + * Each component in the protocol stack must have a configuration element. + * This module generates the configuration elements for the TLV codec. + * + * @code + * { + * // Configure a stack with {APIConnector,TLVCodec,MetisConnector} + * + * stackConfig = ccnxStackConfig_Create(); + * connConfig = ccnxConnectionConfig_Create(); + * + * apiConnector_ProtocolStackConfig(stackConfig); + * apiConnector_ConnectionConfig(connConfig); + * tlvCodec_ProtocolStackConfig(stackConfig); + * tlvCodec_ConnectionConfig(connConfig); + * metisForwarder_ProtocolStackConfig(stackConfig); + * metisForwarder_ConnectionConfig(connConfig, metisForwarder_GetDefaultPort()); + * + * CCNxTransportConfig *config = ccnxTransportConfig_Create(stackConfig, connConfig); + * } + * + */ + +#ifndef Libccnx_config_Codec_Tlv_h +#define Libccnx_config_Codec_Tlv_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> +#include <ccnx/common/internal/ccnx_TlvDictionary.h> + +/** + * Generates the configuration settings included in the Protocol Stack configuration + * + * Adds configuration elements to the Protocol Stack configuration + * + * { "TLV_CODEC" : { } } + * + * @param [in] stackConfig The protocl stack configuration to update + * + * @return non-null The updated protocol stack configuration + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxStackConfig *tlvCodec_ProtocolStackConfig(CCNxStackConfig *stackConfig); + +/** + * Creates a connection configuration based on CCNxMessages wrapping an CCNxTlvDictionary + * + * Adds configuration elements to the `CCNxConnectionConfig` + * + * @param [in] config A pointer to a valid CCNxConnectionConfig instance. + * + * @return non-null The modified `CCNxConnectionConfig` + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxConnectionConfig *tlvCodec_ConnectionConfig(CCNxConnectionConfig *config); + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *tlvCodec_GetName(void); + +#endif diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_CryptoCache.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_CryptoCache.h new file mode 100644 index 00000000..f707c324 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_CryptoCache.h @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#ifndef Libccnx_config_CryptoCache_h +#define Libccnx_config_CryptoCache_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> + +/** + * Generates: + * + * { "KEYS" : + * [ + * { "KEYID" : base64{ keyhash }, + * "KEY" : base64{ derEncodedKey }, + * "PREFIXES" : [ uripath, uripath, ... uripath ] + * }, + * { "KEYID" : base64{ keyhash }, + * "KEY" : base64{ derEncodedKey }, + * "PREFIXES" : [ uripath, uripath, ... uripath ] + * }, + * ... + * ] + * } + */ +CCNxConnectionConfig *cryptoCache_ConnectionConfig(CCNxConnectionConfig *connConfig, const char *filename, const char *password); + +const char *cryptoCache_GetName(void); +#endif // Libccnx_config_CryptoCache_h diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_FlowControl_Vegas.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_FlowControl_Vegas.c new file mode 100644 index 00000000..9b31d26e --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_FlowControl_Vegas.c @@ -0,0 +1,50 @@ +/* + * 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 "config_FlowControl_Vegas.h" + +#include <ccnx/transport/transport_rta/core/components.h> + +/** + * Generates: + * + * { "FC_VEGAS" : { } } + */ +CCNxStackConfig * +vegasFlowController_ProtocolStackConfig(CCNxStackConfig *stackConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxStackConfig *result = ccnxStackConfig_Add(stackConfig, vegasFlowController_GetName(), value); + parcJSONValue_Release(&value); + return result; +} + +CCNxConnectionConfig * +vegasFlowController_ConnectionConfig(CCNxConnectionConfig *connectionConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connectionConfig, vegasFlowController_GetName(), value); + parcJSONValue_Release(&value); + return result; +} + +const char * +vegasFlowController_GetName(void) +{ + return RtaComponentNames[FC_VEGAS]; +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_FlowControl_Vegas.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_FlowControl_Vegas.h new file mode 100644 index 00000000..28bcd992 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_FlowControl_Vegas.h @@ -0,0 +1,92 @@ +/* + * 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. + */ + +/** + * @file config_FlowControl_Vegas.h + * @brief Generates stack and connection configuration information + * + * Each component in the protocol stack must have a configuration element. + * This module generates the configuration elements for the API Connector. + * + * @code + * { + * // Configure a stack with {APIConnector,Vegas,TLVCodec,MetisConnector} + * + * stackConfig = ccnxStackConfig_Create(); + * connConfig = ccnxConnectionConfig_Create(); + * + * apiConnector_ProtocolStackConfig(stackConfig); + * apiConnector_ConnectionConfig(connConfig); + * vegasFlowController_ProtocolStackConfig(stackConfig); + * vegasFlowController_ConnectionConfig(connConfig); + * tlvCodec_ProtocolStackConfig(stackConfig); + * tlvCodec_ConnectionConfig(connConfig); + * metisForwarder_ProtocolStackConfig(stackConfig); + * metisForwarder_ConnectionConfig(connConfig, metisForwarder_GetDefaultPort()); + * + * CCNxTransportConfig *config = ccnxTransportConfig_Create(stackConfig, connConfig); + * } + * + */ + +#ifndef Libccnx_config_FlowControl_Vegas_h +#define Libccnx_config_FlowControl_Vegas_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> + +/** + * Generates the configuration settings included in the Protocol Stack configuration + * + * Adds configuration elements to the Protocol Stack configuration + * + * { "FC_VEGAS" : { } } + * + * @param [in] stackConfig The protocl stack configuration to update + * + * @return non-null The updated protocol stack configuration + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxStackConfig *vegasFlowController_ProtocolStackConfig(CCNxStackConfig *stackConfig); + +/** + * Generates the configuration settings included in the Connection configuration + * + * Adds configuration elements to the `CCNxConnectionConfig` + * + * @param [in] config The CCNxConnectionConfig instance + * + * @return non-null The modified `CCNxConnectionConfig` + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxConnectionConfig *vegasFlowController_ConnectionConfig(CCNxConnectionConfig *config); + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *vegasFlowController_GetName(void); +#endif // Libccnx_config_FlowControl_Vegas_h diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Local.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Local.c new file mode 100644 index 00000000..d5c94854 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Local.c @@ -0,0 +1,72 @@ +/* + * 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 "config_Forwarder_Local.h" + +#include <ccnx/transport/transport_rta/core/components.h> +#include <LongBow/runtime.h> + +static const char param_FWD_LOCAL_NAME[] = "LOCAL_NAME"; + +CCNxStackConfig * +localForwarder_ProtocolStackConfig(CCNxStackConfig *stackConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxStackConfig *result = ccnxStackConfig_Add(stackConfig, localForwarder_GetName(), value); + parcJSONValue_Release(&value); + return result; +} + +/** + * Generates: + * + * { "FWD_LOCAL" : { "path" : pipePath } } + */ +CCNxConnectionConfig * +localForwarder_ConnectionConfig(CCNxConnectionConfig *connConfig, const char *pipePath) +{ + PARCJSON *json = parcJSON_Create(); + parcJSON_AddString(json, param_FWD_LOCAL_NAME, pipePath); + PARCJSONValue *value = parcJSONValue_CreateFromJSON(json); + parcJSON_Release(&json); + CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connConfig, localForwarder_GetName(), value); + parcJSONValue_Release(&value); + return result; +} + +const char * +localForwarder_GetName() +{ + return RtaComponentNames[FWD_LOCAL]; +} + +const char * +localForwarder_GetPath(PARCJSON *json) +{ + PARCJSONValue *value = parcJSON_GetValueByName(json, localForwarder_GetName()); + assertNotNull(value, "Got null for %s json", localForwarder_GetName()); + PARCJSON *localJson = parcJSONValue_GetJSON(value); + + value = parcJSON_GetValueByName(localJson, param_FWD_LOCAL_NAME); + assertNotNull(value, "Must specify a path for the PF_UNIX pipe for local forwarder"); + assertTrue(parcJSONValue_IsString(value), "JSON key %s must be type STRING", localForwarder_GetName()); + + PARCBuffer *sBuf = parcJSONValue_GetString(value); + const char *path = parcBuffer_Overlay(sBuf, 0); + + return path; +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Local.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Local.h new file mode 100644 index 00000000..6b865aa8 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Local.h @@ -0,0 +1,102 @@ +/* + * 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. + */ + +/** + * @file config_Forwarder_Local.h + * @brief Generates stack and connection configuration information + * + * Each component in the protocol stack must have a configuration element. + * This module generates the configuration elements for the local testing forwarder. + * + * The local forwarder requires one parameter for the path to the unix socket. + * + * @code + * { + * // Configure a stack with {APIConnector,TLVCodec,LocalForwarder} + * + * stackConfig = ccnxStackConfig_Create(); + * connConfig = ccnxConnectionConfig_Create(); + * + * apiConnector_ProtocolStackConfig(stackConfig); + * apiConnector_ConnectionConfig(connConfig); + * tlvCodec_ProtocolStackConfig(stackConfig); + * tlvCodec_ConnectionConfig(connConfig); + * localForwarder_ProtocolStackConfig(stackConfig); + * localForwarder_ConnectionConfig(connConfig, "/var/run/bentpipe.sock"); + * + * CCNxTransportConfig *config = ccnxTransportConfig_Create(stackConfig, connConfig); + * } + * + */ + +#ifndef Libccnx_config_Forwarder_Local_h +#define Libccnx_config_Forwarder_Local_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> + +/** + * Generates the configuration settings included in the Protocol Stack configuration + * + * Adds configuration elements to the Protocol Stack configuration + * + * { "FWD_LOCAL" : { } } + * + * @param [in] stackConfig The protocl stack configuration to update + * + * @return non-null The updated protocol stack configuration + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxStackConfig *localForwarder_ProtocolStackConfig(CCNxStackConfig *stackConfig); + +/** + * Generates: + * + */ + +/** + * Generates the configuration settings included in the Connection configuration + * + * Adds configuration elements to the `CCNxConnectionConfig` + * + * { "FWD_LOCAL" : { "path" : pipePath } } + * + * @param [in] config A pointer to a valid CCNxConnectionConfig instance. + * @param [in] pipePath The filesystem path to the unix domain socket + * + * @return non-null The modified `CCNxConnectionConfig` + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxConnectionConfig *localForwarder_ConnectionConfig(CCNxConnectionConfig *config, const char *pipePath); + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *localForwarder_GetName(void); + +const char *localForwarder_GetPath(PARCJSON *connectionJson); +#endif // Libccnx_config_Forwarder_Local_h diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Metis.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Metis.c new file mode 100644 index 00000000..511f738f --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Metis.c @@ -0,0 +1,81 @@ +/* + * 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 <LongBow/runtime.h> + +#include <stdio.h> +#include "config_Forwarder_Metis.h" +#include <ccnx/transport/transport_rta/core/components.h> + +static const char param_METIS_PORT[] = METIS_PORT_ENV; // integer, e.g. 9695 +static const short default_port = 9695; + +/** + * Generates: + * + * { "FWD_METIS" : { "port" : port } } + */ +CCNxStackConfig * +metisForwarder_ProtocolStackConfig(CCNxStackConfig *stackConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxStackConfig *result = ccnxStackConfig_Add(stackConfig, metisForwarder_GetName(), value); + parcJSONValue_Release(&value); + + return result; +} + +/** + * The metis forwarder port may be set per connection in the stack + * + * { "FWD_METIS" : { "port" : port } } + */ +CCNxConnectionConfig * +metisForwarder_ConnectionConfig(CCNxConnectionConfig *connConfig, uint16_t port) +{ + PARCJSON *json = parcJSON_Create(); + parcJSON_AddInteger(json, param_METIS_PORT, port); + + PARCJSONValue *value = parcJSONValue_CreateFromJSON(json); + parcJSON_Release(&json); + CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connConfig, metisForwarder_GetName(), value); + parcJSONValue_Release(&value); + + return result; +} + +uint16_t +metisForwarder_GetDefaultPort() +{ + return default_port; +} + +const char * +metisForwarder_GetName() +{ + return RtaComponentNames[FWD_METIS]; +} + +uint16_t +metisForwarder_GetPortFromConfig(PARCJSON *json) +{ + PARCJSONValue *value = parcJSON_GetValueByName(json, metisForwarder_GetName()); + assertNotNull(value, "Got null for %s json", metisForwarder_GetName()); + PARCJSON *metisJson = parcJSONValue_GetJSON(value); + + value = parcJSON_GetValueByName(metisJson, param_METIS_PORT); + return (uint16_t) parcJSONValue_GetInteger(value); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Metis.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Metis.h new file mode 100644 index 00000000..78a0669a --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Forwarder_Metis.h @@ -0,0 +1,118 @@ +/* + * 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. + */ + +/** + * @file config_Forwarder_Metis.h + * @brief Generates stack and connection configuration information + * + * Each component in the protocol stack must have a configuration element. + * This module generates the configuration elements for the Metis connector. + * + * The Metis connector requires one parameter to specify the port. + * + * @code + * { + * // Configure a stack with {APIConnector,TLVCodec,MetisConnector} + * + * stackConfig = ccnxStackConfig_Create(); + * connConfig = ccnxConnectionConfig_Create(); + * + * apiConnector_ProtocolStackConfig(stackConfig); + * apiConnector_ConnectionConfig(connConfig); + * tlvCodec_ProtocolStackConfig(stackConfig); + * tlvCodec_ConnectionConfig(connConfig); + * metisForwarder_ProtocolStackConfig(stackConfig); + * metisForwarder_ConnectionConfig(connConfig, metisForwarder_GetDefaultPort()); + * + * CCNxTransportConfig *config = ccnxTransportConfig_Create(stackConfig, connConfig); + * } + * + */ + +#ifndef Libccnx_config_Forwarder_Metis_h +#define Libccnx_config_Forwarder_Metis_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> + +#define METIS_PORT_ENV "METIS_PORT" +#define FORWARDER_CONNECTION_ENV "CCNX_FORWARDER" + +/** + * Generates the configuration settings included in the Protocol Stack configuration + * + * Adds configuration elements to the Protocol Stack configuration + * + * { "FWD_METIS" : { } } + * + * @param [in] stackConfig The protocl stack configuration to update + * + * @return non-null The updated protocol stack configuration + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxStackConfig *metisForwarder_ProtocolStackConfig(CCNxStackConfig *stackConfig); + +/** + * Generates the configuration settings included in the Connection configuration + * + * Adds configuration elements to the `CCNxConnectionConfig` + * + * { "FWD_METIS" : { "port" : port } } + * + * @param [in] config A pointer to a valid CCNxConnectionConfig instance. + * + * @return non-null The modified `CCNxConnectionConfig` + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxConnectionConfig *metisForwarder_ConnectionConfig(CCNxConnectionConfig *config, uint16_t port); + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *metisForwarder_GetName(void); + +/** + * Returns the IANA assigned port for the CCN forwarder + * + * <#Paragraphs Of Explanation#> + * + * @return 9695 The IANA assigned port for CCN + * + * Example: + * @code + * <#example#> + * @endcode + */ +uint16_t metisForwarder_GetDefaultPort(void); + +/** + * Return the metis port ot use (or the default 9695) based on the setting + * in the per-connection configuration + */ +uint16_t metisForwarder_GetPortFromConfig(PARCJSON *json); + +#endif // Libccnx_config_Forwarder_Metis_h diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_InMemoryVerifier.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_InMemoryVerifier.c new file mode 100644 index 00000000..8f76c184 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_InMemoryVerifier.c @@ -0,0 +1,52 @@ +/* + * 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. + */ + +// +// config_InMemoryVerifier.c +// Libccnx +// +// + +#include <config.h> +#include <stdio.h> +#include "config_InMemoryVerifier.h" + +#include <ccnx/transport/transport_rta/core/components.h> + +#include <LongBow/runtime.h> + +static const char name[] = "InMemoryVerifier"; + +/** + * Generates: + * + * { "SIGNER" : "InMemoryVerifier", + * } + */ +CCNxConnectionConfig * +inMemoryVerifier_ConnectionConfig(CCNxConnectionConfig *connConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connConfig, inMemoryVerifier_GetName(), value); + parcJSONValue_Release(&value); + + return result; +} + +const char * +inMemoryVerifier_GetName(void) +{ + return name; +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_InMemoryVerifier.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_InMemoryVerifier.h new file mode 100644 index 00000000..3cd5bd65 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_InMemoryVerifier.h @@ -0,0 +1,81 @@ +/* + * 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. + */ + +/** + * @file config_InMemoryVerifier.h + * @brief Generates stack and connection configuration information + * + * Each component in the protocol stack must have a configuration element. + * This module generates the configuration elements for the InMemoryVerifier. + * + * The InMemoryVerifier sits beside the Codec. The user sends ControlPlaneInformation (CPI) + * messages down to the InMemoryVerifier to configure it with keys. Only those keys specified + * as trusted will verify content objects. + * + * @code + * { + * // Configure a stack with {APIConnector,TLVCodec,MetisConnector} + * + * stackConfig = ccnxStackConfig_Create(); + * connConfig = ccnxConnectionConfig_Create(); + * + * apiConnector_ProtocolStackConfig(stackConfig); + * apiConnector_ConnectionConfig(connConfig); + * tlvCodec_ProtocolStackConfig(stackConfig); + * tlvCodec_ConnectionConfig(connConfig); + * + * inMemoryVerifier_ConnectionConfig(connConfig); + * + * metisForwarder_ProtocolStackConfig(stackConfig); + * metisForwarder_ConnectionConfig(connConfig, metisForwarder_GetDefaultPort()); + * + * CCNxTransportConfig *config = ccnxTransportConfig_Create(stackConfig, connConfig); + * } + * + */ + +#ifndef Libccnx_config_InMemoryVerifier_h +#define Libccnx_config_InMemoryVerifier_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> + +/** + * Generates the configuration settings included in the Connection configuration + * + * Adds configuration elements to the `CCNxConnectionConfig` + * + * { "VERIFIER" : "InMemoryVerifier" } + * + * @param [in] config A pointer to a valid CCNxConnectionConfig instance. + * + * @return non-null The modified `CCNxConnectionConfig` + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxConnectionConfig *inMemoryVerifier_ConnectionConfig(CCNxConnectionConfig *config); + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *inMemoryVerifier_GetName(void); +#endif // Libccnx_config_InMemoryVerifier_h diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ProtocolStack.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ProtocolStack.c new file mode 100644 index 00000000..de52c805 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ProtocolStack.c @@ -0,0 +1,121 @@ +/* + * 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 "config_ProtocolStack.h" + +#include <ccnx/transport/transport_rta/core/components.h> + +#include <LongBow/runtime.h> + +static const char param_STACK[] = "STACK"; +static const char param_COMPONENTS[] = "COMPONENTS"; + +/* + * Call with the names of each component, terminated by a NULL, for example: + * + * <code> + * ccnxStackConfig_AppendComponents(stackConfig, apiConnector_GetName(), vegasFlowController_GetName(), + * tlvCodec_GetName(), localForwarder_GetName(), NULL); + * </code> + * + * Generates: + * + * { "STACK" : { "COMPONENTS" : [ name1, name2, ... ] } + */ +CCNxStackConfig * +protocolStack_ComponentsConfigArgs(CCNxStackConfig *stackConfig, ...) +{ + PARCArrayList *list = parcArrayList_Create(NULL); + + va_list ap; + const char *componentName; + va_start(ap, stackConfig); + + while ((componentName = va_arg(ap, const char *)) != NULL) { + parcArrayList_Add(list, (char *) componentName); + } + + va_end(ap); + + stackConfig = protocolStack_ComponentsConfigArrayList(stackConfig, list); + parcArrayList_Destroy(&list); + + return stackConfig; +} + +/** + * Same as <code>protocolStack_ComponentsConfigArgs</code>, except uses + * an ArrayList of <code>const char *</code> component names. + */ +CCNxStackConfig * +protocolStack_ComponentsConfigArrayList(CCNxStackConfig *stackConfig, const PARCArrayList *listOfComponentNames) +{ + PARCJSON *stackJson = parcJSON_Create(); + PARCJSONArray *arrayJson = parcJSONArray_Create(); + + for (int i = 0; i < parcArrayList_Size(listOfComponentNames); i++) { + char *componentName = parcArrayList_Get(listOfComponentNames, i); + PARCJSONValue *value = parcJSONValue_CreateFromCString(componentName); + parcJSONArray_AddValue(arrayJson, value); + parcJSONValue_Release(&value); + } + + parcJSON_AddArray(stackJson, param_COMPONENTS, arrayJson); + parcJSONArray_Release(&arrayJson); + + PARCJSONValue *value = parcJSONValue_CreateFromJSON(stackJson); + parcJSON_Release(&stackJson); + + CCNxStackConfig *result = ccnxStackConfig_Add(stackConfig, param_STACK, value); + parcJSONValue_Release(&value); + return result; +} + +const char * +protocolStack_GetName(void) +{ + return param_STACK; +} + +/** + * Parse the protocol stack json to extract an array list of the component names + */ +PARCArrayList * +protocolStack_GetComponentNameArray(PARCJSON *protocolStackJson) +{ + // created with NULL destroyer because we're putting in const char * + PARCArrayList *arraylist = parcArrayList_Create_Capacity(NULL, NULL, 16); + + PARCJSONValue *value = parcJSON_GetValueByName(protocolStackJson, param_STACK); + assertNotNull(value, "Cannot have null %s key in json", param_STACK); + PARCJSON *stackJson = parcJSONValue_GetJSON(value); + + value = parcJSON_GetValueByName(stackJson, param_COMPONENTS); + assertNotNull(value, "Cannot have null %s key in json", param_COMPONENTS); + assertTrue(parcJSONValue_IsArray(value), "key %s not type ARRAY", param_COMPONENTS); + PARCJSONArray *componentsJson = parcJSONValue_GetArray(value); + + size_t length = parcJSONArray_GetLength(componentsJson); + + for (size_t i = 0; i < length; i++) { + value = parcJSONArray_GetValue(componentsJson, i); + PARCBuffer *sBuf = parcJSONValue_GetString(value); + parcArrayList_Add(arraylist, parcBuffer_Overlay(sBuf, 0)); + } + return arraylist; +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ProtocolStack.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ProtocolStack.h new file mode 100644 index 00000000..8248f4a3 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_ProtocolStack.h @@ -0,0 +1,114 @@ +/* + * 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. + */ + +/** + * @file config_ProtocolStack.h + * @brief Generates stack and connection configuration information + * + * Each component in the protocol stack must have a configuration element. + * This module generates the configuration elements for the ProtocolStack. + * + * The ProtocolStack configuration is a list of key names for the components + * in the stack. It is an in-order list of the components to configure in the + * stack. + * + * @code + * { + * // Configure a stack with {APIConnector,TLVCodec,MetisConnector} + * + * stackConfig = ccnxStackConfig_Create(); + * connConfig = ccnxConnectionConfig_Create(); + * + * apiConnector_ProtocolStackConfig(stackConfig); + * apiConnector_ConnectionConfig(connConfig); + * tlvCodec_ProtocolStackConfig(stackConfig); + * tlvCodec_ConnectionConfig(connConfig); + * inMemoryVerifier_ConnectionConfig(connConfig); + * metisForwarder_ProtocolStackConfig(stackConfig); + * metisForwarder_ConnectionConfig(connConfig, metisForwarder_GetDefaultPort()); + * + * protocolStack_ComponentsConfigArgs(stackConfig, apiConnector_Name(), tlvCodec_Name(), metisForwarder_Name(), NULL); + * + * CCNxTransportConfig *config = ccnxTransportConfig_Create(stackConfig, connConfig); + * } + * + */ + +#ifndef Libccnx_config_ProtocolStack_h +#define Libccnx_config_ProtocolStack_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> +#include <parc/algol/parc_ArrayList.h> + +/** + * Generates the configuration settings included in the Protocol Stack configuration + * + * Adds configuration elements to the Protocol Stack configuration + * + * { "COMPONENTS" : [ name1, name2, ... ] } + * + * The ProtocolStack function adds a configuration element that enumerates each component + * that will be in the protocol stack, in order. These names must match the names + * used by each component in its own particular configuration. + * + * @param [in] stackConfig The protocl stack configuration to update + * + * @return non-null The updated protocol stack configuration + * + * Example: + * @code + * { + * protocolStack_ComponentsConfigArgs(stackConfig, apiConnector_Name(), tlvCodec_Name(), metisForwarder_Name(), NULL); + * } + * @endcode + */ +CCNxStackConfig *protocolStack_ComponentsConfigArgs(CCNxStackConfig *stackConfig, ...); + +/** + * Generates the configuration settings included in the Protocol Stack configuration + * + * Adds configuration elements to the Protocol Stack configuration + * + * { "COMPONENTS" : [ name1, name2, ... ] } + * + * The ProtocolStack function adds a configuration element that enumerates each component + * that will be in the protocol stack, in order. These names must match the names + * used by each component in its own particular configuration. + * + * @param [in] stackConfig The protocl stack configuration to update + * + * @return non-null The updated protocol stack configuration + * + * Example: + * @code + * @endcode + */ +CCNxStackConfig *protocolStack_ComponentsConfigArrayList(CCNxStackConfig *stackConfig, const PARCArrayList *listOfComponentNames); + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *protocolStack_GetName(void); + +/** + * Parse the protocol stack json to extract an array list of the component names + */ +PARCArrayList *protocolStack_GetComponentNameArray(PARCJSON *stackJson); +#endif // Libccnx_config_ProtocolStack_h diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_PublicKeySigner.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_PublicKeySigner.c new file mode 100644 index 00000000..3114e7b6 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_PublicKeySigner.c @@ -0,0 +1,106 @@ +/* + * 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. + */ + +// +// config_PublicKeySigner.c +// Libccnx +// +// +// +#include <config.h> +#include <LongBow/runtime.h> + +#include <stdio.h> + +#include <parc/security/parc_Identity.h> +#include "config_PublicKeySigner.h" + +#include <ccnx/transport/transport_rta/core/components.h> + +static const char name[] = "publicKeySigner"; + +static const char param_KEYSTORE_NAME[] = "KEYSTORE_NAME"; +static const char param_KEYSTORE_PASSWD[] = "KEYSTORE_PASSWD"; +static const char param_SIGNER[] = "SIGNER"; + +/** + * Generates: + * + * { "SIGNER" : "publicKeySigner", + * "publicKeySigner" : { "filename" : filename, "password" : password } + * } + */ +CCNxConnectionConfig * +configPublicKeySigner_SetIdentity(CCNxConnectionConfig *connConfig, const PARCIdentity *identity) +{ + return publicKeySigner_ConnectionConfig(connConfig, + parcIdentity_GetFileName(identity), + parcIdentity_GetPassWord(identity)); +} + +CCNxConnectionConfig * +publicKeySigner_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 *) publicKeySigner_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, publicKeySigner_GetName(), value); + parcJSONValue_Release(&value); + return result; +} + +const char * +publicKeySigner_GetName() +{ + return name; +} + +/** + * If successful, return true and fill in the parameters in the output argument + */ +bool +publicKeySigner_GetConnectionParams(PARCJSON *connectionJson, struct publickeysigner_params *output) +{ + assertNotNull(connectionJson, "Parameter connectionJson must be non-null"); + assertNotNull(output, "Parameter output must be non-null"); + + PARCJSONValue *value = parcJSON_GetValueByName(connectionJson, publicKeySigner_GetName()); + assertNotNull(value, "JSON key %s missing", publicKeySigner_GetName()); + PARCJSON *keystoreJson = parcJSONValue_GetJSON(value); + + value = parcJSON_GetValueByName(keystoreJson, param_KEYSTORE_NAME); + assertNotNull(value, "JSON key %s missing inside %s", param_KEYSTORE_NAME, publicKeySigner_GetName()); + PARCBuffer *sBuf = parcJSONValue_GetString(value); + output->filename = parcBuffer_Overlay(sBuf, 0); + + value = parcJSON_GetValueByName(keystoreJson, param_KEYSTORE_PASSWD); + assertNotNull(value, "JSON key %s missing inside %s", param_KEYSTORE_PASSWD, publicKeySigner_GetName()); + sBuf = parcJSONValue_GetString(value); + output->password = parcBuffer_Overlay(sBuf, 0); + + + return true; +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_PublicKeySigner.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_PublicKeySigner.h new file mode 100644 index 00000000..61fe893c --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_PublicKeySigner.h @@ -0,0 +1,112 @@ +/* + * 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. + */ + +/** + * @file config_PublicKeySigner.h + * @brief Generates stack and connection configuration information + * + * Each component in the protocol stack must have a configuration element. + * This module generates the configuration elements for the PKCS12 Signer. + * + * The signer only as a Connection configuration. + * + * @code + * { + * // Configure a stack with {APIConnector,TLVCodec,PKCS12Signer,MetisConnector} + * + * stackConfig = ccnxStackConfig_Create(); + * connConfig = ccnxConnectionConfig_Create(); + * + * apiConnector_ProtocolStackConfig(stackConfig); + * apiConnector_ConnectionConfig(connConfig); + * tlvCodec_ProtocolStackConfig(stackConfig); + * tlvCodec_ConnectionConfig(connConfig); + * + * publicKeySigner_ConnectionConfig(connConfig, "~/.ccnx/keystore.p12", "foobar password"); + * + * metisForwarder_ProtocolStackConfig(stackConfig); + * metisForwarder_ConnectionConfig(connConfig, metisForwarder_GetDefaultPort()); + * + * CCNxTransportConfig *config = ccnxTransportConfig_Create(stackConfig, connConfig); + * } + * + */ +#ifndef Libccnx_config_PublicKeySigner_h +#define Libccnx_config_PublicKeySigner_h +#include <stdbool.h> + +#include <parc/security/parc_Identity.h> + +#include <ccnx/transport/common/ccnx_TransportConfig.h> + +struct publickeysigner_params { + const char *filename; + const char *password; +}; + +/** + * Generates the configuration settings included in the Connection configuration + * + * Adds configuration elements to the `CCNxConnectionConfig` + * + * { "SIGNER" : "publicKeySigner", + * "publicKeySigner" : { "filename" : filename, "password" : password } + * } + * + * @param [in] config A pointer to a valid CCNxConnectionConfig instance. + * + * @return non-null The modified `CCNxConnectionConfig` + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxConnectionConfig *publicKeySigner_ConnectionConfig(CCNxConnectionConfig *config, const char *filename, const char *password); + +/** + * Generates the configuration settings included in the CCNxConnectionConfig for the identity of the configuration 'owner' + * + * Adds configuration elements to the `CCNxConnectionConfig` + * + * { "SIGNER" : "publicKeySigner", + * "publicKeySigner" : { "filename" : filename, "password" : password } + * } + * + * @param [in] connConfig The pointer to a valid CCNxConnectionConfig instance. + * @param [in] identity A pointer to a valid PARCIdentity instance. + * + * @return non-null The modified `CCNxConnectionConfig` + */ +CCNxConnectionConfig *configPublicKeySigner_SetIdentity(CCNxConnectionConfig *connConfig, const PARCIdentity *identity); + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *publicKeySigner_GetName(void); + +/** + * If successful, return true and fill in the parameters in the output argument + * + * Parses the JSON created by publicKeySigner_ConnectionConfig() and fills in the + * output parameter. The output parameter must be allocated by the caller. + */ +bool publicKeySigner_GetConnectionParams(PARCJSON *connectionJson, struct publickeysigner_params *output); +#endif // Libccnx_config_PublicKeySigner_h diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Signer.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Signer.c new file mode 100644 index 00000000..ae386c3b --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Signer.c @@ -0,0 +1,65 @@ +/* + * 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. + */ + +// +// config_Signer.c +// Libccnx +// +// + +#include <config.h> +#include <stdio.h> +#include <string.h> +#include "config_Signer.h" +#include "config_PublicKeySigner.h" +#include "config_SymmetricKeySigner.h" + +#include <ccnx/transport/transport_rta/core/components.h> + +#include <LongBow/runtime.h> + +static const char param_SIGNER[] = "SIGNER"; + +const char * +signer_GetName() +{ + return param_SIGNER; +} + +/** + * Determine which signer is configured + */ +SignerType +signer_GetImplementationType(PARCJSON *connectionJson) +{ + assertNotNull(connectionJson, "Parameter must be non-null"); + + PARCJSONValue *value = parcJSON_GetValueByName(connectionJson, signer_GetName()); + assertNotNull(value, "signer must be specified in the connection configuration"); + PARCBuffer *sBuf = parcJSONValue_GetString(value); + const char *signer_name = parcBuffer_Overlay(sBuf, 0); + + assertNotNull(signer_name, "Name of signer must be non-null in connection configuration"); + + if (strcasecmp(signer_name, publicKeySigner_GetName()) == 0) { + return SignerType_PublicKeySigner; + } + + if (strcasecmp(signer_name, symmetricKeySigner_GetName()) == 0) { + return SignerType_SymmetricKeySigner; + } + + return SignerType_Unknown; +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Signer.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Signer.h new file mode 100644 index 00000000..230c55f3 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_Signer.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +/** + * @file config_Signer.h + * @brief Queries the configuration to determine which signer is used + * + * <#Detailed Description#> + * + */ +#ifndef Libccnx_config_Signer_h +#define Libccnx_config_Signer_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> +#include "config_SymmetricKeySigner.h" +#include "config_PublicKeySigner.h" + +typedef enum { + SignerType_Unknown, + SignerType_PublicKeySigner, + SignerType_SymmetricKeySigner +} SignerType; + +/** + * Determine which signer is configured. Each specific implementation will emit a line + * such as { "SIGNER" : "signer_name" } + */ +SignerType signer_GetImplementationType(PARCJSON *connectionJson); + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *signer_GetName(void); +#endif // Libccnx_config_Signer_h diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_SymmetricKeySigner.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_SymmetricKeySigner.c new file mode 100644 index 00000000..5326af31 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_SymmetricKeySigner.c @@ -0,0 +1,95 @@ +/* + * 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. + */ + +// +// config_SymmetricKeySigner.c +// Libccnx +// +// + +#include <config.h> +#include <stdio.h> +#include "config_SymmetricKeySigner.h" + +#include <ccnx/transport/transport_rta/core/components.h> + +#include <LongBow/runtime.h> + +static const char name[] = "SymmetricKeySigner"; + +static const char param_KEYSTORE_NAME[] = "KEYSTORE_NAME"; +static const char param_KEYSTORE_PASSWD[] = "KEYSTORE_PASSWD"; +static const char param_SIGNER[] = "SIGNER"; + +/** + * Generates: + * + * { "SIGNER" : "SymmetricKeySigner", + * "SymmetricKeySigner" : { "filename" : filename, "password" : password } + * } + */ +CCNxConnectionConfig * +symmetricKeySigner_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 *) symmetricKeySigner_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_Add(connConfig, symmetricKeySigner_GetName(), value); + parcJSONValue_Release(&value); + return connConfig; +} + +const char * +symmetricKeySigner_GetName() +{ + return name; +} + +/** + * If successful, return true and fill in the parameters in the output argument + */ +bool +symmetricKeySigner_GetConnectionParams(PARCJSON *connectionJson, struct symmetrickeysigner_params *output) +{ + assertNotNull(connectionJson, "Parameter connectionJson must be non-null"); + assertNotNull(output, "Parameter output must be non-null"); + + PARCJSONValue *value = parcJSON_GetValueByName(connectionJson, symmetricKeySigner_GetName()); + assertNotNull(value, "JSON key %s missing", symmetricKeySigner_GetName()); + PARCJSON *keystoreJson = parcJSONValue_GetJSON(value); + + value = parcJSON_GetValueByName(keystoreJson, param_KEYSTORE_NAME); + assertNotNull(value, "JSON key %s missing inside %s", param_KEYSTORE_NAME, symmetricKeySigner_GetName()); + PARCBuffer *sBuf = parcJSONValue_GetString(value); + output->filename = parcBuffer_Overlay(sBuf, 0); + + value = parcJSON_GetValueByName(keystoreJson, param_KEYSTORE_PASSWD); + assertNotNull(value, "JSON key %s missing inside %s", param_KEYSTORE_PASSWD, symmetricKeySigner_GetName()); + sBuf = parcJSONValue_GetString(value); + output->password = parcBuffer_Overlay(sBuf, 0); + return true; +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_SymmetricKeySigner.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_SymmetricKeySigner.h new file mode 100644 index 00000000..0de4be3f --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_SymmetricKeySigner.h @@ -0,0 +1,103 @@ +/* + * 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. + */ + +/** + * @file config_SymmetricKeySigner.h + * @brief Generates stack and connection configuration information + * + * Each component in the protocol stack must have a configuration element. + * This module generates the configuration elements for the Symmetric Keystore. + * The keystore is specific to a Connection, so there is no Protocol Stack configuration. + * + * @code + * { + * // Configure a stack with {APIConnector,TLVCodec,MetisConnector} + * // The coded will use a symmetric keystore + * + * stackConfig = ccnxStackConfig_Create(); + * connConfig = ccnxConnectionConfig_Create(); + * + * apiConnector_ProtocolStackConfig(stackConfig); + * apiConnector_ConnectionConfig(connConfig); + * tlvCodec_ProtocolStackConfig(stackConfig); + * tlvCodec_ConnectionConfig(connConfig); + * symmetricKeySigner_ConnectionConfig(connConfig, "~/.ccnx/keystore.p12", "foobar password"); + * + * metisForwarder_ProtocolStackConfig(stackConfig); + * metisForwarder_ConnectionConfig(connConfig, metis_port); + * + * CCNxTransportConfig *config = ccnxTransportConfig_Create(stackConfig, connConfig); + * } + * + */ + +#ifndef Libccnx_config_SymmetricKeySigner_h +#define Libccnx_config_SymmetricKeySigner_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> +#include <stdbool.h> + +struct symmetrickeysigner_params { + const char *filename; + const char *password; +}; + +/** + * Generates the configuration settings included in the Connection configuration + * + * Adds configuration elements to the `CCNxConnectionConfig` + * + * { "SIGNER" : "SymmetricFileStore", + * "SymmetricFileStore" : { "filename" : filename, password : password } + * } + * + * @param [in] config A pointer to a valid CCNxConnectionConfig instance. + * + * @return non-null The modified `CCNxConnectionConfig` + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxConnectionConfig *symmetricKeySigner_ConnectionConfig(CCNxConnectionConfig *config, const char *filename, const char *password); + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *symmetricKeySigner_GetName(void); + +/** + * Look inside a JSON configuration and extract the Signer parameters + * + * <#Paragraphs Of Explanation#> + * + * @param [out] output The filename and password passed down the stack + * + * @return true Configuration item found and output set + * @return false Configuration item not found, output not set + * + * Example: + * @code + * <#example#> + * @endcode + */ +bool symmetricKeySigner_GetConnectionParams(PARCJSON *connectionJson, struct symmetrickeysigner_params *output); +#endif // Libccnx_config_SymmetricKeySigner_h diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_TestingComponent.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_TestingComponent.c new file mode 100644 index 00000000..1f12bc9b --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_TestingComponent.c @@ -0,0 +1,73 @@ +/* + * 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 "config_TestingComponent.h" + +#include <ccnx/transport/transport_rta/core/components.h> + +CCNxStackConfig * +testingUpper_ProtocolStackConfig(CCNxStackConfig *stackConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxStackConfig *result = ccnxStackConfig_Add(stackConfig, testingUpper_GetName(), value); + parcJSONValue_Release(&value); + + return result; +} + +CCNxStackConfig * +testingLower_ProtocolStackConfig(CCNxStackConfig *stackConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxStackConfig *result = ccnxStackConfig_Add(stackConfig, testingLower_GetName(), value); + parcJSONValue_Release(&value); + + return result; +} + +CCNxConnectionConfig * +testingUpper_ConnectionConfig(CCNxConnectionConfig *connConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connConfig, testingUpper_GetName(), value); + parcJSONValue_Release(&value); + + return result; +} + +CCNxConnectionConfig * +testingLower_ConnectionConfig(CCNxConnectionConfig *connConfig) +{ + PARCJSONValue *value = parcJSONValue_CreateFromNULL(); + CCNxConnectionConfig *result = ccnxConnectionConfig_Add(connConfig, testingLower_GetName(), value); + parcJSONValue_Release(&value); + + return result; +} + +const char * +testingUpper_GetName() +{ + return RtaComponentNames[TESTING_UPPER]; +} + +const char * +testingLower_GetName() +{ + return RtaComponentNames[TESTING_LOWER]; +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_TestingComponent.h b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_TestingComponent.h new file mode 100644 index 00000000..a8c6e83b --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/config_TestingComponent.h @@ -0,0 +1,137 @@ +/* + * 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. + */ + +/** + * @file config_TestingComponent.h + * @brief Generates stack and connection configuration information + * + * Each component in the protocol stack must have a configuration element. + * This module generates the configuration elements for a testing component + * to be used in unit tests. The upper and lower testing components surround + * a component under test to simulate feeding in or sending out messages. + * + * @code + * { + * // Configure a stack with {TestingUpper,TLVCodec,TestingLower} + * + * stackConfig = ccnxStackConfig_Create(); + * connConfig = ccnxConnectionConfig_Create(); + * + * testingUpper_ProtocolStackConfig(stackConfig); + * testingUpper_ConnectionConfig(connConfig); + * tlvCodec_ProtocolStackConfig(stackConfig); + * tlvCodec_ConnectionConfig(connConfig); + * testingLower_ProtocolStackConfig(stackConfig); + * testingLower_ConnectionConfig(connConfig, metis_port); + * + * CCNxTransportConfig *config = ccnxTransportConfig_Create(stackConfig, connConfig); + * } + * + */ + +#ifndef Libccnx_config_TestingComponent_h +#define Libccnx_config_TestingComponent_h + +#include <ccnx/transport/common/ccnx_TransportConfig.h> + +/** + * Generates the configuration settings included in the Protocol Stack configuration + * + * Adds configuration elements to the Protocol Stack configuration + * + * { "TESTING UPPER" : { } } + * + * @param [in] stackConfig The protocl stack configuration to update + * + * @return non-null The updated protocol stack configuration + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxStackConfig *testingUpper_ProtocolStackConfig(CCNxStackConfig *stackConfig); + +/** + * Generates the configuration settings included in the Protocol Stack configuration + * + * Adds configuration elements to the Protocol Stack configuration + * + * { "TESTING LOWER" : { } } + * + * @param [in] stackConfig The protocl stack configuration to update + * + * @return non-null The updated protocol stack configuration + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxStackConfig *testingLower_ProtocolStackConfig(CCNxStackConfig *stackConfig); + +/** + * Generates the configuration settings included in the Connection configuration + * + * Adds configuration elements to the `CCNxConnectionConfig` + * + * @param [in] config A pointer to a valid `CCNxConnectionConfig` instance. + * + * @return non-null A pointer to the modified `CCNxConnectionConfig` instance + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxConnectionConfig *testingUpper_ConnectionConfig(CCNxConnectionConfig *config); + +/** + * Generates the configuration settings included in the Connection configuration + * + * Adds configuration elements to the `CCNxConnectionConfig` + * + * @param [in] config A pointer to a valid `CCNxConnectionConfig` instance. + * + * @return non-null The modified `CCNxConnectionConfig` + * + * Example: + * @code + * <#example#> + * @endcode + */ +CCNxConnectionConfig *testingLower_ConnectionConfig(CCNxConnectionConfig *config); + + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *testingUpper_GetName(void); + +/** + * Returns the text string for this component + * + * Used as the text key to a JSON block. You do not need to free it. + * + * @return non-null A text string unique to this component + * + */ +const char *testingLower_GetName(void); +#endif // Libccnx_config_TestingComponent_h diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/CMakeLists.txt b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/CMakeLists.txt new file mode 100644 index 00000000..235ef4be --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/CMakeLists.txt @@ -0,0 +1,22 @@ +# Enable gcov output for the tests +add_definitions(--coverage) +set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} " --coverage") + +set(TestsExpectedToPass + test_config_ApiConnector + test_config_Codec_Tlv + test_config_FlowControl_Vegas + test_config_Forwarder_Local + test_config_Forwarder_Metis + test_config_InMemoryVerifier + test_config_ProtocolStack + test_config_PublicKeySigner + test_config_Signer + test_config_SymmetricKeySigner + test_config_TestingComponent +) + + +foreach(test ${TestsExpectedToPass}) + AddTest(${test}) +endforeach() diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ApiConnector.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ApiConnector.c new file mode 100644 index 00000000..10abcbd8 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ApiConnector.c @@ -0,0 +1,141 @@ +/* + * 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. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_ApiConnector.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_ApiConnector) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_ApiConnector) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_ApiConnector) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, apiConnector_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, apiConnector_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, apiConnector_GetName); + LONGBOW_RUN_TEST_CASE(Global, apiConnector_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, apiConnector_ProtocolStackConfig_ReturnValue); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, apiConnector_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = apiConnector_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, apiConnector_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(apiConnector_ConnectionConfig(data->connConfig), + apiConnector_GetName()); +} + +LONGBOW_TEST_CASE(Global, apiConnector_GetName) +{ + testRtaConfiguration_ComponentName(apiConnector_GetName, RtaComponentNames[API_CONNECTOR]); +} + +LONGBOW_TEST_CASE(Global, apiConnector_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(apiConnector_ProtocolStackConfig(data->stackConfig), + apiConnector_GetName()); +} + +LONGBOW_TEST_CASE(Global, apiConnector_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = apiConnector_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_ApiConnector); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Codec_Tlv.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Codec_Tlv.c new file mode 100644 index 00000000..d3159bb1 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Codec_Tlv.c @@ -0,0 +1,154 @@ +/* + * 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. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_Codec_Tlv.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_Codec_Tlv) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_Codec_Tlv) +{ + parcMemory_SetInterface(&PARCSafeMemoryAsPARCMemory); + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_Codec_Tlv) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, Codec_Tlv_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Codec_Tlv_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, Codec_Tlv_GetName); + LONGBOW_RUN_TEST_CASE(Global, Codec_Tlv_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Codec_Tlv_ProtocolStackConfig_ReturnValue); + + LONGBOW_RUN_TEST_CASE(Global, tlvCodec_ConnectionConfig); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, Codec_Tlv_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = tlvCodec_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, Codec_Tlv_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(tlvCodec_ConnectionConfig(data->connConfig), + tlvCodec_GetName()); +} + +LONGBOW_TEST_CASE(Global, Codec_Tlv_GetName) +{ + testRtaConfiguration_ComponentName(tlvCodec_GetName, RtaComponentNames[CODEC_TLV]); +} + +LONGBOW_TEST_CASE(Global, Codec_Tlv_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(tlvCodec_ProtocolStackConfig(data->stackConfig), + tlvCodec_GetName()); +} + +LONGBOW_TEST_CASE(Global, Codec_Tlv_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = tlvCodec_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_CASE(Global, tlvCodec_ConnectionConfig) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(tlvCodec_ConnectionConfig(data->connConfig), + tlvCodec_GetName()); + + PARCJSON *json = ccnxConnectionConfig_GetJson(data->connConfig); + assertNotNull(json, "Expected a non-NULL connectionConfig."); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_Codec_Tlv); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_FlowControl_Vegas.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_FlowControl_Vegas.c new file mode 100644 index 00000000..84e8349d --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_FlowControl_Vegas.c @@ -0,0 +1,141 @@ +/* + * 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. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_FlowControl_Vegas.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_FlowControl_Vegas) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_FlowControl_Vegas) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_FlowControl_Vegas) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, FlowControl_Vegas_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, FlowControl_Vegas_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, FlowControl_Vegas_GetName); + LONGBOW_RUN_TEST_CASE(Global, FlowControl_Vegas_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, FlowControl_Vegas_ProtocolStackConfig_ReturnValue); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, FlowControl_Vegas_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = vegasFlowController_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, FlowControl_Vegas_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(vegasFlowController_ConnectionConfig(data->connConfig), + vegasFlowController_GetName()); +} + +LONGBOW_TEST_CASE(Global, FlowControl_Vegas_GetName) +{ + testRtaConfiguration_ComponentName(vegasFlowController_GetName, RtaComponentNames[FC_VEGAS]); +} + +LONGBOW_TEST_CASE(Global, FlowControl_Vegas_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(vegasFlowController_ProtocolStackConfig(data->stackConfig), + vegasFlowController_GetName()); +} + +LONGBOW_TEST_CASE(Global, FlowControl_Vegas_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = vegasFlowController_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_FlowControl_Vegas); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Local.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Local.c new file mode 100644 index 00000000..39d82172 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Local.c @@ -0,0 +1,152 @@ +/* + * 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. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_Forwarder_Local.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_Forwarder_Local) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_Forwarder_Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_Forwarder_Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_GetName); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_ProtocolStackConfig_ReturnValue); + + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_GetPath); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = localForwarder_ConnectionConfig(data->connConfig, "/path/to/socket"); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(localForwarder_ConnectionConfig(data->connConfig, "/path/to/socket"), + localForwarder_GetName()); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_GetName) +{ + testRtaConfiguration_ComponentName(localForwarder_GetName, RtaComponentNames[FWD_LOCAL]); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_GetPath) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + const char *truth = "/path/to/socket"; + localForwarder_ConnectionConfig(data->connConfig, truth); + const char *test = localForwarder_GetPath(ccnxConnectionConfig_GetJson(data->connConfig)); + assertTrue(strcmp(truth, test) == 0, "Got wrong socket path, got %s expected %s", test, truth); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(localForwarder_ProtocolStackConfig(data->stackConfig), + localForwarder_GetName()); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = localForwarder_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_Forwarder_Local); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Metis.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Metis.c new file mode 100644 index 00000000..b4c2c8c4 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Metis.c @@ -0,0 +1,154 @@ +/* + * 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. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_Forwarder_Metis.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_Forwarder_Metis) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Metis); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_Forwarder_Metis) +{ + parcMemory_SetInterface(&PARCSafeMemoryAsPARCMemory); + + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_Forwarder_Metis) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_GetName); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_ProtocolStackConfig_ReturnValue); + + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_GetPath); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = metisForwarder_ConnectionConfig(data->connConfig, 9999); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(metisForwarder_ConnectionConfig(data->connConfig, 9999), + metisForwarder_GetName()); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_GetName) +{ + testRtaConfiguration_ComponentName(metisForwarder_GetName, RtaComponentNames[FWD_METIS]); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_GetPath) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + int truth = 9999; + metisForwarder_ConnectionConfig(data->connConfig, truth); + int test = metisForwarder_GetPortFromConfig(ccnxConnectionConfig_GetJson(data->connConfig)); + assertTrue(truth == test, "Got wrong socket path, got %d expected %d", test, truth); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(metisForwarder_ProtocolStackConfig(data->stackConfig), + metisForwarder_GetName()); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = metisForwarder_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_FIXTURE(Metis) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Metis) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Metis) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_Forwarder_Metis); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_InMemoryVerifier.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_InMemoryVerifier.c new file mode 100644 index 00000000..f4455b48 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_InMemoryVerifier.c @@ -0,0 +1,122 @@ +/* + * 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. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_InMemoryVerifier.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_InMemoryVerifier) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_InMemoryVerifier) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_InMemoryVerifier) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, InMemoryVerifier_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, InMemoryVerifier_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, InMemoryVerifier_GetName); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, InMemoryVerifier_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = inMemoryVerifier_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, InMemoryVerifier_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(inMemoryVerifier_ConnectionConfig(data->connConfig), + inMemoryVerifier_GetName()); +} + +LONGBOW_TEST_CASE(Global, InMemoryVerifier_GetName) +{ + testRtaConfiguration_ComponentName(inMemoryVerifier_GetName, "InMemoryVerifier"); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_InMemoryVerifier); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ProtocolStack.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ProtocolStack.c new file mode 100644 index 00000000..d784b2be --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ProtocolStack.c @@ -0,0 +1,167 @@ +/* + * 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 the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_ProtocolStack.c" +#include <LongBow/unit-test.h> + +#include <parc/algol/parc_SafeMemory.h> +#include "testrig_RtaConfigCommon.c" + +#include <ccnx/transport/common/ccnx_TransportConfig.h> + +LONGBOW_TEST_RUNNER(config_ProtocolStack) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_ProtocolStack) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_ProtocolStack) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, protocolStack_ComponentsConfigArgs); + LONGBOW_RUN_TEST_CASE(Global, protocolStack_ComponentsConfigArrayList); + LONGBOW_RUN_TEST_CASE(Global, protocolStack_GetComponentNameArray); + LONGBOW_RUN_TEST_CASE(Global, protocolStack_GetName); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, protocolStack_ComponentsConfigArgs) +{ + CCNxStackConfig *stackConfig = ccnxStackConfig_Create(); + + const char truth[] = "{\"STACK\":{\"COMPONENTS\":[\"Apple\",\"Bananna\",\"Cherry\"]}}"; + + protocolStack_ComponentsConfigArgs(stackConfig, "Apple", "Bananna", "Cherry", NULL); + PARCJSON *json = ccnxStackConfig_GetJson(stackConfig); + char *str = parcJSON_ToCompactString(json); + assertTrue(strcmp(truth, str) == 0, "Got wrong config, got %s expected %s", str, truth); + parcMemory_Deallocate((void **) &str); + ccnxStackConfig_Release(&stackConfig); +} + +LONGBOW_TEST_CASE(Global, protocolStack_ComponentsConfigArrayList) +{ + CCNxStackConfig *stackConfig = ccnxStackConfig_Create(); + PARCArrayList *names = parcArrayList_Create(NULL); + parcArrayList_Add(names, "Apple"); + parcArrayList_Add(names, "Bananna"); + parcArrayList_Add(names, "Cherry"); + + const char truth[] = "{\"STACK\":{\"COMPONENTS\":[\"Apple\",\"Bananna\",\"Cherry\"]}}"; + + protocolStack_ComponentsConfigArrayList(stackConfig, names); + PARCJSON *json = ccnxStackConfig_GetJson(stackConfig); + char *str = parcJSON_ToCompactString(json); + assertTrue(strcmp(truth, str) == 0, "Got wrong config, got %s expected %s", str, truth); + + parcMemory_Deallocate((void **) &str); + ccnxStackConfig_Release(&stackConfig); + parcArrayList_Destroy(&names); +} + +LONGBOW_TEST_CASE(Global, protocolStack_GetComponentNameArray) +{ + CCNxStackConfig *stackConfig = ccnxStackConfig_Create(); + PARCArrayList *names = parcArrayList_Create(NULL); + parcArrayList_Add(names, "Apple"); + parcArrayList_Add(names, "Bananna"); + parcArrayList_Add(names, "Cherry"); + + protocolStack_ComponentsConfigArrayList(stackConfig, names); + + char truth[] = "{\"STACK\":{\"COMPONENTS\":[\"Apple\",\"Bananna\",\"Cherry\"]}}"; + PARCJSON *json = parcJSON_ParseString(truth); + + PARCArrayList *test = protocolStack_GetComponentNameArray(json); + + assertTrue(parcArrayList_Size(test) == parcArrayList_Size(names), + "wrong array list size, got %zu expected %zu", + parcArrayList_Size(test), parcArrayList_Size(names)); + for (int i = 0; i < parcArrayList_Size(test); i++) { + char *a = parcArrayList_Get(test, i); + char *b = parcArrayList_Get(names, i); + assertTrue(strcmp(a, b) == 0, "mismatch elements %d, got %s expected %s", i, a, b); + } + + ccnxStackConfig_Release(&stackConfig); + parcArrayList_Destroy(&names); + parcJSON_Release(&json); + parcArrayList_Destroy(&test); +} + +LONGBOW_TEST_CASE(Global, protocolStack_GetName) +{ + const char *name = protocolStack_GetName(); + assertTrue(strcmp(name, param_STACK) == 0, "Got wrong name, got %s expected %s", name, param_STACK); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_ProtocolStack); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_PublicKeySigner.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_PublicKeySigner.c new file mode 100644 index 00000000..325d4b86 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_PublicKeySigner.c @@ -0,0 +1,133 @@ +/* + * 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 the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_PublicKeySigner.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> +#include "testrig_RtaConfigCommon.c" +#include <ccnx/transport/transport_rta/config/config_Signer.h> + +LONGBOW_TEST_RUNNER(config_PublicKeySignerPkcs12Store) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_PublicKeySignerPkcs12Store) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_PublicKeySignerPkcs12Store) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, publicKeySignerPkcs12Store_ConnectionConfig); + LONGBOW_RUN_TEST_CASE(Global, publicKeySignerPkcs12Store_GetConnectionParams); + LONGBOW_RUN_TEST_CASE(Global, publicKeySignerPkcs12Store_GetName); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, publicKeySignerPkcs12Store_ConnectionConfig) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + publicKeySigner_ConnectionConfig(connConfig, filename, password); + + // make sure our stuff is in there + testRtaConfiguration_ConnectionJsonKey(connConfig, publicKeySigner_GetName()); + + // make sure the SIGNER parameter is in there + testRtaConfiguration_ConnectionJsonKey(connConfig, signer_GetName()); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, publicKeySignerPkcs12Store_GetConnectionParams) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + publicKeySigner_ConnectionConfig(connConfig, filename, password); + + PARCJSON *json = ccnxConnectionConfig_GetJson(connConfig); + struct publickeysigner_params params; + + publicKeySigner_GetConnectionParams(json, ¶ms); + + assertTrue(strncmp(params.filename, filename, strlen(filename)) == 0, "wrong filename, got %s expected %s", params.filename, filename); + assertTrue(strncmp(params.password, password, strlen(password)) == 0, "wrong password, got %s expected %s", params.password, password); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, publicKeySignerPkcs12Store_GetName) +{ + testRtaConfiguration_ComponentName(&publicKeySigner_GetName, name); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_PublicKeySignerPkcs12Store); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Signer.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Signer.c new file mode 100644 index 00000000..cf8f3e98 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Signer.c @@ -0,0 +1,141 @@ +/* + * 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 the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_Signer.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_Signer) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_Signer) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_Signer) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, signer_GetImplementationType_PublicKey); + LONGBOW_RUN_TEST_CASE(Global, signer_GetImplementationType_SymmetricKey); + LONGBOW_RUN_TEST_CASE(Global, signer_GetImplementationType_Unknown); + LONGBOW_RUN_TEST_CASE(Global, signer_GetName); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, signer_GetImplementationType_PublicKey) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + publicKeySigner_ConnectionConfig(connConfig, filename, password); + + PARCJSON *json = ccnxConnectionConfig_GetJson(connConfig); + + SignerType type = signer_GetImplementationType(json); + assertTrue(type == SignerType_PublicKeySigner, "Got wrong signer type, got %d expected %d", type, SignerType_PublicKeySigner); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, signer_GetImplementationType_SymmetricKey) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + symmetricKeySigner_ConnectionConfig(connConfig, filename, password); + + PARCJSON *json = ccnxConnectionConfig_GetJson(connConfig); + + SignerType type = signer_GetImplementationType(json); + assertTrue(type == SignerType_SymmetricKeySigner, "Got wrong signer type, got %d expected %d", type, SignerType_SymmetricKeySigner); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, signer_GetImplementationType_Unknown) +{ + char *bogusSignerString = "{\"SIGNER\":\"BogusSigner\",\"BogusSigner\":{}}"; + + PARCJSON *json = parcJSON_ParseString(bogusSignerString); + + SignerType type = signer_GetImplementationType(json); + assertTrue(type == SignerType_Unknown, "Got wrong signer type, got %d expected %d", type, SignerType_Unknown); + + parcJSON_Release(&json); +} + +LONGBOW_TEST_CASE(Global, signer_GetName) +{ + testRtaConfiguration_ComponentName(&signer_GetName, param_SIGNER); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_Signer); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_SymmetricKeySigner.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_SymmetricKeySigner.c new file mode 100644 index 00000000..4d6244e1 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_SymmetricKeySigner.c @@ -0,0 +1,135 @@ +/* + * 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 the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_SymmetricKeySigner.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> +#include "testrig_RtaConfigCommon.c" +#include <ccnx/transport/transport_rta/config/config_Signer.h> + +LONGBOW_TEST_RUNNER(config_SymmetricKeySignerFileStore) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_SymmetricKeySignerFileStore) +{ + parcMemory_SetInterface(&PARCSafeMemoryAsPARCMemory); + + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_SymmetricKeySignerFileStore) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, symmetricKeySignerFileStore_ConnectionConfig); + LONGBOW_RUN_TEST_CASE(Global, symmetricKeySignerFileStore_GetConnectionParams); + LONGBOW_RUN_TEST_CASE(Global, symmetricKeySignerFileStore_GetName); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, symmetricKeySignerFileStore_ConnectionConfig) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + symmetricKeySigner_ConnectionConfig(connConfig, filename, password); + + // make sure our stuff is in there + testRtaConfiguration_ConnectionJsonKey(connConfig, symmetricKeySigner_GetName()); + + // make sure the SIGNER parameter is in there + testRtaConfiguration_ConnectionJsonKey(connConfig, signer_GetName()); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, symmetricKeySignerFileStore_GetConnectionParams) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + symmetricKeySigner_ConnectionConfig(connConfig, filename, password); + + PARCJSON *json = ccnxConnectionConfig_GetJson(connConfig); + struct symmetrickeysigner_params params; + + symmetricKeySigner_GetConnectionParams(json, ¶ms); + + assertTrue(strncmp(params.filename, filename, strlen(filename)) == 0, "wrong filename, got %s expected %s", params.filename, filename); + assertTrue(strncmp(params.password, password, strlen(password)) == 0, "wrong password, got %s expected %s", params.password, password); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, symmetricKeySignerFileStore_GetName) +{ + testRtaConfiguration_ComponentName(&symmetricKeySigner_GetName, name); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_SymmetricKeySignerFileStore); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_TestingComponent.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_TestingComponent.c new file mode 100644 index 00000000..ac8ba52e --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_TestingComponent.c @@ -0,0 +1,186 @@ +/* + * 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. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_TestingComponent.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_TestingComponent) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_TestingComponent) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_TestingComponent) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, testingUpper_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, testingUpper_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, testingUpper_GetName); + LONGBOW_RUN_TEST_CASE(Global, testingUpper_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, testingUpper_ProtocolStackConfig_ReturnValue); + + LONGBOW_RUN_TEST_CASE(Global, testingLower_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, testingLower_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, testingLower_GetName); + LONGBOW_RUN_TEST_CASE(Global, testingLower_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, testingLower_ProtocolStackConfig_ReturnValue); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, testingUpper_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = testingUpper_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, testingUpper_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(testingUpper_ConnectionConfig(data->connConfig), + testingUpper_GetName()); +} + +LONGBOW_TEST_CASE(Global, testingUpper_GetName) +{ + testRtaConfiguration_ComponentName(testingUpper_GetName, RtaComponentNames[TESTING_UPPER]); +} + +LONGBOW_TEST_CASE(Global, testingUpper_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(testingUpper_ProtocolStackConfig(data->stackConfig), + testingUpper_GetName()); +} + +LONGBOW_TEST_CASE(Global, testingUpper_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = testingUpper_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_CASE(Global, testingLower_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = testingLower_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, testingLower_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(testingUpper_ConnectionConfig(data->connConfig), + testingUpper_GetName()); +} + +LONGBOW_TEST_CASE(Global, testingLower_GetName) +{ + testRtaConfiguration_ComponentName(testingLower_GetName, RtaComponentNames[TESTING_LOWER]); +} + +LONGBOW_TEST_CASE(Global, testingLower_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(testingLower_ProtocolStackConfig(data->stackConfig), + testingLower_GetName()); +} + +LONGBOW_TEST_CASE(Global, testingLower_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = testingLower_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_TestingComponent); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/testrig_RtaConfigCommon.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/testrig_RtaConfigCommon.c new file mode 100644 index 00000000..29f2da24 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/testrig_RtaConfigCommon.c @@ -0,0 +1,66 @@ +/* + * 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. + */ + +/** + * Common test routines for the RTA component configuration functions + * + */ + +typedef struct test_data { + CCNxConnectionConfig *connConfig; + CCNxStackConfig *stackConfig; +} TestData; + +TestData * +testRtaConfiguration_CommonSetup(void) +{ + TestData *data = parcMemory_AllocateAndClear(sizeof(TestData)); + assertNotNull(data, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(TestData)); + data->connConfig = ccnxConnectionConfig_Create(); + data->stackConfig = ccnxStackConfig_Create(); + return data; +} + +void +testRtaConfiguration_CommonTeardown(TestData *data) +{ + ccnxStackConfig_Release(&data->stackConfig); + ccnxConnectionConfig_Destroy(&data->connConfig); + parcMemory_Deallocate((void **) &data); +} + +void +testRtaConfiguration_ComponentName(const char * (*getname)(void), const char *truth) +{ + const char *name = getname(); + assertTrue(strcmp(name, truth) == 0, + "Got wrong name, got %s expected %s", name, truth); +} + +void +testRtaConfiguration_ConnectionJsonKey(CCNxConnectionConfig *configToTest, const char *key) +{ + PARCJSON *json = ccnxConnectionConfig_GetJson(configToTest); + PARCJSONValue *value = parcJSON_GetValueByName(json, key); + assertNotNull(value, "Could not find key %s in configuration json", key); +} + +void +testRtaConfiguration_ProtocolStackJsonKey(CCNxStackConfig *configToTest, const char *key) +{ + PARCJSON *json = ccnxStackConfig_GetJson(configToTest); + PARCJSONValue *value = parcJSON_GetValueByName(json, key); + assertNotNull(value, "Could not find key %s in configuration json", key); +} |