Skip to content

Commit

Permalink
Merge pull request #106 from atlanticwave-sdx/105.schema-updates
Browse files Browse the repository at this point in the history
Validate and document schemas
  • Loading branch information
sajith authored Aug 18, 2023
2 parents 2548a8e + 0a372df commit 29c46bf
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 36 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,27 @@ supposed to generated and pass on to the SDX controller.

## Topology description schemas

There are defined in the `schema` subfolder. Some attributes of each
objects are requied (Can be found in the API definition) while some
are optional. Two attributes are worth of mentioning:
There are some JSON schemas defined in the [schemas] subfolder. These
are meant to guide and validate model development.

Some attributes of each objects are requied (can be found in the API
definition) while some are optional. Two attributes are worth
mentioning:

1. In the `service` object, there is a `vendor` attribute for the
domain to list device vendors that are NOT in its domain.

2. In topology, link, node, and port objects, there is a `private`
attibute for the domain to list attributes that need to kept private.

There are some unit tests to validate JSON blobs we have against their
corresponding schemas. Another nifty tool is [check-jsonschema]:

```console
$ check-jsonschema --schemafile schemas/Topology.json \
src/sdx_datamodel/data/topologies/amlight.json
```


## Developing the library

Expand Down Expand Up @@ -118,3 +129,8 @@ $ python -m unittest -v tests.test_topology_validator

[datamodel-cov-badge]: https://coveralls.io/repos/github/atlanticwave-sdx/datamodel/badge.svg?branch=main (Coverage Status)
[datamodel-cov]: https://coveralls.io/github/atlanticwave-sdx/datamodel?branch=main

[check-jsonschema]: https://pypi.org/project/check-jsonschema/

[schemas]: ./schemas

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Issues = "https://github.com/atlanticwave-sdx/datamodel/issues"
test = [
"pytest >= 7.1.2",
"pytest-cov >= 3.0.0",
"jsonschema >= 4.19.0",
"jsonref >= 1.1.0",
]

[options.packages.find]
Expand Down
19 changes: 12 additions & 7 deletions schemas/Connection.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"maximum": 7
},
"ingress_port": {
"$ref": "Port"
"$ref": "Port.json"
},
"egress_port": {
"$ref": "Port"
"$ref": "Port.json"
},
"end_time": {
"type": "string",
Expand Down Expand Up @@ -47,14 +47,14 @@
"type": "array",
"items": [
{
"$ref": "Link"
"$ref": "Link.json"
}
]
},
"inclusive_links": {
"type": "array",
"items": {
"$ref": "Link"
"$ref": "Link.json"
}
},
"bandwidth_required": {
Expand Down Expand Up @@ -101,7 +101,7 @@
"type": "array",
"items": [
{
"$ref": "Path"
"$ref": "Path.json"
}
]
},
Expand All @@ -114,5 +114,10 @@
]
}
},
"required": ["id", "name", "ingress_port", "egress_port"]
}
"required": [
"id",
"name",
"ingress_port",
"egress_port"
]
}
10 changes: 7 additions & 3 deletions schemas/Link.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"uniqueItems": true,
"items": [
{
"$ref": "Port"
"$ref": "Port.json"
}
]
},
Expand Down Expand Up @@ -88,5 +88,9 @@
}
}
},
"required": ["id", "name", "ports"]
}
"required": [
"id",
"name",
"ports"
]
}
2 changes: 1 addition & 1 deletion schemas/Location.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
}
},
"required": []
}
}
13 changes: 9 additions & 4 deletions schemas/Node.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@
"type": "string"
},
"location": {
"$ref": "location.json"
"$ref": "Location.json"
},
"ports": {
"type": "array",
"items": [
{
"$ref": "port.json"
"$ref": "Port.json"
}
]
}
},
"required": ["id", "location", "name", "ports"]
}
"required": [
"id",
"location",
"name",
"ports"
]
}
10 changes: 7 additions & 3 deletions schemas/Path.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@
"type": "array",
"items": [
{
"$ref": "Link"
"$ref": "Link.json"
}
]
}
},
"required": ["id", "name", "links"]
}
"required": [
"id",
"name",
"links"
]
}
9 changes: 7 additions & 2 deletions schemas/Port.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"label_range": {
"type": "array",
"items": {
"type": "array",
"type": "string",
"minItems": 1,
"maxItems": 4096,
"uniqueItems": true,
Expand Down Expand Up @@ -94,5 +94,10 @@
}
}
},
"required": ["id", "name", "node", "status"]
"required": [
"id",
"name",
"node",
"status"
]
}
18 changes: 10 additions & 8 deletions schemas/Service.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
"type": "string"
},
"vendor": {
"not": [
{
"type": "array",
"items": {
"type": "string"
"not": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
}
}
]
]
}
},
"monitoring_capability": {
"anyOf": [
Expand All @@ -35,4 +37,4 @@
}
},
"required": []
}
}
18 changes: 13 additions & 5 deletions schemas/Topology.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,32 @@
"minimum": 0
},
"domain_service": {
"$ref": "Service"
"$ref": "Service.json"
},
"nodes": {
"type": "array",
"items": [
{
"$ref": "Node"
"$ref": "Node.json"
}
]
},
"links": {
"type": "array",
"items": [
{
"$ref": "Link"
"$ref": "Link.json"
}
]
}
},
"required": ["id", "name", "version","model_version","time_stamp","nodes", "links"]
}
"required": [
"id",
"name",
"version",
"model_version",
"time_stamp",
"nodes",
"links"
]
}
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TestData:
TOPOLOGY_FILE_AMLIGHT = TOPOLOGY_DIR / "amlight.json"
TOPOLOGY_FILE_AMPATH = TOPOLOGY_DIR / "ampath.json"
TOPOLOGY_FILE_SAX = TOPOLOGY_DIR / "sax.json"
TOPOLOGY_FILE_SDX = TOPOLOGY_DIR / "sdx.json"
TOPOLOGY_FILE_ZAOXI = TOPOLOGY_DIR / "zaoxi.json"

REQUESTS_DIR = PACKAGE_DATA_DIR / "requests"
Expand Down
Loading

0 comments on commit 29c46bf

Please sign in to comment.