From: Viacheslav Ovsiienko Date: Tue, 22 Jan 2019 10:57:04 +0000 (+0000) Subject: app/testpmd: add TOS and TTL fields to VXLAN encapsulation X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=62e8a5a8c888ec03e2485248132fd32d3b3c5b60;p=dpdk.git app/testpmd: add TOS and TTL fields to VXLAN encapsulation The new testpmd set vxlan-tos-ttl command is added. It allows to specify tos and tll fields for encapsulation IP header. IPv4 VXLAN outer header: testpmd> set vxlan-tos-ttl ip-version ipv4 vni 4 udp-src 4 udp-dst 4 ip-tos 0 ip-ttl 255 ip-src 127.0.0.1 ip-dst 128.0.0.1 eth-src 11:11:11:11:11:11 eth-dst 22:22:22:22:22:22 IPv6 VXLAN outer header: testpmd> set vxlan-tos-ttl ip-version ipv6 vni 4 udp-src 4 udp-dst 4 ip-tos 0 ip-ttl 255 ::1 ip-dst ::2222 eth-src 11:11:11:11:11:11 eth-dst 22:22:22:22:22:22 Note: ip-ttl parameter corresponds the nop_limits field for IPv6. Signed-off-by: Viacheslav Ovsiienko Acked-by: Ori Kam --- diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 51704b500f..db53cc0cce 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -794,6 +794,12 @@ static void cmd_help_long_parsed(void *parsed_result, " eth-dst (eth-dst)\n" " Configure the VXLAN encapsulation for flows.\n\n" + "vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src" + " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)" + " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)" + " eth-dst (eth-dst)\n" + " Configure the VXLAN encapsulation for flows.\n\n" + "nvgre ip-version (ipv4|ipv6) tni (tni) ip-src" " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst" " (eth-dst)\n" @@ -15034,6 +15040,8 @@ struct cmd_set_vxlan_result { cmdline_ipaddr_t ip_src; cmdline_ipaddr_t ip_dst; uint16_t tci; + uint8_t tos; + uint8_t ttl; struct ether_addr eth_src; struct ether_addr eth_dst; }; @@ -15042,6 +15050,9 @@ cmdline_parse_token_string_t cmd_set_vxlan_set = TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set"); cmdline_parse_token_string_t cmd_set_vxlan_vxlan = TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan"); +cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl = + TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, + "vxlan-tos-ttl"); cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan = TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan-with-vlan"); @@ -15066,6 +15077,16 @@ cmdline_parse_token_string_t cmd_set_vxlan_udp_dst = "udp-dst"); cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value = TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16); +cmdline_parse_token_string_t cmd_set_vxlan_ip_tos = + TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, + "ip-tos"); +cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value = + TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8); +cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl = + TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, + "ip-ttl"); +cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value = + TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8); cmdline_parse_token_string_t cmd_set_vxlan_ip_src = TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token, "ip-src"); @@ -15104,10 +15125,15 @@ static void cmd_set_vxlan_parsed(void *parsed_result, .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff), }; + vxlan_encap_conf.select_tos_ttl = 0; if (strcmp(res->vxlan, "vxlan") == 0) vxlan_encap_conf.select_vlan = 0; else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0) vxlan_encap_conf.select_vlan = 1; + else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) { + vxlan_encap_conf.select_vlan = 0; + vxlan_encap_conf.select_tos_ttl = 1; + } if (strcmp(res->ip_version, "ipv4") == 0) vxlan_encap_conf.select_ipv4 = 1; else if (strcmp(res->ip_version, "ipv6") == 0) @@ -15117,6 +15143,8 @@ static void cmd_set_vxlan_parsed(void *parsed_result, rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3); vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src); vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst); + vxlan_encap_conf.ip_tos = res->tos; + vxlan_encap_conf.ip_ttl = res->ttl; if (vxlan_encap_conf.select_ipv4) { IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src); IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst); @@ -15161,6 +15189,40 @@ cmdline_parse_inst_t cmd_set_vxlan = { }, }; +cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = { + .f = cmd_set_vxlan_parsed, + .data = NULL, + .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni udp-src" + " udp-dst ip-tos ip-ttl " + " ip-src ip-dst eth-src " + " eth-dst ", + .tokens = { + (void *)&cmd_set_vxlan_set, + (void *)&cmd_set_vxlan_vxlan_tos_ttl, + (void *)&cmd_set_vxlan_ip_version, + (void *)&cmd_set_vxlan_ip_version_value, + (void *)&cmd_set_vxlan_vni, + (void *)&cmd_set_vxlan_vni_value, + (void *)&cmd_set_vxlan_udp_src, + (void *)&cmd_set_vxlan_udp_src_value, + (void *)&cmd_set_vxlan_udp_dst, + (void *)&cmd_set_vxlan_udp_dst_value, + (void *)&cmd_set_vxlan_ip_tos, + (void *)&cmd_set_vxlan_ip_tos_value, + (void *)&cmd_set_vxlan_ip_ttl, + (void *)&cmd_set_vxlan_ip_ttl_value, + (void *)&cmd_set_vxlan_ip_src, + (void *)&cmd_set_vxlan_ip_src_value, + (void *)&cmd_set_vxlan_ip_dst, + (void *)&cmd_set_vxlan_ip_dst_value, + (void *)&cmd_set_vxlan_eth_src, + (void *)&cmd_set_vxlan_eth_src_value, + (void *)&cmd_set_vxlan_eth_dst, + (void *)&cmd_set_vxlan_eth_dst_value, + NULL, + }, +}; + cmdline_parse_inst_t cmd_set_vxlan_with_vlan = { .f = cmd_set_vxlan_parsed, .data = NULL, @@ -18696,6 +18758,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default, #endif (cmdline_parse_inst_t *)&cmd_set_vxlan, + (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl, (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan, (cmdline_parse_inst_t *)&cmd_set_nvgre, (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan, diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 659908fcf1..36659a64af 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -3501,6 +3501,38 @@ parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token, if (!vxlan_encap_conf.select_vlan) action_vxlan_encap_data->items[1].type = RTE_FLOW_ITEM_TYPE_VOID; + if (vxlan_encap_conf.select_tos_ttl) { + if (vxlan_encap_conf.select_ipv4) { + static struct rte_flow_item_ipv4 ipv4_mask_tos; + + memcpy(&ipv4_mask_tos, &rte_flow_item_ipv4_mask, + sizeof(ipv4_mask_tos)); + ipv4_mask_tos.hdr.type_of_service = 0xff; + ipv4_mask_tos.hdr.time_to_live = 0xff; + action_vxlan_encap_data->item_ipv4.hdr.type_of_service = + vxlan_encap_conf.ip_tos; + action_vxlan_encap_data->item_ipv4.hdr.time_to_live = + vxlan_encap_conf.ip_ttl; + action_vxlan_encap_data->items[2].mask = + &ipv4_mask_tos; + } else { + static struct rte_flow_item_ipv6 ipv6_mask_tos; + + memcpy(&ipv6_mask_tos, &rte_flow_item_ipv6_mask, + sizeof(ipv6_mask_tos)); + ipv6_mask_tos.hdr.vtc_flow |= + RTE_BE32(0xfful << IPV6_HDR_TC_SHIFT); + ipv6_mask_tos.hdr.hop_limits = 0xff; + action_vxlan_encap_data->item_ipv6.hdr.vtc_flow |= + rte_cpu_to_be_32 + ((uint32_t)vxlan_encap_conf.ip_tos << + IPV6_HDR_TC_SHIFT); + action_vxlan_encap_data->item_ipv6.hdr.hop_limits = + vxlan_encap_conf.ip_ttl; + action_vxlan_encap_data->items[2].mask = + &ipv6_mask_tos; + } + } memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni, RTE_DIM(vxlan_encap_conf.vni)); action->conf = &action_vxlan_encap_data->conf; diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 15a948828c..98c1baa8b1 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -469,6 +469,7 @@ uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES; struct vxlan_encap_conf vxlan_encap_conf = { .select_ipv4 = 1, .select_vlan = 0, + .select_tos_ttl = 0, .vni = "\x00\x00\x00", .udp_src = 0, .udp_dst = RTE_BE16(4789), @@ -479,6 +480,8 @@ struct vxlan_encap_conf vxlan_encap_conf = { .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x11\x11", .vlan_tci = 0, + .ip_tos = 0, + .ip_ttl = 255, .eth_src = "\x00\x00\x00\x00\x00\x00", .eth_dst = "\xff\xff\xff\xff\xff\xff", }; diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 3ff11e6442..fa48878538 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -488,6 +488,7 @@ extern uint16_t gso_max_segment_size; struct vxlan_encap_conf { uint32_t select_ipv4:1; uint32_t select_vlan:1; + uint32_t select_tos_ttl:1; uint8_t vni[3]; rte_be16_t udp_src; rte_be16_t udp_dst; @@ -496,6 +497,8 @@ struct vxlan_encap_conf { uint8_t ipv6_src[16]; uint8_t ipv6_dst[16]; rte_be16_t vlan_tci; + uint8_t ip_tos; + uint8_t ip_ttl; uint8_t eth_src[ETHER_ADDR_LEN]; uint8_t eth_dst[ETHER_ADDR_LEN]; }; diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 854af2d5fb..0291480410 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -1583,6 +1583,10 @@ Configure the outer layer to encapsulate a packet inside a VXLAN tunnel:: udp-dst (udp-dst) ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci) \ eth-src (eth-src) eth-dst (eth-dst) + set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src (udp-src) \ + udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl) ip-src (ip-src) \ + ip-dst (ip-dst) eth-src (eth-src) eth-dst (eth-dst) + Those command will set an internal configuration inside testpmd, any following flow rule using the action vxlan_encap will use the last configuration set. To have a different encapsulation header, one of those commands must be called @@ -4241,6 +4245,12 @@ IPv4 VXLAN outer header:: testpmd> flow create 0 ingress pattern end actions vxlan_encap / queue index 0 / end + testpmd> set vxlan-tos-ttl ip-version ipv4 vni 4 udp-src 4 udp-dst 4 ip-tos 0 + ip-ttl 255 ip-src 127.0.0.1 ip-dst 128.0.0.1 eth-src 11:11:11:11:11:11 + eth-dst 22:22:22:22:22:22 + testpmd> flow create 0 ingress pattern end actions vxlan_encap / + queue index 0 / end + IPv6 VXLAN outer header:: testpmd> set vxlan ip-version ipv6 vni 4 udp-src 4 udp-dst 4 ip-src ::1 @@ -4254,6 +4264,12 @@ IPv6 VXLAN outer header:: testpmd> flow create 0 ingress pattern end actions vxlan_encap / queue index 0 / end + testpmd> set vxlan-tos-ttl ip-version ipv6 vni 4 udp-src 4 udp-dst 4 + ip-tos 0 ip-ttl 255 ::1 ip-dst ::2222 eth-src 11:11:11:11:11:11 + eth-dst 22:22:22:22:22:22 + testpmd> flow create 0 ingress pattern end actions vxlan_encap / + queue index 0 / end + Sample NVGRE encapsulation rule ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~