diff --git a/orchagent/dash/dashorch.cpp b/orchagent/dash/dashorch.cpp index f4538797b2..7332664dc8 100644 --- a/orchagent/dash/dashorch.cpp +++ b/orchagent/dash/dashorch.cpp @@ -28,6 +28,7 @@ using namespace swss; extern Directory gDirectory; extern std::unordered_map gVnetNameToId; +extern sai_dash_appliance_api_t* sai_dash_appliance_api; extern sai_dash_vip_api_t* sai_dash_vip_api; extern sai_dash_direction_lookup_api_t* sai_dash_direction_lookup_api; extern sai_dash_eni_api_t* sai_dash_eni_api; @@ -66,15 +67,31 @@ bool DashOrch::addApplianceEntry(const string& appliance_id, const dash::applian } uint32_t attr_count = 1; + sai_attribute_t appliance_attr; + sai_status_t status; + + // NOTE: DASH Appliance object should be the first object pushed to SAI + sai_object_id_t sai_appliance_id = 0UL; + appliance_attr.id = SAI_DASH_APPLIANCE_ATTR_LOCAL_REGION_ID; + appliance_attr.value.u32 = entry.local_region_id(); + status = sai_dash_appliance_api->create_dash_appliance(&sai_appliance_id, gSwitchId, + attr_count, &appliance_attr); + if (status != SAI_STATUS_SUCCESS && status != SAI_STATUS_NOT_IMPLEMENTED) + { + SWSS_LOG_ERROR("Failed to create dash appliance object in SAI for %s", appliance_id.c_str()); + task_process_status handle_status = handleSaiCreateStatus((sai_api_t) SAI_API_DASH_APPLIANCE, status); + if (handle_status != task_success) + { + return parseHandleSaiStatusFailure(handle_status); + } + } + sai_vip_entry_t vip_entry; vip_entry.switch_id = gSwitchId; if (!to_sai(entry.sip(), vip_entry.vip)) { return false; } - sai_attribute_t appliance_attr; - vector appliance_attrs; - sai_status_t status; appliance_attr.id = SAI_VIP_ENTRY_ATTR_ACTION; appliance_attr.value.u32 = SAI_VIP_ENTRY_ACTION_ACCEPT; status = sai_dash_vip_api->create_vip_entry(&vip_entry, attr_count, &appliance_attr); @@ -103,7 +120,7 @@ bool DashOrch::addApplianceEntry(const string& appliance_id, const dash::applian return parseHandleSaiStatusFailure(handle_status); } } - appliance_entries_[appliance_id] = entry; + appliance_entries_[appliance_id] = ApplianceEntry { sai_appliance_id, entry }; SWSS_LOG_NOTICE("Created vip and direction lookup entries for %s", appliance_id.c_str()); return true; @@ -114,7 +131,6 @@ bool DashOrch::removeApplianceEntry(const string& appliance_id) SWSS_LOG_ENTER(); sai_status_t status; - dash::appliance::Appliance entry; if (appliance_entries_.find(appliance_id) == appliance_entries_.end()) { @@ -122,7 +138,7 @@ bool DashOrch::removeApplianceEntry(const string& appliance_id) return true; } - entry = appliance_entries_[appliance_id]; + const auto& entry = appliance_entries_[appliance_id].metadata; sai_vip_entry_t vip_entry; vip_entry.switch_id = gSwitchId; if (!to_sai(entry.sip(), vip_entry.vip)) @@ -153,6 +169,21 @@ bool DashOrch::removeApplianceEntry(const string& appliance_id) return parseHandleSaiStatusFailure(handle_status); } } + + auto sai_appliance_id = appliance_entries_[appliance_id].appliance_id; + if (sai_appliance_id != 0UL) + { + status = sai_dash_appliance_api->remove_dash_appliance(sai_appliance_id); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to remove dash appliance object in SAI for %s", appliance_id.c_str()); + task_process_status handle_status = handleSaiRemoveStatus((sai_api_t) SAI_API_DASH_APPLIANCE, status); + if (handle_status != task_success) + { + return parseHandleSaiStatusFailure(handle_status); + } + } + } appliance_entries_.erase(appliance_id); SWSS_LOG_NOTICE("Removed vip and direction lookup entries for %s", appliance_id.c_str()); @@ -383,7 +414,7 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry) eni_attrs.push_back(eni_attr); eni_attr.id = SAI_ENI_ATTR_VM_VNI; - auto app_entry = appliance_entries_.begin()->second; + auto& app_entry = appliance_entries_.begin()->second.metadata; eni_attr.value.u32 = app_entry.vm_vni(); eni_attrs.push_back(eni_attr); diff --git a/orchagent/dash/dashorch.h b/orchagent/dash/dashorch.h index e2b6e3554d..645131d443 100644 --- a/orchagent/dash/dashorch.h +++ b/orchagent/dash/dashorch.h @@ -30,7 +30,13 @@ struct EniEntry dash::eni::Eni metadata; }; -typedef std::map ApplianceTable; +struct ApplianceEntry +{ + sai_object_id_t appliance_id; + dash::appliance::Appliance metadata; +}; + +typedef std::map ApplianceTable; typedef std::map RoutingTypeTable; typedef std::map EniTable; typedef std::map QosTable; diff --git a/orchagent/saihelper.cpp b/orchagent/saihelper.cpp index 1265364d97..48e6c14e14 100644 --- a/orchagent/saihelper.cpp +++ b/orchagent/saihelper.cpp @@ -74,6 +74,7 @@ sai_counter_api_t* sai_counter_api; sai_bfd_api_t* sai_bfd_api; sai_my_mac_api_t* sai_my_mac_api; sai_generic_programmable_api_t* sai_generic_programmable_api; +sai_dash_appliance_api_t* sai_dash_appliance_api; sai_dash_acl_api_t* sai_dash_acl_api; sai_dash_vnet_api_t sai_dash_vnet_api; sai_dash_outbound_ca_to_pa_api_t* sai_dash_outbound_ca_to_pa_api; @@ -221,6 +222,7 @@ void initSaiApi() sai_api_query(SAI_API_BFD, (void **)&sai_bfd_api); sai_api_query(SAI_API_MY_MAC, (void **)&sai_my_mac_api); sai_api_query(SAI_API_GENERIC_PROGRAMMABLE, (void **)&sai_generic_programmable_api); + sai_api_query((sai_api_t)SAI_API_DASH_APPLIANCE, (void**)&sai_dash_appliance_api); sai_api_query((sai_api_t)SAI_API_DASH_ACL, (void**)&sai_dash_acl_api); sai_api_query((sai_api_t)SAI_API_DASH_VNET, (void**)&sai_dash_vnet_api); sai_api_query((sai_api_t)SAI_API_DASH_OUTBOUND_CA_TO_PA, (void**)&sai_dash_outbound_ca_to_pa_api); diff --git a/tests/dash/dash_configs.py b/tests/dash/dash_configs.py index 2f1590ebaa..0635631b41 100644 --- a/tests/dash/dash_configs.py +++ b/tests/dash/dash_configs.py @@ -52,7 +52,8 @@ "sip": { "ipv4": socket.htonl(int(IP(SIP))) }, - "vm_vni": int(VM_VNI) + "vm_vni": int(VM_VNI), + "local_region_id": 10 } VNET_CONFIG = { @@ -168,4 +169,4 @@ ENI_ROUTE_GROUP2_CONFIG = { "group_id": ROUTE_GROUP2, -} \ No newline at end of file +} diff --git a/tests/dash/test_dash_vnet.py b/tests/dash/test_dash_vnet.py index a591b5c9b1..432a9caff3 100644 --- a/tests/dash/test_dash_vnet.py +++ b/tests/dash/test_dash_vnet.py @@ -27,6 +27,7 @@ def test_appliance(self, dash_db: DashDB): self.appliance_id = "100" self.sip = "10.0.0.1" self.vm_vni = "4321" + self.local_region_id = "10" pb = Appliance() pb.sip.ipv4 = socket.htonl(int(ipaddress.ip_address(self.sip))) pb.vm_vni = int(self.vm_vni)