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

[SAI-PTF] Enhance the function for getting counters in sai_adapter.py #1626

Merged

Conversation

richardyu-ms
Copy link
Collaborator

@richardyu-ms richardyu-ms commented Oct 24, 2022

Description

For the auto-generated adapter, need to add a parameter for which counter_id/counter_ids we want, in order to compatiable with current code and reduce the modification, we can define a constant parameter as the list of counter_ids, and use this constant as the default.

Resolve issue

#1614

Before

    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid):

        counter_ids = []
        counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS

After the refactor

sai_get_bfd_session_stats_counter_ids = []
sai_get_bfd_session_stats_counter_ids_dict = dict()
sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
sai_get_bfd_session_stats_counter_ids_dict[SAI_BFD_SESSION_STAT_IN_PACKETS] = "SAI_BFD_SESSION_STAT_IN_PACKETS"
sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
sai_get_bfd_session_stats_counter_ids_dict[SAI_BFD_SESSION_STAT_OUT_PACKETS] = "SAI_BFD_SESSION_STAT_OUT_PACKETS"
sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)
sai_get_bfd_session_stats_counter_ids_dict[SAI_BFD_SESSION_STAT_DROP_PACKETS] = "SAI_BFD_SESSION_STAT_DROP_PACKETS"

def sai_thrift_get_bfd_session_stats(client,
                                     bfd_session_oid,
                                     counter_ids=sai_get_bfd_session_stats_counter_ids):
...

    stats = dict()

    for index, item in enumerate(counter_ids):
        stats[sai_get_bfd_session_stats_counter_ids_dict[item]] = counters[index]


    return stats

Usage

        ids = []    
        ids.append(SAI_QUEUE_STAT_PACKETS)
        pre_cpu_queue_state = sai_thrift_get_queue_stats(self.client, self.cpu_queue0, counter_ids=ids)[

@richardyu-ms
Copy link
Collaborator Author

@ravi861 Could you please help to make a review. Thanks

    Resolve issue opencomputeproject#1614

    For the auto-generated adapter, need to add a parameter for which counter_id/counter_ids we want, in order to compatiable with current code and reduce the modification, we can define a constant parameter as the list of counter_ids, and use this constant as the default.

    Before

    ```
    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid):

        counter_ids = []
        counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

    After the refactor
    ```
    sai_get_bfd_session_stats_counter_ids = []
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid,
                                         counter_ids=sai_get_bfd_session_stats_counter_ids):

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
…me by id

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
@ravi861
Copy link
Contributor

ravi861 commented Oct 25, 2022

pre_cpu_queue_state["SAI_QUEUE_STAT_PACKETS"]
You can now get the counter value using above dict?

@richardyu-ms
Copy link
Collaborator Author

richardyu-ms commented Oct 26, 2022

pre_cpu_queue_state["SAI_QUEUE_STAT_PACKETS"] You can now get the counter value using above dict?

Yes. By specifying what's the excatlly attributes need to use, I can get the value from the dict.
Have to confirm if that attribute/counter is supported in advance, anyway.

@richardyu-ms richardyu-ms merged commit 1a69c05 into opencomputeproject:master Nov 1, 2022
richardyu-ms added a commit to richardyu-ms/SAI that referenced this pull request Nov 1, 2022
…opencomputeproject#1626)

* [SAI-PTF] Enhance the function for getting counters in sai_adapter.py

    Resolve issue opencomputeproject#1614

    For the auto-generated adapter, need to add a parameter for which counter_id/counter_ids we want, in order to compatiable with current code and reduce the modification, we can define a constant parameter as the list of counter_ids, and use this constant as the default.

    Before

    ```
    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid):

        counter_ids = []
        counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

    After the refactor
    ```
    sai_get_bfd_session_stats_counter_ids = []
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid,
                                         counter_ids=sai_get_bfd_session_stats_counter_ids):

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

* make some enhancement on the code, add dict which can get the enum name by id

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Co-authored-by: richardyu <richardyu@contoso.com>
richardyu-ms added a commit to richardyu-ms/SAI that referenced this pull request Nov 1, 2022
…opencomputeproject#1626)

* [SAI-PTF] Enhance the function for getting counters in sai_adapter.py

    Resolve issue opencomputeproject#1614

    For the auto-generated adapter, need to add a parameter for which counter_id/counter_ids we want, in order to compatiable with current code and reduce the modification, we can define a constant parameter as the list of counter_ids, and use this constant as the default.

    Before

    ```
    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid):

        counter_ids = []
        counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

    After the refactor
    ```
    sai_get_bfd_session_stats_counter_ids = []
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid,
                                         counter_ids=sai_get_bfd_session_stats_counter_ids):

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

* make some enhancement on the code, add dict which can get the enum name by id

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Co-authored-by: richardyu <richardyu@contoso.com>
richardyu-ms added a commit that referenced this pull request Nov 1, 2022
…#1626) (#1633)

* [SAI-PTF] Enhance the function for getting counters in sai_adapter.py

    Resolve issue #1614

    For the auto-generated adapter, need to add a parameter for which counter_id/counter_ids we want, in order to compatiable with current code and reduce the modification, we can define a constant parameter as the list of counter_ids, and use this constant as the default.

    Before

    ```
    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid):

        counter_ids = []
        counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

    After the refactor
    ```
    sai_get_bfd_session_stats_counter_ids = []
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid,
                                         counter_ids=sai_get_bfd_session_stats_counter_ids):

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

* make some enhancement on the code, add dict which can get the enum name by id

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Co-authored-by: richardyu <richardyu@contoso.com>

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Co-authored-by: richardyu <richardyu@contoso.com>
richardyu-ms added a commit that referenced this pull request Nov 1, 2022
* [SAI-PTF] Add decorator for skipping test on specified error (#1609)

* [SAI-PTF] Add decorator for skipping test on specified error

Add decorator method in the perl template  for skipping test on specified error

details:
1. add decorator method in sai_adapter_utils.tt
2. use decorator when set parameters ``skip_error``
3. add parameters when building from template, like ``perl -Irpc gensairpc.pl  --skip_error=-2,-3``
4. remove the new added parameters, add more doc
Test done:
make  rpc

Signed-off-by: richardyu <richardyu@contoso.com>

* Update sai_fdb_test.py

remove unnecessary test

Signed-off-by: Richard.Yu <richard.yu@microsoft.com>

Signed-off-by: richardyu <richardyu@contoso.com>
Signed-off-by: Richard.Yu <richard.yu@microsoft.com>
Co-authored-by: richardyu <richardyu@contoso.com>

* [SAI-PTF] Enhance the function for getting counters in sai_adapter.py (#1626)

* [SAI-PTF] Enhance the function for getting counters in sai_adapter.py

    Resolve issue #1614

    For the auto-generated adapter, need to add a parameter for which counter_id/counter_ids we want, in order to compatiable with current code and reduce the modification, we can define a constant parameter as the list of counter_ids, and use this constant as the default.

    Before

    ```
    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid):

        counter_ids = []
        counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

    After the refactor
    ```
    sai_get_bfd_session_stats_counter_ids = []
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid,
                                         counter_ids=sai_get_bfd_session_stats_counter_ids):

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

* make some enhancement on the code, add dict which can get the enum name by id

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Co-authored-by: richardyu <richardyu@contoso.com>

Signed-off-by: richardyu <richardyu@contoso.com>
Signed-off-by: Richard.Yu <richard.yu@microsoft.com>
Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Co-authored-by: richardyu <richardyu@contoso.com>
richardyu-ms added a commit to richardyu-ms/SAI that referenced this pull request Nov 1, 2022
…opencomputeproject#1626)

* [SAI-PTF] Enhance the function for getting counters in sai_adapter.py

    Resolve issue opencomputeproject#1614

    For the auto-generated adapter, need to add a parameter for which counter_id/counter_ids we want, in order to compatiable with current code and reduce the modification, we can define a constant parameter as the list of counter_ids, and use this constant as the default.

    Before

    ```
    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid):

        counter_ids = []
        counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

    After the refactor
    ```
    sai_get_bfd_session_stats_counter_ids = []
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid,
                                         counter_ids=sai_get_bfd_session_stats_counter_ids):

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

* make some enhancement on the code, add dict which can get the enum name by id

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Co-authored-by: richardyu <richardyu@contoso.com>
richardyu-ms added a commit that referenced this pull request Nov 1, 2022
* [SAI-PTF] Add decorator for skipping test on specified error (#1609)

* [SAI-PTF] Add decorator for skipping test on specified error

Add decorator method in the perl template  for skipping test on specified error

details:
1. add decorator method in sai_adapter_utils.tt
2. use decorator when set parameters ``skip_error``
3. add parameters when building from template, like ``perl -Irpc gensairpc.pl  --skip_error=-2,-3``
4. remove the new added parameters, add more doc
Test done:
make  rpc

Signed-off-by: richardyu <richardyu@contoso.com>

* Update sai_fdb_test.py

remove unnecessary test

Signed-off-by: Richard.Yu <richard.yu@microsoft.com>

Signed-off-by: richardyu <richardyu@contoso.com>
Signed-off-by: Richard.Yu <richard.yu@microsoft.com>
Co-authored-by: richardyu <richardyu@contoso.com>

* [SAI-PTF] Enhance the function for getting counters in sai_adapter.py (#1626)

* [SAI-PTF] Enhance the function for getting counters in sai_adapter.py

    Resolve issue #1614

    For the auto-generated adapter, need to add a parameter for which counter_id/counter_ids we want, in order to compatiable with current code and reduce the modification, we can define a constant parameter as the list of counter_ids, and use this constant as the default.

    Before

    ```
    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid):

        counter_ids = []
        counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
        counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

    After the refactor
    ```
    sai_get_bfd_session_stats_counter_ids = []
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS)
    sai_get_bfd_session_stats_counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS)

    def sai_thrift_get_bfd_session_stats(client,
                                         bfd_session_oid,
                                         counter_ids=sai_get_bfd_session_stats_counter_ids):

        counters = [0] * 3
        global status
        status = SAI_STATUS_SUCCESS
    ```

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

* make some enhancement on the code, add dict which can get the enum name by id

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Co-authored-by: richardyu <richardyu@contoso.com>

Signed-off-by: richardyu <richardyu@contoso.com>
Signed-off-by: Richard.Yu <richard.yu@microsoft.com>
Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Co-authored-by: richardyu <richardyu@contoso.com>
@richardyu-ms richardyu-ms deleted the counter_saiadaptor branch January 1, 2023 04:14
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