From 2681b1f0ac7644490df9bbd125ae18e15ba33c19 Mon Sep 17 00:00:00 2001 From: Satish Pitchikala Date: Fri, 9 Feb 2024 07:20:28 +0530 Subject: [PATCH] geneve support in LNW.p4 (#394) * geneve support in LNW.p4 Signed-off-by: Satish Pitchikala * added actions for geneve Signed-off-by: Satish Pitchikala * geneve dcap actions Signed-off-by: Satish Pitchikala * fix for dpdk target build fail Signed-off-by: Satish Pitchikala * fix for issue while deleting entries Signed-off-by: Satish Pitchikala * updated ovs refpoint Signed-off-by: Satish Pitchikala * Update ovs-p4rt/ovs_p4rt.cc Co-authored-by: Derek G Foster Signed-off-by: Satish Pitchikala * Update ovs-p4rt/ovs_p4rt.cc Co-authored-by: Derek G Foster Signed-off-by: Satish Pitchikala * Update ovs-p4rt/ovs_p4rt.cc Co-authored-by: Derek G Foster Signed-off-by: Satish Pitchikala * Update ovs-p4rt/ovs_p4rt.cc Co-authored-by: Derek G Foster Signed-off-by: Satish Pitchikala * Bump robinraju/release-downloader from 1.8 to 1.9 (#400) Bumps [robinraju/release-downloader](https://github.com/robinraju/release-downloader) from 1.8 to 1.9. - [Release notes](https://github.com/robinraju/release-downloader/releases) - [Commits](https://github.com/robinraju/release-downloader/compare/v1.8...v1.9) --- updated-dependencies: - dependency-name: robinraju/release-downloader dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Satish Pitchikala * Bump tj-actions/changed-files from 41 to 42 (#399) Bumps [tj-actions/changed-files](https://github.com/tj-actions/changed-files) from 41 to 42. - [Release notes](https://github.com/tj-actions/changed-files/releases) - [Changelog](https://github.com/tj-actions/changed-files/blob/main/HISTORY.md) - [Commits](https://github.com/tj-actions/changed-files/compare/v41...v42) --- updated-dependencies: - dependency-name: tj-actions/changed-files dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Satish Pitchikala * Refine p4cp github lint workflows (#398) - Rename lintdocs.yml to linters.yml. - Move py_bandit_check and clang_format_check to linters.yml. - Expand py_bandit_check to apply to all .py files. Signed-off-by: Derek G Foster Signed-off-by: Satish Pitchikala * P4CP : DefaultActionSupport (#397) * P4Runtime Client Changes Signed-off-by: Kumar, Aashish * Addressing comments Signed-off-by: Kumar, Aashish * Addressing comments Signed-off-by: Kumar, Aashish --------- Signed-off-by: Kumar, Aashish Signed-off-by: Satish Pitchikala * Update krnlmon submodule reference (#401) Signed-off-by: Kumar, Aashish Signed-off-by: Satish Pitchikala * clang format the code Signed-off-by: Satish Pitchikala * fix for ipv6 tunnel port Signed-off-by: Satish Pitchikala * Addressing review comments Signed-off-by: Satish Pitchikala --------- Signed-off-by: Satish Pitchikala Signed-off-by: dependabot[bot] Signed-off-by: Derek G Foster Signed-off-by: Kumar, Aashish Co-authored-by: Derek G Foster Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: aashishkuma --- ovs-p4rt/es2k/p4_name_mapping.h | 132 +++++- ovs-p4rt/ovs_p4rt.cc | 740 +++++++++++++++++++++++++++++--- ovs/ovs | 2 +- 3 files changed, 786 insertions(+), 88 deletions(-) diff --git a/ovs-p4rt/es2k/p4_name_mapping.h b/ovs-p4rt/es2k/p4_name_mapping.h index 5a56a344..1b64914f 100644 --- a/ovs-p4rt/es2k/p4_name_mapping.h +++ b/ovs-p4rt/es2k/p4_name_mapping.h @@ -58,7 +58,7 @@ extern "C" { #define ACTION_VXLAN_ENCAP_V6_PARAM_DS "ds" #define ACTION_VXLAN_ENCAP_V6_PARAM_ECN "ecn" #define ACTION_VXLAN_ENCAP_V6_PARAM_FLOW_LABEL "flow_label" -#define ACTION_VXLAN_ENCAP_V6_PARAM_hop_limit "hop_limit" +#define ACTION_VXLAN_ENCAP_V6_PARAM_HOP_LIMIT "hop_limit" #define ACTION_VXLAN_ENCAP_V6_PARAM_SRC_PORT "src_port" #define ACTION_VXLAN_ENCAP_V6_PARAM_DST_PORT "dst_port" #define ACTION_VXLAN_ENCAP_V6_PARAM_VNI "vni" @@ -77,11 +77,77 @@ extern "C" { #define ACTION_VXLAN_ENCAP_V6_VLAN_POP_PARAM_DS "ds" #define ACTION_VXLAN_ENCAP_V6_VLAN_POP_PARAM_ECN "ecn" #define ACTION_VXLAN_ENCAP_V6_VLAN_POP_PARAM_FLOW_LABEL "flow_label" -#define ACTION_VXLAN_ENCAP_V6_VLAN_POP_PARAM_hop_limit "hop_limit" +#define ACTION_VXLAN_ENCAP_V6_VLAN_POP_PARAM_HOP_LIMIT "hop_limit" #define ACTION_VXLAN_ENCAP_V6_VLAN_POP_PARAM_SRC_PORT "src_port" #define ACTION_VXLAN_ENCAP_V6_VLAN_POP_PARAM_DST_PORT "dst_port" #define ACTION_VXLAN_ENCAP_V6_VLAN_POP_PARAM_VNI "vni" +/* GENEVE_ENCAP_MOD_TABLE */ +#define GENEVE_ENCAP_MOD_TABLE "linux_networking_control.geneve_encap_mod_table" + +#define GENEVE_ENCAP_MOD_TABLE_KEY_VENDORMETA_MOD_DATA_PTR \ + "vmeta.common.mod_blob_ptr" + +#define ACTION_GENEVE_ENCAP "linux_networking_control.geneve_encap" +#define ACTION_GENEVE_ENCAP_PARAM_SRC_ADDR "src_addr" +#define ACTION_GENEVE_ENCAP_PARAM_DST_ADDR "dst_addr" +#define ACTION_GENEVE_ENCAP_PARAM_DST_PORT "dst_port" +#define ACTION_GENEVE_ENCAP_PARAM_SRC_PORT "src_port" +#define ACTION_GENEVE_ENCAP_PARAM_VNI "vni" + +/* GENEVE_ENCAP_VLAN_POP_MOD_TABLE */ +#define GENEVE_ENCAP_VLAN_POP_MOD_TABLE \ + "linux_networking_control.geneve_encap_vlan_pop_mod_table" + +#define GENEVE_ENCAP_VLAN_POP_MOD_TABLE_KEY_VENDORMETA_MOD_DATA_PTR \ + "vmeta.common.mod_blob_ptr" + +#define ACTION_GENEVE_ENCAP_VLAN_POP \ + "linux_networking_control.geneve_encap_vlan_pop" + +#define ACTION_GENEVE_ENCAP_VLAN_POP_PARAM_SRC_ADDR "src_addr" +#define ACTION_GENEVE_ENCAP_VLAN_POP_PARAM_DST_ADDR "dst_addr" +#define ACTION_GENEVE_ENCAP_VLAN_POP_PARAM_DST_PORT "dst_port" +#define ACTION_GENEVE_ENCAP_VLAN_POP_PARAM_SRC_PORT "src_port" +#define ACTION_GENEVE_ENCAP_VLAN_POP_PARAM_VNI "vni" + +/* GENEVE_ENCAP_V6_MOD_TABLE */ +#define GENEVE_ENCAP_V6_MOD_TABLE \ + "linux_networking_control.geneve_encap_v6_mod_table" + +#define GENEVE_ENCAP_V6_MOD_TABLE_KEY_VENDORMETA_MOD_DATA_PTR \ + "vmeta.common.mod_blob_ptr" + +#define ACTION_GENEVE_ENCAP_V6 "linux_networking_control.geneve_encap_v6" +#define ACTION_GENEVE_ENCAP_V6_PARAM_SRC_ADDR "src_addr" +#define ACTION_GENEVE_ENCAP_V6_PARAM_DST_ADDR "dst_addr" +#define ACTION_GENEVE_ENCAP_V6_PARAM_DS "ds" +#define ACTION_GENEVE_ENCAP_V6_PARAM_ECN "ecn" +#define ACTION_GENEVE_ENCAP_V6_PARAM_FLOW_LABEL "flow_label" +#define ACTION_GENEVE_ENCAP_V6_PARAM_HOP_LIMIT "hop_limit" +#define ACTION_GENEVE_ENCAP_V6_PARAM_SRC_PORT "src_port" +#define ACTION_GENEVE_ENCAP_V6_PARAM_DST_PORT "dst_port" +#define ACTION_GENEVE_ENCAP_V6_PARAM_VNI "vni" + +/* GENEVE_ENCAP_V6_VLAN_POP_MOD_TABLE */ +#define GENEVE_ENCAP_V6_VLAN_POP_MOD_TABLE \ + "linux_networking_control.geneve_encap_v6_vlan_pop_mod_table" + +#define GENEVE_ENCAP_V6_VLAN_POP_MOD_TABLE_KEY_VENDORMETA_MOD_DATA_PTR \ + "vmeta.common.mod_blob_ptr" + +#define ACTION_GENEVE_ENCAP_V6_VLAN_POP \ + "linux_networking_control.geneve_encap_v6_vlan_pop" +#define ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_SRC_ADDR "src_addr" +#define ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_DST_ADDR "dst_addr" +#define ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_DS "ds" +#define ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_ECN "ecn" +#define ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_FLOW_LABEL "flow_label" +#define ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_HOP_LIMIT "hop_limit" +#define ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_SRC_PORT "src_port" +#define ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_DST_PORT "dst_port" +#define ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_VNI "vni" + /* IPV4_TUNNEL_TERM_TABLE */ #define IPV4_TUNNEL_TERM_TABLE "linux_networking_control.ipv4_tunnel_term_table" @@ -90,12 +156,14 @@ extern "C" { #define IPV4_TUNNEL_TERM_TABLE_KEY_IPV4_DST "ipv4_dst" #define IPV4_TUNNEL_TERM_TABLE_KEY_VNI "vni" -#define ACTION_DECAP_OUTER_HDR "linux_networking_control.decap_outer_hdr" -#define ACTION_DECAP_OUTER_HDR_PARAM_TUNNEL_ID "tunnel_id" - -#define ACTION_DECAP_OUTER_HDR_AND_PUSH_VLAN \ - "linux_networking_control.decap_outer_and_push_vlan" -#define ACTION_DECAP_OUTER_HDR_AND_PUSH_VLAN_PARAM_TUNNEL_ID "tunnel_id" +#define ACTION_SET_VXLAN_DECAP_OUTER_HDR \ + "linux_networking_control.set_vxlan_decap_outer_hdr" +#define ACTION_SET_VXLAN_DECAP_OUTER_HDR_AND_PUSH_VLAN \ + "linux_networking_control.set_vxlan_decap_outer_and_push_vlan" +#define ACTION_SET_GENEVE_DECAP_OUTER_HDR \ + "linux_networking_control.set_geneve_decap_outer_hdr" +#define ACTION_SET_GENEVE_DECAP_OUTER_HDR_AND_PUSH_VLAN \ + "linux_networking_control.set_geneve_decap_outer_and_push_vlan" /* IPV6_TUNNEL_TERM_TABLE */ #define IPV6_TUNNEL_TERM_TABLE "linux_networking_control.ipv6_tunnel_term_table" @@ -122,6 +190,24 @@ extern "C" { #define ACTION_VXLAN_DECAP_AND_PUSH_VLAN_PARAM_DEI "dei" #define ACTION_VXLAN_DECAP_AND_PUSH_VLAN_PARAM_VLAN_ID "vlan_id" +/* GENEVE_DECAP_MOD TABLE */ +#define GENEVE_DECAP_MOD_TABLE "linux_networking_control.geneve_decap_mod_table" +#define GENEVE_DECAP_MOD_TABLE_KEY_MOD_BLOB_PTR "vmeta.common.mod_blob_ptr" +#define ACTION_GENEVE_DECAP_OUTER_HDR \ + "linux_networking_control.geneve_decap_outer_hdr" + +/* GENEVE_DECAP_AND_VLAN_PUSH_MOD TABLE */ +#define GENEVE_DECAP_AND_VLAN_PUSH_MOD_TABLE \ + "linux_networking_control.geneve_decap_and_push_vlan_mod_table" +#define GENEVE_DECAP_AND_VLAN_PUSH_MOD_TABLE_KEY_MOD_BLOB_PTR \ + "vmeta.common.mod_blob_ptr" + +#define ACTION_GENEVE_DECAP_AND_PUSH_VLAN \ + "linux_networking_control.geneve_decap_and_push_vlan" +#define ACTION_GENEVE_DECAP_AND_PUSH_VLAN_PARAM_PCP "pcp" +#define ACTION_GENEVE_DECAP_AND_PUSH_VLAN_PARAM_DEI "dei" +#define ACTION_GENEVE_DECAP_AND_PUSH_VLAN_PARAM_VLAN_ID "vlan_id" + /* L2_FWD_RX_TABLE */ #define L2_FWD_RX_TABLE "linux_networking_control.l2_fwd_rx_table" @@ -159,25 +245,31 @@ extern "C" { #define L2_FWD_TX_TABLE_ACTION_L2_FWD "linux_networking_control.l2_fwd" -#define L2_FWD_TX_TABLE_ACTION_SET_TUNNEL_UNDERLAY_V4 \ - "linux_networking_control.set_tunnel_underlay_v4" +#define L2_FWD_TX_TABLE_ACTION_SET_VXLAN_UNDERLAY_V4 \ + "linux_networking_control.set_vxlan_underlay_v4" + +#define L2_FWD_TX_TABLE_ACTION_SET_GENEVE_UNDERLAY_V4 \ + "linux_networking_control.set_geneve_underlay_v4" -#define ACTION_SET_TUNNEL_UNDERLAY_V4_PARAM_TUNNEL_ID "tunnel_id" +#define L2_FWD_TX_TABLE_ACTION_SET_VXLAN_UNDERLAY_V6 \ + "linux_networking_control.set_vxlan_underlay_v6" -#define L2_FWD_TX_TABLE_ACTION_SET_TUNNEL_UNDERLAY_V6 \ - "linux_networking_control.set_tunnel_underlay_v6" +#define L2_FWD_TX_TABLE_ACTION_SET_GENEVE_UNDERLAY_V6 \ + "linux_networking_control.set_geneve_underlay_v6" -#define ACTION_SET_TUNNEL_UNDERLAY_V6_PARAM_TUNNEL_ID "tunnel_id" +#define L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_VXLAN_UNDERLAY_V4 \ + "linux_networking_control.pop_vlan_set_vxlan_underlay_v4" -#define L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_TUNNEL_UNDERLAY_V4 \ - "linux_networking_control.pop_vlan_set_tunnel_underlay_v4" +#define L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_GENEVE_UNDERLAY_V4 \ + "linux_networking_control.pop_vlan_set_geneve_underlay_v4" -#define ACTION_POP_VLAN_SET_TUNNEL_UNDERLAY_V4_PARAM_TUNNEL_ID "tunnel_id" +#define L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_VXLAN_UNDERLAY_V6 \ + "linux_networking_control.pop_vlan_set_vxlan_underlay_v6" -#define L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_TUNNEL_UNDERLAY_V6 \ - "linux_networking_control.pop_vlan_set_tunnel_underlay_v6" +#define L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_GENEVE_UNDERLAY_V6 \ + "linux_networking_control.pop_vlan_set_geneve_underlay_v6" -#define ACTION_POP_VLAN_SET_TUNNEL_UNDERLAY_V6_PARAM_TUNNEL_ID "tunnel_id" +#define ACTION_PARAM_TUNNEL_ID "tunnel_id" #define L2_FWD_TX_TABLE_ACTION_ADD_VLAN_AND_FWD \ "linux_networking_control.add_vlan_and_fwd" diff --git a/ovs-p4rt/ovs_p4rt.cc b/ovs-p4rt/ovs_p4rt.cc index 314c9921..76222544 100644 --- a/ovs-p4rt/ovs_p4rt.cc +++ b/ovs-p4rt/ovs_p4rt.cc @@ -278,10 +278,115 @@ void PrepareFdbRxVlanTableEntry(p4::v1::TableEntry* table_entry, } #endif -void PrepareFdbTableEntryforV4Tunnel(p4::v1::TableEntry* table_entry, - const struct mac_learning_info& learn_info, - const ::p4::config::v1::P4Info& p4info, - bool insert_entry) { +void PrepareFdbTableEntryforV4VxlanTunnel( + p4::v1::TableEntry* table_entry, const struct mac_learning_info& learn_info, + const ::p4::config::v1::P4Info& p4info, bool insert_entry) { + table_entry->set_table_id(GetTableId(p4info, L2_FWD_TX_TABLE)); + auto match = table_entry->add_match(); + match->set_field_id( + GetMatchFieldId(p4info, L2_FWD_TX_TABLE, L2_FWD_TX_TABLE_KEY_DST_MAC)); + + std::string mac_addr = CanonicalizeMac(learn_info.mac_addr); + match->mutable_exact()->set_value(mac_addr); +#if defined(ES2K_TARGET) + // Based on p4 program for ES2K, we need to provide a match key Bridge ID + auto match1 = table_entry->add_match(); + match1->set_field_id( + GetMatchFieldId(p4info, L2_FWD_TX_TABLE, L2_FWD_TX_TABLE_KEY_BRIDGE_ID)); + + match1->mutable_exact()->set_value(EncodeByteValue(1, learn_info.bridge_id)); + + // Based on p4 program for ES2K, we need to provide a match key SMAC flag + auto match2 = table_entry->add_match(); + match2->set_field_id(GetMatchFieldId(p4info, L2_FWD_TX_TABLE, + L2_FWD_TX_TABLE_KEY_SMAC_LEARNED)); + + match2->mutable_exact()->set_value(EncodeByteValue(1, 1)); + +#endif + +#if defined(DPDK_TARGET) + if (insert_entry) { + auto table_action = table_entry->mutable_action(); + auto action = table_action->mutable_action(); + action->set_action_id( + GetActionId(p4info, L2_FWD_TX_TABLE_ACTION_SET_TUNNEL)); + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, L2_FWD_TX_TABLE_ACTION_SET_TUNNEL, + ACTION_SET_TUNNEL_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, learn_info.tnl_info.vni)); + } + + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, L2_FWD_TX_TABLE_ACTION_SET_TUNNEL, + ACTION_SET_TUNNEL_PARAM_DST_ADDR)); + std::string ip_address = + CanonicalizeIp(learn_info.tnl_info.remote_ip.ip.v4addr.s_addr); + param->set_value(ip_address); + } + } +#elif defined(ES2K_TARGET) + if (insert_entry) { + auto table_action = table_entry->mutable_action(); + auto action = table_action->mutable_action(); + + if (learn_info.tnl_info.local_ip.family == AF_INET && + learn_info.tnl_info.remote_ip.family == AF_INET) { + if (learn_info.vlan_info.port_vlan_mode == P4_PORT_VLAN_NATIVE_UNTAGGED) { + action->set_action_id(GetActionId( + p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_VXLAN_UNDERLAY_V4)); + { + auto param = action->add_params(); + param->set_param_id(GetParamId( + p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_VXLAN_UNDERLAY_V4, + ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, learn_info.tnl_info.vni)); + } + } else { + action->set_action_id( + GetActionId(p4info, L2_FWD_TX_TABLE_ACTION_SET_VXLAN_UNDERLAY_V4)); + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, L2_FWD_TX_TABLE_ACTION_SET_VXLAN_UNDERLAY_V4, + ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, learn_info.tnl_info.vni)); + } + } + } else if (learn_info.tnl_info.local_ip.family == AF_INET6 && + learn_info.tnl_info.remote_ip.family == AF_INET6) { + if (learn_info.vlan_info.port_vlan_mode == P4_PORT_VLAN_NATIVE_UNTAGGED) { + action->set_action_id(GetActionId( + p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_VXLAN_UNDERLAY_V6)); + { + auto param = action->add_params(); + param->set_param_id(GetParamId( + p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_VXLAN_UNDERLAY_V6, + ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, learn_info.tnl_info.vni)); + } + } else { + action->set_action_id( + GetActionId(p4info, L2_FWD_TX_TABLE_ACTION_SET_VXLAN_UNDERLAY_V6)); + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, L2_FWD_TX_TABLE_ACTION_SET_VXLAN_UNDERLAY_V6, + ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, learn_info.tnl_info.vni)); + } + } + } + } +#endif + return; +} + +void PrepareFdbTableEntryforV4GeneveTunnel( + p4::v1::TableEntry* table_entry, const struct mac_learning_info& learn_info, + const ::p4::config::v1::P4Info& p4info, bool insert_entry) { table_entry->set_table_id(GetTableId(p4info, L2_FWD_TX_TABLE)); auto match = table_entry->add_match(); match->set_field_id( @@ -337,22 +442,22 @@ void PrepareFdbTableEntryforV4Tunnel(p4::v1::TableEntry* table_entry, learn_info.tnl_info.remote_ip.family == AF_INET) { if (learn_info.vlan_info.port_vlan_mode == P4_PORT_VLAN_NATIVE_UNTAGGED) { action->set_action_id(GetActionId( - p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_TUNNEL_UNDERLAY_V4)); + p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_GENEVE_UNDERLAY_V4)); { auto param = action->add_params(); param->set_param_id(GetParamId( - p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_TUNNEL_UNDERLAY_V4, - ACTION_POP_VLAN_SET_TUNNEL_UNDERLAY_V4_PARAM_TUNNEL_ID)); + p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_GENEVE_UNDERLAY_V4, + ACTION_PARAM_TUNNEL_ID)); param->set_value(EncodeByteValue(1, learn_info.tnl_info.vni)); } } else { action->set_action_id( - GetActionId(p4info, L2_FWD_TX_TABLE_ACTION_SET_TUNNEL_UNDERLAY_V4)); + GetActionId(p4info, L2_FWD_TX_TABLE_ACTION_SET_GENEVE_UNDERLAY_V4)); { auto param = action->add_params(); param->set_param_id( - GetParamId(p4info, L2_FWD_TX_TABLE_ACTION_SET_TUNNEL_UNDERLAY_V4, - ACTION_SET_TUNNEL_UNDERLAY_V4_PARAM_TUNNEL_ID)); + GetParamId(p4info, L2_FWD_TX_TABLE_ACTION_SET_GENEVE_UNDERLAY_V4, + ACTION_PARAM_TUNNEL_ID)); param->set_value(EncodeByteValue(1, learn_info.tnl_info.vni)); } } @@ -360,22 +465,22 @@ void PrepareFdbTableEntryforV4Tunnel(p4::v1::TableEntry* table_entry, learn_info.tnl_info.remote_ip.family == AF_INET6) { if (learn_info.vlan_info.port_vlan_mode == P4_PORT_VLAN_NATIVE_UNTAGGED) { action->set_action_id(GetActionId( - p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_TUNNEL_UNDERLAY_V6)); + p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_GENEVE_UNDERLAY_V6)); { auto param = action->add_params(); param->set_param_id(GetParamId( - p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_TUNNEL_UNDERLAY_V6, - ACTION_POP_VLAN_SET_TUNNEL_UNDERLAY_V6_PARAM_TUNNEL_ID)); + p4info, L2_FWD_TX_TABLE_ACTION_POP_VLAN_SET_GENEVE_UNDERLAY_V6, + ACTION_PARAM_TUNNEL_ID)); param->set_value(EncodeByteValue(1, learn_info.tnl_info.vni)); } } else { action->set_action_id( - GetActionId(p4info, L2_FWD_TX_TABLE_ACTION_SET_TUNNEL_UNDERLAY_V6)); + GetActionId(p4info, L2_FWD_TX_TABLE_ACTION_SET_GENEVE_UNDERLAY_V6)); { auto param = action->add_params(); param->set_param_id( - GetParamId(p4info, L2_FWD_TX_TABLE_ACTION_SET_TUNNEL_UNDERLAY_V6, - ACTION_SET_TUNNEL_UNDERLAY_V6_PARAM_TUNNEL_ID)); + GetParamId(p4info, L2_FWD_TX_TABLE_ACTION_SET_GENEVE_UNDERLAY_V6, + ACTION_PARAM_TUNNEL_ID)); param->set_value(EncodeByteValue(1, learn_info.tnl_info.vni)); } } @@ -555,15 +660,35 @@ absl::Status ConfigFdbTunnelTableEntry( table_entry = ovs_p4rt::SetupTableEntryToDelete(session, &write_request); } - PrepareFdbTableEntryforV4Tunnel(table_entry, learn_info, p4info, - insert_entry); +#if defined(DPDK_TARGET) + PrepareFdbTableEntryforV4VxlanTunnel(table_entry, learn_info, p4info, + insert_entry); +#elif defined(ES2K_TARGET) + if (learn_info.tnl_info.tunnel_type == OVS_TUNNEL_VXLAN) { + PrepareFdbTableEntryforV4VxlanTunnel(table_entry, learn_info, p4info, + insert_entry); + } else if (learn_info.tnl_info.tunnel_type == OVS_TUNNEL_GENEVE) { + PrepareFdbTableEntryforV4GeneveTunnel(table_entry, learn_info, p4info, + insert_entry); + } else { + if (!insert_entry) { + // Tunnel type doesn't matter for delete. So calling one of the functions + // to prepare the entry + PrepareFdbTableEntryforV4VxlanTunnel(table_entry, learn_info, p4info, + insert_entry); + } + } +#else +#error "Unsupported target" +#endif return ovs_p4rt::SendWriteRequest(session, write_request); } -void PrepareEncapTableEntry(p4::v1::TableEntry* table_entry, - const struct tunnel_info& tunnel_info, - const ::p4::config::v1::P4Info& p4info, - bool insert_entry) { +/* VXLAN_ENCAP_MOD_TABLE */ +void PrepareVxlanEncapTableEntry(p4::v1::TableEntry* table_entry, + const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, + bool insert_entry) { table_entry->set_table_id(GetTableId(p4info, VXLAN_ENCAP_MOD_TABLE)); auto match = table_entry->add_match(); match->set_field_id( @@ -619,10 +744,91 @@ void PrepareEncapTableEntry(p4::v1::TableEntry* table_entry, } #if defined(ES2K_TARGET) -void PrepareV6EncapTableEntry(p4::v1::TableEntry* table_entry, - const struct tunnel_info& tunnel_info, - const ::p4::config::v1::P4Info& p4info, - bool insert_entry) { +/* GENEVE_ENCAP_MOD_TABLE */ +void PrepareGeneveEncapTableEntry(p4::v1::TableEntry* table_entry, + const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, + bool insert_entry) { + table_entry->set_table_id(GetTableId(p4info, GENEVE_ENCAP_MOD_TABLE)); + auto match = table_entry->add_match(); + match->set_field_id( + GetMatchFieldId(p4info, GENEVE_ENCAP_MOD_TABLE, + GENEVE_ENCAP_MOD_TABLE_KEY_VENDORMETA_MOD_DATA_PTR)); + match->mutable_exact()->set_value(EncodeByteValue(1, tunnel_info.vni)); + + if (insert_entry) { + auto table_action = table_entry->mutable_action(); + auto action = table_action->mutable_action(); + action->set_action_id(GetActionId(p4info, ACTION_GENEVE_ENCAP)); + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_GENEVE_ENCAP, + ACTION_GENEVE_ENCAP_PARAM_SRC_ADDR)); + param->set_value(CanonicalizeIp(tunnel_info.local_ip.ip.v4addr.s_addr)); + } + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_GENEVE_ENCAP, + ACTION_GENEVE_ENCAP_PARAM_DST_ADDR)); + param->set_value(CanonicalizeIp(tunnel_info.remote_ip.ip.v4addr.s_addr)); + } + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_GENEVE_ENCAP, + ACTION_GENEVE_ENCAP_PARAM_SRC_PORT)); + uint16_t dst_port = htons(tunnel_info.dst_port); + + param->set_value(EncodeByteValue(2, (((dst_port * 2) >> 8) & 0xff), + ((dst_port * 2) & 0xff))); + } + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_GENEVE_ENCAP, + ACTION_GENEVE_ENCAP_PARAM_DST_PORT)); + uint16_t dst_port = htons(tunnel_info.dst_port); + + param->set_value( + EncodeByteValue(2, ((dst_port >> 8) & 0xff), (dst_port & 0xff))); + } + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_GENEVE_ENCAP, + ACTION_GENEVE_ENCAP_PARAM_VNI)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } + } + + return; +} +#endif + +void PrepareEncapTableEntry(p4::v1::TableEntry* table_entry, + const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, + bool insert_entry) { +#if defined(DPDK_TARGET) + PrepareVxlanEncapTableEntry(table_entry, tunnel_info, p4info, insert_entry); +#elif defined(ES2K_TARGET) + if (tunnel_info.tunnel_type == OVS_TUNNEL_VXLAN) { + PrepareVxlanEncapTableEntry(table_entry, tunnel_info, p4info, insert_entry); + } else if (tunnel_info.tunnel_type == OVS_TUNNEL_GENEVE) { + PrepareGeneveEncapTableEntry(table_entry, tunnel_info, p4info, + insert_entry); + } else { + std::cout << "ERROR: Unsupported tunnel type" << std::endl; + } +#endif + + return; +} + +#if defined(ES2K_TARGET) + +/* VXLAN_ENCAP_V6_MOD_TABLE */ +void PrepareV6VxlanEncapTableEntry(p4::v1::TableEntry* table_entry, + const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, + bool insert_entry) { table_entry->set_table_id(GetTableId(p4info, VXLAN_ENCAP_V6_MOD_TABLE)); auto match = table_entry->add_match(); match->set_field_id( @@ -675,10 +881,84 @@ void PrepareV6EncapTableEntry(p4::v1::TableEntry* table_entry, return; } -void PrepareEncapAndVlanPopTableEntry(p4::v1::TableEntry* table_entry, - const struct tunnel_info& tunnel_info, - const ::p4::config::v1::P4Info& p4info, - bool insert_entry) { +/* GENEVE_ENCAP_V6_MOD_TABLE */ +void PrepareV6GeneveEncapTableEntry(p4::v1::TableEntry* table_entry, + const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, + bool insert_entry) { + table_entry->set_table_id(GetTableId(p4info, GENEVE_ENCAP_V6_MOD_TABLE)); + auto match = table_entry->add_match(); + match->set_field_id( + GetMatchFieldId(p4info, GENEVE_ENCAP_V6_MOD_TABLE, + GENEVE_ENCAP_V6_MOD_TABLE_KEY_VENDORMETA_MOD_DATA_PTR)); + match->mutable_exact()->set_value(EncodeByteValue(1, tunnel_info.vni)); + + if (insert_entry) { + auto table_action = table_entry->mutable_action(); + auto action = table_action->mutable_action(); + action->set_action_id(GetActionId(p4info, ACTION_GENEVE_ENCAP_V6)); + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_GENEVE_ENCAP_V6, + ACTION_GENEVE_ENCAP_V6_PARAM_SRC_ADDR)); + param->set_value(CanonicalizeIpv6(tunnel_info.local_ip.ip.v6addr)); + } + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_GENEVE_ENCAP_V6, + ACTION_GENEVE_ENCAP_V6_PARAM_DST_ADDR)); + param->set_value(CanonicalizeIpv6(tunnel_info.remote_ip.ip.v6addr)); + } + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_GENEVE_ENCAP_V6, + ACTION_GENEVE_ENCAP_V6_PARAM_SRC_PORT)); + uint16_t dst_port = htons(tunnel_info.dst_port); + + param->set_value(EncodeByteValue(2, ((dst_port * 2) >> 8) & 0xff, + (dst_port * 2) & 0xff)); + } + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_GENEVE_ENCAP_V6, + ACTION_GENEVE_ENCAP_V6_PARAM_DST_PORT)); + uint16_t dst_port = htons(tunnel_info.dst_port); + + param->set_value( + EncodeByteValue(2, (dst_port >> 8) & 0xff, dst_port & 0xff)); + } + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_GENEVE_ENCAP_V6, + ACTION_GENEVE_ENCAP_V6_PARAM_VNI)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } + } + + return; +} + +void PrepareV6EncapTableEntry(p4::v1::TableEntry* table_entry, + const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, + bool insert_entry) { + if (tunnel_info.tunnel_type == OVS_TUNNEL_VXLAN) { + PrepareV6VxlanEncapTableEntry(table_entry, tunnel_info, p4info, + insert_entry); + } else if (tunnel_info.tunnel_type == OVS_TUNNEL_GENEVE) { + PrepareV6GeneveEncapTableEntry(table_entry, tunnel_info, p4info, + insert_entry); + } else { + std::cout << "ERROR: Unsupported tunnel type" << std::endl; + } + + return; +} + +/* VXLAN_ENCAP_VLAN_POP_MOD_TABLE */ +void PrepareVxlanEncapAndVlanPopTableEntry( + p4::v1::TableEntry* table_entry, const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, bool insert_entry) { table_entry->set_table_id(GetTableId(p4info, VXLAN_ENCAP_VLAN_POP_MOD_TABLE)); auto match = table_entry->add_match(); match->set_field_id(GetMatchFieldId( @@ -735,10 +1015,88 @@ void PrepareEncapAndVlanPopTableEntry(p4::v1::TableEntry* table_entry, return; } -void PrepareV6EncapAndVlanPopTableEntry(p4::v1::TableEntry* table_entry, - const struct tunnel_info& tunnel_info, - const ::p4::config::v1::P4Info& p4info, - bool insert_entry) { +/* GENEVE_ENCAP_VLAN_POP_MOD_TABLE */ +void PrepareGeneveEncapAndVlanPopTableEntry( + p4::v1::TableEntry* table_entry, const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, bool insert_entry) { + table_entry->set_table_id( + GetTableId(p4info, GENEVE_ENCAP_VLAN_POP_MOD_TABLE)); + auto match = table_entry->add_match(); + match->set_field_id(GetMatchFieldId( + p4info, GENEVE_ENCAP_VLAN_POP_MOD_TABLE, + GENEVE_ENCAP_VLAN_POP_MOD_TABLE_KEY_VENDORMETA_MOD_DATA_PTR)); + match->mutable_exact()->set_value(EncodeByteValue(1, tunnel_info.vni)); + + if (insert_entry) { + auto table_action = table_entry->mutable_action(); + auto action = table_action->mutable_action(); + action->set_action_id(GetActionId(p4info, ACTION_GENEVE_ENCAP_VLAN_POP)); + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_ENCAP_VLAN_POP, + ACTION_GENEVE_ENCAP_VLAN_POP_PARAM_SRC_ADDR)); + param->set_value(CanonicalizeIp(tunnel_info.local_ip.ip.v4addr.s_addr)); + } + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_ENCAP_VLAN_POP, + ACTION_GENEVE_ENCAP_VLAN_POP_PARAM_DST_ADDR)); + param->set_value(CanonicalizeIp(tunnel_info.remote_ip.ip.v4addr.s_addr)); + } + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_ENCAP_VLAN_POP, + ACTION_GENEVE_ENCAP_VLAN_POP_PARAM_SRC_PORT)); + uint16_t dst_port = htons(tunnel_info.dst_port); + + param->set_value(EncodeByteValue(2, (((dst_port * 2) >> 8) & 0xff), + ((dst_port * 2) & 0xff))); + } + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_ENCAP_VLAN_POP, + ACTION_GENEVE_ENCAP_VLAN_POP_PARAM_DST_PORT)); + uint16_t dst_port = htons(tunnel_info.dst_port); + + param->set_value( + EncodeByteValue(2, ((dst_port >> 8) & 0xff), (dst_port & 0xff))); + } + { + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_GENEVE_ENCAP_VLAN_POP, + ACTION_GENEVE_ENCAP_VLAN_POP_PARAM_VNI)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } + } + + return; +} + +void PrepareEncapAndVlanPopTableEntry(p4::v1::TableEntry* table_entry, + const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, + bool insert_entry) { + if (tunnel_info.tunnel_type == OVS_TUNNEL_VXLAN) { + PrepareVxlanEncapAndVlanPopTableEntry(table_entry, tunnel_info, p4info, + insert_entry); + } else if (tunnel_info.tunnel_type == OVS_TUNNEL_GENEVE) { + PrepareGeneveEncapAndVlanPopTableEntry(table_entry, tunnel_info, p4info, + insert_entry); + } else { + std::cout << "ERROR: Unsupported tunnel type" << std::endl; + } + + return; +} + +/* VXLAN_ENCAP_V6_VLAN_POP_MOD_TABLE */ +void PrepareV6VxlanEncapAndVlanPopTableEntry( + p4::v1::TableEntry* table_entry, const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, bool insert_entry) { table_entry->set_table_id( GetTableId(p4info, VXLAN_ENCAP_V6_VLAN_POP_MOD_TABLE)); auto match = table_entry->add_match(); @@ -796,6 +1154,85 @@ void PrepareV6EncapAndVlanPopTableEntry(p4::v1::TableEntry* table_entry, return; } +/* GENEVE_ENCAP_V6_VLAN_POP_MOD_TABLE */ +void PrepareV6GeneveEncapAndVlanPopTableEntry( + p4::v1::TableEntry* table_entry, const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, bool insert_entry) { + table_entry->set_table_id( + GetTableId(p4info, GENEVE_ENCAP_V6_VLAN_POP_MOD_TABLE)); + auto match = table_entry->add_match(); + match->set_field_id(GetMatchFieldId( + p4info, GENEVE_ENCAP_V6_VLAN_POP_MOD_TABLE, + GENEVE_ENCAP_V6_VLAN_POP_MOD_TABLE_KEY_VENDORMETA_MOD_DATA_PTR)); + match->mutable_exact()->set_value(EncodeByteValue(1, tunnel_info.vni)); + + if (insert_entry) { + auto table_action = table_entry->mutable_action(); + auto action = table_action->mutable_action(); + action->set_action_id(GetActionId(p4info, ACTION_GENEVE_ENCAP_V6_VLAN_POP)); + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_ENCAP_V6_VLAN_POP, + ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_SRC_ADDR)); + param->set_value(CanonicalizeIpv6(tunnel_info.local_ip.ip.v6addr)); + } + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_ENCAP_V6_VLAN_POP, + ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_DST_ADDR)); + param->set_value(CanonicalizeIpv6(tunnel_info.remote_ip.ip.v6addr)); + } + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_ENCAP_V6_VLAN_POP, + ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_SRC_PORT)); + uint16_t dst_port = htons(tunnel_info.dst_port); + + param->set_value(EncodeByteValue(2, ((dst_port * 2) >> 8) & 0xff, + (dst_port * 2) & 0xff)); + } + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_ENCAP_V6_VLAN_POP, + ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_DST_PORT)); + uint16_t dst_port = htons(tunnel_info.dst_port); + + param->set_value( + EncodeByteValue(2, (dst_port >> 8) & 0xff, dst_port & 0xff)); + } + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_ENCAP_V6_VLAN_POP, + ACTION_GENEVE_ENCAP_V6_VLAN_POP_PARAM_VNI)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } + } + + return; +} + +void PrepareV6EncapAndVlanPopTableEntry(p4::v1::TableEntry* table_entry, + const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, + bool insert_entry) { + if (tunnel_info.tunnel_type == OVS_TUNNEL_VXLAN) { + PrepareV6VxlanEncapAndVlanPopTableEntry(table_entry, tunnel_info, p4info, + insert_entry); + } else if (tunnel_info.tunnel_type == OVS_TUNNEL_GENEVE) { + PrepareV6GeneveEncapAndVlanPopTableEntry(table_entry, tunnel_info, p4info, + insert_entry); + } else { + std::cout << "ERROR: Unsupported tunnel type" << std::endl; + } + + return; +} + void PrepareRxTunnelTableEntry(p4::v1::TableEntry* table_entry, const struct tunnel_info& tunnel_info, const ::p4::config::v1::P4Info& p4info, @@ -864,7 +1301,8 @@ void PrepareV6RxTunnelTableEntry(p4::v1::TableEntry* table_entry, param->set_param_id(GetParamId( p4info, RX_IPV6_TUNNEL_SOURCE_PORT_TABLE_ACTION_SET_SRC_PORT, ACTION_SET_SRC_PORT)); - param->set_value(EncodeByteValue(1, tunnel_info.src_port)); + param->set_value(EncodeByteValue(2, ((tunnel_info.src_port >> 8) & 0xff), + (tunnel_info.src_port & 0xff))); } } @@ -925,21 +1363,46 @@ void PrepareTunnelTermTableEntry(p4::v1::TableEntry* table_entry, auto table_action = table_entry->mutable_action(); auto action = table_action->mutable_action(); if (tunnel_info.vlan_info.port_vlan_mode == P4_PORT_VLAN_NATIVE_UNTAGGED) { - action->set_action_id( - GetActionId(p4info, ACTION_DECAP_OUTER_HDR_AND_PUSH_VLAN)); - auto param = action->add_params(); - param->set_param_id( - GetParamId(p4info, ACTION_DECAP_OUTER_HDR_AND_PUSH_VLAN, - ACTION_DECAP_OUTER_HDR_AND_PUSH_VLAN_PARAM_TUNNEL_ID)); - param->set_value(EncodeByteValue(1, tunnel_info.vni)); + if (tunnel_info.tunnel_type == OVS_TUNNEL_VXLAN) { + action->set_action_id(GetActionId( + p4info, ACTION_SET_VXLAN_DECAP_OUTER_HDR_AND_PUSH_VLAN)); + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_SET_VXLAN_DECAP_OUTER_HDR_AND_PUSH_VLAN, + ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } else if (tunnel_info.tunnel_type == OVS_TUNNEL_GENEVE) { + action->set_action_id(GetActionId( + p4info, ACTION_SET_GENEVE_DECAP_OUTER_HDR_AND_PUSH_VLAN)); + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_SET_GENEVE_DECAP_OUTER_HDR_AND_PUSH_VLAN, + ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } else { + std::cout << "Unsupported tunnel type" << std::endl; + } } else { - action->set_action_id(GetActionId(p4info, ACTION_DECAP_OUTER_HDR)); - auto param = action->add_params(); - param->set_param_id(GetParamId(p4info, ACTION_DECAP_OUTER_HDR, - ACTION_DECAP_OUTER_HDR_PARAM_TUNNEL_ID)); - param->set_value(EncodeByteValue(1, tunnel_info.vni)); + if (tunnel_info.tunnel_type == OVS_TUNNEL_VXLAN) { + action->set_action_id( + GetActionId(p4info, ACTION_SET_VXLAN_DECAP_OUTER_HDR)); + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_SET_VXLAN_DECAP_OUTER_HDR, + ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } else if (tunnel_info.tunnel_type == OVS_TUNNEL_GENEVE) { + action->set_action_id( + GetActionId(p4info, ACTION_SET_GENEVE_DECAP_OUTER_HDR)); + auto param = action->add_params(); + param->set_param_id(GetParamId( + p4info, ACTION_SET_GENEVE_DECAP_OUTER_HDR, ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } else { + std::cout << "Unsupported tunnel type" << std::endl; + } } } + #endif return; @@ -971,19 +1434,43 @@ void PrepareV6TunnelTermTableEntry(p4::v1::TableEntry* table_entry, auto table_action = table_entry->mutable_action(); auto action = table_action->mutable_action(); if (tunnel_info.vlan_info.port_vlan_mode == P4_PORT_VLAN_NATIVE_UNTAGGED) { - action->set_action_id( - GetActionId(p4info, ACTION_DECAP_OUTER_HDR_AND_PUSH_VLAN)); - auto param = action->add_params(); - param->set_param_id( - GetParamId(p4info, ACTION_DECAP_OUTER_HDR_AND_PUSH_VLAN, - ACTION_DECAP_OUTER_HDR_AND_PUSH_VLAN_PARAM_TUNNEL_ID)); - param->set_value(EncodeByteValue(1, tunnel_info.vni)); + if (tunnel_info.tunnel_type == OVS_TUNNEL_VXLAN) { + action->set_action_id(GetActionId( + p4info, ACTION_SET_VXLAN_DECAP_OUTER_HDR_AND_PUSH_VLAN)); + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_SET_VXLAN_DECAP_OUTER_HDR_AND_PUSH_VLAN, + ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } else if (tunnel_info.tunnel_type == OVS_TUNNEL_GENEVE) { + action->set_action_id(GetActionId( + p4info, ACTION_SET_GENEVE_DECAP_OUTER_HDR_AND_PUSH_VLAN)); + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_SET_GENEVE_DECAP_OUTER_HDR_AND_PUSH_VLAN, + ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } else { + std::cout << "Unsupported tunnel type" << std::endl; + } } else { - action->set_action_id(GetActionId(p4info, ACTION_DECAP_OUTER_HDR)); - auto param = action->add_params(); - param->set_param_id(GetParamId(p4info, ACTION_DECAP_OUTER_HDR, - ACTION_DECAP_OUTER_HDR_PARAM_TUNNEL_ID)); - param->set_value(EncodeByteValue(1, tunnel_info.vni)); + if (tunnel_info.tunnel_type == OVS_TUNNEL_VXLAN) { + action->set_action_id( + GetActionId(p4info, ACTION_SET_VXLAN_DECAP_OUTER_HDR)); + auto param = action->add_params(); + param->set_param_id(GetParamId(p4info, ACTION_SET_VXLAN_DECAP_OUTER_HDR, + ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } else if (tunnel_info.tunnel_type == OVS_TUNNEL_GENEVE) { + action->set_action_id( + GetActionId(p4info, ACTION_SET_GENEVE_DECAP_OUTER_HDR)); + auto param = action->add_params(); + param->set_param_id(GetParamId( + p4info, ACTION_SET_GENEVE_DECAP_OUTER_HDR, ACTION_PARAM_TUNNEL_ID)); + param->set_value(EncodeByteValue(1, tunnel_info.vni)); + } else { + std::cout << "Unsupported tunnel type" << std::endl; + } } } return; @@ -1025,17 +1512,17 @@ absl::Status ConfigEncapTableEntry(ovs_p4rt::OvsP4rtSession* session, } } #else - return absl::UnknownError("Unsupported platform") +#error "Unsupported target" #endif return ovs_p4rt::SendWriteRequest(session, write_request); } #if defined(ES2K_TARGET) -void PrepareDecapModTableEntry(p4::v1::TableEntry* table_entry, - const struct tunnel_info& tunnel_info, - const ::p4::config::v1::P4Info& p4info, - bool insert_entry) { +void PrepareVxlanDecapModTableEntry(p4::v1::TableEntry* table_entry, + const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, + bool insert_entry) { table_entry->set_table_id(GetTableId(p4info, VXLAN_DECAP_MOD_TABLE)); auto match = table_entry->add_match(); match->set_field_id(GetMatchFieldId(p4info, VXLAN_DECAP_MOD_TABLE, @@ -1052,7 +1539,44 @@ void PrepareDecapModTableEntry(p4::v1::TableEntry* table_entry, return; } -void PrepareDecapModAndVlanPushTableEntry( +void PrepareGeneveDecapModTableEntry(p4::v1::TableEntry* table_entry, + const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, + bool insert_entry) { + table_entry->set_table_id(GetTableId(p4info, GENEVE_DECAP_MOD_TABLE)); + auto match = table_entry->add_match(); + match->set_field_id(GetMatchFieldId(p4info, GENEVE_DECAP_MOD_TABLE, + GENEVE_DECAP_MOD_TABLE_KEY_MOD_BLOB_PTR)); + match->mutable_exact()->set_value(EncodeByteValue(1, tunnel_info.vni)); + + if (insert_entry) { + auto table_action = table_entry->mutable_action(); + auto action = table_action->mutable_action(); + { + action->set_action_id(GetActionId(p4info, ACTION_GENEVE_DECAP_OUTER_HDR)); + } + } + return; +} + +void PrepareDecapModTableEntry(p4::v1::TableEntry* table_entry, + const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, + bool insert_entry) { + if (tunnel_info.tunnel_type == OVS_TUNNEL_VXLAN) { + PrepareVxlanDecapModTableEntry(table_entry, tunnel_info, p4info, + insert_entry); + } else if (tunnel_info.tunnel_type == OVS_TUNNEL_GENEVE) { + PrepareGeneveDecapModTableEntry(table_entry, tunnel_info, p4info, + insert_entry); + } else { + std::cout << "ERROR: Unsupported tunnel type" << std::endl; + } + + return; +} + +void PrepareVxlanDecapModAndVlanPushTableEntry( p4::v1::TableEntry* table_entry, const struct tunnel_info& tunnel_info, const ::p4::config::v1::P4Info& p4info, bool insert_entry) { table_entry->set_table_id( @@ -1093,6 +1617,63 @@ void PrepareDecapModAndVlanPushTableEntry( return; } +void PrepareGeneveDecapModAndVlanPushTableEntry( + p4::v1::TableEntry* table_entry, const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, bool insert_entry) { + table_entry->set_table_id( + GetTableId(p4info, GENEVE_DECAP_AND_VLAN_PUSH_MOD_TABLE)); + auto match = table_entry->add_match(); + match->set_field_id( + GetMatchFieldId(p4info, GENEVE_DECAP_AND_VLAN_PUSH_MOD_TABLE, + GENEVE_DECAP_AND_VLAN_PUSH_MOD_TABLE_KEY_MOD_BLOB_PTR)); + match->mutable_exact()->set_value(EncodeByteValue(1, tunnel_info.vni)); + + if (insert_entry) { + auto table_action = table_entry->mutable_action(); + auto action = table_action->mutable_action(); + action->set_action_id( + GetActionId(p4info, ACTION_GENEVE_DECAP_AND_PUSH_VLAN)); + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_DECAP_AND_PUSH_VLAN, + ACTION_GENEVE_DECAP_AND_PUSH_VLAN_PARAM_PCP)); + param->set_value(EncodeByteValue(1, 1)); + } + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_DECAP_AND_PUSH_VLAN, + ACTION_GENEVE_DECAP_AND_PUSH_VLAN_PARAM_DEI)); + param->set_value(EncodeByteValue(1, 0)); + } + { + auto param = action->add_params(); + param->set_param_id( + GetParamId(p4info, ACTION_GENEVE_DECAP_AND_PUSH_VLAN, + ACTION_GENEVE_DECAP_AND_PUSH_VLAN_PARAM_VLAN_ID)); + param->set_value(EncodeByteValue(1, tunnel_info.vlan_info.port_vlan)); + } + } + return; +} + +void PrepareDecapModAndVlanPushTableEntry( + p4::v1::TableEntry* table_entry, const struct tunnel_info& tunnel_info, + const ::p4::config::v1::P4Info& p4info, bool insert_entry) { + if (tunnel_info.tunnel_type == OVS_TUNNEL_VXLAN) { + PrepareVxlanDecapModAndVlanPushTableEntry(table_entry, tunnel_info, p4info, + insert_entry); + } else if (tunnel_info.tunnel_type == OVS_TUNNEL_GENEVE) { + PrepareGeneveDecapModAndVlanPushTableEntry(table_entry, tunnel_info, p4info, + insert_entry); + } else { + std::cout << "ERROR: Unsupported tunnel type" << std::endl; + } + + return; +} + absl::Status ConfigDecapTableEntry(ovs_p4rt::OvsP4rtSession* session, const struct tunnel_info& tunnel_info, const ::p4::config::v1::P4Info& p4info, @@ -1322,7 +1903,21 @@ absl::StatusOr<::p4::v1::ReadResponse> GetFdbTunnelTableEntry( table_entry = ovs_p4rt::SetupTableEntryToRead(session, &read_request); - PrepareFdbTableEntryforV4Tunnel(table_entry, learn_info, p4info, false); +#if defined(DPDK_TARGET) + PrepareFdbTableEntryforV4VxlanTunnel(table_entry, learn_info, p4info, false); +#elif defined(ES2K_TARGET) + if (learn_info.tnl_info.tunnel_type == OVS_TUNNEL_VXLAN) { + PrepareFdbTableEntryforV4VxlanTunnel(table_entry, learn_info, p4info, + false); + } else if (learn_info.tnl_info.tunnel_type == OVS_TUNNEL_GENEVE) { + PrepareFdbTableEntryforV4GeneveTunnel(table_entry, learn_info, p4info, + false); + } else { + return absl::UnknownError("Unsupported tunnel type"); + } +#else +#error "Unsupported target" +#endif return ovs_p4rt::SendReadRequest(session, read_request); } @@ -1420,7 +2015,7 @@ absl::Status ConfigTunnelTermTableEntry(ovs_p4rt::OvsP4rtSession* session, insert_entry); } #else - return absl::UnknownError("Unsupported platform") +#error "Unsupported target" #endif return ovs_p4rt::SendWriteRequest(session, write_request); @@ -1432,6 +2027,17 @@ absl::Status ConfigTunnelTermTableEntry(ovs_p4rt::OvsP4rtSession* session, // Functions with C interfaces //---------------------------------------------------------------------- +enum ovs_tunnel_type TunnelTypeStrtoEnum(const char* tnl_type) { + if (tnl_type) { + if (strcmp(tnl_type, "vxlan") == 0) { + return OVS_TUNNEL_VXLAN; + } else if (strcmp(tnl_type, "geneve") == 0) { + return OVS_TUNNEL_GENEVE; + } + } + return OVS_TUNNEL_UNKNOWN; +} + #if defined(ES2K_TARGET) void ConfigFdbTableEntry(struct mac_learning_info learn_info, bool insert_entry) { diff --git a/ovs/ovs b/ovs/ovs index 8ae0569d..1cd186d5 160000 --- a/ovs/ovs +++ b/ovs/ovs @@ -1 +1 @@ -Subproject commit 8ae0569d3f18f35d995c511391db8175fbdc3398 +Subproject commit 1cd186d5f17b84b44d9154dd06a3875c241b0ee5