diff --git a/renderer/templates/services/data_plane.uc b/renderer/templates/services/data_plane.uc new file mode 100644 index 0000000..41c5a50 --- /dev/null +++ b/renderer/templates/services/data_plane.uc @@ -0,0 +1,29 @@ +# Data Plane service configuration +{% +let iface = {}; + +function render(dict, type) { + for (let idx, filter in dict) { +%} +set dataplane.{{ filter.name }}=program +set dataplane.{{ filter.name }}.type={{ type }} +set dataplane.{{ filter.name }}.program={{ s(files.add_anonymous(location, 'ingress_' + idx, b64dec(filter.program))) }} +{% + for (let i in services.lookup_interfaces("data-plane:" + filter.name)) { + let name = ethernet.calculate_name(i); + if (!length(iface[name])) + iface[name] = []; + push(iface[name], filter.name); + } + } +} + +render(data_plane.ingress_filters, "ingress"); +%} + +{% for (let k, v in iface): %} +set dataplane.{{ k }}=interface +{% for (let i, p in v): %} +add_list dataplane.{{ k }}.program={{ s(p) }} +{% endfor %} +{% endfor %} diff --git a/schema/service.yml b/schema/service.yml index 6c7fcb1..8b3c430 100644 --- a/schema/service.yml +++ b/schema/service.yml @@ -27,5 +27,7 @@ properties: $ref: "https://ucentral.io/schema/v1/service/online-check/" open-flow: $ref: "https://ucentral.io/schema/v1/service/open-flow/" + data-plane: + $ref: "https://ucentral.io/schema/v1/service/data-plane/" wifi-steering: $ref: "https://ucentral.io/schema/v1/service/wifi-steering/" diff --git a/schemareader.uc b/schemareader.uc index 61989d2..aba89f9 100644 --- a/schemareader.uc +++ b/schemareader.uc @@ -4334,6 +4334,75 @@ function instantiateServiceOpenFlow(location, value, errors) { return value; } +function instantiateServiceDataPlane(location, value, errors) { + if (type(value) == "object") { + let obj = {}; + + function parseIngressFilters(location, value, errors) { + if (type(value) == "array") { + function parseItem(location, value, errors) { + if (type(value) == "object") { + let obj = {}; + + function parseName(location, value, errors) { + if (type(value) != "string") + push(errors, [ location, "must be of type string" ]); + + return value; + } + + if (exists(value, "name")) { + obj.name = parseName(location + "/name", value["name"], errors); + } + + function parseProgram(location, value, errors) { + if (type(value) == "string") { + if (!matchUcBase64(value)) + push(errors, [ location, "must be a valid base64 encoded data" ]); + + } + + if (type(value) != "string") + push(errors, [ location, "must be of type string" ]); + + return value; + } + + if (exists(value, "program")) { + obj.program = parseProgram(location + "/program", value["program"], errors); + } + + return obj; + } + + if (type(value) != "object") + push(errors, [ location, "must be of type object" ]); + + return value; + } + + return map(value, (item, i) => parseItem(location + "/" + i, item, errors)); + } + + if (type(value) != "array") + push(errors, [ location, "must be of type array" ]); + + return value; + } + + if (exists(value, "ingress-filters")) { + obj.ingress_filters = parseIngressFilters(location + "/ingress-filters", value["ingress-filters"], errors); + } + + return obj; + } + + if (type(value) != "object") + push(errors, [ location, "must be of type object" ]); + + return value; +} + function instantiateServiceWifiSteering(location, value, errors) { if (type(value) == "object") { let obj = {}; @@ -4497,6 +4566,10 @@ function instantiateService(location, value, errors) { obj.open_flow = instantiateServiceOpenFlow(location + "/open-flow", value["open-flow"], errors); } + if (exists(value, "data-plane")) { + obj.data_plane = instantiateServiceDataPlane(location + "/data-plane", value["data-plane"], errors); + } + if (exists(value, "wifi-steering")) { obj.wifi_steering = instantiateServiceWifiSteering(location + "/wifi-steering", value["wifi-steering"], errors); } diff --git a/ucentral.schema.json b/ucentral.schema.json index b484b66..2a98102 100644 --- a/ucentral.schema.json +++ b/ucentral.schema.json @@ -1642,6 +1642,26 @@ } } }, + "service.data-plane": { + "type": "object", + "properties": { + "ingress-filters": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "program": { + "type": "string", + "format": "uc-base64" + } + } + } + } + } + }, "service.wifi-steering": { "type": "object", "properties": { @@ -1720,6 +1740,9 @@ "open-flow": { "$ref": "#/$defs/service.open-flow" }, + "data-plane": { + "$ref": "#/$defs/service.data-plane" + }, "wifi-steering": { "$ref": "#/$defs/service.wifi-steering" }