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

[pd] add pd daemon service to support the automation of dhcpcd PD management #2360

Merged
merged 12 commits into from
Nov 7, 2024

Conversation

sherysheng
Copy link
Contributor

@sherysheng sherysheng commented Jul 4, 2024

The changes include:

PD daemon (dhcp6_pd_daemon.py) to monitor and react to PD state changes between running and stopped/disabled.
Creation of systemd service file (dhcp6_pd_daemon.service) for managing the daemon.
Update of _dhcpv6_pd_ref to support pd daemon installation and uninstallation

This scripts essentially automate the process of setting up a machine as a dhcpcd pd reference device, handling prefix delegation.

local test log:
Terminal #1:
sherys@raspberrypi:~ $ python3 dhcp6_pd_daemon.py
2024-07-06 03:35:31,718 - INFO - Connected to D-Bus signal.
2024-07-06 03:35:41,577 - INFO - Dhcp6PdState changed to: running
2024-07-06 03:35:42,182 - INFO - Successfully restarted dhcpcd service.

Terminal #2:

br pd enable
Done
br pd state
running
Done
br pd disable
Done
br pd state
disabled
Done

Terminal #3:
signal time=1719724170.782791 sender=:1.32 -> destination=(null destination) serial=14 path=/io/openthread/BorderRouter/wpan0; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string "io.openthread.BorderRouter"
array [
dict entry(
string "Dhcp6PdState"
variant string "running"
)
]
array [
]
signal time=1719724369.495711 sender=:1.32 -> destination=(null destination) serial=16 path=/io/openthread/BorderRouter/wpan0; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string "io.openthread.BorderRouter"
array [
dict entry(
string "Dhcp6PdState"
variant string "disabled"
)
]
array [
]

Copy link

codecov bot commented Jul 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 45.95%. Comparing base (2b41187) to head (93904d1).
Report is 862 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2360      +/-   ##
==========================================
- Coverage   55.77%   45.95%   -9.83%     
==========================================
  Files          87      105      +18     
  Lines        6890    12575    +5685     
  Branches        0      912     +912     
==========================================
+ Hits         3843     5779    +1936     
- Misses       3047     6482    +3435     
- Partials        0      314     +314     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sherysheng sherysheng requested review from erjiaqing, alinlazar, Irving-cl and superwhd and removed request for alinlazar July 5, 2024 05:28
Copy link
Contributor

@erjiaqing erjiaqing left a comment

Choose a reason for hiding this comment

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

LGTM overall, a few comments for code style.

Thanks!

script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
@suveshpratapa
Copy link
Member

@jwhui @sherysheng Can we prioritize getting this change in soon? It appears we're waiting on this for some PD client qualifying tests in certification.

script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
backup_dir = "/var/lib/ot-dhcpcd-backup"

def properties_changed_handler(interface_name, changed_properties, invalidated_properties):
if "Dhcp6PdState" in changed_properties:
Copy link
Contributor

Choose a reason for hiding this comment

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

You may replace is large 'if' block with an early return.

Copy link
Contributor

Choose a reason for hiding this comment

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

ping on this

if os.path.isfile("/etc/dhcpcd.conf.custom"):
subprocess.run(["sudo", "cp", "/etc/dhcpcd.conf.custom", "/etc/dhcpcd.conf"], check=True)
try:
subprocess.run(["sudo", "systemctl", "daemon-reload"], check=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this daemon-reload is not necessary?

@yangsong-cnyn
Copy link
Contributor

yangsong-cnyn commented Oct 31, 2024

Local test result 10/31:

  1. dhcp6_pd_daemon.py
2024-10-31 18:15:14,378 - INFO - Connected to D-Bus signal.
2024-10-31 18:16:00,277 - INFO - Dhcp6PdState changed to: running
2024-10-31 18:16:09,739 - INFO - Successfully restarted dhcpcd service.
2024-10-31 18:19:11,745 - INFO - Dhcp6PdState changed to: disabled
2024-10-31 18:19:21,577 - INFO - Successfully restored default dhcpcd config.
2024-10-31 18:25:12,337 - INFO - Dhcp6PdState changed to: running
2024-10-31 18:25:22,171 - INFO - Successfully restarted dhcpcd service.
  1. ot-ctl
> dataset init new
Done
> dataset commit active
Done
> ifconfig up
Done
> thread start
Done
> br pd disable
Done
> netdata show
Prefixes:
fdfd:ddf0:fb15:1::/64 paros low 7000
Routes:
::/0 s med 7000
fdfd:ddf0:fb15:2:0:0::/96 sn low 7000
Services:
44970 01 08000500000e10 s 7000 0
44970 5d fded926d4a185bf8fcffe531d2791f5fd121 s 7000 1
Contexts:
fdfd:ddf0:fb15:1::/64 1 c
2001:db8:13:600::/64 2 -
Commissioning:
14091 - - -
Done
> br pd enable
Done
> netdata show
Prefixes:
2001:db8:13:600::/64 paros med 7000
Routes:
::/0 s med 7000
64:ff9b:0:0:0:0::/96 sn med 7000
Services:
44970 01 08000500000e10 s 7000 0
Contexts:
fdfd:ddf0:fb15:1::/64 1 -
2001:db8:13:600::/64 2 c
Commissioning:
14091 - - -
Done
> netdata show
Prefixes:
2001:db8:13:600::/64 paros med 7000
Routes:
::/0 s med 7000
64:ff9b:0:0:0:0::/96 sn med 7000
Services:
44970 01 08000500000e10 s 7000 0
Contexts:
fdfd:ddf0:fb15:1::/64 1 -
2001:db8:13:600::/64 2 c
Commissioning:
14091 - - -
Done
  1. dhcp prefix packet:
13:07:07.310178 IP6 (flowlabel 0x33b53, hlim 1, next-header UDP (17) payload length: 166) fe80::ba27:ebff:fe4f:2400.546 > ff02::1:2.547: [bad udp cksum 0xc6b5 -> 0x4568!] dhcp6 request (xid=1a14d4 (client-ID hwaddr/time type 1 time 673714861 b827eb4f2400) (server-ID hwaddr/time type 1 time 750830217 dca632a54c51) (elapsed-time 0) (vendor-class) (IA_PD IAID:2 T1:0 T2:0 (IA_PD-prefix 2001:db8:13:1900::/56 pltime:300 vltime:900)) (reconfigure-accept) (option-request opt_82 opt_83))
13:07:07.318743 IP6 (flowlabel 0x6a38b, hlim 64, next-header UDP (17) payload length: 93) fe80::dea6:32ff:fea5:4c51.547 > fe80::ba27:ebff:fe4f:2400.546: [udp sum ok] dhcp6 reply (xid=1a14d4 (client-ID hwaddr/time type 1 time 673714861 b827eb4f2400) (server-ID hwaddr/time type 1 time 750830217 dca632a54c51) (IA_PD IAID:2 T1:0 T2:300 (IA_PD-prefix 2001:db8:13:1900::/56 pltime:300 vltime:900)))
13:07:31.812430 IP6 (flowlabel 0x33b53, hlim 1, next-header UDP (17) payload length: 154) fe80::ba27:ebff:fe4f:2400.546 > ff02::1:2.547: [bad udp cksum 0xc6a9 -> 0x0914!] dhcp6 release (xid=e04c3d (client-ID hwaddr/time type 1 time 673714861 b827eb4f2400) (server-ID hwaddr/time type 1 time 750830217 dca632a54c51) (elapsed-time 0) (vendor-class) (IA_PD IAID:2 T1:0 T2:0 (IA_PD-prefix 2001:db8:13:1900::/56 pltime:300 vltime:900)))
13:07:31.824541 IP6 (flowlabel 0x6a38b, hlim 64, next-header UDP (17) payload length: 160) fe80::dea6:32ff:fea5:4c51.547 > fe80::ba27:ebff:fe4f:2400.546: [udp sum ok] dhcp6 reply (xid=e04c3d (client-ID hwaddr/time type 1 time 673714861 b827eb4f2400) (server-ID hwaddr/time type 1 time 750830217 dca632a54c51) (status-code Success) (IA_PD IAID:2 T1:0 T2:0 (status-code Success)))

Copy link
Contributor

@Irving-cl Irving-cl left a comment

Choose a reason for hiding this comment

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

LGTM 👍

script/_dhcpv6_pd_ref Outdated Show resolved Hide resolved
script/_dhcpv6_pd_ref Outdated Show resolved Hide resolved
script/_dhcpv6_pd_ref Outdated Show resolved Hide resolved
script/_dhcpv6_pd_ref Show resolved Hide resolved
script/_dhcpv6_pd_ref Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/_dhcpv6_pd_ref Outdated Show resolved Hide resolved
script/_dhcpv6_pd_ref Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
script/_dhcpv6_pd_ref Outdated Show resolved Hide resolved
script/_dhcpv6_pd_ref Outdated Show resolved Hide resolved
script/_dhcpv6_pd_ref Outdated Show resolved Hide resolved
Copy link
Contributor

@erjiaqing erjiaqing left a comment

Choose a reason for hiding this comment

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

Thanks!

script/_dhcpv6_pd_ref Outdated Show resolved Hide resolved
script/reference-device/dhcp6_pd_daemon.py Outdated Show resolved Hide resolved
backup_dir = "/var/lib/ot-dhcpcd-backup"

def properties_changed_handler(interface_name, changed_properties, invalidated_properties):
if "Dhcp6PdState" in changed_properties:
Copy link
Contributor

Choose a reason for hiding this comment

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

ping on this

@yangsong-cnyn yangsong-cnyn force-pushed the pd_daemon branch 2 times, most recently from 3e14b61 to a3033df Compare November 5, 2024 09:44
Copy link
Contributor

@superwhd superwhd left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@jwhui jwhui merged commit 6934ff0 into openthread:main Nov 7, 2024
32 checks passed
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.

7 participants