diff --git a/yang/JSON_CBOR.py b/yang/JSON_CBOR.py new file mode 100644 index 00000000..ccbfc351 --- /dev/null +++ b/yang/JSON_CBOR.py @@ -0,0 +1,14 @@ +from yangson import DataModel + +import cbor +import json + +class Message: + def __init__(self, filename, _type): + self.filename = filename + with open(self.filename, "rb") as sf: + self.raw = { "json": json, "cbor": cbor }[_type].load(sf) + + self.dm = DataModel.from_file('yang-library.json') + self.data = self.dm.from_raw(self.raw) + self.data.validate() diff --git a/yang/cbor-json-yang b/yang/cbor-json-yang new file mode 100755 index 00000000..a31b769e --- /dev/null +++ b/yang/cbor-json-yang @@ -0,0 +1,5 @@ +python3 -m venv venv +. venv/bin/activate +pip3 install yangson cbor + +python3 cbor-json-yang.py "$@" diff --git a/yang/cbor-json-yang.py b/yang/cbor-json-yang.py new file mode 100644 index 00000000..2b4f79fe --- /dev/null +++ b/yang/cbor-json-yang.py @@ -0,0 +1,13 @@ +import cbor +import json +import sys + +import JSON_CBOR + +#print(sys.argv[1]) + +msg = JSON_CBOR.Message(sys.argv[1], "cbor") +with open(sys.argv[2], "w") as of: + json.dump(msg.raw, of, indent=2) + +print("OK") diff --git a/yang/json-cbor-yang b/yang/json-cbor-yang index 24b74617..97e9546a 100755 --- a/yang/json-cbor-yang +++ b/yang/json-cbor-yang @@ -3,4 +3,3 @@ python3 -m venv venv pip3 install yangson cbor python3 json-cbor-yang.py "$@" -#python3 json2cbor.py "$@" diff --git a/yang/json-cbor-yang.py b/yang/json-cbor-yang.py index 14b0a1b7..f613303b 100644 --- a/yang/json-cbor-yang.py +++ b/yang/json-cbor-yang.py @@ -1,23 +1,12 @@ -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() +import JSON_CBOR #print(sys.argv[1]) -msg = Message(sys.argv[1]) -#print(msg, msg.raw) -#print(cbor.dumps(msg.raw)) +msg = JSON_CBOR.Message(sys.argv[1], "json") with open(sys.argv[2], "wb") as of: cbor.dump(msg.raw, of) diff --git a/yang/show_memory.json b/yang/show_memory.json index f5c71279..85c972f1 100644 --- a/yang/show_memory.json +++ b/yang/show_memory.json @@ -1,31 +1,31 @@ { "show_memory:message": { - "header": "BIRD memory usage", - "body": { - "routing_tables": { - "effective": 324, - "overhead": 48 - }, - "route_attributes": { - "effective": 324, - "overhead": 48 - }, - "protocols": { - "effective": 324, - "overhead": 48 - }, - "current_config": { - "effective": 324, - "overhead": 48 - }, - "standby_memory": { - "effective": 324, - "overhead": 48 - }, - "total": { - "effective": 324, - "overhead": 48 - } - } + "header": "BIRD memory usage", + "body": { + "routing_tables": { + "effective": 324, + "overhead": 48 + }, + "route_attributes": { + "effective": 324, + "overhead": 48 + }, + "protocols": { + "effective": 324, + "overhead": 48 + }, + "current_config": { + "effective": 324, + "overhead": 48 + }, + "standby_memory": { + "effective": 324, + "overhead": 48 + }, + "total": { + "effective": 324, + "overhead": 48 + } + } } }