aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnrico Loparco (eloparco) <eloparco@cisco.com>2021-03-23 14:58:34 +0100
committerMauro Sardara <msardara@cisco.com>2021-03-30 15:23:55 +0000
commita5a6ffb506aa3c2a0c7fe8fd09abf3f737984aa5 (patch)
treecfb82e9667e287b08c665d4d671b6e767490d403
parenta070b0de9f9e9cbca150eea4eda74757ca588bed (diff)
[HICN-645] Fix data structures to support hicn-light-daemon and hicn-light-control communication
The daemon should be able to start, receive commands from hicn-light-control and execute them. Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com> Change-Id: I0ca5bb3d9bdfb37ac8cfa9f671f6c162c9a394f5 Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com>
-rw-r--r--.gitignore1
-rw-r--r--cmake/Modules/GTestImport.cmake6
-rw-r--r--ctrl/libhicnctrl/includes/hicn/ctrl/commands.h575
-rw-r--r--ctrl/libhicnctrl/src/api.c282
-rw-r--r--ctrl/libhicnctrl/src/hicn_plugin_api.c2
-rw-r--r--hicn-light/src/hicn/cli/hicnc.c28
-rw-r--r--hicn-light/src/hicn/config/configuration.c44
-rw-r--r--hicn-light/src/hicn/config/configuration.h5
-rw-r--r--hicn-light/src/hicn/config/controlListConnections.c4
-rw-r--r--hicn-light/src/hicn/config/controlListListeners.c4
-rw-r--r--hicn-light/src/hicn/config/controlListPolicies.c4
-rw-r--r--hicn-light/src/hicn/config/controlListRoutes.c4
-rw-r--r--hicn-light/src/hicn/core/connection.c26
-rw-r--r--hicn-light/src/hicn/core/connection_vft.c6
-rw-r--r--hicn-light/src/hicn/core/forwarder.c16
-rw-r--r--hicn-light/src/hicn/core/listener.c46
-rw-r--r--hicn-light/src/hicn/core/listener.h2
-rw-r--r--hicn-light/src/hicn/core/listener_vft.c6
-rw-r--r--hicn-light/src/hicn/core/msgbuf.h1
-rw-r--r--hicn-light/src/hicn/core/test/test-msgbuf_pool.cc2
-rw-r--r--hicn-light/src/hicn/io/base.c5
-rw-r--r--hicn-light/src/hicn/io/tcp.c4
-rw-r--r--hicn-light/src/hicn/io/udp.c15
-rw-r--r--hicn-light/src/hicn/utils/utils.c10
-rw-r--r--lib/includes/hicn/face.h9
-rw-r--r--lib/includes/hicn/util/ip_address.h11
-rw-r--r--lib/src/face.c21
27 files changed, 609 insertions, 530 deletions
diff --git a/.gitignore b/.gitignore
index 52ecb4e..869c746 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
build*
.ccls-cache/
compile_commands.json
+.vscode \ No newline at end of file
diff --git a/cmake/Modules/GTestImport.cmake b/cmake/Modules/GTestImport.cmake
index 938dec7..cdca922 100644
--- a/cmake/Modules/GTestImport.cmake
+++ b/cmake/Modules/GTestImport.cmake
@@ -19,6 +19,12 @@ ExternalProject_Add(gtest
URL https://github.com/google/googletest/archive/v1.10.x.zip
PREFIX ${CMAKE_BINARY_DIR}/gtest
INSTALL_COMMAND ""
+
+ # Necessary to build using ninja
+ BUILD_BYPRODUCTS "${CMAKE_BINARY_DIR}/gtest/src/gtest-build/lib/libgmock.a"
+ BUILD_BYPRODUCTS "${CMAKE_BINARY_DIR}/gtest/src/gtest-build/lib/libgmock_main.a"
+ BUILD_BYPRODUCTS "${CMAKE_BINARY_DIR}/gtest/src/gtest-build/lib/libgtest_main.a"
+ BUILD_BYPRODUCTS "${CMAKE_BINARY_DIR}/gtest/src/gtest-build/lib/libgtest.a"
)
ExternalProject_Get_Property(gtest source_dir binary_dir)
diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h b/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h
index d8e5329..767ef98 100644
--- a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h
+++ b/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h
@@ -43,47 +43,6 @@ typedef struct in6_addr ipv6_addr_t;
typedef uint32_t ipv4_addr_t;
typedef enum {
- REQUEST_LIGHT = 0xc0, // this is a command
- RESPONSE_LIGHT,
- ACK_LIGHT,
- NACK_LIGHT,
- LAST_MSG_TYPE_VALUE
-} message_type;
-
-typedef enum {
- ADD_LISTENER = 0,
- ADD_CONNECTION,
- LIST_CONNECTIONS,
- ADD_ROUTE,
- LIST_ROUTES,
- REMOVE_CONNECTION,
- REMOVE_LISTENER,
- REMOVE_ROUTE,
- CACHE_STORE,
- CACHE_SERVE,
- CACHE_CLEAR,
- SET_STRATEGY,
- SET_WLDR,
- ADD_PUNTING,
- LIST_LISTENERS,
- MAPME_ENABLE,
- MAPME_DISCOVERY,
- MAPME_TIMESCALE,
- MAPME_RETX,
- MAPME_SEND_UPDATE,
- CONNECTION_SET_ADMIN_STATE,
-#ifdef WITH_POLICY
- ADD_POLICY,
- LIST_POLICIES,
- REMOVE_POLICY,
- UPDATE_CONNECTION,
- CONNECTION_SET_PRIORITY,
- CONNECTION_SET_TAGS,
-#endif /* WITH_POLICY */
- LAST_COMMAND_VALUE
-} command_id;
-
-typedef enum {
ADDR_INET = 1,
ADDR_INET6,
ADDR_LINK,
@@ -98,58 +57,144 @@ typedef enum {
HICN_CONN
} connection_type;
-typedef enum { ACTIVATE_ON, ACTIVATE_OFF } activate_type;
+typedef struct in6_addr ipv6_addr_t;
+typedef uint32_t ipv4_addr_t;
-//========== HEADER ==========
+typedef enum {
+ MESSAGE_COMMAND_SUBTYPE_UNDEFINED,
+ REQUEST_LIGHT = 0xc0, // this is a command
+ RESPONSE_LIGHT,
+ ACK_LIGHT,
+ NACK_LIGHT,
+ MESSAGE_COMMAND_SUBTYPE_N
+} message_command_subtype_t;
+
+#define message_type_is_valid(message_type) \
+ ((message_type != MESSAGE_TYPE_UNDEFINED) && (message_type != MESSAGE_COMMAND_SUBTYPE_N))
+
+#define message_type_from_uchar(x) \
+ (((x) < REQUEST_LIGHT) || (((x) >= MESSAGE_COMMAND_SUBTYPE_N)) ? MESSAGE_COMMAND_SUBTYPE_N : (message_command_subtype_t)(x))
+
+#define foreach_command_type \
+ _(listener_add, LISTENER_ADD) \
+ _(listener_remove, LISTENER_REMOVE) \
+ _(listener_list, LISTENER_LIST) \
+ _(connection_add, CONNECTION_ADD) \
+ _(connection_remove, CONNECTION_REMOVE) \
+ _(connection_list, CONNECTION_LIST) \
+ _(connection_set_admin_state, CONNECTION_SET_ADMIN_STATE) \
+ _(connection_update, CONNECTION_UPDATE) \
+ _(connection_set_priority, CONNECTION_SET_PRIORITY) \
+ _(connection_set_tags, CONNECTION_SET_TAGS) \
+ _(route_add, ROUTE_ADD) \
+ _(route_remove, ROUTE_REMOVE) \
+ _(route_list, ROUTE_LIST) \
+ _(cache_set_store, CACHE_SET_STORE) \
+ _(cache_set_serve, CACHE_SET_SERVE) \
+ _(cache_clear, CACHE_CLEAR) \
+ _(strategy_set, STRATEGY_SET) \
+ _(wldr_set, WLDR_SET) \
+ _(punting_add, PUNTING_ADD) \
+ _(mapme_enable, MAPME_ENABLE) \
+ _(mapme_set_discovery, MAPME_SET_DISCOVERY) \
+ _(mapme_set_timescale, MAPME_SET_TIMESCALE) \
+ _(mapme_set_retx, MAPME_SET_RETX) \
+ _(mapme_send_update, MAPME_SEND_UPDATE) \
+ _(policy_add, POLICY_ADD) \
+ _(policy_remove, POLICY_REMOVE) \
+ _(policy_list, POLICY_LIST) \
+
+typedef enum {
+ COMMAND_TYPE_UNDEFINED,
+#define _(l, u) COMMAND_TYPE_ ## u,
+ foreach_command_type
+#undef _
+ COMMAND_TYPE_N,
+} command_type_t;
+
+#define command_type_is_valid(command_type) \
+ ((command_type != COMMAND_TYPE_UNDEFINED) && (command_type != COMMAND_TYPE_N))
+#define command_type_from_uchar(x) \
+ (((x) >= COMMAND_TYPE_N) ? COMMAND_TYPE_N : (command_type_t)(x))
+
+/* Header */
+
+/* Should be at least 8 bytes */
typedef struct {
- uint8_t messageType;
- uint8_t commandID;
- uint16_t length; // tells the number of structures in the payload
- uint32_t seqNum;
-} header_control_message;
-// for the moment has to be at least 8 bytes
+ uint8_t messageType;
+ uint8_t commandID ;
+ uint16_t length; /* Number of structures in the payload */
+ uint32_t seqNum;
+} cmd_header_t;
-// SIZE=8
+typedef struct {
+ cmd_header_t header;
+} msg_header_t;
-//========== [00] ADD LISTENER ==========
+/* Listener */
typedef enum { ETHER_MODE, IP_MODE, HICN_MODE } listener_mode;
typedef struct {
- char symbolic[SYMBOLIC_NAME_LEN];
- char interfaceName[SYMBOLIC_NAME_LEN];
- ip_address_t address;
- uint16_t port;
- // uint16_t etherType;
- uint8_t addressType;
- uint8_t listenerMode;
- uint8_t connectionType;
-} add_listener_command;
-
-// SIZE=56
-
-//========== [01] ADD CONNECTION ==========
-
-typedef struct {
- char symbolic[SYMBOLIC_NAME_LEN];
- //char interfaceName[SYMBOLIC_NAME_LEN];
- ip_address_t remoteIp;
- ip_address_t localIp;
- uint16_t remotePort;
- uint16_t localPort;
- uint8_t ipType;
- uint8_t connectionType;
- uint8_t admin_state;
+ char symbolic[SYMBOLIC_NAME_LEN];
+ char interfaceName[SYMBOLIC_NAME_LEN];
+ ip_address_t address;
+ uint16_t port;
+ // uint16_t etherType;
+ uint8_t addressType;
+ uint8_t listenerMode;
+ uint8_t connectionType;
+ uint8_t family;
+ uint8_t listenerType;
+} cmd_listener_add_t;
+
+typedef struct {
+ char symbolicOrListenerid[SYMBOLIC_NAME_LEN];
+} cmd_listener_remove_t;
+
+typedef struct {
+ ip_address_t address;
+ char listenerName[SYMBOLIC_NAME_LEN];
+ char interfaceName[SYMBOLIC_NAME_LEN];
+ uint32_t connid;
+ uint16_t port;
+ uint8_t addressType;
+ uint8_t encapType;
+} cmd_listener_list_t;
+
+typedef struct {
+ ip_address_t address;
+ char name[SYMBOLIC_NAME_LEN];
+ char interface_name[SYMBOLIC_NAME_LEN];
+ uint32_t id;
+ uint16_t port;
+ uint8_t family;
+ uint8_t type;
+} cmd_listener_list_item_t;
+
+/* Connection */
+
+typedef struct {
+ char symbolic[SYMBOLIC_NAME_LEN];
+ //char interface_name[SYMBOLIC_NAME_LEN];
+ ip_address_t remote_ip;
+ ip_address_t local_ip;
+ uint16_t remote_port;
+ uint16_t local_port;
+ uint8_t family;
+ uint8_t type;
+ uint8_t connection_type;
+ uint8_t admin_state;
#ifdef WITH_POLICY
- uint32_t priority;
- policy_tags_t tags;
+ uint32_t priority;
+ policy_tags_t tags;
#endif /* WITH_POLICY */
-} add_connection_command;
+} cmd_connection_add_t;
-// SIZE=56
-
-//========== [02] LIST CONNECTIONS ==========
+typedef struct {
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+} cmd_connection_remove_t;
typedef enum {
CONN_GRE,
@@ -167,268 +212,238 @@ typedef enum {
} connection_state;
typedef struct {
- add_connection_command connectionData;
+ cmd_connection_add_t connectionData;
uint32_t connid;
uint8_t state;
char interfaceName[SYMBOLIC_NAME_LEN];
char connectionName[SYMBOLIC_NAME_LEN];
-} list_connections_command;
-
-// SIZE=80
-
-//========== [03] ADD ROUTE ==========
+} cmd_connection_list_t;
typedef struct {
- char symbolicOrConnid[SYMBOLIC_NAME_LEN];
- ip_address_t address;
- uint16_t cost;
- uint8_t addressType;
- uint8_t len;
-} add_route_command;
-
-// SIZE=36
-
-//========== [04] LIST ROUTE ==========
+ char symbolic[SYMBOLIC_NAME_LEN];
+ //char interface_name[SYMBOLIC_NAME_LEN];
+ ip_address_t remote_ip;
+ ip_address_t local_ip;
+ uint16_t remote_port;
+ uint16_t local_port;
+ uint8_t family;
+ uint8_t type;
+ uint8_t admin_state;
+#ifdef WITH_POLICY
+ uint32_t priority;
+ policy_tags_t tags;
+#endif /* WITH_POLICY */
+ uint32_t id;
+ uint8_t state;
+ char interface_name[SYMBOLIC_NAME_LEN];
+ char name[SYMBOLIC_NAME_LEN];
+} cmd_connection_list_item_t;
typedef struct {
- ip_address_t address;
- uint32_t connid;
- uint16_t cost;
- uint8_t addressType;
- uint8_t len;
-} list_routes_command;
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+ uint8_t admin_state;
+ uint8_t pad8[3];
+} cmd_connection_set_admin_state_t;
-// SIZE=24
-
-//========== [05] REMOVE CONNECTION ==========
typedef struct {
- char symbolicOrConnid[SYMBOLIC_NAME_LEN];
-} remove_connection_command;
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+ uint8_t admin_state;
+ uint32_t priority;
+ policy_tags_t tags;
+} cmd_connection_update_t;
-//========== [06] REMOVE LISTENER ==========
typedef struct {
- char symbolicOrListenerid[SYMBOLIC_NAME_LEN];
-} remove_listener_command;
-
-// SIZE=16
-
-//========== [07] REMOVE ROUTE ==========
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+ uint32_t priority;
+} cmd_connection_set_priority_t;
typedef struct {
- char symbolicOrConnid[SYMBOLIC_NAME_LEN];
- ip_address_t address;
- uint8_t addressType;
- uint8_t len;
-} remove_route_command;
-
-// SIZE=36
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+ policy_tags_t tags;
+} cmd_connection_set_tags_t;
-//========== [08] CACHE STORE ==========
+/* Route */
typedef struct {
- uint8_t activate;
-} cache_store_command;
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+ ip_address_t address;
+ uint16_t cost;
+ uint8_t addressType;
+ uint8_t family;
+ uint8_t len;
+} cmd_route_add_t;
-// SIZE=1
-
-//========== [09] CACHE SERVE ==========
+typedef struct {
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+ ip_address_t address;
+ uint8_t addressType;
+ uint8_t family;
+ uint8_t len;
+} cmd_route_remove_t;
typedef struct {
- uint8_t activate;
-} cache_serve_command;
+ ip_address_t address;
+ uint32_t connid;
+ uint16_t cost;
+ uint8_t addressType;
+ uint8_t len;
+} cmd_route_list_t;
-// SIZE=1
+typedef struct {
+ ip_address_t address;
+ uint32_t connection_id;
+ uint16_t cost;
+ uint8_t family;
+ uint8_t len;
+} cmd_route_list_item_t;
-//========== [10] SET STRATEGY ==========
+/* Cache */
-typedef enum {
- SET_STRATEGY_LOADBALANCER,
- SET_STRATEGY_RANDOM,
- SET_STRATEGY_LOW_LATENCY,
- LAST_STRATEGY_VALUE
-} strategy_type;
+typedef struct {
+ uint8_t activate;
+} cmd_cache_set_store_t;
typedef struct {
- ip_address_t address;
- uint8_t strategyType;
- uint8_t addressType;
- uint8_t len;
- uint8_t related_prefixes;
- ip_address_t addresses[MAX_FWD_STRATEGY_RELATED_PREFIXES];
- uint8_t lens[MAX_FWD_STRATEGY_RELATED_PREFIXES];
- uint8_t addresses_type[MAX_FWD_STRATEGY_RELATED_PREFIXES];
-} set_strategy_command;
+ uint8_t activate;
+} cmd_cache_set_serve_t;
-// SIZE=208
+typedef struct {
+} cmd_cache_clear_t;
-//========== [11] SET WLDR ==========
+/* WLDR */
typedef struct {
- char symbolicOrConnid[SYMBOLIC_NAME_LEN];
- uint8_t activate;
-} set_wldr_command;
-
-// SIZE=17
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+ uint8_t activate;
+} cmd_wldr_set_t;
-//========== [12] ADD PUNTING ==========
+/* Strategy */
typedef struct {
- char symbolicOrConnid[SYMBOLIC_NAME_LEN];
- ip_address_t address;
- uint8_t addressType;
- uint8_t len;
-} add_punting_command;
+ ip_address_t address;
+ uint8_t strategy_type;
+ uint8_t address_type;
+ uint8_t family;
+ uint8_t len;
+ uint8_t related_prefixes;
+ union {
+ struct {
+ ip_address_t addresses[MAX_FWD_STRATEGY_RELATED_PREFIXES];
+ uint8_t lens[MAX_FWD_STRATEGY_RELATED_PREFIXES];
+ uint8_t families[MAX_FWD_STRATEGY_RELATED_PREFIXES];
+ } low_latency;
+ };
+} cmd_strategy_set_t;
+
+/* Punting */
-// SIZE=36
+typedef struct {
+ char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+ ip_address_t address;
+ uint8_t addressType;
+ uint8_t family;
+ uint8_t len;
+} cmd_punting_add_t;
-//========== [13] LIST LISTENER ==========
+/* MAP-Me */
typedef struct {
- ip_address_t address;
- char listenerName[SYMBOLIC_NAME_LEN];
- char interfaceName[SYMBOLIC_NAME_LEN];
- uint32_t connid;
- uint16_t port;
- uint8_t addressType;
- uint8_t encapType;
-} list_listeners_command;
+ uint8_t activate;
+} cmd_mapme_activator_t;
-// SIZE=56
+typedef cmd_mapme_activator_t cmd_mapme_enable_t;
+typedef cmd_mapme_activator_t cmd_mapme_set_discovery_t;
-//========== [14] MAPME ==========
+typedef struct {
+ uint32_t timePeriod;
+} cmd_mapme_timing_t;
-// (enable/discovery/timescale/retx)
+typedef cmd_mapme_timing_t cmd_mapme_set_timescale_t;
+typedef cmd_mapme_timing_t cmd_mapme_set_retx_t;
typedef struct {
- uint8_t activate;
-} mapme_activator_command;
+ ip_address_t address;
+ uint8_t family;
+ uint8_t len;
+} cmd_mapme_send_update_t;
-// SIZE=1
+#ifdef WITH_POLICY
+/* Policy */
typedef struct {
- uint32_t timePeriod;
-} mapme_timing_command;
+ ip_address_t address;
+ uint8_t addressType;
+ uint8_t family;
+ uint8_t len;
+ policy_t policy;
+} cmd_policy_add_t;
typedef struct {
- ip_address_t address;
- uint8_t addressType;
- uint8_t len;
-} mapme_send_update_command;
+ ip_address_t address;
+ uint8_t addressType;
+ uint8_t family;
+ uint8_t len;
+} cmd_policy_remove_t;
-// SIZE=1
+typedef struct {
+ ip_address_t address;
+ uint8_t addressType;
+ uint8_t len;
+ policy_t policy;
+} cmd_policy_list_t;
typedef struct {
- char symbolicOrConnid[SYMBOLIC_NAME_LEN];
- uint8_t admin_state;
- uint8_t pad8[3];
-} connection_set_admin_state_command;
+ ip_address_t address;
+ uint8_t family;
+ uint8_t len;
+ policy_t policy;
+} cmd_policy_list_item_t;
-#ifdef WITH_POLICY
+#endif /* WITH_POLICY */
-typedef struct {
- ip_address_t address;
- uint8_t addressType;
- uint8_t len;
- policy_t policy;
-} add_policy_command;
+/* Full messages */
-typedef struct {
- ip_address_t address;
- uint8_t addressType;
- uint8_t len;
- policy_t policy;
-} list_policies_command;
+#define _(l, u) \
+typedef struct { \
+ cmd_header_t header; \
+ cmd_ ## l ## _t payload; \
+} msg_ ## l ## _t;
+ foreach_command_type
+#undef _
typedef struct {
- ip_address_t address;
- uint8_t addressType;
- uint8_t len;
-} remove_policy_command;
+ cmd_header_t header;
+ cmd_listener_list_item_t payload;
+} msg_listener_list_reply_t;
typedef struct {
- char symbolicOrConnid[SYMBOLIC_NAME_LEN];
- uint8_t admin_state;
- uint32_t priority;
- policy_tags_t tags;
-} update_connection_command;
+ cmd_header_t header;
+ cmd_connection_list_item_t payload;
+} msg_connection_list_reply_t;
typedef struct {
- char symbolicOrConnid[SYMBOLIC_NAME_LEN];
- uint32_t priority;
-} connection_set_priority_command;
+ cmd_header_t header;
+ cmd_route_list_item_t payload;
+} msg_route_list_reply_t;
typedef struct {
- char symbolicOrConnid[SYMBOLIC_NAME_LEN];
- policy_tags_t tags;
-} connection_set_tags_command;
-
-#endif /* WITH_POLICY */
+ cmd_header_t header;
+ cmd_policy_list_item_t payload;
+} msg_policy_list_reply_t;
//===== size of commands ======
// REMINDER: when a new_command is added, the following switch has to be
// updated.
-static inline int payloadLengthDaemon(command_id id) {
- switch (id) {
- case ADD_LISTENER:
- return sizeof(add_listener_command);
- case ADD_CONNECTION:
- return sizeof(add_connection_command);
- case LIST_CONNECTIONS:
- return 0; // list connections: payload always 0
- case ADD_ROUTE:
- return sizeof(add_route_command);
- case LIST_ROUTES:
- return 0; // list routes: payload always 0
- case REMOVE_CONNECTION:
- return sizeof(remove_connection_command);
- case REMOVE_LISTENER:
- return sizeof(remove_listener_command);
- case REMOVE_ROUTE:
- return sizeof(remove_route_command);
- case CACHE_STORE:
- return sizeof(cache_store_command);
- case CACHE_SERVE:
- return sizeof(cache_serve_command);
- case CACHE_CLEAR:
- return 0; // cache clear
- case SET_STRATEGY:
- return sizeof(set_strategy_command);
- case SET_WLDR:
- return sizeof(set_wldr_command);
- case ADD_PUNTING:
- return sizeof(add_punting_command);
- case LIST_LISTENERS:
- return 0; // list listeners: payload always 0
- case MAPME_ENABLE:
- return sizeof(mapme_activator_command);
- case MAPME_DISCOVERY:
- return sizeof(mapme_activator_command);
- case MAPME_TIMESCALE:
- return sizeof(mapme_timing_command);
- case MAPME_RETX:
- return sizeof(mapme_timing_command);
- case MAPME_SEND_UPDATE:
- return sizeof(mapme_send_update_command);
- case CONNECTION_SET_ADMIN_STATE:
- return sizeof(connection_set_admin_state_command);
-#ifdef WITH_POLICY
- case ADD_POLICY:
- return sizeof(add_policy_command);
- case LIST_POLICIES:
- return 0; // list policies: payload always 0
- case REMOVE_POLICY:
- return sizeof(remove_policy_command);
- case UPDATE_CONNECTION:
- return sizeof(update_connection_command);
- case CONNECTION_SET_PRIORITY:
- return sizeof(connection_set_priority_command);
- case CONNECTION_SET_TAGS:
- return sizeof(connection_set_tags_command);
-#endif /* WITH_POLICY */
- case LAST_COMMAND_VALUE:
- return 0;
- default:
- return 0;
- }
+static inline int command_get_payload_len(command_type_t command_type) {
+ switch (command_type) {
+#define _(l, u) \
+ case COMMAND_TYPE_ ## u: \
+ return sizeof(cmd_## l ## _t);
+ foreach_command_type
+#undef _
+ case COMMAND_TYPE_UNDEFINED:
+ case COMMAND_TYPE_N:
+ return 0;
+ }
}
#endif
diff --git a/ctrl/libhicnctrl/src/api.c b/ctrl/libhicnctrl/src/api.c
index 080b654..ef9f4af 100644
--- a/ctrl/libhicnctrl/src/api.c
+++ b/ctrl/libhicnctrl/src/api.c
@@ -57,7 +57,7 @@ typedef struct {
/**
* Messages to the forwarder might be multiplexed thanks to the seqNum fields in
- * the header_control_message structure. The forwarder simply answers back the
+ * the cmd_header_t structure. The forwarder simply answers back the
* original sequence number. We maintain a map of such sequence number to
* outgoing queries so that replied can be demultiplexed and treated
* appropriately.
@@ -272,28 +272,28 @@ static const address_type map_to_addr_type[] = {
******************************************************************************/
#define foreach_hc_command \
- _(add_connection) \
- _(remove_connection) \
- _(list_connections) \
- _(add_listener) \
- _(remove_listener) \
- _(list_listeners) \
- _(add_route) \
- _(remove_route) \
- _(list_routes) \
- _(cache_store) \
- _(cache_serve) \
+ _(connection_add) \
+ _(connection_remove) \
+ _(connection_list) \
+ _(listener_add) \
+ _(listener_remove) \
+ _(listener_list) \
+ _(route_add) \
+ _(route_remove) \
+ _(route_list) \
+ _(cache_set_store) \
+ _(cache_set_serve) \
/*_(cache_clear) */ \
- _(set_strategy) \
- _(set_wldr) \
- _(add_punting) \
+ _(strategy_set) \
+ _(wldr_set) \
+ _(punting_add) \
_(mapme_activator) \
_(mapme_timing)
-typedef header_control_message hc_msg_header_t;
+typedef cmd_header_t hc_msg_header_t;
typedef union {
-#define _(x) x ## _command x;
+#define _(x) cmd_ ## x ## _t x;
foreach_hc_command
#undef _
} hc_msg_payload_t;
@@ -486,7 +486,7 @@ hc_sock_create_url(const char * url)
s->url = url ? strdup(url) : NULL;
- s->fd = socket(AF_INET, SOCK_STREAM, 0);
+ s->fd = socket(AF_INET, SOCK_DGRAM, 0);
if (s->fd < 0)
goto ERR_SOCKET;
@@ -526,7 +526,7 @@ hc_sock_free(hc_sock_t * s)
hc_sock_request_t ** request_array = NULL;
int n = hc_sock_map_get_value_array(s->map, &request_array);
if (n < 0) {
- ERROR("Could not retrieve pending request array for freeing up resources");
+ ERROR("Could not retrieve pending request array for freeing up resources");
} else {
for (unsigned i = 0; i < n; i++) {
hc_sock_request_t * request = request_array[i];
@@ -620,7 +620,7 @@ hc_sock_recv(hc_sock_t * s)
rc = (int)recv(s->fd, s->buf + s->woff, RECV_BUFLEN - s->woff, 0);
if (rc == 0) {
/* Connection has been closed */
- return 0;
+ return 0;
}
if (rc < 0) {
/*
@@ -649,15 +649,15 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data)
while(available > 0) {
if (!s->cur_request) { // No message being parsed, alternatively (remaining == 0)
- hc_msg_t * msg = (hc_msg_t*)(s->buf + s->roff);
+ cmd_header_t hdr = ((msg_header_t *) (s->buf + s->roff))->header;
/* We expect a message header */
- if (available < sizeof(hc_msg_header_t)) {
+ if (available < sizeof(cmd_header_t)) {
break;
}
hc_sock_request_t * request = NULL;
- if (hc_sock_map_get(s->map, msg->hdr.seqNum, &request) < 0) {
+ if (hc_sock_map_get(s->map, hdr.seqNum, &request) < 0) {
ERROR("[hc_sock_process] Error searching for matching request");
return -99;
}
@@ -666,19 +666,23 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data)
return -99;
}
- s->remaining = msg->hdr.length;
- switch(msg->hdr.messageType) {
+ s->remaining = hdr.length;
+ switch(hdr.messageType) {
case ACK_LIGHT:
+ DEBUG("ack received");
assert(s->remaining == 1);
assert(!data);
s->cur_request = request;
+ hc_data_set_complete(request->data);
break;
case NACK_LIGHT:
+ DEBUG("nack received");
assert(s->remaining == 1);
assert(!data);
hc_data_set_error(request->data);
s->cur_request = request;
err = -1;
+ hc_data_set_complete(request->data);
break;
case RESPONSE_LIGHT:
assert(data);
@@ -697,9 +701,8 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data)
ERROR("[hc_sock_process] Invalid response received");
return -99;
}
-
- available -= sizeof(hc_msg_header_t);
- s->roff += sizeof(hc_msg_header_t);
+ available -= sizeof(cmd_header_t);
+ s->roff += sizeof(cmd_header_t);
} else {
/* We expect the complete payload, or at least a chunk of it */
size_t num_chunks = available / s->cur_request->data->in_element_size;
@@ -824,7 +827,7 @@ typedef int (*HC_PARSE)(const u8 *, u8 *);
typedef struct {
hc_action_t cmd;
- command_id cmd_id;
+ command_type_t cmd_id;
size_t size_in;
size_t size_out;
HC_PARSE parse;
@@ -966,13 +969,10 @@ _hc_listener_create(hc_sock_t * s, hc_listener_t * listener, bool async)
if (!IS_VALID_CONNECTION_TYPE(listener->type))
return -1;
- struct {
- header_control_message hdr;
- add_listener_command payload;
- } msg = {
- .hdr = {
+ msg_listener_add_t msg = {
+ .header = {
.messageType = REQUEST_LIGHT,
- .commandID = ADD_LISTENER,
+ .commandID = COMMAND_TYPE_LISTENER_ADD,
.length = 1,
.seqNum = 0,
},
@@ -982,6 +982,8 @@ _hc_listener_create(hc_sock_t * s, hc_listener_t * listener, bool async)
.addressType = (u8)map_to_addr_type[listener->family],
.listenerMode = (u8)map_to_listener_mode[listener->type],
.connectionType = (u8)map_to_connection_type[listener->type],
+ .family = listener->family,
+ .listenerType = listener->type,
}
};
@@ -995,8 +997,8 @@ _hc_listener_create(hc_sock_t * s, hc_listener_t * listener, bool async)
hc_command_params_t params = {
.cmd = ACTION_CREATE,
- .cmd_id = ADD_LISTENER,
- .size_in = sizeof(add_listener_command),
+ .cmd_id = COMMAND_TYPE_LISTENER_ADD,
+ .size_in = sizeof(cmd_listener_add_t),
.size_out = 0,
.parse = NULL,
};
@@ -1068,12 +1070,12 @@ _hc_listener_delete(hc_sock_t * s, hc_listener_t * listener, bool async)
BOOLSTR(async));
struct {
- header_control_message hdr;
- remove_listener_command payload;
+ cmd_header_t hdr;
+ cmd_listener_remove_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = REMOVE_LISTENER,
+ .commandID = COMMAND_TYPE_LISTENER_REMOVE,
.length = 1,
.seqNum = 0,
},
@@ -1101,8 +1103,8 @@ _hc_listener_delete(hc_sock_t * s, hc_listener_t * listener, bool async)
hc_command_params_t params = {
.cmd = ACTION_DELETE,
- .cmd_id = REMOVE_LISTENER,
- .size_in = sizeof(remove_listener_command),
+ .cmd_id = COMMAND_TYPE_LISTENER_REMOVE,
+ .size_in = sizeof(cmd_listener_remove_t),
.size_out = 0,
.parse = NULL,
};
@@ -1131,11 +1133,11 @@ _hc_listener_list(hc_sock_t * s, hc_data_t ** pdata, bool async)
DEBUG("[hc_listener_list] async=%s", BOOLSTR(async));
struct {
- header_control_message hdr;
+ cmd_header_t hdr;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = LIST_LISTENERS,
+ .commandID = COMMAND_TYPE_LISTENER_LIST,
.length = 0,
.seqNum = 0,
},
@@ -1143,8 +1145,8 @@ _hc_listener_list(hc_sock_t * s, hc_data_t ** pdata, bool async)
hc_command_params_t params = {
.cmd = ACTION_LIST,
- .cmd_id = LIST_LISTENERS,
- .size_in = sizeof(list_listeners_command),
+ .cmd_id = COMMAND_TYPE_LISTENER_LIST,
+ .size_in = sizeof(cmd_listener_list_t),
.size_out = sizeof(hc_listener_t),
.parse = (HC_PARSE)hc_listener_parse,
};
@@ -1215,7 +1217,7 @@ hc_listener_parse(void * in, hc_listener_t * listener)
{
int rc;
- list_listeners_command * cmd = (list_listeners_command *)in;
+ cmd_listener_list_t * cmd = (cmd_listener_list_t *)in;
if (!IS_VALID_LIST_LISTENERS_TYPE(cmd->encapType))
return -1;
@@ -1287,22 +1289,22 @@ _hc_connection_create(hc_sock_t * s, hc_connection_t * connection, bool async)
return -1;
struct {
- header_control_message hdr;
- add_connection_command payload;
+ cmd_header_t hdr;
+ cmd_connection_add_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = ADD_CONNECTION,
+ .commandID = COMMAND_TYPE_CONNECTION_ADD,
.length = 1,
.seqNum = 0,
},
.payload = {
- .remoteIp = connection->remote_addr,
- .localIp = connection->local_addr,
- .remotePort = htons(connection->remote_port),
- .localPort = htons(connection->local_port),
- .ipType = (u8)map_to_addr_type[connection->family],
- .connectionType = (u8)map_to_connection_type[connection->type],
+ .remote_ip = connection->remote_addr,
+ .local_ip = connection->local_addr,
+ .remote_port = htons(connection->remote_port),
+ .local_port = htons(connection->local_port),
+ .type = (u8)map_to_addr_type[connection->family],
+ .connection_type = (u8)map_to_connection_type[connection->type],
.admin_state = connection->admin_state,
#ifdef WITH_POLICY
.priority = connection->priority,
@@ -1317,8 +1319,8 @@ _hc_connection_create(hc_sock_t * s, hc_connection_t * connection, bool async)
hc_command_params_t params = {
.cmd = ACTION_CREATE,
- .cmd_id = ADD_CONNECTION,
- .size_in = sizeof(add_connection_command),
+ .cmd_id = COMMAND_TYPE_CONNECTION_ADD,
+ .size_in = sizeof(cmd_connection_add_t),
.size_out = 0,
.parse = NULL,
};
@@ -1389,12 +1391,12 @@ _hc_connection_delete(hc_sock_t * s, hc_connection_t * connection, bool async)
DEBUG("[_hc_connection_delete] connection=%s async=%s", connection_s, BOOLSTR(async));
struct {
- header_control_message hdr;
- remove_connection_command payload;
+ cmd_header_t hdr;
+ cmd_connection_remove_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = REMOVE_CONNECTION,
+ .commandID = COMMAND_TYPE_CONNECTION_REMOVE,
.length = 1,
.seqNum = 0,
},
@@ -1422,8 +1424,8 @@ _hc_connection_delete(hc_sock_t * s, hc_connection_t * connection, bool async)
hc_command_params_t params = {
.cmd = ACTION_DELETE,
- .cmd_id = REMOVE_CONNECTION,
- .size_in = sizeof(remove_connection_command),
+ .cmd_id = COMMAND_TYPE_CONNECTION_REMOVE,
+ .size_in = sizeof(cmd_connection_remove_t),
.size_out = 0,
.parse = NULL,
};
@@ -1451,11 +1453,11 @@ _hc_connection_list(hc_sock_t * s, hc_data_t ** pdata, bool async)
DEBUG("[hc_connection_list] async=%s", BOOLSTR(async));
struct {
- header_control_message hdr;
+ cmd_header_t hdr;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = LIST_CONNECTIONS,
+ .commandID = COMMAND_TYPE_CONNECTION_LIST,
.length = 0,
.seqNum = 0,
},
@@ -1463,8 +1465,8 @@ _hc_connection_list(hc_sock_t * s, hc_data_t ** pdata, bool async)
hc_command_params_t params = {
.cmd = ACTION_LIST,
- .cmd_id = LIST_CONNECTIONS,
- .size_in = sizeof(list_connections_command),
+ .cmd_id = COMMAND_TYPE_CONNECTION_LIST,
+ .size_in = sizeof(cmd_connection_list_t),
.size_out = sizeof(hc_connection_t),
.parse = (HC_PARSE)hc_connection_parse,
};
@@ -1548,12 +1550,12 @@ int
hc_connection_parse(void * in, hc_connection_t * connection)
{
int rc;
- list_connections_command * cmd = (list_connections_command *)in;
+ cmd_connection_list_t * cmd = (cmd_connection_list_t *)in;
- if (!IS_VALID_LIST_CONNECTIONS_TYPE(cmd->connectionData.connectionType))
+ if (!IS_VALID_LIST_CONNECTIONS_TYPE(cmd->connectionData.connection_type))
return -1;
- hc_connection_type_t type = map_from_list_connections_type[cmd->connectionData.connectionType];
+ hc_connection_type_t type = map_from_list_connections_type[cmd->connectionData.connection_type];
if (type == CONNECTION_TYPE_UNDEFINED)
return -1;
@@ -1564,10 +1566,10 @@ hc_connection_parse(void * in, hc_connection_t * connection)
if (state == HC_CONNECTION_STATE_UNDEFINED)
return -1;
- if (!IS_VALID_ADDR_TYPE(cmd->connectionData.ipType))
+ if (!IS_VALID_ADDR_TYPE(cmd->connectionData.type))
return -1;
- int family = map_from_addr_type[cmd->connectionData.ipType];
+ int family = map_from_addr_type[cmd->connectionData.type];
if (!IS_VALID_FAMILY(family))
return -1;
@@ -1575,12 +1577,12 @@ hc_connection_parse(void * in, hc_connection_t * connection)
.id = cmd->connid,
.type = type,
.family = family,
- .local_addr = cmd->connectionData.localIp,
+ .local_addr = cmd->connectionData.local_ip,
//.local_addr = UNION_CAST(cmd->connectionData.localIp, ip_address_t),
- .local_port = ntohs(cmd->connectionData.localPort),
- .remote_addr = cmd->connectionData.remoteIp,
+ .local_port = ntohs(cmd->connectionData.local_port),
+ .remote_addr = cmd->connectionData.remote_ip,
//.remote_addr = UNION_CAST(cmd->connectionData.remoteIp, ip_address_t),
- .remote_port = ntohs(cmd->connectionData.remotePort),
+ .remote_port = ntohs(cmd->connectionData.remote_port),
.admin_state = cmd->connectionData.admin_state,
#ifdef WITH_POLICY
.priority = cmd->connectionData.priority,
@@ -1642,12 +1644,12 @@ _hc_connection_set_admin_state(hc_sock_t * s, const char * conn_id_or_name,
DEBUG("[hc_connection_set_admin_state] connection_id/name=%s admin_state=%s async=%s",
conn_id_or_name, face_state_str(state), BOOLSTR(async));
struct {
- header_control_message hdr;
- connection_set_admin_state_command payload;
+ cmd_header_t hdr;
+ cmd_connection_set_admin_state_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = CONNECTION_SET_ADMIN_STATE,
+ .commandID = COMMAND_TYPE_CONNECTION_SET_ADMIN_STATE,
.length = 1,
.seqNum = 0,
},
@@ -1661,8 +1663,8 @@ _hc_connection_set_admin_state(hc_sock_t * s, const char * conn_id_or_name,
hc_command_params_t params = {
.cmd = ACTION_SET,
- .cmd_id = CONNECTION_SET_ADMIN_STATE,
- .size_in = sizeof(connection_set_admin_state_command),
+ .cmd_id = COMMAND_TYPE_CONNECTION_SET_ADMIN_STATE,
+ .size_in = sizeof(cmd_connection_set_admin_state_t),
.size_out = 0,
.parse = NULL,
};
@@ -1692,12 +1694,12 @@ _hc_connection_set_priority(hc_sock_t * s, const char * conn_id_or_name,
DEBUG("[hc_connection_set_priority] connection_id/name=%s priority=%d async=%s",
conn_id_or_name, priority, BOOLSTR(async));
struct {
- header_control_message hdr;
- connection_set_priority_command payload;
+ cmd_header_t hdr;
+ cmd_connection_set_priority_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = CONNECTION_SET_PRIORITY,
+ .commandID = COMMAND_TYPE_CONNECTION_SET_PRIORITY,
.length = 1,
.seqNum = 0,
},
@@ -1711,8 +1713,8 @@ _hc_connection_set_priority(hc_sock_t * s, const char * conn_id_or_name,
hc_command_params_t params = {
.cmd = ACTION_SET,
- .cmd_id = CONNECTION_SET_PRIORITY,
- .size_in = sizeof(connection_set_priority_command),
+ .cmd_id = COMMAND_TYPE_CONNECTION_SET_PRIORITY,
+ .size_in = sizeof(cmd_connection_set_priority_t),
.size_out = 0,
.parse = NULL,
};
@@ -1742,12 +1744,12 @@ _hc_connection_set_tags(hc_sock_t * s, const char * conn_id_or_name,
DEBUG("[hc_connection_set_tags] connection_id/name=%s tags=%d async=%s",
conn_id_or_name, tags, BOOLSTR(async));
struct {
- header_control_message hdr;
- connection_set_tags_command payload;
+ cmd_header_t hdr;
+ cmd_connection_set_tags_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = CONNECTION_SET_TAGS,
+ .commandID = COMMAND_TYPE_CONNECTION_SET_TAGS,
.length = 1,
.seqNum = 0,
},
@@ -1761,8 +1763,8 @@ _hc_connection_set_tags(hc_sock_t * s, const char * conn_id_or_name,
hc_command_params_t params = {
.cmd = ACTION_SET,
- .cmd_id = CONNECTION_SET_TAGS,
- .size_in = sizeof(connection_set_tags_command),
+ .cmd_id = COMMAND_TYPE_CONNECTION_SET_TAGS,
+ .size_in = sizeof(cmd_connection_set_tags_t),
.size_out = 0,
.parse = NULL,
};
@@ -1806,12 +1808,12 @@ _hc_route_create(hc_sock_t * s, hc_route_t * route, bool async)
return -1;
struct {
- header_control_message hdr;
- add_route_command payload;
+ cmd_header_t hdr;
+ cmd_route_add_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = ADD_ROUTE,
+ .commandID = COMMAND_TYPE_ROUTE_ADD,
.length = 1,
.seqNum = 0,
},
@@ -1833,8 +1835,8 @@ _hc_route_create(hc_sock_t * s, hc_route_t * route, bool async)
hc_command_params_t params = {
.cmd = ACTION_CREATE,
- .cmd_id = ADD_ROUTE,
- .size_in = sizeof(add_route_command),
+ .cmd_id = COMMAND_TYPE_ROUTE_ADD,
+ .size_in = sizeof(cmd_route_add_t),
.size_out = 0,
.parse = NULL,
};
@@ -1869,12 +1871,12 @@ _hc_route_delete(hc_sock_t * s, hc_route_t * route, bool async)
return -1;
struct {
- header_control_message hdr;
- remove_route_command payload;
+ cmd_header_t hdr;
+ cmd_route_remove_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = REMOVE_ROUTE,
+ .commandID = COMMAND_TYPE_ROUTE_REMOVE,
.length = 1,
.seqNum = 0,
},
@@ -1893,8 +1895,8 @@ _hc_route_delete(hc_sock_t * s, hc_route_t * route, bool async)
hc_command_params_t params = {
.cmd = ACTION_DELETE,
- .cmd_id = REMOVE_ROUTE,
- .size_in = sizeof(remove_route_command),
+ .cmd_id = COMMAND_TYPE_ROUTE_REMOVE,
+ .size_in = sizeof(cmd_route_remove_t),
.size_out = 0,
.parse = NULL,
};
@@ -1922,11 +1924,11 @@ _hc_route_list(hc_sock_t * s, hc_data_t ** pdata, bool async)
//DEBUG("[hc_route_list] async=%s", BOOLSTR(async));
struct {
- header_control_message hdr;
+ cmd_header_t hdr;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = LIST_ROUTES,
+ .commandID = COMMAND_TYPE_ROUTE_LIST,
.length = 0,
.seqNum = 0,
},
@@ -1934,8 +1936,8 @@ _hc_route_list(hc_sock_t * s, hc_data_t ** pdata, bool async)
hc_command_params_t params = {
.cmd = ACTION_LIST,
- .cmd_id = LIST_ROUTES,
- .size_in = sizeof(list_routes_command),
+ .cmd_id = COMMAND_TYPE_ROUTE_LIST,
+ .size_in = sizeof(cmd_route_list_t),
.size_out = sizeof(hc_route_t),
.parse = (HC_PARSE)hc_route_parse,
};
@@ -1960,7 +1962,7 @@ hc_route_list_async(hc_sock_t * s)
int
hc_route_parse(void * in, hc_route_t * route)
{
- list_routes_command * cmd = (list_routes_command *) in;
+ cmd_route_list_t * cmd = (cmd_route_list_t *) in;
if (!IS_VALID_ADDR_TYPE(cmd->addressType)) {
ERROR("[hc_route_parse] Invalid address type");
@@ -2516,11 +2518,11 @@ int
hc_face_list_async(hc_sock_t * s)
{
struct {
- header_control_message hdr;
+ cmd_header_t hdr;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = LIST_CONNECTIONS,
+ COMMAND_TYPE_CONNECTION_LIST,
.length = 0,
.seqNum = 0,
},
@@ -2528,8 +2530,8 @@ hc_face_list_async(hc_sock_t * s)
hc_command_params_t params = {
.cmd = ACTION_LIST,
- .cmd_id = LIST_CONNECTIONS,
- .size_in = sizeof(list_connections_command),
+ .cmd_id = COMMAND_TYPE_CONNECTION_LIST,
+ .size_in = sizeof(cmd_connection_list_t),
.size_out = sizeof(hc_face_t),
.parse = (HC_PARSE)hc_connection_parse_to_face,
};
@@ -2656,12 +2658,12 @@ _hc_punting_create(hc_sock_t * s, hc_punting_t * punting, bool async)
return -1;
struct {
- header_control_message hdr;
- add_punting_command payload;
+ cmd_header_t hdr;
+ cmd_punting_add_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = ADD_PUNTING,
+ .commandID = COMMAND_TYPE_PUNTING_ADD,
.length = 1,
.seqNum = 0,
},
@@ -2677,8 +2679,8 @@ _hc_punting_create(hc_sock_t * s, hc_punting_t * punting, bool async)
hc_command_params_t params = {
.cmd = ACTION_CREATE,
- .cmd_id = ADD_PUNTING,
- .size_in = sizeof(add_punting_command),
+ .cmd_id = COMMAND_TYPE_PUNTING_ADD,
+ .size_in = sizeof(cmd_punting_add_t),
.size_out = 0,
.parse = NULL,
};
@@ -2777,12 +2779,12 @@ int
_hc_cache_set_store(hc_sock_t * s, int enabled, bool async)
{
struct {
- header_control_message hdr;
- cache_store_command payload;
+ cmd_header_t hdr;
+ cmd_cache_set_store_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = CACHE_STORE,
+ .commandID = COMMAND_TYPE_CACHE_SET_STORE,
.length = 1,
.seqNum = 0,
},
@@ -2793,8 +2795,8 @@ _hc_cache_set_store(hc_sock_t * s, int enabled, bool async)
hc_command_params_t params = {
.cmd = ACTION_SET,
- .cmd_id = CACHE_STORE,
- .size_in = sizeof(cache_store_command),
+ .cmd_id = COMMAND_TYPE_CACHE_SET_STORE,
+ .size_in = sizeof(cmd_cache_set_store_t),
.size_out = 0,
.parse = NULL,
};
@@ -2818,12 +2820,12 @@ int
_hc_cache_set_serve(hc_sock_t * s, int enabled, bool async)
{
struct {
- header_control_message hdr;
- cache_serve_command payload;
+ cmd_header_t hdr;
+ cmd_cache_set_serve_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = CACHE_SERVE,
+ .commandID = COMMAND_TYPE_CACHE_SET_SERVE,
.length = 1,
.seqNum = 0,
},
@@ -2834,8 +2836,8 @@ _hc_cache_set_serve(hc_sock_t * s, int enabled, bool async)
hc_command_params_t params = {
.cmd = ACTION_SET,
- .cmd_id = CACHE_SERVE,
- .size_in = sizeof(cache_serve_command),
+ .cmd_id = COMMAND_TYPE_CACHE_SET_SERVE,
+ .size_in = sizeof(cmd_cache_set_serve_t),
.size_out = 0,
.parse = NULL,
};
@@ -2955,12 +2957,12 @@ _hc_policy_create(hc_sock_t * s, hc_policy_t * policy, bool async)
return -1;
struct {
- header_control_message hdr;
- add_policy_command payload;
+ cmd_header_t hdr;
+ cmd_policy_add_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = ADD_POLICY,
+ COMMAND_TYPE_POLICY_ADD,
.length = 1,
.seqNum = 0,
},
@@ -2974,8 +2976,8 @@ _hc_policy_create(hc_sock_t * s, hc_policy_t * policy, bool async)
hc_command_params_t params = {
.cmd = ACTION_CREATE,
- .cmd_id = ADD_POLICY,
- .size_in = sizeof(add_policy_command),
+ .cmd_id = COMMAND_TYPE_POLICY_ADD,
+ .size_in = sizeof(cmd_policy_add_t),
.size_out = 0,
.parse = NULL,
};
@@ -3004,12 +3006,12 @@ _hc_policy_delete(hc_sock_t * s, hc_policy_t * policy, bool async)
return -1;
struct {
- header_control_message hdr;
- remove_policy_command payload;
+ cmd_header_t hdr;
+ cmd_policy_remove_t payload;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = REMOVE_POLICY,
+ .commandID = COMMAND_TYPE_POLICY_REMOVE,
.length = 1,
.seqNum = 0,
},
@@ -3022,8 +3024,8 @@ _hc_policy_delete(hc_sock_t * s, hc_policy_t * policy, bool async)
hc_command_params_t params = {
.cmd = ACTION_DELETE,
- .cmd_id = REMOVE_POLICY,
- .size_in = sizeof(remove_policy_command),
+ .cmd_id = COMMAND_TYPE_POLICY_REMOVE,
+ .size_in = sizeof(cmd_policy_remove_t),
.size_out = 0,
.parse = NULL,
};
@@ -3049,11 +3051,11 @@ int
_hc_policy_list(hc_sock_t * s, hc_data_t ** pdata, bool async)
{
struct {
- header_control_message hdr;
+ cmd_header_t hdr;
} msg = {
.hdr = {
.messageType = REQUEST_LIGHT,
- .commandID = LIST_POLICIES,
+ .commandID = COMMAND_TYPE_POLICY_LIST,
.length = 0,
.seqNum = 0,
},
@@ -3061,8 +3063,8 @@ _hc_policy_list(hc_sock_t * s, hc_data_t ** pdata, bool async)
hc_command_params_t params = {
.cmd = ACTION_LIST,
- .cmd_id = LIST_POLICIES,
- .size_in = sizeof(list_policies_command),
+ .cmd_id = COMMAND_TYPE_POLICY_LIST,
+ .size_in = sizeof(cmd_policy_list_t),
.size_out = sizeof(hc_policy_t),
.parse = (HC_PARSE)hc_policy_parse,
};
@@ -3087,7 +3089,7 @@ hc_policy_list_async(hc_sock_t * s, hc_data_t ** pdata)
int
hc_policy_parse(void * in, hc_policy_t * policy)
{
- list_policies_command * cmd = (list_policies_command *) in;
+ cmd_policy_list_t * cmd = (cmd_policy_list_t *) in;
if (!IS_VALID_ADDR_TYPE(cmd->addressType))
return -1;
diff --git a/ctrl/libhicnctrl/src/hicn_plugin_api.c b/ctrl/libhicnctrl/src/hicn_plugin_api.c
index 406f434..04d01e2 100644
--- a/ctrl/libhicnctrl/src/hicn_plugin_api.c
+++ b/ctrl/libhicnctrl/src/hicn_plugin_api.c
@@ -61,7 +61,7 @@ vapi_skc_ctx_t vapi_skc = {
/**
* Messages to the forwarder might be multiplexed thanks to the seqNum fields in
- * the header_control_message structure. The forwarder simply answers back the
+ * the cmd_header_t structure. The forwarder simply answers back the
* original sequence number. We maintain a map of such sequence number to
* outgoing queries so that replied can be demultiplexed and treated
* appropriately.
diff --git a/hicn-light/src/hicn/cli/hicnc.c b/hicn-light/src/hicn/cli/hicnc.c
index d6c7c41..2c1c350 100644
--- a/hicn-light/src/hicn/cli/hicnc.c
+++ b/hicn-light/src/hicn/cli/hicnc.c
@@ -123,9 +123,6 @@ main(int argc, char * const * argv)
goto ERR_PARSE;
}
-
- hc_data_t * data;
-
hc_sock_t * s;
if (server_ip) {
if (server_port == 0)
@@ -147,28 +144,13 @@ main(int argc, char * const * argv)
goto ERR_CONNECT;
}
- /* XXX connection list */
- if (hc_connection_list(s, &data) < 0) {
- fprintf(stderr, "Error running command");
- goto ERR_CMD;
- }
-
- char buf[MAXSZ_HC_CONNECTION]; // XXX
- foreach_connection(c, data) {
- /* XXX connection print */
- int rc = hc_connection_snprintf(buf, MAXSZ_HC_CONNECTION, c);
- if (rc < 0) {
- strncpy(buf, "(Error)", MAXSZ_HC_CONNECTION);
- } else if (rc >= MAXSZ_HC_CONNECTION) {
- buf[MAXSZ_HC_CONNECTION-1] = '\0';
- buf[MAXSZ_HC_CONNECTION-2] = '.';
- buf[MAXSZ_HC_CONNECTION-3] = '.';
- buf[MAXSZ_HC_CONNECTION-4] = '.';
+ // TODO: handle all commands
+ if (command.action == ACTION_CREATE && command.object.type == OBJECT_LISTENER) {
+ if (hc_listener_create(s, &command.object.listener) < 0) {
+ fprintf(stderr, "Error running command");
+ goto ERR_CMD;
}
- printf("%s\n", buf);
}
-
- hc_data_free(data);
exit(EXIT_SUCCESS);
ERR_CMD:
diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c
index fed9d95..f5ed231 100644
--- a/hicn-light/src/hicn/config/configuration.c
+++ b/hicn-light/src/hicn/config/configuration.c
@@ -21,6 +21,8 @@
* @endcode
*/
+#include <hicn/ctrl/commands.h>
+
#ifndef _WIN32
#include <arpa/inet.h>
#include <unistd.h>
@@ -41,7 +43,7 @@
#include <hicn/core/listener.h> //the listener list
#include <hicn/core/listener_table.h>
-#include <hicn/utils/commands.h>
+#include <hicn/ctrl/commands.h>
#include <hicn/utils/utils.h>
#include <hicn/utils/punting.h>
#include <hicn/util/log.h>
@@ -210,13 +212,11 @@ configuration_on_listener_add(configuration_t * config, uint8_t * packet,
}
// NOTE: interface_name is expected NULL for hICN listener
- face_type_t face_type;
- if (!face_type_is_defined(control->listener_type))
+ face_type_t face_type = get_face_type_from_listener_type((hc_connection_type_t) control->listenerType);
+ if (!face_type_is_defined(face_type))
goto NACK;
- face_type = (face_type_t)control->listener_type;
-
- listener = listener_create(face_type, &address, control->interface_name, control->symbolic, forwarder);
+ listener = listener_create(face_type, &address, control->interfaceName, control->symbolic, forwarder);
if (!listener)
goto NACK;
@@ -1061,10 +1061,11 @@ uint8_t *
configuration_on_punting_add(configuration_t * config, uint8_t * packet,
unsigned ingress_id)
{
-#if !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
+// #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 !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
+ cmd_punting_add_t * control = &msg->payload;
if (ip_address_empty(&control->address))
goto NACK;
@@ -1409,9 +1410,11 @@ configuration_receive_command(configuration_t * config, msgbuf_t * msgbuf)
break;
}
- 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);
+ if (connection_id_is_valid(msgbuf->connection_id)) {
+ 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, sizeof(cmd_header_t));
+ }
switch (msgbuf->command.type) {
case COMMAND_TYPE_LISTENER_LIST:
@@ -1429,3 +1432,22 @@ configuration_receive_command(configuration_t * config, msgbuf_t * msgbuf)
// XXX only if we consumed the whole packet.
return (ssize_t)msgbuf_get_len(msgbuf);
}
+
+face_type_t get_face_type_from_listener_type(hc_connection_type_t listener_type) {
+ face_type_t face_type;
+ switch (listener_type) {
+ case CONNECTION_TYPE_TCP:
+ face_type = FACE_TYPE_TCP_LISTENER;
+ break;
+ case CONNECTION_TYPE_UDP:
+ face_type = FACE_TYPE_UDP_LISTENER;
+ break;
+ case CONNECTION_TYPE_HICN:
+ face_type = FACE_TYPE_HICN_LISTENER;
+ break;
+ default:
+ face_type = FACE_TYPE_UNDEFINED;
+ }
+ return face_type;
+}
+
diff --git a/hicn-light/src/hicn/config/configuration.h b/hicn-light/src/hicn/config/configuration.h
index fa1b041..1cf772b 100644
--- a/hicn-light/src/hicn/config/configuration.h
+++ b/hicn-light/src/hicn/config/configuration.h
@@ -27,7 +27,8 @@
#define configuration_h
#include "../core/msgbuf.h"
-#include "../utils/commands.h"
+#include "../core/strategy.h"
+#include <hicn/ctrl/api.h>
typedef struct configuration_s configuration_t;
@@ -126,4 +127,6 @@ uint8_t *
configuration_dispatch_command(configuration_t * config, command_type_t command_type,
uint8_t * packet, unsigned ingress_id);
+face_type_t get_face_type_from_listener_type(hc_connection_type_t listener_type);
+
#endif // configuration_h
diff --git a/hicn-light/src/hicn/config/controlListConnections.c b/hicn-light/src/hicn/config/controlListConnections.c
index c474317..fedc998 100644
--- a/hicn-light/src/hicn/config/controlListConnections.c
+++ b/hicn-light/src/hicn/config/controlListConnections.c
@@ -98,8 +98,8 @@ static CommandReturn _controlListConnections_Execute(CommandParser *parser,
}
// Process/Print message
- header_control_message *receivedHeader =
- (header_control_message *)response[0].iov_base;
+ cmd_header_t *receivedHeader =
+ (cmd_header_t *)response[0].iov_base;
uint8_t *receivedPayload = (uint8_t *)response[1].iov_base;
char *sourceString = NULL;
diff --git a/hicn-light/src/hicn/config/controlListListeners.c b/hicn-light/src/hicn/config/controlListListeners.c
index f0ab820..e8909fc 100644
--- a/hicn-light/src/hicn/config/controlListListeners.c
+++ b/hicn-light/src/hicn/config/controlListListeners.c
@@ -79,8 +79,8 @@ static CommandReturn _controlListListeners_Execute(CommandParser *parser,
}
// Process/Print message
- header_control_message *receivedHeader =
- (header_control_message *)response[0].iov_base;
+ cmd_header_t *receivedHeader =
+ (cmd_header_t *)response[0].iov_base;
uint8_t *receivedPayload = (uint8_t *)response[1].iov_base;
// Allocate output to pass to the main function if the call is not interactive
diff --git a/hicn-light/src/hicn/config/controlListPolicies.c b/hicn-light/src/hicn/config/controlListPolicies.c
index 9ea3bae..424893a 100644
--- a/hicn-light/src/hicn/config/controlListPolicies.c
+++ b/hicn-light/src/hicn/config/controlListPolicies.c
@@ -92,8 +92,8 @@ static CommandReturn _controlListPolicies_Execute(CommandParser *parser,
}
// Process/Print message
- header_control_message *receivedHeader =
- (header_control_message *)response[0].iov_base;
+ cmd_header_t *receivedHeader =
+ (cmd_header_t *)response[0].iov_base;
uint8_t *receivedPayload = (uint8_t *)response[1].iov_base;
if (!receivedPayload) {
printf("No payload!\n");
diff --git a/hicn-light/src/hicn/config/controlListRoutes.c b/hicn-light/src/hicn/config/controlListRoutes.c
index 33a1ac6..df1c243 100644
--- a/hicn-light/src/hicn/config/controlListRoutes.c
+++ b/hicn-light/src/hicn/config/controlListRoutes.c
@@ -91,8 +91,8 @@ static CommandReturn _controlListRoutes_Execute(CommandParser *parser,
}
// Process/Print message
- header_control_message *receivedHeader =
- (header_control_message *)response[0].iov_base;
+ cmd_header_t *receivedHeader =
+ (cmd_header_t *)response[0].iov_base;
uint8_t *receivedPayload = (uint8_t *)response[1].iov_base;
// Allocate output to pass to the main function if the call is not interactive
diff --git a/hicn-light/src/hicn/core/connection.c b/hicn-light/src/hicn/core/connection.c
index 680e82b..3921eb5 100644
--- a/hicn-light/src/hicn/core/connection.c
+++ b/hicn-light/src/hicn/core/connection.c
@@ -233,7 +233,7 @@ connection_initialize(connection_t * connection, face_type_t type, const char *
assert(connection);
/* Interface name can be NULL eg always for TCP connnections */
assert(pair);
- assert(address_pair_is_valid(pair));
+ // assert(address_pair_is_valid(pair)); TODO: local addr in the pair is not initialized for now
*connection = (connection_t) {
.id = connection_id,
@@ -259,13 +259,13 @@ connection_initialize(connection_t * connection, face_type_t type, const char *
.wldr_autostart = true,
};
- connection->data = malloc(connection_vft[connection->type]->data_size);
+ connection->data = malloc(connection_vft[get_protocol(connection->type)]->data_size);
if (!connection->data)
goto ERR_DATA;
assert(connection_has_valid_id(connection));
- rc = connection_vft[connection->type]->initialize(connection);
+ rc = connection_vft[get_protocol(connection->type)]->initialize(connection);
if (rc < 0) {
goto ERR_VFT;
}
@@ -273,7 +273,7 @@ connection_initialize(connection_t * connection, face_type_t type, const char *
// XXX uncertain as fd is created by the listener !!
// XXX check whether it is registered !
#if 0
- connection->fd = connection_vft[connection->type]->get_socket(connection, address, NULL, interface_name);
+ connection->fd = connection_vft[get_protocol(connection->type)]->get_socket(connection, address, NULL, interface_name);
if (connection->fd < 0) {
ERROR("Error creating connection fd: (%d) %s", errno, strerror(errno));
goto ERR_FD;
@@ -282,7 +282,7 @@ connection_initialize(connection_t * connection, face_type_t type, const char *
// XXX data should be pre-allocated here
if (loop_register_fd(MAIN_LOOP, connection->fd, connection,
- connection_vft[connection->type]->read_callback, NULL) < 0)
+ connection_vft[get_protocol(connection->type)]->read_callback, NULL) < 0)
goto ERR_REGISTER_FD;
#endif
@@ -320,7 +320,7 @@ connection_finalize(connection_t * connection)
if (connection->wldr)
wldr_free(connection->wldr);
- connection_vft[connection->type]->finalize(connection);
+ connection_vft[get_protocol(connection->type)]->finalize(connection);
free(connection->interface_name);
free(connection);
@@ -338,7 +338,7 @@ command_type_t
_isACommand(PARCEventBuffer *input)
{
size_t bytesAvailable = parcEventBuffer_GetLength(input);
- parcAssertTrue(bytesAvailable >= sizeof(header_control_message),
+ parcAssertTrue(bytesAvailable >= sizeof(cmd_header_t),
"Called with too short an input: %zu", bytesAvailable);
uint8_t *msg = parcEventBuffer_Pullup(input, bytesAvailable);
@@ -367,7 +367,7 @@ connection_process_buffer(connection_t * connection, const uint8_t * buffer, siz
/* Too small a packet is not useful to decide between a control message and
* an hICN packet, the size of a control message is enough to test for both
* pakcet types */
- if (size < sizeof(header_control_message))
+ if (size < sizeof(cmd_header_t))
return 0;
/* We expect complete packets most of the time, so don't bother with state */
@@ -376,7 +376,7 @@ connection_process_buffer(connection_t * connection, const uint8_t * buffer, siz
command_type_t command_type = command_type_from_uchar(msg[1]);
if (!command_type_is_valid(command_type))
break;
- expected = sizeof(header_control_message) +
+ expected = sizeof(cmd_header_t) +
command_get_payload_len(command_type);
if (size < expected)
return 0;
@@ -423,7 +423,7 @@ connection_read_message(connection_t * connection, msgbuf_t * msgbuf)
assert(face_type_is_valid(connection->type));
assert(msgbuf);
- return connection_vft[connection->type]->read_message(connection, msgbuf);
+ return connection_vft[get_protocol(connection->type)]->read_message(connection, msgbuf);
}
uint8_t *
@@ -432,7 +432,7 @@ connection_read_packet(connection_t * connection)
assert(connection);
assert(face_type_is_valid(connection->type));
- return connection_vft[connection->type]->read_packet(connection);
+ return connection_vft[get_protocol(connection->type)]->read_packet(connection);
}
#endif
@@ -444,7 +444,7 @@ connection_send_packet(const connection_t * connection, const uint8_t * packet,
assert(face_type_is_valid(connection->type));
assert(packet);
- return connection_vft[connection->type]->send_packet(connection, packet, size);
+ return connection_vft[get_protocol(connection->type)]->send_packet(connection, packet, size);
}
// ALL DEPRECATED CODE HERE TO BE UPDATED
@@ -453,7 +453,7 @@ connection_send_packet(const connection_t * connection, const uint8_t * packet,
bool
_connection_send(const connection_t * connection, msgbuf_t * msgbuf, bool queue)
{
- return connection_vft[connection->type]->send(connection, msgbuf, queue);
+ return connection_vft[get_protocol(connection->type)]->send(connection, msgbuf, queue);
}
bool
diff --git a/hicn-light/src/hicn/core/connection_vft.c b/hicn-light/src/hicn/core/connection_vft.c
index 9efdd01..d740a52 100644
--- a/hicn-light/src/hicn/core/connection_vft.c
+++ b/hicn-light/src/hicn/core/connection_vft.c
@@ -25,7 +25,7 @@ extern connection_ops_t connection_tcp;
extern connection_ops_t connection_udp;
const connection_ops_t * connection_vft[] = {
- [FACE_TYPE_HICN] = &connection_hicn,
- [FACE_TYPE_TCP] = &connection_tcp,
- [FACE_TYPE_UDP] = &connection_udp,
+ [FACE_PROTOCOL_HICN] = &connection_hicn,
+ [FACE_PROTOCOL_TCP] = &connection_tcp,
+ [FACE_PROTOCOL_UDP] = &connection_udp,
};
diff --git a/hicn-light/src/hicn/core/forwarder.c b/hicn-light/src/hicn/core/forwarder.c
index 4a31075..9954ecd 100644
--- a/hicn-light/src/hicn/core/forwarder.c
+++ b/hicn-light/src/hicn/core/forwarder.c
@@ -1130,7 +1130,11 @@ forwarder_receive(forwarder_t * forwarder, listener_t * listener,
uint8_t * packet = msgbuf_get_packet(msgbuf);
size_t size = msgbuf_get_len(msgbuf);
- assert(messageHandler_GetTotalPacketLength(packet) == size); // XXX confirm ?
+
+ // TODO: the assert fails
+ // size_t tmp = messageHandler_GetTotalPacketLength(packet);
+ // (void) tmp;
+ // assert(messageHandler_GetTotalPacketLength(packet) == size); // XXX confirm ?
/* Connection lookup */
const connection_table_t * table = forwarder_get_connection_table(listener->forwarder);
@@ -1179,11 +1183,13 @@ forwarder_receive(forwarder_t * forwarder, listener_t * listener,
return msgbuf_get_len(msgbuf);
case MSGBUF_TYPE_COMMAND:
- // XXX before it used to create the connection
+ // Create the connection to send the ack back
if (!connection_id_is_valid(msgbuf->connection_id))
- return forwarder_drop(forwarder, msgbuf_id);
- msgbuf->command.type = *(packet + 1); // XXX use header
- if (msgbuf->command.type >= COMMAND_TYPE_N) {
+ msgbuf->connection_id = listener_create_connection(listener, pair);
+
+ msg_header_t * msg = (msg_header_t*) packet;
+ msgbuf->command.type = msg->header.commandID;
+ if (msgbuf->command.type >= COMMAND_TYPE_N || msgbuf->command.type == COMMAND_TYPE_UNDEFINED) {
ERROR("Invalid command");
return -msgbuf_get_len(msgbuf);
}
diff --git a/hicn-light/src/hicn/core/listener.c b/hicn-light/src/hicn/core/listener.c
index de078b8..66b5c09 100644
--- a/hicn-light/src/hicn/core/listener.c
+++ b/hicn-light/src/hicn/core/listener.c
@@ -69,17 +69,21 @@ listener_initialize(listener_t * listener, face_type_t type, const char * name,
.forwarder = forwarder,
};
- listener->data = malloc(listener_vft[listener->type]->data_size);
+ face_protocol_t face_protocol = get_protocol(listener->type);
+ if (face_protocol == FACE_PROTOCOL_UNKNOWN)
+ goto ERR_VFT;
+
+ listener->data = malloc(listener_vft[face_protocol]->data_size);
if (!listener->data)
goto ERR_DATA;
assert(listener_has_valid_type(listener));
- rc = listener_vft[listener->type]->initialize(listener);
+ rc = listener_vft[face_protocol]->initialize(listener);
if (rc < 0)
goto ERR_VFT;
- listener->fd = listener_vft[listener->type]->get_socket(listener, address, NULL, interface_name);
+ listener->fd = listener_vft[face_protocol]->get_socket(listener, address, NULL, interface_name);
if (listener->fd < 0) {
ERROR("Error creating listener fd: (%d) %s", errno, strerror(errno));
goto ERR_FD;
@@ -136,7 +140,7 @@ listener_finalize(listener_t * listener)
closesocket(listener->fd);
#endif
- listener_vft[listener->type]->finalize(listener);
+ listener_vft[get_protocol(listener->type)]->finalize(listener);
free(listener->data);
free(listener->interface_name);
@@ -152,13 +156,12 @@ int listener_get_socket(const listener_t * listener, const address_t * local,
assert(listener);
assert(listener_has_valid_type(listener));
assert(local);
- assert(remote);
+ // assert(remote); TODO: can it be null?
- return listener_vft[listener->type]->get_socket(listener, local, remote,
+ return listener_vft[get_protocol(listener->type)]->get_socket(listener, local, remote,
interface_name);
}
-// XXX CHANGE : we now get the fd directly from the listener
unsigned listener_create_connection(const listener_t * listener,
const address_pair_t * pair)
{
@@ -167,22 +170,17 @@ unsigned listener_create_connection(const listener_t * listener,
assert(pair);
// XXX TODO This code is likely common with connection creation code
- const char * name = NULL;
connection_table_t * table = forwarder_get_connection_table(listener->forwarder);
connection_t * connection;
- connection_table_allocate(table, connection, pair, name);
+ connection_table_allocate(table, connection, pair, listener->name);
unsigned connid = connection_table_get_connection_id(table, connection);
bool local = address_is_local(address_pair_get_local(pair));
- int fd = listener_get_socket(listener, address_pair_get_local(pair),
- address_pair_get_remote(pair), NULL); // XXX interfacename was not specified
-
- // XXX here we use the same interface name as the listener
- int rc = connection_initialize(connection, listener->type, name,
- listener->interface_name, fd, pair, local, connid, listener->forwarder);
+ int rc = connection_initialize(connection, listener->type, listener->name,
+ listener->interface_name, listener->fd, pair, local, connid, listener->forwarder);
if (rc < 0)
return ~0; // XXX how to return an error
@@ -199,7 +197,7 @@ listener_punt(const listener_t * listener, const char * prefix_s)
assert(listener_get_type(listener) == FACE_TYPE_HICN);
assert(prefix_s);
- return listener_vft[listener_get_type(listener)]->punt(listener, prefix_s);
+ return listener_vft[get_protocol(listener->type)]->punt(listener, prefix_s);
}
@@ -223,7 +221,7 @@ listener_read_single(listener_t * listener)
address_pair_t pair;
pair.local = *listener_get_address(listener);
- ssize_t n = listener_vft[listener->type]->read_single(listener->fd, msgbuf,
+ ssize_t n = listener_vft[get_protocol(listener->type)]->read_single(listener->fd, msgbuf,
address_pair_get_remote(&pair));
if (n < 1)
return 0;
@@ -262,7 +260,7 @@ listener_read_batch(listener_t * listener)
do {
/* Prepare the msgbuf and address pair arrays */
msgbuf_t * msgbuf[MAX_MSG];
- if (!msgbuf_pool_getn(msgbuf_pool, msgbuf, MAX_MSG))
+ if (msgbuf_pool_getn(msgbuf_pool, msgbuf, MAX_MSG) < 0)
break;
address_pair_t pair[MAX_MSG];
@@ -270,7 +268,7 @@ listener_read_batch(listener_t * listener)
for (unsigned i = 0; i < MAX_MSG; i++)
address_remote[i] = address_pair_get_remote(&pair[i]);
- ssize_t n = listener_vft[listener->type]->read_batch(listener->fd,
+ ssize_t n = listener_vft[get_protocol(listener->type)]->read_batch(listener->fd,
msgbuf, address_remote, MAX_MSG);
// XXX error check
@@ -303,7 +301,7 @@ listener_read_callback(listener_t * listener, int fd, void * user_data)
assert(listener);
assert(fd == listener->fd);
- if (listener_vft[listener->type]->read_batch)
+ if (listener_vft[get_protocol(listener->type)]->read_batch)
return listener_read_batch(listener);
return listener_read_single(listener);
@@ -375,7 +373,7 @@ listener_setup_all(const forwarder_t * forwarder, uint16_t port, const char *loc
// XXX TODO
void
-listener_setup_local_ipv4(const forwarder_t * forwarder, uint16_t port)
+listener_setup_local_ipv4(forwarder_t * forwarder, uint16_t port)
{
#if 0
// XXX memset
@@ -384,4 +382,10 @@ listener_setup_local_ipv4(const forwarder_t * forwarder, uint16_t port)
_setupUdpListener(forwarder, "lo_udp", &address, "lo");
_setupTcpListener(forwarder, "lo_tcp", &address, "lo");
#endif
+ address_t address;
+ memset(&address, 0, sizeof(address_t));
+ address = ADDRESS4_LOCALHOST(port);
+
+ listener_create(FACE_TYPE_UDP_LISTENER, &address, "lo", "lo_udp", forwarder);
+ // listener_create(FACE_TYPE_TCP_LISTENER, &address, "lo", "lo_tcp", forwarder);
}
diff --git a/hicn-light/src/hicn/core/listener.h b/hicn-light/src/hicn/core/listener.h
index 79aefef..b550749 100644
--- a/hicn-light/src/hicn/core/listener.h
+++ b/hicn-light/src/hicn/core/listener.h
@@ -85,7 +85,7 @@ unsigned listener_create_connection(const listener_t * listener,
void listener_setup_all(const struct forwarder_s * forwarder, uint16_t port, const char *localPath);
-void listener_setup_local_ipv4(const struct forwarder_s * forwarder, uint16_t port);
+void listener_setup_local_ipv4(struct forwarder_s * forwarder, uint16_t port);
void listener_process_packet(const listener_t * listener,
const uint8_t * packet, size_t size);
diff --git a/hicn-light/src/hicn/core/listener_vft.c b/hicn-light/src/hicn/core/listener_vft.c
index edaa0c2..4f15fdd 100644
--- a/hicn-light/src/hicn/core/listener_vft.c
+++ b/hicn-light/src/hicn/core/listener_vft.c
@@ -25,7 +25,7 @@ extern listener_ops_t listener_tcp;
extern listener_ops_t listener_udp;
const listener_ops_t * listener_vft[] = {
- [FACE_TYPE_HICN] = &listener_hicn,
- [FACE_TYPE_TCP] = &listener_tcp,
- [FACE_TYPE_UDP] = &listener_udp,
+ [FACE_PROTOCOL_HICN] = &listener_hicn,
+ [FACE_PROTOCOL_TCP] = &listener_tcp,
+ [FACE_PROTOCOL_UDP] = &listener_udp,
};
diff --git a/hicn-light/src/hicn/core/msgbuf.h b/hicn-light/src/hicn/core/msgbuf.h
index 72480b5..a52e6b2 100644
--- a/hicn-light/src/hicn/core/msgbuf.h
+++ b/hicn-light/src/hicn/core/msgbuf.h
@@ -47,6 +47,7 @@ typedef enum {
foreach_type
#undef _
} msgbuf_type_t;
+#undef foreach_type
typedef struct {
unsigned length;
diff --git a/hicn-light/src/hicn/core/test/test-msgbuf_pool.cc b/hicn-light/src/hicn/core/test/test-msgbuf_pool.cc
index 027f16a..9a79aef 100644
--- a/hicn-light/src/hicn/core/test/test-msgbuf_pool.cc
+++ b/hicn-light/src/hicn/core/test/test-msgbuf_pool.cc
@@ -26,7 +26,7 @@
extern "C" {
#define WITH_TESTS
#include <hicn/core/msgbuf_pool.h>
-#include <hicn/base/pool.h> // TODO: remove this line
+#include <hicn/base/pool.h>
}
#define PACKET_POOL_DEFAULT_INIT_SIZE 1024
diff --git a/hicn-light/src/hicn/io/base.c b/hicn-light/src/hicn/io/base.c
index 35d8915..bd5904c 100644
--- a/hicn-light/src/hicn/io/base.c
+++ b/hicn-light/src/hicn/io/base.c
@@ -115,11 +115,16 @@ ssize_t io_read_batch_socket(int fd, msgbuf_t ** msgbuf,
}
/* Assign size to msgbuf, and build address pair */
+ // TODO: local (in pair) is not initialized
for (int i = 0; i < n; i++) {
struct mmsghdr *msg = &msghdr[i];
msgbuf[i]->length = msg->msg_hdr.msg_iovlen;
**address = *(address_t*)msg->msg_hdr.msg_name;
+
+ struct sockaddr_in *src = msghdr[i].msg_hdr.msg_name;
+ DEBUG("msg received from port %u", ntohs(src->sin_port));
}
+ break;
}
return n;
diff --git a/hicn-light/src/hicn/io/tcp.c b/hicn-light/src/hicn/io/tcp.c
index e4e2b06..e4f5d19 100644
--- a/hicn-light/src/hicn/io/tcp.c
+++ b/hicn-light/src/hicn/io/tcp.c
@@ -391,14 +391,14 @@ connection_tcp_read_message(connection_t * connection, msgbuf_t * msgbuf)
size_t n = evbuffer_get_length(data->evbuffer);
// XXX this check was wrong
- // parcAssertTrue(n >= sizeof(header_control_message),
+ // parcAssertTrue(n >= sizeof(cmd_header_t),
"Called with too short an input: %zu", n);
// XXX WTF
if (stream->next_len == 0) {
// this linearizes the first messageHandler_GetIPv6HeaderLength() bytes of the
// input buffer's iovecs and returns a pointer to it.
- uint8_t *fh = parcEventBuffer_Pullup(data->evbuffer, sizeof(header_control_message));
+ uint8_t *fh = parcEventBuffer_Pullup(data->evbuffer, sizeof(cmd_header_t));
// Calculate the total message size based on the fixed header
stream->next_len = messageHandler_GetTotalPacketLength(fh);
diff --git a/hicn-light/src/hicn/io/udp.c b/hicn-light/src/hicn/io/udp.c
index 38d6438..edff902 100644
--- a/hicn-light/src/hicn/io/udp.c
+++ b/hicn-light/src/hicn/io/udp.c
@@ -215,15 +215,6 @@ listener_udp_initialize(listener_t * listener)
listener_udp_data_t * data = listener->data;
assert(data);
#endif
-
- // XXX Socket creation should be a function per-se and not be called in
- // initialize !
- listener->fd = listener_get_socket(listener, &listener->address, NULL,
- listener->interface_name);
- if (listener->fd < 0) {
- ERROR("Error creating UDP socket: (%d) %s", errno, strerror(errno));
- return -1;
- }
return 0;
}
@@ -249,7 +240,7 @@ int
listener_udp_get_socket(const listener_t * listener, const address_t * local,
const address_t * remote, const char * interface_name)
{
- int fd = socket(address_family(remote), SOCK_DGRAM, 0);
+ int fd = socket(address_family(local), SOCK_DGRAM, 0);
if (fd < 0)
goto ERR_SOCKET;
@@ -257,7 +248,7 @@ listener_udp_get_socket(const listener_t * listener, const address_t * local,
goto ERR;
}
- if (bind(fd, address_sa(local), address_socklen(remote)) < 0) {
+ if (bind(fd, address_sa(local), address_socklen(local)) < 0) {
perror("bind");
goto ERR;
}
@@ -313,7 +304,7 @@ connection_udp_initialize(connection_t * connection)
{
assert(connection);
- assert(connection->type == FACE_TYPE_UDP);
+ assert(connection->type == FACE_TYPE_UDP || connection->type == FACE_TYPE_UDP_LISTENER);
assert(connection->interface_name);
connection_udp_data_t * data = connection->data;
diff --git a/hicn-light/src/hicn/utils/utils.c b/hicn-light/src/hicn/utils/utils.c
index 42bcb7f..2bfd8dc 100644
--- a/hicn-light/src/hicn/utils/utils.c
+++ b/hicn-light/src/hicn/utils/utils.c
@@ -128,8 +128,8 @@ bool utils_IsNumber(const char *string) {
//uint32_t currentSeqNum = utils_GetNextSequenceNumber();
//
//// Allocate and fill the header
-//header_control_message *headerControlMessage =
-// parcMemory_AllocateAndClear(sizeof(header_control_message));
+//cmd_header_t *headerControlMessage =
+// parcMemory_AllocateAndClear(sizeof(cmd_header_t));
//headerControlMessage->messageType = REQUEST_LIGHT;
//headerControlMessage->commandID = command;
//headerControlMessage->seqNum = currentSeqNum;
@@ -139,14 +139,14 @@ bool utils_IsNumber(const char *string) {
//
//struct iovec msg[2];
//msg[0].iov_base = headerControlMessage;
-//msg[0].iov_len = sizeof(header_control_message);
+//msg[0].iov_len = sizeof(cmd_header_t);
//msg[1].iov_base = payload;
//msg[1].iov_len = payloadLen;
//
//struct iovec *response = controlState_WriteRead(state, msg);
//
-//header_control_message *receivedHeader =
-// (header_control_message *)response[0].iov_base;
+//cmd_header_t *receivedHeader =
+// (cmd_header_t *)response[0].iov_base;
//if (receivedHeader->seqNum != currentSeqNum) {
//printf("Seq number is NOT correct: expected %d got %d \n", currentSeqNum,
// receivedHeader->seqNum);
diff --git a/lib/includes/hicn/face.h b/lib/includes/hicn/face.h
index 45a1b97..0d116b6 100644
--- a/lib/includes/hicn/face.h
+++ b/lib/includes/hicn/face.h
@@ -138,6 +138,13 @@ foreach_face_type
#undef _
} face_type_t;
+typedef enum {
+ FACE_PROTOCOL_HICN,
+ FACE_PROTOCOL_UDP,
+ FACE_PROTOCOL_TCP,
+ FACE_PROTOCOL_UNKNOWN,
+} face_protocol_t;
+
#define face_type_is_valid(face_type) \
(((face_type) >= FACE_TYPE_UNDEFINED) && (face_type < FACE_TYPE_N))
#define face_type_is_defined(face_type) \
@@ -209,5 +216,7 @@ face_snprintf(char * s, size_t size, const face_t * face);
policy_tags_t face_get_tags(const face_t * face);
int face_set_tags(face_t * face, policy_tags_t tags);
+face_protocol_t get_protocol(face_type_t face_type);
+
#endif /* HICN_FACE_H */
diff --git a/lib/includes/hicn/util/ip_address.h b/lib/includes/hicn/util/ip_address.h
index 2788004..a43f167 100644
--- a/lib/includes/hicn/util/ip_address.h
+++ b/lib/includes/hicn/util/ip_address.h
@@ -135,6 +135,17 @@ const u8 * ip_address_get_buffer(const ip_address_t * ip_address, int family);
int ip_address_ntop (const ip_address_t * ip_address, char *dst,
const size_t len, int family);
int ip_address_pton (const char *ip_address_str, ip_address_t * ip_address);
+
+/**
+ * @brief Return the ip_address provided as parameter in string format.
+ * E.g. (for ipv4): "0.0.0.0"
+ *
+ * @param[in, out] s String to store the parsed address
+ * @param[in] size Size of the string @p s
+ * @param[in] ip_address Address to parse to string
+ * @param[in] family Address family (e.g. AF_INET, AF_INET6)
+ * @return int Length of the string generated parsing the addr
+ */
int ip_address_snprintf(char * s, size_t size, const ip_address_t * ip_address,
int family);
int ip_address_to_sockaddr(const ip_address_t * ip_address, struct sockaddr *sa,
diff --git a/lib/src/face.c b/lib/src/face.c
index 6d0d9c4..7b3bbe3 100644
--- a/lib/src/face.c
+++ b/lib/src/face.c
@@ -420,3 +420,24 @@ face_set_tags(face_t * face, policy_tags_t tags)
face->tags = tags;
return 1;
}
+
+face_protocol_t
+get_protocol(face_type_t face_type) {
+ switch (face_type) {
+ case FACE_TYPE_HICN:
+ case FACE_TYPE_HICN_LISTENER:
+ return FACE_PROTOCOL_HICN;
+
+ case FACE_TYPE_TCP:
+ case FACE_TYPE_TCP_LISTENER:
+ return FACE_PROTOCOL_TCP;
+
+ case FACE_TYPE_UDP:
+ case FACE_TYPE_UDP_LISTENER:
+ return FACE_PROTOCOL_UDP;
+ break;
+
+ default:
+ return FACE_PROTOCOL_UNKNOWN;
+ }
+}