Skip to content

Commit

Permalink
[orchagent] Move PT TAM logic to separate func
Browse files Browse the repository at this point in the history
Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
  • Loading branch information
cscarpitta committed Oct 26, 2023
1 parent 6883ab9 commit fc6b5ba
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 82 deletions.
188 changes: 106 additions & 82 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4151,77 +4151,30 @@ void PortsOrch::doPortTask(Consumer &consumer)
{
/* Path Tracing ENABLED case */

/*
* First, let's check if a TAM object is already assigned to the port.
*/
if (m_portPtTam.find(p.m_alias) == m_portPtTam.end())
/* Create and set port TAM object */
if (!createAndSetPortPtTam(p))
{
/*
* The port does not have a TAM object assigned to it.
*
* Let's create a new TAM object (if we don't already have one)
* and assign it to the port.
*/
if (m_ptTam == SAI_NULL_OBJECT_ID)
{
if (!createPtTam())
{
SWSS_LOG_ERROR(
"Failed to create TAM object for Path Tracing"
);
it++;
continue;
}
}

if (!setPortPtTam(p, m_ptTam))
{
SWSS_LOG_ERROR(
"Failed to set port %s TAM object for Path Tracing",
p.m_alias.c_str()
);
it++;
continue;
}
m_ptTamRefCount++;
m_portPtTam[p.m_alias] = m_ptTam;
SWSS_LOG_ERROR(
"Failed to create and set port %s TAM object for Path Tracing",
p.m_alias.c_str()
);
it++;
continue;
}
}
else
{
/* Path Tracing DISABLED case */

/*
* Let's unassign the TAM object from the port and decrease ref counter
*/
if (m_portPtTam.find(p.m_alias) != m_portPtTam.end())
/* Unset port TAM object */
if (!unsetPortPtTam(p))
{
if (!setPortPtTam(p, SAI_NULL_OBJECT_ID))
{
SWSS_LOG_ERROR(
"Failed to unset port %s TAM object for Path Tracing",
p.m_alias.c_str()
);
it++;
continue;
}
m_ptTamRefCount--;
m_portPtTam.erase(p.m_alias);

/*
* If the TAM object is no longer used, we can safely remove it.
*/
if (m_ptTamRefCount == 0)
{
if (!removePtTam(m_ptTam))
{
SWSS_LOG_ERROR(
"Failed to remove TAM object for Path Tracing"
);
it++;
continue;
}
}
SWSS_LOG_ERROR(
"Failed to unset port %s TAM object for Path Tracing",
p.m_alias.c_str()
);
it++;
continue;
}
}

Expand Down Expand Up @@ -4326,27 +4279,15 @@ void PortsOrch::doPortTask(Consumer &consumer)
}

/*
* Decrease TAM object ref count before removing the port, if the port
* has a TAM object assigned
* Unset port Path Tracing TAM object and decrease TAM object refcount before
* removing the port (if the port has a TAM object associated)
*/
if (m_portPtTam.find(alias) != m_portPtTam.end())
if (!unsetPortPtTam(p))
{
if (!setPortPtTam(p, SAI_NULL_OBJECT_ID))
{
SWSS_LOG_ERROR(
"Failed to unset port %s TAM object for Path Tracing",
p.m_alias.c_str()
);
}
m_ptTamRefCount--;
m_portPtTam.erase(alias);
if (m_ptTamRefCount == 0)
{
if (!removePtTam(m_ptTam))
{
throw runtime_error("Remove port TAM object for Path Tracing failed");
}
}
SWSS_LOG_ERROR(
"Failed to unset port %s TAM object for Path Tracing",
p.m_alias.c_str()
);
}

sai_status_t status = removePort(port_id);
Expand Down Expand Up @@ -8862,6 +8803,89 @@ void PortsOrch::updatePortStatePoll(const Port &port, port_state_poll_t type, bo
}
}

bool PortsOrch::createAndSetPortPtTam(const Port &p)
{
/*
* First, let's check if a TAM object is already assigned to the port.
*/

/* If the port has already a TAM object, nothing to do */
if (m_portPtTam.find(p.m_alias) != m_portPtTam.end())
{
SWSS_LOG_DEBUG(
"Port %s has already a TAM object", p.m_alias.c_str()
);
return true;
}

/*
* The port does not have a TAM object assigned to it.
*
* Let's create a new TAM object (if we don't already have one)
* and assign it to the port.
*/
if (m_ptTam == SAI_NULL_OBJECT_ID)
{
if (!createPtTam())
{
SWSS_LOG_ERROR(
"Failed to create TAM object for Path Tracing"
);
return false;
}
}

if (!setPortPtTam(p, m_ptTam))
{
SWSS_LOG_ERROR(
"Failed to set port %s TAM object for Path Tracing",
p.m_alias.c_str()
);
return false;
}

m_ptTamRefCount++;
m_portPtTam[p.m_alias] = m_ptTam;

return true;
}

bool PortsOrch::unsetPortPtTam(const Port &p)
{
/*
* Let's unassign the TAM object from the port and decrease ref counter
*/
if (m_portPtTam.find(p.m_alias) != m_portPtTam.end())
{
if (!setPortPtTam(p, SAI_NULL_OBJECT_ID))
{
SWSS_LOG_ERROR(
"Failed to unset port %s TAM object for Path Tracing",
p.m_alias.c_str()
);
return false;
}
m_ptTamRefCount--;
m_portPtTam.erase(p.m_alias);

/*
* If the TAM object is no longer used, we can safely remove it.
*/
if (m_ptTamRefCount == 0)
{
if (!removePtTam(m_ptTam))
{
SWSS_LOG_ERROR(
"Failed to remove TAM object for Path Tracing"
);
return false;
}
}
}

return true;
}

bool PortsOrch::getPortPtIntfId(const Port& port, sai_uint16_t &intf_id)
{
sai_attribute_t attr;
Expand Down
2 changes: 2 additions & 0 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ class PortsOrch : public Orch, public Subject
/* Prototypes for Path Tracing */
bool createPtTam();
bool removePtTam(sai_object_id_t tam_id);
bool createAndSetPortPtTam(const Port &p);
bool unsetPortPtTam(const Port &p);
sai_object_id_t m_ptTamReport = SAI_NULL_OBJECT_ID;
sai_object_id_t m_ptTamInt = SAI_NULL_OBJECT_ID;
sai_object_id_t m_ptTam = SAI_NULL_OBJECT_ID;
Expand Down

0 comments on commit fc6b5ba

Please sign in to comment.