diff mbox series

package: add new poe-common package

Message ID 20240125130033.106260-1-sander@svanheule.net
State Under Review
Delegated to: Sander Vanheule
Headers show
Series package: add new poe-common package | expand

Commit Message

Sander Vanheule Jan. 25, 2024, 1 p.m. UTC
Create a new package to generate configuration files for devices capable
of delivering power via PoE. The configuration file at /etc/config/poe
can be used by PoE daemons to configure the hardware in an implementation
specific way.

This is part of the core packages because it needs to be in sync with
the format of board.json, from which the config file is generated. The
config file structure is based on the current config file of the
realtek-poe package, but should be (and remain) implementation
independent. With a common basis, a common (LuCI) configuration
interface also becomes possible in the future.

For a device with a power budget of 130W and ports lan1-lan8 mapping to
PSE outputs 8-1, /etc/config/poe could look like (lan1-lan6 omitted):
	config global
		option budget '130'

	config port
		option name 'lan8'
		option id '1'
		option enable '1'

	config port
		option name 'lan7'
		option id '2'
		option enable '1'

	[...]

Signed-off-by: Sander Vanheule <sander@svanheule.net>
---
 package/network/config/poe-common/Makefile    | 37 ++++++++++++++++
 .../poe-common/files/etc/uci-defaults/30_poe  | 42 +++++++++++++++++++
 2 files changed, 79 insertions(+)
 create mode 100644 package/network/config/poe-common/Makefile
 create mode 100755 package/network/config/poe-common/files/etc/uci-defaults/30_poe

Comments

Paul D Jan. 25, 2024, 11 p.m. UTC | #1
So, the power budget is a global option. Do we ever envisage that parts 
of this budget can be concretely assigned to specific ports or more 
abstract <board sections>?

e.g.

  	config port
  		option name 'lan8'
  		option id '1'
  		option enable '1'
  		option budget '15'




On 2024-01-25 14:00, Sander Vanheule wrote:
> Create a new package to generate configuration files for devices capable
> of delivering power via PoE. The configuration file at /etc/config/poe
> can be used by PoE daemons to configure the hardware in an implementation
> specific way.
> 
> This is part of the core packages because it needs to be in sync with
> the format of board.json, from which the config file is generated. The
> config file structure is based on the current config file of the
> realtek-poe package, but should be (and remain) implementation
> independent. With a common basis, a common (LuCI) configuration
> interface also becomes possible in the future.
> 
> For a device with a power budget of 130W and ports lan1-lan8 mapping to
> PSE outputs 8-1, /etc/config/poe could look like (lan1-lan6 omitted):
> 	config global
> 		option budget '130'
> 
> 	config port
> 		option name 'lan8'
> 		option id '1'
> 		option enable '1'
> 
> 	config port
> 		option name 'lan7'
> 		option id '2'
> 		option enable '1'
> 
> 	[...]
> 
> Signed-off-by: Sander Vanheule <sander@svanheule.net>
> ---
>   package/network/config/poe-common/Makefile    | 37 ++++++++++++++++
>   .../poe-common/files/etc/uci-defaults/30_poe  | 42 +++++++++++++++++++
>   2 files changed, 79 insertions(+)
>   create mode 100644 package/network/config/poe-common/Makefile
>   create mode 100755 package/network/config/poe-common/files/etc/uci-defaults/30_poe
> 
> diff --git a/package/network/config/poe-common/Makefile b/package/network/config/poe-common/Makefile
> new file mode 100644
> index 000000000000..a7970b4b5b15
> --- /dev/null
> +++ b/package/network/config/poe-common/Makefile
> @@ -0,0 +1,37 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +
> +include $(TOPDIR)/rules.mk
> +
> +PKG_NAME:=poe-common
> +PGK_VERSION:=1
> +PKG_RELEASE:=1
> +
> +PKG_MAINTAINER:=Sander Vanheule <sander@svanheule.net>
> +PKG_LICENSE:=GPL-2.0-or-later
> +
> +include $(INCLUDE_DIR)/package.mk
> +
> +define Package/poe-common
> +  SECTION:=net
> +  CATEGORY:=Network
> +  TITLE:=Common base files for PoE
> +  DEPENDS:=+libubox +libuci
> +endef
> +
> +define Package/poe-common/conffiles
> +/etc/config/poe
> +endef
> +
> +define Package/poe-common/description
> + Common base files for PoE configuration and control
> +endef
> +
> +define Package/poe-common/install
> +	$(INSTALL_DIR) $(1)/etc/uci-defaults/
> +	$(INSTALL_CONF) ./files/etc/uci-defaults/30_poe $(1)/etc/uci-defaults/
> +endef
> +
> +define Build/Compile
> +endef
> +
> +$(eval $(call BuildPackage,poe-common))
> diff --git a/package/network/config/poe-common/files/etc/uci-defaults/30_poe b/package/network/config/poe-common/files/etc/uci-defaults/30_poe
> new file mode 100755
> index 000000000000..3a429402c59b
> --- /dev/null
> +++ b/package/network/config/poe-common/files/etc/uci-defaults/30_poe
> @@ -0,0 +1,42 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +
> +[ -e /etc/config/poe ] && exit 0
> +
> +. /lib/functions.sh
> +. /usr/share/libubox/jshn.sh
> +
> +CFG=/etc/board.json
> +
> +json_init
> +json_load_file "${CFG}"
> +
> +json_is_a poe object || exit 0
> +
> +umask 055
> +touch /etc/config/poe
> +
> +json_select poe
> +	json_get_vars budget
> +
> +	uci add poe global
> +	uci set poe.@global[-1].budget="$budget"
> +
> +	if json_is_a ports array; then
> +		json_get_values ports ports
> +		id='1'
> +
> +		for port in $ports; do
> +			uci -q batch <<-EOF
> +				add poe port
> +				set poe.@port[-1].name='$port'
> +				set poe.@port[-1].id='$id'
> +				set poe.@port[-1].enable='1'
> +			EOF
> +			let id=id+1
> +		done
> +	fi
> +json_select ..
> +
> +uci commit
> +
> +exit 0
Sander Vanheule Jan. 26, 2024, 7:01 a.m. UTC | #2
[Added the others back in Cc]

Hi Paul,

On Fri, 2024-01-26 at 00:00 +0100, Paul D wrote:
> 
> So, the power budget is a global option. Do we ever envisage that parts 
> of this budget can be concretely assigned to specific ports or more 
> abstract <board sections>?
> 
> e.g.
> 
>   	config port
>   		option name 'lan8'
>   		option id '1'
>   		option enable '1'
>   		option budget '15'

This would certainly be an option to extend the format. I'm not entirely sure where or how
the full supported format should be documented. The OpenWrt wiki seem to be where other
config files are documented, but I don't think we support documentation in our package
format.

Note that this package only intends to generate the bare minimum from information
contained in board.json, which is currently a list sorted by PSE output port. Following
the example config file:

        "poe" : ["lan8", "lan7", ... , "lan1"]

Board specific power constraints also belong in board.json. For a device with four 802.3af
ports (lan1-lan4) and four 802.3at ports (lan5-lan8) this could become:

	"poe" : {
		"lan1" : { "type" : "802.3af" },
		...
		"lan5" : { "type" : "802.3at" },
		...
	}

This could then be translated into a per-port "poe_type" property for example. We also
have some discussion going on this topic for the realtek-poe package [1].

1. https://github.com/Hurricos/realtek-poe/pull/31

Best,
Sander
diff mbox series

Patch

diff --git a/package/network/config/poe-common/Makefile b/package/network/config/poe-common/Makefile
new file mode 100644
index 000000000000..a7970b4b5b15
--- /dev/null
+++ b/package/network/config/poe-common/Makefile
@@ -0,0 +1,37 @@ 
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=poe-common
+PGK_VERSION:=1
+PKG_RELEASE:=1
+
+PKG_MAINTAINER:=Sander Vanheule <sander@svanheule.net>
+PKG_LICENSE:=GPL-2.0-or-later
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/poe-common
+  SECTION:=net
+  CATEGORY:=Network
+  TITLE:=Common base files for PoE
+  DEPENDS:=+libubox +libuci
+endef
+
+define Package/poe-common/conffiles
+/etc/config/poe
+endef
+
+define Package/poe-common/description
+ Common base files for PoE configuration and control
+endef
+
+define Package/poe-common/install
+	$(INSTALL_DIR) $(1)/etc/uci-defaults/
+	$(INSTALL_CONF) ./files/etc/uci-defaults/30_poe $(1)/etc/uci-defaults/
+endef
+
+define Build/Compile
+endef
+
+$(eval $(call BuildPackage,poe-common))
diff --git a/package/network/config/poe-common/files/etc/uci-defaults/30_poe b/package/network/config/poe-common/files/etc/uci-defaults/30_poe
new file mode 100755
index 000000000000..3a429402c59b
--- /dev/null
+++ b/package/network/config/poe-common/files/etc/uci-defaults/30_poe
@@ -0,0 +1,42 @@ 
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+[ -e /etc/config/poe ] && exit 0
+
+. /lib/functions.sh
+. /usr/share/libubox/jshn.sh
+
+CFG=/etc/board.json
+
+json_init
+json_load_file "${CFG}"
+
+json_is_a poe object || exit 0
+
+umask 055
+touch /etc/config/poe
+
+json_select poe
+	json_get_vars budget
+
+	uci add poe global
+	uci set poe.@global[-1].budget="$budget"
+
+	if json_is_a ports array; then
+		json_get_values ports ports
+		id='1'
+
+		for port in $ports; do
+			uci -q batch <<-EOF
+				add poe port
+				set poe.@port[-1].name='$port'
+				set poe.@port[-1].id='$id'
+				set poe.@port[-1].enable='1'
+			EOF
+			let id=id+1
+		done
+	fi
+json_select ..
+
+uci commit
+
+exit 0