diff --git a/app/pktgen-cmds.c b/app/pktgen-cmds.c index d03522e9..23406158 100644 --- a/app/pktgen-cmds.c +++ b/app/pktgen-cmds.c @@ -55,7 +55,7 @@ convert_bitfield(bf_spec_t *bf) } /** - * pktgen_save - Save a configuration as a startup script + * pktgen_script_save - Save a configuration as a startup script * * DESCRIPTION * Save a configuration as a startup script @@ -464,7 +464,7 @@ pktgen_lua_save(char *path) fprintf(fd, "pktgen.mac_from_arp(\"%s\");\n\n", (pktgen.flags & MAC_FROM_ARP_FLAG) ? "enable" : "disable"); - for (i = 0; i < RTE_MAX_ETHPORTS; i++) { + for (i = 0; i < pktgen.nb_ports; i++) { pinfo = l2p_get_port_pinfo(i); pkt = &pinfo->seq_pkt[SINGLE_PKT]; range = &pinfo->range; diff --git a/app/pktgen-pcap.c b/app/pktgen-pcap.c index 165b3872..826d0871 100644 --- a/app/pktgen-pcap.c +++ b/app/pktgen-pcap.c @@ -26,7 +26,7 @@ pktgen_pcap_info(pcap_info_t *pcap, uint16_t port, int flag) printf(" snaplen: %d,", pcap->info.snaplen); printf(" sigfigs: %d,", pcap->info.sigfigs); printf(" network: %d", pcap->info.network); - printf(" Endian: %s\n", pcap->convert ? "Big" : "Little"); + printf(" Convert Endian: %s\n", pcap->convert ? "Yes" : "No"); if (flag) printf(" Packet count: %d\n", pcap->pkt_count); printf("\n"); @@ -58,17 +58,14 @@ static void pcap_get_info(pcap_info_t *pcap) { pcap_record_hdr_t hdr; + if (fread(&pcap->info, 1, sizeof(pcap_hdr_t), pcap->fp) != sizeof(pcap_hdr_t)) rte_exit(EXIT_FAILURE, "%s: failed to read pcap header\n", __func__); - /* Make sure we have a valid PCAP file for Big or Little Endian formats. */ - if (pcap->info.magic_number != PCAP_MAGIC_NUMBER) - pcap->convert = 0; - else if (pcap->info.magic_number != ntohl(PCAP_MAGIC_NUMBER)) - pcap->convert = 1; - else - rte_exit(EXIT_FAILURE, "%s: invalid magic number 0x%08x\n", __func__, - pcap->info.magic_number); + pcap->convert = (PCAP_MAGIC_NUMBER == pcap->info.magic_number) ? 0 : 1; + + printf("PCAP: MAGIC_NUMBER 0x%08x == 0x%08x, Convert: %s\n", PCAP_MAGIC_NUMBER, + pcap->info.magic_number, (pcap->convert) ? "Yes" : "No"); if (pcap->convert) { pcap->info.magic_number = ntohl(pcap->info.magic_number); @@ -80,6 +77,7 @@ pcap_get_info(pcap_info_t *pcap) pcap->info.network = ntohl(pcap->info.network); } + pcap->max_pkt_size = 0; /* count the number of packets and get the largest size packet */ for (;;) { if (fread(&hdr, 1, sizeof(pcap_record_hdr_t), pcap->fp) != sizeof(hdr)) @@ -95,15 +93,19 @@ pcap_get_info(pcap_info_t *pcap) if (hdr.incl_len > pcap->max_pkt_size) pcap->max_pkt_size = hdr.incl_len; } + pcap->max_pkt_size += RTE_PKTMBUF_HEADROOM; + pcap->max_pkt_size = RTE_ALIGN_CEIL(pcap->max_pkt_size, RTE_CACHE_LINE_SIZE); + printf("PCAP: Max Packet Size: %d\n", pcap->max_pkt_size); + pcap_rewind(pcap); } static __inline__ void mbuf_iterate_cb(struct rte_mempool *mp, void *opaque, void *obj, unsigned obj_idx __rte_unused) { - pcap_info_t *pcap = (pcap_info_t *)opaque; - struct rte_mbuf *m = (struct rte_mbuf *)obj; - pcap_record_hdr_t hdr; + pcap_info_t *pcap = (pcap_info_t *)opaque; + struct rte_mbuf *m = (struct rte_mbuf *)obj; + pcap_record_hdr_t hdr = {0}; if (fread(&hdr, 1, sizeof(pcap_record_hdr_t), pcap->fp) != sizeof(hdr)) rte_exit(EXIT_FAILURE, "%s: failed to read pcap header\n", __func__); @@ -569,4 +571,4 @@ pktgen_write_mbuf_to_pcap_file(FILE *fp, struct rte_mbuf *mbuf) fflush(fp); return 0; -} \ No newline at end of file +}