Differences

This shows you the differences between two versions of the page.

doc:techref:ubus [2013/05/11 20:15]
jaseg
doc:techref:ubus [2014/04/09 22:15] (current)
zajec Move uci.* to the rpcd
Line 1: Line 1:
====== ubus (OpenWrt micro bus architecture) ====== ====== ubus (OpenWrt micro bus architecture) ======
-{{page>meta:infobox:construction&noheader&nofooter&noeditbtn}}+To provide communication between various daemons and applications in OpenWrt an ubus project has been developed. It consists of few parts including daemon, library and some extra helpers.
-The code can be found via git at ''git://nbd.name/luci2/libubox.git'' or via http at [[http://nbd.name/gitweb.cgi]] .+The heart of this project is ubusd daemon. It provides interface for other daemons to register themselves as well as sending messages. For those curious, this interface is implemented using Unix socket and it uses TLV (type-length-value) messages.
-===== Command line utility =====+To simplify development of software using ubus (connecting to it) a library called libubus has been created.
-The ''ubus'' command line client allows to interact with the ''ubusd'' rpc server, below is an explanation of its commands.+Every daemon registers set of own paths under specific namespace. Every path can provide multiple procedures with various amount of arguments. Procedures can reply with a message. 
 + 
 +The code is published under LGPL 2.1 and can be found via git at ''git://nbd.name/luci2/ubus.git'' or via http at [[http://nbd.name/gitweb.cgi?p=luci2/ubus.git;a=summary]]. It's included in OpenWrt since [[https://dev.openwrt.org/changeset/28499|r28499]]. 
 + 
 +===== Command-line ubus tool ===== 
 + 
 +The ''ubus'' command line tool allows to interact with the ''ubusd'' server (with all currently registered services). It's useful for investigating/debugging registered namespaces as well as writing shell scripts. For calling procedures with parameters and returning responses it uses user-friendly JSON format. Below is an explanation of its commands.
==== list ==== ==== list ====
Line 130: Line 136:
root@uplink:~# </code> root@uplink:~# </code>
-===== Lua binding =====+===== Access to ubus over HTTP =====
-The package ''libubus-lua'' implements a simple Lua binding to the ''libubus'' library to allow for easy client connections.+There is an ''uhttpd'' plugin called ''uhttpd-mod-ubus'' that allows ''ubus'' calls using HTTP protocol. Requests have to be send to the ''/ubus'' URL (unless changed) using ''POST'' method. There are two methods (possible calls) available: 
 + 
 +  - <code>method=list&params=...</code> 
 +  - <code>method=call&sid=...&object=...&function=...&data=...</code> 
 + 
 +===== Lua module for ubus ===== 
 + 
 +This is even possible to use ''ubus'' in ''lua'' scripts. Of course it's not possible to use native libraries directly in ''lua'', so an extra module has been created. It's simply called ''ubus'' and is a simple interface between ''lua'' scripts and the ''ubus'' (it uses ''libubus'' internally).
==== Load module ==== ==== Load module ====
Line 172: Line 185:
===== Namespaces & Procedures ===== ===== Namespaces & Procedures =====
-==== Implemented ====+As explained earlier, there can be many different daemons (services) registered in ''ubus''. Below you will find a list of the most common projects with namespaces, paths and procedures they provide.
-=== netifd ===+==== netifd ===
 + 
 +[[http://nbd.name/gitweb.cgi?p=luci2/netifd.git;a=blob;f=DESIGN|Design of netifd]]
^ Path ^ Procedure ^ Signature ^ Description ^ ^ Path ^ Procedure ^ Signature ^ Description ^
Line 189: Line 204:
| ''network.interface.//name//'' | ''remove'' | ''{ }'' | Remove interface ''//name//'' (?) | | ''network.interface.//name//'' | ''remove'' | ''{ }'' | Remove interface ''//name//'' (?) |
-=== uhttpd-mod-ubus ===+==== rpcd ==== 
 + 
 +Project ''rpcd'' is set of small plugins providing sets of ''ubus'' procedures in separated namespaces. These plugins are not strictly related to any particular software (like ''netifd'' or ''dhcp'') so it wasn't worth it to implement them as separated projects. 
 + 
 +^ Path ^ Procedure ^ Signature ^ Description ^ 
 +| ''file'' | ''read'' | ? | ? | 
 +| ''file'' | ''write'' | ? | ? | 
 +| ''file'' | ''list'' | ? | ? | 
 +| ''file'' | ''stat'' | ? | ? | 
 +| ''file'' | ''exec'' | ? | ? | 
 +\\ 
 +^ Path ^ Procedure ^ Signature ^ Description ^ 
 +| ''iwinfo'' | ''info'' | ? | ? | 
 +| ''iwinfo'' | ''scan'' | ? | ? | 
 +| ''iwinfo'' | ''assoclist'' | ? | ? | 
 +| ''iwinfo'' | ''freqlist'' | ? | ? | 
 +| ''iwinfo'' | ''txpowerlist'' | ? | ? | 
 +| ''iwinfo'' | ''countrylist'' | ? | ? |
^ Path ^ Procedure ^ Signature ^ Description ^ ^ Path ^ Procedure ^ Signature ^ Description ^
Line 198: Line 230:
| ''session'' | ''revoke'' | ''{ "session": "//sid//", | ''session'' | ''revoke'' | ''{ "session": "//sid//",
  "objects": [ [ "path", "func" ], ... ] }'' | Within the session identified by ''//sid//'' revoke access to all specified procedures ''//func//'' in the namespace ''//path//'' listed in the ''//objects//'' array. If ''//objects//'' is unset, revoke all access |   "objects": [ [ "path", "func" ], ... ] }'' | Within the session identified by ''//sid//'' revoke access to all specified procedures ''//func//'' in the namespace ''//path//'' listed in the ''//objects//'' array. If ''//objects//'' is unset, revoke all access |
 +| ''session'' | ''access'' | ? | ? |
| ''session'' | ''set'' | ''{ "session": "//sid//", | ''session'' | ''set'' | ''{ "session": "//sid//",
  "values": { "//key//": //value//, ... } }'' | Within the session identified by ''//sid//'' store the given arbitrary values under their corresponding keys specified in the ''//values//'' object |   "values": { "//key//": //value//, ... } }'' | Within the session identified by ''//sid//'' store the given arbitrary values under their corresponding keys specified in the ''//values//'' object |
Line 204: Line 237:
| ''session'' | ''unset'' | ''{ "session": "//sid//", | ''session'' | ''unset'' | ''{ "session": "//sid//",
  "keys": [ "//key//", ... ] }'' | Within the session identified by ''//sid//'' unset all keys listed in the ''//keys//'' array. If the key list is unset, clear all keys |   "keys": [ "//key//", ... ] }'' | Within the session identified by ''//sid//'' unset all keys listed in the ''//keys//'' array. If the key list is unset, clear all keys |
-| ''session'' | ''extend'' | ''{ "session": "//sid//" }'' | Within the session identified by ''//sid//'' reset inactivity timeout counter | 
| ''session'' | ''destroy'' | ''{ "session": "//sid//" }'' | Terminate the session identified by the given ID ''//sid//'' | | ''session'' | ''destroy'' | ''{ "session": "//sid//" }'' | Terminate the session identified by the given ID ''//sid//'' |
- +| ''session'' | ''login'' | ? | ? |
-==== Planned ==== +
- +
-=== LuCI2 ===+
^ Path ^ Procedure ^ Signature ^ Description ^ ^ Path ^ Procedure ^ Signature ^ Description ^
Line 283: Line 312:
  - If the option named ''//oname//'' within named section ''//sname//'' was not found: ''UBUS_STATUS_NOT_FOUND'' else: ''UBUS_STATUS_OK''   - If the option named ''//oname//'' within named section ''//sname//'' was not found: ''UBUS_STATUS_NOT_FOUND'' else: ''UBUS_STATUS_OK''
</WRAP> | </WRAP> |
 +
 +===== Example code snippets =====
 +
 +==== Check if Link is up using devstatus and Json ====
 +
 +<code>
 +#!/bin/sh
 +
 +. /usr/share/libubox/jshn.sh
 +
 +WANDEV="$(uci get network.wan.ifname)"
 +
 +json_load "$(devstatus $WANDEV)"
 +
 +json_get_var var1 speed
 +json_get_var var2 link
 +
 +echo "Speed: $var1"
 +echo "Link: $var2"
 +</code>

Back to top

doc/techref/ubus.1368296158.txt.bz2 · Last modified: 2013/05/11 20:15 by jaseg