Skip to content

Commit

Permalink
Add suppport for SAI DASH appliance object
Browse files Browse the repository at this point in the history
Signed-off-by: mukeshmv <[email protected]>
  • Loading branch information
mukeshmv committed Oct 26, 2024
1 parent 064f2e3 commit df555e9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
45 changes: 38 additions & 7 deletions orchagent/dash/dashorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace swss;

extern Directory<Orch*> gDirectory;
extern std::unordered_map<std::string, sai_object_id_t> 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;
Expand Down Expand Up @@ -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<sai_attribute_t> 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);
Expand Down Expand Up @@ -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;
Expand All @@ -114,15 +131,14 @@ 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())
{
SWSS_LOG_WARN("Appliance id does not exist: %s", appliance_id.c_str());
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))
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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);

Expand Down
8 changes: 7 additions & 1 deletion orchagent/dash/dashorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ struct EniEntry
dash::eni::Eni metadata;
};

typedef std::map<std::string, dash::appliance::Appliance> ApplianceTable;
struct ApplianceEntry
{
sai_object_id_t appliance_id;
dash::appliance::Appliance metadata;
};

typedef std::map<std::string, ApplianceEntry> ApplianceTable;
typedef std::map<dash::route_type::RoutingType, dash::route_type::RouteType> RoutingTypeTable;
typedef std::map<std::string, EniEntry> EniTable;
typedef std::map<std::string, dash::qos::Qos> QosTable;
Expand Down
2 changes: 2 additions & 0 deletions orchagent/saihelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions tests/dash/dash_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -168,4 +169,4 @@

ENI_ROUTE_GROUP2_CONFIG = {
"group_id": ROUTE_GROUP2,
}
}
1 change: 1 addition & 0 deletions tests/dash/test_dash_vnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit df555e9

Please sign in to comment.