Skip to content

Commit

Permalink
Update addOutboundCaToPa
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyzhai committed Jan 9, 2025
1 parent 381c014 commit 9f42b26
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 38 deletions.
82 changes: 46 additions & 36 deletions orchagent/dash/dashvnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions tests/dash/test_dash_vnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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])
Expand Down

0 comments on commit 9f42b26

Please sign in to comment.