const ip_addr_t *LWIP::get_ip_addr(bool any_addr, const struct netif *netif) { const ip_addr_t *pref_ip_addr = 0; const ip_addr_t *npref_ip_addr = 0; #if LWIP_IPV4 && LWIP_IPV6 #if IP_VERSION_PREF == PREF_IPV4 pref_ip_addr = get_ipv4_addr(netif); npref_ip_addr = get_ipv6_addr(netif); #else pref_ip_addr = get_ipv6_addr(netif); npref_ip_addr = get_ipv4_addr(netif); #endif #elif LWIP_IPV6 pref_ip_addr = get_ipv6_addr(netif); #elif LWIP_IPV4 pref_ip_addr = get_ipv4_addr(netif); #endif if (pref_ip_addr) { return pref_ip_addr; } else if (npref_ip_addr && any_addr) { return npref_ip_addr; } return NULL; }
void prepare_and_bench_polling(void) { auto& ctx = uhd::transport::uhd_dpdk_ctx::get(); uhd::transport::dpdk_zero_copy::sptr eth_data[NUM_PORTS]; uhd::transport::zero_copy_xport_params buff_args; buff_args.recv_frame_size = 8000; buff_args.send_frame_size = 8000; buff_args.num_send_frames = 8; buff_args.num_recv_frames = 8; auto dev_addr = uhd::device_addr_t(); eth_data[0] = uhd::transport::dpdk_zero_copy::make( ctx, 0, get_ipv4_addr(1), "48888", "48888", buff_args, dev_addr ); eth_data[1] = uhd::transport::dpdk_zero_copy::make( ctx, 1, get_ipv4_addr(0), "48888", "48888", buff_args, dev_addr ); bench(eth_data, NUM_PORTS, 0.0); }
/* print all networks present between address <low> and address <high> in * cidr format, followed by <eol>. */ static void convert_range(unsigned int low, unsigned int high, const char *eol) { int bit; if (low == high) { /* single value */ printf("%s%s\n", get_ipv4_addr(low), eol); return; } else if (low > high) { int swap = low; low = high; high = swap; } if (low == high + 1) { /* full range */ printf("0.0.0.0/0%s\n", eol); return; } //printf("low=%08x high=%08x\n", low, high); bit = 0; while (bit < 32 && low + (1 << bit) - 1 <= high) { /* enlarge mask */ if (low & (1 << bit)) { /* can't aggregate anymore, dump and retry from the same bit */ printf("%s/%d%s\n", get_ipv4_addr(low), 32-bit, eol); low += (1 << bit); } else { /* try to enlarge the mask as much as possible first */ bit++; //printf(" ++bit=%d\n", bit); } } //printf("stopped 1 at low=%08x, bit=%d\n", low, bit); bit = 31; while (bit >= 0 && high - low + 1 != 0) { /* shrink mask */ if ((high - low + 1) & (1 << bit)) { /* large bit accepted, dump and go on from the same bit */ //printf("max: %08x/%d\n", low, 32-bit); printf("%s/%d%s\n", get_ipv4_addr(low), 32-bit, eol); low += (1 << bit); } else { bit--; //printf(" --bit=%d, low=%08x\n", bit, low); } } //printf("stopped at low=%08x\n", low); }
void liblustre_init_random() { int seed[2]; struct timeval tv; #ifdef LIBLUSTRE_USE_URANDOM int _rand_dev_fd; _rand_dev_fd = syscall(SYS_open, "/dev/urandom", O_RDONLY); if (_rand_dev_fd >= 0) { if (syscall(SYS_read, _rand_dev_fd, &seed, sizeof(seed)) == sizeof(seed)) { cfs_srand(seed[0], seed[1]); syscall(SYS_close, _rand_dev_fd); return; } syscall(SYS_close, _rand_dev_fd); } #endif /* LIBLUSTRE_USE_URANDOM */ #ifdef HAVE_GETHOSTBYNAME seed[0] = get_ipv4_addr(); #else seed[0] = _my_pnid; #endif gettimeofday(&tv, NULL); cfs_srand(tv.tv_sec ^ __swab32(seed[0]), tv.tv_usec ^__swab32(getpid())); }
int rpc_init(unsigned short port) { char *s = getenv("CACHE_IPV4_ADDRESS"); debugf("rpc_init() entered\n"); ctable_init(); stable_init(); if (s != NULL) { strcpy(my_address, s); } else { get_ipv4_addr(my_address); } return common_init(port); }
void LWIP::add_dns_addr(struct netif *lwip_netif) { // Check for existing dns address for (char numdns = 0; numdns < DNS_MAX_SERVERS; numdns++) { const ip_addr_t *dns_ip_addr = dns_getserver(numdns); if (!ip_addr_isany(dns_ip_addr)) { return; } } // Get preferred ip version const ip_addr_t *ip_addr = get_ip_addr(false, lwip_netif); u8_t addr_type = IPADDR_TYPE_ANY; // Add preferred ip version dns address to index 0 if (ip_addr) { addr_type = get_ip_addr_type(ip_addr); add_dns_addr_to_dns_list_index(addr_type, 0); } #if LWIP_IPV4 && LWIP_IPV6 if (!ip_addr) { // Get address for any ip version ip_addr = get_ip_addr(true, lwip_netif); if (!ip_addr) { return; } addr_type = get_ip_addr_type(ip_addr); // Add the dns address to index 0 add_dns_addr_to_dns_list_index(addr_type, 0); } if (addr_type == IPADDR_TYPE_V4) { // If ipv4 is preferred and ipv6 is available add ipv6 dns address to index 1 ip_addr = get_ipv6_addr(lwip_netif); } else if (addr_type == IPADDR_TYPE_V6) { // If ipv6 is preferred and ipv4 is available add ipv4 dns address to index 1 ip_addr = get_ipv4_addr(lwip_netif); } else { ip_addr = NULL; } if (ip_addr) { addr_type = get_ip_addr_type(ip_addr); add_dns_addr_to_dns_list_index(addr_type, 1); } #endif }
char* get_ip(void) { return get_ipv4_addr("eth0"); }
int main(int argc, char **argv) { int retval, user0_cpu = 0, user1_cpu = 2; int status = 0; std::string args; std::string cpusets; po::options_description desc("Allowed options"); desc.add_options() ("help", "help message") ("args", po::value<std::string>(&args)->default_value(""), "UHD-DPDK args") ("polling-mode", "Use polling mode (single thread on own core)") ("cpusets", po::value<std::string>(&cpusets)->default_value(""), "which core(s) to use for a given thread in blocking mode (specify something like \"user0=0,user1=2\")") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help")) { std::cout << desc << std::endl; return 0; } auto dpdk_args = uhd::device_addr_t(args); auto cpuset_map = uhd::device_addr_t(cpusets); for (std::string& key : cpuset_map.keys()) { if (key == "user0") { user0_cpu = std::stoi(cpuset_map[key], NULL, 0); } else if (key == "user1") { user1_cpu = std::stoi(cpuset_map[key], NULL, 0); } } auto& ctx = uhd::transport::uhd_dpdk_ctx::get(); ctx.init(args); if (vm.count("polling-mode")) { prepare_and_bench_polling(); } else { pthread_cond_t cond; pthread_cond_init(&cond, NULL); struct dpdk_test_args bench_args[2]; pthread_mutex_init(&bench_args[0].mutex, NULL); pthread_mutex_init(&bench_args[1].mutex, NULL); bench_args[0].cpu = user0_cpu; bench_args[0].cond = &cond; bench_args[0].dst_ip = get_ipv4_addr(1); bench_args[0].started = false; bench_args[0].portid = 0; bench_args[1].cpu = user1_cpu; bench_args[1].cond = &cond; bench_args[1].dst_ip = get_ipv4_addr(0); bench_args[1].started = false; bench_args[1].portid = 1; pthread_t threads[2]; pthread_create(&threads[0], NULL, prepare_and_bench_blocking, &bench_args[0]); pthread_create(&threads[1], NULL, prepare_and_bench_blocking, &bench_args[1]); do { pthread_mutex_lock(&bench_args[0].mutex); if (bench_args[0].started) break; pthread_mutex_unlock(&bench_args[0].mutex); } while (true); pthread_mutex_unlock(&bench_args[0].mutex); do { pthread_mutex_lock(&bench_args[1].mutex); if (bench_args[1].started) break; pthread_mutex_unlock(&bench_args[1].mutex); } while (true); pthread_mutex_unlock(&bench_args[1].mutex); pthread_cond_broadcast(&cond); status = pthread_join(threads[0], (void **) &retval); if (status) { perror("Error while joining thread"); return status; } status = pthread_join(threads[1], (void **) &retval); if (status) { perror("Error while joining thread"); return status; } } return status; }