2014-08-22 09:01:34 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011-2014 M3S, Srl - Italy
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rapid Spanning Tree Protocol (IEEE 802.1D-2004) public interface.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Martino Fornasa <mf@fornasa.it>
|
|
|
|
* Daniele Venturino <daniele.venturino@m3s.it>
|
|
|
|
*
|
|
|
|
* References to IEEE 802.1D-2004 standard are enclosed in square brackets.
|
|
|
|
* E.g. [17.3], [Table 17-1], etc.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2014-09-09 09:01:16 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
#include "rstp.h"
|
|
|
|
#include "rstp-common.h"
|
|
|
|
#include "rstp-state-machines.h"
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include "byte-order.h"
|
|
|
|
#include "connectivity.h"
|
|
|
|
#include "ofpbuf.h"
|
|
|
|
#include "ofproto/ofproto.h"
|
2015-02-22 03:21:09 -08:00
|
|
|
#include "dp-packet.h"
|
2014-08-22 09:01:34 -07:00
|
|
|
#include "packets.h"
|
|
|
|
#include "seq.h"
|
|
|
|
#include "unixctl.h"
|
|
|
|
#include "util.h"
|
2014-12-15 14:10:38 +01:00
|
|
|
#include "openvswitch/vlog.h"
|
2014-08-22 09:01:34 -07:00
|
|
|
|
|
|
|
VLOG_DEFINE_THIS_MODULE(rstp);
|
|
|
|
|
2014-08-22 09:01:35 -07:00
|
|
|
struct ovs_mutex rstp_mutex = OVS_MUTEX_INITIALIZER;
|
2014-09-09 11:11:18 -07:00
|
|
|
|
2014-12-15 14:10:38 +01:00
|
|
|
static struct ovs_list all_rstps__ = OVS_LIST_INITIALIZER(&all_rstps__);
|
2014-12-15 14:10:38 +01:00
|
|
|
static struct ovs_list *const all_rstps OVS_GUARDED_BY(rstp_mutex) = &all_rstps__;
|
2014-09-09 11:11:18 -07:00
|
|
|
|
|
|
|
/* Internal use only. */
|
|
|
|
static void rstp_set_bridge_address__(struct rstp *, rstp_identifier)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_set_bridge_priority__(struct rstp *, int new_priority)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_set_bridge_ageing_time__(struct rstp *, int new_ageing_time)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_set_bridge_force_protocol_version__(struct rstp *,
|
|
|
|
enum rstp_force_protocol_version)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_set_bridge_hello_time__(struct rstp *)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_set_bridge_max_age__(struct rstp *, int new_max_age)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_set_bridge_forward_delay__(struct rstp *, int new_forward_delay)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_set_bridge_transmit_hold_count__(struct rstp *,
|
|
|
|
int new_transmit_hold_count)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_set_bridge_migrate_time__(struct rstp *)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_set_bridge_times__(struct rstp *, int new_forward_delay,
|
|
|
|
int new_hello_time, int new_max_age,
|
|
|
|
int new_message_age)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
|
|
|
|
static struct rstp_port *rstp_get_port__(struct rstp *rstp,
|
|
|
|
uint16_t port_number)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void set_port_id__(struct rstp_port *)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void update_port_enabled__(struct rstp_port *)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void set_bridge_priority__(struct rstp *)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void reinitialize_rstp__(struct rstp *)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static bool is_port_number_available__(struct rstp *, int, struct rstp_port *)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static uint16_t rstp_first_free_number__(struct rstp *, struct rstp_port *)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_initialize_port_defaults__(struct rstp_port *)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_port_set_priority__(struct rstp_port *, int priority)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_port_set_port_number__(struct rstp_port *,
|
|
|
|
uint16_t port_number)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_port_set_path_cost__(struct rstp_port *, uint32_t path_cost)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_port_set_administrative_bridge_port__(struct rstp_port *,
|
2014-11-14 14:07:51 -08:00
|
|
|
uint8_t admin_port_state,
|
|
|
|
bool initializing)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_port_set_admin_edge__(struct rstp_port *, bool admin_edge)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void rstp_port_set_auto_edge__(struct rstp_port *, bool auto_edge)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
2014-11-14 14:07:50 -08:00
|
|
|
static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port *,
|
|
|
|
enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
2014-09-09 11:11:18 -07:00
|
|
|
static void rstp_port_set_mcheck__(struct rstp_port *, bool mcheck)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
|
|
|
static void reinitialize_port__(struct rstp_port *p)
|
|
|
|
OVS_REQUIRES(rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
|
|
|
|
const char *
|
|
|
|
rstp_state_name(enum rstp_state state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case RSTP_DISABLED:
|
|
|
|
return "Disabled";
|
|
|
|
case RSTP_LEARNING:
|
|
|
|
return "Learning";
|
|
|
|
case RSTP_FORWARDING:
|
|
|
|
return "Forwarding";
|
|
|
|
case RSTP_DISCARDING:
|
|
|
|
return "Discarding";
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
rstp_port_role_name(enum rstp_port_role role)
|
|
|
|
{
|
|
|
|
switch (role) {
|
|
|
|
case ROLE_ROOT:
|
|
|
|
return "Root";
|
|
|
|
case ROLE_DESIGNATED:
|
|
|
|
return "Designated";
|
|
|
|
case ROLE_ALTERNATE:
|
|
|
|
return "Alternate";
|
|
|
|
case ROLE_BACKUP:
|
|
|
|
return "Backup";
|
|
|
|
case ROLE_DISABLED:
|
|
|
|
return "Disabled";
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 09:01:16 -07:00
|
|
|
/* Caller has to hold a reference to prevent 'rstp' from being deleted
|
2014-09-09 11:11:18 -07:00
|
|
|
* while taking a new reference. */
|
2014-08-22 09:01:34 -07:00
|
|
|
struct rstp *
|
2014-09-09 09:01:16 -07:00
|
|
|
rstp_ref(struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
if (rstp) {
|
|
|
|
ovs_refcount_ref(&rstp->ref_cnt);
|
|
|
|
}
|
|
|
|
return rstp;
|
|
|
|
}
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
/* Frees RSTP struct when reference count reaches zero. */
|
2014-08-22 09:01:34 -07:00
|
|
|
void
|
|
|
|
rstp_unref(struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-10 16:28:01 +00:00
|
|
|
if (rstp && ovs_refcount_unref_relaxed(&rstp->ref_cnt) == 1) {
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
|
|
|
|
/* Each RSTP port points back to struct rstp without holding a
|
|
|
|
* reference for that pointer. This is OK as we never move
|
|
|
|
* ports from one bridge to another, and holders always
|
|
|
|
* release their ports before releasing the bridge. This
|
|
|
|
* means that there should be not ports at this time. */
|
2014-08-22 09:01:36 -07:00
|
|
|
ovs_assert(hmap_is_empty(&rstp->ports));
|
2014-09-09 09:01:16 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
list_remove(&rstp->node);
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
free(rstp->name);
|
|
|
|
free(rstp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 09:01:16 -07:00
|
|
|
/* Returns the port number. Mutex is needed to guard against
|
|
|
|
* concurrent reinitialization (which can temporarily clear the
|
|
|
|
* port_number). */
|
2014-08-22 09:01:34 -07:00
|
|
|
int
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_port_get_number(const struct rstp_port *p)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
int number;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
number = p->port_number;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
return number;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rstp_unixctl_tcn(struct unixctl_conn *, int argc,
|
|
|
|
const char *argv[], void *aux);
|
|
|
|
|
|
|
|
/* Decrements the State Machines' timers. */
|
|
|
|
void
|
|
|
|
rstp_tick_timers(struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
decrease_rstp_port_timers__(rstp);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Processes an incoming BPDU. */
|
|
|
|
void
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_port_received_bpdu(struct rstp_port *rp, const void *bpdu,
|
|
|
|
size_t bpdu_size)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
/* Only process packets on ports that have RSTP enabled. */
|
|
|
|
if (rp && rp->rstp_state != RSTP_DISABLED) {
|
|
|
|
process_received_bpdu__(rp, bpdu, bpdu_size);
|
|
|
|
}
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rstp_init(void)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 09:01:16 -07:00
|
|
|
unixctl_command_register("rstp/tcn", "[bridge]", 0, 1, rstp_unixctl_tcn,
|
|
|
|
NULL);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Creates and returns a new RSTP instance that initially has no ports. */
|
|
|
|
struct rstp *
|
|
|
|
rstp_create(const char *name, rstp_identifier bridge_address,
|
2015-02-22 03:21:09 -08:00
|
|
|
void (*send_bpdu)(struct dp_packet *bpdu, void *port_aux,
|
2014-08-22 09:01:35 -07:00
|
|
|
void *rstp_aux),
|
2014-09-09 09:01:16 -07:00
|
|
|
void *aux)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
struct rstp *rstp;
|
|
|
|
|
|
|
|
VLOG_DBG("Creating RSTP instance");
|
|
|
|
|
|
|
|
rstp = xzalloc(sizeof *rstp);
|
|
|
|
rstp->name = xstrdup(name);
|
2014-09-09 11:11:18 -07:00
|
|
|
|
2014-08-22 09:01:36 -07:00
|
|
|
/* Initialize the ports map before calling any setters,
|
|
|
|
* so that the state machines will see an empty ports map. */
|
|
|
|
hmap_init(&rstp->ports);
|
2014-09-09 11:13:26 -07:00
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
/* Set bridge address. */
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_set_bridge_address__(rstp, bridge_address);
|
2014-08-22 09:01:34 -07:00
|
|
|
/* Set default parameters values. */
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_set_bridge_priority__(rstp, RSTP_DEFAULT_PRIORITY);
|
|
|
|
rstp_set_bridge_ageing_time__(rstp, RSTP_DEFAULT_AGEING_TIME);
|
|
|
|
rstp_set_bridge_force_protocol_version__(rstp, FPV_DEFAULT);
|
|
|
|
rstp_set_bridge_forward_delay__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY);
|
|
|
|
rstp_set_bridge_hello_time__(rstp);
|
|
|
|
rstp_set_bridge_max_age__(rstp, RSTP_DEFAULT_BRIDGE_MAX_AGE);
|
|
|
|
rstp_set_bridge_migrate_time__(rstp);
|
|
|
|
rstp_set_bridge_transmit_hold_count__(rstp,
|
|
|
|
RSTP_DEFAULT_TRANSMIT_HOLD_COUNT);
|
|
|
|
rstp_set_bridge_times__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY,
|
|
|
|
RSTP_BRIDGE_HELLO_TIME,
|
|
|
|
RSTP_DEFAULT_BRIDGE_MAX_AGE, 0);
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp->send_bpdu = send_bpdu;
|
|
|
|
rstp->aux = aux;
|
|
|
|
rstp->changes = false;
|
|
|
|
rstp->begin = true;
|
2015-09-30 10:49:52 +02:00
|
|
|
rstp->old_root_aux = NULL;
|
|
|
|
rstp->new_root_aux = NULL;
|
2014-08-22 09:01:34 -07:00
|
|
|
|
|
|
|
ovs_refcount_init(&rstp->ref_cnt);
|
2014-09-09 09:01:16 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
list_push_back(all_rstps, &rstp->node);
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-09-09 09:01:16 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
VLOG_DBG("RSTP instance creation done");
|
|
|
|
return rstp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called by rstp_set_bridge_address() and rstp_set_bridge_priority(),
|
|
|
|
* it updates the bridge priority vector according to the values passed by
|
|
|
|
* those setters.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_bridge_priority__(struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 11:13:26 -07:00
|
|
|
struct rstp_port *p;
|
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp->bridge_priority.root_bridge_id = rstp->bridge_identifier;
|
|
|
|
rstp->bridge_priority.designated_bridge_id = rstp->bridge_identifier;
|
|
|
|
VLOG_DBG("%s: new bridge identifier: "RSTP_ID_FMT"", rstp->name,
|
|
|
|
RSTP_ID_ARGS(rstp->bridge_identifier));
|
2014-08-22 09:01:35 -07:00
|
|
|
|
|
|
|
/* [17.13] When the bridge address changes, recalculates all priority
|
|
|
|
* vectors.
|
|
|
|
*/
|
2014-08-22 09:01:36 -07:00
|
|
|
HMAP_FOR_EACH (p, node, &rstp->ports) {
|
2014-09-09 11:13:26 -07:00
|
|
|
p->selected = false;
|
|
|
|
p->reselect = true;
|
2014-08-22 09:01:35 -07:00
|
|
|
}
|
|
|
|
rstp->changes = true;
|
2014-09-09 11:11:18 -07:00
|
|
|
updt_roles_tree__(rstp);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the bridge address. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_set_bridge_address__(struct rstp *rstp, rstp_identifier bridge_address)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
VLOG_DBG("%s: set bridge address to: "RSTP_ID_FMT"", rstp->name,
|
|
|
|
RSTP_ID_ARGS(bridge_address));
|
2014-11-06 16:31:15 +01:00
|
|
|
if (rstp->address != bridge_address) {
|
|
|
|
rstp->address = bridge_address;
|
|
|
|
rstp->bridge_identifier &= 0xffff000000000000ULL;
|
|
|
|
rstp->bridge_identifier |= bridge_address;
|
|
|
|
set_bridge_priority__(rstp);
|
|
|
|
}
|
2014-09-09 11:11:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the bridge address. */
|
|
|
|
void
|
|
|
|
rstp_set_bridge_address(struct rstp *rstp, rstp_identifier bridge_address)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
|
|
|
{
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp_set_bridge_address__(rstp, bridge_address);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
rstp_get_name(const struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
name = rstp->name;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
rstp_identifier
|
|
|
|
rstp_get_bridge_id(const struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
rstp_identifier bridge_id;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
bridge_id = rstp->bridge_identifier;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
return bridge_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the bridge priority. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_set_bridge_priority__(struct rstp *rstp, int new_priority)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-08-22 09:01:35 -07:00
|
|
|
new_priority = ROUND_DOWN(new_priority, RSTP_PRIORITY_STEP);
|
|
|
|
|
2014-11-06 16:31:15 +01:00
|
|
|
if (rstp->priority != new_priority
|
|
|
|
&& new_priority >= RSTP_MIN_PRIORITY
|
2014-08-22 09:01:35 -07:00
|
|
|
&& new_priority <= RSTP_MAX_PRIORITY) {
|
|
|
|
VLOG_DBG("%s: set bridge priority to %d", rstp->name, new_priority);
|
2014-08-22 09:01:34 -07:00
|
|
|
|
2014-08-22 09:01:35 -07:00
|
|
|
rstp->priority = new_priority;
|
2014-09-09 09:01:16 -07:00
|
|
|
rstp->bridge_identifier &= 0x0000ffffffffffffULL;
|
2014-08-22 09:01:35 -07:00
|
|
|
rstp->bridge_identifier |= (uint64_t)new_priority << 48;
|
2014-08-22 09:01:34 -07:00
|
|
|
set_bridge_priority__(rstp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_set_bridge_priority(struct rstp *rstp, int new_priority)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
|
|
|
{
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp_set_bridge_priority__(rstp, new_priority);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the bridge ageing time. */
|
|
|
|
static void
|
|
|
|
rstp_set_bridge_ageing_time__(struct rstp *rstp, int new_ageing_time)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 09:01:16 -07:00
|
|
|
if (new_ageing_time >= RSTP_MIN_AGEING_TIME
|
|
|
|
&& new_ageing_time <= RSTP_MAX_AGEING_TIME) {
|
2014-08-22 09:01:34 -07:00
|
|
|
VLOG_DBG("%s: set ageing time to %d", rstp->name, new_ageing_time);
|
2014-09-09 09:01:16 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp->ageing_time = new_ageing_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
void
|
|
|
|
rstp_set_bridge_ageing_time(struct rstp *rstp, int new_ageing_time)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
|
|
|
{
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp_set_bridge_ageing_time__(rstp, new_ageing_time);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
}
|
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
/* Reinitializes RSTP when switching from RSTP mode to STP mode
|
|
|
|
* or vice versa.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
reinitialize_rstp__(struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
struct rstp temp;
|
2014-08-22 09:01:36 -07:00
|
|
|
static struct hmap ports;
|
2014-09-09 11:13:26 -07:00
|
|
|
struct rstp_port *p;
|
2014-08-22 09:01:34 -07:00
|
|
|
|
|
|
|
/* Copy rstp in temp */
|
|
|
|
temp = *rstp;
|
|
|
|
ports = rstp->ports;
|
2014-09-09 09:01:16 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
/* stop and clear rstp */
|
|
|
|
memset(rstp, 0, sizeof(struct rstp));
|
|
|
|
|
|
|
|
/* Initialize rstp. */
|
|
|
|
rstp->name = temp.name;
|
2014-09-09 11:13:26 -07:00
|
|
|
|
2014-08-22 09:01:36 -07:00
|
|
|
/* Initialize the ports hmap before calling any setters,
|
2014-09-09 11:13:26 -07:00
|
|
|
* so that the state machines will see an empty ports list. */
|
2014-08-22 09:01:36 -07:00
|
|
|
hmap_init(&rstp->ports);
|
2014-09-09 11:13:26 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
/* Set bridge address. */
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_set_bridge_address__(rstp, temp.address);
|
2014-08-22 09:01:34 -07:00
|
|
|
/* Set default parameters values. */
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_set_bridge_priority__(rstp, RSTP_DEFAULT_PRIORITY);
|
|
|
|
rstp_set_bridge_ageing_time__(rstp, RSTP_DEFAULT_AGEING_TIME);
|
|
|
|
rstp_set_bridge_forward_delay__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY);
|
|
|
|
rstp_set_bridge_hello_time__(rstp);
|
|
|
|
rstp_set_bridge_max_age__(rstp, RSTP_DEFAULT_BRIDGE_MAX_AGE);
|
|
|
|
rstp_set_bridge_migrate_time__(rstp);
|
|
|
|
rstp_set_bridge_transmit_hold_count__(rstp,
|
|
|
|
RSTP_DEFAULT_TRANSMIT_HOLD_COUNT);
|
|
|
|
rstp_set_bridge_times__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY,
|
|
|
|
RSTP_BRIDGE_HELLO_TIME,
|
|
|
|
RSTP_DEFAULT_BRIDGE_MAX_AGE, 0);
|
2014-08-22 09:01:34 -07:00
|
|
|
|
|
|
|
rstp->send_bpdu = temp.send_bpdu;
|
|
|
|
rstp->aux = temp.aux;
|
|
|
|
rstp->node = temp.node;
|
|
|
|
rstp->changes = false;
|
|
|
|
rstp->begin = true;
|
2014-09-09 09:01:16 -07:00
|
|
|
|
2014-09-09 11:13:26 -07:00
|
|
|
/* Restore ports. */
|
|
|
|
rstp->ports = ports;
|
2014-09-09 09:01:16 -07:00
|
|
|
|
2014-08-22 09:01:36 -07:00
|
|
|
HMAP_FOR_EACH (p, node, &rstp->ports) {
|
2014-09-09 11:13:26 -07:00
|
|
|
reinitialize_port__(p);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
2014-09-09 11:13:26 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp->ref_cnt = temp.ref_cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the force protocol version parameter. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_set_bridge_force_protocol_version__(struct rstp *rstp,
|
2014-08-22 09:01:34 -07:00
|
|
|
enum rstp_force_protocol_version new_force_protocol_version)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
if (new_force_protocol_version != rstp->force_protocol_version &&
|
|
|
|
(new_force_protocol_version == FPV_STP_COMPATIBILITY ||
|
|
|
|
new_force_protocol_version == FPV_DEFAULT)) {
|
|
|
|
VLOG_DBG("%s: set bridge Force Protocol Version to %d", rstp->name,
|
|
|
|
new_force_protocol_version);
|
2014-09-09 11:11:18 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
/* [17.13] The Spanning Tree Protocol Entity shall be reinitialized,
|
|
|
|
* as specified by the assertion of BEGIN (17.18.1) in the state
|
|
|
|
* machine specification.
|
|
|
|
*/
|
|
|
|
reinitialize_rstp__(rstp);
|
|
|
|
rstp->force_protocol_version = new_force_protocol_version;
|
|
|
|
if (rstp->force_protocol_version < 2) {
|
|
|
|
rstp->stp_version = true;
|
|
|
|
rstp->rstp_version = false;
|
|
|
|
} else {
|
|
|
|
rstp->stp_version = false;
|
|
|
|
rstp->rstp_version = true;
|
|
|
|
}
|
|
|
|
rstp->changes = true;
|
2014-09-09 11:11:18 -07:00
|
|
|
move_rstp__(rstp);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_set_bridge_force_protocol_version(struct rstp *rstp,
|
|
|
|
enum rstp_force_protocol_version new_force_protocol_version)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
|
|
|
{
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp_set_bridge_force_protocol_version__(rstp, new_force_protocol_version);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the bridge Hello Time parameter. */
|
|
|
|
static void
|
|
|
|
rstp_set_bridge_hello_time__(struct rstp *rstp)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
VLOG_DBG("%s: set RSTP Hello Time to %d", rstp->name,
|
|
|
|
RSTP_BRIDGE_HELLO_TIME);
|
|
|
|
/* 2 is the only acceptable value. */
|
|
|
|
rstp->bridge_hello_time = RSTP_BRIDGE_HELLO_TIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the bridge max age parameter. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_set_bridge_max_age__(struct rstp *rstp, int new_max_age)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-11-14 14:07:50 -08:00
|
|
|
if (rstp->bridge_max_age != new_max_age
|
|
|
|
&& new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
|
|
|
|
&& new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
|
2014-08-22 09:01:34 -07:00
|
|
|
/* [17.13] */
|
2014-09-09 09:01:16 -07:00
|
|
|
if ((2 * (rstp->bridge_forward_delay - 1) >= new_max_age)
|
|
|
|
&& (new_max_age >= 2 * rstp->bridge_hello_time)) {
|
2014-08-22 09:01:34 -07:00
|
|
|
VLOG_DBG("%s: set RSTP bridge Max Age to %d", rstp->name,
|
|
|
|
new_max_age);
|
2014-09-09 11:11:18 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp->bridge_max_age = new_max_age;
|
|
|
|
rstp->bridge_times.max_age = new_max_age;
|
2014-11-14 14:07:50 -08:00
|
|
|
rstp->changes = true;
|
|
|
|
updt_roles_tree__(rstp);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_set_bridge_max_age(struct rstp *rstp, int new_max_age)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
|
|
|
{
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp_set_bridge_max_age__(rstp, new_max_age);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the bridge forward delay parameter. */
|
|
|
|
static void
|
|
|
|
rstp_set_bridge_forward_delay__(struct rstp *rstp, int new_forward_delay)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-11-14 14:07:50 -08:00
|
|
|
if (rstp->bridge_forward_delay != new_forward_delay
|
|
|
|
&& new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
|
|
|
|
&& new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
|
2014-08-22 09:01:34 -07:00
|
|
|
if (2 * (new_forward_delay - 1) >= rstp->bridge_max_age) {
|
|
|
|
VLOG_DBG("%s: set RSTP Forward Delay to %d", rstp->name,
|
|
|
|
new_forward_delay);
|
|
|
|
rstp->bridge_forward_delay = new_forward_delay;
|
|
|
|
rstp->bridge_times.forward_delay = new_forward_delay;
|
2014-11-14 14:07:50 -08:00
|
|
|
rstp->changes = true;
|
|
|
|
updt_roles_tree__(rstp);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_set_bridge_forward_delay(struct rstp *rstp, int new_forward_delay)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
|
|
|
{
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp_set_bridge_forward_delay__(rstp, new_forward_delay);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the bridge transmit hold count parameter. */
|
|
|
|
static void
|
|
|
|
rstp_set_bridge_transmit_hold_count__(struct rstp *rstp,
|
|
|
|
int new_transmit_hold_count)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-11-06 16:31:15 +01:00
|
|
|
if (rstp->transmit_hold_count != new_transmit_hold_count
|
|
|
|
&& new_transmit_hold_count >= RSTP_MIN_TRANSMIT_HOLD_COUNT
|
2014-09-09 09:01:16 -07:00
|
|
|
&& new_transmit_hold_count <= RSTP_MAX_TRANSMIT_HOLD_COUNT) {
|
2014-09-09 11:13:26 -07:00
|
|
|
struct rstp_port *p;
|
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
VLOG_DBG("%s: set RSTP Transmit Hold Count to %d", rstp->name,
|
|
|
|
new_transmit_hold_count);
|
|
|
|
/* Resetting txCount on all ports [17.13]. */
|
2014-09-09 11:11:18 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp->transmit_hold_count = new_transmit_hold_count;
|
2014-08-22 09:01:36 -07:00
|
|
|
HMAP_FOR_EACH (p, node, &rstp->ports) {
|
2014-09-09 11:13:26 -07:00
|
|
|
p->tx_count = 0;
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_set_bridge_transmit_hold_count(struct rstp *rstp,
|
|
|
|
int new_transmit_hold_count)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
|
|
|
{
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp_set_bridge_transmit_hold_count__(rstp, new_transmit_hold_count);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the bridge migrate time parameter. */
|
|
|
|
static void
|
|
|
|
rstp_set_bridge_migrate_time__(struct rstp *rstp)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
VLOG_DBG("%s: set RSTP Migrate Time to %d", rstp->name,
|
|
|
|
RSTP_MIGRATE_TIME);
|
|
|
|
/* 3 is the only acceptable value */
|
|
|
|
rstp->migrate_time = RSTP_MIGRATE_TIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the bridge times. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_set_bridge_times__(struct rstp *rstp, int new_forward_delay,
|
|
|
|
int new_hello_time, int new_max_age,
|
|
|
|
int new_message_age)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
VLOG_DBG("%s: set RSTP times to (%d, %d, %d, %d)", rstp->name,
|
|
|
|
new_forward_delay, new_hello_time, new_max_age, new_message_age);
|
2014-09-09 09:01:16 -07:00
|
|
|
if (new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
|
|
|
|
&& new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp->bridge_times.forward_delay = new_forward_delay;
|
2014-09-09 09:01:16 -07:00
|
|
|
}
|
|
|
|
if (new_hello_time == RSTP_BRIDGE_HELLO_TIME) {
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp->bridge_times.hello_time = new_hello_time;
|
2014-09-09 09:01:16 -07:00
|
|
|
}
|
|
|
|
if (new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
|
|
|
|
&& new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp->bridge_times.max_age = new_max_age;
|
2014-09-09 09:01:16 -07:00
|
|
|
}
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp->bridge_times.message_age = new_message_age;
|
|
|
|
}
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
/* Sets the port id, it is called by rstp_port_set_port_number__() or
|
|
|
|
* rstp_port_set_priority__().
|
2014-08-22 09:01:34 -07:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_port_id__(struct rstp_port *p)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
struct rstp *rstp;
|
|
|
|
|
|
|
|
rstp = p->rstp;
|
|
|
|
/* [9.2.7] Port identifier. */
|
|
|
|
p->port_id = p->port_number | (p->priority << 8);
|
|
|
|
VLOG_DBG("%s: new RSTP port id "RSTP_PORT_ID_FMT"", rstp->name,
|
|
|
|
p->port_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the port priority. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_port_set_priority__(struct rstp_port *port, int priority)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-11-06 16:31:15 +01:00
|
|
|
if (port->priority != priority
|
|
|
|
&& priority >= RSTP_MIN_PORT_PRIORITY
|
2014-09-09 11:11:18 -07:00
|
|
|
&& priority <= RSTP_MAX_PORT_PRIORITY) {
|
|
|
|
VLOG_DBG("%s, port %u: set RSTP port priority to %d", port->rstp->name,
|
|
|
|
port->port_number, priority);
|
|
|
|
|
|
|
|
priority -= priority % RSTP_STEP_PORT_PRIORITY;
|
|
|
|
port->priority = priority;
|
|
|
|
set_port_id__(port);
|
|
|
|
port->selected = false;
|
|
|
|
port->reselect = true;
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-22 09:01:35 -07:00
|
|
|
/* Checks if a port number is available. */
|
2014-08-22 09:01:34 -07:00
|
|
|
static bool
|
2014-08-22 09:01:35 -07:00
|
|
|
is_port_number_available__(struct rstp *rstp, int n, struct rstp_port *port)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-08-22 09:01:35 -07:00
|
|
|
if (n >= 1 && n <= RSTP_MAX_PORTS) {
|
2014-09-09 11:11:18 -07:00
|
|
|
struct rstp_port *p = rstp_get_port__(rstp, n);
|
2014-08-22 09:01:34 -07:00
|
|
|
|
2014-08-22 09:01:35 -07:00
|
|
|
return p == NULL || p == port;
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t
|
2014-08-22 09:01:35 -07:00
|
|
|
rstp_first_free_number__(struct rstp *rstp, struct rstp_port *rstp_port)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:35 -07:00
|
|
|
{
|
|
|
|
int free_number = 1;
|
2014-08-22 09:01:34 -07:00
|
|
|
|
|
|
|
while (free_number <= RSTP_MAX_PORTS) {
|
2014-08-22 09:01:35 -07:00
|
|
|
if (is_port_number_available__(rstp, free_number, rstp_port)) {
|
2014-08-22 09:01:34 -07:00
|
|
|
return free_number;
|
|
|
|
}
|
|
|
|
free_number++;
|
|
|
|
}
|
|
|
|
VLOG_DBG("%s, No free port number available.", rstp->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the port number. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_port_set_port_number__(struct rstp_port *port, uint16_t port_number)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-11-19 09:24:52 -08:00
|
|
|
int old_port_number = port->port_number;
|
|
|
|
|
2014-08-22 09:01:35 -07:00
|
|
|
/* If new_port_number is available, use it, otherwise use the first free
|
|
|
|
* available port number. */
|
2014-11-06 16:31:15 +01:00
|
|
|
if (port->port_number != port_number || port_number == 0) {
|
|
|
|
port->port_number =
|
|
|
|
is_port_number_available__(port->rstp, port_number, port)
|
|
|
|
? port_number
|
|
|
|
: rstp_first_free_number__(port->rstp, port);
|
|
|
|
|
|
|
|
if (port->port_number != old_port_number) {
|
|
|
|
set_port_id__(port);
|
|
|
|
/* [17.13] is not clear. I suppose that a port number change
|
|
|
|
* should trigger reselection like a port priority change. */
|
|
|
|
port->selected = false;
|
|
|
|
port->reselect = true;
|
|
|
|
|
|
|
|
/* Adjust the ports hmap. */
|
|
|
|
if (!hmap_node_is_null(&port->node)) {
|
|
|
|
hmap_remove(&port->rstp->ports, &port->node);
|
|
|
|
}
|
|
|
|
hmap_insert(&port->rstp->ports, &port->node,
|
|
|
|
hash_int(port->port_number, 0));
|
2014-11-19 09:24:52 -08:00
|
|
|
|
2014-11-06 16:31:15 +01:00
|
|
|
VLOG_DBG("%s: set new RSTP port number %d", port->rstp->name,
|
|
|
|
port->port_number);
|
2014-11-19 09:24:52 -08:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Converts the link speed to a port path cost [Table 17-3]. */
|
|
|
|
uint32_t
|
|
|
|
rstp_convert_speed_to_cost(unsigned int speed)
|
|
|
|
{
|
|
|
|
uint32_t value;
|
|
|
|
|
|
|
|
value = speed >= 10000000 ? 2 /* 10 Tb/s. */
|
|
|
|
: speed >= 1000000 ? 20 /* 1 Tb/s. */
|
|
|
|
: speed >= 100000 ? 200 /* 100 Gb/s. */
|
|
|
|
: speed >= 10000 ? 2000 /* 10 Gb/s. */
|
|
|
|
: speed >= 1000 ? 20000 /* 1 Gb/s. */
|
|
|
|
: speed >= 100 ? 200000 /* 100 Mb/s. */
|
|
|
|
: speed >= 10 ? 2000000 /* 10 Mb/s. */
|
|
|
|
: speed >= 1 ? 20000000 /* 1 Mb/s. */
|
|
|
|
: RSTP_DEFAULT_PORT_PATH_COST; /* 100 Mb/s. */
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the port path cost. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_port_set_path_cost__(struct rstp_port *port, uint32_t path_cost)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-11-06 16:31:15 +01:00
|
|
|
if (port->port_path_cost != path_cost
|
|
|
|
&& path_cost >= RSTP_MIN_PORT_PATH_COST
|
2014-09-09 11:11:18 -07:00
|
|
|
&& path_cost <= RSTP_MAX_PORT_PATH_COST) {
|
|
|
|
VLOG_DBG("%s, port %u, set RSTP port path cost to %d",
|
|
|
|
port->rstp->name, port->port_number, path_cost);
|
|
|
|
|
|
|
|
port->port_path_cost = path_cost;
|
|
|
|
port->selected = false;
|
|
|
|
port->reselect = true;
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Gets the root path cost. */
|
|
|
|
uint32_t
|
|
|
|
rstp_get_root_path_cost(const struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
uint32_t cost;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
cost = rstp->root_priority.root_path_cost;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
2014-11-14 14:07:50 -08:00
|
|
|
/* Finds a port which needs to flush its own MAC learning table. A NULL
|
|
|
|
* pointer is returned if no port needs to flush its MAC learning table.
|
|
|
|
* '*port' needs to be NULL in the first call to start the iteration. If
|
|
|
|
* '*port' is passed as non-NULL, it must be the value set by the last
|
2014-11-19 09:24:52 -08:00
|
|
|
* invocation of this function.
|
|
|
|
*
|
|
|
|
* This function may only be called by the thread that creates and deletes
|
|
|
|
* ports. Otherwise this function is not thread safe, as the returned
|
|
|
|
* '*port' could become stale before it is used in the next invocation. */
|
2014-11-14 14:07:50 -08:00
|
|
|
void *
|
|
|
|
rstp_check_and_reset_fdb_flush(struct rstp *rstp, struct rstp_port **port)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-11-14 14:07:50 -08:00
|
|
|
void *aux = NULL;
|
2014-08-22 09:01:34 -07:00
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-11-14 14:07:50 -08:00
|
|
|
if (*port == NULL) {
|
|
|
|
struct rstp_port *p;
|
|
|
|
|
|
|
|
HMAP_FOR_EACH (p, node, &rstp->ports) {
|
|
|
|
if (p->fdb_flush) {
|
|
|
|
aux = p->aux;
|
|
|
|
*port = p;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* continue */
|
|
|
|
struct rstp_port *p = *port;
|
|
|
|
|
|
|
|
HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
|
|
|
|
if (p->fdb_flush) {
|
|
|
|
aux = p->aux;
|
|
|
|
*port = p;
|
|
|
|
goto out;
|
|
|
|
}
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-14 14:07:50 -08:00
|
|
|
/* No port needs flushing. */
|
|
|
|
*port = NULL;
|
|
|
|
out:
|
|
|
|
/* fdb_flush should be reset by the filtering database
|
|
|
|
* once the entries are removed if rstp_version is TRUE, and
|
|
|
|
* immediately if stp_version is TRUE.*/
|
|
|
|
if (*port != NULL) {
|
|
|
|
(*port)->fdb_flush = false;
|
|
|
|
}
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-11-19 09:24:52 -08:00
|
|
|
|
2014-11-14 14:07:50 -08:00
|
|
|
return aux;
|
2014-11-19 09:24:52 -08:00
|
|
|
}
|
2014-08-22 09:01:34 -07:00
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
/* Finds a port whose state has changed, and returns the aux pointer set for
|
|
|
|
* the port. A NULL pointer is returned when no changed port is found. On
|
|
|
|
* return '*portp' contains the pointer to the rstp port that changed, or NULL
|
|
|
|
* if no changed port can be found.
|
2014-09-09 09:01:16 -07:00
|
|
|
*
|
2014-09-09 11:11:18 -07:00
|
|
|
* If '*portp' is passed as non-NULL, it must be the value set by the last
|
|
|
|
* invocation of this function.
|
|
|
|
*
|
|
|
|
* This function may only be called by the thread that creates and deletes
|
|
|
|
* ports. Otherwise this function is not thread safe, as the returned
|
|
|
|
* '*portp' could become stale before it is used in the next invocation. */
|
|
|
|
void *
|
|
|
|
rstp_get_next_changed_port_aux(struct rstp *rstp, struct rstp_port **portp)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
void *aux = NULL;
|
2014-08-22 09:01:34 -07:00
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
if (*portp == NULL) {
|
2014-09-09 09:01:16 -07:00
|
|
|
struct rstp_port *p;
|
|
|
|
|
2014-08-22 09:01:36 -07:00
|
|
|
HMAP_FOR_EACH (p, node, &rstp->ports) {
|
2014-08-22 09:01:34 -07:00
|
|
|
if (p->state_changed) {
|
|
|
|
p->state_changed = false;
|
2014-09-09 11:11:18 -07:00
|
|
|
aux = p->aux;
|
|
|
|
*portp = p;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* continue */
|
|
|
|
struct rstp_port *p = *portp;
|
|
|
|
|
2014-08-22 09:01:36 -07:00
|
|
|
HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
|
2014-09-09 11:11:18 -07:00
|
|
|
if (p->state_changed) {
|
|
|
|
p->state_changed = false;
|
|
|
|
aux = p->aux;
|
2014-08-22 09:01:34 -07:00
|
|
|
*portp = p;
|
2014-09-09 11:11:18 -07:00
|
|
|
goto out;
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-09 11:11:18 -07:00
|
|
|
/* No changed port found. */
|
2014-08-22 09:01:34 -07:00
|
|
|
*portp = NULL;
|
2014-09-09 11:11:18 -07:00
|
|
|
out:
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-11-19 09:24:52 -08:00
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
return aux;
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
2014-11-19 09:24:52 -08:00
|
|
|
bool
|
|
|
|
rstp_shift_root_learned_address(struct rstp *rstp)
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
ret = rstp->root_changed;
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
rstp_get_old_root_aux(struct rstp *rstp)
|
|
|
|
{
|
|
|
|
void *aux;
|
|
|
|
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
aux = rstp->old_root_aux;
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
|
|
|
|
return aux;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
rstp_get_new_root_aux(struct rstp *rstp)
|
|
|
|
{
|
|
|
|
void *aux;
|
|
|
|
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
aux = rstp->new_root_aux;
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
|
|
|
|
return aux;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rstp_reset_root_changed(struct rstp *rstp)
|
|
|
|
{
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp->root_changed = false;
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
}
|
|
|
|
|
2014-08-22 09:01:35 -07:00
|
|
|
/* Returns the port in 'rstp' with number 'port_number'.
|
|
|
|
*
|
|
|
|
* XXX: May only be called while concurrent deletion of ports is excluded. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static struct rstp_port *
|
|
|
|
rstp_get_port__(struct rstp *rstp, uint16_t port_number)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
struct rstp_port *port;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_assert(rstp && port_number > 0 && port_number <= RSTP_MAX_PORTS);
|
|
|
|
|
2014-08-22 09:01:36 -07:00
|
|
|
HMAP_FOR_EACH_WITH_HASH (port, node, hash_int(port_number, 0),
|
|
|
|
&rstp->ports) {
|
2014-09-09 11:13:26 -07:00
|
|
|
if (port->port_number == port_number) {
|
|
|
|
return port;
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
struct rstp_port *
|
|
|
|
rstp_get_port(struct rstp *rstp, uint16_t port_number)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
|
|
|
{
|
|
|
|
struct rstp_port *p;
|
|
|
|
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
p = rstp_get_port__(rstp, port_number);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2014-11-19 09:24:52 -08:00
|
|
|
rstp_get_port_aux__(struct rstp *rstp, uint16_t port_number)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-09-09 11:11:18 -07:00
|
|
|
{
|
|
|
|
struct rstp_port *p;
|
|
|
|
p = rstp_get_port__(rstp, port_number);
|
2014-11-19 09:24:52 -08:00
|
|
|
if (p) {
|
|
|
|
return p->aux;
|
|
|
|
}
|
|
|
|
return NULL;
|
2014-09-09 11:11:18 -07:00
|
|
|
}
|
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
/* Updates the port_enabled parameter. */
|
|
|
|
static void
|
|
|
|
update_port_enabled__(struct rstp_port *p)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-08-22 09:01:35 -07:00
|
|
|
if (p->mac_operational && p->is_administrative_bridge_port
|
|
|
|
== RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED) {
|
2014-08-22 09:01:34 -07:00
|
|
|
p->port_enabled = true;
|
|
|
|
} else {
|
|
|
|
p->port_enabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the port MAC_Operational parameter [6.4.2]. */
|
|
|
|
void
|
|
|
|
rstp_port_set_mac_operational(struct rstp_port *p, bool new_mac_operational)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
struct rstp *rstp;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp = p->rstp;
|
2014-09-09 11:11:18 -07:00
|
|
|
if (p->mac_operational != new_mac_operational) {
|
|
|
|
p->mac_operational = new_mac_operational;
|
|
|
|
update_port_enabled__(p);
|
|
|
|
rstp->changes = true;
|
|
|
|
move_rstp__(rstp);
|
|
|
|
}
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the port Administrative Bridge Port parameter. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_port_set_administrative_bridge_port__(struct rstp_port *p,
|
2014-11-14 14:07:51 -08:00
|
|
|
uint8_t admin_port_state,
|
|
|
|
bool initializing)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-11-14 14:07:50 -08:00
|
|
|
VLOG_DBG("%s, port %u: set RSTP port admin-port-state to %d",
|
|
|
|
p->rstp->name, p->port_number, admin_port_state);
|
|
|
|
|
2014-11-06 16:31:15 +01:00
|
|
|
if (p->is_administrative_bridge_port != admin_port_state
|
|
|
|
&& (admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_DISABLED
|
|
|
|
|| admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED)) {
|
2014-09-09 11:11:18 -07:00
|
|
|
p->is_administrative_bridge_port = admin_port_state;
|
2014-08-22 09:01:34 -07:00
|
|
|
update_port_enabled__(p);
|
2014-11-14 14:07:51 -08:00
|
|
|
|
|
|
|
if (!initializing) {
|
|
|
|
struct rstp *rstp = p->rstp;
|
|
|
|
|
|
|
|
rstp->changes = true;
|
|
|
|
move_rstp__(rstp);
|
|
|
|
}
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the port oper_point_to_point_mac parameter. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_port_set_oper_point_to_point_mac__(struct rstp_port *p,
|
|
|
|
uint8_t new_oper_p2p_mac)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-11-06 16:31:15 +01:00
|
|
|
if (p->oper_point_to_point_mac != new_oper_p2p_mac
|
|
|
|
&& (new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_DISABLED
|
|
|
|
|| new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_ENABLED)) {
|
2014-09-09 11:11:18 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
p->oper_point_to_point_mac = new_oper_p2p_mac;
|
|
|
|
update_port_enabled__(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initializes a port with the defaults values for its parameters. */
|
|
|
|
static void
|
2014-08-22 09:01:35 -07:00
|
|
|
rstp_initialize_port_defaults__(struct rstp_port *p)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_port_set_administrative_bridge_port__(p,
|
2014-11-14 14:07:51 -08:00
|
|
|
RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED,
|
|
|
|
true);
|
2014-09-10 16:28:00 +00:00
|
|
|
rstp_port_set_oper_point_to_point_mac__(p,
|
|
|
|
RSTP_OPER_P2P_MAC_STATE_ENABLED);
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_port_set_path_cost__(p, RSTP_DEFAULT_PORT_PATH_COST);
|
|
|
|
rstp_port_set_admin_edge__(p, false);
|
|
|
|
rstp_port_set_auto_edge__(p, true);
|
|
|
|
rstp_port_set_mcheck__(p, false);
|
2014-08-22 09:01:34 -07:00
|
|
|
|
2014-08-22 09:01:35 -07:00
|
|
|
/* Initialize state machines. */
|
2014-08-22 09:01:34 -07:00
|
|
|
p->port_receive_sm_state = PORT_RECEIVE_SM_INIT;
|
|
|
|
p->port_protocol_migration_sm_state = PORT_PROTOCOL_MIGRATION_SM_INIT;
|
|
|
|
p->bridge_detection_sm_state = BRIDGE_DETECTION_SM_INIT;
|
|
|
|
p->port_transmit_sm_state = PORT_TRANSMIT_SM_INIT;
|
|
|
|
p->port_information_sm_state = PORT_INFORMATION_SM_INIT;
|
|
|
|
p->port_role_transition_sm_state = PORT_ROLE_TRANSITION_SM_INIT;
|
|
|
|
p->port_state_transition_sm_state = PORT_STATE_TRANSITION_SM_INIT;
|
|
|
|
p->topology_change_sm_state = TOPOLOGY_CHANGE_SM_INIT;
|
|
|
|
p->uptime = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-22 09:01:35 -07:00
|
|
|
static void
|
|
|
|
reinitialize_port__(struct rstp_port *p)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
struct rstp_port temp_port;
|
|
|
|
struct rstp *rstp;
|
|
|
|
|
|
|
|
rstp = p->rstp;
|
|
|
|
temp_port = *p;
|
|
|
|
memset(p, 0, sizeof(struct rstp_port));
|
2014-09-09 11:11:18 -07:00
|
|
|
|
|
|
|
p->ref_cnt = temp_port.ref_cnt;
|
2014-08-22 09:01:34 -07:00
|
|
|
p->rstp = rstp;
|
|
|
|
p->node = temp_port.node;
|
|
|
|
p->aux = temp_port.aux;
|
|
|
|
p->port_number = temp_port.port_number;
|
|
|
|
p->port_priority = temp_port.port_priority;
|
|
|
|
p->port_id = temp_port.port_id;
|
|
|
|
p->rstp_state = RSTP_DISCARDING;
|
|
|
|
|
2014-08-22 09:01:35 -07:00
|
|
|
rstp_initialize_port_defaults__(p);
|
2014-08-22 09:01:34 -07:00
|
|
|
|
|
|
|
VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" reinitialized.", rstp->name,
|
2014-08-22 09:01:35 -07:00
|
|
|
p->port_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
reinitialize_port(struct rstp_port *p)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:35 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:35 -07:00
|
|
|
reinitialize_port__(p);
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the port state. */
|
|
|
|
void
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_port_set_state__(struct rstp_port *p, enum rstp_state state)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
struct rstp *rstp;
|
|
|
|
|
|
|
|
rstp = p->rstp;
|
|
|
|
VLOG_DBG("%s, port %u: set RSTP port state %s -> %s", rstp->name,
|
|
|
|
p->port_number,
|
|
|
|
rstp_state_name(p->rstp_state), rstp_state_name(state));
|
|
|
|
|
|
|
|
if (state != p->rstp_state && !p->state_changed) {
|
|
|
|
p->state_changed = true;
|
|
|
|
seq_change(connectivity_seq_get());
|
|
|
|
}
|
|
|
|
p->rstp_state = state;
|
|
|
|
}
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
void
|
|
|
|
rstp_port_set_state(struct rstp_port *p, enum rstp_state state)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
|
|
|
{
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp_port_set_state__(p, state);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
}
|
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
/* Adds a RSTP port. */
|
|
|
|
struct rstp_port *
|
2014-08-22 09:01:35 -07:00
|
|
|
rstp_add_port(struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:35 -07:00
|
|
|
{
|
2014-08-22 09:01:34 -07:00
|
|
|
struct rstp_port *p = xzalloc(sizeof *p);
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_refcount_init(&p->ref_cnt);
|
2014-11-19 09:24:52 -08:00
|
|
|
hmap_node_nullify(&p->node);
|
2014-09-09 11:11:18 -07:00
|
|
|
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
p->rstp = rstp;
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_port_set_priority__(p, RSTP_DEFAULT_PORT_PRIORITY);
|
|
|
|
rstp_port_set_port_number__(p, 0);
|
2014-08-22 09:01:35 -07:00
|
|
|
p->aux = NULL;
|
|
|
|
rstp_initialize_port_defaults__(p);
|
|
|
|
VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" initialized.", rstp->name,
|
|
|
|
p->port_id);
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_port_set_state__(p, RSTP_DISCARDING);
|
2014-08-22 09:01:34 -07:00
|
|
|
rstp->changes = true;
|
2014-09-09 11:11:18 -07:00
|
|
|
move_rstp__(rstp);
|
2014-08-22 09:01:34 -07:00
|
|
|
VLOG_DBG("%s: added port "RSTP_PORT_ID_FMT"", rstp->name, p->port_id);
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
/* Caller has to hold a reference to prevent 'rstp_port' from being deleted
|
|
|
|
* while taking a new reference. */
|
|
|
|
struct rstp_port *
|
|
|
|
rstp_port_ref(const struct rstp_port *rp_)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:35 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
struct rstp_port *rp = CONST_CAST(struct rstp_port *, rp_);
|
2014-08-22 09:01:34 -07:00
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
if (rp) {
|
|
|
|
ovs_refcount_ref(&rp->ref_cnt);
|
|
|
|
}
|
|
|
|
return rp;
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
/* Frees RSTP struct. This can be caller by any thread. */
|
2014-08-22 09:01:34 -07:00
|
|
|
void
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_port_unref(struct rstp_port *rp)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-10 16:28:01 +00:00
|
|
|
if (rp && ovs_refcount_unref_relaxed(&rp->ref_cnt) == 1) {
|
2014-08-22 09:01:35 -07:00
|
|
|
struct rstp *rstp;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp = rp->rstp;
|
|
|
|
rstp_port_set_state__(rp, RSTP_DISABLED);
|
2014-08-22 09:01:36 -07:00
|
|
|
hmap_remove(&rstp->ports, &rp->node);
|
2014-09-09 11:13:26 -07:00
|
|
|
VLOG_DBG("%s: removed port "RSTP_PORT_ID_FMT"", rstp->name,
|
|
|
|
rp->port_id);
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
free(rp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the port Admin Edge parameter. */
|
|
|
|
static void
|
|
|
|
rstp_port_set_admin_edge__(struct rstp_port *port, bool admin_edge)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
|
|
|
{
|
|
|
|
if (port->admin_edge != admin_edge) {
|
|
|
|
VLOG_DBG("%s, port %u: set RSTP Admin Edge to %d", port->rstp->name,
|
|
|
|
port->port_number, admin_edge);
|
|
|
|
|
|
|
|
port->admin_edge = admin_edge;
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the port Auto Edge parameter. */
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_port_set_auto_edge__(struct rstp_port *port, bool auto_edge)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
if (port->auto_edge != auto_edge) {
|
|
|
|
VLOG_DBG("%s, port %u: set RSTP Auto Edge to %d", port->rstp->name,
|
|
|
|
port->port_number, auto_edge);
|
2014-08-22 09:01:35 -07:00
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
port->auto_edge = auto_edge;
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-14 14:07:50 -08:00
|
|
|
/* Sets the port admin_point_to_point_mac parameter. */
|
|
|
|
static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port *port,
|
|
|
|
enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
|
|
|
{
|
|
|
|
VLOG_DBG("%s, port %u: set RSTP port admin-point-to-point-mac to %d",
|
|
|
|
port->rstp->name, port->port_number, admin_p2p_mac_state);
|
2014-11-06 16:31:15 +01:00
|
|
|
if (port->admin_point_to_point_mac != admin_p2p_mac_state) {
|
|
|
|
if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_TRUE) {
|
|
|
|
port->admin_point_to_point_mac = admin_p2p_mac_state;
|
|
|
|
rstp_port_set_oper_point_to_point_mac__(
|
|
|
|
port, RSTP_OPER_P2P_MAC_STATE_ENABLED);
|
|
|
|
} else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_FALSE) {
|
|
|
|
port->admin_point_to_point_mac = admin_p2p_mac_state;
|
|
|
|
rstp_port_set_oper_point_to_point_mac__(
|
|
|
|
port, RSTP_OPER_P2P_MAC_STATE_DISABLED);
|
|
|
|
} else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_AUTO) {
|
|
|
|
/* If adminPointToPointMAC is set to Auto, then the value of
|
|
|
|
* operPointToPointMAC is determined in accordance with the
|
|
|
|
* specific procedures defined for the MAC entity concerned, as
|
|
|
|
* defined in 6.5. If these procedures determine that the MAC
|
|
|
|
* entity is connected to a point-to-point LAN, then
|
|
|
|
* operPointToPointMAC is set TRUE; otherwise it is set FALSE.
|
|
|
|
* In the absence of a specific definition of how to determine
|
|
|
|
* whether the MAC is connected to a point-to-point LAN or not,
|
|
|
|
* the value of operPointToPointMAC shall be FALSE. */
|
|
|
|
port->admin_point_to_point_mac = admin_p2p_mac_state;
|
|
|
|
rstp_port_set_oper_point_to_point_mac__(
|
|
|
|
port, RSTP_OPER_P2P_MAC_STATE_DISABLED);
|
|
|
|
}
|
2014-11-14 14:07:50 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
/* Sets the port mcheck parameter.
|
|
|
|
* [17.19.13] May be set by management to force the Port Protocol Migration
|
|
|
|
* state machine to transmit RST BPDUs for a MigrateTime (17.13.9) period, to
|
|
|
|
* test whether all STP Bridges (17.4) on the attached LAN have been removed
|
|
|
|
* and the Port can continue to transmit RSTP BPDUs. Setting mcheck has no
|
|
|
|
* effect if stpVersion (17.20.12) is TRUE, i.e., the Bridge is operating in
|
2014-09-09 11:11:18 -07:00
|
|
|
* STP Compatibility mode.
|
2014-08-22 09:01:34 -07:00
|
|
|
*/
|
2014-09-09 11:11:18 -07:00
|
|
|
static void
|
|
|
|
rstp_port_set_mcheck__(struct rstp_port *port, bool mcheck)
|
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
if (mcheck == true && port->rstp->force_protocol_version >= 2) {
|
|
|
|
port->mcheck = true;
|
2014-08-22 09:01:34 -07:00
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
VLOG_DBG("%s, port %u: set RSTP mcheck to %d", port->rstp->name,
|
|
|
|
port->port_number, mcheck);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the designated bridge id. */
|
|
|
|
rstp_identifier
|
|
|
|
rstp_get_designated_id(const struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
rstp_identifier designated_id;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
designated_id = rstp->root_priority.designated_bridge_id;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:35 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
return designated_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the root bridge id. */
|
|
|
|
rstp_identifier
|
|
|
|
rstp_get_root_id(const struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
rstp_identifier root_id;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
root_id = rstp->root_priority.root_bridge_id;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:35 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
return root_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the designated port id. */
|
|
|
|
uint16_t
|
|
|
|
rstp_get_designated_port_id(const struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
uint16_t designated_port_id;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
designated_port_id = rstp->root_priority.designated_port_id;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:35 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
return designated_port_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the bridge port id. */
|
|
|
|
uint16_t
|
|
|
|
rstp_get_bridge_port_id(const struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
uint16_t bridge_port_id;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
bridge_port_id = rstp->root_priority.bridge_port_id;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:35 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
return bridge_port_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns true if the bridge believes to the be root of the spanning tree,
|
|
|
|
* false otherwise.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
rstp_is_root_bridge(const struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
bool is_root;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
is_root = rstp->bridge_identifier ==
|
|
|
|
rstp->root_priority.designated_bridge_id;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:35 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
return is_root;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the bridge ID of the bridge currently believed to be the root. */
|
|
|
|
rstp_identifier
|
|
|
|
rstp_get_designated_root(const struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
rstp_identifier designated_root;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
designated_root = rstp->root_priority.designated_bridge_id;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:35 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
return designated_root;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the port connecting 'rstp' to the root bridge, or a null pointer if
|
|
|
|
* there is no such port.
|
|
|
|
*/
|
|
|
|
struct rstp_port *
|
|
|
|
rstp_get_root_port(struct rstp *rstp)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
struct rstp_port *p;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:36 -07:00
|
|
|
HMAP_FOR_EACH (p, node, &rstp->ports) {
|
2014-09-09 11:13:26 -07:00
|
|
|
if (p->port_id == rstp->root_port_id) {
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
return p;
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the state of port 'p'. */
|
|
|
|
enum rstp_state
|
|
|
|
rstp_port_get_state(const struct rstp_port *p)
|
2014-11-19 09:24:52 -08:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
enum rstp_state state;
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
state = p->rstp_state;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:35 -07:00
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
/* Retrieves port status. */
|
2014-08-22 09:01:34 -07:00
|
|
|
void
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_port_get_status(const struct rstp_port *p, uint16_t *id,
|
|
|
|
enum rstp_state *state, enum rstp_port_role *role,
|
2014-11-13 14:55:25 -08:00
|
|
|
rstp_identifier *designated_bridge_id,
|
|
|
|
uint16_t *designated_port_id,
|
|
|
|
uint32_t *designated_path_cost, int *tx_count,
|
|
|
|
int *rx_count, int *error_count, int *uptime)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
*id = p->port_id;
|
|
|
|
*state = p->rstp_state;
|
|
|
|
*role = p->role;
|
|
|
|
|
2014-11-13 14:55:25 -08:00
|
|
|
*designated_bridge_id = p->port_priority.designated_bridge_id;
|
|
|
|
*designated_port_id = p->port_priority.designated_port_id;
|
|
|
|
*designated_path_cost = p->port_priority.root_path_cost;
|
|
|
|
|
2014-08-22 09:01:34 -07:00
|
|
|
*tx_count = p->tx_count;
|
|
|
|
*rx_count = p->rx_rstp_bpdu_cnt;
|
|
|
|
*error_count = p->error_count;
|
|
|
|
*uptime = p->uptime;
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_port_set(struct rstp_port *port, uint16_t port_num, int priority,
|
|
|
|
uint32_t path_cost, bool is_admin_edge, bool is_auto_edge,
|
2014-11-14 14:07:50 -08:00
|
|
|
enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state,
|
|
|
|
bool admin_port_state, bool do_mcheck, void *aux)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
port->aux = aux;
|
|
|
|
rstp_port_set_priority__(port, priority);
|
|
|
|
rstp_port_set_port_number__(port, port_num);
|
|
|
|
rstp_port_set_path_cost__(port, path_cost);
|
|
|
|
rstp_port_set_admin_edge__(port, is_admin_edge);
|
|
|
|
rstp_port_set_auto_edge__(port, is_auto_edge);
|
2014-11-14 14:07:50 -08:00
|
|
|
rstp_port_set_admin_point_to_point_mac__(port, admin_p2p_mac_state);
|
2014-11-14 14:07:51 -08:00
|
|
|
rstp_port_set_administrative_bridge_port__(port, admin_port_state, false);
|
2014-09-09 11:11:18 -07:00
|
|
|
rstp_port_set_mcheck__(port, do_mcheck);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
/* Individual setters only used by test-rstp.c. */
|
|
|
|
void
|
|
|
|
rstp_port_set_priority(struct rstp_port *port, int priority)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp_port_set_priority__(port, priority);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
}
|
2014-08-22 09:01:34 -07:00
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
void
|
|
|
|
rstp_port_set_path_cost(struct rstp_port *port, uint32_t path_cost)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
|
|
|
{
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
rstp_port_set_path_cost__(port, path_cost);
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
|
|
|
}
|
2014-08-22 09:01:35 -07:00
|
|
|
|
2014-09-09 11:11:18 -07:00
|
|
|
void
|
|
|
|
rstp_port_set_aux(struct rstp_port *port, void *aux)
|
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
|
|
|
{
|
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
|
|
|
port->aux = aux;
|
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Unixctl. */
|
|
|
|
static struct rstp *
|
2014-08-22 09:01:35 -07:00
|
|
|
rstp_find(const char *name)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_REQUIRES(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
|
|
|
struct rstp *rstp;
|
|
|
|
|
|
|
|
LIST_FOR_EACH (rstp, node, all_rstps) {
|
|
|
|
if (!strcmp(rstp->name, name)) {
|
|
|
|
return rstp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rstp_unixctl_tcn(struct unixctl_conn *conn, int argc,
|
|
|
|
const char *argv[], void *aux OVS_UNUSED)
|
2014-09-09 11:11:18 -07:00
|
|
|
OVS_EXCLUDED(rstp_mutex)
|
2014-08-22 09:01:34 -07:00
|
|
|
{
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_lock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
if (argc > 1) {
|
|
|
|
struct rstp *rstp = rstp_find(argv[1]);
|
|
|
|
if (!rstp) {
|
|
|
|
unixctl_command_reply_error(conn, "No such RSTP object");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
rstp->changes = true;
|
2014-09-09 11:11:18 -07:00
|
|
|
move_rstp__(rstp);
|
2014-08-22 09:01:34 -07:00
|
|
|
} else {
|
|
|
|
struct rstp *rstp;
|
|
|
|
LIST_FOR_EACH (rstp, node, all_rstps) {
|
|
|
|
rstp->changes = true;
|
2014-09-09 11:11:18 -07:00
|
|
|
move_rstp__(rstp);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
unixctl_command_reply(conn, "OK");
|
|
|
|
|
|
|
|
out:
|
2014-09-09 11:11:18 -07:00
|
|
|
ovs_mutex_unlock(&rstp_mutex);
|
2014-08-22 09:01:34 -07:00
|
|
|
}
|