Skip to content
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

Timeouts for states #231

Merged
merged 15 commits into from
Sep 20, 2024

Conversation

ol-imorozko
Copy link
Collaborator

No description provided.

@ol-imorozko ol-imorozko changed the title Timeouts for states WIP: Timeouts for states Aug 12, 2024
@ol-imorozko ol-imorozko force-pushed the timeouts-for-states branch 2 times, most recently from a378c58 to 5abcb27 Compare September 3, 2024 15:02
@ol-imorozko ol-imorozko force-pushed the timeouts-for-states branch 7 times, most recently from c95aa37 to f907835 Compare September 17, 2024 20:43
@ol-imorozko ol-imorozko changed the title WIP: Timeouts for states Timeouts for states Sep 17, 2024
@ol-imorozko ol-imorozko marked this pull request as ready for review September 17, 2024 20:43
@ol-imorozko ol-imorozko force-pushed the timeouts-for-states branch 3 times, most recently from 45d1b4a to 972ba95 Compare September 18, 2024 09:10
@ol-imorozko ol-imorozko mentioned this pull request Sep 18, 2024
Makes it easier to read and avoid writing decltype<Actions::raw_action>
where we need such type
This commit introduces parsing for the state-timeout rule.
The tests and the actual semantics will be implemented later.

Note that the current implementation does not properly manage StateTimeout yet,
as we are only interested in the last action for performance optimization.
Storing only the last state-timeout action reduces the number of actions
processed in the dataplane, enhancing performance.

In general, we can optimize performance for actions that only need to be
executed once. For instance, only the first execution of CheckStateAction
matters, as we cannot add new states while processing the current packet actions.
Similarly, only the last StateTimeoutAction is relevant, as it provides the
most accurate timeout value.

By storing only the relevant action and tracking its index during the
"compile" step, we can use this information to optimize performance.
For example, instead of storing a StateTimeoutAction, we could directly
add the timeout field to the FlowAction.

The next commit will propose a generic way to handle this optimization
across various action types.
Adds simple structures to make the folliwing VarinatTraitMap
implementation easier
Introduce the `VariantTraitMap`, a generic helper that maps types within a
`std::variant` to a value (e.g., `std::optional<size_t>`) based on a given trait.

Why this is needed:

Some actions, (those with `MAX_COUNT=1`), only need to be executed once or
only the first/last occurrence of them matters. For example:

- CheckStateAction:
    Only the first occurrence of this action is meaningful.
- StateTimeoutAction:
    Only the last occurrence of this action should be stored and processed,
    as it provides the most accurate or latest information.

To optimize contolplane, we can store only one of those actions with their index.
This way, on "compile" step in value_t we can do something with this information
to increase contolplane performance. For example, compeletly ditch the
StateTimeoutAction and just add the timeout to the FlowAction as a field.

Therefore, to avoid writing boilerplate code like
`std::optional<size_t> check_state_index, state_timeout_index`, we can
use VariantTraitMap to directly map Actions with MAX_COUNT=1 to their index.
This commit introduces a new common/utils.h file to store small utility
functions, as such a file didn't previously exist.

It also adds the always_false trait, which is a trait that evaluates to false
for any type. This trait is useful for triggering static assertions in order
to identify the exact type that caused a compilation error.
This commit refactors the way actions with `MAX_COUNT=1` are tracked by using
`VariantTraitMap`. The change enables storing the index of the first or last
occurrence of specific actions, like `CheckStateAction` or `StateTimeoutAction`,
in a more generic way.

Previously, actions like `check_state_index` and `state_timeout_index` were
handled manually with specific member variables. Now, these actions are handled
through a type-safe mechanism based on traits, allowing easy extension for other
actions in the future.

This improves control plane performance by reducing redundant actions,
as only the relevant instances are processed and stored.
This is a representation of a processed action, but not quite
ready for use in dataplane yet. Here we build the actions for the
packet, and on "compile" step we will shape the final form of a
structure, hence Intermediate name
These are helpful methods that will reduce code duplication later
Refactored the compile method by splitting it into two functions
Remove StateTimeoutAction to improve performance of dataplane, since now it
wont have to execute this action. By tracking only the last timeout and adding
its value directly to FlowAction we can just fill the required timeout
on FlowAction execution
acl_touch_state is used only in acl_create_state and acl_checkstate.
The former creates the state, while the latter attempts to match a packet
with it. During state creation, we need to fill the `value` with the
appropriate timeout, which is initialized to zero by default. However,
in acl_checkstate, we still need to "touch" the state, ensuring that the
last_seen field is updated with the current time.

The issue with the current code is that it unnecessarily fills the
state_timeout value every time, even though this value doesn't change
once set. It is defined during state creation and later used to check
for timeouts, but we don't modify it afterward. Recalculating it each
time adds extra complexity/branches to the dataplane without any benefit.
This commit removes that behavior.
Modifies `acl_create_state` to accept an optional timeout value.
If provided, this value is used to set the state's timeout.
If not, get timeout as before.
Verify the correct behavior when moving state-timeout timeout to flow action.
Checks that only the last state timeout is stored in the flow action.
Some tests were missing clearFWState, which resulted in other tests
wrong behaviour due to the presence of states from previous runs
@GeorgyKirichenko GeorgyKirichenko merged commit cba03ee into yanet-platform:main Sep 20, 2024
8 checks passed
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.

2 participants