diff mbox series

[ovs-dev,2/2] ovn-controller: Add MAC_Binding aging test

Message ID 20180315092012.5956-2-ligs@dtdream.com
State Changes Requested
Headers show
Series [ovs-dev,1/2] ovn-controller: support MAC_Binding aging | expand

Commit Message

Guoshuai Li March 15, 2018, 9:20 a.m. UTC
Add a test case:
The MAC_Binding ages when an ARP packet is not received.
And it does not age when it receives an arp packet.
20 minutes is too long for testing,
so add commands to set the MAC_Binding aging time.

Signed-off-by: Guoshuai Li <ligs@dtdream.com>
---
 ovn/controller/pinctrl.c | 44 ++++++++++++++++++++++++++++++
 tests/ovn.at             | 70 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+)
diff mbox series

Patch

diff --git a/ovn/controller/pinctrl.c b/ovn/controller/pinctrl.c
index b258a7f29..2ccf105d6 100644
--- a/ovn/controller/pinctrl.c
+++ b/ovn/controller/pinctrl.c
@@ -51,6 +51,7 @@ 
 #include "timeval.h"
 #include "vswitch-idl.h"
 #include "lflow.h"
+#include "unixctl.h"
 
 VLOG_DEFINE_THIS_MODULE(pinctrl);
 
@@ -81,6 +82,14 @@  static void init_aging_mac_binding(uint32_t,
                                    uint32_t,
                                    const char *,
                                    uint32_t);
+static void aging_mac_binding_cache_list(struct unixctl_conn *conn,
+                                         int argc OVS_UNUSED,
+                                         const char *argv[] OVS_UNUSED,
+                                         void *arg OVS_UNUSED);
+static void set_aging_mac_binding_time(struct unixctl_conn *conn,
+                                       int argc OVS_UNUSED,
+                                       const char *argv[],
+                                       void *arg OVS_UNUSED);
 
 static void init_send_garps(void);
 static void destroy_send_garps(void);
@@ -120,6 +129,10 @@  pinctrl_init(void)
     init_aging_mac_bindings();
     init_send_garps();
     init_ipv6_ras();
+    unixctl_command_register("mac-binding-cache-list", "", 0, 0,
+                             aging_mac_binding_cache_list, NULL);
+    unixctl_command_register("set-mac-binding-aging-time", "MSECS", 1, 1,
+                             set_aging_mac_binding_time, NULL);
 }
 
 static ovs_be32
@@ -2009,6 +2022,37 @@  aging_mac_bindings_run(const struct controller_ctx *ctx,
 
     simap_destroy(&localnet_ofports);
 }
+
+static void
+aging_mac_binding_cache_list(struct unixctl_conn *conn, int argc OVS_UNUSED,
+                             const char *argv[] OVS_UNUSED,
+                             void *arg OVS_UNUSED)
+{
+    struct ds ds = DS_EMPTY_INITIALIZER;
+
+    ds_put_format(&ds, "aging mac binding time is %lld s.\n",
+                  base_reachable_time / 1000);
+    const struct aging_mac_binding *pmb;
+    HMAP_FOR_EACH (pmb, hmap_node, &aging_mac_bindings) {
+        long long int age = (time_msec() - pmb->timestamp) / 1000;
+        ds_put_format(&ds, "dp:%d port:%d ip:%s age:%lld s send arp"
+                      " count:%d\n.",
+                      pmb->dp_key, pmb->port_key,
+                      pmb->ip_s, age, pmb->arp_send_count);
+    }
+
+    unixctl_command_reply(conn, ds_cstr(&ds));
+    ds_destroy(&ds);
+}
+
+static void
+set_aging_mac_binding_time(struct unixctl_conn *conn,
+                           int argc OVS_UNUSED,
+                           const char *argv[], void *arg OVS_UNUSED)
+{
+    base_reachable_time = atoll(argv[1]);
+    unixctl_command_reply(conn, "OK.");
+}
 
 /*
  * Send gratuitous ARP for vif on localnet.
diff --git a/tests/ovn.at b/tests/ovn.at
index 5f985f345..60896ea68 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -9428,3 +9428,73 @@  done
 
 OVN_CLEANUP([hv1], [hv2], [hv3])
 AT_CLEANUP
+
+AT_SETUP([ovn -- MAC_Binding aging])
+ovn_start
+
+net_add n1
+
+sim_add hv1
+as hv1
+ovs-vsctl add-br br-phys
+ovn_attach n1 br-phys 192.168.0.1
+ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-phys
+
+ovn-nbctl lr-add lr0
+ovn-nbctl ls-add ls0
+
+# Create logical router port lrp0 and peer lsp0
+ovn-nbctl lrp-add lr0 lrp0 f0:00:00:00:00:02 192.168.0.2/24 \
+    -- set Logical_Router_Port lrp0 options:redirect-chassis="hv1"
+ovn-nbctl lsp-add ls0 lsp0 \
+    -- lsp-set-addresses lsp0 router \
+    -- lsp-set-type lsp0 router \
+    -- lsp-set-options lsp0 router-port=lrp0 nat-addresses=router
+
+# Create localnet port in ls0
+ovn-nbctl lsp-add ls0 ln0 \
+    -- lsp-set-addresses ln0 unknown \
+    -- lsp-set-type ln0 localnet \
+    -- lsp-set-options ln0 network_name=physnet1
+
+ovs-appctl -t ovn-controller set-mac-binding-aging-time 4000
+
+# Create Mac_Binding in lrp0
+dp_uuid=`ovn-sbctl find datapath external_ids:name=lr0 | grep uuid | cut -f2 -d ":" | cut -f2 -d " "`
+ovn-sbctl create MAC_Binding ip=192.168.0.3 datapath=$dp_uuid logical_port=lrp0 mac="f0\:00\:00\:00\:00\:03"
+
+AT_CHECK([ovn-sbctl find MAC_Binding | grep 192.168.0.3 | wc -l ], [0], [1
+])
+
+# Wait for mac_binding aging.
+OVS_WAIT_UNTIL([grep -c "MAC_Binding aging" hv1/ovn-controller.log])
+
+$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/br-phys-tx.pcap > packets
+echo "fffffffffffff0000000000208060001080006040001f00000000002c0a80002000000000000c0a80003" > expout
+echo "fffffffffffff0000000000208060001080006040001f00000000002c0a80002000000000000c0a80003" >> expout
+echo "fffffffffffff0000000000208060001080006040001f00000000002c0a80002000000000000c0a80003" >> expout
+AT_CHECK([cat packets], [0], [expout])
+
+# Check the mac binding is aged.
+AT_CHECK([ovn-sbctl find MAC_Binding | grep 192.168.0.3 | wc -l ], [0], [0
+])
+
+# Create Mac_Binding(192.168.0.1) in lrp0
+ovn-sbctl create MAC_Binding ip=192.168.0.1 datapath=$dp_uuid logical_port=lrp0 mac="f0\:00\:00\:00\:00\:01"
+
+AT_CHECK([ovn-sbctl find MAC_Binding | grep 192.168.0.1 | wc -l ], [0], [1
+])
+
+mac=`ovs-vsctl get Interface br-phys mac_in_use | sed s/\"//g | sed s/\://g`
+
+# Wait for packet to be received.
+package=f00000000002${mac}08060001080006040002${mac}c0a80001f00000000002c0a80002
+echo $package > expected
+OVN_CHECK_PACKETS([hv1/br-phys-rx.pcap], [expected])
+
+# Check the mac binding is not aged.
+AT_CHECK([ovn-sbctl find MAC_Binding | grep 192.168.0.1 | wc -l ], [0], [1
+])
+
+OVN_CLEANUP([hv1])
+AT_CLEANUP
\ No newline at end of file