-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
[sai-gen] Support merging SAI specs. (#577)
This change added the SAI spec merging support. This is to ensure any new SAI attribute changes will follow the rules below to help ABI compatibility: - All new attributes or action enum values will be added in the end of the list. - Existing attributes will be updated inline. In the future, we can add more check here, e.g., type changed in non-compatible way and etc. - All old attributes will be marked as deprecated instead of removed. Recently, the tunnel APIs are added, but because it merged with the SAI spec PR together without rebase, it is not captured in the previous SAI spec. With SAI spec merging, we can see the changes are showing up in the expected sequence. This would be an example that demos the several usages of SAI spec.
Showing
18 changed files
with
284 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
!!python/object:utils.sai_spec.sai_api_group.SaiApiGroup | ||
name: dash_tunnel | ||
description: '' | ||
sai_apis: | ||
- !!python/object:utils.sai_spec.sai_api.SaiApi | ||
name: dash_tunnel | ||
description: '' | ||
is_object: true | ||
enums: [] | ||
structs: [] | ||
attributes: | ||
- !!python/object:utils.sai_spec.sai_attribute.SaiAttribute | ||
name: SAI_DASH_TUNNEL_DIP | ||
description: Action parameter DIP | ||
type: sai_ip_address_t | ||
attr_value_field: ipaddr | ||
default: 0.0.0.0 | ||
isresourcetype: false | ||
flags: CREATE_AND_SET | ||
object_name: null | ||
allow_null: false | ||
valid_only: null | ||
deprecated: null | ||
- !!python/object:utils.sai_spec.sai_attribute.SaiAttribute | ||
name: SAI_DASH_TUNNEL_DASH_ENCAPSULATION | ||
description: Action parameter DASH_ENCAPSULATION | ||
type: sai_dash_encapsulation_t | ||
attr_value_field: s32 | ||
default: SAI_DASH_ENCAPSULATION_VXLAN | ||
isresourcetype: false | ||
flags: CREATE_AND_SET | ||
object_name: null | ||
allow_null: false | ||
valid_only: null | ||
deprecated: null | ||
- !!python/object:utils.sai_spec.sai_attribute.SaiAttribute | ||
name: SAI_DASH_TUNNEL_TUNNEL_KEY | ||
description: Action parameter TUNNEL_KEY | ||
type: sai_uint32_t | ||
attr_value_field: u32 | ||
default: '0' | ||
isresourcetype: false | ||
flags: CREATE_AND_SET | ||
object_name: null | ||
allow_null: false | ||
valid_only: null | ||
deprecated: null | ||
stats: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from typing import Dict, List | ||
|
||
|
||
class SaiApiP4MetaAction: | ||
def __init__(self, name: str, id: int): | ||
self.name: str = name | ||
self.id: int = id | ||
self.attr_param_id: Dict[str, int] = {} | ||
|
||
|
||
class SaiApiP4MetaTable: | ||
def __init__(self, id: int): | ||
self.id: int = id | ||
self.actions: Dict[str, SaiApiP4MetaAction] = {} | ||
|
||
|
||
class SaiApiP4Meta: | ||
def __init__(self): | ||
self.tables: List[SaiApiP4MetaTable] = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Any, List, Callable | ||
from .sai_common import SaiCommon | ||
|
||
|
||
def merge_sai_value_lists( | ||
target: List[Any], | ||
source: List[Any], | ||
get_key: Callable[[Any], str], | ||
on_conflict: Callable[[Any, Any], None] = lambda x, y: x, | ||
on_deprecate: Callable[[Any], bool] = lambda x: False | ||
) -> None: | ||
""" | ||
Merge 2 SAI value lists from source list into target. | ||
Since we could not remove the old value or change the order of old values, the merge | ||
is done as below: | ||
- Any new values will be added in the end of the list. | ||
- Any values that collapse with existing values will invoke on_conflict callback to resolve. | ||
- Any values that needs to be removed will invoke on_deprecate function to deprecate. By default, | ||
it will not be removed from the old list. | ||
""" | ||
target_dict = {get_key(item): item for item in target} | ||
|
||
source_keys = set() | ||
for source_item in source: | ||
source_key = get_key(source_item) | ||
source_keys.add(source_key) | ||
|
||
if source_key in target_dict: | ||
target_item = target_dict[source_key] | ||
on_conflict(target_item, source_item) | ||
else: | ||
target.append(source_item) | ||
target_dict[source_key] = source_item | ||
|
||
# Remove all items in target, if its key doesn't exist in source_keys and on_deprecate returns True. | ||
target[:] = [item for item in target if get_key(item) in source_keys or not on_deprecate(item)] | ||
|
||
|
||
def merge_sai_common_lists( | ||
target: List[SaiCommon], | ||
source: List[SaiCommon], | ||
) -> None: | ||
merge_sai_value_lists( | ||
target, | ||
source, | ||
get_key=lambda x: x.name, | ||
on_conflict=lambda x, y: x.merge(y), | ||
on_deprecate=lambda x: x.deprecate(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters