Restconf stream debugging and README

This commit is contained in:
Olof hagsand 2018-11-04 15:59:05 +01:00
parent 09e2e767fe
commit fdfbbcdb9e
6 changed files with 60 additions and 30 deletions

View file

@ -133,16 +133,18 @@ Clixon does not yet support the following netconf features:
Restconf Restconf
======== ========
Clixon restconf is a daemon based on FASTCGI. Instructions are available to Clixon Restconf is a daemon based on FastCGI C-API. Instructions are available to
run with NGINX. run with NGINX.
The implementatation is based on [RFC 8040: RESTCONF Protocol](https://tools.ietf.org/html/rfc8040). The implementatation is based on [RFC 8040: RESTCONF Protocol](https://tools.ietf.org/html/rfc8040).
The following features are supported: The following features are supported:
- OPTIONS, HEAD, GET, POST, PUT, DELETE - OPTIONS, HEAD, GET, POST, PUT, DELETE
- stream notifications - stream notifications (RFC8040 sec 6)
- query parameters start-time and stop-time(RFC8040 section 4.9)
The following are not implemented The following features are not implemented:
- PATCH - PATCH
- query parameters (section 4.9) - query parameters other than start/stop-time.
See [more detailed instructions](apps/restconf/README.md). See [more detailed instructions](apps/restconf/README.md).

View file

@ -1,6 +1,13 @@
# Clixon Restconf # Clixon Restconf
### Installation using Nginx * [Installation](#Installation)
* [Streams](Streams)
* [Nchan Streams](Nchan)
* [Debugging](Debugging)
### 1. Installation
The examples are based on Nginx. Other reverse proxies should work but are not verified.
Ensure www-data is member of the CLICON_SOCK_GROUP (default clicon). If not, add it: Ensure www-data is member of the CLICON_SOCK_GROUP (default clicon). If not, add it:
``` ```
@ -69,28 +76,31 @@ olof@vandal> curl -G http://127.0.0.1/restconf/data/interfaces/interface/name=et
curl -sX POST -d '{"interfaces":{"interface":{"name":"eth1","type":"eth","enabled":"true"}}}' http://localhost/restconf/data curl -sX POST -d '{"interfaces":{"interface":{"name":"eth1","type":"eth","enabled":"true"}}}' http://localhost/restconf/data
``` ```
### Event streams ### 2. Streams
Clixon have two experimental restconf event stream implementations following Clixon have two experimental restconf event stream implementations following
RFC8040 Section 6 using SSE. One native and one using Nginx RFC8040 Section 6 using SSE. One native and one using Nginx
nchan. The two variants to subscribe to the stream is described in the nchan. The Nchan alternaitve is described in the
next section. next section.
The example [../../example/README.md] creates and EXAMPLE stream. The (example)[../../example/README.md] creates an EXAMPLE stream.
Set the Clixon configuration options if they differ from default values - if they are OK you do not need to modify them: Set the Clixon configuration options:
``` ```
<CLICON_STREAM_PATH>streams</CLICON_STREAM_PATH> <CLICON_STREAM_PATH>streams</CLICON_STREAM_PATH>
<CLICON_STREAM_URL>https://example.com</CLICON_STREAM_URL> <CLICON_STREAM_URL>https://example.com</CLICON_STREAM_URL>
<CLICON_STREAM_PUB>http://localhost/pub</CLICON_STREAM_PUB> <CLICON_STREAM_RETENTION>3600</CLICON_STREAM_RETENTION>
``` ```
where In this example, the stream EXAMPLE would be accessed with `https://example.com/streams/EXAMPLE`.
- https://example.com/streams is the public fronting subscription base URL. A specific stream NAME can be accessed as https://example.com/streams/NAME
- http://localhost/pub is the local internal base publish stream.
You access the streams using curl, but they differ slightly in behaviour as described in the following two sections. The retention is configured as 1 hour, i.e., the stream replay function will only save timeseries one other.
Add the following to extend the nginx configuration file with the following statements: Clixon defines an internal in-memory (not persistent) replay function
controlled by the configure option above.
You may access a restconf streams using curl.
Add the following to extend the nginx configuration file with the following statements (for example):
``` ```
location /streams { location /streams {
fastcgi_pass unix:/www-data/fastcgi_restconf.sock; fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
@ -100,26 +110,36 @@ Add the following to extend the nginx configuration file with the following stat
} }
``` ```
You access a native stream as follos: AN example of a stream access is as follows:
``` ```
curl -H "Accept: text/event-stream" -s -X GET http://localhost/streams/EXAMPLE vandal> curl -H "Accept: text/event-stream" -s -X GET http://localhost/streams/EXAMPLE
curl -H "Accept: text/event-stream" -s -X GET http://localhost/streams/EXAMPLE?start-time=2014-10-25T10%3A02%3A00Z&stop-time=2014-10-25T12%3A31%3A00Z data: <notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"><eventTime>2018-11-04T14:47:11.373124</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event></notification>
data: <notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"><eventTime>2018-11-04T14:47:16.375265</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event></notification>
``` ```
where the first command retrieves only new notifications, and the second receives a range of messages.
### Nginx Nchan streams You can also specify start and stop time. Start-time enables replay of existing samples, while stop-time is used both for replay, but also for stopping a stream at some future time.
```
curl -H "Accept: text/event-stream" -s -X GET http://localhost/streams/EXAMPLE?start-time=2014-10-25T10:02:00&stop-time=2014-10-25T12:31:00
```
As an alternative, Nginx/Nchan can be used for streams. See (stream tests)[../test/test_streams.sh] for more examples.
### 3. Nchan
As an alternative streams implementation, Nginx/Nchan can be used.
Nginx uses pub/sub channels and can be configured in a variety of Nginx uses pub/sub channels and can be configured in a variety of
ways. The following uses a simple variant with one generic subscription ways. The following uses a simple variant with one generic subscription
channel (streams) and one publication channel (pub). channel (streams) and one publication channel (pub).
Configure clixon with `--enable-publish` which enables curl code for publishing streams to nchan. The advantage with Nchan is the large eco-system of
Set configure option CLICON_STREAM_PUB to, for example, http://localhost/pub to enable pushing notifications to nchan.
Native mode and Nchan mode can co-exist?
Nchan mode does not use Clixon retention,
Download and install nchan, see (https://nchan.io/#install). Download and install nchan, see (https://nchan.io/#install).
Add the following to extend the nginx configuration file with the following statements: Add the following to extend the Nginx configuration file with the following statements (example):
``` ```
location ~ /streams/(\w+)$ { location ~ /streams/(\w+)$ {
nchan_subscriber; nchan_subscriber;
@ -131,6 +151,15 @@ Add the following to extend the nginx configuration file with the following stat
} }
``` ```
Configure clixon with `--enable-publish` which enables curl code for
publishing streams to nchan.
You also need to configure CLICON_STREAM_PUB to enable pushing notifications to Nginx/Nchan. Example:
```
<CLICON_STREAM_PUB>http://localhost/pub</CLICON_STREAM_PUB>
```
Clicon will then publish events from stream EXAMPLE to `http://localhost/pub/EXAMPLE
Access the event stream EXAMPLE using curl: Access the event stream EXAMPLE using curl:
``` ```
curl -H "Accept: text/event-stream" -s -X GET http://localhost/streams/EXAMPLE curl -H "Accept: text/event-stream" -s -X GET http://localhost/streams/EXAMPLE
@ -140,7 +169,7 @@ where the first command retrieves the whole stream history, and the second only
See (https://nchan.io/#eventsource) on more info on how to access an SSE sub endpoint. See (https://nchan.io/#eventsource) on more info on how to access an SSE sub endpoint.
### Debugging ### 4. Debugging
Start the restconf fastcgi program with debug flag: Start the restconf fastcgi program with debug flag:
``` ```

View file

@ -662,7 +662,6 @@ main(int argc,
clixon_plugin_start(h, argc+1, argv-1); clixon_plugin_start(h, argc+1, argv-1);
*(argv-1) = tmp; *(argv-1) = tmp;
/**/
if ((sockpath = clicon_option_str(h, "CLICON_RESTCONF_PATH")) == NULL){ if ((sockpath = clicon_option_str(h, "CLICON_RESTCONF_PATH")) == NULL){
clicon_err(OE_CFG, errno, "No CLICON_RESTCONF_PATH in clixon configure file"); clicon_err(OE_CFG, errno, "No CLICON_RESTCONF_PATH in clixon configure file");
goto done; goto done;

View file

@ -467,7 +467,6 @@ api_stream(clicon_handle h,
#ifdef STREAM_FORK #ifdef STREAM_FORK
FCGX_Finish_r(r); FCGX_Finish_r(r);
FCGX_Free(r, 0); FCGX_Free(r, 0);
fprintf(stderr, "child exit and free\n");
restconf_terminate(h); restconf_terminate(h);
exit(0); exit(0);
} }

View file

@ -75,6 +75,7 @@ APPSRC += clixon_util_xpath.c
APPS = $(APPSRC:.c=) APPS = $(APPSRC:.c=)
all: $(APPS) all: $(APPS)
echo "You may want to make clixon_util_stream separately (curl dependency)"
clean: clean:
rm -f $(APPS) *.core rm -f $(APPS) *.core

View file

@ -135,8 +135,8 @@ stream_url_get(char *url,
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
/* HEADERS */ /* HEADERS */
list = curl_slist_append(list, "Accept: text/event-stream"); list = curl_slist_append(list, "Accept: text/event-stream");
list = curl_slist_append(list, "Cache-Control: no-cache"); // list = curl_slist_append(list, "Cache-Control: no-cache");
list = curl_slist_append(list, "Connection: keep-alive"); // list = curl_slist_append(list, "Connection: keep-alive");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
/* specify URL to get */ /* specify URL to get */
cprintf(cbf, "%s", url); cprintf(cbf, "%s", url);