From patchwork Thu Mar 15 09:20:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoshuai Li X-Patchwork-Id: 886170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=dtdream.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40233P1zTDz9sVc for ; Thu, 15 Mar 2018 20:20:33 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 437C1F70; Thu, 15 Mar 2018 09:20:31 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 1B3DCEBD for ; Thu, 15 Mar 2018 09:20:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2203-239.mail.aliyun.com (smtp2203-239.mail.aliyun.com [121.197.203.239]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B2CF95D4 for ; Thu, 15 Mar 2018 09:20:27 +0000 (UTC) X-Alimail-AntiSpam: AC=CONTINUE; BC=0.074442|-1; CH=green; FP=0|0|0|0|0|-1|-1|-1; HT=e01e01454; MF=ligs@dtdream.com; NM=1; PH=DS; RN=2; RT=2; SR=0; TI=SMTPD_---.BJR-3cL_1521105622; Received: from localhost.localdomain(mailfrom:ligs@dtdream.com fp:222.128.6.212) by smtp.aliyun-inc.com(10.147.40.7); Thu, 15 Mar 2018 17:20:24 +0800 From: Guoshuai Li To: ovs-dev@openvswitch.org Date: Thu, 15 Mar 2018 17:20:12 +0800 Message-Id: <20180315092012.5956-2-ligs@dtdream.com> X-Mailer: git-send-email 2.13.2.windows.1 In-Reply-To: <20180315092012.5956-1-ligs@dtdream.com> References: <20180315092012.5956-1-ligs@dtdream.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 2/2] ovn-controller: Add MAC_Binding aging test X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 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 --- ovn/controller/pinctrl.c | 44 ++++++++++++++++++++++++++++++ tests/ovn.at | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) 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