summaryrefslogtreecommitdiffstats
path: root/ctrl/facemgr/includes
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2019-10-07 09:52:33 +0200
committerJordan Augé <jordan.auge+fdio@cisco.com>2019-10-07 15:55:42 +0200
commit6b84ec54083da9911f5ad4816d0eb4f4745afad4 (patch)
treee4296ebb218fff02dc0bbea73ce1c8d12aba7bcc /ctrl/facemgr/includes
parent85a791ac2cdd35d79c00141e748b4c68fbdafb0d (diff)
[HICN-298] Release new hICN app for Android
Change-Id: I43adc62fadf00690b687078d739788dffdc5e566 Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'ctrl/facemgr/includes')
-rw-r--r--ctrl/facemgr/includes/CMakeLists.txt44
-rw-r--r--ctrl/facemgr/includes/facemgr.h28
-rw-r--r--ctrl/facemgr/includes/hicn/android_utility/android_utility.h48
-rw-r--r--ctrl/facemgr/includes/hicn/facemgr.h27
-rw-r--r--ctrl/facemgr/includes/hicn/facemgr/api.h81
-rw-r--r--ctrl/facemgr/includes/hicn/facemgr/cfg.h193
-rw-r--r--ctrl/facemgr/includes/hicn/util/log.h66
7 files changed, 487 insertions, 0 deletions
diff --git a/ctrl/facemgr/includes/CMakeLists.txt b/ctrl/facemgr/includes/CMakeLists.txt
new file mode 100644
index 000000000..566424c67
--- /dev/null
+++ b/ctrl/facemgr/includes/CMakeLists.txt
@@ -0,0 +1,44 @@
+# 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.
+
+# XXX
+
+set(LIBFACEMGR_INCLUDE_DIRS
+ ${CMAKE_CURRENT_SOURCE_DIR} ""
+ CACHE INTERNAL
+ "" FORCE
+)
+if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
+
+ set(TO_INSTALL_HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/facemgr.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn/facemgr/api.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn/facemgr/cfg.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn/util/log.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn/android_utility/android_utility.h
+ PARENT_SCOPE
+ )
+
+else ()
+
+ set(TO_INSTALL_HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/facemgr.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn/facemgr/api.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn/facemgr/cfg.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn/util/log.h
+ PARENT_SCOPE
+ )
+
+endif ()
+
+
diff --git a/ctrl/facemgr/includes/facemgr.h b/ctrl/facemgr/includes/facemgr.h
new file mode 100644
index 000000000..b322e7b1f
--- /dev/null
+++ b/ctrl/facemgr/includes/facemgr.h
@@ -0,0 +1,28 @@
+/*
+ * 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 facemgr.h
+ * \brief Main interface for hICN face manager library
+ */
+#ifndef HICN_FACEMGR_H
+#define HICN_FACEMGR_H
+
+#include <hicn/policy.h>
+#include <hicn/facemgr/api.h>
+#include <hicn/facemgr/cfg.h>
+
+#endif /* HICN_FACEMGR_H */
+
diff --git a/ctrl/facemgr/includes/hicn/android_utility/android_utility.h b/ctrl/facemgr/includes/hicn/android_utility/android_utility.h
new file mode 100644
index 000000000..53adfedf6
--- /dev/null
+++ b/ctrl/facemgr/includes/hicn/android_utility/android_utility.h
@@ -0,0 +1,48 @@
+/*
+ * 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 android_utility/android_utility.h
+ * \brief Android utility.
+ *
+ * This class relies on a small utility wrapper shipped with the Android
+ * application to access to Java SDK APIs for information not available to
+ * native code.
+ *
+ * For instance, we currently don't have on Linux any mean to get the type
+ * associated to an interface, especially for cellular interfaces. WiFi and
+ * Bluetooth information is for instance available through specific netlink
+ * subsystems, or by means of a support library, but cellular detection mostly
+ * relies on heuristics based on interface names (eg. in network manager).
+ *
+ * Android ship a Radio Interface Layer (RIL) daemon that exposes a control
+ * socket to the Java API to control the radio layer, but there is no working
+ * code exploiting it and no proper documentation.
+ */
+
+#ifndef FACEMGR_INTERFACE_ANDROID_UTILITY_H
+#define FACEMGR_INTERFACE_ANDROID_UTILITY_H
+
+#ifdef __ANDROID__
+
+#include <jni.h>
+
+typedef struct {
+ JavaVM *jvm;
+} android_utility_cfg_t;
+
+#endif /* __ANDROID__ */
+
+#endif /* FACEMGR_INTERFACE_ANDROID_UTILITY_H */
diff --git a/ctrl/facemgr/includes/hicn/facemgr.h b/ctrl/facemgr/includes/hicn/facemgr.h
new file mode 100644
index 000000000..4165a8fc4
--- /dev/null
+++ b/ctrl/facemgr/includes/hicn/facemgr.h
@@ -0,0 +1,27 @@
+/*
+ * 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 facemgr.h
+ * \brief Main interface for hICN face manager library
+ */
+#ifndef HICN_FACEMGR_H
+#define HICN_FACEMGR_H
+
+#include <hicn/policy.h>
+#include <hicn/facemgr/api.h>
+
+#endif /* HICN_FACEMGR_H */
+
diff --git a/ctrl/facemgr/includes/hicn/facemgr/api.h b/ctrl/facemgr/includes/hicn/facemgr/api.h
new file mode 100644
index 000000000..c5c29c219
--- /dev/null
+++ b/ctrl/facemgr/includes/hicn/facemgr/api.h
@@ -0,0 +1,81 @@
+/*
+ * 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 facemgr.h
+ * \brief Face manager library interface
+ */
+#ifndef FACEMGR_H
+#define FACEMGR_H
+
+#include <hicn/facemgr/cfg.h>
+#include <hicn/util/ip_address.h>
+#ifdef __ANDROID__
+#include <hicn/android_utility/android_utility.h>
+#endif
+
+/*
+ * \brief Manual overlay settings (alternative to service discovery)
+ */
+
+typedef struct {
+ uint16_t local_port;
+ ip_address_t remote_addr;
+ uint16_t remote_port;
+} facemgr_overlay_setting_t;
+
+#define FACEMGR_OVERLAY_SETTING_EMPTY (facemgr_overlay_setting_t) { \
+ .local_port = 0, \
+ .remote_addr = IP_ADDRESS_EMPTY, \
+ .remote_port = 0, \
+}
+
+typedef struct {
+ facemgr_overlay_setting_t v4;
+ facemgr_overlay_setting_t v6;
+} facemgr_overlay_t;
+
+#define FACEMGR_OVERLAY_EMPTY (facemgr_overlay_t) { \
+ .v4 = FACEMGR_OVERLAY_SETTING_EMPTY, \
+ .v6 = FACEMGR_OVERLAY_SETTING_EMPTY, \
+}
+
+/*
+ * \brief Face manager context
+ */
+typedef struct facemgr_s facemgr_t;
+
+int facemgr_initialize(facemgr_t *);
+int facemgr_finalize(facemgr_t *);
+facemgr_t * facemgr_create();
+facemgr_t * facemgr_create_with_config(facemgr_cfg_t * cfg);
+void facemgr_stop(facemgr_t *);
+void facemgr_free(facemgr_t *);
+
+int facemgr_set_config(facemgr_t * facemgr, facemgr_cfg_t * cfg);
+int facemgr_reset_config(facemgr_t * facemgr);
+void facemgr_set_event_loop_handler(facemgr_t * facemgr, void * loop,
+ void * loop_register_fd,
+ void * loop_unregister_event);
+int facemgr_bootstrap(facemgr_t * facemgr);
+#ifdef __ANDROID__
+void facemgr_set_jvm(facemgr_t * facemgr, JavaVM *jvm);
+#endif /* __ANDROID__ */
+
+typedef int (*facemgr_list_faces_cb_t)(face_t * face, void * user_data);
+
+void facemgr_list_faces(facemgr_t * facemgr, facemgr_list_faces_cb_t cb, void * user_data);
+
+#endif /* FACEMGR_H */
diff --git a/ctrl/facemgr/includes/hicn/facemgr/cfg.h b/ctrl/facemgr/includes/hicn/facemgr/cfg.h
new file mode 100644
index 000000000..c121c687f
--- /dev/null
+++ b/ctrl/facemgr/includes/hicn/facemgr/cfg.h
@@ -0,0 +1,193 @@
+/*
+ * 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 cfg.h
+ * \brief Face manager configuration
+ */
+#ifndef FACEMGR_CFG_H
+#define FACEMGR_CFG_H
+
+#include <hicn/ctrl/face.h>
+#include <hicn/util/log.h>
+
+/* Face type */
+
+#define foreach_face_type_layer \
+ _(UNDEFINED) \
+ _(3) \
+ _(4) \
+ _(N)
+
+typedef enum {
+#define _(x) FACE_TYPE_LAYER_ ## x,
+ foreach_face_type_layer
+#undef _
+} face_type_layer_t;
+
+#define foreach_face_type_encap \
+ _(UNDEFINED) \
+ _(TCP) \
+ _(UDP) \
+ _(N)
+
+typedef enum {
+#define _(x) FACE_TYPE_ENCAP_ ## x,
+ foreach_face_type_encap
+#undef _
+} face_type_encap_t;
+
+typedef struct {
+ face_type_layer_t layer;
+ face_type_encap_t encap;
+} facemgr_face_type_t;
+
+#define FACEMGR_FACE_TYPE_UNDEFINED (facemgr_face_type_t) { \
+ .layer = FACE_TYPE_LAYER_UNDEFINED, \
+ .encap = FACE_TYPE_ENCAP_UNDEFINED, \
+}
+
+#define FACEMGR_FACE_TYPE_NATIVE_UDP (facemgr_face_type_t) { \
+ .layer = FACE_TYPE_LAYER_3, \
+ .encap = FACE_TYPE_ENCAP_UDP, \
+}
+
+#define FACEMGR_FACE_TYPE_NATIVE_TCP (facemgr_face_type_t) { \
+ .layer = FACE_TYPE_LAYER_3, \
+ .encap = FACE_TYPE_ENCAP_TCP, \
+}
+
+#define FACEMGR_FACE_TYPE_OVERLAY_UDP (facemgr_face_type_t) { \
+ .layer = FACE_TYPE_LAYER_4, \
+ .encap = FACE_TYPE_ENCAP_UDP, \
+}
+
+#define FACEMGR_FACE_TYPE_OVERLAY_TCP (facemgr_face_type_t) { \
+ .layer = FACE_TYPE_LAYER_4, \
+ .encap = FACE_TYPE_ENCAP_TCP, \
+}
+
+/* Face manager configuration */
+
+#ifdef __ANDROID__
+#define FACEMGR_FACE_TYPE_DEFAULT FACEMGR_FACE_TYPE_OVERLAY_UDP
+#else
+#define FACEMGR_FACE_TYPE_DEFAULT FACEMGR_FACE_TYPE_NATIVE_TCP
+#endif /* __ANDROID__ */
+
+#define DEFAULT_FACE_TYPE FACE_TYPE_AUTO
+#define FACEMGR_CFG_DEFAULT_DISCOVERY true
+//#define DEFAULT_IGNORE "lo"
+#define FACEMGR_CFG_DEFAULT_IPV4 true
+#define FACEMGR_CFG_DEFAULT_IPV6 true
+
+
+
+typedef struct facemgr_cfg_s facemgr_cfg_t;
+
+facemgr_cfg_t * facemgr_cfg_create();
+void facemgr_cfg_free(facemgr_cfg_t * cfg);
+int facemgr_cfg_initialize(facemgr_cfg_t * cfg);
+int facemgr_cfg_finalize(facemgr_cfg_t * cfg);
+void facemgr_cfg_dump(facemgr_cfg_t * cfg);
+
+/* Rules */
+
+typedef struct facemgr_cfg_rule_s facemgr_cfg_rule_t;
+
+facemgr_cfg_rule_t * facemgr_cfg_rule_create();
+void facemgr_cfg_rule_free(facemgr_cfg_rule_t * rule);
+int facemgr_cfg_rule_initialize(facemgr_cfg_rule_t * rule);
+int facemgr_cfg_rule_finalize(facemgr_cfg_rule_t * rule);
+
+int facemgr_cfg_rule_set_match(facemgr_cfg_rule_t * rule,
+ const char * interface_name, netdevice_type_t interface_type);
+
+int facemgr_cfg_rule_set_face_type(facemgr_cfg_rule_t * cfg_rule, facemgr_face_type_t * face_type);
+int facemgr_cfg_rule_unset_face_type(facemgr_cfg_rule_t * cfg_rule);
+
+int facemgr_cfg_rule_set_discovery(facemgr_cfg_rule_t * cfg_rule, bool status);
+int facemgr_cfg_rule_unset_discovery(facemgr_cfg_rule_t * cfg_rule);
+
+int facemgr_cfg_rule_set_ignore(facemgr_cfg_rule_t * cfg_rule, bool status);
+int facemgr_cfg_rule_unset_ignore(facemgr_cfg_rule_t * cfg_rule);
+
+int facemgr_cfg_rule_set_ipv4(facemgr_cfg_rule_t * cfg_rule, bool status);
+int facemgr_cfg_rule_unset_ipv4(facemgr_cfg_rule_t * cfg_rule);
+
+int facemgr_cfg_rule_set_ipv6(facemgr_cfg_rule_t * cfg_rule, bool status);
+int facemgr_cfg_rule_unset_ipv6(facemgr_cfg_rule_t * cfg_rule);
+
+int facemgr_cfg_rule_set_overlay(facemgr_cfg_rule_t * rule, int family,
+ ip_address_t * local_addr, uint16_t local_port,
+ ip_address_t * remote_addr, uint16_t remote_port);
+int facemgr_rule_unset_overlay(facemgr_cfg_rule_t * rule, int family);
+
+/* General */
+int facemgr_cfg_set_face_type(facemgr_cfg_t * cfg, facemgr_face_type_t * face_type);
+int facemgr_cfg_unset_face_type(facemgr_cfg_t * cfg);
+int facemgr_cfg_set_discovery(facemgr_cfg_t * cfg, bool status);
+int facemgr_cfg_unset_discovery(facemgr_cfg_t * cfg);
+
+int facemgr_cfg_set_overlay(facemgr_cfg_t * cfg, int family,
+ ip_address_t * local_addr, uint16_t local_port,
+ ip_address_t * remote_addr, uint16_t remote_port);
+int facemgr_cfg_unset_overlay(facemgr_cfg_t * cfg, int family);
+
+
+int facemgr_cfg_add_rule(facemgr_cfg_t * cfg, facemgr_cfg_rule_t * rule);
+int facemgr_cfg_del_rule(facemgr_cfg_t * cfg, facemgr_cfg_rule_t * rule);
+int facemgr_cfg_get_rule(const facemgr_cfg_t * cfg, const char * interface_name,
+ netdevice_type_t interface_type, facemgr_cfg_rule_t ** rule);
+
+/* Log */
+
+/*
+ * Query API
+ *
+ * Takes the overrides into account
+ *
+ * TODO : interface_types are currently not taken into account by this API
+ */
+
+int facemgr_cfg_get_face_type(const facemgr_cfg_t * cfg,
+ const netdevice_t * netdevice, netdevice_type_t netdevice_type,
+ facemgr_face_type_t * face_type);
+int facemgr_cfg_get_discovery(const facemgr_cfg_t * cfg,
+ const netdevice_t * netdevice, netdevice_type_t netdevice_type,
+ bool * discovery);
+int facemgr_cfg_get_ignore(const facemgr_cfg_t * cfg,
+ const netdevice_t * netdevice, netdevice_type_t netdevice_type,
+ bool * ignore);
+int facemgr_cfg_get_ipv4(const facemgr_cfg_t * cfg,
+ const netdevice_t * netdevice, netdevice_type_t netdevice_type,
+ bool * ipv4);
+int facemgr_cfg_get_ipv6(const facemgr_cfg_t * cfg,
+ const netdevice_t * netdevice, netdevice_type_t netdevice_type,
+ bool * ipv6);
+int facemgr_cfg_get_overlay_local_addr(const facemgr_cfg_t * cfg,
+ const netdevice_t * netdevice, netdevice_type_t netdevice_type,
+ int family, ip_address_t * addr);
+int facemgr_cfg_get_overlay_local_port(const facemgr_cfg_t * cfg,
+ const netdevice_t * netdevice, netdevice_type_t netdevice_type,
+ int family, u16 * port);
+int facemgr_cfg_get_overlay_remote_addr(const facemgr_cfg_t * cfg,
+ const netdevice_t * netdevice, netdevice_type_t netdevice_type,
+ int family, ip_address_t * addr);
+int facemgr_cfg_get_overlay_remote_port(const facemgr_cfg_t * cfg,
+ const netdevice_t * netdevice, netdevice_type_t netdevice_type,
+ int family, u16 * port);
+
+#endif /* FACEMGR_CFG_H */
diff --git a/ctrl/facemgr/includes/hicn/util/log.h b/ctrl/facemgr/includes/hicn/util/log.h
new file mode 100644
index 000000000..f1cafba47
--- /dev/null
+++ b/ctrl/facemgr/includes/hicn/util/log.h
@@ -0,0 +1,66 @@
+/*
+ * 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 UTIL_LOG_H
+#define UTIL_LOG_H
+
+#include <stdarg.h> // va_*
+#include <stdio.h> // FILE
+#include <time.h> // time, localtime
+
+#define LOG_FATAL 0
+#define LOG_ERROR 1
+#define LOG_WARN 2
+#define LOG_INFO 3
+#define LOG_DEBUG 4
+#define LOG_TRACE 5
+
+typedef struct {
+ int log_level;
+ int debug;
+ FILE * log_file;
+} log_conf_t;
+
+#define DEFAULT_LOG_CONF { \
+ .log_level = LOG_DEBUG, \
+ .debug = 0, \
+ .log_file = NULL, \
+};
+
+extern log_conf_t log_conf;
+
+#define WITH_DEBUG(BLOCK) \
+ if (log_conf.log_level >= LOG_DEBUG) \
+ BLOCK
+
+#define FATAL(fmt, ...) (_log(LOG_FATAL, fmt, ##__VA_ARGS__ ))
+#define ERROR(fmt, ...) (_log(LOG_ERROR, fmt, ##__VA_ARGS__ ))
+#define WARN(fmt, ...) (_log(LOG_WARN, fmt, ##__VA_ARGS__ ))
+#define INFO(fmt, ...) (_log(LOG_INFO, fmt, ##__VA_ARGS__ ))
+#define DEBUG(fmt, ...) (_log(LOG_DEBUG, fmt, ##__VA_ARGS__ ))
+#define TRACE(fmt, ...) (_log(LOG_TRACE, fmt, ##__VA_ARGS__ ))
+
+void _log_va(int level, const char *fmt, va_list ap);
+
+void _log(int level, const char *fmt, ...);
+
+void fatal(char *fmt, ...);
+
+#ifdef HAVE_BACKTRACE
+#include <execinfo.h>
+void print_trace(void);
+#endif
+
+#endif // UTIL_LOG_H