/* * Parse the command line arguments passed to the application. */ int parse_args(int argc, char** argv, app_params* p) { // initialize the environment int ret = rte_eal_init(argc, argv); if (ret < 0) { rte_exit(EXIT_FAILURE, "Failed to initialize EAL: %i\n", ret); } // advance past the environmental settings argc -= ret; argv += ret; // parse arguments to the application ret = parse_app_args(argc, argv, p); if (ret < 0) { rte_exit(EXIT_FAILURE, "\n"); } p->nb_ports = rte_eth_dev_count(); p->nb_rx_workers = p->nb_rx_queue; p->nb_tx_workers = (rte_lcore_count() - 1) - p->nb_rx_workers; // validate the number of workers if(p->nb_tx_workers < p->nb_rx_workers) { rte_exit(EXIT_FAILURE, "Additional lcore(s) required; found=%u, required=%u \n", rte_lcore_count(), (p->nb_rx_queue*2) + 1); } return 0; }
/** * Main init function for the multi-process server app, * calls subfunctions to do each stage of the initialisation. */ int init(int argc, char *argv[]) { int retval; const struct rte_memzone *mz; uint8_t i, total_ports; /* init EAL, parsing EAL args */ retval = rte_eal_init(argc, argv); if (retval < 0) return -1; argc -= retval; argv += retval; /* initialise the nic drivers */ retval = init_drivers(); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot initialise drivers\n"); /* get total number of ports */ total_ports = rte_eth_dev_count(); /* set up array for port data */ mz = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports), rte_socket_id(), NO_FLAGS); if (mz == NULL) rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for port information\n"); memset(mz->addr, 0, sizeof(*ports)); ports = mz->addr; /* parse additional, application arguments */ retval = parse_app_args(total_ports, argc, argv); if (retval != 0) return -1; /* initialise mbuf pools */ retval = init_mbuf_pools(); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n"); /* now initialise the ports we will use */ for (i = 0; i < ports->num_ports; i++) { retval = init_port(ports->id[i]); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot initialise port %u\n", (unsigned)i); } check_all_ports_link_status(ports->num_ports, (~0x0)); /* initialise the client queues/rings for inter-eu comms */ init_shm_rings(); return 0; }
/* * Application main function - loops through * receiving and processing packets. Never returns */ int main(int argc, char *argv[]) { int retval = 0; uint8_t port = 0; char *port_name; if ((retval = rte_eal_init(argc, argv)) < 0) { RTE_LOG(INFO, APP, "EAL init failed.\n"); return -1; } argc -= retval; argv += retval; if (parse_app_args(argc, argv) < 0) rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n"); memset(kni_list, 0, sizeof(struct rte_kni) * MAX_KNI_PORTS); /* Open KNI or exit */ kni_fd = open("/dev/" KNI_DEVICE, O_RDWR); if (kni_fd < 0) { RTE_LOG(ERR, KNI, "Can not open /dev/%s\n", KNI_DEVICE); return -1; } /* Lookup for vports struct */ if (ovs_vport_lookup_vport_info() == NULL) return -1; /* Initialise the devices for each port*/ for (port = 0; port < ports_n; port++) { port_name = port_names[port]; RTE_LOG(INFO, KNI, "Attaching queues for port '%s'\n", port_name); if (create_kni_device(&kni_list[port], port_name, port) < 0) return -1; } RTE_LOG(INFO, KNI, "\nKNI client handling packets \n"); RTE_LOG(INFO, KNI, "[Press Ctrl-C to quit ...]\n"); for (;;) { for (port = 0; port < ports_n; port++) { /* Sleep to reduce processor load. As long as we respond * before rtnetlink times out we will still be able to ifup * and change mtu */ sleep(1); rte_kni_handle_request(&kni_list[port]); } } return 0; }
/** * Main init function for the multi-process server app, * calls subfunctions to do each stage of the initialisation. */ int init(int argc, char *argv[]) { int retval; uint8_t i, total_ports; /* init EAL, parsing EAL args */ retval = rte_eal_init(argc, argv); if (retval < 0) return -1; argc -= retval; argv += retval; /* get total number of ports */ total_ports = 0; /* parse additional, application arguments */ retval = parse_app_args(total_ports, argc, argv); if (retval != 0) return -1; /* initialise mbuf pools */ retval = init_mbuf_pools(); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n"); init_shm_rings(); if (rte_eal_process_type() == RTE_PROC_PRIMARY) { /* create metadata, output cmdline */ if (rte_ivshmem_metadata_create(IVSHMEN_METADATA_NAME) < 0) rte_exit(EXIT_FAILURE, "Cannot create IVSHMEM metadata\n"); if (rte_ivshmem_metadata_add_mempool(pktmbuf_pool, IVSHMEN_METADATA_NAME)) rte_exit(EXIT_FAILURE, "Cannot add mbuf mempool to IVSHMEM metadata\n"); for (i = 0; i < num_rings; i++) { if (rte_ivshmem_metadata_add_ring(clients[i].rx_q, IVSHMEN_METADATA_NAME) < 0) rte_exit(EXIT_FAILURE, "Cannot add ring client %d to IVSHMEM metadata\n", i); } generate_ivshmem_cmdline(IVSHMEN_METADATA_NAME); } return 0; }
/** * Main init function for the multi-process server app, * calls subfunctions to do each stage of the initialisation. */ int init(int argc, char *argv[]) { int retval; uint8_t total_ports = 0; /* init EAL, parsing EAL args */ retval = rte_eal_init(argc, argv); if (retval < 0) return -1; argc -= retval; argv += retval; if (rte_eal_pci_probe()) rte_panic("Cannot probe PCI\n"); /* initialise the nic drivers */ retval = init_drivers(); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot initialise drivers\n"); /* get total number of ports */ total_ports = rte_eth_dev_count(); printf("total_ports = %d\n", total_ports); /* parse additional, application arguments */ retval = parse_app_args(total_ports, argc, argv); if (retval != 0) return -1; /* initialise mbuf pools */ retval = init_mbuf_pools(); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n"); flow_table_init(); datapath_init(); vport_init(); stats_init(); // Added by Y.Born RTE_LOG(INFO, QoS, "QOS system initializing\n"); pktsched_init(); return 0; }
int main(int argc, char *argv[]) { int arg_offset; const char *progname = argv[0]; if ((arg_offset = onvm_nf_init(argc, argv, NF_TAG)) < 0) return -1; argc -= arg_offset; argv += arg_offset; if (parse_app_args(argc, argv, progname) < 0) rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n"); struct rte_mempool *pktmbuf_pool; struct rte_mbuf* pkts[NUM_PKTS]; int i; pktmbuf_pool = rte_mempool_lookup(PKTMBUF_POOL_NAME); if(pktmbuf_pool == NULL) { rte_exit(EXIT_FAILURE, "Cannot find mbuf pool!\n"); } printf("Creating %d packets to send to %d\n", NUM_PKTS, destination); for (i=0; i < NUM_PKTS; i++) { struct onvm_pkt_meta* pmeta; pkts[i] = rte_pktmbuf_alloc(pktmbuf_pool); pmeta = onvm_get_pkt_meta(pkts[i]); pmeta->destination = destination; pmeta->action = ONVM_NF_ACTION_TONF; pkts[i]->port = 3; pkts[i]->hash.rss = i; onvm_nf_return_pkt(pkts[i]); } onvm_nf_run(nf_info, &packet_handler); printf("If we reach here, program is ending"); return 0; }
/** * Main init function for the multi-process server app, * calls subfunctions to do each stage of the initialisation. */ int init(int argc, char *argv[]) { int retval; const struct rte_memzone *mz; unsigned i, total_ports; /* init EAL, parsing EAL args */ retval = rte_eal_init(argc, argv); if (retval < 0) return -1; argc -= retval; argv += retval; /* get total number of ports */ total_ports = rte_eth_dev_count(); /* set up array for port data */ if (rte_eal_process_type() == RTE_PROC_SECONDARY) { mz = rte_memzone_lookup(MZ_PORT_INFO); if (mz == NULL) rte_exit(EXIT_FAILURE, "Cannot get port info structure\n"); ports = mz->addr; } else /* RTE_PROC_PRIMARY */ { mz = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports), rte_socket_id(), NO_FLAGS); if (mz == NULL) rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for port information\n"); memset(mz->addr, 0, sizeof(*ports)); ports = mz->addr; } /* parse additional, application arguments */ retval = parse_app_args(total_ports, argc, argv); if (retval != 0) return -1; /* initialise mbuf pools */ retval = init_mbuf_pools(); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n"); /* now initialise the ports we will use */ if (rte_eal_process_type() == RTE_PROC_PRIMARY) { for (i = 0; i < ports->num_ports; i++) { retval = init_port(ports->id[i]); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot initialise port %u\n", (unsigned)i); } } check_all_ports_link_status(ports->num_ports, (~0x0)); /* initialise the client queues/rings for inter-eu comms */ init_shm_rings(); if (rte_eal_process_type() == RTE_PROC_PRIMARY) { RTE_LOG(INFO, APP, "HOST SHARE MEM Init.\n"); /* create metadata, output cmdline if (rte_hostshmem_metadata_create(HOSTSHMEM_METADATA_NAME) < 0) rte_exit(EXIT_FAILURE, "Cannot create HOSTSHMEM metadata\n"); if (rte_hostshmem_metadata_add_memzone(mz, HOSTSHMEM_METADATA_NAME)) rte_exit(EXIT_FAILURE, "Cannot add memzone to HOSTSHMEM metadata\n"); if (rte_hostshmem_metadata_add_mempool(pktmbuf_pool, HOSTSHMEM_METADATA_NAME)) rte_exit(EXIT_FAILURE, "Cannot add mbuf mempool to HOSTSHMEM metadata\n"); for (i = 0; i < num_clients; i++) { if (rte_hostshmem_metadata_add_ring(clients[i].rx_q, HOSTSHMEM_METADATA_NAME) < 0) rte_exit(EXIT_FAILURE, "Cannot add ring client %d to HOSTSHMEM metadata\n", i); } generate_hostshmem_cmdline(HOSTSHMEM_METADATA_NAME); */ const struct rte_mem_config *mcfg; /* get pointer to global configuration */ mcfg = rte_eal_get_configuration()->mem_config; for (i = 0; i < RTE_MAX_MEMSEG; i++) { if (mcfg->memseg[i].addr == NULL) break; printf("Segment %u: phys:0x%"PRIx64", len:%zu, " "virt:%p, socket_id:%"PRId32", " "hugepage_sz:%"PRIu64", nchannel:%"PRIx32", " "nrank:%"PRIx32"\n", i, mcfg->memseg[i].phys_addr, mcfg->memseg[i].len, mcfg->memseg[i].addr, mcfg->memseg[i].socket_id, mcfg->memseg[i].hugepage_sz, mcfg->memseg[i].nchannel, mcfg->memseg[i].nrank); } RTE_LOG(INFO, APP, "HOST SHARE MEM Init. done\n"); RTE_LOG(INFO, APP, "IV SHARE MEM Init.\n"); /* create metadata, output cmdline */ if (rte_ivshmem_metadata_create(IVSHMEM_METADATA_NAME) < 0) rte_exit(EXIT_FAILURE, "Cannot create IVSHMEM metadata\n"); if (rte_ivshmem_metadata_add_memzone(mz, IVSHMEM_METADATA_NAME)) rte_exit(EXIT_FAILURE, "Cannot add memzone to IVSHMEM metadata\n"); if (rte_ivshmem_metadata_add_mempool(pktmbuf_pool, IVSHMEM_METADATA_NAME)) rte_exit(EXIT_FAILURE, "Cannot add mbuf mempool to IVSHMEM metadata\n"); for (i = 0; i < num_clients; i++) { if (rte_ivshmem_metadata_add_ring(clients[i].rx_q, IVSHMEM_METADATA_NAME) < 0) rte_exit(EXIT_FAILURE, "Cannot add ring client %d to IVSHMEM metadata\n", i); } generate_ivshmem_cmdline(IVSHMEM_METADATA_NAME); RTE_LOG(INFO, APP, "IV SHARE MEM Done.\n"); } return 0; }
/** * Main init function for the multi-process server app, * calls subfunctions to do each stage of the initialisation. */ int init(int argc, char *argv[]) { int retval; const struct rte_memzone *mz; uint8_t i, total_ports; /* init EAL, parsing EAL args */ retval = rte_eal_init(argc, argv); if (retval < 0) return -1; argc -= retval; argv += retval; if (rte_eal_pci_probe()) rte_panic("Cannot probe PCI\n"); /* initialise the nic drivers */ retval = init_drivers(); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot initialise drivers\n"); /* get total number of ports */ total_ports = rte_eth_dev_count(); /* set up array for port data */ mz = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports), rte_socket_id(), NO_FLAGS); if (mz == NULL) rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for port information\n"); memset(mz->addr, 0, sizeof(*ports)); ports = mz->addr; RTE_LOG(INFO, APP, "memzone address is %lx\n", mz->phys_addr); /* set up array for statistics */ mz = rte_memzone_reserve(MZ_STATS_INFO, VPORT_STATS_SIZE, rte_socket_id(), NO_FLAGS); if (mz == NULL) rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for statistics\n"); memset(mz->addr, 0, VPORT_STATS_SIZE); vport_stats = mz->addr; /* set up array for flow table data */ mz = rte_memzone_reserve(MZ_FLOW_TABLE, sizeof(*flow_table), rte_socket_id(), NO_FLAGS); if (mz == NULL) rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for port information\n"); memset(mz->addr, 0, sizeof(*flow_table)); flow_table = mz->addr; /* parse additional, application arguments */ retval = parse_app_args(total_ports, argc, argv); if (retval != 0) return -1; /* initialise mbuf pools */ retval = init_mbuf_pools(); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n"); /* now initialise the ports we will use */ for (i = 0; i < ports->num_ports; i++) { retval = init_port(ports->id[i]); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot initialise port %u\n", (unsigned)i); } /* initialise the client queues/rings for inter process comms */ init_shm_rings(); /* initalise kni queues */ init_kni(); return 0; }
/* * Application main function - loops through * receiving and processing packets. Never returns */ int main(int argc, char *argv[]) { struct rte_ring *rx_ring = NULL; struct rte_ring *tx_ring = NULL; int retval = 0; void *pkts[PKT_READ_SIZE]; int rslt = 0; if ((retval = rte_eal_init(argc, argv)) < 0) { return -1; } argc -= retval; argv += retval; if (parse_app_args(argc, argv) < 0) { rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n"); } rx_ring = rte_ring_lookup(get_rx_queue_name(client_id)); if (rx_ring == NULL) { rte_exit(EXIT_FAILURE, "Cannot get RX ring - is server process running?\n"); } tx_ring = rte_ring_lookup(get_tx_queue_name(client_id)); if (tx_ring == NULL) { rte_exit(EXIT_FAILURE, "Cannot get TX ring - is server process running?\n"); } RTE_LOG(INFO, APP, "Finished Process Init.\n"); printf("\nClient process %d handling packets\n", client_id); printf("[Press Ctrl-C to quit ...]\n"); for (;;) { unsigned rx_pkts = PKT_READ_SIZE; /* Try dequeuing max possible packets first, if that fails, get the * most we can. Loop body should only execute once, maximum. */ while (unlikely(rte_ring_dequeue_bulk(rx_ring, pkts, rx_pkts) != 0) && rx_pkts > 0) { rx_pkts = (uint16_t)RTE_MIN(rte_ring_count(rx_ring), PKT_READ_SIZE); } if (rx_pkts > 0) { pkt++; /* blocking enqueue */ do { rslt = rte_ring_enqueue_bulk(tx_ring, pkts, rx_pkts); } while (rslt == -ENOBUFS); } else { no_pkt++; } if (!(pkt % 100000)) { printf("pkt %d %d\n", pkt, no_pkt); pkt = no_pkt = 0; } } }
/** * Main init function for the multi-process distributor app, * calls subfunctions to do each stage of the initialisation. */ int init(int argc, char *argv[]) { int retval; const struct rte_memzone *mz; uint8_t i, total_ports; /* init EAL, parsing EAL args */ retval = rte_eal_init(argc, argv); if (retval < 0) return -1; argc -= retval; argv += retval; /* get total number of ports */ total_ports = rte_eth_dev_count(); /* set up array for port data */ mz = rte_memzone_reserve(MZ_SHARED_INFO, sizeof(*info), rte_socket_id(), NO_FLAGS); if (mz == NULL) rte_exit(EXIT_FAILURE, "Cannot reserve memory zone " "for port information\n"); memset(mz->addr, 0, sizeof(*info)); info = mz->addr; /* parse additional, application arguments */ retval = parse_app_args(total_ports, argc, argv); if (retval != 0) return -1; /* initialise mbuf pools */ retval = init_mbuf_pools(); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n"); /* now initialise the ports we will use */ for (i = 0; i < info->num_ports; i++) { retval = init_port(info->id[i]); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot initialise port %u\n", (unsigned int) i); } check_all_ports_link_status(info->num_ports, (~0x0)); /* initialise the node queues/rings for inter-eu comms */ init_shm_rings(); /* Create the flow distributor table */ create_flow_distributor_table(); /* Populate the flow distributor table */ populate_flow_distributor_table(); /* Share the total number of nodes */ info->num_nodes = num_nodes; /* Share the total number of flows */ info->num_flows = num_flows; return 0; }
int main(int argc, char *argv[]) { int arg_offset; const char *progname = argv[0]; if ((arg_offset = onvm_nf_init(argc, argv, NF_TAG)) < 0) return -1; argc -= arg_offset; argv += arg_offset; if (parse_app_args(argc, argv, progname) < 0) rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n"); // NIDS // Init ... flag_start = 0; flag_counter = 0; flag_packets = 0; blockNum = 11; threadNum = 1024; batchSize = 983040; pkt_calculate = 0; /* packets = (char *)malloc(batchSize * blockNum * threadNum * MAX_LEN * sizeof(char)); packets_len = (uint16_t *)malloc(batchSize * blockNum * threadNum * sizeof(uint16_t)); memset(packets, 0, batchSize * blockNum * threadNum * MAX_LEN * sizeof(char)); memset(packets_len, 0, batchSize * blockNum * threadNum * sizeof(uint16_t)); packets2 = (char *)malloc(batchSize * blockNum * threadNum * MAX_LEN * sizeof(char)); packets_len2 = (uint16_t *)malloc(batchSize * blockNum * threadNum * sizeof(uint16_t)); memset(packets2, 0, batchSize * blockNum * threadNum * MAX_LEN * sizeof(char)); memset(packets_len2, 0, batchSize * blockNum * threadNum * sizeof(uint16_t)); */ int i = 0; packets = (char **)malloc(PKTS_NUM * sizeof(char *)); for(i = 0; i < PKTS_NUM;i ++) { packets[i] = (char *)malloc(batchSize * MAX_LEN * sizeof(char)); } packets_len = (uint16_t **)malloc(PKTS_NUM * sizeof(uint16_t *)); for(i = 0; i < PKTS_NUM;i ++) { packets_len[i] = (uint16_t *)malloc(batchSize * sizeof(uint16_t)); } char rules_path[20]; // "community.rules"; rules_path[0] = 't'; rules_path[1] = 'r'; rules_path[2] = '\0'; ListRoot *listroot; listroot = configrules((char *)rules_path); precreatearray(listroot); test(listroot); rsr = listroot->TcpListRoot->prmGeneric->rsr; gpuinit(rsr, blockNum, threadNum, batchSize, &acGPU, &pkt_cuda, &pkt_len, &res); // Create matching thread int ret; pthread_t pid; ret = pthread_create(&pid, NULL, (void *)&nids_match, NULL); if(ret != 0) { printf("!!!!!!Error: create pthread error!\n"); return 0; } // Run... onvm_nf_run(nf_info, &packet_handler); printf("If we reach here, program is ending"); clock_gettime(CLOCK_MONOTONIC, &ts2); // printf("stop!!\n"); struct timespec temp = diff(ts1, ts2); //double mpps = (double)(batchSize * ITERATION) / (double)(temp.tv_sec * 1000000 + temp.tv_nsec / 1000); double mpps = (double)(batchSize * pkt_calculate) / (double)(temp.tv_sec * 1000000 + temp.tv_nsec / 1000); double gbps = (mpps * 1000 * 8) / 1000; printf("\n"); printf("BatchSize is %d, batchNum is %d\n", batchSize, pkt_calculate); printf("Throughput is %lf Gbps\n", gbps); // Free... gpufree(0, acGPU, pkt_cuda, pkt_len, res); freeall(listroot); printf("End.\n"); return 0; }
/* * Application main function - loops through * receiving and processing packets. Never returns */ int main(int argc, char *argv[]) { const struct rte_memzone *mz; struct rte_ring *rx_ring; struct rte_mempool *mp; struct port_info *ports; int need_flush = 0; /* indicates whether we have unsent packets */ int retval; void *pkts[PKT_READ_SIZE]; uint16_t sent; if ((retval = rte_eal_init(argc, argv)) < 0) return -1; argc -= retval; argv += retval; if (parse_app_args(argc, argv) < 0) rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n"); if (rte_eth_dev_count() == 0) rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n"); rx_ring = rte_ring_lookup(get_rx_queue_name(client_id)); if (rx_ring == NULL) rte_exit(EXIT_FAILURE, "Cannot get RX ring - is server process running?\n"); mp = rte_mempool_lookup(PKTMBUF_POOL_NAME); if (mp == NULL) rte_exit(EXIT_FAILURE, "Cannot get mempool for mbufs\n"); mz = rte_memzone_lookup(MZ_PORT_INFO); if (mz == NULL) rte_exit(EXIT_FAILURE, "Cannot get port info structure\n"); ports = mz->addr; tx_stats = &(ports->tx_stats[client_id]); configure_output_ports(ports); RTE_LOG(INFO, APP, "Finished Process Init.\n"); printf("\nClient process %d handling packets\n", client_id); printf("[Press Ctrl-C to quit ...]\n"); for (;;) { uint16_t i, rx_pkts = PKT_READ_SIZE; uint8_t port; /* try dequeuing max possible packets first, if that fails, get the * most we can. Loop body should only execute once, maximum */ while (rx_pkts > 0 && unlikely(rte_ring_dequeue_bulk(rx_ring, pkts, rx_pkts) != 0)) rx_pkts = (uint16_t)RTE_MIN(rte_ring_count(rx_ring), PKT_READ_SIZE); if (unlikely(rx_pkts == 0)) { if (need_flush) for (port = 0; port < ports->num_ports; port++) { sent = rte_eth_tx_buffer_flush(ports->id[port], client_id, tx_buffer[port]); if (unlikely(sent)) tx_stats->tx[port] += sent; } need_flush = 0; continue; } for (i = 0; i < rx_pkts; i++) handle_packet(pkts[i]); need_flush = 1; } }
int init(int argc, char *argv[]) { int retval; const struct rte_memzone *mz_nf; const struct rte_memzone *mz_port; const struct rte_memzone *mz_cores; const struct rte_memzone *mz_scp; const struct rte_memzone *mz_services; const struct rte_memzone *mz_nf_per_service; uint8_t i, total_ports, port_id; /* init EAL, parsing EAL args */ retval = rte_eal_init(argc, argv); if (retval < 0) return -1; argc -= retval; argv += retval; #ifdef RTE_LIBRTE_PDUMP rte_pdump_init(NULL); #endif /* get total number of ports */ total_ports = rte_eth_dev_count_avail(); /* set up array for NF tx data */ mz_nf = rte_memzone_reserve(MZ_NF_INFO, sizeof(*nfs) * MAX_NFS, rte_socket_id(), NO_FLAGS); if (mz_nf == NULL) rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for nf information\n"); memset(mz_nf->addr, 0, sizeof(*nfs) * MAX_NFS); nfs = mz_nf->addr; /* set up ports info */ mz_port = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports), rte_socket_id(), NO_FLAGS); if (mz_port == NULL) rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for port information\n"); ports = mz_port->addr; /* set up core status */ mz_cores = rte_memzone_reserve(MZ_CORES_STATUS, sizeof(*cores) * onvm_threading_get_num_cores(), rte_socket_id(), NO_FLAGS); if (mz_cores == NULL) rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for core information\n"); memset(mz_cores->addr, 0, sizeof(*cores) * 64); cores = mz_cores->addr; /* set up array for NF tx data */ mz_services = rte_memzone_reserve(MZ_SERVICES_INFO, sizeof(uint16_t *) * num_services, rte_socket_id(), NO_FLAGS); if (mz_services == NULL) rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for services information\n"); services = mz_services->addr; for (i = 0; i < num_services; i++) { services[i] = rte_calloc("one service NFs", MAX_NFS_PER_SERVICE, sizeof(uint16_t), 0); } mz_nf_per_service = rte_memzone_reserve(MZ_NF_PER_SERVICE_INFO, sizeof(uint16_t) * num_services, rte_socket_id(), NO_FLAGS); if (mz_nf_per_service == NULL) { rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for NF per service information.\n"); } nf_per_service_count = mz_nf_per_service->addr; /* parse additional, application arguments */ retval = parse_app_args(total_ports, argc, argv); if (retval != 0) return -1; /* initialise mbuf pools */ retval = init_mbuf_pools(); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n"); /* initialise nf info pool */ retval = init_nf_info_pool(); if (retval != 0) { rte_exit(EXIT_FAILURE, "Cannot create nf info mbuf pool: %s\n", rte_strerror(rte_errno)); } /* initialise pool for NF messages */ retval = init_nf_msg_pool(); if (retval != 0) { rte_exit(EXIT_FAILURE, "Cannot create nf message pool: %s\n", rte_strerror(rte_errno)); } /* now initialise the ports we will use */ for (i = 0; i < ports->num_ports; i++) { port_id = ports->id[i]; rte_eth_macaddr_get(port_id, &ports->mac[port_id]); retval = init_port(port_id); if (retval != 0) rte_exit(EXIT_FAILURE, "Cannot initialise port %u\n", port_id); char event_msg_buf[20]; sprintf(event_msg_buf, "Port %d initialized", port_id); onvm_stats_add_event(event_msg_buf, NULL); } check_all_ports_link_status(ports->num_ports, (~0x0)); /* initialise the NF queues/rings for inter-eu comms */ init_shm_rings(); /* initialise a queue for newly created NFs */ init_info_queue(); /*initialize a default service chain*/ default_chain = onvm_sc_create(); retval = onvm_sc_append_entry(default_chain, ONVM_NF_ACTION_TONF, 1); if (retval == ENOSPC) { printf("chain length can not be larger than the maximum chain length\n"); exit(1); } printf("Default service chain: send to sdn NF\n"); /* set up service chain pointer shared to NFs*/ mz_scp = rte_memzone_reserve(MZ_SCP_INFO, sizeof(struct onvm_service_chain *), rte_socket_id(), NO_FLAGS); if (mz_scp == NULL) rte_exit(EXIT_FAILURE, "Canot reserve memory zone for service chain pointer\n"); memset(mz_scp->addr, 0, sizeof(struct onvm_service_chain *)); default_sc_p = mz_scp->addr; *default_sc_p = default_chain; onvm_sc_print(default_chain); onvm_flow_dir_init(); return 0; }