The port number of UDP tunneling packet is configurable, which has 16 entries 
in total for i40e.

Signed-off-by: Jijiang Liu <jijiang.liu at intel.com>
---
 examples/tep_termination/main.c        |   14 ++++++++++++++
 examples/tep_termination/vxlan.c       |    3 ++-
 examples/tep_termination/vxlan_setup.c |   17 +++++++++++++----
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/examples/tep_termination/main.c b/examples/tep_termination/main.c
index 60a825e..68d1706 100644
--- a/examples/tep_termination/main.c
+++ b/examples/tep_termination/main.c
@@ -113,6 +113,9 @@ struct vpool {
 /* number of devices */
 uint16_t num_devices;

+/* VXLAN UDP destination port */
+uint16_t udp_port;
+
 /* overlay packet operation */
 struct ol_switch_ops overlay_options = {
        .port_configure = vxlan_port_init,
@@ -231,6 +234,7 @@ static void
 vep_termination_usage(const char *prgname)
 {
        RTE_LOG(INFO, VHOST_CONFIG, "%s [EAL options] -- -p PORTMASK\n"
+       "               --udp-port: UDP destination port for VXLAN packet\n"
        "               --nb-devices: number of virtIO device\n"
        "               --dev-basename <name>\n"
        "               -p PORTMASK: Set mask for ports to be used by 
application\n"
@@ -250,6 +254,7 @@ tep_parse_args(int argc, char **argv)
        unsigned i;
        const char *prgname = argv[0];
        static struct option long_option[] = {
+               {"udp-port", required_argument, NULL, 0},
                {"nb-devices", required_argument, NULL, 0},
                {"stats", required_argument, NULL, 0},
                {"dev-basename", required_argument, NULL, 0},
@@ -280,6 +285,15 @@ tep_parse_args(int argc, char **argv)
                                } else 
                                        num_devices = ret;
                        }
+       
+                       if (!strncmp(long_option[option_index].name, 
"udp-port", MAX_LONG_OPT_SZ)) {
+                               ret = parse_num_opt(optarg, INT16_MAX);
+                               if (ret == -1) {
+                                       RTE_LOG(INFO, VHOST_CONFIG, "Invalid 
argument for UDP port [0-N]\n");
+                                               vep_termination_usage(prgname);
+                                       return -1;
+                               }
+                       }

                        /* Enable/disable stats. */
                        if (!strncmp(long_option[option_index].name, "stats", 
MAX_LONG_OPT_SZ)) {
diff --git a/examples/tep_termination/vxlan.c b/examples/tep_termination/vxlan.c
index 9d86616..942eb10 100644
--- a/examples/tep_termination/vxlan.c
+++ b/examples/tep_termination/vxlan.c
@@ -46,6 +46,7 @@
 extern struct vxlan_conf vxdev;
 extern struct ipv4_hdr app_ip_hdr[VXLAN_N_PORTS];
 extern struct ether_hdr app_l2_hdr[VXLAN_N_PORTS];
+extern uint16_t udp_port;

 /*
  * Parse an ethernet header to fill the ethertype, l2_len, l3_len and
@@ -100,7 +101,7 @@ int decapsulation(struct rte_mbuf *pkt)
                struct udp_hdr *udp_hdr;
                udp_hdr = (struct udp_hdr *)((char *)phdr +
                        info.outer_l2_len + info.outer_l3_len);
-               if (udp_hdr->dst_port != rte_cpu_to_be_16(4789))
+               if (udp_hdr->dst_port != rte_cpu_to_be_16(udp_port))
                        return -1;
        }
        outer_header_len = info.outer_l2_len + info.outer_l3_len
diff --git a/examples/tep_termination/vxlan_setup.c 
b/examples/tep_termination/vxlan_setup.c
index 7cb2660..fbffbc8 100644
--- a/examples/tep_termination/vxlan_setup.c
+++ b/examples/tep_termination/vxlan_setup.c
@@ -80,6 +80,7 @@
 #define RTE_TEST_TX_DESC_DEFAULT 512

 extern uint16_t num_devices;
+extern uint16_t udp_port;
 extern uint8_t ports[RTE_MAX_ETHPORTS];

 /* ethernet addresses of ports */
@@ -156,10 +157,12 @@ vxlan_port_init(uint8_t port, struct rte_mempool 
*mbuf_pool)
        const uint16_t tx_ring_size = RTE_TEST_TX_DESC_DEFAULT;
        int retval;
        uint16_t num_queues, q;
-        //struct vxlan_conf *pconf = &vxdev;
+        struct vxlan_conf *pconf = &vxdev;
+       struct rte_eth_udp_tunnel tunnel_udp;
        struct rte_eth_rxconf *rxconf;
        struct rte_eth_txconf *txconf;

+       pconf->vxport = udp_port;
        rte_eth_dev_info_get (port, &dev_info);

        dev_info.max_rx_queues = num_devices;
@@ -204,6 +207,13 @@ vxlan_port_init(uint8_t port, struct rte_mempool 
*mbuf_pool)
        if (retval < 0)
                return retval;

+       /* Configure UDP port for VXLAN */
+       tunnel_udp.udp_port = udp_port;
+       tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
+       retval = rte_eth_dev_udp_tunnel_add(port, &tunnel_udp);
+       if (retval < 0)
+               return retval;
+
        rte_eth_macaddr_get(port, &ports_eth_addr[port]);
        RTE_LOG(INFO, PORT, "Port %u MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8
                        " %02"PRIx8" %02"PRIx8" %02"PRIx8"\n",
@@ -230,8 +240,7 @@ vxlan_rx_process(struct rte_mbuf *pkt)
        return ret;
 }

-static int 
-vxlan_tx_process(uint8_t vport_id, struct rte_mbuf *pkt)
+static int vxlan_tx_process(uint8_t vport_id, struct rte_mbuf *pkt)
 {
        int ret = 0;

@@ -241,6 +250,7 @@ vxlan_tx_process(uint8_t vport_id, struct rte_mbuf *pkt)
        }

        ret = encapsulation(pkt, vport_id);
+
        return ret;
 }

@@ -367,7 +377,6 @@ vxlan_tx_pkts (uint8_t port_id, uint16_t queue_id,
        }

        ret = rte_eth_tx_burst(port_id, queue_id, tx_pkts, nb_pkts);
-
        return ret;

 }
-- 
1.7.7.6

Reply via email to