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
|
/*
* Copyright (c) 2017-2020 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.
*/
#include <vnet/vnet.h>
#include <vnet/plugin/plugin.h>
#include <vlib/vlib.h>
#include "hicn.h"
#include "params.h"
#include "infra.h"
#include "strategy_dpo_manager.h"
#include "mgmt.h"
#include "error.h"
#include "faces/app/address_mgr.h"
#include "face_db.h"
#include "udp_tunnels/udp_tunnel.h"
#include "route.h"
hicn_main_t hicn_main;
/* Module vars */
int hicn_infra_fwdr_initialized = 0;
/*
* Global time counters we're trying out for opportunistic hashtable
* expiration.
*/
uint16_t hicn_infra_fast_timer; /* Counts at 1 second intervals */
uint16_t hicn_infra_slow_timer; /* Counts at 1 minute intervals */
hicn_face_bucket_t *hicn_face_bucket_pool;
/*
* Init hicn forwarder with configurable PIT, CS sizes
*/
static int
hicn_infra_fwdr_init (uint32_t shard_pit_size, uint32_t shard_cs_size)
{
int ret = 0;
if (hicn_infra_fwdr_initialized)
{
ret = HICN_ERROR_FWD_ALREADY_ENABLED;
goto done;
}
/* Init per worker limits */
hicn_infra_pit_size = shard_pit_size;
hicn_infra_cs_size = shard_cs_size;
/* Init the global time-compression counters */
hicn_infra_fast_timer = 1;
hicn_infra_slow_timer = 1;
ret = hicn_pit_create (&hicn_main.pitcs, hicn_infra_pit_size);
hicn_pit_set_lru_max (&hicn_main.pitcs, hicn_infra_cs_size);
done:
if ((ret == HICN_ERROR_NONE) && !hicn_infra_fwdr_initialized)
{
hicn_infra_fwdr_initialized = 1;
}
return (ret);
}
/*
* Action function shared between message handler and debug CLI NOTICE: we're
* only 'enabling' now
*/
int
hicn_infra_plugin_enable_disable (int enable_disable,
int pit_size_req,
f64 pit_max_lifetime_sec_req,
int cs_size_req)
{
int ret = 0;
hicn_main_t *sm = &hicn_main;
uint32_t pit_size, cs_size;
/* Notice if we're already enabled... */
if (sm->is_enabled)
{
ret = HICN_ERROR_FWD_ALREADY_ENABLED;
goto done;
}
/* Set up params and call fwdr_init set up PIT/CS, forwarder nodes */
/* Check the range and assign some globals */
if (pit_max_lifetime_sec_req < 0)
{
sm->pit_lifetime_max_ms = HICN_PARAM_PIT_LIFETIME_DFLT_MAX_MS;
}
else
{
if (pit_max_lifetime_sec_req < HICN_PARAM_PIT_LIFETIME_BOUND_MIN_SEC ||
pit_max_lifetime_sec_req > HICN_PARAM_PIT_LIFETIME_BOUND_MAX_SEC)
{
ret = HICN_ERROR_PIT_CONFIG_MAXLT_OOB;
goto done;
}
sm->pit_lifetime_max_ms = pit_max_lifetime_sec_req * SEC_MS;
}
if (pit_size_req < 0)
{
pit_size = HICN_PARAM_PIT_ENTRIES_DFLT;
}
else
{
if (pit_size_req < HICN_PARAM_PIT_ENTRIES_MIN ||
pit_size_req > HICN_PARAM_PIT_ENTRIES_MAX)
{
ret = HICN_ERROR_PIT_CONFIG_SIZE_OOB;
goto done;
}
pit_size = (uint32_t) pit_size_req;
}
if (cs_size_req < 0)
{
cs_size = HICN_PARAM_CS_ENTRIES_DFLT;
}
else
{
/*
* This should be relatively safe
* At this point vlib buffers should have been already allocated
*/
vlib_buffer_main_t *bm;
vlib_buffer_pool_t *bp;
vlib_main_t *vm = vlib_get_main ();
bm = vm->buffer_main;
u32 n_buffers = 0;
vec_foreach (bp, bm->buffer_pools)
n_buffers = n_buffers < bp->n_buffers ? bp->n_buffers : n_buffers;
// check if CS is bugger tha PIT or bigger than the available vlib_buffers
uword cs_buffers =
(n_buffers >
HICN_PARAM_CS_MIN_MBUF) ? n_buffers - HICN_PARAM_CS_MIN_MBUF : 0;
if (cs_size_req > (pit_size_req / 2) || cs_size_req > cs_buffers)
{
cs_size_req =
((pit_size_req / 2) > cs_buffers) ? cs_buffers : pit_size_req / 2;
vlib_cli_output (vm,
"WARNING!! CS too large. Please check size of PIT or the number of buffers available in VPP\n");
}
cs_size = (uint32_t) cs_size_req;
}
ret = hicn_infra_fwdr_init (pit_size, cs_size);
hicn_face_db_init (pit_size);
if (ret != HICN_ERROR_NONE)
{
goto done;
}
sm->is_enabled = 1;
//hicn_face_udp_init_internal ();
done:
return (ret);
}
static clib_error_t *
hicn_configure (vlib_main_t * vm, unformat_input_t * input)
{
u32 pit_size = HICN_PARAM_PIT_ENTRIES_DFLT;
u32 cs_size = HICN_PARAM_CS_ENTRIES_DFLT;
u64 pit_lifetime_max_sec = HICN_PARAM_PIT_LIFETIME_DFLT_MAX_MS / SEC_MS;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (input, "pit-size %u", &pit_size))
;
else if (unformat (input, "cs-size %u", &cs_size))
;
else if (unformat (input, "pit-lifetime-max %u", &pit_lifetime_max_sec))
;
else
break;
}
unformat_free (input);
hicn_infra_plugin_enable_disable (1, pit_size,
pit_lifetime_max_sec,
cs_size);
return 0;
}
VLIB_CONFIG_FUNCTION (hicn_configure, "hicn");
/*
* Init entry-point for the icn plugin
*/
static clib_error_t *
hicn_init (vlib_main_t * vm)
{
clib_error_t *error = 0;
hicn_main_t *sm = &hicn_main;
/* Init other elements in the 'main' struct */
sm->is_enabled = 0;
error = hicn_api_plugin_hookup (vm);
/* Init the dpo module */
hicn_dpos_init ();
/* Init the app manager */
address_mgr_init ();
hicn_face_module_init (vm);
/* Init the route module */
hicn_route_init ();
udp_tunnel_init ();
return error;
}
VLIB_INIT_FUNCTION (hicn_init);
/* *INDENT-OFF* */
VLIB_PLUGIN_REGISTER() =
{
.description = "hICN forwarder"
};
/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables: eval: (c-set-style "gnu") End:
*/
|