Skip to content

Commit

Permalink
[counter] Clear counter table when dhcpmon init
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqiangz committed Dec 27, 2023
1 parent 7c55e50 commit 826854f
Showing 1 changed file with 20 additions and 1 deletion.
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 = 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

0 comments on commit 826854f

Please sign in to comment.