2015-03-29 15:49:29 -07:00
|
|
|
|
/* Copyright (c) 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
|
2011-02-28 14:48:06 -08:00
|
|
|
|
*
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
#include "lacp.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
2013-12-13 03:33:47 +00:00
|
|
|
|
#include "connectivity.h"
|
2016-03-03 10:20:46 -08:00
|
|
|
|
#include "openvswitch/dynamic-string.h"
|
2011-02-28 14:48:06 -08:00
|
|
|
|
#include "hash.h"
|
2016-07-12 16:37:34 -05:00
|
|
|
|
#include "openvswitch/hmap.h"
|
2015-02-22 03:21:09 -08:00
|
|
|
|
#include "dp-packet.h"
|
2015-03-29 15:49:29 -07:00
|
|
|
|
#include "ovs-atomic.h"
|
2011-02-28 14:48:06 -08:00
|
|
|
|
#include "packets.h"
|
2017-11-03 13:53:53 +08:00
|
|
|
|
#include "openvswitch/poll-loop.h"
|
2013-12-13 03:33:47 +00:00
|
|
|
|
#include "seq.h"
|
2016-07-12 16:37:34 -05:00
|
|
|
|
#include "openvswitch/shash.h"
|
2011-03-31 13:54:15 -07:00
|
|
|
|
#include "timer.h"
|
2011-02-28 14:48:06 -08:00
|
|
|
|
#include "timeval.h"
|
|
|
|
|
|
#include "unixctl.h"
|
2014-12-15 14:10:38 +01:00
|
|
|
|
#include "openvswitch/vlog.h"
|
2016-07-12 16:37:34 -05:00
|
|
|
|
#include "util.h"
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
|
|
|
|
|
VLOG_DEFINE_THIS_MODULE(lacp);
|
|
|
|
|
|
|
2011-08-30 18:17:27 -07:00
|
|
|
|
/* Masks for lacp_info state member. */
|
|
|
|
|
|
#define LACP_STATE_ACT 0x01 /* Activity. Active or passive? */
|
|
|
|
|
|
#define LACP_STATE_TIME 0x02 /* Timeout. Short or long timeout? */
|
|
|
|
|
|
#define LACP_STATE_AGG 0x04 /* Aggregation. Is the link is bondable? */
|
|
|
|
|
|
#define LACP_STATE_SYNC 0x08 /* Synchronization. Is the link in up to date? */
|
|
|
|
|
|
#define LACP_STATE_COL 0x10 /* Collecting. Is the link receiving frames? */
|
|
|
|
|
|
#define LACP_STATE_DIST 0x20 /* Distributing. Is the link sending frames? */
|
|
|
|
|
|
#define LACP_STATE_DEF 0x40 /* Defaulted. Using default partner info? */
|
|
|
|
|
|
#define LACP_STATE_EXP 0x80 /* Expired. Using expired partner info? */
|
|
|
|
|
|
|
|
|
|
|
|
#define LACP_FAST_TIME_TX 1000 /* Fast transmission rate. */
|
|
|
|
|
|
#define LACP_SLOW_TIME_TX 30000 /* Slow transmission rate. */
|
|
|
|
|
|
#define LACP_RX_MULTIPLIER 3 /* Multiply by TX rate to get RX rate. */
|
|
|
|
|
|
|
|
|
|
|
|
#define LACP_INFO_LEN 15
|
2013-07-17 12:08:25 -07:00
|
|
|
|
OVS_PACKED(
|
2011-08-30 18:17:27 -07:00
|
|
|
|
struct lacp_info {
|
|
|
|
|
|
ovs_be16 sys_priority; /* System priority. */
|
2015-08-28 14:55:11 -07:00
|
|
|
|
struct eth_addr sys_id; /* System ID. */
|
2011-08-30 18:17:27 -07:00
|
|
|
|
ovs_be16 key; /* Operational key. */
|
|
|
|
|
|
ovs_be16 port_priority; /* Port priority. */
|
|
|
|
|
|
ovs_be16 port_id; /* Port ID. */
|
|
|
|
|
|
uint8_t state; /* State mask. See LACP_STATE macros. */
|
2013-07-17 12:08:25 -07:00
|
|
|
|
});
|
2011-08-30 18:17:27 -07:00
|
|
|
|
BUILD_ASSERT_DECL(LACP_INFO_LEN == sizeof(struct lacp_info));
|
|
|
|
|
|
|
|
|
|
|
|
#define LACP_PDU_LEN 110
|
|
|
|
|
|
struct lacp_pdu {
|
|
|
|
|
|
uint8_t subtype; /* Always 1. */
|
|
|
|
|
|
uint8_t version; /* Always 1. */
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t actor_type; /* Always 1. */
|
|
|
|
|
|
uint8_t actor_len; /* Always 20. */
|
|
|
|
|
|
struct lacp_info actor; /* LACP actor information. */
|
|
|
|
|
|
uint8_t z1[3]; /* Reserved. Always 0. */
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t partner_type; /* Always 2. */
|
|
|
|
|
|
uint8_t partner_len; /* Always 20. */
|
|
|
|
|
|
struct lacp_info partner; /* LACP partner information. */
|
|
|
|
|
|
uint8_t z2[3]; /* Reserved. Always 0. */
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t collector_type; /* Always 3. */
|
|
|
|
|
|
uint8_t collector_len; /* Always 16. */
|
|
|
|
|
|
ovs_be16 collector_delay; /* Maximum collector delay. Set to UINT16_MAX. */
|
|
|
|
|
|
uint8_t z3[64]; /* Combination of several fields. Always 0. */
|
2015-06-16 08:47:34 -07:00
|
|
|
|
};
|
2011-08-30 18:17:27 -07:00
|
|
|
|
BUILD_ASSERT_DECL(LACP_PDU_LEN == sizeof(struct lacp_pdu));
|
|
|
|
|
|
|
|
|
|
|
|
/* Implementation. */
|
|
|
|
|
|
|
2011-02-28 14:48:06 -08:00
|
|
|
|
enum slave_status {
|
|
|
|
|
|
LACP_CURRENT, /* Current State. Partner up to date. */
|
|
|
|
|
|
LACP_EXPIRED, /* Expired State. Partner out of date. */
|
|
|
|
|
|
LACP_DEFAULTED, /* Defaulted State. No partner. */
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct lacp {
|
2014-12-15 14:10:38 +01:00
|
|
|
|
struct ovs_list node; /* Node in all_lacps list. */
|
2011-02-28 14:48:06 -08:00
|
|
|
|
char *name; /* Name of this lacp object. */
|
2015-08-28 14:55:11 -07:00
|
|
|
|
struct eth_addr sys_id; /* System ID. */
|
2011-02-28 14:48:06 -08:00
|
|
|
|
uint16_t sys_priority; /* System Priority. */
|
|
|
|
|
|
bool active; /* Active or Passive. */
|
|
|
|
|
|
|
|
|
|
|
|
struct hmap slaves; /* Slaves this LACP object controls. */
|
|
|
|
|
|
struct slave *key_slave; /* Slave whose ID will be the aggregation key. */
|
|
|
|
|
|
|
2012-04-16 14:55:58 -07:00
|
|
|
|
bool fast; /* True if using fast probe interval. */
|
2011-02-28 14:48:06 -08:00
|
|
|
|
bool negotiated; /* True if LACP negotiations were successful. */
|
|
|
|
|
|
bool update; /* True if lacp_update() needs to be called. */
|
2013-11-04 23:07:10 +00:00
|
|
|
|
bool fallback_ab; /* True if fallback to active-backup on LACP failure. */
|
2013-06-18 16:44:23 -07:00
|
|
|
|
|
2013-12-27 19:39:24 -08:00
|
|
|
|
struct ovs_refcount ref_cnt;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct slave {
|
|
|
|
|
|
void *aux; /* Handle used to identify this slave. */
|
|
|
|
|
|
struct hmap_node node; /* Node in master's slaves map. */
|
|
|
|
|
|
|
|
|
|
|
|
struct lacp *lacp; /* LACP object containing this slave. */
|
|
|
|
|
|
uint16_t port_id; /* Port ID. */
|
|
|
|
|
|
uint16_t port_priority; /* Port Priority. */
|
2011-04-26 15:39:58 -07:00
|
|
|
|
uint16_t key; /* Aggregation Key. 0 if default. */
|
2011-02-28 14:48:06 -08:00
|
|
|
|
char *name; /* Name of this slave. */
|
|
|
|
|
|
|
|
|
|
|
|
enum slave_status status; /* Slave status. */
|
|
|
|
|
|
bool attached; /* Attached. Traffic may flow. */
|
|
|
|
|
|
struct lacp_info partner; /* Partner information. */
|
2011-03-08 18:32:58 -08:00
|
|
|
|
struct lacp_info ntt_actor; /* Used to decide if we Need To Transmit. */
|
2011-03-31 13:54:15 -07:00
|
|
|
|
struct timer tx; /* Next message transmission timer. */
|
|
|
|
|
|
struct timer rx; /* Expected message receive timer. */
|
2014-06-27 11:19:59 -07:00
|
|
|
|
|
2018-04-18 23:57:43 +05:30
|
|
|
|
uint32_t count_rx_pdus; /* dot3adAggPortStatsLACPDUsRx */
|
|
|
|
|
|
uint32_t count_rx_pdus_bad; /* dot3adAggPortStatsIllegalRx */
|
|
|
|
|
|
uint32_t count_tx_pdus; /* dot3adAggPortStatsLACPDUsTx */
|
|
|
|
|
|
uint32_t count_link_expired; /* Num of times link expired */
|
|
|
|
|
|
uint32_t count_link_defaulted; /* Num of times link defaulted */
|
|
|
|
|
|
uint32_t count_carrier_changed; /* Num of times link status changed */
|
2011-02-28 14:48:06 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
2013-07-22 18:35:28 -07:00
|
|
|
|
static struct ovs_mutex mutex;
|
2014-12-15 14:10:38 +01:00
|
|
|
|
static struct ovs_list all_lacps__ = OVS_LIST_INITIALIZER(&all_lacps__);
|
2014-12-15 14:10:38 +01:00
|
|
|
|
static struct ovs_list *const all_lacps OVS_GUARDED_BY(mutex) = &all_lacps__;
|
2013-07-22 18:35:28 -07:00
|
|
|
|
|
2013-08-08 15:14:19 -07:00
|
|
|
|
static void lacp_update_attached(struct lacp *) OVS_REQUIRES(mutex);
|
2013-07-22 18:35:28 -07:00
|
|
|
|
|
2013-08-08 15:14:19 -07:00
|
|
|
|
static void slave_destroy(struct slave *) OVS_REQUIRES(mutex);
|
|
|
|
|
|
static void slave_set_defaulted(struct slave *) OVS_REQUIRES(mutex);
|
|
|
|
|
|
static void slave_set_expired(struct slave *) OVS_REQUIRES(mutex);
|
2013-07-22 18:35:28 -07:00
|
|
|
|
static void slave_get_actor(struct slave *, struct lacp_info *actor)
|
2013-08-08 15:14:19 -07:00
|
|
|
|
OVS_REQUIRES(mutex);
|
2013-07-22 18:35:28 -07:00
|
|
|
|
static void slave_get_priority(struct slave *, struct lacp_info *priority)
|
2013-08-08 15:14:19 -07:00
|
|
|
|
OVS_REQUIRES(mutex);
|
2013-07-22 18:35:28 -07:00
|
|
|
|
static bool slave_may_tx(const struct slave *)
|
2013-08-08 15:14:19 -07:00
|
|
|
|
OVS_REQUIRES(mutex);
|
2013-07-22 18:35:28 -07:00
|
|
|
|
static struct slave *slave_lookup(const struct lacp *, const void *slave)
|
2013-08-08 15:14:19 -07:00
|
|
|
|
OVS_REQUIRES(mutex);
|
2013-07-22 18:35:28 -07:00
|
|
|
|
static bool info_tx_equal(struct lacp_info *, struct lacp_info *)
|
2013-08-08 15:14:19 -07:00
|
|
|
|
OVS_REQUIRES(mutex);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2011-12-02 15:29:19 -08:00
|
|
|
|
static unixctl_cb_func lacp_unixctl_show;
|
2018-04-18 23:57:43 +05:30
|
|
|
|
static unixctl_cb_func lacp_unixctl_show_stats;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2011-04-18 12:33:14 -07:00
|
|
|
|
/* Populates 'pdu' with a LACP PDU comprised of 'actor' and 'partner'. */
|
2011-08-30 18:17:27 -07:00
|
|
|
|
static void
|
2011-04-18 12:33:14 -07:00
|
|
|
|
compose_lacp_pdu(const struct lacp_info *actor,
|
|
|
|
|
|
const struct lacp_info *partner, struct lacp_pdu *pdu)
|
|
|
|
|
|
{
|
|
|
|
|
|
memset(pdu, 0, sizeof *pdu);
|
|
|
|
|
|
|
|
|
|
|
|
pdu->subtype = 1;
|
|
|
|
|
|
pdu->version = 1;
|
|
|
|
|
|
|
|
|
|
|
|
pdu->actor_type = 1;
|
|
|
|
|
|
pdu->actor_len = 20;
|
|
|
|
|
|
pdu->actor = *actor;
|
|
|
|
|
|
|
|
|
|
|
|
pdu->partner_type = 2;
|
|
|
|
|
|
pdu->partner_len = 20;
|
|
|
|
|
|
pdu->partner = *partner;
|
|
|
|
|
|
|
|
|
|
|
|
pdu->collector_type = 3;
|
|
|
|
|
|
pdu->collector_len = 16;
|
|
|
|
|
|
pdu->collector_delay = htons(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Parses 'b' which represents a packet containing a LACP PDU. This function
|
|
|
|
|
|
* returns NULL if 'b' is malformed, or does not represent a LACP PDU format
|
|
|
|
|
|
* supported by OVS. Otherwise, it returns a pointer to the lacp_pdu contained
|
|
|
|
|
|
* within 'b'. */
|
2011-08-30 18:17:27 -07:00
|
|
|
|
static const struct lacp_pdu *
|
2015-02-22 03:21:09 -08:00
|
|
|
|
parse_lacp_packet(const struct dp_packet *p)
|
2011-04-18 12:33:14 -07:00
|
|
|
|
{
|
|
|
|
|
|
const struct lacp_pdu *pdu;
|
|
|
|
|
|
|
2015-02-22 03:21:09 -08:00
|
|
|
|
pdu = dp_packet_at(p, (uint8_t *)dp_packet_l3(p) - (uint8_t *)dp_packet_data(p),
|
lib/ofpbuf: Compact
This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit
systems, or from 52 to 36 bytes on 32-bit systems (counting in the
'l7' removal from an earlier patch). This may help contribute to
cache efficiency, and will speed up initializing, copying and
manipulating ofpbufs. This is potentially important for the DPDK
datapath, but the rest of the code base may also see a little benefit.
Changes are:
- Remove 'l7' pointer (previous patch).
- Use offsets instead of layer pointers for l2_5, l3, and l4 using
'l2' as basis. Usually 'data' is the same as 'l2', but this is not
always the case (e.g., when parsing or constructing a packet), so it
can not be easily used as the offset basis. Also, packet parsing is
faster if we do not need to maintain the offsets each time we pull
data from the ofpbuf.
- Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for
largest possible messages/packets.
- Use packed enum for 'source'.
- Rearrange to avoid unnecessary padding.
- Remove 'private_p', which was used only in two cases, both of which
had the invariant ('l2' == 'data'), so we can temporarily use 'l2'
as a private pointer.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-03-24 09:17:01 -07:00
|
|
|
|
LACP_PDU_LEN);
|
2011-04-18 12:33:14 -07:00
|
|
|
|
|
|
|
|
|
|
if (pdu && pdu->subtype == 1
|
|
|
|
|
|
&& pdu->actor_type == 1 && pdu->actor_len == 20
|
|
|
|
|
|
&& pdu->partner_type == 2 && pdu->partner_len == 20) {
|
|
|
|
|
|
return pdu;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* LACP Protocol Implementation. */
|
|
|
|
|
|
|
2011-02-28 14:48:06 -08:00
|
|
|
|
/* Initializes the lacp module. */
|
|
|
|
|
|
void
|
|
|
|
|
|
lacp_init(void)
|
|
|
|
|
|
{
|
2011-12-02 15:29:19 -08:00
|
|
|
|
unixctl_command_register("lacp/show", "[port]", 0, 1,
|
|
|
|
|
|
lacp_unixctl_show, NULL);
|
2018-04-18 23:57:43 +05:30
|
|
|
|
unixctl_command_register("lacp/show-stats", "[port]", 0, 1,
|
|
|
|
|
|
lacp_unixctl_show_stats, NULL);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
static void
|
|
|
|
|
|
lacp_lock(void) OVS_ACQUIRES(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
2013-07-22 18:35:28 -07:00
|
|
|
|
static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2013-07-22 18:35:28 -07:00
|
|
|
|
if (ovsthread_once_start(&once)) {
|
Use "error-checking" mutexes in place of other kinds wherever possible.
We've seen a number of deadlocks in the tree since thread safety was
introduced. So far, all of these are self-deadlocks, that is, a single
thread acquiring a lock and then attempting to re-acquire the same lock
recursively. When this has happened, the process simply hung, and it was
somewhat difficult to find the cause.
POSIX "error-checking" mutexes check for this specific problem (and
others). This commit switches from other types of mutexes to
error-checking mutexes everywhere that we can, that is, everywhere that
we're not using recursive mutexes. This ought to help find problems more
quickly in the future.
There might be performance advantages to other kinds of mutexes in some
cases. However, the existing mutex type choices were just guesses, so I'd
rather go for easy detection of errors until we know that other mutex
types actually perform better in specific cases. Also, I did a quick
microbenchmark of glibc mutex types on my host and found that the
error checking mutexes weren't any slower than the other types, at least
when the mutex is uncontended.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-08-20 13:40:02 -07:00
|
|
|
|
ovs_mutex_init_recursive(&mutex);
|
2013-07-22 18:35:28 -07:00
|
|
|
|
ovsthread_once_done(&once);
|
|
|
|
|
|
}
|
2014-05-07 13:14:45 -07:00
|
|
|
|
ovs_mutex_lock(&mutex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
lacp_unlock(void) OVS_RELEASES(mutex)
|
|
|
|
|
|
{
|
|
|
|
|
|
ovs_mutex_unlock(&mutex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Creates a LACP object. */
|
|
|
|
|
|
struct lacp *
|
|
|
|
|
|
lacp_create(void) OVS_EXCLUDED(mutex)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct lacp *lacp;
|
2013-07-22 18:35:28 -07:00
|
|
|
|
|
2011-02-28 14:48:06 -08:00
|
|
|
|
lacp = xzalloc(sizeof *lacp);
|
|
|
|
|
|
hmap_init(&lacp->slaves);
|
2013-12-27 19:39:24 -08:00
|
|
|
|
ovs_refcount_init(&lacp->ref_cnt);
|
2013-07-22 18:35:28 -07:00
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2016-03-25 14:10:22 -07:00
|
|
|
|
ovs_list_push_back(all_lacps, &lacp->node);
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2013-06-18 16:44:23 -07:00
|
|
|
|
return lacp;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct lacp *
|
|
|
|
|
|
lacp_ref(const struct lacp *lacp_)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct lacp *lacp = CONST_CAST(struct lacp *, lacp_);
|
|
|
|
|
|
if (lacp) {
|
2013-12-27 19:39:24 -08:00
|
|
|
|
ovs_refcount_ref(&lacp->ref_cnt);
|
2013-06-18 16:44:23 -07:00
|
|
|
|
}
|
2011-02-28 14:48:06 -08:00
|
|
|
|
return lacp;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Destroys 'lacp' and its slaves. Does nothing if 'lacp' is NULL. */
|
|
|
|
|
|
void
|
2013-07-22 18:35:28 -07:00
|
|
|
|
lacp_unref(struct lacp *lacp) OVS_EXCLUDED(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
2014-07-07 13:18:46 -07:00
|
|
|
|
if (lacp && ovs_refcount_unref_relaxed(&lacp->ref_cnt) == 1) {
|
2011-02-28 14:48:06 -08:00
|
|
|
|
struct slave *slave, *next;
|
|
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
HMAP_FOR_EACH_SAFE (slave, next, node, &lacp->slaves) {
|
|
|
|
|
|
slave_destroy(slave);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
hmap_destroy(&lacp->slaves);
|
2016-03-25 14:10:22 -07:00
|
|
|
|
ovs_list_remove(&lacp->node);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
free(lacp->name);
|
|
|
|
|
|
free(lacp);
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-03-21 14:30:33 -07:00
|
|
|
|
/* Configures 'lacp' with settings from 's'. */
|
2011-02-28 14:48:06 -08:00
|
|
|
|
void
|
2011-03-21 14:30:33 -07:00
|
|
|
|
lacp_configure(struct lacp *lacp, const struct lacp_settings *s)
|
2013-07-22 18:35:28 -07:00
|
|
|
|
OVS_EXCLUDED(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
2012-11-06 13:14:55 -08:00
|
|
|
|
ovs_assert(!eth_addr_is_zero(s->id));
|
2011-11-29 13:22:18 -08:00
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2011-03-21 14:30:33 -07:00
|
|
|
|
if (!lacp->name || strcmp(s->name, lacp->name)) {
|
2011-02-28 14:48:06 -08:00
|
|
|
|
free(lacp->name);
|
2011-03-21 14:30:33 -07:00
|
|
|
|
lacp->name = xstrdup(s->name);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-04-18 15:32:30 -07:00
|
|
|
|
if (!eth_addr_equals(lacp->sys_id, s->id)
|
2012-04-16 15:01:09 -07:00
|
|
|
|
|| lacp->sys_priority != s->priority) {
|
2015-08-28 14:55:11 -07:00
|
|
|
|
lacp->sys_id = s->id;
|
2011-04-18 15:32:30 -07:00
|
|
|
|
lacp->sys_priority = s->priority;
|
|
|
|
|
|
lacp->update = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-03-21 14:30:33 -07:00
|
|
|
|
lacp->active = s->active;
|
2012-04-16 14:55:58 -07:00
|
|
|
|
lacp->fast = s->fast;
|
2013-11-04 23:07:10 +00:00
|
|
|
|
|
|
|
|
|
|
if (lacp->fallback_ab != s->fallback_ab_cfg) {
|
|
|
|
|
|
lacp->fallback_ab = s->fallback_ab_cfg;
|
|
|
|
|
|
lacp->update = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-03-21 12:49:44 -07:00
|
|
|
|
/* Returns true if 'lacp' is configured in active mode, false if 'lacp' is
|
|
|
|
|
|
* configured for passive mode. */
|
|
|
|
|
|
bool
|
2013-07-22 18:35:28 -07:00
|
|
|
|
lacp_is_active(const struct lacp *lacp) OVS_EXCLUDED(mutex)
|
2011-03-21 12:49:44 -07:00
|
|
|
|
{
|
2013-07-22 18:35:28 -07:00
|
|
|
|
bool ret;
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2013-07-22 18:35:28 -07:00
|
|
|
|
ret = lacp->active;
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2013-07-22 18:35:28 -07:00
|
|
|
|
return ret;
|
2011-03-21 12:49:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-08-30 18:17:27 -07:00
|
|
|
|
/* Processes 'packet' which was received on 'slave_'. This function should be
|
|
|
|
|
|
* called on all packets received on 'slave_' with Ethernet Type ETH_TYPE_LACP.
|
|
|
|
|
|
*/
|
2011-02-28 14:48:06 -08:00
|
|
|
|
void
|
2011-08-30 18:17:27 -07:00
|
|
|
|
lacp_process_packet(struct lacp *lacp, const void *slave_,
|
2015-02-22 03:21:09 -08:00
|
|
|
|
const struct dp_packet *packet)
|
2013-07-22 18:35:28 -07:00
|
|
|
|
OVS_EXCLUDED(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
2011-08-30 18:17:27 -07:00
|
|
|
|
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
|
|
|
|
|
|
const struct lacp_pdu *pdu;
|
2011-04-18 12:22:12 -07:00
|
|
|
|
long long int tx_rate;
|
2013-07-22 18:35:28 -07:00
|
|
|
|
struct slave *slave;
|
2011-04-18 12:22:12 -07:00
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2013-07-22 18:35:28 -07:00
|
|
|
|
slave = slave_lookup(lacp, slave_);
|
2013-06-19 14:40:21 -07:00
|
|
|
|
if (!slave) {
|
2013-07-22 18:35:28 -07:00
|
|
|
|
goto out;
|
2013-06-19 14:40:21 -07:00
|
|
|
|
}
|
2014-06-27 11:19:59 -07:00
|
|
|
|
slave->count_rx_pdus++;
|
2013-06-19 14:40:21 -07:00
|
|
|
|
|
2011-08-30 18:17:27 -07:00
|
|
|
|
pdu = parse_lacp_packet(packet);
|
|
|
|
|
|
if (!pdu) {
|
2017-03-02 05:02:53 -08:00
|
|
|
|
slave->count_rx_pdus_bad++;
|
2011-08-30 18:17:27 -07:00
|
|
|
|
VLOG_WARN_RL(&rl, "%s: received an unparsable LACP PDU.", lacp->name);
|
2013-07-22 18:35:28 -07:00
|
|
|
|
goto out;
|
2011-08-30 18:17:27 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-02-28 14:48:06 -08:00
|
|
|
|
slave->status = LACP_CURRENT;
|
2012-04-16 14:55:58 -07:00
|
|
|
|
tx_rate = lacp->fast ? LACP_FAST_TIME_TX : LACP_SLOW_TIME_TX;
|
2011-04-18 12:22:12 -07:00
|
|
|
|
timer_set_duration(&slave->rx, LACP_RX_MULTIPLIER * tx_rate);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2011-03-08 18:32:58 -08:00
|
|
|
|
slave->ntt_actor = pdu->partner;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
|
|
|
|
|
/* Update our information about our partner if it's out of date. This may
|
|
|
|
|
|
* cause priorities to change so re-calculate attached status of all
|
|
|
|
|
|
* slaves. */
|
|
|
|
|
|
if (memcmp(&slave->partner, &pdu->actor, sizeof pdu->actor)) {
|
|
|
|
|
|
lacp->update = true;
|
|
|
|
|
|
slave->partner = pdu->actor;
|
|
|
|
|
|
}
|
2013-07-22 18:35:28 -07:00
|
|
|
|
|
|
|
|
|
|
out:
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-11-28 13:54:08 -08:00
|
|
|
|
/* Returns the lacp_status of the given 'lacp' object (which may be NULL). */
|
|
|
|
|
|
enum lacp_status
|
2013-07-22 18:35:28 -07:00
|
|
|
|
lacp_status(const struct lacp *lacp) OVS_EXCLUDED(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
2014-04-24 16:58:45 -07:00
|
|
|
|
if (lacp) {
|
|
|
|
|
|
enum lacp_status ret;
|
2013-07-22 18:35:28 -07:00
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2014-04-24 16:58:45 -07:00
|
|
|
|
ret = lacp->negotiated ? LACP_NEGOTIATED : LACP_CONFIGURED;
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2014-04-24 16:58:45 -07:00
|
|
|
|
return ret;
|
2011-11-28 13:54:08 -08:00
|
|
|
|
} else {
|
2014-04-24 16:58:45 -07:00
|
|
|
|
/* Don't take 'mutex'. It might not even be initialized, since we
|
|
|
|
|
|
* don't know that any lacp object has been created. */
|
|
|
|
|
|
return LACP_DISABLED;
|
2011-11-28 13:54:08 -08:00
|
|
|
|
}
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Registers 'slave_' as subordinate to 'lacp'. This should be called at least
|
|
|
|
|
|
* once per slave in a LACP managed bond. Should also be called whenever a
|
2011-03-21 14:30:33 -07:00
|
|
|
|
* slave's settings change. */
|
2011-02-28 14:48:06 -08:00
|
|
|
|
void
|
2011-03-21 14:30:33 -07:00
|
|
|
|
lacp_slave_register(struct lacp *lacp, void *slave_,
|
|
|
|
|
|
const struct lacp_slave_settings *s)
|
2013-07-22 18:35:28 -07:00
|
|
|
|
OVS_EXCLUDED(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
2013-07-22 18:35:28 -07:00
|
|
|
|
struct slave *slave;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2013-07-22 18:35:28 -07:00
|
|
|
|
slave = slave_lookup(lacp, slave_);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
if (!slave) {
|
|
|
|
|
|
slave = xzalloc(sizeof *slave);
|
|
|
|
|
|
slave->lacp = lacp;
|
|
|
|
|
|
slave->aux = slave_;
|
|
|
|
|
|
hmap_insert(&lacp->slaves, &slave->node, hash_pointer(slave_, 0));
|
|
|
|
|
|
slave_set_defaulted(slave);
|
|
|
|
|
|
|
|
|
|
|
|
if (!lacp->key_slave) {
|
|
|
|
|
|
lacp->key_slave = slave;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-03-21 14:30:33 -07:00
|
|
|
|
if (!slave->name || strcmp(s->name, slave->name)) {
|
2011-02-28 14:48:06 -08:00
|
|
|
|
free(slave->name);
|
2011-03-21 14:30:33 -07:00
|
|
|
|
slave->name = xstrdup(s->name);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-04-26 15:39:58 -07:00
|
|
|
|
if (slave->port_id != s->id
|
|
|
|
|
|
|| slave->port_priority != s->priority
|
|
|
|
|
|
|| slave->key != s->key) {
|
2011-03-21 14:30:33 -07:00
|
|
|
|
slave->port_id = s->id;
|
|
|
|
|
|
slave->port_priority = s->priority;
|
2011-04-26 15:39:58 -07:00
|
|
|
|
slave->key = s->key;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
|
|
|
|
|
lacp->update = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (lacp->active || lacp->negotiated) {
|
|
|
|
|
|
slave_set_expired(slave);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Unregisters 'slave_' with 'lacp'. */
|
|
|
|
|
|
void
|
|
|
|
|
|
lacp_slave_unregister(struct lacp *lacp, const void *slave_)
|
2013-07-22 18:35:28 -07:00
|
|
|
|
OVS_EXCLUDED(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
2013-07-22 18:35:28 -07:00
|
|
|
|
struct slave *slave;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2013-07-22 18:35:28 -07:00
|
|
|
|
slave = slave_lookup(lacp, slave_);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
if (slave) {
|
|
|
|
|
|
slave_destroy(slave);
|
2011-04-18 15:32:30 -07:00
|
|
|
|
lacp->update = true;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This function should be called whenever the carrier status of 'slave_' has
|
2012-03-02 12:24:55 -08:00
|
|
|
|
* changed. If 'lacp' is null, this function has no effect.*/
|
2011-02-28 14:48:06 -08:00
|
|
|
|
void
|
|
|
|
|
|
lacp_slave_carrier_changed(const struct lacp *lacp, const void *slave_)
|
2013-07-22 18:35:28 -07:00
|
|
|
|
OVS_EXCLUDED(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
2013-07-22 18:35:28 -07:00
|
|
|
|
struct slave *slave;
|
|
|
|
|
|
if (!lacp) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2013-07-22 18:35:28 -07:00
|
|
|
|
slave = slave_lookup(lacp, slave_);
|
|
|
|
|
|
if (!slave) {
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
}
|
2013-06-19 14:40:21 -07:00
|
|
|
|
|
2013-07-22 18:35:28 -07:00
|
|
|
|
if (slave->status == LACP_CURRENT || slave->lacp->active) {
|
|
|
|
|
|
slave_set_expired(slave);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
2018-04-18 23:57:43 +05:30
|
|
|
|
slave->count_carrier_changed++;
|
2013-07-22 18:35:28 -07:00
|
|
|
|
|
|
|
|
|
|
out:
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-06-07 14:21:36 -07:00
|
|
|
|
static bool
|
2013-08-08 15:14:19 -07:00
|
|
|
|
slave_may_enable__(struct slave *slave) OVS_REQUIRES(mutex)
|
2012-06-07 14:21:36 -07:00
|
|
|
|
{
|
|
|
|
|
|
/* The slave may be enabled if it's attached to an aggregator and its
|
|
|
|
|
|
* partner is synchronized.*/
|
2013-11-04 23:07:10 +00:00
|
|
|
|
return slave->attached && (slave->partner.state & LACP_STATE_SYNC
|
|
|
|
|
|
|| (slave->lacp && slave->lacp->fallback_ab
|
|
|
|
|
|
&& slave->status == LACP_DEFAULTED));
|
2012-06-07 14:21:36 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-02-28 14:48:06 -08:00
|
|
|
|
/* This function should be called before enabling 'slave_' to send or receive
|
|
|
|
|
|
* traffic. If it returns false, 'slave_' should not enabled. As a
|
|
|
|
|
|
* convenience, returns true if 'lacp' is NULL. */
|
|
|
|
|
|
bool
|
|
|
|
|
|
lacp_slave_may_enable(const struct lacp *lacp, const void *slave_)
|
2013-07-22 18:35:28 -07:00
|
|
|
|
OVS_EXCLUDED(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
|
|
|
|
|
if (lacp) {
|
2013-07-22 18:35:28 -07:00
|
|
|
|
struct slave *slave;
|
|
|
|
|
|
bool ret;
|
|
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2013-07-22 18:35:28 -07:00
|
|
|
|
slave = slave_lookup(lacp, slave_);
|
|
|
|
|
|
ret = slave ? slave_may_enable__(slave) : false;
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2013-07-22 18:35:28 -07:00
|
|
|
|
return ret;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
} else {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-04-13 15:44:37 -07:00
|
|
|
|
/* Returns true if partner information on 'slave_' is up to date. 'slave_'
|
|
|
|
|
|
* not being current, generally indicates a connectivity problem, or a
|
|
|
|
|
|
* misconfigured (or broken) partner. */
|
|
|
|
|
|
bool
|
|
|
|
|
|
lacp_slave_is_current(const struct lacp *lacp, const void *slave_)
|
2013-07-22 18:35:28 -07:00
|
|
|
|
OVS_EXCLUDED(mutex)
|
2011-04-13 15:44:37 -07:00
|
|
|
|
{
|
2013-07-22 18:35:28 -07:00
|
|
|
|
struct slave *slave;
|
|
|
|
|
|
bool ret;
|
|
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2013-07-22 18:35:28 -07:00
|
|
|
|
slave = slave_lookup(lacp, slave_);
|
|
|
|
|
|
ret = slave ? slave->status != LACP_DEFAULTED : false;
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2013-07-22 18:35:28 -07:00
|
|
|
|
return ret;
|
2011-04-13 15:44:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-02-28 14:48:06 -08:00
|
|
|
|
/* This function should be called periodically to update 'lacp'. */
|
|
|
|
|
|
void
|
2013-07-22 18:35:28 -07:00
|
|
|
|
lacp_run(struct lacp *lacp, lacp_send_pdu *send_pdu) OVS_EXCLUDED(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
|
|
|
|
|
struct slave *slave;
|
|
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
HMAP_FOR_EACH (slave, node, &lacp->slaves) {
|
2011-03-31 13:54:15 -07:00
|
|
|
|
if (timer_expired(&slave->rx)) {
|
2013-12-13 03:33:47 +00:00
|
|
|
|
enum slave_status old_status = slave->status;
|
|
|
|
|
|
|
2011-02-28 14:48:06 -08:00
|
|
|
|
if (slave->status == LACP_CURRENT) {
|
|
|
|
|
|
slave_set_expired(slave);
|
2018-04-18 23:57:43 +05:30
|
|
|
|
slave->count_link_expired++;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
} else if (slave->status == LACP_EXPIRED) {
|
|
|
|
|
|
slave_set_defaulted(slave);
|
2018-04-18 23:57:43 +05:30
|
|
|
|
slave->count_link_defaulted++;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
2013-12-13 03:33:47 +00:00
|
|
|
|
if (slave->status != old_status) {
|
|
|
|
|
|
seq_change(connectivity_seq_get());
|
|
|
|
|
|
}
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (lacp->update) {
|
|
|
|
|
|
lacp_update_attached(lacp);
|
2017-07-12 22:35:58 +08:00
|
|
|
|
seq_change(connectivity_seq_get());
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HMAP_FOR_EACH (slave, node, &lacp->slaves) {
|
2011-03-08 18:32:58 -08:00
|
|
|
|
struct lacp_info actor;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2011-03-08 18:32:58 -08:00
|
|
|
|
if (!slave_may_tx(slave)) {
|
2011-02-28 14:48:06 -08:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-03-08 18:32:58 -08:00
|
|
|
|
slave_get_actor(slave, &actor);
|
|
|
|
|
|
|
2011-03-31 13:54:15 -07:00
|
|
|
|
if (timer_expired(&slave->tx)
|
2011-03-08 18:32:58 -08:00
|
|
|
|
|| !info_tx_equal(&actor, &slave->ntt_actor)) {
|
2011-04-18 12:22:12 -07:00
|
|
|
|
long long int duration;
|
2011-08-30 18:17:27 -07:00
|
|
|
|
struct lacp_pdu pdu;
|
2011-03-08 18:32:58 -08:00
|
|
|
|
|
|
|
|
|
|
slave->ntt_actor = actor;
|
|
|
|
|
|
compose_lacp_pdu(&actor, &slave->partner, &pdu);
|
2011-08-30 18:17:27 -07:00
|
|
|
|
send_pdu(slave->aux, &pdu, sizeof pdu);
|
2017-03-02 05:02:53 -08:00
|
|
|
|
slave->count_tx_pdus++;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2012-04-16 14:55:58 -07:00
|
|
|
|
duration = (slave->partner.state & LACP_STATE_TIME
|
|
|
|
|
|
? LACP_FAST_TIME_TX
|
|
|
|
|
|
: LACP_SLOW_TIME_TX);
|
2011-04-18 12:22:12 -07:00
|
|
|
|
|
|
|
|
|
|
timer_set_duration(&slave->tx, duration);
|
2013-12-13 03:33:47 +00:00
|
|
|
|
seq_change(connectivity_seq_get());
|
2011-03-08 18:32:58 -08:00
|
|
|
|
}
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Causes poll_block() to wake up when lacp_run() needs to be called again. */
|
|
|
|
|
|
void
|
2013-07-22 18:35:28 -07:00
|
|
|
|
lacp_wait(struct lacp *lacp) OVS_EXCLUDED(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
|
|
|
|
|
struct slave *slave;
|
|
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
HMAP_FOR_EACH (slave, node, &lacp->slaves) {
|
|
|
|
|
|
if (slave_may_tx(slave)) {
|
2011-03-31 13:54:15 -07:00
|
|
|
|
timer_wait(&slave->tx);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (slave->status != LACP_DEFAULTED) {
|
2011-03-31 13:54:15 -07:00
|
|
|
|
timer_wait(&slave->rx);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Static Helpers. */
|
|
|
|
|
|
|
2011-04-18 15:13:34 -07:00
|
|
|
|
/* Updates the attached status of all slaves controlled by 'lacp' and sets its
|
2011-02-28 14:48:06 -08:00
|
|
|
|
* negotiated parameter to true if any slaves are attachable. */
|
|
|
|
|
|
static void
|
2013-08-08 15:14:19 -07:00
|
|
|
|
lacp_update_attached(struct lacp *lacp) OVS_REQUIRES(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
LACP: Check active partner sys id
A reboot of one switch in an MC-LAG bond makes all bond links
to go down, causing a total connectivity loss for 3 seconds.
Packet capture shows that spurious LACP PDUs are sent to OVS with
a different MAC address (partner system id) during the final
stages of the MC-LAG switch reboot. The current implementation
doesn't care about the partner sys_id (MAC address).
The code change based on the following:
- If an interface (lead interface) on a bond has an "attached"
LACP connection, then any other slaves on that bond is allowed
to become active only when its partner's sys_id is the same as
the partner's sys_id of the lead interface.
- So, when a slave interface of a bond becomes "current" (it gets
valid LACP information), first checks if there is already an
active interface on the bond.
- If there is a lead, the slave checks for the partner sys_ids,
and becomes active only when they are the same, otherwise it
remains in "current" state, but "detached".
- If there is no lead, it follows the old way, and accepts any
partner sys_id.
Signed-off-by: Robert Mulik <robert.mulik@ericsson.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-12-06 10:36:33 +00:00
|
|
|
|
struct slave *lead, *lead_current, *slave;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
struct lacp_info lead_pri;
|
2016-12-21 09:15:59 -08:00
|
|
|
|
bool lead_enable;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 10);
|
|
|
|
|
|
|
|
|
|
|
|
lacp->update = false;
|
|
|
|
|
|
|
|
|
|
|
|
lead = NULL;
|
LACP: Check active partner sys id
A reboot of one switch in an MC-LAG bond makes all bond links
to go down, causing a total connectivity loss for 3 seconds.
Packet capture shows that spurious LACP PDUs are sent to OVS with
a different MAC address (partner system id) during the final
stages of the MC-LAG switch reboot. The current implementation
doesn't care about the partner sys_id (MAC address).
The code change based on the following:
- If an interface (lead interface) on a bond has an "attached"
LACP connection, then any other slaves on that bond is allowed
to become active only when its partner's sys_id is the same as
the partner's sys_id of the lead interface.
- So, when a slave interface of a bond becomes "current" (it gets
valid LACP information), first checks if there is already an
active interface on the bond.
- If there is a lead, the slave checks for the partner sys_ids,
and becomes active only when they are the same, otherwise it
remains in "current" state, but "detached".
- If there is no lead, it follows the old way, and accepts any
partner sys_id.
Signed-off-by: Robert Mulik <robert.mulik@ericsson.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-12-06 10:36:33 +00:00
|
|
|
|
lead_current = NULL;
|
2016-12-21 09:15:59 -08:00
|
|
|
|
lead_enable = false;
|
LACP: Check active partner sys id
A reboot of one switch in an MC-LAG bond makes all bond links
to go down, causing a total connectivity loss for 3 seconds.
Packet capture shows that spurious LACP PDUs are sent to OVS with
a different MAC address (partner system id) during the final
stages of the MC-LAG switch reboot. The current implementation
doesn't care about the partner sys_id (MAC address).
The code change based on the following:
- If an interface (lead interface) on a bond has an "attached"
LACP connection, then any other slaves on that bond is allowed
to become active only when its partner's sys_id is the same as
the partner's sys_id of the lead interface.
- So, when a slave interface of a bond becomes "current" (it gets
valid LACP information), first checks if there is already an
active interface on the bond.
- If there is a lead, the slave checks for the partner sys_ids,
and becomes active only when they are the same, otherwise it
remains in "current" state, but "detached".
- If there is no lead, it follows the old way, and accepts any
partner sys_id.
Signed-off-by: Robert Mulik <robert.mulik@ericsson.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-12-06 10:36:33 +00:00
|
|
|
|
|
|
|
|
|
|
/* Check if there is a working interface.
|
|
|
|
|
|
* Store as lead_current, if there is one. */
|
|
|
|
|
|
HMAP_FOR_EACH (slave, node, &lacp->slaves) {
|
|
|
|
|
|
if (slave->status == LACP_CURRENT && slave->attached) {
|
|
|
|
|
|
struct lacp_info pri;
|
|
|
|
|
|
slave_get_priority(slave, &pri);
|
|
|
|
|
|
if (!lead_current || memcmp(&pri, &lead_pri, sizeof pri) < 0) {
|
|
|
|
|
|
lead_current = slave;
|
|
|
|
|
|
lead = lead_current;
|
|
|
|
|
|
lead_pri = pri;
|
|
|
|
|
|
lead_enable = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Find interface with highest priority. */
|
2011-02-28 14:48:06 -08:00
|
|
|
|
HMAP_FOR_EACH (slave, node, &lacp->slaves) {
|
|
|
|
|
|
struct lacp_info pri;
|
|
|
|
|
|
|
2011-11-28 13:54:08 -08:00
|
|
|
|
slave->attached = false;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
|
|
|
|
|
/* XXX: In the future allow users to configure the expected system ID.
|
|
|
|
|
|
* For now just special case loopback. */
|
2011-03-08 18:32:58 -08:00
|
|
|
|
if (eth_addr_equals(slave->partner.sys_id, slave->lacp->sys_id)) {
|
2011-02-28 14:48:06 -08:00
|
|
|
|
VLOG_WARN_RL(&rl, "slave %s: Loopback detected. Slave is "
|
|
|
|
|
|
"connected to its own bond", slave->name);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (slave->status == LACP_DEFAULTED) {
|
2013-11-04 23:07:10 +00:00
|
|
|
|
if (lacp->fallback_ab) {
|
|
|
|
|
|
slave->attached = true;
|
|
|
|
|
|
}
|
2011-02-28 14:48:06 -08:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
slave_get_priority(slave, &pri);
|
2016-12-21 09:15:59 -08:00
|
|
|
|
bool enable = slave_may_enable__(slave);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
LACP: Check active partner sys id
A reboot of one switch in an MC-LAG bond makes all bond links
to go down, causing a total connectivity loss for 3 seconds.
Packet capture shows that spurious LACP PDUs are sent to OVS with
a different MAC address (partner system id) during the final
stages of the MC-LAG switch reboot. The current implementation
doesn't care about the partner sys_id (MAC address).
The code change based on the following:
- If an interface (lead interface) on a bond has an "attached"
LACP connection, then any other slaves on that bond is allowed
to become active only when its partner's sys_id is the same as
the partner's sys_id of the lead interface.
- So, when a slave interface of a bond becomes "current" (it gets
valid LACP information), first checks if there is already an
active interface on the bond.
- If there is a lead, the slave checks for the partner sys_ids,
and becomes active only when they are the same, otherwise it
remains in "current" state, but "detached".
- If there is no lead, it follows the old way, and accepts any
partner sys_id.
Signed-off-by: Robert Mulik <robert.mulik@ericsson.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-12-06 10:36:33 +00:00
|
|
|
|
/* Check if partner MAC address is the same as on the working
|
|
|
|
|
|
* interface. Activate slave only if the MAC is the same, or
|
|
|
|
|
|
* there is no working interface. */
|
|
|
|
|
|
if (!lead_current || (lead_current
|
|
|
|
|
|
&& eth_addr_equals(slave->partner.sys_id,
|
|
|
|
|
|
lead_current->partner.sys_id))) {
|
|
|
|
|
|
slave->attached = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (slave->attached &&
|
|
|
|
|
|
(!lead
|
|
|
|
|
|
|| enable > lead_enable
|
|
|
|
|
|
|| (enable == lead_enable
|
|
|
|
|
|
&& memcmp(&pri, &lead_pri, sizeof pri) < 0))) {
|
2011-02-28 14:48:06 -08:00
|
|
|
|
lead = slave;
|
2016-12-21 09:15:59 -08:00
|
|
|
|
lead_enable = enable;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
lead_pri = pri;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lacp->negotiated = lead != NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (lead) {
|
|
|
|
|
|
HMAP_FOR_EACH (slave, node, &lacp->slaves) {
|
2013-11-04 23:07:10 +00:00
|
|
|
|
if ((lacp->fallback_ab && slave->status == LACP_DEFAULTED)
|
|
|
|
|
|
|| lead->partner.key != slave->partner.key
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|| !eth_addr_equals(lead->partner.sys_id,
|
|
|
|
|
|
slave->partner.sys_id)) {
|
|
|
|
|
|
slave->attached = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2013-08-08 15:14:19 -07:00
|
|
|
|
slave_destroy(struct slave *slave) OVS_REQUIRES(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
|
|
|
|
|
if (slave) {
|
|
|
|
|
|
struct lacp *lacp = slave->lacp;
|
|
|
|
|
|
|
|
|
|
|
|
lacp->update = true;
|
|
|
|
|
|
hmap_remove(&lacp->slaves, &slave->node);
|
|
|
|
|
|
|
|
|
|
|
|
if (lacp->key_slave == slave) {
|
|
|
|
|
|
struct hmap_node *slave_node = hmap_first(&lacp->slaves);
|
|
|
|
|
|
|
|
|
|
|
|
if (slave_node) {
|
|
|
|
|
|
lacp->key_slave = CONTAINER_OF(slave_node, struct slave, node);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
lacp->key_slave = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
free(slave->name);
|
|
|
|
|
|
free(slave);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2013-08-08 15:14:19 -07:00
|
|
|
|
slave_set_defaulted(struct slave *slave) OVS_REQUIRES(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
|
|
|
|
|
memset(&slave->partner, 0, sizeof slave->partner);
|
|
|
|
|
|
|
|
|
|
|
|
slave->lacp->update = true;
|
|
|
|
|
|
slave->status = LACP_DEFAULTED;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2013-08-08 15:14:19 -07:00
|
|
|
|
slave_set_expired(struct slave *slave) OVS_REQUIRES(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
|
|
|
|
|
slave->status = LACP_EXPIRED;
|
|
|
|
|
|
slave->partner.state |= LACP_STATE_TIME;
|
|
|
|
|
|
slave->partner.state &= ~LACP_STATE_SYNC;
|
2011-04-18 12:22:12 -07:00
|
|
|
|
|
2012-04-16 14:55:58 -07:00
|
|
|
|
timer_set_duration(&slave->rx, LACP_RX_MULTIPLIER * LACP_FAST_TIME_TX);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2011-03-08 18:32:58 -08:00
|
|
|
|
slave_get_actor(struct slave *slave, struct lacp_info *actor)
|
2013-08-08 15:14:19 -07:00
|
|
|
|
OVS_REQUIRES(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
2011-04-26 15:05:19 -07:00
|
|
|
|
struct lacp *lacp = slave->lacp;
|
2011-04-26 15:39:58 -07:00
|
|
|
|
uint16_t key;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
uint8_t state = 0;
|
|
|
|
|
|
|
2011-04-26 15:05:19 -07:00
|
|
|
|
if (lacp->active) {
|
2011-02-28 14:48:06 -08:00
|
|
|
|
state |= LACP_STATE_ACT;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-04-16 14:55:58 -07:00
|
|
|
|
if (lacp->fast) {
|
2011-03-08 16:34:20 -08:00
|
|
|
|
state |= LACP_STATE_TIME;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-02-28 14:48:06 -08:00
|
|
|
|
if (slave->attached) {
|
|
|
|
|
|
state |= LACP_STATE_SYNC;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (slave->status == LACP_DEFAULTED) {
|
|
|
|
|
|
state |= LACP_STATE_DEF;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (slave->status == LACP_EXPIRED) {
|
|
|
|
|
|
state |= LACP_STATE_EXP;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-04-16 15:01:09 -07:00
|
|
|
|
if (hmap_count(&lacp->slaves) > 1) {
|
2011-02-28 14:48:06 -08:00
|
|
|
|
state |= LACP_STATE_AGG;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-04-26 15:05:19 -07:00
|
|
|
|
if (slave->attached || !lacp->negotiated) {
|
2011-02-28 14:48:06 -08:00
|
|
|
|
state |= LACP_STATE_COL | LACP_STATE_DIST;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-04-26 15:39:58 -07:00
|
|
|
|
key = lacp->key_slave->key;
|
|
|
|
|
|
if (!key) {
|
|
|
|
|
|
key = lacp->key_slave->port_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-03-08 18:32:58 -08:00
|
|
|
|
actor->state = state;
|
2011-04-26 15:39:58 -07:00
|
|
|
|
actor->key = htons(key);
|
2011-03-08 18:32:58 -08:00
|
|
|
|
actor->port_priority = htons(slave->port_priority);
|
|
|
|
|
|
actor->port_id = htons(slave->port_id);
|
2011-04-26 15:05:19 -07:00
|
|
|
|
actor->sys_priority = htons(lacp->sys_priority);
|
2015-08-28 14:55:11 -07:00
|
|
|
|
actor->sys_id = lacp->sys_id;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Given 'slave', populates 'priority' with data representing its LACP link
|
|
|
|
|
|
* priority. If two priority objects populated by this function are compared
|
|
|
|
|
|
* using memcmp, the higher priority link will be less than the lower priority
|
|
|
|
|
|
* link. */
|
|
|
|
|
|
static void
|
|
|
|
|
|
slave_get_priority(struct slave *slave, struct lacp_info *priority)
|
2013-08-08 15:14:19 -07:00
|
|
|
|
OVS_REQUIRES(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
|
|
|
|
|
uint16_t partner_priority, actor_priority;
|
|
|
|
|
|
|
|
|
|
|
|
/* Choose the lacp_info of the higher priority system by comparing their
|
|
|
|
|
|
* system priorities and mac addresses. */
|
2011-03-08 18:32:58 -08:00
|
|
|
|
actor_priority = slave->lacp->sys_priority;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
partner_priority = ntohs(slave->partner.sys_priority);
|
|
|
|
|
|
if (actor_priority < partner_priority) {
|
2011-03-08 18:32:58 -08:00
|
|
|
|
slave_get_actor(slave, priority);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
} else if (partner_priority < actor_priority) {
|
|
|
|
|
|
*priority = slave->partner;
|
2011-03-08 18:32:58 -08:00
|
|
|
|
} else if (eth_addr_compare_3way(slave->lacp->sys_id,
|
2011-02-28 14:48:06 -08:00
|
|
|
|
slave->partner.sys_id) < 0) {
|
2011-03-08 18:32:58 -08:00
|
|
|
|
slave_get_actor(slave, priority);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
} else {
|
|
|
|
|
|
*priority = slave->partner;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Key and state are not used in priority comparisons. */
|
|
|
|
|
|
priority->key = 0;
|
|
|
|
|
|
priority->state = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
2013-08-08 15:14:19 -07:00
|
|
|
|
slave_may_tx(const struct slave *slave) OVS_REQUIRES(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
|
|
|
|
|
return slave->lacp->active || slave->status != LACP_DEFAULTED;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct slave *
|
2013-08-08 15:14:19 -07:00
|
|
|
|
slave_lookup(const struct lacp *lacp, const void *slave_) OVS_REQUIRES(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
|
|
|
|
|
struct slave *slave;
|
|
|
|
|
|
|
|
|
|
|
|
HMAP_FOR_EACH_IN_BUCKET (slave, node, hash_pointer(slave_, 0),
|
|
|
|
|
|
&lacp->slaves) {
|
|
|
|
|
|
if (slave->aux == slave_) {
|
|
|
|
|
|
return slave;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
2011-03-08 18:32:58 -08:00
|
|
|
|
|
|
|
|
|
|
/* Two lacp_info structures are tx_equal if and only if they do not differ in
|
|
|
|
|
|
* ways which would require a lacp_pdu transmission. */
|
|
|
|
|
|
static bool
|
|
|
|
|
|
info_tx_equal(struct lacp_info *a, struct lacp_info *b)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/* LACP specification dictates that we transmit whenever the actor and
|
|
|
|
|
|
* remote_actor differ in the following fields: Port, Port Priority,
|
|
|
|
|
|
* System, System Priority, Aggregation Key, Activity State, Timeout State,
|
|
|
|
|
|
* Sync State, and Aggregation State. The state flags are most likely to
|
|
|
|
|
|
* change so are checked first. */
|
|
|
|
|
|
return !((a->state ^ b->state) & (LACP_STATE_ACT
|
|
|
|
|
|
| LACP_STATE_TIME
|
|
|
|
|
|
| LACP_STATE_SYNC
|
|
|
|
|
|
| LACP_STATE_AGG))
|
|
|
|
|
|
&& a->port_id == b->port_id
|
|
|
|
|
|
&& a->port_priority == b->port_priority
|
|
|
|
|
|
&& a->key == b->key
|
|
|
|
|
|
&& a->sys_priority == b->sys_priority
|
|
|
|
|
|
&& eth_addr_equals(a->sys_id, b->sys_id);
|
|
|
|
|
|
}
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
|
|
|
|
|
static struct lacp *
|
2013-08-08 15:14:20 -07:00
|
|
|
|
lacp_find(const char *name) OVS_REQUIRES(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
|
|
|
|
|
struct lacp *lacp;
|
|
|
|
|
|
|
2013-07-22 18:35:28 -07:00
|
|
|
|
LIST_FOR_EACH (lacp, node, all_lacps) {
|
2011-02-28 14:48:06 -08:00
|
|
|
|
if (!strcmp(lacp->name, name)) {
|
|
|
|
|
|
return lacp;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
ds_put_lacp_state(struct ds *ds, uint8_t state)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (state & LACP_STATE_ACT) {
|
2011-11-29 14:27:12 -08:00
|
|
|
|
ds_put_cstr(ds, " activity");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (state & LACP_STATE_TIME) {
|
2011-11-29 14:27:12 -08:00
|
|
|
|
ds_put_cstr(ds, " timeout");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (state & LACP_STATE_AGG) {
|
2011-11-29 14:27:12 -08:00
|
|
|
|
ds_put_cstr(ds, " aggregation");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (state & LACP_STATE_SYNC) {
|
2011-11-29 14:27:12 -08:00
|
|
|
|
ds_put_cstr(ds, " synchronized");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (state & LACP_STATE_COL) {
|
2011-11-29 14:27:12 -08:00
|
|
|
|
ds_put_cstr(ds, " collecting");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (state & LACP_STATE_DIST) {
|
2011-11-29 14:27:12 -08:00
|
|
|
|
ds_put_cstr(ds, " distributing");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (state & LACP_STATE_DEF) {
|
2011-11-29 14:27:12 -08:00
|
|
|
|
ds_put_cstr(ds, " defaulted");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (state & LACP_STATE_EXP) {
|
2011-11-29 14:27:12 -08:00
|
|
|
|
ds_put_cstr(ds, " expired");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2013-08-08 15:14:20 -07:00
|
|
|
|
lacp_print_details(struct ds *ds, struct lacp *lacp) OVS_REQUIRES(mutex)
|
2011-02-28 14:48:06 -08:00
|
|
|
|
{
|
2011-11-29 14:21:26 -08:00
|
|
|
|
struct shash slave_shash = SHASH_INITIALIZER(&slave_shash);
|
|
|
|
|
|
const struct shash_node **sorted_slaves = NULL;
|
|
|
|
|
|
|
2011-02-28 14:48:06 -08:00
|
|
|
|
struct slave *slave;
|
2011-11-29 14:21:26 -08:00
|
|
|
|
int i;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "---- %s ----\n", lacp->name);
|
|
|
|
|
|
ds_put_format(ds, "\tstatus: %s", lacp->active ? "active" : "passive");
|
2011-04-18 15:13:34 -07:00
|
|
|
|
if (lacp->negotiated) {
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_cstr(ds, " negotiated");
|
2011-04-18 15:13:34 -07:00
|
|
|
|
}
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_cstr(ds, "\n");
|
2011-04-18 15:13:34 -07:00
|
|
|
|
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\tsys_id: " ETH_ADDR_FMT "\n", ETH_ADDR_ARGS(lacp->sys_id));
|
|
|
|
|
|
ds_put_format(ds, "\tsys_priority: %u\n", lacp->sys_priority);
|
|
|
|
|
|
ds_put_cstr(ds, "\taggregation key: ");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
if (lacp->key_slave) {
|
2013-01-02 17:23:07 +00:00
|
|
|
|
ds_put_format(ds, "%u", lacp->key_slave->key
|
|
|
|
|
|
? lacp->key_slave->key
|
|
|
|
|
|
: lacp->key_slave->port_id);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
} else {
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_cstr(ds, "none");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_cstr(ds, "\n");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_cstr(ds, "\tlacp_time: ");
|
2012-04-16 14:55:58 -07:00
|
|
|
|
if (lacp->fast) {
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_cstr(ds, "fast\n");
|
2012-04-16 14:55:58 -07:00
|
|
|
|
} else {
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_cstr(ds, "slow\n");
|
2011-04-18 12:22:12 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-02-28 14:48:06 -08:00
|
|
|
|
HMAP_FOR_EACH (slave, node, &lacp->slaves) {
|
2011-11-29 14:21:26 -08:00
|
|
|
|
shash_add(&slave_shash, slave->name, slave);
|
|
|
|
|
|
}
|
|
|
|
|
|
sorted_slaves = shash_sort(&slave_shash);
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < shash_count(&slave_shash); i++) {
|
2011-02-28 14:48:06 -08:00
|
|
|
|
char *status;
|
2011-03-08 18:32:58 -08:00
|
|
|
|
struct lacp_info actor;
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2011-11-29 14:21:26 -08:00
|
|
|
|
slave = sorted_slaves[i]->data;
|
2011-03-08 18:32:58 -08:00
|
|
|
|
slave_get_actor(slave, &actor);
|
2011-02-28 14:48:06 -08:00
|
|
|
|
switch (slave->status) {
|
|
|
|
|
|
case LACP_CURRENT:
|
|
|
|
|
|
status = "current";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case LACP_EXPIRED:
|
|
|
|
|
|
status = "expired";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case LACP_DEFAULTED:
|
|
|
|
|
|
status = "defaulted";
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2013-12-17 10:32:12 -08:00
|
|
|
|
OVS_NOT_REACHED();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\nslave: %s: %s %s\n", slave->name, status,
|
2011-04-14 15:24:18 -07:00
|
|
|
|
slave->attached ? "attached" : "detached");
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\tport_id: %u\n", slave->port_id);
|
|
|
|
|
|
ds_put_format(ds, "\tport_priority: %u\n", slave->port_priority);
|
2012-06-07 14:21:36 -07:00
|
|
|
|
ds_put_format(ds, "\tmay_enable: %s\n", (slave_may_enable__(slave)
|
|
|
|
|
|
? "true" : "false"));
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\n\tactor sys_id: " ETH_ADDR_FMT "\n",
|
2011-03-08 18:32:58 -08:00
|
|
|
|
ETH_ADDR_ARGS(actor.sys_id));
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\tactor sys_priority: %u\n",
|
2011-03-08 18:32:58 -08:00
|
|
|
|
ntohs(actor.sys_priority));
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\tactor port_id: %u\n",
|
2011-03-08 18:32:58 -08:00
|
|
|
|
ntohs(actor.port_id));
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\tactor port_priority: %u\n",
|
2011-03-08 18:32:58 -08:00
|
|
|
|
ntohs(actor.port_priority));
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\tactor key: %u\n",
|
2011-03-08 18:32:58 -08:00
|
|
|
|
ntohs(actor.key));
|
2011-11-29 14:27:12 -08:00
|
|
|
|
ds_put_cstr(ds, "\tactor state:");
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_lacp_state(ds, actor.state);
|
|
|
|
|
|
ds_put_cstr(ds, "\n\n");
|
2011-02-28 14:48:06 -08:00
|
|
|
|
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\tpartner sys_id: " ETH_ADDR_FMT "\n",
|
2011-02-28 14:48:06 -08:00
|
|
|
|
ETH_ADDR_ARGS(slave->partner.sys_id));
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\tpartner sys_priority: %u\n",
|
2011-02-28 14:48:06 -08:00
|
|
|
|
ntohs(slave->partner.sys_priority));
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\tpartner port_id: %u\n",
|
2011-02-28 14:48:06 -08:00
|
|
|
|
ntohs(slave->partner.port_id));
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\tpartner port_priority: %u\n",
|
2011-02-28 14:48:06 -08:00
|
|
|
|
ntohs(slave->partner.port_priority));
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_format(ds, "\tpartner key: %u\n",
|
2011-02-28 14:48:06 -08:00
|
|
|
|
ntohs(slave->partner.key));
|
2011-11-29 14:27:12 -08:00
|
|
|
|
ds_put_cstr(ds, "\tpartner state:");
|
2011-09-26 15:44:46 -07:00
|
|
|
|
ds_put_lacp_state(ds, slave->partner.state);
|
|
|
|
|
|
ds_put_cstr(ds, "\n");
|
|
|
|
|
|
}
|
2011-11-29 14:21:26 -08:00
|
|
|
|
|
|
|
|
|
|
shash_destroy(&slave_shash);
|
|
|
|
|
|
free(sorted_slaves);
|
2011-09-26 15:44:46 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-18 23:57:43 +05:30
|
|
|
|
static void
|
|
|
|
|
|
lacp_print_stats(struct ds *ds, struct lacp *lacp) OVS_REQUIRES(mutex)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct shash slave_shash = SHASH_INITIALIZER(&slave_shash);
|
|
|
|
|
|
const struct shash_node **sorted_slaves = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
struct slave *slave;
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
ds_put_format(ds, "---- %s statistics ----\n", lacp->name);
|
|
|
|
|
|
|
|
|
|
|
|
HMAP_FOR_EACH (slave, node, &lacp->slaves) {
|
|
|
|
|
|
shash_add(&slave_shash, slave->name, slave);
|
|
|
|
|
|
}
|
|
|
|
|
|
sorted_slaves = shash_sort(&slave_shash);
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < shash_count(&slave_shash); i++) {
|
|
|
|
|
|
slave = sorted_slaves[i]->data;
|
|
|
|
|
|
ds_put_format(ds, "\nslave: %s:\n", slave->name);
|
|
|
|
|
|
ds_put_format(ds, "\tRX PDUs: %u\n", slave->count_rx_pdus);
|
|
|
|
|
|
ds_put_format(ds, "\tRX Bad PDUs: %u\n", slave->count_rx_pdus_bad);
|
|
|
|
|
|
ds_put_format(ds, "\tTX PDUs: %u\n", slave->count_tx_pdus);
|
|
|
|
|
|
ds_put_format(ds, "\tLink Expired: %u\n",
|
|
|
|
|
|
slave->count_link_expired);
|
|
|
|
|
|
ds_put_format(ds, "\tLink Defaulted: %u\n",
|
|
|
|
|
|
slave->count_link_defaulted);
|
|
|
|
|
|
ds_put_format(ds, "\tCarrier Status Changed: %u\n",
|
|
|
|
|
|
slave->count_carrier_changed);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
shash_destroy(&slave_shash);
|
|
|
|
|
|
free(sorted_slaves);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-09-26 15:44:46 -07:00
|
|
|
|
static void
|
2011-12-02 15:29:19 -08:00
|
|
|
|
lacp_unixctl_show(struct unixctl_conn *conn, int argc, const char *argv[],
|
2013-07-22 18:35:28 -07:00
|
|
|
|
void *aux OVS_UNUSED) OVS_EXCLUDED(mutex)
|
2011-09-26 15:44:46 -07:00
|
|
|
|
{
|
|
|
|
|
|
struct ds ds = DS_EMPTY_INITIALIZER;
|
|
|
|
|
|
struct lacp *lacp;
|
|
|
|
|
|
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_lock();
|
2011-12-02 15:29:19 -08:00
|
|
|
|
if (argc > 1) {
|
|
|
|
|
|
lacp = lacp_find(argv[1]);
|
2011-09-26 15:44:46 -07:00
|
|
|
|
if (!lacp) {
|
2012-02-14 20:53:59 -08:00
|
|
|
|
unixctl_command_reply_error(conn, "no such lacp object");
|
2013-07-22 18:35:28 -07:00
|
|
|
|
goto out;
|
2011-09-26 15:44:46 -07:00
|
|
|
|
}
|
|
|
|
|
|
lacp_print_details(&ds, lacp);
|
|
|
|
|
|
} else {
|
2013-07-22 18:35:28 -07:00
|
|
|
|
LIST_FOR_EACH (lacp, node, all_lacps) {
|
2011-09-26 15:44:46 -07:00
|
|
|
|
lacp_print_details(&ds, lacp);
|
|
|
|
|
|
}
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-02-14 20:53:59 -08:00
|
|
|
|
unixctl_command_reply(conn, ds_cstr(&ds));
|
2011-02-28 14:48:06 -08:00
|
|
|
|
ds_destroy(&ds);
|
2013-07-22 18:35:28 -07:00
|
|
|
|
|
|
|
|
|
|
out:
|
2014-05-07 13:14:45 -07:00
|
|
|
|
lacp_unlock();
|
2011-02-28 14:48:06 -08:00
|
|
|
|
}
|
2014-06-27 11:19:59 -07:00
|
|
|
|
|
2018-04-18 23:57:43 +05:30
|
|
|
|
static void
|
|
|
|
|
|
lacp_unixctl_show_stats(struct unixctl_conn *conn,
|
|
|
|
|
|
int argc,
|
|
|
|
|
|
const char *argv[],
|
|
|
|
|
|
void *aux OVS_UNUSED) OVS_EXCLUDED(mutex)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct ds ds = DS_EMPTY_INITIALIZER;
|
|
|
|
|
|
struct lacp *lacp;
|
|
|
|
|
|
|
|
|
|
|
|
lacp_lock();
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
|
|
lacp = lacp_find(argv[1]);
|
|
|
|
|
|
if (!lacp) {
|
|
|
|
|
|
unixctl_command_reply_error(conn, "no such lacp object");
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
}
|
|
|
|
|
|
lacp_print_stats(&ds, lacp);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
LIST_FOR_EACH (lacp, node, all_lacps) {
|
|
|
|
|
|
lacp_print_stats(&ds, lacp);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unixctl_command_reply(conn, ds_cstr(&ds));
|
|
|
|
|
|
ds_destroy(&ds);
|
|
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
|
lacp_unlock();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-27 11:19:59 -07:00
|
|
|
|
/* Extract a snapshot of the current state and counters for a slave port.
|
|
|
|
|
|
Return false if the slave is not active. */
|
|
|
|
|
|
bool
|
|
|
|
|
|
lacp_get_slave_stats(const struct lacp *lacp, const void *slave_, struct lacp_slave_stats *stats)
|
|
|
|
|
|
OVS_EXCLUDED(mutex)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct slave *slave;
|
|
|
|
|
|
struct lacp_info actor;
|
|
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
|
|
|
|
ovs_mutex_lock(&mutex);
|
|
|
|
|
|
|
|
|
|
|
|
slave = slave_lookup(lacp, slave_);
|
|
|
|
|
|
if (slave) {
|
|
|
|
|
|
ret = true;
|
|
|
|
|
|
slave_get_actor(slave, &actor);
|
2015-08-28 14:55:11 -07:00
|
|
|
|
stats->dot3adAggPortActorSystemID = actor.sys_id;
|
|
|
|
|
|
stats->dot3adAggPortPartnerOperSystemID = slave->partner.sys_id;
|
2014-06-27 11:19:59 -07:00
|
|
|
|
stats->dot3adAggPortAttachedAggID = (lacp->key_slave->key ?
|
|
|
|
|
|
lacp->key_slave->key :
|
|
|
|
|
|
lacp->key_slave->port_id);
|
|
|
|
|
|
|
|
|
|
|
|
/* Construct my admin-state. Assume aggregation is configured on. */
|
|
|
|
|
|
stats->dot3adAggPortActorAdminState = LACP_STATE_AGG;
|
|
|
|
|
|
if (lacp->active) {
|
|
|
|
|
|
stats->dot3adAggPortActorAdminState |= LACP_STATE_ACT;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (lacp->fast) {
|
|
|
|
|
|
stats->dot3adAggPortActorAdminState |= LACP_STATE_TIME;
|
|
|
|
|
|
}
|
|
|
|
|
|
/* XXX Not sure how to know the partner admin state. It
|
|
|
|
|
|
* might have to be captured and remembered during the
|
|
|
|
|
|
* negotiation phase.
|
|
|
|
|
|
*/
|
|
|
|
|
|
stats->dot3adAggPortPartnerAdminState = 0;
|
|
|
|
|
|
|
|
|
|
|
|
stats->dot3adAggPortActorOperState = actor.state;
|
|
|
|
|
|
stats->dot3adAggPortPartnerOperState = slave->partner.state;
|
|
|
|
|
|
|
|
|
|
|
|
/* Read out the latest counters */
|
|
|
|
|
|
stats->dot3adAggPortStatsLACPDUsRx = slave->count_rx_pdus;
|
|
|
|
|
|
stats->dot3adAggPortStatsIllegalRx = slave->count_rx_pdus_bad;
|
|
|
|
|
|
stats->dot3adAggPortStatsLACPDUsTx = slave->count_tx_pdus;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ret = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
ovs_mutex_unlock(&mutex);
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
|
|
}
|