luci icon indicating copy to clipboard operation
luci copied to clipboard

luci-app-lldpd: Create based on TanoWrt's app

Open marek22k opened this issue 2 years ago • 47 comments

This is a customized copy of TanoWrt's fork, which you can find at https://github.com/tano-systems/luci-app-tn-lldpd, which is under the MIT license. For the app to work, https://github.com/openwrt/openwrt/pull/14193/ must be accepted.

marek22k avatar Jul 04 '23 10:07 marek22k

This is... nice. @jow-

it has prerequisites for lldp tho.

@marek22k - those filltervals for the uninitiated: those are just the most common presets, right?

systemcrash avatar Jul 28 '23 00:07 systemcrash

Regarding the 'presets' - would it be possible for the user to choose independently of those?

systemcrash avatar Jul 28 '23 00:07 systemcrash

Please test the following ucode replacement for the Lua rpcd plugin:

'use strict';

import { popen } from 'fs';

function lldpcli_json(section) {
	return json(popen(`lldpcli -f json0 show ${section}`, 'r'));
}

return {
	lldpd: {
		getStatus: {
			call: function() {
				return {
					statistics: lldpcli_json("statistics"),
					neighbors:  lldpcli_json("neighbors details"),
					interfaces: lldpcli_json("interfaces"),
					chassis:    lldpcli_json("chassis")
				};
			}
		}
	}
};

It needs to be placed in /usr/share/rpcd/ucode/lldpd. If it works, please include it in your PR instead of the Lua plugin and remove the dependency on luci-lua-runtime (and add rpcd-mod-ucode).

jow- avatar Jul 28 '23 06:07 jow-

@marek22k - those filltervals for the uninitiated: those are just the most common presets, right?

Do you mean the neighbor filter? There are all possibilities. They were taken from the matrix in the man page.

marek22k avatar Jul 30 '23 11:07 marek22k

Please test the following ucode replacement for the Lua rpcd plugin:

Is there any particular reason to prefer ucode over Lua?

marek22k avatar Jul 30 '23 11:07 marek22k

root@OpenWrt:~# ls -l /usr/share/rpcd/ucode/
-rwxr-xr-x    1 root     root           416 Jul 30 11:51 lldpd
Uncaught (in promise) RPCError: RPC call to lldpd/getStatus failed with error -32000: Object not found
  at handleCallReply (http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:11:3)
    raise http://192.168.122.244/luci-static/resources/luci.js?v=git-23.119.80898-65ef406:155
    handleCallReply http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:11
[luci.js:155:3](http://192.168.122.244/luci-static/resources/luci.js?v=git-23.119.80898-65ef406)
RPCError: RPC call to lldpd/getStatus failed with error -32000: Object not found
  at handleCallReply (http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:11:3)
  at promise callback*parseCallReply (http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:9:70)
  at promise callback*call (http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:5:110)
  at declare/</< (http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:23:320)
  at declare/< (http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:20:436)
  at startPolling/< (http://192.168.122.244/luci-static/resources/view/lldpd/status.js?v=git-23.119.80898-65ef406:585:11)
  at step (http://192.168.122.244/luci-static/resources/luci.js?v=git-23.119.80898-65ef406:92:38)
    raise http://192.168.122.244/luci-static/resources/luci.js?v=git-23.119.80898-65ef406:155
    handleCallReply http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:11
    promise callback*parseCallReply http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:9
    promise callback*call http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:5
    declare http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:23
    declare http://192.168.122.244/luci-static/resources/rpc.js?v=git-23.119.80898-65ef406:20
    startPolling http://192.168.122.244/luci-static/resources/view/lldpd/status.js?v=git-23.119.80898-65ef406:585
    step http://192.168.122.244/luci-static/resources/luci.js?v=git-23.119.80898-65ef406:92

Mhh, am I missing something here?

EDIT: Works after installing rpcd-mod-ucode.

marek22k avatar Jul 30 '23 11:07 marek22k

One other thing: Since I minimally adjusted the source code in some places, the line numbers in the translation file are no longer correct. How do you regenerate them?

marek22k avatar Jul 30 '23 11:07 marek22k

EDIT: Works after installing rpcd-mod-ucode.

Is there something like luci-ucode-runtime?

marek22k avatar Jul 30 '23 12:07 marek22k

Is there any particular reason to prefer ucode over Lua?

It's the future in openwrt. Moving away from lua.

One other thing: Since I minimally adjusted the source code in some places, the line numbers in the translation file are no longer correct. How do you regenerate them?

I think recompiling.

Do you mean the neighbor filter? There are all possibilities. They were taken from the matrix in the man page.

OK - I suppose they're common then. User being able to choose and pick themselves would be a plus.

systemcrash avatar Jul 30 '23 12:07 systemcrash

I think recompiling.

Do you know how to recompile the translation files?

OK - I suppose they're common then. User being able to choose and pick themselves would be a plus.

Why? The user can choose it itself. There are no more options than are listed there. There are no more than the filters 0-19 or 1-20. pic

marek22k avatar Jul 30 '23 13:07 marek22k

Do you know how to recompile the translation files?

Just focus on putting your new strings in, then I think there is a build string step which will build the .po files.

Why? The user can choose it itself. There are no more options than are listed there. There are no more than the filters 0-19 or 1-20.

I see.

systemcrash avatar Aug 04 '23 23:08 systemcrash

@marek22k Would it be possible to obtain opkg files to test this? The code should be architecture-independent I think.

howels avatar Aug 18 '23 19:08 howels

If someone chooses to write up how to make an opkg of a PR, it might happen. I usually just ssh the files to my unit and test in situ.

systemcrash avatar Aug 18 '23 19:08 systemcrash

If someone chooses to write up how to make an opkg of a PR, it might happen

Creating a .ipk file for opkg is the normal end result of compiling a package. Applying PRs is pretty straightforward

  • download the PR as a patch (wget https://github.com/openwrt/luci/pull/6456.patch )
  • apply the patch / commit into feeds/packages repo
  • update package info with feeds update & install, and enable the new package in menuconfig
  • compile package with make package/luci-app-lldpd/compile

And then transfer the compiled .ipk to the router.

hnyman avatar Aug 18 '23 20:08 hnyman

@hnyman Thanks for the tutorial!

@howels If you tell me for which device I should compile it, I can try to create an IPK package.

marek22k avatar Aug 18 '23 20:08 marek22k

@hnyman Thanks for the tutorial!

@howels If you tell me for which device I should compile it, I can try to create an IPK package.

I am testing on these devices: Gl.inet AR750: https://openwrt.org/toh/gl.inet/gl-ar750 Zyxel GS1900-48: https://openwrt.org/toh/hwdata/zyxel/zyxel_gs1900-48

Thanks very much, excited to try it out.

howels avatar Aug 18 '23 20:08 howels

I used the following "instructions" to create the IPK files. ~~Unfortunately, this did not work for the ZyXEL device. Does anyone know what could be the reason for this?~~ EDIT: It seems that both GL.iNet GL-AR750 and ZyXEL GS1900-48 are "mips_24kc". Therefore the IPK packages for GL.iNet GL-AR750 are probably also compatible with those for ZyXEL GS1900-48.

# Download OpenWrt sources
git clone -b openwrt-22.03 https://github.com/openwrt/openwrt.git openwrt-22.03
cd openwrt-22.03
git checkout v22.03.5
./scripts/feeds update
./scripts/feeds install -a

# Download configuration file
# VM image
wget https://downloads.openwrt.org/releases/22.03.5/targets/x86/generic/config.buildinfo -O .config

# Gl.iNet GL-MT300N-V2
wget https://downloads.openwrt.org/releases/22.03.5/targets/ramips/mt76x8/config.buildinfo -O .config

# GL.iNet GL-AR750
wget https://downloads.openwrt.org/releases/22.03.5/targets/ath79/generic/config.buildinfo -O .config

# ZyXEL GS1900-48
wget https://downloads.openwrt.org/releases/22.03.5/targets/realtek/rtl839x/config.buildinfo -O .config

# Download the patches
wget https://github.com/openwrt/luci/pull/6456.patch -O luci-app-lldpd.patch
wget https://github.com/openwrt/openwrt/pull/13018.patch -O lldpd.patch

# Apply the patches
git -C feeds/luci am ../../luci-app-lldpd.patch
git am lldpd.patch
# Reflect changes in symlinks
./scripts/feeds install -a

make defconfig

# Enable building of packages
echo "CONFIG_PACKAGE_lldpd=m" >> .config
echo "CONFIG_PACKAGE_luci-app-lldpd=m" >> .config

make defconfig

# Compile the packages
make -j$(nproc) tools/install
make -j$(nproc) toolchain/install
make -j$(nproc) package/lldpd/compile
make -j$(nproc) package/luci-app-lldpd/compile

(Please remove the .txt extension. GitHub unfortunately does not allow .7z files) ipks.7z.asc.txt ipks.7z.txt

marek22k avatar Aug 19 '23 17:08 marek22k

I used the following "instructions" to create the IPK files. ~Unfortunately, this did not work for the ZyXEL device. Does anyone know what could be the reason for this?~ EDIT: It seems that both GL.iNet GL-AR750 and ZyXEL GS1900-48 are "mips_24kc". Therefore the IPK packages for GL.iNet GL-AR750 are probably also compatible with those for ZyXEL GS1900-48.

# Download OpenWrt sources
git clone -b openwrt-22.03 https://github.com/openwrt/openwrt.git openwrt-22.03
cd openwrt-22.03
git checkout v22.03.5
./scripts/feeds update
./scripts/feeds install -a

# Download configuration file
# VM image
wget https://downloads.openwrt.org/releases/22.03.5/targets/x86/generic/config.buildinfo -O .config

# Gl.iNet GL-MT300N-V2
wget https://downloads.openwrt.org/releases/22.03.5/targets/ramips/mt76x8/config.buildinfo -O .config

# GL.iNet GL-AR750
wget https://downloads.openwrt.org/releases/22.03.5/targets/ath79/generic/config.buildinfo -O .config

# ZyXEL GS1900-48
wget https://downloads.openwrt.org/releases/22.03.5/targets/realtek/rtl839x/config.buildinfo -O .config

# Download the patches
wget https://github.com/openwrt/luci/pull/6456.patch -O luci-app-lldpd.patch
wget https://github.com/openwrt/openwrt/pull/13018.patch -O lldpd.patch

# Apply the patches
git -C feeds/luci am ../../luci-app-lldpd.patch
git am lldpd.patch
# Reflect changes in symlinks
./scripts/feeds install -a

make defconfig

# Enable building of packages
echo "CONFIG_PACKAGE_lldpd=m" >> .config
echo "CONFIG_PACKAGE_luci-app-lldpd=m" >> .config

make defconfig

# Compile the packages
make -j$(nproc) tools/install
make -j$(nproc) toolchain/install
make -j$(nproc) package/lldpd/compile
make -j$(nproc) package/luci-app-lldpd/compile

(Please remove the .txt extension. GitHub unfortunately does not allow .7z files) ipks.7z.asc.txt ipks.7z.txt

Working really well here, the protocol initially didn't come up but I noticed that no interfaces were added in settings. After adding the correct interfaces via Luci it worked perfectly and /etc/config/lldpd is updated and read properly to set lldpd interfaces.

howels avatar Aug 20 '23 12:08 howels

Tried to compile this on 23.05.0-rc3 but getting errors on the new luci-app-lldpd package:

$ make -j1 V=sc  package/luci-app-lldpd/compile
make[2]: Entering directory '/home/whatever/git/openwrt/scripts/config'
make[2]: 'conf' is up to date.
make[2]: Leaving directory '/home/whatever/git/openwrt/scripts/config'
make[1]: Entering directory '/home/whatever/git/openwrt'
cd "/home/whatever/git/openwrt"; git log --format=%h -1 toolchain > /home/whatever/git/openwrt/tmp/.ver_check
cmp -s /home/whatever/git/openwrt/tmp/.ver_check /home/whatever/git/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/stamp/.ver_check || { \
	rm -rf /home/whatever/git/openwrt/build_dir/target-mips_24kc_musl /home/whatever/git/openwrt/staging_dir/target-mips_24kc_musl /home/whatever/git/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl /home/whatever/git/openwrt/build_dir/toolchain-mips_24kc_gcc-12.3.0_musl; \
	mkdir -p /home/whatever/git/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/stamp; \
	mv /home/whatever/git/openwrt/tmp/.ver_check /home/whatever/git/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/stamp/.ver_check; \
}
make[1]: *** No rule to make target 'package/luci-app-lldpd/compile'.  Stop.
make[1]: Leaving directory '/home/whatever/git/openwrt'
make: *** [/home/whatever/git/openwrt/include/toplevel.mk:232: package/luci-app-lldpd/compile] Error 2

LLDPD compiles fine as do other Luci app packages, so something is missing for this new package?

I need to build a version for my GS1900 because this is running snapshot due to an error in the 22.03 release on this product which can cause bootloops.

howels avatar Aug 21 '23 10:08 howels

Mhh, I'm not an expert in building OpenWrt packages either. I would suggest to try the following instructions after applying the patch.

./scripts/feeds install -a

echo "CONFIG_PACKAGE_luci-app-lldpd=m" >> .config

make defconfig

marek22k avatar Aug 21 '23 17:08 marek22k

Mhh, I'm not an expert in building OpenWrt packages either. I would suggest to try the following instructions after applying the patch.

./scripts/feeds install -a

echo "CONFIG_PACKAGE_luci-app-lldpd=m" >> .config

make defconfig

thanks. I had followed the commands but somehow repeating those 3 made the build work. appreciate the pointers.

howels avatar Aug 22 '23 20:08 howels

Unfortunately the resulting packages give some errors on 23.05.0

root@GS1900-48:/tmp# opkg install lldpd_1.0.17-1_mips_24kc.ipk 
Installing lldpd (1.0.17-1) to root...
Configuring lldpd.
Collected errors:
 * resolve_conffiles: Existing conffile /etc/config/lldpd is different from the conffile in the new package. The new conffile will be placed at /etc/config/lldpd-opkg.
root@GS1900-48:/tmp# opkg install luci-app-lldpd_git-23.233.35287-d022eae_all.ipk 
Installing luci-app-lldpd (git-23.233.35287-d022eae) to root...
Configuring luci-app-lldpd.
uci: Parse error (invalid command) at line 20, byte 1

The page does not show up in Luci after this error. Tried RC2 and RC3 codedbases but get the same error.

howels avatar Aug 22 '23 20:08 howels

Mhh, the only thing I could do would be to try the whole thing myself in a VM. Maybe someone else here knows how to fix the bug? What I also wonder is which line 20 of uci is meant?

I could also imagine that it is somehow because the whole it is snaphot and RC?!

Actually I thought the Luci Web App should be quite version independent.

marek22k avatar Aug 23 '23 07:08 marek22k

Mhh, the only thing I could do would be to try the whole thing myself in a VM. Maybe someone else here knows how to fix the bug? What I also wonder is which line 20 of uci is meant?

I could also imagine that it is somehow because the whole it is snaphot and RC?!

Actually I thought the Luci Web App should be quite version independent.

Which file is uci trying to parse when it generates this error? We should check line 20, maybe the format changed between 22 and 23?

howels avatar Aug 23 '23 10:08 howels

Which file is uci trying to parse when it generates this error? We should check line 20

Likely this: /etc/config/lldpd

https://github.com/openwrt/openwrt/blob/master/package/network/services/lldpd/files/lldpd.config

hnyman avatar Aug 23 '23 11:08 hnyman

lldp_location is probably not recognized?! (I think that is not implemented in the new init; should I add that?)

marek22k avatar Aug 23 '23 11:08 marek22k

UCI doesn't care about that. You probably got a syntax error somewhere, run uci showand check line 20. Might be you should limit the output to the LLPD entries, you can do that by appending it to the command (if the entries are indeed llpd.xx=...).

Borromini avatar Aug 23 '23 12:08 Borromini

The problem does not appear to be lldp module, but the corresponding luci module.

systemcrash avatar Aug 23 '23 12:08 systemcrash

Yes, it's the syntax of that file. We should not fail the install due to inability to parse config files however - that should perhaps complete the install but perhaps backup and replace the config file or show a warning? After removing the offending line (I had left configure system interfaces ... in that file whilst trying to get the old lldpd to bind correctly) the package works really well.

Delighted to be able to see neighbors on a 48-port switch!

howels avatar Aug 23 '23 16:08 howels

Have now tested on several 22.03.5 and 23.05-rc2 platforms - working on everything so far. Can anyone else review the PR? Looks good here.

howels avatar Aug 28 '23 11:08 howels