2016-08-02 15 views
1

DPDKの基本的な例の転送メカニズムを理解しようとしています。誰でもrte_mbufのペイロードの初期化と編集を手伝ってもらえますか? Hereがクラスです。 tcpdumpとを使用して、パケットの内容を表示する予定です。DPDK - rte_mbufペイロード/データの初期化または更新/変更

ここ

は、私は私自身のペイロードを追加したいrte_mbufです:これは受信されrte_mbufある

struct rte_mbuf *bufs[BURST_SIZE]; 

const uint16_t nb_rx = rte_eth_rx_burst(port, 0, bufs, BURST_SIZE); 

このrte_mbufが送信されている:

const uint16_t nb_tx = rte_eth_tx_burst(port^1, 0, 
            bufs, nb_rx); 

サンプルアプリケーションを変更しましたファイルに転送されたパケットを印刷するDPDK例で: The dump for the first three iterations of the loop 私はより良く理解するために内容を変更できるようにしたいと思います:

/* Get burst of RX packets, from first port of pair. */ 

const uint16_t nb_rx = rte_eth_rx_burst(port, 0, bufs, BURST_SIZE); 
FILE *fp; 

fp = fopen("dump.txt", "a"); 
fprintf(fp, "\n-----------------------\n fprintf... %d<->%d\n", count, port); 

rte_pktmbuf_dump(fp, bufs[0], 1000); 
fclose(fp); 
if (unlikely(nb_rx == 0)) 
     continue; 

/* Send burst of TX packets, to second port of pair. */ 
    const uint16_t nb_tx = rte_eth_tx_burst(port^1, 0,bufs, nb_rx); 

これらは、私は、出力ファイルに表示パケットです。私はrte_pktmbuf_initbufs->userdata =*(unsigned short*) 0xAAAAAAAAを試しましたが、それは私のためには機能しません。

+0

ユーザデータは、ユーザが使用するプライベートエリアであるペイロードではありません。ペイロードはmbuf-> buf_addrにあり、実パケットの最初のバイトを指しています。 – roni

答えて

2

私は自分のパケットをメモリプールに作成することで問題を解決しました。

  1. プログラム用のメモリプールを作成します。
  2. メモリプールにパケットを割り当てます。
  3. パケットにデータ、送信元アドレス、宛先アドレス、およびパケットの初期化フィールドを設定します。

完全lcore_main機能:

/* 
* The main thread that does the work, reading from 
* an input port and writing to an output port. 
*/ 
struct message { 
    char data[DATA_SIZE]; 
}; 

static __attribute__(()) void 
lcore_main(void) 
{ 
    const uint8_t nb_ports = rte_eth_dev_count(); 
    uint8_t port; 

    for (port = 0; port < nb_ports; port++) 
     if (rte_eth_dev_socket_id(port) > 0 && 
      rte_eth_dev_socket_id(port) != 
      (int)rte_socket_id()) 
      printf("WARNING, port %u is on remote NUMA node to " 
      "polling thread.\n\tPerformance will " 
      "not be optimal.\n", port); 

    struct rte_mbuf *pkt; 
    struct ether_hdr *eth_hdr; 

    struct message obj; 
    struct message *msg; 
    int nb_rx = 0, nb_tx = 0, cnt = 0, pkt_size = 0; 
    int count = 0; 
    int k = 0; 
    for (count = 0; count < DATA_SIZE; count++){ 
     obj.data[count] = (char)(97 + (k++)); 
     if (k == 26) 
      k = 0; 
    } 
    time_t endtime = time(NULL) + 10; 
    port = 0; 
    while (time(NULL) < endtime) { 
     cnt = rte_eth_rx_burst(port, 0, &pkt, 1); 
     nb_rx += cnt; 

     if (cnt > 0) 
     { 
      eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *); 

      rte_eth_macaddr_get(port, &eth_hdr->s_addr); 

      pkt_size = sizeof(struct message) + sizeof(struct ether_hdr); 
      msg = (struct message *) (rte_pktmbuf_mtod(pkt, char*)) + sizeof(struct ether_hdr); 
      rte_pktmbuf_free(pkt); 
     } 

     msg = &obj; 
     pkt = rte_pktmbuf_alloc(mbuf_pool); 
     pkt_size = sizeof(struct message) + sizeof(struct ether_hdr); 
     pkt->data_len = pkt_size; 
     pkt->pkt_len = pkt_size; 
     eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *); 
     rte_eth_macaddr_get(port, &eth_hdr->d_addr); 
     rte_eth_macaddr_get(port^1, &eth_hdr->s_addr); 
     eth_hdr->ether_type = htons(PTP_PROTOCOL); 
     char* data; 

     data = rte_pktmbuf_append(pkt, sizeof(struct message)); 
     if (data != NULL) 
      rte_memcpy(data, msg, sizeof(struct message)); 

     nb_tx += rte_eth_tx_burst(port^1, 0, &pkt, 1); 
    } 
    printf("----\nData size: %d\nPacket size: %d\nRX : %d, TX : %d\n\n", DATA_SIZE, pkt_size, nb_rx, nb_tx); 
} 
関連する問題