Skip to content

Commit

Permalink
[counter] Clear counter table when dhcpmon init (#14) (#16)
Browse files Browse the repository at this point in the history
Cherry-pick from #14

Why I did it
Fix issue sonic-net/sonic-buildimage#15047
dhcp counter didn't restore after config reload

Work item tracking
Microsoft ADO (number only): 26270786
How I did it
Clear all counters when dhcpmon start
Remove clear counter in initialize_counter since they are cleared in previous
How to verify it
Build debian packet and install in DUT do manually testing
Run dhcp_relay test, all passed
  • Loading branch information
yaqiangz authored Jan 10, 2024
1 parent 7c55e50 commit 2443073
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 = 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

0 comments on commit 2443073

Please sign in to comment.