From patchwork Wed May 10 11:15:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nickcooper-zhangtonghao X-Patchwork-Id: 760547 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3wNDHZ6R6Jz9rxl for ; Wed, 10 May 2017 21:18:02 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 96E4BB6B; Wed, 10 May 2017 11:15:40 +0000 (UTC) X-Original-To: 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 1E8DDB37 for ; Wed, 10 May 2017 11:15:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 4414E154 for ; Wed, 10 May 2017 11:15:36 +0000 (UTC) X-QQ-mid: bizesmtp13t1494414931tiopplre Received: from local.opencloud.tech.localdomai (unknown [106.120.127.10]) by esmtp4.qq.com (ESMTP) with id ; Wed, 10 May 2017 19:15:30 +0800 (CST) X-QQ-SSF: 01100000008000F0FG80B00A0000000 X-QQ-FEAT: NCurqkplqhML/mKgAAMnXKXej2VKW7yo/MOXXxFUPMd7ZifsOV+Mtyg6zdHXF 8ypOq33PTEc/YclTORozD5mqPus9JnRW1zTYUYHj8cHMzJD/9uI1fB+Z8NgZf6DpRG2WVPJ DlamT7JRulYwVGLRtf67y1Tj+WpE69ga55QxC6dlORtYsMr3Sh/vV1nqyIBk0xRgiUZZVbH IrctdzyYII0TdKT5fljkqDYawANMH8dfrs5CxbPD5iYXaU2GbOKuF+AnWDUIbt40z8SWJwE NSp5cj6GJhfgeM X-QQ-GoodBg: 0 From: nickcooper-zhangtonghao To: dev@openvswitch.org Date: Wed, 10 May 2017 04:15:06 -0700 Message-Id: <1494414906-71269-5-git-send-email-nic@opencloud.tech> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1494414906-71269-1-git-send-email-nic@opencloud.tech> References: <1494414906-71269-1-git-send-email-nic@opencloud.tech> X-QQ-SENDSIZE: 520 X-QQ-Bgrelay: 1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 v2 5/5] stp: Add link-state checking support for stp ports. 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 When bridge stp enabled, we can enable the stp ports despite ports are down. When initializing, this patch checks link-state of ports and enable or disable them according to their link-state. This patch also allow user to enable and disable a port when bridge stp is running. If a stp port is in disable state, it can forward packets. If its link is down and this patch sets it to disable, there is no L2 loop. Signed-off-by: nickcooper-zhangtonghao --- ofproto/ofproto-dpif.c | 41 ++++++++++++++++++++++++++++- tests/stp.at | 71 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 6d3f1fb..098d363 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -2574,6 +2574,37 @@ update_stp_port_state(struct ofport_dpif *ofport) } } +static void +stp_check_and_update_link_state(struct ofproto_dpif *ofproto) +{ + struct ofport *ofport_; + struct ofport_dpif *ofport; + bool up; + + HMAP_FOR_EACH (ofport_, hmap_node, &ofproto->up.ports) { + ofport = ofport_dpif_cast(ofport_); + up = netdev_get_carrier(ofport_->netdev); + + if (ofport->stp_port && + up != (stp_port_get_state(ofport->stp_port) != STP_DISABLED)) { + + VLOG_DBG("bridge: %s, port: %s is %s, %s it", ofproto->up.name, + netdev_get_name(ofport->up.netdev), + up ? "up" : "down", + up ? "enabling" : "disabling"); + + if (up) { + stp_port_enable(ofport->stp_port); + stp_port_set_aux(ofport->stp_port, ofport); + } else { + stp_port_disable(ofport->stp_port); + } + + update_stp_port_state(ofport); + } + } +} + /* Configures STP on 'ofport_' using the settings defined in 's'. The * caller is responsible for assigning STP port numbers and ensuring * there are no duplicates. */ @@ -2604,7 +2635,12 @@ set_stp_port(struct ofport *ofport_, /* Set name before enabling the port so that debugging messages can print * the name. */ stp_port_set_name(sp, netdev_get_name(ofport->up.netdev)); - stp_port_enable(sp); + + if (netdev_get_carrier(ofport_->netdev)) { + stp_port_enable(sp); + } else { + stp_port_disable(sp); + } stp_port_set_aux(sp, ofport); stp_port_set_priority(sp, s->priority); @@ -2666,6 +2702,9 @@ stp_run(struct ofproto_dpif *ofproto) stp_tick(ofproto->stp, MIN(INT_MAX, elapsed)); ofproto->stp_last_tick = now; } + + stp_check_and_update_link_state(ofproto); + while (stp_get_changed_port(ofproto->stp, &sp)) { struct ofport_dpif *ofport = stp_port_get_aux(sp); diff --git a/tests/stp.at b/tests/stp.at index bd5d208..e27600e 100644 --- a/tests/stp.at +++ b/tests/stp.at @@ -420,6 +420,7 @@ AT_CHECK([ovs-vsctl add-port br1 p8 -- \ set port p8 other_config:stp-enable=false -- \ ]) +ovs-appctl netdev-dummy/set-admin-state up ovs-appctl time/stop AT_CHECK([ovs-ofctl add-flow br0 "in_port=7 icmp actions=1"]) @@ -519,7 +520,7 @@ AT_CHECK([ set interface p6 type=dummy options:pstream=punix:$OVS_RUNDIR/p6.sock ofport_request=6 ], [0]) - +ovs-appctl netdev-dummy/set-admin-state up ovs-appctl time/stop # give time for STP to move initially @@ -626,5 +627,73 @@ AT_CHECK([ovs-appctl mdb/show br2], [0], [dnl port VLAN GROUP Age ]) +AT_CLEANUP + +AT_SETUP([STP - check link-state when stp is running]) +OVS_VSWITCHD_START([]) + +AT_CHECK([ + ovs-vsctl -- \ + set port br0 other_config:stp-enable=false -- \ + set bridge br0 datapath-type=dummy stp_enable=true \ + other-config:hwaddr=aa:66:aa:66:00:00 +], [0]) + +AT_CHECK([ + ovs-vsctl add-port br0 p1 -- \ + set interface p1 type=dummy -- \ + set port p1 other_config:stp-port-num=1 + ovs-vsctl add-port br0 p2 -- \ + set interface p2 type=dummy -- \ + set port p2 other_config:stp-port-num=2 +], [0]) + +ovs-appctl netdev-dummy/set-admin-state up +ovs-appctl time/stop + +# give time for STP to move initially +for i in $(seq 0 30); do + ovs-appctl time/warp 1000 +done + +AT_CHECK([ovs-appctl stp/show br0 | grep p1], [0], [dnl + p1 designated forwarding 19 128.1 +]) +AT_CHECK([ovs-appctl stp/show br0 | grep p2], [0], [dnl + p2 designated forwarding 19 128.2 +]) + +# add a stp port +AT_CHECK([ + ovs-vsctl add-port br0 p3 -- \ + set interface p3 type=dummy -- \ + set port p3 other_config:stp-port-num=3 +], [0]) + +ovs-appctl netdev-dummy/set-admin-state p3 down + +# We should not show the p3 because its link-state is down +AT_CHECK([ovs-appctl stp/show br0 | grep p1], [0], [dnl + p1 designated forwarding 19 128.1 +]) +AT_CHECK([ovs-appctl stp/show br0 | grep p2], [0], [dnl + p2 designated forwarding 19 128.2 +]) +AT_CHECK([ovs-appctl stp/show br0 | grep p3], [1], [dnl +]) + +ovs-appctl netdev-dummy/set-admin-state p3 up + +AT_CHECK([ovs-appctl stp/show br0 | grep p1], [0], [dnl + p1 designated forwarding 19 128.1 +]) +AT_CHECK([ovs-appctl stp/show br0 | grep p2], [0], [dnl + p2 designated forwarding 19 128.2 +]) +AT_CHECK([ovs-appctl stp/show br0 | grep p3], [0], [dnl + p3 designated listening 19 128.3 +]) + + OVS_VSWITCHD_STOP AT_CLEANUP