[ovs-dev] [PATCH RFC] ovn: Add support for DSCP marking

bschanmu at redhat.com bschanmu at redhat.com
Fri Apr 15 11:00:41 UTC 2016


From: Babu Shanmugam <bschanmu at redhat.com>

Added an additional option 'dscp_code' for VMI Logica_Ports in addition to the
ingress_policing_rate and burst in the OVN Northbound database.

Also in the controller, replaced the earlier approach of setting the rate and
burst parameters in the Interface table with Port tables's qos parameter
(using the default queue). In this patch, 'linux-htb' is used as a
fixed Qos type.

Signed-off-by: Babu Shanmugam <bschanmu at redhat.com>
---
 ovn/controller/binding.c | 67 ++++++++++++++++++++++++++++++++++++++++--------
 ovn/ovn-nb.xml           |  5 ++++
 2 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c
index 32fcb85..53e2677 100644
--- a/ovn/controller/binding.c
+++ b/ovn/controller/binding.c
@@ -40,13 +40,18 @@ binding_register_ovs_idl(struct ovsdb_idl *ovs_idl)
     ovsdb_idl_add_table(ovs_idl, &ovsrec_table_port);
     ovsdb_idl_add_column(ovs_idl, &ovsrec_port_col_name);
     ovsdb_idl_add_column(ovs_idl, &ovsrec_port_col_interfaces);
+    ovsdb_idl_add_column(ovs_idl, &ovsrec_port_col_qos);
 
     ovsdb_idl_add_table(ovs_idl, &ovsrec_table_interface);
     ovsdb_idl_add_column(ovs_idl, &ovsrec_interface_col_name);
     ovsdb_idl_add_column(ovs_idl, &ovsrec_interface_col_external_ids);
-    ovsdb_idl_add_column(ovs_idl, &ovsrec_interface_col_ingress_policing_rate);
-    ovsdb_idl_add_column(ovs_idl,
-                         &ovsrec_interface_col_ingress_policing_burst);
+
+    ovsdb_idl_add_table(ovs_idl, &ovsrec_table_qos);
+    ovsdb_idl_add_column(ovs_idl, &ovsrec_qos_col_queues);
+
+    ovsdb_idl_add_table(ovs_idl, &ovsrec_table_queue);
+    ovsdb_idl_add_column(ovs_idl, &ovsrec_queue_col_other_config);
+    ovsdb_idl_add_column(ovs_idl, &ovsrec_queue_col_dscp);
 }
 
 static void
@@ -71,7 +76,7 @@ get_local_iface_ids(const struct ovsrec_bridge *br_int, struct shash *lports)
             if (!iface_id) {
                 continue;
             }
-            shash_add(lports, iface_id, iface_rec);
+            shash_add(lports, iface_id, port_rec);
         }
     }
 }
@@ -136,14 +141,54 @@ add_local_datapath(struct hmap *local_datapaths,
 }
 
 static void
-update_qos(const struct ovsrec_interface *iface_rec,
+update_qos(struct ovsdb_idl_txn *txn,
+           const struct ovsrec_port *port_rec,
            const struct sbrec_port_binding *pb)
 {
     int rate = smap_get_int(&pb->options, "policing_rate", 0);
     int burst = smap_get_int(&pb->options, "policing_burst", 0);
+    int64_t dscp = smap_get_int(&pb->options, "dscp_code", -1);
+    struct smap other_config = SMAP_INITIALIZER(&other_config);
+    struct ovsrec_queue *default_queue;
+    bool is_empty_config;
+
+    if (rate)
+        smap_add_format(&other_config, "max-rate", "%d", rate);
+    if (burst)
+        smap_add_format(&other_config, "burst", "%d", burst);
+
+    is_empty_config = smap_is_empty(&other_config) && dscp < 0;
+    if (port_rec->qos) {
+        if (is_empty_config) {
+            struct ovsrec_qos *qos = port_rec->qos;
+            struct ovsrec_queue *queue = qos->value_queues[0];
+            ovsrec_port_set_qos(port_rec, NULL);
+            ovsrec_qos_delete(qos);
+            ovsrec_queue_delete(queue);
+            return;
+        } else {
+            default_queue = port_rec->qos->value_queues[0];
+        }
+    } else {
+        if (is_empty_config) {
+            return;
+        } else {
+            int64_t key = 0;
+            struct ovsrec_qos *qos = ovsrec_qos_insert(txn);
+
+            ovsrec_port_set_qos(port_rec, qos);
+            default_queue = ovsrec_queue_insert(txn);
+            ovsrec_qos_set_type(qos, "linux-htb");
+            ovsrec_qos_set_queues(qos, &key, &default_queue, 1);
+        }
+    }
+    ovsrec_queue_set_other_config(default_queue, &other_config);
+    if (dscp >= 0)
+        ovsrec_queue_set_dscp(default_queue, &dscp, 1);
+    else
+        ovsrec_queue_set_dscp(default_queue, NULL, 0);
 
-    ovsrec_interface_set_ingress_policing_rate(iface_rec, MAX(0, rate));
-    ovsrec_interface_set_ingress_policing_burst(iface_rec, MAX(0, burst));
+    smap_destroy(&other_config);
 }
 
 void
@@ -177,9 +222,9 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
      * chassis and update the binding accordingly.  This includes both
      * directly connected logical ports and children of those ports. */
     SBREC_PORT_BINDING_FOR_EACH(binding_rec, ctx->ovnsb_idl) {
-        const struct ovsrec_interface *iface_rec
+        const struct ovsrec_port *port_rec
             = shash_find_and_delete(&lports, binding_rec->logical_port);
-        if (iface_rec
+        if (port_rec
             || (binding_rec->parent_port && binding_rec->parent_port[0] &&
                 sset_contains(&all_lports, binding_rec->parent_port))) {
             if (binding_rec->parent_port && binding_rec->parent_port[0]) {
@@ -187,8 +232,8 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
                 sset_add(&all_lports, binding_rec->logical_port);
             }
             add_local_datapath(local_datapaths, binding_rec);
-            if (iface_rec && ctx->ovs_idl_txn) {
-                update_qos(iface_rec, binding_rec);
+            if (port_rec && ctx->ovs_idl_txn) {
+                update_qos(ctx->ovs_idl_txn, port_rec, binding_rec);
             }
             if (binding_rec->chassis == chassis_rec) {
                 continue;
diff --git a/ovn/ovn-nb.xml b/ovn/ovn-nb.xml
index e65bc3a..65ac7ed 100644
--- a/ovn/ovn-nb.xml
+++ b/ovn/ovn-nb.xml
@@ -211,6 +211,11 @@
           If set, indicates the maximum burst size for data sent from this
           interface, in kb.
         </column>
+
+        <column name="options" key="dscp_code">
+          If set, indicates the DSCP marking to be be done on packets sent
+          from this interface.
+        </column>
       </group>
     </group>
 
-- 
2.5.0




More information about the dev mailing list