Hello:

This patch  aims to enhance the functionality of the tunnel_port
by enabling the flow-based setting of TTL and TOS.
This improvement provides more flexibility in network traffic
management and allows for more granular control over tunneled
connections.In our specific application scenario, the dynamic
adjustment of TTL and TOS based on flows is of utmost importance.
There are various situations where such dynamic settings are
required. For example, in a multi-tenant cloud environment,
different tenants may have distinct SLAs. High-priority tenants
may demand lower latency and higher throughput for their
network traffic.

This is the second version of the patch.
- Fixed the build failure issue caused by typo: resolve the typo
of function call from ds_put_cstr to ds_put_char.

Signed-off-by: yanxia <yana06...@163.com>
---
 include/openvswitch/meta-flow.h |  5 +++--
 lib/meta-flow.xml               |  5 +++--
 lib/netdev-vport.c              |  9 +++++++++
 lib/netdev.h                    |  3 +++
 ofproto/tunnel.c                | 29 +++++++++++++++++++----------
 5 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/include/openvswitch/meta-flow.h b/include/openvswitch/meta-flow.h
index 875f122c5..5f48bfd12 100644
--- a/include/openvswitch/meta-flow.h
+++ b/include/openvswitch/meta-flow.h
@@ -401,7 +401,7 @@ enum OVS_PACKED_ENUM mf_field_id {
      * Maskable: no.
      * Formatting: decimal.
      * Prerequisites: none.
-     * Access: read-only.
+     * Access: read/write.
      * NXM: none.
      * OXM: none.
      */
@@ -416,7 +416,7 @@ enum OVS_PACKED_ENUM mf_field_id {
      * Maskable: no.
      * Formatting: decimal.
      * Prerequisites: none.
-     * Access: read-only.
+     * Access: read/write.
      * NXM: none.
      * OXM: none.
      */
@@ -2379,3 +2379,4 @@ void mf_set_mask_l3_prereqs(const struct mf_field *, 
const struct flow *,
 #endif
 
 #endif /* meta-flow.h */
+
diff --git a/lib/meta-flow.xml b/lib/meta-flow.xml
index 5c57ab08f..439e3f1d4 100644
--- a/lib/meta-flow.xml
+++ b/lib/meta-flow.xml
@@ -2061,8 +2061,8 @@ ovs-ofctl add-flow br0 
tun_metadata0=1234,actions=controller
     <!-- Open vSwitch uses the following fields internally, but it
          does not expose them to the user via OpenFlow, so we do not
          document them. -->
-    <field id="MFF_TUN_TTL" title="Tunnel IPv4 Time-to-Live" internal="yes"/>
-    <field id="MFF_TUN_TOS" title="Tunnel IPv4 Type of Service" 
internal="yes"/>
+    <field id="MFF_TUN_TTL" title="Tunnel IPv4 Time-to-Live"/>
+    <field id="MFF_TUN_TOS" title="Tunnel IPv4 Type of Service"/>
   </group>
 
   <group title="Metadata">
@@ -4878,3 +4878,4 @@ r c c c r.
     OXM fields not yet supported Future Directions References/See Also
     OXM fields required by various versions and by the "Conformance Test 
Specification for OpenFlow Switch Specification 1.0.1"
 -->
+
diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index ed67b509d..8c53c4e13 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -664,6 +664,8 @@ set_tunnel_config(struct netdev *dev_, const struct smap 
*args, char **errp)
         } else if (!strcmp(node->key, "tos")) {
             if (!strcmp(node->value, "inherit")) {
                 tnl_cfg.tos_inherit = true;
+            } else if (!strcmp(node->value, "flow")) {
+                tnl_cfg.tos_flow = true;
             } else {
                 char *endptr;
                 int tos;
@@ -678,6 +680,8 @@ set_tunnel_config(struct netdev *dev_, const struct smap 
*args, char **errp)
         } else if (!strcmp(node->key, "ttl")) {
             if (!strcmp(node->value, "inherit")) {
                 tnl_cfg.ttl_inherit = true;
+            } else if (!strcmp(node->value, "flow")) {
+                tnl_cfg.ttl_flow = true;
             } else {
                 tnl_cfg.ttl = atoi(node->value);
             }
@@ -998,12 +1002,16 @@ get_tunnel_config(const struct netdev *dev, struct smap 
*args)
 
     if (tnl_cfg->ttl_inherit) {
         smap_add(args, "ttl", "inherit");
+    } else if (tnl_cfg->ttl_flow) {
+        smap_add(args, "ttl", "flow");
     } else if (tnl_cfg->ttl != DEFAULT_TTL) {
         smap_add_format(args, "ttl", "%"PRIu8, tnl_cfg->ttl);
     }
 
     if (tnl_cfg->tos_inherit) {
         smap_add(args, "tos", "inherit");
+    } else if (tnl_cfg->tos_flow) {
+        smap_add(args, "tos", "flow");
     } else if (tnl_cfg->tos) {
         smap_add_format(args, "tos", "0x%x", tnl_cfg->tos);
     }
@@ -1391,3 +1399,4 @@ netdev_vport_patch_register(void)
     simap_init(&patch_class.global_cfg_tracker);
     netdev_register_provider(&patch_class.netdev_class);
 }
+
diff --git a/lib/netdev.h b/lib/netdev.h
index 63e03d72d..4bf9a03f3 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -151,9 +151,11 @@ struct netdev_tunnel_config {
 
     uint8_t ttl;
     bool ttl_inherit;
+    bool ttl_flow;
 
     uint8_t tos;
     bool tos_inherit;
+    bool tos_flow;
 
     enum netdev_tnl_csum csum;
     bool dont_fragment;
@@ -396,3 +398,4 @@ int netdev_get_addrs(const char dev[], struct in6_addr 
**paddr,
 #endif
 
 #endif /* netdev.h */
+
diff --git a/ofproto/tunnel.c b/ofproto/tunnel.c
index f067a6c26..e0e0a8280 100644
--- a/ofproto/tunnel.c
+++ b/ofproto/tunnel.c
@@ -438,18 +438,22 @@ tnl_port_send(const struct ofport_dpif *ofport, struct 
flow *flow,
         flow->tunnel.tun_id = cfg->out_key;
     }
 
-    if (cfg->ttl_inherit && is_ip_any(flow)) {
-        wc->masks.nw_ttl = 0xff;
-        flow->tunnel.ip_ttl = flow->nw_ttl;
-    } else {
-        flow->tunnel.ip_ttl = cfg->ttl;
+    if (!cfg->ttl_flow) {
+        if (cfg->ttl_inherit && is_ip_any(flow)) {
+            wc->masks.nw_ttl = 0xff;
+            flow->tunnel.ip_ttl = flow->nw_ttl;
+        } else {
+            flow->tunnel.ip_ttl = cfg->ttl;
+        }
     }
 
-    if (cfg->tos_inherit && is_ip_any(flow)) {
-        wc->masks.nw_tos |= IP_DSCP_MASK;
-        flow->tunnel.ip_tos = flow->nw_tos & IP_DSCP_MASK;
-    } else {
-        flow->tunnel.ip_tos = cfg->tos;
+    if (!cfg->tos_flow) {
+        if (cfg->tos_inherit && is_ip_any(flow)) {
+            wc->masks.nw_tos |= IP_DSCP_MASK;
+            flow->tunnel.ip_tos = flow->nw_tos & IP_DSCP_MASK;
+        } else {
+            flow->tunnel.ip_tos = cfg->tos;
+        }
     }
 
     /* ECN fields are always inherited. */
@@ -696,12 +700,16 @@ tnl_port_format(const struct tnl_port *tnl_port, struct 
ds *ds)
 
     if (cfg->ttl_inherit) {
         ds_put_cstr(ds, ", ttl=inherit");
+    } else if (cfg->ttl_flow) {
+        ds_put_cstr(ds, ", ttl=flow");
     } else {
         ds_put_format(ds, ", ttl=%"PRIu8, cfg->ttl);
     }
 
     if (cfg->tos_inherit) {
         ds_put_cstr(ds, ", tos=inherit");
+    } else if (cfg->tos_flow) {
+        ds_put_cstr(ds, ", tos=flow");
     } else if (cfg->tos) {
         ds_put_format(ds, ", tos=%#"PRIx8, cfg->tos);
     }
@@ -782,3 +790,4 @@ tnl_unixctl_list(struct unixctl_conn *conn,
     unixctl_command_reply(conn, ds_cstr(&reply));
     ds_destroy(&reply);
 }
+
-- 
2.33.0

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to