aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/config
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/config')
-rw-r--r--hicn-light/src/hicn/config/CMakeLists.txt168
-rw-r--r--hicn-light/src/hicn/config/configuration.c2407
-rw-r--r--hicn-light/src/hicn/config/configuration.h51
-rw-r--r--hicn-light/src/hicn/config/configurationFile.c313
-rw-r--r--hicn-light/src/hicn/config/configurationListeners.c627
-rw-r--r--hicn-light/src/hicn/config/configurationListeners.h74
-rw-r--r--hicn-light/src/hicn/config/configuration_file.c292
-rw-r--r--hicn-light/src/hicn/config/configuration_file.h (renamed from hicn-light/src/hicn/config/configurationFile.h)32
-rw-r--r--hicn-light/src/hicn/config/controlAddConnection.c41
-rw-r--r--hicn-light/src/hicn/config/controlAddListener.c4
-rw-r--r--hicn-light/src/hicn/config/controlAddPolicy.c4
-rw-r--r--hicn-light/src/hicn/config/controlAddPunting.c4
-rw-r--r--hicn-light/src/hicn/config/controlAddRoute.c28
-rw-r--r--hicn-light/src/hicn/config/controlListConnections.c8
-rw-r--r--hicn-light/src/hicn/config/controlListListeners.c2
-rw-r--r--hicn-light/src/hicn/config/controlListPolicies.c30
-rw-r--r--hicn-light/src/hicn/config/controlListRoutes.c2
-rw-r--r--hicn-light/src/hicn/config/controlRemoveConnection.c1
-rw-r--r--hicn-light/src/hicn/config/controlRemoveListener.c1
-rw-r--r--hicn-light/src/hicn/config/controlRemovePolicy.c6
-rw-r--r--hicn-light/src/hicn/config/controlRemovePunting.c1
-rw-r--r--hicn-light/src/hicn/config/controlRemoveRoute.c6
-rw-r--r--hicn-light/src/hicn/config/controlSetStrategy.c29
-rw-r--r--hicn-light/src/hicn/config/controlState.c14
-rw-r--r--hicn-light/src/hicn/config/controlState.h2
-rw-r--r--hicn-light/src/hicn/config/symbolicNameTable.c191
26 files changed, 1654 insertions, 2684 deletions
diff --git a/hicn-light/src/hicn/config/CMakeLists.txt b/hicn-light/src/hicn/config/CMakeLists.txt
index 45f36e8ff..9db413867 100644
--- a/hicn-light/src/hicn/config/CMakeLists.txt
+++ b/hicn-light/src/hicn/config/CMakeLists.txt
@@ -14,95 +14,93 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
list(APPEND HEADER_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/commandOps.h
- ${CMAKE_CURRENT_SOURCE_DIR}/commandParser.h
- ${CMAKE_CURRENT_SOURCE_DIR}/configuration.h
- ${CMAKE_CURRENT_SOURCE_DIR}/commandReturn.h
- ${CMAKE_CURRENT_SOURCE_DIR}/symbolicNameTable.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlState.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRoot.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAddConnection.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAdd.h
- ${CMAKE_CURRENT_SOURCE_DIR}/configurationFile.h
- ${CMAKE_CURRENT_SOURCE_DIR}/configurationListeners.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAddRoute.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAddPolicy.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAddListener.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlListConnections.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlList.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlListListeners.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlListRoutes.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlListPolicies.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlQuit.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemove.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveListener.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveConnection.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveRoute.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemovePolicy.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlSet.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlUnset.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlSetDebug.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlUnsetDebug.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMe.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeEnable.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeDiscovery.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeTimescale.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheServe.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheStore.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheClear.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlCache.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlSetStrategy.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlSetWldr.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAddPunting.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemovePunting.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlUpdate.h
- ${CMAKE_CURRENT_SOURCE_DIR}/controlUpdateConnection.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/commandOps.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/commandParser.h
+${CMAKE_CURRENT_SOURCE_DIR}/configuration.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/commandReturn.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/symbolicNameTable.h
+#${CMAKE_CURRENT_SOURCE_DIR}/controlState.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRoot.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAddConnection.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAdd.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/configuration_file.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAddRoute.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAddPolicy.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAddListener.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlListConnections.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlList.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlListListeners.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlListRoutes.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlListPolicies.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlQuit.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemove.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveListener.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveConnection.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveRoute.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemovePolicy.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlSet.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlUnset.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlSetDebug.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlUnsetDebug.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMe.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeEnable.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeDiscovery.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeTimescale.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheServe.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheStore.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheClear.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlCache.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlSetStrategy.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlSetWldr.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAddPunting.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemovePunting.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlUpdate.h
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlUpdateConnection.h
)
list(APPEND SOURCE_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/commandOps.c
- ${CMAKE_CURRENT_SOURCE_DIR}/commandParser.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/commandOps.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/commandParser.c
${CMAKE_CURRENT_SOURCE_DIR}/configuration.c
- ${CMAKE_CURRENT_SOURCE_DIR}/configurationFile.c
- ${CMAKE_CURRENT_SOURCE_DIR}/configurationListeners.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlState.c
- ${CMAKE_CURRENT_SOURCE_DIR}/symbolicNameTable.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAdd.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAddConnection.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAddRoute.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAddPolicy.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAddListener.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlList.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlListConnections.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlListListeners.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlListRoutes.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlListPolicies.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlQuit.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemove.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveListener.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveConnection.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveRoute.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemovePolicy.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRoot.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlSet.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlSetDebug.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlUnset.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlUnsetDebug.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMe.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeEnable.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeDiscovery.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeTimescale.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeRetx.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheServe.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheStore.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheClear.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlCache.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlSetStrategy.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlSetWldr.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlAddPunting.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlRemovePunting.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlUpdate.c
- ${CMAKE_CURRENT_SOURCE_DIR}/controlUpdateConnection.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/configuration_file.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlState.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/symbolicNameTable.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAdd.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAddConnection.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAddRoute.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAddPolicy.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAddListener.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlList.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlListConnections.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlListListeners.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlListRoutes.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlListPolicies.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlQuit.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemove.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveListener.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveConnection.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemoveRoute.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemovePolicy.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRoot.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlSet.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlSetDebug.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlUnset.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlUnsetDebug.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMe.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeEnable.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeDiscovery.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeTimescale.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlMapMeRetx.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheServe.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheStore.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlCacheClear.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlCache.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlSetStrategy.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlSetWldr.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlAddPunting.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlRemovePunting.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlUpdate.c
+# ${CMAKE_CURRENT_SOURCE_DIR}/controlUpdateConnection.c
)
set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c
index 39d327165..a6f78f9c2 100644
--- a/hicn-light/src/hicn/config/configuration.c
+++ b/hicn-light/src/hicn/config/configuration.c
@@ -26,531 +26,424 @@
#include <unistd.h>
#endif
#include <ctype.h>
-#include <parc/assert/parc_Assert.h>
#include <hicn/hicn-light/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <parc/algol/parc_HashMap.h>
-#include <parc/algol/parc_Memory.h>
-#include <parc/algol/parc_String.h>
-
-#include <hicn/config/configurationListeners.h>
-#include <hicn/config/symbolicNameTable.h>
-
#include <hicn/core/connection.h>
-#include <hicn/core/connectionTable.h>
+#include <hicn/core/connection_table.h>
#include <hicn/core/forwarder.h>
-#include <hicn/core/system.h>
+//#include <hicn/core/system.h>
#ifdef WITH_MAPME
#include <hicn/core/mapme.h>
#endif /* WITH_MAPME */
-#include <hicn/io/streamConnection.h>
-
-#include <hicn/io/hicnTunnel.h>
-#include <hicn/io/tcpTunnel.h>
-#include <hicn/io/udpTunnel.h>
-
-#include <parc/algol/parc_Unsigned.h>
-#include <hicn/io/listener.h> //the listener list
-#include <hicn/io/listenerSet.h> // needed to print
+#include <hicn/core/listener.h> //the listener list
+#include <hicn/core/listener_table.h>
#include <hicn/utils/commands.h>
#include <hicn/utils/utils.h>
-
-#include <hicn/utils/address.h>
+#include <hicn/utils/punting.h>
+#include <hicn/util/log.h>
+#include <hicn/face.h>
#define ETHERTYPE 0x0801
+#define DEFAULT_COST 1
+#define DEFAULT_PORT 1234
+
+#define make_ack(msg) msg->header.messageType = ACK_LIGHT
+#define make_nack(msg) msg->header.messageType = NACK_LIGHT
+
+#define msg_malloc_list(msg, N) \
+do { \
+ msg = malloc(sizeof((msg)->header) + N * sizeof((msg)->payload)); \
+ (msg)->header.messageType = RESPONSE_LIGHT; \
+ (msg)->header.length = (uint16_t)(N); \
+} while(0);
+
+/*
+ * XXX TODO
+ *
+ * Currently the strategy map only stores the strategy type, but it should be
+ * extended with strategy options.
+ *
+ * Or maybe we simply remove this map like in VPP.
+ *
+ * prefix_str -> strategy_type
+ */
+KHASH_INIT(strategy_map, const char *, unsigned, 0, str_hash, str_hash_eq);
-struct configuration {
- Forwarder *forwarder;
- Logger *logger;
+struct configuration_s {
+ forwarder_t * forwarder;
- size_t maximumContentObjectStoreSize;
+ size_t maximumContentObjectStoreSize;
- // map from prefix (parcString) to strategy (parcString)
- PARCHashMap *strategy_map;
+ // map from prefix (parcString) to strategy (parcString)
+ kh_strategy_map_t * strategy_map;
- // translates between a symblic name and a connection id
- SymbolicNameTable *symbolicNameTable;
+#if 0
+ // translates between a symblic name and a connection id
+ // XXX This might be moved as two indices in the listener and connection
+ // tables to be widely reachable... this has nothing to do with
+ // configuration.
+ SymbolicNameTable *symbolic_nameTable;
+#endif
};
// ========================================================================================
-Connection *
-getConnectionBySymbolicOrId(Configuration * config, const char * symbolicOrConnid)
+// conn_id = UINT_MAX when symbolic_name is not found
+static inline
+unsigned
+_symbolic_to_conn_id(configuration_t * config, const char * symbolicOrConnid,
+ bool allow_self, unsigned ingress_id)
{
- ConnectionTable *table = forwarder_GetConnectionTable(config->forwarder);
- unsigned connid;
- Connection *conn = NULL;
-
- /* Try to resolve an eventual symbolic name as input */
- if (utils_IsNumber(symbolicOrConnid)) {
- connid = (unsigned int)strtold(symbolicOrConnid, NULL);
-
- } else {
- connid = symbolicNameTable_Get(config->symbolicNameTable, symbolicOrConnid);
- if (connid == UINT32_MAX) {
- if (logger_IsLoggable(config->logger, LoggerFacility_Config,
- PARCLogLevel_Warning)) {
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error,
- __func__, "Symbolic name '%s' could not be resolved",
- symbolicOrConnid);
- }
- }
- }
-
- /* Get connection by ID */
- conn = (Connection *)connectionTable_FindById( table, connid);
- if (!conn) {
- if (logger_IsLoggable(config->logger, LoggerFacility_Config,
- PARCLogLevel_Warning)) {
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error,
- __func__, "ConnID not found, check list connections");
+ unsigned conn_id;
+ const connection_table_t * table = forwarder_get_connection_table(config->forwarder);
+
+ if (allow_self && strcmp(symbolicOrConnid, "SELF") == 0) {
+ conn_id = ingress_id;
+ } else if (utils_IsNumber(symbolicOrConnid)) {
+ // case for conn_id as input
+ // XXX type issue ! XXX No check, see man
+ int id = atoi(symbolicOrConnid);
+ if (id < 0)
+ return CONNECTION_ID_UNDEFINED;
+ conn_id = id;
+
+ if (!connection_table_validate_id(table, conn_id)) {
+ ERROR("ConnID not found, check list connections");
+ conn_id = CONNECTION_ID_UNDEFINED;
+ }
+ } else {
+ // case for symbolic as input: check if symbolic name can be resolved
+ conn_id = connection_table_get_id_by_name(table, symbolicOrConnid);
+ if (connection_id_is_valid(conn_id)) {
+ DEBUG("Resolved symbolic name '%s' to conn_id %u", symbolicOrConnid, conn_id);
+ } else {
+ WARN("Symbolic name '%s' could not be resolved", symbolicOrConnid);
+ }
}
- }
- return conn;
+ return conn_id;
}
-// ========================================================================================
+#define symbolic_to_conn_id(config, symbolic) _symbolic_to_conn_id(config, symbolic, false, 0)
+
+#define symbolic_to_conn_id_self(config, symbolic, ingress_id) \
+ _symbolic_to_conn_id(config, symbolic, true, ingress_id)
-Configuration *configuration_Create(Forwarder *forwarder) {
- parcAssertNotNull(forwarder, "Parameter hicn-fwd must be non-null");
- Configuration *config = parcMemory_AllocateAndClear(sizeof(Configuration));
- parcAssertNotNull(config, "parcMemory_AllocateAndClear(%zu) returned NULL",
- sizeof(Configuration));
- config->forwarder = forwarder;
- config->logger = logger_Acquire(forwarder_GetLogger(forwarder));
- config->maximumContentObjectStoreSize = 100000;
- config->strategy_map = parcHashMap_Create();
- config->symbolicNameTable = symbolicNameTable_Create();
-
- return config;
+connection_t *
+getConnectionBySymbolicOrId(configuration_t * config, const char * symbolicOrConnid)
+{
+ connection_table_t * table = forwarder_get_connection_table(config->forwarder);
+ unsigned conn_id = symbolic_to_conn_id(config, symbolicOrConnid);
+ if (!connection_id_is_valid(conn_id))
+ return NULL;
+
+ /* conn_id is assumed validated here */
+ return connection_table_at(table, conn_id);
}
-void configuration_Destroy(Configuration **configPtr) {
- parcAssertNotNull(configPtr, "Parameter must be non-null double poitner");
- parcAssertNotNull(*configPtr,
- "Parameter must dereference to non-null pointer");
-
- Configuration *config = *configPtr;
- logger_Release(&config->logger);
- parcHashMap_Release(&(config->strategy_map));
- symbolicNameTable_Destroy(&config->symbolicNameTable);
- parcMemory_Deallocate((void **)&config);
- *configPtr = NULL;
+// ========================================================================================
+
+configuration_t *
+configuration_create(forwarder_t * forwarder)
+{
+ assert(forwarder);
+
+ configuration_t * config = malloc(sizeof(configuration_t));
+ if (!config)
+ return NULL;
+
+ config->forwarder = forwarder;
+ config->maximumContentObjectStoreSize = 100000;
+ config->strategy_map = kh_init_strategy_map();
+#if 0
+ config->symbolic_nameTable = symbolic_nameTable_Create();
+#endif
+
+ return config;
}
-struct iovec *configuration_ProcessRegisterHicnPrefix(Configuration *config,
- struct iovec *request,
- unsigned ingressId) {
- header_control_message *header = request[0].iov_base;
- add_route_command *control = request[1].iov_base;
+void
+configuration_free(configuration_t * config)
+{
+ assert(config);
- bool success = false;
+ kh_destroy_strategy_map(config->strategy_map);
+#if 0
+ symbolic_nameTable_Destroy(&config->symbolic_nameTable);
+#endif
+ free(config);
+}
- const char *symbolicOrConnid = control->symbolicOrConnid;
+/* Listener */
- if (strcmp(symbolicOrConnid, "SELF") == 0) {
- success = forwarder_AddOrUpdateRoute(config->forwarder, control, ingressId);
- } else if (utils_IsNumber(symbolicOrConnid)) {
- // case for connid as input
- unsigned connid = (unsigned)strtold(symbolicOrConnid, NULL);
- ConnectionTable *table = forwarder_GetConnectionTable(config->forwarder);
+uint8_t *
+configuration_on_listener_add(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
- // check if iconnID present in the fwd table
- if (connectionTable_FindById(table, connid)) {
- success = forwarder_AddOrUpdateRoute(config->forwarder, control, connid);
- } else {
- logger_Log(forwarder_GetLogger(config->forwarder), LoggerFacility_IO,
- PARCLogLevel_Error, __func__,
- "ConnID not found, check list connections");
- // failure
- }
+ msg_listener_add_t * msg = (msg_listener_add_t *)packet;
+ cmd_listener_add_t * control = &msg->payload;
- } else {
- // case for symbolic as input: check if symbolic name can be resolved
- unsigned connid =
- symbolicNameTable_Get(config->symbolicNameTable, symbolicOrConnid);
- // connid = UINT_MAX when symbolicName is not found
- if (connid != UINT32_MAX) {
- if (logger_IsLoggable(config->logger, LoggerFacility_Config,
- PARCLogLevel_Debug)) {
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Debug,
- __func__, "Add route resolve name '%s' to connid %u",
- symbolicOrConnid, connid);
- }
-
- success = forwarder_AddOrUpdateRoute(config->forwarder, control, connid);
+ forwarder_t * forwarder = configuration_get_forwarder(config);
+ assert(forwarder);
- } else {
- if (logger_IsLoggable(config->logger, LoggerFacility_Config,
- PARCLogLevel_Warning)) {
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Warning,
- __func__,
- "Add route symbolic name '%s' could not be resolved",
- symbolicOrConnid);
- }
- // failure
- }
- }
+ listener_table_t * table = forwarder_get_listener_table(forwarder);
+ assert(table);
- // generate ACK/NACK
- struct iovec *response;
+ /* Verify that the listener DOES NOT exist */
+ listener_t * listener = listener_table_get_by_name(table, control->symbolic);
+ if (listener)
+ goto NACK;
- if (success) { // ACK
- response = utils_CreateAck(header, control, sizeof(add_route_command));
- } else { // NACK
- response = utils_CreateNack(header, control, sizeof(add_route_command));
- }
+ address_t address;
+ if (address_from_ip_port(&address, control->family, &control->address,
+ control->port) < 0) {
+ WARN("Unsupported address type for HICN (ingress id %u): "
+ "must be either IPV4 or IPV6", ingress_id);
+ return false;
+ }
- return response;
-}
+ // NOTE: interface_name is expected NULL for hICN listener
+ face_type_t face_type;
+ if (!face_type_is_defined(control->listener_type))
+ goto NACK;
+ face_type = (face_type_t)control->listener_type;
-struct iovec *configuration_ProcessUnregisterHicnPrefix(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- remove_route_command *control = request[1].iov_base;
- bool success = false;
+ listener = listener_create(face_type, &address, control->interface_name, control->symbolic, forwarder);
+ if (!listener)
+ goto NACK;
- const char *symbolicOrConnid = control->symbolicOrConnid;
+ make_ack(msg);
+ return (uint8_t*)msg;
- if (utils_IsNumber(symbolicOrConnid)) {
- // case for connid as input
- unsigned connid = (unsigned)strtold(symbolicOrConnid, NULL);
- ConnectionTable *table = forwarder_GetConnectionTable(config->forwarder);
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
+}
- // check if interface index present in the fwd table
- if (connectionTable_FindById(table, connid)) {
- success = forwarder_RemoveRoute(config->forwarder, control, connid);
+uint8_t *
+configuration_on_listener_remove(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ msg_listener_remove_t * msg = (msg_listener_remove_t*)packet;
+ cmd_listener_remove_t * control = &msg->payload;
+
+ const char *symbolicOrListenerid = control->symbolicOrListenerid;
+ off_t listener_id;
+ listener_t * listener;
+
+ listener_table_t * listener_table = forwarder_get_listener_table(config->forwarder);
+
+ // Factor like for connections
+ if (utils_IsNumber(symbolicOrListenerid)) {
+ // XXX no check
+ int id = atoi(symbolicOrListenerid);
+ if (id < 0)
+ goto NACK;
+ listener_id = id;
+
+ listener = listener_table_get_by_id(listener_table, listener_id);
+ if (!listener) {
+ ERROR("Listener Id not found, check list listeners");
+ goto NACK;
+ }
} else {
- logger_Log(forwarder_GetLogger(config->forwarder), LoggerFacility_IO,
- PARCLogLevel_Error, __func__,
- "ConnID not found, check list connections");
- // failure
+ listener = listener_table_get_by_name(listener_table, symbolicOrListenerid);
+ listener_id = listener_table_get_listener_id(listener_table, listener);
}
- } else {
- // case for symbolic as input: chech if symbolic name can be resolved
- unsigned connid =
- symbolicNameTable_Get(config->symbolicNameTable, symbolicOrConnid);
- // connid = UINT_MAX when symbolicName is not found
- if (connid != UINT32_MAX) {
- if (logger_IsLoggable(config->logger, LoggerFacility_Config,
- PARCLogLevel_Debug)) {
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Debug,
- __func__, "Remove route resolve name '%s' to connid %u",
- symbolicOrConnid, connid);
- }
- success = forwarder_RemoveRoute(config->forwarder, control, connid);
- } else {
- if (logger_IsLoggable(config->logger, LoggerFacility_Config,
- PARCLogLevel_Warning)) {
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Warning,
- __func__,
- "Remove route symbolic name '%s' could not be resolved",
- symbolicOrConnid);
- }
- // failure
- }
- }
+ connection_table_t * table = forwarder_get_connection_table(config->forwarder);
+ connection_t * connection;
+ connection_table_foreach(table, connection, {
+ const address_pair_t * pair = connection_get_pair(connection);
+ if (!address_equals(listener_get_address(listener),
+ address_pair_get_local(pair)))
+ continue;
+
+ unsigned conn_id = connection_table_get_connection_id(table, connection);
+ /* Remove connection from the FIB */
+ forwarder_remove_connection_id_from_routes(config->forwarder, conn_id);
+
+ /* Remove connection */
+ connection_table_remove_by_id(table, conn_id);
+
+#if 0
+ const char *symbolicConnection =
+ symbolic_nameTable_GetNameByIndex(config->symbolic_nameTable, conn_id);
+ symbolic_nameTable_Remove(config->symbolic_nameTable, symbolicConnection);
+#endif
+ });
- // generate ACK/NACK
- struct iovec *response;
+ /* Remove listener */
+ listener_table_remove_by_id(listener_table, listener_id);
- if (success) { // ACK
- response = utils_CreateAck(header, control, sizeof(remove_route_command));
- } else { // NACK
- response = utils_CreateNack(header, control, sizeof(remove_route_command));
- }
+ make_ack(msg);
+ return (uint8_t*)msg;
- return response;
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-struct iovec *configuration_ProcessRegistrationList(Configuration *config,
- struct iovec *request) {
- FibEntryList *fibList = forwarder_GetFibEntries(config->forwarder);
-
- size_t payloadSize = fibEntryList_Length(fibList);
- size_t effective_payloadSize = 0;
- size_t pointerLocation = 0;
- struct sockaddr_in tmpAddr;
- struct sockaddr_in6 tmpAddr6;
-
- // allocate payload, cast from void* to uint8_t* = bytes granularity
- uint8_t *payloadResponse =
- parcMemory_AllocateAndClear(sizeof(list_routes_command) * payloadSize);
-
- for (size_t i = 0; i < fibEntryList_Length(fibList); i++) {
- FibEntry *entry = (FibEntry *)fibEntryList_Get(fibList, i);
- NameBitvector *prefix = name_GetContentName(fibEntry_GetPrefix(entry));
- const NumberSet *nexthops = fibEntry_GetNexthops(entry);
-
- if (numberSet_Length(nexthops) == 0)
- continue;
-
- if (numberSet_Length(nexthops) > 1) {
- // payload extended, need reallocate, further entries via nexthops
- payloadSize = payloadSize + numberSet_Length(nexthops) - 1;
- payloadResponse = (uint8_t *) parcMemory_Reallocate(
- payloadResponse, sizeof(list_routes_command) * payloadSize);
+static inline
+void
+fill_listener_command(configuration_t * config, listener_t * listener,
+ cmd_listener_list_item_t * cmd)
+{
+ assert(config);
+ assert(listener);
+ assert(cmd);
+
+ struct sockaddr_in * sin;
+ struct sockaddr_in6 * sin6;
+
+ const address_t * addr = listener_get_address(listener);
+
+ cmd->id = (uint32_t)listener_get_id(listener);
+ cmd->type = (uint8_t)listener_get_type(listener);
+
+ switch(addr->ss_family) {
+ case AF_INET:
+ sin = (struct sockaddr_in *) addr;
+ cmd->family = AF_INET;
+ cmd->address.v4.as_inaddr = sin->sin_addr;
+ cmd->port = sin->sin_port;
+ break;
+ case AF_INET6:
+ sin6 = (struct sockaddr_in6 *) addr;
+ cmd->family = AF_INET6;
+ cmd->address.v6.as_in6addr = sin6->sin6_addr;
+ cmd->port = sin6->sin6_port;
+ break;
+ default:
+ break;
}
- for (size_t j = 0; j < numberSet_Length(nexthops); j++) {
- list_routes_command *listRouteCommand =
- (list_routes_command *)(payloadResponse +
- (pointerLocation *
- sizeof(list_routes_command)));
-
- Address *addressEntry = nameBitvector_ToAddress(prefix);
- if (addressGetType(addressEntry) == ADDR_INET) {
- addressGetInet(addressEntry, &tmpAddr);
- listRouteCommand->addressType = ADDR_INET;
- listRouteCommand->address.v4.as_inaddr = tmpAddr.sin_addr;
- } else if (addressGetType(addressEntry) == ADDR_INET6) {
- addressGetInet6(addressEntry, &tmpAddr6);
- listRouteCommand->addressType = ADDR_INET6;
- listRouteCommand->address.v6.as_in6addr = tmpAddr6.sin6_addr;
- }
- listRouteCommand->connid = numberSet_GetItem(nexthops, j);
- listRouteCommand->len = nameBitvector_GetLength(prefix);
- listRouteCommand->cost = 1; // cost
-
- pointerLocation++;
- effective_payloadSize++;
- addressDestroy(&addressEntry);
- }
- }
+ const char * name = listener_get_name(listener);
+ snprintf(cmd->name, SYMBOLIC_NAME_LEN, "%s", name);
+ const char * interface_name = listener_get_interface_name(listener);
+ snprintf(cmd->interface_name, SYMBOLIC_NAME_LEN, "%s", interface_name);
+}
- // send response
- header_control_message *header = request[0].iov_base;
- header->messageType = RESPONSE_LIGHT;
- header->length = (unsigned)effective_payloadSize;
+uint8_t *
+configuration_on_listener_list(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ listener_table_t * table = forwarder_get_listener_table(config->forwarder);
+ size_t n = listener_table_len(table);
- struct iovec *response =
- parcMemory_AllocateAndClear(sizeof(struct iovec) * 2);
+ msg_listener_list_reply_t * msg;
+ msg_malloc_list(msg, n)
+ if (!msg)
+ return NULL;
- response[0].iov_base = header;
- response[0].iov_len = sizeof(header_control_message);
- response[1].iov_base = payloadResponse;
- response[1].iov_len = sizeof(list_routes_command) * effective_payloadSize;
+ cmd_listener_list_item_t * payload = &msg->payload;
+ listener_t * listener;
+ listener_table_foreach(table, listener, {
+ fill_listener_command(config, listener, payload);
+ payload++;
+ });
- fibEntryList_Destroy(&fibList);
- return response;
+ return (uint8_t*)msg;
}
-static void configuration_SendResponse(Configuration *config, struct iovec *msg,
- unsigned egressId) {
- ConnectionTable *connectionTable =
- forwarder_GetConnectionTable(config->forwarder);
- const Connection *conn = connectionTable_FindById(connectionTable, egressId);
+/* Connection */
- if (conn == NULL) {
- return;
- }
- connection_SendIOVBuffer(conn, msg, 2);
-}
+uint8_t *
+configuration_on_connection_add(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
-struct iovec *configuration_ProcessCreateTunnel(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- add_connection_command *control = request[1].iov_base;
-
- bool success = false;
-
- Connection *conn;
- const char *symbolicName = control->symbolic;
-
- Address *source = NULL;
- Address *destination = NULL;
-
- if (symbolicNameTable_Exists(config->symbolicNameTable, symbolicName)) {
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error,
- __func__, "Connection symbolic name already exists");
- goto ERR;
- }
-
- if (control->ipType == ADDR_INET) {
- source =
- addressFromInaddr4Port(&control->localIp.v4.as_u32, &control->localPort);
- destination =
- addressFromInaddr4Port(&control->remoteIp.v4.as_u32, &control->remotePort);
- } else if (control->ipType == ADDR_INET6) {
- source =
- addressFromInaddr6Port(&control->localIp.v6.as_in6addr, &control->localPort);
- destination =
- addressFromInaddr6Port(&control->remoteIp.v6.as_in6addr, &control->remotePort);
- } else {
- printf("Invalid IP type.\n"); // will generate a Nack
- }
-
- AddressPair *pair = addressPair_Create(source, destination);
- conn = (Connection *)connectionTable_FindByAddressPair(
- forwarder_GetConnectionTable(config->forwarder), pair);
-
- addressPair_Release(&pair);
-
- if (!conn) {
- IoOperations *ops = NULL;
- switch (control->connectionType) {
- case TCP_CONN:
- // logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error,
- // __func__,
- // "Unsupported tunnel protocol: TCP");
- ops = tcpTunnel_Create(config->forwarder, source, destination);
- break;
- case UDP_CONN:
- ops = udpTunnel_Create(config->forwarder, source, destination);
- break;
- case GRE_CONN:
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error,
- __func__, "Unsupported tunnel protocol: GRE");
- break;
-#if !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
- case HICN_CONN:
- ops = hicnTunnel_Create(config->forwarder, source, destination);
- break;
-#endif /* __APPLE__ _WIN32*/
- default:
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error,
- __func__, "Unsupported tunnel protocol: %d",
- control->connectionType);
- break;
- }
+ msg_connection_add_t * msg = (msg_connection_add_t*)packet;
+ cmd_connection_add_t * control = &msg->payload;
- if (ops != NULL) {
- Connection *conn = connection_Create(ops);
-#ifdef WITH_POLICY
- connection_SetTags(conn, control->tags);
- connection_SetPriority(conn, control->priority);
-#endif /* WITH_POLICY */
+ const char *symbolic_name = control->symbolic;
- connection_SetAdminState(conn, control->admin_state);
+ face_type_t face_type;
+ if (!face_type_is_defined(control->type))
+ goto NACK;
+ face_type = (face_type_t)control->type;
- connectionTable_Add(forwarder_GetConnectionTable(config->forwarder),
- conn);
- symbolicNameTable_Add(config->symbolicNameTable, symbolicName,
- connection_GetConnectionId(conn));
+ connection_table_t * table = forwarder_get_connection_table(config->forwarder);
+ if (connection_table_get_by_name(table, symbolic_name)) {
+ ERROR("Connection symbolic name already exists");
+ goto NACK;
+ }
+
+ address_pair_t pair;
+ if (address_pair_from_ip_port(&pair, control->family,
+ &control->local_ip, control->local_port,
+ &control->remote_ip, control->remote_port) < 0)
+ goto NACK;
+ connection_t * connection = connection_table_get_by_pair(table, &pair);
#ifdef WITH_MAPME
- /* Hook: new connection created through the control protocol */
- forwarder_onConnectionEvent(config->forwarder, conn, CONNECTION_EVENT_CREATE);
+ connection_event_t event;
#endif /* WITH_MAPME */
- success = true;
+ if (!connection) {
+ connection = connection_create(face_type, symbolic_name, &pair, config->forwarder);
+ if (!connection) {
+ ERROR("Failed to create %s connection",
+ face_type_str(connection->type));
+ goto NACK;
+ }
- } else {
- printf("failed, could not create IoOperations");
- }
+#ifdef WITH_MAPME
+ event = CONNECTION_EVENT_CREATE;
+#endif /* WITH_MAPME */
- } else {
+ } else {
#ifdef WITH_POLICY
- connection_SetTags(conn, control->tags);
- connection_SetPriority(conn, control->priority);
- connection_SetAdminState(conn, control->admin_state);
-
#ifdef WITH_MAPME
- /* Hook: new connection created through the control protocol */
- forwarder_onConnectionEvent(config->forwarder, conn, CONNECTION_EVENT_UPDATE);
+ event = CONNECTION_EVENT_UPDATE;
#endif /* WITH_MAPME */
- if (source)
- addressDestroy(&source);
- if (destination)
- addressDestroy(&destination);
-
- success = true;
#else
- printf("failed, symbolic name or connection already exist\n");
+ ERROR("failed, symbolic name or connection already exist\n");
+ goto NACK;
#endif /* WITH_POLICY */
- }
-
- if (source)
- addressDestroy(&source);
- if (destination)
- addressDestroy(&destination);
-
- if (!success)
- goto ERR;
-
- // ACK
- return utils_CreateAck(header, control, sizeof(add_connection_command));
+ }
-ERR:
- return utils_CreateNack(header, control, sizeof(add_connection_command));
-}
+#ifdef WITH_POLICY
+ connection_set_tags(connection, control->tags);
+ connection_set_priority(connection, control->priority);
+#endif /* WITH_POLICY */
-struct iovec *configuration_ProcessRemoveListener(Configuration *config,
- struct iovec *request,
- unsigned ingressId) {
- header_control_message *header = request[0].iov_base;
- remove_listener_command *control = request[1].iov_base;
-
- bool success = false;
-
- const char *symbolicOrListenerid = control->symbolicOrListenerid;
- int listenerId = -1;
- ListenerSet *listenerSet = forwarder_GetListenerSet(config->forwarder);
- if (utils_IsNumber(symbolicOrListenerid)) {
- // case for connid as input
- listenerId = (unsigned)strtold(symbolicOrListenerid, NULL);
- } else {
- listenerId = listenerSet_FindIdByListenerName(listenerSet, symbolicOrListenerid);
- }
-
- if (listenerId >= 0) {
-
- ConnectionTable *connTable = forwarder_GetConnectionTable(config->forwarder);
- ListenerOps *listenerOps = listenerSet_FindById(listenerSet, listenerId);
- if (listenerOps) {
- ConnectionList *connectionList = connectionTable_GetEntries(connTable);
- for (size_t i = 0; i < connectionList_Length(connectionList); i++) {
- Connection *connection = connectionList_Get(connectionList, i);
- const AddressPair *addressPair = connection_GetAddressPair(connection);
- const Address *address = addressPair_GetLocal(addressPair);
- if (addressEquals(listenerOps->getListenAddress(listenerOps),address)) {
- // case for connid as input
- unsigned connid = connection_GetConnectionId(connection);
- // remove connection from the FIB
- forwarder_RemoveConnectionIdFromRoutes(config->forwarder, connid);
- // remove connection
- connectionTable_RemoveById(connTable, connid);
- const char *symbolicConnection = symbolicNameTable_GetNameByIndex(config->symbolicNameTable,connid);
- symbolicNameTable_Remove(config->symbolicNameTable, symbolicConnection);
- }
- }
- connectionList_Destroy(&connectionList);
- // remove listener
- listenerSet_RemoveById(listenerSet, listenerId);
- success = true;
- } else {
- logger_Log(forwarder_GetLogger(config->forwarder), LoggerFacility_IO,
- PARCLogLevel_Error, __func__,
- "Listener Id not found, check list listeners");
- }
- }
+ connection_set_admin_state(connection, control->admin_state);
- // generate ACK/NACK
- struct iovec *response;
+#ifdef WITH_MAPME
+ /* Hook: new connection created through the control protocol */
+ forwarder_on_connection_event(config->forwarder, connection, event);
+#endif /* WITH_MAPME */
- if (success) { // ACK
- response =
- utils_CreateAck(header, control, sizeof(remove_listener_command));
- } else { // NACK
- response =
- utils_CreateNack(header, control, sizeof(remove_connection_command));
- }
+ make_ack(msg);
+ return (uint8_t*)msg;
- return response;
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
}
/**
* Add an IP-based tunnel.
*
- * The call cal fail if the symbolic name is a duplicate. It could also fail if
+ * The call can fail if the symbolic name is a duplicate. It could also fail if
* there's an problem creating the local side of the tunnel (i.e. the local
* socket address is not usable).
*
@@ -558,952 +451,966 @@ struct iovec *configuration_ProcessRemoveListener(Configuration *config,
* @return false Tunnel not added (an error)
*/
-struct iovec *configuration_ProcessRemoveTunnel(Configuration *config,
- struct iovec *request,
- unsigned ingressId) {
- header_control_message *header = request[0].iov_base;
- remove_connection_command *control = request[1].iov_base;
+uint8_t *
+configuration_on_connection_remove(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
- bool success = false;
+ msg_connection_remove_t * msg = (msg_connection_remove_t*)packet;
+ cmd_connection_remove_t * control = &msg->payload;
- const char *symbolicOrConnid = control->symbolicOrConnid;
- ConnectionTable *table = forwarder_GetConnectionTable(config->forwarder);
- if (strcmp(symbolicOrConnid, "SELF") == 0) {
- forwarder_RemoveConnectionIdFromRoutes(config->forwarder, ingressId);
- connectionTable_RemoveById(table, ingressId);
+ unsigned conn_id = symbolic_to_conn_id_self(config, control->symbolicOrConnid,
+ ingress_id);
+ if (!connection_id_is_valid(conn_id))
+ goto NACK;
-#ifdef WITH_MAPME
- /* Hook: new connection created through the control protocol */
- forwarder_onConnectionEvent(config->forwarder, NULL, CONNECTION_EVENT_DELETE);
-#endif /* WITH_MAPME */
+ /* Remove connection from the FIB */
+ forwarder_remove_connection_id_from_routes(config->forwarder, conn_id);
- success = true;
- } else if (utils_IsNumber(symbolicOrConnid)) {
- // case for connid as input
- unsigned connid = (unsigned)strtold(symbolicOrConnid, NULL);
-
- // check if interface index present in the fwd table
- //(it was missing and therefore caused a program crash)
- if (connectionTable_FindById(table, connid)) {
- // remove connection from the FIB
- forwarder_RemoveConnectionIdFromRoutes(config->forwarder, connid);
- // remove connection
- connectionTable_RemoveById(table, connid);
- // remove connection from symbolicNameTable
- const char *symbolicConnection = symbolicNameTable_GetNameByIndex(config->symbolicNameTable,connid);
- symbolicNameTable_Remove(config->symbolicNameTable, symbolicConnection);
+ /* Remove connection */
+ connection_table_t *table = forwarder_get_connection_table(config->forwarder);
+ connection_table_remove_by_id(table, conn_id);
+
+#if 0
+ /* Remove connection from symbolic_nameTable */
+ const char *symbolicConnection = symbolic_nameTable_GetNameByIndex(config->symbolic_nameTable, conn_id);
+ symbolic_nameTable_Remove(config->symbolic_nameTable, symbolicConnection);
+#endif
#ifdef WITH_MAPME
- /* Hook: new connection created through the control protocol */
- forwarder_onConnectionEvent(config->forwarder, NULL, CONNECTION_EVENT_DELETE);
+ /* Hook: new connection created through the control protocol */
+ forwarder_on_connection_event(config->forwarder, NULL, CONNECTION_EVENT_DELETE);
#endif /* WITH_MAPME */
- success = true;
- } else {
- logger_Log(forwarder_GetLogger(config->forwarder), LoggerFacility_IO,
- PARCLogLevel_Error, __func__,
- "ConnID not found, check list connections");
- // failure
- }
+ make_ack(msg);
+ return (uint8_t*)msg;
- } else {
- // case for symbolic as input
- // chech if symbolic name can be resolved
- unsigned connid =
- symbolicNameTable_Get(config->symbolicNameTable, symbolicOrConnid);
- // connid = UINT_MAX when symbolicName is not found
- if (connid != UINT32_MAX) {
- if (logger_IsLoggable(config->logger, LoggerFacility_Config,
- PARCLogLevel_Debug)) {
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Debug,
- __func__, "Remove connection resolve name '%s' to connid %u",
- symbolicOrConnid, connid);
- }
-
- // remove connection from the FIB
- forwarder_RemoveConnectionIdFromRoutes(config->forwarder, connid);
- // remove connection
- connectionTable_RemoveById(table, connid);
- // remove connection from symbolicNameTable since we have symbolic input
- symbolicNameTable_Remove(config->symbolicNameTable, symbolicOrConnid);
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
+}
-#ifdef WITH_MAPME
- /* Hook: new connection created through the control protocol */
- forwarder_onConnectionEvent(config->forwarder, NULL, CONNECTION_EVENT_DELETE);
-#endif /* WITH_MAPME */
+static inline
+void
+tolower_str(char * str) {
+ char * p = str;
+ for (; *p; p++)
+ *p = tolower(*p);
+}
- success = true; // to write
- } else {
- if (logger_IsLoggable(config->logger, LoggerFacility_Config,
- PARCLogLevel_Warning)) {
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error,
- __func__,
- "Remove connection symbolic name '%s' could not be resolved",
- symbolicOrConnid);
- }
- // failure
- }
- }
+static inline
+void
+fill_connections_command(configuration_t * config, connection_t * connection,
+ cmd_connection_list_item_t * cmd)
+{
+ assert(config);
+ assert(connection);
+ assert(cmd);
+ struct sockaddr_in * sin;
+ struct sockaddr_in6 * sin6;
+ const address_pair_t * pair = connection_get_pair(connection);
+#if 0
+ const char *name = symbolic_nameTable_GetNameByIndex(config->symbolic_nameTable,
+ connection_get_id(connection));
+#endif
+
+ *cmd = (cmd_connection_list_item_t) {
+ .id = connection_get_id(connection),
+ .state = connection_get_state(connection),
+ .admin_state = connection_get_admin_state(connection),
+ .type = connection_get_type(connection),
+#ifdef WITH_POLICY
+ .priority = connection_get_priority(connection),
+ .tags = connection_get_tags(connection),
+#endif /* WITH_POLICY */
+ };
+
+ snprintf(cmd->name, SYMBOLIC_NAME_LEN, "%s", connection_get_name(connection));
+ tolower_str(cmd->name);
+
+ snprintf(cmd->interface_name, SYMBOLIC_NAME_LEN, "%s",
+ connection_get_interface_name(connection));
+
+ switch(pair->local.ss_family) {
+ case AF_INET:
+ cmd->family = AF_INET;
+
+ sin = (struct sockaddr_in *)(&pair->local);
+ cmd->local_port = sin->sin_port;
+ cmd->local_ip.v4.as_inaddr = sin->sin_addr;
- // generate ACK/NACK
- struct iovec *response;
+ sin = (struct sockaddr_in *)(&pair->remote);
+ cmd->remote_port = sin->sin_port;
+ cmd->remote_ip.v4.as_inaddr = sin->sin_addr;
+ break;
- if (success) { // ACK
- response =
- utils_CreateAck(header, control, sizeof(remove_connection_command));
- } else { // NACK
- response =
- utils_CreateNack(header, control, sizeof(remove_connection_command));
- }
+ case AF_INET6:
+ cmd->family = AF_INET6;
- return response;
+ sin6 = (struct sockaddr_in6 *)(&pair->local);
+ cmd->local_port = sin6->sin6_port;
+ cmd->local_ip.v6.as_in6addr = sin6->sin6_addr;
+
+ sin6 = (struct sockaddr_in6 *)(&pair->remote);
+ cmd->remote_port = sin6->sin6_port;
+ cmd->remote_ip.v6.as_in6addr = sin6->sin6_addr;
+ break;
+
+ default:
+ break;
+ }
}
-void _parc_strlwr(char *string) {
- char *p = string;
- while ((*p = tolower(*p))) {
- p++;
- }
+uint8_t *
+configuration_on_connection_list(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ connection_table_t *table = forwarder_get_connection_table(config->forwarder);
+ size_t n = connection_table_len(table);
+
+ msg_connection_list_reply_t * msg;
+ msg_malloc_list(msg, n)
+ if (!msg)
+ return NULL;
+
+ cmd_connection_list_item_t * payload = &msg->payload;
+ connection_t * connection;
+ connection_table_foreach(table, connection, {
+ fill_connections_command(config, connection, payload);
+ payload++;
+ });
+
+ return (uint8_t*)msg;
}
-struct iovec *configuration_ProcessConnectionList(Configuration *config,
- struct iovec *request) {
- ConnectionTable *table = forwarder_GetConnectionTable(config->forwarder);
- ConnectionList *connList = connectionTable_GetEntries(table);
- struct sockaddr_in tmpAddr;
- struct sockaddr_in6 tmpAddr6;
+uint8_t *
+configuration_on_connection_set_admin_state(configuration_t * config,
+ uint8_t * packet, unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
- // allocate payload, cast from void* to uint8_t* fot bytes granularity
- uint8_t *payloadResponse = parcMemory_AllocateAndClear(
- sizeof(list_connections_command) * connectionList_Length(connList));
+ msg_connection_set_admin_state_t * msg = (msg_connection_set_admin_state_t *)packet;
+ cmd_connection_set_admin_state_t *control = &msg->payload;
- for (size_t i = 0; i < connectionList_Length(connList); i++) {
- // Don't release original, it is not stored
- Connection *original = connectionList_Get(connList, i);
+ if ((control->admin_state != FACE_STATE_UP) &&
+ (control->admin_state != FACE_STATE_DOWN))
+ goto NACK;
- const AddressPair *addressPair = connection_GetAddressPair(original);
- Address *localAddress = addressCopy(addressPair_GetLocal(addressPair));
- Address *remoteAddress = addressCopy(addressPair_GetRemote(addressPair));
+ connection_t * conn = getConnectionBySymbolicOrId(config, control->symbolicOrConnid);
+ if (!conn)
+ goto NACK;
- // Fill payload by shifting and casting at each 'i' step.
- list_connections_command *listConnectionsCommand =
- (list_connections_command *)(payloadResponse +
- (i * sizeof(list_connections_command)));
- // set structure fields
+ connection_set_admin_state(conn, control->admin_state);
- listConnectionsCommand->connid = connection_GetConnectionId(original);
+#ifdef WITH_MAPME
+ /* Hook: connection event */
+ forwarder_on_connection_event(config->forwarder, conn,
+ control->admin_state == FACE_STATE_UP
+ ? CONNECTION_EVENT_SET_UP
+ : CONNECTION_EVENT_SET_DOWN);
+#endif /* WITH_MAPME */
- const char *connectionName = symbolicNameTable_GetNameByIndex(config->symbolicNameTable, connection_GetConnectionId(original));
- snprintf(listConnectionsCommand->connectionName, SYMBOLIC_NAME_LEN, "%s", connectionName);
- _parc_strlwr(listConnectionsCommand->connectionName);
+ make_ack(msg);
+ return (uint8_t*)msg;
- snprintf(listConnectionsCommand->interfaceName, SYMBOLIC_NAME_LEN, "%s", ioOperations_GetInterfaceName(connection_GetIoOperations(original)));
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
+}
- listConnectionsCommand->state =
- connection_IsUp(original) ? IFACE_UP : IFACE_DOWN;
- listConnectionsCommand->connectionData.admin_state =
- (connection_GetAdminState(original) == CONNECTION_STATE_UP) ? IFACE_UP : IFACE_DOWN;
- listConnectionsCommand->connectionData.connectionType =
- ioOperations_GetConnectionType(connection_GetIoOperations(original));
- listConnectionsCommand->connectionData.admin_state = connection_GetAdminState(original);
+uint8_t *
+configuration_on_connection_update(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
#ifdef WITH_POLICY
- listConnectionsCommand->connectionData.priority = connection_GetPriority(original);
- listConnectionsCommand->connectionData.tags = connection_GetTags(original);
-#endif /* WITH_POLICY */
+ msg_connection_update_t * msg = (msg_connection_update_t *)packet;
+ cmd_connection_update_t * control = &msg->payload;
+
+ connection_t * conn = getConnectionBySymbolicOrId(config, control->symbolicOrConnid);
+ if (!conn)
+ goto NACK;
+
+ connection_set_tags(conn, control->tags);
+ connection_set_admin_state(conn, control->admin_state);
+ if (control->priority > 0)
+ connection_set_priority(conn, control->priority);
- if (addressGetType(localAddress) == ADDR_INET &&
- addressGetType(remoteAddress) == ADDR_INET) {
- listConnectionsCommand->connectionData.ipType = ADDR_INET;
-
- // get local port/address
- addressGetInet(localAddress, &tmpAddr);
- listConnectionsCommand->connectionData.localPort = tmpAddr.sin_port;
- listConnectionsCommand->connectionData.localIp.v4.as_inaddr =
- tmpAddr.sin_addr;
- memset(&tmpAddr, 0, sizeof(tmpAddr));
- // get remote port/address
- addressGetInet(remoteAddress, &tmpAddr);
- listConnectionsCommand->connectionData.remotePort = tmpAddr.sin_port;
- listConnectionsCommand->connectionData.remoteIp.v4.as_inaddr =
- tmpAddr.sin_addr;
-
- } else if (addressGetType(localAddress) == ADDR_INET6 &&
- addressGetType(remoteAddress) == ADDR_INET6) {
- listConnectionsCommand->connectionData.ipType = ADDR_INET6;
-
- // get local port/address
- addressGetInet6(localAddress, &tmpAddr6);
- listConnectionsCommand->connectionData.localPort = tmpAddr6.sin6_port;
- listConnectionsCommand->connectionData.localIp.v6.as_in6addr = tmpAddr6.sin6_addr;
- memset(&tmpAddr6, 0, sizeof(tmpAddr6));
- // get remote port/address
- addressGetInet6(remoteAddress, &tmpAddr6);
- listConnectionsCommand->connectionData.remotePort = tmpAddr6.sin6_port;
- listConnectionsCommand->connectionData.remoteIp.v6.as_in6addr = tmpAddr6.sin6_addr;
-
- } // no need further else, control on the addressed already done at the
- // time of insertion in the connection table
- addressDestroy(&localAddress);
- addressDestroy(&remoteAddress);
- }
-
- // send response
- header_control_message *header = request[0].iov_base;
- header->messageType = RESPONSE_LIGHT;
- header->length = (uint16_t)connectionList_Length(connList);
-
- struct iovec *response =
- parcMemory_AllocateAndClear(sizeof(struct iovec) * 2);
-
- response[0].iov_base = header;
- response[0].iov_len = sizeof(header_control_message);
- response[1].iov_base = payloadResponse;
- response[1].iov_len =
- sizeof(list_connections_command) * connectionList_Length(connList);
-
- connectionList_Destroy(&connList);
- return response;
+ make_ack(msg);
+ return (uint8_t*)msg;
+
+NACK:
+#endif /* WITH_POLICY */
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-struct iovec *configuration_ProcessListenersList(Configuration *config,
- struct iovec *request) {
- ListenerSet *listenerList = forwarder_GetListenerSet(config->forwarder);
- struct sockaddr_in tmpAddr;
- struct sockaddr_in6 tmpAddr6;
-
- // allocate payload, cast from void* to uint8_t* fot bytes granularity
- uint8_t *payloadResponse = parcMemory_AllocateAndClear(
- sizeof(list_listeners_command) * listenerSet_Length(listenerList));
-
- for (size_t i = 0; i < listenerSet_Length(listenerList); i++) {
- ListenerOps *listenerEntry = listenerSet_Get(listenerList, i);
-
- // Fill payload by shifting and casting at each 'i' step.
- list_listeners_command *listListenersCommand =
- (list_listeners_command *)(payloadResponse +
- (i * sizeof(list_listeners_command)));
-
- listListenersCommand->connid =
- (uint32_t)listenerEntry->getInterfaceIndex(listenerEntry);
- listListenersCommand->encapType =
- (uint8_t)listenerEntry->getEncapType(listenerEntry);
- if (addressGetType((const Address *)listenerEntry->getListenAddress(
- listenerEntry)) == ADDR_INET) {
- addressGetInet(
- (const Address *)listenerEntry->getListenAddress(listenerEntry),
- &tmpAddr);
- listListenersCommand->addressType = ADDR_INET;
- listListenersCommand->address.v4.as_inaddr = tmpAddr.sin_addr;
- listListenersCommand->port = tmpAddr.sin_port;
- } else if (addressGetType((const Address *)listenerEntry->getListenAddress(
- listenerEntry)) == ADDR_INET6) {
- addressGetInet6(
- (const Address *)listenerEntry->getListenAddress(listenerEntry),
- &tmpAddr6);
- listListenersCommand->addressType = ADDR_INET6;
- listListenersCommand->address.v6.as_in6addr = tmpAddr6.sin6_addr;
- listListenersCommand->port = tmpAddr6.sin6_port;
- }
+uint8_t *
+configuration_on_connection_set_priority(configuration_t * config,
+ uint8_t * packet, unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
- const char * listenerName = listenerEntry->getListenerName(listenerEntry);
- snprintf(listListenersCommand->listenerName, SYMBOLIC_NAME_LEN, "%s", listenerName);
- if (listenerEntry->getEncapType(listenerEntry) == ENCAP_TCP ||
- listenerEntry->getEncapType(listenerEntry) == ENCAP_UDP) {
- const char * interfaceName = listenerEntry->getInterfaceName(listenerEntry);
- snprintf(listListenersCommand->interfaceName, SYMBOLIC_NAME_LEN, "%s", interfaceName);
- }
- }
+#ifdef WITH_POLICY
+ msg_connection_set_priority_t * msg = (msg_connection_set_priority_t *)packet;
+ cmd_connection_set_priority_t * control = &msg->payload;
- // send response
- header_control_message *header = request[0].iov_base;
- header->messageType = RESPONSE_LIGHT;
- header->length = (uint16_t)listenerSet_Length(listenerList);
+ connection_t * conn = getConnectionBySymbolicOrId(config, control->symbolicOrConnid);
+ if (!conn)
+ goto NACK;
- struct iovec *response =
- parcMemory_AllocateAndClear(sizeof(struct iovec) * 2);
+ connection_set_priority(conn, control->priority);
- response[0].iov_base = header;
- response[0].iov_len = sizeof(header_control_message);
- response[1].iov_base = payloadResponse;
- response[1].iov_len =
- sizeof(list_listeners_command) * listenerSet_Length(listenerList);
+#ifdef WITH_MAPME
+ /* Hook: connection event */
+ forwarder_on_connection_event(config->forwarder, conn,
+ CONNECTION_EVENT_PRIORITY_CHANGED);
+#endif /* WITH_MAPME */
- return response;
-}
+ make_ack(msg);
+ return (uint8_t*)msg;
-struct iovec *configuration_ProcessCacheStore(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- ;
- cache_store_command *control = request[1].iov_base;
- ;
-
- bool success = false;
-
- switch (control->activate) {
- case ACTIVATE_ON:
- forwarder_SetChacheStoreFlag(config->forwarder, true);
- if (forwarder_GetChacheStoreFlag(config->forwarder)) {
- success = true;
- }
- break;
-
- case ACTIVATE_OFF:
- forwarder_SetChacheStoreFlag(config->forwarder, false);
- if (!forwarder_GetChacheStoreFlag(config->forwarder)) {
- success = true;
- }
- break;
-
- default:
- break;
- }
-
- struct iovec *response;
- if (success) { // ACK
- response = utils_CreateAck(header, control, sizeof(cache_store_command));
- } else { // NACK
- response = utils_CreateNack(header, control, sizeof(cache_store_command));
- }
-
- return response;
+NACK:
+#endif /* WITH_POLICY */
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-struct iovec *configuration_ProcessCacheServe(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- cache_serve_command *control = request[1].iov_base;
-
- bool success = false;
-
- switch (control->activate) {
- case ACTIVATE_ON:
- forwarder_SetChacheServeFlag(config->forwarder, true);
- if (forwarder_GetChacheServeFlag(config->forwarder)) {
- success = true;
- }
- break;
-
- case ACTIVATE_OFF:
- forwarder_SetChacheServeFlag(config->forwarder, false);
- if (!forwarder_GetChacheServeFlag(config->forwarder)) {
- success = true;
- }
- break;
-
- default:
- break;
- }
-
- struct iovec *response;
- if (success) { // ACK
- response = utils_CreateAck(header, control, sizeof(cache_store_command));
- } else { // NACK
- response = utils_CreateNack(header, control, sizeof(cache_store_command));
- }
-
- return response;
-}
+uint8_t *
+configuration_on_connection_set_tags(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+#ifdef WITH_POLICY
+ msg_connection_set_tags_t * msg = (msg_connection_set_tags_t *)packet;
+ cmd_connection_set_tags_t * control = &msg->payload;
-struct iovec *configuration_ProcessCacheClear(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
+ connection_t * conn = getConnectionBySymbolicOrId(config, control->symbolicOrConnid);
+ if (!conn)
+ goto NACK;
- forwarder_ClearCache(config->forwarder);
+ connection_set_tags(conn, control->tags);
- struct iovec *response = utils_CreateAck(header, NULL, 0);
- return response;
-}
+#ifdef WITH_MAPME
+ /* Hook: connection event */
+ forwarder_on_connection_event(config->forwarder, conn,
+ CONNECTION_EVENT_TAGS_CHANGED);
+#endif /* WITH_MAPME */
-size_t configuration_GetObjectStoreSize(Configuration *config) {
- return config->maximumContentObjectStoreSize;
+ make_ack(msg);
+ return (uint8_t*)msg;
+
+NACK:
+#endif /* WITH_POLICY */
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-void _configuration_StoreFwdStrategy(Configuration *config, const char *prefix,
- strategy_type strategy) {
- PARCString *prefixStr = parcString_Create(prefix);
- PARCUnsigned *strategyValue = parcUnsigned_Create((unsigned)strategy);
- parcHashMap_Put(config->strategy_map, prefixStr, strategyValue);
- parcUnsigned_Release(&strategyValue);
- parcString_Release(&prefixStr);
+
+/* Route */
+
+uint8_t *
+configuration_on_route_add(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ msg_route_add_t * msg = (msg_route_add_t *)packet;
+ cmd_route_add_t * control = &msg->payload;
+
+ unsigned conn_id = symbolic_to_conn_id_self(config,
+ control->symbolicOrConnid, ingress_id);
+ if (!connection_id_is_valid(conn_id))
+ goto NACK;
+
+ ip_prefix_t prefix = {
+ .family = control->family,
+ .address = control->address,
+ .len = control->len
+ };
+
+ if (!forwarder_add_or_update_route(config->forwarder, &prefix, conn_id))
+ goto NACK;
+
+ make_ack(msg);
+ return (uint8_t*)msg;
+
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-struct iovec *configuration_SetWldr(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- set_wldr_command *control = request[1].iov_base;
- ConnectionTable *table = forwarder_GetConnectionTable(config->forwarder);
- Connection *conn = NULL;
- bool success = false;
-
- const char *symbolicOrConnid = control->symbolicOrConnid;
-
- if (utils_IsNumber(symbolicOrConnid)) {
- // case for connid as input: check if connID present in the fwd table
- conn = (Connection *)connectionTable_FindById(
- table, (unsigned)strtold(symbolicOrConnid, NULL));
- if (conn) {
- success = true;
- } else {
- logger_Log(forwarder_GetLogger(config->forwarder), LoggerFacility_IO,
- PARCLogLevel_Error, __func__,
- "ConnID not found, check list connections"); // failure
- }
- } else {
- // case for symbolic as input: check if symbolic name can be resolved
- unsigned connid =
- symbolicNameTable_Get(config->symbolicNameTable, symbolicOrConnid);
- if (connid != UINT32_MAX) {
- conn = (Connection *)connectionTable_FindById(table, connid);
- if (conn) {
- if (logger_IsLoggable(config->logger, LoggerFacility_Config,
- PARCLogLevel_Debug)) {
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Debug,
- __func__, "Set wldr resolve name '%s' to connid %u",
- symbolicOrConnid, connid);
- }
- success = true;
- }
- } else {
- if (logger_IsLoggable(config->logger, LoggerFacility_Config,
- PARCLogLevel_Warning)) {
- logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error,
- __func__, "Symbolic name '%s' could not be resolved",
- symbolicOrConnid);
- } // failure
- }
- }
-
- // generate ACK/NACK
- struct iovec *response;
-
- if (success) {
- switch (control->activate) {
- case ACTIVATE_ON:
- connection_EnableWldr(conn);
- response = utils_CreateAck(header, control, sizeof(set_wldr_command));
- break;
-
- case ACTIVATE_OFF:
- connection_DisableWldr(conn);
- response = utils_CreateAck(header, control, sizeof(set_wldr_command));
- break;
-
- default: // received wrong value
- response = utils_CreateNack(header, control, sizeof(set_wldr_command));
- break;
- }
- } else {
- response = utils_CreateNack(header, control, sizeof(set_wldr_command));
- }
+uint8_t *
+configuration_on_route_remove(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ msg_route_remove_t * msg = (msg_route_remove_t *)packet;
+ cmd_route_remove_t * control = &msg->payload;
+
+ unsigned conn_id = symbolic_to_conn_id(config, control->symbolicOrConnid);
+ if (!connection_id_is_valid(conn_id))
+ goto NACK;
+
+ ip_prefix_t prefix = {
+ .family = control->family,
+ .address = control->address,
+ .len = control->len
+ };
+
+ if (!forwarder_remove_route(config->forwarder, &prefix, conn_id))
+ goto NACK;
- return response;
+ make_ack(msg);
+ return (uint8_t*)msg;
+
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-strategy_type configuration_GetForwardingStrategy(Configuration *config,
- const char *prefix) {
- PARCString *prefixStr = parcString_Create(prefix);
- const unsigned *val = parcHashMap_Get(config->strategy_map, prefixStr);
- parcString_Release(&prefixStr);
-
- if (val == NULL) {
- return LAST_STRATEGY_VALUE;
- } else {
- return (strategy_type)*val;
- }
+uint8_t *
+configuration_on_route_list(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ const fib_t * fib = forwarder_get_fib(config->forwarder);
+ fib_entry_t * entry;
+
+ /*
+ * Two step approach to precompute the number of entries to allocate
+ *
+ * NOTE: we might have routes with no or multiple next hops.
+ */
+ size_t n = 0;
+ fib_foreach_entry(fib, entry, {
+ const nexthops_t * nexthops = fib_entry_get_nexthops(entry);
+ assert(nexthops_get_len(nexthops) == nexthops_get_curlen(nexthops));
+ n += nexthops_get_len(nexthops);
+ });
+
+ msg_route_list_reply_t * msg;
+ msg_malloc_list(msg, n);
+ if (!msg)
+ return NULL;
+
+ cmd_route_list_item_t * payload = &msg->payload;
+ fib_foreach_entry(fib, entry, {
+ const nexthops_t * nexthops = fib_entry_get_nexthops(entry);
+ assert(nexthops_get_len(nexthops) == nexthops_get_curlen(nexthops));
+ size_t num_nexthops = nexthops_get_len(nexthops);
+
+ if (num_nexthops == 0)
+ continue;
+
+ NameBitvector *prefix = name_GetContentName(fib_entry_get_prefix(entry));
+
+ unsigned nexthop;
+ nexthops_foreach(nexthops, nexthop, {
+
+ address_t address;
+ nameBitvector_ToAddress(prefix, &address);
+ switch(address_family(&address)) {
+ case AF_INET:
+ payload->family = AF_INET;
+ payload->address.v4.as_inaddr = address4_ip(&address);
+ break;
+ case AF_INET6:
+ payload->family = AF_INET6;
+ payload->address.v6.as_in6addr = address6_ip(&address);
+ break;
+ default:
+ break;
+ }
+ payload->connection_id = nexthop;
+ payload->len = nameBitvector_GetLength(prefix);
+ payload->cost = DEFAULT_COST;
+
+ payload++;
+ });
+ });
+
+ return (uint8_t*)msg;
}
-struct iovec *configuration_SetForwardingStrategy(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- set_strategy_command *control = request[1].iov_base;
-
- const char *prefix = utils_PrefixLenToString(
- control->addressType, &control->address, &control->len);
- strategy_type strategy = control->strategyType;
- strategy_type existingFwdStrategy =
- configuration_GetForwardingStrategy(config, prefix);
-
- if (existingFwdStrategy == LAST_STRATEGY_VALUE ||
- strategy != existingFwdStrategy) {
- // means such a new strategy is not present in the hash table or has to be
- // updated
- _configuration_StoreFwdStrategy(config, prefix, strategy);
- Name *hicnPrefix = name_CreateFromAddress(control->addressType,
- control->address, control->len);
- Name *related_prefixes[MAX_FWD_STRATEGY_RELATED_PREFIXES];
- if(control->related_prefixes != 0){
- for(int i = 0; i < control->related_prefixes; i++){
- related_prefixes[i] = name_CreateFromAddress(
- control->addresses_type[i],
- control->addresses[i], control->lens[i]);
- }
- }
- forwarder_SetStrategy(config->forwarder, hicnPrefix, strategy,
- control->related_prefixes, related_prefixes);
- name_Release(&hicnPrefix);
- if(control->related_prefixes != 0){
- for(int i = 0; i < control->related_prefixes; i++){
- name_Release(&related_prefixes[i]);
- }
- }
- }
- free((char *) prefix);
- struct iovec *response =
- utils_CreateAck(header, control, sizeof(set_strategy_command));
+/* Cache */
- return response;
-}
+uint8_t *
+configuration_on_cache_set_store(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ msg_cache_set_store_t * msg = (msg_cache_set_store_t *)packet;
+ cmd_cache_set_store_t * control = &msg->payload;
+
+ if ((control->activate != 0) && (control->activate != 1))
+ goto NACK;
+ bool value = (bool)control->activate;
-void configuration_SetObjectStoreSize(Configuration *config,
- size_t maximumObjectCount) {
- config->maximumContentObjectStoreSize = maximumObjectCount;
+ forwarder_content_store_set_store(config->forwarder, value);
+ /* XXX Why do we need to check ? */
+ if (forwarder_content_store_get_store(config->forwarder) != value)
+ goto NACK;
- forwarder_SetContentObjectStoreSize(config->forwarder,
- config->maximumContentObjectStoreSize);
+ make_ack(msg);
+ return (uint8_t*)msg;
+
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-Forwarder *configuration_GetForwarder(const Configuration *config) {
- return config->forwarder;
+uint8_t *
+configuration_on_cache_set_serve(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ msg_cache_set_serve_t * msg = (msg_cache_set_serve_t *)packet;
+ cmd_cache_set_serve_t * control = &msg->payload;
+
+ if ((control->activate != 0) && (control->activate != 1))
+ goto NACK;
+ bool value = (bool)control->activate;
+
+ forwarder_content_store_set_serve(config->forwarder, value);
+ /* XXX Why do we need to check ? */
+ if (forwarder_content_store_get_serve(config->forwarder) != value)
+ goto NACK;
+
+ make_ack(msg);
+ return (uint8_t*)msg;
+
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-Logger *configuration_GetLogger(const Configuration *config) {
- return config->logger;
+uint8_t *
+configuration_on_cache_clear(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ msg_cache_clear_t * msg = (msg_cache_clear_t *)packet;
+
+ forwarder_content_store_clear(config->forwarder);
+
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-struct iovec *configuration_MapMeEnable(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- mapme_activator_command *control = request[1].iov_base;
- const char *stateString[2] = {"on", "off"};
-
- PARCBufferComposer *composer = parcBufferComposer_Create();
- parcBufferComposer_Format(composer,
- "The mapme enable setting received is: %s",
- stateString[control->activate]);
-
- PARCBuffer *tempBuffer = parcBufferComposer_ProduceBuffer(composer);
- char *result = parcBuffer_ToString(tempBuffer);
- parcBuffer_Release(&tempBuffer);
- puts(result);
- parcMemory_Deallocate((void **)&result);
- parcBufferComposer_Release(&composer);
-
- return utils_CreateAck(header, control, sizeof(mapme_timing_command));
+/* Strategy */
+
+strategy_type_t
+configuration_get_strategy(configuration_t * config, const char *prefix)
+{
+ khiter_t k = kh_get_strategy_map(config->strategy_map, prefix);
+ if (k == kh_end(config->strategy_map))
+ return STRATEGY_TYPE_UNDEFINED;
+ return kh_val(config->strategy_map, k);
}
-struct iovec *configuration_MapMeDiscovery(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- mapme_activator_command *control = request[1].iov_base;
- const char *stateString[2] = {"on", "off"};
-
- PARCBufferComposer *composer = parcBufferComposer_Create();
- parcBufferComposer_Format(composer,
- "The mapme discovery setting received is: %s",
- stateString[control->activate]);
-
- PARCBuffer *tempBuffer = parcBufferComposer_ProduceBuffer(composer);
- char *result = parcBuffer_ToString(tempBuffer);
- parcBuffer_Release(&tempBuffer);
- puts(result);
- parcMemory_Deallocate((void **)&result);
- parcBufferComposer_Release(&composer);
-
- return utils_CreateAck(header, control, sizeof(mapme_timing_command));
+uint8_t *
+configuration_on_strategy_set(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ msg_strategy_set_t * msg = (msg_strategy_set_t *)packet;
+ cmd_strategy_set_t * control = &msg->payload;
+
+ char prefix_s[MAXSZ_IP_PREFIX];
+ ip_prefix_t prefix = {
+ .family = control->family,
+ .address = control->address,
+ .len = control->len,
+ };
+ int rc = ip_prefix_snprintf(prefix_s, MAXSZ_IP_PREFIX, &prefix);
+ assert(rc < MAXSZ_IP_PREFIX);
+ if (rc < 0)
+ goto NACK;
+
+ strategy_type_t strategy = control->strategy_type;
+ strategy_type_t existingFwdStrategy =
+ configuration_get_strategy(config, prefix_s);
+
+ strategy_options_t options;
+
+ if (existingFwdStrategy == STRATEGY_TYPE_UNDEFINED ||
+ strategy != existingFwdStrategy) {
+ // means such a new strategy is not present in the hash table or has to be
+ // updated
+ int res;
+ khiter_t k = kh_put_strategy_map(config->strategy_map, prefix_s, &res);
+ kh_value(config->strategy_map, k) = strategy;
+
+ Name *name_prefix = name_CreateFromAddress(control->family,
+ control->address, control->len);
+ // XXX TODO error handling
+
+ switch(control->strategy_type) {
+ case STRATEGY_TYPE_LOW_LATENCY:
+ options.low_latency.related_prefixes_len = control->related_prefixes;
+ Name **related_prefixes = options.low_latency.related_prefixes;
+
+ if(control->related_prefixes != 0){
+ for(int i = 0; i < control->related_prefixes; i++){
+ related_prefixes[i] = name_CreateFromAddress(
+ control->low_latency.families[i],
+ control->low_latency.addresses[i],
+ control->low_latency.lens[i]);
+ }
+ // XXX TODO error handling
+ }
+ forwarder_set_strategy(config->forwarder, name_prefix, strategy, &options);
+
+ if (control->related_prefixes != 0) {
+ for(int i = 0; i < control->related_prefixes; i++)
+ name_Release(&related_prefixes[i]);
+ }
+ break;
+ default:
+ break;
+ }
+ name_Release(&name_prefix);
+ }
+
+ make_ack(msg);
+ return (uint8_t*)msg;
+
+NACK:
+ make_nack(msg);
+ return (uint8_t*)msg;
}
-struct iovec *configuration_MapMeTimescale(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- mapme_timing_command *control = request[1].iov_base;
+/* WLDR */
- PARCBufferComposer *composer = parcBufferComposer_Create();
- parcBufferComposer_Format(composer,
- "The mapme timescale value received is: %u",
- control->timePeriod);
+uint8_t *
+configuration_on_wldr_set(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
- PARCBuffer *tempBuffer = parcBufferComposer_ProduceBuffer(composer);
- char *result = parcBuffer_ToString(tempBuffer);
- parcBuffer_Release(&tempBuffer);
- puts(result);
- parcMemory_Deallocate((void **)&result);
- parcBufferComposer_Release(&composer);
+ msg_wldr_set_t * msg = (msg_wldr_set_t *)packet;
+ cmd_wldr_set_t * control = &msg->payload;
- return utils_CreateAck(header, control, sizeof(mapme_timing_command));
-}
+ if ((control->activate != 0) && (control->activate != 1))
+ goto NACK;
+ bool value = (bool)control->activate;
-struct iovec *configuration_MapMeRetx(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- mapme_timing_command *control = request[1].iov_base;
+ unsigned conn_id = symbolic_to_conn_id(config, control->symbolicOrConnid);
+ if (!connection_id_is_valid(conn_id))
+ goto NACK;
- PARCBufferComposer *composer = parcBufferComposer_Create();
- parcBufferComposer_Format(
- composer, "The mapme retransmission time value received is: %u",
- control->timePeriod);
+ connection_table_t * table = forwarder_get_connection_table(config->forwarder);
+ connection_t * conn = connection_table_at(table, conn_id);
- PARCBuffer *tempBuffer = parcBufferComposer_ProduceBuffer(composer);
- char *result = parcBuffer_ToString(tempBuffer);
- parcBuffer_Release(&tempBuffer);
- puts(result);
- parcMemory_Deallocate((void **)&result);
- parcBufferComposer_Release(&composer);
+ if (value)
+ connection_wldr_enable(conn, value);
- return utils_CreateAck(header, control, sizeof(mapme_timing_command));
+ make_ack(msg);
+ return (uint8_t*)msg;
+
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-struct iovec * configuration_MapMeSendUpdate(Configuration *config,
- struct iovec *request, unsigned ingressId) {
- header_control_message *header = request[0].iov_base;
- mapme_send_update_command *control = request[1].iov_base;
-
- FIB * fib = forwarder_getFib(config->forwarder);
- if (!fib)
- goto ERR;
- Name *prefix = name_CreateFromAddress(control->addressType, control->address,
- control->len);
- if (!prefix)
- goto ERR;
- FibEntry *entry = fib_Contains(fib, prefix);
- name_Release(&prefix);
- if (!entry)
- goto ERR;
-
- const NumberSet * nexthops = fibEntry_GetNexthops(entry);
- unsigned size = (unsigned) numberSet_Length(nexthops);
-
- /* The command is accepted iif triggered by (one of) the producer of this prefix */
- for (unsigned i = 0; i < size; i++) {
- unsigned nhop = numberSet_GetItem(nexthops, i);
- if (nhop == ingressId) {
- MapMe * mapme = forwarder_getMapmeInstance(config->forwarder);
- mapme_send_updates(mapme, entry, nexthops);
- return utils_CreateAck(header, control, sizeof(mapme_timing_command));
+/* Punting */
+
+uint8_t *
+configuration_on_punting_add(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+#if !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
+ msg_punting_add_t * msg = (msg_punting_add_t *)packet;
+ cmd_punting_add_t * control = &msg->payload;
+
+ if (ip_address_empty(&control->address))
+ goto NACK;
+
+ /* This is for hICN listeners only */
+ // XXX add check !
+ // comments:
+ // EncapType: I use the Hicn encap since the punting is available only for
+ // Hicn listeners LocalAddress: The only listern for which we need punting
+ // rules is the main one, which has no address
+ // so I create a fake empty address. This need to be consistent
+ // with the address set at creation time
+ address_t fakeaddr;
+ memset(&fakeaddr, 0, sizeof(address_t));
+ fakeaddr = ADDRESS_ANY(control->family, DEFAULT_PORT);
+
+ forwarder_t * forwarder = configuration_get_forwarder(config);
+ listener_table_t * table = forwarder_get_listener_table(forwarder);
+ listener_t * listener = listener_table_get_by_address(table, FACE_TYPE_HICN, &fakeaddr);
+ if (!listener) {
+ ERROR("the main listener does not exist");
+ goto NACK;
+ }
+
+
+ ip_prefix_t prefix = {
+ .family = control->family,
+ .address = control->address,
+ .len = control->len
+ };
+ char prefix_s[MAXSZ_IP_PREFIX];
+ int rc = ip_prefix_snprintf(prefix_s, MAXSZ_IP_PREFIX, &prefix);
+ assert(rc < MAXSZ_IP_PREFIX);
+ if (rc < 0)
+ goto NACK;
+
+ if (listener_punt(listener, prefix_s) < 0) {
+ ERROR("error while adding the punting rule\n");
+ goto NACK;
}
- }
-ERR:
- return utils_CreateNack(header, control, sizeof(connection_set_admin_state_command));
+ make_ack(msg);
+ return (uint8_t*)msg;
+
+NACK:
+#endif
+ make_ack(msg);
+ return (uint8_t*)msg;
}
+/* MAP-Me */
-struct iovec *configuration_ConnectionSetAdminState(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- connection_set_admin_state_command *control = request[1].iov_base;
+uint8_t *
+configuration_on_mapme_enable(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
- if ((control->admin_state != CONNECTION_STATE_UP) && (control->admin_state != CONNECTION_STATE_DOWN))
- return utils_CreateNack(header, control, sizeof(connection_set_admin_state_command));
+ msg_mapme_enable_t * msg = (msg_mapme_enable_t *)packet;
+ cmd_mapme_enable_t * control = &msg->payload;
- Connection * conn = getConnectionBySymbolicOrId(config, control->symbolicOrConnid);
- if (!conn)
- return utils_CreateNack(header, control, sizeof(connection_set_admin_state_command));
+ if ((control->activate != 0) && (control->activate != 1))
+ goto NACK;
+ bool value = (bool)control->activate;
- connection_SetAdminState(conn, control->admin_state);
+ INFO("MAP-Me SET enable: %s", value ? "on" : "off");
-#ifdef WITH_MAPME
- /* Hook: connection event */
- forwarder_onConnectionEvent(config->forwarder, conn,
- control->admin_state == CONNECTION_STATE_UP
- ? CONNECTION_EVENT_SET_UP
- : CONNECTION_EVENT_SET_DOWN);
-#endif /* WITH_MAPME */
+ make_ack(msg);
+ return (uint8_t*)msg;
- return utils_CreateAck(header, control, sizeof(connection_set_admin_state_command));
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-#ifdef WITH_POLICY
+uint8_t *
+configuration_on_mapme_set_discovery(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
-struct iovec *configuration_ConnectionSetPriority(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- connection_set_priority_command *control = request[1].iov_base;
+ msg_mapme_set_discovery_t * msg = (msg_mapme_set_discovery_t *)packet;
+ cmd_mapme_set_discovery_t * control = &msg->payload;
- Connection * conn = getConnectionBySymbolicOrId(config, control->symbolicOrConnid);
- if (!conn)
- return utils_CreateNack(header, control, sizeof(connection_set_priority_command));
+ if ((control->activate != 0) && (control->activate != 1))
+ goto NACK;
+ bool value = (bool)control->activate;
- connection_SetPriority(conn, control->priority);
+ INFO("MAP-Me SET discovery: %s", value ? "on" : "off");
-#ifdef WITH_MAPME
- /* Hook: connection event */
- forwarder_onConnectionEvent(config->forwarder, conn,
- CONNECTION_EVENT_PRIORITY_CHANGED);
-#endif /* WITH_MAPME */
+ make_ack(msg);
+ return (uint8_t*)msg;
- return utils_CreateAck(header, control, sizeof(connection_set_priority_command));
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-struct iovec *configuration_ConnectionSetTags(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- connection_set_tags_command *control = request[1].iov_base;
+uint8_t *
+configuration_on_mapme_set_timescale(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
- Connection * conn = getConnectionBySymbolicOrId(config, control->symbolicOrConnid);
- if (!conn)
- return utils_CreateNack(header, control, sizeof(connection_set_tags_command));
+ msg_mapme_set_timescale_t * msg = (msg_mapme_set_timescale_t *)packet;
+ cmd_mapme_set_timescale_t * control = &msg->payload;
- connection_SetTags(conn, control->tags);
+ INFO("MAP-Me SET timescale: %u", control->timePeriod);
-#ifdef WITH_MAPME
- /* Hook: connection event */
- forwarder_onConnectionEvent(config->forwarder, conn,
- CONNECTION_EVENT_TAGS_CHANGED);
-#endif /* WITH_MAPME */
+ make_ack(msg);
+ return (uint8_t*)msg;
+}
+
+uint8_t *
+configuration_on_mapme_set_retx(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ msg_mapme_set_retx_t * msg = (msg_mapme_set_retx_t *)packet;
+ cmd_mapme_set_retx_t * control = &msg->payload;
- return utils_CreateAck(header, control, sizeof(connection_set_tags_command));
+ INFO("MAP-Me SET retx: %u", control->timePeriod);
+
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-struct iovec *configuration_ProcessPolicyAdd(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- add_policy_command *control = request[1].iov_base;
- if (forwarder_AddOrUpdatePolicy(config->forwarder, control)) {
- return utils_CreateAck(header, control, sizeof(add_policy_command));
- } else {
- return utils_CreateNack(header, control, sizeof(add_policy_command));
- }
+uint8_t *
+configuration_on_mapme_send_update(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
+
+ msg_mapme_send_update_t * msg = (msg_mapme_send_update_t *)packet;
+ cmd_mapme_send_update_t * control = &msg->payload;
+
+ fib_t * fib = forwarder_get_fib(config->forwarder);
+ if (!fib)
+ goto NACK;
+ Name *prefix = name_CreateFromAddress(control->family, control->address,
+ control->len);
+ if (!prefix)
+ goto NACK;
+ fib_entry_t *entry = fib_contains(fib, prefix);
+ name_Release(&prefix);
+ if (!entry)
+ goto NACK;
+
+ /* The command is accepted iif triggered by (one of) the producer of this prefix */
+ const nexthops_t * nexthops = fib_entry_get_nexthops(entry);
+
+ unsigned nexthop;
+ nexthops_foreach(nexthops, nexthop, {
+ if (nexthop != ingress_id)
+ continue;
+ mapme_t * mapme = forwarder_get_mapme(config->forwarder);
+ mapme_send_to_all_nexthops(mapme, entry);
+ make_ack(msg);
+ return (uint8_t*)msg;
+ });
+
+NACK:
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-struct iovec *configuration_ProcessPolicyList(Configuration *config,
- struct iovec *request) {
- FibEntryList *fibList = forwarder_GetFibEntries(config->forwarder);
-
- size_t payloadSize = fibEntryList_Length(fibList);
- struct sockaddr_in tmpAddr;
- struct sockaddr_in6 tmpAddr6;
-
- // allocate payload, cast from void* to uint8_t* = bytes granularity
- uint8_t *payloadResponse =
- parcMemory_AllocateAndClear(sizeof(list_policies_command) * payloadSize);
-
- for (size_t i = 0; i < fibEntryList_Length(fibList); i++) {
- FibEntry *entry = (FibEntry *)fibEntryList_Get(fibList, i);
- NameBitvector *prefix = name_GetContentName(fibEntry_GetPrefix(entry));
-
- list_policies_command *listPoliciesCommand =
- (list_policies_command *)(payloadResponse +
- (i * sizeof(list_policies_command)));
-
- Address *addressEntry = nameBitvector_ToAddress(prefix);
- if (addressGetType(addressEntry) == ADDR_INET) {
- addressGetInet(addressEntry, &tmpAddr);
- listPoliciesCommand->addressType = ADDR_INET;
- listPoliciesCommand->address.v4.as_inaddr = tmpAddr.sin_addr;
- } else if (addressGetType(addressEntry) == ADDR_INET6) {
- addressGetInet6(addressEntry, &tmpAddr6);
- listPoliciesCommand->addressType = ADDR_INET6;
- listPoliciesCommand->address.v6.as_in6addr = tmpAddr6.sin6_addr;
- }
- listPoliciesCommand->len = nameBitvector_GetLength(prefix);
- listPoliciesCommand->policy = fibEntry_GetPolicy(entry);
+/* Policy */
- addressDestroy(&addressEntry);
- }
+uint8_t *
+configuration_on_policy_add(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
- // send response
- header_control_message *header = request[0].iov_base;
- header->messageType = RESPONSE_LIGHT;
- header->length = (unsigned)payloadSize;
+#ifdef WITH_POLICY
+ msg_policy_add_t * msg = (msg_policy_add_t *)packet;
+ cmd_policy_add_t * control = &msg->payload;
+
+ ip_prefix_t prefix = {
+ .family = control->family,
+ .address = control->address,
+ .len = control->len
+ };
- struct iovec *response =
- parcMemory_AllocateAndClear(sizeof(struct iovec) * 2);
+ if (!forwarder_add_or_update_policy(config->forwarder, &prefix, &control->policy))
+ goto NACK;
- response[0].iov_base = header;
- response[0].iov_len = sizeof(header_control_message);
- response[1].iov_base = payloadResponse;
- response[1].iov_len = sizeof(list_policies_command) * payloadSize;
+ make_ack(msg);
+ return (uint8_t*)msg;
- fibEntryList_Destroy(&fibList);
- return response;
+NACK:
+#endif /* WITH_POLICY */
+ make_ack(msg);
+ return (uint8_t*)msg;
}
-struct iovec *configuration_ProcessPolicyRemove(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- remove_policy_command *control = request[1].iov_base;
- if (forwarder_RemovePolicy(config->forwarder, control))
- return utils_CreateAck(header, control, sizeof(remove_policy_command));
- else
- return utils_CreateNack(header, control, sizeof(remove_policy_command));
-}
+uint8_t *
+configuration_on_policy_remove(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
-struct iovec *configuration_UpdateConnection(Configuration *config,
- struct iovec *request) {
- header_control_message *header = request[0].iov_base;
- update_connection_command *control = request[1].iov_base;
+#ifdef WITH_POLICY
+ msg_policy_remove_t * msg = (msg_policy_remove_t *)packet;
+ cmd_policy_remove_t * control = &msg->payload;
- Connection * conn = getConnectionBySymbolicOrId(config, control->symbolicOrConnid);
- if (!conn)
- return utils_CreateNack(header, control, sizeof(update_connection_command));
+ ip_prefix_t prefix = {
+ .family = control->family,
+ .address = control->address,
+ .len = control->len
+ };
- connection_SetTags(conn, control->tags);
- connection_SetAdminState(conn, control->admin_state);
- if (control->priority > 0)
- connection_SetPriority(conn, control->priority);
+ if (!forwarder_remove_policy(config->forwarder, &prefix))
+ goto NACK;
- return utils_CreateAck(header, control, sizeof(update_connection_command));
-}
+ make_ack(msg);
+ return (uint8_t*)msg;
+
+NACK:
#endif /* WITH_POLICY */
+ make_ack(msg);
+ return (uint8_t*)msg;
+}
-// ===========================
-// Main functions that deal with receiving commands, executing them, and sending
-// ACK/NACK
+uint8_t *
+configuration_on_policy_list(configuration_t * config, uint8_t * packet,
+ unsigned ingress_id)
+{
+ assert(config);
+ assert(packet);
-struct iovec *configuration_DispatchCommand(Configuration *config,
- command_id command,
- struct iovec *control,
- unsigned ingressId) {
- struct iovec *response = NULL;
- switch (command) {
- case ADD_LISTENER:
- response = configurationListeners_Add(config, control, ingressId);
- break;
-
- case ADD_CONNECTION:
- response = configuration_ProcessCreateTunnel(config, control);
- break;
-
- case LIST_CONNECTIONS:
- response = configuration_ProcessConnectionList(config, control);
- break;
-
- case ADD_ROUTE:
- response =
- configuration_ProcessRegisterHicnPrefix(config, control, ingressId);
- break;
-
- case LIST_ROUTES:
- response = configuration_ProcessRegistrationList(config, control);
- break;
-
- case REMOVE_CONNECTION:
- response = configuration_ProcessRemoveTunnel(config, control, ingressId);
- break;
-
- case REMOVE_LISTENER:
- response = configuration_ProcessRemoveListener(config, control, ingressId);
- break;
-
- case REMOVE_ROUTE:
- response = configuration_ProcessUnregisterHicnPrefix(config, control);
- break;
-
- case CACHE_STORE:
- response = configuration_ProcessCacheStore(config, control);
- break;
-
- case CACHE_SERVE:
- response = configuration_ProcessCacheServe(config, control);
- break;
-
- case CACHE_CLEAR:
- response = configuration_ProcessCacheClear(config, control);
- break;
-
- case SET_STRATEGY:
- response = configuration_SetForwardingStrategy(config, control);
- break;
-
- case SET_WLDR:
- response = configuration_SetWldr(config, control);
- break;
-
- case ADD_PUNTING:
- response = configurationListeners_AddPunting(config, control, ingressId);
- break;
-
- case LIST_LISTENERS:
- response = configuration_ProcessListenersList(config, control);
- break;
-
- case MAPME_ENABLE:
- response = configuration_MapMeEnable(config, control);
- break;
-
- case MAPME_DISCOVERY:
- response = configuration_MapMeDiscovery(config, control);
- break;
-
- case MAPME_TIMESCALE:
- response = configuration_MapMeTimescale(config, control);
- break;
-
- case MAPME_RETX:
- response = configuration_MapMeRetx(config, control);
- break;
-
- case MAPME_SEND_UPDATE:
- response = configuration_MapMeSendUpdate(config, control, ingressId);
- break;
-
- case CONNECTION_SET_ADMIN_STATE:
- response = configuration_ConnectionSetAdminState(config, control);
- break;
+ const fib_t * fib = forwarder_get_fib(config->forwarder);
+ assert(fib);
+ size_t n = fib_get_size(fib);
#ifdef WITH_POLICY
- case ADD_POLICY:
- response = configuration_ProcessPolicyAdd(config, control);
- break;
+ msg_policy_list_reply_t * msg;
+ msg_malloc_list(msg, n);
+ if (!msg)
+ return NULL;
+
+ cmd_policy_list_item_t * payload = &msg->payload;
+
+ fib_entry_t * entry;
- case LIST_POLICIES:
- response = configuration_ProcessPolicyList(config, control);
- break;
+ fib_foreach_entry(fib, entry, {
+ NameBitvector *prefix = name_GetContentName(fib_entry_get_prefix(entry));
+ address_t address;
+ nameBitvector_ToAddress(prefix, &address);
- case REMOVE_POLICY:
- response = configuration_ProcessPolicyRemove(config, control);
- break;
+ switch(address_family(&address)) {
+ case AF_INET:
+ payload->family = AF_INET;
+ payload->address.v4.as_inaddr = address4_ip(&address);
+ break;
- case UPDATE_CONNECTION:
- response = configuration_UpdateConnection(config, control);
- break;
+ case AF_INET6:
+ payload->family = AF_INET6;
+ payload->address.v6.as_in6addr = address6_ip(&address);
+ break;
- case CONNECTION_SET_PRIORITY:
- response = configuration_ConnectionSetPriority(config, control);
- break;
+ default:
+ break;
+ }
+ payload->len = nameBitvector_GetLength(prefix);
+ payload->policy = fib_entry_get_policy(entry);
+
+ payload++;
+ });
- case CONNECTION_SET_TAGS:
- response = configuration_ConnectionSetTags(config, control);
- break;
+ return (uint8_t*)msg;
+#else
+ return NULL;
#endif /* WITH_POLICY */
+}
- default:
- break;
- }
+size_t
+configuration_content_store_get_size(configuration_t * config)
+{
+ return config->maximumContentObjectStoreSize;
+}
+
+void
+configuration_content_store_set_size(configuration_t * config, size_t size)
+{
+ config->maximumContentObjectStoreSize = size;
- return response;
+ forwarder_content_store_set_size(config->forwarder,
+ config->maximumContentObjectStoreSize);
}
-void configuration_ReceiveCommand(Configuration *config, command_id command,
- struct iovec *request, unsigned ingressId) {
- parcAssertNotNull(config, "Parameter config must be non-null");
- parcAssertNotNull(request, "Parameter request must be non-null");
- struct iovec *response =
- configuration_DispatchCommand(config, command, request, ingressId);
- configuration_SendResponse(config, response, ingressId);
-
- switch (command) {
- case LIST_CONNECTIONS:
- case LIST_ROUTES: // case LIST_INTERFACES: case ETC...:
- case LIST_LISTENERS:
- parcMemory_Deallocate(
- &response[1]
- .iov_base); // deallocate payload only if generated at fwd side
- break;
- default:
- break;
- }
-
- // deallocate received request. It coincides with response[0].iov_base memory
- // parcMemory_Deallocate(&request); //deallocate header and payload (if
- // same sent by controller)
- parcMemory_Deallocate(&response); // deallocate iovec pointer
+forwarder_t *
+configuration_get_forwarder(const configuration_t * config) {
+ return config->forwarder;
+}
+
+
+// ===========================
+// Main functions that deal with receiving commands, executing them, and sending
+// ACK/NACK
+
+uint8_t *
+configuration_dispatch_command(configuration_t * config, command_type_t command_type,
+ uint8_t * packet, unsigned ingress_id)
+{
+ switch (command_type) {
+#define _(l, u) \
+ case COMMAND_TYPE_ ## u: \
+ return configuration_on_ ## l(config, packet, ingress_id);
+ foreach_command_type
+#undef _
+ case COMMAND_TYPE_UNDEFINED:
+ case COMMAND_TYPE_N:
+ ERROR("Unexpected command type");
+ break;
+ }
+ return NULL;
+}
+
+void configuration_receive_command(configuration_t * config,
+ command_type_t command_type, uint8_t * packet, unsigned ingress_id)
+{
+ assert(config);
+ assert(command_type_is_valid(command_type));
+ assert(packet);
+
+ bool nack = false;
+
+ uint8_t * reply = configuration_dispatch_command(config, command_type, packet, ingress_id);
+ if (!reply) {
+ reply = packet;
+ msg_header_t * hdr = (msg_header_t *)reply;
+ make_nack(hdr);
+ nack = true;
+ }
+
+ connection_table_t * table = forwarder_get_connection_table(config->forwarder);
+ const connection_t *connection = connection_table_at(table, ingress_id);
+ connection_send_packet(connection, reply, false);
+
+ switch (command_type) {
+ case COMMAND_TYPE_LISTENER_LIST:
+ case COMMAND_TYPE_CONNECTION_LIST:
+ case COMMAND_TYPE_ROUTE_LIST:
+ case COMMAND_TYPE_POLICY_LIST:
+ if (!nack)
+ free(reply);
+ break;
+ default:
+ break;
+ }
}
diff --git a/hicn-light/src/hicn/config/configuration.h b/hicn-light/src/hicn/config/configuration.h
index 5090f1413..86efa5236 100644
--- a/hicn-light/src/hicn/config/configuration.h
+++ b/hicn-light/src/hicn/config/configuration.h
@@ -26,14 +26,11 @@
#ifndef configuration_h
#define configuration_h
-#include <hicn/core/logger.h>
#include <hicn/utils/commands.h>
-struct configuration;
-typedef struct configuration Configuration;
+typedef struct configuration_s configuration_t;
-struct forwarder;
-typedef struct forwarder Forwarder;
+struct forwarder_s;
/**
* <#One Line Description#>
@@ -49,7 +46,7 @@ typedef struct forwarder Forwarder;
* <#example#>
* @endcode
*/
-Configuration *configuration_Create(Forwarder *forwarder);
+configuration_t * configuration_create(struct forwarder_s * forwarder);
/**
* <#One Line Description#>
@@ -65,13 +62,13 @@ Configuration *configuration_Create(Forwarder *forwarder);
* <#example#>
* @endcode
*/
-void configuration_Destroy(Configuration **configPtr);
+void configuration_free(configuration_t * config);
-void configuration_SetupAllListeners(Configuration *config, uint16_t port,
+void configuration_setup_all_listeners(configuration_t *config, uint16_t port,
const char *localPath);
-void configuration_ReceiveCommand(Configuration *config, command_id command,
- struct iovec *request, unsigned ingressId);
+void configuration_receive_command(configuration_t *config, command_type_t command,
+ uint8_t * packet, unsigned ingress_id);
/**
* Returns the configured size of the content store
@@ -87,7 +84,7 @@ void configuration_ReceiveCommand(Configuration *config, command_id command,
* <#example#>
* @endcode
*/
-size_t configuration_GetObjectStoreSize(Configuration *config);
+size_t configuration_content_store_get_size(configuration_t *config);
/**
* Sets the size of the content store (in objects, not bytes)
@@ -101,11 +98,9 @@ size_t configuration_GetObjectStoreSize(Configuration *config);
* <#example#>
* @endcode
*/
-void configuration_SetObjectStoreSize(Configuration *config,
- size_t maximumContentObjectCount);
+void configuration_content_store_set_size(configuration_t *config, size_t size);
-strategy_type configuration_GetForwardingStrategy(Configuration *config,
- const char *prefix);
+strategy_type_t configuration_get_strategy(configuration_t *config, const char *prefix);
/**
* Returns the Forwarder that owns the Configuration
@@ -125,28 +120,10 @@ strategy_type configuration_GetForwardingStrategy(Configuration *config,
* }
* @endcode
*/
-Forwarder *configuration_GetForwarder(const Configuration *config);
+struct forwarder_s * configuration_get_forwarder(const configuration_t *config);
-/**
- * Returns the logger used by the Configuration subsystem
- *
- * Returns the logger specified when the Configuration was created.
- *
- * @param [in] config An allocated Configuration
- *
- * @retval non-null The logger
- * @retval null An error
- *
- * Example:
- * @code
- * <#example#>
- * @endcode
- */
-Logger *configuration_GetLogger(const Configuration *config);
-
-struct iovec *configuration_DispatchCommand(Configuration *config,
- command_id command,
- struct iovec *control,
- unsigned ingressId);
+uint8_t *
+configuration_dispatch_command(configuration_t * config, command_type_t command_type,
+ uint8_t * packet, unsigned ingress_id);
#endif // configuration_h
diff --git a/hicn-light/src/hicn/config/configurationFile.c b/hicn-light/src/hicn/config/configurationFile.c
deleted file mode 100644
index 5f9c9ce9d..000000000
--- a/hicn-light/src/hicn/config/configurationFile.c
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * Copyright (c) 2017-2019 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 _WIN32
-#include <unistd.h>
-#endif
-#include <ctype.h>
-#include <errno.h>
-#include <hicn/hicn-light/config.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <parc/algol/parc_ArrayList.h>
-#include <parc/algol/parc_List.h>
-#include <parc/algol/parc_Memory.h>
-#include <parc/algol/parc_Object.h>
-#include <parc/assert/parc_Assert.h>
-#include <hicn/config/configuration.h>
-#include <hicn/config/configurationFile.h>
-#include <hicn/config/controlRoot.h>
-#include <hicn/config/controlState.h>
-
-struct configuration_file {
- Forwarder *forwarder;
- const char *filename;
- FILE *fh;
-
- size_t linesRead;
-
- // our custom state machine.
- ControlState *controlState;
-};
-
-/*
- * Called by a command to dispatch the correct command
- */
-struct iovec *_writeRead(ControlState *state, struct iovec *msg) {
- ConfigurationFile *configFile =
- (ConfigurationFile *)controlState_GetUserdata(state);
-
- parcAssertNotNull(msg, "Parameter msg must be non-null");
- struct iovec *response = configuration_DispatchCommand(
- forwarder_GetConfiguration(configFile->forwarder),
- ((header_control_message *)msg[0].iov_base)->commandID, msg, 0);
-
- return response;
-}
-
-/**
- * Removes leading whitespace (space + tab).
- *
- * If the string is all whitespace, the return value will point to the
- * terminating '\0'.
- *
- * @param [in] str A null-terminated c-string
- *
- * @retval non-null A pointer in to string of the first non-whitespace
- *
- *
- * Example:
- * @code
- * <#example#>
- * @endcode
- */
-static char *_stripLeadingWhitespace(char *str) {
- while (isspace(*str)) {
- str++;
- }
- return str;
-}
-
-/**
- * Removes trailing whitespace
- *
- * Inserts a NULL after the last non-whitespace character, modiyfing the input
- * string.
- *
- * @param [in] str A null-terminated c-string
- *
- * @return non-null A pointer to the input string
- *
- * Example:
- * @code
- * {
- * <#example#>
- * }
- * @endcode
- */
-static char *_stripTrailingWhitespace(char *str) {
- char *p = str + strlen(str) - 1;
- while (p > str && isspace(*p)) {
- p--;
- }
-
- // cap it. If no whitespace, p+1 == str + strlen(str), so will overwrite the
- // current null. If all whitespace p+1 == str+1. For an empty string, p+1 =
- // str.
- *(p + 1) = 0;
-
- // this does not catch the case where the entire string is whitespace
- if (p == str && isspace(*p)) {
- *p = 0;
- }
-
- return str;
-}
-
-/**
- * Removed leading and trailing whitespace
- *
- * Modifies the input string (may add a NULL at the end). Will return
- * a pointer to the first non-whitespace character or the terminating NULL.
- *
- * @param [in] str A null-terminated c-string
- *
- * @return non-null A pointer in to the input string
- *
- * Example:
- * @code
- * {
- * <#example#>
- * }
- * @endcode
- */
-static char *_trim(char *str) {
- return _stripTrailingWhitespace(_stripLeadingWhitespace(str));
-}
-
-/**
- * Parse a string in to a PARCList with one word per element
- *
- * The string passed will be modified by inserting NULLs after each token.
- *
- * @param [in] str A c-string (will be modified)
- *
- * @retval non-null A PARCList where each item is a single word
- *
- * Example:
- * @code
- * <#example#>
- * @endcode
- */
-static PARCList *_parseArgs(char *str) {
- PARCList *list =
- parcList(parcArrayList_Create(NULL), PARCArrayListAsPARCList);
-
- const char delimiters[] = " \t";
-
- char *token;
- token = strtok(str, delimiters);
- while (token != NULL) {
- if (strlen(token) > 0) {
- parcList_Add(list, strdup(token));
- }
- token = strtok(NULL, delimiters);
- }
- // while ((token = strsep(&str, delimiters)) != NULL) {
- // parcList_Add(list, token);
- // }
-
- return list;
-}
-
-// =============================================================
-
-static void _destroy(ConfigurationFile **configFilePtr) {
- ConfigurationFile *configFile = *configFilePtr;
- parcMemory_Deallocate((void **)&configFile->filename);
-
- if (configFile->fh != NULL) {
- fclose(configFile->fh);
- }
-
- controlState_Destroy(&configFile->controlState);
-}
-
-parcObject_ExtendPARCObject(ConfigurationFile, _destroy, NULL, NULL, NULL, NULL,
- NULL, NULL);
-
-parcObject_ImplementRelease(configurationFile, ConfigurationFile);
-
-ConfigurationFile *configurationFile_Create(Forwarder *forwarder,
- const char *filename) {
- parcAssertNotNull(forwarder, "Parameter hicn-fwd must be non-null");
- parcAssertNotNull(filename, "Parameter filename must be non-null");
-
- ConfigurationFile *configFile = parcObject_CreateInstance(ConfigurationFile);
-
- if (configFile) {
- configFile->linesRead = 0;
- configFile->forwarder = forwarder;
- configFile->filename =
- parcMemory_StringDuplicate(filename, strlen(filename));
- parcAssertNotNull(configFile->filename, "Could not copy string '%s'",
- filename);
-
- // setup the control state for the command parser: last parameter NULL
- // because
- // writeRead still not implemented from configuration file.
- configFile->controlState =
- controlState_Create(configFile, _writeRead, false,
- SRV_CTRL_IP, SRV_CTRL_PORT);
-
- // we do not register Help commands
- controlState_RegisterCommand(configFile->controlState,
- controlRoot_Create(configFile->controlState));
-
- // open the file and make sure we can read it
- configFile->fh = fopen(configFile->filename, "r");
-
- if (configFile->fh) {
- if (logger_IsLoggable(forwarder_GetLogger(forwarder),
- LoggerFacility_Config, PARCLogLevel_Debug)) {
- logger_Log(forwarder_GetLogger(forwarder), LoggerFacility_Config,
- PARCLogLevel_Debug, __func__, "Open config file %s",
- configFile->filename);
- }
- } else {
- if (logger_IsLoggable(forwarder_GetLogger(forwarder),
- LoggerFacility_Config, PARCLogLevel_Error)) {
- logger_Log(forwarder_GetLogger(forwarder), LoggerFacility_Config,
- PARCLogLevel_Error, __func__,
- "Could not open config file %s: (%d) %s",
- configFile->filename, errno, strerror(errno));
- }
-
- // failure cleanup the object -- this nulls it so final return null be
- // NULL
- configurationFile_Release(&configFile);
- }
- }
- return configFile;
-}
-
-bool configurationFile_Process(ConfigurationFile *configFile) {
- parcAssertNotNull(configFile, "Parameter configFile must be non-null");
-
- // default to a "true" return value and only set to false if we encounter an
- // error.
- bool success = true;
-
-#define BUFFERLEN 2048
- char buffer[BUFFERLEN];
-
- configFile->linesRead = 0;
-
- // always clear errors and fseek to start of file in case we get called
- // multiple times.
- clearerr(configFile->fh);
- rewind(configFile->fh);
-
- while (success && fgets(buffer, BUFFERLEN, configFile->fh) != NULL) {
- configFile->linesRead++;
-
- char *stripedBuffer = _trim(buffer);
- if (strlen(stripedBuffer) > 0) {
- if (stripedBuffer[0] != '#') {
- // not empty and not a comment
-
- // _parseArgs will modify the string
- char *copy =
- parcMemory_StringDuplicate(stripedBuffer, strlen(stripedBuffer));
- PARCList *args = _parseArgs(copy);
- CommandReturn result =
- controlState_DispatchCommand(configFile->controlState, args);
-
- // we ignore EXIT from the configuration file
- if (result == CommandReturn_Failure) {
- if (logger_IsLoggable(forwarder_GetLogger(configFile->forwarder),
- LoggerFacility_Config, PARCLogLevel_Error)) {
- logger_Log(forwarder_GetLogger(configFile->forwarder),
- LoggerFacility_Config, PARCLogLevel_Error, __func__,
- "Error on input file %s line %d: %s",
- configFile->filename, configFile->linesRead,
- stripedBuffer);
- }
- success = false;
- }
- for(int i = 0; i < parcList_Size(args); i++){
- free(parcList_GetAtIndex(args, i));
- }
- parcList_Release(&args);
- parcMemory_Deallocate((void **)&copy);
- }
- }
- }
-
- if (ferror(configFile->fh)) {
- if (logger_IsLoggable(forwarder_GetLogger(configFile->forwarder),
- LoggerFacility_Config, PARCLogLevel_Error)) {
- logger_Log(forwarder_GetLogger(configFile->forwarder),
- LoggerFacility_Config, PARCLogLevel_Error, __func__,
- "Error on input file %s line %d: (%d) %s",
- configFile->filename, configFile->linesRead, errno,
- strerror(errno));
- }
- success = false;
- }
-
- return success;
-}
diff --git a/hicn-light/src/hicn/config/configurationListeners.c b/hicn-light/src/hicn/config/configurationListeners.c
deleted file mode 100644
index 21bfe7640..000000000
--- a/hicn-light/src/hicn/config/configurationListeners.c
+++ /dev/null
@@ -1,627 +0,0 @@
-/*
- * Copyright (c) 2017-2019 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 _WIN32
-#include <arpa/inet.h>
-#include <unistd.h>
-#endif
-#include <parc/assert/parc_Assert.h>
-#include <hicn/hicn-light/config.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <parc/algol/parc_Memory.h>
-#include <parc/algol/parc_Network.h>
-
-#include <hicn/core/system.h>
-#include <hicn/utils/interfaceSet.h>
-#include <hicn/utils/punting.h>
-
-#include <hicn/config/configurationListeners.h>
-#include <hicn/io/hicnListener.h>
-#include <hicn/io/tcpListener.h>
-#include <hicn/io/udpListener.h>
-
-#include <hicn/utils/address.h>
-#include <hicn/utils/addressList.h>
-#include <hicn/utils/commands.h>
-#include <hicn/utils/utils.h>
-
-static bool _setupHicnListenerOnInet4(Forwarder *forwarder,
- const char *symbolic, Address *address) {
- bool success = false;
-#if !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
- ListenerOps *ops =
- hicnListener_CreateInet(forwarder, (char *)symbolic, address);
- if (ops != NULL) {
- success = listenerSet_Add(forwarder_GetListenerSet(forwarder), ops);
- parcAssertTrue(success, "Failed to add Hicn listener %s to ListenerSet",
- symbolic);
- }
-#endif /* __APPLE__ _WIN32*/
- return success;
-}
-
-static bool _setupHicnListenerOnInet6(Forwarder *forwarder,
- const char *symbolic, Address *address) {
- bool success = false;
-#if !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
- ListenerOps *ops =
- hicnListener_CreateInet6(forwarder, (char *)symbolic, address);
- if (ops != NULL) {
- success = listenerSet_Add(forwarder_GetListenerSet(forwarder), ops);
- parcAssertTrue(success, "Failed to add Hicn listener %s to ListenerSet",
- symbolic);
- }
-#endif /* __APPLE__ _WIN32 */
- return success;
-}
-
-bool configurationListeners_Remove(const Configuration *config) {
- Logger *logger = configuration_GetLogger(config);
- if (logger_IsLoggable(logger, LoggerFacility_Config, PARCLogLevel_Warning)) {
- logger_Log(logger, LoggerFacility_Config, PARCLogLevel_Warning, __func__,
- "Removing a listener not supported: ingress %u control %s");
- }
-
- return false;
-}
-
-bool _AddPuntingInet(const Configuration *config, Punting *punting,
- unsigned ingressId) {
-#if !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
- struct sockaddr *addr = parcNetwork_SockAddress("0.0.0.0", 1234);
- if (addr == NULL) {
- printf("Error creating address\n");
- return false;
- }
-
- Address *fakeAddr = addressCreateFromInet((struct sockaddr_in *)addr);
-
- ListenerOps *listenerOps = listenerSet_Find(
- forwarder_GetListenerSet(configuration_GetForwarder(config)), ENCAP_HICN,
- fakeAddr);
- addressDestroy(&fakeAddr);
-
- if (listenerOps == NULL) {
- printf("the main listener (IPV4) does not exists\n");
- return false;
- }
-
- struct sockaddr_in puntingAddr;
-
- Address *address = puntingGetAddress(punting);
- if (address == NULL) return false;
-
- bool res = addressGetInet(address, &puntingAddr);
- if (!res) {
- printf("unable to read the punting address\n");
- return false;
- }
-
- char prefix[INET_ADDRSTRLEN];
- inet_ntop(AF_INET, &(puntingAddr.sin_addr), prefix, INET_ADDRSTRLEN);
-
- char len[5];
- sprintf(len, "%d", puntingPrefixLen(punting));
-
- char *prefixStr =
- malloc(strlen(prefix) + strlen(len) + 2); //+1 for the zero-terminator
- if (prefixStr == NULL) {
- printf("error while create the prefix string\n");
- return false;
- }
- strcpy(prefixStr, prefix);
- strcat(prefixStr, "/");
- strcat(prefixStr, len);
-
- res = hicnListener_Punting(listenerOps, prefixStr);
- if (!res) {
- printf("error while adding the punting rule\n");
- return false;
- }
-
- return true;
-#else
- return false;
-#endif
-}
-
-bool _AddPuntingInet6(const Configuration *config, Punting *punting,
- unsigned ingressId) {
-#if !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
- struct sockaddr *addr = parcNetwork_SockAddress("0::0", 1234);
- if (addr == NULL) {
- printf("Error creating address\n");
- return false;
- }
-
- Address *fakeAddr = addressCreateFromInet6((struct sockaddr_in6 *)addr);
-
- // comments:
- // EncapType: I use the Hicn encap since the punting is available only for
- // Hicn listeners LocalAddress: The only listern for which we need punting
- // rules is the main one, which has no address
- // so I create a fake empty address. This need to be consistent
- // with the address set at creation time
-
- ListenerOps *listenerOps = listenerSet_Find(
- forwarder_GetListenerSet(configuration_GetForwarder(config)), ENCAP_HICN,
- fakeAddr);
- addressDestroy(&fakeAddr);
-
- if (listenerOps == NULL) {
- printf("the main listener does not exists\n");
- return false;
- }
-
- struct sockaddr_in6 puntingAddr;
- bool res = addressGetInet6(puntingGetAddress(punting), &puntingAddr);
- if (!res) {
- printf("unable to read the punting address\n");
- return false;
- }
-
- char prefix[INET6_ADDRSTRLEN];
- inet_ntop(AF_INET6, &(puntingAddr.sin6_addr), prefix, INET6_ADDRSTRLEN);
-
- char len[5];
- sprintf(len, "%d", puntingPrefixLen(punting));
-
- char *prefixStr =
- malloc(strlen(prefix) + strlen(len) + 2); //+1 for the zero-terminator
- if (prefixStr == NULL) {
- printf("error while create the prefix string\n");
- return false;
- }
- strcpy(prefixStr, prefix);
- strcat(prefixStr, "/");
- strcat(prefixStr, len);
-
- res = hicnListener_Punting(listenerOps, prefixStr);
- if (!res) {
- printf("error while adding the punting rule\n");
- return false;
- }
-
- return true;
-#else
- return false;
-#endif
-}
-
-//============= LIGHT COMMAN ===============
-
-static bool _addEther(Configuration *config, add_listener_command *control,
- unsigned ingressId) {
- // Not implemented
- return false;
-}
-
-/*
- * Create a new IPV4/TCP listener.
- *
- * @param [in,out] forwarder The hicn-light forwarder instance
- * @param [in] listenerName The name of the listener
- * @param [in] addr4 The ipv4 address in network byte order
- * @param [in] port The port number in network byte order
- * @param [in] interfaceName The name of the interface to bind the socket
- *
- * return true if success, false otherwise
- */
-static bool _setupTcpListenerOnInet(Forwarder *forwarder, char *listenerName, ipv4_addr_t *addr4,
- uint16_t *port, char *interfaceName) {
- parcAssertNotNull(listenerName, "Parameter listenerName must be non-null");
-
- bool success = false;
-
- struct sockaddr_in addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = *port;
- addr.sin_addr.s_addr = *addr4;
-
- ListenerOps *ops = tcpListener_CreateInet(forwarder, listenerName, addr, interfaceName);
- if (ops) {
- success = listenerSet_Add(forwarder_GetListenerSet(forwarder), ops);
-#if 0
- parcAssertTrue(success, "Failed to add TCP listener on %s to ListenerSet",
- addressToString(ops->getListenAddress(ops)));
-#endif
- }
- return success;
-}
-
-
-/*
- * Create a new IPV4/UDP listener.
- *
- * @param [in,out] forwarder The hicn-light forwarder instance
- * @param [in] listenerName The name of the listener
- * @param [in] addr4 The ipv4 address in network byte order
- * @param [in] port The port number in network byte order
- * @param [in] interfaceName The name of the interface to bind the socket
- *
- * return true if success, false otherwise
- */
-static bool _setupUdpListenerOnInet(Forwarder *forwarder, char *listenerName, ipv4_addr_t *addr4,
- uint16_t *port, char *interfaceName) {
- bool success = false;
-
- struct sockaddr_in addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = *port;
- addr.sin_addr.s_addr = *addr4;
-
- ListenerOps *ops = udpListener_CreateInet(forwarder, listenerName, addr, interfaceName);
- if (ops) {
- success = listenerSet_Add(forwarder_GetListenerSet(forwarder), ops);
-#if 0
- parcAssertTrue(success, "Failed to add UDP listener on %s to ListenerSet",
- addressToString(ops->getListenAddress(ops)));
-#endif
- }
- return success;
-}
-
-
-/*
- * Create a new IPV6/TCP listener.
- *
- * @param [in,out] forwarder The hicn-light forwarder instance
- * @param [in] addr6 The ipv6 address in network byte order
- * @param [in] port The port number in network byte order
- * @param [in] interfaceName The name of the interface to bind the socket
- *
- * return true if success, false otherwise
- */
-static bool _setupTcpListenerOnInet6Light(Forwarder *forwarder, char *listenerName,
- ipv6_addr_t *addr6, uint16_t *port, char *interfaceName,
- uint32_t scopeId) {
- bool success = false;
-
- struct sockaddr_in6 addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin6_family = AF_INET6;
- addr.sin6_port = *port;
- addr.sin6_addr = *addr6;
- addr.sin6_scope_id = scopeId;
-
- ListenerOps *ops = tcpListener_CreateInet6(forwarder, listenerName, addr, interfaceName);
- if (ops) {
- success = listenerSet_Add(forwarder_GetListenerSet(forwarder), ops);
-#if 0
- parcAssertTrue(success, "Failed to add TCP6 listener on %s to ListenerSet",
- addressToString(ops->getListenAddress(ops)));
-#endif
- }
- return success;
-}
-
-
-/*
- * Create a new IPV6/UDP listener.
- *
- * @param [in,out] forwarder The hicn-light forwarder instance
- * @param [in] listenerName The name of the listener
- * @param [in] addr6 The ipv6 address in network byte order
- * @param [in] port The port number in network byte order
- * @param [in] interfaceName The name of the interface to bind the socket
- *
- * return true if success, false otherwise
- */
-static bool _setupUdpListenerOnInet6Light(Forwarder *forwarder, char *listenerName,
- ipv6_addr_t *addr6, uint16_t *port, char *interfaceName) {
- bool success = false;
-
- struct sockaddr_in6 addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin6_family = AF_INET6;
- addr.sin6_port = *port;
- addr.sin6_addr = *addr6;
- addr.sin6_scope_id = 0;
-
- ListenerOps *ops = udpListener_CreateInet6(forwarder, listenerName, addr, interfaceName);
- if (ops) {
- success = listenerSet_Add(forwarder_GetListenerSet(forwarder), ops);
-#if 0
- parcAssertTrue(success, "Failed to add UDP6 listener on %s to ListenerSet",
- addressToString(ops->getListenAddress(ops)));
-#endif
- }
- return success;
-}
-
-/*
- * Create a new HICN listener.
- *
- * @param [in] config The configuration
- * @param [in] control The control command
- * @param [in] port The connection id of the command
- *
- * return true if success, false otherwise
- */
-bool _addHicn(Configuration *config, add_listener_command *control,
- unsigned ingressId) {
- bool success = false;
- const char *symbolic = control->symbolic;
- Address *localAddress = NULL;
-
- switch (control->addressType) {
- case ADDR_INET: {
- localAddress =
- addressFromInaddr4Port(&control->address.v4.as_u32, &control->port);
- success = _setupHicnListenerOnInet4(configuration_GetForwarder(config),
- symbolic, localAddress);
- break;
- }
-
- case ADDR_INET6: {
- localAddress =
- addressFromInaddr6Port(&control->address.v6.as_in6addr, &control->port);
- success = _setupHicnListenerOnInet6(configuration_GetForwarder(config),
- symbolic, localAddress);
- break;
- }
-
- default:
- if (logger_IsLoggable(configuration_GetLogger(config),
- LoggerFacility_Config, PARCLogLevel_Warning)) {
- logger_Log(configuration_GetLogger(config), LoggerFacility_Config,
- PARCLogLevel_Warning, __func__,
- "Unsupported address type for HICN (ingress id %u): "
- "must be either IPV4 or IPV6",
- ingressId);
- }
- break;
- }
-
- if (success == true && localAddress != NULL) {
- if (logger_IsLoggable(configuration_GetLogger(config),
- LoggerFacility_Config, PARCLogLevel_Info)) {
- logger_Log(configuration_GetLogger(config), LoggerFacility_Config,
- PARCLogLevel_Info, __func__,
- "Setup hicn listener on address %s",
- addressToString(localAddress));
- }
- }
-
- addressDestroy(&localAddress);
-
- return success;
-}
-
-bool _addIP(Configuration *config, add_listener_command *control,
- unsigned ingressId) {
- bool success = false;
- char *symbolic = control->symbolic;
-
- switch (control->addressType) {
- case ADDR_INET: {
-
- if (control->connectionType == UDP_CONN) {
- success =
- _setupUdpListenerOnInet(configuration_GetForwarder(config), symbolic,
- &control->address.v4.as_u32, &control->port, control->interfaceName);
- } else if (control->connectionType == TCP_CONN) {
- success =
- _setupTcpListenerOnInet(configuration_GetForwarder(config), symbolic,
- &control->address.v4.as_u32, &control->port, control->interfaceName);
- }
- break;
- }
-
- case ADDR_INET6: {
- if (control->connectionType == UDP_CONN) {
- success = _setupUdpListenerOnInet6Light(
- configuration_GetForwarder(config), symbolic, &control->address.v6.as_in6addr,
- &control->port, control->interfaceName);
- } else if (control->connectionType == TCP_CONN) {
- success = _setupTcpListenerOnInet6Light(
- configuration_GetForwarder(config), symbolic, &control->address.v6.as_in6addr,
- &control->port, control->interfaceName, 0);
- }
- break;
- }
-
- default:
- if (logger_IsLoggable(configuration_GetLogger(config),
- LoggerFacility_Config, PARCLogLevel_Warning)) {
- char *addrStr = utils_CommandAddressToString(
- control->addressType, &control->address, &control->port);
- logger_Log(
- configuration_GetLogger(config), LoggerFacility_Config,
- PARCLogLevel_Warning, __func__,
- "Unsupported address type for IP encapsulation ingress id %u: %s",
- ingressId, addrStr);
- parcMemory_Deallocate((void **)&addrStr);
- }
- break;
- }
-
- if (success) {
- if (logger_IsLoggable(configuration_GetLogger(config),
- LoggerFacility_Config, PARCLogLevel_Info)) {
- char *addrStr = utils_CommandAddressToString(
- control->addressType, &control->address, &control->port);
- logger_Log(configuration_GetLogger(config), LoggerFacility_Config,
- PARCLogLevel_Info, __func__, "Setup listener on address %s",
- addrStr);
- parcMemory_Deallocate((void **)&addrStr);
- }
- }
-
- return success;
-}
-
-struct iovec *configurationListeners_Add(Configuration *config,
- struct iovec *request,
- unsigned ingressId) {
- header_control_message *header = request[0].iov_base;
- add_listener_command *control = request[1].iov_base;
-
- bool success = false;
-
- ListenerSet *listenerSet = forwarder_GetListenerSet(configuration_GetForwarder(config));
- int listenerId = listenerSet_FindIdByListenerName(listenerSet, control->symbolic);
-
- if (listenerId < 0) {
- if (control->listenerMode == ETHER_MODE) {
- parcTrapNotImplemented("Add Ethernet Listener is not supported");
- success = _addEther(config, control, ingressId);
- // it is a failure
- } else if (control->listenerMode == IP_MODE) {
- success = _addIP(config, control, ingressId);
- } else if (control->listenerMode == HICN_MODE) {
- success = _addHicn(config, control, ingressId);
- } else {
- Logger *logger = configuration_GetLogger(config);
- if (logger_IsLoggable(logger, LoggerFacility_Config,
- PARCLogLevel_Warning)) {
- logger_Log(logger, LoggerFacility_Config, PARCLogLevel_Warning, __func__,
- "Unsupported encapsulation mode (ingress id %u)", ingressId);
- }
- }
- }
-
- // generate ACK/NACK
- struct iovec *response;
-
- if (success) { // ACK
- response = utils_CreateAck(header, control, sizeof(add_listener_command));
- } else { // NACK
- response = utils_CreateNack(header, control, sizeof(add_listener_command));
- }
-
- return response;
-}
-
-struct iovec *configurationListeners_AddPunting(Configuration *config,
- struct iovec *request,
- unsigned ingressId) {
- header_control_message *header = request[0].iov_base;
- add_punting_command *control = request[1].iov_base;
-
- const char *symbolicOrConnid = control->symbolicOrConnid;
- uint32_t len = control->len;
- in_port_t port = htons(1234);
- bool success = false;
-
- if (control->addressType == ADDR_INET) {
- Address *address = addressFromInaddr4Port(&control->address.v4.as_u32, &port);
- Punting *punting = puntingCreate(symbolicOrConnid, address, len);
- success = _AddPuntingInet(config, punting, ingressId);
- addressDestroy(&address);
- } else if (control->addressType == ADDR_INET6) {
- Address *address = addressFromInaddr6Port(&control->address.v6.as_in6addr, &port);
- Punting *punting = puntingCreate(symbolicOrConnid, address, len);
- success = _AddPuntingInet6(config, punting, ingressId);
- addressDestroy(&address);
- } else {
- printf("Invalid IP type.\n"); // will generate a Nack
- return utils_CreateNack(header, control, sizeof(add_punting_command));
- }
-
- // generate ACK/NACK
- struct iovec *response;
- if (success) { // ACK
- response = utils_CreateAck(header, control, sizeof(add_punting_command));
- } else { // NACK
- response = utils_CreateNack(header, control, sizeof(add_punting_command));
- }
-
- return response;
-}
-
-//=========================== INITIAL LISTENERS ====================
-
-static void _setupListenersOnAddress(Forwarder *forwarder, char *listenerName,
- const Address *address, uint16_t port,
- char *interfaceName) {
- address_type type = addressGetType(address);
- switch (type) {
- case ADDR_INET: {
- struct sockaddr_in tmp;
- addressGetInet(address, &tmp);
- _setupTcpListenerOnInet(forwarder, listenerName, &tmp.sin_addr.s_addr, &port, interfaceName);
- break;
- }
-
- case ADDR_INET6: {
- struct sockaddr_in6 tmp;
- addressGetInet6(address, &tmp);
- _setupTcpListenerOnInet6Light(forwarder, listenerName, &tmp.sin6_addr, &port, interfaceName,
- tmp.sin6_scope_id);
- break;
- }
-
- case ADDR_LINK:
- // not used
- break;
-
- default:
- // dont' know how to handle this, so no listeners
- break;
- }
-}
-
-void configurationListeners_SetupAll(const Configuration *config, uint16_t port,
- const char *localPath) {
- Forwarder *forwarder = configuration_GetForwarder(config);
- InterfaceSet *set = system_Interfaces(forwarder);
-
- size_t interfaceSetLen = interfaceSetLength(set);
- for (size_t i = 0; i < interfaceSetLen; i++) {
- Interface *iface = interfaceSetGetByOrdinalIndex(set, i);
-
- const AddressList *addresses = interfaceGetAddresses(iface);
- size_t addressListLen = addressListLength(addresses);
-
- for (size_t j = 0; j < addressListLen; j++) {
- const Address *address = addressListGetItem(addresses, j);
-
- // Do not start on link address
- char listenerName[SYMBOLIC_NAME_LEN];
-#ifdef __ANDROID__
- snprintf(listenerName, SYMBOLIC_NAME_LEN, "local_%zu", i);
-#else
- snprintf(listenerName, SYMBOLIC_NAME_LEN, "local_%ld", i);
-#endif
- if (addressGetType(address) != ADDR_LINK) {
- _setupListenersOnAddress(forwarder, listenerName, address, port,
- (char *)interfaceGetName(iface));
- }
- }
- }
-
- interfaceSetDestroy(&set);
-}
-
-void configurationListeners_SetutpLocalIPv4(const Configuration *config,
- uint16_t port) {
- Forwarder *forwarder = configuration_GetForwarder(config);
- in_addr_t addr = inet_addr("127.0.0.1");
- uint16_t network_byte_order_port = htons(port);
-
- char listenerNameUdp[SYMBOLIC_NAME_LEN] = "lo_udp";
- char listenerNameTcp[SYMBOLIC_NAME_LEN] = "lo_tcp";
- char *loopback_interface = "lo";
- _setupUdpListenerOnInet(forwarder, listenerNameUdp,(ipv4_addr_t *)&(addr),
- &network_byte_order_port, loopback_interface);
- _setupTcpListenerOnInet(forwarder, listenerNameTcp, (ipv4_addr_t *)&(addr),
- &network_byte_order_port, loopback_interface);
-}
diff --git a/hicn-light/src/hicn/config/configurationListeners.h b/hicn-light/src/hicn/config/configurationListeners.h
deleted file mode 100644
index b09ad5167..000000000
--- a/hicn-light/src/hicn/config/configurationListeners.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2017-2019 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 configurationListeners.h
- * @brief Configuration routines related to Listeners
- *
- * Adding and removing listeners.
- *
- */
-
-#ifndef configurationListeners_h
-#define configurationListeners_h
-
-#include <hicn/config/configuration.h>
-#include <hicn/core/forwarder.h>
-
-#include <hicn/utils/address.h>
-
-/**
- * Setup udp, tcp, and local listeners
- *
- * Will bind to all available IP protocols on the given port.
- * Does not add Ethernet listeners.
- *
- * @param port is the UPD and TCP port to use
- * @param localPath is the AF_UNIX path to use, if NULL no AF_UNIX listener is
- * setup
- *
- * Example:
- * @code
- * <#example#>
- * @endcode
- */
-void configurationListeners_SetupAll(const Configuration *config, uint16_t port,
- const char *localPath);
-
-void configurationListeners_SetutpLocalIPv4(const Configuration *config,
- uint16_t port);
-
-bool configurationListeners_Remove(const Configuration *config);
-
-// light functions
-
-/**
- * Add new listener.
- *
- * @param request The request coming from hicnLightControl or the
- * configuration file. The bytes in the request are
- * ordered following the network byte order convention.
- *
- * @param ingressId The connection id of the incoming request.
- */
-struct iovec *configurationListeners_Add(Configuration *config,
- struct iovec *request,
- unsigned ingressId);
-
-struct iovec *configurationListeners_AddPunting(Configuration *config,
- struct iovec *request,
- unsigned ingressId);
-
-#endif /* defined(configurationListeners_h) */
diff --git a/hicn-light/src/hicn/config/configuration_file.c b/hicn-light/src/hicn/config/configuration_file.c
new file mode 100644
index 000000000..b53bb025f
--- /dev/null
+++ b/hicn-light/src/hicn/config/configuration_file.c
@@ -0,0 +1,292 @@
+/*
+ * Copyright (c) 2017-2019 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 _WIN32
+#include <unistd.h>
+#endif
+#include <ctype.h>
+#include <errno.h>
+#include <hicn/hicn-light/config.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <hicn/config/configuration.h>
+#include <hicn/config/configuration_file.h>
+//#include <hicn/config/controlRoot.h>
+//#include <hicn/config/controlState.h>
+#include <hicn/util/log.h>
+
+struct configuration_file {
+ forwarder_t *forwarder;
+ char *filename;
+ FILE *fh;
+
+ size_t linesRead;
+
+ // our custom state machine.
+ // XXX ControlState *control_state;
+};
+
+#if 0
+/*
+ * Called by a command to dispatch the correct command
+ */
+uint8_t *
+_write_read(ControlState *state, uint8_t * packet)
+{
+ assert(state);
+ assert(packet);
+
+ configuration_file_t *configFile =
+ (configuration_file_t *)controlState_GetUserdata(state);
+
+ configuration_t * config = forwarder_get_configuration(configFile->forwarder);
+ command_type_t command_type =
+ command_type_from_uchar(((cmd_header_t*)packet)->commandID);
+
+ return configuration_dispatch_command(config, command_type, packet, 0);
+}
+
+/**
+ * Removes leading whitespace (space + tab).
+ *
+ * If the string is all whitespace, the return value will point to the
+ * terminating '\0'.
+ *
+ * @param [in] str A null-terminated c-string
+ *
+ * @retval non-null A pointer in to string of the first non-whitespace
+ *
+ *
+ * Example:
+ * @code
+ * <#example#>
+ * @endcode
+ */
+static char *
+_stripLeadingWhitespace(char *str)
+{
+ while (isspace(*str))
+ str++;
+ return str;
+}
+
+/**
+ * Removes trailing whitespace
+ *
+ * Inserts a NULL after the last non-whitespace character, modiyfing the input
+ * string.
+ *
+ * @param [in] str A null-terminated c-string
+ *
+ * @return non-null A pointer to the input string
+ *
+ * Example:
+ * @code
+ * {
+ * <#example#>
+ * }
+ * @endcode
+ */
+static char *
+_stripTrailingWhitespace(char *str)
+{
+ char *p = str + strlen(str) - 1;
+ while (p > str && isspace(*p))
+ p--;
+
+ // cap it. If no whitespace, p+1 == str + strlen(str), so will overwrite the
+ // current null. If all whitespace p+1 == str+1. For an empty string, p+1 =
+ // str.
+ *(p + 1) = 0;
+
+ // this does not catch the case where the entire string is whitespace
+ if (p == str && isspace(*p))
+ *p = 0;
+
+ return str;
+}
+
+/**
+ * Removed leading and trailing whitespace
+ *
+ * Modifies the input string (may add a NULL at the end). Will return
+ * a pointer to the first non-whitespace character or the terminating NULL.
+ *
+ * @param [in] str A null-terminated c-string
+ *
+ * @return non-null A pointer in to the input string
+ *
+ * Example:
+ * @code
+ * {
+ * <#example#>
+ * }
+ * @endcode
+ */
+static char *
+_trim(char *str)
+{
+ return _stripTrailingWhitespace(_stripLeadingWhitespace(str));
+}
+
+/**
+ * Parse a string in to a PARCList with one word per element
+ *
+ * The string passed will be modified by inserting NULLs after each token.
+ *
+ * @param [in] str A c-string (will be modified)
+ *
+ * @retval non-null A PARCList where each item is a single word
+ *
+ * Example:
+ * @code
+ * <#example#>
+ * @endcode
+ */
+static PARCList *
+_parseArgs(char *str)
+{
+ PARCList *list =
+ parcList(parcArrayList_Create(NULL), PARCArrayListAsPARCList);
+
+ const char delimiters[] = " \t";
+
+ char *token;
+ token = strtok(str, delimiters);
+ while (token != NULL) {
+ if (strlen(token) > 0) {
+ parcList_Add(list, strdup(token));
+ }
+ token = strtok(NULL, delimiters);
+ }
+ return list;
+}
+#endif
+
+// =============================================================
+
+configuration_file_t *
+configuration_file_create(forwarder_t * forwarder, const char * filename)
+{
+ assert(forwarder);
+ assert(filename);
+
+ configuration_file_t *cfg = malloc(sizeof(configuration_file_t));
+ if (!cfg)
+ return NULL;
+
+ cfg->linesRead = 0;
+ cfg->forwarder = forwarder;
+ cfg->filename = strdup(filename);
+ assert(cfg->filename);
+
+#if 0
+ // setup the control state for the command parser: last parameter NULL
+ // because
+ // write_read still not implemented from configuration file.
+ cfg->control_state = controlState_Create(cfg, _write_read, false,
+ SRV_CTRL_IP, SRV_CTRL_PORT);
+#endif
+
+ // we do not register Help commands
+ //controlState_RegisterCommand(cfg->control_state, controlRoot_Create(cfg->control_state));
+
+ // open the file and make sure we can read it
+ cfg->fh = fopen(cfg->filename, "r");
+
+ if (cfg->fh) {
+ DEBUG("Open config file %s", cfg->filename);
+ } else {
+ ERROR("Could not open config file %s: (%d) %s", cfg->filename, errno, strerror(errno));
+
+ // failure cleanup the object -- this nulls it so final return null be
+ // NULL
+ configuration_file_free(cfg);
+ }
+ return cfg;
+}
+
+bool
+configuration_file_process(configuration_file_t *configFile)
+{
+ assert(configFile);
+
+ // default to a "true" return value and only set to false if we encounter an
+ // error.
+ bool success = true;
+
+#if 0
+#define BUFFERLEN 2048
+ char buffer[BUFFERLEN];
+
+ configFile->linesRead = 0;
+
+ // always clear errors and fseek to start of file in case we get called
+ // multiple times.
+ clearerr(configFile->fh);
+ rewind(configFile->fh);
+
+ while (success && fgets(buffer, BUFFERLEN, configFile->fh) != NULL) {
+ configFile->linesRead++;
+
+ char *stripedBuffer = _trim(buffer);
+ if (strlen(stripedBuffer) > 0) {
+ if (stripedBuffer[0] != '#') {
+ // not empty and not a comment
+
+ // _parseArgs will modify the string
+ char *copy =
+ parcMemory_StringDuplicate(stripedBuffer, strlen(stripedBuffer));
+ PARCList *args = _parseArgs(copy);
+ CommandReturn result =
+ controlState_DispatchCommand(configFile->control_state, args);
+
+ // we ignore EXIT from the configuration file
+ if (result == CommandReturn_Failure) {
+ ERROR("Error on input file %s line %d: %s",
+ configFile->filename, configFile->linesRead,
+ stripedBuffer);
+ success = false;
+ }
+ for(int i = 0; i < parcList_Size(args); i++){
+ free(parcList_GetAtIndex(args, i));
+ }
+ parcList_Release(&args);
+ parcMemory_Deallocate((void **)&copy);
+ }
+ }
+ }
+
+ if (ferror(configFile->fh)) {
+ ERROR("Error on input file %s line %d: (%d) %s",
+ configFile->filename, configFile->linesRead, errno,
+ strerror(errno));
+ success = false;
+ }
+
+#endif
+ return success;
+}
+
+void
+configuration_file_free(configuration_file_t * cfg)
+{
+ free(cfg->filename);
+ if (cfg->fh)
+ fclose(cfg->fh);
+ //controlState_Destroy(&cfg->control_state);
+ free(cfg);
+}
diff --git a/hicn-light/src/hicn/config/configurationFile.h b/hicn-light/src/hicn/config/configuration_file.h
index b748dfc15..eedcbc6bd 100644
--- a/hicn-light/src/hicn/config/configurationFile.h
+++ b/hicn-light/src/hicn/config/configuration_file.h
@@ -14,7 +14,7 @@
*/
/**
- * @file configurationFile.h
+ * @file configuration_file.h
* @brief Accepts a filename and provides a means to read it into Configuration
*
* Reads a configuration file and converts the lines in to configuration
@@ -24,24 +24,24 @@
*
*/
-#ifndef configurationFile_h
-#define configurationFile_h
+#ifndef configuration_file_h
+#define configuration_file_h
#include <hicn/core/forwarder.h>
struct configuration_file;
-typedef struct configuration_file ConfigurationFile;
+typedef struct configuration_file configuration_file_t;
/**
- * Creates a ConfigurationFile to prepare to process the file
+ * Creates a configuration_file_t to prepare to process the file
*
* Prepares the object and opens the file. Makes sure we can read the file.
* Does not read the file or process any commands from the file.
*
- * @param [in] hicn-light An allocated Forwarder to configure with the file
+ * @param [in] hicn-light An allocated forwarder_t * to configure with the file
* @param [in] filename The file to use
*
- * @retval non-null An allocated ConfigurationFile that is readable
+ * @retval non-null An allocated configuration_file_t that is readable
* @retval null An error
*
* Example:
@@ -49,8 +49,8 @@ typedef struct configuration_file ConfigurationFile;
* <#example#>
* @endcode
*/
-ConfigurationFile *configurationFile_Create(Forwarder *forwarder,
- const char *filename);
+configuration_file_t * configuration_file_create(forwarder_t * forwarder, const
+ char * filename);
/**
* Reads the configuration file line-by-line and issues commands to
@@ -60,7 +60,7 @@ ConfigurationFile *configurationFile_Create(Forwarder *forwarder,
*
* Will stop on the first error. Lines already processed will not be un-done.
*
- * @param [in] configFile An allocated ConfigurationFile
+ * @param [in] configFile An allocated configuration_file_t
*
* @retval true The entire files was processed without error.
* @retval false There was an error in the file.
@@ -70,17 +70,17 @@ ConfigurationFile *configurationFile_Create(Forwarder *forwarder,
* <#example#>
* @endcode
*/
-bool configurationFile_Process(ConfigurationFile *configFile);
+bool configuration_file_process(configuration_file_t *configFile);
-// void configurationFile_ProcessForwardingStrategies(Configuration * config,
-// ConfigurationFile * configFile);
+// void configuration_file_ProcessForwardingStrategies(Configuration * config,
+// configuration_file_t * configFile);
/**
* Closes the underlying file and releases memory
*
* <#Paragraphs Of Explanation#>
*
- * @param [in,out] configFilePtr An allocated ConfigurationFile that will be
+ * @param [in,out] configFilePtr An allocated configuration_file_t that will be
* NULL'd as output
*
* Example:
@@ -88,6 +88,6 @@ bool configurationFile_Process(ConfigurationFile *configFile);
* <#example#>
* @endcode
*/
-void configurationFile_Release(ConfigurationFile **configFilePtr);
+void configuration_file_free(configuration_file_t * configFile);
-#endif /* defined(configurationFile_h) */
+#endif /* defined(configuration_file_h) */
diff --git a/hicn-light/src/hicn/config/controlAddConnection.c b/hicn-light/src/hicn/config/controlAddConnection.c
index e5af5a251..6160ff188 100644
--- a/hicn-light/src/hicn/config/controlAddConnection.c
+++ b/hicn-light/src/hicn/config/controlAddConnection.c
@@ -29,6 +29,7 @@
#include <hicn/utils/commands.h>
#include <hicn/utils/utils.h>
+#include <hicn/face.h>
// ===================================================
@@ -189,7 +190,7 @@ static CommandReturn _controlAddConnection_Execute(CommandParser *parser,
* @param [in] localAddress the local IP and port. The port may be the wildcard
* value.
* @param [in] remoteAddress The remote IP and port (both must be specified)
- * @param [in] tunnelType The tunneling protocol
+ * @param [in] type The tunneling protocol
* @param [in] symbolic The symbolic name for the connection (must be unique)
*
* @return <#value#> <#explanation#>
@@ -218,44 +219,44 @@ static CommandReturn _controlAddConnection_Execute(CommandParser *parser,
static CommandReturn _controlAddConnection_CreateTunnel(
CommandParser *parser, CommandOps *ops, const char *local_ip,
const char *local_port, const char *remote_ip, const char *remote_port,
- connection_type tunnelType, const char *symbolic) {
+ face_type_t type, const char *symbolic) {
ControlState *state = ops->closure;
// a request like this always has an interface index of 0 [FIELD REMOVED]
// unsigned int interfaceIndex = 0;
// allocate command payload
- add_connection_command *addConnectionCommand =
- parcMemory_AllocateAndClear(sizeof(add_connection_command));
+ cmd_connection_add_t *cmd =
+ parcMemory_AllocateAndClear(sizeof(cmd_connection_add_t));
// check and set IP addresses
- if (inet_pton(AF_INET, remote_ip, &addConnectionCommand->remoteIp.v4.as_u32) ==
+ if (inet_pton(AF_INET, remote_ip, &cmd->remote_ip.v4.as_u32) ==
1 &&
- inet_pton(AF_INET, local_ip, &addConnectionCommand->localIp.v4.as_u32) == 1) {
- addConnectionCommand->ipType = ADDR_INET;
+ inet_pton(AF_INET, local_ip, &cmd->local_ip.v4.as_u32) == 1) {
+ cmd->family = AF_INET;
} else if (inet_pton(AF_INET6, remote_ip,
- &addConnectionCommand->remoteIp.v6.as_in6addr) == 1 &&
+ &cmd->remote_ip.v6.as_in6addr) == 1 &&
inet_pton(AF_INET6, local_ip,
- &addConnectionCommand->localIp.v6.as_in6addr) == 1) {
- addConnectionCommand->ipType = ADDR_INET6;
+ &cmd->local_ip.v6.as_in6addr) == 1) {
+ cmd->family = AF_INET6;
} else {
printf("Error: local address %s not same type as remote address %s\n",
local_ip, remote_ip);
- parcMemory_Deallocate(&addConnectionCommand);
+ parcMemory_Deallocate(&cmd);
return CommandReturn_Failure;
}
// Fill remaining payload fields
- addConnectionCommand->connectionType = tunnelType;
- strcpy(addConnectionCommand->symbolic, symbolic);
- addConnectionCommand->remotePort = htons((uint16_t)atoi(remote_port));
- addConnectionCommand->localPort = htons((uint16_t)atoi(local_port));
+ cmd->type = type;
+ strcpy(cmd->symbolic, symbolic);
+ cmd->remote_port = htons((uint16_t)atoi(remote_port));
+ cmd->local_port = htons((uint16_t)atoi(local_port));
// send message and receive response
struct iovec *response =
- utils_SendRequest(state, ADD_CONNECTION, addConnectionCommand,
- sizeof(add_connection_command));
+ utils_SendRequest(state, COMMAND_TYPE_CONNECTION_ADD, cmd,
+ sizeof(cmd_connection_add_t));
if (!response) { // get NULL pointer
return CommandReturn_Failure;
@@ -318,7 +319,7 @@ static CommandReturn _controlAddConnection_HicnExecute(CommandParser *parser,
char *port = "1234"; // this is a random port number that will be ignored
return _controlAddConnection_CreateTunnel(
- parser, ops, local_ip, port, remote_ip, port, HICN_CONN, symbolic);
+ parser, ops, local_ip, port, remote_ip, port, FACE_TYPE_HICN, symbolic);
}
#endif
@@ -360,7 +361,7 @@ static CommandReturn _controlAddConnection_UdpExecute(CommandParser *parser,
char *local_port = parcList_GetAtIndex(args, _indexLocPort);
return _controlAddConnection_CreateTunnel(parser, ops, local_ip, local_port,
- remote_ip, remote_port, UDP_CONN,
+ remote_ip, remote_port, FACE_TYPE_UDP,
symbolic);
}
@@ -402,6 +403,6 @@ static CommandReturn _controlAddConnection_TcpExecute(CommandParser *parser,
char *local_port = parcList_GetAtIndex(args, _indexLocPort);
return _controlAddConnection_CreateTunnel(parser, ops, local_ip, local_port,
- remote_ip, remote_port, TCP_CONN,
+ remote_ip, remote_port, FACE_TYPE_TCP,
symbolic);
}
diff --git a/hicn-light/src/hicn/config/controlAddListener.c b/hicn-light/src/hicn/config/controlAddListener.c
index 2f0fd3f67..18766fd49 100644
--- a/hicn-light/src/hicn/config/controlAddListener.c
+++ b/hicn-light/src/hicn/config/controlAddListener.c
@@ -107,10 +107,10 @@ static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops,
// check and set IP address
if (inet_pton(AF_INET, addr, &addListenerCommand->address.v4.as_u32) == 1) {
- addListenerCommand->addressType = ADDR_INET;
+ addListenerCommand->family = AF_INET;
} else if (inet_pton(AF_INET6, addr, &addListenerCommand->address.v6.as_in6addr) == 1) {
- addListenerCommand->addressType = ADDR_INET6;
+ addListenerCommand->family = AF_INET6;
} else {
printf("Error: %s is not a valid network address \n", addr);
diff --git a/hicn-light/src/hicn/config/controlAddPolicy.c b/hicn-light/src/hicn/config/controlAddPolicy.c
index 29120446b..24b9d5eec 100644
--- a/hicn-light/src/hicn/config/controlAddPolicy.c
+++ b/hicn-light/src/hicn/config/controlAddPolicy.c
@@ -111,7 +111,7 @@ static CommandReturn _controlAddPolicy_Execute(CommandParser *parser,
free(addr);
return CommandReturn_Failure;
}
- addPolicyCommand->addressType = ADDR_INET;
+ addPolicyCommand->family = AF_INET;
} else if (inet_pton(AF_INET6, addr, &addPolicyCommand->address.v6.as_in6addr) == 1) {
if (len > 128) {
printf("ERROR: exceeded INET6 mask length, max=128\n");
@@ -119,7 +119,7 @@ static CommandReturn _controlAddPolicy_Execute(CommandParser *parser,
free(addr);
return CommandReturn_Failure;
}
- addPolicyCommand->addressType = ADDR_INET6;
+ addPolicyCommand->family = AF_INET6;
} else {
printf("Error: %s is not a valid network address \n", addr);
parcMemory_Deallocate(&addPolicyCommand);
diff --git a/hicn-light/src/hicn/config/controlAddPunting.c b/hicn-light/src/hicn/config/controlAddPunting.c
index e3fb57c6b..a83350876 100644
--- a/hicn-light/src/hicn/config/controlAddPunting.c
+++ b/hicn-light/src/hicn/config/controlAddPunting.c
@@ -116,7 +116,7 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
free(addr);
return CommandReturn_Failure;
}
- addPuntingCommand->addressType = ADDR_INET;
+ addPuntingCommand->family = AF_INET;
} else if (inet_pton(AF_INET6, addr, &addPuntingCommand->address.v6.as_in6addr) == 1) {
if (len > 128) {
printf("ERROR: exceeded INET6 mask length, max=128\n");
@@ -124,7 +124,7 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
free(addr);
return CommandReturn_Failure;
}
- addPuntingCommand->addressType = ADDR_INET6;
+ addPuntingCommand->family = AF_INET6;
} else {
printf("Error: %s is not a valid network address \n", addr);
parcMemory_Deallocate(&addPuntingCommand);
diff --git a/hicn-light/src/hicn/config/controlAddRoute.c b/hicn-light/src/hicn/config/controlAddRoute.c
index 8a1adf6d6..f7b83e3a8 100644
--- a/hicn-light/src/hicn/config/controlAddRoute.c
+++ b/hicn-light/src/hicn/config/controlAddRoute.c
@@ -109,29 +109,29 @@ static CommandReturn _controlAddRoute_Execute(CommandParser *parser,
}
// allocate command payload
- add_route_command *addRouteCommand =
- parcMemory_AllocateAndClear(sizeof(add_route_command));
+ cmd_route_add_t *cmd =
+ parcMemory_AllocateAndClear(sizeof(cmd_route_add_t));
// check and set IP address
- if (inet_pton(AF_INET, addr, &addRouteCommand->address.v4.as_u32) == 1) {
+ if (inet_pton(AF_INET, addr, &cmd->address.v4.as_u32) == 1) {
if (len > 32) {
printf("ERROR: exceeded INET mask length, max=32\n");
- parcMemory_Deallocate(&addRouteCommand);
+ parcMemory_Deallocate(&cmd);
free(addr);
return CommandReturn_Failure;
}
- addRouteCommand->addressType = ADDR_INET;
- } else if (inet_pton(AF_INET6, addr, &addRouteCommand->address.v6.as_in6addr) == 1) {
+ cmd->family = AF_INET;
+ } else if (inet_pton(AF_INET6, addr, &cmd->address.v6.as_in6addr) == 1) {
if (len > 128) {
printf("ERROR: exceeded INET6 mask length, max=128\n");
- parcMemory_Deallocate(&addRouteCommand);
+ parcMemory_Deallocate(&cmd);
free(addr);
return CommandReturn_Failure;
}
- addRouteCommand->addressType = ADDR_INET6;
+ cmd->family = AF_INET6;
} else {
printf("Error: %s is not a valid network address \n", addr);
- parcMemory_Deallocate(&addRouteCommand);
+ parcMemory_Deallocate(&cmd);
free(addr);
return CommandReturn_Failure;
}
@@ -139,13 +139,13 @@ static CommandReturn _controlAddRoute_Execute(CommandParser *parser,
free(addr);
// Fill remaining payload fields
- addRouteCommand->len = len;
- addRouteCommand->cost = (uint16_t)cost;
- strcpy(addRouteCommand->symbolicOrConnid, symbolicOrConnid);
+ cmd->len = len;
+ cmd->cost = (uint16_t)cost;
+ strcpy(cmd->symbolicOrConnid, symbolicOrConnid);
// send message and receive response
- struct iovec *response = utils_SendRequest(state, ADD_ROUTE, addRouteCommand,
- sizeof(add_route_command));
+ struct iovec *response = utils_SendRequest(state, COMMAND_TYPE_ROUTE_ADD, cmd,
+ sizeof(cmd_route_add_t));
if (!response) { // get NULL pointer
return CommandReturn_Failure;
diff --git a/hicn-light/src/hicn/config/controlListConnections.c b/hicn-light/src/hicn/config/controlListConnections.c
index cbed8a79c..c47431726 100644
--- a/hicn-light/src/hicn/config/controlListConnections.c
+++ b/hicn-light/src/hicn/config/controlListConnections.c
@@ -38,8 +38,10 @@ static CommandReturn _controlListConnections_HelpExecute(CommandParser *parser,
static const char *_commandListConnections = "list connections";
static const char *_commandListConnectionsHelp = "help list connections";
+
+// XXX TODO in connection{_state}.h
const char *connTypeString[6] = {"GRE", "TCP", "UDP", "MCAST", "L2", "HICN"};
-const char *stateString[3] = {"UP", "DOWN", "UNKNOWN"};
+const char *stateString[3] = {"UNKNOWN", "DOWN", "UP"};
CommandOps *controlListConnections_Create(ControlState *state) {
return commandOps_Create(state, _commandListConnections, NULL,
@@ -127,12 +129,12 @@ static CommandReturn _controlListConnections_Execute(CommandParser *parser,
(i * sizeof(list_connections_command)));
sourceString = utils_CommandAddressToString(
- listConnectionsCommand->connectionData.ipType,
+ listConnectionsCommand->connectionData.family,
&listConnectionsCommand->connectionData.localIp,
&listConnectionsCommand->connectionData.localPort);
destinationString = utils_CommandAddressToString(
- listConnectionsCommand->connectionData.ipType,
+ listConnectionsCommand->connectionData.family,
&listConnectionsCommand->connectionData.remoteIp,
&listConnectionsCommand->connectionData.remotePort);
diff --git a/hicn-light/src/hicn/config/controlListListeners.c b/hicn-light/src/hicn/config/controlListListeners.c
index 1489470a8..f0ab820f5 100644
--- a/hicn-light/src/hicn/config/controlListListeners.c
+++ b/hicn-light/src/hicn/config/controlListListeners.c
@@ -106,7 +106,7 @@ static CommandReturn _controlListListeners_Execute(CommandParser *parser,
(list_listeners_command *)(receivedPayload +
(i * sizeof(list_listeners_command)));
- addrString = utils_CommandAddressToString(listListenersCommand->addressType,
+ addrString = utils_CommandAddressToString(listListenersCommand->family,
&listListenersCommand->address,
&listListenersCommand->port);
diff --git a/hicn-light/src/hicn/config/controlListPolicies.c b/hicn-light/src/hicn/config/controlListPolicies.c
index 81be6ddfc..9ea3bae75 100644
--- a/hicn-light/src/hicn/config/controlListPolicies.c
+++ b/hicn-light/src/hicn/config/controlListPolicies.c
@@ -148,7 +148,7 @@ static CommandReturn _controlListPolicies_Execute(CommandParser *parser,
#undef _
addrString = utils_CommandAddressToString(
- listPoliciesCommand->addressType, &listPoliciesCommand->address, &port);
+ listPoliciesCommand->family, &listPoliciesCommand->address, &port);
#if 0
PARCBufferComposer *composer = parcBufferComposer_Create();
@@ -191,6 +191,7 @@ static CommandReturn _controlListPolicies_Execute(CommandParser *parser,
#endif
}
+#if 0
printf("\nSTATISTICS\n\n");
// STATISTICS
printf("%*s %*s %*s | %*s | %*s | %*s\n",
@@ -207,22 +208,23 @@ static CommandReturn _controlListPolicies_Execute(CommandParser *parser,
(list_policies_command *)(receivedPayload +
(i * sizeof(list_policies_command)));
addrString = utils_CommandAddressToString(
- listPoliciesCommand->addressType, &listPoliciesCommand->address, &port);
+ listPoliciesCommand->family, &listPoliciesCommand->address, &port);
printf("%*s %*s %*.2f %*.2f %*.2f | %*.2f %*.2f %*.2f | %*.2f %*.2f %*.2f | %*.2f %*.2f %*.2f\n",
MAXSZ_PREFIX, addrString, MAXSZ_APP_NAME, listPoliciesCommand->policy.app_name,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.wired.throughput,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.wired.latency,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.wired.loss_rate,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.wifi.throughput,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.wifi.latency,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.wifi.loss_rate,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.cellular.throughput,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.cellular.latency,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.cellular.loss_rate,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.all.throughput,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.all.latency,
- MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.all.loss_rate);
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.wired.throughput,
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.wired.latency,
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.wired.loss_rate,
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.wifi.throughput,
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.wifi.latency,
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.wifi.loss_rate,
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.cellular.throughput,
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.cellular.latency,
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.cellular.loss_rate,
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.all.throughput,
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.all.latency,
+ MAXSZ_STR_STAT, listPoliciesCommand->prefix_stats.all.loss_rate);
}
+#endif
controlState_SetCommandOutput(state, commandOutputMain);
diff --git a/hicn-light/src/hicn/config/controlListRoutes.c b/hicn-light/src/hicn/config/controlListRoutes.c
index 3dc8fa3a3..33a1ac6f5 100644
--- a/hicn-light/src/hicn/config/controlListRoutes.c
+++ b/hicn-light/src/hicn/config/controlListRoutes.c
@@ -120,7 +120,7 @@ static CommandReturn _controlListRoutes_Execute(CommandParser *parser,
(i * sizeof(list_routes_command)));
addrString = utils_CommandAddressToString(
- listRoutesCommand->addressType, &listRoutesCommand->address, &port);
+ listRoutesCommand->family, &listRoutesCommand->address, &port);
PARCBufferComposer *composer = parcBufferComposer_Create();
diff --git a/hicn-light/src/hicn/config/controlRemoveConnection.c b/hicn-light/src/hicn/config/controlRemoveConnection.c
index 7c79f9c2f..cbc1fb8db 100644
--- a/hicn-light/src/hicn/config/controlRemoveConnection.c
+++ b/hicn-light/src/hicn/config/controlRemoveConnection.c
@@ -25,7 +25,6 @@
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Network.h>
-#include <hicn/utils/address.h>
#include <hicn/config/controlRemoveConnection.h>
diff --git a/hicn-light/src/hicn/config/controlRemoveListener.c b/hicn-light/src/hicn/config/controlRemoveListener.c
index 545e189c0..2e38a8a2f 100644
--- a/hicn-light/src/hicn/config/controlRemoveListener.c
+++ b/hicn-light/src/hicn/config/controlRemoveListener.c
@@ -25,7 +25,6 @@
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Network.h>
-#include <hicn/utils/address.h>
#include <hicn/config/controlRemoveListener.h>
diff --git a/hicn-light/src/hicn/config/controlRemovePolicy.c b/hicn-light/src/hicn/config/controlRemovePolicy.c
index bd2e6e6d8..ff49cb73a 100644
--- a/hicn-light/src/hicn/config/controlRemovePolicy.c
+++ b/hicn-light/src/hicn/config/controlRemovePolicy.c
@@ -27,8 +27,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include <hicn/utils/address.h>
-
#include <hicn/config/controlRemovePolicy.h>
#include <hicn/utils/commands.h>
@@ -103,7 +101,7 @@ static CommandReturn _controlRemovePolicy_Execute(CommandParser *parser,
free(addr);
return CommandReturn_Failure;
}
- removePolicyCommand->addressType = ADDR_INET;
+ removePolicyCommand->family = AF_INET;
} else if (inet_pton(AF_INET6, addr, &removePolicyCommand->address.v6.as_in6addr) ==
1) {
if (len > 128) {
@@ -112,7 +110,7 @@ static CommandReturn _controlRemovePolicy_Execute(CommandParser *parser,
free(addr);
return CommandReturn_Failure;
}
- removePolicyCommand->addressType = ADDR_INET6;
+ removePolicyCommand->family = AF_INET6;
} else {
printf("Error: %s is not a valid network address \n", addr);
parcMemory_Deallocate(&removePolicyCommand);
diff --git a/hicn-light/src/hicn/config/controlRemovePunting.c b/hicn-light/src/hicn/config/controlRemovePunting.c
index bf00389d6..b5b734820 100644
--- a/hicn-light/src/hicn/config/controlRemovePunting.c
+++ b/hicn-light/src/hicn/config/controlRemovePunting.c
@@ -25,7 +25,6 @@
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Network.h>
-#include <hicn/utils/address.h>
#include <hicn/config/controlRemovePunting.h>
diff --git a/hicn-light/src/hicn/config/controlRemoveRoute.c b/hicn-light/src/hicn/config/controlRemoveRoute.c
index 0f46211c1..067fea25f 100644
--- a/hicn-light/src/hicn/config/controlRemoveRoute.c
+++ b/hicn-light/src/hicn/config/controlRemoveRoute.c
@@ -25,8 +25,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include <hicn/utils/address.h>
-
#include <hicn/config/controlRemoveRoute.h>
#include <hicn/utils/commands.h>
@@ -111,7 +109,7 @@ static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
free(addr);
return CommandReturn_Failure;
}
- removeRouteCommand->addressType = ADDR_INET;
+ removeRouteCommand->family = AF_INET;
} else if (inet_pton(AF_INET6, addr, &removeRouteCommand->address.v6.as_in6addr) ==
1) {
if (len > 128) {
@@ -120,7 +118,7 @@ static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
free(addr);
return CommandReturn_Failure;
}
- removeRouteCommand->addressType = ADDR_INET6;
+ removeRouteCommand->family = AF_INET6;
} else {
printf("Error: %s is not a valid network address \n", addr);
parcMemory_Deallocate(&removeRouteCommand);
diff --git a/hicn-light/src/hicn/config/controlSetStrategy.c b/hicn-light/src/hicn/config/controlSetStrategy.c
index 10fec964b..3cb5d9df5 100644
--- a/hicn-light/src/hicn/config/controlSetStrategy.c
+++ b/hicn-light/src/hicn/config/controlSetStrategy.c
@@ -42,7 +42,8 @@ static CommandReturn _controlSetStrategy_HelpExecute(CommandParser *parser,
static const char *_commandSetStrategy = "set strategy";
static const char *_commandSetStrategyHelp = "help set strategy";
-static const char *_commandSetStrategyOptions[LAST_STRATEGY_VALUE] = {
+static const char *_commandSetStrategyOptions[STRATEGY_TYPE_N] = {
+ "(undefined)",
"loadbalancer",
"random",
"low_latency",
@@ -62,10 +63,10 @@ CommandOps *controlSetStrategy_HelpCreate(ControlState *state) {
// ====================================================
-strategy_type _validStrategy(const char *strategy) {
- strategy_type validStrategy = LAST_STRATEGY_VALUE;
+strategy_type_t _validStrategy(const char *strategy) {
+ strategy_type_t validStrategy = STRATEGY_TYPE_UNDEFINED;
- for (int i = 0; i < LAST_STRATEGY_VALUE; i++) {
+ for (int i = 0; i < STRATEGY_TYPE_N; i++) {
if (strcmp(_commandSetStrategyOptions[i], strategy) == 0) {
validStrategy = i;
break;
@@ -92,7 +93,7 @@ static bool _checkAndSetIp(set_strategy_command * setStrategyCommand,
res = inet_pton(AF_INET, addr, &setStrategyCommand->address.v4.as_u32);
else
res = inet_pton(AF_INET, addr,
- &setStrategyCommand->addresses[index].v4.as_u32);
+ &setStrategyCommand->low_latency.addresses[index].v4.as_u32);
if(res == 1) {
if (len == UINT32_MAX) {
@@ -103,9 +104,9 @@ static bool _checkAndSetIp(set_strategy_command * setStrategyCommand,
return false;
}
if(index == -1)
- setStrategyCommand->addressType = ADDR_INET;
+ setStrategyCommand->family = AF_INET;
else
- setStrategyCommand->addresses_type[index] = ADDR_INET;
+ setStrategyCommand->low_latency.families[index] = AF_INET;
} else {
@@ -114,7 +115,7 @@ static bool _checkAndSetIp(set_strategy_command * setStrategyCommand,
&setStrategyCommand->address.v6.as_in6addr);
else
res = inet_pton(AF_INET6, addr,
- &setStrategyCommand->addresses[index].v6.as_in6addr);
+ &setStrategyCommand->low_latency.addresses[index].v6.as_in6addr);
if(res == 1) {
if (len == UINT32_MAX) {
@@ -126,9 +127,9 @@ static bool _checkAndSetIp(set_strategy_command * setStrategyCommand,
}
if(index == -1)
- setStrategyCommand->addressType = ADDR_INET6;
+ setStrategyCommand->family = AF_INET6;
else
- setStrategyCommand->addresses_type[index] = ADDR_INET6;
+ setStrategyCommand->low_latency.families[index] = AF_INET6;
} else {
printf("Error: %s is not a valid network address \n", addr);
@@ -191,8 +192,8 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
const char *strategyStr = parcList_GetAtIndex(args, 3);
// check valid strategy
- strategy_type strategy;
- if ((strategy = _validStrategy(strategyStr)) == LAST_STRATEGY_VALUE) {
+ strategy_type_t strategy;
+ if ((strategy = _validStrategy(strategyStr)) == STRATEGY_TYPE_UNDEFINED) {
printf("Error: invalid strategy \n");
parcMemory_Deallocate(&setStrategyCommand);
_controlSetStrategy_HelpExecute(parser, ops, args);
@@ -204,7 +205,7 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
// Fill remaining payload fields
setStrategyCommand->len = len;
- setStrategyCommand->strategyType = strategy;
+ setStrategyCommand->strategy_type = strategy;
//check additional prefixes
if(parcList_Size(args) > 4){
@@ -223,7 +224,7 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
free(rel_addr);
return CommandReturn_Failure;
}
- setStrategyCommand->lens[addr_index] = rel_len;
+ setStrategyCommand->low_latency.lens[addr_index] = rel_len;
free(rel_addr);
index++;
addr_index++;
diff --git a/hicn-light/src/hicn/config/controlState.c b/hicn-light/src/hicn/config/controlState.c
index 2df8805c6..34a0b1327 100644
--- a/hicn-light/src/hicn/config/controlState.c
+++ b/hicn-light/src/hicn/config/controlState.c
@@ -42,7 +42,7 @@ struct controller_state {
bool debugFlag;
void *userdata;
- struct iovec *(*writeRead)(ControlState *state, struct iovec *msg);
+ uint8_t *(*writeRead)(ControlState *state, uint8_t *msg);
int sockfd;
char **commandOutput;
bool isInteractive;
@@ -75,7 +75,7 @@ int controlState_connectToFwdDeamon(char *server_ip, uint16_t port) {
ControlState *controlState_Create(
void *userdata,
- struct iovec *(*writeRead)(ControlState *state, struct iovec *msg),
+ uint8_t *(*writeRead)(ControlState *state, uint8_t * msg),
bool openControllerConnetion,
char *server_ip, uint16_t port) {
ControlState *state = parcMemory_AllocateAndClear(sizeof(ControlState));
@@ -128,11 +128,13 @@ void controlState_RegisterCommand(ControlState *state, CommandOps *ops) {
commandParser_RegisterCommand(state->parser, ops);
}
-struct iovec *controlState_WriteRead(ControlState *state, struct iovec *msg) {
- parcAssertNotNull(state, "Parameter state must be non-null");
- parcAssertNotNull(msg, "Parameter msg must be non-null");
+uint8_t *
+controlState_write_read(ControlState *state, uint8_t *packet)
+{
+ assert(state);
+ assert(packet);
- return state->writeRead(state, msg);
+ return state->writeRead(state, packet);
}
static PARCList *_controlState_ParseStringIntoTokens(
diff --git a/hicn-light/src/hicn/config/controlState.h b/hicn-light/src/hicn/config/controlState.h
index cc38cbe37..5c565f9a4 100644
--- a/hicn-light/src/hicn/config/controlState.h
+++ b/hicn-light/src/hicn/config/controlState.h
@@ -61,7 +61,7 @@ typedef struct controller_state ControlState;
ControlState *controlState_Create(
void *userdata,
- struct iovec *(*writeRead)(ControlState *state, struct iovec *msg),
+ uint8_t *(*writeRead)(ControlState *state, uint8_t * msg),
bool openControllerConnetion,
char * server_ip, uint16_t port);
diff --git a/hicn-light/src/hicn/config/symbolicNameTable.c b/hicn-light/src/hicn/config/symbolicNameTable.c
deleted file mode 100644
index e5ae81d3e..000000000
--- a/hicn-light/src/hicn/config/symbolicNameTable.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright (c) 2017-2019 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 <ctype.h>
-#include <parc/algol/parc_Hash.h>
-#include <parc/algol/parc_HashCodeTable.h>
-#include <parc/algol/parc_Memory.h>
-#include <parc/assert/parc_Assert.h>
-#include <hicn/hicn-light/config.h>
-#include <stdio.h>
-
-#include <hicn/config/symbolicNameTable.h>
-
-struct symblic_name_table {
- PARCHashCodeTable *symbolicNameTable;
- PARCHashCodeTable *indexToNameTable;
-};
-
-// ========================================================================================
-// symbolic name table functions
-
-static bool _symbolicNameEquals(const void *keyA, const void *keyB) {
- return (strcasecmp((const char *)keyA, (const char *)keyB) == 0);
-}
-
-static HashCodeType _symbolicNameHash(const void *keyA) {
- const char *str = (const char *)keyA;
- size_t length = strlen(str);
- return parcHash32_Data(str, length);
-}
-
-static bool _connectionIdEquals(const void *keyA, const void *keyB) {
- unsigned idA = *((unsigned *)keyA);
- unsigned idB = *((unsigned *)keyB);
- return (idA == idB);
-}
-
-static HashCodeType _connectionIdHash(const void *keyA) {
- unsigned idA = *((unsigned *)keyA);
- return parcHash32_Int32(idA);
-}
-
-// ========================================================================================
-
-SymbolicNameTable *symbolicNameTable_Create(void) {
- SymbolicNameTable *table = parcMemory_Allocate(sizeof(SymbolicNameTable));
-
- if (table) {
- // key = char *
- // value = uint32_t *
- table->symbolicNameTable = parcHashCodeTable_Create(
- _symbolicNameEquals, _symbolicNameHash, parcMemory_DeallocateImpl,
- parcMemory_DeallocateImpl);
- table->indexToNameTable = parcHashCodeTable_Create(
- _connectionIdEquals, _connectionIdHash, parcMemory_DeallocateImpl,
- parcMemory_DeallocateImpl);
- }
-
- return table;
-}
-
-void symbolicNameTable_Destroy(SymbolicNameTable **tablePtr) {
- SymbolicNameTable *table = *tablePtr;
- parcHashCodeTable_Destroy(&table->symbolicNameTable);
- parcHashCodeTable_Destroy(&table->indexToNameTable);
- parcMemory_Deallocate((void **)&table);
- *tablePtr = NULL;
-}
-
-static char *_createKey(const char *symbolicName) {
- char *key = parcMemory_StringDuplicate(symbolicName, strlen(symbolicName));
-
- // convert key to upper case
- char *p = key;
-
- // keeps looping until the first null
- while ((*p = toupper(*p))) {
- p++;
- }
- return key;
-}
-
-bool symbolicNameTable_Exists(SymbolicNameTable *table,
- const char *symbolicName) {
- parcAssertNotNull(table, "Parameter table must be non-null");
- parcAssertNotNull(symbolicName, "Parameter symbolicName must be non-null");
-
- char *key = _createKey(symbolicName);
- bool found = (parcHashCodeTable_Get(table->symbolicNameTable, key) != NULL);
- parcMemory_Deallocate((void **)&key);
- return found;
-}
-
-void symbolicNameTable_Remove(SymbolicNameTable *table,
- const char *symbolicName) {
- parcAssertNotNull(table, "Parameter table must be non-null");
- parcAssertNotNull(symbolicName, "Parameter symbolicName must be non-null");
-
- char *key = _createKey(symbolicName);
-
- unsigned id = symbolicNameTable_Get(table, symbolicName);
- uint32_t *value = parcMemory_Allocate(sizeof(uint32_t));
- *value = id;
-
- parcHashCodeTable_Del(table->symbolicNameTable, key);
- parcHashCodeTable_Del(table->indexToNameTable, value);
- parcMemory_Deallocate((void **)&key);
- parcMemory_Deallocate((void **)&value);
-}
-
-bool symbolicNameTable_Add(SymbolicNameTable *table, const char *symbolicName,
- unsigned connid) {
- parcAssertNotNull(table, "Parameter table must be non-null");
- parcAssertNotNull(symbolicName, "Parameter symbolicName must be non-null");
- parcAssertTrue(connid < UINT32_MAX, "Parameter connid must be less than %u",
- UINT32_MAX);
-
- char *key1 = _createKey(symbolicName);
-
- uint32_t *value1 = parcMemory_Allocate(sizeof(uint32_t));
- *value1 = connid;
-
- bool success = parcHashCodeTable_Add(table->symbolicNameTable, key1, value1);
- if (!success)
- goto ERR_NAME;
-
- char *key2 = _createKey(symbolicName);
-
- uint32_t *value2 = parcMemory_Allocate(sizeof(uint32_t));
- *value2 = connid;
-
- success = parcHashCodeTable_Add(table->indexToNameTable, value2, key2);
- if (!success)
- goto ERR_INDEX;
-
- goto END;
-
-ERR_INDEX:
- parcMemory_Deallocate((void **)&key2);
- parcMemory_Deallocate((void **)&value2);
- parcHashCodeTable_Del(table->symbolicNameTable, key1);
-ERR_NAME:
- parcMemory_Deallocate((void **)&key1);
- parcMemory_Deallocate((void **)&value1);
-END:
- return success;
-
-}
-
-unsigned symbolicNameTable_Get(SymbolicNameTable *table,
- const char *symbolicName) {
- parcAssertNotNull(table, "Parameter table must be non-null");
- parcAssertNotNull(symbolicName, "Parameter symbolicName must be non-null");
-
- unsigned connid = UINT32_MAX;
-
- char *key = _createKey(symbolicName);
-
- uint32_t *value = parcHashCodeTable_Get(table->symbolicNameTable, key);
- if (value)
- connid = *value;
-
- parcMemory_Deallocate((void **)&key);
- return connid;
-}
-
-const char *symbolicNameTable_GetNameByIndex(SymbolicNameTable *table,
- unsigned id) {
- parcAssertNotNull(table, "Parameter table must be non-null");
-
- uint32_t *value = parcMemory_Allocate(sizeof(uint32_t));
- *value = id;
-
- const char *name = parcHashCodeTable_Get(table->indexToNameTable, value);
- if (name == NULL) name = "";
-
- parcMemory_Deallocate((void **)&value);
- return name;
-}