Skip to content

Commit

Permalink
stp: Add more logging points for debug.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
yew011 committed Jul 22, 2014
1 parent 222f045 commit 1130627
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/stp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -795,6 +804,18 @@ stp_port_get_stp(struct stp_port *p)
return stp;
}

void
stp_port_set_name(struct stp_port *p, const char *name)
{
char *old;

ovs_mutex_lock(&mutex);
old = p->port_name;
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
Expand Down Expand Up @@ -1019,6 +1040,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;
Expand Down Expand Up @@ -1049,6 +1072,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);
}
Expand Down Expand Up @@ -1119,9 +1144,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;
Expand Down Expand Up @@ -1367,6 +1395,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);
Expand Down
1 change: 1 addition & 0 deletions lib/stp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
1 change: 1 addition & 0 deletions ofproto/ofproto-dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1130627

Please sign in to comment.