Skip to content

Commit

Permalink
- Moved deviation actions to include grouped/uses statements. See #211
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed May 6, 2021
1 parent 1c5c5a7 commit 0225488
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
8 changes: 7 additions & 1 deletion apps/restconf/restconf_api_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ restconf_reply_send(void *req0,
clicon_err(OE_DAEMON, EFAULT, "evhtp_request_get_connection");
goto done;
}
/* If body, add a content-length header */
/* If body, add a content-length header
* A server MUST NOT send a Content-Length header field in any response
* with a status code of 1xx (Informational) or 204 (No Content). A
* server MUST NOT send a Content-Length header field in any 2xx
* (Successful) response to a CONNECT request (Section 4.3.6 of
* [RFC7231]).
*/
if (cb != NULL && cbuf_len(cb)){
cprintf(cb, "\r\n");
if (restconf_reply_header(req, "Content-Length", "%d", cbuf_len(cb)) < 0)
Expand Down
1 change: 1 addition & 0 deletions lib/src/clixon_yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,7 @@ yang_deviation(yang_stmt *ys,
if (yang_abs_schema_nodeid(ys, nodeid, &ytarget) < 0)
goto done;
if (ytarget == NULL){
clicon_log(LOG_WARNING, "deviation %s: target not found", nodeid);
goto ok;
/* The RFC does not explicitly say the target node MUST exist
clicon_err(OE_YANG, 0, "schemanode sanity check of %s", nodeid);
Expand Down
23 changes: 11 additions & 12 deletions lib/src/clixon_yang_parse_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1323,21 +1323,13 @@ yang_parse_post(clicon_handle h,
if (yang_features(h, yang_child_i(yspec, i)) < 0)
goto done;

/* 4: Check deviations: not-supported add/delete/replace statements
* done after if-features since they may affect deviations but before populate since target yang statements
* may be removed or changed
*/
for (i=modmin; i<modmax; i++) /* Really only under (sub)modules no need to traverse whole tree */
if (yang_apply(yang_child_i(yspec, i), -1, yang_deviation, 1, (void*)h) < 0)
goto done;

/* 5: Go through parse tree and populate it with cv types */
/* 4: Go through parse tree and populate it with cv types */
for (i=modmin; i<modmax; i++){
if (yang_apply(yang_child_i(yspec, i), -1, ys_populate, 0, (void*)h) < 0)
goto done;
}

/* 6: Resolve all types: populate type caches. Requires eg length/range cvecs
/* 5: Resolve all types: populate type caches. Requires eg length/range cvecs
* from ys_populate step.
* Must be done using static binding.
*/
Expand All @@ -1352,14 +1344,14 @@ yang_parse_post(clicon_handle h,
* single tree as they are used.
*/

/* 7: Macro expansion of all grouping/uses pairs. Expansion needs marking */
/* 6: Macro expansion of all grouping/uses pairs. Expansion needs marking */
for (i=0; i<ylen; i++){
if (yang_expand_grouping(ylist[i]) < 0)
goto done;
yang_apply(ylist[i], -1, (yang_applyfn_t*)yang_flag_reset, 1, (void*)YANG_FLAG_MARK);
}

/* 8: Top-level augmentation of all modules.
/* 7: Top-level augmentation of all modules.
* Note: Clixon does not implement augment in USES
* Note: There is an ordering problem, where an augment in one module depends on an augment in
* another module not yet augmented.
Expand All @@ -1368,6 +1360,13 @@ yang_parse_post(clicon_handle h,
if (yang_augment_module(ylist[i]) < 0)
goto done;

/* 8: Check deviations: not-supported add/delete/replace statements
* done late since eg groups must be expanded
*/
for (i=modmin; i<modmax; i++) /* Really only under (sub)modules no need to traverse whole tree */
if (yang_apply(yang_child_i(yspec, i), -1, yang_deviation, 1, (void*)h) < 0)
goto done;

/* 9: Go through parse tree and do 2nd step populate (eg default) */
for (i=0; i<ylen; i++)
if (yang_apply(ylist[i], -1, ys_populate2, 1, (void*)h) < 0)
Expand Down
12 changes: 9 additions & 3 deletions test/test_yang_deviation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Yang deviate tests
# See RFC 7950 5.6.3 and 7.20.3
# Four examples: not supported, add, replace, delete
# Also:
# - keyword with/without string
# - use grouping

# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = "$0" ]; then exit 0; else return 0; fi
Expand Down Expand Up @@ -34,7 +37,8 @@ module example-base{
yang-version 1.1;
prefix base;
namespace "urn:example:base";
container system {
grouping system-top {
container system {
must "daytime or time"; /* deviate delete removes this */
leaf daytime{ /* deviate not-supported removes this */
type string;
Expand All @@ -59,7 +63,9 @@ module example-base{
/* deviate add adds "default admin" here */
}
}
}
}
uses system-top;
}
EOF

Expand Down Expand Up @@ -162,7 +168,7 @@ module example-deviations{
}
}
EOF
new "1. daytime supported"
new "1. Baseline: no deviations"
testrun true false true true

# Example from RFC 7950 Sec 7.20.3.3
Expand Down Expand Up @@ -193,7 +199,7 @@ module example-deviations{
}
deviation /base:system/base:user/base:type {
deviate add {
default "admin"; // new users are 'admin' by default
default "admin";
}
}
}
Expand Down

0 comments on commit 0225488

Please sign in to comment.