Skip to content

Commit

Permalink
[everflow]: Fixed issue with accessing ACL counters of inactive sessi…
Browse files Browse the repository at this point in the history
…on. (sonic-net#188)
  • Loading branch information
oleksandrivantsiv authored and marian-pritsak committed Apr 12, 2017
1 parent ee14e9e commit 807318d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
44 changes: 36 additions & 8 deletions orchagent/aclorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,23 @@ bool AclRule::remove()
return res;
}

AclRuleCounters AclRule::getCounters()
{
SWSS_LOG_ENTER();

sai_attribute_t counter_attr[2];
counter_attr[0].id = SAI_ACL_COUNTER_ATTR_PACKETS;
counter_attr[1].id = SAI_ACL_COUNTER_ATTR_BYTES;

if (sai_acl_api->get_acl_counter_attribute(m_counterOid, 2, counter_attr) != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get counters for %s rule", m_id.c_str());
return AclRuleCounters();
}

return AclRuleCounters(counter_attr[0].value.u64, counter_attr[1].value.u64);
}

shared_ptr<AclRule> AclRule::makeShared(acl_table_type_t type, AclOrch *acl, MirrorOrch *mirror, string rule, string table)
{
switch (type)
Expand Down Expand Up @@ -591,7 +608,7 @@ bool AclRuleMirror::create()
return false;
}

state = true;
m_state = true;

return m_pMirrorOrch->increaseRefCount(m_sessionName);
}
Expand Down Expand Up @@ -629,11 +646,26 @@ void AclRuleMirror::update(SubjectType type, void *cntx)
}
else
{
// Store counters before deactivating ACL rule
counters += getCounters();

SWSS_LOG_INFO("Deactivating mirroring ACL %s for session %s", m_id.c_str(), m_sessionName.c_str());
remove();
}
}

AclRuleCounters AclRuleMirror::getCounters()
{
AclRuleCounters cnt(counters);

if (m_state)
{
cnt += AclRule::getCounters();
}

return cnt;
}

AclRange::AclRange(sai_acl_range_type_t type, sai_object_id_t oid, int min, int max):
m_oid(oid), m_refCnt(0), m_min(min), m_max(max), m_type(type)
{
Expand Down Expand Up @@ -1271,9 +1303,6 @@ sai_status_t AclOrch::deleteUnbindAclTable(sai_object_id_t table_oid)
void AclOrch::collectCountersThread(AclOrch* pAclOrch)
{
SWSS_LOG_ENTER();
sai_attribute_t counter_attr[2];
counter_attr[0].id = SAI_ACL_COUNTER_ATTR_PACKETS;
counter_attr[1].id = SAI_ACL_COUNTER_ATTR_BYTES;

while(m_bCollectCounters)
{
Expand All @@ -1288,14 +1317,13 @@ void AclOrch::collectCountersThread(AclOrch* pAclOrch)

for (auto rule_it : table_it.second.rules)
{
sai_acl_api->get_acl_counter_attribute(rule_it.second->getCounterOid(), 2, counter_attr);
AclRuleCounters cnt = rule_it.second->getCounters();

swss::FieldValueTuple fvtp("Packets", to_string(counter_attr[0].value.u64));
swss::FieldValueTuple fvtp("Packets", to_string(cnt.packets));
values.push_back(fvtp);
swss::FieldValueTuple fvtb("Bytes", to_string(counter_attr[1].value.u64));
swss::FieldValueTuple fvtb("Bytes", to_string(cnt.bytes));
values.push_back(fvtb);

SWSS_LOG_DEBUG("Counter %lX, value %ld/%ld", rule_it.second->getCounterOid(), counter_attr[0].value.u64, counter_attr[1].value.u64);
AclOrch::getCountersTable().set(table_it.second.id + ":" + rule_it.second->getId(), values, "");
}
values.clear();
Expand Down
28 changes: 28 additions & 0 deletions orchagent/aclorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ class AclRange
static map<acl_range_properties_t, AclRange*> m_ranges;
};

struct AclRuleCounters
{
uint64_t packets;
uint64_t bytes;

AclRuleCounters(uint64_t p = 0, uint64_t b = 0) :
packets(p),
bytes(b)
{
}

AclRuleCounters(const AclRuleCounters& rhs) :
packets(rhs.packets),
bytes(rhs.bytes)
{
}

AclRuleCounters& operator +=(const AclRuleCounters& rhs)
{
packets += rhs.packets;
bytes += rhs.bytes;
return *this;
}
};

class AclRule
{
public:
Expand All @@ -113,6 +138,7 @@ class AclRule
virtual bool create();
virtual bool remove();
virtual void update(SubjectType, void *) = 0;
virtual AclRuleCounters getCounters();

string getId()
{
Expand Down Expand Up @@ -170,10 +196,12 @@ class AclRuleMirror: public AclRule
bool create();
bool remove();
void update(SubjectType, void *);
AclRuleCounters getCounters();

protected:
bool m_state;
string m_sessionName;
AclRuleCounters counters;
MirrorOrch *m_pMirrorOrch;
};

Expand Down

0 comments on commit 807318d

Please sign in to comment.