Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
api.h
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
25 #ifndef HICN_SOCKET_API_H
26 #define HICN_SOCKET_API_H
27 
28 #include <stdint.h> // uint*_t
29 #include <stdlib.h>
30 
31 #include <hicn/hicn.h>
32 #include "error.h"
33 
34 #define BUFSIZE 4096
35 #define MAX_CONNECTIONS \
36  255 // We currently limit the number of connections we can establish
37 #ifndef IF_NAMESIZE
38 #define IF_NAMESIZE 16
39 #endif
40 /* hICN socket helper */
41 
43 typedef struct {
44  // uint32_t interval;
45 
46  /* Identifier used to name hICN TUN interfaces (should be unique) */
47  char *identifier;
48  // hicn_format_t format;
49 
50 } hicn_conf_t;
51 
55 typedef struct {
56  char *local_ip_address;
57  char *gateway_ip_address;
59 
60 #define EMPTY_HICN_ADJACENCY \
61  (hicn_adjacency_t) { 0, 0 }
62 
63 /* hICN socket operations */
64 
65 typedef struct {
66  uint8_t pkbuf[BUFSIZE];
67  uint32_t rb_pkbuf_r;
68  uint32_t rb_pkbuf_w;
70 
71 typedef enum { HS_UNSPEC, HS_LISTENER, HS_CONNECTION } hicn_socket_type_t;
72 
73 typedef struct hicn_socket_s {
74  hicn_socket_type_t type;
75  int fd;
76 
77  /* Implementation specific state follows */
78  char tun_name[IF_NAMESIZE];
79  uint32_t tun_id;
80 
81  hicn_buffer_t buffer;
82  void (*cb)(struct hicn_socket_s *, void *, uint8_t *, size_t);
83  void *cb_data;
84 
85  union {
86  struct {
87  ip_prefix_t tun_ip_address;
88  uint32_t interface_id;
89 
90  /* ID of the corresponding table : avoid default values of 0, 32766 and
91  * 32767 */
92  uint8_t table_id;
93  } connection;
94  };
96 
100 typedef struct {
101  /* Configuration data */
102  hicn_conf_t *conf;
103 
104  // We need state associate to each FD, to know what type of socket it is and
105  // its state.
106  void *socket_root;
109 
119 hicn_socket_helper_t *hicn_create();
120 
121 void hicn_destroy();
122 
138 hicn_conf_t *hicn_get_conf(hicn_socket_helper_t *hicn);
139 
149 int hicn_set_conf(hicn_socket_helper_t *hicn, hicn_conf_t *hicn_conf);
150 
156 void hicn_free(hicn_socket_helper_t *hicn);
157 
166 int hicn_get_local_address(const ip_prefix_t *remote_address,
167  ip_prefix_t *local_address);
168 
169 /* hICN socket */
170 
191 int hicn_socket(hicn_socket_helper_t *hicn, const char *identifier,
192  const char *local_ip_address);
193 
207 int hicn_listen(hicn_socket_helper_t *hicn, int fd, const char *prefix);
208 
219 int hicn_bind(hicn_socket_helper_t *hicn, int fd,
220  const char *remote_ip_address);
221 
222 #endif /* HICN_SOCKET_API_H */
hicn_conf_t
Definition: api.h:43
hicn_buffer_t
Definition: api.h:65
hicn_adjacency_t
Definition: api.h:55
ip_prefix_t
Definition: ip_address.h:103
hicn_socket_helper_t
Definition: api.h:100
error.h
hicn_socket_s
Definition: api.h:73
hicn_socket_helper_t::socket_root
void * socket_root
Definition: api.h:106