MCPcopy Create free account
hub / github.com/F-Stack/f-stack / get_random_rules

Function get_random_rules

dpdk/app/test-sad/main.c:235–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233}
234
235static void
236get_random_rules(struct rule *tbl, uint32_t nb_rules, int rule_tbl)
237{
238 unsigned int i, j, rnd;
239 int rule_type;
240 double edge = 0;
241 double step;
242
243 step = (double)UINT32_MAX / nb_rules;
244 for (i = 0; i < nb_rules; i++, edge += step) {
245 rnd = rte_rand() % 100;
246 if (rule_tbl) {
247 tbl[i].tuple.v4.spi = get_rnd_rng((uint64_t)edge,
248 (uint64_t)(edge + step));
249 if (config.ipv6) {
250 for (j = 0; j < 16; j++) {
251 tbl[i].tuple.v6.dip[j] = rte_rand();
252 tbl[i].tuple.v6.sip[j] = rte_rand();
253 }
254 } else {
255 tbl[i].tuple.v4.dip = rte_rand();
256 tbl[i].tuple.v4.sip = rte_rand();
257 }
258 if (rnd >= (100UL - config.fract_32)) {
259 rule_type = RTE_IPSEC_SAD_SPI_ONLY;
260 config.nb_rules_32++;
261 } else if (rnd >= (100UL - (config.fract_32 +
262 config.fract_64))) {
263 rule_type = RTE_IPSEC_SAD_SPI_DIP;
264 config.nb_rules_64++;
265 } else {
266 rule_type = RTE_IPSEC_SAD_SPI_DIP_SIP;
267 config.nb_rules_96++;
268 }
269 tbl[i].rule_type = rule_type;
270 } else {
271 if (rnd >= 100UL - config.fract_rnd_tuples) {
272 tbl[i].tuple.v4.spi =
273 get_rnd_rng((uint64_t)edge,
274 (uint64_t)(edge + step));
275 if (config.ipv6) {
276 for (j = 0; j < 16; j++) {
277 tbl[i].tuple.v6.dip[j] =
278 rte_rand();
279 tbl[i].tuple.v6.sip[j] =
280 rte_rand();
281 }
282 } else {
283 tbl[i].tuple.v4.dip = rte_rand();
284 tbl[i].tuple.v4.sip = rte_rand();
285 }
286 config.nb_tuples_rnd++;
287 } else {
288 tbl[i].tuple.v4.spi = rules_tbl[i %
289 config.nb_rules].tuple.v4.spi;
290 if (config.ipv6) {
291 int r_idx = i % config.nb_rules;
292 memcpy(tbl[i].tuple.v6.dip,

Callers 1

tbl_initFunction · 0.85

Calls 3

rte_randFunction · 0.85
get_rnd_rngFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected