Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add groupings support #4

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fdef271
Fix CMake UCI_INCLUDE_DIR
terz99 Apr 10, 2020
654ea9f
Fix SEGFAULT
terz99 Apr 10, 2020
9fe60f7
Fix SIGABRT free() invalid pointer
terz99 Apr 10, 2020
7a1c89b
Fix char memory
terz99 Apr 11, 2020
976693b
Add read directly from file in POST/PUT for debugging
terz99 Apr 11, 2020
cc4060d
Copy yin folder to root
terz99 Apr 12, 2020
4a2764b
Annotate ietf-lmap-common.yang
terz99 Apr 17, 2020
92fc130
Annotate ietf-netconf-acm.yang
terz99 Apr 17, 2020
34a262f
Annotate ietf-lmap-control.yang
terz99 Apr 17, 2020
4564027
rename some modules
terz99 Apr 17, 2020
c60141c
Add control module in modulemap
terz99 Apr 17, 2020
d2465de
Replace hyphens with underscores in annotation
terz99 Apr 18, 2020
229cb11
Disable mandatory fields for debugging
terz99 Apr 19, 2020
dd2f8ae
Modify modules/delete unnecessary nesting and choice/case types
terz99 Apr 19, 2020
83b7cfd
Generate .yin files
terz99 Apr 19, 2020
79ac861
Update lmapd module with groupings and add conversion bash script
terz99 Apr 19, 2020
b72892f
Fix multiple regex when converting from yin2json
terz99 Apr 20, 2020
1fb11d8
Fix script
terz99 Apr 20, 2020
b63ac2d
Fix YANG control module for lmapd
terz99 Apr 20, 2020
1361111
Update YANG module
terz99 Apr 20, 2020
add419c
Update YANG module
terz99 Apr 21, 2020
0847954
Update some modules again
terz99 Apr 21, 2020
6efa6c6
Fix corrupted_size vs prev_size problem
terz99 Apr 21, 2020
eb9dd26
Fix script to convert ranges with max properly
terz99 Apr 22, 2020
fed847b
Fix list in list path deformity
terz99 Apr 22, 2020
8ffe2e8
Add POST test yaml file
terz99 Apr 22, 2020
95a5aa6
Change lmapd-valid.yaml a bit
terz99 Apr 23, 2020
9c32112
Extract data from groupings
terz99 Apr 23, 2020
343da2b
Add groupings support
terz99 Apr 23, 2020
007bb3a
Add YANG type grouping support
terz99 Apr 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ cmake-build-debug
.env
scratch
.idea
cgi-bin
cgi-bin
generated
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 14)
include_directories(src)

find_path(JSON_C_INCLUDE_DIR json-c/json.h)
find_path(UCI_INCLUDE_DIR uci.h)
find_path(UCI_INCLUDE_DIR uci/uci.h)
include_directories(${JSON_C_INCLUDE_DIR})
include_directories(${UCI_INCLUDE_DIR})

Expand Down
43 changes: 36 additions & 7 deletions src/cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "cgi.h"
#include "restconf.h"

#define MAX_BUFFER_SIZE 1024

/**
* Create the cgi_context from environment variables
* @return cgi_context
Expand Down Expand Up @@ -54,19 +56,46 @@ char *get_content() {
char *post_data;
char *length_str;
char *trailing;
char *file_path;
unsigned long length;

length_str = getenv("CONTENT_LENGTH");
if (!length_str || !*length_str) return NULL;
if (!length_str || !*length_str) {
file_path = getenv("CONTENT_FILE_PATH");
if (!file_path || !*file_path) {
return NULL;
}

FILE *fp = fopen(file_path, "rb");
if (!fp) {
return NULL;
}

fseek(fp, 0L, SEEK_END);
long size = ftell(fp);
fseek(fp, 0L, SEEK_SET);

post_data = (char *) malloc(sizeof(char) * size);
if (!post_data) {
fclose(fp);
return NULL;
}

if (fread(post_data, sizeof(char), size, fp) == size) {
post_data[size] = '\0';
}
fclose(fp);

length = strtoul(length_str, &trailing, 10);
if (*trailing != '\0' || !length || length > 1024UL * 1024UL) return NULL;
} else {
length = strtoul(length_str, &trailing, 10);
if (*trailing != '\0' || !length || length > 1024UL * 1024UL) return NULL;

post_data = (char *)malloc(length + 1);
if (!post_data) return NULL;
post_data = (char *)malloc(length + 1);
if (!post_data) return NULL;

if (fread(post_data, sizeof(char), length, stdin) == length) {
post_data[length] = '\0';
if (fread(post_data, sizeof(char), length, stdin) == length) {
post_data[length] = '\0';
}
}

return post_data;
Expand Down
32 changes: 29 additions & 3 deletions src/generated/yang.h

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/restconf-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "restconf.h"
#include "yang-util.h"

#define DEBUG

/**
* Return json_object's value as a string
* @param jobj input object to be searched
Expand Down Expand Up @@ -166,13 +168,13 @@ error json_yang_verify_list(struct json_object* list,
return KEY_NOT_PRESENT;
}
}

#ifndef DEBUG
if (mandatory_exist) {
if (check_mandatory_values(mandatory, list_item) != RE_OK) {
return MANDATORY_NOT_PRESENT;
}
}

#endif
for (size_t verify_i = list_i + 1;
verify_i < json_object_array_length(list) && keys_exist; verify_i++) {
int different = 0;
Expand Down
9 changes: 9 additions & 0 deletions src/restconf-method.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static UciWritePair **verify_content_yang(struct json_object *content,
int root, int check_exists) {
UciWritePair **command_list = NULL;
const char *child_type = NULL;
struct UciPath *old_path = NULL;
if (!(child_type = json_get_string(yang_node, YANG_TYPE))) {
*err = YANG_SCHEMA_ERROR;
return NULL;
Expand Down Expand Up @@ -96,12 +97,19 @@ static UciWritePair **verify_content_yang(struct json_object *content,
struct json_object *tmp = json_object_array_get_idx(content, index);
path->index = pos;
path->where = 1;
old_path = (struct UciPath *) malloc(sizeof(struct UciPath));
if (!old_path) {
return NULL;
}
memcpy(old_path, path, sizeof(struct UciPath));
UciWritePair **tmp_list =
verify_content_yang(tmp, yang_node, path, err, 0, check_exists);
if (*err != RE_OK) {
free_uci_write_list(tmp_list);
return NULL;
}
memcpy(path, old_path, sizeof(struct UciPath));
free(old_path);
for (size_t i = 0; i < vector_size(tmp_list); i++) {
vector_push_back(command_list, tmp_list[i]);
}
Expand Down Expand Up @@ -705,6 +713,7 @@ int data_put(struct CgiContext *cgi, char **pathvec, int root) {
if ((keys = json_get_array(top_level, YANG_KEYS))) {
struct json_object *values = NULL;
if (json_extract_key_values(keys, root_object, &values) == RE_OK) {
key_out[0] = '\0';
json_object_object_foreach(values, key, value) {
strcat(key_out, json_object_get_string(value));
strcat(key_out, ",");
Expand Down
2 changes: 1 addition & 1 deletion src/restconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int api_root(struct CgiContext *cgi) {
static int data_root(struct CgiContext *cgi, char **pathvec) {
int retval = 1;

if (pathvec[1] == NULL) {
if (vector_size(pathvec) <= 1) {
// root
if (is_OPTIONS(cgi->method)) {
content_type_json();
Expand Down
3 changes: 1 addition & 2 deletions src/uci/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ struct UciWritePair *initialize_uci_write_pair(struct UciPath *path,

int free_uci_write_list(UciWritePair **list) {
for (size_t i = 0; i < vector_size(list); i++) {
UciWritePair *cmd = list[i];
free(cmd->value);
free(list[i]);
}
vector_free(list);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/uci/methods.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "methods.h"
#include <string.h>
#include <uci.h>
#include <uci/uci.h>
#include "http.h"
#include "uci-util.h"
#include "util.h"
Expand Down
2 changes: 1 addition & 1 deletion src/uci/methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _RESTCONF_UCI_H

#include <stddef.h>
#include <uci.h>
#include <uci/uci.h>
#include "generated/yang.h"

/**
Expand Down
5 changes: 4 additions & 1 deletion src/yang-verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ static int yang_verify_value_type(struct json_object* type, const char* value) {
yang_type converted = str_to_yang_type(leaf_type);
switch (converted) {
case BOOLEAN:
if (strcmp(value, "true") != 0 && strcmp(value, "false") != 0) return 1;
if (strcmp(value, "true") != 0 && strcmp(value, "false") != 0 &&
strcmp(value, "1") != 0 && strcmp(value, "0") != 0) {
return 1;
}
break;
case EMPTY:
break;
Expand Down
167 changes: 167 additions & 0 deletions test/acceptance/POST/lmapd-valid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{
"lmapd:lmap":{
"schedules":{
"schedule":[
{
"name":"demo",
"start":"every-minute",
"execution-mode": "sequential",
"action":[
{
"name":"mtr0",
"task":"mtr",
"destination":[
"report-primary"
],
"option":[
{
"id":"0",
"value":"www.ietf.org"
}
]
},
{
"name":"mtr1",
"task":"mtr",
"destination":[
"report-primary"
],
"option":[
{
"id":"1",
"value":"www.ieee.org"
}
]
},
{
"name":"happy0",
"task":"happy",
"destination":[
"report-primary",
"report-secondary"
],
"option":[
{
"id":"2",
"value":"www.ieee.org"
}
]
},
{
"name":"happy1",
"task":"happy",
"destination":[
"report-primary",
"report-secondary"
],
"option":[
{
"id":"3",
"value":"www.ieee.org"
}
]
}
]
},
{
"name":"report_primary",
"start":"every-six-hours",
"action":[
{
"name":"report",
"task":"lmap-reporting-task",
"option":[
{
"id":"collector_uri",
"value":"https://collector.example.com/restconf/operations/ietf-lmap-report:report"
}
]
}
]
},
{
"name":"report_secondary",
"start":"daily",
"action":[
{
"name":"report",
"task":"lmap-reporting-task",
"option":[
{
"id":"collector_uri",
"value":"https://shadow.example.com/restconf/operations/ietf-lmap-report:report"
}
]
}
]
}
]
},
"agent":{
"agent-id":"7984713289472",
"group-id":"network-measurement-at-the-north-pole",
"report-agent-id":true,
"report-group-id":false
},
"tasks":{
"task":[
{
"name":"mtr",
"program":"/usr/bin/mtr",
"option":[
{
"id":"numeric",
"name":"--no-dns"
},
{
"id":"csv",
"name":"--csv"
},
{
"id":"lookup_AS_numbers",
"name":"-z"
},
{
"id":"one_cycle",
"name":"--report-cycles=3"
}
]
},
{
"name":"happy",
"program":"/usr/local/bin/happy",
"option":[
{
"id":"csv",
"name":"-m"
},
{
"id":"one_query",
"name":"-q",
"value":"1"
}
]
},
{
"name":"lmap_reporting_task",
"program":"/usr/bin/lmap-reporter",
"option":[
{
"id":"collector_uri",
"value":"https://example.com/restconf/operations/ietf-lmap-report:report"
}
]
}
]
},
"events":{
"event":[
{
"name":"every_minute",
"event-type": 0,
"interval": 60
}
]
}
}
}
20 changes: 19 additions & 1 deletion test/acceptance/POST/root-valid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,25 @@
"lastname": "student",
"age": 21,
"major": "CS",
"grade": 75
"grade": 75,
"contact-option": [
{
"email": "d_terzikj_jacobs_university_de",
"example-leaf": "example-leaf-example"
}
],
"option": [
{
"id": "0",
"name": "example-name",
"more-options": [
{
"id": "1",
"value": "example-value"
}
]
}
]
}
]
}
Expand Down
Loading