Skip to content

Adding HaOrch for smartswitch dpu #3550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open

Conversation

zjswhhh
Copy link

@zjswhhh zjswhhh commented Mar 10, 2025

HLD:
https://github.com/sonic-net/DASH/blob/main/documentation/high-avail/ha-api-hld.md
https://github.com/sonic-net/SONiC/blob/master/doc/smart-switch/high-availability/smart-switch-ha-detailed-design.md

Requires:
sonic-net/sonic-swss-common#985
sonic-net/sonic-dash-api#33

How did I verify?
UTs:

[----------] 8 tests from DashHaOrchTest
[ RUN      ] DashHaOrchTest.AddRemoveHaSet
[       OK ] DashHaOrchTest.AddRemoveHaSet (10 ms)
[ RUN      ] DashHaOrchTest.HaSetAlreadyExists
[       OK ] DashHaOrchTest.HaSetAlreadyExists (10 ms)
[ RUN      ] DashHaOrchTest.AddRemoveHaScope
[       OK ] DashHaOrchTest.AddRemoveHaScope (10 ms)
[ RUN      ] DashHaOrchTest.NoHaSetFound
[       OK ] DashHaOrchTest.NoHaSetFound (10 ms)
[ RUN      ] DashHaOrchTest.SetHaScopeHaRole
[       OK ] DashHaOrchTest.SetHaScopeHaRole (11 ms)
[ RUN      ] DashHaOrchTest.SetHaScopeActivateRoleRequest
[       OK ] DashHaOrchTest.SetHaScopeActivateRoleRequest (10 ms)
[ RUN      ] DashHaOrchTest.SetHaScopeFlowReconcileRequest
[       OK ] DashHaOrchTest.SetHaScopeFlowReconcileRequest (10 ms)
[ RUN      ] DashHaOrchTest.InvalidInput
[       OK ] DashHaOrchTest.InvalidInput (10 ms)
[----------] 8 tests from DashHaOrchTest (86 ms total)

TODO:
2. add support to set ha_scope attribute ha_role
3. event notifications handling (new PR)
4. Bulk create/remove (new PR)
5. Ha stats (new PR)

sign-off: Jing Zhang [email protected]

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

extern sai_dash_eni_api_t* sai_dash_eni_api;
extern sai_object_id_t gSwitchId;

static std::map<dash::types::HaRole, std::string> ha_role_to_str_map = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to explicitly define these maps? Might be simpler to use dash::types::HaRole_Name and dash::types::HaRole_Parse

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

{dash::types::HA_SCOPE_ROLE_SWITCHING_TO_ACTIVE, "HA_SCOPE_ROLE_SWITCHING_TO_ACTIVE"}
};

static std::map<dash::types::HaScope, std::string> ha_set_scope_to_str_map = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

}
}

sai_ip_address_t DashHaOrch::covertPbIpaddrToSaiIpaddr(const dash::types::IpAddress &ipaddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use pbutils.cpp::to_sai instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

return parseHandleSaiStatusFailure(handle_status);
}
}
m_ha_set_entries[key] = HaSetEntry {sai_ha_set_oid, entry};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the expected scale/how many entries do we expect per DPU?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 ha set per DPU.

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@zjswhhh zjswhhh requested a review from theasianpianist May 1, 2025 17:10
Comment on lines 191 to 204
if (ha_scope_it->second.metadata.ha_role() != entry.ha_role())
{
return setHaScopeHaRole(key, entry);
}

if (entry.flow_reconcile_requested() == true)
{
return setHaScopeFlowReconcileRequest(key);
}

if (entry.activate_role_requested() == true)
{
return setHaScopeActivateRoleRequest(key);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these three attributes mutually exclusive, or is it possible for more than one to be changed in a single update?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.


// TODO: add ha_role to attribute value enum
ha_scope_attrs[1].id = SAI_HA_SCOPE_ATTR_DASH_HA_ROLE;
ha_scope_attrs[1].value.u16 = static_cast<sai_uint16_t>(entry.ha_role());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do entry.ha_role() + 1 here? In the SAI enum, value 0 for sai_dash_ha_role_t is SAI_DASH_HA_ROLE_DEAD, but in the protobuf enum value 0 is HA_SCOPE_ROLE_UNSPECIFIED

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.


sai_attribute_t ha_scope_attr;
ha_scope_attr.id = SAI_HA_SCOPE_ATTR_DASH_HA_ROLE;
ha_scope_attr.value.u32 = entry.ha_role();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same concern as above about SAI/protobuf enum off-by-one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.




#define DEFINE_SAI_GENERIC_APIS_MOCK(sai_api_name, ...) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this macro and DEFINE_SAI_GENERIC_API_MOCK, is it just allow mocking multiple APIs with one macro call?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we have ha_set and ha_scope in the same sai_dash_ha_api, that's why I need this macro.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. This should also still work for mocking just a single object type right? Can you add a comment above the old DEFINE_SAI_GENERIC_API_MOCK macro to deprecate it and use your new macro instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.


void CreateHaSet()
{
auto consumer = unique_ptr<Consumer>(new Consumer(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why not use swss::Table and m_dashHaOrch->addExistingData like existing tests?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason. Is addExistingData preferred?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes a difference functionally but it might be better to keep thing consistent across UTs, plus it needs less boilerplate

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this consumer and addToSync are also commonly used in UTs, I think the benefit is we can explicitly set the operation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Table has del which should allow us to choose the op. But I didn't realize that we used addToSync so much, I think it's fine to leave this as-is then.

{
it++;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add changes to write result of operations back to DPU_APPL_STATE_DB? Refer sonic-net/SONiC#1759 and #3490

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants