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

[202311][counter] Clear counter table when dhcpmon init (#14) #16

Merged
merged 1 commit into from
Jan 10, 2024
Merged
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
21 changes: 20 additions & 1 deletion src/dhcp_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,25 @@ void update_vlan_mapping(std::shared_ptr<swss::DBConnector> db_conn) {
}
}


/**
* @code clear_counter(std::shared_ptr<swss::DBConnector> state_db);
*
* @brief Clear all counter
*
* @param state_db state_db connector pointer
*
*/
void clear_counter(std::shared_ptr<swss::DBConnector> state_db) {
std::string match_pattern = DB_COUNTER_TABLE + std::string("*");
auto keys = state_db->keys(match_pattern);

for (auto &itr : keys) {
state_db->del(itr);
}
}


/** update ethernet interface to port-channel map
* PORTCHANNEL_MEMBER|PortChannel101|Ethernet112
*/
Expand Down Expand Up @@ -265,7 +284,6 @@ void initialize_db_counters(std::string &ifname)
{
auto table_name = DB_COUNTER_TABLE + ifname;
auto init_value = gen_counter_json_str(db_counter);
mStateDbPtr->del(table_name);
mStateDbPtr->hset(table_name, "RX", init_value);
mStateDbPtr->hset(table_name, "TX", init_value);
}
Expand Down Expand Up @@ -924,6 +942,7 @@ int dhcp_device_start_capture(size_t snaplen, struct event_base *base, in_addr_t

init_recv_buffers(snaplen);

clear_counter(mStateDbPtr);
update_vlan_mapping(mConfigDbPtr);
update_portchannel_mapping(mConfigDbPtr);
update_mgmt_mapping();
Expand Down