examples/l3fwd: support config file for LPM/FIB
[dpdk.git] / examples / bond / main.c
index 398553b..335bde5 100644 (file)
@@ -24,7 +24,6 @@
 #include <rte_memcpy.h>
 #include <rte_eal.h>
 #include <rte_launch.h>
-#include <rte_atomic.h>
 #include <rte_cycles.h>
 #include <rte_prefetch.h>
 #include <rte_lcore.h>
 #include <rte_tcp.h>
 #include <rte_arp.h>
 #include <rte_spinlock.h>
+#include <rte_devargs.h>
+#include <rte_byteorder.h>
+#include <rte_cpuflags.h>
+#include <rte_eth_bond.h>
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
 
 #include "main.h"
 
-#include <rte_devargs.h>
-
-
-#include "rte_byteorder.h"
-#include "rte_cpuflags.h"
-#include "rte_eth_bond.h"
-
 #define RTE_LOGTYPE_DCB RTE_LOGTYPE_USER1
 
 #define NB_MBUF   (1024*8)
 #define MAX_PORTS      4
 #define PRINT_MAC(addr)                printf("%02"PRIx8":%02"PRIx8":%02"PRIx8 \
                ":%02"PRIx8":%02"PRIx8":%02"PRIx8,      \
-               addr.addr_bytes[0], addr.addr_bytes[1], addr.addr_bytes[2], \
-               addr.addr_bytes[3], addr.addr_bytes[4], addr.addr_bytes[5])
+               RTE_ETHER_ADDR_BYTES(&addr))
 
 uint16_t slaves[RTE_MAX_ETHPORTS];
 uint16_t slaves_count;
@@ -119,18 +114,17 @@ static struct rte_mempool *mbuf_pool;
 
 static struct rte_eth_conf port_conf = {
        .rxmode = {
-               .mq_mode = ETH_MQ_RX_NONE,
-               .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
+               .mq_mode = RTE_ETH_MQ_RX_NONE,
                .split_hdr_size = 0,
        },
        .rx_adv_conf = {
                .rss_conf = {
                        .rss_key = NULL,
-                       .rss_hf = ETH_RSS_IP,
+                       .rss_hf = RTE_ETH_RSS_IP,
                },
        },
        .txmode = {
-               .mq_mode = ETH_MQ_TX_NONE,
+               .mq_mode = RTE_ETH_MQ_TX_NONE,
        },
 };
 
@@ -154,9 +148,9 @@ slave_port_init(uint16_t portid, struct rte_mempool *mbuf_pool)
                        "Error during getting device (port %u) info: %s\n",
                        portid, strerror(-retval));
 
-       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
+       if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
                local_port_conf.txmode.offloads |=
-                       DEV_TX_OFFLOAD_MBUF_FAST_FREE;
+                       RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
 
        local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
                dev_info.flow_type_rss_offloads;
@@ -236,7 +230,7 @@ bond_port_init(struct rte_mempool *mbuf_pool)
                        0 /*SOCKET_ID_ANY*/);
        if (retval < 0)
                rte_exit(EXIT_FAILURE,
-                               "Faled to create bond port\n");
+                               "Failed to create bond port\n");
 
        BOND_PORT = retval;
 
@@ -246,9 +240,9 @@ bond_port_init(struct rte_mempool *mbuf_pool)
                        "Error during getting device (port %u) info: %s\n",
                        BOND_PORT, strerror(-retval));
 
-       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
+       if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
                local_port_conf.txmode.offloads |=
-                       DEV_TX_OFFLOAD_MBUF_FAST_FREE;
+                       RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
        retval = rte_eth_dev_configure(BOND_PORT, 1, 1, &local_port_conf);
        if (retval != 0)
                rte_exit(EXIT_FAILURE, "port %u: configuration failed (res=%d)\n",
@@ -362,7 +356,7 @@ struct global_flag_stru_t *global_flag_stru_p = &global_flag_stru;
 static int lcore_main(__rte_unused void *arg1)
 {
        struct rte_mbuf *pkts[MAX_PKT_BURST] __rte_cache_aligned;
-       struct rte_ether_addr d_addr;
+       struct rte_ether_addr dst_addr;
 
        struct rte_ether_addr bond_mac_addr;
        struct rte_ether_hdr *eth_hdr;
@@ -411,7 +405,7 @@ static int lcore_main(__rte_unused void *arg1)
                                                struct rte_ether_hdr *);
                        ether_type = eth_hdr->ether_type;
                        if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN))
-                               printf("VLAN taged frame, offset:");
+                               printf("VLAN tagged frame, offset:");
                        offset = get_vlan_offset(eth_hdr, &ether_type);
                        if (offset > 0)
                                printf("%d\n", offset);
@@ -426,13 +420,13 @@ static int lcore_main(__rte_unused void *arg1)
                                        if (arp_hdr->arp_opcode == rte_cpu_to_be_16(RTE_ARP_OP_REQUEST)) {
                                                arp_hdr->arp_opcode = rte_cpu_to_be_16(RTE_ARP_OP_REPLY);
                                                /* Switch src and dst data and set bonding MAC */
-                                               rte_ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);
-                                               rte_ether_addr_copy(&bond_mac_addr, &eth_hdr->s_addr);
+                                               rte_ether_addr_copy(&eth_hdr->src_addr, &eth_hdr->dst_addr);
+                                               rte_ether_addr_copy(&bond_mac_addr, &eth_hdr->src_addr);
                                                rte_ether_addr_copy(&arp_hdr->arp_data.arp_sha,
                                                                &arp_hdr->arp_data.arp_tha);
                                                arp_hdr->arp_data.arp_tip = arp_hdr->arp_data.arp_sip;
-                                               rte_ether_addr_copy(&bond_mac_addr, &d_addr);
-                                               rte_ether_addr_copy(&d_addr, &arp_hdr->arp_data.arp_sha);
+                                               rte_ether_addr_copy(&bond_mac_addr, &dst_addr);
+                                               rte_ether_addr_copy(&dst_addr, &arp_hdr->arp_data.arp_sha);
                                                arp_hdr->arp_data.arp_sip = bond_ip;
                                                rte_eth_tx_burst(BOND_PORT, 0, &pkts[i], 1);
                                                is_free = 1;
@@ -447,8 +441,10 @@ static int lcore_main(__rte_unused void *arg1)
                                 }
                                ipv4_hdr = (struct rte_ipv4_hdr *)((char *)(eth_hdr + 1) + offset);
                                if (ipv4_hdr->dst_addr == bond_ip) {
-                                       rte_ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);
-                                       rte_ether_addr_copy(&bond_mac_addr, &eth_hdr->s_addr);
+                                       rte_ether_addr_copy(&eth_hdr->src_addr,
+                                                       &eth_hdr->dst_addr);
+                                       rte_ether_addr_copy(&bond_mac_addr,
+                                                       &eth_hdr->src_addr);
                                        ipv4_hdr->dst_addr = ipv4_hdr->src_addr;
                                        ipv4_hdr->src_addr = bond_ip;
                                        rte_eth_tx_burst(BOND_PORT, 0, &pkts[i], 1);
@@ -523,8 +519,8 @@ static void cmd_obj_send_parsed(void *parsed_result,
        created_pkt->pkt_len = pkt_size;
 
        eth_hdr = rte_pktmbuf_mtod(created_pkt, struct rte_ether_hdr *);
-       rte_ether_addr_copy(&bond_mac_addr, &eth_hdr->s_addr);
-       memset(&eth_hdr->d_addr, 0xFF, RTE_ETHER_ADDR_LEN);
+       rte_ether_addr_copy(&bond_mac_addr, &eth_hdr->src_addr);
+       memset(&eth_hdr->dst_addr, 0xFF, RTE_ETHER_ADDR_LEN);
        eth_hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP);
 
        arp_hdr = (struct rte_arp_hdr *)(
@@ -879,5 +875,9 @@ main(int argc, char *argv[])
        prompt(NULL);
 
        rte_delay_ms(100);
+
+       /* clean up the EAL */
+       rte_eal_cleanup();
+
        return 0;
 }