[ovs-dev] [PATCH V3 2/2] bfd: Add new key "flap_count" to "bfd_status".
Alex Wang
alexw at nicira.com
Thu Nov 14 01:59:41 UTC 2013
This commit adds a new key "flap_count" to "bfd_status". It is to
count the number of bfd state flapping since start.
Signed-off-by: Alex Wang <alexw at nicira.com>
---
v2 -> v3:
- rebase to master
v1 -> v2:
- rebase to master
---
lib/bfd.c | 14 ++++++++++++++
tests/bfd.at | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
vswitchd/vswitch.xml | 7 +++++++
3 files changed, 71 insertions(+)
diff --git a/lib/bfd.c b/lib/bfd.c
index 740f4fc..f34b895 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -206,6 +206,8 @@ struct bfd {
/* detect interval. */
uint64_t decay_rx_packets; /* Packets received by 'netdev'. */
long long int decay_detect_time; /* Decay detection time. */
+
+ uint64_t flap_count; /* Counts the flapping. */
};
static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER;
@@ -262,11 +264,17 @@ void
bfd_get_status(const struct bfd *bfd, struct smap *smap)
OVS_EXCLUDED(mutex)
{
+ char *flap_count;
+
ovs_mutex_lock(&mutex);
smap_add(smap, "forwarding", bfd_forwarding__(bfd)? "true" : "false");
smap_add(smap, "state", bfd_state_str(bfd->state));
smap_add(smap, "diagnostic", bfd_diag_str(bfd->diag));
+ flap_count = xasprintf("%"PRIu64, bfd->flap_count);
+ smap_add(smap, "flap_count", flap_count);
+ free(flap_count);
+
if (bfd->state != STATE_DOWN) {
smap_add(smap, "remote_state", bfd_state_str(bfd->rmt_state));
smap_add(smap, "remote_diagnostic", bfd_diag_str(bfd->rmt_diag));
@@ -323,6 +331,7 @@ bfd_configure(struct bfd *bfd, const char *name, const struct smap *cfg,
bfd->netdev = netdev_ref(netdev);
bfd->rx_packets = bfd_rx_packets(bfd);
bfd->in_decay = false;
+ bfd->flap_count = 0;
/* RFC 5881 section 4
* The source port MUST be in the range 49152 through 65535. The same
@@ -998,6 +1007,11 @@ bfd_set_state(struct bfd *bfd, enum state state, enum diag diag)
ds_destroy(&ds);
}
+ /* If there is a flap, increments the counter. */
+ if (bfd->state == STATE_DOWN || state == STATE_DOWN) {
+ bfd->flap_count++;
+ }
+
bfd->state = state;
bfd->diag = diag;
diff --git a/tests/bfd.at b/tests/bfd.at
index 73bf07f..2571ca8 100644
--- a/tests/bfd.at
+++ b/tests/bfd.at
@@ -34,6 +34,14 @@ AT_CHECK([ovs-appctl bfd/show $1 | sed -n '/RX Interval/p'],[0],
Remote Minimum RX Interval: $4
])
])
+
+m4_define([BFD_VSCTL_LIST_IFACE], [
+AT_CHECK([ovs-vsctl list interface $1 | sed -n $2],[0],
+[dnl
+$3
+])
+])
+
AT_SETUP([bfd - basic config on different bridges])
#Create 2 bridges connected by patch ports and enable BFD
OVS_VSWITCHD_START(
@@ -699,4 +707,46 @@ BFD_CHECK_TX([p0], [300ms], [300ms], [300ms])
BFD_CHECK_RX([p0], [1000ms], [1000ms], [300ms])
AT_CHECK([ovs-vsctl del-br br1], [0], [ignore])
+AT_CLEANUP
+
+# test bfd:flap_count.
+AT_SETUP([bfd - flap_count])
+#Create 2 bridges connected by patch ports and enable bfd
+OVS_VSWITCHD_START([add-br br1 -- \
+ set bridge br1 datapath-type=dummy \
+ other-config:hwaddr=aa:55:aa:56:00:00 -- \
+ add-port br1 p1 -- set Interface p1 type=patch \
+ options:peer=p0 -- \
+ add-port br0 p0 -- set Interface p0 type=patch \
+ options:peer=p1 -- \
+ set Interface p0 bfd:enable=true bfd:min_tx=100 bfd:min_rx=100 -- \
+ set Interface p1 bfd:enable=true bfd:min_tx=100 bfd:min_rx=100])
+
+ovs-appctl time/stop
+
+# wait for a while to stablize bfd.
+for i in `seq 0 100`; do ovs-appctl time/warp 100; 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], [100ms], [100ms], [100ms])
+BFD_CHECK_RX([p0], [100ms], [100ms], [100ms])
+# both p0 and p1 should have flap_count = "2". since admin_down->down, down->up.
+BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["2"])
+BFD_VSCTL_LIST_IFACE([p1], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["2"])
+
+# turn bfd on p1 off, should increment the bfd:flap_count on p1.
+AT_CHECK([ovs-vsctl set interface p1 bfd:enable=false])
+for i in `seq 0 10`; do ovs-appctl time/warp 100; done
+BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
+BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["3"])
+AT_CHECK([ovs-vsctl list interface p1 | sed -n "s/^.*flap_count=\(.*\), forwarding.*$/\1/p"])
+
+# turn bfd on p1 on again, should increment the bfd:flap_count on p1.
+# p1 should still have flap_count = "2", since it is reset.
+AT_CHECK([ovs-vsctl set interface p1 bfd:enable=true])
+for i in `seq 0 10`; do ovs-appctl time/warp 100; done
+BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["4"])
+BFD_VSCTL_LIST_IFACE([p1], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["2"])
+
+OVS_VSWITCHD_STOP
AT_CLEANUP
\ No newline at end of file
diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml
index 84f6481..ba4ec9f 100644
--- a/vswitchd/vswitch.xml
+++ b/vswitchd/vswitch.xml
@@ -2009,6 +2009,13 @@
In case of a problem, set to a short message that reports what the
remote endpoint's BFD session thinks is wrong.
</column>
+
+ <column name="bfd_status" key="flap_count"
+ type='{"type": "integer", "minInteger": 0}'>
+ Counts the number of bfd state flapping since start. A flap is
+ considered as the change of <ref column="bfd_status"
+ key="state"/> from "down" to "up", or vice versa.
+ </column>
</group>
</group>
--
1.7.9.5
More information about the dev
mailing list