From 9f42b266fc94d0265d0442d4218ce0c7343da188 Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Thu, 9 Jan 2025 16:29:40 +0000 Subject: [PATCH] Update addOutboundCaToPa --- orchagent/dash/dashvnetorch.cpp | 82 ++++++++++++++++++--------------- tests/dash/test_dash_vnet.py | 4 +- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/orchagent/dash/dashvnetorch.cpp b/orchagent/dash/dashvnetorch.cpp index 512b03396d..65e4ff2f4f 100644 --- a/orchagent/dash/dashvnetorch.cpp +++ b/orchagent/dash/dashvnetorch.cpp @@ -294,39 +294,34 @@ bool DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt return false; } - for (auto action: route_type_actions.items()) + if (ctxt.metadata.routing_type() == dash::route_type::ROUTING_TYPE_PRIVATELINK) { - if (action.action_type() == dash::route_type::ACTION_TYPE_STATICENCAP) + for (auto action: route_type_actions.items()) { - outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION; - if (action.encap_type() == dash::route_type::ENCAP_TYPE_VXLAN) - { - outbound_ca_to_pa_attr.value.u32 = SAI_DASH_ENCAPSULATION_VXLAN; - } - else if (action.encap_type() == dash::route_type::ENCAP_TYPE_NVGRE) + if (action.action_type() == dash::route_type::ACTION_TYPE_STATICENCAP) { - outbound_ca_to_pa_attr.value.u32 = SAI_DASH_ENCAPSULATION_NVGRE; - } - else - { - SWSS_LOG_ERROR("Invalid encap type %d for %s", action.encap_type(), key.c_str()); - return false; - } - outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); - - outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY; - outbound_ca_to_pa_attr.value.u32 = action.vni(); - outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); - - outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_UNDERLAY_DIP; - to_sai(ctxt.metadata.underlay_ip(), outbound_ca_to_pa_attr.value.ipaddr); - outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION; + if (action.encap_type() == dash::route_type::ENCAP_TYPE_VXLAN) + { + outbound_ca_to_pa_attr.value.u32 = SAI_DASH_ENCAPSULATION_VXLAN; + } + else if (action.encap_type() == dash::route_type::ENCAP_TYPE_NVGRE) + { + outbound_ca_to_pa_attr.value.u32 = SAI_DASH_ENCAPSULATION_NVGRE; + } + else + { + SWSS_LOG_ERROR("Invalid encap type %d for %s", action.encap_type(), key.c_str()); + return false; + } + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_TUNNEL_KEY; + outbound_ca_to_pa_attr.value.u32 = action.vni(); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + } } - } - if (ctxt.metadata.routing_type() == dash::route_type::ROUTING_TYPE_PRIVATELINK) - { outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION; outbound_ca_to_pa_attr.value.u32 = SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_PRIVATE_LINK_MAPPING; outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); @@ -348,21 +343,36 @@ bool DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt to_sai(ctxt.metadata.overlay_sip_prefix().mask(), outbound_ca_to_pa_attr.value.ipaddr); outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); } - - if (ctxt.metadata.has_mac_address()) + else if (ctxt.metadata.routing_type() == dash::route_type::ROUTING_TYPE_VNET_ENCAP) { - outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DMAC; - memcpy(outbound_ca_to_pa_attr.value.mac, ctxt.metadata.mac_address().c_str(), sizeof(sai_mac_t)); + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION; + outbound_ca_to_pa_attr.value.u32 = SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING; outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); - } - if (ctxt.metadata.has_use_dst_vni()) + if (ctxt.metadata.has_mac_address()) + { + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DMAC; + memcpy(outbound_ca_to_pa_attr.value.mac, ctxt.metadata.mac_address().c_str(), sizeof(sai_mac_t)); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + } + if (ctxt.metadata.has_use_dst_vni()) + { + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_USE_DST_VNET_VNI; + outbound_ca_to_pa_attr.value.booldata = ctxt.metadata.use_dst_vni(); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + } + } + else { - outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_USE_DST_VNET_VNI; - outbound_ca_to_pa_attr.value.booldata = ctxt.metadata.use_dst_vni(); - outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + SWSS_LOG_ERROR("Invalid routing type %d for OutboundCaToPa", ctxt.metadata.routing_type()); + return false; } + // mandatory attr for both routing_type PRIVATELINK and VNET_ENCAP + outbound_ca_to_pa_attr.id = SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_UNDERLAY_DIP; + to_sai(ctxt.metadata.underlay_ip(), outbound_ca_to_pa_attr.value.ipaddr); + outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr); + object_statuses.emplace_back(); outbound_ca_to_pa_bulker_.create_entry(&object_statuses.back(), &outbound_ca_to_pa_entry, (uint32_t)outbound_ca_to_pa_attrs.size(), outbound_ca_to_pa_attrs.data()); diff --git a/tests/dash/test_dash_vnet.py b/tests/dash/test_dash_vnet.py index 8409db7ce6..4c0d3c70a1 100644 --- a/tests/dash/test_dash_vnet.py +++ b/tests/dash/test_dash_vnet.py @@ -119,7 +119,6 @@ def test_vnet_map(self, dash_db: DashDB): route_action = RouteTypeItem() route_action.action_name = "action1" route_action.action_type = ACTION_TYPE_STATICENCAP - route_action.encap_type = ENCAP_TYPE_NVGRE route_type_msg.items.append(route_action) dash_db.create_routing_type(self.routing_type, {"pb": route_type_msg.SerializeToString()}) pb = VnetMapping() @@ -133,9 +132,10 @@ def test_vnet_map(self, dash_db: DashDB): vnet_ca_to_pa_maps = dash_db.wait_for_asic_db_keys(ASIC_OUTBOUND_CA_TO_PA_TABLE, min_keys=2) attrs = dash_db.get_asic_db_entry(ASIC_OUTBOUND_CA_TO_PA_TABLE, vnet_ca_to_pa_maps[0]) + assert_sai_attribute_exists("SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_ACTION", attrs, "SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING") assert_sai_attribute_exists("SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_UNDERLAY_DIP", attrs, self.underlay_ip) assert_sai_attribute_exists("SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_OVERLAY_DMAC", attrs, self.mac_address) - assert_sai_attribute_exists("SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_DASH_ENCAPSULATION", attrs, "SAI_DASH_ENCAPSULATION_NVGRE") + assert_sai_attribute_exists("SAI_OUTBOUND_CA_TO_PA_ENTRY_ATTR_USE_DST_VNET_VNI", attrs, "false") vnet_pa_validation_maps = dash_db.wait_for_asic_db_keys(ASIC_PA_VALIDATION_TABLE) pa_validation_attrs = dash_db.get_asic_db_entry(ASIC_PA_VALIDATION_TABLE, vnet_pa_validation_maps[0])