aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/libhicnctrl/includes/hicn/ctrl/socket.h
diff options
context:
space:
mode:
authorLuca Muscariello <muscariello@ieee.org>2022-08-04 16:06:34 +0200
committerLuca Muscariello <muscariello@ieee.org>2022-08-04 16:31:51 +0200
commit6d22a0db96aa7f8e3102ae44d00c09e36a2e9c57 (patch)
tree79546bbf09f6fbf74db7bc89117843f06ce937ea /ctrl/libhicnctrl/includes/hicn/ctrl/socket.h
parent012843b1c0bc0838e69085ed83a79ec8b6f97360 (diff)
feat: Due to the deep modifications related to names and packet format,
this task cover a large part of the codebase and involves several changes: - the library provides a name data structure (hicn_name_t ), which is composed of a name prefix (hicn_name_prefix_t) and a name suffix (hicn_name_suffix_t), and it has been extended to provide all support functions required for name manipulation, including common prefix computation, as required for the Longest Prefix Match (LPM)in the forwarder, in addition to Exact Prefix Match (EPM). - all code has been rewritten to use this data structure instead of having for instance the forwarder define its own name class (used to be Name and NameBitVector) the code has been refactored to minimize name allocations and copies, one remaining aspect is the difference of name storage between PIT and CS entries (respectively in the PIT entry, and in the message buffer), which causes the packet cache index to be updated when a PIT entry is converted into a CS entry. By storing the name in the PIT/CS entry everytime, we might save on this operation). - hicn-light FIB has been rewritten : code has been refactored and should now be shorter and documented; unit tests have been drafted but more would be required to cover all cases and match the algorithms to add/remove nodes, as specified in the doc. all protocol details and hICN header formats are now abstracted by the library for the forwarder (and thus header.h and  protocols/*.h have been removed from public includes, and replaced by packet.h providing protocol agnostic packet level functions, completely replacing the compat.h header that used to provide similar functions. - this works by exposing a opaque buffer to the application (a kind of socket buffer) which is used by the lib to cache the packet format and offsets of the different layers in the buffer and provider efficient operations (the packet format is either defined for packet construction, or guessed at ingress, and this structure is updated accordingly only once). Co-authored-by: Jordan Augé <jordan.auge+fdio@cisco.com> Signed-off-by: Luca Muscariello <muscariello@ieee.org> Change-Id: I31e321897f85f0267fe8ba4720363c180564492f
Diffstat (limited to 'ctrl/libhicnctrl/includes/hicn/ctrl/socket.h')
-rw-r--r--ctrl/libhicnctrl/includes/hicn/ctrl/socket.h181
1 files changed, 181 insertions, 0 deletions
diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/socket.h b/ctrl/libhicnctrl/includes/hicn/ctrl/socket.h
new file mode 100644
index 000000000..2503fadd0
--- /dev/null
+++ b/ctrl/libhicnctrl/includes/hicn/ctrl/socket.h
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2021-2022 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 socket.h
+ * \brief Control socket
+ */
+
+#ifndef HICNCTRL_SOCKET_H
+#define HICNCTRL_SOCKET_H
+
+#include <hicn/ctrl/data.h>
+
+/* With UDP, the buffer should be able to receieve a full packet, and thus MTU
+ * (max 9000) is sufficient. Messages will be received fully one by one.
+ * With TCP, the buffer should be at least able to receive a message header and
+ * the maximum size of a data element, so any reasonable size will be correct,
+ * it might just optimize performance. Messages might arrive in chunks that the
+ * library is able to parse.
+ */
+#define JUMBO_MTU 9000
+#define RECV_BUFLEN 65535
+
+#define foreach_forwarder_type \
+ _(UNDEFINED) \
+ _(HICNLIGHT) \
+ _(VPP) \
+ _(N)
+
+typedef enum {
+#define _(x) FORWARDER_TYPE_##x,
+ foreach_forwarder_type
+#undef _
+} forwarder_type_t;
+
+extern const char *forwarder_type_str[];
+
+#define forwarder_type_str(x) forwarder_type_str[x]
+
+forwarder_type_t forwarder_type_from_str(const char *str);
+
+/**
+ * \brief Holds the state of an hICN control socket
+ */
+typedef struct hc_sock_s hc_sock_t;
+
+/**
+ * \brief Create an hICN control socket using the specified URL.
+ * \param [in] url - The URL to connect to.
+ * \return an hICN control socket
+ */
+hc_sock_t *hc_sock_create_url(const char *url);
+
+/**
+ * \brief Create an hICN control socket using the provided forwarder.
+ * \return an hICN control socket
+ */
+hc_sock_t *hc_sock_create_forwarder(forwarder_type_t forwarder);
+
+/**
+ * \brief Create an hICN control socket using the provided forwarder and a
+ * URL. \return an hICN control socket
+ */
+hc_sock_t *hc_sock_create_forwarder_url(forwarder_type_t forwarder,
+ const char *url);
+
+/**
+ * \brief Create an hICN control socket using the default connection type.
+ * XXX doc
+ * \return an hICN control socket
+ */
+hc_sock_t *hc_sock_create(forwarder_type_t forwarder, const char *url);
+
+/**
+ * \brief Frees an hICN control socket
+ * \param [in] s - hICN control socket
+ */
+void hc_sock_free(hc_sock_t *s);
+
+/**
+ * \brief Returns the next available sequence number to use for requests to
+ * the API. \param [in] s - hICN control socket
+ */
+int hc_sock_get_next_seq(hc_sock_t *s);
+
+/**
+ * \brief Sets the socket as non-blocking
+ * \param [in] s - hICN control socket
+ * \return Error code
+ */
+int hc_sock_set_nonblocking(hc_sock_t *s);
+
+/**
+ * \brief Return the file descriptor associated to the hICN contorl sock
+ * \param [in] s - hICN control socket
+ * \return The file descriptor (positive value), or a negative integer in case
+ * of error
+ */
+int hc_sock_get_fd(hc_sock_t *s);
+
+/**
+ * \brief Connect the socket
+ * \return Error code
+ */
+int hc_sock_connect(hc_sock_t *s);
+
+/**
+ * \brief Return the offset and size of available buffer space
+ * \param [in] s - hICN control socket
+ * \param [out] buffer - Offset in buffer
+ * \param [out] size - Remaining size
+ * \return Error code
+ */
+int hc_sock_get_recv_buffer(hc_sock_t *s, uint8_t **buffer, size_t *size);
+
+#if 0
+/**
+ * \brief Write/read iexchance on the control socket (internal helper
+ * function) \param [in] s - hICN control socket \param [in] msg - Message to
+ * send \param [in] msglen - Length of the message to send \return Error code
+ */
+int hc_sock_send(hc_sock_t *s, hc_msg_t *msg, size_t msglen, uint32_t seq);
+#endif
+
+/**
+ * \brief Processing data received by socket
+ * \param [in] s - hICN control socket
+ * \param [in] parse - Parse function to convert remote types into lib native
+ * types, or NULL not to perform any translation.
+ * \return Error code
+ */
+int hc_sock_process(hc_sock_t *s, hc_data_t **data);
+
+int hc_sock_receive(hc_sock_t *s, hc_data_t **data);
+int hc_sock_receive_all(hc_sock_t *s, hc_data_t **data);
+
+#if 0
+/**
+ * \brief Callback used in async mode when data is available on the socket
+ * \param [in] s - hICN control socket
+ * \return Error code
+ */
+int hc_sock_callback(hc_sock_t *s, hc_data_t **data);
+#endif
+
+/**
+ * \brief Reset the state of the sock (eg. to handle a reconnecton)
+ * \param [in] s - hICN control socket
+ * \return Error code
+ */
+int hc_sock_reset(hc_sock_t *s);
+
+void hc_sock_increment_woff(hc_sock_t *s, size_t bytes);
+
+#if 0
+int hc_sock_prepare_send(hc_sock_t *s, hc_result_t *result,
+ data_callback_t complete_cb, void *complete_cb_data);
+
+#endif
+
+int hc_sock_set_recv_timeout_ms(hc_sock_t *s, long timeout_ms);
+
+int hc_sock_set_async(hc_sock_t *s);
+
+int hc_sock_is_async(hc_sock_t *s);
+
+int hc_sock_on_receive(hc_sock_t *s, size_t count);
+
+#endif /* HICNCTRL_SOCKET_H */