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

make reset crm polling interval effective immediately #451

Merged
merged 3 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions orchagent/crmorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ const map<string, CrmResourceType> crmUsedCntsTableMap =
CrmOrch::CrmOrch(DBConnector *db, string tableName):
Orch(db, tableName),
m_countersDb(new DBConnector(COUNTERS_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)),
m_countersCrmTable(new Table(m_countersDb.get(), COUNTERS_CRM_TABLE))
m_countersCrmTable(new Table(m_countersDb.get(), COUNTERS_CRM_TABLE)),
m_timer(new SelectableTimer(timespec { .tv_sec = CRM_POLLING_INTERVAL_DEFAULT, .tv_nsec = 0 }))
{
SWSS_LOG_ENTER();

Expand All @@ -160,11 +161,9 @@ CrmOrch::CrmOrch(DBConnector *db, string tableName):
m_resourcesMap.emplace(res.first, CrmResourceEntry(res.second, CRM_THRESHOLD_TYPE_DEFAULT, CRM_THRESHOLD_LOW_DEFAULT, CRM_THRESHOLD_HIGH_DEFAULT));
}

auto interv = timespec { .tv_sec = CRM_POLLING_INTERVAL_DEFAULT, .tv_nsec = 0 };
auto timer = new SelectableTimer(interv);
auto executor = new ExecutableTimer(timer, this);
auto executor = new ExecutableTimer(m_timer.get(), this);
Orch::addExecutor("CRM_COUNTERS_POLL", executor);
timer->start();
m_timer->start();
}

CrmOrch::CrmResourceEntry::CrmResourceEntry(string name, CrmThresholdType thresholdType, uint32_t lowThreshold, uint32_t highThreshold):
Expand Down Expand Up @@ -236,6 +235,9 @@ void CrmOrch::handleSetCommand(const string& key, const vector<FieldValueTuple>&
if (field == CRM_POLLING_INTERVAL)
{
m_pollingInterval = chrono::seconds(to_uint<uint32_t>(value));
auto interv = timespec { .tv_sec = m_pollingInterval.count(), .tv_nsec = 0 };
m_timer->setInterval(interv);
m_timer->reset();
}
else if (crmThreshTypeResMap.find(field) != crmThreshTypeResMap.end())
{
Expand Down
1 change: 1 addition & 0 deletions orchagent/crmorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class CrmOrch : public Orch
private:
shared_ptr<DBConnector> m_countersDb = nullptr;
shared_ptr<Table> m_countersCrmTable = nullptr;
shared_ptr<SelectableTimer> m_timer = nullptr;

struct CrmResourceCounter
{
Expand Down
11 changes: 11 additions & 0 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,17 @@ void Orch::addExecutor(string executorName, Executor* executor)
std::forward_as_tuple(executor));
}

Executor *Orch::getExecutor(string executorName)
{
auto it = m_consumerMap.find(executorName);
if (it != m_consumerMap.end())
{
return it->second.get();
}

return NULL;
}

void Orch2::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();
Expand Down
1 change: 1 addition & 0 deletions orchagent/orch.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class Orch

/* Note: consumer will be owned by this class */
void addExecutor(string executorName, Executor* executor);
Executor *getExecutor(string executorName);
private:
void addConsumer(DBConnector *db, string tableName);
};
Expand Down
60 changes: 30 additions & 30 deletions tests/test_crm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_CrmFdbEntry(dvs):

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000')

time.sleep(5*60)
time.sleep(2)

# get counters
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used')
Expand All @@ -72,7 +72,7 @@ def test_CrmFdbEntry(dvs):
# update available counter
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '999')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used')
Expand All @@ -84,7 +84,7 @@ def test_CrmFdbEntry(dvs):
# update available counter
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000')

time.sleep(1)
time.sleep(2)

# get counters
new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available')
Expand All @@ -107,7 +107,7 @@ def test_CrmIpv4Route(dvs):
ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE")
fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")])

time.sleep(5*60)
time.sleep(2)

# get counters
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used')
Expand All @@ -117,7 +117,7 @@ def test_CrmIpv4Route(dvs):
ps.set("2.2.2.0/24", fvs)
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '999')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used')
Expand All @@ -131,7 +131,7 @@ def test_CrmIpv4Route(dvs):
dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used')
Expand Down Expand Up @@ -163,7 +163,7 @@ def test_CrmIpv6Route(dvs):
ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE")
fvs = swsscommon.FieldValuePairs([("nexthop","fc00::2"), ("ifname", "Ethernet0")])

time.sleep(5*60)
time.sleep(2)

# get counters
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used')
Expand All @@ -173,7 +173,7 @@ def test_CrmIpv6Route(dvs):
ps.set("2001::/64", fvs)
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '999')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used')
Expand All @@ -187,7 +187,7 @@ def test_CrmIpv6Route(dvs):
dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used')
Expand All @@ -205,7 +205,7 @@ def test_CrmIpv4Nexthop(dvs):

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000')

time.sleep(5*60)
time.sleep(2)

# get counters
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used')
Expand All @@ -215,7 +215,7 @@ def test_CrmIpv4Nexthop(dvs):
dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '999')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used')
Expand All @@ -228,7 +228,7 @@ def test_CrmIpv4Nexthop(dvs):
dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used')
Expand All @@ -250,7 +250,7 @@ def test_CrmIpv6Nexthop(dvs):

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000')

time.sleep(5*60)
time.sleep(2)

# get counters
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used')
Expand All @@ -260,7 +260,7 @@ def test_CrmIpv6Nexthop(dvs):
dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '999')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used')
Expand All @@ -273,7 +273,7 @@ def test_CrmIpv6Nexthop(dvs):
dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used')
Expand All @@ -291,7 +291,7 @@ def test_CrmIpv4Neighbor(dvs):

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000')

time.sleep(5*60)
time.sleep(2)

# get counters
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used')
Expand All @@ -301,7 +301,7 @@ def test_CrmIpv4Neighbor(dvs):
dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '999')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used')
Expand All @@ -314,7 +314,7 @@ def test_CrmIpv4Neighbor(dvs):
dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used')
Expand All @@ -336,7 +336,7 @@ def test_CrmIpv6Neighbor(dvs):

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000')

time.sleep(5*60)
time.sleep(2)

# get counters
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used')
Expand All @@ -346,7 +346,7 @@ def test_CrmIpv6Neighbor(dvs):
dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '999')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used')
Expand All @@ -359,7 +359,7 @@ def test_CrmIpv6Neighbor(dvs):
dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used')
Expand All @@ -386,7 +386,7 @@ def test_CrmNexthopGroup(dvs):
ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE")
fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3"), ("ifname", "Ethernet0,Ethernet4")])

time.sleep(5*60)
time.sleep(2)

# get counters
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used')
Expand All @@ -396,7 +396,7 @@ def test_CrmNexthopGroup(dvs):
ps.set("2.2.2.0/24", fvs)
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '999')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used')
Expand All @@ -411,7 +411,7 @@ def test_CrmNexthopGroup(dvs):
dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used')
Expand All @@ -438,7 +438,7 @@ def test_CrmNexthopGroupMember(dvs):
ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE")
fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3"), ("ifname", "Ethernet0,Ethernet4")])

time.sleep(5*60)
time.sleep(2)

# get counters
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used')
Expand All @@ -448,7 +448,7 @@ def test_CrmNexthopGroupMember(dvs):
ps.set("2.2.2.0/24", fvs)
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '998')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used')
Expand All @@ -463,7 +463,7 @@ def test_CrmNexthopGroupMember(dvs):
dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000')

time.sleep(1)
time.sleep(2)

# get counters
new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used')
Expand Down Expand Up @@ -492,7 +492,7 @@ def test_CrmAcl(dvs):
fvs = swsscommon.FieldValuePairs([("priority", "55"), ("PACKET_ACTION", "FORWARD"), ("L4_SRC_PORT", "65000")])
rtbl.set("test|acl_test_rule", fvs)

time.sleep(5*60)
time.sleep(2)

table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used')
assert table_used_counter == 1
Expand All @@ -511,7 +511,7 @@ def test_CrmAcl(dvs):
# remove ACL rule
rtbl._del("test|acl_test_rule")

time.sleep(1)
time.sleep(2)

entry_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_entry_used')
assert entry_used_counter == 0
Expand All @@ -522,7 +522,7 @@ def test_CrmAcl(dvs):
# remove ACL table
ttbl._del("test")

time.sleep(1)
time.sleep(2)

table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used')
assert table_used_counter == 0
Expand Down