From ab8cb7a3ac3b1aeec31529dd59dda792f265d554 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Thu, 30 May 2024 10:55:25 +0200 Subject: [PATCH] confd: interfaces: VLAN QoS mappings Let the ring-bearer^Wuser decide the policy around how VLAN PCP is mapped to skb->priority on ingress, and back to PCP again on egress. Either a fixed value is used for all packets, or a 1:1 mapping is done between the two domains. By default, we follow Linux's defaults of a fixed 0 value on both ingress and egress. --- src/confd/src/ietf-interfaces.c | 46 +++++++++ src/confd/yang/infix-if-vlan@2023-10-25.yang | 49 --------- src/confd/yang/infix-if-vlan@2024-05-30.yang | 101 +++++++++++++++++++ 3 files changed, 147 insertions(+), 49 deletions(-) delete mode 100644 src/confd/yang/infix-if-vlan@2023-10-25.yang create mode 100644 src/confd/yang/infix-if-vlan@2024-05-30.yang diff --git a/src/confd/src/ietf-interfaces.c b/src/confd/src/ietf-interfaces.c index a75d19ad..3d584b9f 100644 --- a/src/confd/src/ietf-interfaces.c +++ b/src/confd/src/ietf-interfaces.c @@ -1397,6 +1397,44 @@ static int netdag_gen_veth(struct dagger *net, struct lyd_node *dif, return 0; } +static int netdag_gen_vlan_ingress_qos(struct lyd_node *cif, FILE *ip) +{ + const char *prio; + + prio = lyd_get_value(lydx_get_descendant(lyd_child(cif), + "vlan", "ingress-qos", "priority", NULL)); + + if (prio[0] >= '0' && prio[0] <= '7' && prio[1] == '\0') { + fprintf(ip, " ingress-qos-map 0:%c 1:%c 2:%c 3:%c 4:%c 5:%c 6:%c 7:%c", + prio[0], prio[0], prio[0], prio[0], prio[0], prio[0], prio[0], prio[0]); + return 0; + } else if (!strcmp(prio, "from-pcp")) { + fputs(" ingress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7", ip); + return 0; + } + + return ERR_IFACE(cif, -EINVAL, "Unsupported ingress priority mode \"%s\"", prio); +} + +static int netdag_gen_vlan_egress_qos(struct lyd_node *cif, FILE *ip) +{ + const char *pcp; + + pcp = lyd_get_value(lydx_get_descendant(lyd_child(cif), + "vlan", "egress-qos", "pcp", NULL)); + + if (pcp[0] >= '0' && pcp[0] <= '7' && pcp[1] == '\0') { + fprintf(ip, " egress-qos-map 0:%c 1:%c 2:%c 3:%c 4:%c 5:%c 6:%c 7:%c", + pcp[0], pcp[0], pcp[0], pcp[0], pcp[0], pcp[0], pcp[0], pcp[0]); + return 0; + } else if (!strcmp(pcp, "from-priority")) { + fputs(" egress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7", ip); + return 0; + } + + return ERR_IFACE(cif, -EINVAL, "Unsupported egress priority mode \"%s\"", pcp); +} + static int netdag_gen_vlan(struct dagger *net, struct lyd_node *dif, struct lyd_node *cif, FILE *ip) { @@ -1440,6 +1478,14 @@ static int netdag_gen_vlan(struct dagger *net, struct lyd_node *dif, if (lydx_get_diff(lydx_get_child(vlan, "id"), &vidd)) fprintf(ip, " id %s", vidd.new); + err = netdag_gen_vlan_ingress_qos(cif, ip); + if (err) + return err; + + err = netdag_gen_vlan_egress_qos(cif, ip); + if (err) + return err; + fputc('\n', ip); return 0; diff --git a/src/confd/yang/infix-if-vlan@2023-10-25.yang b/src/confd/yang/infix-if-vlan@2023-10-25.yang deleted file mode 100644 index ad1092ec..00000000 --- a/src/confd/yang/infix-if-vlan@2023-10-25.yang +++ /dev/null @@ -1,49 +0,0 @@ -submodule infix-if-vlan { - yang-version 1.1; - belongs-to infix-interfaces { - prefix infix-if; - } - - import ietf-interfaces { - prefix if; - } - - import infix-if-type { - prefix infixift; - } - import ieee802-dot1q-types { - prefix dot1q-types; - } - contact "kernelkit@googlegroups.com"; - description - "This module implements VLAN (8021q) encapsulation"; - - revision 2023-10-25 { - description "Initial revision"; - } - - augment "/if:interfaces/if:interface" { - when "derived-from-or-self(if:type, 'infixift:vlan')" { - description "Only shown for if:type vlan"; - } - description "Augment to add 802.1Q VLAN tag classifications"; - container vlan { - description "Configure 802.1q/802.1ad VLANs"; - leaf tag-type { - type dot1q-types:dot1q-tag-type; - default dot1q-types:c-vlan; - description "VLAN type"; - } - leaf id { - type dot1q-types:vlanid; - mandatory true; - description "VLAN Id"; - } - leaf lower-layer-if { - type if:interface-ref; - mandatory true; - description "Base interface for VLAN"; - } - } - } -} diff --git a/src/confd/yang/infix-if-vlan@2024-05-30.yang b/src/confd/yang/infix-if-vlan@2024-05-30.yang new file mode 100644 index 00000000..c4948f57 --- /dev/null +++ b/src/confd/yang/infix-if-vlan@2024-05-30.yang @@ -0,0 +1,101 @@ +submodule infix-if-vlan { + yang-version 1.1; + belongs-to infix-interfaces { + prefix infix-if; + } + + import ietf-interfaces { + prefix if; + } + + import infix-if-type { + prefix infixift; + } + import ieee802-dot1q-types { + prefix dot1q-types; + } + contact "kernelkit@googlegroups.com"; + description + "This module implements VLAN (8021q) encapsulation"; + + revision 2024-05-30 { + description "Added basic QoS policy + + Support for mapping the Priority Code Point (PCP) to + internal priority on ingress, and the reverse on + egress."; + } + + revision 2023-10-25 { + description "Initial revision"; + } + + augment "/if:interfaces/if:interface" { + when "derived-from-or-self(if:type, 'infixift:vlan')" { + description "Only shown for if:type vlan"; + } + description "Augment to add 802.1Q VLAN tag classifications"; + container vlan { + description "Configure 802.1q/802.1ad VLANs"; + leaf tag-type { + type dot1q-types:dot1q-tag-type; + default dot1q-types:c-vlan; + description "VLAN type"; + } + leaf id { + type dot1q-types:vlanid; + mandatory true; + description "VLAN Id"; + } + leaf lower-layer-if { + type if:interface-ref; + mandatory true; + description "Base interface for VLAN"; + } + container ingress-qos { + leaf priority { + description "Internal priority assignment + + The policy by which ingressing packets' + internal priority is determined. Supported + modes are to use a fixed value for all packets, + or to derive it from the packet's Priority Code + Point (PCP) field."; + + type union { + type uint8 { + range "0..7"; + } + type enumeration { + enum from-pcp { + description "Map PCP 1:1 to internal priority"; + } + } + } + default 0; + } + } + container egress-qos { + leaf pcp { + description "Priority Code Point (PCP) assignment + + The policy by which egressing packets' PCP + field is determined. Supported modes are to use + a fixed value for all packets, or to derive it + from the packet's internal priority."; + type union { + type uint8 { + range "0..7"; + } + type enumeration { + enum from-priority { + description "Map internal priority 1:1 to PCP"; + } + } + } + default 0; + } + } + } + } +}