Skip to content

Commit

Permalink
Support translated YANG models.
Browse files Browse the repository at this point in the history
This change allows one model to be translated to another model. This is
useful if multiple YANG models for the same type of data exist. In this
case a back-end super YANG model is created which is a combination of
the contributing models, and requests to the individual models are
translated into a request of the super model and responses are
translated back into the individual requesting models. In the Apteryx
data store information only exists for the super model. The translation
is controlled by a translating configuration file named {name}.xlat

is that a single super mode
  • Loading branch information
gcampbell512 committed Dec 4, 2023
1 parent 8ea05c1 commit 6ea2295
Show file tree
Hide file tree
Showing 5 changed files with 925 additions and 2 deletions.
3 changes: 3 additions & 0 deletions apteryx-xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ char *sch_translate_from (sch_node * node, char *value);
bool sch_validate_pattern (sch_node * node, const char *value);
gboolean sch_match_name (const char *s1, const char *s2);
bool sch_ns_match (sch_node *node, void *ns);
GNode *sch_translate_input (sch_instance * instance, GNode *node, int flags,
void **xlat_data, sch_node **rschema);
GNode *sch_translate_output (sch_instance * instance, GNode *node, int flags, void *xlat_data);

/* Data translation/manipulation */
typedef enum
Expand Down
29 changes: 29 additions & 0 deletions models/xlat_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
xlat_data = {}

xlat_data.translate_type = function(field, value, dir)
local value1 = value
if field == 'type' then
value1 = tonumber (value)
print("field " .. field)
print("value1 " .. value1)
print("dir " .. dir)
if dir == 'out' then
if value == '1' then
value1 = '3'
else
value1 = '4'
end
print("value1 " .. value1)
else
if value == '3' then
value1 = '1'
else
value1 = '2'
end
end
end
return value1
end

return xlat_data

7 changes: 7 additions & 0 deletions models/xlat_test.xlat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/xlat-test/xlat-animals /test/animals/animal
/xlat-test/xlat-animals/xlat-animal /test/animals/animal
/xlat-test/xlat-animals/xlat-animal/*/name /test/animals/animal/*/name
/xlat-test/xlat-animals/xlat-animal/*/type /test/animals/animal/*/type xlat_data.translate_type
/xlat-test/xlat-animals/xlat-animal/*/colour /test/animals/animal/*/colour
/xlat-test/xlat-animals/xlat-animal/*/food /test/animals/animal/*/food
/xlat-test/xlat-animals/xlat-animal/*/toys /test/animals/animal/*/toys
32 changes: 32 additions & 0 deletions models/xlat_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version='1.0' encoding='UTF-8'?>
<MODULE xmlns="http://test.com/ns/yang/xlat-testing"
xmlns:xlat-test="http://test.com/ns/yang/xlat-testing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://github.com/alliedtelesis/apteryx-xml https://github.com/alliedtelesis/apteryx-xml/releases/download/v1.2/apteryx.xsd"
model="xlat-test" organization="Test Ltd" version="2023-01-01">
<NODE name="xlat-test" help="This is a test node">
<NODE name="xlat-animals">
<NODE name="xlat-animal" help="This is a list of animals">
<NODE name="*" help="The animal entry with key name">
<NODE name="name" mode="rw" help="This is the name of the animal" />
<NODE name="type" mode="rw" default="big" help="This is the type of the animal">
<VALUE name="fast" value="3" />
<VALUE name="slow" value="4" />
</NODE>
<NODE name="colour" mode="rw" help="This is the colour of the animal" />
<NODE name="food">
<NODE name="*" help="This is a list of food">
<NODE name="name" mode="rw" help="Food name" />
<NODE name="type" mode="rw" help="Food type" />
</NODE>
</NODE>
<NODE name="toys">
<NODE name="toy" help="This is a leaf list of toys">
<NODE name="*" mode="rw" help="List of toys" />
</NODE>
</NODE>
</NODE>
</NODE>
</NODE>
</NODE>
</MODULE>
Loading

0 comments on commit 6ea2295

Please sign in to comment.