When there is no incoming data traffic at the interface for a period, BFD decay allows the bfd session to increase the min_rx. This is helpful in that some interfaces may be idle for long a time. And cpu consumption can be reduced by processing fewer bfd control packets.
Signed-off-by: Alex Wang <al...@nicira.com> --- v3 -> v4: - remove the change about "do not allow decay when decay_min_rx is less than rmt_min_tx" in v3. - refine the decay algorithm. v2 -> v3: - refine the decay algorithm. - add comments about the decay and decay algorithm. - reset decay_detect_time when state goes to STATE_UP and decay_min_rx is configured.. - reset the bfd->min_rx to cfg_min_rx when state goes to STATE_DOWN and bfd is in decay. - do not allow bfd to call bfd_may_decay when decay_min_rx is less than rmt_min_tx. - reset the decay_detect_time when netdev is changed and decay_min_rx is configured. - add two more unit tests. v1 -> v2: - add 'in_decay' boolean variable to bfd struct and simplify code. - include unit test to this patch. --- lib/bfd.c | 136 ++++++++++++++++++++++- lib/bfd.h | 5 +- ofproto/ofproto-dpif.c | 7 +- tests/bfd.at | 279 ++++++++++++++++++++++++++++++++++++++++++++++-- vswitchd/vswitch.xml | 10 ++ 5 files changed, 421 insertions(+), 16 deletions(-) diff --git a/lib/bfd.c b/lib/bfd.c index 74b27c4..89ba4a9 100644 --- a/lib/bfd.c +++ b/lib/bfd.c @@ -27,6 +27,7 @@ #include "hash.h" #include "hmap.h" #include "list.h" +#include "netdev.h" #include "netlink.h" #include "odp-util.h" #include "ofpbuf.h" @@ -150,6 +151,9 @@ struct bfd { bool cpath_down; /* Concatenated Path Down. */ uint8_t mult; /* bfd.DetectMult. */ + struct netdev *netdev; + uint64_t rx_packets; /* Packets received by 'netdev'. */ + enum state state; /* bfd.SessionState. */ enum state rmt_state; /* bfd.RemoteSessionState. */ @@ -185,6 +189,14 @@ struct bfd { atomic_bool check_tnl_key; /* Verify tunnel key of inbound packets? */ atomic_int ref_cnt; + + /* 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 */ + /* in decay. */ + int decay_rx_count; /* Count rx packets received within decay */ + /* detect interval. */ + long long int decay_detect_time; /* Decay detection time. */ }; static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER; @@ -207,6 +219,9 @@ static void bfd_set_state(struct bfd *, enum state, enum diag) static uint32_t generate_discriminator(void) OVS_REQUIRES(mutex); static void bfd_put_details(struct ds *, const struct bfd *) OVS_REQUIRES(mutex); +static uint64_t bfd_rx_packets(const struct bfd *) OVS_REQUIRES(mutex); +static void bfd_try_decay(struct bfd *) OVS_REQUIRES(mutex); +static void bfd_decay_update(struct bfd *) OVS_REQUIRES(mutex); static void bfd_unixctl_show(struct unixctl_conn *, int argc, const char *argv[], void *aux OVS_UNUSED); static void bfd_unixctl_set_forwarding_override(struct unixctl_conn *, @@ -254,14 +269,16 @@ bfd_get_status(const struct bfd *bfd, struct smap *smap) * handle for the session, or NULL if BFD is not enabled according to 'cfg'. * Also returns NULL if cfg is NULL. */ struct bfd * -bfd_configure(struct bfd *bfd, const char *name, const struct smap *cfg) - OVS_EXCLUDED(mutex) +bfd_configure(struct bfd *bfd, const char *name, const struct smap *cfg, + struct netdev *netdev) OVS_EXCLUDED(mutex) { static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; static atomic_uint16_t udp_src = ATOMIC_VAR_INIT(0); + int decay_min_rx; long long int min_tx, min_rx; bool need_poll = false; + bool cfg_min_rx_changed = false; bool cpath_down; const char *hwaddr; uint8_t ea[ETH_ADDR_LEN]; @@ -292,6 +309,8 @@ bfd_configure(struct bfd *bfd, const char *name, const struct smap *cfg) bfd->min_tx = 1000; bfd->mult = 3; atomic_init(&bfd->ref_cnt, 1); + bfd->netdev = netdev_ref(netdev); + bfd->in_decay = false; /* RFC 5881 section 4 * The source port MUST be in the range 49152 through 65535. The same @@ -327,6 +346,22 @@ bfd_configure(struct bfd *bfd, const char *name, const struct smap *cfg) || (!bfd_in_poll(bfd) && bfd->cfg_min_rx > bfd->min_rx)) { bfd->min_rx = bfd->cfg_min_rx; } + cfg_min_rx_changed = true; + need_poll = true; + } + + decay_min_rx = smap_get_int(cfg, "decay_min_rx", 0); + if (bfd->decay_min_rx != decay_min_rx || cfg_min_rx_changed) { + if (decay_min_rx > 0 && decay_min_rx < bfd->cfg_min_rx) { + VLOG_WARN("%s: decay_min_rx cannot be less than %lld ms", + bfd->name, bfd->cfg_min_rx); + bfd->decay_min_rx = 0; + } else { + bfd->decay_min_rx = decay_min_rx; + } + /* Resets decay. */ + bfd->in_decay = false; + bfd_decay_update(bfd); need_poll = true; } @@ -378,6 +413,7 @@ bfd_unref(struct bfd *bfd) OVS_EXCLUDED(mutex) if (orig == 1) { ovs_mutex_lock(&mutex); hmap_remove(all_bfds, &bfd->node); + netdev_close(bfd->netdev); free(bfd->name); free(bfd); ovs_mutex_unlock(&mutex); @@ -403,12 +439,27 @@ bfd_wait(const struct bfd *bfd) OVS_EXCLUDED(mutex) void bfd_run(struct bfd *bfd) OVS_EXCLUDED(mutex) { + long long int now; + bool old_in_decay; + ovs_mutex_lock(&mutex); - if (bfd->state > STATE_DOWN && time_msec() >= bfd->detect_time) { + now = time_msec(); + old_in_decay = bfd->in_decay; + + if (bfd->state > STATE_DOWN && now >= bfd->detect_time) { bfd_set_state(bfd, STATE_DOWN, DIAG_EXPIRED); } - if (bfd->min_tx != bfd->cfg_min_tx || bfd->min_rx != bfd->cfg_min_rx) { + /* Decay may only happen when state is STATE_UP, bfd->decay_min_rx is + * configured, and decay_detect_time is reached. */ + if (bfd->state == STATE_UP && bfd->decay_min_rx > 0 + && now >= bfd->decay_detect_time) { + bfd_try_decay(bfd); + } + + if (bfd->min_tx != bfd->cfg_min_tx + || (bfd->min_rx != bfd->cfg_min_rx && bfd->min_rx != bfd->decay_min_rx) + || bfd->in_decay != old_in_decay) { bfd_poll(bfd); } ovs_mutex_unlock(&mutex); @@ -536,6 +587,9 @@ bfd_process_packet(struct bfd *bfd, const struct flow *flow, /* This function is designed to follow section RFC 5880 6.8.6 closely. */ ovs_mutex_lock(&mutex); + /* Increments the decay rx counter. */ + bfd->decay_rx_count++; + if (flow->nw_ttl != 255) { /* XXX Should drop in the kernel to prevent DOS. */ goto out; @@ -685,6 +739,23 @@ bfd_process_packet(struct bfd *bfd, const struct flow *flow, out: ovs_mutex_unlock(&mutex); } + +/* Must be called when the netdev owned by 'bfd' should change. */ +void +bfd_set_netdev(struct bfd *bfd, const struct netdev *netdev) + OVS_EXCLUDED(mutex) +{ + ovs_mutex_lock(&mutex); + if (bfd->netdev != netdev) { + netdev_close(bfd->netdev); + bfd->netdev = netdev_ref(netdev); + if (bfd->decay_min_rx) { + bfd_decay_update(bfd); + } + } + ovs_mutex_unlock(&mutex); +} + static bool bfd_forwarding__(const struct bfd *bfd) OVS_REQUIRES(mutex) @@ -712,7 +783,7 @@ bfd_poll(struct bfd *bfd) OVS_REQUIRES(mutex) if (bfd->state > STATE_DOWN && !bfd_in_poll(bfd) && !(bfd->flags & FLAG_FINAL)) { bfd->poll_min_tx = bfd->cfg_min_tx; - bfd->poll_min_rx = bfd->cfg_min_rx; + bfd->poll_min_rx = bfd->in_decay ? bfd->decay_min_rx : bfd->cfg_min_rx; bfd->flags |= FLAG_POLL; bfd->next_tx = 0; VLOG_INFO_RL(&rl, "%s: Initiating poll sequence", bfd->name); @@ -885,10 +956,65 @@ bfd_set_state(struct bfd *bfd, enum state state, enum diag diag) bfd->rmt_flags = 0; bfd->rmt_disc = 0; bfd->rmt_min_tx = 0; + /* Resets the min_rx if in_decay. */ + if (bfd->in_decay) { + bfd->min_rx = bfd->cfg_min_rx; + bfd->in_decay = false; + } + } + /* Resets the decay when state changes to STATE_UP + * and decay_min_rx is configured. */ + if (bfd->state == STATE_UP && bfd->decay_min_rx) { + bfd_decay_update(bfd); } } } +static uint64_t +bfd_rx_packets(const struct bfd *bfd) OVS_REQUIRES(mutex) +{ + struct netdev_stats stats; + + if (!netdev_get_stats(bfd->netdev, &stats)) { + return stats.rx_packets; + } else { + return 0; + } +} + +/* Decays the bfd->min_rx to bfd->decay_min_rx when 'diff' is less than + * the 'expect' value. + * + * The 'diff' is the difference between current interface rx_packets stats + * and last-time check. The 'expect' is the recorded number of bfd control + * packets received within an approximately decay_min_rx (2000 ms if + * decay_min_rx is less than 2000 ms) interval. + * + * Note, since the update of rx_packets stats at interface happens every + * 2000 ms and is asynchronous to the bfd_rx_packets() function, the + * 'diff' value can be jittered. And the maximum jitter can be + * approximately (2000 ms / bfd->cfg_min_rx). So, a value greater than this + * is added to 'expect' to compensate for the jitter. */ +static void +bfd_try_decay(struct bfd *bfd) OVS_REQUIRES(mutex) +{ + int64_t diff, expect; + + diff = bfd_rx_packets(bfd) - bfd->rx_packets; + expect = bfd->decay_rx_count + (2000 / bfd->cfg_min_rx + 10); + bfd->in_decay = diff <= expect ? true : false; + bfd_decay_update(bfd); +} + +/* Updates the rx_packets, decay_rx_count and decay_detect_time. */ +static void +bfd_decay_update(struct bfd * bfd) OVS_REQUIRES(mutex) +{ + bfd->rx_packets = bfd_rx_packets(bfd); + bfd->decay_rx_count = 0; + bfd->decay_detect_time = MAX(bfd->decay_min_rx, 2000) + time_msec(); +} + static uint32_t generate_discriminator(void) { diff --git a/lib/bfd.h b/lib/bfd.h index 67d012e..0e1e33d 100644 --- a/lib/bfd.h +++ b/lib/bfd.h @@ -24,6 +24,7 @@ struct bfd; struct flow; struct flow_wildcards; +struct netdev; struct ofpbuf; struct smap; @@ -40,11 +41,13 @@ void bfd_process_packet(struct bfd *, const struct flow *, const struct ofpbuf *); struct bfd *bfd_configure(struct bfd *, const char *name, - const struct smap *smap); + const struct smap *smap, + struct netdev *netdev); struct bfd *bfd_ref(const struct bfd *); void bfd_unref(struct bfd *); bool bfd_forwarding(const struct bfd *); void bfd_get_status(const struct bfd *, struct smap *); +void bfd_set_netdev(struct bfd *, const struct netdev *); #endif /* bfd.h */ diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 229b16c..a52ec1b 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1891,6 +1891,10 @@ port_modified(struct ofport *port_) cfm_set_netdev(port->cfm, port->up.netdev); } + if (port->bfd) { + bfd_set_netdev(port->bfd, port->up.netdev); + } + if (port->is_tunnel && tnl_port_reconfigure(port, port->up.netdev, port->odp_port)) { ofproto_dpif_cast(port->up.ofproto)->backer->need_revalidate = @@ -2025,7 +2029,8 @@ set_bfd(struct ofport *ofport_, const struct smap *cfg) struct bfd *old; old = ofport->bfd; - ofport->bfd = bfd_configure(old, netdev_get_name(ofport->up.netdev), cfg); + ofport->bfd = bfd_configure(old, netdev_get_name(ofport->up.netdev), + cfg, ofport->up.netdev); if (ofport->bfd != old) { ofproto->backer->need_revalidate = REV_RECONFIGURE; } diff --git a/tests/bfd.at b/tests/bfd.at index fb8b1d3..da45b27 100644 --- a/tests/bfd.at +++ b/tests/bfd.at @@ -20,9 +20,9 @@ AT_CHECK([ovs-appctl bfd/show $1 | sed -e '/Time:/d' | sed -e '/Discriminator/d' m4_define([BFD_CHECK_TX], [ AT_CHECK([ovs-appctl bfd/show $1 | sed -n '/TX Interval/p'],[0], [dnl - TX Interval: Approx 1000ms - Local Minimum TX Interval: $2 - Remote Minimum TX Interval: $3 + TX Interval: Approx $2 + Local Minimum TX Interval: $3 + Remote Minimum TX Interval: $4 ]) ]) @@ -30,8 +30,8 @@ m4_define([BFD_CHECK_RX], [ AT_CHECK([ovs-appctl bfd/show $1 | sed -n '/RX Interval/p'],[0], [dnl RX Interval: Approx $2 - Local Minimum RX Interval: $2 - Remote Minimum RX Interval: $3 + Local Minimum RX Interval: $3 + Remote Minimum RX Interval: $4 ]) ]) AT_SETUP([bfd - basic config on different bridges]) @@ -202,14 +202,14 @@ BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [N #Edit the min Tx value. AT_CHECK([ovs-vsctl set interface p0 bfd:min_tx=200]) for i in `seq 0 20`; do ovs-appctl time/warp 100; done -BFD_CHECK_TX([p0], [200ms], [100ms]) -BFD_CHECK_TX([p1], [100ms], [200ms]) +BFD_CHECK_TX([p0], [1000ms], [200ms], [100ms]) +BFD_CHECK_TX([p1], [1000ms], [100ms], [200ms]) #Edit the min Rx value. AT_CHECK([ovs-vsctl set interface p1 bfd:min_rx=300]) for i in `seq 0 20`; do ovs-appctl time/warp 100; done -BFD_CHECK_RX([p1], [300ms], [1000ms]) -BFD_CHECK_RX([p0], [1000ms], [300ms]) +BFD_CHECK_RX([p1], [300ms], [300ms], [1000ms]) +BFD_CHECK_RX([p0], [1000ms], [1000ms], [300ms]) OVS_VSWITCHD_STOP AT_CLEANUP @@ -247,3 +247,264 @@ This flow is handled by the userspace slow path because it: OVS_VSWITCHD_STOP AT_CLEANUP + +# Tests below are for bfd decay features. +AT_SETUP([bfd - bfd decay]) +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 bfd:decay_min_rx=3000 -- \ + set Interface p1 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500]) + +ovs-appctl time/stop + +# wait for local session state to go from down to up. +for i in `seq 0 2`; do ovs-appctl time/warp 500; done +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [init], [No Diagnostic]) + + +# Test-1 BFD decay: decay to decay_min_rx +# bfd:decay_min_rx is set to 3000ms after the local state of p0 goes up, +# so for the first 2500ms, there should be no change. +for i in `seq 0 3`; do ovs-appctl time/warp 500; done +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [500ms], [300ms], [500ms]) + +# advance the clock by 500ms. +ovs-appctl time/warp 500 +# now at 3000ms, min_rx should decay to 3000ms and there should be +# poll sequence flags. +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms]) + +# since the tx_min of p0 is still 500ms, after 500ms from decay, +# the control message will be sent from p0 to p1, and p1 'flag' +# will go back to none. +ovs-appctl time/warp 500 +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic]) + +# the rx_min of p0 is 3000ms now, and p1 will send next control message +# 3000ms after decay. so, advance clock by 2500ms to make that happen. +for i in `seq 0 4`; do ovs-appctl time/warp 500; done +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms]) +# End of Test-1 ############################################################### + + +# Test-2 BFD decay: go back to cfg_min_rx when there is traffic +# receive packet at 1/100ms rate for 3000ms. +for i in `seq 0 30` +do + ovs-appctl time/warp 100 + AT_CHECK([ovs-ofctl packet-out br1 3 2 "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"], + [0], [stdout], []) +done +# after a decay interval (3000ms), the p0 min_rx will go back to +# cfg_min_rx. there should be poll sequence flags. +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [500ms], [300ms], [500ms]) + +# 500ms later, both direction will send control messages, +# and their 'flag' will go back to none. +ovs-appctl time/warp 500 +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]) +BFD_CHECK_RX([p0], [500ms], [300ms], [500ms]) +# End of Test-2 ############################################################### + + +# Test-3 BFD decay: go back to cfg_min_rx when decay_min_rx is changed +# advance the clock by 2500ms to 3000m after restore of +# min_rx. p0 is decayed, and there should be the poll sequence flags. +for i in `seq 0 4`; do ovs-appctl time/warp 500; done +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms]) + +# advance the clock, to make 'flag' go back to none. +for i in `seq 0 5`; 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]) + +# change decay_min_rx to 1000ms. +# for decay_min_rx < 2000ms, the decay detection time is set to 2000ms. +# this should firstly reset the min_rx and start poll sequence. +AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=1000]) +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [500ms], [300ms], [500ms]) + +# for the following 1500ms, there should be no decay, +# since the decay_detect_time is set to 2000ms. +for i in `seq 0 2` +do + ovs-appctl time/warp 500 + 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]) + BFD_CHECK_RX([p0], [500ms], [300ms], [500ms]) +done + +ovs-appctl time/warp 500 +# at 2000ms, decay should happen and there should be the poll sequence flags. +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [1000ms], [1000ms], [500ms]) +# advance the clock, so 'flag' go back to none. +for i in `seq 0 4`; do ovs-appctl time/warp 500; done +# End of Test-3 ############################################################### + + +# Test-4 BFD decay: set min_rx to 800ms. +# this should firstly reset the min_rx and then re-decay to 1000ms. +AT_CHECK([ovs-vsctl set Interface p0 bfd:min_rx=800]) +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [800ms], [800ms], [500ms]) + +# for the following 1600ms, there should be no decay, +# since the decay detection time is set to 2000ms. +for i in `seq 0 1` +do + ovs-appctl time/warp 800 + 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]) + BFD_CHECK_RX([p0], [800ms], [800ms], [500ms]) +done + +ovs-appctl time/warp 400 +# at 2000ms, decay should happen and there should be the poll sequence flags. +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [1000ms], [1000ms], [500ms]) +# advance the clock, so 'flag' go back to none. +for i in `seq 0 4`; do ovs-appctl time/warp 500; done +# End of Test-4 ############################################################### + + +# Test-5 BFD decay: set min_rx to 300ms and decay_min_rx to 5000ms together. +AT_CHECK([ovs-vsctl set Interface p0 bfd:min_rx=300 bfd:decay_min_rx=5000]) +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [500ms], [300ms], [500ms]) + +# for decay_min_rx > 2000ms, the decay detection time is set to +# decay_min_rx (5000ms). +# for the following 4500ms, there should be no decay, +# since the decay detection time is set to 5000ms. +for i in `seq 0 8` +do + ovs-appctl time/warp 500 + 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]) + BFD_CHECK_RX([p0], [500ms], [300ms], [500ms]) +done + +ovs-appctl time/warp 500 +# at 5000ms, decay should happen and there should be the poll sequence flags. +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [5000ms], [5000ms], [500ms]) +# advance the clock, to make 'flag' go back to none. +for i in `seq 0 9`; do ovs-appctl time/warp 500; done +# End of Test-5 ############################################################### + + +# Test-6 BFD decay: set decay_min_rx to 0 to disable bfd decay. +AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=0]) +# min_rx is reset, and there should be the poll sequence flags. +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [500ms], [300ms], [500ms]) +for i in `seq 0 20` +do + ovs-appctl time/warp 500 + 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]) + BFD_CHECK_RX([p0], [500ms], [300ms], [500ms]) +done +# End of Test-6 ################################################################ + + +# Test-7 BFD decay: rmt_min_tx is greater than decay_min_rx +AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=3000 -- set interface p1 bfd:min_tx=5000]) +# there will be poll sequences from both sides. and it is hard to determine the +# order. so just skip 10000ms and check the RX/TX. at that time, p0 should be in decay already. +for i in `seq 0 19`; do echo $i; ovs-appctl bfd/show; 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], [5000ms]) +BFD_CHECK_RX([p0], [5000ms], [3000ms], [500ms]) +# then, there should be no change of status, +for i in `seq 0 9` +do + ovs-appctl time/warp 500 + 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], [5000ms]) + BFD_CHECK_RX([p0], [5000ms], [3000ms], [500ms]) +done +# reset the p1's min_tx to 500ms. +AT_CHECK([ovs-vsctl set Interface p1 bfd:min_tx=500]) +# check the poll sequence. since p0 has been in decay, now the RX will show 3000ms. +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic]) +BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms]) +# advance the clock by 3000ms, at that time, p1 will send the control packets. +# then there will be no poll flags. +for i in `seq 0 5`; 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]) +BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms]) +# End of Test-7 ############################################################### + + +# Test-8 BFD decay: state up->down->up. +# turn bfd off on p1 +AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false]) + +# check the state change of bfd on p0. After 9000 ms (3 min_rx intervals) +for i in `seq 0 8`; do ovs-appctl time/warp 1000; done +BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic]) +BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms]) +BFD_CHECK_RX([p0], [300ms], [300ms], [1ms]) + +# resume the bfd on p1. the bfd should not go to decay mode direclty. +AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true]) +for i in `seq 0 1`; do ovs-appctl time/warp 500; done +BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [500ms], [300ms], [500ms]) + +# since the decay_min_rx is still 3000ms, so after 3000ms, there should be the decay and poll sequence. +for i in `seq 0 5`; do ovs-appctl time/warp 500; done +BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [final], [up], [No Diagnostic]) +BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [Control Detection Time Expired]) +BFD_CHECK_TX([p0], [500ms], [300ms], [500ms]) +BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms]) +# End of Test-8 ################################################################ + +OVS_VSWITCHD_STOP +AT_CLEANUP \ No newline at end of file diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml index b89d58c..b73a612 100644 --- a/vswitchd/vswitch.xml +++ b/vswitchd/vswitch.xml @@ -1880,6 +1880,16 @@ specified. Defaults to <code>100</code>. </column> + <column name="bfd" key="decay_min_rx" type='{"type": "integer"}'> + <code>decay_min_rx</code> is used to set the <code>min_rx</code>, + when there is no obvious incoming data traffic at the interface. + It cannot be less than the <code>min_rx</code>. The decay feature + is disable by setting the <code>decay_min_rx</code> to 0. And the + feature is reset everytime itself or <code>min_rx</code> is + reconfigured. + </column> + + <column name="bfd" key="cpath_down" type='{"type": "boolean"}'> Concatenated path down may be used when the local system should not have traffic forwarded to it for some reason other than a connectivty -- 1.7.9.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev