Exemplo n.º 1
0
void
pktgen_page_seq(uint32_t pid)
{
    uint32_t    i, row, col;
    port_info_t * info;
    pkt_seq_t   * pkt;
    char buff[64];

    display_topline("** Sequence Page **");

    info = &pktgen.info[pid];

    row = PORT_STATE_ROW;
    col = 1;
    wr_scrn_printf(row++, col, "Port: %2d, Sequence Count: %2d of %2d  ", pid, info->seqCnt, NUM_SEQ_PKTS);
    wr_scrn_printf(row++, col, "%*s %*s%*s%*s%*s%*s%*s%*s",
            6, "Seq:",
            COLUMN_WIDTH_0, "Dst MAC",
            COLUMN_WIDTH_0, "Src MAC",
            COLUMN_WIDTH_0, "Dst IP",
            COLUMN_WIDTH_0+2, "Src IP",
            12, "Port S/D",
            15, "Protocol:VLAN",
            5, "Size");
    for(i = 0; i < NUM_SEQ_PKTS; i++) {
        col = 1;
        pkt = &info->seq_pkt[i];

        if ( i >= info->seqCnt ) {
        	wr_scrn_eol_pos(row++, col);
        	continue;
        }

        wr_scrn_printf(row, col, "%5d:", i);
        col += 7;
        wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_mtoa(buff, sizeof(buff), &pkt->eth_dst_addr));
        col += COLUMN_WIDTH_1;
        wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_mtoa(buff, sizeof(buff), &pkt->eth_src_addr));
        col += COLUMN_WIDTH_1;
        wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_ntop4(buff, sizeof(buff), htonl(pkt->ip_dst_addr), 0xFFFFFFFF));
        col += COLUMN_WIDTH_1;
        wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1+2, inet_ntop4(buff, sizeof(buff), htonl(pkt->ip_src_addr), pkt->ip_mask));
        col += COLUMN_WIDTH_1+2;

        snprintf(buff, sizeof(buff), "%d/%d", pkt->sport, pkt->dport);
        wr_scrn_printf(row, col, "%*s", 12, buff);
        col += 12;
        snprintf(buff, sizeof(buff), "%s/%s:%04x", (pkt->ethType == ETHER_TYPE_IPv4)? "IPv4" :
                                                      (pkt->ethType == ETHER_TYPE_IPv6)? "IPv6" : "Other",
                                                      (pkt->ipProto == PG_IPPROTO_TCP)? "TCP" :
                                                      (pkt->ipProto == PG_IPPROTO_ICMP)? "ICMP" : "UDP",
                                                    		  pkt->vlanid);
        wr_scrn_printf(row, col, "%*s", 15, buff);
        col += 15;
        wr_scrn_printf(row, col, "%5d", pkt->pktSize+FCS_SIZE);
        row++;
    }

    display_dashline(row+2);
}
Exemplo n.º 2
0
void
wr_logo(int row, int col, const char * appname)
{
	int		i;
	static const char * logo[] = {
		"#     #",
		"#  #  #     #    #    #  #####",
		"#  #  #     #    ##   #  #    #",
		"#  #  #     #    # #  #  #    #",
		"#  #  #     #    #  # #  #    #",
		"#  #  #     #    #   ##  #    #",
		" ## ##      #    #    #  #####",
		"",
		"######",
		"#     #     #    #    #  ######  #####",
		"#     #     #    #    #  #       #    #",
		"######      #    #    #  #####   #    #",
		"#   #       #    #    #  #       #####",
		"#    #      #     #  #   #       #   #",
		"#     #     #      ##    ######  #    #",
		"",
		" #####",
		"#     #   #   #   ####    #####  ######  #    #   ####",
		"#          # #   #          #    #       ##  ##  #",
		" #####      #     ####      #    #####   # ## #   ####",
		"      #     #         #     #    #       #    #       #",
		"#     #     #    #    #     #    #       #    #  #    #",
		" #####      #     ####      #    ######  #    #   ####",
		NULL
	};

	wr_scrn_cls();
	wr_scrn_color(GREEN, NO_CHANGE, BOLD);
	for(i=0, row++; logo[i] != NULL; i++)
		wr_scrn_printf(row++, 7, "%s", logo[i]);

	wr_scrn_color(MAGENTA, NO_CHANGE, OFF);
	wr_scrn_printf(++row, col, "%s", COPYRIGHT_MSG);
	wr_scrn_color(BLUE, NO_CHANGE, BOLD);
	wr_scrn_printf(++row, col+6, ">>> %s is %s <<<", appname, POWERED_BY_DPDK);
	wr_scrn_color(BLACK, NO_CHANGE, OFF);
	wr_scrn_pos(++row, 1);

	rte_delay_ms(1500);

    wr_scrn_cls();
    wr_scrn_pos(100, 1);
}
Exemplo n.º 3
0
void
wr_splash_screen(int row, int col, const char * appname, const char * created_by)
{
	int		i;

	row = 3;
	wr_scrn_color(BLUE, NO_CHANGE, OFF);
	wr_scrn_printf(row++, col, "%s", COPYRIGHT_MSG);
	wr_scrn_color(GREEN, NO_CHANGE, BOLD);
	for(i=0, row++; wr_copyright[i] != NULL; i++)
		wr_scrn_printf(row++, 7, "%s", wr_copyright[i]);
	wr_scrn_color(BLUE, NO_CHANGE, BOLD);
	wr_scrn_printf(row++, col, "%s created by %s -- >>> %s <<<", appname, created_by, POWERED_BY_DPDK);
	wr_scrn_color(BLACK, NO_CHANGE, OFF);
	wr_scrn_pos(++row, 1);

	rte_delay_ms(1500);

    wr_scrn_cls();
    wr_scrn_pos(100, 1);
}
Exemplo n.º 4
0
static void
pktgen_print_pcap(uint16_t pid)
{
	uint32_t i, row, col, max_pkts, len;
	uint16_t type, vlan, skip;
	uint8_t proto;
	port_info_t *info;
	pkt_hdr_t   *hdr;
	pcap_info_t *pcap;
	pcaprec_hdr_t pcap_hdr;
	char buff[64];
	char pkt_buff[2048];

	display_topline("<PCAP Page>");
	wr_scrn_printf(1, 3, "Port %d of %d", pid, pktgen.nb_ports);

	info = &pktgen.info[pid];
	pcap = info->pcap;

	row = PORT_STATE_ROW;
	col = 1;
	if (pcap == NULL) {
		wr_scrn_center(10, pktgen.scrn->ncols, "** Port does not have a PCAP file assigned **");
		row = 28;
		goto leave;
	}

	wr_scrn_eol_pos(row, col);
	wr_scrn_printf(row++, col, "Port: %d, PCAP Count: %d of %d",
	               pid, pcap->pkt_idx, pcap->pkt_count);
	wr_scrn_printf(row++, col, "%*s %*s%*s%*s%*s%*s%*s%*s",
	               5, "Seq",
	               COLUMN_WIDTH_0, "Dst MAC",
	               COLUMN_WIDTH_0, "Src MAC",
	               COLUMN_WIDTH_0, "Dst IP",
	               COLUMN_WIDTH_0 + 2, "Src IP",
	               12, "Port S/D",
	               15, "Protocol:VLAN",
	               9, "Size-FCS");

	max_pkts = pcap->pkt_idx + PCAP_PAGE_SIZE;
	if (max_pkts > pcap->pkt_count)
		max_pkts = pcap->pkt_count;

	wr_pcap_skip(pcap, pcap->pkt_idx);

	for (i = pcap->pkt_idx; i < max_pkts; i++) {
		col = 1;
		skip = 0;

		len = wr_pcap_read(pcap, &pcap_hdr, pkt_buff, sizeof(pkt_buff));
		if (len == 0)
			break;

		/* Skip any jumbo packets larger then buffer. */
		if (pcap_hdr.incl_len > sizeof(pkt_buff) ) {
			i--;
			skip++;
		}
		/* Skip packets that are not normal IP packets. */
		type = ntohs( ((uint16_t *)pkt_buff)[6]);
		if (unlikely(type == ETHER_TYPE_VLAN) )
			type = ntohs( ((uint16_t *)pkt_buff)[8]);

		if (unlikely(type < MAX_ETHER_TYPE_SIZE) )
			skip++;

		hdr = (pkt_hdr_t *)&pkt_buff[0];

		wr_scrn_eol_pos(row, col);

		wr_scrn_printf(row, col, "%5d:", i);
		col += 7;
		wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_mtoa(buff, sizeof(buff), &hdr->eth.d_addr));
		col += COLUMN_WIDTH_1;
		wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_mtoa(buff, sizeof(buff), &hdr->eth.s_addr));
		col += COLUMN_WIDTH_1;

		type = ntohs(hdr->eth.ether_type);
		proto = hdr->u.ipv4.proto;
		vlan = 0;
		if (type == ETHER_TYPE_VLAN) {
			vlan = ntohs( ((uint16_t *)&hdr->eth.ether_type)[1]);
			type = ntohs( ((uint16_t *)&hdr->eth.ether_type)[2]);
			proto = ((ipHdr_t *)((char *)&hdr->u.ipv4 + 4))->proto;
		}

		if (type == ETHER_TYPE_IPv4) {
			wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1, inet_ntop4(buff, sizeof(buff), hdr->u.ipv4.dst, 0xFFFFFFFF));
			col += COLUMN_WIDTH_1;
			wr_scrn_printf(row, col, "%*s", COLUMN_WIDTH_1 + 2, inet_ntop4(buff, sizeof(buff), hdr->u.ipv4.src, 0xFFFFFFFF));
			col += COLUMN_WIDTH_1 + 2;

			snprintf(buff, sizeof(buff), "%d/%d", ntohs(hdr->u.uip.udp.sport), ntohs(hdr->u.uip.udp.dport));
			wr_scrn_printf(row, col, "%*s", 12, buff);
			col += 12;
		} else {
			skip++;
			col += ((2 * COLUMN_WIDTH_1) + 2 + 12);
		}
		snprintf(buff, sizeof(buff), "%s/%s:%4d", (type == ETHER_TYPE_IPv4) ? "IPv4" :
		         (type == ETHER_TYPE_IPv6) ? "IPv6" : "Other",
		         (type == PG_IPPROTO_TCP) ? "TCP" :
		         (proto == PG_IPPROTO_ICMP) ? "ICMP" : "UDP",
		         (vlan & 0xFFF));
		wr_scrn_printf(row, col, "%*s", 15, buff);
		col += 15;
		wr_scrn_printf(row, col, "%5d", len);

		if (skip && (type < ETHER_TYPE_IPv4) )
			wr_scrn_printf(row, col + 7, "<<< Skip %04x", type);
		else if (skip && (type != ETHER_TYPE_IPv4) )
			wr_scrn_printf(row, col + 7, " EthType %04x", type);
		row++;
	}
leave:
	display_dashline(row + 2);

	pktgen.flags &= ~PRINT_LABELS_FLAG;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
/* Display log page on the screen */
void
pktgen_page_log(uint32_t print_labels)
{
	/* Maximum number of log lines to display */
#define MAX_PAGE_LINES 28

	uint32_t row, curr_msg, output_lines, curr_char;
	int curr_line;
	char lines[MAX_PAGE_LINES][LOG_MAX_LINE];

	if (!print_labels && !log_history.need_refresh)
		return;

	display_topline("<Logged messages>");
	row = 2;

	/* Header line */
	wr_scrn_printf(row++, 1, "%1s %8s %-32s %s",
	               "L", "Time", "Function", "Message");

	curr_line = output_lines = 0;
	curr_msg = log_history.head;
	while ((curr_msg != log_history.tail) && (output_lines < MAX_PAGE_LINES)) {
		/* Go backwards and wrap around */
		curr_msg = (curr_msg + LOG_HISTORY - 1) % LOG_HISTORY;

		snprintf(lines[curr_line], LOG_MAX_LINE, "%s",
		         pktgen_format_msg_page(&log_history.msg[curr_msg]));

		/* Count number of lines occupied by current log entry. Line wrapping
		 * because of screen width is not counted, \n's embedded in the log
		 * message are counted.
		 */
		for (curr_char = 0; lines[curr_line][curr_char] != '\0'; ++curr_char)
			if (lines[curr_line][curr_char] == '\n')
				++output_lines;

		++output_lines;	/* First line before possible \n's */

		++curr_line;
	}

	/* The lines[] array contains the messages to print on the screen, with
	 * the most recent message first.
	 * Iterating backwards gives the messages in chronological order.
	 * curr_line points 1 beyond the last entry in lines[].
	 */
	for (--curr_line; curr_line >= 0; --curr_line) {
		wr_scrn_printf(row++, 1, "%s", lines[curr_line]);

		/* Increase row for each embedded \n */
		for (curr_char = 0; lines[curr_line][curr_char] != '\0'; ++curr_char)
			if (lines[curr_line][curr_char] == '\n')
				++row;
	}

	if (row < MAX_PAGE_LINES)
		row = MAX_PAGE_LINES;

	display_dashline(++row);
	log_history.need_refresh = 0;

#undef MAX_PAGE_LINES
}