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

fix dhcpv6 counters are not cleared on clear command #38

Merged
merged 1 commit into from
Jun 5, 2023

Conversation

jcaiMR
Copy link
Contributor

@jcaiMR jcaiMR commented May 25, 2023

Description of PR

Fix dhcpv6 counters are not cleared after "clear dhcp6relay_counters", or "sonic-db-cli STATE_DB hmset "DHCPv6_COUNTER_TABLE|Vlan1000" {} 0

Summary:
Fix sonic-net/sonic-buildimage#14447
dhcpv6 relay counter cached in original relay code, so even we clear counter in STATE_DB, next time when packets come from downlink or uplink ports, counter will be flushed with relay cached data + 1, so the counter flushed back to original data + 1.

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Back port request

  • 201911
  • 202012
  • 202205
    Need in 202205 and 202012, need manually double commit because of code conflict.

Approach

What is the motivation for this PR?

Fix clear counter issue

How did you do it?

Remove cache in dhcp_relay code, instead we will read count from STATE_DB then refresh.

How did you verify/test it?

test_dhcpv6_relay.py::test_dhcpv6_relay_counter multiple times and with clear counter.

Any platform specific information?

Supported testbed topology if it's a new test case?

@jcaiMR jcaiMR requested a review from kellyyeh May 25, 2023 16:08
src/relay.cpp Outdated
state_db->hset(counterVlan, "Relay-Forward", toString(counters[DHCPv6_MESSAGE_TYPE_RELAY_FORW]));
state_db->hset(counterVlan, "Relay-Reply", toString(counters[DHCPv6_MESSAGE_TYPE_RELAY_REPL]));
state_db->hset(counterVlan, "Malformed", toString(counters[DHCPv6_MESSAGE_TYPE_MALFORMED]));
void initialize_counter(std::shared_ptr<swss::DBConnector> state_db, std::string ifname) {
Copy link
Contributor Author

@jcaiMR jcaiMR May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here is if counter is not zero, keep original data.
If counter not exists, initialize it to 0.

So container restart will not clear counter, clear counter cli or sonic-db-cli can clear counters.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A container restart is supposed to happen if there is a config change or config reload. And so i think its is okay to zero all the counters initially. and then the STATE_DB is reflective of the status of counters seen during the lifetime of the current process.

we anyway have dhcpmon which tracks and dumps counters periodically or when its terminated crct.

Also, what about the stale entries. i.e. if some VLAN is removed and we do a container restart the entries in STATE_DB would remain forever unless clear is called. During process init, i suggest clearing out the entire DHCPv6_COUNTER_TABLE table

@jcaiMR jcaiMR requested review from vivekrnv and yxieca May 25, 2023 16:11
src/relay.h Outdated Show resolved Hide resolved
src/relay.h Outdated Show resolved Hide resolved
src/relay.cpp Outdated Show resolved Hide resolved
src/relay.cpp Outdated Show resolved Hide resolved
src/relay.cpp Outdated
state_db->hset(counterVlan, "Relay-Forward", toString(counters[DHCPv6_MESSAGE_TYPE_RELAY_FORW]));
state_db->hset(counterVlan, "Relay-Reply", toString(counters[DHCPv6_MESSAGE_TYPE_RELAY_REPL]));
state_db->hset(counterVlan, "Malformed", toString(counters[DHCPv6_MESSAGE_TYPE_MALFORMED]));
void initialize_counter(std::shared_ptr<swss::DBConnector> state_db, std::string ifname) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A container restart is supposed to happen if there is a config change or config reload. And so i think its is okay to zero all the counters initially. and then the STATE_DB is reflective of the status of counters seen during the lifetime of the current process.

we anyway have dhcpmon which tracks and dumps counters periodically or when its terminated crct.

Also, what about the stale entries. i.e. if some VLAN is removed and we do a container restart the entries in STATE_DB would remain forever unless clear is called. During process init, i suggest clearing out the entire DHCPv6_COUNTER_TABLE table

@jcaiMR jcaiMR force-pushed the dev/dhcprelay_counter_fix branch from 1a1bd6f to 1b4c76e Compare May 26, 2023 07:18
@jcaiMR jcaiMR force-pushed the dev/dhcprelay_counter_fix branch from 2426e3c to de3f99f Compare May 26, 2023 12:15
@@ -1089,8 +1075,7 @@ void loop_relay(std::unordered_map<std::string, relay_config> &vlans) {

update_vlan_mapping(vlan.first, config_db);

std::string counterVlan = counter_table;
initialize_counter(vlan.second.state_db, counterVlan.append(vlan.second.interface));
initialize_counter(vlan.second.state_db, vlan.second.interface);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, i also suggest clearing out the entire COUNTERS Table, during init. That'll fix this issue as well https://github.com/sonic-net/sonic-buildimage/issues/15047

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sonic-net/sonic-buildimage#15047

Looks like the issue is handled by sonic-net/sonic-utilities#2852, not required to clear DHCPv6_COUNTERS table here. #Resolved

@jcaiMR jcaiMR merged commit 511ef96 into sonic-net:master Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[dhcp6_relay] [counters] dhcpv6 counters are not cleared on clear command
3 participants