[dpdk-dev,RFC,07/10] examples/tep_termination:add tunnel filter type configuration

Message ID 1429156558-28548-8-git-send-email-jijiang.liu@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Jijiang Liu April 16, 2015, 3:55 a.m. UTC
  The follwoing filter types are supported for VXLAN,

1> Inner MAC&VLAN and tenent ID

2> Inner MAC and tenent ID, and Outer MAC

3> Inner MAC and tenent ID

Signed-off-by: Jijiang Liu <jijiang.liu@intel.com>
---
 examples/tep_termination/main.c        |   21 +++++++++++++
 examples/tep_termination/vxlan_setup.c |   50 ++++++++++++++++++++++++++++++-
 2 files changed, 69 insertions(+), 2 deletions(-)
  

Patch

diff --git a/examples/tep_termination/main.c b/examples/tep_termination/main.c
index 68d1706..e8142e0 100644
--- a/examples/tep_termination/main.c
+++ b/examples/tep_termination/main.c
@@ -72,6 +72,9 @@ 
 #define MAX_PKT_BURST 32 	/* Max burst size for RX/TX */
 #define BURST_TX_DRAIN_US 100 	/* TX drain every ~100us */
 
+/* Defines how long we wait between retries on RX */
+#define BURST_RX_WAIT_US 15
+
 #define BURST_RX_RETRIES 4/* Number of retries on RX. */
 
 #define JUMBO_FRAME_MAX_SIZE    0x2600
@@ -116,6 +119,9 @@  uint16_t num_devices;
 /* VXLAN UDP destination port */
 uint16_t udp_port;
 
+/* RX filter type for tunneling packet */
+uint8_t filter_idx;
+
 /* overlay packet operation */
 struct ol_switch_ops overlay_options = {
 	.port_configure = vxlan_port_init,
@@ -236,6 +242,10 @@  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"
+	"		--filter-type[1-3]: filter type for tunneling packet\n"
+	"		    1: Inner MAC&VLAN and tenent ID\n"
+	"		    2: Inner MAC and tenent ID\n"
+	"		    3: Outer MAC, Inner MAC and tenent ID\n"
 	"		--dev-basename <name>\n"
 	"		-p PORTMASK: Set mask for ports to be used by application\n"
 	"		--stats [0-N]: 0: Disable stats, N: Time in seconds to print stats\n"
@@ -256,6 +266,7 @@  tep_parse_args(int argc, char **argv)
 	static struct option long_option[] = {
 		{"udp-port", required_argument, NULL, 0},
 		{"nb-devices", required_argument, NULL, 0},
+		{"filter-type", required_argument, NULL, 0},
 		{"stats", required_argument, NULL, 0},
 		{"dev-basename", required_argument, NULL, 0},
 		{NULL, 0, 0, 0},
@@ -294,6 +305,16 @@  tep_parse_args(int argc, char **argv)
 					return -1;
 				}
 			}
+			
+			if (!strncmp(long_option[option_index].name, "filter-type", MAX_LONG_OPT_SZ)) {
+				ret = parse_num_opt(optarg, 3);
+				if (ret == -1) {
+					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for filter type [1-3]\n");
+					vep_termination_usage(prgname);
+					return -1;
+				} else
+					filter_idx = ret - 1;
+			}
 
 			/* Enable/disable stats. */
 			if (!strncmp(long_option[option_index].name, "stats", MAX_LONG_OPT_SZ)) {
diff --git a/examples/tep_termination/vxlan_setup.c b/examples/tep_termination/vxlan_setup.c
index fbffbc8..312a878 100644
--- a/examples/tep_termination/vxlan_setup.c
+++ b/examples/tep_termination/vxlan_setup.c
@@ -82,6 +82,7 @@ 
 extern uint16_t num_devices;
 extern uint16_t udp_port;
 extern uint8_t ports[RTE_MAX_ETHPORTS];
+extern uint8_t filter_idx;
 
 /* ethernet addresses of ports */
 extern struct ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
@@ -237,10 +238,12 @@  vxlan_rx_process(struct rte_mbuf *pkt)
 		return -1;
 
 	ret = decapsulation(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;
 
@@ -260,11 +263,12 @@  static int vxlan_tx_process(uint8_t vport_id, struct rte_mbuf *pkt)
 int
 vxlan_link(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
-	int i;
+	int i, ret;
 	struct ether_hdr *pkt_hdr;
 	struct virtio_net_data_ll *dev_ll;
 	struct virtio_net *dev = vdev->dev;
 	uint64_t portid = dev->device_fh;
+	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
 
 	dev_ll = ll_root_used;
 
@@ -290,6 +294,28 @@  vxlan_link(struct vhost_dev *vdev, struct rte_mbuf *m)
 		vxdev.port[portid].peermac.addr_bytes[i] = peer_mac[i];
 	}
 
+	memset(&tunnel_filter_conf, 0, sizeof(struct rte_eth_tunnel_filter_conf));
+
+	tunnel_filter_conf.outer_mac = &ports_eth_addr[0];
+	tunnel_filter_conf.filter_type = tep_filter_type[filter_idx];
+
+	/* inner MAC */
+	tunnel_filter_conf.inner_mac = &vdev->mac_address;
+
+	tunnel_filter_conf.queue_id = vdev->rx_q;
+	tunnel_filter_conf.tenant_id = tenant_id_conf[vdev->rx_q];
+	tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
+
+	ret = rte_eth_dev_filter_ctrl(ports[0],
+		RTE_ETH_FILTER_TUNNEL,
+		RTE_ETH_FILTER_ADD,
+		&tunnel_filter_conf);
+	if (ret) {
+		RTE_LOG(ERR, VHOST_DATA, "%d Failed to add device MAC address to cloud filter\n",
+		vdev->rx_q);
+		return -1;
+	}
+
 	/* Print out inner MAC and VNI info. */
 	RTE_LOG(INFO, VHOST_DATA, "(%d) MAC_ADDRESS %02x:%02x:%02x:%02x:%02x:%02x and VNI %d registered\n",
 		vdev->rx_q,
@@ -341,8 +367,28 @@  vxlan_unlink(struct vhost_dev *vdev)
 	int ret = 1;
 	unsigned i = 0, rx_count;
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
+	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
 
 	if (vdev->ready == DEVICE_RX) {
+		memset(&tunnel_filter_conf, 0, sizeof(struct rte_eth_tunnel_filter_conf));
+
+		tunnel_filter_conf.outer_mac = &ports_eth_addr[0];
+		tunnel_filter_conf.inner_mac = &vdev->mac_address;
+		tunnel_filter_conf.tenant_id = tenant_id_conf[vdev->rx_q];
+		tunnel_filter_conf.filter_type = tep_filter_type[filter_idx];
+
+		tunnel_filter_conf.queue_id = vdev->rx_q;
+		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
+
+		ret = rte_eth_dev_filter_ctrl(ports[0],
+				RTE_ETH_FILTER_TUNNEL,
+				RTE_ETH_FILTER_DELETE,
+				&tunnel_filter_conf);
+		if (ret) {
+			RTE_LOG(ERR, VHOST_DATA, "%d Failed to add device MAC address to cloud filter\n",
+				vdev->rx_q);
+			return;
+		}
 		for (i = 0; i < ETHER_ADDR_LEN; i++)
 			vdev->mac_address.addr_bytes[i] = 0;