X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fstp.c;h=3d293b6c6137c5fd2bf3817c9d8eba41e991a1ff;hb=b19e8793390f788a4e394d049ea64ce0161ad923;hp=f7fe53cc9fe93e07a49bcfeb9dbbdc8b9e3095b5;hpb=6ae507231be01f14c37dd7f52783de36a70d9d09;p=openvswitch diff --git a/lib/stp.c b/lib/stp.c index f7fe53cc..3d293b6c 100644 --- a/lib/stp.c +++ b/lib/stp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks. + * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ #include "byte-order.h" #include "ofpbuf.h" #include "packets.h" +#include "unixctl.h" #include "util.h" #include "vlog.h" @@ -101,6 +102,8 @@ struct stp_port { }; struct stp { + struct list node; /* Node in all_stps list. */ + /* Static bridge data. */ char *name; /* Human-readable name for log messages. */ stp_identifier bridge_id; /* 8.5.3.7: This bridge. */ @@ -137,6 +140,8 @@ struct stp { void *aux; }; +static struct list all_stps = LIST_INITIALIZER(&all_stps); + #define FOR_EACH_ENABLED_PORT(PORT, STP) \ for ((PORT) = stp_next_enabled_port((STP), (STP)->ports); \ (PORT); \ @@ -146,7 +151,7 @@ stp_next_enabled_port(const struct stp *stp, const struct stp_port *port) { for (; port < &stp->ports[ARRAY_SIZE(stp->ports)]; port++) { if (port->state != STP_DISABLED) { - return (struct stp_port *) port; + return CONST_CAST(struct stp_port *, port); } } return NULL; @@ -199,6 +204,15 @@ static void stp_stop_timer(struct stp_timer *); static bool stp_timer_expired(struct stp_timer *, int elapsed, int timeout); static void stp_send_bpdu(struct stp_port *, const void *, size_t); +static void stp_unixctl_tcn(struct unixctl_conn *, int argc, + const char *argv[], void *aux); + +void +stp_init(void) +{ + unixctl_command_register("stp/tcn", "[bridge]", 0, 1, stp_unixctl_tcn, + NULL); +} /* Creates and returns a new STP instance that initially has no ports enabled. * @@ -256,6 +270,7 @@ stp_create(const char *name, stp_identifier bridge_id, p->path_cost = 19; /* Recommended default for 100 Mb/s link. */ stp_initialize_port(p, STP_DISABLED); } + list_push_back(&all_stps, &stp->node); return stp; } @@ -264,6 +279,7 @@ void stp_destroy(struct stp *stp) { if (stp) { + list_remove(&stp->node); free(stp->name); free(stp); } @@ -1052,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); @@ -1061,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 @@ -1328,3 +1347,41 @@ stp_send_bpdu(struct stp_port *p, const void *bpdu, size_t bpdu_size) p->stp->send_bpdu(pkt, stp_port_no(p), p->stp->aux); p->tx_count++; } + +/* Unixctl. */ + +static struct stp * +stp_find(const char *name) +{ + struct stp *stp; + + LIST_FOR_EACH (stp, node, &all_stps) { + if (!strcmp(stp->name, name)) { + return stp; + } + } + return NULL; +} + +static void +stp_unixctl_tcn(struct unixctl_conn *conn, int argc, + const char *argv[], void *aux OVS_UNUSED) +{ + if (argc > 1) { + struct stp *stp = stp_find(argv[1]); + + if (!stp) { + unixctl_command_reply_error(conn, "no such stp object"); + return; + } + stp_topology_change_detection(stp); + } else { + struct stp *stp; + + LIST_FOR_EACH (stp, node, &all_stps) { + stp_topology_change_detection(stp); + } + } + + unixctl_command_reply(conn, "OK"); +}