[ovs-dev,v2,1/2] ovn: Ability to set multiple load balancers.
diff mbox

Message ID 1470995293-28467-1-git-send-email-guru@ovn.org
State Accepted
Headers show

Commit Message

Guru Shetty Aug. 12, 2016, 9:48 a.m. UTC
The schema prevented one from setting more than one load balancer
to a switch. This removes that anomaly.

(The test has a slightly unrelated change where it increases the
number of connections to get rid of some occasional unit test failures.)

Signed-off-by: Gurucharan Shetty <guru@ovn.org>
---
 ovn/northd/ovn-northd.c | 38 +++++++++++++++++++-------------------
 ovn/ovn-nb.ovsschema    |  6 +++---
 tests/system-ovn.at     | 23 ++++++++++++++++++++---
 3 files changed, 42 insertions(+), 25 deletions(-)

Comments

Ben Pfaff Aug. 15, 2016, 12:52 a.m. UTC | #1
On Fri, Aug 12, 2016 at 02:48:12AM -0700, Gurucharan Shetty wrote:
> The schema prevented one from setting more than one load balancer
> to a switch. This removes that anomaly.
> 
> (The test has a slightly unrelated change where it increases the
> number of connections to get rid of some occasional unit test failures.)
> 
> Signed-off-by: Gurucharan Shetty <guru@ovn.org>

Acked-by: Ben Pfaff <blp@ovn.org>

Patch
diff mbox

diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c
index 861f872..97d71ea 100644
--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -1938,11 +1938,11 @@  build_pre_lb(struct ovn_datapath *od, struct hmap *lflows)
     ovn_lflow_add(lflows, od, S_SWITCH_OUT_PRE_LB, 0, "1", "next;");
 
     struct sset all_ips = SSET_INITIALIZER(&all_ips);
-    if (od->nbs->load_balancer) {
-        struct nbrec_load_balancer *lb = od->nbs->load_balancer;
+    bool vip_configured = false;
+    for (int i = 0; i < od->nbs->n_load_balancer; i++) {
+        struct nbrec_load_balancer *lb = od->nbs->load_balancer[i];
         struct smap *vips = &lb->vips;
         struct smap_node *node;
-        bool vip_configured = false;
 
         SMAP_FOR_EACH (node, vips) {
             vip_configured = true;
@@ -1966,23 +1966,23 @@  build_pre_lb(struct ovn_datapath *od, struct hmap *lflows)
              * the packet through ct() action to de-fragment. In stateful
              * table, we will eventually look at L4 information. */
         }
+    }
 
-        /* 'REGBIT_CONNTRACK_DEFRAG' is set to let the pre-stateful table send
-         * packet to conntrack for defragmentation. */
-        const char *ip_address;
-        SSET_FOR_EACH(ip_address, &all_ips) {
-            char *match = xasprintf("ip && ip4.dst == %s", ip_address);
-            ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_LB,
-                          100, match, REGBIT_CONNTRACK_DEFRAG" = 1; next;");
-            free(match);
-        }
+    /* 'REGBIT_CONNTRACK_DEFRAG' is set to let the pre-stateful table send
+     * packet to conntrack for defragmentation. */
+    const char *ip_address;
+    SSET_FOR_EACH(ip_address, &all_ips) {
+        char *match = xasprintf("ip && ip4.dst == %s", ip_address);
+        ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_LB,
+                      100, match, REGBIT_CONNTRACK_DEFRAG" = 1; next;");
+        free(match);
+    }
 
-        sset_destroy(&all_ips);
+    sset_destroy(&all_ips);
 
-        if (vip_configured) {
-            ovn_lflow_add(lflows, od, S_SWITCH_OUT_PRE_LB,
-                          100, "ip", REGBIT_CONNTRACK_DEFRAG" = 1; next;");
-        }
+    if (vip_configured) {
+        ovn_lflow_add(lflows, od, S_SWITCH_OUT_PRE_LB,
+                      100, "ip", REGBIT_CONNTRACK_DEFRAG" = 1; next;");
     }
 }
 
@@ -2297,8 +2297,8 @@  build_stateful(struct ovn_datapath *od, struct hmap *lflows)
      * a higher priority rule for load balancing below also commits the
      * connection, so it is okay if we do not hit the above match on
      * REGBIT_CONNTRACK_COMMIT. */
-    if (od->nbs->load_balancer) {
-        struct nbrec_load_balancer *lb = od->nbs->load_balancer;
+    for (int i = 0; i < od->nbs->n_load_balancer; i++) {
+        struct nbrec_load_balancer *lb = od->nbs->load_balancer[i];
         struct smap *vips = &lb->vips;
         struct smap_node *node;
 
diff --git a/ovn/ovn-nb.ovsschema b/ovn/ovn-nb.ovsschema
index 660db76..6bf1291 100644
--- a/ovn/ovn-nb.ovsschema
+++ b/ovn/ovn-nb.ovsschema
@@ -1,7 +1,7 @@ 
 {
     "name": "OVN_Northbound",
-    "version": "5.3.0",
-    "cksum": "1305504870 9051",
+    "version": "5.3.1",
+    "cksum": "106203516 9061",
     "tables": {
         "NB_Global": {
             "columns": {
@@ -30,7 +30,7 @@ 
                                                   "refTable": "Load_Balancer",
                                                   "refType": "strong"},
                                            "min": 0,
-                                           "max": 1}},
+                                           "max": "unlimited"}},
                 "other_config": {
                     "type": {"key": "string", "value": "string",
                              "min": 0, "max": "unlimited"}},
diff --git a/tests/system-ovn.at b/tests/system-ovn.at
index b96b260..6ac5ece 100755
--- a/tests/system-ovn.at
+++ b/tests/system-ovn.at
@@ -347,6 +347,10 @@  ovn-nbctl lsp-add bar bar3 \
 uuid=`ovn-nbctl  create load_balancer vips:30.0.0.1="172.16.1.2,172.16.1.3,172.16.1.4"`
 ovn-nbctl set logical_switch foo load_balancer=$uuid
 
+# Create another load-balancer with another VIP.
+uuid=`ovn-nbctl create load_balancer vips:30.0.0.3="172.16.1.2,172.16.1.3,172.16.1.4"`
+ovn-nbctl add logical_switch foo load_balancer $uuid
+
 # Config OVN load-balancer with another VIP (this time with ports).
 ovn-nbctl set load_balancer $uuid vips:'"30.0.0.2:8000"'='"172.16.1.2:80,172.16.1.3:80,172.16.1.4:80"'
 
@@ -358,8 +362,8 @@  NETNS_DAEMONIZE([bar1], [[$PYTHON $srcdir/test-l7.py]], [http1.pid])
 NETNS_DAEMONIZE([bar2], [[$PYTHON $srcdir/test-l7.py]], [http2.pid])
 NETNS_DAEMONIZE([bar3], [[$PYTHON $srcdir/test-l7.py]], [http3.pid])
 
-dnl Should work with the virtual IP address through NAT
-for i in 1 2 3 4 5 6 7 8 9 10 11 12; do
+dnl Should work with the virtual IP 30.0.0.1 address through NAT
+for i in `seq 1 20`; do
     echo Request $i
     NS_CHECK_EXEC([foo1], [wget 30.0.0.1 -t 5 -T 1 --retry-connrefused -v -o wget$i.log])
 done
@@ -371,8 +375,21 @@  tcp,orig=(src=192.168.1.2,dst=30.0.0.1,sport=<cleared>,dport=<cleared>),reply=(s
 tcp,orig=(src=192.168.1.2,dst=30.0.0.1,sport=<cleared>,dport=<cleared>),reply=(src=172.16.1.4,dst=192.168.1.2,sport=<cleared>,dport=<cleared>),protoinfo=(state=<cleared>)
 ])
 
+dnl Should work with the virtual IP 30.0.0.3 address through NAT
+for i in `seq 1 20`; do
+    echo Request $i
+    NS_CHECK_EXEC([foo1], [wget 30.0.0.3 -t 5 -T 1 --retry-connrefused -v -o wget$i.log])
+done
+
+dnl Each server should have at least one connection.
+AT_CHECK([ovs-appctl dpctl/dump-conntrack | FORMAT_CT(30.0.0.3)], [0], [dnl
+tcp,orig=(src=192.168.1.2,dst=30.0.0.3,sport=<cleared>,dport=<cleared>),reply=(src=172.16.1.2,dst=192.168.1.2,sport=<cleared>,dport=<cleared>),protoinfo=(state=<cleared>)
+tcp,orig=(src=192.168.1.2,dst=30.0.0.3,sport=<cleared>,dport=<cleared>),reply=(src=172.16.1.3,dst=192.168.1.2,sport=<cleared>,dport=<cleared>),protoinfo=(state=<cleared>)
+tcp,orig=(src=192.168.1.2,dst=30.0.0.3,sport=<cleared>,dport=<cleared>),reply=(src=172.16.1.4,dst=192.168.1.2,sport=<cleared>,dport=<cleared>),protoinfo=(state=<cleared>)
+])
+
 dnl Test load-balancing that includes L4 ports in NAT.
-for i in 1 2 3 4 5 6 7 8 9 10 11 12; do
+for i in `seq 1 20`; do
     echo Request $i
     NS_CHECK_EXEC([foo1], [wget 30.0.0.2:8000 -t 5 -T 1 --retry-connrefused -v -o wget$i.log])
 done