summaryrefslogtreecommitdiffstats
path: root/hicn-plugin/src/faces/ip/face_ip.h
blob: 74f3a83dc65d9cbdf75dbaae23085f5fd16affa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
 * 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 __HICN_FACE_IP_H__
#define __HICN_FACE_IP_H__

#include <vlib/vlib.h>
#include <vnet/vnet.h>
#include "../face.h"
#include "../../cache_policies/cs_policy.h"

/**
 * @file
 *
 * @brief IP face
 *
 * A face is carried through nodes as a dpo. The face state is the object
 * pointed by the dpoi_index in the dpo_id_t (see
 * https://docs.fd.io/vpp/18.07/d0/d37/dpo_8h_source.html)
 */
typedef struct hicn_ip_face_t_
{
  /**
   * The headers to paint, in packet painting order
   */
  /* Local address of the interface sw_if */
  ip46_address_t local_addr;

  /* Remote address of neighbor */
  ip46_address_t remote_addr;

} hicn_face_ip_t;

/**
 * @bried vector of faces used to collect faces having the same local address
 *
 */
typedef hicn_face_id_t *hicn_face_ip_vec_t;

typedef struct hicn_ip_input_faces_s_
{
  /* Vector of all possible input faces */
  u32 vec_id;

  /* Preferred face. If an prod_app face is in the vector it will be the preferred one. */
  /* It's not possible to have multiple prod_app face in the same vector, they would have */
  /* the same local address. Every prod_app face is a point-to-point face between the forwarder */
  /* and the application. */
  hicn_face_id_t face_id;

} hicn_face_ip_input_faces_t;

/**
 * Hash tables that indexes a face by local address. For fast lookup when an
 * data arrives.
 */
extern mhash_t hicn_face_ip_local_hashtb;

/**
 * Hash tables that indexes a face by remote address. For fast lookup when an
 * interest arrives.
 */
extern mhash_t hicn_face_ip_remote_hashtb;

/**
 * Pool containing the vector of possible incoming faces.
 */
extern hicn_face_ip_vec_t *hicn_vec_pool;

/**
 * Key definition for the mhash table. An ip face is uniquely identified by ip
 * address and the interface id. The ip address can correspond to the remote ip
 * address of the next hicn hop, or to the local address of the receiving
 * interface. The former is used to retrieve the incoming face when an interest
 * is received, the latter when the arring packet is a data.
 */
typedef struct hicn_face_ip_key_s
{
  ip46_address_t addr;
  u32 sw_if;
} hicn_face_ip_key_t;


extern hicn_face_type_t hicn_face_ip_type;
extern hicn_face_vft_t ip_vft;

/**
 * @brief Create the key object for the mhash. Fill in the key object with the
 * expected values.
 *
 * @param addr Local or remote ip v6 address of the face
 * @param sw_if interface associated to the face
 * @param key Pointer to an allocated hicn_face_ip_key_t object
 */
always_inline void
hicn_face_ip6_get_key (const ip6_address_t * addr,
		       u32 sw_if, hicn_face_ip_key_t * key)
{
  key->addr.ip6 = *addr;
  key->sw_if = sw_if;
}


/**
 * @brief Create the key object for the mhash. Fill in the key object with the
 * expected values.
 *
 * @param addr Local or remote ip v4 address of the face
 * @param sw_if interface associated to the face
 * @param key Pointer to an allocated hicn_face_ip_key_t object
 */
always_inline void
hicn_face_ip4_get_key (const ip4_address_t * addr,
		       u32 sw_if, hicn_face_ip_key_t * key)
{
  ip46_address_set_ip4 (&(key->addr), addr);
  key->sw_if = sw_if;
}

/**
 * @brief Get the dpoi from the ip v4 address. Does not add any lock.
 *
 * @param addr Ip v4 address used to create the key for the hash table.
 * @param sw_if Software interface id used to create the key for the hash table.
 * @param hashtb Hash table (remote or local) where to perform the lookup.
 *
 * @result Pointer to the face.
 */
always_inline hicn_face_t *
hicn_face_ip4_get (const ip4_address_t * addr, u32 sw_if, mhash_t * hashtb)
{
  hicn_face_ip_key_t key;

  hicn_face_ip4_get_key (addr, sw_if, &key);

  hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb,
							     &key);

  return dpoi_index == NULL ? NULL : hicn_dpoi_get_from_idx (*dpoi_index);
}

/**
 * @brief Get the vector of faces from the ip v4 address. Does not add any lock.
 *
 * @param addr Ip v4 address used to create the key for the hash table.
 * @param sw_if Software interface id used to create the key for the hash table.
 * @param hashtb Hash table (remote or local) where to perform the lookup.
 *
 * @result Pointer to the face.
 */
always_inline hicn_face_ip_input_faces_t *
hicn_face_ip4_get_vec (const ip4_address_t * addr, u32 sw_if,
		       mhash_t * hashtb)
{
  hicn_face_ip_key_t key;

  hicn_face_ip4_get_key (addr, sw_if, &key);
  return (hicn_face_ip_input_faces_t *) mhash_get (hashtb, &key);
}

/**
 * @brief Get the vector of faces from the ip v6 address. Does not add any lock.
 *
 * @param addr Ip v6 address used to create the key for the hash table.
 * @param sw_if Software interface id used to create the key for the hash table.
 * @param hashtb Hash table (remote or local) where to perform the lookup.
 *
 * @result Pointer to the face.
 */
always_inline hicn_face_ip_input_faces_t *
hicn_face_ip6_get_vec (const ip6_address_t * addr, u32 sw_if,
		       mhash_t * hashtb)
{
  hicn_face_ip_key_t key;

  hicn_face_ip6_get_key (addr, sw_if, &key);
  return (hicn_face_ip_input_faces_t *) mhash_get (hashtb, &key);
}

/**
 * @brief Get the dpoi from the ip v6 address. Does not add any lock.
 *
 * @param addr Ip v6 address used to create the key for the hash table.
 * @param sw_if Software interface id used to create the key for the hash table.
 * @param hashtb Hash table (remote or local) where to perform the lookup.
 *
 * @result Pointer to the face.
 */
always_inline hicn_face_t *
hicn_face_ip6_get (const ip6_address_t * addr, u32 sw_if, mhash_t * hashtb)
{
  hicn_face_ip_key_t key;

  hicn_face_ip6_get_key (addr, sw_if, &key);

  hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb,
							     &key);

  return dpoi_index == NULL ? NULL : hicn_dpoi_get_from_idx (*dpoi_index);
}

/**
 * @brief Create a new face ip. API for other modules (e.g., routing)
 *
 * @param local_addr Local ip v4 or v6 address of the face
 * @param remote_addr Remote ip v4 or v6 address of the face
 * @param sw_if interface associated to the face
 * @param is_app_face Boolean to set the face as an application face
 * @param pfaceid Pointer to return the face id
 * @param is_app_prod if HICN_FACE_FLAGS_APPFACE_PROD the face is a local application face, all other values are ignored
 * @return HICN_ERROR_FACE_NO_GLOBAL_IP if the face does not have a globally
 * reachable ip address, otherwise HICN_ERROR_NONE
 */
int hicn_face_ip_add (const ip46_address_t * local_addr,
		      const ip46_address_t * remote_addr,
		      int swif, hicn_face_id_t * pfaceid, u8 is_app_prod);

/**
 * @brief Create a new incomplete face ip. (Meant to be used by the data plane)
 *
 * @param local_addr Local ip v4 or v6 address of the face
 * @param remote_addr Remote ip v4 or v6 address of the face
 * @param sw_if interface associated to the face
 * @param pfaceid Pointer to return the face id
 * @return HICN_ERROR_FACE_NO_GLOBAL_IP if the face does not have a globally
 * reachable ip address, otherwise HICN_ERROR_NONE
 */
always_inline void
hicn_iface_ip_add (const ip46_address_t * local_addr,
		   const ip46_address_t * remote_addr,
		   int sw_if, hicn_face_id_t * pfaceid)
{
  hicn_face_t *face;
  pool_get (hicn_dpoi_face_pool, face);

  hicn_face_ip_t *ip_face = (hicn_face_ip_t *) (face->data);

  clib_memcpy (&(ip_face->local_addr.ip6), local_addr,
	       sizeof (ip6_address_t));
  clib_memcpy (&(ip_face->remote_addr.ip6), remote_addr,
	       sizeof (ip6_address_t));
  face->shared.sw_if = sw_if;

  face->shared.adj = ADJ_INDEX_INVALID;
  face->shared.pl_id = (u16) 0;
  face->shared.face_type = hicn_face_ip_type;
  face->shared.flags = HICN_FACE_FLAGS_IFACE;
  face->shared.locks = 1;

  hicn_face_ip_key_t key;
  hicn_face_ip6_get_key (&(remote_addr->ip6), sw_if, &key);
  *pfaceid = hicn_dpoi_get_index (face);

  mhash_set_mem (&hicn_face_ip_remote_hashtb, &key, (uword *) pfaceid, 0);

  for (int i = 0; i < HICN_N_COUNTER; i++)
    {
      vlib_validate_combined_counter (&counters[(*pfaceid) * HICN_N_COUNTER],
				      i);
      vlib_zero_combined_counter (&counters[(*pfaceid) * HICN_N_COUNTER], i);
    }
}

/**
 * @brief Delete an ip face
 *
 * @param face_id Id of the face to delete
 * @return HICN_ERROR_FACE_NOT_FOUND if the face does not exist, otherwise
 * HICN_ERROR_NONE
 */
int hicn_face_ip_del (hicn_face_id_t face_id);

/**
 * @brief Format a IP face
 *
 * @param s Pointer to a previous string. If null it will be initialize
 * @param args Array storing input values. Expected u32 face_id and u32 indent
 * @return String with the formatted face
 */
u8 *format_hicn_face_ip (u8 * s, va_list * args);

/**
 * @brief Create a dpo from an ip face
 *
 * @param face Face from which to create the dpo
 * @return the dpo
 */
void hicn_face_ip_get_dpo (hicn_face_t * face, dpo_id_t * dpo);

#endif // __HICN_FACE_IP_H__

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */