Skip to content

Commit

Permalink
update the qos scheme/renderer
Browse files Browse the repository at this point in the history
Signed-off-by: John Crispin <[email protected]>
  • Loading branch information
blogic committed Oct 27, 2021
1 parent 6b3bdb1 commit 1bdc8de
Show file tree
Hide file tree
Showing 11 changed files with 524 additions and 194 deletions.
2 changes: 1 addition & 1 deletion renderer/templates/interface.uc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
network = "";
} else if (!interface.ethernet && length(interface.ssids) == 1 && !tunnel_proto)
// interfaces with a single ssid and no tunnel do not need a bridge
netdev = ''
netdev = '';
else
// anything else requires a bridge-vlan
include("interface/bridge-vlan.uc", { interface, name, eth_ports, this_vid, bridgedev });
Expand Down
6 changes: 6 additions & 0 deletions renderer/templates/interface/ssid.uc
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ add_list wireless.{{ section }}.hs20_conn_capab={{ s(name) }}
set wireless.{{ section }}.hs20_wan_metrics={{ s(get_hs20_wan_metrics()) }}
{% endif %}

{% include("wmm.uc", { section }); %}


{% if (ssid.pass_point): %}
{% for (let id, icon in ssid.pass_point.icons): %}
add wireless hs20-icon
Expand All @@ -351,6 +354,9 @@ set wireless.@hs20-icon[-1].type={{ s(icon.type) }}
set wireless.@hs20-icon[-1].lang={{ s(icon.language) }}
set wireless.@hs20-icon[-1].path={{ s(files.add_anonymous(location, 'hs20_icon_' + id, b64dec(icon.icon))) }}
{% endfor %}



{% endif %}

add wireless wifi-vlan
Expand Down
78 changes: 78 additions & 0 deletions renderer/templates/interface/wmm.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{%

let wmm = state?.globals?.wireless_multimedia;

if (!length(wmm))
return;

let class = {
"CS1": 8,
"CS2": 16,
"CS3": 24,
"CS4": 32,
"CS5": 40,
"CS6": 48,
"CS7": 56,
"AF11": 10,
"AF12": 12,
"AF13": 14,
"AF21": 18,
"AF22": 20,
"AF23": 22,
"AF31": 26,
"AF32": 28,
"AF33": 30,
"AF41": 34,
"AF42": 36,
"AF43": 38,
"EF": 46,
"DF": 0,
};

let profiles = {
"enterprise": {
"UP0": [ "DF"],
"UP1": [ "CS1" ],
"UP2": [ "AF11", "AF12", "AF13" ],
"UP3": [ "CS2", "AF21", "AF22", "AF23" ],
"UP4": [ "CS3", "AF31", "AF32", "AF33" ],
"UP5": [ "CS5", "AF41", "AF42", "AF43" ],
"UP6": [ "CS4", "EF" ],
"UP7": [ "CS6" ]
}
};

function qos_map() {
let up_map = [];

if (wmm.profile)
wmm = profiles[wmm.profile];

for (let prio = 0; prio < 8; prio++) {
let up = wmm["UP" + prio];
let len = length(up);

if (length(up) < 2)
continue;

for (let idx = 1; idx < len; idx++) {
push(up_map, class[up[idx]]);
push(up_map, prio);
}
}

for (let prio = 0; prio < 8; prio++) {
let up = wmm["UP" + prio];

if (length(up))
push(up_map, class[up[0]]);
else
push(up_map, 255);
push(up_map, 255);
}
let qos_map = join(",", up_map);

return qos_map;
}
%}
set wireless.{{ section }}.iw_qos_map_set={{ s(qos_map()) }}
72 changes: 28 additions & 44 deletions renderer/templates/services/quality_of_service.uc
Original file line number Diff line number Diff line change
@@ -1,62 +1,46 @@
{%
if (!quality_of_service)
quality_of_service = {};
let egress = ethernet.lookup_by_select_ports([quality_of_service.select_port]);
let egress = ethernet.lookup_by_select_ports(quality_of_service.select_ports);
let enable = length(egress);
services.set_enabled("sqm", enable);
services.set_enabled("qosify", enable);
if (!enable)
return;

if (!quality_of_service.upload_rate || !quality_of_service.download_rate) {
quality_of_service.download_rate = 0;
quality_of_service.upload_rate = 0;
}

function get_speed(dev, speed) {
if (!speed)
speed = ethernet.get_speed(dev);
return speed * 1000;
return speed;
}

function get_proto(proto) {
if (proto == "any")
return [ "udp", "tcp" ];
return [ proto ];
}

function dscp_map(dscp) {
let map = { "CS1": 8, "CS2": 16, "CS3": 24, "CS4": 32, "CS5": 40, "CS6": 48, "CS7": 56 };
return map[dscp] ? map[dscp] : 0;
function get_range(port) {
if (port.range_end)
return sprintf("-%d", port.range_end)
}

let fs = require("fs");
let file = fs.open("/tmp/qosify.conf", "w");
for (let class in quality_of_service.classifier) {
if (!length(class.ports))
continue;
for (let port in class.ports)
for (let proto in get_proto(port.protocol))
file.write(sprintf("%s:%d%s %s%s\n", proto, port.port,
port.range_end ? sprintf("-%d", port.range_end) : "",
port.reclassify ? "" : "+", class.dscp));
}
file.close();
%}

{% for (let dev in egress): %}
set sqm.{{ dev }}=queue
set sqm.@queue[-1].interface={{ s(dev) }}
set sqm.@queue[-1].download='{{ get_speed(dev, quality_of_service.upload_rate) }}'
set sqm.@queue[-1].upload='{{ get_speed(dev, quality_of_service.download_rate) }}'
set sqm.@queue[-1].auto_rate='{{ quality_of_service.download_rate ? 0 : 1 }}'
set sqm.@queue[-1].enabled='1'
set sqm.@queue[-1].verbosity='5'
set sqm.@queue[-1].qdisc_advanced='1'
set sqm.@queue[-1].egress_ecn='NOECN'
set sqm.@queue[-1].squash_dscp='0'
set sqm.@queue[-1].squash_ingress='0'
set sqm.@queue[-1].ingress_ecn='ECN'
set sqm.@queue[-1].debug_logging='1'
set sqm.@queue[-1].qdisc='fq_codel'
set sqm.@queue[-1].script='layer_cake.qos'
set sqm.@queue[-1].linklayer='ethernet'
set sqm.@queue[-1].overhead='44'
set sqm.@queue[-1].eqdisc_opts='diffserv4 no-split-gso'
set sqm.@queue[-1].iqdisc_opts='diffserv4 no-split-gso'
{% endfor %}

{% for (let class in quality_of_service.classifier): %}
{% if (!length(class.ports) && !length(class.dns)) continue; %}
{% let dscp = dscp_map(class.dscp); %}
add sqm classifier
set sqm.@classifier[-1].dscp={{ dscp }}
{% for (let fqdn in class.dns): %}
add_list sqm.@classifier[-1].dns={{ s(fqdn) }}
{% endfor %}
{% for (let port in class.ports): %}
{% if (!port.protocol || !port.port) continue; %}
add_list sqm.@classifier[-1].ports='{{ port.protocol }}:{{ port.port }}{{ port.range_end ? ":" + port.range_end : "" }}'
{% endfor %}
set qosify.{{ dev }}=device
set qosify.{{ dev }}.name={{ s(dev) }}
set qosify.{{ dev }}.bandwidth_up='{{ get_speed(dev, quality_of_service.bandwidth_up) }}mbit'
set qosify.{{ dev }}.bandwidth_down='{{ get_speed(dev, quality_of_service.bandwidth_down) }}mbit'
{% endfor %}
6 changes: 6 additions & 0 deletions schema/globals.wireless-multimedia-profile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description:
Define a default profile that shall be used for the WMM behaviour of all SSIDs on
the device.
type: string
enum:
- enterprise
24 changes: 24 additions & 0 deletions schema/globals.wireless-multimedia.class-selector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
type: array
items:
type: string
enum:
- CS1
- CS2
- CS3
- CS4
- CS5
- CS6
- AF11
- AF12
- AF13
- AF21
- AF22
- AF23
- AF31
- AF32
- AF33
- AF41
- AF42
- AF43
- DF
- EF
22 changes: 22 additions & 0 deletions schema/globals.wireless-multimedia.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
description:
Define the default WMM behaviour of all SSIDs on the device. Each access
category can be assigned a default class selector that gets used for packet
matching.
type: object
properties:
UP0:
$ref: 'https://ucentral.io/schema/v1/globals/wireless-multimedia/class-selector/'
UP1:
$ref: 'https://ucentral.io/schema/v1/globals/wireless-multimedia/class-selector/'
UP2:
$ref: 'https://ucentral.io/schema/v1/globals/wireless-multimedia/class-selector/'
UP3:
$ref: 'https://ucentral.io/schema/v1/globals/wireless-multimedia/class-selector/'
UP4:
$ref: 'https://ucentral.io/schema/v1/globals/wireless-multimedia/class-selector/'
UP5:
$ref: 'https://ucentral.io/schema/v1/globals/wireless-multimedia/class-selector/'
UP6:
$ref: 'https://ucentral.io/schema/v1/globals/wireless-multimedia/class-selector/'
UP7:
$ref: 'https://ucentral.io/schema/v1/globals/wireless-multimedia/class-selector/'
4 changes: 4 additions & 0 deletions schema/globals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ properties:
format: uc-cidr6
examples:
- fdca:1234:4567::/48
wireless-multimedia:
oneOf:
- $ref: 'https://ucentral.io/schema/v1/globals/wireless-multimedia/'
- $ref: 'https://ucentral.io/schema/v1/globals/wireless-multimedia-profile/'
77 changes: 40 additions & 37 deletions schema/service.quality-of-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@ description:
This section describes the QoS behaviour of the unit.
type: object
properties:
select-port:
select-ports:
description:
The physical network devices that shall be considered the primary uplink interface.
All classification and shaping will happen on this device.
type: string
default: WAN1
upload-rate:
type: array
items:
type: string
default: WAN
bandwidth-up:
description:
Defines the upload rate of this device. If it is not known or the device is
Defines the upload bandwidth of this device. If it is not known or the device is
attached to a shared medium, this value needs to be 0.
type: integer
default: 0
download-rate:
bandwidth-down:
description:
Defines the download rate of this device. If it is not known or the device is
Defines the download bandwidth of this device. If it is not known or the device is
attached to a shared medium, this value needs to be 0.
type: integer
default: 0
reclassify-ingress:
description:
Ignore the ToS/DSCP of incoming packets and reclassify them.
type: boolean
default: true
classifier:
description:
A list of classifiers. Each classifier will map certain traffic to specific ToS/DSCP
Expand All @@ -51,30 +48,36 @@ properties:
ports:
description:
Each entry defines a layer3 protocol and a port(range) that will be used to match packets.
type: object
properties:
protocol:
description:
The port match can apply for TCP, UDP or any IP protocol.
type: string
enum:
- any
- tcp
- udp
default: any
port:
description:
The port of this match rule.
type: integer
range-end:
description:
The last port of this match rule if it is a port range.
type: integer
dns:
description:
Each entry defines a wildcard FQDN. The IP that this resolves to will be used to match packets.
type: array
items:
type: string
format: fqdn

type: object
properties:
protocol:
description:
The port match can apply for TCP, UDP or any IP protocol.
type: string
enum:
- any
- tcp
- udp
default: any
port:
description:
The port of this match rule.
type: integer
range-end:
description:
The last port of this match rule if it is a port range.
type: integer
reclassify:
description:
Ignore the ToS/DSCP of packets and reclassify them.
type: boolean
default: true
dns:
description:
Each entry defines a wildcard FQDN. The IP that this resolves to will be used to match packets.
type: array
items:
type: string
format: fqdn
Loading

0 comments on commit 1bdc8de

Please sign in to comment.