This commit adds more logging points in stp module for debugging. Also, it makes the log print out the port name.
Signed-off-by: Alex Wang <al...@nicira.com> --- lib/stp.c | 30 ++++++++++++++++++++++++++++++ lib/stp.h | 1 + ofproto/ofproto-dpif.c | 1 + 3 files changed, 32 insertions(+) diff --git a/lib/stp.c b/lib/stp.c index 92948ef..2f77bfb 100644 --- a/lib/stp.c +++ b/lib/stp.c @@ -36,6 +36,8 @@ VLOG_DEFINE_THIS_MODULE(stp); +static struct vlog_rate_limit stp_rl = VLOG_RATE_LIMIT_INIT(60, 60); + #define STP_PROTOCOL_ID 0x0000 #define STP_PROTOCOL_VERSION 0x00 #define STP_TYPE_CONFIG 0x00 @@ -82,6 +84,7 @@ struct stp_timer { struct stp_port { struct stp *stp; + char *port_name; /* Human-readable name for log messages. */ void *aux; /* Auxiliary data the user may retrieve. */ int port_id; /* 8.5.5.1: Unique port identifier. */ enum stp_state state; /* 8.5.5.2: Current state. */ @@ -328,10 +331,16 @@ void stp_unref(struct stp *stp) { if (stp && ovs_refcount_unref_relaxed(&stp->ref_cnt) == 1) { + size_t i; + ovs_mutex_lock(&mutex); list_remove(&stp->node); ovs_mutex_unlock(&mutex); free(stp->name); + + for (i = 0; i < STP_MAX_PORTS; i++) { + free(stp->ports[i].port_name); + } free(stp); } } @@ -795,6 +804,17 @@ stp_port_get_stp(struct stp_port *p) return stp; } +void +stp_port_set_name(struct stp_port *p, const char *name) +{ + char *old = p->port_name; + + ovs_mutex_lock(&mutex); + p->port_name = xstrdup(name); + free(old); + ovs_mutex_unlock(&mutex); +} + /* Sets the 'aux' member of 'p'. * * The 'aux' member will be reset to NULL when stp_port_disable() is @@ -1019,6 +1039,8 @@ stp_transmit_config(struct stp_port *p) OVS_REQUIRES(mutex) return; } if (p->hold_timer.active) { + VLOG_DBG_RL(&stp_rl, "bridge: %s, port: %s, transmit config bpdu pending", + stp->name, p->port_name); p->config_pending = true; } else { struct stp_config_bpdu config; @@ -1049,6 +1071,8 @@ stp_transmit_config(struct stp_port *p) OVS_REQUIRES(mutex) if (ntohs(config.message_age) < stp->max_age) { p->topology_change_ack = false; p->config_pending = false; + VLOG_DBG_RL(&stp_rl, "bridge: %s, port: %s, transmit config bpdu", + stp->name, p->port_name); stp_send_bpdu(p, &config, sizeof config); stp_start_timer(&p->hold_timer, 0); } @@ -1119,9 +1143,12 @@ stp_transmit_tcn(struct stp *stp) OVS_REQUIRES(mutex) { struct stp_port *p = stp->root_port; struct stp_tcn_bpdu tcn_bpdu; + if (!p) { return; } + VLOG_DBG_RL(&stp_rl, "bridge: %s, root port: %s, transmit tcn", stp->name, + p->port_name); tcn_bpdu.header.protocol_id = htons(STP_PROTOCOL_ID); tcn_bpdu.header.protocol_version = STP_PROTOCOL_VERSION; tcn_bpdu.header.bpdu_type = STP_TYPE_TCN; @@ -1367,6 +1394,9 @@ stp_message_age_timer_expiry(struct stp_port *p) OVS_REQUIRES(mutex) { struct stp *stp = p->stp; bool root = stp_is_root_bridge(stp); + + VLOG_DBG_RL(&stp_rl, "bridge: %s, port: %s, message age timer expired", + stp->name, p->port_name); stp_become_designated_port(p); stp_configuration_update(stp); stp_port_state_selection(stp); diff --git a/lib/stp.h b/lib/stp.h index 93c4904..cdc24d4 100644 --- a/lib/stp.h +++ b/lib/stp.h @@ -146,6 +146,7 @@ const char *stp_role_name(enum stp_role); void stp_received_bpdu(struct stp_port *, const void *bpdu, size_t bpdu_size); struct stp *stp_port_get_stp(struct stp_port *); +void stp_port_set_name(struct stp_port *, const char *); void stp_port_set_aux(struct stp_port *, void *); void *stp_port_get_aux(struct stp_port *); int stp_port_no(const struct stp_port *); diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 10b0cd4..53faa2c 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -2038,6 +2038,7 @@ set_stp_port(struct ofport *ofport_, sp = ofport->stp_port = stp_get_port(ofproto->stp, s->port_num); stp_port_enable(sp); + stp_port_set_name(sp, netdev_get_name(ofport->up.netdev)); stp_port_set_aux(sp, ofport); stp_port_set_priority(sp, s->priority); stp_port_set_path_cost(sp, s->path_cost); -- 1.7.9.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev