openwrt-ubus

了解openwrt ubus用法


更新記錄

item note
20170105 第一版

目錄


ubus (OpenWrt micro bus architecture)

來源:ubus (OpenWrt micro bus architecture)

  • ubus (OpenWrt micro bus architecture)
    • provide communication between various daemons and applications
    • using Unix sockets and it uses TLV (type-length-value) messages
    • Every daemon registers a set of paths under a specific namespace.
    • The ubus command line tool allows to interact with the ubusd server

ubus

  • 顯示目前系統ubus提供那些service
    ubus list

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    root@OpenWrt:/# ubus list
    dhcp
    log
    network
    network.device
    network.interface
    network.interface.lan
    network.interface.loopback
    network.interface.wan
    network.interface.wan6
    network.wireless
    service
    session
    system
    uci
  • 顯示system service 細節
    -v (More verbose output)
    顯示提供那些call object method

    1
    2
    3
    4
    5
    6
    7
    8
    9
    root@OpenWrt:/# ubus -v list system
    'system' @b4b76d22
    "board":{}
    "info":{}
    "upgrade":{}
    "watchdog":{"frequency":"Integer","timeout":"Integer","stop":"Boolean"}
    "signal":{"pid":"Integer","signum":"Integer"}
    "nandupgrade":{"path":"String"}
    root@OpenWrt:/#
  • 呼叫ubus service

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    root@OpenWrt:/# ubus call system board
    {
    "kernel": "3.18.29",
    "hostname": "OpenWrt",
    "system": "Atheros AR7240 rev 2",
    "model": "TP-Link TL-WR741N\/ND v1",
    "release": {
    "distribution": "OpenWrt",
    "version": "Chaos Calmer",
    "revision": "r49118",
    "codename": "chaos_calmer",
    "target": "ar71xx\/generic",
    "description": "OpenWrt Chaos Calmer 15.05.1"
    }
    }

其它

openwrt中ubus的具体使用

來源:openwrt中ubus的具体使用

  • ubus有两种调用,一个是method调用,一个是notification

    • 其中method包括等待函数返回和不用等待返回
    • notification是广播和DBus的signal类似
  • ubus可以和ubusd服务器交互(和当前所有已经注册的服务).它对研究和调试注册的命名空间以及编写脚本非常有用

  • ubuscall 调用指定命名空间中指定的方法,并且通过消息传递给它, 消息参数必须是有效的JSON字符串,并且携带函数所要求的键及值

參考