Signed-off-by: Ethan Jackson <[email protected]>
---
lib/stp.c | 3 ++
tests/stp.at | 88 ++++++++++++++++++++++++++++++++++++++++++++++-------
tests/test-stp.c | 58 +++++++++++++++++++++++++++++++++--
3 files changed, 134 insertions(+), 15 deletions(-)
diff --git a/lib/stp.c b/lib/stp.c
index ba27306..06ac001 100644
--- a/lib/stp.c
+++ b/lib/stp.c
@@ -1068,6 +1068,8 @@ stp_set_port_state(struct stp_port *p, enum stp_state
state)
static void
stp_topology_change_detection(struct stp *stp)
{
+ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+
if (stp_is_root_bridge(stp)) {
stp->topology_change = true;
stp_start_timer(&stp->topology_change_timer, 0);
@@ -1077,6 +1079,7 @@ stp_topology_change_detection(struct stp *stp)
}
stp->fdb_needs_flush = true;
stp->topology_change_detected = true;
+ VLOG_INFO_RL(&rl, "%s: detected topology change.", stp->name);
}
static void
diff --git a/tests/stp.at b/tests/stp.at
index ba19837..ad039ba 100644
--- a/tests/stp.at
+++ b/tests/stp.at
@@ -15,7 +15,13 @@ check 2 = F:10 B
check 3 = F:5 F
check 4 = F:5 B
])
-AT_CHECK([test-stp test-stp-ieee802.1d-1998])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m' test-stp-ieee802.1d-1998],
[0], [], [dnl
+stp|INFO|stp42: detected topology change.
+stp|INFO|stp42: detected topology change.
+stp|INFO|stp97: detected topology change.
+stp|INFO|stp97: detected topology change.
+stp|INFO|stp97: detected topology change.
+])
AT_CLEANUP
AT_SETUP([STP example from IEEE 802.1D-2004 figures 17.4 and 17.5])
@@ -52,7 +58,13 @@ check 5 = F:20 B F F
check 6 = F:20 B F F
check 7 = F:20 B F B
])
-AT_CHECK([test-stp test-stp-ieee802.1d-2004-fig17.4])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m'
test-stp-ieee802.1d-2004-fig17.4], [0], [], [dnl
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp222: detected topology change.
+])
AT_CLEANUP
AT_SETUP([STP example from IEEE 802.1D-2004 figure 17.6])
@@ -72,7 +84,13 @@ check 3 = F:30 F B
check 4 = F:20 F F
check 5 = F:10 F F
])
-AT_CHECK([test-stp test-stp-ieee802.1d-2004-fig17.6])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m'
test-stp-ieee802.1d-2004-fig17.6], [0], [], [dnl
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp222: detected topology change.
+stp|INFO|stp222: detected topology change.
+])
AT_CLEANUP
AT_SETUP([STP example from IEEE 802.1D-2004 figure 17.7])
@@ -95,7 +113,13 @@ check 0 = root
check 1 = F F:10 F F F F F F
check 2 = F:20 D F F F F F F
])
-AT_CHECK([test-stp test-stp-ieee802.1d-2004-fig17.7])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m'
test-stp-ieee802.1d-2004-fig17.7], [0], [], [dnl
+stp|INFO|stpaa: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+])
AT_CLEANUP
AT_SETUP([STP.io.1.1: Link Failure])
@@ -128,7 +152,13 @@ run 1000
check 0 = root
check 1 = D D F:10
])
-AT_CHECK([test-stp test-stp-iol-io-1.1])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m' test-stp-iol-io-1.1], [0], [],
[dnl
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp222: detected topology change.
+stp|INFO|stp111: detected topology change.
+])
AT_CLEANUP
AT_SETUP([STP.io.1.2: Repeated Network])
@@ -148,7 +178,11 @@ run 1000
check 0 = rootid:0x111 F B
check 1 = rootid:0x111 B F:10
])
-AT_CHECK([test-stp test-stp-iol-io-1.2])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m' test-stp-iol-io-1.2], [0], [],
[dnl
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp222: detected topology change.
+stp|INFO|stp111: detected topology change.
+])
AT_CLEANUP
AT_SETUP([STP.io.1.4: Network Initialization])
@@ -168,7 +202,13 @@ check 1 = F:10 F F
check 2 = F:10 B F
check 3 = F:10 B B
])
-AT_CHECK([test-stp test-stp-iol-io-1.4])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m' test-stp-iol-io-1.4], [0], [],
[dnl
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp222: detected topology change.
+stp|INFO|stp222: detected topology change.
+])
AT_CLEANUP
AT_SETUP([STP.io.1.5: Topology Change])
@@ -215,7 +255,13 @@ check 1 = F:10 B F F
check 2 = B F:10 F F
check 3 = B F:20 B B
])
-AT_CHECK([test-stp test-stp-iol-io-1.5])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m' test-stp-iol-io-1.5], [0], [],
[dnl
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp222: detected topology change.
+])
AT_CLEANUP
AT_SETUP([STP.op.1.1 and STP.op.1.2])
@@ -244,7 +290,13 @@ check 0 = Li Li Li Li Li Li
run 1000
check 0 = F F F F F F
])
-AT_CHECK([test-stp test-stp-iol-op-1.4])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m' test-stp-iol-op-1.4], [0], [],
[dnl
+stp|INFO|stp123: detected topology change.
+stp|INFO|stp123: detected topology change.
+stp|INFO|stp123: detected topology change.
+stp|INFO|stp123: detected topology change.
+stp|INFO|stp123: detected topology change.
+])
AT_CLEANUP
AT_SETUP([STP.op.3.1: Root Bridge Selection: Root ID Values])
@@ -262,7 +314,9 @@ run 1000
check 0 = rootid:0x111 root
check 1 = rootid:0x111 F:10
])
-AT_CHECK([test-stp test-stp-iol-op-3.1])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m' test-stp-iol-op-3.1], [0], [],
[dnl
+stp|INFO|stp111: detected topology change.
+])
AT_CLEANUP
AT_SETUP([STP.op.3.3: Root Bridge Selection: Bridge ID Values])
@@ -280,7 +334,12 @@ check 0 = rootid:0x333^0x6000 root
check 1 = rootid:0x333^0x6000 F:20
check 2 = rootid:0x333^0x6000 F:10 F
])
-AT_CHECK([test-stp test-stp-iol-op-3.3])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m' test-stp-iol-op-3.3], [0], [],
[dnl
+stp|INFO|stp333: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp333: detected topology change.
+])
AT_CLEANUP
AT_SETUP([STP.op.3.3: Root Bridge Selection: Bridge ID Values])
@@ -298,5 +357,10 @@ check 0 = rootid:0x333^0x6000 root
check 1 = rootid:0x333^0x6000 F:20
check 2 = rootid:0x333^0x6000 F:10 F
])
-AT_CHECK([test-stp test-stp-iol-op-3.4])
+AT_CHECK([test-stp '-vPATTERN:console:%c|%p|%m' test-stp-iol-op-3.4], [0], [],
[dnl
+stp|INFO|stp333: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp111: detected topology change.
+stp|INFO|stp333: detected topology change.
+])
AT_CLEANUP
diff --git a/tests/test-stp.c b/tests/test-stp.c
index fecada7..d8033df 100644
--- a/tests/test-stp.c
+++ b/tests/test-stp.c
@@ -20,11 +20,16 @@
#include <assert.h>
#include <ctype.h>
#include <errno.h>
+#include <getopt.h>
#include <inttypes.h>
#include <stdarg.h>
#include <stdlib.h>
+#include "command-line.h"
#include "ofpbuf.h"
#include "packets.h"
+#include "vlog.h"
+
+VLOG_DEFINE_THIS_MODULE(test_stp);
struct bpdu {
int port_no;
@@ -433,6 +438,50 @@ must_match(const char *want)
}
}
+static void
+usage(void)
+{
+ printf("%s: STP test utility\n"
+ "usage: %s [OPTIONS] INPUT.STP\n",
+ program_name, program_name);
+ vlog_usage();
+ exit(EXIT_SUCCESS);
+}
+
+static void
+parse_options(int argc, char *argv[])
+{
+ enum {
+ VLOG_OPTION_ENUMS
+ };
+ static struct option long_options[] = {
+ {"help", no_argument, NULL, 'h'},
+ VLOG_LONG_OPTIONS,
+ {NULL, 0, NULL, 0}
+ };
+ char *short_options = long_options_to_short_options(long_options);
+
+ for (;;) {
+ int c;
+
+ c = getopt_long(argc, argv, short_options, long_options, NULL);
+ if (c == -1) {
+ break;
+ }
+
+ switch (c) {
+ case 'h':
+ usage();
+
+ VLOG_OPTION_HANDLERS
+
+ default:
+ NOT_REACHED();
+ }
+ }
+ free(short_options);
+}
+
int
main(int argc, char *argv[])
{
@@ -440,10 +489,13 @@ main(int argc, char *argv[])
FILE *input_file;
int i;
- if (argc != 2) {
- ovs_fatal(0, "usage: test-stp INPUT.STP\n");
+ set_program_name(argv[0]);
+ parse_options(argc, argv);
+
+ if (optind + 1 != argc) {
+ usage();
}
- file_name = argv[1];
+ file_name = argv[optind];
input_file = fopen(file_name, "r");
if (!input_file) {
--
1.7.8.3
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev