This commit adds a new configuration option "demand_rx_bfd" for bfd which is equivalent to the 'demand_rx_ccm' of cfm and is to be used in forwarding_if_rx mode.
Signed-off-by: Alex Wang <al...@nicira.com> --- lib/bfd.c | 43 ++++++++++++++++++++----- tests/bfd.at | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ vswitchd/vswitch.xml | 23 ++++++++++++++ 3 files changed, 143 insertions(+), 8 deletions(-) diff --git a/lib/bfd.c b/lib/bfd.c index e3e3ae5..4966506 100644 --- a/lib/bfd.c +++ b/lib/bfd.c @@ -203,6 +203,14 @@ struct bfd { bool forwarding_if_rx; long long int forwarding_if_rx_detect_time; + /* When 'bfd->forwarding_if_rx' is set, users can specify the + * 'demand_rx_bfd' interval. If bfd control packet is not received + * within this interval, even if data packets are received, the + * bfd->forwarding will be false. The configured value should be at + * least 20 * bfd->cfg_min_rx. */ + int demand_rx_bfd; + long long int demand_rx_bfd_time; + /* BFD decay related variables. */ bool in_decay; /* True when bfd is in decay. */ int decay_min_rx; /* min_rx is set to decay_min_rx when */ @@ -331,7 +339,7 @@ bfd_configure(struct bfd *bfd, const char *name, const struct smap *cfg, static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; static atomic_uint16_t udp_src = ATOMIC_VAR_INIT(0); - int decay_min_rx; + int decay_min_rx, demand_rx_bfd; long long int min_tx, min_rx; bool need_poll = false; bool cfg_min_rx_changed = false; @@ -464,6 +472,17 @@ bfd_configure(struct bfd *bfd, const char *name, const struct smap *cfg, } } + demand_rx_bfd = smap_get_int(cfg, "demand_rx_bfd", 0); + if (bfd->forwarding_if_rx) { + bfd->demand_rx_bfd = demand_rx_bfd ? MAX(demand_rx_bfd, + 20 * bfd->cfg_min_rx) : 0; + if (bfd->last_forwarding && bfd->demand_rx_bfd) { + bfd->demand_rx_bfd_time = time_msec() + bfd->demand_rx_bfd; + } else { + bfd->demand_rx_bfd_time = LLONG_MIN; + } + } + if (need_poll) { bfd_poll(bfd); } @@ -841,6 +860,10 @@ bfd_process_packet(struct bfd *bfd, const struct flow *flow, } /* XXX: RFC 5880 Section 6.8.6 Demand mode related calculations here. */ + if (bfd->forwarding_if_rx && bfd->demand_rx_bfd) { + bfd->demand_rx_bfd_time = time_msec() + bfd->demand_rx_bfd; + } + out: bfd_forwarding__(bfd); ovs_mutex_unlock(&mutex); @@ -876,19 +899,23 @@ bfd_set_netdev(struct bfd *bfd, const struct netdev *netdev) static bool bfd_forwarding__(struct bfd *bfd) OVS_REQUIRES(mutex) { - long long int time; + long long int now = time_msec(); + bool forwarding_if_rx; bool last_forwarding = bfd->last_forwarding; if (bfd->forwarding_override != -1) { return bfd->forwarding_override == 1; } - time = bfd->forwarding_if_rx_detect_time; - bfd->last_forwarding = (bfd->state == STATE_UP - || (bfd->forwarding_if_rx && time > time_msec())) - && bfd->rmt_diag != DIAG_PATH_DOWN - && bfd->rmt_diag != DIAG_CPATH_DOWN - && bfd->rmt_diag != DIAG_RCPATH_DOWN; + forwarding_if_rx = bfd->forwarding_if_rx + && bfd->forwarding_if_rx_detect_time > now + && (!bfd->demand_rx_bfd + || bfd->demand_rx_bfd_time > now); + + bfd->last_forwarding = (bfd->state == STATE_UP || forwarding_if_rx) + && bfd->rmt_diag != DIAG_PATH_DOWN + && bfd->rmt_diag != DIAG_CPATH_DOWN + && bfd->rmt_diag != DIAG_RCPATH_DOWN; if (bfd->last_forwarding != last_forwarding) { bfd->flap_count++; bfd_status_changed(bfd); diff --git a/tests/bfd.at b/tests/bfd.at index 3723d60..0065397 100644 --- a/tests/bfd.at +++ b/tests/bfd.at @@ -605,6 +605,91 @@ BFD_CHECK_RX([p0], [1000ms], [1000ms], [300ms]) AT_CHECK([ovs-vsctl del-br br1], [0], [ignore]) AT_CLEANUP +# forwarding_if_rx Test4 +# Test4 is for testing the demand_rx_bfd feature. +# bfd is enabled on both ends of the link. +AT_SETUP([bfd - bfd forwarding_if_rx - demand_rx_bfd]) +OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \ + add-port br1 p1 -- set Interface p1 type=patch \ + options:peer=p0 ofport_request=2 -- \ + add-port br0 p0 -- set Interface p0 type=patch \ + options:peer=p1 ofport_request=1 -- \ + set Interface p0 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300 -- \ + set Interface p1 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500]) + +ovs-appctl time/stop +# advance the clock, to stablize the states. +for i in `seq 0 19`; do ovs-appctl time/warp 500; done +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) + +# enable forwarding_if_rx. +AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true], [0]) +# disable the bfd on p1. +AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false], [0]) + +# advance clock by 4000ms, while receiving packets. +# the STATE should go DOWN, due to Control Detection Time Expired. +# but forwarding flag should be still true. +for i in `seq 0 7` +do + ovs-appctl time/warp 500 + AT_CHECK([ovs-ofctl packet-out br1 3 2 "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"], + [0], [stdout], []) +done +BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic]) + +# now set the demand_rx_bfd to a 6000 (20 * bfd->cfg_min_rx) of p0. +AT_CHECK([ovs-vsctl set Interface p0 bfd:demand_rx_bfd=6000]) +# advance clock by 8000ms, while receiving packets. +# forwarding flag should go down since there is no bfd control packet +# received during the demand_rx_bfd. +for i in `seq 0 15` +do + ovs-appctl time/warp 500 + AT_CHECK([ovs-ofctl packet-out br1 3 2 "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"], + [0], [stdout], []) +done +BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic]) + +# now enable the bfd on p1 again. +AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true], [0]) +# advance clock by 5000ms. and p1 and p0 should be all up. +for i in `seq 0 9`; do ovs-appctl time/warp 500; done +BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [Control Detection Time Expired]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) + +# disable the bfd on p1 again. +AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false], [0]) +# advance clock by 8000ms, while receiving packets. +# forwarding flag should go down since there is no bfd control packet +# received during the demand_rx_bfd. +for i in `seq 0 15` +do + ovs-appctl time/warp 500 + AT_CHECK([ovs-ofctl packet-out br1 3 2 "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"], + [0], [stdout], []) +done +BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic]) + +# now reset the demand_rx_bfd. +AT_CHECK([ovs-vsctl remove Interface p0 bfd demand_rx_bfd=6000]) +# advance clock by 4000ms, while receiving packets. +# the STATE should go DOWN, due to Control Detection Time Expired. +# but forwarding flag should be still true. +for i in `seq 0 7` +do + ovs-appctl time/warp 500 + AT_CHECK([ovs-ofctl packet-out br1 3 2 "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"], + [0], [stdout], []) +done +BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic]) + +AT_CHECK([ovs-vsctl del-br br1], [0], [ignore]) +AT_CLEANUP + # test bfd:flap_count. # This test contains three part: # part 1. tests the flap_count on normal bfd monitored link. diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml index 78ccd24..d20eceb 100644 --- a/vswitchd/vswitch.xml +++ b/vswitchd/vswitch.xml @@ -1974,6 +1974,29 @@ to be lost from marking the interface down. </column> + <column name="bfd" key="demand_rx_bfd" type='{"type": "integer"}'> + <p> + A time interval in milliseconds. When set, must be greater than + twenty time of <ref column="bfd" key="min_rx"/>. + </p> + + <p> + When configured and <ref column="bfd" key="forwarding_if_rx"/> + is true, the BFD session is required to receive at least one BFD + control packet during this interval. Otherwise, the + <ref column="bfd" key="forwarding"/> flag will be false even + though data packet is received from the monitored interface. + </p> + + <p> + Since the datapath flow is not purged when the userspace Open Vswitch + crashes, data packet can still be forwarded through the tunnel and + fool the remote BFD session in <code>forwarding_if_rx</code> mode. + Thus, this option can prevent the remote BFD session from falsely + declaring tunnel liveness in this situation. + </p> + </column> + <column name="bfd" key="cpath_down" type='{"type": "boolean"}'> Set to true to notify the remote endpoint that traffic should not be forwarded to this system for some reason other than a connectivty -- 1.7.9.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev