2019年9月28日 星期六

ubus

ubus (OpenWrt micro bus architecture)

包含 daemon ubusd、函式庫 libubus、和一些額外的 helpers.

ubusd 是 ubus 的心臟,提供界面給其它 daemons 註冊和送訊息,採用 Unix sockets 和 TLV (type-length-value) 訊息。

libubus 簡化使用 ubus 的軟體開發。

每個 daemon 在特定 namespace 註冊一些路徑,每個路徑可提供多個有任意數目引數的 procedure,procedures 可用訊息回應。

http://git.openwrt.org/project/ubus.git

工具指令

指令 ubus 和註冊到 ubus 的服務互動,用來檢查註冊的 namespaces,以及撰寫 shell 指令搞。使用 user-friendly 的 JSON 格式呼叫 procedure 和回應。

用法:ubus [選項] 命令 [參數...]

選項:
-s <socket>:設定要連結的 unix socket,沒指定預設是「/var/run/ubus.sock」
-t <timeout>:設定指令逾時秒數
-S:使用簡化輸出 (指令稿用)
-v:More verbose 輸出
-m <type>:(for monitor): include a specific message type (可多個)
-M <r|t>:(for monitor): only capture received or transmitted traffic

命令:
list [<path>]:列出已註冊的 namespace,-v 的話包含 procedures 和其 argument signatures 也列出。
call <path> <method> [<message>]:呼叫 namespace 的 procedure,可含以 JSON 表示的引數
listen [<path>...]:Listen for events
send <type> [<message>]:送事件通知。
wait_for <object> [<object>...]:等候 multiple objects to appear on ubus
monitor:Monitor ubus traffic

範例
`ubus listen &`:建立一個 listening socket 來觀察新進的事件。
ubus
ubus list
ubus -v list system
ubus call system info

透過 HTTP 存取 ubus

uhttpd 有 ubus plugin -- uhttpd-mod-ubus 讓 ...

在 lua 使用 ubus

Namespaces & Procedures

使用 ubus 常見的專案。

netifd

rpcd

for file, iwinfo, session, uci

Example code snippets

ubusd

ubusd 內部是一個 uloop,監視預設 bind 到「/var/run/ubus.sock」的 fd 所發生的事件,

參考

  1. https://wiki.openwrt.org/doc/techref/ubus
  2. 用ubus實現Inter-Process Communication
  3. ubus_invoke()使用介紹
http://wiki.openwrt.org/doc/techref/netifd

延伸閱讀:http://data.pavlix.net/installfest/2014/openwrt-software.pdf

沒有留言:

張貼留言

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...