[ovs-dev] [PATCH V2] bfd: Implements BFD decay
Alex Wang
alexw at nicira.com
Thu Jul 11 16:55:07 UTC 2013
When there is no incoming data traffic in the tunnel for a period,
BFD decay allows the bfd session to increase the min_rx. This isa
helpful in that usually some tunnels are rarely used. And cpu
consumption can be reduced by processing fewer bfd control packets.
Signed-off-by: Alex Wang <alexw at nicira.com>
---
v1 -> v2:
1. replace the gradual decay to immediately decay.
2. add configurable decay_min_rx.
---
lib/bfd.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++--
lib/bfd.h | 5 ++-
ofproto/ofproto-dpif.c | 3 +-
vswitchd/vswitch.xml | 18 ++++++++++
4 files changed, 110 insertions(+), 5 deletions(-)
diff --git a/lib/bfd.c b/lib/bfd.c
index aa1a3f7..0d4805a 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -152,6 +152,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. */
@@ -182,6 +185,11 @@ struct bfd {
int ref_cnt;
int forwarding_override; /* Manual override of 'forwarding' status. */
+
+ /* BFD decay related variables. */
+ bool decay_enabled; /* Flag that enables bfd decay. */
+ int decay_min_rx;
+ long long int decay_detect_time;
};
static bool bfd_in_poll(const struct bfd *);
@@ -191,6 +199,9 @@ static const char *bfd_state_str(enum state);
static long long int bfd_min_tx(const struct bfd *);
static long long int bfd_tx_interval(const struct bfd *);
static long long int bfd_rx_interval(const struct bfd *);
+static uint64_t bfd_rx_packets(const struct bfd *);
+static void bfd_decay_min_rx_set_default(struct bfd *);
+static void bfd_decay(struct bfd *);
static void bfd_set_next_tx(struct bfd *);
static void bfd_set_state(struct bfd *, enum state, enum diag);
static uint32_t generate_discriminator(void);
@@ -243,7 +254,8 @@ bfd_get_status(const struct bfd *bfd, struct smap *smap)
* Also returns NULL if cfg is NULL. */
struct bfd *
bfd_configure(struct bfd *bfd, const char *name,
- const struct smap *cfg)
+ const struct smap *cfg,
+ struct netdev *netdev)
{
static uint16_t udp_src = 0;
static bool init = false;
@@ -276,6 +288,9 @@ bfd_configure(struct bfd *bfd, const char *name,
bfd->min_tx = 1000;
bfd->mult = 3;
bfd->ref_cnt = 1;
+ bfd->netdev = netdev;
+ bfd->decay_detect_time = 0;
+ bfd->rx_packets = bfd_rx_packets(bfd);
/* RFC 5881 section 4
* The source port MUST be in the range 49152 through 65535. The same
@@ -309,6 +324,15 @@ bfd_configure(struct bfd *bfd, const char *name,
bfd_poll(bfd);
}
+ bfd->decay_enabled = smap_get_bool(cfg, "decay_enable", false);
+ bfd->decay_min_rx = smap_get_int(cfg, "decay_min_rx", -1);
+ /* Set the default decay_min_rx if decay is enabled and decay_min_rx
+ is not specified. */
+ if (bfd->decay_enabled && bfd->decay_min_rx < 0) {
+ bfd_decay_min_rx_set_default(bfd);
+ bfd_poll(bfd);
+ }
+
cpath_down = smap_get_bool(cfg, "cpath_down", false);
if (bfd->cpath_down != cpath_down) {
bfd->cpath_down = cpath_down;
@@ -360,11 +384,19 @@ bfd_wait(const struct bfd *bfd)
void
bfd_run(struct bfd *bfd)
{
- if (bfd->state > STATE_DOWN && time_msec() >= bfd->detect_time) {
+ long long int now = time_msec();
+
+ 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) {
+ if (bfd->state == STATE_UP && bfd->decay_enabled
+ && now >= bfd->decay_detect_time) {
+ bfd_decay(bfd);
+ }
+
+ if (!bfd->decay_enabled &&
+ (bfd->min_tx != bfd->cfg_min_tx || bfd->min_rx != bfd->cfg_min_rx)) {
bfd_poll(bfd);
}
}
@@ -804,6 +836,57 @@ bfd_set_state(struct bfd *bfd, enum state state, enum diag diag)
}
}
+static uint64_t
+bfd_rx_packets(const struct bfd *bfd)
+{
+ struct netdev_stats stats;
+
+ if (bfd->netdev && !netdev_get_stats(bfd->netdev, &stats)) {
+ return stats.rx_packets;
+ } else {
+ return 0;
+ }
+}
+
+static void
+bfd_decay_min_rx_set_default(struct bfd *bfd)
+{
+
+ bfd->decay_min_rx = bfd->mult * bfd->mult * MAX(bfd->cfg_min_rx,
+ bfd->rmt_min_tx);
+ /* Always restore the min_rx. */
+ bfd->min_rx = bfd->cfg_min_rx;
+}
+
+static void
+bfd_decay(struct bfd *bfd)
+{
+ uint64_t rx_packets = bfd_rx_packets(bfd);
+ int64_t diff;
+
+ diff = rx_packets - bfd->rx_packets;
+ bfd->rx_packets = rx_packets;
+ bfd->decay_detect_time = bfd->decay_min_rx + time_msec();
+
+ if (diff <= (bfd->decay_min_rx / bfd->min_rx + 5)) {
+ /* Decay when there is no obvious data traffic. */
+ if (bfd->min_rx != bfd->decay_min_rx) {
+ bfd->min_rx = bfd->decay_min_rx;
+ /* Increase the detect time to avoid
+ * "Control Detection Time Expired". */
+ bfd->detect_time = bfd->decay_detect_time;
+ }
+ } else {
+ /* Restore the min_rx. */
+ if (bfd->min_rx != bfd->cfg_min_rx) {
+ bfd->min_rx = bfd->cfg_min_rx;
+ /* Increase the detect time to avoid
+ * "Control Detection Time Expired". */
+ bfd->detect_time = bfd->decay_detect_time;
+ }
+ }
+}
+
static uint32_t
generate_discriminator(void)
{
diff --git a/lib/bfd.h b/lib/bfd.h
index ab854d8..a9b6d43 100644
--- a/lib/bfd.h
+++ b/lib/bfd.h
@@ -21,6 +21,8 @@
#include <stdbool.h>
#include <inttypes.h>
+#include "netdev.h"
+
struct bfd;
struct flow;
struct flow_wildcards;
@@ -39,7 +41,8 @@ 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 *);
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 67e6c7a..d475379 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1882,7 +1882,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/vswitchd/vswitch.xml b/vswitchd/vswitch.xml
index 6c08f70..0d07152 100644
--- a/vswitchd/vswitch.xml
+++ b/vswitchd/vswitch.xml
@@ -1880,6 +1880,24 @@
specified. Defaults to <code>100</code>.
</column>
+ <column name="bfd" key="decay_enable" type='{"type": "boolean"}'>
+ Allow the BFD session decay the <code>min_rx</code> to <code>
+ decay_min_rx</code> when there is no obvious incoming data traffic
+ in the tunnel. This is helpful in that usually some tunnels are
+ rarely used. And decaying the min_rx can reduce the number of
+ BFD control packets processed, as well as the cpu consumption.
+ </column>
+
+ <column name="bfd" key="decay_min_rx"
+ type='{"type": "integer", "minInteger":1}'>
+ When <code>decay_enable</code> is true, the BFD session will wait
+ <code>decay_min_rx</code> amount of time. If there is no obvious
+ incoming data traffic in the tunnel during this time interal,
+ BFD session will set <code>min_rx</code> to <code>decay_min_rx
+ </code>.
+ </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
More information about the dev
mailing list