From: Maria Matejka Date: Wed, 15 Nov 2023 11:31:42 +0000 (+0100) Subject: YANG: basic convertor JSON -> CBOR X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=815b1d403657f3b28713ef516fe1c940d929e115;p=thirdparty%2Fbird.git YANG: basic convertor JSON -> CBOR --- diff --git a/yang/create-venv.sh b/yang/create-venv.sh index 07428c59d..13f092f9a 100755 --- a/yang/create-venv.sh +++ b/yang/create-venv.sh @@ -1,2 +1,2 @@ python3 -m venv venv -pip3 install pyang cbor +pip3 install yangson cbor diff --git a/yang/json-cbor-yang b/yang/json-cbor-yang new file mode 100755 index 000000000..d34e7e7d4 --- /dev/null +++ b/yang/json-cbor-yang @@ -0,0 +1,3 @@ +. venv/bin/activate +python3 json-cbor-yang.py "$@" +#python3 json2cbor.py "$@" diff --git a/yang/json-cbor-yang.py b/yang/json-cbor-yang.py new file mode 100644 index 000000000..14b0a1b7d --- /dev/null +++ b/yang/json-cbor-yang.py @@ -0,0 +1,24 @@ +from yangson import DataModel +import cbor +import json +import sys + +class Message: + def __init__(self, filename): + self.filename = filename + with open(self.filename) as sf: + self.raw = json.load(sf) + + self.dm = DataModel.from_file('yang-library.json') + self.data = self.dm.from_raw(self.raw) + self.data.validate() + +#print(sys.argv[1]) + +msg = Message(sys.argv[1]) +#print(msg, msg.raw) +#print(cbor.dumps(msg.raw)) +with open(sys.argv[2], "wb") as of: + cbor.dump(msg.raw, of) + +print("OK") diff --git a/yang/show_memory.cbor b/yang/show_memory.cbor new file mode 100644 index 000000000..f1cfe02cb --- /dev/null +++ b/yang/show_memory.cbor @@ -0,0 +1 @@ +¡sshow_memory:message¢fheaderqBIRD memory usagedbody¦nrouting_tables¢ieffectiveDhoverhead0proute_attributes¢ieffectiveDhoverhead0iprotocols¢ieffectiveDhoverhead0ncurrent_config¢ieffectiveDhoverhead0nstandby_memory¢ieffectiveDhoverhead0etotal¢ieffectiveDhoverhead0 \ No newline at end of file diff --git a/yang/show_memory.yang b/yang/show_memory.yang index 93f4e1db9..fc454ba5f 100644 --- a/yang/show_memory.yang +++ b/yang/show_memory.yang @@ -1,6 +1,6 @@ module show_memory { - namespace "."; + namespace "https://bird.nic.cz/yang/v2.15/cli-debug"; prefix "memory"; diff --git a/yang/yang-library.json b/yang/yang-library.json new file mode 100644 index 000000000..fcf43be73 --- /dev/null +++ b/yang/yang-library.json @@ -0,0 +1,13 @@ +{ + "ietf-yang-library:modules-state": { + "module-set-id": "12345678abcdef1cefd14622032c432fa598540e", + "module": [ + { + "name": "show_memory", + "namespace": "https://bird.nic.cz/yang/v2.15/cli-debug", + "revision": "", + "conformance-type": "implement" + } + ] + } +}