/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <inttypes.h>
#include <stdlib.h>
#include "byte-order.h"
+#include "connectivity.h"
#include "ofpbuf.h"
#include "packets.h"
+#include "seq.h"
#include "unixctl.h"
#include "util.h"
#include "vlog.h"
void (*send_bpdu)(struct ofpbuf *bpdu, int port_no, void *aux);
void *aux;
- atomic_int ref_cnt;
+ struct ovs_refcount ref_cnt;
};
static struct ovs_mutex mutex;
p->path_cost = 19; /* Recommended default for 100 Mb/s link. */
stp_initialize_port(p, STP_DISABLED);
}
- atomic_init(&stp->ref_cnt, 1);
+ ovs_refcount_init(&stp->ref_cnt);
list_push_back(all_stps, &stp->node);
ovs_mutex_unlock(&mutex);
{
struct stp *stp = CONST_CAST(struct stp *, stp_);
if (stp) {
- int orig;
- atomic_add(&stp->ref_cnt, 1, &orig);
- ovs_assert(orig > 0);
+ ovs_refcount_ref(&stp->ref_cnt);
}
return stp;
}
void
stp_unref(struct stp *stp)
{
- int orig;
-
- if (!stp) {
- return;
- }
-
- atomic_sub(&stp->ref_cnt, 1, &orig);
- ovs_assert(orig > 0);
- if (orig == 1) {
+ if (stp && ovs_refcount_unref(&stp->ref_cnt) == 1) {
ovs_mutex_lock(&mutex);
list_remove(&stp->node);
ovs_mutex_unlock(&mutex);
case STP_BLOCKING:
return "blocking";
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
return (state & (STP_DISABLED | STP_LEARNING | STP_FORWARDING)) != 0;
}
+/* Returns true if 'state' is one in which rx&tx bpdu should be done on
+ * on a port, false otherwise. */
+bool
+stp_listen_in_state(enum stp_state state)
+{
+ return (state &
+ (STP_LISTENING | STP_LEARNING | STP_FORWARDING)) != 0;
+}
+
/* Returns the name for the given 'role' (for use in debugging and log
* messages). */
const char *
case STP_ROLE_DISABLED:
return "disabled";
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
}
if (bpdu_size < sizeof(struct stp_bpdu_header)) {
- VLOG_WARN("%s: received runt %zu-byte BPDU", stp->name, bpdu_size);
+ VLOG_WARN("%s: received runt %"PRIuSIZE"-byte BPDU", stp->name, bpdu_size);
p->error_count++;
goto out;
}
switch (header->bpdu_type) {
case STP_TYPE_CONFIG:
if (bpdu_size < sizeof(struct stp_config_bpdu)) {
- VLOG_WARN("%s: received config BPDU with invalid size %zu",
+ VLOG_WARN("%s: received config BPDU with invalid size %"PRIuSIZE,
stp->name, bpdu_size);
p->error_count++;
goto out;
case STP_TYPE_TCN:
if (bpdu_size != sizeof(struct stp_tcn_bpdu)) {
- VLOG_WARN("%s: received TCN BPDU with invalid size %zu",
+ VLOG_WARN("%s: received TCN BPDU with invalid size %"PRIuSIZE,
stp->name, bpdu_size);
p->error_count++;
goto out;
{
stp_root_selection(stp);
stp_designated_port_selection(stp);
+ seq_change(connectivity_seq_get());
}
static bool
if (p < p->stp->first_changed_port) {
p->stp->first_changed_port = p;
}
+ seq_change(connectivity_seq_get());
}
p->state = state;
}
}
stp->fdb_needs_flush = true;
stp->topology_change_detected = true;
+ seq_change(connectivity_seq_get());
VLOG_INFO_RL(&rl, "%s: detected topology change.", stp->name);
}
pkt = ofpbuf_new(ETH_HEADER_LEN + LLC_HEADER_LEN + bpdu_size);
pkt->l2 = eth = ofpbuf_put_zeros(pkt, sizeof *eth);
llc = ofpbuf_put_zeros(pkt, sizeof *llc);
- pkt->l3 = ofpbuf_put(pkt, bpdu, bpdu_size);
+ ofpbuf_set_l3(pkt, ofpbuf_put(pkt, bpdu, bpdu_size));
/* 802.2 header. */
memcpy(eth->eth_dst, eth_addr_stp, ETH_ADDR_LEN);
/* p->stp->send_bpdu() must fill in source address. */
- eth->eth_type = htons(pkt->size - ETH_HEADER_LEN);
+ eth->eth_type = htons(ofpbuf_size(pkt) - ETH_HEADER_LEN);
/* LLC header. */
llc->llc_dsap = STP_LLC_DSAP;