int main(int argc, char *argv[]) { struct sigaction signal_action; struct rlimit rlimit; uint32_t pkts_into_tm, pkts_from_tm; odp_instance_t instance; int rc; memset(&signal_action, 0, sizeof(signal_action)); signal_action.sa_handler = signal_handler; sigfillset(&signal_action.sa_mask); sigaction(SIGILL, &signal_action, NULL); sigaction(SIGFPE, &signal_action, NULL); sigaction(SIGSEGV, &signal_action, NULL); sigaction(SIGTERM, &signal_action, NULL); sigaction(SIGBUS, &signal_action, NULL); getrlimit(RLIMIT_CORE, &rlimit); rlimit.rlim_cur = rlimit.rlim_max; setrlimit(RLIMIT_CORE, &rlimit); rc = odp_init_global(&instance, &ODP_INIT_PARAMS, NULL); if (rc != 0) { printf("Error: odp_init_global() failed, rc = %d\n", rc); abort(); } rc = odp_init_local(instance, ODP_THREAD_CONTROL); if (rc != 0) { printf("Error: odp_init_local() failed, rc = %d\n", rc); abort(); } if (process_cmd_line_options(argc, argv) < 0) return -1; create_and_config_tm(); odp_random_data(random_buf, RANDOM_BUF_LEN, 1); next_rand_byte = 0; odp_atomic_init_u32(&atomic_pkts_into_tm, 0); odp_atomic_init_u32(&atomic_pkts_from_tm, 0); traffic_generator(g_num_pkts_to_send); pkts_into_tm = odp_atomic_load_u32(&atomic_pkts_into_tm); pkts_from_tm = odp_atomic_load_u32(&atomic_pkts_from_tm); printf("pkts_into_tm=%u pkts_from_tm=%u\n", pkts_into_tm, pkts_from_tm); odp_tm_stats_print(odp_tm_test); return 0; }
static uint32_t random_16(void) { uint8_t byte1, byte2; if ((RANDOM_BUF_LEN - 1) <= next_rand_byte) { odp_random_data(random_buf, RANDOM_BUF_LEN, 1); next_rand_byte = 0; } byte1 = random_buf[next_rand_byte++]; byte2 = random_buf[next_rand_byte++]; return (((uint16_t)byte1) << 8) | ((uint16_t)byte2); }
static uint32_t timer_get_skiplist_level(unsigned curr_depth) { uint32_t rand; odp_random_data((uint8_t *)&rand, sizeof(int32_t), 0); rand = rand & (UINT32_MAX - 1); uint32_t level = rand == 0 ? MAX_SKIPLIST_DEPTH : (odp_bsf32(rand) - 1) / 2; if (level > curr_depth) level = curr_depth; if (level >= MAX_SKIPLIST_DEPTH) level = MAX_SKIPLIST_DEPTH - 1; return level; }
int create_ipsec_cache_entry(sa_db_entry_t *cipher_sa, sa_db_entry_t *auth_sa, tun_db_entry_t *tun, crypto_api_mode_e api_mode, odp_bool_t in, odp_queue_t completionq, odp_pool_t out_pool) { odp_crypto_session_params_t params; ipsec_cache_entry_t *entry; odp_crypto_ses_create_err_t ses_create_rc; odp_crypto_session_t session; sa_mode_t mode = IPSEC_SA_MODE_TRANSPORT; /* Verify we have a good entry */ entry = &ipsec_cache->array[ipsec_cache->index]; if (MAX_DB <= ipsec_cache->index) return -1; /* Verify SA mode match in case of cipher&auth */ if (cipher_sa && auth_sa && (cipher_sa->mode != auth_sa->mode)) return -1; /* Setup parameters and call crypto library to create session */ params.op = (in) ? ODP_CRYPTO_OP_DECODE : ODP_CRYPTO_OP_ENCODE; params.auth_cipher_text = TRUE; if (CRYPTO_API_SYNC == api_mode) { params.pref_mode = ODP_CRYPTO_SYNC; params.compl_queue = ODP_QUEUE_INVALID; params.output_pool = ODP_POOL_INVALID; } else { params.pref_mode = ODP_CRYPTO_ASYNC; params.compl_queue = completionq; params.output_pool = out_pool; } if (CRYPTO_API_ASYNC_NEW_BUFFER == api_mode) entry->in_place = FALSE; else entry->in_place = TRUE; /* Cipher */ if (cipher_sa) { params.cipher_alg = cipher_sa->alg.u.cipher; params.cipher_key.data = cipher_sa->key.data; params.cipher_key.length = cipher_sa->key.length; params.iv.data = entry->state.iv; params.iv.length = cipher_sa->iv_len; mode = cipher_sa->mode; } else { params.cipher_alg = ODP_CIPHER_ALG_NULL; params.iv.data = NULL; params.iv.length = 0; } /* Auth */ if (auth_sa) { params.auth_alg = auth_sa->alg.u.auth; params.auth_key.data = auth_sa->key.data; params.auth_key.length = auth_sa->key.length; mode = auth_sa->mode; } else { params.auth_alg = ODP_AUTH_ALG_NULL; } /* Generate an IV */ if (params.iv.length) { int32_t size = params.iv.length; int32_t ret = odp_random_data(params.iv.data, size, 1); if (ret != size) return -1; } /* Synchronous session create for now */ if (odp_crypto_session_create(¶ms, &session, &ses_create_rc)) return -1; if (ODP_CRYPTO_SES_CREATE_ERR_NONE != ses_create_rc) return -1; /* Copy remainder */ if (cipher_sa) { entry->src_ip = cipher_sa->src_ip; entry->dst_ip = cipher_sa->dst_ip; entry->esp.alg = cipher_sa->alg.u.cipher; entry->esp.spi = cipher_sa->spi; entry->esp.block_len = cipher_sa->block_len; entry->esp.iv_len = cipher_sa->iv_len; memcpy(&entry->esp.key, &cipher_sa->key, sizeof(ipsec_key_t)); } if (auth_sa) { entry->src_ip = auth_sa->src_ip; entry->dst_ip = auth_sa->dst_ip; entry->ah.alg = auth_sa->alg.u.auth; entry->ah.spi = auth_sa->spi; entry->ah.icv_len = auth_sa->icv_len; memcpy(&entry->ah.key, &auth_sa->key, sizeof(ipsec_key_t)); } if (tun) { entry->tun_src_ip = tun->tun_src_ip; entry->tun_dst_ip = tun->tun_dst_ip; mode = IPSEC_SA_MODE_TUNNEL; int ret; if (!in) { /* init tun hdr id */ ret = odp_random_data((uint8_t *) &entry->state.tun_hdr_id, sizeof(entry->state.tun_hdr_id), 1); if (ret != sizeof(entry->state.tun_hdr_id)) return -1; } } entry->mode = mode; /* Initialize state */ entry->state.esp_seq = 0; entry->state.ah_seq = 0; entry->state.session = session; /* Add entry to the appropriate list */ ipsec_cache->index++; if (in) { entry->next = ipsec_cache->in_list; ipsec_cache->in_list = entry; } else { entry->next = ipsec_cache->out_list; ipsec_cache->out_list = entry; } return 0; }