renderer: add virtual data-plane support

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2021-07-25 07:15:14 +02:00
parent 1022c4a364
commit 15ffad8706
4 changed files with 127 additions and 0 deletions

View File

@@ -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 %}

View File

@@ -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/"

View File

@@ -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);
}

View File

@@ -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"
}