void pktgen_cls(void) { if ( scrn_is_paused() ) { scrn_cls(); scrn_pos(100, 1); } else // Update the display quickly. pktgen_redisplay(1); }
void pktgen_set_port_number(uint32_t port_number) { if ( port_number <= pktgen.nb_ports ) { pktgen.portNum = port_number; pktgen_redisplay(1); } }
void pktgen_set_page_size(uint32_t page_size) { if ( (page_size > 0) && (page_size <= pktgen.nb_ports) && (page_size <= 6) ) { pktgen.nb_ports_per_page = page_size; pktgen.ending_port = pktgen.starting_port + page_size; if ( pktgen.ending_port >= (pktgen.starting_port + pktgen.nb_ports) ) pktgen.ending_port = (pktgen.starting_port + pktgen.nb_ports); pktgen_redisplay(1); } }
void pktgen_screen(const char * onOff) { if ( parseState(onOff) == DISABLE_STATE ) { if ( !scrn_is_paused() ) { scrn_pause(); scrn_cls(); scrn_setw(1); scrn_pos(scrn->nrows, 1); } } else { scrn_cls(); scrn_pos(scrn->nrows,1); scrn_setw(pktgen.last_row+1); scrn_resume(); pktgen_redisplay(1); } }
int main(int argc, char **argv) { uint32_t i; int32_t ret; printf("\n%s %s\n", wr_copyright_msg(), wr_powered_by()); fflush(stdout); wr_scrn_setw(1);/* Reset the window size */ /* call before the rte_eal_init() */ (void)rte_set_application_usage_hook(pktgen_usage); memset(&pktgen, 0, sizeof(pktgen)); pktgen.flags = PRINT_LABELS_FLAG; pktgen.ident = 0x1234; pktgen.nb_rxd = DEFAULT_RX_DESC; pktgen.nb_txd = DEFAULT_TX_DESC; pktgen.nb_ports_per_page = DEFAULT_PORTS_PER_PAGE; if ( (pktgen.l2p = wr_l2p_create()) == NULL) pktgen_log_panic("Unable to create l2p"); pktgen.portdesc_cnt = wr_get_portdesc(pktgen.portlist, pktgen.portdesc, RTE_MAX_ETHPORTS, 0); /* Initialize the screen and logging */ pktgen_init_log(); pktgen_cpu_init(); /* initialize EAL */ ret = rte_eal_init(argc, argv); if (ret < 0) return -1; argc -= ret; argv += ret; pktgen.hz = rte_get_timer_hz(); /* Get the starting HZ value. */ /* parse application arguments (after the EAL ones) */ ret = pktgen_parse_args(argc, argv); if (ret < 0) return -1; pktgen_init_screen((pktgen.flags & ENABLE_THEME_FLAG) ? THEME_ON : THEME_OFF); rte_delay_ms(100); /* Wait a bit for things to settle. */ wr_print_copyright(PKTGEN_APP_NAME, PKTGEN_CREATED_BY); lua_newlib_add(_lua_openlib); /* Open the Lua script handler. */ if ( (pktgen.L = lua_create_instance()) == NULL) { pktgen_log_error("Failed to open Lua pktgen support library"); return -1; } pktgen_log_info(">>> Packet Burst %d, RX Desc %d, TX Desc %d, mbufs/port %d, mbuf cache %d", DEFAULT_PKT_BURST, DEFAULT_RX_DESC, DEFAULT_TX_DESC, MAX_MBUFS_PER_PORT, MBUF_CACHE_SIZE); /* Configure and initialize the ports */ pktgen_config_ports(); pktgen_log_info(""); pktgen_log_info("=== Display processing on lcore %d", rte_lcore_id()); /* launch per-lcore init on every lcore except master and master + 1 lcores */ for (i = 0; i < RTE_MAX_LCORE; i++) { if ( (i == rte_get_master_lcore()) || !rte_lcore_is_enabled(i) ) continue; ret = rte_eal_remote_launch(pktgen_launch_one_lcore, NULL, i); if (ret != 0) pktgen_log_error("Failed to start lcore %d, return %d", i, ret); } rte_delay_ms(1000); /* Wait for the lcores to start up. */ /* Disable printing log messages of level info and below to screen, */ /* erase the screen and start updating the screen again. */ pktgen_log_set_screen_level(LOG_LEVEL_WARNING); wr_scrn_erase(pktgen.scrn->nrows); wr_logo(3, 16, PKTGEN_APP_NAME); wr_splash_screen(3, 16, PKTGEN_APP_NAME, PKTGEN_CREATED_BY); wr_scrn_resume(); pktgen_redisplay(1); rte_timer_setup(); if (pktgen.flags & ENABLE_GUI_FLAG) { if (!wr_scrn_is_paused() ) { wr_scrn_pause(); wr_scrn_cls(); wr_scrn_setw(1); wr_scrn_pos(pktgen.scrn->nrows, 1); } lua_init_socket(pktgen.L, &pktgen.thread, pktgen.hostname, pktgen.socket_port); } pktgen_cmdline_start(); execute_lua_close(pktgen.L); pktgen_stop_running(); wr_scrn_pause(); wr_scrn_setw(1); wr_scrn_printf(100, 1, "\n"); /* Put the cursor on the last row and do a newline. */ /* Wait for all of the cores to stop running and exit. */ rte_eal_mp_wait_lcore(); return 0; }
void pktgen_process_arp( struct rte_mbuf * m, uint32_t pid, uint32_t vlan ) { port_info_t * info = &pktgen.info[pid]; pkt_seq_t * pkt; struct ether_hdr *eth = rte_pktmbuf_mtod(m, struct ether_hdr *); arpPkt_t * arp = (arpPkt_t *)ð[1]; /* Adjust for a vlan header if present */ if ( vlan ) arp = (arpPkt_t *)((char *)arp + sizeof(struct vlan_hdr)); // Process all ARP requests if they are for us. if ( arp->op == htons(ARP_REQUEST) ) { if ((rte_atomic32_read(&info->port_flags) & PROCESS_GARP_PKTS) && (arp->tpa._32 == arp->spa._32) ) { /* Must be a GARP packet */ pkt = pktgen_find_matching_ipdst(info, arp->spa._32); /* Found a matching packet, replace the dst address */ if ( pkt ) { rte_memcpy(&pkt->eth_dst_addr, &arp->sha, 6); pktgen_set_q_flags(info, wr_get_txque(pktgen.l2p, rte_lcore_id(), pid), DO_TX_CLEANUP); pktgen_redisplay(0); } return; } pkt = pktgen_find_matching_ipsrc(info, arp->tpa._32); /* ARP request not for this interface. */ if ( likely(pkt != NULL) ) { /* Grab the source MAC address as the destination address for the port. */ if ( unlikely(pktgen.flags & MAC_FROM_ARP_FLAG) ) { uint32_t i; rte_memcpy(&pkt->eth_dst_addr, &arp->sha, 6); for (i = 0; i < info->seqCnt; i++) pktgen_packet_ctor(info, i, -1); } // Swap the two MAC addresses ethAddrSwap(&arp->sha, &arp->tha); // Swap the two IP addresses inetAddrSwap(&arp->tpa._32, &arp->spa._32); // Set the packet to ARP reply arp->op = htons(ARP_REPLY); // Swap the MAC addresses ethAddrSwap(ð->d_addr, ð->s_addr); // Copy in the MAC address for the reply. rte_memcpy(&arp->sha, &pkt->eth_src_addr, 6); rte_memcpy(ð->s_addr, &pkt->eth_src_addr, 6); pktgen_send_mbuf(m, pid, 0); // Flush all of the packets in the queue. pktgen_set_q_flags(info, 0, DO_TX_FLUSH); // No need to free mbuf as it was reused return; } } else if ( arp->op == htons(ARP_REPLY) ) { pkt = pktgen_find_matching_ipsrc(info, arp->tpa._32); // ARP request not for this interface. if ( likely(pkt != NULL) ) { // Grab the real destination MAC address if ( pkt->ip_dst_addr == ntohl(arp->spa._32) ) rte_memcpy(&pkt->eth_dst_addr, &arp->sha, 6); pktgen.flags |= PRINT_LABELS_FLAG; } } }
void pktgen_update_display(void) { pktgen_redisplay(0); }
void pktgen_set_page( char * str ) { uint16_t page; if ( str == NULL ) return; page = atoi(str); if ( page > pktgen.nb_ports ) return; // Switch to the correct page if ( str[0] == 'n' ) { pcap_info_t * pcap = pktgen.info[pktgen.portNum].pcap; if ( pcap ) { if ( (pcap->pkt_idx + PCAP_PAGE_SIZE) < pcap->pkt_count ) pcap->pkt_idx += PCAP_PAGE_SIZE; else pcap->pkt_idx = 0; } pktgen.flags |= PRINT_LABELS_FLAG; } else if ( (str[0] == 'c') && (str[1] == 'p') ) { pktgen.flags &= ~SEQUENCE_PAGE_FLAG; pktgen.flags &= ~CONFIG_PAGE_FLAG; pktgen.flags &= ~RANGE_PAGE_FLAG; pktgen.flags &= ~PCAP_PAGE_FLAG; pktgen.flags |= CPU_PAGE_FLAG; } else if ( str[0] == 'p' ) { pktgen.flags &= ~SEQUENCE_PAGE_FLAG; pktgen.flags &= ~CONFIG_PAGE_FLAG; pktgen.flags &= ~RANGE_PAGE_FLAG; pktgen.flags &= ~CPU_PAGE_FLAG; pktgen.flags |= PCAP_PAGE_FLAG; if ( pktgen.info[pktgen.portNum].pcap ) pktgen.info[pktgen.portNum].pcap->pkt_idx = 0; } else if ( str[0] == 'r' ) { pktgen.flags &= ~SEQUENCE_PAGE_FLAG; pktgen.flags &= ~CONFIG_PAGE_FLAG; pktgen.flags &= ~PCAP_PAGE_FLAG; pktgen.flags &= ~CPU_PAGE_FLAG; pktgen.flags |= RANGE_PAGE_FLAG; } else if ( str[0] == 'c' ) { pktgen.flags &= ~SEQUENCE_PAGE_FLAG; pktgen.flags &= ~RANGE_PAGE_FLAG; pktgen.flags &= ~PCAP_PAGE_FLAG; pktgen.flags &= ~CPU_PAGE_FLAG; pktgen.flags |= CONFIG_PAGE_FLAG; } else if ( str[0] == 's' ) { pktgen.flags &= ~CONFIG_PAGE_FLAG; pktgen.flags &= ~RANGE_PAGE_FLAG; pktgen.flags &= ~PCAP_PAGE_FLAG; pktgen.flags &= ~CPU_PAGE_FLAG; pktgen.flags |= SEQUENCE_PAGE_FLAG; } else { uint16_t start_port = (page * pktgen.nb_ports_per_page); if ( (pktgen.starting_port != start_port) && (start_port < pktgen.nb_ports) ) { pktgen.starting_port = start_port; pktgen.ending_port = start_port + pktgen.nb_ports_per_page; if ( pktgen.ending_port > (pktgen.starting_port + pktgen.nb_ports) ) pktgen.ending_port = (pktgen.starting_port + pktgen.nb_ports); } if ( pktgen.flags & (CONFIG_PAGE_FLAG | SEQUENCE_PAGE_FLAG | RANGE_PAGE_FLAG | PCAP_PAGE_FLAG | CPU_PAGE_FLAG) ) { pktgen.flags &= ~(CONFIG_PAGE_FLAG | SEQUENCE_PAGE_FLAG | RANGE_PAGE_FLAG | PCAP_PAGE_FLAG | CPU_PAGE_FLAG); pktgen.flags |= PRINT_LABELS_FLAG; } } pktgen_redisplay(1); }