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

[orchagent] add & remove port counters dynamically each time port was added or removed #2019

Merged

Conversation

tomer-israel
Copy link
Contributor

@tomer-israel tomer-israel commented Nov 9, 2021

What I did
Add support for adding & removing port counters dynamically each time port was added or removed
the counters that were supported are:

  • pg watermark counters
  • pg drop counters
  • queue stat counters
  • queue watermark counters
  • debug counters
  • buffer drop counters and port stat counters are already supported to be added or removed each time port is added/removed

Implemented according to the - HLD document on add/remove ports dynamically feature

Why I did it
In order to support dynamically add or removed ports on sonic

How I verified it
tested manually that the flex counters were added or removed correctly whenever we add or remove ports
added new test cases to the following vs tests:

  • test_flex_counters.py
  • test_drop_counters.py
  • test_pg_drop_counter.py

Details if related

@lgtm-com
Copy link

lgtm-com bot commented Nov 9, 2021

This pull request fixes 2 alerts when merging a343a09 into 05c7c05 - view on LGTM.com

fixed alerts:

  • 2 for Unused import

@liat-grozovik
Copy link
Collaborator

@praveen-li I am unable to assign code review to you. Could you please add yourself as the reviewer?

@lgtm-com
Copy link

lgtm-com bot commented Nov 11, 2021

This pull request fixes 2 alerts when merging 550fe05 into 5f8ebfa - view on LGTM.com

fixed alerts:

  • 2 for Unused import

@dprital
Copy link
Collaborator

dprital commented Nov 21, 2021

@prsunny - Can you please add @praveen-li as a reviewer ?

@lgtm-com
Copy link

lgtm-com bot commented Nov 22, 2021

This pull request fixes 2 alerts when merging 3e72fa4 into 4f6cb05 - view on LGTM.com

fixed alerts:

  • 2 for Unused import

@tomer-israel
Copy link
Contributor Author

/azpw run

@mssonicbld
Copy link
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tomer-israel
Copy link
Contributor Author

/azpw run

@mssonicbld
Copy link
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tomer-israel
Copy link
Contributor Author

/azpw run

@mssonicbld
Copy link
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tomer-israel
Copy link
Contributor Author

/azpw run

@mssonicbld
Copy link
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

{
SWSS_LOG_ENTER();

SWSS_LOG_NOTICE("add debug counter for port 0x%" PRIu64 , port_id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

INFO?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will change it to INFO


SWSS_LOG_NOTICE("add debug counter for port 0x%" PRIu64 , port_id);

for (const auto& debug_counter: debug_counters) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

put { in the second line as consistency as other code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be changed

auto counter_stat = counter->getDebugCounterSAIStat();
auto flex_counter_type = getFlexCounterType(counter_type);

if (flex_counter_type == CounterType::PORT_DEBUG){
Copy link
Collaborator

Choose a reason for hiding this comment

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

put { in the second line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be changed

{
SWSS_LOG_ENTER();

SWSS_LOG_NOTICE("remove debug counter for port 0x%" PRIu64 , port_id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be change to INFO


SWSS_LOG_NOTICE("remove debug counter for port 0x%" PRIu64 , port_id);

for (const auto& debug_counter: debug_counters) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

put { in the second line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be change

auto counter_stat = counter->getDebugCounterSAIStat();
auto flex_counter_type = getFlexCounterType(counter_type);

if (flex_counter_type == CounterType::PORT_DEBUG){
Copy link
Collaborator

Choose a reason for hiding this comment

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

put { in the second line

Copy link
Contributor Author

@tomer-israel tomer-israel Nov 30, 2021

Choose a reason for hiding this comment

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

will be change

}
}

void DebugCounterOrch::removePortDebugCounter(sai_object_id_t port_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

re-use existing function like uninstallDebugFlexCounters()?

Copy link
Contributor Author

@tomer-israel tomer-israel Nov 30, 2021

Choose a reason for hiding this comment

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

uninstallDebugFlexCounters is removing the debug counters from all the ports, in order to fit the function uninstallDebugFlexCounters to remove only one port debug counter we need to add extra argument for indicating which ports to remove (specific port or all the ports)

do you think it's better to change uninstallDebugFlexCounters for that?

like this example:

void DebugCounterOrch::uninstallDebugFlexCounters(const string& counter_type,
                                                  const string& counter_stat,
                                                  sai_object_id_t port_id = SAI_NULL_OBJECT_ID)
{
    SWSS_LOG_ENTER();
    CounterType flex_counter_type = getFlexCounterType(counter_type);

    if (flex_counter_type == CounterType::SWITCH_DEBUG)
    {
        flex_counter_manager.removeFlexCounterStat(gSwitchId, flex_counter_type, counter_stat);
    }
    else if (flex_counter_type == CounterType::PORT_DEBUG)
    {
        if (port_id != SAI_NULL_OBJECT_ID)
        {
            flex_counter_manager.removeFlexCounterStat(
                curr.second.m_port_id,
                flex_counter_type,
                counter_stat);
        }
        else
        {
            for (auto const &curr : gPortsOrch->getAllPorts())
            {
                if (curr.second.m_type != Port::Type::PHY)
                {
                    continue;
                }

                flex_counter_manager.removeFlexCounterStat(
                    curr.second.m_port_id,
                    flex_counter_type,
                    counter_stat);
            }
        }
    }
} 

or this option:

void DebugCounterOrch::uninstallDebugFlexCounters(const string& counter_type,
                                                  const string& counter_stat,
                                                  sai_object_id_t port_id = SAI_NULL_OBJECT_ID)
{
    SWSS_LOG_ENTER();
    CounterType flex_counter_type = getFlexCounterType(counter_type);

    if (flex_counter_type == CounterType::SWITCH_DEBUG)
    {
        flex_counter_manager.removeFlexCounterStat(gSwitchId, flex_counter_type, counter_stat);
    }
    else if (flex_counter_type == CounterType::PORT_DEBUG)
    {

        for (auto const &curr : gPortsOrch->getAllPorts())
        {
            if (port_id != SAI_NULL_OBJECT_ID)
            {
                if (curr.second.m_port_id != port_id)
                {
                    continue;
                }
            }

            if (curr.second.m_type != Port::Type::PHY)
            {
                continue;
            }

            flex_counter_manager.removeFlexCounterStat(
                curr.second.m_port_id,
                flex_counter_type,
                counter_stat);
        }
    }
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

The point was to not introduce more functions that has similar needs. One of the option should be fine but be consistent with the Add counter function case.

Copy link
Contributor Author

@tomer-israel tomer-israel Dec 15, 2021

Choose a reason for hiding this comment

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

was changed to the second option for add and remove

@@ -616,3 +640,50 @@ bool DebugCounterOrch::isDropReasonValid(const string& drop_reason) const

return true;
}

void DebugCounterOrch::addPortDebugCounter(sai_object_id_t port_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

re-use installDebugFlexCounters()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

if (!getPort(port_id, p))
{
SWSS_LOG_ERROR("Failed to get port object for port id 0x%" PRIx64, port_id);
p.m_port_id = port_id;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why assign p.m_port_id only when failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the way they did it in previous version but, i think it's not needed, if get_port is failing so we just need to add error message and return from this function.
I will change it

@lgtm-com
Copy link

lgtm-com bot commented Nov 30, 2021

This pull request fixes 2 alerts when merging d868d8c into f6f6f86 - view on LGTM.com

fixed alerts:

  • 2 for Unused import

@tomer-israel
Copy link
Contributor Author

/azpw run

@mssonicbld
Copy link
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tomer-israel
Copy link
Contributor Author

/azpw run

@mssonicbld
Copy link
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lgtm-com
Copy link

lgtm-com bot commented Dec 1, 2021

This pull request fixes 2 alerts when merging 904b583 into 15a3b6c - view on LGTM.com

fixed alerts:

  • 2 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Dec 2, 2021

This pull request fixes 2 alerts when merging 3bc9fb5 into d352d5a - view on LGTM.com

fixed alerts:

  • 2 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Mar 27, 2022

This pull request fixes 2 alerts when merging e92133c into 7350d49 - view on LGTM.com

fixed alerts:

  • 2 for Unused import

@liat-grozovik
Copy link
Collaborator

/azp run Azure.sonic-swss

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -2378,6 +2378,16 @@ bool PortsOrch::initPort(const string &alias, const string &role, const int inde
port_buffer_drop_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, port_buffer_drop_stats);
}

/* when a port is added and priority group map counter is enabled --> we need to add pg counter for it */
if (m_isPriorityGroupMapGenerated) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

"{" to separate line to be consistent.

Can you go through the whole PR to make sure we follow the same coding style?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done!

}

/* when a port is added and queue map counter is enabled --> we need to add queue map counter for it */
if (m_isQueueMapGenerated) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done!

@@ -2425,9 +2440,18 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
port_buffer_drop_stat_manager.clearCounterIdList(p.m_port_id);
}

/* remove pg port counters */
if (m_isPriorityGroupMapGenerated) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

{ to separate line

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done!

}

/* remove queue port counters */
if (m_isQueueMapGenerated) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

{ to separate line

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done!

@lgtm-com
Copy link

lgtm-com bot commented Mar 28, 2022

This pull request fixes 2 alerts when merging ca47331 into 8941cc0 - view on LGTM.com

fixed alerts:

  • 2 for Unused import

@dprital
Copy link
Collaborator

dprital commented Mar 28, 2022

@prsunny - Can you please approve this PR ?

@liat-grozovik
Copy link
Collaborator

/azp run Azure.sonic-swss

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@dprital
Copy link
Collaborator

dprital commented Mar 30, 2022

@prsunny - can you please review ?

@dprital
Copy link
Collaborator

dprital commented Apr 5, 2022

@prsunny - Can you please review ?

@liat-grozovik liat-grozovik merged commit 53620f3 into sonic-net:master Apr 7, 2022
dprital added a commit to dprital/sonic-swss that referenced this pull request May 8, 2022
… added or removed (sonic-net#2019)

- What I did
Add support for adding & removing port counters dynamically each time port was added or removed the counters that were supported are:

1. pg watermark counters
2. pg drop counters
3. queue stat counters
4. queue watermark counters
5. debug counters
6. buffer drop counters and port stat counters are already supported to be added or removed each time port is added/removed

Implemented according to the - 'HLD document on add/remove ports dynamically feature' sonic-net/SONiC#900

- Why I did it
In order to support dynamically add or removed ports on sonic

- How I verified it
tested manually that the flex counters were added or removed correctly whenever we add or remove ports
added new test cases to the following vs tests:

test_flex_counters.py
test_drop_counters.py
test_pg_drop_counter.py

Co-authored-by: dprital <drorp@nvidia.com>
preetham-singh pushed a commit to preetham-singh/sonic-swss that referenced this pull request Aug 6, 2022
… added or removed (sonic-net#2019)

- What I did
Add support for adding & removing port counters dynamically each time port was added or removed the counters that were supported are:

1. pg watermark counters
2. pg drop counters
3. queue stat counters
4. queue watermark counters
5. debug counters
6. buffer drop counters and port stat counters are already supported to be added or removed each time port is added/removed

Implemented according to the - 'HLD document on add/remove ports dynamically feature' sonic-net/SONiC#900

- Why I did it
In order to support dynamically add or removed ports on sonic

- How I verified it
tested manually that the flex counters were added or removed correctly whenever we add or remove ports
added new test cases to the following vs tests:

test_flex_counters.py
test_drop_counters.py
test_pg_drop_counter.py

Co-authored-by: dprital <drorp@nvidia.com>
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.

5 participants